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

Commit caaa85d3 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Prioritize high importance system notifications"

parents 3380e190 34d237f0
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);