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

Commit eb8b460c authored by Hai Zhang's avatar Hai Zhang
Browse files

Exclude packages that's not installed from the hash for role.

Otherwise we won't detect the change when a package is set to
installed for an user.

Also added the number of enabled components to the hash so that when
an enabled component get disabled but the order didn't change, we can
still detect the change.

Fixes: 129004850
Test: follow the repro step in b/129004850 and confirm it's fixed
Change-Id: I87d62daf0f6a4d34939ee03ee783e9bdb19bf558
parent 09c5edd7
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -844,6 +844,13 @@ public abstract class PackageManagerInternal {
     */
    public abstract void forEachPackage(Consumer<PackageParser.Package> actionLocked);

    /**
     * Perform the given action for each installed package for a user.
     * Note that packages lock will be held while performin the actions.
     */
    public abstract void forEachInstalledPackage(
            @NonNull Consumer<PackageParser.Package> actionLocked, @UserIdInt int userId);

    /** Returns the list of enabled components */
    public abstract ArraySet<String> getEnabledComponents(String packageName, int userId);

+21 −0
Original line number Diff line number Diff line
@@ -24766,6 +24766,12 @@ public class PackageManagerService extends IPackageManager.Stub
            PackageManagerService.this.forEachPackage(actionLocked);
        }
        @Override
        public void forEachInstalledPackage(@NonNull Consumer<PackageParser.Package> actionLocked,
                @UserIdInt int userId) {
            PackageManagerService.this.forEachInstalledPackage(actionLocked, userId);
        }
        @Override
        public ArraySet<String> getEnabledComponents(String packageName, int userId) {
            synchronized (mPackages) {
@@ -25058,6 +25064,21 @@ public class PackageManagerService extends IPackageManager.Stub
        }
    }
    void forEachInstalledPackage(@NonNull Consumer<PackageParser.Package> actionLocked,
            @UserIdInt int userId) {
        synchronized (mPackages) {
            int numPackages = mPackages.size();
            for (int i = 0; i < numPackages; i++) {
                PackageParser.Package pkg = mPackages.valueAt(i);
                PackageSetting setting = mSettings.getPackageLPr(pkg.packageName);
                if (setting == null || !setting.getInstalled(userId)) {
                    continue;
                }
                actionLocked.accept(pkg);
            }
        }
    }
    private static void enforceSystemOrPhoneCaller(String tag) {
        int callingUid = Binder.getCallingUid();
        if (callingUid != Process.PHONE_UID && callingUid != Process.SYSTEM_UID) {
+3 −2
Original line number Diff line number Diff line
@@ -280,7 +280,7 @@ public class RoleManagerService extends SystemService implements RoleUserState.C
        PackageManagerInternal pm = LocalServices.getService(PackageManagerInternal.class);
        ByteArrayOutputStream out = new ByteArrayOutputStream();

        pm.forEachPackage(FunctionalUtils.uncheckExceptions(pkg -> {
        pm.forEachInstalledPackage(FunctionalUtils.uncheckExceptions(pkg -> {
            out.write(pkg.packageName.getBytes());
            out.write(BitUtils.toBytes(pkg.getLongVersionCode()));
            out.write(pm.getApplicationEnabledState(pkg.packageName, userId));
@@ -288,6 +288,7 @@ public class RoleManagerService extends SystemService implements RoleUserState.C
            ArraySet<String> enabledComponents =
                    pm.getEnabledComponents(pkg.packageName, userId);
            int numComponents = CollectionUtils.size(enabledComponents);
            out.write(numComponents);
            for (int i = 0; i < numComponents; i++) {
                out.write(enabledComponents.valueAt(i).getBytes());
            }
@@ -301,7 +302,7 @@ public class RoleManagerService extends SystemService implements RoleUserState.C
            for (Signature signature : pkg.mSigningDetails.signatures) {
                out.write(signature.toByteArray());
            }
        }));
        }), userId);

        return PackageUtils.computeSha256Digest(out.toByteArray());
    }