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

Commit f531147a authored by Hai Zhang's avatar Hai Zhang Committed by android-build-merger
Browse files

Merge "Exclude packages that's not installed from the hash for role." into qt-dev

am: c3c75a49

Change-Id: Ie93cc1d841c572ff841efcd96c7bdf47ad19df25
parents 63358485 c3c75a49
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
@@ -24783,6 +24783,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) {
@@ -25075,6 +25081,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());
    }