Loading services/core/java/com/android/server/notification/NotificationManagerService.java +2 −4 Original line number Diff line number Diff line Loading @@ -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(), Loading Loading @@ -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()) { Loading services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +46 −0 Original line number Diff line number Diff line Loading @@ -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 { Loading Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +2 −4 Original line number Diff line number Diff line Loading @@ -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(), Loading Loading @@ -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()) { Loading
services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +46 −0 Original line number Diff line number Diff line Loading @@ -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 { Loading