Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 34d237f0 authored by Jeff DeCew's avatar Jeff DeCew
Browse files

Prioritize high importance system notifications

System notifications with IMPORTANCE_HIGH shall appear before non-system alerting notifications.

Test: atest NotificationComparatorTest
Fixes: 216662581
Change-Id: Ic129fd51f6c7427d7d1fcae51515b8f6947742ef
parent feb567fa
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -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;
+9 −0
Original line number Diff line number Diff line
@@ -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);