diff options
| author | 2023-12-21 15:38:49 +0000 | |
|---|---|---|
| committer | 2023-12-21 15:38:49 +0000 | |
| commit | 28c0cec7c4329ac8b27ec72c9f52ae4e542dda9c (patch) | |
| tree | 867fedea7601537a114ca89122d9a1f767cbc12e | |
| parent | 5c6bd9f6c1f7907be08a8a37beab35b5daa8ecf4 (diff) | |
| parent | ebf3375aac3560fa76cf13a57bc1027beb3db190 (diff) | |
Merge "Only match identical userIDs for autogroup summaries" into udc-dev
2 files changed, 71 insertions, 16 deletions
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index 647087de1c04..2e29941ee43b 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -9522,14 +9522,19 @@ public class NotificationManagerService extends SystemService { * Determine whether the userId applies to the notification in question, either because * they match exactly, or one of them is USER_ALL (which is treated as a wildcard). */ - private boolean notificationMatchesUserId(NotificationRecord r, int userId) { - return + private static boolean notificationMatchesUserId(NotificationRecord r, int userId, + boolean isAutogroupSummary) { + if (isAutogroupSummary) { + return r.getUserId() == userId; + } else { + return // looking for USER_ALL notifications? match everything - userId == UserHandle.USER_ALL - // a notification sent to USER_ALL matches any query - || r.getUserId() == UserHandle.USER_ALL - // an exact user match - || r.getUserId() == userId; + userId == UserHandle.USER_ALL + // a notification sent to USER_ALL matches any query + || r.getUserId() == UserHandle.USER_ALL + // an exact user match + || r.getUserId() == userId; + } } /** @@ -9538,7 +9543,7 @@ public class NotificationManagerService extends SystemService { * because it matches one of the users profiles. */ private boolean notificationMatchesCurrentProfiles(NotificationRecord r, int userId) { - return notificationMatchesUserId(r, userId) + return notificationMatchesUserId(r, userId, false) || mUserProfiles.isCurrentProfile(r.getUserId()); } @@ -9607,7 +9612,7 @@ public class NotificationManagerService extends SystemService { if (!notificationMatchesCurrentProfiles(r, userId)) { continue; } - } else if (!notificationMatchesUserId(r, userId)) { + } else if (!notificationMatchesUserId(r, userId, false)) { continue; } // Don't remove notifications to all, if there's no package name specified @@ -9845,7 +9850,7 @@ public class NotificationManagerService extends SystemService { final int len = list.size(); for (int i = 0; i < len; i++) { NotificationRecord r = list.get(i); - if (notificationMatchesUserId(r, userId) && r.getGroupKey().equals(groupKey) + if (notificationMatchesUserId(r, userId, false) && r.getGroupKey().equals(groupKey) && r.getSbn().getPackageName().equals(pkg)) { records.add(r); } @@ -9887,8 +9892,8 @@ public class NotificationManagerService extends SystemService { final int len = list.size(); for (int i = 0; i < len; i++) { NotificationRecord r = list.get(i); - if (notificationMatchesUserId(r, userId) && r.getSbn().getId() == id && - TextUtils.equals(r.getSbn().getTag(), tag) + if (notificationMatchesUserId(r, userId, (r.getFlags() & GroupHelper.BASE_FLAGS) != 0) + && r.getSbn().getId() == id && TextUtils.equals(r.getSbn().getTag(), tag) && r.getSbn().getPackageName().equals(pkg)) { return r; } @@ -9903,8 +9908,8 @@ public class NotificationManagerService extends SystemService { final int len = list.size(); for (int i = 0; i < len; i++) { NotificationRecord r = list.get(i); - if (notificationMatchesUserId(r, userId) && r.getSbn().getId() == id && - TextUtils.equals(r.getSbn().getTag(), tag) + if (notificationMatchesUserId(r, userId, false) && r.getSbn().getId() == id + && TextUtils.equals(r.getSbn().getTag(), tag) && r.getSbn().getPackageName().equals(pkg)) { matching.add(r); } @@ -9937,7 +9942,7 @@ public class NotificationManagerService extends SystemService { final int n = mEnqueuedNotifications.size(); for (int i = 0; i < n; i++) { NotificationRecord r = mEnqueuedNotifications.get(i); - if (notificationMatchesUserId(r, userId) + if (notificationMatchesUserId(r, userId, false) && r.getSbn().getId() == id && TextUtils.equals(r.getSbn().getTag(), tag) && r.getSbn().getPackageName().equals(pkg)) { diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java index 86d2b2fc6b56..620e362c86b8 100755 --- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java @@ -865,13 +865,18 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { } private NotificationRecord generateNotificationRecord(NotificationChannel channel, int userId) { + return generateNotificationRecord(channel, 1, userId); + } + + private NotificationRecord generateNotificationRecord(NotificationChannel channel, int id, + int userId) { if (channel == null) { channel = mTestNotificationChannel; } Notification.Builder nb = new Notification.Builder(mContext, channel.getId()) .setContentTitle("foo") .setSmallIcon(android.R.drawable.sym_def_app_icon); - StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 1, "tag", mUid, 0, + StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, id, "tag", mUid, 0, nb.build(), new UserHandle(userId), null, 0); return new NotificationRecord(mContext, sbn, channel); } @@ -10795,6 +10800,51 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { } @Test + public void testUngroupingAutoSummary_differentUsers() throws Exception { + NotificationRecord nr0 = + generateNotificationRecord(mTestNotificationChannel, 0, USER_SYSTEM); + NotificationRecord nr1 = + generateNotificationRecord(mTestNotificationChannel, 1, USER_SYSTEM); + + // add notifications + summary for USER_SYSTEM + mService.addNotification(nr0); + mService.addNotification(nr1); + mService.addNotification(mService.createAutoGroupSummary(nr1.getUserId(), + nr1.getSbn().getPackageName(), nr1.getKey(), GroupHelper.BASE_FLAGS)); + + // add notifications + summary for USER_ALL + NotificationRecord nr0_all = + generateNotificationRecord(mTestNotificationChannel, 2, UserHandle.USER_ALL); + NotificationRecord nr1_all = + generateNotificationRecord(mTestNotificationChannel, 3, UserHandle.USER_ALL); + + mService.addNotification(nr0_all); + mService.addNotification(nr1_all); + mService.addNotification(mService.createAutoGroupSummary(nr0_all.getUserId(), + nr0_all.getSbn().getPackageName(), nr0_all.getKey(), GroupHelper.BASE_FLAGS)); + + // cancel both children for USER_ALL + mBinderService.cancelNotificationWithTag(PKG, PKG, nr0_all.getSbn().getTag(), + nr0_all.getSbn().getId(), UserHandle.USER_ALL); + mBinderService.cancelNotificationWithTag(PKG, PKG, nr1_all.getSbn().getTag(), + nr1_all.getSbn().getId(), UserHandle.USER_ALL); + waitForIdle(); + + // group helper would send 'remove summary' event + mService.clearAutogroupSummaryLocked(UserHandle.USER_ALL, + nr0_all.getSbn().getPackageName()); + waitForIdle(); + + // make sure the right summary was removed + assertThat(mService.getNotificationCount(nr0_all.getSbn().getPackageName(), + UserHandle.USER_ALL, 0, null)).isEqualTo(0); + + // the USER_SYSTEM notifications + summary were not removed + assertThat(mService.getNotificationCount(nr0.getSbn().getPackageName(), + USER_SYSTEM, 0, null)).isEqualTo(3); + } + + @Test public void testStrongAuthTracker_isInLockDownMode() { mStrongAuthTracker.setGetStrongAuthForUserReturnValue( STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN); |