Merge "Prioritize high importance system notifications"

This commit is contained in:
TreeHugger Robot
2022-01-28 21:15:03 +00:00
committed by Android (Google) Code Review
2 changed files with 29 additions and 0 deletions

View File

@@ -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;

View File

@@ -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);