Index: chrome/android/java/src/org/chromium/chrome/browser/notifications/ChannelsInitializer.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/notifications/ChannelsInitializer.java b/chrome/android/java/src/org/chromium/chrome/browser/notifications/ChannelsInitializer.java |
index 040d7881d4ac5fd996636a08e0de21689e38fc1a..f3f21c93f4c961487726307a00c6cd68ce5c096e 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/notifications/ChannelsInitializer.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/notifications/ChannelsInitializer.java |
@@ -19,6 +19,13 @@ import java.util.Map; |
* Initializes our notification channels. |
*/ |
public class ChannelsInitializer { |
+ /** |
+ * Version number identifying the current set of channels. This must be incremented whenever |
+ * any channels are added or removed from the set of channels created in |
+ * {@link ChannelsInitializer#initializeStartupChannels()} |
+ */ |
+ static final int CHANNELS_VERSION = 0; |
+ |
// To define a new channel, add the channel ID to this StringDef and add a new entry to |
// PredefinedChannels.MAP below with the appropriate channel parameters. |
@StringDef({CHANNEL_ID_BROWSER, CHANNEL_ID_SITES}) |
@@ -35,6 +42,10 @@ public class ChannelsInitializer { |
// Map defined in static inner class so it's only initialized lazily. |
@TargetApi(Build.VERSION_CODES.N) // for NotificationManager.IMPORTANCE_* constants |
private static class PredefinedChannels { |
+ /** |
+ * The set of predefined channels to be initialized on startup. CHANNELS_VERSION must be |
+ * incremented every time an entry is modified, removed or added to this map. |
+ */ |
private static final Map<String, Channel> MAP; |
static { |
Map<String, Channel> map = new HashMap<>(); |
@@ -68,6 +79,19 @@ public class ChannelsInitializer { |
mNotificationManager = notificationManagerProxy; |
} |
+ public void initializeStartupChannels() { |
+ // CHANNELS_VERSION must be incremented if the set of channels initialized here changes. |
+ for (@ChannelId String channelId : PredefinedChannels.MAP.keySet()) { |
+ ensureInitialized(channelId); |
+ } |
+ } |
+ |
+ void deleteAllChannels() { |
+ for (String channelId : mNotificationManager.getNotificationChannelIds()) { |
+ mNotificationManager.deleteNotificationChannel(channelId); |
+ } |
+ } |
+ |
/** |
* Ensures the given channel has been created on the notification manager so a notification |
* can be safely posted to it. This should only be used for channels that are predefined in |
@@ -93,7 +117,7 @@ public class ChannelsInitializer { |
*/ |
public static class Channel { |
@ChannelId |
- final String mId; |
+ public final String mId; |
final int mNameResId; |
final int mImportance; |
@ChannelGroupId |