Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 59575e7a authored by Iavor-Valentin Iftime's avatar Iavor-Valentin Iftime Committed by Android (Google) Code Review
Browse files

Merge "Cleanup user-set NLS list on package removed" into main

parents 71deafd4 aa3f5583
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -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;
    }
+20 −0
Original line number Diff line number Diff line
@@ -1076,6 +1076,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}) {