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

Commit 068f0057 authored by Winson Chiu's avatar Winson Chiu Committed by Android (Google) Code Review
Browse files

Merge changes Ibdea719c,Ib53ad5f9

* changes:
  Remove PackageInfo from ApexPackageInfo
  Make PackageImpl SigningDetails non-null
parents ff195e8a 86b4d6cf
Loading
Loading
Loading
Loading
+98 −91
Original line number Original line Diff line number Diff line
@@ -22,10 +22,9 @@ import static com.android.server.pm.ApexManager.MATCH_FACTORY_PACKAGE;
import android.annotation.NonNull;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Nullable;
import android.apex.ApexInfo;
import android.apex.ApexInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager;
import android.util.ArrayMap;
import android.util.ArrayMap;
import android.util.Pair;
import android.util.PrintWriterPrinter;
import android.util.PrintWriterPrinter;


import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.GuardedBy;
@@ -33,8 +32,9 @@ import com.android.internal.util.IndentingPrintWriter;
import com.android.internal.util.Preconditions;
import com.android.internal.util.Preconditions;
import com.android.server.pm.parsing.PackageParser2;
import com.android.server.pm.parsing.PackageParser2;
import com.android.server.pm.parsing.pkg.AndroidPackage;
import com.android.server.pm.parsing.pkg.AndroidPackage;
import com.android.server.pm.parsing.pkg.AndroidPackageUtils;
import com.android.server.pm.parsing.pkg.ParsedPackage;
import com.android.server.pm.parsing.pkg.ParsedPackage;
import com.android.server.pm.pkg.parsing.PackageInfoWithoutStateUtils;
import com.android.server.pm.pkg.PackageStateInternal;
import com.android.server.pm.pkg.parsing.ParsingPackageUtils;
import com.android.server.pm.pkg.parsing.ParsingPackageUtils;


