Loading services/core/java/com/android/server/notification/NotificationManagerService.java +7 −3 Original line number Diff line number Diff line Loading @@ -7496,15 +7496,19 @@ public class NotificationManagerService extends SystemService { if (users != null) { for (UserInfo user : users) { int userId = user.id; if (assistant == null) { ComponentName allowedAssistant = CollectionUtils.firstOrNull( mAssistants.getAllowedComponents(userId)); if (assistant == null) { if (allowedAssistant != null) { setNotificationAssistantAccessGrantedForUserInternal( allowedAssistant, userId, false, userSet); } continue; } if (granted && assistant.equals(allowedAssistant)) { continue; } if (!granted || mAllowedManagedServicePackages.test(assistant.getPackageName(), userId, mAssistants.getRequiredPermission())) { mConditionProviders.setPackageOrComponentEnabled(assistant.flattenToString(), Loading Loading @@ -13048,7 +13052,7 @@ public class NotificationManagerService extends SystemService { return mNasUnsupported.getOrDefault(userId, new HashSet<>()); } private void setNasUnsupportedDefaults(@UserIdInt int userId) { void setNasUnsupportedDefaults(@UserIdInt int userId) { if (mNasUnsupported != null) { mNasUnsupported.put(userId, new HashSet(List.of(mDefaultUnsupportedAdjustments))); handleSavePolicyFile(); services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +24 −0 Original line number Diff line number Diff line Loading @@ -6163,6 +6163,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { any(), anyInt(), anyBoolean(), anyBoolean(), anyBoolean()); } @Test public void testSetAssistantAccess() throws Exception { List<UserInfo> uis = new ArrayList<>(); Loading Loading @@ -6209,6 +6210,29 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { any(), anyInt(), anyBoolean(), anyBoolean()); } @Test public void testSetAssistantAccess_sameAsCurrentNas() throws Exception { List<UserInfo> uis = new ArrayList<>(); UserInfo ui = new UserInfo(); ui.id = mContext.getUserId(); uis.add(ui); when(mUm.getEnabledProfiles(ui.id)).thenReturn(uis); ComponentName c = ComponentName.unflattenFromString("package/Component"); ArrayList<ComponentName> componentList = new ArrayList<>(); componentList.add(c); when(mAssistants.getAllowedComponents(anyInt())).thenReturn(componentList); mBinderService.setNotificationAssistantAccessGranted(c, true); mBinderService.setNotificationAssistantAccessGranted(c, true); verify(mAssistants, never()).setPackageOrComponentEnabled( c.flattenToString(), ui.id, true, true, true); verify(mConditionProviders, never()).setPackageOrComponentEnabled( c.flattenToString(), ui.id, false, true); verify(mListeners, never()).setPackageOrComponentEnabled( any(), anyInt(), anyBoolean(), anyBoolean()); } @Test public void testSetAssistantAccess_nullWithAllowedAssistant() throws Exception { ArrayList<ComponentName> componentList = new ArrayList<>(); Loading Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +7 −3 Original line number Diff line number Diff line Loading @@ -7496,15 +7496,19 @@ public class NotificationManagerService extends SystemService { if (users != null) { for (UserInfo user : users) { int userId = user.id; if (assistant == null) { ComponentName allowedAssistant = CollectionUtils.firstOrNull( mAssistants.getAllowedComponents(userId)); if (assistant == null) { if (allowedAssistant != null) { setNotificationAssistantAccessGrantedForUserInternal( allowedAssistant, userId, false, userSet); } continue; } if (granted && assistant.equals(allowedAssistant)) { continue; } if (!granted || mAllowedManagedServicePackages.test(assistant.getPackageName(), userId, mAssistants.getRequiredPermission())) { mConditionProviders.setPackageOrComponentEnabled(assistant.flattenToString(), Loading Loading @@ -13048,7 +13052,7 @@ public class NotificationManagerService extends SystemService { return mNasUnsupported.getOrDefault(userId, new HashSet<>()); } private void setNasUnsupportedDefaults(@UserIdInt int userId) { void setNasUnsupportedDefaults(@UserIdInt int userId) { if (mNasUnsupported != null) { mNasUnsupported.put(userId, new HashSet(List.of(mDefaultUnsupportedAdjustments))); handleSavePolicyFile();
services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +24 −0 Original line number Diff line number Diff line Loading @@ -6163,6 +6163,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { any(), anyInt(), anyBoolean(), anyBoolean(), anyBoolean()); } @Test public void testSetAssistantAccess() throws Exception { List<UserInfo> uis = new ArrayList<>(); Loading Loading @@ -6209,6 +6210,29 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { any(), anyInt(), anyBoolean(), anyBoolean()); } @Test public void testSetAssistantAccess_sameAsCurrentNas() throws Exception { List<UserInfo> uis = new ArrayList<>(); UserInfo ui = new UserInfo(); ui.id = mContext.getUserId(); uis.add(ui); when(mUm.getEnabledProfiles(ui.id)).thenReturn(uis); ComponentName c = ComponentName.unflattenFromString("package/Component"); ArrayList<ComponentName> componentList = new ArrayList<>(); componentList.add(c); when(mAssistants.getAllowedComponents(anyInt())).thenReturn(componentList); mBinderService.setNotificationAssistantAccessGranted(c, true); mBinderService.setNotificationAssistantAccessGranted(c, true); verify(mAssistants, never()).setPackageOrComponentEnabled( c.flattenToString(), ui.id, true, true, true); verify(mConditionProviders, never()).setPackageOrComponentEnabled( c.flattenToString(), ui.id, false, true); verify(mListeners, never()).setPackageOrComponentEnabled( any(), anyInt(), anyBoolean(), anyBoolean()); } @Test public void testSetAssistantAccess_nullWithAllowedAssistant() throws Exception { ArrayList<ComponentName> componentList = new ArrayList<>(); Loading