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

Commit 6bc0cb33 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Migrate remaining parsePackage V1 to V2" into rvc-dev am: a83fad74

Change-Id: I42bad76fde7dfe0470976c9ce4df36a7ca8548ff
parents 376bf32b a83fad74
Loading
Loading
Loading
Loading
+19 −20
Original line number Original line Diff line number Diff line
@@ -47,8 +47,11 @@ import android.content.Context;
import android.content.Intent;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.IntentFilter;
import android.content.IntentSender;
import android.content.IntentSender;
import android.content.pm.PackageParser.PackageParserException;
import android.content.pm.dex.ArtManager;
import android.content.pm.dex.ArtManager;
import android.content.pm.parsing.PackageInfoWithoutStateUtils;
import android.content.pm.parsing.ParsingPackage;
import android.content.pm.parsing.ParsingPackageUtils;
import android.content.pm.parsing.result.ParseResult;
import android.content.res.Resources;
import android.content.res.Resources;
import android.content.res.XmlResourceParser;
import android.content.res.XmlResourceParser;
import android.graphics.Rect;
import android.graphics.Rect;
@@ -6037,28 +6040,24 @@ public abstract class PackageManager {
    @Nullable
    @Nullable
    public PackageInfo getPackageArchiveInfo(@NonNull String archiveFilePath,
    public PackageInfo getPackageArchiveInfo(@NonNull String archiveFilePath,
            @PackageInfoFlags int flags) {
            @PackageInfoFlags int flags) {
        final PackageParser parser = new PackageParser();
        if ((flags & (PackageManager.MATCH_DIRECT_BOOT_UNAWARE
        parser.setCallback(new PackageParser.CallbackImpl(this));
                | PackageManager.MATCH_DIRECT_BOOT_AWARE)) == 0) {
        final File apkFile = new File(archiveFilePath);
            // Caller expressed no opinion about what encryption
        try {
            // aware/unaware components they want to see, so match both
            if ((flags & (MATCH_DIRECT_BOOT_UNAWARE | MATCH_DIRECT_BOOT_AWARE)) != 0) {
            flags |= PackageManager.MATCH_DIRECT_BOOT_AWARE
                // Caller expressed an explicit opinion about what encryption
                    | PackageManager.MATCH_DIRECT_BOOT_UNAWARE;
                // aware/unaware components they want to see, so fall through and
                // give them what they want
            } else {
                // Caller expressed no opinion, so match everything
                flags |= MATCH_DIRECT_BOOT_AWARE | MATCH_DIRECT_BOOT_UNAWARE;
        }
        }


            PackageParser.Package pkg = parser.parseMonolithicPackage(apkFile, 0);
        boolean collectCertificates = (flags & PackageManager.GET_SIGNATURES) != 0
            if ((flags & GET_SIGNATURES) != 0) {
                || (flags & PackageManager.GET_SIGNING_CERTIFICATES) != 0;
                PackageParser.collectCertificates(pkg, false /* skipVerify */);

            }
        ParseResult<ParsingPackage> result = ParsingPackageUtils.parseDefaultOneTime(
            PackageUserState state = new PackageUserState();
                new File(archiveFilePath), 0, collectCertificates);
            return PackageParser.generatePackageInfo(pkg, null, flags, 0, 0, null, state);
        if (result.isError()) {
        } catch (PackageParserException e) {
            return null;
            return null;
        }
        }
        return PackageInfoWithoutStateUtils.generate(result.getResult(), null, flags, 0, 0, null,
                new PackageUserState(), UserHandle.getCallingUserId());
    }
    }


    /**
    /**
+4 −0
Original line number Original line Diff line number Diff line
@@ -1517,6 +1517,10 @@ public class PackageParser {
                ? null : "must have at least one '.' separator";
                ? null : "must have at least one '.' separator";
    }
    }


    /**
     * @deprecated Use {@link android.content.pm.parsing.ApkLiteParseUtils#parsePackageSplitNames}
     */
    @Deprecated
    public static Pair<String, String> parsePackageSplitNames(XmlPullParser parser,
    public static Pair<String, String> parsePackageSplitNames(XmlPullParser parser,
            AttributeSet attrs) throws IOException, XmlPullParserException,
            AttributeSet attrs) throws IOException, XmlPullParserException,
            PackageParserException {
            PackageParserException {
+143 −79
Original line number Original line Diff line number Diff line
@@ -16,6 +16,8 @@


package android.content.pm.parsing;
package android.content.pm.parsing;


import static android.content.pm.PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME;
import static android.content.pm.PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
import static android.os.Trace.TRACE_TAG_PACKAGE_MANAGER;
import static android.os.Trace.TRACE_TAG_PACKAGE_MANAGER;


import android.compat.annotation.UnsupportedAppUsage;
import android.compat.annotation.UnsupportedAppUsage;
@@ -23,6 +25,8 @@ import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager;
import android.content.pm.PackageParser;
import android.content.pm.PackageParser;
import android.content.pm.VerifierInfo;
import android.content.pm.VerifierInfo;
import android.content.pm.parsing.result.ParseInput;
import android.content.pm.parsing.result.ParseResult;
import android.content.res.ApkAssets;
import android.content.res.ApkAssets;
import android.content.res.XmlResourceParser;
import android.content.res.XmlResourceParser;
import android.os.Trace;
import android.os.Trace;
@@ -70,47 +74,60 @@ public class ApkLiteParseUtils {
     *
     *
     * @see PackageParser#parsePackage(File, int)
     * @see PackageParser#parsePackage(File, int)
     */
     */
    @UnsupportedAppUsage
    public static ParseResult<PackageParser.PackageLite> parsePackageLite(ParseInput input,
    public static PackageParser.PackageLite parsePackageLite(File packageFile, int flags)
            File packageFile, int flags) {
            throws PackageParser.PackageParserException {
        if (packageFile.isDirectory()) {
        if (packageFile.isDirectory()) {
            return parseClusterPackageLite(packageFile, flags);
            return parseClusterPackageLite(input, packageFile, flags);
        } else {
        } else {
            return parseMonolithicPackageLite(packageFile, flags);
            return parseMonolithicPackageLite(input, packageFile, flags);
        }
        }
    }
    }


    public static PackageParser.PackageLite parseMonolithicPackageLite(File packageFile, int flags)
    public static ParseResult<PackageParser.PackageLite> parseMonolithicPackageLite(
            throws PackageParser.PackageParserException {
            ParseInput input, File packageFile, int flags) {
        Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "parseApkLite");
        Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "parseApkLite");
        final PackageParser.ApkLite baseApk = parseApkLite(packageFile, flags);
        try {
            ParseResult<PackageParser.ApkLite> result = parseApkLite(input, packageFile, flags);
            if (result.isError()) {
                return input.error(result);
            }

            final PackageParser.ApkLite baseApk = result.getResult();
            final String packagePath = packageFile.getAbsolutePath();
            final String packagePath = packageFile.getAbsolutePath();
            return input.success(
                    new PackageParser.PackageLite(packagePath, baseApk, null, null, null, null,
                            null, null));
        } finally {
            Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
            Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
        return new PackageParser.PackageLite(packagePath, baseApk, null, null, null, null,
        }
                null, null);
    }
    }


    public static PackageParser.PackageLite parseClusterPackageLite(File packageDir, int flags)
    public static ParseResult<PackageParser.PackageLite> parseClusterPackageLite(ParseInput input,
            throws PackageParser.PackageParserException {
            File packageDir, int flags) {
        final File[] files = packageDir.listFiles();
        final File[] files = packageDir.listFiles();
        if (ArrayUtils.isEmpty(files)) {
        if (ArrayUtils.isEmpty(files)) {
            throw new PackageParser.PackageParserException(
            return input.error(PackageManager.INSTALL_PARSE_FAILED_NOT_APK,
                    PackageManager.INSTALL_PARSE_FAILED_NOT_APK, "No packages found in split");
                    "No packages found in split");
        }
        }
        // Apk directory is directly nested under the current directory
        // Apk directory is directly nested under the current directory
        if (files.length == 1 && files[0].isDirectory()) {
        if (files.length == 1 && files[0].isDirectory()) {
            return parseClusterPackageLite(files[0], flags);
            return parseClusterPackageLite(input, files[0], flags);
        }
        }


        String packageName = null;
        String packageName = null;
        int versionCode = 0;
        int versionCode = 0;


        Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "parseApkLite");
        final ArrayMap<String, PackageParser.ApkLite> apks = new ArrayMap<>();
        final ArrayMap<String, PackageParser.ApkLite> apks = new ArrayMap<>();
        Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "parseApkLite");
        try {
            for (File file : files) {
            for (File file : files) {
                if (PackageParser.isApkFile(file)) {
                if (PackageParser.isApkFile(file)) {
                final PackageParser.ApkLite lite = parseApkLite(file, flags);
                    ParseResult<PackageParser.ApkLite> result = parseApkLite(input, file, flags);
                    if (result.isError()) {
                        return input.error(result);
                    }


                    final PackageParser.ApkLite lite = result.getResult();
                    // Assert that all package names and version codes are
                    // Assert that all package names and version codes are
                    // consistent with the first one we encounter.
                    // consistent with the first one we encounter.
                    if (packageName == null) {
                    if (packageName == null) {
@@ -118,14 +135,12 @@ public class ApkLiteParseUtils {
                        versionCode = lite.versionCode;
                        versionCode = lite.versionCode;
                    } else {
                    } else {
                        if (!packageName.equals(lite.packageName)) {
                        if (!packageName.equals(lite.packageName)) {
                        throw new PackageParser.PackageParserException(
                            return input.error(PackageManager.INSTALL_PARSE_FAILED_BAD_MANIFEST,
                                PackageManager.INSTALL_PARSE_FAILED_BAD_MANIFEST,
                                    "Inconsistent package " + lite.packageName + " in " + file
                                    "Inconsistent package " + lite.packageName + " in " + file
                                            + "; expected " + packageName);
                                            + "; expected " + packageName);
                        }
                        }
                        if (versionCode != lite.versionCode) {
                        if (versionCode != lite.versionCode) {
                        throw new PackageParser.PackageParserException(
                            return input.error(PackageManager.INSTALL_PARSE_FAILED_BAD_MANIFEST,
                                PackageManager.INSTALL_PARSE_FAILED_BAD_MANIFEST,
                                    "Inconsistent version " + lite.versionCode + " in " + file
                                    "Inconsistent version " + lite.versionCode + " in " + file
                                            + "; expected " + versionCode);
                                            + "; expected " + versionCode);
                        }
                        }
@@ -133,19 +148,19 @@ public class ApkLiteParseUtils {


                    // Assert that each split is defined only oncuses-static-libe
                    // Assert that each split is defined only oncuses-static-libe
                    if (apks.put(lite.splitName, lite) != null) {
                    if (apks.put(lite.splitName, lite) != null) {
                    throw new PackageParser.PackageParserException(
                        return input.error(PackageManager.INSTALL_PARSE_FAILED_BAD_MANIFEST,
                            PackageManager.INSTALL_PARSE_FAILED_BAD_MANIFEST,
                                "Split name " + lite.splitName
                                "Split name " + lite.splitName
                                        + " defined more than once; most recent was " + file);
                                        + " defined more than once; most recent was " + file);
                    }
                    }
                }
                }
            }
            }
        } finally {
            Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
            Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
        }


        final PackageParser.ApkLite baseApk = apks.remove(null);
        final PackageParser.ApkLite baseApk = apks.remove(null);
        if (baseApk == null) {
        if (baseApk == null) {
            throw new PackageParser.PackageParserException(
            return input.error(PackageManager.INSTALL_PARSE_FAILED_BAD_MANIFEST,
                    PackageManager.INSTALL_PARSE_FAILED_BAD_MANIFEST,
                    "Missing base APK in " + packageDir);
                    "Missing base APK in " + packageDir);
        }
        }


@@ -180,8 +195,9 @@ public class ApkLiteParseUtils {
        }
        }


        final String codePath = packageDir.getAbsolutePath();
        final String codePath = packageDir.getAbsolutePath();
        return new PackageParser.PackageLite(codePath, baseApk, splitNames, isFeatureSplits,
        return input.success(new PackageParser.PackageLite(codePath, baseApk, splitNames,
                usesSplitNames, configForSplits, splitCodePaths, splitRevisionCodes);
                isFeatureSplits, usesSplitNames, configForSplits, splitCodePaths,
                splitRevisionCodes));
    }
    }


    /**
    /**
@@ -192,9 +208,9 @@ public class ApkLiteParseUtils {
     * @param flags optional parse flags, such as
     * @param flags optional parse flags, such as
     *            {@link PackageParser#PARSE_COLLECT_CERTIFICATES}
     *            {@link PackageParser#PARSE_COLLECT_CERTIFICATES}
     */
     */
    public static PackageParser.ApkLite parseApkLite(File apkFile, int flags)
    public static ParseResult<PackageParser.ApkLite> parseApkLite(ParseInput input, File apkFile,
            throws PackageParser.PackageParserException {
            int flags) {
        return parseApkLiteInner(apkFile, null, null, flags);
        return parseApkLiteInner(input, apkFile, null, null, flags);
    }
    }


    /**
    /**
@@ -206,13 +222,13 @@ public class ApkLiteParseUtils {
     * @param flags optional parse flags, such as
     * @param flags optional parse flags, such as
     *            {@link PackageParser#PARSE_COLLECT_CERTIFICATES}
     *            {@link PackageParser#PARSE_COLLECT_CERTIFICATES}
     */
     */
    public static PackageParser.ApkLite parseApkLite(FileDescriptor fd, String debugPathName,
    public static ParseResult<PackageParser.ApkLite> parseApkLite(ParseInput input,
            int flags) throws PackageParser.PackageParserException {
            FileDescriptor fd, String debugPathName, int flags) {
        return parseApkLiteInner(null, fd, debugPathName, flags);
        return parseApkLiteInner(input, null, fd, debugPathName, flags);
    }
    }


    private static PackageParser.ApkLite parseApkLiteInner(File apkFile, FileDescriptor fd,
    private static ParseResult<PackageParser.ApkLite> parseApkLiteInner(ParseInput input,
            String debugPathName, int flags) throws PackageParser.PackageParserException {
            File apkFile, FileDescriptor fd, String debugPathName, int flags) {
        final String apkPath = fd != null ? debugPathName : apkFile.getAbsolutePath();
        final String apkPath = fd != null ? debugPathName : apkFile.getAbsolutePath();


        XmlResourceParser parser = null;
        XmlResourceParser parser = null;
@@ -223,8 +239,7 @@ public class ApkLiteParseUtils {
                        ? ApkAssets.loadFromFd(fd, debugPathName, 0 /* flags */, null /* assets */)
                        ? ApkAssets.loadFromFd(fd, debugPathName, 0 /* flags */, null /* assets */)
                        : ApkAssets.loadFromPath(apkPath);
                        : ApkAssets.loadFromPath(apkPath);
            } catch (IOException e) {
            } catch (IOException e) {
                throw new PackageParser.PackageParserException(
                return input.error(PackageManager.INSTALL_PARSE_FAILED_NOT_APK,
                        PackageManager.INSTALL_PARSE_FAILED_NOT_APK,
                        "Failed to parse " + apkPath, e);
                        "Failed to parse " + apkPath, e);
            }
            }


@@ -235,9 +250,15 @@ public class ApkLiteParseUtils {
                final boolean skipVerify = (flags & PackageParser.PARSE_IS_SYSTEM_DIR) != 0;
                final boolean skipVerify = (flags & PackageParser.PARSE_IS_SYSTEM_DIR) != 0;
                Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "collectCertificates");
                Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "collectCertificates");
                try {
                try {
                    signingDetails = ParsingPackageUtils.collectCertificates(apkFile.getAbsolutePath(),
                    ParseResult<PackageParser.SigningDetails> result =
                            skipVerify, false, PackageParser.SigningDetails.UNKNOWN,
                            ParsingPackageUtils.getSigningDetails(input,
                                    apkFile.getAbsolutePath(), skipVerify, false,
                                    PackageParser.SigningDetails.UNKNOWN,
                                    DEFAULT_TARGET_SDK_VERSION);
                                    DEFAULT_TARGET_SDK_VERSION);
                    if (result.isError()) {
                        return input.error(result);
                    }
                    signingDetails = result.getResult();
                } finally {
                } finally {
                    Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
                    Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
                }
                }
@@ -246,12 +267,10 @@ public class ApkLiteParseUtils {
            }
            }


            final AttributeSet attrs = parser;
            final AttributeSet attrs = parser;
            return parseApkLite(apkPath, parser, attrs, signingDetails);
            return parseApkLite(input, apkPath, parser, attrs, signingDetails);

        } catch (XmlPullParserException | IOException | RuntimeException e) {
        } catch (XmlPullParserException | IOException | RuntimeException e) {
            Slog.w(TAG, "Failed to parse " + apkPath, e);
            Slog.w(TAG, "Failed to parse " + apkPath, e);
            throw new PackageParser.PackageParserException(
            return input.error(PackageManager.INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION,
                    PackageManager.INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION,
                    "Failed to parse " + apkPath, e);
                    "Failed to parse " + apkPath, e);
        } finally {
        } finally {
            IoUtils.closeQuietly(parser);
            IoUtils.closeQuietly(parser);
@@ -265,12 +284,16 @@ public class ApkLiteParseUtils {
        }
        }
    }
    }


    private static PackageParser.ApkLite parseApkLite(
    private static ParseResult<PackageParser.ApkLite> parseApkLite(ParseInput input,
            String codePath, XmlPullParser parser, AttributeSet attrs,
            String codePath, XmlPullParser parser, AttributeSet attrs,
            PackageParser.SigningDetails signingDetails)
            PackageParser.SigningDetails signingDetails)
            throws IOException, XmlPullParserException, PackageParser.PackageParserException {
            throws IOException, XmlPullParserException {
        final Pair<String, String> packageSplit = PackageParser.parsePackageSplitNames(
        ParseResult<Pair<String, String>> result = parsePackageSplitNames(input, parser, attrs);
                parser, attrs);
        if (result.isError()) {
            return input.error(result);
        }

        Pair<String, String> packageSplit = result.getResult();


        int installLocation = PARSE_DEFAULT_INSTALL_LOCATION;
        int installLocation = PARSE_DEFAULT_INSTALL_LOCATION;
        int versionCode = 0;
        int versionCode = 0;
@@ -394,8 +417,7 @@ public class ApkLiteParseUtils {


                usesSplitName = attrs.getAttributeValue(PackageParser.ANDROID_RESOURCES, "name");
                usesSplitName = attrs.getAttributeValue(PackageParser.ANDROID_RESOURCES, "name");
                if (usesSplitName == null) {
                if (usesSplitName == null) {
                    throw new PackageParser.PackageParserException(
                    return input.error(PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED,
                            PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED,
                            "<uses-split> tag requires 'android:name' attribute");
                            "<uses-split> tag requires 'android:name' attribute");
                }
                }
            } else if (PackageParser.TAG_USES_SDK.equals(parser.getName())) {
            } else if (PackageParser.TAG_USES_SDK.equals(parser.getName())) {
@@ -423,12 +445,54 @@ public class ApkLiteParseUtils {
            overlayPriority = 0;
            overlayPriority = 0;
        }
        }


        return new PackageParser.ApkLite(codePath, packageSplit.first, packageSplit.second,
        return input.success(new PackageParser.ApkLite(codePath, packageSplit.first,
                isFeatureSplit, configForSplit, usesSplitName, isSplitRequired, versionCode,
                packageSplit.second, isFeatureSplit, configForSplit, usesSplitName, isSplitRequired,
                versionCodeMajor, revisionCode, installLocation, verifiers, signingDetails,
                versionCode, versionCodeMajor, revisionCode, installLocation, verifiers,
                coreApp, debuggable, multiArch, use32bitAbi, useEmbeddedDex, extractNativeLibs,
                signingDetails, coreApp, debuggable, multiArch, use32bitAbi, useEmbeddedDex,
                isolatedSplits, targetPackage, overlayIsStatic, overlayPriority, minSdkVersion,
                extractNativeLibs, isolatedSplits, targetPackage, overlayIsStatic, overlayPriority,
                targetSdkVersion);
                minSdkVersion, targetSdkVersion));
    }

    public static ParseResult<Pair<String, String>> parsePackageSplitNames(ParseInput input,
            XmlPullParser parser, AttributeSet attrs) throws IOException, XmlPullParserException {
        int type;
        while ((type = parser.next()) != XmlPullParser.START_TAG
                && type != XmlPullParser.END_DOCUMENT) {
        }

        if (type != XmlPullParser.START_TAG) {
            return input.error(INSTALL_PARSE_FAILED_MANIFEST_MALFORMED,
                    "No start tag found");
        }
        if (!parser.getName().equals(PackageParser.TAG_MANIFEST)) {
            return input.error(INSTALL_PARSE_FAILED_MANIFEST_MALFORMED,
                    "No <manifest> tag");
        }

        final String packageName = attrs.getAttributeValue(null, "package");
        if (!"android".equals(packageName)) {
            final String error = PackageParser.validateName(packageName, true, true);
            if (error != null) {
                return input.error(INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME,
                        "Invalid manifest package: " + error);
            }
        }

        String splitName = attrs.getAttributeValue(null, "split");
        if (splitName != null) {
            if (splitName.length() == 0) {
                splitName = null;
            } else {
                final String error = PackageParser.validateName(splitName, false, false);
                if (error != null) {
                    return input.error(INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME,
                            "Invalid manifest split: " + error);
                }
            }
        }

        return input.success(Pair.create(packageName.intern(),
                (splitName != null) ? splitName.intern() : splitName));
    }
    }


    public static VerifierInfo parseVerifier(AttributeSet attrs) {
    public static VerifierInfo parseVerifier(AttributeSet attrs) {
+105 −54

File changed.

Preview size limit exceeded, changes collapsed.

+26 −0
Original line number Original line Diff line number Diff line
@@ -18,12 +18,16 @@ package android.content.pm.parsing.result;


import android.annotation.NonNull;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Nullable;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager;
import android.content.pm.parsing.ParsingUtils;
import android.content.pm.parsing.ParsingUtils;
import android.os.ServiceManager;
import android.util.ArrayMap;
import android.util.ArrayMap;
import android.util.Log;
import android.util.Log;
import android.util.Slog;
import android.util.Slog;


import com.android.internal.compat.IPlatformCompat;
import com.android.internal.util.CollectionUtils;
import com.android.internal.util.CollectionUtils;


/** @hide */
/** @hide */
@@ -60,6 +64,28 @@ public class ParseTypeImpl implements ParseInput, ParseResult<Object> {
    private String mPackageName;
    private String mPackageName;
    private Integer mTargetSdkVersion;
    private Integer mTargetSdkVersion;


    /**
     * Assumes {@link Context#PLATFORM_COMPAT_SERVICE} is available to the caller. For use
     * with {@link android.content.pm.parsing.ApkLiteParseUtils} or similar where parsing is
     * done outside of {@link com.android.server.pm.PackageManagerService}.
     */
    public static ParseTypeImpl forDefaultParsing() {
        IPlatformCompat platformCompat = IPlatformCompat.Stub.asInterface(
                ServiceManager.getService(Context.PLATFORM_COMPAT_SERVICE));
        return new ParseTypeImpl((changeId, packageName, targetSdkVersion) -> {
            ApplicationInfo appInfo = new ApplicationInfo();
            appInfo.packageName = packageName;
            appInfo.targetSdkVersion = targetSdkVersion;
            try {
                return platformCompat.isChangeEnabled(changeId, appInfo);
            } catch (Exception e) {
                // This shouldn't happen, but assume enforcement if it does
                Slog.wtf(ParsingUtils.TAG, "IPlatformCompat query failed", e);
                return true;
            }
        });
    }

    /**
    /**
     * @param callback if nullable, fallback to manual targetSdk > Q check
     * @param callback if nullable, fallback to manual targetSdk > Q check
     */
     */
Loading