diff --git a/vector/src/gplay/java/im/vector/riotredesign/push/fcm/VectorFirebaseMessagingService.kt b/vector/src/gplay/java/im/vector/riotredesign/push/fcm/VectorFirebaseMessagingService.kt index 14fed48d..0dacb939 100755 --- a/vector/src/gplay/java/im/vector/riotredesign/push/fcm/VectorFirebaseMessagingService.kt +++ b/vector/src/gplay/java/im/vector/riotredesign/push/fcm/VectorFirebaseMessagingService.kt @@ -38,6 +38,7 @@ import im.vector.riotredesign.features.notifications.NotifiableEventResolver 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 org.koin.android.ext.android.inject import timber.log.Timber @@ -61,6 +62,11 @@ class VectorFirebaseMessagingService : FirebaseMessagingService() { * @param message the message */ override fun onMessageReceived(message: RemoteMessage?) { + if (!PreferencesManager.areNotificationEnabledForDevice(applicationContext)) { + Timber.i("Notification are disabled for this device") + return + } + if (message == null || message.data == null) { Timber.e("## onMessageReceived() : received a null message or message with no data") return @@ -91,7 +97,9 @@ class VectorFirebaseMessagingService : FirebaseMessagingService() { if (refreshedToken == null) { Timber.w("onNewToken:received null token") } else { - pusherManager.registerPusherWithFcmKey(refreshedToken) + if (PreferencesManager.areNotificationEnabledForDevice(applicationContext)) { + pusherManager.registerPusherWithFcmKey(refreshedToken) + } } } diff --git a/vector/src/main/java/im/vector/riotredesign/VectorApplication.kt b/vector/src/main/java/im/vector/riotredesign/VectorApplication.kt index 93e34a78..6f812753 100644 --- a/vector/src/main/java/im/vector/riotredesign/VectorApplication.kt +++ b/vector/src/main/java/im/vector/riotredesign/VectorApplication.kt @@ -54,6 +54,7 @@ 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 @@ -137,11 +138,12 @@ class VectorApplication : Application() { } else { //TODO check if notifications are enabled for this device //We need to use alarm in this mode - if (Matrix.getInstance().currentSession != null) { - AlarmSyncBroadcastReceiver.scheduleAlarm(applicationContext, 4_000L) - Timber.i("Alarm scheduled to restart service") + if (PreferencesManager.areNotificationEnabledForDevice(applicationContext)) { + if (Matrix.getInstance().currentSession != null) { + AlarmSyncBroadcastReceiver.scheduleAlarm(applicationContext, 4_000L) + Timber.i("Alarm scheduled to restart service") + } } - } } diff --git a/vector/src/main/java/im/vector/riotredesign/features/notifications/NotificationDrawerManager.kt b/vector/src/main/java/im/vector/riotredesign/features/notifications/NotificationDrawerManager.kt index d1ff76f7..3e0875b0 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/notifications/NotificationDrawerManager.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/notifications/NotificationDrawerManager.kt @@ -27,6 +27,7 @@ import im.vector.matrix.android.api.session.content.ContentUrlResolver import im.vector.riotredesign.BuildConfig import im.vector.riotredesign.R import im.vector.riotredesign.core.utils.SecretStoringUtils +import im.vector.riotredesign.features.settings.PreferencesManager import timber.log.Timber import java.io.File import java.io.FileInputStream @@ -65,6 +66,10 @@ class NotificationDrawerManager(val context: Context, Events might be grouped and there might not be one notification per event! */ fun onNotifiableEventReceived(notifiableEvent: NotifiableEvent) { + if (!PreferencesManager.areNotificationEnabledForDevice(context)) { + Timber.i("Notification are disabled for this device") + return + } //If we support multi session, event list should be per userId //Currently only manage single session if (BuildConfig.LOW_PRIVACY_LOG_ENABLE) { diff --git a/vector/src/main/java/im/vector/riotredesign/features/settings/VectorSettingsNotificationFragment.kt b/vector/src/main/java/im/vector/riotredesign/features/settings/VectorSettingsNotificationFragment.kt index de2aa10b..6cff9f2d 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/settings/VectorSettingsNotificationFragment.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/settings/VectorSettingsNotificationFragment.kt @@ -35,7 +35,9 @@ class VectorSettingsNotificationPreferenceFragment : VectorPreferenceFragment() val switchPref = preference as SwitchPreference if (switchPref.isChecked) { FcmHelper.getFcmToken(requireContext())?.let { - pushManager.registerPusherWithFcmKey(it) + if (PreferencesManager.areNotificationEnabledForDevice(requireContext())) { + pushManager.registerPusherWithFcmKey(it) + } } } else { FcmHelper.getFcmToken(requireContext())?.let {