From 3949de155274cd3a2a8bfda8e5e3779353a29064 Mon Sep 17 00:00:00 2001 From: Jackal Guo Date: Mon, 14 Dec 2020 10:42:17 +0800 Subject: [PATCH] Refactor PackageParser (1/n) The PackageParser is deprecated, but two inner classes PackageLite and ApkLite are still used widely. To move away from PackageParser, the first step is having alternatives of these inner classes. Besides, some constants in the PackageParser are also used. This CL also moves them into the individual class. Bug: 174723245 Test: make Change-Id: Ice151dc4daf7e342e9f77cfdae69682c1d5ba56f --- .../android/content/pm/parsing/ApkLite.java | 412 ++++++++++++++++++ .../content/pm/parsing/ApkLiteParseUtils.java | 21 +- .../content/pm/parsing/PackageLite.java | 363 +++++++++++++++ .../pm/parsing/ParsingPackageUtils.java | 79 ++++ .../component/ParsedActivityUtils.java | 11 + .../component/ParsedIntentInfoUtils.java | 2 + .../server/pm/PackageInstallerSession.java | 2 +- 7 files changed, 888 insertions(+), 2 deletions(-) create mode 100644 core/java/android/content/pm/parsing/ApkLite.java create mode 100644 core/java/android/content/pm/parsing/PackageLite.java diff --git a/core/java/android/content/pm/parsing/ApkLite.java b/core/java/android/content/pm/parsing/ApkLite.java new file mode 100644 index 0000000000000..d8ec512d9f1ec --- /dev/null +++ b/core/java/android/content/pm/parsing/ApkLite.java @@ -0,0 +1,412 @@ +/* + * Copyright (C) 2021 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.content.pm.parsing; + +import android.annotation.NonNull; +import android.annotation.Nullable; +import android.content.pm.PackageInfo; +import android.content.pm.PackageParser.SigningDetails; +import android.content.pm.VerifierInfo; + +import com.android.internal.util.DataClass; + +import java.util.List; + +/** + * Lightweight parsed details about a single APK file. + * + * @hide + */ +@DataClass(genConstructor = false, genConstDefs = false) +public class ApkLite { + /** Name of the package as used to identify it in the system */ + private final @NonNull String mPackageName; + /** Path where this APK file was found on disk */ + private final @NonNull String mPath; + /** Split name of this APK */ + private final @Nullable String mSplitName; + /** Dependencies of the split APK */ + /** Name of the split APK that this APK depends on */ + private final @Nullable String mUsesSplitName; + /** Name of the split APK that this APK is a configuration for */ + private final @Nullable String mConfigForSplit; + + /** Major version number of this package */ + private final int mVersionCodeMajor; + /** Minor version number of this package */ + private final int mVersionCode; + /** Revision code of this APK */ + private final int mRevisionCode; + /** + * Indicate the install location of this package + * + * @see {@link PackageInfo#INSTALL_LOCATION_AUTO} + * @see {@link PackageInfo#INSTALL_LOCATION_INTERNAL_ONLY} + * @see {@link PackageInfo#INSTALL_LOCATION_PREFER_EXTERNAL} + */ + private final int mInstallLocation; + /** Indicate the minimum SDK version number that the app requires */ + private final int mMinSdkVersion; + /** Indicate the SDK version number that the application is targeting */ + private final int mTargetSdkVersion; + /** Information about a package verifiers as used during package verification */ + private final @NonNull VerifierInfo[] mVerifiers; + /** Signing-related data of an application package */ + private final @NonNull SigningDetails mSigningDetails; + + /** Indicate whether this APK is a 'feature' split */ + private final boolean mFeatureSplit; + /** Indicate whether each split should be load into their own Context objects */ + private final boolean mIsolatedSplits; + /** + * Indicate whether this package requires at least one split (either feature or resource) + * to be present in order to function + */ + private final boolean mSplitRequired; + /** Indicate whether this app is coreApp */ + private final boolean mCoreApp; + /** Indicate whether this app can be debugged */ + private final boolean mDebuggable; + /** Indicate whether this app is profileable by Shell */ + private final boolean mProfileableByShell; + /** Indicate whether this app needs to be loaded into other applications' processes */ + private final boolean mMultiArch; + /** Indicate whether the 32 bit version of the ABI should be used */ + private final boolean mUse32bitAbi; + /** Indicate whether installer extracts native libraries */ + private final boolean mExtractNativeLibs; + /** + * Indicate whether this package wants to run the dex within its APK but not extracted + * or locally compiled variants. + */ + private final boolean mUseEmbeddedDex; + + /** Name of the overlay-able set of elements package */ + private final @Nullable String mTargetPackageName; + /** Indicate whether the overlay is static */ + private final boolean mOverlayIsStatic; + /** Indicate the priority of this overlay package */ + private final int mOverlayPriority; + + /** + * Indicate the policy to deal with user data when rollback is committed + * + * @see {@link android.content.pm.PackageManager.RollbackDataPolicy#RESTORE} + * @see {@link android.content.pm.PackageManager.RollbackDataPolicy#WIPE} + * @see {@link android.content.pm.PackageManager.RollbackDataPolicy#RETAIN} + */ + private final int mRollbackDataPolicy; + + public ApkLite(String path, String packageName, String splitName, boolean isFeatureSplit, + String configForSplit, String usesSplitName, boolean isSplitRequired, int versionCode, + int versionCodeMajor, int revisionCode, int installLocation, + List verifiers, SigningDetails signingDetails, boolean coreApp, + boolean debuggable, boolean profileableByShell, boolean multiArch, boolean use32bitAbi, + boolean useEmbeddedDex, boolean extractNativeLibs, boolean isolatedSplits, + String targetPackageName, boolean overlayIsStatic, int overlayPriority, + int minSdkVersion, int targetSdkVersion, int rollbackDataPolicy) { + mPath = path; + mPackageName = packageName; + mSplitName = splitName; + mFeatureSplit = isFeatureSplit; + mConfigForSplit = configForSplit; + mUsesSplitName = usesSplitName; + mSplitRequired = isSplitRequired; + mVersionCode = versionCode; + mVersionCodeMajor = versionCodeMajor; + mRevisionCode = revisionCode; + mInstallLocation = installLocation; + mVerifiers = verifiers.toArray(new VerifierInfo[verifiers.size()]); + mSigningDetails = signingDetails; + mCoreApp = coreApp; + mDebuggable = debuggable; + mProfileableByShell = profileableByShell; + mMultiArch = multiArch; + mUse32bitAbi = use32bitAbi; + mUseEmbeddedDex = useEmbeddedDex; + mExtractNativeLibs = extractNativeLibs; + mIsolatedSplits = isolatedSplits; + mTargetPackageName = targetPackageName; + mOverlayIsStatic = overlayIsStatic; + mOverlayPriority = overlayPriority; + mMinSdkVersion = minSdkVersion; + mTargetSdkVersion = targetSdkVersion; + mRollbackDataPolicy = rollbackDataPolicy; + } + + /** + * Return {@link #mVersionCode} and {@link #mVersionCodeMajor} combined together as a + * single long value. The {@link #mVersionCodeMajor} is placed in the upper 32 bits. + */ + public long getLongVersionCode() { + return PackageInfo.composeLongVersionCode(mVersionCodeMajor, mVersionCode); + } + + + + // Code below generated by codegen v1.0.22. + // + // DO NOT MODIFY! + // CHECKSTYLE:OFF Generated code + // + // To regenerate run: + // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/content/pm/parsing/ApkLite.java + // + // To exclude the generated code from IntelliJ auto-formatting enable (one-time): + // Settings > Editor > Code Style > Formatter Control + //@formatter:off + + + /** + * Name of the package as used to identify it in the system + */ + @DataClass.Generated.Member + public @NonNull String getPackageName() { + return mPackageName; + } + + /** + * Path where this APK file was found on disk + */ + @DataClass.Generated.Member + public @NonNull String getPath() { + return mPath; + } + + /** + * Split name of this APK + */ + @DataClass.Generated.Member + public @Nullable String getSplitName() { + return mSplitName; + } + + /** + * Name of the split APK that this APK depends on + */ + @DataClass.Generated.Member + public @Nullable String getUsesSplitName() { + return mUsesSplitName; + } + + /** + * Name of the split APK that this APK is a configuration for + */ + @DataClass.Generated.Member + public @Nullable String getConfigForSplit() { + return mConfigForSplit; + } + + /** + * Major version number of this package + */ + @DataClass.Generated.Member + public int getVersionCodeMajor() { + return mVersionCodeMajor; + } + + /** + * Minor version number of this package + */ + @DataClass.Generated.Member + public int getVersionCode() { + return mVersionCode; + } + + /** + * Revision code of this APK + */ + @DataClass.Generated.Member + public int getRevisionCode() { + return mRevisionCode; + } + + /** + * Indicate the install location of this package + * + * @see {@link PackageInfo#INSTALL_LOCATION_AUTO} + * @see {@link PackageInfo#INSTALL_LOCATION_INTERNAL_ONLY} + * @see {@link PackageInfo#INSTALL_LOCATION_PREFER_EXTERNAL} + */ + @DataClass.Generated.Member + public int getInstallLocation() { + return mInstallLocation; + } + + /** + * Indicate the minimum SDK version number that the app requires + */ + @DataClass.Generated.Member + public int getMinSdkVersion() { + return mMinSdkVersion; + } + + /** + * Indicate the SDK version number that the application is targeting + */ + @DataClass.Generated.Member + public int getTargetSdkVersion() { + return mTargetSdkVersion; + } + + /** + * Information about a package verifiers as used during package verification + */ + @DataClass.Generated.Member + public @NonNull VerifierInfo[] getVerifiers() { + return mVerifiers; + } + + /** + * Signing-related data of an application package + */ + @DataClass.Generated.Member + public @NonNull SigningDetails getSigningDetails() { + return mSigningDetails; + } + + /** + * Indicate whether this APK is a 'feature' split + */ + @DataClass.Generated.Member + public boolean isFeatureSplit() { + return mFeatureSplit; + } + + /** + * Indicate whether each split should be load into their own Context objects + */ + @DataClass.Generated.Member + public boolean isIsolatedSplits() { + return mIsolatedSplits; + } + + /** + * Indicate whether this package requires at least one split (either feature or resource) + * to be present in order to function + */ + @DataClass.Generated.Member + public boolean isSplitRequired() { + return mSplitRequired; + } + + /** + * Indicate whether this app is coreApp + */ + @DataClass.Generated.Member + public boolean isCoreApp() { + return mCoreApp; + } + + /** + * Indicate whether this app can be debugged + */ + @DataClass.Generated.Member + public boolean isDebuggable() { + return mDebuggable; + } + + /** + * Indicate whether this app is profileable by Shell + */ + @DataClass.Generated.Member + public boolean isProfileableByShell() { + return mProfileableByShell; + } + + /** + * Indicate whether this app needs to be loaded into other applications' processes + */ + @DataClass.Generated.Member + public boolean isMultiArch() { + return mMultiArch; + } + + /** + * Indicate whether the 32 bit version of the ABI should be used + */ + @DataClass.Generated.Member + public boolean isUse32bitAbi() { + return mUse32bitAbi; + } + + /** + * Indicate whether installer extracts native libraries + */ + @DataClass.Generated.Member + public boolean isExtractNativeLibs() { + return mExtractNativeLibs; + } + + /** + * Indicate whether this package wants to run the dex within its APK but not extracted + * or locally compiled variants. + */ + @DataClass.Generated.Member + public boolean isUseEmbeddedDex() { + return mUseEmbeddedDex; + } + + /** + * Name of the overlay-able set of elements package + */ + @DataClass.Generated.Member + public @Nullable String getTargetPackageName() { + return mTargetPackageName; + } + + /** + * Indicate whether the overlay is static + */ + @DataClass.Generated.Member + public boolean isOverlayIsStatic() { + return mOverlayIsStatic; + } + + /** + * Indicate the priority of this overlay package + */ + @DataClass.Generated.Member + public int getOverlayPriority() { + return mOverlayPriority; + } + + /** + * Indicate the policy to deal with user data when rollback is committed + * + * @see {@link android.content.pm.PackageManager.RollbackDataPolicy#RESTORE} + * @see {@link android.content.pm.PackageManager.RollbackDataPolicy#WIPE} + * @see {@link android.content.pm.PackageManager.RollbackDataPolicy#RETAIN} + */ + @DataClass.Generated.Member + public int getRollbackDataPolicy() { + return mRollbackDataPolicy; + } + + @DataClass.Generated( + time = 1610596637723L, + codegenVersion = "1.0.22", + sourceFile = "frameworks/base/core/java/android/content/pm/parsing/ApkLite.java", + inputSignatures = "private final @android.annotation.NonNull java.lang.String mPackageName\nprivate final @android.annotation.NonNull java.lang.String mPath\nprivate final @android.annotation.Nullable java.lang.String mSplitName\nprivate final @android.annotation.Nullable java.lang.String mUsesSplitName\nprivate final @android.annotation.Nullable java.lang.String mConfigForSplit\nprivate final int mVersionCodeMajor\nprivate final int mVersionCode\nprivate final int mRevisionCode\nprivate final int mInstallLocation\nprivate final int mMinSdkVersion\nprivate final int mTargetSdkVersion\nprivate final @android.annotation.NonNull android.content.pm.VerifierInfo[] mVerifiers\nprivate final @android.annotation.NonNull android.content.pm.PackageParser.SigningDetails mSigningDetails\nprivate final boolean mFeatureSplit\nprivate final boolean mIsolatedSplits\nprivate final boolean mSplitRequired\nprivate final boolean mCoreApp\nprivate final boolean mDebuggable\nprivate final boolean mProfileableByShell\nprivate final boolean mMultiArch\nprivate final boolean mUse32bitAbi\nprivate final boolean mExtractNativeLibs\nprivate final boolean mUseEmbeddedDex\nprivate final @android.annotation.Nullable java.lang.String mTargetPackageName\nprivate final boolean mOverlayIsStatic\nprivate final int mOverlayPriority\nprivate final int mRollbackDataPolicy\npublic long getLongVersionCode()\nclass ApkLite extends java.lang.Object implements []\n@com.android.internal.util.DataClass(genConstructor=false, genConstDefs=false)") + @Deprecated + private void __metadata() {} + + + //@formatter:on + // End of generated code + +} diff --git a/core/java/android/content/pm/parsing/ApkLiteParseUtils.java b/core/java/android/content/pm/parsing/ApkLiteParseUtils.java index f583e2597855e..51b81b60a825c 100644 --- a/core/java/android/content/pm/parsing/ApkLiteParseUtils.java +++ b/core/java/android/content/pm/parsing/ApkLiteParseUtils.java @@ -18,7 +18,6 @@ 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.content.pm.PackageParser.APK_FILE_EXTENSION; import static android.content.pm.parsing.ParsingPackageUtils.validateName; import static android.os.Trace.TRACE_TAG_PACKAGE_MANAGER; @@ -51,6 +50,7 @@ import java.io.IOException; import java.security.PublicKey; import java.util.ArrayList; import java.util.Arrays; +import java.util.Comparator; import java.util.List; import java.util.Objects; @@ -66,6 +66,8 @@ public class ApkLiteParseUtils { private static final int PARSE_DEFAULT_INSTALL_LOCATION = PackageInfo.INSTALL_LOCATION_UNSPECIFIED; + public static final String APK_FILE_EXTENSION = ".apk"; + /** * Parse only lightweight details about the package at the given location. * Automatically detects if the package is a monolithic style (single APK @@ -606,4 +608,21 @@ public class ApkLiteParseUtils { return new VerifierInfo(packageName, publicKey); } + + /** + * Used to sort a set of APKs based on their split names, always placing the + * base APK (with {@code null} split name) first. + */ + private static class SplitNameComparator implements Comparator { + @Override + public int compare(String lhs, String rhs) { + if (lhs == null) { + return -1; + } else if (rhs == null) { + return 1; + } else { + return lhs.compareTo(rhs); + } + } + } } diff --git a/core/java/android/content/pm/parsing/PackageLite.java b/core/java/android/content/pm/parsing/PackageLite.java new file mode 100644 index 0000000000000..803d643c985c6 --- /dev/null +++ b/core/java/android/content/pm/parsing/PackageLite.java @@ -0,0 +1,363 @@ +/* + * Copyright (C) 2021 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.content.pm.parsing; + +import android.annotation.NonNull; +import android.annotation.Nullable; +import android.content.pm.PackageInfo; +import android.content.pm.VerifierInfo; + +import com.android.internal.util.ArrayUtils; +import com.android.internal.util.DataClass; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * Lightweight parsed details about a single package. + * + * @hide + */ +@DataClass(genConstructor = false, genConstDefs = false) +public class PackageLite { + /** Name of the package as used to identify it in the system */ + private final @NonNull String mPackageName; + /** + * Path where this package was found on disk. For monolithic packages + * this is path to single base APK file; for cluster packages this is + * path to the cluster directory. + */ + private final @NonNull String mPath; + /** Path of base APK */ + private final @NonNull String mBaseApkPath; + /** Paths of any split APKs, ordered by parsed splitName */ + private final @Nullable String[] mSplitApkPaths; + /** Names of any split APKs, ordered by parsed splitName */ + private final @Nullable String[] mSplitNames; + /** Dependencies of any split APKs, ordered by parsed splitName */ + private final @Nullable String[] mUsesSplitNames; + private final @Nullable String[] mConfigForSplit; + /** Major and minor version number of this package */ + private final int mVersionCodeMajor; + private final int mVersionCode; + /** Revision code of base APK */ + private final int mBaseRevisionCode; + /** Revision codes of any split APKs, ordered by parsed splitName */ + private final @Nullable int[] mSplitRevisionCodes; + /** + * Indicate the install location of this package + * + * @see {@link PackageInfo#INSTALL_LOCATION_AUTO} + * @see {@link PackageInfo#INSTALL_LOCATION_INTERNAL_ONLY} + * @see {@link PackageInfo#INSTALL_LOCATION_PREFER_EXTERNAL} + */ + private final int mInstallLocation; + /** Information about a package verifiers as used during package verification */ + private final @NonNull VerifierInfo[] mVerifiers; + + /** Indicate whether any split APKs that are features. Ordered by splitName */ + private final @Nullable boolean[] mIsFeatureSplits; + /** Indicate whether each split should be load into their own Context objects */ + private final boolean mIsolatedSplits; + /** + * Indicate whether this package requires at least one split (either feature or resource) + * to be present in order to function + */ + private final boolean mSplitRequired; + /** Indicate whether this app is coreApp */ + private final boolean mCoreApp; + /** Indicate whether this app can be debugged */ + private final boolean mDebuggable; + /** Indicate whether this app needs to be loaded into other applications' processes */ + private final boolean mMultiArch; + /** Indicate whether the 32 bit version of the ABI should be used */ + private final boolean mUse32bitAbi; + /** Indicate whether installer extracts native libraries */ + private final boolean mExtractNativeLibs; + /** Indicate whether this app is profileable by Shell */ + private final boolean mProfileableByShell; + /** + * Indicate whether this package wants to run the dex within its APK but not extracted + * or locally compiled variants. + */ + private final boolean mUseEmbeddedDex; + + public PackageLite(String path, String baseApkPath, ApkLite baseApk, + String[] splitNames, boolean[] isFeatureSplits, String[] usesSplitNames, + String[] configForSplit, String[] splitApkPaths, int[] splitRevisionCodes) { + // The following paths may be different from the path in ApkLite because we + // move or rename the APK files. Use parameters to indicate the correct paths. + mPath = path; + mBaseApkPath = baseApkPath; + mPackageName = baseApk.getPackageName(); + mVersionCode = baseApk.getVersionCode(); + mVersionCodeMajor = baseApk.getVersionCodeMajor(); + mInstallLocation = baseApk.getInstallLocation(); + mVerifiers = baseApk.getVerifiers(); + mBaseRevisionCode = baseApk.getRevisionCode(); + mCoreApp = baseApk.isCoreApp(); + mDebuggable = baseApk.isDebuggable(); + mMultiArch = baseApk.isMultiArch(); + mUse32bitAbi = baseApk.isUse32bitAbi(); + mExtractNativeLibs = baseApk.isExtractNativeLibs(); + mIsolatedSplits = baseApk.isIsolatedSplits(); + mUseEmbeddedDex = baseApk.isUseEmbeddedDex(); + mSplitRequired = baseApk.isSplitRequired(); + mProfileableByShell = baseApk.isProfileableByShell(); + mSplitNames = splitNames; + mIsFeatureSplits = isFeatureSplits; + mUsesSplitNames = usesSplitNames; + mConfigForSplit = configForSplit; + mSplitApkPaths = splitApkPaths; + mSplitRevisionCodes = splitRevisionCodes; + } + + /** + * Return code path to the base APK file, and split APK files if any. + */ + public List getAllApkPaths() { + final ArrayList paths = new ArrayList<>(); + paths.add(mBaseApkPath); + if (!ArrayUtils.isEmpty(mSplitApkPaths)) { + Collections.addAll(paths, mSplitApkPaths); + } + return paths; + } + + /** + * Return {@link #mVersionCode} and {@link #mVersionCodeMajor} combined together as a + * single long value. The {@link #mVersionCodeMajor} is placed in the upper 32 bits. + */ + public long getLongVersionCode() { + return PackageInfo.composeLongVersionCode(mVersionCodeMajor, mVersionCode); + } + + + + // Code below generated by codegen v1.0.22. + // + // DO NOT MODIFY! + // CHECKSTYLE:OFF Generated code + // + // To regenerate run: + // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/content/pm/parsing/PackageLite.java + // + // To exclude the generated code from IntelliJ auto-formatting enable (one-time): + // Settings > Editor > Code Style > Formatter Control + //@formatter:off + + + /** + * Name of the package as used to identify it in the system + */ + @DataClass.Generated.Member + public @NonNull String getPackageName() { + return mPackageName; + } + + /** + * Path where this package was found on disk. For monolithic packages + * this is path to single base APK file; for cluster packages this is + * path to the cluster directory. + */ + @DataClass.Generated.Member + public @NonNull String getPath() { + return mPath; + } + + /** + * Path of base APK + */ + @DataClass.Generated.Member + public @NonNull String getBaseApkPath() { + return mBaseApkPath; + } + + /** + * Paths of any split APKs, ordered by parsed splitName + */ + @DataClass.Generated.Member + public @Nullable String[] getSplitApkPaths() { + return mSplitApkPaths; + } + + /** + * Names of any split APKs, ordered by parsed splitName + */ + @DataClass.Generated.Member + public @Nullable String[] getSplitNames() { + return mSplitNames; + } + + /** + * Dependencies of any split APKs, ordered by parsed splitName + */ + @DataClass.Generated.Member + public @Nullable String[] getUsesSplitNames() { + return mUsesSplitNames; + } + + @DataClass.Generated.Member + public @Nullable String[] getConfigForSplit() { + return mConfigForSplit; + } + + /** + * Major and minor version number of this package + */ + @DataClass.Generated.Member + public int getVersionCodeMajor() { + return mVersionCodeMajor; + } + + @DataClass.Generated.Member + public int getVersionCode() { + return mVersionCode; + } + + /** + * Revision code of base APK + */ + @DataClass.Generated.Member + public int getBaseRevisionCode() { + return mBaseRevisionCode; + } + + /** + * Revision codes of any split APKs, ordered by parsed splitName + */ + @DataClass.Generated.Member + public @Nullable int[] getSplitRevisionCodes() { + return mSplitRevisionCodes; + } + + /** + * Indicate the install location of this package + * + * @see {@link PackageInfo#INSTALL_LOCATION_AUTO} + * @see {@link PackageInfo#INSTALL_LOCATION_INTERNAL_ONLY} + * @see {@link PackageInfo#INSTALL_LOCATION_PREFER_EXTERNAL} + */ + @DataClass.Generated.Member + public int getInstallLocation() { + return mInstallLocation; + } + + /** + * Information about a package verifiers as used during package verification + */ + @DataClass.Generated.Member + public @NonNull VerifierInfo[] getVerifiers() { + return mVerifiers; + } + + /** + * Indicate whether any split APKs that are features. Ordered by splitName + */ + @DataClass.Generated.Member + public @Nullable boolean[] getIsFeatureSplits() { + return mIsFeatureSplits; + } + + /** + * Indicate whether each split should be load into their own Context objects + */ + @DataClass.Generated.Member + public boolean isIsolatedSplits() { + return mIsolatedSplits; + } + + /** + * Indicate whether this package requires at least one split (either feature or resource) + * to be present in order to function + */ + @DataClass.Generated.Member + public boolean isSplitRequired() { + return mSplitRequired; + } + + /** + * Indicate whether this app is coreApp + */ + @DataClass.Generated.Member + public boolean isCoreApp() { + return mCoreApp; + } + + /** + * Indicate whether this app can be debugged + */ + @DataClass.Generated.Member + public boolean isDebuggable() { + return mDebuggable; + } + + /** + * Indicate whether this app needs to be loaded into other applications' processes + */ + @DataClass.Generated.Member + public boolean isMultiArch() { + return mMultiArch; + } + + /** + * Indicate whether the 32 bit version of the ABI should be used + */ + @DataClass.Generated.Member + public boolean isUse32bitAbi() { + return mUse32bitAbi; + } + + /** + * Indicate whether installer extracts native libraries + */ + @DataClass.Generated.Member + public boolean isExtractNativeLibs() { + return mExtractNativeLibs; + } + + /** + * Indicate whether this app is profileable by Shell + */ + @DataClass.Generated.Member + public boolean isProfileableByShell() { + return mProfileableByShell; + } + + /** + * Indicate whether this package wants to run the dex within its APK but not extracted + * or locally compiled variants. + */ + @DataClass.Generated.Member + public boolean isUseEmbeddedDex() { + return mUseEmbeddedDex; + } + + @DataClass.Generated( + time = 1610596639255L, + codegenVersion = "1.0.22", + sourceFile = "frameworks/base/core/java/android/content/pm/parsing/PackageLite.java", + inputSignatures = "private final @android.annotation.NonNull java.lang.String mPackageName\nprivate final @android.annotation.NonNull java.lang.String mPath\nprivate final @android.annotation.NonNull java.lang.String mBaseApkPath\nprivate final @android.annotation.Nullable java.lang.String[] mSplitApkPaths\nprivate final @android.annotation.Nullable java.lang.String[] mSplitNames\nprivate final @android.annotation.Nullable java.lang.String[] mUsesSplitNames\nprivate final @android.annotation.Nullable java.lang.String[] mConfigForSplit\nprivate final int mVersionCodeMajor\nprivate final int mVersionCode\nprivate final int mBaseRevisionCode\nprivate final @android.annotation.Nullable int[] mSplitRevisionCodes\nprivate final int mInstallLocation\nprivate final @android.annotation.NonNull android.content.pm.VerifierInfo[] mVerifiers\nprivate final @android.annotation.Nullable boolean[] mIsFeatureSplits\nprivate final boolean mIsolatedSplits\nprivate final boolean mSplitRequired\nprivate final boolean mCoreApp\nprivate final boolean mDebuggable\nprivate final boolean mMultiArch\nprivate final boolean mUse32bitAbi\nprivate final boolean mExtractNativeLibs\nprivate final boolean mProfileableByShell\nprivate final boolean mUseEmbeddedDex\npublic java.util.List getAllApkPaths()\npublic long getLongVersionCode()\nclass PackageLite extends java.lang.Object implements []\n@com.android.internal.util.DataClass(genConstructor=false, genConstDefs=false)") + @Deprecated + private void __metadata() {} + + + //@formatter:on + // End of generated code + +} diff --git a/core/java/android/content/pm/parsing/ParsingPackageUtils.java b/core/java/android/content/pm/parsing/ParsingPackageUtils.java index 561a9e31b4b02..494b3cc1c28f8 100644 --- a/core/java/android/content/pm/parsing/ParsingPackageUtils.java +++ b/core/java/android/content/pm/parsing/ParsingPackageUtils.java @@ -29,6 +29,7 @@ import static android.os.Trace.TRACE_TAG_PACKAGE_MANAGER; import android.annotation.AnyRes; import android.annotation.CheckResult; +import android.annotation.IntDef; import android.annotation.IntRange; import android.annotation.NonNull; import android.annotation.Nullable; @@ -112,6 +113,8 @@ import org.xmlpull.v1.XmlPullParserException; import java.io.File; import java.io.IOException; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; import java.security.PublicKey; import java.util.ArrayList; import java.util.Arrays; @@ -130,6 +133,82 @@ public class ParsingPackageUtils { private static final String TAG = ParsingUtils.TAG; + public static final boolean DEBUG_JAR = false; + public static final boolean DEBUG_BACKUP = false; + public static final float DEFAULT_PRE_O_MAX_ASPECT_RATIO = 1.86f; + + /** File name in an APK for the Android manifest. */ + public static final String ANDROID_MANIFEST_FILENAME = "AndroidManifest.xml"; + + /** Path prefix for apps on expanded storage */ + public static final String MNT_EXPAND = "/mnt/expand/"; + + public static final String TAG_ADOPT_PERMISSIONS = "adopt-permissions"; + public static final String TAG_APPLICATION = "application"; + public static final String TAG_COMPATIBLE_SCREENS = "compatible-screens"; + public static final String TAG_EAT_COMMENT = "eat-comment"; + public static final String TAG_FEATURE_GROUP = "feature-group"; + public static final String TAG_INSTRUMENTATION = "instrumentation"; + public static final String TAG_KEY_SETS = "key-sets"; + public static final String TAG_MANIFEST = "manifest"; + public static final String TAG_ORIGINAL_PACKAGE = "original-package"; + public static final String TAG_OVERLAY = "overlay"; + public static final String TAG_PACKAGE = "package"; + public static final String TAG_PACKAGE_VERIFIER = "package-verifier"; + public static final String TAG_ATTRIBUTION = "attribution"; + public static final String TAG_PERMISSION = "permission"; + public static final String TAG_PERMISSION_GROUP = "permission-group"; + public static final String TAG_PERMISSION_TREE = "permission-tree"; + public static final String TAG_PROTECTED_BROADCAST = "protected-broadcast"; + public static final String TAG_QUERIES = "queries"; + public static final String TAG_RESTRICT_UPDATE = "restrict-update"; + public static final String TAG_SUPPORT_SCREENS = "supports-screens"; + public static final String TAG_SUPPORTS_INPUT = "supports-input"; + public static final String TAG_USES_CONFIGURATION = "uses-configuration"; + public static final String TAG_USES_FEATURE = "uses-feature"; + public static final String TAG_USES_GL_TEXTURE = "uses-gl-texture"; + public static final String TAG_USES_PERMISSION = "uses-permission"; + public static final String TAG_USES_PERMISSION_SDK_23 = "uses-permission-sdk-23"; + public static final String TAG_USES_PERMISSION_SDK_M = "uses-permission-sdk-m"; + public static final String TAG_USES_SDK = "uses-sdk"; + public static final String TAG_USES_SPLIT = "uses-split"; + public static final String TAG_PROFILEABLE = "profileable"; + + public static final String METADATA_MAX_ASPECT_RATIO = "android.max_aspect"; + public static final String METADATA_SUPPORTS_SIZE_CHANGES = "android.supports_size_changes"; + public static final String METADATA_ACTIVITY_WINDOW_LAYOUT_AFFINITY = + "android.activity_window_layout_affinity"; + + public static final int SDK_VERSION = Build.VERSION.SDK_INT; + public static final String[] SDK_CODENAMES = Build.VERSION.ACTIVE_CODENAMES; + + public static boolean sCompatibilityModeEnabled = true; + public static boolean sUseRoundIcon = false; + + public static final int PARSE_DEFAULT_INSTALL_LOCATION = + PackageInfo.INSTALL_LOCATION_UNSPECIFIED; + public static final int PARSE_DEFAULT_TARGET_SANDBOX = 1; + + public static final int PARSE_MUST_BE_APK = 1 << 0; + public static final int PARSE_IGNORE_PROCESSES = 1 << 1; + public static final int PARSE_EXTERNAL_STORAGE = 1 << 3; + public static final int PARSE_IS_SYSTEM_DIR = 1 << 4; + public static final int PARSE_COLLECT_CERTIFICATES = 1 << 5; + public static final int PARSE_ENFORCE_CODE = 1 << 6; + public static final int PARSE_CHATTY = 1 << 31; + + @IntDef(flag = true, prefix = { "PARSE_" }, value = { + PARSE_CHATTY, + PARSE_COLLECT_CERTIFICATES, + PARSE_ENFORCE_CODE, + PARSE_EXTERNAL_STORAGE, + PARSE_IGNORE_PROCESSES, + PARSE_IS_SYSTEM_DIR, + PARSE_MUST_BE_APK, + }) + @Retention(RetentionPolicy.SOURCE) + public @interface ParseFlags {} + /** * For those names would be used as a part of the file name. Limits size to 223 and reserves 32 * for the OS. diff --git a/core/java/android/content/pm/parsing/component/ParsedActivityUtils.java b/core/java/android/content/pm/parsing/component/ParsedActivityUtils.java index 0d7198d4aa4ae..f96bd5400cd2b 100644 --- a/core/java/android/content/pm/parsing/component/ParsedActivityUtils.java +++ b/core/java/android/content/pm/parsing/component/ParsedActivityUtils.java @@ -21,6 +21,7 @@ import static android.content.pm.parsing.component.ComponentParseUtils.flag; import android.annotation.NonNull; import android.app.ActivityTaskManager; +import android.content.Intent; import android.content.pm.ActivityInfo; import android.content.pm.PackageParser; import android.content.pm.parsing.ParsingPackage; @@ -33,6 +34,7 @@ import android.content.res.Resources; import android.content.res.TypedArray; import android.content.res.XmlResourceParser; import android.os.Build; +import android.util.ArraySet; import android.util.AttributeSet; import android.util.Log; import android.util.Slog; @@ -50,12 +52,21 @@ import org.xmlpull.v1.XmlPullParserException; import java.io.IOException; import java.util.List; import java.util.Objects; +import java.util.Set; /** @hide */ public class ParsedActivityUtils { private static final String TAG = ParsingUtils.TAG; + public static final boolean LOG_UNSAFE_BROADCASTS = false; + + // Set of broadcast actions that are safe for manifest receivers + public static final Set SAFE_BROADCASTS = new ArraySet<>(); + static { + SAFE_BROADCASTS.add(Intent.ACTION_BOOT_COMPLETED); + } + @NonNull @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) public static ParseResult parseActivityOrReceiver(String[] separateProcesses, diff --git a/core/java/android/content/pm/parsing/component/ParsedIntentInfoUtils.java b/core/java/android/content/pm/parsing/component/ParsedIntentInfoUtils.java index c0536bb7eb106..0a2c86833d2fc 100644 --- a/core/java/android/content/pm/parsing/component/ParsedIntentInfoUtils.java +++ b/core/java/android/content/pm/parsing/component/ParsedIntentInfoUtils.java @@ -44,6 +44,8 @@ public class ParsedIntentInfoUtils { private static final String TAG = ParsingUtils.TAG; + public static final boolean DEBUG = false; + @NonNull public static ParseResult parseIntentInfo(String className, ParsingPackage pkg, Resources res, XmlResourceParser parser, boolean allowGlobs, diff --git a/services/core/java/com/android/server/pm/PackageInstallerSession.java b/services/core/java/com/android/server/pm/PackageInstallerSession.java index 3d04b56079227..874113092244f 100644 --- a/services/core/java/com/android/server/pm/PackageInstallerSession.java +++ b/services/core/java/com/android/server/pm/PackageInstallerSession.java @@ -30,7 +30,6 @@ import static android.content.pm.PackageManager.INSTALL_FAILED_MISSING_SPLIT; import static android.content.pm.PackageManager.INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING; import static android.content.pm.PackageManager.INSTALL_STAGED; import static android.content.pm.PackageManager.INSTALL_SUCCEEDED; -import static android.content.pm.PackageParser.APEX_FILE_EXTENSION; import static android.system.OsConstants.O_CREAT; import static android.system.OsConstants.O_RDONLY; import static android.system.OsConstants.O_WRONLY; @@ -254,6 +253,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { private static final ApkChecksum[] EMPTY_FILE_CHECKSUM_ARRAY = {}; private static final String SYSTEM_DATA_LOADER_PACKAGE = "android"; + private static final String APEX_FILE_EXTENSION = ".apex"; private static final int INCREMENTAL_STORAGE_BLOCKED_TIMEOUT_MS = 2000; private static final int INCREMENTAL_STORAGE_UNHEALTHY_TIMEOUT_MS = 7000;