summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Iavor-Valentin Iftime <valiiftime@google.com> 2023-11-22 17:25:54 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2023-11-22 17:25:54 +0000
commit59575e7a94c9075fa93acea0b5bc9a5be9f0aad9 (patch)
tree330f374b5184e782a8bedb01619cf3465755d426
parent71deafd46bb95563e86ed15d52e1f7a5026b55ce (diff)
parentaa3f558311f38350569933404480852e8e8c2bfe (diff)
Merge "Cleanup user-set NLS list on package removed" into main
-rw-r--r--services/core/java/com/android/server/notification/ManagedServices.java15
-rw-r--r--services/tests/uiservicestests/src/com/android/server/notification/ManagedServicesTest.java20
2 files changed, 35 insertions, 0 deletions
diff --git a/services/core/java/com/android/server/notification/ManagedServices.java b/services/core/java/com/android/server/notification/ManagedServices.java
index fe91050917f5..d0c054307d0c 100644
--- a/services/core/java/com/android/server/notification/ManagedServices.java
+++ b/services/core/java/com/android/server/notification/ManagedServices.java
@@ -1249,6 +1249,21 @@ abstract public class ManagedServices {
}
}
}
+ // Remove uninstalled components from user-set list
+ final ArraySet<String> userSet = mUserSetServices.get(uninstalledUserId);
+ if (userSet != null) {
+ int numServices = userSet.size();
+ for (int i = numServices - 1; i >= 0; i--) {
+ String pkgOrComponent = userSet.valueAt(i);
+ if (TextUtils.equals(pkg, getPackageName(pkgOrComponent))) {
+ userSet.removeAt(i);
+ if (DEBUG) {
+ Slog.v(TAG, "Removing " + pkgOrComponent
+ + " from user-set list; uninstalled");
+ }
+ }
+ }
+ }
}
return removed;
}
diff --git a/services/tests/uiservicestests/src/com/android/server/notification/ManagedServicesTest.java b/services/tests/uiservicestests/src/com/android/server/notification/ManagedServicesTest.java
index 213681172882..344a4b0ce324 100644
--- a/services/tests/uiservicestests/src/com/android/server/notification/ManagedServicesTest.java
+++ b/services/tests/uiservicestests/src/com/android/server/notification/ManagedServicesTest.java
@@ -1077,6 +1077,26 @@ public class ManagedServicesTest extends UiServiceTestCase {
}
@Test
+ public void testPackageUninstall_componentNoLongerUserSetList() throws Exception {
+ final String pkg = "this.is.a.package.name";
+ final String component = pkg + "/Ba";
+ for (int approvalLevel : new int[] { APPROVAL_BY_COMPONENT, APPROVAL_BY_PACKAGE}) {
+ ManagedServices service = new TestManagedServices(getContext(), mLock, mUserProfiles,
+ mIpm, approvalLevel);
+ writeExpectedValuesToSettings(approvalLevel);
+ service.migrateToXml();
+
+ final String verifyValue = (approvalLevel == APPROVAL_BY_COMPONENT) ? component : pkg;
+
+ assertThat(service.isPackageOrComponentAllowed(verifyValue, 0)).isTrue();
+ assertThat(service.isPackageOrComponentUserSet(verifyValue, 0)).isTrue();
+
+ service.onPackagesChanged(true, new String[]{pkg}, new int[]{103});
+ assertThat(service.isPackageOrComponentUserSet(verifyValue, 0)).isFalse();
+ }
+ }
+
+ @Test
public void testIsPackageAllowed() {
for (int approvalLevel : new int[] {APPROVAL_BY_COMPONENT, APPROVAL_BY_PACKAGE}) {
ManagedServices service = new TestManagedServices(getContext(), mLock, mUserProfiles,