Loading services/core/java/com/android/server/notification/NotificationManagerService.java +24 −5 Original line number Diff line number Diff line Loading @@ -12320,13 +12320,33 @@ public class NotificationManagerService extends SystemService { : new ArraySet<>(DEFAULT_ALLOWED_ADJUSTMENT_KEY_TYPES); } // Convenience method to return the effective list of denied adjustments for the given user. // For full users, this is just the list of denied adjustments contained in // mDeniedAdjustments for that user. // For profile users, this method checks additional criteria that may cause an adjustment to // be effectively denied for that user. In particular: // - if an adjustment is denied for that profile user's parent, then it is also effectively // denied for that profile regardless of what the profile's current setting is. @GuardedBy("mLock") private @NonNull Set<String> deniedAdjustmentsForUser(@UserIdInt int userId) { Set<String> denied = new HashSet<>(); if (mDeniedAdjustments.containsKey(userId)) { denied.addAll(mDeniedAdjustments.get(userId)); } final @UserIdInt int parentId = mUmInternal.getProfileParentId(userId); if ((parentId != userId) && mDeniedAdjustments.containsKey(parentId)) { denied.addAll(mDeniedAdjustments.get(parentId)); } // TODO: b/415768865 - add any cases where a (work/managed) profile should default to // off unless explicitly turned on return denied; } protected Set<String> getAllowedAssistantAdjustments(@UserIdInt int userId) { synchronized (mLock) { if (notificationClassification()) { Set<String> types = new HashSet<>(Set.of(DEFAULT_ALLOWED_ADJUSTMENTS)); if (mDeniedAdjustments.containsKey(userId)) { types.removeAll(mDeniedAdjustments.get(userId)); } types.removeAll(deniedAdjustmentsForUser(userId)); return types; } else { Set<String> types = new HashSet<>(); Loading @@ -12340,8 +12360,7 @@ public class NotificationManagerService extends SystemService { synchronized (mLock) { if (notificationClassification()) { return List.of(DEFAULT_ALLOWED_ADJUSTMENTS).contains(type) && !(mDeniedAdjustments.containsKey(userId) && mDeniedAdjustments.get(userId).contains(type)); && !(deniedAdjustmentsForUser(userId).contains(type)); } else { return mAllowedAdjustments.contains(type); } services/tests/uiservicestests/src/com/android/server/notification/NotificationAssistantsTest.java +22 −3 Original line number Diff line number Diff line Loading @@ -212,6 +212,7 @@ public class NotificationAssistantsTest extends UiServiceTestCase { profileIds.add(11); profileIds.add(10); profileIds.add(12); when(mUmInternal.getProfileParentId(13)).thenReturn(13); // 13 is a full user when(mUserProfiles.getCurrentProfileIds()).thenReturn(profileIds); when(mUmInternal.getProfileParentId(11)).thenReturn(mZero.id); when(mNm.isNASMigrationDone(anyInt())).thenReturn(true); Loading Loading @@ -681,8 +682,8 @@ public class NotificationAssistantsTest extends UiServiceTestCase { .doesNotContain(Adjustment.KEY_RANKING_SCORE); assertThat(mAssistants.getAllowedAssistantAdjustments(mZero.id)).contains(KEY_TYPE); // should not affect other users assertThat(mAssistants.getAllowedAssistantAdjustments(mTen.id)).contains( // should not affect other (full) users assertThat(mAssistants.getAllowedAssistantAdjustments(13)).contains( Adjustment.KEY_RANKING_SCORE); } Loading @@ -697,6 +698,25 @@ public class NotificationAssistantsTest extends UiServiceTestCase { .contains(Adjustment.KEY_RANKING_SCORE); } @Test public void testIsAdjustmentAllowed_profileUser_offIfParentOff() { // Even if an adjustment is allowed for a profile user, it should not be considered allowed // if the profile's parent has that adjustment disabled. // User 11 is set up as a profile user of mZero in setup; user 13 is not mAssistants.allowAdjustmentType(11, Adjustment.KEY_TYPE); mAssistants.disallowAdjustmentType(mZero.id, Adjustment.KEY_TYPE); assertThat(mAssistants.getAllowedAssistantAdjustments(11)).doesNotContain( Adjustment.KEY_TYPE); assertThat(mAssistants.isAdjustmentAllowed(11, Adjustment.KEY_TYPE)).isFalse(); // Now turn it back on for the parent; it should be considered allowed for the profile // (for which it was already on). mAssistants.allowAdjustmentType(mZero.id, Adjustment.KEY_TYPE); assertThat(mAssistants.getAllowedAssistantAdjustments(11)).contains(Adjustment.KEY_TYPE); assertThat(mAssistants.isAdjustmentAllowed(11, Adjustment.KEY_TYPE)).isTrue(); } @Test @EnableFlags(android.service.notification.Flags.FLAG_NOTIFICATION_CLASSIFICATION) public void testAllowAdjustmentType_classifListEmpty_resetDefaultClassificationTypes() { Loading Loading @@ -994,7 +1014,6 @@ public class NotificationAssistantsTest extends UiServiceTestCase { // * KEY_TYPE is allowed; KEY_SUMMARIZATION disallowed // * user 13 has only KEY_TYPE, which is disallowed // * other users have neither supported when(mUmInternal.getProfileParentId(13)).thenReturn(13); // make sure 12 is a full user mAssistants.setAdjustmentTypeSupportedState(mZero.id, KEY_TYPE, true); mAssistants.allowAdjustmentType(mZero.id, KEY_TYPE); mAssistants.setAdjustmentTypeSupportedState(mZero.id, KEY_SUMMARIZATION, true); Loading Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +24 −5 Original line number Diff line number Diff line Loading @@ -12320,13 +12320,33 @@ public class NotificationManagerService extends SystemService { : new ArraySet<>(DEFAULT_ALLOWED_ADJUSTMENT_KEY_TYPES); } // Convenience method to return the effective list of denied adjustments for the given user. // For full users, this is just the list of denied adjustments contained in // mDeniedAdjustments for that user. // For profile users, this method checks additional criteria that may cause an adjustment to // be effectively denied for that user. In particular: // - if an adjustment is denied for that profile user's parent, then it is also effectively // denied for that profile regardless of what the profile's current setting is. @GuardedBy("mLock") private @NonNull Set<String> deniedAdjustmentsForUser(@UserIdInt int userId) { Set<String> denied = new HashSet<>(); if (mDeniedAdjustments.containsKey(userId)) { denied.addAll(mDeniedAdjustments.get(userId)); } final @UserIdInt int parentId = mUmInternal.getProfileParentId(userId); if ((parentId != userId) && mDeniedAdjustments.containsKey(parentId)) { denied.addAll(mDeniedAdjustments.get(parentId)); } // TODO: b/415768865 - add any cases where a (work/managed) profile should default to // off unless explicitly turned on return denied; } protected Set<String> getAllowedAssistantAdjustments(@UserIdInt int userId) { synchronized (mLock) { if (notificationClassification()) { Set<String> types = new HashSet<>(Set.of(DEFAULT_ALLOWED_ADJUSTMENTS)); if (mDeniedAdjustments.containsKey(userId)) { types.removeAll(mDeniedAdjustments.get(userId)); } types.removeAll(deniedAdjustmentsForUser(userId)); return types; } else { Set<String> types = new HashSet<>(); Loading @@ -12340,8 +12360,7 @@ public class NotificationManagerService extends SystemService { synchronized (mLock) { if (notificationClassification()) { return List.of(DEFAULT_ALLOWED_ADJUSTMENTS).contains(type) && !(mDeniedAdjustments.containsKey(userId) && mDeniedAdjustments.get(userId).contains(type)); && !(deniedAdjustmentsForUser(userId).contains(type)); } else { return mAllowedAdjustments.contains(type); }
services/tests/uiservicestests/src/com/android/server/notification/NotificationAssistantsTest.java +22 −3 Original line number Diff line number Diff line Loading @@ -212,6 +212,7 @@ public class NotificationAssistantsTest extends UiServiceTestCase { profileIds.add(11); profileIds.add(10); profileIds.add(12); when(mUmInternal.getProfileParentId(13)).thenReturn(13); // 13 is a full user when(mUserProfiles.getCurrentProfileIds()).thenReturn(profileIds); when(mUmInternal.getProfileParentId(11)).thenReturn(mZero.id); when(mNm.isNASMigrationDone(anyInt())).thenReturn(true); Loading Loading @@ -681,8 +682,8 @@ public class NotificationAssistantsTest extends UiServiceTestCase { .doesNotContain(Adjustment.KEY_RANKING_SCORE); assertThat(mAssistants.getAllowedAssistantAdjustments(mZero.id)).contains(KEY_TYPE); // should not affect other users assertThat(mAssistants.getAllowedAssistantAdjustments(mTen.id)).contains( // should not affect other (full) users assertThat(mAssistants.getAllowedAssistantAdjustments(13)).contains( Adjustment.KEY_RANKING_SCORE); } Loading @@ -697,6 +698,25 @@ public class NotificationAssistantsTest extends UiServiceTestCase { .contains(Adjustment.KEY_RANKING_SCORE); } @Test public void testIsAdjustmentAllowed_profileUser_offIfParentOff() { // Even if an adjustment is allowed for a profile user, it should not be considered allowed // if the profile's parent has that adjustment disabled. // User 11 is set up as a profile user of mZero in setup; user 13 is not mAssistants.allowAdjustmentType(11, Adjustment.KEY_TYPE); mAssistants.disallowAdjustmentType(mZero.id, Adjustment.KEY_TYPE); assertThat(mAssistants.getAllowedAssistantAdjustments(11)).doesNotContain( Adjustment.KEY_TYPE); assertThat(mAssistants.isAdjustmentAllowed(11, Adjustment.KEY_TYPE)).isFalse(); // Now turn it back on for the parent; it should be considered allowed for the profile // (for which it was already on). mAssistants.allowAdjustmentType(mZero.id, Adjustment.KEY_TYPE); assertThat(mAssistants.getAllowedAssistantAdjustments(11)).contains(Adjustment.KEY_TYPE); assertThat(mAssistants.isAdjustmentAllowed(11, Adjustment.KEY_TYPE)).isTrue(); } @Test @EnableFlags(android.service.notification.Flags.FLAG_NOTIFICATION_CLASSIFICATION) public void testAllowAdjustmentType_classifListEmpty_resetDefaultClassificationTypes() { Loading Loading @@ -994,7 +1014,6 @@ public class NotificationAssistantsTest extends UiServiceTestCase { // * KEY_TYPE is allowed; KEY_SUMMARIZATION disallowed // * user 13 has only KEY_TYPE, which is disallowed // * other users have neither supported when(mUmInternal.getProfileParentId(13)).thenReturn(13); // make sure 12 is a full user mAssistants.setAdjustmentTypeSupportedState(mZero.id, KEY_TYPE, true); mAssistants.allowAdjustmentType(mZero.id, KEY_TYPE); mAssistants.setAdjustmentTypeSupportedState(mZero.id, KEY_SUMMARIZATION, true); Loading