OSDN Git Service

Only foreground notis should be sorted higher
authorJulia Reynolds <juliacr@google.com>
Wed, 12 Apr 2017 16:27:00 +0000 (12:27 -0400)
committerJulia Reynolds <juliacr@google.com>
Thu, 13 Apr 2017 15:03:57 +0000 (11:03 -0400)
Having the ongoing flag is not enough.

Test: runtest systemui-notification
Change-Id: I8a6c15af819f2bb4ad3937ae45d33361663fbe13

services/core/java/com/android/server/notification/NotificationComparator.java
services/tests/notification/src/com/android/server/notification/NotificationComparatorTest.java

index d6c89a4..63647ff 100644 (file)
@@ -21,15 +21,7 @@ import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
-import android.database.ContentObserver;
-import android.net.Uri;
-import android.os.Handler;
-import android.os.Looper;
-import android.os.UserHandle;
-import android.provider.Settings;
 import android.telecom.TelecomManager;
-import android.text.TextUtils;
-import android.util.ArrayMap;
 
 import com.android.internal.util.NotificationMessagingUtil;
 
@@ -56,8 +48,8 @@ public class NotificationComparator
     @Override
     public int compare(NotificationRecord left, NotificationRecord right) {
         // first all colorized notifications
-        boolean leftImportantColorized = isImportantColorized(left);
-        boolean rightImportantColorized = isImportantColorized(right);
+        boolean leftImportantColorized = isImportantOngoingColorized(left);
+        boolean rightImportantColorized = isImportantOngoingColorized(right);
 
         if (leftImportantColorized != rightImportantColorized) {
             return -1 * Boolean.compare(leftImportantColorized, rightImportantColorized);
@@ -118,7 +110,10 @@ public class NotificationComparator
         return -1 * Long.compare(left.getRankingTimeMs(), right.getRankingTimeMs());
     }
 
-    private boolean isImportantColorized(NotificationRecord record) {
+    private boolean isImportantOngoingColorized(NotificationRecord record) {
+        if (!isOngoing(record)) {
+            return false;
+        }
         if (record.getImportance() < NotificationManager.IMPORTANCE_LOW) {
             return false;
         }
@@ -133,7 +128,6 @@ public class NotificationComparator
         if (record.getImportance() < NotificationManager.IMPORTANCE_LOW) {
             return false;
         }
-        // TODO: add whitelist
 
         return isCall(record) || isMediaNotification(record);
     }
@@ -153,8 +147,7 @@ public class NotificationComparator
     }
 
     private boolean isOngoing(NotificationRecord record) {
-        final int ongoingFlags =
-                Notification.FLAG_FOREGROUND_SERVICE | Notification.FLAG_ONGOING_EVENT;
+        final int ongoingFlags = Notification.FLAG_FOREGROUND_SERVICE;
         return (record.getNotification().flags & ongoingFlags) != 0;
     }
 
index 176342b..84945ab 100644 (file)
@@ -75,6 +75,7 @@ public class NotificationComparatorTest {
     private NotificationRecord mRecordContact;
     private NotificationRecord mRecordUrgent;
     private NotificationRecord mRecordCheater;
+    private NotificationRecord mRecordCheaterColorized;
 
 
     @Before
@@ -174,6 +175,7 @@ public class NotificationComparatorTest {
                 pkg2, 1, "cheater", uid2, uid2, n9, new UserHandle(userId),
                 "", 9258), getDefaultChannel());
         mRecordCheater.setUserImportance(NotificationManager.IMPORTANCE_LOW);
+        mRecordCheater.setPackagePriority(Notification.PRIORITY_MAX);
 
         Notification n10 = new Notification.Builder(mContext, TEST_CHANNEL_ID)
                 .setStyle(new Notification.InboxStyle().setSummaryText("message!")).build();
@@ -181,6 +183,15 @@ public class NotificationComparatorTest {
                 pkg2, 1, "email", uid2, uid2, n10, new UserHandle(userId),
                 "", 1599), getDefaultChannel());
         mRecordEmail.setUserImportance(NotificationManager.IMPORTANCE_HIGH);
+
+        Notification n11 = new Notification.Builder(mContext, TEST_CHANNEL_ID)
+                .setCategory(Notification.CATEGORY_MESSAGE)
+                .setColorized(true)
+                .build();
+        mRecordCheaterColorized = new NotificationRecord(mContext, new StatusBarNotification(pkg2,
+                pkg2, 1, "cheater", uid2, uid2, n11, new UserHandle(userId),
+                "", 9258), getDefaultChannel());
+        mRecordCheaterColorized.setUserImportance(NotificationManager.IMPORTANCE_LOW);
     }
 
     @Test
@@ -195,6 +206,7 @@ public class NotificationComparatorTest {
         expected.add(mRecordEmail);
         expected.add(mRecordUrgent);
         expected.add(mRecordCheater);
+        expected.add(mRecordCheaterColorized);
         expected.add(mRecordMinCall);
 
         List<NotificationRecord> actual = new ArrayList<>();