Loading services/core/java/com/android/server/notification/ConditionProviders.java +5 −0 Original line number Diff line number Diff line Loading @@ -250,6 +250,11 @@ public class ConditionProviders extends ManagedServices { return true; } @Override protected boolean allowRebindForParentUser() { return true; } @Override protected String getRequiredPermission() { return null; Loading services/core/java/com/android/server/notification/ManagedServices.java +10 −1 Original line number Diff line number Diff line Loading @@ -1371,7 +1371,9 @@ abstract public class ManagedServices { protected void rebindServices(boolean forceRebind, int userToRebind) { if (DEBUG) Slog.d(TAG, "rebindServices " + forceRebind + " " + userToRebind); IntArray userIds = mUserProfiles.getCurrentProfileIds(); if (userToRebind != USER_ALL) { boolean rebindAllCurrentUsers = mUserProfiles.isProfileUser(userToRebind) && allowRebindForParentUser(); if (userToRebind != USER_ALL && !rebindAllCurrentUsers) { userIds = new IntArray(1); userIds.add(userToRebind); } Loading Loading @@ -1758,6 +1760,13 @@ abstract public class ManagedServices { return true; } /** * Returns true if services in the parent user should be rebound * when rebindServices is called with a profile userId. * Must be false for NotificationAssistants. */ protected abstract boolean allowRebindForParentUser(); public class ManagedServiceInfo implements IBinder.DeathRecipient { public IInterface service; public ComponentName component; Loading services/core/java/com/android/server/notification/NotificationManagerService.java +10 −0 Original line number Diff line number Diff line Loading @@ -10503,6 +10503,11 @@ public class NotificationManagerService extends SystemService { rebindServices(true, user); } @Override protected boolean allowRebindForParentUser() { return false; } @Override protected String getRequiredPermission() { // only signature/privileged apps can be bound. Loading Loading @@ -11047,6 +11052,11 @@ public class NotificationManagerService extends SystemService { } } @Override protected boolean allowRebindForParentUser() { return true; } @Override public void onPackagesChanged(boolean removingPackage, String[] pkgList, int[] uidList) { super.onPackagesChanged(removingPackage, pkgList, uidList); Loading services/tests/uiservicestests/src/com/android/server/notification/ManagedServicesTest.java +35 −0 Original line number Diff line number Diff line Loading @@ -1933,6 +1933,36 @@ public class ManagedServicesTest extends UiServiceTestCase { }, 20, 30); } @Test public void isComponentEnabledForCurrentProfiles_profileUserId() { final int profileUserId = 10; when(mUserProfiles.isProfileUser(profileUserId)).thenReturn(true); // Only approve for parent user (0) mService.addApprovedList("pkg1/cmp1:pkg2/cmp2:pkg3/cmp3", 0, true); // Test that the component is enabled after calling rebindServices with profile userId (10) mService.rebindServices(false, profileUserId); assertThat(mService.isComponentEnabledForCurrentProfiles( new ComponentName("pkg1", "cmp1"))).isTrue(); } @Test public void isComponentEnabledForCurrentProfiles_profileUserId_NAS() { final int profileUserId = 10; when(mUserProfiles.isProfileUser(profileUserId)).thenReturn(true); // Do not rebind for parent users (NAS use-case) ManagedServices service = spy(mService); when(service.allowRebindForParentUser()).thenReturn(false); // Only approve for parent user (0) service.addApprovedList("pkg1/cmp1:pkg2/cmp2:pkg3/cmp3", 0, true); // Test that the component is disabled after calling rebindServices with profile userId (10) service.rebindServices(false, profileUserId); assertThat(service.isComponentEnabledForCurrentProfiles( new ComponentName("pkg1", "cmp1"))).isFalse(); } private void mockServiceInfoWithMetaData(List<ComponentName> componentNames, ManagedServices service, ArrayMap<ComponentName, Bundle> metaDatas) throws RemoteException { Loading Loading @@ -2276,6 +2306,11 @@ public class ManagedServicesTest extends UiServiceTestCase { protected String getRequiredPermission() { return null; } @Override protected boolean allowRebindForParentUser() { return true; } } class TestManagedServicesSettings extends TestManagedServices { Loading Loading
services/core/java/com/android/server/notification/ConditionProviders.java +5 −0 Original line number Diff line number Diff line Loading @@ -250,6 +250,11 @@ public class ConditionProviders extends ManagedServices { return true; } @Override protected boolean allowRebindForParentUser() { return true; } @Override protected String getRequiredPermission() { return null; Loading
services/core/java/com/android/server/notification/ManagedServices.java +10 −1 Original line number Diff line number Diff line Loading @@ -1371,7 +1371,9 @@ abstract public class ManagedServices { protected void rebindServices(boolean forceRebind, int userToRebind) { if (DEBUG) Slog.d(TAG, "rebindServices " + forceRebind + " " + userToRebind); IntArray userIds = mUserProfiles.getCurrentProfileIds(); if (userToRebind != USER_ALL) { boolean rebindAllCurrentUsers = mUserProfiles.isProfileUser(userToRebind) && allowRebindForParentUser(); if (userToRebind != USER_ALL && !rebindAllCurrentUsers) { userIds = new IntArray(1); userIds.add(userToRebind); } Loading Loading @@ -1758,6 +1760,13 @@ abstract public class ManagedServices { return true; } /** * Returns true if services in the parent user should be rebound * when rebindServices is called with a profile userId. * Must be false for NotificationAssistants. */ protected abstract boolean allowRebindForParentUser(); public class ManagedServiceInfo implements IBinder.DeathRecipient { public IInterface service; public ComponentName component; Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +10 −0 Original line number Diff line number Diff line Loading @@ -10503,6 +10503,11 @@ public class NotificationManagerService extends SystemService { rebindServices(true, user); } @Override protected boolean allowRebindForParentUser() { return false; } @Override protected String getRequiredPermission() { // only signature/privileged apps can be bound. Loading Loading @@ -11047,6 +11052,11 @@ public class NotificationManagerService extends SystemService { } } @Override protected boolean allowRebindForParentUser() { return true; } @Override public void onPackagesChanged(boolean removingPackage, String[] pkgList, int[] uidList) { super.onPackagesChanged(removingPackage, pkgList, uidList); Loading
services/tests/uiservicestests/src/com/android/server/notification/ManagedServicesTest.java +35 −0 Original line number Diff line number Diff line Loading @@ -1933,6 +1933,36 @@ public class ManagedServicesTest extends UiServiceTestCase { }, 20, 30); } @Test public void isComponentEnabledForCurrentProfiles_profileUserId() { final int profileUserId = 10; when(mUserProfiles.isProfileUser(profileUserId)).thenReturn(true); // Only approve for parent user (0) mService.addApprovedList("pkg1/cmp1:pkg2/cmp2:pkg3/cmp3", 0, true); // Test that the component is enabled after calling rebindServices with profile userId (10) mService.rebindServices(false, profileUserId); assertThat(mService.isComponentEnabledForCurrentProfiles( new ComponentName("pkg1", "cmp1"))).isTrue(); } @Test public void isComponentEnabledForCurrentProfiles_profileUserId_NAS() { final int profileUserId = 10; when(mUserProfiles.isProfileUser(profileUserId)).thenReturn(true); // Do not rebind for parent users (NAS use-case) ManagedServices service = spy(mService); when(service.allowRebindForParentUser()).thenReturn(false); // Only approve for parent user (0) service.addApprovedList("pkg1/cmp1:pkg2/cmp2:pkg3/cmp3", 0, true); // Test that the component is disabled after calling rebindServices with profile userId (10) service.rebindServices(false, profileUserId); assertThat(service.isComponentEnabledForCurrentProfiles( new ComponentName("pkg1", "cmp1"))).isFalse(); } private void mockServiceInfoWithMetaData(List<ComponentName> componentNames, ManagedServices service, ArrayMap<ComponentName, Bundle> metaDatas) throws RemoteException { Loading Loading @@ -2276,6 +2306,11 @@ public class ManagedServicesTest extends UiServiceTestCase { protected String getRequiredPermission() { return null; } @Override protected boolean allowRebindForParentUser() { return true; } } class TestManagedServicesSettings extends TestManagedServices { Loading