Index: chrome/android/java/src/org/chromium/chrome/browser/notifications/ChannelsUpdater.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/notifications/ChannelsUpdater.java b/chrome/android/java/src/org/chromium/chrome/browser/notifications/ChannelsUpdater.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ffce9d24fab527f995e994818660434f66f64205 |
--- /dev/null |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/notifications/ChannelsUpdater.java |
@@ -0,0 +1,49 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+package org.chromium.chrome.browser.notifications; |
+ |
+import android.annotation.SuppressLint; |
+import android.app.NotificationManager; |
+import android.content.Context; |
+ |
+import org.chromium.base.BuildInfo; |
+import org.chromium.base.ContextUtils; |
+ |
+/** |
+ * Contains helper methods for checking if we should update channels and updating them if so. |
+ */ |
+public class ChannelsUpdater { |
+ private static final String CHANNELS_VERSION_KEY = "channels_version_key"; |
+ /** |
+ * Version number identifying the current set of channels. This should be incremented whenever |
nyquist
2017/04/10 21:04:30
s/should/must/
awdf
2017/04/11 14:19:21
Done.
|
+ * any channels are added or removed from the set of channels created in |
+ * {@link ChannelsInitializer#initializeStartupChannels()} |
+ */ |
+ private static final int CHANNELS_VERSION = 1; |
awdf
2017/04/11 14:19:21
I usually count from 0, set to 1 from manual testi
|
+ |
+ public static boolean shouldUpdateChannels() { |
+ return BuildInfo.isAtLeastO() |
+ && ContextUtils.getAppSharedPreferences().getInt(CHANNELS_VERSION_KEY, -1) |
+ != CHANNELS_VERSION; |
+ } |
+ |
+ @SuppressLint("NewApi") // For Context.getSystemService(Class) |
+ public static void updateChannels(Context context) { |
nyquist
2017/04/10 21:04:30
This seems to be an important part of our future l
awdf
2017/04/11 14:19:21
The only method that is really testable here is up
awdf
2017/04/11 16:37:03
On second thoughts, if I just inject the Notificat
|
+ assert BuildInfo.isAtLeastO(); |
+ ChannelsInitializer channelsInitializer = |
+ new ChannelsInitializer(new NotificationManagerProxyImpl( |
+ context.getSystemService(NotificationManager.class))); |
+ channelsInitializer.deleteAllChannels(); |
+ channelsInitializer.initializeStartupChannels(); |
+ storeChannelVersionInPrefs(); |
+ } |
+ |
+ private static void storeChannelVersionInPrefs() { |
+ ContextUtils.getAppSharedPreferences() |
+ .edit() |
+ .putInt(CHANNELS_VERSION_KEY, CHANNELS_VERSION) |
+ .apply(); |
+ } |
+} |