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

Commit aa3f5583 authored by Valentin Iftime's avatar Valentin Iftime
Browse files

Cleanup user-set NLS list on package removed

 Remove the NLS components of the deleted package from the user-set list.

Test: atest ManagedServicesTest
Bug: 306041680
Change-Id: Ibd585dd1af6c3bc3bd8a7c0c5101d24732947ff8
parent 54fb3a04
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}) {