diff --git a/services/core/java/com/android/server/notification/NotificationComparator.java b/services/core/java/com/android/server/notification/NotificationComparator.java index 583cdd599780c..647a89efcbbf6 100644 --- a/services/core/java/com/android/server/notification/NotificationComparator.java +++ b/services/core/java/com/android/server/notification/NotificationComparator.java @@ -104,6 +104,12 @@ public class NotificationComparator return -1 * Boolean.compare(leftPeople, rightPeople); } + boolean leftSystemMax = isSystemMax(left); + boolean rightSystemMax = isSystemMax(right); + if (leftSystemMax != rightSystemMax) { + return -1 * Boolean.compare(leftSystemMax, rightSystemMax); + } + if (leftImportance != rightImportance) { // by importance, high to low return -1 * Integer.compare(leftImportance, rightImportance); @@ -173,6 +179,20 @@ public class NotificationComparator return mMessagingUtil.isImportantMessaging(record.getSbn(), record.getImportance()); } + protected boolean isSystemMax(NotificationRecord record) { + if (record.getImportance() < NotificationManager.IMPORTANCE_HIGH) { + return false; + } + String packageName = record.getSbn().getPackageName(); + if ("android".equals(packageName)) { + return true; + } + if ("com.android.systemui".equals(packageName)) { + return true; + } + return false; + } + private boolean isOngoing(NotificationRecord record) { final int ongoingFlags = Notification.FLAG_FOREGROUND_SERVICE; return (record.getNotification().flags & ongoingFlags) != 0; diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationComparatorTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationComparatorTest.java index 5eed30be92795..91d4f8f63f38b 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationComparatorTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationComparatorTest.java @@ -67,6 +67,7 @@ public class NotificationComparatorTest extends UiServiceTestCase { @Mock Vibrator mVibrator; private final String callPkg = "com.android.server.notification"; + private final String sysPkg = "android"; private final int callUid = 10; private String smsPkg; private final int smsUid = 11; @@ -79,6 +80,7 @@ public class NotificationComparatorTest extends UiServiceTestCase { private NotificationRecord mRecordHighCall; private NotificationRecord mRecordHighCallStyle; private NotificationRecord mRecordEmail; + private NotificationRecord mRecordSystemMax; private NotificationRecord mRecordInlineReply; private NotificationRecord mRecordSms; private NotificationRecord mRecordStarredContact; @@ -191,6 +193,12 @@ public class NotificationComparatorTest extends UiServiceTestCase { mRecordContact.setContactAffinity(ValidateNotificationPeople.VALID_CONTACT); mRecordContact.setSystemImportance(NotificationManager.IMPORTANCE_DEFAULT); + Notification nSystemMax = new Notification.Builder(mContext, TEST_CHANNEL_ID).build(); + mRecordSystemMax = new NotificationRecord(mContext, new StatusBarNotification(sysPkg, + sysPkg, 1, "systemmax", uid2, uid2, nSystemMax, new UserHandle(userId), + "", 1244), getDefaultChannel()); + mRecordSystemMax.setSystemImportance(NotificationManager.IMPORTANCE_HIGH); + Notification n8 = new Notification.Builder(mContext, TEST_CHANNEL_ID).build(); mRecordUrgent = new NotificationRecord(mContext, new StatusBarNotification(pkg2, pkg2, 1, "urgent", uid2, uid2, n8, new UserHandle(userId), @@ -267,6 +275,7 @@ public class NotificationComparatorTest extends UiServiceTestCase { } expected.add(mRecordStarredContact); expected.add(mRecordContact); + expected.add(mRecordSystemMax); expected.add(mRecordEmail); expected.add(mRecordUrgent); expected.add(mNoMediaSessionMedia);