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

Commit f9d5c8a0 authored by Julia Reynolds's avatar Julia Reynolds Committed by Automerger Merge Worker
Browse files

Merge "Simply ignore invalid keys" into sc-qpr1-dev am: 362b31f1

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15531685

Change-Id: Ifbd3b1294729ba94dc052fa41b2e8c4634f51eaf
parents ca0b9290 362b31f1
Loading
Loading
Loading
Loading
+2 −4
Original line number Diff line number Diff line
@@ -4363,8 +4363,7 @@ public class NotificationManagerService extends SystemService {
                            final int userId = r.getSbn().getUserId();
                            if (userId != info.userid && userId != UserHandle.USER_ALL &&
                                    !mUserProfiles.isCurrentProfile(userId)) {
                                throw new SecurityException("Disallowed call from listener: "
                                        + info.service);
                                continue;
                            }
                            cancelNotificationFromListenerLocked(info, callingUid, callingPid,
                                    r.getSbn().getPackageName(), r.getSbn().getTag(),
@@ -4431,8 +4430,7 @@ public class NotificationManagerService extends SystemService {
                        final int userId = r.getSbn().getUserId();
                        if (userId != info.userid && userId != UserHandle.USER_ALL
                                && !mUserProfiles.isCurrentProfile(userId)) {
                            throw new SecurityException("Disallowed call from listener: "
                                    + info.service);
                            continue;
                        }
                        seen.add(r);
                        if (!r.isSeen()) {
+46 −0
Original line number Diff line number Diff line
@@ -4792,6 +4792,52 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        verify(mAppUsageStats).reportInterruptiveNotification(anyString(), anyString(), anyInt());
    }

    @Test
    public void testSetNotificationsShownFromListener_protectsCrossUserInformation()
            throws RemoteException {
        Notification.Builder nb = new Notification.Builder(
                mContext, mTestNotificationChannel.getId())
                .setContentTitle("foo")
                .setSmallIcon(android.R.drawable.sym_def_app_icon);
        StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 1,
                "tag" + System.currentTimeMillis(),  UserHandle.PER_USER_RANGE, 0,
                nb.build(), UserHandle.getUserHandleForUid(mUid + UserHandle.PER_USER_RANGE),
                null, 0);
        final NotificationRecord r =
                new NotificationRecord(mContext, sbn, mTestNotificationChannel);
        r.setTextChanged(true);
        mService.addNotification(r);

        // no security exception!
        mBinderService.setNotificationsShownFromListener(null, new String[] {r.getKey()});

        verify(mAppUsageStats, never()).reportInterruptiveNotification(
                anyString(), anyString(), anyInt());
    }

    @Test
    public void testCancelNotificationsFromListener_protectsCrossUserInformation()
            throws RemoteException {
        Notification.Builder nb = new Notification.Builder(
                mContext, mTestNotificationChannel.getId())
                .setContentTitle("foo")
                .setSmallIcon(android.R.drawable.sym_def_app_icon);
        StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 1,
                "tag" + System.currentTimeMillis(),  UserHandle.PER_USER_RANGE, 0,
                nb.build(), UserHandle.getUserHandleForUid(mUid + UserHandle.PER_USER_RANGE),
                null, 0);
        final NotificationRecord r =
                new NotificationRecord(mContext, sbn, mTestNotificationChannel);
        r.setTextChanged(true);
        mService.addNotification(r);

        // no security exception!
        mBinderService.cancelNotificationsFromListener(null, new String[] {r.getKey()});

        waitForIdle();
        assertEquals(1, mService.getNotificationRecordCount());
    }

    @Test
    public void testMaybeRecordInterruptionLocked_doesNotRecordTwice()
            throws RemoteException {