Bug 921776 - Forced notifications to keep the same timestamp to preserve the order they are displayed in; fixed current notification mechanism in notification handler to update correctly the current foreground notification; r=wesj
authorFederico Paolinelli <fedepaol@gmail.com>
Mon, 14 Oct 2013 13:38:57 -0700
changeset 164547 76251cfbba5bcdca495f60dbcd9a5eac574c43af
parent 164546 4ab2e3a7d4ff207b99049ada316471e3521832ec
child 164548 8c2d93bcb585fb7ccdfca3373315f4524d36f2f4
push id3066
push userakeybl@mozilla.com
push dateMon, 09 Dec 2013 19:58:46 +0000
treeherdermozilla-beta@a31a0dce83aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswesj
bugs921776
milestone27.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 921776 - Forced notifications to keep the same timestamp to preserve the order they are displayed in; fixed current notification mechanism in notification handler to update correctly the current foreground notification; r=wesj
mobile/android/base/NotificationHandler.java
mobile/android/chrome/content/downloads.js
--- a/mobile/android/base/NotificationHandler.java
+++ b/mobile/android/base/NotificationHandler.java
@@ -28,16 +28,17 @@ public class NotificationHandler {
      * {@link android.app.Service#startForeground(int, android.app.Notification)}
      * associates the foreground with exactly one notification from the service.
      * To keep Fennec alive during downloads (and to make sure it can be killed
      * once downloads are complete), we make sure that the foreground is always
      * associated with an active progress notification if and only if at least
      * one download is in progress.
      */
     private Notification mForegroundNotification;
+    private int mForegroundNotificationId;
 
     public NotificationHandler(Context context) {
         mContext = context;
         mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
     }
 
     /**
      * Adds a notification.
@@ -163,28 +164,31 @@ public class NotificationHandler {
     private boolean isProgressStyle(Notification notification) {
         if (notification != null && notification instanceof AlertNotification) {
             return ((AlertNotification)notification).isProgressStyle();
         }
         return false;
     }
 
     protected void setForegroundNotification(int id, Notification notification) {
+        mForegroundNotificationId = id;
         mForegroundNotification = notification;
     }
 
-    private void updateForegroundNotification(int id, Notification oldNotification) {
-        if (mForegroundNotification == oldNotification) {
+    private void updateForegroundNotification(int oldId, Notification oldNotification) {
+        if (mForegroundNotificationId == oldId) {
             // If we're removing the notification associated with the
             // foreground, we need to pick another active notification to act
             // as the foreground notification.
             Notification foregroundNotification = null;
-            for (final Notification notification : mNotifications.values()) {
+            int foregroundId = 0;
+            for (final Integer id : mNotifications.keySet()) {
+                final Notification notification = mNotifications.get(id);
                 if (isOngoing(notification)) {
                     foregroundNotification = notification;
+                    foregroundId = id;
                     break;
                 }
             }
-
-            setForegroundNotification(id, foregroundNotification);
+            setForegroundNotification(foregroundId, foregroundNotification);
         }
     }
 }
--- a/mobile/android/chrome/content/downloads.js
+++ b/mobile/android/chrome/content/downloads.js
@@ -90,17 +90,18 @@ var Downloads = {
   showNotification: function dl_showNotification(aDownload, aMessage, aTitle, aOptions) {
     let msg = {
         type: "Notification:Show",
         id: this.getNotificationIdFromDownload(aDownload),
         title: aTitle,
         smallIcon: URI_GENERIC_ICON_DOWNLOAD,
         text: aMessage,
         ongoing: false,
-        cookie: aDownload.guid
+        cookie: aDownload.guid,
+        when: aDownload.startTime
     };
 
     if (aOptions && aOptions.icon) {
       msg.smallIcon = aOptions.icon;
     }
 
     if (aOptions && aOptions.percentComplete) {
       msg.progress_value = aOptions.percentComplete;