Loading services/core/java/com/android/server/notification/NotificationComparator.java +7 −14 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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); Loading Loading @@ -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; } Loading @@ -133,7 +128,6 @@ public class NotificationComparator if (record.getImportance() < NotificationManager.IMPORTANCE_LOW) { return false; } // TODO: add whitelist return isCall(record) || isMediaNotification(record); } Loading @@ -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; } Loading services/tests/notification/src/com/android/server/notification/NotificationComparatorTest.java +12 −0 Original line number Diff line number Diff line Loading @@ -75,6 +75,7 @@ public class NotificationComparatorTest { private NotificationRecord mRecordContact; private NotificationRecord mRecordUrgent; private NotificationRecord mRecordCheater; private NotificationRecord mRecordCheaterColorized; @Before Loading Loading @@ -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(); Loading @@ -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 Loading @@ -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<>(); Loading Loading
services/core/java/com/android/server/notification/NotificationComparator.java +7 −14 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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); Loading Loading @@ -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; } Loading @@ -133,7 +128,6 @@ public class NotificationComparator if (record.getImportance() < NotificationManager.IMPORTANCE_LOW) { return false; } // TODO: add whitelist return isCall(record) || isMediaNotification(record); } Loading @@ -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; } Loading
services/tests/notification/src/com/android/server/notification/NotificationComparatorTest.java +12 −0 Original line number Diff line number Diff line Loading @@ -75,6 +75,7 @@ public class NotificationComparatorTest { private NotificationRecord mRecordContact; private NotificationRecord mRecordUrgent; private NotificationRecord mRecordCheater; private NotificationRecord mRecordCheaterColorized; @Before Loading Loading @@ -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(); Loading @@ -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 Loading @@ -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<>(); Loading