Merge "Simply ignore invalid keys" into sc-qpr1-dev

This commit is contained in:
Julia Reynolds
2021-08-13 20:26:18 +00:00
committed by Android (Google) Code Review
2 changed files with 48 additions and 4 deletions

View File

@@ -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()) {

View File

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