import java.io.File;
import java.io.File;
@@ -59,17 +59,7 @@ class ApexPackageInfo {
    private final Object mLock = new Object();
    private final Object mLock = new Object();


    @GuardedBy("mLock")
    @GuardedBy("mLock")
    private List<PackageInfo> mAllPackagesCache;
    private List<Pair<ApexInfo, AndroidPackage>> mAllPackagesCache;

    /**
     * Whether an APEX package is active or not.
     *
     * @param packageInfo the package to check
     * @return {@code true} if this package is active, {@code false} otherwise.
     */
    private static boolean isActive(PackageInfo packageInfo) {
        return packageInfo.isActiveApex;
    }


    /**
    /**
     * Called by package manager service to scan apex package files when device boots up.
     * Called by package manager service to scan apex package files when device boots up.
@@ -105,20 +95,23 @@ class ApexPackageInfo {
     *         is not found.
     *         is not found.
     */
     */
    @Nullable
    @Nullable
    PackageInfo getPackageInfo(String packageName, @ApexManager.PackageInfoFlags int flags) {
    Pair<ApexInfo, AndroidPackage> getPackageInfo(String packageName,
            @ApexManager.PackageInfoFlags int flags) {
        synchronized (mLock) {
        synchronized (mLock) {
            Preconditions.checkState(mAllPackagesCache != null,
            Preconditions.checkState(mAllPackagesCache != null,
                    "APEX packages have not been scanned");
                    "APEX packages have not been scanned");
            boolean matchActive = (flags & MATCH_ACTIVE_PACKAGE) != 0;
            boolean matchActive = (flags & MATCH_ACTIVE_PACKAGE) != 0;
            boolean matchFactory = (flags & MATCH_FACTORY_PACKAGE) != 0;
            boolean matchFactory = (flags & MATCH_FACTORY_PACKAGE) != 0;
            for (int i = 0, size = mAllPackagesCache.size(); i < size; i++) {
            for (int i = 0, size = mAllPackagesCache.size(); i < size; i++) {
                final PackageInfo packageInfo = mAllPackagesCache.get(i);
                final Pair<ApexInfo, AndroidPackage> pair = mAllPackagesCache.get(i);
                if (!packageInfo.packageName.equals(packageName)) {
                var apexInfo = pair.first;
                var pkg = pair.second;
                if (!pkg.getPackageName().equals(packageName)) {
                    continue;
                    continue;
                }
                }
                if ((matchActive && isActive(packageInfo))
                if ((matchActive && apexInfo.isActive)
                        || (matchFactory && isFactory(packageInfo))) {
                        || (matchFactory && apexInfo.isFactory)) {
                    return packageInfo;
                    return pair;
                }
                }
            }
            }
            return null;
            return null;
@@ -128,18 +121,18 @@ class ApexPackageInfo {
    /**
    /**
     * Retrieves information about all active APEX packages.
     * Retrieves information about all active APEX packages.
     *
     *
     * @return a List of PackageInfo object, each one containing information about a different
     * @return list containing information about different active packages.
     *         active package.
     */
     */
    List<PackageInfo> getActivePackages() {
    @NonNull
    List<Pair<ApexInfo, AndroidPackage>> getActivePackages() {
        synchronized (mLock) {
        synchronized (mLock) {
            Preconditions.checkState(mAllPackagesCache != null,
            Preconditions.checkState(mAllPackagesCache != null,
                    "APEX packages have not been scanned");
                    "APEX packages have not been scanned");
            final List<PackageInfo> activePackages = new ArrayList<>();
            final List<Pair<ApexInfo, AndroidPackage>> activePackages = new ArrayList<>();
            for (int i = 0; i < mAllPackagesCache.size(); i++) {
            for (int i = 0; i < mAllPackagesCache.size(); i++) {
                final PackageInfo packageInfo = mAllPackagesCache.get(i);
                final var pair = mAllPackagesCache.get(i);
                if (isActive(packageInfo)) {
                if (pair.first.isActive) {
                    activePackages.add(packageInfo);
                    activePackages.add(pair);
                }
                }
            }
            }
            return activePackages;
            return activePackages;
@@ -147,20 +140,20 @@ class ApexPackageInfo {
    }
    }


    /**
    /**
     * Retrieves information about all active pre-installed APEX packages.
     * Retrieves information about all pre-installed APEX packages.
     *
     *
     * @return a List of PackageInfo object, each one containing information about a different
     * @return list containing information about different pre-installed packages.
     *         active pre-installed package.
     */
     */
    List<PackageInfo> getFactoryPackages() {
    @NonNull
    List<Pair<ApexInfo, AndroidPackage>> getFactoryPackages() {
        synchronized (mLock) {
        synchronized (mLock) {
            Preconditions.checkState(mAllPackagesCache != null,
            Preconditions.checkState(mAllPackagesCache != null,
                    "APEX packages have not been scanned");
                    "APEX packages have not been scanned");
            final List<PackageInfo> factoryPackages = new ArrayList<>();
            final List<Pair<ApexInfo, AndroidPackage>> factoryPackages = new ArrayList<>();
            for (int i = 0; i < mAllPackagesCache.size(); i++) {
            for (int i = 0; i < mAllPackagesCache.size(); i++) {
                final PackageInfo packageInfo = mAllPackagesCache.get(i);
                final var pair = mAllPackagesCache.get(i);
                if (isFactory(packageInfo)) {
                if (pair.first.isFactory) {
                    factoryPackages.add(packageInfo);
                    factoryPackages.add(pair);
                }
                }
            }
            }
            return factoryPackages;
            return factoryPackages;
@@ -170,18 +163,18 @@ class ApexPackageInfo {
    /**
    /**
     * Retrieves information about all inactive APEX packages.
     * Retrieves information about all inactive APEX packages.
     *
     *
     * @return a List of PackageInfo object, each one containing information about a different
     * @return list containing information about different inactive packages.
     *         inactive package.
     */
     */
    List<PackageInfo> getInactivePackages() {
    @NonNull
    List<Pair<ApexInfo, AndroidPackage>> getInactivePackages() {
        synchronized (mLock) {
        synchronized (mLock) {
            Preconditions.checkState(mAllPackagesCache != null,
            Preconditions.checkState(mAllPackagesCache != null,
                    "APEX packages have not been scanned");
                    "APEX packages have not been scanned");
            final List<PackageInfo> inactivePackages = new ArrayList<>();
            final List<Pair<ApexInfo, AndroidPackage>> inactivePackages = new ArrayList<>();
            for (int i = 0; i < mAllPackagesCache.size(); i++) {
            for (int i = 0; i < mAllPackagesCache.size(); i++) {
                final PackageInfo packageInfo = mAllPackagesCache.get(i);
                final var pair = mAllPackagesCache.get(i);
                if (!isActive(packageInfo)) {
                if (!pair.first.isActive) {
                    inactivePackages.add(packageInfo);
                    inactivePackages.add(pair);
                }
                }
            }
            }
            return inactivePackages;
            return inactivePackages;
@@ -199,8 +192,8 @@ class ApexPackageInfo {
            Preconditions.checkState(mAllPackagesCache != null,
            Preconditions.checkState(mAllPackagesCache != null,
                    "APEX packages have not been scanned");
                    "APEX packages have not been scanned");
            for (int i = 0, size = mAllPackagesCache.size(); i < size; i++) {
            for (int i = 0, size = mAllPackagesCache.size(); i < size; i++) {
                final PackageInfo packageInfo = mAllPackagesCache.get(i);
                final var pair = mAllPackagesCache.get(i);
                if (packageInfo.packageName.equals(packageName)) {
                if (pair.second.getPackageName().equals(packageName)) {
                    return true;
                    return true;
                }
                }
            }
            }
@@ -222,21 +215,18 @@ class ApexPackageInfo {
    }
    }


    void notifyPackageInstalled(ApexInfo apexInfo, AndroidPackage pkg) {
    void notifyPackageInstalled(ApexInfo apexInfo, AndroidPackage pkg) {
        final int flags = PackageManager.GET_META_DATA
        final String packageName = pkg.getPackageName();
                | PackageManager.GET_SIGNING_CERTIFICATES
                | PackageManager.GET_SIGNATURES;
        final PackageInfo newApexPkg = PackageInfoWithoutStateUtils.generate(
                pkg, apexInfo, flags);
        final String packageName = newApexPkg.packageName;
        synchronized (mLock) {
        synchronized (mLock) {
            for (int i = 0, size = mAllPackagesCache.size(); i < size; i++) {
            for (int i = 0, size = mAllPackagesCache.size(); i < size; i++) {
                PackageInfo oldApexPkg = mAllPackagesCache.get(i);
                var pair = mAllPackagesCache.get(i);
                if (oldApexPkg.isActiveApex && oldApexPkg.packageName.equals(packageName)) {
                var oldApexInfo = pair.first;
                    if (isFactory(oldApexPkg)) {
                var oldApexPkg = pair.second;
                        oldApexPkg.isActiveApex = false;
                if (oldApexInfo.isActive && oldApexPkg.getPackageName().equals(packageName)) {
                        mAllPackagesCache.add(newApexPkg);
                    if (oldApexInfo.isFactory) {
                        oldApexInfo.isActive = false;
                        mAllPackagesCache.add(Pair.create(apexInfo, pkg));
                    } else {
                    } else {
                        mAllPackagesCache.set(i, newApexPkg);
                        mAllPackagesCache.set(i, Pair.create(apexInfo, pkg));
                    }
                    }
                    break;
                    break;
                }
                }
@@ -244,16 +234,6 @@ class ApexPackageInfo {
        }
        }
    }
    }


    /**
     * Whether the APEX package is pre-installed or not.
     *
     * @param packageInfo the package to check
     * @return {@code true} if this package is pre-installed, {@code false} otherwise.
     */
    private static boolean isFactory(@NonNull PackageInfo packageInfo) {
        return (packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == 0;
    }

    /**
    /**
     * Dumps various state information to the provided {@link PrintWriter} object.
     * Dumps various state information to the provided {@link PrintWriter} object.
     *
     *
@@ -288,33 +268,25 @@ class ApexPackageInfo {
        HashSet<String> factoryPackagesSet = new HashSet<>();
        HashSet<String> factoryPackagesSet = new HashSet<>();
        for (ApexManager.ScanResult result : scanResults) {
        for (ApexManager.ScanResult result : scanResults) {
            ApexInfo ai = result.apexInfo;
            ApexInfo ai = result.apexInfo;

            String packageName = result.pkg.getPackageName();
            final PackageInfo packageInfo = PackageInfoWithoutStateUtils.generate(
            if (!packageName.equals(result.packageName)) {
                    result.pkg, ai, flags);
            if (packageInfo == null) {
                throw new IllegalStateException("Unable to generate package info: "
                        + ai.modulePath);
            }
            if (!packageInfo.packageName.equals(result.packageName)) {
                throw new IllegalStateException("Unmatched package name: "
                throw new IllegalStateException("Unmatched package name: "
                        + result.packageName + " != " + packageInfo.packageName
                        + result.packageName + " != " + packageName
                        + ", path=" + ai.modulePath);
                        + ", path=" + ai.modulePath);
            }
            }
            mAllPackagesCache.add(packageInfo);
            mAllPackagesCache.add(Pair.create(ai, result.pkg));
            if (ai.isActive) {
            if (ai.isActive) {
                if (!activePackagesSet.add(packageInfo.packageName)) {
                if (!activePackagesSet.add(packageName)) {
                    throw new IllegalStateException(
                    throw new IllegalStateException(
                            "Two active packages have the same name: "
                            "Two active packages have the same name: " + packageName);
                                    + packageInfo.packageName);
                }
                }
            }
            }
            if (ai.isFactory) {
            if (ai.isFactory) {
                // Don't throw when the duplicating APEX is VNDK APEX
                // Don't throw when the duplicating APEX is VNDK APEX
                if (!factoryPackagesSet.add(packageInfo.packageName)
                if (!factoryPackagesSet.add(packageName)
                        && !ai.moduleName.startsWith(VNDK_APEX_MODULE_NAME_PREFIX)) {
                        && !ai.moduleName.startsWith(VNDK_APEX_MODULE_NAME_PREFIX)) {
                    throw new IllegalStateException(
                    throw new IllegalStateException(
                            "Two factory packages have the same name: "
                            "Two factory packages have the same name: " + packageName);
                                    + packageInfo.packageName);
                }
                }
            }
            }
        }
        }
@@ -362,6 +334,37 @@ class ApexPackageInfo {
        return results;
        return results;
    }
    }


    /**
     * @see #dumpPackages(List, String, IndentingPrintWriter)
     */
    static void dumpPackageStates(List<PackageStateInternal> packageStates, boolean isActive,
            @Nullable String packageName, IndentingPrintWriter ipw) {
        ipw.println();
        ipw.increaseIndent();
        for (int i = 0, size = packageStates.size(); i < size; i++) {
            final var packageState = packageStates.get(i);
            var pkg = packageState.getPkg();
            if (packageName != null && !packageName.equals(pkg.getPackageName())) {
                continue;
            }
            ipw.println(pkg.getPackageName());
            ipw.increaseIndent();
            ipw.println("Version: " + pkg.getLongVersionCode());
            ipw.println("Path: " + pkg.getBaseApkPath());
            ipw.println("IsActive: " + isActive);
            ipw.println("IsFactory: " + !packageState.isUpdatedSystemApp());
            ipw.println("ApplicationInfo: ");
            ipw.increaseIndent();
            // TODO: Dump the package manually
            AndroidPackageUtils.generateAppInfoWithoutState(pkg)
                    .dump(new PrintWriterPrinter(ipw), "");
            ipw.decreaseIndent();
            ipw.decreaseIndent();
        }
        ipw.decreaseIndent();
        ipw.println();
    }

    /**
    /**
     * Dump information about the packages contained in a particular cache
     * Dump information about the packages contained in a particular cache
     * @param packagesCache the cache to print information about.
     * @param packagesCache the cache to print information about.
@@ -369,24 +372,28 @@ class ApexPackageInfo {
     *                    only information about that specific package will be dumped.
     *                    only information about that specific package will be dumped.
     * @param ipw the {@link IndentingPrintWriter} object to send information to.
     * @param ipw the {@link IndentingPrintWriter} object to send information to.
     */
     */
    static void dumpPackages(List<PackageInfo> packagesCache,
    static void dumpPackages(List<Pair<ApexInfo, AndroidPackage>> packagesCache,
            @Nullable String packageName, IndentingPrintWriter ipw) {
            @Nullable String packageName, IndentingPrintWriter ipw) {
        ipw.println();
        ipw.println();
        ipw.increaseIndent();
        ipw.increaseIndent();
        for (int i = 0, size = packagesCache.size(); i < size; i++) {
        for (int i = 0, size = packagesCache.size(); i < size; i++) {
            final PackageInfo pi = packagesCache.get(i);
            final var pair = packagesCache.get(i);
            if (packageName != null && !packageName.equals(pi.packageName)) {
            var apexInfo = pair.first;
            var pkg = pair.second;
            if (packageName != null && !packageName.equals(pkg.getPackageName())) {
                continue;
                continue;
            }
            }
            ipw.println(pi.packageName);
            ipw.println(pkg.getPackageName());
            ipw.increaseIndent();
            ipw.increaseIndent();
            ipw.println("Version: " + pi.versionCode);
            ipw.println("Version: " + pkg.getLongVersionCode());
            ipw.println("Path: " + pi.applicationInfo.sourceDir);
            ipw.println("Path: " + pkg.getBaseApkPath());
            ipw.println("IsActive: " + isActive(pi));
            ipw.println("IsActive: " + apexInfo.isActive);
            ipw.println("IsFactory: " + isFactory(pi));
            ipw.println("IsFactory: " + apexInfo.isFactory);
            ipw.println("ApplicationInfo: ");
            ipw.println("ApplicationInfo: ");
            ipw.increaseIndent();
            ipw.increaseIndent();
            pi.applicationInfo.dump(new PrintWriterPrinter(ipw), "");
            // TODO: Dump the package manually
            AndroidPackageUtils.generateAppInfoWithoutState(pkg)
                    .dump(new PrintWriterPrinter(ipw), "");
            ipw.decreaseIndent();
            ipw.decreaseIndent();
            ipw.decreaseIndent();
            ipw.decreaseIndent();
        }
        }
+42 −28
Original line number Original line Diff line number Diff line
@@ -65,6 +65,7 @@ import android.Manifest;
import android.annotation.NonNull;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Nullable;
import android.annotation.UserIdInt;
import android.annotation.UserIdInt;
import android.apex.ApexInfo;
import android.app.ActivityManager;
import android.app.ActivityManager;
import android.content.ComponentName;
import android.content.ComponentName;
import android.content.Context;
import android.content.Context;
@@ -1018,11 +1019,12 @@ public class ComputerEngine implements Computer {
                if ((flags & PackageManager.MATCH_SYSTEM_ONLY) != 0) {
                if ((flags & PackageManager.MATCH_SYSTEM_ONLY) != 0) {
                    apexFlags = ApexManager.MATCH_FACTORY_PACKAGE;
                    apexFlags = ApexManager.MATCH_FACTORY_PACKAGE;
                }
                }
                final PackageInfo pi = mApexPackageInfo.getPackageInfo(packageName, apexFlags);
                final var pair = mApexPackageInfo.getPackageInfo(packageName, apexFlags);
                if (pi == null) {
                if (pair == null) {
                    return null;
                    return null;
                }
                }
                return pi.applicationInfo;
                return PackageInfoUtils.generateApplicationInfo(pair.second, flags,
                        PackageUserStateInternal.DEFAULT, userId, null);
            }
            }
        }
        }
        if ("android".equals(packageName) || "system".equals(packageName)) {
        if ("android".equals(packageName) || "system".equals(packageName)) {
@@ -1718,8 +1720,12 @@ public class ComputerEngine implements Computer {
            // Instant app filtering for APEX modules is ignored
            // Instant app filtering for APEX modules is ignored
            if (!ApexPackageInfo.ENABLE_FEATURE_SCAN_APEX) {
            if (!ApexPackageInfo.ENABLE_FEATURE_SCAN_APEX) {
                if (matchApex) {
                if (matchApex) {
                    return mApexPackageInfo.getPackageInfo(packageName,
                    final var pair = mApexPackageInfo.getPackageInfo(packageName,
                            ApexManager.MATCH_FACTORY_PACKAGE);
                            ApexManager.MATCH_FACTORY_PACKAGE);
                    if (pair == null) {
                        return null;
                    }
                    return PackageInfoUtils.generate(pair.second, pair.first, flags, null, userId);
                }
                }
            }
            }
            final PackageStateInternal ps = mSettings.getDisabledSystemPkg(packageName);
            final PackageStateInternal ps = mSettings.getDisabledSystemPkg(packageName);
@@ -1775,8 +1781,12 @@ public class ComputerEngine implements Computer {
        }
        }
        if (!ApexPackageInfo.ENABLE_FEATURE_SCAN_APEX) {
        if (!ApexPackageInfo.ENABLE_FEATURE_SCAN_APEX) {
            if (matchApex) {
            if (matchApex) {
                return mApexPackageInfo.getPackageInfo(packageName,
                final var pair = mApexPackageInfo.getPackageInfo(packageName,
                        ApexManager.MATCH_ACTIVE_PACKAGE);
                        ApexManager.MATCH_ACTIVE_PACKAGE);
                if (pair == null) {
                    return null;
                }
                return PackageInfoUtils.generate(pair.second, pair.first, flags, null, userId);
            }
            }
        }
        }
        return null;
        return null;
@@ -1883,10 +1893,17 @@ public class ComputerEngine implements Computer {
        }
        }
        if (!ApexPackageInfo.ENABLE_FEATURE_SCAN_APEX) {
        if (!ApexPackageInfo.ENABLE_FEATURE_SCAN_APEX) {
            if (listApex) {
            if (listApex) {
                List<Pair<ApexInfo, AndroidPackage>> pairs;
                if (listFactory) {
                if (listFactory) {
                    list.addAll(mApexPackageInfo.getFactoryPackages());
                    pairs = mApexPackageInfo.getFactoryPackages();
                } else {
                } else {
                    list.addAll(mApexPackageInfo.getActivePackages());
                    pairs = mApexPackageInfo.getActivePackages();
                }

                for (int index = 0; index < pairs.size(); index++) {
                    var pair = pairs.get(index);
                    list.add(PackageInfoUtils.generate(pair.second, pair.first, flags, null,
                            userId));
                }
                }
            }
            }
        }
        }
@@ -3404,29 +3421,23 @@ public class ComputerEngine implements Computer {
        } // switch
        } // switch
    }
    }


    private void generateApexPackageInfo(List<PackageInfo> activePackages,
    private void generateApexPackageInfo(@NonNull List<PackageStateInternal> activePackages,
            List<PackageInfo> inactivePackages, List<PackageInfo> factoryPackages) {
            @NonNull List<PackageStateInternal> inactivePackages,
            @NonNull List<PackageStateInternal> factoryActivePackages,
            @NonNull List<PackageStateInternal> factoryInactivePackages) {
        for (AndroidPackage p : mPackages.values()) {
        for (AndroidPackage p : mPackages.values()) {
            final String packageName = p.getPackageName();
            final String packageName = p.getPackageName();
            PackageStateInternal ps = mSettings.getPackage(packageName);
            PackageStateInternal ps = mSettings.getPackage(packageName);
            if (!p.isApex() || ps == null) {
            if (!p.isApex() || ps == null) {
                continue;
                continue;
            }
            }
            PackageInfo pi = generatePackageInfo(ps, 0, 0);
            activePackages.add(ps);
            if (pi == null) {
                continue;
            }
            pi.isActiveApex = true;
            activePackages.add(pi);
            if (!ps.isUpdatedSystemApp()) {
            if (!ps.isUpdatedSystemApp()) {
                factoryPackages.add(pi);
                factoryActivePackages.add(ps);
            } else {
            } else {
                PackageStateInternal psDisabled = mSettings.getDisabledSystemPkg(packageName);
                PackageStateInternal psDisabled = mSettings.getDisabledSystemPkg(packageName);
                pi = generatePackageInfo(psDisabled, 0, 0);
                factoryInactivePackages.add(psDisabled);
                if (pi != null) {
                inactivePackages.add(psDisabled);
                    factoryPackages.add(pi);
                    inactivePackages.add(pi);
                }
            }
            }
        }
        }
    }
    }
@@ -3434,16 +3445,19 @@ public class ComputerEngine implements Computer {
    private void dumpApex(PrintWriter pw, String packageName) {
    private void dumpApex(PrintWriter pw, String packageName) {
        if (ApexPackageInfo.ENABLE_FEATURE_SCAN_APEX) {
        if (ApexPackageInfo.ENABLE_FEATURE_SCAN_APEX) {
            final IndentingPrintWriter ipw = new IndentingPrintWriter(pw, "  ", 120);
            final IndentingPrintWriter ipw = new IndentingPrintWriter(pw, "  ", 120);
            List<PackageInfo> activePackages = new ArrayList<>();
            List<PackageStateInternal> activePackages = new ArrayList<>();
            List<PackageInfo> inactivePackages = new ArrayList<>();
            List<PackageStateInternal> inactivePackages = new ArrayList<>();
            List<PackageInfo> factoryPackages = new ArrayList<>();
            List<PackageStateInternal> factoryActivePackages = new ArrayList<>();
            generateApexPackageInfo(activePackages, inactivePackages, factoryPackages);
            List<PackageStateInternal> factoryInactivePackages = new ArrayList<>();
            generateApexPackageInfo(activePackages, inactivePackages, factoryActivePackages,
                    factoryInactivePackages);
            ipw.println("Active APEX packages:");
            ipw.println("Active APEX packages:");
            ApexPackageInfo.dumpPackages(activePackages, packageName, ipw);
            ApexPackageInfo.dumpPackageStates(activePackages, true, packageName, ipw);
            ipw.println("Inactive APEX packages:");
            ipw.println("Inactive APEX packages:");
            ApexPackageInfo.dumpPackages(inactivePackages, packageName, ipw);
            ApexPackageInfo.dumpPackageStates(inactivePackages, false, packageName, ipw);
            ipw.println("Factory APEX packages:");
            ipw.println("Factory APEX packages:");
            ApexPackageInfo.dumpPackages(factoryPackages, packageName, ipw);
            ApexPackageInfo.dumpPackageStates(factoryActivePackages, true, packageName, ipw);
            ApexPackageInfo.dumpPackageStates(factoryInactivePackages, false, packageName, ipw);
        } else {
        } else {
            mApexPackageInfo.dump(pw, packageName);
            mApexPackageInfo.dump(pw, packageName);
        }
        }
+2 −2
Original line number Original line Diff line number Diff line
@@ -1611,7 +1611,7 @@ public class PackageManagerService implements PackageSender, TestUtilityService
        mSharedLibraries = injector.getSharedLibrariesImpl();
        mSharedLibraries = injector.getSharedLibrariesImpl();


        mApexManager = testParams.apexManager;
        mApexManager = testParams.apexManager;
        mApexPackageInfo = new ApexPackageInfo();
        mApexPackageInfo = new ApexPackageInfo(this);
        mArtManagerService = testParams.artManagerService;
        mArtManagerService = testParams.artManagerService;
        mAvailableFeatures = testParams.availableFeatures;
        mAvailableFeatures = testParams.availableFeatures;
        mBackgroundDexOptService = testParams.backgroundDexOptService;
        mBackgroundDexOptService = testParams.backgroundDexOptService;
@@ -1811,7 +1811,7 @@ public class PackageManagerService implements PackageSender, TestUtilityService
        mProtectedPackages = new ProtectedPackages(mContext);
        mProtectedPackages = new ProtectedPackages(mContext);


        mApexManager = injector.getApexManager();
        mApexManager = injector.getApexManager();
        mApexPackageInfo = new ApexPackageInfo();
        mApexPackageInfo = new ApexPackageInfo(this);
        mAppsFilter = mInjector.getAppsFilter();
        mAppsFilter = mInjector.getAppsFilter();


        mInstantAppRegistry = new InstantAppRegistry(mContext, mPermissionManager,
        mInstantAppRegistry = new InstantAppRegistry(mContext, mPermissionManager,
+2 −2
Original line number Original line Diff line number Diff line
@@ -823,8 +823,8 @@ final class ScanPackageUtils {
     * ideally be static, but, it requires locks to read system state.
     * ideally be static, but, it requires locks to read system state.
     */
     */
    public static void applyPolicy(ParsedPackage parsedPackage,
    public static void applyPolicy(ParsedPackage parsedPackage,
            final @PackageManagerService.ScanFlags int scanFlags, AndroidPackage platformPkg,
            final @PackageManagerService.ScanFlags int scanFlags,
            boolean isUpdatedSystemApp) {
            @Nullable AndroidPackage platformPkg, boolean isUpdatedSystemApp) {
        if ((scanFlags & SCAN_AS_SYSTEM) != 0) {
        if ((scanFlags & SCAN_AS_SYSTEM) != 0) {
            parsedPackage.setSystem(true);
            parsedPackage.setSystem(true);
            // TODO(b/135203078): Can this be done in PackageParser? Or just inferred when the flag
            // TODO(b/135203078): Can this be done in PackageParser? Or just inferred when the flag
+5 −3
Original line number Original line Diff line number Diff line
@@ -93,12 +93,14 @@ public class PackageInfoUtils {


    /**
    /**
     * @param pkgSetting See {@link PackageInfoUtils} for description of pkgSetting usage.
     * @param pkgSetting See {@link PackageInfoUtils} for description of pkgSetting usage.
     * @deprecated Once ENABLE_FEATURE_SCAN_APEX is removed, this should also be removed.
     */
     */
    @Deprecated
    @Nullable
    @Nullable
    public static PackageInfo generate(AndroidPackage pkg, ApexInfo apexInfo, int flags,
    public static PackageInfo generate(AndroidPackage pkg, ApexInfo apexInfo, long flags,
            @Nullable PackageStateInternal pkgSetting) {
            @Nullable PackageStateInternal pkgSetting, @UserIdInt int userId) {
        return generateWithComponents(pkg, EmptyArray.INT, flags, 0, 0, Collections.emptySet(),
        return generateWithComponents(pkg, EmptyArray.INT, flags, 0, 0, Collections.emptySet(),
                PackageUserStateInternal.DEFAULT, UserHandle.getCallingUserId(), apexInfo, pkgSetting);
                PackageUserStateInternal.DEFAULT, userId, apexInfo, pkgSetting);
    }
    }


    /**
    /**
Loading