summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Iavor-Valentin Iftime <valiiftime@google.com> 2025-01-16 04:08:31 -0800
committer Android (Google) Code Review <android-gerrit@google.com> 2025-01-16 04:08:31 -0800
commitc9b303d89c8ff80d6e0c9ee184ac1bdcbb9f01cf (patch)
treea5d7b51d42f14c316c6c00154e5a6c28d6086826
parentb8e3784153088a942d97f475fc0ac7c706e29570 (diff)
parent987a22d5c9ecc3621adb3f3020acd87530578774 (diff)
Merge "Revert "Modify API to save package bundle type prefs"" into main
-rw-r--r--core/java/android/app/INotificationManager.aidl4
-rw-r--r--core/java/android/app/NotificationManager.java6
-rw-r--r--services/core/java/com/android/server/notification/NotificationManagerService.java170
-rw-r--r--services/tests/uiservicestests/src/com/android/server/notification/NotificationAssistantsTest.java206
-rw-r--r--services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java29
5 files changed, 103 insertions, 312 deletions
diff --git a/core/java/android/app/INotificationManager.aidl b/core/java/android/app/INotificationManager.aidl
index 1738a92b7672..4a78d01783f8 100644
--- a/core/java/android/app/INotificationManager.aidl
+++ b/core/java/android/app/INotificationManager.aidl
@@ -271,6 +271,6 @@ interface INotificationManager
int[] getAllowedAdjustmentKeyTypes();
void setAssistantAdjustmentKeyTypeState(int type, boolean enabled);
- int[] getAllowedAdjustmentKeyTypesForPackage(String pkg);
- void setAssistantAdjustmentKeyTypeStateForPackage(String pkg, int type, boolean enabled);
+ String[] getTypeAdjustmentDeniedPackages();
+ void setTypeAdjustmentForPackageState(String pkg, boolean enabled);
}
diff --git a/core/java/android/app/NotificationManager.java b/core/java/android/app/NotificationManager.java
index 24f2495d8f09..e5d80de24f2b 100644
--- a/core/java/android/app/NotificationManager.java
+++ b/core/java/android/app/NotificationManager.java
@@ -2163,12 +2163,10 @@ public class NotificationManager {
* @hide
*/
@FlaggedApi(android.app.Flags.FLAG_NOTIFICATION_CLASSIFICATION_UI)
- public void setAssistantAdjustmentKeyTypeStateForPackage(@NonNull String pkg,
- @Adjustment.Types int type,
- boolean enabled) {
+ public void setTypeAdjustmentForPackageState(@NonNull String pkg, boolean enabled) {
INotificationManager service = service();
try {
- service.setAssistantAdjustmentKeyTypeStateForPackage(pkg, type, enabled);
+ service.setTypeAdjustmentForPackageState(pkg, enabled);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java
index adf6c1b94fbd..ef39f1811876 100644
--- a/services/core/java/com/android/server/notification/NotificationManagerService.java
+++ b/services/core/java/com/android/server/notification/NotificationManagerService.java
@@ -3037,10 +3037,9 @@ public class NotificationManagerService extends SystemService {
switch(atomTag) {
case PACKAGE_NOTIFICATION_PREFERENCES:
if (notificationClassificationUi()) {
- Set<String> pkgs = mAssistants.getPackagesWithKeyTypeAdjustmentSettings();
mPreferencesHelper.pullPackagePreferencesStats(data,
getAllUsersNotificationPermissions(),
- getPackageSpecificAdjustmentKeyTypes(pkgs));
+ new ArrayMap<>());
} else {
mPreferencesHelper.pullPackagePreferencesStats(data,
getAllUsersNotificationPermissions());
@@ -4401,16 +4400,16 @@ public class NotificationManagerService extends SystemService {
@Override
@FlaggedApi(android.app.Flags.FLAG_NOTIFICATION_CLASSIFICATION_UI)
- public @NonNull int[] getAllowedAdjustmentKeyTypesForPackage(String pkg) {
+ public @NonNull String[] getTypeAdjustmentDeniedPackages() {
checkCallerIsSystemOrSystemUiOrShell();
- return mAssistants.getAllowedAdjustmentKeyTypesForPackage(pkg);
+ return mAssistants.getTypeAdjustmentDeniedPackages();
}
+ @Override
@FlaggedApi(android.app.Flags.FLAG_NOTIFICATION_CLASSIFICATION_UI)
- public void setAssistantAdjustmentKeyTypeStateForPackage(String pkg, int type,
- boolean enabled) {
+ public void setTypeAdjustmentForPackageState(String pkg, boolean enabled) {
checkCallerIsSystemOrSystemUiOrShell();
- mAssistants.setAssistantAdjustmentKeyTypeStateForPackage(pkg, type, enabled);
+ mAssistants.setTypeAdjustmentForPackageState(pkg, enabled);
handleSavePolicyFile();
}
@@ -7219,7 +7218,7 @@ public class NotificationManagerService extends SystemService {
toRemove.add(potentialKey);
} else if (notificationClassificationUi()
&& !mAssistants.isTypeAdjustmentAllowedForPackage(
- r.getSbn().getPackageName(), adjustments.getInt(KEY_TYPE))) {
+ r.getSbn().getPackageName())) {
toRemove.add(potentialKey);
}
}
@@ -7556,24 +7555,6 @@ public class NotificationManagerService extends SystemService {
return allPermissions;
}
- @VisibleForTesting
- @FlaggedApi(android.app.Flags.FLAG_NOTIFICATION_CLASSIFICATION_UI)
- protected @NonNull Map<String, Set<Integer>> getPackageSpecificAdjustmentKeyTypes(
- Set<String> pkgs) {
- ArrayMap<String, Set<Integer>> pkgToAllowedTypes = new ArrayMap<>();
- for (String pkg : pkgs) {
- int[] allowedTypesArray = mAssistants.getAllowedAdjustmentKeyTypesForPackage(pkg);
- if (allowedTypesArray != null) {
- Set<Integer> allowedTypes = new ArraySet<Integer>();
- for (int i : allowedTypesArray) {
- allowedTypes.add(i);
- }
- pkgToAllowedTypes.append(pkg, allowedTypes);
- }
- }
- return pkgToAllowedTypes;
- }
-
private void dumpJson(PrintWriter pw, @NonNull DumpFilter filter,
ArrayMap<Pair<Integer, String>, Pair<Boolean, Boolean>> pkgPermissions) {
JSONObject dump = new JSONObject();
@@ -11889,11 +11870,7 @@ public class NotificationManagerService extends SystemService {
private static final String ATT_DENIED = "denied_adjustments";
private static final String ATT_ENABLED_TYPES = "enabled_key_types";
private static final String ATT_NAS_UNSUPPORTED = "unsupported_adjustments";
- // Encapsulates a list of packages and the bundle types enabled for each package.
- private static final String TAG_TYPES_ENABLED_FOR_APPS = "types_enabled_for_apps";
- // Encapsulates the bundle types enabled for a package.
- private static final String ATT_APP_ENABLED_TYPES = "app_enabled_types";
- private static final String ATT_PACKAGE = "package";
+ private static final String ATT_TYPES_DENIED_APPS = "types_denied_apps";
private final Object mLock = new Object();
@@ -11909,14 +11886,8 @@ public class NotificationManagerService extends SystemService {
@GuardedBy("mLock")
private Map<Integer, HashSet<String>> mNasUnsupported = new ArrayMap<>();
- // Types of classifications (aka bundles) enabled/allowed for this package.
- // If the set is NULL (or package is not in the list), default classification allow list
- // (the global one) should be used.
- // If the set is empty, that indicates the package explicitly has all classifications
- // disallowed.
@GuardedBy("mLock")
- private Map<String, Set<Integer>> mClassificationTypePackagesEnabledTypes =
- new ArrayMap<>();
+ private Set<String> mClassificationTypeDeniedPackages = new ArraySet<>();
protected ComponentName mDefaultFromConfig = null;
@@ -12120,104 +12091,41 @@ public class NotificationManagerService extends SystemService {
}
}
- /**
- * Returns whether the type adjustment is allowed for this particular package.
- * If no package-specific restrictions have been set, defaults to the same value as
- * isAdjustmentKeyTypeAllowed(type).
- */
@FlaggedApi(android.app.Flags.FLAG_NOTIFICATION_CLASSIFICATION_UI)
- protected boolean isTypeAdjustmentAllowedForPackage(String pkg,
- @Adjustment.Types int type) {
+ protected @NonNull boolean isTypeAdjustmentAllowedForPackage(String pkg) {
synchronized (mLock) {
if (notificationClassificationUi()) {
- if (mClassificationTypePackagesEnabledTypes.containsKey(pkg)) {
- Set<Integer> enabled = mClassificationTypePackagesEnabledTypes.get(pkg);
- if (enabled != null) {
- return enabled.contains(type);
- }
- }
- // If mClassificationTypePackagesEnabledTypes does not contain the pkg, or
- // the stored set is null, return the default.
- return isAdjustmentKeyTypeAllowed(type);
- }
- }
- return false;
- }
-
- @FlaggedApi(android.app.Flags.FLAG_NOTIFICATION_CLASSIFICATION_UI)
- protected @NonNull Set<String> getPackagesWithKeyTypeAdjustmentSettings() {
- if (notificationClassificationUi()) {
- Set<String> packagesWithModifications = new ArraySet<String>();
- synchronized (mLock) {
- for (String pkg : mClassificationTypePackagesEnabledTypes.keySet()) {
- if (mClassificationTypePackagesEnabledTypes.get(pkg) != null) {
- packagesWithModifications.add(pkg);
- }
- }
+ return !mClassificationTypeDeniedPackages.contains(pkg);
}
- return packagesWithModifications;
}
- return new ArraySet<String>();
+ return true;
}
@FlaggedApi(android.app.Flags.FLAG_NOTIFICATION_CLASSIFICATION_UI)
- protected @NonNull int[] getAllowedAdjustmentKeyTypesForPackage(String pkg) {
+ protected @NonNull String[] getTypeAdjustmentDeniedPackages() {
synchronized (mLock) {
if (notificationClassificationUi()) {
- if (mClassificationTypePackagesEnabledTypes.containsKey(pkg)) {
- Set<Integer> enabled = mClassificationTypePackagesEnabledTypes.get(pkg);
- if (enabled != null) {
- // Convert Set to int[] for return.
- int[] returnEnabled = new int[enabled.size()];
- int i = 0;
- for (int val: enabled) {
- returnEnabled[i] = val;
- i++;
- }
- return returnEnabled;
- }
- }
- // If package is not in the map, or the value is null, return the default.
- return getAllowedAdjustmentKeyTypes();
+ return mClassificationTypeDeniedPackages.toArray(new String[0]);
}
}
- return new int[]{};
+ return new String[]{};
}
/**
* Set whether a particular package can have its notification channels adjusted to have a
* different type by NotificationAssistants.
- * Note: once this method is called to enable or disable a specific type for a package,
- * the global default is set as the starting point, and the type is enabled/disabled from
- * there. Future changes to the global default will not apply automatically to this package.
*/
@FlaggedApi(android.app.Flags.FLAG_NOTIFICATION_CLASSIFICATION_UI)
- public void setAssistantAdjustmentKeyTypeStateForPackage(String pkg,
- @Adjustment.Types int type,
- boolean enabled) {
+ public void setTypeAdjustmentForPackageState(String pkg, boolean enabled) {
if (!notificationClassificationUi()) {
return;
}
synchronized (mLock) {
- Set<Integer> enabledTypes = null;
- if (mClassificationTypePackagesEnabledTypes.containsKey(pkg)) {
- enabledTypes = mClassificationTypePackagesEnabledTypes.get(pkg);
- }
- if (enabledTypes == null) {
- // Use global default to start.
- enabledTypes = new ArraySet<Integer>();
- // Convert from int[] to Set<Integer>
- for (int value : getAllowedAdjustmentKeyTypes()) {
- enabledTypes.add(value);
- }
- }
-
if (enabled) {
- enabledTypes.add(type);
+ mClassificationTypeDeniedPackages.remove(pkg);
} else {
- enabledTypes.remove(type);
+ mClassificationTypeDeniedPackages.add(pkg);
}
- mClassificationTypePackagesEnabledTypes.put(pkg, enabledTypes);
}
}
@@ -12684,25 +12592,16 @@ public class NotificationManagerService extends SystemService {
TextUtils.join(",", mAllowedAdjustmentKeyTypes));
out.endTag(null, ATT_ENABLED_TYPES);
if (notificationClassificationUi()) {
- out.startTag(null, TAG_TYPES_ENABLED_FOR_APPS);
- for (String pkg: mClassificationTypePackagesEnabledTypes.keySet()) {
- Set<Integer> allowedTypes =
- mClassificationTypePackagesEnabledTypes.get(pkg);
- if (allowedTypes != null) {
- out.startTag(null, ATT_APP_ENABLED_TYPES);
- out.attribute(null, ATT_PACKAGE, pkg);
- out.attribute(null, ATT_TYPES, TextUtils.join(",", allowedTypes));
- out.endTag(null, ATT_APP_ENABLED_TYPES);
- }
- }
- out.endTag(null, TAG_TYPES_ENABLED_FOR_APPS);
+ out.startTag(null, ATT_TYPES_DENIED_APPS);
+ out.attribute(null, ATT_TYPES,
+ TextUtils.join(",", mClassificationTypeDeniedPackages));
+ out.endTag(null, ATT_TYPES_DENIED_APPS);
}
}
}
@Override
- protected void readExtraTag(String tag, TypedXmlPullParser parser) throws IOException,
- XmlPullParserException {
+ protected void readExtraTag(String tag, TypedXmlPullParser parser) throws IOException {
if (!notificationClassification()) {
return;
}
@@ -12729,25 +12628,12 @@ public class NotificationManagerService extends SystemService {
}
}
}
- } else if (TAG_TYPES_ENABLED_FOR_APPS.equals(tag)) {
- final int appsOuterDepth = parser.getDepth();
+ } else if (notificationClassificationUi() && ATT_TYPES_DENIED_APPS.equals(tag)) {
+ final String apps = XmlUtils.readStringAttribute(parser, ATT_TYPES);
synchronized (mLock) {
- mClassificationTypePackagesEnabledTypes.clear();
- while (XmlUtils.nextElementWithin(parser, appsOuterDepth)) {
- if (!ATT_APP_ENABLED_TYPES.equals(parser.getName())) {
- continue;
- }
- final String app = XmlUtils.readStringAttribute(parser, ATT_PACKAGE);
- Set<Integer> allowedTypes = new ArraySet<>();
- final String typesString = XmlUtils.readStringAttribute(parser, ATT_TYPES);
- if (!TextUtils.isEmpty(typesString)) {
- allowedTypes = Arrays.stream(typesString.split(","))
- .map(Integer::valueOf)
- .collect(Collectors.toSet());
- }
- // Empty type list is allowed, because empty type list signifies the user
- // has manually cleared the package of allowed types.
- mClassificationTypePackagesEnabledTypes.put(app, allowedTypes);
+ mClassificationTypeDeniedPackages.clear();
+ if (!TextUtils.isEmpty(apps)) {
+ mClassificationTypeDeniedPackages.addAll(Arrays.asList(apps.split(",")));
}
}
}
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 1df8e3deb84b..d2f8d14c5007 100644
--- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationAssistantsTest.java
+++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationAssistantsTest.java
@@ -19,13 +19,9 @@ import static android.os.UserHandle.USER_ALL;
import static android.service.notification.Adjustment.KEY_IMPORTANCE;
import static android.service.notification.Adjustment.TYPE_CONTENT_RECOMMENDATION;
import static android.service.notification.Adjustment.TYPE_NEWS;
-import static android.service.notification.Adjustment.TYPE_OTHER;
import static android.service.notification.Adjustment.TYPE_PROMOTION;
-import static android.service.notification.Adjustment.TYPE_SOCIAL_MEDIA;
-import static android.service.notification.Flags.notificationClassification;
import static com.android.server.notification.NotificationManagerService.DEFAULT_ALLOWED_ADJUSTMENTS;
-import static com.android.server.notification.NotificationManagerService.DEFAULT_ALLOWED_ADJUSTMENT_KEY_TYPES;
import static com.google.common.truth.Truth.assertThat;
@@ -160,17 +156,6 @@ public class NotificationAssistantsTest extends UiServiceTestCase {
mAssistants.readXml(parser, mNm::canUseManagedServices, false, USER_ALL);
}
- private void setDefaultAllowedAdjustmentKeyTypes(NotificationAssistants assistants) {
- assistants.setAssistantAdjustmentKeyTypeState(TYPE_OTHER, false);
- assistants.setAssistantAdjustmentKeyTypeState(TYPE_PROMOTION, false);
- assistants.setAssistantAdjustmentKeyTypeState(TYPE_SOCIAL_MEDIA, false);
- assistants.setAssistantAdjustmentKeyTypeState(TYPE_NEWS, false);
- assistants.setAssistantAdjustmentKeyTypeState(TYPE_CONTENT_RECOMMENDATION, false);
-
- for (int type : DEFAULT_ALLOWED_ADJUSTMENT_KEY_TYPES) {
- assistants.setAssistantAdjustmentKeyTypeState(type, true);
- }
- }
@Before
public void setUp() throws Exception {
@@ -181,9 +166,6 @@ public class NotificationAssistantsTest extends UiServiceTestCase {
com.android.internal.R.string.config_defaultAssistantAccessComponent,
mCn.flattenToString());
mAssistants = spy(mNm.new NotificationAssistants(mContext, mLock, mUserProfiles, miPm));
- if (notificationClassification()) {
- setDefaultAllowedAdjustmentKeyTypes(mAssistants);
- }
when(mNm.getBinderService()).thenReturn(mINm);
mContext.ensureTestableResources();
@@ -727,7 +709,7 @@ public class NotificationAssistantsTest extends UiServiceTestCase {
mAssistants.setAssistantAdjustmentKeyTypeState(TYPE_CONTENT_RECOMMENDATION, true);
assertThat(mAssistants.getAllowedAdjustmentKeyTypes()).asList()
- .containsExactly(TYPE_PROMOTION, TYPE_CONTENT_RECOMMENDATION);
+ .containsExactlyElementsIn(List.of(TYPE_PROMOTION, TYPE_CONTENT_RECOMMENDATION));
}
@Test
@@ -748,7 +730,7 @@ public class NotificationAssistantsTest extends UiServiceTestCase {
writeXmlAndReload(USER_ALL);
assertThat(mAssistants.getAllowedAdjustmentKeyTypes()).asList()
- .containsExactly(TYPE_NEWS, TYPE_CONTENT_RECOMMENDATION);
+ .containsExactlyElementsIn(List.of(TYPE_NEWS, TYPE_CONTENT_RECOMMENDATION));
}
@Test
@@ -765,168 +747,98 @@ public class NotificationAssistantsTest extends UiServiceTestCase {
@Test
@EnableFlags({android.service.notification.Flags.FLAG_NOTIFICATION_CLASSIFICATION,
android.app.Flags.FLAG_NOTIFICATION_CLASSIFICATION_UI})
- public void testGetPackagesWithKeyTypeAdjustmentSettings() throws Exception {
+ public void testGetTypeAdjustmentDeniedPackages() throws Exception {
String pkg = "my.package";
String pkg2 = "my.package.2";
- setDefaultAllowedAdjustmentKeyTypes(mAssistants);
- assertThat(mAssistants.isTypeAdjustmentAllowedForPackage(pkg, TYPE_PROMOTION)).isTrue();
- assertThat(mAssistants.getPackagesWithKeyTypeAdjustmentSettings()).isEmpty();
+ assertThat(mAssistants.isTypeAdjustmentAllowedForPackage(pkg)).isTrue();
+ assertThat(mAssistants.getTypeAdjustmentDeniedPackages()).isEmpty();
- mAssistants.setAssistantAdjustmentKeyTypeStateForPackage(pkg, TYPE_PROMOTION, true);
- assertThat(mAssistants.getPackagesWithKeyTypeAdjustmentSettings())
+ mAssistants.setTypeAdjustmentForPackageState(pkg, true);
+ assertThat(mAssistants.getTypeAdjustmentDeniedPackages()).isEmpty();
+ mAssistants.setTypeAdjustmentForPackageState(pkg, false);
+ assertThat(mAssistants.getTypeAdjustmentDeniedPackages()).asList()
.containsExactly(pkg);
- mAssistants.setAssistantAdjustmentKeyTypeStateForPackage(pkg, TYPE_PROMOTION, false);
- assertThat(mAssistants.getPackagesWithKeyTypeAdjustmentSettings())
+ mAssistants.setTypeAdjustmentForPackageState(pkg2, true);
+ assertThat(mAssistants.getTypeAdjustmentDeniedPackages()).asList()
.containsExactly(pkg);
- mAssistants.setAssistantAdjustmentKeyTypeStateForPackage(pkg2, TYPE_NEWS, true);
- mAssistants.setAssistantAdjustmentKeyTypeStateForPackage(pkg2, TYPE_PROMOTION, false);
- assertThat(mAssistants.getPackagesWithKeyTypeAdjustmentSettings())
+ mAssistants.setTypeAdjustmentForPackageState(pkg2, false);
+ assertThat(mAssistants.getTypeAdjustmentDeniedPackages()).asList()
.containsExactly(pkg, pkg2);
}
@Test
@EnableFlags(android.app.Flags.FLAG_NOTIFICATION_CLASSIFICATION_UI)
- public void testSetAssistantAdjustmentKeyTypeStateForPackage_usesGlobalDefault() {
- String pkg = "my.package";
- setDefaultAllowedAdjustmentKeyTypes(mAssistants);
- assertThat(mAssistants.isTypeAdjustmentAllowedForPackage(pkg, TYPE_PROMOTION)).isTrue();
- assertThat(mAssistants.isTypeAdjustmentAllowedForPackage(pkg, TYPE_NEWS)).isFalse();
- assertThat(mAssistants.getAllowedAdjustmentKeyTypesForPackage(pkg)).asList()
- .containsExactlyElementsIn(DEFAULT_ALLOWED_ADJUSTMENT_KEY_TYPES);
- }
-
- @Test
- @EnableFlags(android.app.Flags.FLAG_NOTIFICATION_CLASSIFICATION_UI)
- public void testSetAssistantAdjustmentKeyTypeStateForPackage_allowsAndDenies() {
- setDefaultAllowedAdjustmentKeyTypes(mAssistants);
- // Given that a package is set to have a type adjustment allowed,
- String pkg = "my.package";
- mAssistants.setAssistantAdjustmentKeyTypeStateForPackage(pkg, TYPE_NEWS, true);
+ public void testSetTypeAdjustmentForPackageState_allowsAndDenies() {
+ // Given that a package is allowed to have its type adjusted,
+ String allowedPackage = "allowed.package";
+ assertThat(mAssistants.getTypeAdjustmentDeniedPackages()).isEmpty();
+ mAssistants.setTypeAdjustmentForPackageState(allowedPackage, true);
- // The newly set state is the combination of the global default and the newly set type.
- assertThat(mAssistants.getAllowedAdjustmentKeyTypesForPackage(pkg)).asList()
- .containsExactly(TYPE_NEWS, TYPE_PROMOTION);
- assertThat(mAssistants.isTypeAdjustmentAllowedForPackage(pkg, TYPE_NEWS)).isTrue();
+ assertThat(mAssistants.getTypeAdjustmentDeniedPackages()).isEmpty();
+ assertTrue(mAssistants.isTypeAdjustmentAllowedForPackage(allowedPackage));
// Set type adjustment disallowed for this package
- mAssistants.setAssistantAdjustmentKeyTypeStateForPackage(pkg, TYPE_NEWS, false);
- mAssistants.setAssistantAdjustmentKeyTypeStateForPackage(pkg, TYPE_PROMOTION, false);
+ mAssistants.setTypeAdjustmentForPackageState(allowedPackage, false);
// Then the package is marked as denied
- assertThat(mAssistants.getAllowedAdjustmentKeyTypesForPackage(pkg)).isEmpty();
- assertThat(mAssistants.isTypeAdjustmentAllowedForPackage(pkg, TYPE_NEWS)).isFalse();
+ assertThat(mAssistants.getTypeAdjustmentDeniedPackages()).asList()
+ .containsExactly(allowedPackage);
+ assertFalse(mAssistants.isTypeAdjustmentAllowedForPackage(allowedPackage));
// Set type adjustment allowed again
- mAssistants.setAssistantAdjustmentKeyTypeStateForPackage(pkg, TYPE_NEWS, true);
- mAssistants.setAssistantAdjustmentKeyTypeStateForPackage(pkg, TYPE_PROMOTION, true);
+ mAssistants.setTypeAdjustmentForPackageState(allowedPackage, true);
// Then the package is marked as allowed again
- assertThat(mAssistants.getAllowedAdjustmentKeyTypesForPackage(pkg)).asList()
- .containsExactly(TYPE_NEWS, TYPE_PROMOTION);
- assertThat(mAssistants.isTypeAdjustmentAllowedForPackage(pkg, TYPE_NEWS)).isTrue();
- assertThat(mAssistants.isTypeAdjustmentAllowedForPackage(pkg, TYPE_PROMOTION)).isTrue();
-
- // Set type adjustment promotions false,
- mAssistants.setAssistantAdjustmentKeyTypeStateForPackage(pkg, TYPE_PROMOTION, false);
- assertThat(mAssistants.getAllowedAdjustmentKeyTypesForPackage(pkg)).asList()
- .containsExactly(TYPE_NEWS);
- assertThat(mAssistants.isTypeAdjustmentAllowedForPackage(pkg, TYPE_NEWS)).isTrue();
- assertThat(mAssistants.isTypeAdjustmentAllowedForPackage(pkg, TYPE_PROMOTION)).isFalse();
+ assertThat(mAssistants.getTypeAdjustmentDeniedPackages()).isEmpty();
+ assertTrue(mAssistants.isTypeAdjustmentAllowedForPackage(allowedPackage));
}
@Test
@EnableFlags(android.app.Flags.FLAG_NOTIFICATION_CLASSIFICATION_UI)
- public void testSetAssistantAdjustmentKeyTypeStateForPackage_allowsMultiplePkgs() {
- setDefaultAllowedAdjustmentKeyTypes(mAssistants);
- // Given packages allowed to have their type adjusted to TYPE_NEWS,
- String allowedPkg1 = "allowed.Pkg1";
- String allowedPkg2 = "allowed.Pkg2";
- String allowedPkg3 = "allowed.Pkg3";
- // Set type adjustment allowed for these packages
- mAssistants.setAssistantAdjustmentKeyTypeStateForPackage(allowedPkg1, TYPE_NEWS, true);
- mAssistants.setAssistantAdjustmentKeyTypeStateForPackage(allowedPkg2, TYPE_NEWS, true);
- mAssistants.setAssistantAdjustmentKeyTypeStateForPackage(allowedPkg3, TYPE_NEWS, true);
-
- // The newly set state is the combination of the global default and the newly set type.
- assertThat(mAssistants.getAllowedAdjustmentKeyTypesForPackage(allowedPkg1)).asList()
- .containsExactly(TYPE_NEWS, TYPE_PROMOTION);
- assertThat(mAssistants.getAllowedAdjustmentKeyTypesForPackage(allowedPkg2)).asList()
- .containsExactly(TYPE_NEWS, TYPE_PROMOTION);
- assertThat(mAssistants.getAllowedAdjustmentKeyTypesForPackage(allowedPkg3)).asList()
- .containsExactly(TYPE_NEWS, TYPE_PROMOTION);
- assertThat(mAssistants.isTypeAdjustmentAllowedForPackage(allowedPkg1, TYPE_NEWS)).isTrue();
- assertThat(mAssistants.isTypeAdjustmentAllowedForPackage(allowedPkg2, TYPE_NEWS)).isTrue();
- assertThat(mAssistants.isTypeAdjustmentAllowedForPackage(allowedPkg3, TYPE_NEWS)).isTrue();
-
- // And when we deny some of them,
- mAssistants.setAssistantAdjustmentKeyTypeStateForPackage(allowedPkg2, TYPE_NEWS, false);
- mAssistants.setAssistantAdjustmentKeyTypeStateForPackage(allowedPkg2, TYPE_PROMOTION,
- false);
- mAssistants.setAssistantAdjustmentKeyTypeStateForPackage(allowedPkg3, TYPE_PROMOTION,
- false);
-
- // Then the rest of the original packages are still marked as allowed.
- assertThat(mAssistants.getAllowedAdjustmentKeyTypesForPackage(allowedPkg1)).asList()
- .containsExactly(TYPE_NEWS, TYPE_PROMOTION);
- assertThat(mAssistants.getAllowedAdjustmentKeyTypesForPackage(allowedPkg2)).isEmpty();
- assertThat(mAssistants.getAllowedAdjustmentKeyTypesForPackage(allowedPkg3)).asList()
- .containsExactly(TYPE_NEWS);
- assertThat(mAssistants.isTypeAdjustmentAllowedForPackage(allowedPkg1, TYPE_NEWS)).isTrue();
- assertThat(mAssistants.isTypeAdjustmentAllowedForPackage(allowedPkg2, TYPE_NEWS)).isFalse();
- assertThat(mAssistants.isTypeAdjustmentAllowedForPackage(allowedPkg3, TYPE_NEWS)).isTrue();
+ public void testSetAssistantAdjustmentKeyTypeStateForPackage_deniesMultiple() {
+ // Given packages not allowed to have their type adjusted,
+ String deniedPkg1 = "denied.Pkg1";
+ String deniedPkg2 = "denied.Pkg2";
+ String deniedPkg3 = "denied.Pkg3";
+ // Set type adjustment disallowed for these packages
+ mAssistants.setTypeAdjustmentForPackageState(deniedPkg1, false);
+ mAssistants.setTypeAdjustmentForPackageState(deniedPkg2, false);
+ mAssistants.setTypeAdjustmentForPackageState(deniedPkg3, false);
+
+ // Then the packages are marked as denied
+ assertThat(mAssistants.getTypeAdjustmentDeniedPackages()).asList()
+ .containsExactlyElementsIn(List.of(deniedPkg1, deniedPkg2, deniedPkg3));
+ assertFalse(mAssistants.isTypeAdjustmentAllowedForPackage(deniedPkg1));
+ assertFalse(mAssistants.isTypeAdjustmentAllowedForPackage(deniedPkg2));
+ assertFalse(mAssistants.isTypeAdjustmentAllowedForPackage(deniedPkg3));
+
+ // And when we re-allow one of them,
+ mAssistants.setTypeAdjustmentForPackageState(deniedPkg2, true);
+
+ // Then the rest of the original packages are still marked as denied.
+ assertThat(mAssistants.getTypeAdjustmentDeniedPackages()).asList()
+ .containsExactlyElementsIn(List.of(deniedPkg1, deniedPkg3));
+ assertFalse(mAssistants.isTypeAdjustmentAllowedForPackage(deniedPkg1));
+ assertTrue(mAssistants.isTypeAdjustmentAllowedForPackage(deniedPkg2));
+ assertFalse(mAssistants.isTypeAdjustmentAllowedForPackage(deniedPkg3));
}
@Test
@EnableFlags(android.app.Flags.FLAG_NOTIFICATION_CLASSIFICATION_UI)
public void testSetAssistantAdjustmentKeyTypeStateForPackage_readWriteXml() throws Exception {
- setDefaultAllowedAdjustmentKeyTypes(mAssistants);
mAssistants.loadDefaultsFromConfig(true);
String deniedPkg1 = "denied.Pkg1";
String allowedPkg2 = "allowed.Pkg2";
- String allowedPkg3 = "allowed.Pkg3";
+ String deniedPkg3 = "denied.Pkg3";
// Set type adjustment disallowed or allowed for these packages
- mAssistants.setAssistantAdjustmentKeyTypeStateForPackage(deniedPkg1, TYPE_PROMOTION, false);
- mAssistants.setAssistantAdjustmentKeyTypeStateForPackage(allowedPkg2, TYPE_NEWS, true);
- mAssistants.setAssistantAdjustmentKeyTypeStateForPackage(allowedPkg3, TYPE_NEWS, true);
- mAssistants.setAssistantAdjustmentKeyTypeStateForPackage(allowedPkg3, TYPE_SOCIAL_MEDIA,
- true);
+ mAssistants.setTypeAdjustmentForPackageState(deniedPkg1, false);
+ mAssistants.setTypeAdjustmentForPackageState(allowedPkg2, true);
+ mAssistants.setTypeAdjustmentForPackageState(deniedPkg3, false);
writeXmlAndReload(USER_ALL);
- assertThat(mAssistants.getAllowedAdjustmentKeyTypesForPackage(deniedPkg1)).isEmpty();
- assertThat(mAssistants.getAllowedAdjustmentKeyTypesForPackage(allowedPkg2)).asList()
- .containsExactly(TYPE_NEWS, TYPE_PROMOTION);
- assertThat(mAssistants.getAllowedAdjustmentKeyTypesForPackage(allowedPkg3)).asList()
- .containsExactly(TYPE_NEWS, TYPE_SOCIAL_MEDIA, TYPE_PROMOTION);
- }
-
- @Test
- @EnableFlags(android.app.Flags.FLAG_NOTIFICATION_CLASSIFICATION_UI)
- public void testSetAssistantAdjustmentKeyTypeStateForPackage_noGlobalImpact() throws Exception {
- setDefaultAllowedAdjustmentKeyTypes(mAssistants);
- // When the global state is changed,
- mAssistants.setAssistantAdjustmentKeyTypeState(TYPE_NEWS, true);
-
- // The package state reflects the global state.
- String pkg = "my.package";
- assertThat(mAssistants.isTypeAdjustmentAllowedForPackage(pkg, TYPE_PROMOTION)).isTrue();
- assertThat(mAssistants.isTypeAdjustmentAllowedForPackage(pkg, TYPE_NEWS)).isTrue();
- assertThat(mAssistants.getAllowedAdjustmentKeyTypesForPackage(pkg)).asList()
- .containsExactly(TYPE_NEWS, TYPE_PROMOTION);
-
- // Once the package specific state is modified,
- mAssistants.setAssistantAdjustmentKeyTypeStateForPackage(pkg, TYPE_SOCIAL_MEDIA, true);
-
- // The package specific state combines the global state with those modifications
- assertThat(mAssistants.isTypeAdjustmentAllowedForPackage(pkg, TYPE_SOCIAL_MEDIA)).isTrue();
- assertThat(mAssistants.getAllowedAdjustmentKeyTypesForPackage(pkg)).asList()
- .containsExactly(TYPE_NEWS, TYPE_PROMOTION, TYPE_SOCIAL_MEDIA);
-
- // And further changes to the global state are ignored.
- mAssistants.setAssistantAdjustmentKeyTypeState(TYPE_NEWS, false);
- assertThat(mAssistants.isTypeAdjustmentAllowedForPackage(pkg, TYPE_NEWS)).isTrue();
- assertThat(mAssistants.getAllowedAdjustmentKeyTypesForPackage(pkg)).asList()
- .containsExactly(TYPE_NEWS, TYPE_PROMOTION, TYPE_SOCIAL_MEDIA);
+ assertThat(mAssistants.getTypeAdjustmentDeniedPackages()).asList()
+ .containsExactlyElementsIn(List.of(deniedPkg1, deniedPkg3));
}
@Test
diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
index fdb6a6802b7e..85c592084acf 100644
--- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
+++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
@@ -369,9 +369,6 @@ import org.mockito.MockitoAnnotations;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
-import platform.test.runner.parameterized.ParameterizedAndroidJunit4;
-import platform.test.runner.parameterized.Parameters;
-
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
@@ -387,6 +384,9 @@ import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.function.Consumer;
+import platform.test.runner.parameterized.ParameterizedAndroidJunit4;
+import platform.test.runner.parameterized.Parameters;
+
@SmallTest
@RunWith(ParameterizedAndroidJunit4.class)
@RunWithLooper
@@ -7662,7 +7662,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
when(mAssistants.isSameUser(any(), anyInt())).thenReturn(true);
when(mAssistants.isServiceTokenValidLocked(any())).thenReturn(true);
when(mAssistants.isAdjustmentKeyTypeAllowed(anyInt())).thenReturn(true);
- when(mAssistants.isTypeAdjustmentAllowedForPackage(anyString(), anyInt())).thenReturn(true);
+ when(mAssistants.isTypeAdjustmentAllowedForPackage(anyString())).thenReturn(true);
// Set up notifications that will be adjusted
final NotificationRecord r1 = spy(generateNotificationRecord(
@@ -17512,7 +17512,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
NotificationManagerService.WorkerHandler.class);
mService.setHandler(handler);
when(mAssistants.isAdjustmentKeyTypeAllowed(anyInt())).thenReturn(true);
- when(mAssistants.isTypeAdjustmentAllowedForPackage(anyString(), anyInt())).thenReturn(true);
+ when(mAssistants.isTypeAdjustmentAllowedForPackage(anyString())).thenReturn(true);
Bundle signals = new Bundle();
signals.putInt(KEY_TYPE, TYPE_NEWS);
@@ -17556,11 +17556,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
NotificationManagerService.WorkerHandler.class);
mService.setHandler(handler);
when(mAssistants.isAdjustmentKeyTypeAllowed(anyInt())).thenReturn(true);
- when(mAssistants.isTypeAdjustmentAllowedForPackage(anyString(), eq(TYPE_NEWS)))
- .thenReturn(true);
- // Blocking adjustments for a different type does nothing
- when(mAssistants.isTypeAdjustmentAllowedForPackage(anyString(), eq(TYPE_PROMOTION)))
- .thenReturn(false);
+ when(mAssistants.isTypeAdjustmentAllowedForPackage(anyString())).thenReturn(true);
Bundle signals = new Bundle();
signals.putInt(KEY_TYPE, TYPE_NEWS);
@@ -17575,9 +17571,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
assertThat(r.getChannel().getId()).isEqualTo(NEWS_ID);
- // When we block adjustments for this package/type
- when(mAssistants.isTypeAdjustmentAllowedForPackage(anyString(), eq(TYPE_PROMOTION)))
- .thenReturn(false);
+ // When we block adjustments for this package
+ when(mAssistants.isTypeAdjustmentAllowedForPackage(anyString())).thenReturn(false);
signals.putInt(KEY_TYPE, TYPE_PROMOTION);
mBinderService.applyAdjustmentFromAssistant(null, adjustment);
@@ -17907,7 +17902,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
when(mAssistants.isSameUser(any(), anyInt())).thenReturn(true);
when(mAssistants.isServiceTokenValidLocked(any())).thenReturn(true);
when(mAssistants.isAdjustmentKeyTypeAllowed(anyInt())).thenReturn(true);
- when(mAssistants.isTypeAdjustmentAllowedForPackage(anyString(), anyInt())).thenReturn(true);
+ when(mAssistants.isTypeAdjustmentAllowedForPackage(anyString())).thenReturn(true);
// Post a single notification
final boolean hasOriginalSummary = false;
@@ -17947,7 +17942,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
when(mAssistants.isSameUser(any(), anyInt())).thenReturn(true);
when(mAssistants.isServiceTokenValidLocked(any())).thenReturn(true);
when(mAssistants.isAdjustmentKeyTypeAllowed(anyInt())).thenReturn(true);
- when(mAssistants.isTypeAdjustmentAllowedForPackage(anyString(), anyInt())).thenReturn(true);
+ when(mAssistants.isTypeAdjustmentAllowedForPackage(anyString())).thenReturn(true);
// Post grouped notifications
final String originalGroupName = "originalGroup";
@@ -17996,7 +17991,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
when(mAssistants.isSameUser(any(), anyInt())).thenReturn(true);
when(mAssistants.isServiceTokenValidLocked(any())).thenReturn(true);
when(mAssistants.isAdjustmentKeyTypeAllowed(anyInt())).thenReturn(true);
- when(mAssistants.isTypeAdjustmentAllowedForPackage(anyString(), anyInt())).thenReturn(true);
+ when(mAssistants.isTypeAdjustmentAllowedForPackage(anyString())).thenReturn(true);
// Post grouped notifications
final String originalGroupName = "originalGroup";
@@ -18047,7 +18042,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
when(mAssistants.isSameUser(any(), anyInt())).thenReturn(true);
when(mAssistants.isServiceTokenValidLocked(any())).thenReturn(true);
when(mAssistants.isAdjustmentKeyTypeAllowed(anyInt())).thenReturn(true);
- when(mAssistants.isTypeAdjustmentAllowedForPackage(anyString(), anyInt())).thenReturn(true);
+ when(mAssistants.isTypeAdjustmentAllowedForPackage(anyString())).thenReturn(true);
// Post a single notification
final boolean hasOriginalSummary = false;