Bug 1358598 - Show ongoing notifications even if they're not the "official" foreground notification. r=jchen a=jcristau
authorJan Henning <jh+bugzilla@buttercookie.de>
Sun, 11 Mar 2018 20:01:33 +0100
changeset 462608 e51c4126451301e3ffb577640b1544480997afeb
parent 462607 1d1b5770dffd4c5873915624bc1f3c0e6ebccfe0
child 462609 d30ae32ee90e7488d9cd72e7f79dcaf4d8d98737
push id1683
push usersfraser@mozilla.com
push dateThu, 26 Apr 2018 16:43:40 +0000
treeherdermozilla-release@5af6cb21869d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjchen, jcristau
bugs1358598
milestone60.0
Bug 1358598 - Show ongoing notifications even if they're not the "official" foreground notification. r=jchen a=jcristau We can have only one "official" foreground notification that's associated with the NotificationService to keep the OS from background-killing us at the same time, but that doesn't mean that we should simply ignore any further ongoing notifications possibly arriving afterwards. MozReview-Commit-ID: L8rigs6GKzH
mobile/android/base/java/org/mozilla/gecko/notifications/NotificationClient.java
--- a/mobile/android/base/java/org/mozilla/gecko/notifications/NotificationClient.java
+++ b/mobile/android/base/java/org/mozilla/gecko/notifications/NotificationClient.java
@@ -177,17 +177,17 @@ public final class NotificationClient im
      * @param notification   the Notification to add
      */
     public synchronized void add(final String name, final Notification notification) {
         final boolean ongoing = isOngoing(notification);
 
         if (ongoing != isOngoing(mNotifications.get(name))) {
             // In order to change notification from ongoing to non-ongoing, or vice versa,
             // we have to remove the previous notification, because ongoing notifications
-            // use a different id value than non-ongoing notifications.
+            // might use a different id value than non-ongoing notifications.
             onNotificationClose(name);
         }
 
         mNotifications.put(name, notification);
 
         if (!ongoing) {
             mNotificationManager.notify(name, 0, notification);
             return;
@@ -195,16 +195,18 @@ public final class NotificationClient im
 
         // Ongoing
         if (mForegroundNotification == null) {
             setForegroundNotificationLocked(name, notification);
         } else if (mForegroundNotification.equals(name)) {
             // Shortcut to update the current foreground notification, instead of
             // going through the service.
             mNotificationManager.notify(R.id.foregroundNotification, notification);
+        } else {
+            mNotificationManager.notify(name, 0, notification);
         }
     }
 
     /**
      * Updates a notification.
      *
      * @param name          Name of existing notification
      * @param progress      progress of item being updated
@@ -312,16 +314,20 @@ public final class NotificationClient im
         }
 
         // If we're removing the notification associated with the
         // foreground, we need to pick another active notification to act
         // as the foreground notification.
         for (final String name : mNotifications.keySet()) {
             final Notification notification = mNotifications.get(name);
             if (isOngoing(notification)) {
+                // The same reasoning as above applies - the current foreground notification
+                // uses a special ID, so we need to close its old instantiation and then
+                // re-add it with the new ID through the NotificationService.
+                onNotificationClose(name);
                 setForegroundNotificationLocked(name, notification);
                 return;
             }
         }
 
         setForegroundNotificationLocked(null, null);
     }
 }