From d1642c928a484dcdc573fafe51e8032ef474d8dd Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 26 Jun 2019 14:07:53 +0200 Subject: [PATCH 1/2] Move specific classes for FDroid into FDroid variant source code --- vector/src/fdroid/AndroidManifest.xml | 8 ++++-- .../troubleshoot/TestAutoStartBoot.kt | 2 +- .../TestBackgroundRestrictions.kt | 2 +- .../troubleshoot/TestBatteryOptimization.kt | 2 +- .../riotredesign/fdroid/package-info.kt | 20 ++++++++++++++ .../receiver}/AlarmSyncBroadcastReceiver.kt | 27 ++++++++++++++----- .../OnApplicationUpgradeOrRebootReceiver.kt | 3 +-- .../fdroid/service}/VectorSyncService.kt | 8 +++--- .../vector/riotredesign/push/fcm/FcmHelper.kt | 20 +++++++++++++- ...ificationTroubleshootTestManagerFactory.kt | 4 +-- vector/src/gplay/AndroidManifest.xml | 2 +- .../troubleshoot/TestFirebaseToken.kt | 2 +- .../troubleshoot/TestPlayServices.kt | 2 +- .../troubleshoot/TestTokenRegistration.kt | 2 +- .../vector/riotredesign/gplay/package-info.kt | 21 +++++++++++++++ .../fcm/VectorFirebaseMessagingService.kt | 3 ++- .../vector/riotredesign/push/fcm/FcmHelper.kt | 8 ++++++ ...ificationTroubleshootTestManagerFactory.kt | 6 ++--- vector/src/main/AndroidManifest.xml | 9 ------- .../vector/riotredesign/VectorApplication.kt | 18 ++----------- 20 files changed, 116 insertions(+), 53 deletions(-) rename vector/src/fdroid/java/im/vector/riotredesign/{push/fcm => fdroid/features/settings}/troubleshoot/TestAutoStartBoot.kt (96%) rename vector/src/fdroid/java/im/vector/riotredesign/{push/fcm => fdroid/features/settings}/troubleshoot/TestBackgroundRestrictions.kt (98%) rename vector/src/fdroid/java/im/vector/riotredesign/{push/fcm => fdroid/features/settings}/troubleshoot/TestBatteryOptimization.kt (96%) create mode 100644 vector/src/fdroid/java/im/vector/riotredesign/fdroid/package-info.kt rename vector/src/{main/java/im/vector/riotredesign/core/services => fdroid/java/im/vector/riotredesign/fdroid/receiver}/AlarmSyncBroadcastReceiver.kt (70%) rename vector/src/fdroid/java/im/vector/riotredesign/{ => fdroid}/receiver/OnApplicationUpgradeOrRebootReceiver.kt (90%) rename vector/src/{main/java/im/vector/riotredesign/core/services => fdroid/java/im/vector/riotredesign/fdroid/service}/VectorSyncService.kt (92%) rename vector/src/gplay/java/im/vector/riotredesign/{push/fcm => gplay/features/settings}/troubleshoot/TestFirebaseToken.kt (98%) rename vector/src/gplay/java/im/vector/riotredesign/{push/fcm => gplay/features/settings}/troubleshoot/TestPlayServices.kt (97%) rename vector/src/gplay/java/im/vector/riotredesign/{push/fcm => gplay/features/settings}/troubleshoot/TestTokenRegistration.kt (96%) create mode 100644 vector/src/gplay/java/im/vector/riotredesign/gplay/package-info.kt rename vector/src/gplay/java/im/vector/riotredesign/{ => gplay}/push/fcm/VectorFirebaseMessagingService.kt (99%) diff --git a/vector/src/fdroid/AndroidManifest.xml b/vector/src/fdroid/AndroidManifest.xml index 042d9ef8..11d116fe 100644 --- a/vector/src/fdroid/AndroidManifest.xml +++ b/vector/src/fdroid/AndroidManifest.xml @@ -8,7 +8,7 @@ - + @@ -16,10 +16,14 @@ + + \ No newline at end of file diff --git a/vector/src/fdroid/java/im/vector/riotredesign/push/fcm/troubleshoot/TestAutoStartBoot.kt b/vector/src/fdroid/java/im/vector/riotredesign/fdroid/features/settings/troubleshoot/TestAutoStartBoot.kt similarity index 96% rename from vector/src/fdroid/java/im/vector/riotredesign/push/fcm/troubleshoot/TestAutoStartBoot.kt rename to vector/src/fdroid/java/im/vector/riotredesign/fdroid/features/settings/troubleshoot/TestAutoStartBoot.kt index bd266448..211f7337 100644 --- a/vector/src/fdroid/java/im/vector/riotredesign/push/fcm/troubleshoot/TestAutoStartBoot.kt +++ b/vector/src/fdroid/java/im/vector/riotredesign/fdroid/features/settings/troubleshoot/TestAutoStartBoot.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package im.vector.riotredesign.push.fcm.troubleshoot +package im.vector.riotredesign.fdroid.features.settings.troubleshoot import androidx.fragment.app.Fragment import im.vector.riotredesign.R diff --git a/vector/src/fdroid/java/im/vector/riotredesign/push/fcm/troubleshoot/TestBackgroundRestrictions.kt b/vector/src/fdroid/java/im/vector/riotredesign/fdroid/features/settings/troubleshoot/TestBackgroundRestrictions.kt similarity index 98% rename from vector/src/fdroid/java/im/vector/riotredesign/push/fcm/troubleshoot/TestBackgroundRestrictions.kt rename to vector/src/fdroid/java/im/vector/riotredesign/fdroid/features/settings/troubleshoot/TestBackgroundRestrictions.kt index d5903b92..72c0b433 100644 --- a/vector/src/fdroid/java/im/vector/riotredesign/push/fcm/troubleshoot/TestBackgroundRestrictions.kt +++ b/vector/src/fdroid/java/im/vector/riotredesign/fdroid/features/settings/troubleshoot/TestBackgroundRestrictions.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package im.vector.riotredesign.push.fcm.troubleshoot +package im.vector.riotredesign.fdroid.features.settings.troubleshoot import android.content.Context import android.net.ConnectivityManager diff --git a/vector/src/fdroid/java/im/vector/riotredesign/push/fcm/troubleshoot/TestBatteryOptimization.kt b/vector/src/fdroid/java/im/vector/riotredesign/fdroid/features/settings/troubleshoot/TestBatteryOptimization.kt similarity index 96% rename from vector/src/fdroid/java/im/vector/riotredesign/push/fcm/troubleshoot/TestBatteryOptimization.kt rename to vector/src/fdroid/java/im/vector/riotredesign/fdroid/features/settings/troubleshoot/TestBatteryOptimization.kt index ad1529e8..4cfd762f 100644 --- a/vector/src/fdroid/java/im/vector/riotredesign/push/fcm/troubleshoot/TestBatteryOptimization.kt +++ b/vector/src/fdroid/java/im/vector/riotredesign/fdroid/features/settings/troubleshoot/TestBatteryOptimization.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package im.vector.riotredesign.push.fcm.troubleshoot +package im.vector.riotredesign.fdroid.features.settings.troubleshoot import androidx.fragment.app.Fragment import im.vector.riotredesign.R diff --git a/vector/src/fdroid/java/im/vector/riotredesign/fdroid/package-info.kt b/vector/src/fdroid/java/im/vector/riotredesign/fdroid/package-info.kt new file mode 100644 index 00000000..9873a280 --- /dev/null +++ b/vector/src/fdroid/java/im/vector/riotredesign/fdroid/package-info.kt @@ -0,0 +1,20 @@ +/* + * Copyright 2019 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Code exclusively used by the FDroid build and not referenced on the main source code + */ +package im.vector.riotredesign.fdroid \ No newline at end of file diff --git a/vector/src/main/java/im/vector/riotredesign/core/services/AlarmSyncBroadcastReceiver.kt b/vector/src/fdroid/java/im/vector/riotredesign/fdroid/receiver/AlarmSyncBroadcastReceiver.kt similarity index 70% rename from vector/src/main/java/im/vector/riotredesign/core/services/AlarmSyncBroadcastReceiver.kt rename to vector/src/fdroid/java/im/vector/riotredesign/fdroid/receiver/AlarmSyncBroadcastReceiver.kt index f89f39e3..ec37964f 100644 --- a/vector/src/main/java/im/vector/riotredesign/core/services/AlarmSyncBroadcastReceiver.kt +++ b/vector/src/fdroid/java/im/vector/riotredesign/fdroid/receiver/AlarmSyncBroadcastReceiver.kt @@ -1,4 +1,20 @@ -package im.vector.riotredesign.core.services +/* + * Copyright 2019 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.riotredesign.fdroid.receiver import android.app.AlarmManager import android.app.PendingIntent @@ -8,6 +24,7 @@ import android.content.Intent import android.os.Build import android.os.PowerManager import androidx.core.content.ContextCompat +import im.vector.riotredesign.fdroid.service.VectorSyncService import timber.log.Timber class AlarmSyncBroadcastReceiver : BroadcastReceiver() { @@ -46,13 +63,12 @@ class AlarmSyncBroadcastReceiver : BroadcastReceiver() { } companion object { - const val REQUEST_CODE = 0 + private const val REQUEST_CODE = 0 fun scheduleAlarm(context: Context, delay: Long) { //Reschedule val intent = Intent(context, AlarmSyncBroadcastReceiver::class.java) - val pIntent = PendingIntent.getBroadcast(context, AlarmSyncBroadcastReceiver.REQUEST_CODE, - intent, PendingIntent.FLAG_UPDATE_CURRENT) + val pIntent = PendingIntent.getBroadcast(context, REQUEST_CODE, intent, PendingIntent.FLAG_UPDATE_CURRENT) val firstMillis = System.currentTimeMillis() + delay val alarmMgr = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { @@ -64,8 +80,7 @@ class AlarmSyncBroadcastReceiver : BroadcastReceiver() { fun cancelAlarm(context: Context) { val intent = Intent(context, AlarmSyncBroadcastReceiver::class.java) - val pIntent = PendingIntent.getBroadcast(context, AlarmSyncBroadcastReceiver.REQUEST_CODE, - intent, PendingIntent.FLAG_UPDATE_CURRENT) + val pIntent = PendingIntent.getBroadcast(context, REQUEST_CODE, intent, PendingIntent.FLAG_UPDATE_CURRENT) val alarmMgr = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager alarmMgr.cancel(pIntent) } diff --git a/vector/src/fdroid/java/im/vector/riotredesign/receiver/OnApplicationUpgradeOrRebootReceiver.kt b/vector/src/fdroid/java/im/vector/riotredesign/fdroid/receiver/OnApplicationUpgradeOrRebootReceiver.kt similarity index 90% rename from vector/src/fdroid/java/im/vector/riotredesign/receiver/OnApplicationUpgradeOrRebootReceiver.kt rename to vector/src/fdroid/java/im/vector/riotredesign/fdroid/receiver/OnApplicationUpgradeOrRebootReceiver.kt index a13bc71a..4ed793d7 100644 --- a/vector/src/fdroid/java/im/vector/riotredesign/receiver/OnApplicationUpgradeOrRebootReceiver.kt +++ b/vector/src/fdroid/java/im/vector/riotredesign/fdroid/receiver/OnApplicationUpgradeOrRebootReceiver.kt @@ -15,12 +15,11 @@ * limitations under the License. */ -package im.vector.riotredesign.receiver +package im.vector.riotredesign.fdroid.receiver import android.content.BroadcastReceiver import android.content.Context import android.content.Intent -import im.vector.riotredesign.core.services.AlarmSyncBroadcastReceiver import timber.log.Timber class OnApplicationUpgradeOrRebootReceiver : BroadcastReceiver() { diff --git a/vector/src/main/java/im/vector/riotredesign/core/services/VectorSyncService.kt b/vector/src/fdroid/java/im/vector/riotredesign/fdroid/service/VectorSyncService.kt similarity index 92% rename from vector/src/main/java/im/vector/riotredesign/core/services/VectorSyncService.kt rename to vector/src/fdroid/java/im/vector/riotredesign/fdroid/service/VectorSyncService.kt index 6f105c94..6b3cec1a 100644 --- a/vector/src/main/java/im/vector/riotredesign/core/services/VectorSyncService.kt +++ b/vector/src/fdroid/java/im/vector/riotredesign/fdroid/service/VectorSyncService.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package im.vector.riotredesign.core.services +package im.vector.riotredesign.fdroid.service import android.app.NotificationManager import android.content.Context @@ -28,12 +28,12 @@ import timber.log.Timber class VectorSyncService : SyncService() { override fun onCreate() { - Timber.v("VectorSyncService - onCreate ") + Timber.v("VectorSyncService - onCreate") super.onCreate() } override fun onDestroy() { - Timber.v("VectorSyncService - onDestroy ") + Timber.v("VectorSyncService - onDestroy") removeForegroundNotif() super.onDestroy() } @@ -57,7 +57,7 @@ class VectorSyncService : SyncService() { } /** - * If the service is bounded and the service was previously started we can remove foreground notif + * If the service is bounded and the service was previously started we can remove foreground notification */ override fun onBind(intent: Intent?): IBinder { Timber.v("VectorSyncService - onBind ") diff --git a/vector/src/fdroid/java/im/vector/riotredesign/push/fcm/FcmHelper.kt b/vector/src/fdroid/java/im/vector/riotredesign/push/fcm/FcmHelper.kt index 11826a7b..6691f5ed 100755 --- a/vector/src/fdroid/java/im/vector/riotredesign/push/fcm/FcmHelper.kt +++ b/vector/src/fdroid/java/im/vector/riotredesign/push/fcm/FcmHelper.kt @@ -18,9 +18,14 @@ package im.vector.riotredesign.push.fcm import android.app.Activity import android.content.Context - import im.vector.riotredesign.core.pushers.PushersManager +import im.vector.riotredesign.fdroid.receiver.AlarmSyncBroadcastReceiver +import im.vector.riotredesign.features.settings.PreferencesManager +import timber.log.Timber +/** + * This class has an alter ego in the gplay variant. + */ object FcmHelper { fun isPushSupported(): Boolean = false @@ -52,4 +57,17 @@ object FcmHelper { fun ensureFcmTokenIsRetrieved(activity: Activity, pushersManager: PushersManager) { // No op } + + fun onEnterForeground(context: Context) { + AlarmSyncBroadcastReceiver.cancelAlarm(context) + } + + fun onEnterBackground(context: Context, hasSession: Boolean) { + //We need to use alarm in this mode + if (PreferencesManager.areNotificationEnabledForDevice(context) + && hasSession) { + AlarmSyncBroadcastReceiver.scheduleAlarm(context, 4_000L) + Timber.i("Alarm scheduled to restart service") + } + } } diff --git a/vector/src/fdroid/java/im/vector/riotredesign/push/fcm/NotificationTroubleshootTestManagerFactory.kt b/vector/src/fdroid/java/im/vector/riotredesign/push/fcm/NotificationTroubleshootTestManagerFactory.kt index 0a3fdd22..9a5ada35 100644 --- a/vector/src/fdroid/java/im/vector/riotredesign/push/fcm/NotificationTroubleshootTestManagerFactory.kt +++ b/vector/src/fdroid/java/im/vector/riotredesign/push/fcm/NotificationTroubleshootTestManagerFactory.kt @@ -17,9 +17,9 @@ package im.vector.riotredesign.push.fcm import androidx.fragment.app.Fragment import im.vector.matrix.android.api.session.Session +import im.vector.riotredesign.fdroid.features.settings.troubleshoot.TestAutoStartBoot +import im.vector.riotredesign.fdroid.features.settings.troubleshoot.TestBackgroundRestrictions import im.vector.riotredesign.features.settings.troubleshoot.* -import im.vector.riotredesign.push.fcm.troubleshoot.TestAutoStartBoot -import im.vector.riotredesign.push.fcm.troubleshoot.TestBackgroundRestrictions class NotificationTroubleshootTestManagerFactory { diff --git a/vector/src/gplay/AndroidManifest.xml b/vector/src/gplay/AndroidManifest.xml index 145da025..8f6a1cef 100755 --- a/vector/src/gplay/AndroidManifest.xml +++ b/vector/src/gplay/AndroidManifest.xml @@ -9,7 +9,7 @@ android:name="firebase_analytics_collection_deactivated" android:value="true" /> - + diff --git a/vector/src/gplay/java/im/vector/riotredesign/push/fcm/troubleshoot/TestFirebaseToken.kt b/vector/src/gplay/java/im/vector/riotredesign/gplay/features/settings/troubleshoot/TestFirebaseToken.kt similarity index 98% rename from vector/src/gplay/java/im/vector/riotredesign/push/fcm/troubleshoot/TestFirebaseToken.kt rename to vector/src/gplay/java/im/vector/riotredesign/gplay/features/settings/troubleshoot/TestFirebaseToken.kt index 6ab552da..56ee8062 100644 --- a/vector/src/gplay/java/im/vector/riotredesign/push/fcm/troubleshoot/TestFirebaseToken.kt +++ b/vector/src/gplay/java/im/vector/riotredesign/gplay/features/settings/troubleshoot/TestFirebaseToken.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package im.vector.riotredesign.push.fcm.troubleshoot +package im.vector.riotredesign.gplay.features.settings.troubleshoot import androidx.fragment.app.Fragment import com.google.firebase.iid.FirebaseInstanceId diff --git a/vector/src/gplay/java/im/vector/riotredesign/push/fcm/troubleshoot/TestPlayServices.kt b/vector/src/gplay/java/im/vector/riotredesign/gplay/features/settings/troubleshoot/TestPlayServices.kt similarity index 97% rename from vector/src/gplay/java/im/vector/riotredesign/push/fcm/troubleshoot/TestPlayServices.kt rename to vector/src/gplay/java/im/vector/riotredesign/gplay/features/settings/troubleshoot/TestPlayServices.kt index 5d56712b..842f043d 100644 --- a/vector/src/gplay/java/im/vector/riotredesign/push/fcm/troubleshoot/TestPlayServices.kt +++ b/vector/src/gplay/java/im/vector/riotredesign/gplay/features/settings/troubleshoot/TestPlayServices.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package im.vector.riotredesign.push.fcm.troubleshoot +package im.vector.riotredesign.gplay.features.settings.troubleshoot import androidx.fragment.app.Fragment import com.google.android.gms.common.ConnectionResult diff --git a/vector/src/gplay/java/im/vector/riotredesign/push/fcm/troubleshoot/TestTokenRegistration.kt b/vector/src/gplay/java/im/vector/riotredesign/gplay/features/settings/troubleshoot/TestTokenRegistration.kt similarity index 96% rename from vector/src/gplay/java/im/vector/riotredesign/push/fcm/troubleshoot/TestTokenRegistration.kt rename to vector/src/gplay/java/im/vector/riotredesign/gplay/features/settings/troubleshoot/TestTokenRegistration.kt index 912597ec..8f96aaa8 100644 --- a/vector/src/gplay/java/im/vector/riotredesign/push/fcm/troubleshoot/TestTokenRegistration.kt +++ b/vector/src/gplay/java/im/vector/riotredesign/gplay/features/settings/troubleshoot/TestTokenRegistration.kt @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package im.vector.riotredesign.push.fcm.troubleshoot +package im.vector.riotredesign.gplay.features.settings.troubleshoot import androidx.fragment.app.Fragment import im.vector.riotredesign.R diff --git a/vector/src/gplay/java/im/vector/riotredesign/gplay/package-info.kt b/vector/src/gplay/java/im/vector/riotredesign/gplay/package-info.kt new file mode 100644 index 00000000..60938525 --- /dev/null +++ b/vector/src/gplay/java/im/vector/riotredesign/gplay/package-info.kt @@ -0,0 +1,21 @@ +/* + * Copyright 2019 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Code exclusively used by the GPlay build and not referenced on the main source code + */ +package im.vector.riotredesign.gplay + diff --git a/vector/src/gplay/java/im/vector/riotredesign/push/fcm/VectorFirebaseMessagingService.kt b/vector/src/gplay/java/im/vector/riotredesign/gplay/push/fcm/VectorFirebaseMessagingService.kt similarity index 99% rename from vector/src/gplay/java/im/vector/riotredesign/push/fcm/VectorFirebaseMessagingService.kt rename to vector/src/gplay/java/im/vector/riotredesign/gplay/push/fcm/VectorFirebaseMessagingService.kt index 99c95d89..2d0ad013 100755 --- a/vector/src/gplay/java/im/vector/riotredesign/push/fcm/VectorFirebaseMessagingService.kt +++ b/vector/src/gplay/java/im/vector/riotredesign/gplay/push/fcm/VectorFirebaseMessagingService.kt @@ -17,7 +17,7 @@ * limitations under the License. */ -package im.vector.riotredesign.push.fcm +package im.vector.riotredesign.gplay.push.fcm import android.os.Handler import android.os.Looper @@ -39,6 +39,7 @@ import im.vector.riotredesign.features.notifications.NotifiableMessageEvent import im.vector.riotredesign.features.notifications.NotificationDrawerManager import im.vector.riotredesign.features.notifications.SimpleNotifiableEvent import im.vector.riotredesign.features.settings.PreferencesManager +import im.vector.riotredesign.push.fcm.FcmHelper import org.koin.android.ext.android.inject import timber.log.Timber diff --git a/vector/src/gplay/java/im/vector/riotredesign/push/fcm/FcmHelper.kt b/vector/src/gplay/java/im/vector/riotredesign/push/fcm/FcmHelper.kt index 25f380f4..a0e2d824 100755 --- a/vector/src/gplay/java/im/vector/riotredesign/push/fcm/FcmHelper.kt +++ b/vector/src/gplay/java/im/vector/riotredesign/push/fcm/FcmHelper.kt @@ -99,4 +99,12 @@ object FcmHelper { val resultCode = apiAvailability.isGooglePlayServicesAvailable(activity) return resultCode == ConnectionResult.SUCCESS } + + fun onEnterForeground(context: Context) { + // No op + } + + fun onEnterBackground(context: Context, hasSession: Boolean) { + // TODO FCM fallback + } } diff --git a/vector/src/gplay/java/im/vector/riotredesign/push/fcm/NotificationTroubleshootTestManagerFactory.kt b/vector/src/gplay/java/im/vector/riotredesign/push/fcm/NotificationTroubleshootTestManagerFactory.kt index ee4e59e4..f2bb4007 100644 --- a/vector/src/gplay/java/im/vector/riotredesign/push/fcm/NotificationTroubleshootTestManagerFactory.kt +++ b/vector/src/gplay/java/im/vector/riotredesign/push/fcm/NotificationTroubleshootTestManagerFactory.kt @@ -18,9 +18,9 @@ package im.vector.riotredesign.push.fcm import androidx.fragment.app.Fragment import im.vector.matrix.android.api.session.Session import im.vector.riotredesign.features.settings.troubleshoot.* -import im.vector.riotredesign.push.fcm.troubleshoot.TestFirebaseToken -import im.vector.riotredesign.push.fcm.troubleshoot.TestPlayServices -import im.vector.riotredesign.push.fcm.troubleshoot.TestTokenRegistration +import im.vector.riotredesign.gplay.features.settings.troubleshoot.TestFirebaseToken +import im.vector.riotredesign.gplay.features.settings.troubleshoot.TestPlayServices +import im.vector.riotredesign.gplay.features.settings.troubleshoot.TestTokenRegistration class NotificationTroubleshootTestManagerFactory { diff --git a/vector/src/main/AndroidManifest.xml b/vector/src/main/AndroidManifest.xml index aaae3edb..8fa24217 100644 --- a/vector/src/main/AndroidManifest.xml +++ b/vector/src/main/AndroidManifest.xml @@ -68,15 +68,6 @@ - - - - - - - diff --git a/vector/src/main/java/im/vector/riotredesign/VectorApplication.kt b/vector/src/main/java/im/vector/riotredesign/VectorApplication.kt index 9bef712e..90ec01c9 100644 --- a/vector/src/main/java/im/vector/riotredesign/VectorApplication.kt +++ b/vector/src/main/java/im/vector/riotredesign/VectorApplication.kt @@ -36,7 +36,6 @@ import com.github.piasy.biv.loader.glide.GlideImageLoader import com.jakewharton.threetenabp.AndroidThreeTen import im.vector.matrix.android.api.Matrix import im.vector.riotredesign.core.di.AppModule -import im.vector.riotredesign.core.services.AlarmSyncBroadcastReceiver import im.vector.riotredesign.features.configuration.VectorConfiguration import im.vector.riotredesign.features.crypto.keysbackup.KeysBackupModule import im.vector.riotredesign.features.home.HomeModule @@ -47,7 +46,6 @@ import im.vector.riotredesign.features.notifications.PushRuleTriggerListener import im.vector.riotredesign.features.rageshake.VectorFileLogger import im.vector.riotredesign.features.rageshake.VectorUncaughtExceptionHandler import im.vector.riotredesign.features.roomdirectory.RoomDirectoryModule -import im.vector.riotredesign.features.settings.PreferencesManager import im.vector.riotredesign.features.version.getVersion import im.vector.riotredesign.push.fcm.FcmHelper import org.koin.android.ext.android.get @@ -117,7 +115,7 @@ class VectorApplication : Application() { @OnLifecycleEvent(Lifecycle.Event.ON_RESUME) fun entersForeground() { - AlarmSyncBroadcastReceiver.cancelAlarm(appContext) + FcmHelper.onEnterForeground(appContext) Matrix.getInstance().currentSession?.also { it.stopAnyBackgroundSync() } @@ -129,20 +127,8 @@ class VectorApplication : Application() { notificationDrawerManager.persistInfo() - if (FcmHelper.isPushSupported()) { - //TODO FCM fallback - } else { - //TODO check if notifications are enabled for this device - //We need to use alarm in this mode - if (PreferencesManager.areNotificationEnabledForDevice(applicationContext)) { - if (Matrix.getInstance().currentSession != null) { - AlarmSyncBroadcastReceiver.scheduleAlarm(applicationContext, 4_000L) - Timber.i("Alarm scheduled to restart service") - } - } - } + FcmHelper.onEnterBackground(appContext, Matrix.getInstance().currentSession != null) } - }) From ae7e617fdd5e59f90e24f7dcf2a5cd63c63c5a48 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 26 Jun 2019 14:35:00 +0200 Subject: [PATCH 2/2] Rename and format and remove duplicate EventType.REDACTION --- .../session/notification/BingRuleWatcher.kt | 5 +++- .../notification/ProcessEventForPushTask.kt | 23 ++++++++++--------- .../notifications/PushRuleTriggerListener.kt | 16 ++++++------- 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/notification/BingRuleWatcher.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/notification/BingRuleWatcher.kt index 2e6a1a9a..cf99c205 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/notification/BingRuleWatcher.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/notification/BingRuleWatcher.kt @@ -36,12 +36,15 @@ internal class BingRuleWatcher(monarchy: Monarchy, override val query = Monarchy.Query { EventEntity.types(it, listOf( - EventType.REDACTION, EventType.MESSAGE, EventType.REDACTION, EventType.ENCRYPTED) + EventType.MESSAGE, + EventType.REDACTION, + EventType.ENCRYPTED) ) } override fun processChanges(inserted: List, updated: List, deleted: List) { + // TODO Use const for "global" val rules = defaultPushRuleService.getPushRules("global") inserted.map { it.asDomain() } .filter { it.senderId != sessionParams.credentials.userId } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/notification/ProcessEventForPushTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/notification/ProcessEventForPushTask.kt index 36b7f720..7db4daa3 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/notification/ProcessEventForPushTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/notification/ProcessEventForPushTask.kt @@ -33,18 +33,19 @@ internal class DefaultProcessEventForPushTask( private fun fulfilledBingRule(event: Event, rules: List): PushRule? { val conditionResolver = DefaultConditionResolver(event) - rules.filter { it.enabled }.forEach { rule -> - val isFullfilled = rule.conditions?.map { - it.asExecutableCondition()?.isSatisfied(conditionResolver) ?: false - }?.fold(true/*A rule with no conditions always matches*/, { acc, next -> - //All conditions must hold true for an event in order to apply the action for the event. - acc && next - }) ?: false + rules.filter { it.enabled } + .forEach { rule -> + val isFullfilled = rule.conditions?.map { + it.asExecutableCondition()?.isSatisfied(conditionResolver) ?: false + }?.fold(true/*A rule with no conditions always matches*/, { acc, next -> + //All conditions must hold true for an event in order to apply the action for the event. + acc && next + }) ?: false - if (isFullfilled) { - return rule - } - } + if (isFullfilled) { + return rule + } + } return null } diff --git a/vector/src/main/java/im/vector/riotredesign/features/notifications/PushRuleTriggerListener.kt b/vector/src/main/java/im/vector/riotredesign/features/notifications/PushRuleTriggerListener.kt index f3aed6ad..e0fe0fe8 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/notifications/PushRuleTriggerListener.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/notifications/PushRuleTriggerListener.kt @@ -25,7 +25,7 @@ import timber.log.Timber class PushRuleTriggerListener( private val resolver: NotifiableEventResolver, - private val drawerManager: NotificationDrawerManager + private val notificationDrawerManager: NotificationDrawerManager ) : PushRuleService.PushRuleListener { @@ -39,14 +39,14 @@ class PushRuleTriggerListener( } val notificationAction = NotificationAction.extractFrom(actions) if (notificationAction.shouldNotify) { - val resolveEvent = resolver.resolveEvent(event, session!!) - if (resolveEvent == null) { + val notifiableEvent = resolver.resolveEvent(event, session!!) + if (notifiableEvent == null) { Timber.v("## Failed to resolve event") //TODO } else { - resolveEvent.noisy = !notificationAction.soundName.isNullOrBlank() - Timber.v("New event to notify $resolveEvent tweaks:$notificationAction") - drawerManager.onNotifiableEventReceived(resolveEvent) + notifiableEvent.noisy = !notificationAction.soundName.isNullOrBlank() + Timber.v("New event to notify $notifiableEvent tweaks:$notificationAction") + notificationDrawerManager.onNotifiableEventReceived(notifiableEvent) } } else { Timber.v("Matched push rule is set to not notify") @@ -54,7 +54,7 @@ class PushRuleTriggerListener( } override fun batchFinish() { - drawerManager.refreshNotificationDrawer() + notificationDrawerManager.refreshNotificationDrawer() } fun startWithSession(session: Session) { @@ -68,7 +68,7 @@ class PushRuleTriggerListener( fun stop() { session?.removePushRuleListener(this) session = null - drawerManager.clearAllEvents() + notificationDrawerManager.clearAllEvents() } } \ No newline at end of file