Loading packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/DeviceProvisionedCoordinator.java +3 −5 Original line number Diff line number Diff line Loading @@ -71,11 +71,9 @@ public class DeviceProvisionedCoordinator implements Coordinator { * marking them as relevant for setup are allowed to show when device is unprovisioned */ private boolean showNotificationEvenIfUnprovisioned(StatusBarNotification sbn) { final boolean hasPermission = checkUidPermission( Manifest.permission.NOTIFICATION_DURING_SETUP, sbn.getUid()) == PackageManager.PERMISSION_GRANTED; return hasPermission && sbn.getNotification().extras.getBoolean(Notification.EXTRA_ALLOW_DURING_SETUP); // system_server checks the permission so systemui can just check whether the // extra exists return sbn.getNotification().extras.getBoolean(Notification.EXTRA_ALLOW_DURING_SETUP); } private int checkUidPermission(String permission, int uid) { Loading packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/coordinator/DeviceProvisionedCoordinatorTest.java +1 −10 Original line number Diff line number Diff line Loading @@ -117,10 +117,6 @@ public class DeviceProvisionedCoordinatorTest extends SysuiTestCase { extras.putBoolean(SHOW_WHEN_UNPROVISIONED_FLAG, true); mNotification.extras = extras; // GIVEN notification has the permission to display during setup when(mIPackageManager.checkUidPermission(SETUP_NOTIF_PERMISSION, NOTIF_UID)) .thenReturn(PackageManager.PERMISSION_GRANTED); // THEN don't filter out the notification assertFalse(mDeviceProvisionedFilter.shouldFilterOut(mEntry, 0)); } Loading @@ -130,15 +126,10 @@ public class DeviceProvisionedCoordinatorTest extends SysuiTestCase { // GIVEN device is unprovisioned when(mDeviceProvisionedController.isDeviceProvisioned()).thenReturn(false); // GIVEN notification has a flag to allow the notification during setup // GIVEN notification does not have the flag to allow the notification during setup Bundle extras = new Bundle(); extras.putBoolean(SHOW_WHEN_UNPROVISIONED_FLAG, true); mNotification.extras = extras; // GIVEN notification does NOT have permission to display during setup when(mIPackageManager.checkUidPermission(SETUP_NOTIF_PERMISSION, NOTIF_UID)) .thenReturn(PackageManager.PERMISSION_DENIED); // THEN filter out the notification assertTrue(mDeviceProvisionedFilter.shouldFilterOut(mEntry, 0)); } Loading services/core/java/com/android/server/notification/NotificationManagerService.java +25 −10 Original line number Diff line number Diff line Loading @@ -6516,7 +6516,7 @@ public class NotificationManagerService extends SystemService { // Fix the notification as best we can. try { fixNotification(notification, pkg, tag, id, userId); fixNotification(notification, pkg, tag, id, userId, notificationUid); } catch (Exception e) { if (notification.isForegroundService()) { throw new SecurityException("Invalid FGS notification", e); Loading Loading @@ -6694,7 +6694,8 @@ public class NotificationManagerService extends SystemService { @VisibleForTesting protected void fixNotification(Notification notification, String pkg, String tag, int id, int userId) throws NameNotFoundException, RemoteException { @UserIdInt int userId, int notificationUid) throws NameNotFoundException, RemoteException { final ApplicationInfo ai = mPackageManagerClient.getApplicationInfoAsUser( pkg, PackageManager.MATCH_DEBUG_TRIAGED_MISSING, (userId == UserHandle.USER_ALL) ? USER_SYSTEM : userId); Loading @@ -6710,17 +6711,31 @@ public class NotificationManagerService extends SystemService { } } int canColorize = mPackageManagerClient.checkPermission( android.Manifest.permission.USE_COLORIZED_NOTIFICATIONS, pkg); int canColorize = getContext().checkPermission( android.Manifest.permission.USE_COLORIZED_NOTIFICATIONS, -1, notificationUid); if (canColorize == PERMISSION_GRANTED) { notification.flags |= Notification.FLAG_CAN_COLORIZE; } else { notification.flags &= ~Notification.FLAG_CAN_COLORIZE; } if (notification.extras.getBoolean(Notification.EXTRA_ALLOW_DURING_SETUP, false)) { int hasShowDuringSetupPerm = getContext().checkPermission( android.Manifest.permission.NOTIFICATION_DURING_SETUP, -1, notificationUid); if (hasShowDuringSetupPerm != PERMISSION_GRANTED) { notification.extras.remove(Notification.EXTRA_ALLOW_DURING_SETUP); if (DBG) { Slog.w(TAG, "warning: pkg " + pkg + " attempting to show during setup" + " without holding perm " + Manifest.permission.NOTIFICATION_DURING_SETUP); } } } if (notification.fullScreenIntent != null && ai.targetSdkVersion >= Build.VERSION_CODES.Q) { int fullscreenIntentPermission = mPackageManagerClient.checkPermission( android.Manifest.permission.USE_FULL_SCREEN_INTENT, pkg); int fullscreenIntentPermission = getContext().checkPermission( android.Manifest.permission.USE_FULL_SCREEN_INTENT, -1, notificationUid); if (fullscreenIntentPermission != PERMISSION_GRANTED) { notification.fullScreenIntent = null; Slog.w(TAG, "Package " + pkg + Loading Loading @@ -6765,8 +6780,8 @@ public class NotificationManagerService extends SystemService { // Ensure MediaStyle has correct permissions for remote device extras if (notification.isStyle(Notification.MediaStyle.class)) { int hasMediaContentControlPermission = mPackageManager.checkPermission( android.Manifest.permission.MEDIA_CONTENT_CONTROL, pkg, userId); int hasMediaContentControlPermission = getContext().checkPermission( android.Manifest.permission.MEDIA_CONTENT_CONTROL, -1, notificationUid); if (hasMediaContentControlPermission != PERMISSION_GRANTED) { notification.extras.remove(Notification.EXTRA_MEDIA_REMOTE_DEVICE); notification.extras.remove(Notification.EXTRA_MEDIA_REMOTE_ICON); Loading @@ -6780,8 +6795,8 @@ public class NotificationManagerService extends SystemService { // Ensure only allowed packages have a substitute app name if (notification.extras.containsKey(Notification.EXTRA_SUBSTITUTE_APP_NAME)) { int hasSubstituteAppNamePermission = mPackageManager.checkPermission( permission.SUBSTITUTE_NOTIFICATION_APP_NAME, pkg, userId); int hasSubstituteAppNamePermission = getContext().checkPermission( permission.SUBSTITUTE_NOTIFICATION_APP_NAME, -1, notificationUid); if (hasSubstituteAppNamePermission != PERMISSION_GRANTED) { notification.extras.remove(Notification.EXTRA_SUBSTITUTE_APP_NAME); if (DBG) { Loading services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +54 −26 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.server.notification; import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND; import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE; import static android.app.ActivityTaskManager.INVALID_TASK_ID; import static android.app.Notification.EXTRA_ALLOW_DURING_SETUP; import static android.app.Notification.FLAG_AUTO_CANCEL; import static android.app.Notification.FLAG_BUBBLE; import static android.app.Notification.FLAG_CAN_COLORIZE; Loading Loading @@ -1594,6 +1595,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test public void testEnqueueNotificationWithTag_FgsAddsFlags_dismissalAllowed() throws Exception { mContext.getTestablePermissions().setPermission( android.Manifest.permission.USE_COLORIZED_NOTIFICATIONS, PERMISSION_GRANTED); DeviceConfig.setProperty( DeviceConfig.NAMESPACE_SYSTEMUI, SystemUiDeviceConfigFlags.TASK_MANAGER_ENABLED, Loading Loading @@ -1622,6 +1625,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test public void testEnqueueNotificationWithTag_FGSaddsFlags_dismissalNotAllowed() throws Exception { mContext.getTestablePermissions().setPermission( android.Manifest.permission.USE_COLORIZED_NOTIFICATIONS, PERMISSION_GRANTED); DeviceConfig.setProperty( DeviceConfig.NAMESPACE_SYSTEMUI, SystemUiDeviceConfigFlags.TASK_MANAGER_ENABLED, Loading Loading @@ -4210,9 +4215,36 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { verify(mGroupHelper, never()).onNotificationPosted(any(), anyBoolean()); } @Test public void testNoNotificationDuringSetupPermission() throws Exception { mContext.getTestablePermissions().setPermission( android.Manifest.permission.NOTIFICATION_DURING_SETUP, PERMISSION_GRANTED); Bundle extras = new Bundle(); extras.putBoolean(EXTRA_ALLOW_DURING_SETUP, true); Notification.Builder nb = new Notification.Builder(mContext, mTestNotificationChannel.getId()) .setContentTitle("foo") .addExtras(extras) .setSmallIcon(android.R.drawable.sym_def_app_icon); StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 1, "testNoNotificationDuringSetupPermission", mUid, 0, nb.build(), UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord nr = new NotificationRecord(mContext, sbn, mTestNotificationChannel); mBinderService.enqueueNotificationWithTag(PKG, PKG, sbn.getTag(), nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId()); waitForIdle(); NotificationRecord posted = mService.findNotificationLocked( PKG, nr.getSbn().getTag(), nr.getSbn().getId(), nr.getSbn().getUserId()); assertTrue(posted.getNotification().extras.containsKey(EXTRA_ALLOW_DURING_SETUP)); } @Test public void testNoFakeColorizedPermission() throws Exception { when(mPackageManagerClient.checkPermission(any(), any())).thenReturn(PERMISSION_DENIED); mContext.getTestablePermissions().setPermission( android.Manifest.permission.USE_COLORIZED_NOTIFICATIONS, PERMISSION_DENIED); Notification.Builder nb = new Notification.Builder(mContext, mTestNotificationChannel.getId()) .setContentTitle("foo") Loading @@ -4237,9 +4269,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test public void testMediaStyleRemote_hasPermission() throws RemoteException { String deviceName = "device"; when(mPackageManager.checkPermission( eq(android.Manifest.permission.MEDIA_CONTENT_CONTROL), any(), anyInt())) .thenReturn(PERMISSION_GRANTED); mContext.getTestablePermissions().setPermission( android.Manifest.permission.MEDIA_CONTENT_CONTROL, PERMISSION_GRANTED); Notification.MediaStyle style = new Notification.MediaStyle(); style.setRemotePlaybackInfo(deviceName, 0, null); Notification.Builder nb = new Notification.Builder(mContext, Loading @@ -4266,9 +4297,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test public void testMediaStyleRemote_noPermission() throws RemoteException { String deviceName = "device"; when(mPackageManager.checkPermission( eq(android.Manifest.permission.MEDIA_CONTENT_CONTROL), any(), anyInt())) .thenReturn(PERMISSION_DENIED); mContext.getTestablePermissions().setPermission( android.Manifest.permission.MEDIA_CONTENT_CONTROL, PERMISSION_DENIED); Notification.MediaStyle style = new Notification.MediaStyle(); style.setRemotePlaybackInfo(deviceName, 0, null); Notification.Builder nb = new Notification.Builder(mContext, Loading @@ -4294,9 +4324,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test public void testSubstituteAppName_hasPermission() throws RemoteException { String subName = "Substitute Name"; when(mPackageManager.checkPermission( eq(android.Manifest.permission.SUBSTITUTE_NOTIFICATION_APP_NAME), any(), anyInt())) .thenReturn(PERMISSION_GRANTED); mContext.getTestablePermissions().setPermission( android.Manifest.permission.SUBSTITUTE_NOTIFICATION_APP_NAME, PERMISSION_GRANTED); Bundle extras = new Bundle(); extras.putString(Notification.EXTRA_SUBSTITUTE_APP_NAME, subName); Notification.Builder nb = new Notification.Builder(mContext, Loading @@ -4321,9 +4350,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test public void testSubstituteAppName_noPermission() throws RemoteException { when(mPackageManager.checkPermission( eq(android.Manifest.permission.SUBSTITUTE_NOTIFICATION_APP_NAME), any(), anyInt())) .thenReturn(PERMISSION_DENIED); mContext.getTestablePermissions().setPermission( android.Manifest.permission.SUBSTITUTE_NOTIFICATION_APP_NAME, PERMISSION_DENIED); Bundle extras = new Bundle(); extras.putString(Notification.EXTRA_SUBSTITUTE_APP_NAME, "Substitute Name"); Notification.Builder nb = new Notification.Builder(mContext, Loading Loading @@ -8290,7 +8318,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { assertNotNull(n.publicVersion.bigContentView); assertNotNull(n.publicVersion.headsUpContentView); mService.fixNotification(n, PKG, "tag", 9, 0); mService.fixNotification(n, PKG, "tag", 9, 0, mUid); assertNull(n.contentView); assertNull(n.bigContentView); Loading Loading @@ -10104,7 +10132,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .thenReturn(systemAppInfo); // When: fix the notification with NotificationManagerService mService.fixNotification(n, PKG, "tag", 9, 0); mService.fixNotification(n, PKG, "tag", 9, 0, mUid); // Then: the notification's flag FLAG_NO_DISMISS should be set assertNotSame(0, n.flags & Notification.FLAG_NO_DISMISS); Loading @@ -10126,7 +10154,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .build(); // When: fix the notification with NotificationManagerService mService.fixNotification(n, PKG, "tag", 9, 0); mService.fixNotification(n, PKG, "tag", 9, 0, mUid); // Then: the notification's flag FLAG_NO_DISMISS should be set assertNotSame(0, n.flags & Notification.FLAG_NO_DISMISS); Loading @@ -10145,7 +10173,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .build(); // When: fix the notification with NotificationManagerService mService.fixNotification(n, PKG, "tag", 9, 0); mService.fixNotification(n, PKG, "tag", 9, 0, mUid); // Then: the notification's flag FLAG_NO_DISMISS should not be set assertEquals(0, n.flags & Notification.FLAG_NO_DISMISS); Loading @@ -10166,7 +10194,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { n.flags |= Notification.FLAG_NO_DISMISS; // When: fix the notification with NotificationManagerService mService.fixNotification(n, PKG, "tag", 9, 0); mService.fixNotification(n, PKG, "tag", 9, 0, mUid); // Then: the notification's flag FLAG_NO_DISMISS should be cleared assertEquals(0, n.flags & Notification.FLAG_NO_DISMISS); Loading @@ -10191,7 +10219,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .thenReturn(systemAppInfo); // When: fix the notification with NotificationManagerService mService.fixNotification(n, PKG, "tag", 9, 0); mService.fixNotification(n, PKG, "tag", 9, 0, mUid); // Then: the notification's flag FLAG_NO_DISMISS should not be set assertEquals(0, n.flags & Notification.FLAG_NO_DISMISS); Loading @@ -10218,7 +10246,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .thenReturn(systemAppInfo); // When: fix the notification with NotificationManagerService mService.fixNotification(n, PKG, "tag", 9, 0); mService.fixNotification(n, PKG, "tag", 9, 0, mUid); // Then: the notification's flag FLAG_NO_DISMISS should be cleared assertEquals(0, n.flags & Notification.FLAG_NO_DISMISS); Loading @@ -10239,7 +10267,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .build(); // When: fix the notification with NotificationManagerService mService.fixNotification(n, PKG, "tag", 9, 0); mService.fixNotification(n, PKG, "tag", 9, 0, mUid); // Then: the notification's flag FLAG_NO_DISMISS should not be set assertEquals(0, n.flags & Notification.FLAG_NO_DISMISS); Loading @@ -10263,7 +10291,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { n.flags |= Notification.FLAG_NO_DISMISS; // When: fix the notification with NotificationManagerService mService.fixNotification(n, PKG, "tag", 9, 0); mService.fixNotification(n, PKG, "tag", 9, 0, mUid); // Then: the notification's flag FLAG_NO_DISMISS should be cleared assertEquals(0, n.flags & Notification.FLAG_NO_DISMISS); Loading @@ -10284,7 +10312,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .build(); // When: fix the notification with NotificationManagerService mService.fixNotification(n, PKG, "tag", 9, 0); mService.fixNotification(n, PKG, "tag", 9, 0, mUid); // Then: the notification's flag FLAG_NO_DISMISS should not be set assertEquals(0, n.flags & Notification.FLAG_NO_DISMISS); Loading @@ -10306,7 +10334,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .build(); // When: fix the notification with NotificationManagerService mService.fixNotification(n, PKG, "tag", 9, 0); mService.fixNotification(n, PKG, "tag", 9, 0, mUid); // Then: the notification's flag FLAG_NO_DISMISS should be set assertNotSame(0, n.flags & Notification.FLAG_NO_DISMISS); Loading @@ -10330,7 +10358,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .build(); // When: fix the notification with NotificationManagerService mService.fixNotification(n, PKG, "tag", 9, 0); mService.fixNotification(n, PKG, "tag", 9, 0, mUid); // Then: the notification's flag FLAG_NO_DISMISS should be set assertNotSame(0, n.flags & Notification.FLAG_NO_DISMISS); Loading @@ -10355,7 +10383,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .build(); // When: fix the notification with NotificationManagerService mService.fixNotification(n, PKG, "tag", 9, 0); mService.fixNotification(n, PKG, "tag", 9, 0, mUid); // Then: the notification's flag FLAG_NO_DISMISS should not be set assertEquals(0, n.flags & Notification.FLAG_NO_DISMISS); Loading services/tests/uiservicestests/src/com/android/server/notification/RoleObserverTest.java +0 −1 Original line number Diff line number Diff line Loading @@ -48,7 +48,6 @@ import android.companion.ICompanionDeviceManager; import android.content.Context; import android.content.pm.IPackageManager; import android.content.pm.PackageManager; import android.content.pm.PackageManagerInternal; import android.os.Looper; import android.os.UserHandle; import android.os.UserManager; Loading Loading
packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/DeviceProvisionedCoordinator.java +3 −5 Original line number Diff line number Diff line Loading @@ -71,11 +71,9 @@ public class DeviceProvisionedCoordinator implements Coordinator { * marking them as relevant for setup are allowed to show when device is unprovisioned */ private boolean showNotificationEvenIfUnprovisioned(StatusBarNotification sbn) { final boolean hasPermission = checkUidPermission( Manifest.permission.NOTIFICATION_DURING_SETUP, sbn.getUid()) == PackageManager.PERMISSION_GRANTED; return hasPermission && sbn.getNotification().extras.getBoolean(Notification.EXTRA_ALLOW_DURING_SETUP); // system_server checks the permission so systemui can just check whether the // extra exists return sbn.getNotification().extras.getBoolean(Notification.EXTRA_ALLOW_DURING_SETUP); } private int checkUidPermission(String permission, int uid) { Loading
packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/coordinator/DeviceProvisionedCoordinatorTest.java +1 −10 Original line number Diff line number Diff line Loading @@ -117,10 +117,6 @@ public class DeviceProvisionedCoordinatorTest extends SysuiTestCase { extras.putBoolean(SHOW_WHEN_UNPROVISIONED_FLAG, true); mNotification.extras = extras; // GIVEN notification has the permission to display during setup when(mIPackageManager.checkUidPermission(SETUP_NOTIF_PERMISSION, NOTIF_UID)) .thenReturn(PackageManager.PERMISSION_GRANTED); // THEN don't filter out the notification assertFalse(mDeviceProvisionedFilter.shouldFilterOut(mEntry, 0)); } Loading @@ -130,15 +126,10 @@ public class DeviceProvisionedCoordinatorTest extends SysuiTestCase { // GIVEN device is unprovisioned when(mDeviceProvisionedController.isDeviceProvisioned()).thenReturn(false); // GIVEN notification has a flag to allow the notification during setup // GIVEN notification does not have the flag to allow the notification during setup Bundle extras = new Bundle(); extras.putBoolean(SHOW_WHEN_UNPROVISIONED_FLAG, true); mNotification.extras = extras; // GIVEN notification does NOT have permission to display during setup when(mIPackageManager.checkUidPermission(SETUP_NOTIF_PERMISSION, NOTIF_UID)) .thenReturn(PackageManager.PERMISSION_DENIED); // THEN filter out the notification assertTrue(mDeviceProvisionedFilter.shouldFilterOut(mEntry, 0)); } Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +25 −10 Original line number Diff line number Diff line Loading @@ -6516,7 +6516,7 @@ public class NotificationManagerService extends SystemService { // Fix the notification as best we can. try { fixNotification(notification, pkg, tag, id, userId); fixNotification(notification, pkg, tag, id, userId, notificationUid); } catch (Exception e) { if (notification.isForegroundService()) { throw new SecurityException("Invalid FGS notification", e); Loading Loading @@ -6694,7 +6694,8 @@ public class NotificationManagerService extends SystemService { @VisibleForTesting protected void fixNotification(Notification notification, String pkg, String tag, int id, int userId) throws NameNotFoundException, RemoteException { @UserIdInt int userId, int notificationUid) throws NameNotFoundException, RemoteException { final ApplicationInfo ai = mPackageManagerClient.getApplicationInfoAsUser( pkg, PackageManager.MATCH_DEBUG_TRIAGED_MISSING, (userId == UserHandle.USER_ALL) ? USER_SYSTEM : userId); Loading @@ -6710,17 +6711,31 @@ public class NotificationManagerService extends SystemService { } } int canColorize = mPackageManagerClient.checkPermission( android.Manifest.permission.USE_COLORIZED_NOTIFICATIONS, pkg); int canColorize = getContext().checkPermission( android.Manifest.permission.USE_COLORIZED_NOTIFICATIONS, -1, notificationUid); if (canColorize == PERMISSION_GRANTED) { notification.flags |= Notification.FLAG_CAN_COLORIZE; } else { notification.flags &= ~Notification.FLAG_CAN_COLORIZE; } if (notification.extras.getBoolean(Notification.EXTRA_ALLOW_DURING_SETUP, false)) { int hasShowDuringSetupPerm = getContext().checkPermission( android.Manifest.permission.NOTIFICATION_DURING_SETUP, -1, notificationUid); if (hasShowDuringSetupPerm != PERMISSION_GRANTED) { notification.extras.remove(Notification.EXTRA_ALLOW_DURING_SETUP); if (DBG) { Slog.w(TAG, "warning: pkg " + pkg + " attempting to show during setup" + " without holding perm " + Manifest.permission.NOTIFICATION_DURING_SETUP); } } } if (notification.fullScreenIntent != null && ai.targetSdkVersion >= Build.VERSION_CODES.Q) { int fullscreenIntentPermission = mPackageManagerClient.checkPermission( android.Manifest.permission.USE_FULL_SCREEN_INTENT, pkg); int fullscreenIntentPermission = getContext().checkPermission( android.Manifest.permission.USE_FULL_SCREEN_INTENT, -1, notificationUid); if (fullscreenIntentPermission != PERMISSION_GRANTED) { notification.fullScreenIntent = null; Slog.w(TAG, "Package " + pkg + Loading Loading @@ -6765,8 +6780,8 @@ public class NotificationManagerService extends SystemService { // Ensure MediaStyle has correct permissions for remote device extras if (notification.isStyle(Notification.MediaStyle.class)) { int hasMediaContentControlPermission = mPackageManager.checkPermission( android.Manifest.permission.MEDIA_CONTENT_CONTROL, pkg, userId); int hasMediaContentControlPermission = getContext().checkPermission( android.Manifest.permission.MEDIA_CONTENT_CONTROL, -1, notificationUid); if (hasMediaContentControlPermission != PERMISSION_GRANTED) { notification.extras.remove(Notification.EXTRA_MEDIA_REMOTE_DEVICE); notification.extras.remove(Notification.EXTRA_MEDIA_REMOTE_ICON); Loading @@ -6780,8 +6795,8 @@ public class NotificationManagerService extends SystemService { // Ensure only allowed packages have a substitute app name if (notification.extras.containsKey(Notification.EXTRA_SUBSTITUTE_APP_NAME)) { int hasSubstituteAppNamePermission = mPackageManager.checkPermission( permission.SUBSTITUTE_NOTIFICATION_APP_NAME, pkg, userId); int hasSubstituteAppNamePermission = getContext().checkPermission( permission.SUBSTITUTE_NOTIFICATION_APP_NAME, -1, notificationUid); if (hasSubstituteAppNamePermission != PERMISSION_GRANTED) { notification.extras.remove(Notification.EXTRA_SUBSTITUTE_APP_NAME); if (DBG) { Loading
services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +54 −26 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.server.notification; import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND; import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE; import static android.app.ActivityTaskManager.INVALID_TASK_ID; import static android.app.Notification.EXTRA_ALLOW_DURING_SETUP; import static android.app.Notification.FLAG_AUTO_CANCEL; import static android.app.Notification.FLAG_BUBBLE; import static android.app.Notification.FLAG_CAN_COLORIZE; Loading Loading @@ -1594,6 +1595,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test public void testEnqueueNotificationWithTag_FgsAddsFlags_dismissalAllowed() throws Exception { mContext.getTestablePermissions().setPermission( android.Manifest.permission.USE_COLORIZED_NOTIFICATIONS, PERMISSION_GRANTED); DeviceConfig.setProperty( DeviceConfig.NAMESPACE_SYSTEMUI, SystemUiDeviceConfigFlags.TASK_MANAGER_ENABLED, Loading Loading @@ -1622,6 +1625,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test public void testEnqueueNotificationWithTag_FGSaddsFlags_dismissalNotAllowed() throws Exception { mContext.getTestablePermissions().setPermission( android.Manifest.permission.USE_COLORIZED_NOTIFICATIONS, PERMISSION_GRANTED); DeviceConfig.setProperty( DeviceConfig.NAMESPACE_SYSTEMUI, SystemUiDeviceConfigFlags.TASK_MANAGER_ENABLED, Loading Loading @@ -4210,9 +4215,36 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { verify(mGroupHelper, never()).onNotificationPosted(any(), anyBoolean()); } @Test public void testNoNotificationDuringSetupPermission() throws Exception { mContext.getTestablePermissions().setPermission( android.Manifest.permission.NOTIFICATION_DURING_SETUP, PERMISSION_GRANTED); Bundle extras = new Bundle(); extras.putBoolean(EXTRA_ALLOW_DURING_SETUP, true); Notification.Builder nb = new Notification.Builder(mContext, mTestNotificationChannel.getId()) .setContentTitle("foo") .addExtras(extras) .setSmallIcon(android.R.drawable.sym_def_app_icon); StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 1, "testNoNotificationDuringSetupPermission", mUid, 0, nb.build(), UserHandle.getUserHandleForUid(mUid), null, 0); NotificationRecord nr = new NotificationRecord(mContext, sbn, mTestNotificationChannel); mBinderService.enqueueNotificationWithTag(PKG, PKG, sbn.getTag(), nr.getSbn().getId(), nr.getSbn().getNotification(), nr.getSbn().getUserId()); waitForIdle(); NotificationRecord posted = mService.findNotificationLocked( PKG, nr.getSbn().getTag(), nr.getSbn().getId(), nr.getSbn().getUserId()); assertTrue(posted.getNotification().extras.containsKey(EXTRA_ALLOW_DURING_SETUP)); } @Test public void testNoFakeColorizedPermission() throws Exception { when(mPackageManagerClient.checkPermission(any(), any())).thenReturn(PERMISSION_DENIED); mContext.getTestablePermissions().setPermission( android.Manifest.permission.USE_COLORIZED_NOTIFICATIONS, PERMISSION_DENIED); Notification.Builder nb = new Notification.Builder(mContext, mTestNotificationChannel.getId()) .setContentTitle("foo") Loading @@ -4237,9 +4269,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test public void testMediaStyleRemote_hasPermission() throws RemoteException { String deviceName = "device"; when(mPackageManager.checkPermission( eq(android.Manifest.permission.MEDIA_CONTENT_CONTROL), any(), anyInt())) .thenReturn(PERMISSION_GRANTED); mContext.getTestablePermissions().setPermission( android.Manifest.permission.MEDIA_CONTENT_CONTROL, PERMISSION_GRANTED); Notification.MediaStyle style = new Notification.MediaStyle(); style.setRemotePlaybackInfo(deviceName, 0, null); Notification.Builder nb = new Notification.Builder(mContext, Loading @@ -4266,9 +4297,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test public void testMediaStyleRemote_noPermission() throws RemoteException { String deviceName = "device"; when(mPackageManager.checkPermission( eq(android.Manifest.permission.MEDIA_CONTENT_CONTROL), any(), anyInt())) .thenReturn(PERMISSION_DENIED); mContext.getTestablePermissions().setPermission( android.Manifest.permission.MEDIA_CONTENT_CONTROL, PERMISSION_DENIED); Notification.MediaStyle style = new Notification.MediaStyle(); style.setRemotePlaybackInfo(deviceName, 0, null); Notification.Builder nb = new Notification.Builder(mContext, Loading @@ -4294,9 +4324,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test public void testSubstituteAppName_hasPermission() throws RemoteException { String subName = "Substitute Name"; when(mPackageManager.checkPermission( eq(android.Manifest.permission.SUBSTITUTE_NOTIFICATION_APP_NAME), any(), anyInt())) .thenReturn(PERMISSION_GRANTED); mContext.getTestablePermissions().setPermission( android.Manifest.permission.SUBSTITUTE_NOTIFICATION_APP_NAME, PERMISSION_GRANTED); Bundle extras = new Bundle(); extras.putString(Notification.EXTRA_SUBSTITUTE_APP_NAME, subName); Notification.Builder nb = new Notification.Builder(mContext, Loading @@ -4321,9 +4350,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { @Test public void testSubstituteAppName_noPermission() throws RemoteException { when(mPackageManager.checkPermission( eq(android.Manifest.permission.SUBSTITUTE_NOTIFICATION_APP_NAME), any(), anyInt())) .thenReturn(PERMISSION_DENIED); mContext.getTestablePermissions().setPermission( android.Manifest.permission.SUBSTITUTE_NOTIFICATION_APP_NAME, PERMISSION_DENIED); Bundle extras = new Bundle(); extras.putString(Notification.EXTRA_SUBSTITUTE_APP_NAME, "Substitute Name"); Notification.Builder nb = new Notification.Builder(mContext, Loading Loading @@ -8290,7 +8318,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { assertNotNull(n.publicVersion.bigContentView); assertNotNull(n.publicVersion.headsUpContentView); mService.fixNotification(n, PKG, "tag", 9, 0); mService.fixNotification(n, PKG, "tag", 9, 0, mUid); assertNull(n.contentView); assertNull(n.bigContentView); Loading Loading @@ -10104,7 +10132,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .thenReturn(systemAppInfo); // When: fix the notification with NotificationManagerService mService.fixNotification(n, PKG, "tag", 9, 0); mService.fixNotification(n, PKG, "tag", 9, 0, mUid); // Then: the notification's flag FLAG_NO_DISMISS should be set assertNotSame(0, n.flags & Notification.FLAG_NO_DISMISS); Loading @@ -10126,7 +10154,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .build(); // When: fix the notification with NotificationManagerService mService.fixNotification(n, PKG, "tag", 9, 0); mService.fixNotification(n, PKG, "tag", 9, 0, mUid); // Then: the notification's flag FLAG_NO_DISMISS should be set assertNotSame(0, n.flags & Notification.FLAG_NO_DISMISS); Loading @@ -10145,7 +10173,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .build(); // When: fix the notification with NotificationManagerService mService.fixNotification(n, PKG, "tag", 9, 0); mService.fixNotification(n, PKG, "tag", 9, 0, mUid); // Then: the notification's flag FLAG_NO_DISMISS should not be set assertEquals(0, n.flags & Notification.FLAG_NO_DISMISS); Loading @@ -10166,7 +10194,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { n.flags |= Notification.FLAG_NO_DISMISS; // When: fix the notification with NotificationManagerService mService.fixNotification(n, PKG, "tag", 9, 0); mService.fixNotification(n, PKG, "tag", 9, 0, mUid); // Then: the notification's flag FLAG_NO_DISMISS should be cleared assertEquals(0, n.flags & Notification.FLAG_NO_DISMISS); Loading @@ -10191,7 +10219,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .thenReturn(systemAppInfo); // When: fix the notification with NotificationManagerService mService.fixNotification(n, PKG, "tag", 9, 0); mService.fixNotification(n, PKG, "tag", 9, 0, mUid); // Then: the notification's flag FLAG_NO_DISMISS should not be set assertEquals(0, n.flags & Notification.FLAG_NO_DISMISS); Loading @@ -10218,7 +10246,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .thenReturn(systemAppInfo); // When: fix the notification with NotificationManagerService mService.fixNotification(n, PKG, "tag", 9, 0); mService.fixNotification(n, PKG, "tag", 9, 0, mUid); // Then: the notification's flag FLAG_NO_DISMISS should be cleared assertEquals(0, n.flags & Notification.FLAG_NO_DISMISS); Loading @@ -10239,7 +10267,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .build(); // When: fix the notification with NotificationManagerService mService.fixNotification(n, PKG, "tag", 9, 0); mService.fixNotification(n, PKG, "tag", 9, 0, mUid); // Then: the notification's flag FLAG_NO_DISMISS should not be set assertEquals(0, n.flags & Notification.FLAG_NO_DISMISS); Loading @@ -10263,7 +10291,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { n.flags |= Notification.FLAG_NO_DISMISS; // When: fix the notification with NotificationManagerService mService.fixNotification(n, PKG, "tag", 9, 0); mService.fixNotification(n, PKG, "tag", 9, 0, mUid); // Then: the notification's flag FLAG_NO_DISMISS should be cleared assertEquals(0, n.flags & Notification.FLAG_NO_DISMISS); Loading @@ -10284,7 +10312,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .build(); // When: fix the notification with NotificationManagerService mService.fixNotification(n, PKG, "tag", 9, 0); mService.fixNotification(n, PKG, "tag", 9, 0, mUid); // Then: the notification's flag FLAG_NO_DISMISS should not be set assertEquals(0, n.flags & Notification.FLAG_NO_DISMISS); Loading @@ -10306,7 +10334,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .build(); // When: fix the notification with NotificationManagerService mService.fixNotification(n, PKG, "tag", 9, 0); mService.fixNotification(n, PKG, "tag", 9, 0, mUid); // Then: the notification's flag FLAG_NO_DISMISS should be set assertNotSame(0, n.flags & Notification.FLAG_NO_DISMISS); Loading @@ -10330,7 +10358,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .build(); // When: fix the notification with NotificationManagerService mService.fixNotification(n, PKG, "tag", 9, 0); mService.fixNotification(n, PKG, "tag", 9, 0, mUid); // Then: the notification's flag FLAG_NO_DISMISS should be set assertNotSame(0, n.flags & Notification.FLAG_NO_DISMISS); Loading @@ -10355,7 +10383,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { .build(); // When: fix the notification with NotificationManagerService mService.fixNotification(n, PKG, "tag", 9, 0); mService.fixNotification(n, PKG, "tag", 9, 0, mUid); // Then: the notification's flag FLAG_NO_DISMISS should not be set assertEquals(0, n.flags & Notification.FLAG_NO_DISMISS); Loading
services/tests/uiservicestests/src/com/android/server/notification/RoleObserverTest.java +0 −1 Original line number Diff line number Diff line Loading @@ -48,7 +48,6 @@ import android.companion.ICompanionDeviceManager; import android.content.Context; import android.content.pm.IPackageManager; import android.content.pm.PackageManager; import android.content.pm.PackageManagerInternal; import android.os.Looper; import android.os.UserHandle; import android.os.UserManager; Loading