summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Julia Reynolds <juliacr@google.com> 2025-01-29 12:50:34 -0500
committer Julia Reynolds <juliacr@google.com> 2025-01-29 12:50:34 -0500
commitd2514f7c7dd86fd729f1a78cca15244018b6ba00 (patch)
treedc73e8232981c0c076724f1425c1d8db1614beb5
parent769d0736d665fde0d9c653870a31ce1391f00532 (diff)
Add full list api
To minimize binder calls Test: NotificationAssistantsTest Flag: android.app.nm_summarization Bug: 377697346 Change-Id: I0f7140c5bc394308e7a316750cce30f610e5eb0c
-rw-r--r--core/java/android/app/INotificationManager.aidl1
-rw-r--r--services/core/java/com/android/server/notification/NotificationManagerService.java16
-rw-r--r--services/tests/uiservicestests/src/com/android/server/notification/NotificationAssistantsTest.java8
3 files changed, 25 insertions, 0 deletions
diff --git a/core/java/android/app/INotificationManager.aidl b/core/java/android/app/INotificationManager.aidl
index 3fb08224b9db..bc01f934e701 100644
--- a/core/java/android/app/INotificationManager.aidl
+++ b/core/java/android/app/INotificationManager.aidl
@@ -270,6 +270,7 @@ interface INotificationManager
int[] getAllowedAdjustmentKeyTypes();
void setAssistantAdjustmentKeyTypeState(int type, boolean enabled);
+ String[] getAdjustmentDeniedPackages(String key);
boolean isAdjustmentSupportedForPackage(String key, String pkg);
void setAdjustmentSupportedForPackage(String key, String pkg, boolean enabled);
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java
index 2305f1bab785..56ec1fa8607b 100644
--- a/services/core/java/com/android/server/notification/NotificationManagerService.java
+++ b/services/core/java/com/android/server/notification/NotificationManagerService.java
@@ -4559,6 +4559,12 @@ public class NotificationManagerService extends SystemService {
}
@Override
+ public String[] getAdjustmentDeniedPackages(String key) {
+ checkCallerIsSystemOrSystemUiOrShell();
+ return mAssistants.getAdjustmentDeniedPackages(key);
+ }
+
+ @Override
public boolean isAdjustmentSupportedForPackage(String key, String pkg) {
checkCallerIsSystemOrSystemUiOrShell();
return mAssistants.isAdjustmentAllowedForPackage(key, pkg);
@@ -12275,6 +12281,16 @@ public class NotificationManagerService extends SystemService {
}
}
+ protected @NonNull String[] getAdjustmentDeniedPackages(@Adjustment.Keys String key) {
+ synchronized (mLock) {
+ if (notificationClassificationUi() || nmSummarization() | nmSummarizationUi()) {
+ return mAdjustmentKeyDeniedPackages.getOrDefault(
+ key, new ArraySet<>()).toArray(new String[0]);
+ }
+ }
+ return new String[]{};
+ }
+
protected @NonNull boolean isAdjustmentAllowedForPackage(@Adjustment.Keys String key,
String pkg) {
synchronized (mLock) {
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 839f27634d0f..0de957412257 100644
--- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationAssistantsTest.java
+++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationAssistantsTest.java
@@ -757,18 +757,22 @@ public class NotificationAssistantsTest extends UiServiceTestCase {
String allowedPackage = "allowed.package";
assertThat(mAssistants.isAdjustmentAllowedForPackage(key, allowedPackage)).isTrue();
+ assertThat(mAssistants.getAdjustmentDeniedPackages(key)).isEmpty();
// Set type adjustment disallowed for this package
mAssistants.setAdjustmentSupportedForPackage(key, allowedPackage, false);
// Then the package is marked as denied
assertThat(mAssistants.isAdjustmentAllowedForPackage(key, allowedPackage)).isFalse();
+ assertThat(mAssistants.getAdjustmentDeniedPackages(key)).asList()
+ .containsExactly(allowedPackage);
// Set type adjustment allowed again
mAssistants.setAdjustmentSupportedForPackage(key, allowedPackage, true);
// Then the package is marked as allowed again
assertThat(mAssistants.isAdjustmentAllowedForPackage(key, allowedPackage)).isTrue();
+ assertThat(mAssistants.getAdjustmentDeniedPackages(key)).isEmpty();
}
@Test
@@ -789,6 +793,8 @@ public class NotificationAssistantsTest extends UiServiceTestCase {
assertThat(mAssistants.isAdjustmentAllowedForPackage(key, deniedPkg1)).isFalse();
assertThat(mAssistants.isAdjustmentAllowedForPackage(key, deniedPkg2)).isFalse();
assertThat(mAssistants.isAdjustmentAllowedForPackage(key, deniedPkg3)).isFalse();
+ assertThat(mAssistants.getAdjustmentDeniedPackages(key)).asList()
+ .containsExactlyElementsIn(List.of(deniedPkg1, deniedPkg2, deniedPkg3));
// And when we re-allow one of them,
mAssistants.setAdjustmentSupportedForPackage(key, deniedPkg2, true);
@@ -797,6 +803,8 @@ public class NotificationAssistantsTest extends UiServiceTestCase {
assertThat(mAssistants.isAdjustmentAllowedForPackage(key, deniedPkg1)).isFalse();
assertThat(mAssistants.isAdjustmentAllowedForPackage(key, deniedPkg2)).isTrue();
assertThat(mAssistants.isAdjustmentAllowedForPackage(key, deniedPkg3)).isFalse();
+ assertThat(mAssistants.getAdjustmentDeniedPackages(key)).asList()
+ .containsExactlyElementsIn(List.of(deniedPkg1, deniedPkg3));
}
@Test