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

Commit 28c0cec7 authored by Jeff DeCew's avatar Jeff DeCew Committed by Android (Google) Code Review
Browse files

Merge "Only match identical userIDs for autogroup summaries" into udc-dev

parents 5c6bd9f6 ebf3375a
Loading
Loading
Loading
Loading
+20 −15
Original line number Diff line number Diff line
@@ -9522,7 +9522,11 @@ 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) {
    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
@@ -9531,6 +9535,7 @@ public class NotificationManagerService extends SystemService {
                        // an exact user match
                        || r.getUserId() == userId;
        }
    }
    /**
     * Determine whether the userId applies to the notification in question, either because
@@ -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)) {
+51 −1
Original line number Diff line number Diff line
@@ -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);
    }
@@ -10794,6 +10799,51 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        assertThat(mService.getNotificationRecordCount()).isEqualTo(0);
    }
    @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(