Bug 1488174 - Use UpdateServiceHelper to decide on whether to add Updater notification channel. r=jchen
authorJan Henning <jh+bugzilla@buttercookie.de>
Wed, 05 Sep 2018 19:07:50 +0000
changeset 435002 b9e56df24edc03611d26e9b0944ef4b88b4f7fc8
parent 435001 4b3b3a1db0dfbffe3e08e8d1e4f660fabf584ac4
child 435003 8db4f905ae7af3cc59ff0832b4bac21edb810f09
push id107530
push userapavel@mozilla.com
push dateThu, 06 Sep 2018 04:44:27 +0000
treeherdermozilla-inbound@5f5d7a3ce332 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjchen
bugs1488174
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1488174 - Use UpdateServiceHelper to decide on whether to add Updater notification channel. r=jchen That way, we only add that notification channel if the updater really is active, i.e. not if we've been installed from the Play Store. Unfortunately, using the UpdateServiceHelper requires a Context, so adding/re- moving the UPDATER_CHANNEL_TAG cannot be done during variable initialisation. Differential Revision: https://phabricator.services.mozilla.com/D4890
mobile/android/base/java/org/mozilla/gecko/notifications/NotificationHelper.java
--- a/mobile/android/base/java/org/mozilla/gecko/notifications/NotificationHelper.java
+++ b/mobile/android/base/java/org/mozilla/gecko/notifications/NotificationHelper.java
@@ -23,16 +23,17 @@ import android.support.v4.util.SimpleArr
 import android.util.Log;
 
 import org.mozilla.gecko.AppConstants;
 import org.mozilla.gecko.EventDispatcher;
 import org.mozilla.gecko.GeckoActivityMonitor;
 import org.mozilla.gecko.GeckoAppShell;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.mozglue.SafeIntent;
+import org.mozilla.gecko.updater.UpdateServiceHelper;
 import org.mozilla.gecko.util.BitmapUtils;
 import org.mozilla.gecko.util.BundleEventListener;
 import org.mozilla.gecko.util.EventCallback;
 import org.mozilla.gecko.util.GeckoBundle;
 import org.mozilla.gecko.util.ThreadUtils;
 
 import java.io.File;
 import java.io.UnsupportedEncodingException;
@@ -113,17 +114,20 @@ public final class NotificationHelper im
         /**
          * Leanplum notification channel - use only when <code>AppConstants.MOZ_ANDROID_MMA</code> is true.
          */
         LP_DEFAULT,
     }
 
     // Holds the mapping between the Channel enum used by the rest of our codebase and the
     // channel ID used for communication with the system NotificationManager.
-    private final Map<Channel, String> mDefinedNotificationChannels = new HashMap<Channel, String>(7) {{
+    // How to determine the initialCapacity: Count all channels (including the Updater, which is
+    // only added further down in initNotificationChannels), multiply by 4/3 for a maximum load
+    // factor of 75 % and round up to the next multiple of two.
+    private final Map<Channel, String> mDefinedNotificationChannels = new HashMap<Channel, String>(16) {{
         final String DEFAULT_CHANNEL_TAG = "default2-notification-channel";
         put(Channel.DEFAULT, DEFAULT_CHANNEL_TAG);
 
         final String MLS_CHANNEL_TAG = "mls-notification-channel";
         put(Channel.MLS, MLS_CHANNEL_TAG);
 
         final String DOWNLOAD_NOTIFICATION_TAG = "download-notification-channel";
         put(Channel.DOWNLOAD, DOWNLOAD_NOTIFICATION_TAG);
@@ -131,21 +135,16 @@ public final class NotificationHelper im
         final String MEDIA_CHANNEL_TAG = "media-notification-channel";
         put(Channel.MEDIA, MEDIA_CHANNEL_TAG);
 
         if (AppConstants.MOZ_ANDROID_MMA) {
             final String LP_DEFAULT_CHANNEL_TAG = "lp-default-notification-channel";
             put(Channel.LP_DEFAULT, LP_DEFAULT_CHANNEL_TAG);
         }
 
-        if (AppConstants.MOZ_UPDATER) {
-            final String UPDATER_CHANNEL_TAG = "updater-notification-channel";
-            put(Channel.UPDATER, UPDATER_CHANNEL_TAG);
-        }
-
         final String SYNCED_TABS_CHANNEL_TAG = "synced-tabs-notification-channel";
         put(Channel.SYNCED_TABS, SYNCED_TABS_CHANNEL_TAG);
     }};
 
     // These are channels we no longer require and want to retire from Android's settings UI.
     private final List<String> mDeprecatedNotificationChannels = Arrays.asList(
             "default-notification-channel",
             null
@@ -187,16 +186,23 @@ public final class NotificationHelper im
 
         if (sInstance == null) {
             sInstance = new NotificationHelper(context.getApplicationContext());
         }
         return sInstance;
     }
 
     private void initNotificationChannels() {
+        final String UPDATER_CHANNEL_TAG = "updater-notification-channel";
+        if (UpdateServiceHelper.isUpdaterEnabled(mContext)) {
+            mDefinedNotificationChannels.put(Channel.UPDATER, UPDATER_CHANNEL_TAG);
+        } else {
+            mDeprecatedNotificationChannels.add(UPDATER_CHANNEL_TAG);
+        }
+
         final NotificationManager notificationManager =
                 (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
 
         for (String channelId : mDeprecatedNotificationChannels) {
             removeChannel(notificationManager, channelId);
         }
 
         for (Channel mozChannel : mDefinedNotificationChannels.keySet()) {