diff options
2 files changed, 41 insertions, 0 deletions
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index b16b766b6ef6..35f57ba8dae2 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -12660,6 +12660,16 @@ public class NotificationManagerService extends SystemService { return Log.isLoggable("notification_assistant", Log.VERBOSE); } + private void addDefaultClassificationTypes() { + // Add the default classification types if the list is empty + synchronized (mLock) { + if (mAllowedClassificationTypes.isEmpty()) { + mAllowedClassificationTypes.addAll( + List.of(DEFAULT_ALLOWED_ADJUSTMENT_KEY_TYPES)); + } + } + } + @FlaggedApi(android.service.notification.Flags.FLAG_NOTIFICATION_CLASSIFICATION) @GuardedBy("mNotificationLock") public void allowAdjustmentType(@Adjustment.Keys String key) { @@ -12670,6 +12680,9 @@ public class NotificationManagerService extends SystemService { for (final ManagedServiceInfo info : NotificationAssistants.this.getServices()) { mHandler.post(() -> notifyCapabilitiesChanged(info)); } + if (KEY_TYPE.equals(key)) { + addDefaultClassificationTypes(); + } } @FlaggedApi(android.service.notification.Flags.FLAG_NOTIFICATION_CLASSIFICATION) diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationAssistantsTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationAssistantsTest.java index 076e3e9fcc24..7a1ea09453fb 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationAssistantsTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationAssistantsTest.java @@ -681,6 +681,34 @@ public class NotificationAssistantsTest extends UiServiceTestCase { } @Test + @EnableFlags(android.service.notification.Flags.FLAG_NOTIFICATION_CLASSIFICATION) + public void testAllowAdjustmentType_classifListEmpty_resetDefaultClassificationTypes() { + mAssistants.setAssistantAdjustmentKeyTypeState(TYPE_PROMOTION, false); + mAssistants.setAssistantAdjustmentKeyTypeState(TYPE_NEWS, false); + mAssistants.setAssistantAdjustmentKeyTypeState(TYPE_SOCIAL_MEDIA, false); + mAssistants.setAssistantAdjustmentKeyTypeState(TYPE_CONTENT_RECOMMENDATION, false); + assertThat(mAssistants.getAllowedClassificationTypes()).isEmpty(); + mAssistants.disallowAdjustmentType(Adjustment.KEY_TYPE); + mAssistants.allowAdjustmentType(Adjustment.KEY_TYPE); + assertThat(mAssistants.getAllowedClassificationTypes()).asList() + .contains(TYPE_PROMOTION); + } + + @Test + @EnableFlags(android.service.notification.Flags.FLAG_NOTIFICATION_CLASSIFICATION) + public void testAllowAdjustmentType_classifListNotEmpty_doNotResetDefaultClassificationTypes() { + mAssistants.setAssistantAdjustmentKeyTypeState(TYPE_PROMOTION, false); + mAssistants.setAssistantAdjustmentKeyTypeState(TYPE_SOCIAL_MEDIA, false); + mAssistants.setAssistantAdjustmentKeyTypeState(TYPE_CONTENT_RECOMMENDATION, false); + mAssistants.setAssistantAdjustmentKeyTypeState(TYPE_NEWS, true); + assertThat(mAssistants.getAllowedClassificationTypes()).isNotEmpty(); + mAssistants.disallowAdjustmentType(Adjustment.KEY_TYPE); + mAssistants.allowAdjustmentType(Adjustment.KEY_TYPE); + assertThat(mAssistants.getAllowedClassificationTypes()).asList() + .containsExactly(TYPE_NEWS); + } + + @Test @EnableFlags(Flags.FLAG_NOTIFICATION_CLASSIFICATION_UI) public void testDisallowAdjustmentType_readWriteXml_entries() throws Exception { int userId = ActivityManager.getCurrentUser(); |