diff --git a/app/src/main/java/org/thoughtcrime/securesms/megaphone/Megaphones.java b/app/src/main/java/org/thoughtcrime/securesms/megaphone/Megaphones.java index dda5fd9ce2..57651a6065 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/megaphone/Megaphones.java +++ b/app/src/main/java/org/thoughtcrime/securesms/megaphone/Megaphones.java @@ -281,14 +281,14 @@ public final class Megaphones { .setBody(R.string.NotificationsMegaphone_never_miss_a_message) .setImage(R.drawable.megaphone_notifications_64) .setActionButton(R.string.NotificationsMegaphone_turn_on, (megaphone, controller) -> { - controller.onMegaphoneSnooze(Event.NOTIFICATIONS); - if (Build.VERSION.SDK_INT >= 26 && !NotificationChannels.isMessageChannelEnabled(context)) { Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS); intent.putExtra(Settings.EXTRA_CHANNEL_ID, NotificationChannels.getMessagesChannel(context)); intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName()); controller.onMegaphoneNavigationRequested(intent); - } else if (Build.VERSION.SDK_INT >= 26 && !NotificationChannels.areNotificationsEnabled(context)) { + } else if (Build.VERSION.SDK_INT >= 26 && + (!NotificationChannels.areNotificationsEnabled(context) || !NotificationChannels.isMessagesChannelGroupEnabled(context))) + { Intent intent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS); intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName()); controller.onMegaphoneNavigationRequested(intent); @@ -328,8 +328,9 @@ public final class Megaphones { } private static boolean shouldShowNotificationsMegaphone(@NonNull Context context) { - boolean shouldShow = !TextSecurePreferences.isNotificationsEnabled(context) || - !NotificationChannels.isMessageChannelEnabled(context) || + boolean shouldShow = !TextSecurePreferences.isNotificationsEnabled(context) || + !NotificationChannels.isMessageChannelEnabled(context) || + !NotificationChannels.isMessagesChannelGroupEnabled(context) || !NotificationChannels.areNotificationsEnabled(context); if (shouldShow) { Locale locale = DynamicLanguageContextWrapper.getUsersSelectedLocale(context); diff --git a/app/src/main/java/org/thoughtcrime/securesms/notifications/NotificationChannels.java b/app/src/main/java/org/thoughtcrime/securesms/notifications/NotificationChannels.java index de9fd1e31d..1d2cb3597a 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/notifications/NotificationChannels.java +++ b/app/src/main/java/org/thoughtcrime/securesms/notifications/NotificationChannels.java @@ -382,7 +382,9 @@ public class NotificationChannels { * lower importance. * * This could also return true if the specific channnel is enabled, but notifications *overall* - * are disabled. Check {@link #areNotificationsEnabled(Context)} to be safe. + * are disabled, or the messages category is disabled. Check + * {@link #areNotificationsEnabled(Context)} and {@link #isMessagesChannelGroupEnabled(Context)} + * to be safe. */ public static synchronized boolean isMessageChannelEnabled(@NonNull Context context) { if (!supported()) { @@ -395,6 +397,23 @@ public class NotificationChannels { return channel != null && channel.getImportance() != NotificationManager.IMPORTANCE_NONE; } + /** + * Whether or not the notification category for messages is enabled. Note that even if it is, + * a user could have blocked the specific channel, or notifications overall, and it'd still be + * true. See {@link #isMessageChannelEnabled(Context)} and {@link #areNotificationsEnabled(Context)}. + */ + public static synchronized boolean isMessagesChannelGroupEnabled(@NonNull Context context) { + if (Build.VERSION.SDK_INT < 28) { + return true; + } + + NotificationManager notificationManager = ServiceUtil.getNotificationManager(context); + NotificationChannelGroup group = notificationManager.getNotificationChannelGroup(CATEGORY_MESSAGES); + + return group != null && !group.isBlocked(); + } + + /** * Whether or not notifications for the entire app are enabled. */