Loading services/core/java/com/android/server/notification/NotificationManagerService.java +12 −4 Original line number Diff line number Diff line Loading @@ -3741,9 +3741,9 @@ public class NotificationManagerService extends SystemService { } private void maybeNotifyChannelGroupOwner(String pkg, int uid, NotificationChannelGroup preUpdate, NotificationChannelGroup update) { @Nullable NotificationChannelGroup preUpdate, NotificationChannelGroup update) { try { if (preUpdate.isBlocked() != update.isBlocked()) { if (preUpdate != null && preUpdate.isBlocked() != update.isBlocked()) { getContext().sendBroadcastAsUser( new Intent(ACTION_NOTIFICATION_CHANNEL_GROUP_BLOCK_STATE_CHANGED) .putExtra(NotificationManager.EXTRA_NOTIFICATION_CHANNEL_GROUP_ID, Loading Loading @@ -7398,8 +7398,16 @@ public class NotificationManagerService extends SystemService { NotificationChannelGroup group) throws RemoteException { Objects.requireNonNull(user); verifyPrivilegedListener(token, user, false); createNotificationChannelGroup( pkg, getUidForPackageAndUser(pkg, user), group, false, true); int packageUid = getUidForPackageAndUser(pkg, user); if (packageUid == INVALID_UID) { return; } NotificationChannelGroup previous = mPreferencesHelper.getNotificationChannelGroup( group.getId(), pkg, packageUid); if (previous == null) { return; } createNotificationChannelGroup(pkg, packageUid, group, false, true); handleSavePolicyFile(); } Loading services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +60 −0 Original line number Diff line number Diff line Loading @@ -691,6 +691,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { // MockPackageManager - default returns ApplicationInfo with matching calling UID mContext.setMockPackageManager(mPackageManagerClient); when(mPackageManager.getPackageUid(mPkg, 0, mUserId)).thenReturn(mUid); when(mPackageManager.getApplicationInfo(anyString(), anyLong(), anyInt())) .thenAnswer((Answer<ApplicationInfo>) invocation -> { Object[] args = invocation.getArguments(); Loading Loading @@ -5615,6 +5616,65 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { anyInt()); } @Test public void updateNotificationChannelGroupFromPrivilegedListener_cdm_success() throws Exception { NotificationChannelGroup createByApp = new NotificationChannelGroup("grp", "Group"); mService.mPreferencesHelper.createNotificationChannelGroup(mPkg, mUid, createByApp, true, mUid, false); NotificationChannelGroup updateByNls = new NotificationChannelGroup("grp", "Updated"); when(mCompanionMgr.getAssociations(mPkg, mUserId)) .thenReturn(singletonList(mock(AssociationInfo.class))); mBinderService.updateNotificationChannelGroupFromPrivilegedListener( null, mPkg, mUser, updateByNls); NotificationChannelGroup result = mService.mPreferencesHelper.getNotificationChannelGroup( "grp", mPkg, mUid); assertThat(result.getName().toString()).isEqualTo("Updated"); } @Test public void updateNotificationChannelGroupFromPrivilegedListener_noCdm_throws() throws Exception { when(mCompanionMgr.getAssociations(mPkg, mUserId)).thenReturn(Lists.newArrayList()); NotificationChannelGroup updateByNls = new NotificationChannelGroup("grp", "Updated"); SecurityException exception = assertThrows(SecurityException.class, () -> mBinderService.updateNotificationChannelGroupFromPrivilegedListener( null, mPkg, mUser, updateByNls)); assertThat(exception).hasMessageThat().contains("does not have access"); } @Test public void updateNotificationChannelGroupFromPrivilegedListener_wrongPackage_ignored() throws Exception { NotificationChannelGroup updateByNls = new NotificationChannelGroup("grp", "Updated"); when(mCompanionMgr.getAssociations(mPkg, mUserId)) .thenReturn(singletonList(mock(AssociationInfo.class))); mBinderService.updateNotificationChannelGroupFromPrivilegedListener( null, "com.package.does.not.exist", mUser, updateByNls); verify(mService.mPreferencesHelper, never()).createNotificationChannelGroup(any(), anyInt(), any(), anyBoolean(), anyInt(), anyBoolean()); } @Test public void updateNotificationChannelGroupFromPrivilegedListener_notAnUpdate_ignored() throws Exception { NotificationChannelGroup createByNls = new NotificationChannelGroup("grp", "New"); when(mCompanionMgr.getAssociations(mPkg, mUserId)) .thenReturn(singletonList(mock(AssociationInfo.class))); mBinderService.updateNotificationChannelGroupFromPrivilegedListener( null, mPkg, mUser, createByNls); verify(mService.mPreferencesHelper, never()).createNotificationChannelGroup(any(), anyInt(), any(), anyBoolean(), anyInt(), anyBoolean()); } @Test public void testGetPackagesWithChannels_blocked() throws Exception { // While we mostly rely on the PreferencesHelper implementation of channels, we filter in Loading Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +12 −4 Original line number Diff line number Diff line Loading @@ -3741,9 +3741,9 @@ public class NotificationManagerService extends SystemService { } private void maybeNotifyChannelGroupOwner(String pkg, int uid, NotificationChannelGroup preUpdate, NotificationChannelGroup update) { @Nullable NotificationChannelGroup preUpdate, NotificationChannelGroup update) { try { if (preUpdate.isBlocked() != update.isBlocked()) { if (preUpdate != null && preUpdate.isBlocked() != update.isBlocked()) { getContext().sendBroadcastAsUser( new Intent(ACTION_NOTIFICATION_CHANNEL_GROUP_BLOCK_STATE_CHANGED) .putExtra(NotificationManager.EXTRA_NOTIFICATION_CHANNEL_GROUP_ID, Loading Loading @@ -7398,8 +7398,16 @@ public class NotificationManagerService extends SystemService { NotificationChannelGroup group) throws RemoteException { Objects.requireNonNull(user); verifyPrivilegedListener(token, user, false); createNotificationChannelGroup( pkg, getUidForPackageAndUser(pkg, user), group, false, true); int packageUid = getUidForPackageAndUser(pkg, user); if (packageUid == INVALID_UID) { return; } NotificationChannelGroup previous = mPreferencesHelper.getNotificationChannelGroup( group.getId(), pkg, packageUid); if (previous == null) { return; } createNotificationChannelGroup(pkg, packageUid, group, false, true); handleSavePolicyFile(); } Loading
services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +60 −0 Original line number Diff line number Diff line Loading @@ -691,6 +691,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { // MockPackageManager - default returns ApplicationInfo with matching calling UID mContext.setMockPackageManager(mPackageManagerClient); when(mPackageManager.getPackageUid(mPkg, 0, mUserId)).thenReturn(mUid); when(mPackageManager.getApplicationInfo(anyString(), anyLong(), anyInt())) .thenAnswer((Answer<ApplicationInfo>) invocation -> { Object[] args = invocation.getArguments(); Loading Loading @@ -5615,6 +5616,65 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { anyInt()); } @Test public void updateNotificationChannelGroupFromPrivilegedListener_cdm_success() throws Exception { NotificationChannelGroup createByApp = new NotificationChannelGroup("grp", "Group"); mService.mPreferencesHelper.createNotificationChannelGroup(mPkg, mUid, createByApp, true, mUid, false); NotificationChannelGroup updateByNls = new NotificationChannelGroup("grp", "Updated"); when(mCompanionMgr.getAssociations(mPkg, mUserId)) .thenReturn(singletonList(mock(AssociationInfo.class))); mBinderService.updateNotificationChannelGroupFromPrivilegedListener( null, mPkg, mUser, updateByNls); NotificationChannelGroup result = mService.mPreferencesHelper.getNotificationChannelGroup( "grp", mPkg, mUid); assertThat(result.getName().toString()).isEqualTo("Updated"); } @Test public void updateNotificationChannelGroupFromPrivilegedListener_noCdm_throws() throws Exception { when(mCompanionMgr.getAssociations(mPkg, mUserId)).thenReturn(Lists.newArrayList()); NotificationChannelGroup updateByNls = new NotificationChannelGroup("grp", "Updated"); SecurityException exception = assertThrows(SecurityException.class, () -> mBinderService.updateNotificationChannelGroupFromPrivilegedListener( null, mPkg, mUser, updateByNls)); assertThat(exception).hasMessageThat().contains("does not have access"); } @Test public void updateNotificationChannelGroupFromPrivilegedListener_wrongPackage_ignored() throws Exception { NotificationChannelGroup updateByNls = new NotificationChannelGroup("grp", "Updated"); when(mCompanionMgr.getAssociations(mPkg, mUserId)) .thenReturn(singletonList(mock(AssociationInfo.class))); mBinderService.updateNotificationChannelGroupFromPrivilegedListener( null, "com.package.does.not.exist", mUser, updateByNls); verify(mService.mPreferencesHelper, never()).createNotificationChannelGroup(any(), anyInt(), any(), anyBoolean(), anyInt(), anyBoolean()); } @Test public void updateNotificationChannelGroupFromPrivilegedListener_notAnUpdate_ignored() throws Exception { NotificationChannelGroup createByNls = new NotificationChannelGroup("grp", "New"); when(mCompanionMgr.getAssociations(mPkg, mUserId)) .thenReturn(singletonList(mock(AssociationInfo.class))); mBinderService.updateNotificationChannelGroupFromPrivilegedListener( null, mPkg, mUser, createByNls); verify(mService.mPreferencesHelper, never()).createNotificationChannelGroup(any(), anyInt(), any(), anyBoolean(), anyInt(), anyBoolean()); } @Test public void testGetPackagesWithChannels_blocked() throws Exception { // While we mostly rely on the PreferencesHelper implementation of channels, we filter in Loading