From 01e38f40c217c3a3ae1cfb5369e7ef2aa356e75c Mon Sep 17 00:00:00 2001 From: Winson Date: Fri, 24 Jan 2020 11:50:11 -0800 Subject: [PATCH] Separate ParsingPackage into core and ParsedPackage into server PackageParser exists in the core framework SDK, and so callers to it would not not expect a call into the system server. However, some planned features require parts of parsing to exist in the server so that package state/settings contained in the server can be applied to the package. To resolve this, separate ParsingPackage and ParsedPackage through a hard boundary, where ParsingPackageImpl is roughly equivalent to the previous PackageImpl, and the new PackageImpl is everything that should exist in the server and not core. This also copies over documentation and cleans up the data models significantly. The fields have been moved to @NonNull, and in preparation for true immutability, all Collection structures have moved to generic types and assigned Collections#empty_(). This begins moving away from @hide AppInfo fields, so internal use of flags/privateFlags is deprecated. It is now replaced by straight booleans. For simplicity's sake, existing flags have also been migrated. This is split for readability and will not compile without the followup commits. Bug: 135203078 Test: atest com.android.server.pm.parsing Test: atest PackageParserTest Test: atest PackageParserLegacyCoreTest Test: atest ScanTests Test: atest ParallelPackageParserTest Test: manual toggle and run AndroidPackageParsingTestBase Change-Id: Ib4fe51d729a56bfb0ea1316e577358ba0dfceccf --- .../content/pm/parsing/AndroidPackage.java | 497 --- .../content/pm/parsing/PackageImpl.java | 3379 ----------------- .../content/pm/parsing/ParsingPackage.java | 62 +- .../pm/parsing/ParsingPackageImpl.java | 2585 +++++++++++++ .../pm/parsing/ParsingPackageRead.java | 844 ++++ .../pm/parsing/pkg}/AndroidPackage.aidl | 0 .../server/pm/parsing/pkg/AndroidPackage.java | 368 ++ .../pm/parsing/pkg/AndroidPackageUtils.java | 238 ++ .../pm/parsing/pkg}/AndroidPackageWrite.java | 4 +- .../server/pm/parsing/pkg/PackageImpl.java | 968 +++++ .../server/pm/parsing/pkg}/ParsedPackage.java | 43 +- .../server/pm/parsing/pkg/PkgAppInfo.java | 493 +++ .../server/pm/parsing/pkg/PkgPackageInfo.java | 225 ++ 13 files changed, 5762 insertions(+), 3944 deletions(-) delete mode 100644 core/java/android/content/pm/parsing/AndroidPackage.java delete mode 100644 core/java/android/content/pm/parsing/PackageImpl.java create mode 100644 core/java/android/content/pm/parsing/ParsingPackageImpl.java create mode 100644 core/java/android/content/pm/parsing/ParsingPackageRead.java rename {core/java/android/content/pm/parsing => services/core/java/com/android/server/pm/parsing/pkg}/AndroidPackage.aidl (100%) create mode 100644 services/core/java/com/android/server/pm/parsing/pkg/AndroidPackage.java create mode 100644 services/core/java/com/android/server/pm/parsing/pkg/AndroidPackageUtils.java rename {core/java/android/content/pm/parsing => services/core/java/com/android/server/pm/parsing/pkg}/AndroidPackageWrite.java (95%) create mode 100644 services/core/java/com/android/server/pm/parsing/pkg/PackageImpl.java rename {core/java/android/content/pm/parsing => services/core/java/com/android/server/pm/parsing/pkg}/ParsedPackage.java (75%) create mode 100644 services/core/java/com/android/server/pm/parsing/pkg/PkgAppInfo.java create mode 100644 services/core/java/com/android/server/pm/parsing/pkg/PkgPackageInfo.java diff --git a/core/java/android/content/pm/parsing/AndroidPackage.java b/core/java/android/content/pm/parsing/AndroidPackage.java deleted file mode 100644 index 2003ce27a214c..0000000000000 --- a/core/java/android/content/pm/parsing/AndroidPackage.java +++ /dev/null @@ -1,497 +0,0 @@ -/* - * Copyright (C) 2019 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.Nullable; -import android.content.Intent; -import android.content.pm.ApplicationInfo; -import android.content.pm.ConfigurationInfo; -import android.content.pm.FeatureGroupInfo; -import android.content.pm.FeatureInfo; -import android.content.pm.PackageParser; -import android.content.pm.PackageUserState; -import android.content.pm.SharedLibraryInfo; -import android.content.pm.parsing.ComponentParseUtils.ParsedActivity; -import android.content.pm.parsing.ComponentParseUtils.ParsedActivityIntentInfo; -import android.content.pm.parsing.ComponentParseUtils.ParsedFeature; -import android.content.pm.parsing.ComponentParseUtils.ParsedInstrumentation; -import android.content.pm.parsing.ComponentParseUtils.ParsedPermission; -import android.content.pm.parsing.ComponentParseUtils.ParsedPermissionGroup; -import android.content.pm.parsing.ComponentParseUtils.ParsedProvider; -import android.content.pm.parsing.ComponentParseUtils.ParsedService; -import android.os.Bundle; -import android.os.Parcel; -import android.os.Parcelable; -import android.util.ArrayMap; -import android.util.ArraySet; -import android.util.SparseArray; - -import java.security.PublicKey; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.UUID; - -/** - * The last state of a package during parsing/install before it is available in - * {@link com.android.server.pm.PackageManagerService#mPackages}. - * - * It is the responsibility of the caller to understand what data is available at what step of the - * parsing or install process. - * - * TODO(b/135203078): Nullability annotations - * TODO(b/135203078): Remove get/setAppInfo differences - * - * @hide - */ -public interface AndroidPackage extends Parcelable { - - /** - * This will eventually be removed. Avoid calling this at all costs. - */ - @Deprecated - AndroidPackageWrite mutate(); - - boolean canHaveOatDir(); - - boolean cantSaveState(); - - List getAdoptPermissions(); - - List getAllCodePaths(); - - List getAllCodePathsExcludingResourceOnly(); - - String getAppComponentFactory(); - - /** - * TODO(b/135203078): Use non-AppInfo method - * @deprecated use {@link #getClassLoaderName()} - */ - @Deprecated - String getAppInfoClassLoaderName(); - - /** - * TODO(b/135203078): Use non-AppInfo method - * @deprecated use {@link #getCodePath()} - */ - @Deprecated - String getAppInfoCodePath(); - - /** - * TODO(b/135203078): Use non-AppInfo method - * @deprecated use {@link #getName()} - */ - @Deprecated - String getAppInfoName(); - - /** - * TODO(b/135203078): Use non-AppInfo method - * @deprecated use {@link #getPackageName()} - */ - @Deprecated - String getAppInfoPackageName(); - - /** - * TODO(b/135203078): Use non-AppInfo method - * @deprecated use {@link #getProcessName()} - */ - @Deprecated - String getAppInfoProcessName(); - - /** - * TODO(b/135203078): Use non-AppInfo method - * @deprecated use {@link #getCodePath()} - */ - @Deprecated - String getAppInfoResourcePath(); - - Bundle getAppMetaData(); - - /** - * TODO(b/135203078): Use non-AppInfo method - * @deprecated use {@link #getVolumeUuid()} - */ - @Deprecated - String getApplicationInfoVolumeUuid(); - - String getBackupAgentName(); - - int getBanner(); - - String getBaseCodePath(); - - int getBaseRevisionCode(); - - int getCategory(); - - String getClassLoaderName(); - - String getClassName(); - - String getCodePath(); - - int getCompatibleWidthLimitDp(); - - int getCompileSdkVersion(); - - String getCompileSdkVersionCodeName(); - - @Nullable - List getConfigPreferences(); - - String getCpuAbiOverride(); - - String getCredentialProtectedDataDir(); - - String getDataDir(); - - int getDescriptionRes(); - - String getDeviceProtectedDataDir(); - - List getFeatureGroups(); - - int getFlags(); - - int getFullBackupContent(); - - int getHiddenApiEnforcementPolicy(); - - int getIcon(); - - int getIconRes(); - - List getImplicitPermissions(); - - int getInstallLocation(); - - Map> getKeySetMapping(); - - int getLabelRes(); - - int getLargestWidthLimitDp(); - - long[] getLastPackageUsageTimeInMills(); - - long getLatestForegroundPackageUseTimeInMills(); - - long getLatestPackageUseTimeInMills(); - - List getLibraryNames(); - - int getLogo(); - - long getLongVersionCode(); - - String getManageSpaceActivityName(); - - String getManifestPackageName(); - - float getMaxAspectRatio(); - - Bundle getMetaData(); // TODO(b/135203078): Make all the Bundles immutable - - @Nullable - Set getMimeGroups(); - - float getMinAspectRatio(); - - int getMinSdkVersion(); - - String getName(); - - String getNativeLibraryDir(); - - String getNativeLibraryRootDir(); - - int getNetworkSecurityConfigRes(); - - CharSequence getNonLocalizedLabel(); - - @Nullable - List getOriginalPackages(); - - String getOverlayCategory(); - - int getOverlayPriority(); - - String getOverlayTarget(); - - String getOverlayTargetName(); - - /** - * Map of overlayable name to actor name. - */ - Map getOverlayables(); - - // TODO(b/135203078): Does this and getAppInfoPackageName have to be separate methods? - // The refactor makes them the same value with no known consequences, so should be redundant. - String getPackageName(); - - @Nullable - List getActivities(); - - @Nullable - List getInstrumentations(); - - @Nullable - List getFeatures(); - - @Nullable - List getPermissionGroups(); - - @Nullable - List getPermissions(); - - @Nullable - List getProviders(); - - @Nullable - List getReceivers(); - - @Nullable - List getServices(); - - String getPermission(); - - @Nullable - List getPreferredActivityFilters(); - - int getPreferredOrder(); - - String getPrimaryCpuAbi(); - - int getPrivateFlags(); - - String getProcessName(); - - @Nullable - List getProtectedBroadcasts(); - - String getPublicSourceDir(); - - List getQueriesIntents(); - - List getQueriesPackages(); - - Set getQueriesProviders(); - - String getRealPackage(); - - // TODO(b/135203078): Rename to getRequiredFeatures? Somewhat ambiguous whether "Req" is - // required or requested. - @Nullable - List getReqFeatures(); - - List getRequestedPermissions(); - - String getRequiredAccountType(); - - int getRequiresSmallestWidthDp(); - - byte[] getRestrictUpdateHash(); - - String getRestrictedAccountType(); - - int getRoundIconRes(); - - String getScanPublicSourceDir(); - - String getScanSourceDir(); - - String getSeInfo(); - - String getSeInfoUser(); - - String getSecondaryCpuAbi(); - - String getSecondaryNativeLibraryDir(); - - String getSharedUserId(); - - int getSharedUserLabel(); - - PackageParser.SigningDetails getSigningDetails(); - - String[] getSplitClassLoaderNames(); - - @Nullable - String[] getSplitCodePaths(); - - @Nullable - SparseArray getSplitDependencies(); - - int[] getSplitFlags(); - - String[] getSplitNames(); - - String[] getSplitPublicSourceDirs(); - - int[] getSplitRevisionCodes(); - - String getStaticSharedLibName(); - - long getStaticSharedLibVersion(); - - // TODO(b/135203078): Return String directly - UUID getStorageUuid(); - - int getTargetSandboxVersion(); - - int getTargetSdkVersion(); - - String getTaskAffinity(); - - int getTheme(); - - int getUiOptions(); - - int getUid(); - - Set getUpgradeKeySets(); - - @Nullable - List getUsesLibraries(); - - @Nullable - String[] getUsesLibraryFiles(); - - List getUsesLibraryInfos(); - - @Nullable - List getUsesOptionalLibraries(); - - @Nullable - List getUsesStaticLibraries(); - - @Nullable - String[][] getUsesStaticLibrariesCertDigests(); - - @Nullable - long[] getUsesStaticLibrariesVersions(); - - @Nullable - ArrayMap getProcesses(); - - int getVersionCode(); - - int getVersionCodeMajor(); - - String getVersionName(); - - String getVolumeUuid(); - - String getZygotePreloadName(); - - boolean hasComponentClassName(String className); - - boolean hasPreserveLegacyExternalStorage(); - - // App Info - - boolean hasRequestedLegacyExternalStorage(); - - boolean isBaseHardwareAccelerated(); - - boolean isCoreApp(); - - boolean isDefaultToDeviceProtectedStorage(); - - boolean isDirectBootAware(); - - boolean isEmbeddedDexUsed(); - - boolean isEnabled(); - - boolean isCrossProfile(); - - boolean isEncryptionAware(); - - boolean isExternal(); - - boolean isForceQueryable(); - - boolean isForwardLocked(); - - boolean isHiddenUntilInstalled(); - - boolean isInstantApp(); - - boolean isInternal(); - - boolean isLibrary(); - - // TODO(b/135203078): Should probably be in a utility class - boolean isMatch(int flags); - - boolean isNativeLibraryRootRequiresIsa(); - - boolean isOem(); - - boolean isOverlayIsStatic(); - - boolean isPrivileged(); - - boolean isProduct(); - - boolean isProfileableByShell(); - - boolean isRequiredForAllUsers(); - - boolean isStaticSharedLibrary(); - - boolean isStub(); - - boolean isSystem(); // TODO(b/135203078): Collapse with isSystemApp, should be exactly the same. - - boolean isSystemApp(); - - boolean isSystemExt(); - - boolean isUpdatedSystemApp(); - - boolean isUse32BitAbi(); - - boolean isVendor(); - - boolean isVisibleToInstantApps(); - - List makeListAllCodePaths(); // TODO(b/135203078): Collapse with getAllCodePaths - - boolean requestsIsolatedSplitLoading(); - - /** - * Generates an {@link ApplicationInfo} object with only the data available in this object. - * - * This does not contain any system or user state data, and should be avoided. Prefer - * {@link PackageInfoUtils#generateApplicationInfo(AndroidPackage, int, PackageUserState, int)}. - */ - ApplicationInfo toAppInfoWithoutState(); - - Creator CREATOR = new Creator() { - @Override - public PackageImpl createFromParcel(Parcel source) { - return new PackageImpl(source); - } - - @Override - public PackageImpl[] newArray(int size) { - return new PackageImpl[size]; - } - }; -} diff --git a/core/java/android/content/pm/parsing/PackageImpl.java b/core/java/android/content/pm/parsing/PackageImpl.java deleted file mode 100644 index d06865b65f2d9..0000000000000 --- a/core/java/android/content/pm/parsing/PackageImpl.java +++ /dev/null @@ -1,3379 +0,0 @@ -/* - * Copyright (C) 2019 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 static android.os.Build.VERSION_CODES.DONUT; - -import static java.util.Collections.emptyMap; - -import android.annotation.NonNull; -import android.annotation.Nullable; -import android.content.Intent; -import android.content.IntentFilter; -import android.content.pm.ActivityInfo; -import android.content.pm.ApplicationInfo; -import android.content.pm.ConfigurationInfo; -import android.content.pm.FeatureGroupInfo; -import android.content.pm.FeatureInfo; -import android.content.pm.PackageInfo; -import android.content.pm.PackageManager; -import android.content.pm.PackageParser; -import android.content.pm.ProviderInfo; -import android.content.pm.ServiceInfo; -import android.content.pm.SharedLibraryInfo; -import android.content.pm.parsing.ComponentParseUtils.ParsedActivity; -import android.content.pm.parsing.ComponentParseUtils.ParsedActivityIntentInfo; -import android.content.pm.parsing.ComponentParseUtils.ParsedComponent; -import android.content.pm.parsing.ComponentParseUtils.ParsedFeature; -import android.content.pm.parsing.ComponentParseUtils.ParsedInstrumentation; -import android.content.pm.parsing.ComponentParseUtils.ParsedIntentInfo; -import android.content.pm.parsing.ComponentParseUtils.ParsedPermission; -import android.content.pm.parsing.ComponentParseUtils.ParsedPermissionGroup; -import android.content.pm.parsing.ComponentParseUtils.ParsedProvider; -import android.content.pm.parsing.ComponentParseUtils.ParsedService; -import android.content.res.TypedArray; -import android.os.Build; -import android.os.Bundle; -import android.os.Environment; -import android.os.Parcel; -import android.os.UserHandle; -import android.os.storage.StorageManager; -import android.text.TextUtils; -import android.util.ArrayMap; -import android.util.ArraySet; -import android.util.SparseArray; - -import com.android.internal.R; -import com.android.internal.annotations.VisibleForTesting; -import com.android.internal.util.ArrayUtils; -import com.android.internal.util.CollectionUtils; -import com.android.server.SystemConfig; - -import java.security.PublicKey; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Set; -import java.util.UUID; - -/** - * The backing data for a package that was parsed from disk. - * - * TODO(b/135203078): Convert Lists used as sets into Sets, to better express intended use case - * TODO(b/135203078): Field nullability annotations - * TODO(b/135203078): Convert = 1 fields into Booleans - * TODO(b/135203078): Make all lists nullable and Collections.unmodifiable immutable when returned. - * Prefer add/set methods if adding is necessary. - * TODO(b/135203078): Consider comments to disable auto-format and single-line, single-space all the - * get/set methods to make this class far more compact. Maybe even separate some logic into parent - * classes, assuming there is no overhead. - * TODO(b/135203078): Copy documentation from PackageParser#Package for the relevant fields included - * here. Should clarify and clean up any differences. Also consider renames if it helps make - * things clearer. - * TODO(b/135203078): Intern all possibl e String values? Initial refactor just mirrored old - * behavior. - * - * @hide - */ -public final class PackageImpl implements ParsingPackage, ParsedPackage, AndroidPackage, - AndroidPackageWrite { - - private static final String TAG = "PackageImpl"; - - // Resource boolean are -1, so 1 means we don't know the value. - private int supportsSmallScreens = 1; - private int supportsNormalScreens = 1; - private int supportsLargeScreens = 1; - private int supportsXLargeScreens = 1; - private int resizeable = 1; - private int anyDensity = 1; - - private long[] lastPackageUsageTimeInMills = - new long[PackageManager.NOTIFY_PACKAGE_USE_REASONS_COUNT]; - - private int versionCode; - private int versionCodeMajor; - private int baseRevisionCode; - private String versionName; - - private boolean coreApp; - private int compileSdkVersion; - private String compileSdkVersionCodename; - - private String packageName; - private String realPackage; - private String manifestPackageName; - private String baseCodePath; - - private boolean requiredForAllUsers; - private String restrictedAccountType; - private String requiredAccountType; - - private boolean baseHardwareAccelerated; - - private String overlayTarget; - private String overlayTargetName; - private String overlayCategory; - private int overlayPriority; - private boolean overlayIsStatic; - private Map overlayables = emptyMap(); - - private String staticSharedLibName; - private long staticSharedLibVersion; - private ArrayList libraryNames; - private ArrayList usesLibraries; - private ArrayList usesOptionalLibraries; - - private ArrayList usesStaticLibraries; - private long[] usesStaticLibrariesVersions; - private String[][] usesStaticLibrariesCertDigests; - - private String sharedUserId; - - private int sharedUserLabel; - private ArrayList configPreferences; - private ArrayList reqFeatures; - private ArrayList featureGroups; - - private byte[] restrictUpdateHash; - - private ArrayList originalPackages; - private ArrayList adoptPermissions; - - private ArrayList requestedPermissions; - private ArrayList implicitPermissions; - - private ArraySet upgradeKeySets; - private Map> keySetMapping; - - private ArrayList protectedBroadcasts; - - @Nullable - private ArrayList activities; - - @Nullable - private ArrayList receivers; - - @Nullable - private ArrayList services; - - @Nullable - private ArrayList providers; - - @Nullable - private ArrayList features; - - @Nullable - private ArrayList permissions; - - @Nullable - private ArrayList permissionGroups; - - @Nullable - private ArrayList instrumentations; - - private ArrayList preferredActivityFilters; - - private Bundle appMetaData; - - private String volumeUuid; - private String applicationVolumeUuid; - private PackageParser.SigningDetails signingDetails; - - private String codePath; - - private boolean use32BitAbi; - private boolean visibleToInstantApps; - - private String cpuAbiOverride; - - private boolean isStub; - - // TODO(b/135203078): Remove, should be unused - private int preferredOrder; - - private boolean forceQueryable; - - @Nullable - private ArrayList queriesIntents; - - @Nullable - private ArrayList queriesPackages; - - @Nullable - private ArraySet queriesProviders; - - @Nullable - private ArrayMap processes; - - private String[] splitClassLoaderNames; - private String[] splitCodePaths; - private SparseArray splitDependencies; - private int[] splitFlags; - private String[] splitNames; - private int[] splitRevisionCodes; - - // TODO(b/135203078): Audit applicationInfo.something usages, which may be different from - // package.something usages. There were differing cases of package.field = versus - // package.appInfo.field =. This class assumes some obvious ones, like packageName, - // were collapsible, but kept the following separate. - - private String applicationInfoBaseResourcePath; - private String applicationInfoCodePath; - private String applicationInfoResourcePath; - private String[] applicationInfoSplitResourcePaths; - - private String appComponentFactory; - private String backupAgentName; - private int banner; - private int category; - private String classLoaderName; - private String className; - private int compatibleWidthLimitDp; - private String credentialProtectedDataDir; - private String dataDir; - private int descriptionRes; - private String deviceProtectedDataDir; - private boolean enabled; - private boolean crossProfile; - private int flags; - private int fullBackupContent; - private boolean hiddenUntilInstalled; - private int icon; - private int iconRes; - private int installLocation = PackageParser.PARSE_DEFAULT_INSTALL_LOCATION; - private int labelRes; - private int largestWidthLimitDp; - private int logo; - private String manageSpaceActivityName; - private float maxAspectRatio; - private float minAspectRatio; - private int minSdkVersion; - private String name; - private String nativeLibraryDir; - private String nativeLibraryRootDir; - private boolean nativeLibraryRootRequiresIsa; - private int networkSecurityConfigRes; - private CharSequence nonLocalizedLabel; - private String permission; - private String primaryCpuAbi; - private int privateFlags; - private String processName; - private int requiresSmallestWidthDp; - private int roundIconRes; - private String secondaryCpuAbi; - private String secondaryNativeLibraryDir; - private String seInfo; - private String seInfoUser; - private int targetSandboxVersion; - private int targetSdkVersion; - private String taskAffinity; - private int theme; - private int uid = -1; - private int uiOptions; - private String[] usesLibraryFiles; - private List usesLibraryInfos; - private String zygotePreloadName; - private boolean preserveLegacyExternalStorage; - - @Nullable - private ArraySet mimeGroups; - - @VisibleForTesting - public PackageImpl( - String packageName, - String baseCodePath, - TypedArray manifestArray, - boolean isCoreApp - ) { - this.packageName = TextUtils.safeIntern(packageName); - this.manifestPackageName = this.packageName; - this.baseCodePath = baseCodePath; - - this.versionCode = manifestArray.getInteger(R.styleable.AndroidManifest_versionCode, 0); - this.versionCodeMajor = manifestArray.getInteger( - R.styleable.AndroidManifest_versionCodeMajor, 0); - this.baseRevisionCode = manifestArray.getInteger(R.styleable.AndroidManifest_revisionCode, - 0); - setVersionName(manifestArray.getNonConfigurationString( - R.styleable.AndroidManifest_versionName, 0)); - this.coreApp = isCoreApp; - - this.compileSdkVersion = manifestArray.getInteger( - R.styleable.AndroidManifest_compileSdkVersion, 0); - setCompileSdkVersionCodename(manifestArray.getNonConfigurationString( - R.styleable.AndroidManifest_compileSdkVersionCodename, 0)); - } - - private PackageImpl(String packageName) { - this.packageName = TextUtils.safeIntern(packageName); - this.manifestPackageName = this.packageName; - } - - @VisibleForTesting - public static ParsingPackage forParsing(String packageName) { - return new PackageImpl(packageName); - } - - @VisibleForTesting - public static ParsingPackage forParsing( - String packageName, - String baseCodePath, - TypedArray manifestArray, - boolean isCoreApp) { - return new PackageImpl(packageName, baseCodePath, manifestArray, isCoreApp); - } - - /** - * Mock an unavailable {@link AndroidPackage} to use when removing a package from the system. - * This can occur if the package was installed on a storage device that has since been removed. - * Since the infrastructure uses {@link AndroidPackage}, but for this case only cares about - * volumeUuid, just fake it rather than having separate method paths. - */ - public static AndroidPackage buildFakeForDeletion(String packageName, String volumeUuid) { - return new PackageImpl(packageName) - .setVolumeUuid(volumeUuid) - .hideAsParsed() - .hideAsFinal(); - } - - @Override - public ParsedPackage hideAsParsed() { - return this; - } - - @Override - public AndroidPackage hideAsFinal() { - updateFlags(); - return this; - } - - @Override - @Deprecated - public AndroidPackageWrite mutate() { - return this; - } - - private void updateFlags() { - if (supportsSmallScreens < 0 || (supportsSmallScreens > 0 - && targetSdkVersion - >= Build.VERSION_CODES.DONUT)) { - this.flags |= ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS; - } - if (supportsNormalScreens != 0) { - this.flags |= ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS; - } - if (supportsLargeScreens < 0 || (supportsLargeScreens > 0 - && targetSdkVersion - >= Build.VERSION_CODES.DONUT)) { - this.flags |= ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS; - } - if (supportsXLargeScreens < 0 || (supportsXLargeScreens > 0 - && targetSdkVersion - >= Build.VERSION_CODES.GINGERBREAD)) { - this.flags |= ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS; - } - if (resizeable < 0 || (resizeable > 0 - && targetSdkVersion - >= Build.VERSION_CODES.DONUT)) { - this.flags |= ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS; - } - if (anyDensity < 0 || (anyDensity > 0 - && targetSdkVersion - >= Build.VERSION_CODES.DONUT)) { - this.flags |= ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES; - } - } - - @Override - public boolean usesCompatibilityMode() { - int flags = 0; - - if (supportsSmallScreens < 0 || (supportsSmallScreens > 0 - && targetSdkVersion - >= Build.VERSION_CODES.DONUT)) { - flags |= ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS; - } - if (supportsNormalScreens != 0) { - flags |= ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS; - } - if (supportsLargeScreens < 0 || (supportsLargeScreens > 0 - && targetSdkVersion - >= Build.VERSION_CODES.DONUT)) { - flags |= ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS; - } - if (supportsXLargeScreens < 0 || (supportsXLargeScreens > 0 - && targetSdkVersion - >= Build.VERSION_CODES.GINGERBREAD)) { - flags |= ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS; - } - if (resizeable < 0 || (resizeable > 0 - && targetSdkVersion - >= Build.VERSION_CODES.DONUT)) { - flags |= ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS; - } - if (anyDensity < 0 || (anyDensity > 0 - && targetSdkVersion - >= Build.VERSION_CODES.DONUT)) { - flags |= ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES; - } - - return targetSdkVersion < DONUT - || (flags & (ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS - | ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS - | ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS - | ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS - | ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES - | ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS)) == 0; - } - - @Override - public String getBaseCodePath() { - return baseCodePath; - } - - @Override - public int getTargetSdkVersion() { - return targetSdkVersion; - } - - @Override - public String getPackageName() { - return packageName; - } - - @Override - public String getProcessName() { - return processName; - } - - @Override - public String getPermission() { - return permission; - } - - @Override - public String getStaticSharedLibName() { - return staticSharedLibName; - } - - @Override - public long getStaticSharedLibVersion() { - return staticSharedLibVersion; - } - - @Override - public String getSharedUserId() { - return sharedUserId; - } - - @Override - public List getRequestedPermissions() { - return requestedPermissions == null ? Collections.emptyList() : requestedPermissions; - } - - @Nullable - @Override - public List getInstrumentations() { - return instrumentations; - } - - @Override - public Map> getKeySetMapping() { - return keySetMapping == null ? emptyMap() : keySetMapping; - } - - @Override - public float getMaxAspectRatio() { - return maxAspectRatio; - } - - @Override - public float getMinAspectRatio() { - return minAspectRatio; - } - - @NonNull - @Override - public List getLibraryNames() { - return libraryNames == null ? Collections.emptyList() : libraryNames; - } - - @Override - public List getActivities() { - return activities == null ? Collections.emptyList() - : activities; - } - - @Override - public Bundle getAppMetaData() { - return appMetaData; - } - - @Nullable - @Override - public List getUsesLibraries() { - return usesLibraries; - } - - @Nullable - @Override - public List getUsesStaticLibraries() { - return usesStaticLibraries; - } - - @Nullable - @Override - public ArrayMap getProcesses() { - return processes; - } - - @Override - public boolean isBaseHardwareAccelerated() { - return baseHardwareAccelerated; - } - - @Override - public int getUiOptions() { - return uiOptions; - } - - // TODO(b/135203078): Checking flags directly can be error prone, - // consider separate interface methods? - @Override - public int getFlags() { - return flags; - } - - // TODO(b/135203078): Checking flags directly can be error prone, - // consider separate interface methods? - @Override - public int getPrivateFlags() { - return privateFlags; - } - - @Override - public String getTaskAffinity() { - return taskAffinity; - } - - @Nullable - @Override - public List getOriginalPackages() { - return originalPackages; - } - - @Override - public PackageParser.SigningDetails getSigningDetails() { - return signingDetails; - } - - @Override - public String getVolumeUuid() { - return volumeUuid; - } - - @Nullable - @Override - public List getPermissionGroups() { - return permissionGroups; - } - - @Nullable - @Override - public List getPermissions() { - return permissions; - } - - @Nullable - @Override - public List getFeatures() { - return features; - } - - @Override - public String getCpuAbiOverride() { - return cpuAbiOverride; - } - - @Override - public String getPrimaryCpuAbi() { - return primaryCpuAbi; - } - - @Override - public String getSecondaryCpuAbi() { - return secondaryCpuAbi; - } - - @Override - public boolean isUse32BitAbi() { - return use32BitAbi; - } - - @Override - public boolean isForceQueryable() { - return forceQueryable; - } - - @Override - public String getCodePath() { - return codePath; - } - - @Override - public String getNativeLibraryDir() { - return nativeLibraryDir; - } - - @Override - public String getNativeLibraryRootDir() { - return nativeLibraryRootDir; - } - - @Override - public boolean isNativeLibraryRootRequiresIsa() { - return nativeLibraryRootRequiresIsa; - } - - // TODO(b/135203078): Does nothing, remove? - @Override - public int getPreferredOrder() { - return preferredOrder; - } - - @Override - public long getLongVersionCode() { - return PackageInfo.composeLongVersionCode(versionCodeMajor, versionCode); - } - - @Override - public PackageImpl setIsOverlay(boolean isOverlay) { - this.privateFlags = isOverlay - ? this.privateFlags | ApplicationInfo.PRIVATE_FLAG_IS_RESOURCE_OVERLAY - : this.privateFlags & ~ApplicationInfo.PRIVATE_FLAG_IS_RESOURCE_OVERLAY; - return this; - } - - @Override - public PackageImpl setExternalStorage(boolean externalStorage) { - this.flags = externalStorage - ? this.flags | ApplicationInfo.FLAG_EXTERNAL_STORAGE - : this.flags & ~ApplicationInfo.FLAG_EXTERNAL_STORAGE; - return this; - } - - @Override - public PackageImpl setIsolatedSplitLoading(boolean isolatedSplitLoading) { - this.privateFlags = isolatedSplitLoading - ? this.privateFlags | ApplicationInfo.PRIVATE_FLAG_ISOLATED_SPLIT_LOADING - : this.privateFlags & ~ApplicationInfo.PRIVATE_FLAG_ISOLATED_SPLIT_LOADING; - return this; - } - - @Override - public PackageImpl sortActivities() { - Collections.sort(this.activities, (a1, a2) -> Integer.compare(a2.order, a1.order)); - return this; - } - - @Override - public PackageImpl sortReceivers() { - Collections.sort(this.receivers, (a1, a2) -> Integer.compare(a2.order, a1.order)); - return this; - } - - @Override - public PackageImpl sortServices() { - Collections.sort(this.services, (a1, a2) -> Integer.compare(a2.order, a1.order)); - return this; - } - - @Override - public PackageImpl setBaseRevisionCode(int baseRevisionCode) { - this.baseRevisionCode = baseRevisionCode; - return this; - } - - @Override - public PackageImpl setPreferredOrder(int preferredOrder) { - this.preferredOrder = preferredOrder; - return this; - } - - @Override - public PackageImpl setVersionName(String versionName) { - this.versionName = TextUtils.safeIntern(versionName); - return this; - } - - @Override - public ParsingPackage setCompileSdkVersion(int compileSdkVersion) { - this.compileSdkVersion = compileSdkVersion; - return this; - } - - @Override - public ParsingPackage setCompileSdkVersionCodename(String compileSdkVersionCodename) { - this.compileSdkVersionCodename = TextUtils.safeIntern(compileSdkVersionCodename); - return this; - } - - @Override - public PackageImpl setMaxAspectRatio(float maxAspectRatio) { - this.maxAspectRatio = maxAspectRatio; - return this; - } - - @Override - public PackageImpl setMinAspectRatio(float minAspectRatio) { - this.minAspectRatio = minAspectRatio; - return this; - } - - @Override - public PackageImpl setMinSdkVersion(int minSdkVersion) { - this.minSdkVersion = minSdkVersion; - return this; - } - - @Override - public PackageImpl setTargetSdkVersion(int targetSdkVersion) { - this.targetSdkVersion = targetSdkVersion; - return this; - } - - @Override - public PackageImpl setRealPackage(String realPackage) { - this.realPackage = realPackage; - return this; - } - - @Override - public PackageImpl addConfigPreference(ConfigurationInfo configPreference) { - this.configPreferences = ArrayUtils.add(this.configPreferences, configPreference); - return this; - } - - @Override - public PackageImpl addReqFeature(FeatureInfo reqFeature) { - this.reqFeatures = ArrayUtils.add(this.reqFeatures, reqFeature); - return this; - } - - @Override - public PackageImpl addFeatureGroup(FeatureGroupInfo featureGroup) { - this.featureGroups = ArrayUtils.add(this.featureGroups, featureGroup); - return this; - } - - @Override - public PackageImpl addProtectedBroadcast(String protectedBroadcast) { - if (this.protectedBroadcasts == null - || !this.protectedBroadcasts.contains(protectedBroadcast)) { - this.protectedBroadcasts = ArrayUtils.add(this.protectedBroadcasts, - TextUtils.safeIntern(protectedBroadcast)); - } - return this; - } - - @Override - public PackageImpl addInstrumentation(ParsedInstrumentation instrumentation) { - this.instrumentations = ArrayUtils.add(this.instrumentations, instrumentation); - return this; - } - - @Override - public PackageImpl addOriginalPackage(String originalPackage) { - this.originalPackages = ArrayUtils.add(this.originalPackages, originalPackage); - return this; - } - - @Override - public ParsingPackage addOverlayable(String overlayableName, String actorName) { - this.overlayables = CollectionUtils.add(this.overlayables, - TextUtils.safeIntern(overlayableName), TextUtils.safeIntern(actorName)); - return this; - } - - @Override - public PackageImpl addAdoptPermission(String adoptPermission) { - this.adoptPermissions = ArrayUtils.add(this.adoptPermissions, adoptPermission); - return this; - } - - @Override - public PackageImpl addFeature(ParsedFeature feature) { - this.features = ArrayUtils.add(this.features, feature); - return this; - } - - @Override - public PackageImpl addPermission(ParsedPermission permission) { - this.permissions = ArrayUtils.add(this.permissions, permission); - return this; - } - - @Override - public PackageImpl removePermission(int index) { - this.permissions.remove(index); - return this; - } - - @Override - public PackageImpl addPermissionGroup(ParsedPermissionGroup permissionGroup) { - this.permissionGroups = ArrayUtils.add(this.permissionGroups, permissionGroup); - return this; - } - - @Override - public PackageImpl addRequestedPermission(String permission) { - this.requestedPermissions = ArrayUtils.add(this.requestedPermissions, - TextUtils.safeIntern(permission)); - return this; - } - - @Override - public PackageImpl addImplicitPermission(String permission) { - this.implicitPermissions = ArrayUtils.add(this.implicitPermissions, - TextUtils.safeIntern(permission)); - return this; - } - - @Override - public PackageImpl addKeySet(String keySetName, PublicKey publicKey) { - if (keySetMapping == null) { - keySetMapping = new ArrayMap<>(); - } - - ArraySet publicKeys = keySetMapping.get(keySetName); - if (publicKeys == null) { - publicKeys = new ArraySet<>(); - keySetMapping.put(keySetName, publicKeys); - } - - publicKeys.add(publicKey); - - return this; - } - - @Override - public ParsingPackage addActivity(ParsedActivity parsedActivity) { - this.activities = ArrayUtils.add(this.activities, parsedActivity); - addMimeGroupsFromComponent(parsedActivity); - return this; - } - - @Override - public ParsingPackage addReceiver(ParsedActivity parsedReceiver) { - this.receivers = ArrayUtils.add(this.receivers, parsedReceiver); - addMimeGroupsFromComponent(parsedReceiver); - return this; - } - - @Override - public ParsingPackage addService(ParsedService parsedService) { - this.services = ArrayUtils.add(this.services, parsedService); - addMimeGroupsFromComponent(parsedService); - return this; - } - - @Override - public ParsingPackage addProvider(ParsedProvider parsedProvider) { - this.providers = ArrayUtils.add(this.providers, parsedProvider); - addMimeGroupsFromComponent(parsedProvider); - return this; - } - - @Override - public PackageImpl addLibraryName(String libraryName) { - this.libraryNames = ArrayUtils.add(this.libraryNames, TextUtils.safeIntern(libraryName)); - return this; - } - - @Override - public PackageImpl addUsesLibrary(String libraryName) { - this.usesLibraries = ArrayUtils.add(this.usesLibraries, TextUtils.safeIntern(libraryName)); - return this; - } - - @Override - public PackageImpl addUsesOptionalLibrary(String libraryName) { - this.usesOptionalLibraries = ArrayUtils.add(this.usesOptionalLibraries, - TextUtils.safeIntern(libraryName)); - return this; - } - - @Override - public PackageImpl removeUsesOptionalLibrary(String libraryName) { - this.usesOptionalLibraries = ArrayUtils.remove(this.usesOptionalLibraries, libraryName); - return this; - } - - @Override - public PackageImpl addUsesStaticLibrary(String libraryName) { - this.usesStaticLibraries = ArrayUtils.add(this.usesStaticLibraries, - TextUtils.safeIntern(libraryName)); - return this; - } - - @Override - public PackageImpl addUsesStaticLibraryVersion(long version) { - this.usesStaticLibrariesVersions = ArrayUtils.appendLong(this.usesStaticLibrariesVersions, - version, true); - return this; - } - - @Override - public PackageImpl addUsesStaticLibraryCertDigests(String[] certSha256Digests) { - this.usesStaticLibrariesCertDigests = ArrayUtils.appendElement(String[].class, - this.usesStaticLibrariesCertDigests, certSha256Digests, true); - return this; - } - - @Override - public PackageImpl addPreferredActivityFilter( - ParsedActivityIntentInfo parsedActivityIntentInfo) { - this.preferredActivityFilters = ArrayUtils.add(this.preferredActivityFilters, - parsedActivityIntentInfo); - return this; - } - - @Override - public PackageImpl addQueriesIntent(Intent intent) { - this.queriesIntents = ArrayUtils.add(this.queriesIntents, intent); - return this; - } - - @Override - public PackageImpl addQueriesPackage(String packageName) { - this.queriesPackages = ArrayUtils.add(this.queriesPackages, - TextUtils.safeIntern(packageName)); - return this; - } - - @Override - public ParsingPackage addQueriesProvider(String authority) { - this.queriesProviders = ArrayUtils.add(this.queriesProviders, authority); - return this; - } - - @Override - public PackageImpl setProcesses(ArrayMap processes) { - this.processes = processes; - return this; - } - - @Override - public PackageImpl setSupportsSmallScreens(int supportsSmallScreens) { - if (supportsSmallScreens == 1) { - return this; - } - - this.supportsSmallScreens = supportsSmallScreens; - return this; - } - - @Override - public PackageImpl setSupportsNormalScreens(int supportsNormalScreens) { - if (supportsNormalScreens == 1) { - return this; - } - - this.supportsNormalScreens = supportsNormalScreens; - return this; - } - - @Override - public PackageImpl setSupportsLargeScreens(int supportsLargeScreens) { - if (supportsLargeScreens == 1) { - return this; - } - - this.supportsLargeScreens = supportsLargeScreens; - return this; - } - - @Override - public PackageImpl setSupportsXLargeScreens(int supportsXLargeScreens) { - if (supportsXLargeScreens == 1) { - return this; - } - - this.supportsXLargeScreens = supportsXLargeScreens; - return this; - } - - @Override - public PackageImpl setResizeable(int resizeable) { - if (resizeable == 1) { - return this; - } - - this.resizeable = resizeable; - return this; - } - - @Override - public PackageImpl setAnyDensity(int anyDensity) { - if (anyDensity == 1) { - return this; - } - - this.anyDensity = anyDensity; - return this; - } - - @Override - public PackageImpl setRequiresSmallestWidthDp(int requiresSmallestWidthDp) { - this.requiresSmallestWidthDp = requiresSmallestWidthDp; - return this; - } - - @Override - public PackageImpl setCompatibleWidthLimitDp(int compatibleWidthLimitDp) { - this.compatibleWidthLimitDp = compatibleWidthLimitDp; - return this; - } - - @Override - public PackageImpl setLargestWidthLimitDp(int largestWidthLimitDp) { - this.largestWidthLimitDp = largestWidthLimitDp; - return this; - } - - @Override - public PackageImpl setInstallLocation(int installLocation) { - this.installLocation = installLocation; - return this; - } - - @Override - public PackageImpl setTargetSandboxVersion(int targetSandboxVersion) { - this.targetSandboxVersion = targetSandboxVersion; - return this; - } - - @Override - public PackageImpl setRequiredForAllUsers(boolean requiredForAllUsers) { - this.requiredForAllUsers = requiredForAllUsers; - return this; - } - - @Override - public PackageImpl setRestrictedAccountType(String restrictedAccountType) { - this.restrictedAccountType = restrictedAccountType; - return this; - } - - @Override - public PackageImpl setRequiredAccountType(String requiredAccountType) { - this.requiredAccountType = requiredAccountType; - return this; - } - - @Override - public PackageImpl setBaseHardwareAccelerated(boolean baseHardwareAccelerated) { - this.baseHardwareAccelerated = baseHardwareAccelerated; - - this.flags = baseHardwareAccelerated - ? this.flags | ApplicationInfo.FLAG_HARDWARE_ACCELERATED - : this.flags & ~ApplicationInfo.FLAG_HARDWARE_ACCELERATED; - - return this; - } - - @Override - public PackageImpl setHasDomainUrls(boolean hasDomainUrls) { - this.privateFlags = hasDomainUrls - ? this.privateFlags | ApplicationInfo.PRIVATE_FLAG_HAS_DOMAIN_URLS - : this.privateFlags & ~ApplicationInfo.PRIVATE_FLAG_HAS_DOMAIN_URLS; - return this; - } - - @Override - public PackageImpl setAppMetaData(Bundle appMetaData) { - this.appMetaData = appMetaData; - return this; - } - - @Override - public PackageImpl setOverlayTarget(String overlayTarget) { - this.overlayTarget = overlayTarget; - return this; - } - - @Override - public PackageImpl setOverlayTargetName(String overlayTargetName) { - this.overlayTargetName = overlayTargetName; - return this; - } - - @Override - public PackageImpl setOverlayCategory(String overlayCategory) { - this.overlayCategory = overlayCategory; - return this; - } - - @Override - public PackageImpl setOverlayPriority(int overlayPriority) { - this.overlayPriority = overlayPriority; - return this; - } - - @Override - public PackageImpl setOverlayIsStatic(boolean overlayIsStatic) { - this.overlayIsStatic = overlayIsStatic; - return this; - } - - @Override - public PackageImpl setStaticSharedLibName(String staticSharedLibName) { - this.staticSharedLibName = TextUtils.safeIntern(staticSharedLibName); - return this; - } - - @Override - public PackageImpl setStaticSharedLibVersion(long staticSharedLibVersion) { - this.staticSharedLibVersion = staticSharedLibVersion; - return this; - } - - @Override - public PackageImpl setSharedUserId(String sharedUserId) { - this.sharedUserId = TextUtils.safeIntern(sharedUserId); - return this; - } - - @Override - public PackageImpl setSharedUserLabel(int sharedUserLabel) { - this.sharedUserLabel = sharedUserLabel; - return this; - } - - @Override - public PackageImpl setRestrictUpdateHash(byte[] restrictUpdateHash) { - this.restrictUpdateHash = restrictUpdateHash; - return this; - } - - @Override - public PackageImpl setUpgradeKeySets(ArraySet upgradeKeySets) { - this.upgradeKeySets = upgradeKeySets; - return this; - } - - @Override - public PackageImpl setVolumeUuid(String volumeUuid) { - this.volumeUuid = volumeUuid; - return this; - } - - @Deprecated - @Override - public PackageImpl setApplicationVolumeUuid(String applicationVolumeUuid) { - this.applicationVolumeUuid = applicationVolumeUuid; - return this; - } - - @Override - public PackageImpl setSigningDetails(PackageParser.SigningDetails signingDetails) { - this.signingDetails = signingDetails; - return this; - } - - @Override - public PackageImpl setCodePath(String codePath) { - this.codePath = codePath; - return this; - } - - @Override - public PackageImpl setUse32BitAbi(boolean use32BitAbi) { - this.use32BitAbi = use32BitAbi; - return this; - } - - @Override - public PackageImpl setCpuAbiOverride(String cpuAbiOverride) { - this.cpuAbiOverride = cpuAbiOverride; - return this; - } - - @Override - public PackageImpl setForceQueryable(boolean forceQueryable) { - this.forceQueryable = forceQueryable; - return this; - } - - // TODO(b/135203078): Remove and move PackageManagerService#renameStaticSharedLibraryPackage - // into initial package parsing - @Override - public PackageImpl setPackageName(String packageName) { - this.packageName = packageName.intern(); - - if (permissions != null) { - for (ParsedPermission permission : permissions) { - permission.setPackageName(this.packageName); - } - } - - if (permissionGroups != null) { - for (ParsedPermissionGroup permissionGroup : permissionGroups) { - permissionGroup.setPackageName(this.packageName); - } - } - - if (activities != null) { - for (ParsedActivity parsedActivity : activities) { - parsedActivity.setPackageName(this.packageName); - } - } - - if (receivers != null) { - for (ParsedActivity receiver : receivers) { - receiver.setPackageName(this.packageName); - } - } - - if (providers != null) { - for (ParsedProvider provider : providers) { - provider.setPackageName(this.packageName); - } - } - - if (services != null) { - for (ParsedService service : services) { - service.setPackageName(this.packageName); - } - } - - if (instrumentations != null) { - for (ParsedInstrumentation instrumentation : instrumentations) { - instrumentation.setPackageName(this.packageName); - } - } - - return this; - } - - // Under this is parseBaseApplication - - @Override - public PackageImpl setAllowBackup(boolean allowBackup) { - this.flags = allowBackup - ? this.flags | ApplicationInfo.FLAG_ALLOW_BACKUP - : this.flags & ~ApplicationInfo.FLAG_ALLOW_BACKUP; - return this; - } - - @Override - public PackageImpl setKillAfterRestore(boolean killAfterRestore) { - this.flags = killAfterRestore - ? this.flags | ApplicationInfo.FLAG_KILL_AFTER_RESTORE - : this.flags & ~ApplicationInfo.FLAG_KILL_AFTER_RESTORE; - return this; - } - - @Override - public PackageImpl setRestoreAnyVersion(boolean restoreAnyVersion) { - this.flags = restoreAnyVersion - ? this.flags | ApplicationInfo.FLAG_RESTORE_ANY_VERSION - : this.flags & ~ApplicationInfo.FLAG_RESTORE_ANY_VERSION; - return this; - } - - @Override - public PackageImpl setFullBackupOnly(boolean fullBackupOnly) { - this.flags = fullBackupOnly - ? this.flags | ApplicationInfo.FLAG_FULL_BACKUP_ONLY - : this.flags & ~ApplicationInfo.FLAG_FULL_BACKUP_ONLY; - return this; - } - - @Override - public PackageImpl setPersistent(boolean persistent) { - this.flags = persistent - ? this.flags | ApplicationInfo.FLAG_PERSISTENT - : this.flags & ~ApplicationInfo.FLAG_PERSISTENT; - return this; - } - - @Override - public PackageImpl setDebuggable(boolean debuggable) { - this.flags = debuggable - ? this.flags | ApplicationInfo.FLAG_DEBUGGABLE - : this.flags & ~ApplicationInfo.FLAG_DEBUGGABLE; - return this; - } - - @Override - public PackageImpl setProfileableByShell(boolean profileableByShell) { - this.privateFlags = profileableByShell - ? this.privateFlags | ApplicationInfo.PRIVATE_FLAG_PROFILEABLE_BY_SHELL - : this.privateFlags & ~ApplicationInfo.PRIVATE_FLAG_PROFILEABLE_BY_SHELL; - return this; - } - - @Override - public PackageImpl setVmSafeMode(boolean vmSafeMode) { - this.flags = vmSafeMode - ? this.flags | ApplicationInfo.FLAG_VM_SAFE_MODE - : this.flags & ~ApplicationInfo.FLAG_VM_SAFE_MODE; - return this; - } - - @Override - public PackageImpl setHasCode(boolean hasCode) { - this.flags = hasCode - ? this.flags | ApplicationInfo.FLAG_HAS_CODE - : this.flags & ~ApplicationInfo.FLAG_HAS_CODE; - return this; - } - - @Override - public PackageImpl setAllowTaskReparenting(boolean allowTaskReparenting) { - this.flags = allowTaskReparenting - ? this.flags | ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING - : this.flags & ~ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING; - return this; - } - - @Override - public PackageImpl setAllowClearUserData(boolean allowClearUserData) { - this.flags = allowClearUserData - ? this.flags | ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA - : this.flags & ~ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA; - return this; - } - - @Override - public PackageImpl setLargeHeap(boolean largeHeap) { - this.flags = largeHeap - ? this.flags | ApplicationInfo.FLAG_LARGE_HEAP - : this.flags & ~ApplicationInfo.FLAG_LARGE_HEAP; - return this; - } - - @Override - public PackageImpl setUsesCleartextTraffic(boolean usesCleartextTraffic) { - this.flags = usesCleartextTraffic - ? this.flags | ApplicationInfo.FLAG_USES_CLEARTEXT_TRAFFIC - : this.flags & ~ApplicationInfo.FLAG_USES_CLEARTEXT_TRAFFIC; - return this; - } - - @Override - public PackageImpl setSupportsRtl(boolean supportsRtl) { - this.flags = supportsRtl - ? this.flags | ApplicationInfo.FLAG_SUPPORTS_RTL - : this.flags & ~ApplicationInfo.FLAG_SUPPORTS_RTL; - return this; - } - - @Override - public PackageImpl setTestOnly(boolean testOnly) { - this.flags = testOnly - ? this.flags | ApplicationInfo.FLAG_TEST_ONLY - : this.flags & ~ApplicationInfo.FLAG_TEST_ONLY; - return this; - } - - @Override - public PackageImpl setMultiArch(boolean multiArch) { - this.flags = multiArch - ? this.flags | ApplicationInfo.FLAG_MULTIARCH - : this.flags & ~ApplicationInfo.FLAG_MULTIARCH; - return this; - } - - @Override - public PackageImpl setExtractNativeLibs(boolean extractNativeLibs) { - this.flags = extractNativeLibs - ? this.flags | ApplicationInfo.FLAG_EXTRACT_NATIVE_LIBS - : this.flags & ~ApplicationInfo.FLAG_EXTRACT_NATIVE_LIBS; - return this; - } - - @Override - public PackageImpl setIsGame(boolean isGame) { - this.flags = isGame - ? this.flags | ApplicationInfo.FLAG_IS_GAME - : this.flags & ~ApplicationInfo.FLAG_IS_GAME; - return this; - } - - @Override - public PackageImpl setBackupInForeground(boolean backupInForeground) { - this.privateFlags = backupInForeground - ? this.privateFlags | ApplicationInfo.PRIVATE_FLAG_BACKUP_IN_FOREGROUND - : this.privateFlags & ~ApplicationInfo.PRIVATE_FLAG_BACKUP_IN_FOREGROUND; - return this; - } - - @Override - public PackageImpl setUseEmbeddedDex(boolean useEmbeddedDex) { - this.privateFlags = useEmbeddedDex - ? this.privateFlags | ApplicationInfo.PRIVATE_FLAG_USE_EMBEDDED_DEX - : this.privateFlags & ~ApplicationInfo.PRIVATE_FLAG_USE_EMBEDDED_DEX; - return this; - } - - @Override - public PackageImpl setDefaultToDeviceProtectedStorage(boolean defaultToDeviceProtectedStorage) { - this.privateFlags = defaultToDeviceProtectedStorage - ? this.privateFlags | ApplicationInfo - .PRIVATE_FLAG_DEFAULT_TO_DEVICE_PROTECTED_STORAGE - : this.privateFlags & ~ApplicationInfo - .PRIVATE_FLAG_DEFAULT_TO_DEVICE_PROTECTED_STORAGE; - return this; - } - - @Override - public PackageImpl setDirectBootAware(boolean directBootAware) { - this.privateFlags = directBootAware - ? this.privateFlags | ApplicationInfo.PRIVATE_FLAG_DIRECT_BOOT_AWARE - : this.privateFlags & ~ApplicationInfo.PRIVATE_FLAG_DIRECT_BOOT_AWARE; - return this; - } - - @Override - public PackageImpl setPartiallyDirectBootAware(boolean partiallyDirectBootAware) { - this.privateFlags = partiallyDirectBootAware - ? this.privateFlags | ApplicationInfo.PRIVATE_FLAG_PARTIALLY_DIRECT_BOOT_AWARE - : this.privateFlags & ~ApplicationInfo.PRIVATE_FLAG_PARTIALLY_DIRECT_BOOT_AWARE; - return this; - } - - @Override - public PackageImpl setActivitiesResizeModeResizeableViaSdkVersion( - boolean resizeableViaSdkVersion - ) { - this.privateFlags = resizeableViaSdkVersion - ? this.privateFlags | ApplicationInfo - .PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION - : this.privateFlags & ~ApplicationInfo - .PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION; - return this; - } - - @Override - public PackageImpl setActivitiesResizeModeResizeable(boolean resizeable) { - this.privateFlags = resizeable - ? this.privateFlags | ApplicationInfo - .PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE - : this.privateFlags & ~ApplicationInfo - .PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE; - - this.privateFlags = !resizeable - ? this.privateFlags | ApplicationInfo - .PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_UNRESIZEABLE - : this.privateFlags & ~ApplicationInfo - .PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_UNRESIZEABLE; - return this; - } - - @Override - public PackageImpl setAllowClearUserDataOnFailedRestore( - boolean allowClearUserDataOnFailedRestore - ) { - this.privateFlags = allowClearUserDataOnFailedRestore - ? this.privateFlags | ApplicationInfo - .PRIVATE_FLAG_ALLOW_CLEAR_USER_DATA_ON_FAILED_RESTORE - : this.privateFlags & ~ApplicationInfo - .PRIVATE_FLAG_ALLOW_CLEAR_USER_DATA_ON_FAILED_RESTORE; - return this; - } - - @Override - public PackageImpl setAllowAudioPlaybackCapture(boolean allowAudioPlaybackCapture) { - this.privateFlags = allowAudioPlaybackCapture - ? this.privateFlags | ApplicationInfo.PRIVATE_FLAG_ALLOW_AUDIO_PLAYBACK_CAPTURE - : this.privateFlags & ~ApplicationInfo.PRIVATE_FLAG_ALLOW_AUDIO_PLAYBACK_CAPTURE; - return this; - } - - @Override - public PackageImpl setRequestLegacyExternalStorage(boolean requestLegacyExternalStorage) { - this.privateFlags = requestLegacyExternalStorage - ? this.privateFlags | ApplicationInfo.PRIVATE_FLAG_REQUEST_LEGACY_EXTERNAL_STORAGE - : this.privateFlags & ~ApplicationInfo.PRIVATE_FLAG_REQUEST_LEGACY_EXTERNAL_STORAGE; - return this; - } - - @Override - public PackageImpl setAllowNativeHeapPointerTagging(boolean allowNativeHeapPointerTagging) { - this.privateFlags = allowNativeHeapPointerTagging - ? this.privateFlags | ApplicationInfo - .PRIVATE_FLAG_ALLOW_NATIVE_HEAP_POINTER_TAGGING - : this.privateFlags & ~ApplicationInfo - .PRIVATE_FLAG_ALLOW_NATIVE_HEAP_POINTER_TAGGING; - return this; - } - - @Override - public PackageImpl setPreserveLegacyExternalStorage(boolean preserveLegacyExternalStorage) { - this.preserveLegacyExternalStorage = preserveLegacyExternalStorage; - return this; - } - - @Override - public PackageImpl setUsesNonSdkApi(boolean usesNonSdkApi) { - this.privateFlags = usesNonSdkApi - ? this.privateFlags | ApplicationInfo.PRIVATE_FLAG_USES_NON_SDK_API - : this.privateFlags & ~ApplicationInfo.PRIVATE_FLAG_USES_NON_SDK_API; - return this; - } - - @Override - public PackageImpl setHasFragileUserData(boolean hasFragileUserData) { - this.privateFlags = hasFragileUserData - ? this.privateFlags | ApplicationInfo.PRIVATE_FLAG_HAS_FRAGILE_USER_DATA - : this.privateFlags & ~ApplicationInfo.PRIVATE_FLAG_HAS_FRAGILE_USER_DATA; - return this; - } - - @Override - public PackageImpl setCantSaveState(boolean cantSaveState) { - this.privateFlags = cantSaveState - ? this.privateFlags | ApplicationInfo.PRIVATE_FLAG_CANT_SAVE_STATE - : this.privateFlags & ~ApplicationInfo.PRIVATE_FLAG_CANT_SAVE_STATE; - return this; - } - - @Override - public boolean cantSaveState() { - return (privateFlags & ApplicationInfo.PRIVATE_FLAG_CANT_SAVE_STATE) != 0; - } - - @Override - public boolean isLibrary() { - return staticSharedLibName != null || !ArrayUtils.isEmpty(libraryNames); - } - - // TODO(b/135203078): This does nothing until the final stage without applyPolicy being - // part of PackageParser - @Override - public boolean isSystemApp() { - return (flags & ApplicationInfo.FLAG_SYSTEM) != 0; - } - - // TODO(b/135203078): This does nothing until the final stage without applyPolicy being - // part of PackageParser - @Override - public boolean isSystemExt() { - return (privateFlags & ApplicationInfo.PRIVATE_FLAG_SYSTEM_EXT) != 0; - } - - // TODO(b/135203078): This does nothing until the final stage without applyPolicy being - // part of PackageParser - @Override - public boolean isUpdatedSystemApp() { - return (flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0; - } - - @Override - public PackageImpl setStaticSharedLibrary(boolean staticSharedLibrary) { - this.privateFlags = staticSharedLibrary - ? this.privateFlags | ApplicationInfo.PRIVATE_FLAG_STATIC_SHARED_LIBRARY - : this.privateFlags & ~ApplicationInfo.PRIVATE_FLAG_STATIC_SHARED_LIBRARY; - return this; - } - - @Override - public boolean isStaticSharedLibrary() { - return (privateFlags & ApplicationInfo.PRIVATE_FLAG_STATIC_SHARED_LIBRARY) != 0; - } - - @Override - public PackageImpl setVisibleToInstantApps(boolean visibleToInstantApps) { - this.visibleToInstantApps = visibleToInstantApps; - return this; - } - - @Override - public PackageImpl setIconRes(int iconRes) { - this.iconRes = iconRes; - return this; - } - - @Override - public PackageImpl setRoundIconRes(int roundIconRes) { - this.roundIconRes = roundIconRes; - return this; - } - - @Override - public PackageImpl setClassName(String className) { - this.className = className; - return this; - } - - @Override - public PackageImpl setManageSpaceActivityName(String manageSpaceActivityName) { - this.manageSpaceActivityName = manageSpaceActivityName; - return this; - } - - @Override - public PackageImpl setBackupAgentName(String backupAgentName) { - this.backupAgentName = backupAgentName; - return this; - } - - @Override - public PackageImpl setFullBackupContent(int fullBackupContent) { - this.fullBackupContent = fullBackupContent; - return this; - } - - @Override - public PackageImpl setTheme(int theme) { - this.theme = theme; - return this; - } - - @Override - public PackageImpl setDescriptionRes(int descriptionRes) { - this.descriptionRes = descriptionRes; - return this; - } - - @Override - public PackageImpl setNetworkSecurityConfigRes(int networkSecurityConfigRes) { - this.networkSecurityConfigRes = networkSecurityConfigRes; - return this; - } - - @Override - public PackageImpl setCategory(int category) { - this.category = category; - return this; - } - - @Override - public PackageImpl setPermission(String permission) { - this.permission = permission; - return this; - } - - @Override - public PackageImpl setTaskAffinity(String taskAffinity) { - this.taskAffinity = taskAffinity; - return this; - } - - @Override - public PackageImpl setAppComponentFactory(String appComponentFactory) { - this.appComponentFactory = appComponentFactory; - return this; - } - - @Override - public PackageImpl setProcessName(String processName) { - if (processName == null) { - this.processName = packageName; - } else { - this.processName = processName; - } - return this; - } - - @Override - public PackageImpl setEnabled(boolean enabled) { - this.enabled = enabled; - return this; - } - - @Override - public PackageImpl setCrossProfile(boolean crossProfile) { - this.crossProfile = crossProfile; - return this; - } - - @Override - public PackageImpl setUiOptions(int uiOptions) { - this.uiOptions = uiOptions; - return this; - } - - @Override - public PackageImpl setClassLoaderName(String classLoaderName) { - this.classLoaderName = classLoaderName; - return this; - } - - @Override - public PackageImpl setZygotePreloadName(String zygotePreloadName) { - this.zygotePreloadName = zygotePreloadName; - return this; - } - - // parsePackageItemInfo - - @Override - public String getName() { - return name; - } - - @Override - public PackageImpl setName(String name) { - this.name = name; - return this; - } - - @Override - public PackageImpl setIcon(int icon) { - this.icon = icon; - return this; - } - - @Override - public PackageImpl setNonLocalizedLabel(CharSequence nonLocalizedLabel) { - this.nonLocalizedLabel = nonLocalizedLabel; - return this; - } - - @Override - public PackageImpl setLogo(int logo) { - this.logo = logo; - return this; - } - - @Override - public PackageImpl setBanner(int banner) { - this.banner = banner; - return this; - } - - @Override - public PackageImpl setLabelRes(int labelRes) { - this.labelRes = labelRes; - return this; - } - - @Override - public PackageImpl asSplit( - String[] splitNames, - String[] splitCodePaths, - int[] splitRevisionCodes, - SparseArray splitDependencies - ) { - this.splitNames = splitNames; - - if (this.splitNames != null) { - for (int index = 0; index < this.splitNames.length; index++) { - splitNames[index] = TextUtils.safeIntern(splitNames[index]); - } - } - - this.splitCodePaths = splitCodePaths; - this.splitRevisionCodes = splitRevisionCodes; - this.splitDependencies = splitDependencies; - - int count = splitNames.length; - this.splitFlags = new int[count]; - this.splitClassLoaderNames = new String[count]; - return this; - } - - @Override - public String[] getSplitNames() { - return splitNames; - } - - @Override - public String[] getSplitCodePaths() { - return splitCodePaths; - } - - @Override - public PackageImpl setSplitHasCode(int splitIndex, boolean splitHasCode) { - this.splitFlags[splitIndex] = splitHasCode - ? this.splitFlags[splitIndex] | ApplicationInfo.FLAG_HAS_CODE - : this.splitFlags[splitIndex] & ~ApplicationInfo.FLAG_HAS_CODE; - return this; - } - - @Override - public PackageImpl setSplitClassLoaderName(int splitIndex, String classLoaderName) { - this.splitClassLoaderNames[splitIndex] = classLoaderName; - return this; - } - - @Override - public List makeListAllCodePaths() { - ArrayList paths = new ArrayList<>(); - paths.add(baseCodePath); - - if (!ArrayUtils.isEmpty(splitCodePaths)) { - Collections.addAll(paths, splitCodePaths); - } - return paths; - } - - @Override - public PackageImpl setBaseCodePath(String baseCodePath) { - this.baseCodePath = baseCodePath; - return this; - } - - @Override - public PackageImpl setSplitCodePaths(String[] splitCodePaths) { - this.splitCodePaths = splitCodePaths; - return this; - } - - @Override - public String toString() { - return "Package{" - + Integer.toHexString(System.identityHashCode(this)) - + " " + packageName + "}"; - } - - @Override - public PackageImpl setPrimaryCpuAbi(String primaryCpuAbi) { - this.primaryCpuAbi = primaryCpuAbi; - return this; - } - - @Override - public PackageImpl setSecondaryCpuAbi(String secondaryCpuAbi) { - this.secondaryCpuAbi = secondaryCpuAbi; - return this; - } - - @Override - public PackageImpl setNativeLibraryRootDir(String nativeLibraryRootDir) { - this.nativeLibraryRootDir = nativeLibraryRootDir; - return this; - } - - @Override - public PackageImpl setNativeLibraryRootRequiresIsa(boolean nativeLibraryRootRequiresIsa) { - this.nativeLibraryRootRequiresIsa = nativeLibraryRootRequiresIsa; - return this; - } - - @Override - public PackageImpl setNativeLibraryDir(String nativeLibraryDir) { - this.nativeLibraryDir = nativeLibraryDir; - return this; - } - - @Override - public PackageImpl setSecondaryNativeLibraryDir(String secondaryNativeLibraryDir) { - this.secondaryNativeLibraryDir = secondaryNativeLibraryDir; - return this; - } - - @Deprecated - @Override - public PackageImpl setApplicationInfoCodePath(String applicationInfoCodePath) { - this.applicationInfoCodePath = applicationInfoCodePath; - return this; - } - - @Deprecated - @Override - public PackageImpl setApplicationInfoResourcePath(String applicationInfoResourcePath) { - this.applicationInfoResourcePath = applicationInfoResourcePath; - return this; - } - - @Deprecated - @Override - public PackageImpl setApplicationInfoBaseResourcePath( - String applicationInfoBaseResourcePath) { - this.applicationInfoBaseResourcePath = applicationInfoBaseResourcePath; - return this; - } - - @Deprecated - @Override - public PackageImpl setApplicationInfoSplitResourcePaths( - String[] applicationInfoSplitResourcePaths) { - this.applicationInfoSplitResourcePaths = applicationInfoSplitResourcePaths; - return this; - } - - @Override - public boolean isDirectBootAware() { - return (privateFlags & ApplicationInfo.PRIVATE_FLAG_DIRECT_BOOT_AWARE) != 0; - } - - @Override - public PackageImpl setAllComponentsDirectBootAware(boolean allComponentsDirectBootAware) { - if (activities != null) { - for (ParsedActivity parsedActivity : activities) { - parsedActivity.directBootAware = allComponentsDirectBootAware; - } - } - - if (receivers != null) { - for (ParsedActivity parsedReceiver : receivers) { - parsedReceiver.directBootAware = allComponentsDirectBootAware; - } - } - - if (providers != null) { - for (ParsedProvider parsedProvider : providers) { - parsedProvider.directBootAware = allComponentsDirectBootAware; - } - } - - if (services != null) { - for (ParsedService parsedService : services) { - parsedService.directBootAware = allComponentsDirectBootAware; - } - } - - return this; - } - - @Override - public PackageImpl setSystem(boolean system) { - this.flags = system - ? this.flags | ApplicationInfo.FLAG_SYSTEM - : this.flags & ~ApplicationInfo.FLAG_SYSTEM; - return this; - } - - @Override - public PackageImpl setSystemExt(boolean systemExt) { - this.privateFlags = systemExt - ? this.privateFlags | ApplicationInfo.PRIVATE_FLAG_SYSTEM_EXT - : this.privateFlags & ~ApplicationInfo.PRIVATE_FLAG_SYSTEM_EXT; - return this; - } - - @Override - public PackageImpl setIsStub(boolean isStub) { - this.isStub = isStub; - return this; - } - - @Override - public PackageImpl setCoreApp(boolean coreApp) { - this.coreApp = coreApp; - return this; - } - - @Override - public ParsedPackage capPermissionPriorities() { - if (permissionGroups != null && !permissionGroups.isEmpty()) { - for (int i = permissionGroups.size() - 1; i >= 0; --i) { - // TODO(b/135203078): Builder/immutability - permissionGroups.get(i).priority = 0; - } - } - return this; - } - - @Override - public ParsedPackage clearProtectedBroadcasts() { - if (protectedBroadcasts != null) { - protectedBroadcasts.clear(); - } - return this; - } - - @Override - public ParsedPackage markNotActivitiesAsNotExportedIfSingleUser() { - // ignore export request for single user receivers - if (receivers != null) { - for (ParsedActivity receiver : receivers) { - if ((receiver.flags & ActivityInfo.FLAG_SINGLE_USER) != 0) { - receiver.exported = false; - } - } - } - // ignore export request for single user services - if (services != null) { - for (ParsedService service : services) { - if ((service.flags & ServiceInfo.FLAG_SINGLE_USER) != 0) { - service.exported = false; - } - } - } - // ignore export request for single user providers - if (providers != null) { - for (ParsedProvider provider : providers) { - if ((provider.flags & ProviderInfo.FLAG_SINGLE_USER) != 0) { - provider.exported = false; - } - } - } - - return this; - } - - @Override - public ParsedPackage setPrivileged(boolean privileged) { - this.privateFlags = privileged - ? this.privateFlags | ApplicationInfo.PRIVATE_FLAG_PRIVILEGED - : this.privateFlags & ~ApplicationInfo.PRIVATE_FLAG_PRIVILEGED; - return this; - } - - @Override - public ParsedPackage setOem(boolean oem) { - this.privateFlags = oem - ? this.privateFlags | ApplicationInfo.PRIVATE_FLAG_OEM - : this.privateFlags & ~ApplicationInfo.PRIVATE_FLAG_OEM; - return this; - } - - @Override - public ParsedPackage setVendor(boolean vendor) { - this.privateFlags = vendor - ? this.privateFlags | ApplicationInfo.PRIVATE_FLAG_VENDOR - : this.privateFlags & ~ApplicationInfo.PRIVATE_FLAG_VENDOR; - return this; - } - - @Override - public ParsedPackage setProduct(boolean product) { - this.privateFlags = product - ? this.privateFlags | ApplicationInfo.PRIVATE_FLAG_PRODUCT - : this.privateFlags & ~ApplicationInfo.PRIVATE_FLAG_PRODUCT; - return this; - } - - @Override - public ParsedPackage setOdm(boolean odm) { - this.privateFlags = odm - ? this.privateFlags | ApplicationInfo.PRIVATE_FLAG_ODM - : this.privateFlags & ~ApplicationInfo.PRIVATE_FLAG_ODM; - return this; - } - - @Override - public ParsedPackage setSignedWithPlatformKey(boolean signedWithPlatformKey) { - this.privateFlags = signedWithPlatformKey - ? this.privateFlags | ApplicationInfo.PRIVATE_FLAG_SIGNED_WITH_PLATFORM_KEY - : this.privateFlags & ~ApplicationInfo.PRIVATE_FLAG_SIGNED_WITH_PLATFORM_KEY; - return this; - } - - @Override - public ParsedPackage clearOriginalPackages() { - if (originalPackages != null) { - originalPackages.clear(); - } - return this; - } - - @Override - public ParsedPackage clearAdoptPermissions() { - if (adoptPermissions != null) { - adoptPermissions.clear(); - } - return this; - } - - @Override - public PackageImpl addUsesLibrary(int index, String libraryName) { - this.usesLibraries = ArrayUtils.add(usesLibraries, index, libraryName); - return this; - } - - @Override - public ParsedPackage removeUsesLibrary(String libraryName) { - this.usesLibraries = ArrayUtils.remove(this.usesLibraries, libraryName); - return this; - } - - @Override - public PackageImpl addUsesOptionalLibrary(int index, String libraryName) { - this.usesOptionalLibraries = ArrayUtils.add(usesOptionalLibraries, index, libraryName); - return this; - } - - @Nullable - @Override - public List getUsesOptionalLibraries() { - return usesOptionalLibraries; - } - - @Override - public int getVersionCode() { - return versionCode; - } - - @Nullable - @Override - public long[] getUsesStaticLibrariesVersions() { - return usesStaticLibrariesVersions; - } - - @Override - public PackageImpl setPackageSettingCallback(PackageSettingCallback packageSettingCallback) { - packageSettingCallback.setAndroidPackage(this); - return this; - } - - @Override - public PackageImpl setUpdatedSystemApp(boolean updatedSystemApp) { - this.flags = updatedSystemApp - ? this.flags | ApplicationInfo.FLAG_UPDATED_SYSTEM_APP - : this.flags & ~ApplicationInfo.FLAG_UPDATED_SYSTEM_APP; - return this; - } - - @Override - public boolean isPrivileged() { - return (privateFlags & ApplicationInfo.PRIVATE_FLAG_PRIVILEGED) != 0; - } - - @Override - public PackageImpl setSeInfo(String seInfo) { - this.seInfo = seInfo; - return this; - } - - @Override - public PackageImpl setSeInfoUser(String seInfoUser) { - this.seInfoUser = seInfoUser; - return this; - } - - @Override - public PackageImpl initForUser(int userId) { - // TODO(b/135203078): Move this user state to some other data structure - this.uid = UserHandle.getUid(userId, UserHandle.getAppId(this.uid)); - - if ("android".equals(packageName)) { - dataDir = Environment.getDataSystemDirectory().getAbsolutePath(); - return this; - } - - deviceProtectedDataDir = Environment - .getDataUserDePackageDirectory(applicationVolumeUuid, userId, packageName) - .getAbsolutePath(); - credentialProtectedDataDir = Environment - .getDataUserCePackageDirectory(applicationVolumeUuid, userId, packageName) - .getAbsolutePath(); - - if ((privateFlags & ApplicationInfo.PRIVATE_FLAG_DEFAULT_TO_DEVICE_PROTECTED_STORAGE) != 0 - && PackageManager.APPLY_DEFAULT_TO_DEVICE_PROTECTED_STORAGE) { - dataDir = deviceProtectedDataDir; - } else { - dataDir = credentialProtectedDataDir; - } - return this; - } - - @Override - public ParsedPackage setFactoryTest(boolean factoryTest) { - this.flags = factoryTest - ? this.flags | ApplicationInfo.FLAG_FACTORY_TEST - : this.flags & ~ApplicationInfo.FLAG_FACTORY_TEST; - return this; - } - - @Override - public String getManifestPackageName() { - return manifestPackageName; - } - - @Override - public String getRealPackage() { - return realPackage; - } - - @Override - public String getOverlayTarget() { - return overlayTarget; - } - - @Override - public String getOverlayTargetName() { - return overlayTargetName; - } - - @Override - public Map getOverlayables() { - return overlayables; - } - - @Override - public boolean isOverlayIsStatic() { - return overlayIsStatic; - } - - @Override - public int[] getSplitFlags() { - return splitFlags; - } - - @Deprecated - @Override - public String getApplicationInfoVolumeUuid() { - return applicationVolumeUuid; - } - - @Nullable - @Override - public List getProtectedBroadcasts() { - return protectedBroadcasts; - } - - @Nullable - @Override - public Set getUpgradeKeySets() { - return upgradeKeySets; - } - - @Nullable - @Override - public String[][] getUsesStaticLibrariesCertDigests() { - return usesStaticLibrariesCertDigests; - } - - @Override - public int getOverlayPriority() { - return overlayPriority; - } - - @Deprecated - @Override - public String getAppInfoPackageName() { - return packageName; - } - - @Override - public UUID getStorageUuid() { - return StorageManager.convert(applicationVolumeUuid); - } - - @Override - public int getUid() { - return uid; - } - - @Override - public boolean isStub() { - return isStub; - } - - @Deprecated - @Override - public String getAppInfoCodePath() { - return applicationInfoCodePath; - } - - @Override - public boolean isSystem() { - return (flags & ApplicationInfo.FLAG_SYSTEM) != 0; - } - - @Override - public boolean isMatch(int flags) { - if ((flags & PackageManager.MATCH_SYSTEM_ONLY) != 0) { - return isSystem(); - } - return true; - } - - @Override - public boolean isVisibleToInstantApps() { - return visibleToInstantApps; - } - - @Override - public PackageImpl setLastPackageUsageTimeInMills(int reason, long time) { - lastPackageUsageTimeInMills[reason] = time; - return this; - } - - @Override - public List getUsesLibraryInfos() { - return usesLibraryInfos; - } - - @NonNull - @Override - public List getAllCodePaths() { - return makeListAllCodePaths(); - } - - @Nullable - @Override - public String[] getUsesLibraryFiles() { - return usesLibraryFiles; - } - - @Override - public PackageImpl setUsesLibraryInfos( - @Nullable List usesLibraryInfos) { - this.usesLibraryInfos = usesLibraryInfos; - return this; - } - - @Override - public PackageImpl setUsesLibraryFiles(@Nullable String[] usesLibraryFiles) { - this.usesLibraryFiles = usesLibraryFiles; - return this; - } - - @Override - public PackageImpl setUid(int uid) { - this.uid = uid; - return this; - } - - @Override - public List getAdoptPermissions() { - return adoptPermissions; - } - - @Override - public ApplicationInfo toAppInfoWithoutState() { - updateFlags(); - - ApplicationInfo appInfo = new ApplicationInfo(); - appInfo.packageName = packageName; - appInfo.flags = flags; - appInfo.privateFlags = privateFlags; - - appInfo.appComponentFactory = appComponentFactory; - appInfo.backupAgentName = backupAgentName; - appInfo.banner = banner; - appInfo.category = category; - appInfo.classLoaderName = classLoaderName; - appInfo.className = className; - appInfo.compatibleWidthLimitDp = compatibleWidthLimitDp; - appInfo.compileSdkVersion = compileSdkVersion; - appInfo.compileSdkVersionCodename = compileSdkVersionCodename; - appInfo.credentialProtectedDataDir = credentialProtectedDataDir; - appInfo.dataDir = dataDir; - appInfo.descriptionRes = descriptionRes; - appInfo.deviceProtectedDataDir = deviceProtectedDataDir; - appInfo.enabled = enabled; - appInfo.fullBackupContent = fullBackupContent; - appInfo.hiddenUntilInstalled = hiddenUntilInstalled; - appInfo.icon = icon; - appInfo.iconRes = iconRes; - appInfo.installLocation = installLocation; - appInfo.labelRes = labelRes; - appInfo.largestWidthLimitDp = largestWidthLimitDp; - appInfo.logo = logo; - appInfo.manageSpaceActivityName = manageSpaceActivityName; - appInfo.maxAspectRatio = maxAspectRatio; - appInfo.metaData = appMetaData; - appInfo.minAspectRatio = minAspectRatio; - appInfo.minSdkVersion = minSdkVersion; - appInfo.name = className; - if (appInfo.name != null) { - appInfo.name = appInfo.name.trim(); - } - appInfo.nativeLibraryDir = nativeLibraryDir; - appInfo.nativeLibraryRootDir = nativeLibraryRootDir; - appInfo.nativeLibraryRootRequiresIsa = nativeLibraryRootRequiresIsa; - appInfo.networkSecurityConfigRes = networkSecurityConfigRes; - appInfo.nonLocalizedLabel = nonLocalizedLabel; - if (appInfo.nonLocalizedLabel != null) { - appInfo.nonLocalizedLabel = appInfo.nonLocalizedLabel.toString().trim(); - } - appInfo.packageName = packageName; - appInfo.permission = permission; - appInfo.primaryCpuAbi = primaryCpuAbi; - appInfo.processName = getProcessName(); - appInfo.requiresSmallestWidthDp = requiresSmallestWidthDp; - appInfo.roundIconRes = roundIconRes; - appInfo.secondaryCpuAbi = secondaryCpuAbi; - appInfo.secondaryNativeLibraryDir = secondaryNativeLibraryDir; - appInfo.seInfo = seInfo; - appInfo.seInfoUser = seInfoUser; - appInfo.sharedLibraryFiles = usesLibraryFiles; - appInfo.sharedLibraryInfos = ArrayUtils.isEmpty(usesLibraryInfos) ? null : usesLibraryInfos; - appInfo.splitClassLoaderNames = splitClassLoaderNames; - appInfo.splitDependencies = splitDependencies; - appInfo.splitNames = splitNames; - appInfo.storageUuid = StorageManager.convert(volumeUuid); - appInfo.targetSandboxVersion = targetSandboxVersion; - appInfo.targetSdkVersion = targetSdkVersion; - appInfo.taskAffinity = taskAffinity; - appInfo.theme = theme; - appInfo.uid = uid; - appInfo.uiOptions = uiOptions; - appInfo.volumeUuid = volumeUuid; - appInfo.zygotePreloadName = zygotePreloadName; - appInfo.crossProfile = isCrossProfile(); - - appInfo.setBaseCodePath(baseCodePath); - appInfo.setBaseResourcePath(baseCodePath); - appInfo.setCodePath(codePath); - appInfo.setResourcePath(codePath); - appInfo.setSplitCodePaths(splitCodePaths); - appInfo.setSplitResourcePaths(splitCodePaths); - appInfo.setVersionCode(getLongVersionCode()); - - // TODO(b/135203078): Can this be removed? Looks only used in ActivityInfo. -// appInfo.showUserIcon = pkg.getShowUserIcon(); - // TODO(b/135203078): Unused? -// appInfo.resourceDirs = pkg.getResourceDirs(); - // TODO(b/135203078): Unused? -// appInfo.enabledSetting = pkg.getEnabledSetting(); - // TODO(b/135203078): See PackageImpl#getHiddenApiEnforcementPolicy -// appInfo.mHiddenApiPolicy = pkg.getHiddenApiPolicy(); - - return appInfo; - } - - @Override - public PackageImpl setVersionCode(int versionCode) { - this.versionCode = versionCode; - return this; - } - - @Override - public PackageImpl setHiddenUntilInstalled(boolean hidden) { - this.hiddenUntilInstalled = hidden; - return this; - } - - @Override - public String getSeInfo() { - return seInfo; - } - - @Deprecated - @Override - public String getAppInfoResourcePath() { - return applicationInfoResourcePath; - } - - @Override - public boolean isForwardLocked() { - // TODO(b/135203078): Unused? Move to debug flag? - return false; - } - - @Override - public byte[] getRestrictUpdateHash() { - return restrictUpdateHash; - } - - @Override - public boolean hasComponentClassName(String className) { - if (activities != null) { - for (ParsedActivity parsedActivity : activities) { - if (Objects.equals(className, parsedActivity.className)) { - return true; - } - } - } - - if (receivers != null) { - for (ParsedActivity receiver : receivers) { - if (Objects.equals(className, receiver.className)) { - return true; - } - } - } - - if (providers != null) { - for (ParsedProvider provider : providers) { - if (Objects.equals(className, provider.className)) { - return true; - } - } - } - - if (services != null) { - for (ParsedService service : services) { - if (Objects.equals(className, service.className)) { - return true; - } - } - } - - if (instrumentations != null) { - for (ParsedInstrumentation instrumentation : instrumentations) { - if (Objects.equals(className, instrumentation.className)) { - return true; - } - } - } - - return false; - } - - @Override - public boolean isDefaultToDeviceProtectedStorage() { - return (privateFlags & ApplicationInfo.PRIVATE_FLAG_DEFAULT_TO_DEVICE_PROTECTED_STORAGE) - != 0; - } - - @Override - public boolean isInternal() { - return (flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) == 0; - } - - @Override - public int getBaseRevisionCode() { - return baseRevisionCode; - } - - @Override - public int[] getSplitRevisionCodes() { - return splitRevisionCodes; - } - - @Override - public boolean canHaveOatDir() { - // The following app types CANNOT have oat directory - // - non-updated system apps - return !isSystem() || isUpdatedSystemApp(); - } - - @Override - public long getLatestPackageUseTimeInMills() { - long latestUse = 0L; - for (long use : lastPackageUsageTimeInMills) { - latestUse = Math.max(latestUse, use); - } - return latestUse; - } - - @Override - public long getLatestForegroundPackageUseTimeInMills() { - int[] foregroundReasons = { - PackageManager.NOTIFY_PACKAGE_USE_ACTIVITY, - PackageManager.NOTIFY_PACKAGE_USE_FOREGROUND_SERVICE - }; - - long latestUse = 0L; - for (int reason : foregroundReasons) { - latestUse = Math.max(latestUse, lastPackageUsageTimeInMills[reason]); - } - return latestUse; - } - - @Override - public boolean isCoreApp() { - return coreApp; - } - - @Override - public String getVersionName() { - return versionName; - } - - @Override - public PackageImpl setVersionCodeMajor(int versionCodeMajor) { - this.versionCodeMajor = versionCodeMajor; - return this; - } - - @Override - public long[] getLastPackageUsageTimeInMills() { - return lastPackageUsageTimeInMills; - } - - @Override - public String getDataDir() { - return dataDir; - } - - @Override - public boolean isExternal() { - return (flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0; - } - - @Override - public List getImplicitPermissions() { - return implicitPermissions == null ? Collections.emptyList() : implicitPermissions; - } - - /** - * TODO(b/135203078): Remove, ensure b/140256621 is fixed or irrelevant - * TODO(b/140256621): Remove after fixing instant app check - * @deprecated This method always returns false because there's no paired set method - */ - @Deprecated - @Override - public boolean isInstantApp() { - return (privateFlags & ApplicationInfo.PRIVATE_FLAG_INSTANT) != 0; - } - - @Override - public boolean hasRequestedLegacyExternalStorage() { - return (privateFlags & ApplicationInfo.PRIVATE_FLAG_REQUEST_LEGACY_EXTERNAL_STORAGE) != 0; - } - - @Override - public boolean isVendor() { - return (privateFlags & ApplicationInfo.PRIVATE_FLAG_VENDOR) != 0; - } - - @Override - public boolean isProduct() { - return (privateFlags & ApplicationInfo.PRIVATE_FLAG_PRODUCT) != 0; - } - - @Override - public boolean isOem() { - return (privateFlags & ApplicationInfo.PRIVATE_FLAG_OEM) != 0; - } - - @Override - public boolean isEncryptionAware() { - boolean isPartiallyDirectBootAware = - (privateFlags & ApplicationInfo.PRIVATE_FLAG_PARTIALLY_DIRECT_BOOT_AWARE) != 0; - return isDirectBootAware() || isPartiallyDirectBootAware; - } - - @Override - public boolean isEmbeddedDexUsed() { - return (privateFlags & ApplicationInfo.PRIVATE_FLAG_USE_EMBEDDED_DEX) != 0; - } - - @Deprecated - @Override - public String getAppInfoProcessName() { - return processName; - } - - @Override - public List getAllCodePathsExcludingResourceOnly() { - ArrayList paths = new ArrayList<>(); - if ((flags & ApplicationInfo.FLAG_HAS_CODE) != 0) { - paths.add(baseCodePath); - } - if (!ArrayUtils.isEmpty(splitCodePaths)) { - for (int i = 0; i < splitCodePaths.length; i++) { - if ((splitFlags[i] & ApplicationInfo.FLAG_HAS_CODE) != 0) { - paths.add(splitCodePaths[i]); - } - } - } - return paths; - } - - @Deprecated - @Override - public String getAppInfoName() { - return name; - } - - private boolean isSignedWithPlatformKey() { - return (privateFlags & ApplicationInfo.PRIVATE_FLAG_SIGNED_WITH_PLATFORM_KEY) != 0; - } - - private boolean usesNonSdkApi() { - return (privateFlags & ApplicationInfo.PRIVATE_FLAG_USES_NON_SDK_API) != 0; - } - - private boolean isPackageWhitelistedForHiddenApis() { - return SystemConfig.getInstance().getHiddenApiWhitelistedApps().contains(packageName); - } - - private boolean isAllowedToUseHiddenApis() { - if (isSignedWithPlatformKey()) { - return true; - } else if (isSystemApp() || isUpdatedSystemApp()) { - return usesNonSdkApi() || isPackageWhitelistedForHiddenApis(); - } else { - return false; - } - } - - @Override - public int getHiddenApiEnforcementPolicy() { - if (isAllowedToUseHiddenApis()) { - return ApplicationInfo.HIDDEN_API_ENFORCEMENT_DISABLED; - } - - // TODO(b/135203078): Handle maybeUpdateHiddenApiEnforcementPolicy. Right now it's done - // entirely through ApplicationInfo and shouldn't touch this specific class, but that - // may not always hold true. -// if (mHiddenApiPolicy != ApplicationInfo.HIDDEN_API_ENFORCEMENT_DEFAULT) { -// return mHiddenApiPolicy; -// } - return ApplicationInfo.HIDDEN_API_ENFORCEMENT_ENABLED; - } - - @Nullable - @Override - public SparseArray getSplitDependencies() { - return splitDependencies; - } - - @Override - public boolean requestsIsolatedSplitLoading() { - return (privateFlags & ApplicationInfo.PRIVATE_FLAG_ISOLATED_SPLIT_LOADING) != 0; - } - - @Deprecated - @Override - public String getAppInfoClassLoaderName() { - return classLoaderName; - } - - @Override - public String getClassLoaderName() { - return classLoaderName; - } - - @Override - public String[] getSplitClassLoaderNames() { - return splitClassLoaderNames; - } - - @Override - public String getOverlayCategory() { - return overlayCategory; - } - - @Override - public boolean isProfileableByShell() { - return (privateFlags & ApplicationInfo.PRIVATE_FLAG_PROFILEABLE_BY_SHELL) != 0; - } - - @Nullable - @Override - public List getPreferredActivityFilters() { - return preferredActivityFilters; - } - - @Override - public boolean isHiddenUntilInstalled() { - return hiddenUntilInstalled; - } - - @Override - public int getMinSdkVersion() { - return minSdkVersion; - } - - @Override - public String getRestrictedAccountType() { - return restrictedAccountType; - } - - @Override - public String getRequiredAccountType() { - return requiredAccountType; - } - - @Override - public int getInstallLocation() { - return installLocation; - } - - @Override - public List getReceivers() { - return receivers; - } - - @Override - public List getServices() { - return services; - } - - @Override - public List getProviders() { - return providers; - } - - @Override - public int getSharedUserLabel() { - return sharedUserLabel; - } - - @Override - public int getVersionCodeMajor() { - return versionCodeMajor; - } - - @Override - public boolean isRequiredForAllUsers() { - return requiredForAllUsers; - } - - @Override - public int getCompileSdkVersion() { - return compileSdkVersion; - } - - @Override - public String getCompileSdkVersionCodeName() { - return compileSdkVersionCodename; - } - - @Nullable - @Override - public List getConfigPreferences() { - return configPreferences; - } - - @Nullable - @Override - public List getReqFeatures() { - return reqFeatures; - } - - @Override - public List getFeatureGroups() { - return featureGroups; - } - - @Override - public String getDeviceProtectedDataDir() { - return deviceProtectedDataDir; - } - - @Override - public String getCredentialProtectedDataDir() { - return credentialProtectedDataDir; - } - - @Override - public String getSeInfoUser() { - return seInfoUser; - } - - @Override - public String getClassName() { - return className; - } - - @Override - public int getTheme() { - return theme; - } - - @Override - public int getRequiresSmallestWidthDp() { - return requiresSmallestWidthDp; - } - - @Override - public int getCompatibleWidthLimitDp() { - return compatibleWidthLimitDp; - } - - @Override - public int getLargestWidthLimitDp() { - return largestWidthLimitDp; - } - - @Override - public String getScanSourceDir() { - return applicationInfoCodePath; - } - - @Override - public String getScanPublicSourceDir() { - return applicationInfoResourcePath; - } - - @Override - public String getPublicSourceDir() { - return applicationInfoBaseResourcePath; - } - - @Override - public String[] getSplitPublicSourceDirs() { - return applicationInfoSplitResourcePaths; - } - - @Override - public String getSecondaryNativeLibraryDir() { - return secondaryNativeLibraryDir; - } - - @Override - public boolean isEnabled() { - return enabled; - } - - @Override - public boolean isCrossProfile() { - return crossProfile; - } - - @Override - public String getManageSpaceActivityName() { - return manageSpaceActivityName; - } - - @Override - public int getDescriptionRes() { - return descriptionRes; - } - - @Override - public String getBackupAgentName() { - return backupAgentName; - } - - @Override - public int getFullBackupContent() { - return fullBackupContent; - } - - @Override - public int getNetworkSecurityConfigRes() { - return networkSecurityConfigRes; - } - - @Override - public int getCategory() { - return category; - } - - @Override - public int getTargetSandboxVersion() { - return targetSandboxVersion; - } - - @Override - public String getAppComponentFactory() { - return appComponentFactory; - } - - @Override - public int getIconRes() { - return iconRes; - } - - @Override - public int getRoundIconRes() { - return roundIconRes; - } - - @Override - public String getZygotePreloadName() { - return zygotePreloadName; - } - - @Override - public int getLabelRes() { - return labelRes; - } - - @Override - public CharSequence getNonLocalizedLabel() { - return nonLocalizedLabel; - } - - @Override - public int getIcon() { - return icon; - } - - @Override - public int getBanner() { - return banner; - } - - @Override - public int getLogo() { - return logo; - } - - @Override - public Bundle getMetaData() { - return appMetaData; - } - - private void addMimeGroupsFromComponent(ParsedComponent component) { - for (int i = component.intents.size() - 1; i >= 0; i--) { - IntentFilter filter = component.intents.get(i); - for (int groupIndex = filter.countMimeGroups() - 1; groupIndex >= 0; groupIndex--) { - mimeGroups = ArrayUtils.add(mimeGroups, filter.getMimeGroup(groupIndex)); - } - } - } - - @Override - @Nullable - public Set getMimeGroups() { - return mimeGroups; - } - - @Override - @Nullable - public List getQueriesIntents() { - return queriesIntents; - } - - @Override - @Nullable - public List getQueriesPackages() { - return queriesPackages; - } - - @Override - public Set getQueriesProviders() { - return queriesProviders; - } - - @Override - public boolean hasPreserveLegacyExternalStorage() { - return preserveLegacyExternalStorage; - } - - private static void internStringArrayList(List list) { - if (list != null) { - final int N = list.size(); - for (int i = 0; i < N; ++i) { - list.set(i, list.get(i).intern()); - } - } - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - dest.writeInt(this.supportsSmallScreens); - dest.writeInt(this.supportsNormalScreens); - dest.writeInt(this.supportsLargeScreens); - dest.writeInt(this.supportsXLargeScreens); - dest.writeInt(this.resizeable); - dest.writeInt(this.anyDensity); - dest.writeLongArray(this.lastPackageUsageTimeInMills); - dest.writeInt(this.versionCode); - dest.writeInt(this.versionCodeMajor); - dest.writeInt(this.baseRevisionCode); - dest.writeString(this.versionName); - dest.writeBoolean(this.coreApp); - dest.writeInt(this.compileSdkVersion); - dest.writeString(this.compileSdkVersionCodename); - dest.writeString(this.packageName); - dest.writeString(this.realPackage); - dest.writeString(this.manifestPackageName); - dest.writeString(this.baseCodePath); - dest.writeBoolean(this.requiredForAllUsers); - dest.writeString(this.restrictedAccountType); - dest.writeString(this.requiredAccountType); - dest.writeBoolean(this.baseHardwareAccelerated); - dest.writeString(this.overlayTarget); - dest.writeString(this.overlayTargetName); - dest.writeString(this.overlayCategory); - dest.writeInt(this.overlayPriority); - dest.writeBoolean(this.overlayIsStatic); - dest.writeMap(this.overlayables); - dest.writeString(this.staticSharedLibName); - dest.writeLong(this.staticSharedLibVersion); - dest.writeStringList(this.libraryNames); - dest.writeStringList(this.usesLibraries); - dest.writeStringList(this.usesOptionalLibraries); - dest.writeStringList(this.usesStaticLibraries); - dest.writeLongArray(this.usesStaticLibrariesVersions); - final int numProcesses = this.processes != null ? this.processes.size() : 0; - dest.writeInt(numProcesses); - for (int i = 0; i < numProcesses; i++) { - this.processes.valueAt(i).writeToParcel(dest, 0); - } - - if (this.usesStaticLibrariesCertDigests == null) { - dest.writeInt(-1); - } else { - dest.writeInt(this.usesStaticLibrariesCertDigests.length); - for (int index = 0; index < this.usesStaticLibrariesCertDigests.length; index++) { - dest.writeStringArray(this.usesStaticLibrariesCertDigests[index]); - } - } - - dest.writeString(this.sharedUserId); - dest.writeInt(this.sharedUserLabel); - dest.writeTypedList(this.configPreferences); - dest.writeTypedList(this.reqFeatures); - dest.writeTypedList(this.featureGroups); - dest.writeByteArray(this.restrictUpdateHash); - dest.writeStringList(this.originalPackages); - dest.writeStringList(this.adoptPermissions); - dest.writeStringList(this.requestedPermissions); - dest.writeStringList(this.implicitPermissions); - dest.writeArraySet(this.upgradeKeySets); - dest.writeMap(this.keySetMapping); - dest.writeStringList(this.protectedBroadcasts); - dest.writeTypedList(this.activities); - dest.writeTypedList(this.receivers); - dest.writeTypedList(this.services); - dest.writeTypedList(this.providers); - dest.writeTypedList(this.features); - dest.writeTypedList(this.permissions); - dest.writeTypedList(this.permissionGroups); - dest.writeTypedList(this.instrumentations); - ParsedIntentInfo.writeIntentsList(this.preferredActivityFilters, dest, flags); - dest.writeBundle(this.appMetaData); - dest.writeString(this.volumeUuid); - dest.writeString(this.applicationVolumeUuid); - dest.writeParcelable(this.signingDetails, flags); - dest.writeString(this.codePath); - dest.writeBoolean(this.use32BitAbi); - dest.writeBoolean(this.visibleToInstantApps); - dest.writeString(this.cpuAbiOverride); - dest.writeBoolean(this.isStub); - dest.writeInt(this.preferredOrder); - dest.writeBoolean(this.forceQueryable); - dest.writeParcelableList(this.queriesIntents, flags); - dest.writeStringList(this.queriesPackages); - dest.writeString(this.applicationInfoBaseResourcePath); - dest.writeString(this.applicationInfoCodePath); - dest.writeString(this.applicationInfoResourcePath); - dest.writeStringArray(this.applicationInfoSplitResourcePaths); - dest.writeString(this.appComponentFactory); - dest.writeString(this.backupAgentName); - dest.writeInt(this.banner); - dest.writeInt(this.category); - dest.writeString(this.classLoaderName); - dest.writeString(this.className); - dest.writeInt(this.compatibleWidthLimitDp); - dest.writeString(this.credentialProtectedDataDir); - dest.writeString(this.dataDir); - dest.writeInt(this.descriptionRes); - dest.writeString(this.deviceProtectedDataDir); - dest.writeBoolean(this.enabled); - dest.writeBoolean(this.crossProfile); - dest.writeInt(this.flags); - dest.writeInt(this.fullBackupContent); - dest.writeBoolean(this.hiddenUntilInstalled); - dest.writeInt(this.icon); - dest.writeInt(this.iconRes); - dest.writeInt(this.installLocation); - dest.writeInt(this.labelRes); - dest.writeInt(this.largestWidthLimitDp); - dest.writeInt(this.logo); - dest.writeString(this.manageSpaceActivityName); - dest.writeFloat(this.maxAspectRatio); - dest.writeFloat(this.minAspectRatio); - dest.writeInt(this.minSdkVersion); - dest.writeString(this.name); - dest.writeString(this.nativeLibraryDir); - dest.writeString(this.nativeLibraryRootDir); - dest.writeBoolean(this.nativeLibraryRootRequiresIsa); - dest.writeInt(this.networkSecurityConfigRes); - dest.writeCharSequence(this.nonLocalizedLabel); - dest.writeString(this.permission); - dest.writeString(this.primaryCpuAbi); - dest.writeInt(this.privateFlags); - dest.writeString(this.processName); - dest.writeInt(this.requiresSmallestWidthDp); - dest.writeInt(this.roundIconRes); - dest.writeString(this.secondaryCpuAbi); - dest.writeString(this.secondaryNativeLibraryDir); - dest.writeString(this.seInfo); - dest.writeString(this.seInfoUser); - dest.writeInt(this.targetSandboxVersion); - dest.writeInt(this.targetSdkVersion); - dest.writeString(this.taskAffinity); - dest.writeInt(this.theme); - dest.writeInt(this.uid); - dest.writeInt(this.uiOptions); - dest.writeStringArray(this.usesLibraryFiles); - dest.writeTypedList(this.usesLibraryInfos); - dest.writeString(this.zygotePreloadName); - dest.writeStringArray(this.splitClassLoaderNames); - dest.writeStringArray(this.splitCodePaths); - dest.writeSparseArray(this.splitDependencies); - dest.writeIntArray(this.splitFlags); - dest.writeStringArray(this.splitNames); - dest.writeIntArray(this.splitRevisionCodes); - dest.writeArraySet(this.mimeGroups); - } - - public PackageImpl(Parcel in) { - // We use the boot classloader for all classes that we load. - final ClassLoader boot = Object.class.getClassLoader(); - this.supportsSmallScreens = in.readInt(); - this.supportsNormalScreens = in.readInt(); - this.supportsLargeScreens = in.readInt(); - this.supportsXLargeScreens = in.readInt(); - this.resizeable = in.readInt(); - this.anyDensity = in.readInt(); - this.lastPackageUsageTimeInMills = in.createLongArray(); - this.versionCode = in.readInt(); - this.versionCodeMajor = in.readInt(); - this.baseRevisionCode = in.readInt(); - this.versionName = TextUtils.safeIntern(in.readString()); - this.coreApp = in.readBoolean(); - this.compileSdkVersion = in.readInt(); - this.compileSdkVersionCodename = TextUtils.safeIntern(in.readString()); - this.packageName = TextUtils.safeIntern(in.readString()); - this.realPackage = in.readString(); - this.manifestPackageName = in.readString(); - this.baseCodePath = in.readString(); - this.requiredForAllUsers = in.readBoolean(); - this.restrictedAccountType = in.readString(); - this.requiredAccountType = in.readString(); - this.baseHardwareAccelerated = in.readBoolean(); - this.overlayTarget = in.readString(); - this.overlayTargetName = in.readString(); - this.overlayCategory = in.readString(); - this.overlayPriority = in.readInt(); - this.overlayIsStatic = in.readBoolean(); - this.overlayables = new HashMap<>(); - in.readMap(overlayables, boot); - this.staticSharedLibName = TextUtils.safeIntern(in.readString()); - this.staticSharedLibVersion = in.readLong(); - this.libraryNames = in.createStringArrayList(); - internStringArrayList(this.libraryNames); - this.usesLibraries = in.createStringArrayList(); - internStringArrayList(this.usesLibraries); - this.usesOptionalLibraries = in.createStringArrayList(); - internStringArrayList(this.usesOptionalLibraries); - this.usesStaticLibraries = in.createStringArrayList(); - internStringArrayList(usesStaticLibraries); - this.usesStaticLibrariesVersions = in.createLongArray(); - final int numProcesses = in.readInt(); - if (numProcesses > 0) { - this.processes = new ArrayMap<>(numProcesses); - for (int i = 0; i < numProcesses; i++) { - ComponentParseUtils.ParsedProcess proc = new ComponentParseUtils.ParsedProcess(in); - this.processes.put(proc.name, proc); - } - } else { - this.processes = null; - } - - int digestsSize = in.readInt(); - if (digestsSize >= 0) { - this.usesStaticLibrariesCertDigests = new String[digestsSize][]; - for (int index = 0; index < digestsSize; index++) { - this.usesStaticLibrariesCertDigests[index] = in.readStringArray(); - } - } - - this.sharedUserId = TextUtils.safeIntern(in.readString()); - this.sharedUserLabel = in.readInt(); - this.configPreferences = in.createTypedArrayList(ConfigurationInfo.CREATOR); - this.reqFeatures = in.createTypedArrayList(FeatureInfo.CREATOR); - this.featureGroups = in.createTypedArrayList(FeatureGroupInfo.CREATOR); - this.restrictUpdateHash = in.createByteArray(); - this.originalPackages = in.createStringArrayList(); - this.adoptPermissions = in.createStringArrayList(); - this.requestedPermissions = in.createStringArrayList(); - internStringArrayList(this.requestedPermissions); - this.implicitPermissions = in.createStringArrayList(); - internStringArrayList(this.implicitPermissions); - this.upgradeKeySets = (ArraySet) in.readArraySet(boot); - this.keySetMapping = in.readHashMap(boot); - this.protectedBroadcasts = in.createStringArrayList(); - internStringArrayList(this.protectedBroadcasts); - this.activities = in.createTypedArrayList(ParsedActivity.CREATOR); - this.receivers = in.createTypedArrayList(ParsedActivity.CREATOR); - this.services = in.createTypedArrayList(ParsedService.CREATOR); - this.providers = in.createTypedArrayList(ParsedProvider.CREATOR); - this.features = in.createTypedArrayList(ParsedFeature.CREATOR); - this.permissions = in.createTypedArrayList(ParsedPermission.CREATOR); - this.permissionGroups = in.createTypedArrayList(ParsedPermissionGroup.CREATOR); - this.instrumentations = in.createTypedArrayList(ParsedInstrumentation.CREATOR); - this.preferredActivityFilters = ParsedIntentInfo.createIntentsList(in); - this.appMetaData = in.readBundle(boot); - this.volumeUuid = in.readString(); - this.applicationVolumeUuid = in.readString(); - this.signingDetails = in.readParcelable(boot); - this.codePath = in.readString(); - this.use32BitAbi = in.readBoolean(); - this.visibleToInstantApps = in.readBoolean(); - this.cpuAbiOverride = in.readString(); - this.isStub = in.readBoolean(); - this.preferredOrder = in.readInt(); - this.forceQueryable = in.readBoolean(); - this.queriesIntents = in.createTypedArrayList(Intent.CREATOR); - this.queriesPackages = in.createStringArrayList(); - internStringArrayList(this.queriesPackages); - this.applicationInfoBaseResourcePath = in.readString(); - this.applicationInfoCodePath = in.readString(); - this.applicationInfoResourcePath = in.readString(); - this.applicationInfoSplitResourcePaths = in.createStringArray(); - this.appComponentFactory = in.readString(); - this.backupAgentName = in.readString(); - this.banner = in.readInt(); - this.category = in.readInt(); - this.classLoaderName = in.readString(); - this.className = in.readString(); - this.compatibleWidthLimitDp = in.readInt(); - this.credentialProtectedDataDir = in.readString(); - this.dataDir = in.readString(); - this.descriptionRes = in.readInt(); - this.deviceProtectedDataDir = in.readString(); - this.enabled = in.readBoolean(); - this.crossProfile = in.readBoolean(); - this.flags = in.readInt(); - this.fullBackupContent = in.readInt(); - this.hiddenUntilInstalled = in.readBoolean(); - this.icon = in.readInt(); - this.iconRes = in.readInt(); - this.installLocation = in.readInt(); - this.labelRes = in.readInt(); - this.largestWidthLimitDp = in.readInt(); - this.logo = in.readInt(); - this.manageSpaceActivityName = in.readString(); - this.maxAspectRatio = in.readFloat(); - this.minAspectRatio = in.readFloat(); - this.minSdkVersion = in.readInt(); - this.name = in.readString(); - this.nativeLibraryDir = in.readString(); - this.nativeLibraryRootDir = in.readString(); - this.nativeLibraryRootRequiresIsa = in.readBoolean(); - this.networkSecurityConfigRes = in.readInt(); - this.nonLocalizedLabel = in.readCharSequence(); - this.permission = TextUtils.safeIntern(in.readString()); - this.primaryCpuAbi = in.readString(); - this.privateFlags = in.readInt(); - this.processName = in.readString(); - this.requiresSmallestWidthDp = in.readInt(); - this.roundIconRes = in.readInt(); - this.secondaryCpuAbi = in.readString(); - this.secondaryNativeLibraryDir = in.readString(); - this.seInfo = in.readString(); - this.seInfoUser = in.readString(); - this.targetSandboxVersion = in.readInt(); - this.targetSdkVersion = in.readInt(); - this.taskAffinity = in.readString(); - this.theme = in.readInt(); - this.uid = in.readInt(); - this.uiOptions = in.readInt(); - this.usesLibraryFiles = in.createStringArray(); - this.usesLibraryInfos = in.createTypedArrayList(SharedLibraryInfo.CREATOR); - this.zygotePreloadName = in.readString(); - this.splitClassLoaderNames = in.createStringArray(); - this.splitCodePaths = in.createStringArray(); - this.splitDependencies = in.readSparseArray(boot); - this.splitFlags = in.createIntArray(); - this.splitNames = in.createStringArray(); - this.splitRevisionCodes = in.createIntArray(); - this.mimeGroups = (ArraySet) in.readArraySet(boot); - } - - public static final Creator CREATOR = new Creator() { - @Override - public PackageImpl createFromParcel(Parcel source) { - return new PackageImpl(source); - } - - @Override - public PackageImpl[] newArray(int size) { - return new PackageImpl[size]; - } - }; -} diff --git a/core/java/android/content/pm/parsing/ParsingPackage.java b/core/java/android/content/pm/parsing/ParsingPackage.java index 74a2640446f04..2e1cb8dbf7f40 100644 --- a/core/java/android/content/pm/parsing/ParsingPackage.java +++ b/core/java/android/content/pm/parsing/ParsingPackage.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 The Android Open Source Project + * Copyright (C) 2020 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. @@ -16,6 +16,7 @@ package android.content.pm.parsing; +import android.annotation.NonNull; import android.annotation.Nullable; import android.content.Intent; import android.content.pm.ConfigurationInfo; @@ -28,23 +29,23 @@ import android.content.pm.parsing.ComponentParseUtils.ParsedFeature; import android.content.pm.parsing.ComponentParseUtils.ParsedInstrumentation; import android.content.pm.parsing.ComponentParseUtils.ParsedPermission; import android.content.pm.parsing.ComponentParseUtils.ParsedPermissionGroup; +import android.content.pm.parsing.ComponentParseUtils.ParsedProcess; import android.content.pm.parsing.ComponentParseUtils.ParsedProvider; import android.content.pm.parsing.ComponentParseUtils.ParsedService; import android.os.Bundle; -import android.util.ArrayMap; -import android.util.ArraySet; import android.util.SparseArray; import java.security.PublicKey; +import java.util.Map; +import java.util.Set; /** * Methods used for mutation during direct package parsing. * - * Java disallows defining this as an inner interface, so this must be a separate file. - * * @hide */ -public interface ParsingPackage extends AndroidPackage { +@SuppressWarnings("UnusedReturnValue") +public interface ParsingPackage extends ParsingPackageRead { ParsingPackage addActivity(ParsedActivity parsedActivity); @@ -66,18 +67,18 @@ public interface ParsingPackage extends AndroidPackage { ParsingPackage addOverlayable(String overlayableName, String actorName); - ParsingPackage addFeature(ParsedFeature permission); - ParsingPackage addPermission(ParsedPermission permission); ParsingPackage addPermissionGroup(ParsedPermissionGroup permissionGroup); - ParsingPackage addPreferredActivityFilter(ParsedActivityIntentInfo activityIntentInfo); + ParsingPackage addPreferredActivityFilter(ParsedActivityIntentInfo intentInfo); ParsingPackage addProtectedBroadcast(String protectedBroadcast); ParsingPackage addProvider(ParsedProvider parsedProvider); + ParsingPackage addFeature(ParsedFeature permission); + ParsingPackage addReceiver(ParsedActivity parsedReceiver); ParsingPackage addReqFeature(FeatureInfo reqFeature); @@ -102,7 +103,7 @@ public interface ParsingPackage extends AndroidPackage { ParsingPackage addQueriesProvider(String authority); - ParsingPackage setProcesses(ArrayMap processes); + ParsingPackage setProcesses(@NonNull Map processes); ParsingPackage asSplit( String[] splitNames, @@ -111,7 +112,7 @@ public interface ParsingPackage extends AndroidPackage { @Nullable SparseArray splitDependencies ); - ParsingPackage setAppMetaData(Bundle appMetaData); + ParsingPackage setMetaData(Bundle metaData); ParsingPackage setForceQueryable(boolean forceQueryable); @@ -119,8 +120,6 @@ public interface ParsingPackage extends AndroidPackage { ParsingPackage setMinAspectRatio(float minAspectRatio); - ParsingPackage setName(String name); - ParsingPackage setPermission(String permission); ParsingPackage setProcessName(String processName); @@ -137,9 +136,9 @@ public interface ParsingPackage extends AndroidPackage { ParsingPackage setBaseHardwareAccelerated(boolean baseHardwareAccelerated); - ParsingPackage setActivitiesResizeModeResizeable(boolean resizeable); + ParsingPackage setResizeableActivity(Boolean resizeable); - ParsingPackage setActivitiesResizeModeResizeableViaSdkVersion(boolean resizeableViaSdkVersion); + ParsingPackage setResizeableActivityViaSdkVersion(boolean resizeableViaSdkVersion); ParsingPackage setAllowAudioPlaybackCapture(boolean allowAudioPlaybackCapture); @@ -151,7 +150,7 @@ public interface ParsingPackage extends AndroidPackage { ParsingPackage setAllowTaskReparenting(boolean allowTaskReparenting); - ParsingPackage setIsOverlay(boolean isOverlay); + ParsingPackage setOverlay(boolean isOverlay); ParsingPackage setBackupInForeground(boolean backupInForeground); @@ -173,7 +172,7 @@ public interface ParsingPackage extends AndroidPackage { ParsingPackage setHasFragileUserData(boolean hasFragileUserData); - ParsingPackage setIsGame(boolean isGame); + ParsingPackage setGame(boolean isGame); ParsingPackage setIsolatedSplitLoading(boolean isolatedSplitLoading); @@ -221,8 +220,6 @@ public interface ParsingPackage extends AndroidPackage { ParsingPackage setAppComponentFactory(String appComponentFactory); - ParsingPackage setApplicationVolumeUuid(String applicationVolumeUuid); - ParsingPackage setBackupAgentName(String backupAgentName); ParsingPackage setBanner(int banner); @@ -233,8 +230,6 @@ public interface ParsingPackage extends AndroidPackage { ParsingPackage setClassName(String className); - ParsingPackage setCodePath(String codePath); - ParsingPackage setCompatibleWidthLimitDp(int compatibleWidthLimitDp); ParsingPackage setDescriptionRes(int descriptionRes); @@ -247,8 +242,6 @@ public interface ParsingPackage extends AndroidPackage { ParsingPackage setHasDomainUrls(boolean hasDomainUrls); - ParsingPackage setIcon(int icon); - ParsingPackage setIconRes(int iconRes); ParsingPackage setInstallLocation(int installLocation); @@ -307,17 +300,17 @@ public interface ParsingPackage extends AndroidPackage { ParsingPackage setSupportsSmallScreens(int supportsSmallScreens); - ParsingPackage setSupportsXLargeScreens(int supportsXLargeScreens); + ParsingPackage setSupportsExtraLargeScreens(int supportsExtraLargeScreens); ParsingPackage setTargetSandboxVersion(int targetSandboxVersion); ParsingPackage setTheme(int theme); - ParsingPackage setUpgradeKeySets(ArraySet upgradeKeySets); + ParsingPackage setUpgradeKeySets(@NonNull Set upgradeKeySets); ParsingPackage setUse32BitAbi(boolean use32BitAbi); - ParsingPackage setVolumeUuid(String volumeUuid); + ParsingPackage setVolumeUuid(@Nullable String volumeUuid); ParsingPackage setZygotePreloadName(String zygotePreloadName); @@ -327,17 +320,24 @@ public interface ParsingPackage extends AndroidPackage { ParsingPackage sortServices(); - ParsedPackage hideAsParsed(); - ParsingPackage setBaseRevisionCode(int baseRevisionCode); - ParsingPackage setPreferredOrder(int preferredOrder); - ParsingPackage setVersionName(String versionName); ParsingPackage setCompileSdkVersion(int compileSdkVersion); ParsingPackage setCompileSdkVersionCodename(String compileSdkVersionCodename); - boolean usesCompatibilityMode(); + // TODO(b/135203078): This class no longer has access to ParsedPackage, find a replacement + // for moving to the next step + @Deprecated + Object hideAsParsed(); + + //TODO(b/135203078): Remove in favor of individual methods + @Deprecated + int getFlags(); + + //TODO(b/135203078): Remove in favor of individual methods + @Deprecated + int getPrivateFlags(); } diff --git a/core/java/android/content/pm/parsing/ParsingPackageImpl.java b/core/java/android/content/pm/parsing/ParsingPackageImpl.java new file mode 100644 index 0000000000000..840e1af95eb92 --- /dev/null +++ b/core/java/android/content/pm/parsing/ParsingPackageImpl.java @@ -0,0 +1,2585 @@ +/* + * Copyright (C) 2020 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 static android.content.pm.parsing.ComponentParseUtils.ParsedActivityIntentInfo; + +import static java.util.Collections.emptyList; +import static java.util.Collections.emptyMap; +import static java.util.Collections.emptySet; + +import android.annotation.NonNull; +import android.annotation.Nullable; +import android.content.Intent; +import android.content.IntentFilter; +import android.content.pm.ApplicationInfo; +import android.content.pm.ConfigurationInfo; +import android.content.pm.FeatureGroupInfo; +import android.content.pm.FeatureInfo; +import android.content.pm.PackageInfo; +import android.content.pm.PackageParser; +import android.content.pm.parsing.ComponentParseUtils.ParsedActivity; +import android.content.pm.parsing.ComponentParseUtils.ParsedFeature; +import android.content.pm.parsing.ComponentParseUtils.ParsedInstrumentation; +import android.content.pm.parsing.ComponentParseUtils.ParsedIntentInfo; +import android.content.pm.parsing.ComponentParseUtils.ParsedPermission; +import android.content.pm.parsing.ComponentParseUtils.ParsedPermissionGroup; +import android.content.pm.parsing.ComponentParseUtils.ParsedProcess; +import android.content.pm.parsing.ComponentParseUtils.ParsedProvider; +import android.content.pm.parsing.ComponentParseUtils.ParsedService; +import android.content.res.TypedArray; +import android.os.Build; +import android.os.Bundle; +import android.os.Parcel; +import android.os.Parcelable; +import android.os.storage.StorageManager; +import android.text.TextUtils; +import android.util.ArraySet; +import android.util.SparseArray; + +import com.android.internal.R; +import com.android.internal.annotations.VisibleForTesting; +import com.android.internal.util.ArrayUtils; +import com.android.internal.util.CollectionUtils; +import com.android.internal.util.DataClass; +import com.android.internal.util.Parcelling; +import com.android.internal.util.Parcelling.BuiltIn.ForBoolean; +import com.android.internal.util.Parcelling.BuiltIn.ForInternedString; +import com.android.internal.util.Parcelling.BuiltIn.ForInternedStringArray; +import com.android.internal.util.Parcelling.BuiltIn.ForInternedStringList; +import com.android.internal.util.Parcelling.BuiltIn.ForInternedStringMap; +import com.android.internal.util.Parcelling.BuiltIn.ForInternedStringSet; + +import java.security.PublicKey; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * The backing data for a package that was parsed from disk. + * + * The field nullability annotations here are for internal reference. For effective nullability, + * see the parent interfaces. + * + * TODO(b/135203078): Convert Lists used as sets into Sets, to better express intended use case + * + * @hide + */ +public class ParsingPackageImpl implements ParsingPackage, Parcelable { + + private static final String TAG = "PackageImpl"; + + protected static ForBoolean sForBoolean = Parcelling.Cache.getOrCreate(ForBoolean.class); + protected static ForInternedString sForString = Parcelling.Cache.getOrCreate( + ForInternedString.class); + protected static ForInternedStringArray sForStringArray = Parcelling.Cache.getOrCreate( + ForInternedStringArray.class); + protected static ForInternedStringList sForStringList = Parcelling.Cache.getOrCreate( + ForInternedStringList.class); + protected static ForInternedStringValueMap sForStringValueMap = Parcelling.Cache.getOrCreate( + ForInternedStringValueMap.class); + protected static ForInternedStringSet sForStringSet = Parcelling.Cache.getOrCreate( + ForInternedStringSet.class); + + // These are objects because null represents not explicitly set + @Nullable + @DataClass.ParcelWith(ForBoolean.class) + private Boolean supportsSmallScreens; + @Nullable + @DataClass.ParcelWith(ForBoolean.class) + private Boolean supportsNormalScreens; + @Nullable + @DataClass.ParcelWith(ForBoolean.class) + private Boolean supportsLargeScreens; + @Nullable + @DataClass.ParcelWith(ForBoolean.class) + private Boolean supportsExtraLargeScreens; + @Nullable + @DataClass.ParcelWith(ForBoolean.class) + private Boolean resizeable; + @Nullable + @DataClass.ParcelWith(ForBoolean.class) + private Boolean anyDensity; + + protected int versionCode; + protected int versionCodeMajor; + private int baseRevisionCode; + @Nullable + @DataClass.ParcelWith(ForInternedString.class) + private String versionName; + + private int compileSdkVersion; + @Nullable + @DataClass.ParcelWith(ForInternedString.class) + private String compileSdkVersionCodeName; + + @NonNull + @DataClass.ParcelWith(ForInternedString.class) + protected String packageName; + + @Nullable + @DataClass.ParcelWith(ForInternedString.class) + private String realPackage; + + @NonNull + protected String baseCodePath; + + private boolean requiredForAllUsers; + @Nullable + @DataClass.ParcelWith(ForInternedString.class) + private String restrictedAccountType; + @Nullable + @DataClass.ParcelWith(ForInternedString.class) + private String requiredAccountType; + + @Nullable + @DataClass.ParcelWith(ForInternedString.class) + private String overlayTarget; + @Nullable + @DataClass.ParcelWith(ForInternedString.class) + private String overlayTargetName; + @Nullable + @DataClass.ParcelWith(ForInternedString.class) + private String overlayCategory; + private int overlayPriority; + private boolean overlayIsStatic; + @NonNull + @DataClass.ParcelWith(ForInternedStringMap.class) + private Map overlayables = emptyMap(); + + @Nullable + @DataClass.ParcelWith(ForInternedString.class) + private String staticSharedLibName; + private long staticSharedLibVersion; + @NonNull + @DataClass.ParcelWith(ForInternedStringList.class) + private List libraryNames = emptyList(); + @NonNull + @DataClass.ParcelWith(ForInternedStringList.class) + protected List usesLibraries = emptyList(); + @NonNull + @DataClass.ParcelWith(ForInternedStringList.class) + protected List usesOptionalLibraries = emptyList(); + + @NonNull + @DataClass.ParcelWith(ForInternedStringList.class) + private List usesStaticLibraries = emptyList(); + @Nullable + private long[] usesStaticLibrariesVersions; + + @Nullable + private String[][] usesStaticLibrariesCertDigests; + + @Nullable + @DataClass.ParcelWith(ForInternedString.class) + private String sharedUserId; + + private int sharedUserLabel; + @NonNull + private List configPreferences = emptyList(); + @NonNull + private List reqFeatures = emptyList(); + @NonNull + private List featureGroups = emptyList(); + + @Nullable + private byte[] restrictUpdateHash; + + @NonNull + @DataClass.ParcelWith(ForInternedStringList.class) + protected List originalPackages = emptyList(); + @NonNull + @DataClass.ParcelWith(ForInternedStringList.class) + protected List adoptPermissions = emptyList(); + + @NonNull + @DataClass.ParcelWith(ForInternedStringList.class) + private List requestedPermissions = emptyList(); + @NonNull + @DataClass.ParcelWith(ForInternedStringList.class) + private List implicitPermissions = emptyList(); + + @NonNull + private Set upgradeKeySets = emptySet(); + @NonNull + private Map> keySetMapping = emptyMap(); + + @NonNull + @DataClass.ParcelWith(ForInternedStringList.class) + protected List protectedBroadcasts = emptyList(); + + @NonNull + protected List activities = emptyList(); + + @NonNull + protected List receivers = emptyList(); + + @NonNull + protected List services = emptyList(); + + @NonNull + protected List providers = emptyList(); + + @NonNull + private List features = emptyList(); + + @NonNull + protected List permissions = emptyList(); + + @NonNull + protected List permissionGroups = emptyList(); + + @NonNull + protected List instrumentations = emptyList(); + + @NonNull + private List preferredActivityFilters = emptyList(); + + @NonNull + private Map processes = emptyMap(); + + @Nullable + private Bundle metaData; + + @Nullable + @DataClass.ParcelWith(ForInternedString.class) + protected String volumeUuid; + @Nullable + private PackageParser.SigningDetails signingDetails; + + @NonNull + @DataClass.ParcelWith(ForInternedString.class) + protected String codePath; + + private boolean use32BitAbi; + private boolean visibleToInstantApps; + + private boolean forceQueryable; + + @NonNull + @DataClass.ParcelWith(ForInternedStringList.class) + private List queriesIntents = emptyList(); + + @NonNull + @DataClass.ParcelWith(ForInternedStringList.class) + private List queriesPackages = emptyList(); + + @NonNull + @DataClass.ParcelWith(ForInternedStringSet.class) + private Set queriesProviders = emptySet(); + + @Nullable + @DataClass.ParcelWith(ForInternedStringArray.class) + private String[] splitClassLoaderNames; + @Nullable + protected String[] splitCodePaths; + @Nullable + private SparseArray splitDependencies; + @Nullable + private int[] splitFlags; + @Nullable + @DataClass.ParcelWith(ForInternedStringArray.class) + private String[] splitNames; + @Nullable + private int[] splitRevisionCodes; + + @Nullable + @DataClass.ParcelWith(ForInternedString.class) + private String appComponentFactory; + @Nullable + @DataClass.ParcelWith(ForInternedString.class) + private String backupAgentName; + private int banner; + private int category; + @Nullable + @DataClass.ParcelWith(ForInternedString.class) + private String classLoaderName; + @Nullable + @DataClass.ParcelWith(ForInternedString.class) + private String className; + private int compatibleWidthLimitDp; + private int descriptionRes; + private boolean enabled; + private boolean crossProfile; + private int fullBackupContent; + private int iconRes; + private int installLocation = PackageParser.PARSE_DEFAULT_INSTALL_LOCATION; + private int labelRes; + private int largestWidthLimitDp; + private int logo; + @Nullable + @DataClass.ParcelWith(ForInternedString.class) + private String manageSpaceActivityName; + private float maxAspectRatio; + private float minAspectRatio; + private int minSdkVersion; + private int networkSecurityConfigRes; + @Nullable + private CharSequence nonLocalizedLabel; + @Nullable + @DataClass.ParcelWith(ForInternedString.class) + private String permission; + @Nullable + @DataClass.ParcelWith(ForInternedString.class) + private String processName; + private int requiresSmallestWidthDp; + private int roundIconRes; + private int targetSandboxVersion; + private int targetSdkVersion; + @Nullable + @DataClass.ParcelWith(ForInternedString.class) + private String taskAffinity; + private int theme; + + private int uiOptions; + @Nullable + @DataClass.ParcelWith(ForInternedString.class) + private String zygotePreloadName; + + private boolean externalStorage; + private boolean baseHardwareAccelerated; + private boolean allowBackup; + private boolean killAfterRestore; + private boolean restoreAnyVersion; + private boolean fullBackupOnly; + private boolean persistent; + private boolean debuggable; + private boolean vmSafeMode; + private boolean hasCode; + private boolean allowTaskReparenting; + private boolean allowClearUserData; + private boolean largeHeap; + private boolean usesCleartextTraffic; + private boolean supportsRtl; + private boolean testOnly; + private boolean multiArch; + private boolean extractNativeLibs; + private boolean game; + + /** + * @see ParsingPackageRead#getResizeableActivity() + */ + @Nullable + @DataClass.ParcelWith(ForBoolean.class) + private Boolean resizeableActivity; + + private boolean staticSharedLibrary; + private boolean overlay; + private boolean isolatedSplitLoading; + private boolean hasDomainUrls; + private boolean profileableByShell; + private boolean backupInForeground; + private boolean useEmbeddedDex; + private boolean defaultToDeviceProtectedStorage; + private boolean directBootAware; + private boolean partiallyDirectBootAware; + private boolean resizeableActivityViaSdkVersion; + private boolean allowClearUserDataOnFailedRestore; + private boolean allowAudioPlaybackCapture; + private boolean requestLegacyExternalStorage; + private boolean usesNonSdkApi; + private boolean hasFragileUserData; + private boolean cantSaveState; + private boolean allowNativeHeapPointerTagging; + private boolean preserveLegacyExternalStorage; + + // TODO(chiuwinson): Non-null + @Nullable + private ArraySet mimeGroups; + + @VisibleForTesting + public ParsingPackageImpl(@NonNull String packageName, @NonNull String baseCodePath, + @NonNull String codePath, @Nullable TypedArray manifestArray) { + this.packageName = TextUtils.safeIntern(packageName); + this.baseCodePath = TextUtils.safeIntern(baseCodePath); + this.codePath = TextUtils.safeIntern(codePath); + + if (manifestArray != null) { + versionCode = manifestArray.getInteger(R.styleable.AndroidManifest_versionCode, 0); + versionCodeMajor = manifestArray.getInteger( + R.styleable.AndroidManifest_versionCodeMajor, 0); + setBaseRevisionCode( + manifestArray.getInteger(R.styleable.AndroidManifest_revisionCode, 0)); + setVersionName(manifestArray.getNonConfigurationString( + R.styleable.AndroidManifest_versionName, 0)); + + setCompileSdkVersion(manifestArray.getInteger( + R.styleable.AndroidManifest_compileSdkVersion, 0)); + setCompileSdkVersionCodename(manifestArray.getNonConfigurationString( + R.styleable.AndroidManifest_compileSdkVersionCodename, 0)); + } + } + + public boolean isSupportsSmallScreens() { + if (supportsSmallScreens == null) { + return targetSdkVersion >= Build.VERSION_CODES.DONUT; + } + + return supportsSmallScreens; + } + + public boolean isSupportsNormalScreens() { + return supportsNormalScreens == null || supportsNormalScreens; + } + + public boolean isSupportsLargeScreens() { + if (supportsLargeScreens == null) { + return targetSdkVersion >= Build.VERSION_CODES.DONUT; + } + + return supportsLargeScreens; + } + + public boolean isSupportsExtraLargeScreens() { + if (supportsExtraLargeScreens == null) { + return targetSdkVersion >= Build.VERSION_CODES.GINGERBREAD; + } + + return supportsExtraLargeScreens; + } + + public boolean isResizeable() { + if (resizeable == null) { + return targetSdkVersion >= Build.VERSION_CODES.DONUT; + } + + return resizeable; + } + + public boolean isAnyDensity() { + if (anyDensity == null) { + return targetSdkVersion >= Build.VERSION_CODES.DONUT; + } + + return anyDensity; + } + + @Override + public ParsingPackageImpl sortActivities() { + Collections.sort(this.activities, (a1, a2) -> Integer.compare(a2.order, a1.order)); + return this; + } + + @Override + public ParsingPackageImpl sortReceivers() { + Collections.sort(this.receivers, (a1, a2) -> Integer.compare(a2.order, a1.order)); + return this; + } + + @Override + public ParsingPackageImpl sortServices() { + Collections.sort(this.services, (a1, a2) -> Integer.compare(a2.order, a1.order)); + return this; + } + + @Override + public ParsingPackageImpl setVersionName(String versionName) { + this.versionName = TextUtils.safeIntern(versionName); + return this; + } + + @Override + public ParsingPackage setCompileSdkVersionCodename(String compileSdkVersionCodename) { + this.compileSdkVersionCodeName = TextUtils.safeIntern(compileSdkVersionCodename); + return this; + } + + @Override + public Object hideAsParsed() { + // There is no equivalent for core-only parsing + throw new UnsupportedOperationException(); + } + + @Override + public int getFlags() { + return PackageInfoWithoutStateUtils.appInfoFlags(this); + } + + @Override + public int getPrivateFlags() { + return PackageInfoWithoutStateUtils.appInfoPrivateFlags(this); + } + + @Override + public ParsingPackageImpl addConfigPreference(ConfigurationInfo configPreference) { + this.configPreferences = CollectionUtils.add(this.configPreferences, configPreference); + return this; + } + + @Override + public ParsingPackageImpl addReqFeature(FeatureInfo reqFeature) { + this.reqFeatures = CollectionUtils.add(this.reqFeatures, reqFeature); + return this; + } + + @Override + public ParsingPackageImpl addFeatureGroup(FeatureGroupInfo featureGroup) { + this.featureGroups = CollectionUtils.add(this.featureGroups, featureGroup); + return this; + } + + @Override + public ParsingPackageImpl addProtectedBroadcast(String protectedBroadcast) { + if (!this.protectedBroadcasts.contains(protectedBroadcast)) { + this.protectedBroadcasts = CollectionUtils.add(this.protectedBroadcasts, + TextUtils.safeIntern(protectedBroadcast)); + } + return this; + } + + @Override + public ParsingPackageImpl addInstrumentation(ParsedInstrumentation instrumentation) { + this.instrumentations = CollectionUtils.add(this.instrumentations, instrumentation); + return this; + } + + @Override + public ParsingPackageImpl addOriginalPackage(String originalPackage) { + this.originalPackages = CollectionUtils.add(this.originalPackages, + TextUtils.safeIntern(originalPackage)); + return this; + } + + @Override + public ParsingPackage addOverlayable(String overlayableName, String actorName) { + this.overlayables = CollectionUtils.add(this.overlayables, + TextUtils.safeIntern(overlayableName), TextUtils.safeIntern(actorName)); + return this; + } + + @Override + public ParsingPackageImpl addAdoptPermission(String adoptPermission) { + this.adoptPermissions = CollectionUtils.add(this.adoptPermissions, + TextUtils.safeIntern(adoptPermission)); + return this; + } + + @Override + public ParsingPackageImpl addPermission(ParsedPermission permission) { + this.permissions = CollectionUtils.add(this.permissions, permission); + return this; + } + + @Override + public ParsingPackageImpl addPermissionGroup(ParsedPermissionGroup permissionGroup) { + this.permissionGroups = CollectionUtils.add(this.permissionGroups, permissionGroup); + return this; + } + + @Override + public ParsingPackageImpl addRequestedPermission(String permission) { + this.requestedPermissions = CollectionUtils.add(this.requestedPermissions, + TextUtils.safeIntern(permission)); + return this; + } + + @Override + public ParsingPackageImpl addImplicitPermission(String permission) { + this.implicitPermissions = CollectionUtils.add(this.implicitPermissions, + TextUtils.safeIntern(permission)); + return this; + } + + @Override + public ParsingPackageImpl addKeySet(String keySetName, PublicKey publicKey) { + ArraySet publicKeys = keySetMapping.get(keySetName); + if (publicKeys == null) { + publicKeys = new ArraySet<>(); + } + publicKeys.add(publicKey); + keySetMapping = CollectionUtils.add(this.keySetMapping, keySetName, publicKeys); + return this; + } + + @Override + public ParsingPackageImpl addActivity(ParsedActivity parsedActivity) { + this.activities = CollectionUtils.add(this.activities, parsedActivity); + addMimeGroupsFromComponent(parsedActivity); + return this; + } + + @Override + public ParsingPackageImpl addReceiver(ParsedActivity parsedReceiver) { + this.receivers = CollectionUtils.add(this.receivers, parsedReceiver); + addMimeGroupsFromComponent(parsedReceiver); + return this; + } + + @Override + public ParsingPackageImpl addService(ParsedService parsedService) { + this.services = CollectionUtils.add(this.services, parsedService); + addMimeGroupsFromComponent(parsedService); + return this; + } + + @Override + public ParsingPackageImpl addProvider(ParsedProvider parsedProvider) { + this.providers = CollectionUtils.add(this.providers, parsedProvider); + addMimeGroupsFromComponent(parsedProvider); + return this; + } + + @Override + public ParsingPackageImpl addFeature(ParsedFeature feature) { + this.features = CollectionUtils.add(this.features, feature); + return this; + } + + @Override + public ParsingPackageImpl addLibraryName(String libraryName) { + this.libraryNames = CollectionUtils.add(this.libraryNames, + TextUtils.safeIntern(libraryName)); + return this; + } + + @Override + public ParsingPackageImpl addUsesOptionalLibrary(String libraryName) { + this.usesOptionalLibraries = CollectionUtils.add(this.usesOptionalLibraries, + TextUtils.safeIntern(libraryName)); + return this; + } + + @Override + public ParsingPackageImpl addUsesLibrary(String libraryName) { + this.usesLibraries = CollectionUtils.add(this.usesLibraries, + TextUtils.safeIntern(libraryName)); + return this; + } + + @Override + public ParsingPackageImpl removeUsesOptionalLibrary(String libraryName) { + this.usesOptionalLibraries = CollectionUtils.remove(this.usesOptionalLibraries, + libraryName); + return this; + } + + @Override + public ParsingPackageImpl addUsesStaticLibrary(String libraryName) { + this.usesStaticLibraries = CollectionUtils.add(this.usesStaticLibraries, + TextUtils.safeIntern(libraryName)); + return this; + } + + @Override + public ParsingPackageImpl addUsesStaticLibraryVersion(long version) { + this.usesStaticLibrariesVersions = ArrayUtils.appendLong(this.usesStaticLibrariesVersions, + version, true); + return this; + } + + @Override + public ParsingPackageImpl addUsesStaticLibraryCertDigests(String[] certSha256Digests) { + this.usesStaticLibrariesCertDigests = ArrayUtils.appendElement(String[].class, + this.usesStaticLibrariesCertDigests, certSha256Digests, true); + return this; + } + + @Override + public ParsingPackageImpl addPreferredActivityFilter(ParsedActivityIntentInfo intentInfo) { + this.preferredActivityFilters = CollectionUtils.add(this.preferredActivityFilters, + intentInfo); + return this; + } + + @Override + public ParsingPackageImpl addQueriesIntent(Intent intent) { + this.queriesIntents = CollectionUtils.add(this.queriesIntents, intent); + return this; + } + + @Override + public ParsingPackageImpl addQueriesPackage(String packageName) { + this.queriesPackages = CollectionUtils.add(this.queriesPackages, + TextUtils.safeIntern(packageName)); + return this; + } + + @Override + public ParsingPackageImpl addQueriesProvider(String authority) { + this.queriesProviders = CollectionUtils.add(this.queriesProviders, + TextUtils.safeIntern(authority)); + return this; + } + + @Override + public ParsingPackageImpl setSupportsSmallScreens(int supportsSmallScreens) { + if (supportsSmallScreens == 1) { + return this; + } + + this.supportsSmallScreens = supportsSmallScreens < 0; + return this; + } + + @Override + public ParsingPackageImpl setSupportsNormalScreens(int supportsNormalScreens) { + if (supportsNormalScreens == 1) { + return this; + } + + this.supportsNormalScreens = supportsNormalScreens < 0; + return this; + } + + @Override + public ParsingPackageImpl setSupportsLargeScreens(int supportsLargeScreens) { + if (supportsLargeScreens == 1) { + return this; + } + + this.supportsLargeScreens = supportsLargeScreens < 0; + return this; + } + + @Override + public ParsingPackageImpl setSupportsExtraLargeScreens(int supportsExtraLargeScreens) { + if (supportsExtraLargeScreens == 1) { + return this; + } + + this.supportsExtraLargeScreens = supportsExtraLargeScreens < 0; + return this; + } + + @Override + public ParsingPackageImpl setResizeable(int resizeable) { + if (resizeable == 1) { + return this; + } + + this.resizeable = resizeable < 0; + return this; + } + + @Override + public ParsingPackageImpl setAnyDensity(int anyDensity) { + if (anyDensity == 1) { + return this; + } + + this.anyDensity = anyDensity < 0; + return this; + } + + @Override + public ParsingPackageImpl asSplit( + String[] splitNames, + String[] splitCodePaths, + int[] splitRevisionCodes, + SparseArray splitDependencies + ) { + this.splitNames = splitNames; + + if (this.splitNames != null) { + for (int index = 0; index < this.splitNames.length; index++) { + splitNames[index] = TextUtils.safeIntern(splitNames[index]); + } + } + + this.splitCodePaths = splitCodePaths; + this.splitRevisionCodes = splitRevisionCodes; + this.splitDependencies = splitDependencies; + + int count = splitNames.length; + this.splitFlags = new int[count]; + this.splitClassLoaderNames = new String[count]; + return this; + } + + @Override + public ParsingPackageImpl setSplitHasCode(int splitIndex, boolean splitHasCode) { + this.splitFlags[splitIndex] = splitHasCode + ? this.splitFlags[splitIndex] | ApplicationInfo.FLAG_HAS_CODE + : this.splitFlags[splitIndex] & ~ApplicationInfo.FLAG_HAS_CODE; + return this; + } + + @Override + public ParsingPackageImpl setSplitClassLoaderName(int splitIndex, String classLoaderName) { + this.splitClassLoaderNames[splitIndex] = classLoaderName; + return this; + } + + @Override + public ParsingPackageImpl setProcessName(String processName) { + this.processName = TextUtils.safeIntern(processName); + return this; + } + + @Override + public ParsingPackageImpl setRealPackage(@Nullable String realPackage) { + this.realPackage = TextUtils.safeIntern(realPackage); + return this; + } + + @Override + public ParsingPackageImpl setRestrictedAccountType(@Nullable String restrictedAccountType) { + this.restrictedAccountType = TextUtils.safeIntern(restrictedAccountType); + return this; + } + + @Override + public ParsingPackageImpl setRequiredAccountType(@Nullable String requiredAccountType) { + this.requiredAccountType = TextUtils.nullIfEmpty(TextUtils.safeIntern(requiredAccountType)); + return this; + } + + @Override + public ParsingPackageImpl setOverlayTarget(@Nullable String overlayTarget) { + this.overlayTarget = TextUtils.safeIntern(overlayTarget); + return this; + } + + @Override + public ParsingPackageImpl setOverlayTargetName(@Nullable String overlayTargetName) { + this.overlayTargetName = TextUtils.safeIntern(overlayTargetName); + return this; + } + + @Override + public ParsingPackageImpl setOverlayCategory(@Nullable String overlayCategory) { + this.overlayCategory = TextUtils.safeIntern(overlayCategory); + return this; + } + + @Override + public ParsingPackageImpl setVolumeUuid(@Nullable String volumeUuid) { + this.volumeUuid = TextUtils.safeIntern(volumeUuid); + return this; + } + + @Override + public ParsingPackageImpl setAppComponentFactory(@Nullable String appComponentFactory) { + this.appComponentFactory = TextUtils.safeIntern(appComponentFactory); + return this; + } + + @Override + public ParsingPackageImpl setBackupAgentName(@Nullable String backupAgentName) { + this.backupAgentName = TextUtils.safeIntern(backupAgentName); + return this; + } + + @Override + public ParsingPackageImpl setClassLoaderName(@Nullable String classLoaderName) { + this.classLoaderName = TextUtils.safeIntern(classLoaderName); + return this; + } + + @Override + public ParsingPackageImpl setClassName(@Nullable String className) { + this.className = TextUtils.safeIntern(className); + return this; + } + + @Override + public ParsingPackageImpl setManageSpaceActivityName(@Nullable String manageSpaceActivityName) { + this.manageSpaceActivityName = TextUtils.safeIntern(manageSpaceActivityName); + return this; + } + + @Override + public ParsingPackageImpl setPermission(@Nullable String permission) { + this.permission = TextUtils.safeIntern(permission); + return this; + } + + @Override + public ParsingPackageImpl setTaskAffinity(@Nullable String taskAffinity) { + this.taskAffinity = TextUtils.safeIntern(taskAffinity); + return this; + } + + @Override + public ParsingPackageImpl setZygotePreloadName(@Nullable String zygotePreloadName) { + this.zygotePreloadName = TextUtils.safeIntern(zygotePreloadName); + return this; + } + + @Override + public ParsingPackageImpl setStaticSharedLibName(String staticSharedLibName) { + this.staticSharedLibName = TextUtils.safeIntern(staticSharedLibName); + return this; + } + + @Override + public ParsingPackageImpl setSharedUserId(String sharedUserId) { + this.sharedUserId = TextUtils.safeIntern(sharedUserId); + return this; + } + + @NonNull + @Override + public String getProcessName() { + return processName != null ? processName : packageName; + } + + @Override + public String toString() { + return "Package{" + + Integer.toHexString(System.identityHashCode(this)) + + " " + packageName + "}"; + } + + @Deprecated + @Override + public ApplicationInfo toAppInfoWithoutState() { + ApplicationInfo appInfo = new ApplicationInfo(); + appInfo.flags = PackageInfoWithoutStateUtils.appInfoFlags(this); + appInfo.privateFlags = PackageInfoWithoutStateUtils.appInfoPrivateFlags(this); + + appInfo.appComponentFactory = appComponentFactory; + appInfo.backupAgentName = backupAgentName; + appInfo.banner = banner; + appInfo.category = category; + appInfo.classLoaderName = classLoaderName; + appInfo.className = className; + appInfo.compatibleWidthLimitDp = compatibleWidthLimitDp; + appInfo.compileSdkVersion = compileSdkVersion; + appInfo.compileSdkVersionCodename = compileSdkVersionCodeName; +// appInfo.credentialProtectedDataDir = credentialProtectedDataDir; +// appInfo.dataDir = dataDir; + appInfo.descriptionRes = descriptionRes; +// appInfo.deviceProtectedDataDir = deviceProtectedDataDir; + appInfo.enabled = enabled; + appInfo.fullBackupContent = fullBackupContent; +// appInfo.hiddenUntilInstalled = hiddenUntilInstalled; + appInfo.icon = (PackageParser.sUseRoundIcon && roundIconRes != 0) ? roundIconRes : iconRes; + appInfo.iconRes = iconRes; + appInfo.roundIconRes = roundIconRes; + appInfo.installLocation = installLocation; + appInfo.labelRes = labelRes; + appInfo.largestWidthLimitDp = largestWidthLimitDp; + appInfo.logo = logo; + appInfo.manageSpaceActivityName = manageSpaceActivityName; + appInfo.maxAspectRatio = maxAspectRatio; + appInfo.metaData = metaData; + appInfo.minAspectRatio = minAspectRatio; + appInfo.minSdkVersion = minSdkVersion; + appInfo.name = className; + if (appInfo.name != null) { + appInfo.name = appInfo.name.trim(); + } +// appInfo.nativeLibraryDir = nativeLibraryDir; +// appInfo.nativeLibraryRootDir = nativeLibraryRootDir; +// appInfo.nativeLibraryRootRequiresIsa = nativeLibraryRootRequiresIsa; + appInfo.networkSecurityConfigRes = networkSecurityConfigRes; + appInfo.nonLocalizedLabel = nonLocalizedLabel; + if (appInfo.nonLocalizedLabel != null) { + appInfo.nonLocalizedLabel = appInfo.nonLocalizedLabel.toString().trim(); + } + appInfo.packageName = packageName; + appInfo.permission = permission; +// appInfo.primaryCpuAbi = primaryCpuAbi; + appInfo.processName = getProcessName(); + appInfo.requiresSmallestWidthDp = requiresSmallestWidthDp; +// appInfo.secondaryCpuAbi = secondaryCpuAbi; +// appInfo.secondaryNativeLibraryDir = secondaryNativeLibraryDir; +// appInfo.seInfo = seInfo; +// appInfo.seInfoUser = seInfoUser; +// appInfo.sharedLibraryFiles = usesLibraryFiles.isEmpty() +// ? null : usesLibraryFiles.toArray(new String[0]); +// appInfo.sharedLibraryInfos = usesLibraryInfos.isEmpty() ? null : usesLibraryInfos; + appInfo.splitClassLoaderNames = splitClassLoaderNames; + appInfo.splitDependencies = splitDependencies; + appInfo.splitNames = splitNames; + appInfo.storageUuid = StorageManager.convert(volumeUuid); + appInfo.targetSandboxVersion = targetSandboxVersion; + appInfo.targetSdkVersion = targetSdkVersion; + appInfo.taskAffinity = taskAffinity; + appInfo.theme = theme; +// appInfo.uid = uid; + appInfo.uiOptions = uiOptions; + appInfo.volumeUuid = volumeUuid; + appInfo.zygotePreloadName = zygotePreloadName; + appInfo.crossProfile = isCrossProfile(); + + appInfo.setBaseCodePath(baseCodePath); + appInfo.setBaseResourcePath(baseCodePath); + appInfo.setCodePath(codePath); + appInfo.setResourcePath(codePath); + appInfo.setSplitCodePaths(splitCodePaths); + appInfo.setSplitResourcePaths(splitCodePaths); + appInfo.setVersionCode(PackageInfo.composeLongVersionCode(versionCodeMajor, versionCode)); + + // TODO(b/135203078): Can this be removed? Looks only used in ActivityInfo. +// appInfo.showUserIcon = pkg.getShowUserIcon(); + // TODO(b/135203078): Unused? +// appInfo.resourceDirs = pkg.getResourceDirs(); + // TODO(b/135203078): Unused? +// appInfo.enabledSetting = pkg.getEnabledSetting(); + // TODO(b/135203078): See ParsingPackageImpl#getHiddenApiEnforcementPolicy +// appInfo.mHiddenApiPolicy = pkg.getHiddenApiPolicy(); + + return appInfo; + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + sForBoolean.parcel(this.supportsSmallScreens, dest, flags); + sForBoolean.parcel(this.supportsNormalScreens, dest, flags); + sForBoolean.parcel(this.supportsLargeScreens, dest, flags); + sForBoolean.parcel(this.supportsExtraLargeScreens, dest, flags); + sForBoolean.parcel(this.resizeable, dest, flags); + sForBoolean.parcel(this.anyDensity, dest, flags); + dest.writeInt(this.versionCode); + dest.writeInt(this.versionCodeMajor); + dest.writeInt(this.baseRevisionCode); + sForString.parcel(this.versionName, dest, flags); + dest.writeInt(this.compileSdkVersion); + sForString.parcel(this.compileSdkVersionCodeName, dest, flags); + sForString.parcel(this.packageName, dest, flags); + sForString.parcel(this.realPackage, dest, flags); + sForString.parcel(this.baseCodePath, dest, flags); + dest.writeBoolean(this.requiredForAllUsers); + sForString.parcel(this.restrictedAccountType, dest, flags); + sForString.parcel(this.requiredAccountType, dest, flags); + sForString.parcel(this.overlayTarget, dest, flags); + sForString.parcel(this.overlayTargetName, dest, flags); + sForString.parcel(this.overlayCategory, dest, flags); + dest.writeInt(this.overlayPriority); + dest.writeBoolean(this.overlayIsStatic); + sForStringValueMap.parcel(this.overlayables, dest, flags); + sForString.parcel(this.staticSharedLibName, dest, flags); + dest.writeLong(this.staticSharedLibVersion); + sForStringList.parcel(this.libraryNames, dest, flags); + sForStringList.parcel(this.usesLibraries, dest, flags); + sForStringList.parcel(this.usesOptionalLibraries, dest, flags); + sForStringList.parcel(this.usesStaticLibraries, dest, flags); + dest.writeLongArray(this.usesStaticLibrariesVersions); + + if (this.usesStaticLibrariesCertDigests == null) { + dest.writeInt(-1); + } else { + dest.writeInt(this.usesStaticLibrariesCertDigests.length); + for (int index = 0; index < this.usesStaticLibrariesCertDigests.length; index++) { + sForStringArray.parcel(this.usesStaticLibrariesCertDigests[index], dest, flags); + } + } + + sForString.parcel(this.sharedUserId, dest, flags); + dest.writeInt(this.sharedUserLabel); + dest.writeTypedList(this.configPreferences); + dest.writeTypedList(this.reqFeatures); + dest.writeTypedList(this.featureGroups); + dest.writeByteArray(this.restrictUpdateHash); + sForStringList.parcel(this.originalPackages, dest, flags); + sForStringList.parcel(this.adoptPermissions, dest, flags); + sForStringList.parcel(this.requestedPermissions, dest, flags); + sForStringList.parcel(this.implicitPermissions, dest, flags); + sForStringSet.parcel(this.upgradeKeySets, dest, flags); + dest.writeMap(this.keySetMapping); + sForStringList.parcel(this.protectedBroadcasts, dest, flags); + dest.writeTypedList(this.activities); + dest.writeTypedList(this.receivers); + dest.writeTypedList(this.services); + dest.writeTypedList(this.providers); + dest.writeTypedList(this.features); + dest.writeTypedList(this.permissions); + dest.writeTypedList(this.permissionGroups); + dest.writeTypedList(this.instrumentations); + ParsedIntentInfo.writeIntentsList(this.preferredActivityFilters, dest, flags); + dest.writeMap(this.processes); + dest.writeBundle(this.metaData); + sForString.parcel(this.volumeUuid, dest, flags); + dest.writeParcelable(this.signingDetails, flags); + sForString.parcel(this.codePath, dest, flags); + dest.writeBoolean(this.use32BitAbi); + dest.writeBoolean(this.visibleToInstantApps); + dest.writeBoolean(this.forceQueryable); + dest.writeParcelableList(this.queriesIntents, flags); + sForStringList.parcel(this.queriesPackages, dest, flags); + sForString.parcel(this.appComponentFactory, dest, flags); + sForString.parcel(this.backupAgentName, dest, flags); + dest.writeInt(this.banner); + dest.writeInt(this.category); + sForString.parcel(this.classLoaderName, dest, flags); + sForString.parcel(this.className, dest, flags); + dest.writeInt(this.compatibleWidthLimitDp); + dest.writeInt(this.descriptionRes); + dest.writeBoolean(this.enabled); + dest.writeBoolean(this.crossProfile); + dest.writeInt(this.fullBackupContent); + dest.writeInt(this.iconRes); + dest.writeInt(this.installLocation); + dest.writeInt(this.labelRes); + dest.writeInt(this.largestWidthLimitDp); + dest.writeInt(this.logo); + sForString.parcel(this.manageSpaceActivityName, dest, flags); + dest.writeFloat(this.maxAspectRatio); + dest.writeFloat(this.minAspectRatio); + dest.writeInt(this.minSdkVersion); + dest.writeInt(this.networkSecurityConfigRes); + dest.writeCharSequence(this.nonLocalizedLabel); + sForString.parcel(this.permission, dest, flags); + sForString.parcel(this.processName, dest, flags); + dest.writeInt(this.requiresSmallestWidthDp); + dest.writeInt(this.roundIconRes); + dest.writeInt(this.targetSandboxVersion); + dest.writeInt(this.targetSdkVersion); + sForString.parcel(this.taskAffinity, dest, flags); + dest.writeInt(this.theme); + dest.writeInt(this.uiOptions); + sForString.parcel(this.zygotePreloadName, dest, flags); + sForStringArray.parcel(this.splitClassLoaderNames, dest, flags); + sForStringArray.parcel(this.splitCodePaths, dest, flags); + dest.writeSparseArray(this.splitDependencies); + dest.writeIntArray(this.splitFlags); + sForStringArray.parcel(this.splitNames, dest, flags); + dest.writeIntArray(this.splitRevisionCodes); + + dest.writeBoolean(this.externalStorage); + dest.writeBoolean(this.baseHardwareAccelerated); + dest.writeBoolean(this.allowBackup); + dest.writeBoolean(this.killAfterRestore); + dest.writeBoolean(this.restoreAnyVersion); + dest.writeBoolean(this.fullBackupOnly); + dest.writeBoolean(this.persistent); + dest.writeBoolean(this.debuggable); + dest.writeBoolean(this.vmSafeMode); + dest.writeBoolean(this.hasCode); + dest.writeBoolean(this.allowTaskReparenting); + dest.writeBoolean(this.allowClearUserData); + dest.writeBoolean(this.largeHeap); + dest.writeBoolean(this.usesCleartextTraffic); + dest.writeBoolean(this.supportsRtl); + dest.writeBoolean(this.testOnly); + dest.writeBoolean(this.multiArch); + dest.writeBoolean(this.extractNativeLibs); + dest.writeBoolean(this.game); + + sForBoolean.parcel(this.resizeableActivity, dest, flags); + + dest.writeBoolean(this.staticSharedLibrary); + dest.writeBoolean(this.overlay); + dest.writeBoolean(this.isolatedSplitLoading); + dest.writeBoolean(this.hasDomainUrls); + dest.writeBoolean(this.profileableByShell); + dest.writeBoolean(this.backupInForeground); + dest.writeBoolean(this.useEmbeddedDex); + dest.writeBoolean(this.defaultToDeviceProtectedStorage); + dest.writeBoolean(this.directBootAware); + dest.writeBoolean(this.partiallyDirectBootAware); + dest.writeBoolean(this.resizeableActivityViaSdkVersion); + dest.writeBoolean(this.allowClearUserDataOnFailedRestore); + dest.writeBoolean(this.allowAudioPlaybackCapture); + dest.writeBoolean(this.requestLegacyExternalStorage); + dest.writeBoolean(this.usesNonSdkApi); + dest.writeBoolean(this.hasFragileUserData); + dest.writeBoolean(this.cantSaveState); + dest.writeBoolean(this.allowNativeHeapPointerTagging); + dest.writeBoolean(this.preserveLegacyExternalStorage); + dest.writeArraySet(this.mimeGroups); + } + + public ParsingPackageImpl(Parcel in) { + // We use the boot classloader for all classes that we load. + final ClassLoader boot = Object.class.getClassLoader(); + this.supportsSmallScreens = sForBoolean.unparcel(in); + this.supportsNormalScreens = sForBoolean.unparcel(in); + this.supportsLargeScreens = sForBoolean.unparcel(in); + this.supportsExtraLargeScreens = sForBoolean.unparcel(in); + this.resizeable = sForBoolean.unparcel(in); + this.anyDensity = sForBoolean.unparcel(in); + this.versionCode = in.readInt(); + this.versionCodeMajor = in.readInt(); + this.baseRevisionCode = in.readInt(); + this.versionName = sForString.unparcel(in); + this.compileSdkVersion = in.readInt(); + this.compileSdkVersionCodeName = sForString.unparcel(in); + this.packageName = sForString.unparcel(in); + this.realPackage = sForString.unparcel(in); + this.baseCodePath = sForString.unparcel(in); + this.requiredForAllUsers = in.readBoolean(); + this.restrictedAccountType = sForString.unparcel(in); + this.requiredAccountType = sForString.unparcel(in); + this.overlayTarget = sForString.unparcel(in); + this.overlayTargetName = sForString.unparcel(in); + this.overlayCategory = sForString.unparcel(in); + this.overlayPriority = in.readInt(); + this.overlayIsStatic = in.readBoolean(); + this.overlayables = sForStringValueMap.unparcel(in); + this.staticSharedLibName = sForString.unparcel(in); + this.staticSharedLibVersion = in.readLong(); + this.libraryNames = sForStringList.unparcel(in); + this.usesLibraries = sForStringList.unparcel(in); + this.usesOptionalLibraries = sForStringList.unparcel(in); + this.usesStaticLibraries = sForStringList.unparcel(in); + this.usesStaticLibrariesVersions = in.createLongArray(); + + int digestsSize = in.readInt(); + if (digestsSize >= 0) { + this.usesStaticLibrariesCertDigests = new String[digestsSize][]; + for (int index = 0; index < digestsSize; index++) { + this.usesStaticLibrariesCertDigests[index] = sForStringArray.unparcel(in); + } + } + + this.sharedUserId = sForString.unparcel(in); + this.sharedUserLabel = in.readInt(); + this.configPreferences = in.createTypedArrayList(ConfigurationInfo.CREATOR); + this.reqFeatures = in.createTypedArrayList(FeatureInfo.CREATOR); + this.featureGroups = in.createTypedArrayList(FeatureGroupInfo.CREATOR); + this.restrictUpdateHash = in.createByteArray(); + this.originalPackages = sForStringList.unparcel(in); + this.adoptPermissions = sForStringList.unparcel(in); + this.requestedPermissions = sForStringList.unparcel(in); + this.implicitPermissions = sForStringList.unparcel(in); + this.upgradeKeySets = sForStringSet.unparcel(in); + this.keySetMapping = in.readHashMap(boot); + this.protectedBroadcasts = sForStringList.unparcel(in); + this.activities = in.createTypedArrayList(ParsedActivity.CREATOR); + this.receivers = in.createTypedArrayList(ParsedActivity.CREATOR); + this.services = in.createTypedArrayList(ParsedService.CREATOR); + this.providers = in.createTypedArrayList(ParsedProvider.CREATOR); + this.features = in.createTypedArrayList(ParsedFeature.CREATOR); + this.permissions = in.createTypedArrayList(ParsedPermission.CREATOR); + this.permissionGroups = in.createTypedArrayList(ParsedPermissionGroup.CREATOR); + this.instrumentations = in.createTypedArrayList(ParsedInstrumentation.CREATOR); + this.preferredActivityFilters = ParsedIntentInfo.createIntentsList(in); + this.processes = in.readHashMap(boot); + this.metaData = in.readBundle(boot); + this.volumeUuid = sForString.unparcel(in); + this.signingDetails = in.readParcelable(boot); + this.codePath = sForString.unparcel(in); + this.use32BitAbi = in.readBoolean(); + this.visibleToInstantApps = in.readBoolean(); + this.forceQueryable = in.readBoolean(); + this.queriesIntents = in.createTypedArrayList(Intent.CREATOR); + this.queriesPackages = sForStringList.unparcel(in); + this.appComponentFactory = sForString.unparcel(in); + this.backupAgentName = sForString.unparcel(in); + this.banner = in.readInt(); + this.category = in.readInt(); + this.classLoaderName = sForString.unparcel(in); + this.className = sForString.unparcel(in); + this.compatibleWidthLimitDp = in.readInt(); + this.descriptionRes = in.readInt(); + this.enabled = in.readBoolean(); + this.crossProfile = in.readBoolean(); + this.fullBackupContent = in.readInt(); + this.iconRes = in.readInt(); + this.installLocation = in.readInt(); + this.labelRes = in.readInt(); + this.largestWidthLimitDp = in.readInt(); + this.logo = in.readInt(); + this.manageSpaceActivityName = sForString.unparcel(in); + this.maxAspectRatio = in.readFloat(); + this.minAspectRatio = in.readFloat(); + this.minSdkVersion = in.readInt(); + this.networkSecurityConfigRes = in.readInt(); + this.nonLocalizedLabel = in.readCharSequence(); + this.permission = sForString.unparcel(in); + this.processName = sForString.unparcel(in); + this.requiresSmallestWidthDp = in.readInt(); + this.roundIconRes = in.readInt(); + this.targetSandboxVersion = in.readInt(); + this.targetSdkVersion = in.readInt(); + this.taskAffinity = sForString.unparcel(in); + this.theme = in.readInt(); + this.uiOptions = in.readInt(); + this.zygotePreloadName = sForString.unparcel(in); + this.splitClassLoaderNames = sForStringArray.unparcel(in); + this.splitCodePaths = sForStringArray.unparcel(in); + this.splitDependencies = in.readSparseArray(boot); + this.splitFlags = in.createIntArray(); + this.splitNames = sForStringArray.unparcel(in); + this.splitRevisionCodes = in.createIntArray(); + this.externalStorage = in.readBoolean(); + this.baseHardwareAccelerated = in.readBoolean(); + this.allowBackup = in.readBoolean(); + this.killAfterRestore = in.readBoolean(); + this.restoreAnyVersion = in.readBoolean(); + this.fullBackupOnly = in.readBoolean(); + this.persistent = in.readBoolean(); + this.debuggable = in.readBoolean(); + this.vmSafeMode = in.readBoolean(); + this.hasCode = in.readBoolean(); + this.allowTaskReparenting = in.readBoolean(); + this.allowClearUserData = in.readBoolean(); + this.largeHeap = in.readBoolean(); + this.usesCleartextTraffic = in.readBoolean(); + this.supportsRtl = in.readBoolean(); + this.testOnly = in.readBoolean(); + this.multiArch = in.readBoolean(); + this.extractNativeLibs = in.readBoolean(); + this.game = in.readBoolean(); + + this.resizeableActivity = sForBoolean.unparcel(in); + + this.staticSharedLibrary = in.readBoolean(); + this.overlay = in.readBoolean(); + this.isolatedSplitLoading = in.readBoolean(); + this.hasDomainUrls = in.readBoolean(); + this.profileableByShell = in.readBoolean(); + this.backupInForeground = in.readBoolean(); + this.useEmbeddedDex = in.readBoolean(); + this.defaultToDeviceProtectedStorage = in.readBoolean(); + this.directBootAware = in.readBoolean(); + this.partiallyDirectBootAware = in.readBoolean(); + this.resizeableActivityViaSdkVersion = in.readBoolean(); + this.allowClearUserDataOnFailedRestore = in.readBoolean(); + this.allowAudioPlaybackCapture = in.readBoolean(); + this.requestLegacyExternalStorage = in.readBoolean(); + this.usesNonSdkApi = in.readBoolean(); + this.hasFragileUserData = in.readBoolean(); + this.cantSaveState = in.readBoolean(); + this.allowNativeHeapPointerTagging = in.readBoolean(); + this.preserveLegacyExternalStorage = in.readBoolean(); + this.mimeGroups = (ArraySet) in.readArraySet(boot); + } + + public static final Parcelable.Creator CREATOR = + new Parcelable.Creator() { + @Override + public ParsingPackageImpl createFromParcel(Parcel source) { + return new ParsingPackageImpl(source); + } + + @Override + public ParsingPackageImpl[] newArray(int size) { + return new ParsingPackageImpl[size]; + } + }; + + @Override + public int getVersionCode() { + return versionCode; + } + + @Override + public int getVersionCodeMajor() { + return versionCodeMajor; + } + + @Override + public int getBaseRevisionCode() { + return baseRevisionCode; + } + + @Nullable + @Override + public String getVersionName() { + return versionName; + } + + @Override + public int getCompileSdkVersion() { + return compileSdkVersion; + } + + @Nullable + @Override + public String getCompileSdkVersionCodeName() { + return compileSdkVersionCodeName; + } + + @NonNull + @Override + public String getPackageName() { + return packageName; + } + + @Nullable + @Override + public String getRealPackage() { + return realPackage; + } + + @NonNull + @Override + public String getBaseCodePath() { + return baseCodePath; + } + + @Override + public boolean isRequiredForAllUsers() { + return requiredForAllUsers; + } + + @Nullable + @Override + public String getRestrictedAccountType() { + return restrictedAccountType; + } + + @Nullable + @Override + public String getRequiredAccountType() { + return requiredAccountType; + } + + @Nullable + @Override + public String getOverlayTarget() { + return overlayTarget; + } + + @Nullable + @Override + public String getOverlayTargetName() { + return overlayTargetName; + } + + @Nullable + @Override + public String getOverlayCategory() { + return overlayCategory; + } + + @Override + public int getOverlayPriority() { + return overlayPriority; + } + + @Override + public boolean isOverlayIsStatic() { + return overlayIsStatic; + } + + @NonNull + @Override + public Map getOverlayables() { + return overlayables; + } + + @Nullable + @Override + public String getStaticSharedLibName() { + return staticSharedLibName; + } + + @Override + public long getStaticSharedLibVersion() { + return staticSharedLibVersion; + } + + @NonNull + @Override + public List getLibraryNames() { + return libraryNames; + } + + @NonNull + @Override + public List getUsesLibraries() { + return usesLibraries; + } + + @NonNull + @Override + public List getUsesOptionalLibraries() { + return usesOptionalLibraries; + } + + @NonNull + @Override + public List getUsesStaticLibraries() { + return usesStaticLibraries; + } + + @Nullable + @Override + public long[] getUsesStaticLibrariesVersions() { + return usesStaticLibrariesVersions; + } + + @Nullable + @Override + public String[][] getUsesStaticLibrariesCertDigests() { + return usesStaticLibrariesCertDigests; + } + + @Nullable + @Override + public String getSharedUserId() { + return sharedUserId; + } + + @Override + public int getSharedUserLabel() { + return sharedUserLabel; + } + + @NonNull + @Override + public List getConfigPreferences() { + return configPreferences; + } + + @NonNull + @Override + public List getReqFeatures() { + return reqFeatures; + } + + @NonNull + @Override + public List getFeatureGroups() { + return featureGroups; + } + + @Nullable + @Override + public byte[] getRestrictUpdateHash() { + return restrictUpdateHash; + } + + @NonNull + @Override + public List getOriginalPackages() { + return originalPackages; + } + + @NonNull + @Override + public List getAdoptPermissions() { + return adoptPermissions; + } + + @NonNull + @Override + public List getRequestedPermissions() { + return requestedPermissions; + } + + @NonNull + @Override + public List getImplicitPermissions() { + return implicitPermissions; + } + + @NonNull + @Override + public Set getUpgradeKeySets() { + return upgradeKeySets; + } + + @NonNull + @Override + public Map> getKeySetMapping() { + return keySetMapping; + } + + @NonNull + @Override + public List getProtectedBroadcasts() { + return protectedBroadcasts; + } + + @NonNull + @Override + public List getActivities() { + return activities; + } + + @NonNull + @Override + public List getReceivers() { + return receivers; + } + + @NonNull + @Override + public List getServices() { + return services; + } + + @NonNull + @Override + public List getProviders() { + return providers; + } + + @NonNull + @Override + public List getFeatures() { + return features; + } + + @NonNull + @Override + public List getPermissions() { + return permissions; + } + + @NonNull + @Override + public List getPermissionGroups() { + return permissionGroups; + } + + @NonNull + @Override + public List getInstrumentations() { + return instrumentations; + } + + @NonNull + @Override + public List getPreferredActivityFilters() { + return preferredActivityFilters; + } + + @NonNull + @Override + public Map getProcesses() { + return processes; + } + + @Nullable + @Override + public Bundle getMetaData() { + return metaData; + } + + private void addMimeGroupsFromComponent(ComponentParseUtils.ParsedComponent component) { + for (int i = component.intents.size() - 1; i >= 0; i--) { + IntentFilter filter = component.intents.get(i); + for (int groupIndex = filter.countMimeGroups() - 1; groupIndex >= 0; groupIndex--) { + mimeGroups = ArrayUtils.add(mimeGroups, filter.getMimeGroup(groupIndex)); + } + } + } + + @Override + @Nullable + public Set getMimeGroups() { + return mimeGroups; + } + + @Nullable + @Override + public String getVolumeUuid() { + return volumeUuid; + } + + @Nullable + @Override + public PackageParser.SigningDetails getSigningDetails() { + return signingDetails; + } + + @NonNull + @Override + public String getCodePath() { + return codePath; + } + + @Override + public boolean isUse32BitAbi() { + return use32BitAbi; + } + + @Override + public boolean isVisibleToInstantApps() { + return visibleToInstantApps; + } + + @Override + public boolean isForceQueryable() { + return forceQueryable; + } + + @NonNull + @Override + public List getQueriesIntents() { + return queriesIntents; + } + + @NonNull + @Override + public List getQueriesPackages() { + return queriesPackages; + } + + @NonNull + @Override + public Set getQueriesProviders() { + return queriesProviders; + } + + @Nullable + @Override + public String[] getSplitClassLoaderNames() { + return splitClassLoaderNames; + } + + @Nullable + @Override + public String[] getSplitCodePaths() { + return splitCodePaths; + } + + @Nullable + @Override + public SparseArray getSplitDependencies() { + return splitDependencies; + } + + @Nullable + @Override + public int[] getSplitFlags() { + return splitFlags; + } + + @Nullable + @Override + public String[] getSplitNames() { + return splitNames; + } + + @Nullable + @Override + public int[] getSplitRevisionCodes() { + return splitRevisionCodes; + } + + @Nullable + @Override + public String getAppComponentFactory() { + return appComponentFactory; + } + + @Nullable + @Override + public String getBackupAgentName() { + return backupAgentName; + } + + @Override + public int getBanner() { + return banner; + } + + @Override + public int getCategory() { + return category; + } + + @Nullable + @Override + public String getClassLoaderName() { + return classLoaderName; + } + + @Nullable + @Override + public String getClassName() { + return className; + } + + @Override + public int getCompatibleWidthLimitDp() { + return compatibleWidthLimitDp; + } + + @Override + public int getDescriptionRes() { + return descriptionRes; + } + + @Override + public boolean isEnabled() { + return enabled; + } + + @Override + public boolean isCrossProfile() { + return crossProfile; + } + + @Override + public int getFullBackupContent() { + return fullBackupContent; + } + + @Override + public int getIconRes() { + return iconRes; + } + + @Override + public int getInstallLocation() { + return installLocation; + } + + @Override + public int getLabelRes() { + return labelRes; + } + + @Override + public int getLargestWidthLimitDp() { + return largestWidthLimitDp; + } + + @Override + public int getLogo() { + return logo; + } + + @Nullable + @Override + public String getManageSpaceActivityName() { + return manageSpaceActivityName; + } + + @Override + public float getMaxAspectRatio() { + return maxAspectRatio; + } + + @Override + public float getMinAspectRatio() { + return minAspectRatio; + } + + @Override + public int getMinSdkVersion() { + return minSdkVersion; + } + + @Override + public int getNetworkSecurityConfigRes() { + return networkSecurityConfigRes; + } + + @Nullable + @Override + public CharSequence getNonLocalizedLabel() { + return nonLocalizedLabel; + } + + @Nullable + @Override + public String getPermission() { + return permission; + } + + @Override + public int getRequiresSmallestWidthDp() { + return requiresSmallestWidthDp; + } + + @Override + public int getRoundIconRes() { + return roundIconRes; + } + + @Override + public int getTargetSandboxVersion() { + return targetSandboxVersion; + } + + @Override + public int getTargetSdkVersion() { + return targetSdkVersion; + } + + @Nullable + @Override + public String getTaskAffinity() { + return taskAffinity; + } + + @Override + public int getTheme() { + return theme; + } + + @Override + public int getUiOptions() { + return uiOptions; + } + + @Nullable + @Override + public String getZygotePreloadName() { + return zygotePreloadName; + } + + @Override + public boolean isExternalStorage() { + return externalStorage; + } + + @Override + public boolean isBaseHardwareAccelerated() { + return baseHardwareAccelerated; + } + + @Override + public boolean isAllowBackup() { + return allowBackup; + } + + @Override + public boolean isKillAfterRestore() { + return killAfterRestore; + } + + @Override + public boolean isRestoreAnyVersion() { + return restoreAnyVersion; + } + + @Override + public boolean isFullBackupOnly() { + return fullBackupOnly; + } + + @Override + public boolean isPersistent() { + return persistent; + } + + @Override + public boolean isDebuggable() { + return debuggable; + } + + @Override + public boolean isVmSafeMode() { + return vmSafeMode; + } + + @Override + public boolean isHasCode() { + return hasCode; + } + + @Override + public boolean isAllowTaskReparenting() { + return allowTaskReparenting; + } + + @Override + public boolean isAllowClearUserData() { + return allowClearUserData; + } + + @Override + public boolean isLargeHeap() { + return largeHeap; + } + + @Override + public boolean isUsesCleartextTraffic() { + return usesCleartextTraffic; + } + + @Override + public boolean isSupportsRtl() { + return supportsRtl; + } + + @Override + public boolean isTestOnly() { + return testOnly; + } + + @Override + public boolean isMultiArch() { + return multiArch; + } + + @Override + public boolean isExtractNativeLibs() { + return extractNativeLibs; + } + + @Override + public boolean isGame() { + return game; + } + + /** + * @see ParsingPackageRead#getResizeableActivity() + */ + @Nullable + @Override + public Boolean getResizeableActivity() { + return resizeableActivity; + } + + @Override + public boolean isStaticSharedLibrary() { + return staticSharedLibrary; + } + + @Override + public boolean isOverlay() { + return overlay; + } + + @Override + public boolean isIsolatedSplitLoading() { + return isolatedSplitLoading; + } + + @Override + public boolean isHasDomainUrls() { + return hasDomainUrls; + } + + @Override + public boolean isProfileableByShell() { + return profileableByShell; + } + + @Override + public boolean isBackupInForeground() { + return backupInForeground; + } + + @Override + public boolean isUseEmbeddedDex() { + return useEmbeddedDex; + } + + @Override + public boolean isDefaultToDeviceProtectedStorage() { + return defaultToDeviceProtectedStorage; + } + + @Override + public boolean isDirectBootAware() { + return directBootAware; + } + + @Override + public boolean isPartiallyDirectBootAware() { + return partiallyDirectBootAware; + } + + @Override + public boolean isResizeableActivityViaSdkVersion() { + return resizeableActivityViaSdkVersion; + } + + @Override + public boolean isAllowClearUserDataOnFailedRestore() { + return allowClearUserDataOnFailedRestore; + } + + @Override + public boolean isAllowAudioPlaybackCapture() { + return allowAudioPlaybackCapture; + } + + @Override + public boolean isRequestLegacyExternalStorage() { + return requestLegacyExternalStorage; + } + + @Override + public boolean isUsesNonSdkApi() { + return usesNonSdkApi; + } + + @Override + public boolean isHasFragileUserData() { + return hasFragileUserData; + } + + @Override + public boolean isCantSaveState() { + return cantSaveState; + } + + @Override + public boolean isAllowNativeHeapPointerTagging() { + return allowNativeHeapPointerTagging; + } + + @Override + public boolean hasPreserveLegacyExternalStorage() { + return preserveLegacyExternalStorage; + } + + @Override + public ParsingPackageImpl setBaseRevisionCode(int value) { + baseRevisionCode = value; + return this; + } + + @Override + public ParsingPackageImpl setCompileSdkVersion(int value) { + compileSdkVersion = value; + return this; + } + + @Override + public ParsingPackageImpl setRequiredForAllUsers(boolean value) { + requiredForAllUsers = value; + return this; + } + + @Override + public ParsingPackageImpl setOverlayPriority(int value) { + overlayPriority = value; + return this; + } + + @Override + public ParsingPackageImpl setOverlayIsStatic(boolean value) { + overlayIsStatic = value; + return this; + } + + @Override + public ParsingPackageImpl setStaticSharedLibVersion(long value) { + staticSharedLibVersion = value; + return this; + } + + @Override + public ParsingPackageImpl setSharedUserLabel(int value) { + sharedUserLabel = value; + return this; + } + + @Override + public ParsingPackageImpl setRestrictUpdateHash(@Nullable byte... value) { + restrictUpdateHash = value; + return this; + } + + @Override + public ParsingPackageImpl setUpgradeKeySets(@NonNull Set value) { + upgradeKeySets = value; + return this; + } + + @Override + public ParsingPackageImpl setProcesses(@NonNull Map value) { + processes = value; + return this; + } + + @Override + public ParsingPackageImpl setMetaData(@Nullable Bundle value) { + metaData = value; + return this; + } + + @Override + public ParsingPackageImpl setSigningDetails(@Nullable PackageParser.SigningDetails value) { + signingDetails = value; + return this; + } + + @Override + public ParsingPackageImpl setUse32BitAbi(boolean value) { + use32BitAbi = value; + return this; + } + + @Override + public ParsingPackageImpl setVisibleToInstantApps(boolean value) { + visibleToInstantApps = value; + return this; + } + + @Override + public ParsingPackageImpl setForceQueryable(boolean value) { + forceQueryable = value; + return this; + } + + @Override + public ParsingPackageImpl setBanner(int value) { + banner = value; + return this; + } + + @Override + public ParsingPackageImpl setCategory(int value) { + category = value; + return this; + } + + @Override + public ParsingPackageImpl setCompatibleWidthLimitDp(int value) { + compatibleWidthLimitDp = value; + return this; + } + + @Override + public ParsingPackageImpl setDescriptionRes(int value) { + descriptionRes = value; + return this; + } + + @Override + public ParsingPackageImpl setEnabled(boolean value) { + enabled = value; + return this; + } + + @Override + public ParsingPackageImpl setCrossProfile(boolean value) { + crossProfile = value; + return this; + } + + @Override + public ParsingPackageImpl setFullBackupContent(int value) { + fullBackupContent = value; + return this; + } + + @Override + public ParsingPackageImpl setIconRes(int value) { + iconRes = value; + return this; + } + + @Override + public ParsingPackageImpl setInstallLocation(int value) { + installLocation = value; + return this; + } + + @Override + public ParsingPackageImpl setLabelRes(int value) { + labelRes = value; + return this; + } + + @Override + public ParsingPackageImpl setLargestWidthLimitDp(int value) { + largestWidthLimitDp = value; + return this; + } + + @Override + public ParsingPackageImpl setLogo(int value) { + logo = value; + return this; + } + + @Override + public ParsingPackageImpl setMaxAspectRatio(float value) { + maxAspectRatio = value; + return this; + } + + @Override + public ParsingPackageImpl setMinAspectRatio(float value) { + minAspectRatio = value; + return this; + } + + @Override + public ParsingPackageImpl setMinSdkVersion(int value) { + minSdkVersion = value; + return this; + } + + @Override + public ParsingPackageImpl setNetworkSecurityConfigRes(int value) { + networkSecurityConfigRes = value; + return this; + } + + @Override + public ParsingPackageImpl setNonLocalizedLabel(@Nullable CharSequence value) { + nonLocalizedLabel = value; + return this; + } + + @Override + public ParsingPackageImpl setRequiresSmallestWidthDp(int value) { + requiresSmallestWidthDp = value; + return this; + } + + @Override + public ParsingPackageImpl setRoundIconRes(int value) { + roundIconRes = value; + return this; + } + + @Override + public ParsingPackageImpl setTargetSandboxVersion(int value) { + targetSandboxVersion = value; + return this; + } + + @Override + public ParsingPackageImpl setTargetSdkVersion(int value) { + targetSdkVersion = value; + return this; + } + + @Override + public ParsingPackageImpl setTheme(int value) { + theme = value; + return this; + } + + @Override + public ParsingPackageImpl setUiOptions(int value) { + uiOptions = value; + return this; + } + + @Override + public ParsingPackageImpl setExternalStorage(boolean value) { + externalStorage = value; + return this; + } + + @Override + public ParsingPackageImpl setBaseHardwareAccelerated(boolean value) { + baseHardwareAccelerated = value; + return this; + } + + @Override + public ParsingPackageImpl setAllowBackup(boolean value) { + allowBackup = value; + return this; + } + + @Override + public ParsingPackageImpl setKillAfterRestore(boolean value) { + killAfterRestore = value; + return this; + } + + @Override + public ParsingPackageImpl setRestoreAnyVersion(boolean value) { + restoreAnyVersion = value; + return this; + } + + @Override + public ParsingPackageImpl setFullBackupOnly(boolean value) { + fullBackupOnly = value; + return this; + } + + @Override + public ParsingPackageImpl setPersistent(boolean value) { + persistent = value; + return this; + } + + @Override + public ParsingPackageImpl setDebuggable(boolean value) { + debuggable = value; + return this; + } + + @Override + public ParsingPackageImpl setVmSafeMode(boolean value) { + vmSafeMode = value; + return this; + } + + @Override + public ParsingPackageImpl setHasCode(boolean value) { + hasCode = value; + return this; + } + + @Override + public ParsingPackageImpl setAllowTaskReparenting(boolean value) { + allowTaskReparenting = value; + return this; + } + + @Override + public ParsingPackageImpl setAllowClearUserData(boolean value) { + allowClearUserData = value; + return this; + } + + @Override + public ParsingPackageImpl setLargeHeap(boolean value) { + largeHeap = value; + return this; + } + + @Override + public ParsingPackageImpl setUsesCleartextTraffic(boolean value) { + usesCleartextTraffic = value; + return this; + } + + @Override + public ParsingPackageImpl setSupportsRtl(boolean value) { + supportsRtl = value; + return this; + } + + @Override + public ParsingPackageImpl setTestOnly(boolean value) { + testOnly = value; + return this; + } + + @Override + public ParsingPackageImpl setMultiArch(boolean value) { + multiArch = value; + return this; + } + + @Override + public ParsingPackageImpl setExtractNativeLibs(boolean value) { + extractNativeLibs = value; + return this; + } + + @Override + public ParsingPackageImpl setGame(boolean value) { + game = value; + return this; + } + + /** + * @see ParsingPackageRead#getResizeableActivity() + */ + @Override + public ParsingPackageImpl setResizeableActivity(@Nullable Boolean value) { + resizeableActivity = value; + return this; + } + + @Override + public ParsingPackageImpl setStaticSharedLibrary(boolean value) { + staticSharedLibrary = value; + return this; + } + + @Override + public ParsingPackageImpl setOverlay(boolean value) { + overlay = value; + return this; + } + + @Override + public ParsingPackageImpl setIsolatedSplitLoading(boolean value) { + isolatedSplitLoading = value; + return this; + } + + @Override + public ParsingPackageImpl setHasDomainUrls(boolean value) { + hasDomainUrls = value; + return this; + } + + @Override + public ParsingPackageImpl setProfileableByShell(boolean value) { + profileableByShell = value; + return this; + } + + @Override + public ParsingPackageImpl setBackupInForeground(boolean value) { + backupInForeground = value; + return this; + } + + @Override + public ParsingPackageImpl setUseEmbeddedDex(boolean value) { + useEmbeddedDex = value; + return this; + } + + @Override + public ParsingPackageImpl setDefaultToDeviceProtectedStorage(boolean value) { + defaultToDeviceProtectedStorage = value; + return this; + } + + @Override + public ParsingPackageImpl setDirectBootAware(boolean value) { + directBootAware = value; + return this; + } + + @Override + public ParsingPackageImpl setPartiallyDirectBootAware(boolean value) { + partiallyDirectBootAware = value; + return this; + } + + @Override + public ParsingPackageImpl setResizeableActivityViaSdkVersion(boolean value) { + resizeableActivityViaSdkVersion = value; + return this; + } + + @Override + public ParsingPackageImpl setAllowClearUserDataOnFailedRestore(boolean value) { + allowClearUserDataOnFailedRestore = value; + return this; + } + + @Override + public ParsingPackageImpl setAllowAudioPlaybackCapture(boolean value) { + allowAudioPlaybackCapture = value; + return this; + } + + @Override + public ParsingPackageImpl setRequestLegacyExternalStorage(boolean value) { + requestLegacyExternalStorage = value; + return this; + } + + @Override + public ParsingPackageImpl setUsesNonSdkApi(boolean value) { + usesNonSdkApi = value; + return this; + } + + @Override + public ParsingPackageImpl setHasFragileUserData(boolean value) { + hasFragileUserData = value; + return this; + } + + @Override + public ParsingPackageImpl setCantSaveState(boolean value) { + cantSaveState = value; + return this; + } + + @Override + public ParsingPackageImpl setAllowNativeHeapPointerTagging(boolean value) { + allowNativeHeapPointerTagging = value; + return this; + } + + @Override + public ParsingPackageImpl setPreserveLegacyExternalStorage(boolean value) { + preserveLegacyExternalStorage = value; + return this; + } +} diff --git a/core/java/android/content/pm/parsing/ParsingPackageRead.java b/core/java/android/content/pm/parsing/ParsingPackageRead.java new file mode 100644 index 0000000000000..c5bb7639ef3e4 --- /dev/null +++ b/core/java/android/content/pm/parsing/ParsingPackageRead.java @@ -0,0 +1,844 @@ +/* + * Copyright (C) 2020 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.Intent; +import android.content.pm.ActivityInfo; +import android.content.pm.ApplicationInfo; +import android.content.pm.ConfigurationInfo; +import android.content.pm.FeatureGroupInfo; +import android.content.pm.FeatureInfo; +import android.content.pm.PackageInfo; +import android.content.pm.PackageParser; +import android.content.pm.ServiceInfo; +import android.content.pm.parsing.ComponentParseUtils.ParsedActivity; +import android.content.pm.parsing.ComponentParseUtils.ParsedActivityIntentInfo; +import android.content.pm.parsing.ComponentParseUtils.ParsedFeature; +import android.content.pm.parsing.ComponentParseUtils.ParsedInstrumentation; +import android.content.pm.parsing.ComponentParseUtils.ParsedPermission; +import android.content.pm.parsing.ComponentParseUtils.ParsedPermissionGroup; +import android.content.pm.parsing.ComponentParseUtils.ParsedProcess; +import android.content.pm.parsing.ComponentParseUtils.ParsedProvider; +import android.content.pm.parsing.ComponentParseUtils.ParsedService; +import android.os.Bundle; +import android.os.Parcelable; +import android.util.ArraySet; +import android.util.SparseArray; + +import com.android.internal.R; + +import java.security.PublicKey; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * Everything written by {@link ParsingPackage} and readable back. + * + * @hide + */ +@SuppressWarnings("UnusedReturnValue") +public interface ParsingPackageRead extends Parcelable { + + /** + * @see ActivityInfo + * @see PackageInfo#activities + */ + @NonNull + List getActivities(); + + /** + * The names of packages to adopt ownership of permissions from, parsed under + * {@link PackageParser#TAG_ADOPT_PERMISSIONS}. + * @see R.styleable#AndroidManifestOriginalPackage_name + */ + @NonNull + List getAdoptPermissions(); + + /** + * @see PackageInfo#configPreferences + * @see R.styleable#AndroidManifestUsesConfiguration + */ + @NonNull + List getConfigPreferences(); + + @NonNull + List getFeatures(); + + /** + * @see PackageInfo#featureGroups + * @see R.styleable#AndroidManifestUsesFeature + */ + @NonNull + List getFeatureGroups(); + + /** + * Permissions requested but not in the manifest. These may have been split or migrated from + * previous versions/definitions. + */ + @NonNull + List getImplicitPermissions(); + + /** + * @see android.content.pm.InstrumentationInfo + * @see PackageInfo#instrumentation + */ + @NonNull + List getInstrumentations(); + + /** + * For use with {@link com.android.server.pm.KeySetManagerService}. Parsed in + * {@link PackageParser#TAG_KEY_SETS}. + * @see R.styleable#AndroidManifestKeySet + * @see R.styleable#AndroidManifestPublicKey + */ + @NonNull + Map> getKeySetMapping(); + + /** + * Library names this package is declared as, for use by other packages with "uses-library". + * @see R.styleable#AndroidManifestLibrary + */ + @NonNull + List getLibraryNames(); + + /** + * For system use to migrate from an old package name to a new one, moving over data + * if available. + * @see R.styleable#AndroidManifestOriginalPackage} + */ + @NonNull + List getOriginalPackages(); + + /** + * Map of overlayable name to actor name. + */ + @NonNull + Map getOverlayables(); + + /** + * @see android.content.pm.PermissionInfo + * @see PackageInfo#permissions + */ + @NonNull + List getPermissions(); + + /** + * @see android.content.pm.PermissionGroupInfo + */ + @NonNull + List getPermissionGroups(); + + /** + * Used to determine the default preferred handler of an {@link Intent}. + * + * Map of component className to intent info inside that component. + * TODO(b/135203078): Is this actually used/working? + */ + @NonNull + List getPreferredActivityFilters(); + + /** + * System protected broadcasts. + * @see R.styleable#AndroidManifestProtectedBroadcast + */ + @NonNull + List getProtectedBroadcasts(); + + /** + * @see android.content.pm.ProviderInfo + * @see PackageInfo#providers + */ + @NonNull + List getProviders(); + + /** + * @see android.content.pm.ProcessInfo + */ + @NonNull + Map getProcesses(); + + /** + * Since they share several attributes, receivers are parsed as {@link ParsedActivity}, even + * though they represent different functionality. + * TODO(b/135203078): Reconsider this and maybe make ParsedReceiver so it's not so confusing + * @see ActivityInfo + * @see PackageInfo#receivers + */ + @NonNull + List getReceivers(); + + /** + * @see PackageInfo#reqFeatures + * @see R.styleable#AndroidManifestUsesFeature + */ + @NonNull + List getReqFeatures(); + + /** + * All the permissions declared. This is an effective set, and may include permissions + * transformed from split/migrated permissions from previous versions, so may not be exactly + * what the package declares in its manifest. + * @see PackageInfo#requestedPermissions + * @see R.styleable#AndroidManifestUsesPermission + */ + @NonNull + List getRequestedPermissions(); + + /** + * Whether or not the app requested explicitly resizeable Activities. + * A null value means nothing was explicitly requested. + */ + @Nullable + Boolean getResizeableActivity(); + + /** + * @see ServiceInfo + * @see PackageInfo#services + */ + @NonNull + List getServices(); + + /** @see R.styleable#AndroidManifestUsesLibrary */ + @NonNull + List getUsesLibraries(); + + /** + * Like {@link #getUsesLibraries()}, but marked optional by setting + * {@link R.styleable#AndroidManifestUsesLibrary_required} to false . Application is expected + * to handle absence manually. + * @see R.styleable#AndroidManifestUsesLibrary + */ + @NonNull + List getUsesOptionalLibraries(); + + /** + * TODO(b/135203078): Move static library stuff to an inner data class + * @see R.styleable#AndroidManifestUsesStaticLibrary + */ + @NonNull + List getUsesStaticLibraries(); + + /** @see R.styleable#AndroidManifestUsesStaticLibrary_certDigest */ + @Nullable + String[][] getUsesStaticLibrariesCertDigests(); + + /** @see R.styleable#AndroidManifestUsesStaticLibrary_version */ + @Nullable + long[] getUsesStaticLibrariesVersions(); + + /** + * Intents that this package may query or require and thus requires visibility into. + * @see R.styleable#AndroidManifestQueriesIntent + */ + @NonNull + List getQueriesIntents(); + + /** + * Other packages that this package may query or require and thus requires visibility into. + * @see R.styleable#AndroidManifestQueriesPackage + */ + @NonNull + List getQueriesPackages(); + + /** + * Authorities that this package may query or require and thus requires visibility into. + * @see R.styleable#AndroidManifestQueriesProvider + */ + @NonNull + Set getQueriesProviders(); + + /** + * We store the application meta-data independently to avoid multiple unwanted references + * TODO(b/135203078): What does this comment mean? + * TODO(b/135203078): Make all the Bundles immutable (and non-null by shared empty reference?) + */ + @Nullable + Bundle getMetaData(); + + /** @see R.styleable#AndroidManifestApplication_forceQueryable */ + boolean isForceQueryable(); + + /** + * @see ApplicationInfo#maxAspectRatio + * @see R.styleable#AndroidManifestApplication_maxAspectRatio + */ + float getMaxAspectRatio(); + + /** + * @see ApplicationInfo#minAspectRatio + * @see R.styleable#AndroidManifestApplication_minAspectRatio + */ + float getMinAspectRatio(); + + /** + * @see ApplicationInfo#permission + * @see R.styleable#AndroidManifestApplication_permission + */ + @Nullable + String getPermission(); + + /** + * @see ApplicationInfo#processName + * @see R.styleable#AndroidManifestApplication_process + */ + @NonNull + String getProcessName(); + + /** + * @see PackageInfo#sharedUserId + * @see R.styleable#AndroidManifest_sharedUserId + */ + @Deprecated + @Nullable + String getSharedUserId(); + + /** @see R.styleable#AndroidManifestStaticLibrary_name */ + @Nullable + String getStaticSharedLibName(); + + /** + * @see ApplicationInfo#taskAffinity + * @see R.styleable#AndroidManifestApplication_taskAffinity + */ + @Nullable + String getTaskAffinity(); + + /** + * @see ApplicationInfo#targetSdkVersion + * @see R.styleable#AndroidManifestUsesSdk_targetSdkVersion + */ + int getTargetSdkVersion(); + + /** + * @see ApplicationInfo#uiOptions + * @see R.styleable#AndroidManifestApplication_uiOptions + */ + int getUiOptions(); + + boolean isCrossProfile(); + + boolean isResizeableActivityViaSdkVersion(); + + /** @see ApplicationInfo#FLAG_HARDWARE_ACCELERATED */ + boolean isBaseHardwareAccelerated(); + + /** + * If omitted from manifest, returns true if {@link #getTargetSdkVersion()} >= + * {@link android.os.Build.VERSION_CODES#DONUT}. + * @see R.styleable#AndroidManifestSupportsScreens_resizeable + * @see ApplicationInfo#FLAG_RESIZEABLE_FOR_SCREENS + */ + boolean isResizeable(); + + /** @see ApplicationInfo#PRIVATE_FLAG_ALLOW_AUDIO_PLAYBACK_CAPTURE */ + boolean isAllowAudioPlaybackCapture(); + + /** @see ApplicationInfo#FLAG_ALLOW_BACKUP */ + boolean isAllowBackup(); + + /** @see ApplicationInfo#FLAG_ALLOW_CLEAR_USER_DATA */ + boolean isAllowClearUserData(); + + /** @see ApplicationInfo#PRIVATE_FLAG_ALLOW_CLEAR_USER_DATA_ON_FAILED_RESTORE */ + boolean isAllowClearUserDataOnFailedRestore(); + + /** @see ApplicationInfo#FLAG_ALLOW_TASK_REPARENTING */ + boolean isAllowTaskReparenting(); + + /** + * @see ApplicationInfo#PRIVATE_FLAG_IS_RESOURCE_OVERLAY + * @see ApplicationInfo#isResourceOverlay() + */ + boolean isOverlay(); + + /** @see ApplicationInfo#PRIVATE_FLAG_BACKUP_IN_FOREGROUND */ + boolean isBackupInForeground(); + + /** @see ApplicationInfo#PRIVATE_FLAG_CANT_SAVE_STATE */ + boolean isCantSaveState(); + + /** @see ApplicationInfo#FLAG_DEBUGGABLE */ + boolean isDebuggable(); + + /** @see ApplicationInfo#PRIVATE_FLAG_DEFAULT_TO_DEVICE_PROTECTED_STORAGE */ + boolean isDefaultToDeviceProtectedStorage(); + + /** @see ApplicationInfo#PRIVATE_FLAG_DIRECT_BOOT_AWARE */ + boolean isDirectBootAware(); + + /** @see ApplicationInfo#FLAG_EXTERNAL_STORAGE */ + boolean isExternalStorage(); + + /** @see ApplicationInfo#FLAG_EXTRACT_NATIVE_LIBS */ + boolean isExtractNativeLibs(); + + /** @see ApplicationInfo#FLAG_FULL_BACKUP_ONLY */ + boolean isFullBackupOnly(); + + /** @see ApplicationInfo#FLAG_HAS_CODE */ + boolean isHasCode(); + + /** @see ApplicationInfo#PRIVATE_FLAG_HAS_FRAGILE_USER_DATA */ + boolean isHasFragileUserData(); + + /** @see ApplicationInfo#FLAG_IS_GAME */ + @Deprecated + boolean isGame(); + + /** @see ApplicationInfo#PRIVATE_FLAG_ISOLATED_SPLIT_LOADING */ + boolean isIsolatedSplitLoading(); + + /** @see ApplicationInfo#FLAG_KILL_AFTER_RESTORE */ + boolean isKillAfterRestore(); + + /** @see ApplicationInfo#FLAG_LARGE_HEAP */ + boolean isLargeHeap(); + + /** @see ApplicationInfo#FLAG_MULTIARCH */ + boolean isMultiArch(); + + /** @see ApplicationInfo#PRIVATE_FLAG_PARTIALLY_DIRECT_BOOT_AWARE */ + boolean isPartiallyDirectBootAware(); + + /** @see ApplicationInfo#FLAG_PERSISTENT */ + boolean isPersistent(); + + /** @see ApplicationInfo#PRIVATE_FLAG_PROFILEABLE_BY_SHELL */ + boolean isProfileableByShell(); + + /** @see ApplicationInfo#PRIVATE_FLAG_REQUEST_LEGACY_EXTERNAL_STORAGE */ + boolean isRequestLegacyExternalStorage(); + + /** @see ApplicationInfo#FLAG_RESTORE_ANY_VERSION */ + boolean isRestoreAnyVersion(); + + // ParsingPackageRead setSplitHasCode(int splitIndex, boolean splitHasCode); + + /** Flags of any split APKs; ordered by parsed splitName */ + @Nullable + int[] getSplitFlags(); + + /** @see ApplicationInfo#splitSourceDirs */ + @Nullable + String[] getSplitCodePaths(); + + /** @see ApplicationInfo#splitDependencies */ + @Nullable + SparseArray getSplitDependencies(); + + /** + * @see ApplicationInfo#splitNames + * @see PackageInfo#splitNames + */ + @Nullable + String[] getSplitNames(); + + /** @see PackageInfo#splitRevisionCodes */ + int[] getSplitRevisionCodes(); + + /** @see ApplicationInfo#PRIVATE_FLAG_STATIC_SHARED_LIBRARY */ + boolean isStaticSharedLibrary(); + + /** @see ApplicationInfo#FLAG_SUPPORTS_RTL */ + boolean isSupportsRtl(); + + /** @see ApplicationInfo#FLAG_TEST_ONLY */ + boolean isTestOnly(); + + /** @see ApplicationInfo#PRIVATE_FLAG_USE_EMBEDDED_DEX */ + boolean isUseEmbeddedDex(); + + /** @see ApplicationInfo#FLAG_USES_CLEARTEXT_TRAFFIC */ + boolean isUsesCleartextTraffic(); + + /** @see ApplicationInfo#PRIVATE_FLAG_USES_NON_SDK_API */ + boolean isUsesNonSdkApi(); + + /** + * Set if the any of components are visible to instant applications. + * @see R.styleable#AndroidManifestActivity_visibleToInstantApps + * @see R.styleable#AndroidManifestProvider_visibleToInstantApps + * @see R.styleable#AndroidManifestService_visibleToInstantApps + */ + boolean isVisibleToInstantApps(); + + /** @see ApplicationInfo#FLAG_VM_SAFE_MODE */ + boolean isVmSafeMode(); + + /** + * If omitted from manifest, returns true if {@link #getTargetSdkVersion()} >= + * {@link android.os.Build.VERSION_CODES#DONUT}. + * @see R.styleable#AndroidManifestSupportsScreens_anyDensity + * @see ApplicationInfo#FLAG_SUPPORTS_SCREEN_DENSITIES + */ + boolean isAnyDensity(); + + /** + * @see ApplicationInfo#appComponentFactory + * @see R.styleable#AndroidManifestApplication_appComponentFactory + */ + @Nullable + String getAppComponentFactory(); + + /** + * @see ApplicationInfo#backupAgentName + * @see R.styleable#AndroidManifestApplication_backupAgent + */ + @Nullable + String getBackupAgentName(); + + /** + * @see ApplicationInfo#banner + * @see R.styleable#AndroidManifestApplication_banner + */ + int getBanner(); + + /** + * @see ApplicationInfo#category + * @see R.styleable#AndroidManifestApplication_appCategory + */ + int getCategory(); + + /** + * @see ApplicationInfo#classLoaderName + * @see R.styleable#AndroidManifestApplication_classLoader + */ + @Nullable + String getClassLoaderName(); + + /** + * @see ApplicationInfo#className + * @see R.styleable#AndroidManifestApplication_name + */ + @Nullable + String getClassName(); + + String getPackageName(); + + /** Path of base APK */ + String getBaseCodePath(); + + /** + * 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. + */ + @NonNull + String getCodePath(); + + /** + * @see ApplicationInfo#compatibleWidthLimitDp + * @see R.styleable#AndroidManifestSupportsScreens_compatibleWidthLimitDp + */ + int getCompatibleWidthLimitDp(); + + /** + * @see ApplicationInfo#descriptionRes + * @see R.styleable#AndroidManifestApplication_description + */ + int getDescriptionRes(); + + /** + * @see ApplicationInfo#enabled + * @see R.styleable#AndroidManifestApplication_enabled + */ + boolean isEnabled(); + + /** + * @see ApplicationInfo#fullBackupContent + * @see R.styleable#AndroidManifestApplication_fullBackupContent + */ + int getFullBackupContent(); + + /** @see ApplicationInfo#PRIVATE_FLAG_HAS_DOMAIN_URLS */ + boolean isHasDomainUrls(); + + /** + * @see ApplicationInfo#iconRes + * @see R.styleable#AndroidManifestApplication_icon + */ + int getIconRes(); + + /** + * @see ApplicationInfo#installLocation + * @see R.styleable#AndroidManifest_installLocation + */ + int getInstallLocation(); + + /** + * @see ApplicationInfo#labelRes + * @see R.styleable#AndroidManifestApplication_label + */ + int getLabelRes(); + + /** + * @see ApplicationInfo#largestWidthLimitDp + * @see R.styleable#AndroidManifestSupportsScreens_largestWidthLimitDp + */ + int getLargestWidthLimitDp(); + + /** + * @see ApplicationInfo#logo + * @see R.styleable#AndroidManifestApplication_logo + */ + int getLogo(); + + /** + * @see ApplicationInfo#manageSpaceActivityName + * @see R.styleable#AndroidManifestApplication_manageSpaceActivity + */ + @Nullable + String getManageSpaceActivityName(); + + /** + * @see ApplicationInfo#minSdkVersion + * @see R.styleable#AndroidManifestUsesSdk_minSdkVersion + */ + int getMinSdkVersion(); + + /** + * @see ApplicationInfo#networkSecurityConfigRes + * @see R.styleable#AndroidManifestApplication_networkSecurityConfig + */ + int getNetworkSecurityConfigRes(); + + /** + * If {@link R.styleable#AndroidManifestApplication_label} is a string literal, this is it. + * Otherwise, it's stored as {@link #getLabelRes()}. + * @see ApplicationInfo#nonLocalizedLabel + * @see R.styleable#AndroidManifestApplication_label + */ + @Nullable + CharSequence getNonLocalizedLabel(); + + /** + * @see PackageInfo#overlayCategory + * @see R.styleable#AndroidManifestResourceOverlay_category + */ + @Nullable + String getOverlayCategory(); + + /** @see PackageInfo#mOverlayIsStatic */ + boolean isOverlayIsStatic(); + + /** + * @see PackageInfo#overlayPriority + * @see R.styleable#AndroidManifestResourceOverlay_priority + */ + int getOverlayPriority(); + + /** + * @see PackageInfo#overlayTarget + * @see R.styleable#AndroidManifestResourceOverlay_targetPackage + */ + @Nullable + String getOverlayTarget(); + + /** + * @see PackageInfo#targetOverlayableName + * @see R.styleable#AndroidManifestResourceOverlay_targetName + */ + @Nullable + String getOverlayTargetName(); + + /** + * If a system app declares {@link #getOriginalPackages()}, and the app was previously installed + * under one of those original package names, the {@link #getPackageName()} system identifier + * will be changed to that previously installed name. This will then be non-null, set to the + * manifest package name, for tracking the package under its true name. + * + * TODO(b/135203078): Remove this in favor of checking originalPackages.isEmpty and + * getManifestPackageName + */ + @Nullable + String getRealPackage(); + + /** + * The required account type without which this application will not function. + * + * @see PackageInfo#requiredAccountType + * @see R.styleable#AndroidManifestApplication_requiredAccountType + */ + @Nullable + String getRequiredAccountType(); + + /** + * @see PackageInfo#requiredForAllUsers + * @see R.styleable#AndroidManifestApplication_requiredForAllUsers + */ + boolean isRequiredForAllUsers(); + + /** + * @see ApplicationInfo#requiresSmallestWidthDp + * @see R.styleable#AndroidManifestSupportsScreens_requiresSmallestWidthDp + */ + int getRequiresSmallestWidthDp(); + + /** + * SHA-512 hash of the only APK that can be used to update a system package. + * @see R.styleable#AndroidManifestRestrictUpdate + */ + @Nullable + byte[] getRestrictUpdateHash(); + + /** + * The restricted account authenticator type that is used by this application + * + * @see PackageInfo#restrictedAccountType + * @see R.styleable#AndroidManifestApplication_restrictedAccountType + */ + @Nullable + String getRestrictedAccountType(); + + /** + * @see ApplicationInfo#roundIconRes + * @see R.styleable#AndroidManifestApplication_roundIcon + */ + int getRoundIconRes(); + + /** + * @see PackageInfo#sharedUserLabel + * @see R.styleable#AndroidManifest_sharedUserLabel + */ + @Deprecated + int getSharedUserLabel(); + + /** + * The signature data of all APKs in this package, which must be exactly the same across the + * base and splits. + */ + PackageParser.SigningDetails getSigningDetails(); + + /** + * @see ApplicationInfo#splitClassLoaderNames + * @see R.styleable#AndroidManifestApplication_classLoader + */ + @Nullable + String[] getSplitClassLoaderNames(); + + /** @see R.styleable#AndroidManifestStaticLibrary_version */ + long getStaticSharedLibVersion(); + + /** + * If omitted from manifest, returns true if {@link #getTargetSdkVersion()} >= + * {@link android.os.Build.VERSION_CODES#DONUT}. + * @see R.styleable#AndroidManifestSupportsScreens_largeScreens + * @see ApplicationInfo#FLAG_SUPPORTS_LARGE_SCREENS + */ + boolean isSupportsLargeScreens(); + + /** + * If omitted from manifest, returns true. + * @see R.styleable#AndroidManifestSupportsScreens_normalScreens + * @see ApplicationInfo#FLAG_SUPPORTS_NORMAL_SCREENS + */ + boolean isSupportsNormalScreens(); + + /** + * If omitted from manifest, returns true if {@link #getTargetSdkVersion()} >= + * {@link android.os.Build.VERSION_CODES#DONUT}. + * @see R.styleable#AndroidManifestSupportsScreens_smallScreens + * @see ApplicationInfo#FLAG_SUPPORTS_SMALL_SCREENS + */ + boolean isSupportsSmallScreens(); + + /** + * If omitted from manifest, returns true if {@link #getTargetSdkVersion()} >= + * {@link android.os.Build.VERSION_CODES#GINGERBREAD}. + * @see R.styleable#AndroidManifestSupportsScreens_xlargeScreens + * @see ApplicationInfo#FLAG_SUPPORTS_XLARGE_SCREENS + */ + boolean isSupportsExtraLargeScreens(); + + /** @see ApplicationInfo#PRIVATE_FLAG_ALLOW_NATIVE_HEAP_POINTER_TAGGING */ + boolean isAllowNativeHeapPointerTagging(); + + boolean hasPreserveLegacyExternalStorage(); + + /** + * @see ApplicationInfo#targetSandboxVersion + * @see R.styleable#AndroidManifest_targetSandboxVersion + */ + @Deprecated + int getTargetSandboxVersion(); + + /** + * @see ApplicationInfo#theme + * @see R.styleable#AndroidManifestApplication_theme + */ + int getTheme(); + + /** + * For use with {@link com.android.server.pm.KeySetManagerService}. Parsed in + * {@link PackageParser#TAG_KEY_SETS}. + * @see R.styleable#AndroidManifestUpgradeKeySet + */ + @NonNull + Set getUpgradeKeySets(); + + /** + * The install time abi override to choose 32bit abi's when multiple abi's + * are present. This is only meaningfull for multiarch applications. + * The use32bitAbi attribute is ignored if cpuAbiOverride is also set. + */ + boolean isUse32BitAbi(); + + /** @see ApplicationInfo#volumeUuid */ + @Nullable + String getVolumeUuid(); + + /** @see ApplicationInfo#zygotePreloadName */ + @Nullable + String getZygotePreloadName(); + + /** Revision code of base APK */ + int getBaseRevisionCode(); + + /** @see PackageInfo#versionName */ + @Nullable + String getVersionName(); + + /** @see PackageInfo#versionCodeMajor */ + @Nullable + int getVersionCode(); + + /** @see PackageInfo#versionCodeMajor */ + @Nullable + int getVersionCodeMajor(); + + /** + * @see ApplicationInfo#compileSdkVersion + * @see R.styleable#AndroidManifest_compileSdkVersion + */ + int getCompileSdkVersion(); + + /** + * @see ApplicationInfo#compileSdkVersionCodename + * @see R.styleable#AndroidManifest_compileSdkVersionCodename + */ + @Nullable + String getCompileSdkVersionCodeName(); + + @Nullable + Set getMimeGroups(); + + // TODO(b/135203078): Hide and enforce going through PackageInfoUtils + ApplicationInfo toAppInfoWithoutState(); +} diff --git a/core/java/android/content/pm/parsing/AndroidPackage.aidl b/services/core/java/com/android/server/pm/parsing/pkg/AndroidPackage.aidl similarity index 100% rename from core/java/android/content/pm/parsing/AndroidPackage.aidl rename to services/core/java/com/android/server/pm/parsing/pkg/AndroidPackage.aidl diff --git a/services/core/java/com/android/server/pm/parsing/pkg/AndroidPackage.java b/services/core/java/com/android/server/pm/parsing/pkg/AndroidPackage.java new file mode 100644 index 0000000000000..239cf9d2f1ae5 --- /dev/null +++ b/services/core/java/com/android/server/pm/parsing/pkg/AndroidPackage.java @@ -0,0 +1,368 @@ +/* + * Copyright (C) 2020 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 com.android.server.pm.parsing.pkg; + +import static android.content.pm.parsing.ComponentParseUtils.ParsedActivityIntentInfo; + +import android.annotation.NonNull; +import android.annotation.Nullable; +import android.content.Intent; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageInfo; +import android.content.pm.PackageParser; +import android.content.pm.PermissionGroupInfo; +import android.content.pm.SharedLibraryInfo; +import android.content.pm.parsing.ComponentParseUtils.ParsedFeature; +import android.content.pm.parsing.ComponentParseUtils.ParsedPermissionGroup; +import android.content.pm.parsing.ParsingPackageRead; +import android.os.Bundle; +import android.os.Parcelable; +import android.util.ArraySet; + +import com.android.internal.R; + +import java.security.PublicKey; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.UUID; + +/** + * The last state of a package during parsing/install before it is available in + * {@link com.android.server.pm.PackageManagerService#mPackages}. + * + * It is the responsibility of the caller to understand what data is available at what step of the + * parsing or install process. + * + * TODO(b/135203078): Nullability annotations + * TODO(b/135203078): Remove get/setAppInfo differences + * + * @hide + */ +public interface AndroidPackage extends PkgAppInfo, PkgPackageInfo, ParsingPackageRead, Parcelable { + + //TODO(b/135203078): Remove in favor of individual methods + @Deprecated + int getFlags(); + + //TODO(b/135203078): Remove in favor of individual methods + @Deprecated + int getPrivateFlags(); + + //TODO(b/135203078): Move to PackageSetting + @Deprecated + @Nullable + String[] getUsesLibraryFiles(); + + //TODO(b/135203078): Move to PackageSetting + @Deprecated + List getUsesLibraryInfos(); + + /** + * This will eventually be removed. Avoid calling this at all costs. + */ + @Deprecated + AndroidPackageWrite mutate(); + + @Deprecated + String getCredentialProtectedDataDir(); + + @Deprecated + String getDataDir(); + + @Deprecated + String getDeviceProtectedDataDir(); + + /** + * The names of packages to adopt ownership of permissions from, parsed under + * {@link PackageParser#TAG_ADOPT_PERMISSIONS}. + * @see R.styleable#AndroidManifestOriginalPackage_name + */ + @NonNull + List getAdoptPermissions(); + + /** Path of base APK */ + @NonNull + String getBaseCodePath(); + + /** Revision code of base APK */ + int getBaseRevisionCode(); + + /** + * 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. + */ + @NonNull + String getCodePath(); + + /** + * The install time abi override for this package, if any. + * + * TODO(b/135203078): This seems like a horrible place to put the abiOverride because + * this isn't something the packageParser parsers. + */ + @Nullable + String getCpuAbiOverride(); + + /** + * Permissions requested but not in the manifest. These may have been split or migrated from + * previous versions/definitions. + */ + @NonNull + List getImplicitPermissions(); + + /** + * For use with {@link com.android.server.pm.KeySetManagerService}. Parsed in + * {@link PackageParser#TAG_KEY_SETS}. + * @see R.styleable#AndroidManifestKeySet + * @see R.styleable#AndroidManifestPublicKey + */ + @NonNull + Map> getKeySetMapping(); + + /** + * Library names this package is declared as, for use by other packages with "uses-library". + * @see R.styleable#AndroidManifestLibrary + */ + @NonNull + List getLibraryNames(); + + /** + * The package name as declared in the manifest, since the package can be renamed. For example, + * static shared libs use synthetic package names. + */ + @NonNull + String getManifestPackageName(); + + /** + * We store the application meta-data independently to avoid multiple unwanted references + * TODO(b/135203078): What does this comment mean? + * TODO(b/135203078): Make all the Bundles immutable (and non-null by shared empty reference?) + */ + @Nullable + Bundle getMetaData(); + + /** + * For system use to migrate from an old package name to a new one, moving over data + * if available. + * @see R.styleable#AndroidManifestOriginalPackage} + */ + @NonNull + List getOriginalPackages(); + + /** + * Map of overlayable name to actor name. + */ + @NonNull + Map getOverlayables(); + + /** + * The name of the package as used to identify it in the system. This may be adjusted by the + * system from the value declared in the manifest, and may not correspond to a Java code + * package. + * @see ApplicationInfo#packageName + * @see PackageInfo#packageName + */ + @NonNull + String getPackageName(); + + /** + * @see PermissionGroupInfo + */ + @NonNull + List getPermissionGroups(); + + @Nullable + List getFeatures(); + + /** + * Used to determine the default preferred handler of an {@link Intent}. + * + * Map of component className to intent info inside that component. + * TODO(b/135203078): Is this actually used/working? + */ + @NonNull + List getPreferredActivityFilters(); + + /** + * System protected broadcasts. + * @see R.styleable#AndroidManifestProtectedBroadcast + */ + @NonNull + List getProtectedBroadcasts(); + + /** + * Intents that this package may query or require and thus requires visibility into. + * @see R.styleable#AndroidManifestQueriesIntent + */ + @NonNull + List getQueriesIntents(); + + /** + * Other packages that this package may query or require and thus requires visibility into. + * @see R.styleable#AndroidManifestQueriesPackage + */ + @NonNull + List getQueriesPackages(); + + /** + * If a system app declares {@link #getOriginalPackages()}, and the app was previously installed + * under one of those original package names, the {@link #getPackageName()} system identifier + * will be changed to that previously installed name. This will then be non-null, set to the + * manifest package name, for tracking the package under its true name. + * + * TODO(b/135203078): Remove this in favor of checking originalPackages.isEmpty and + * getManifestPackageName + */ + @Nullable + String getRealPackage(); + + /** + * SHA-512 hash of the only APK that can be used to update a system package. + * @see R.styleable#AndroidManifestRestrictUpdate + */ + @Nullable + byte[] getRestrictUpdateHash(); + + /** + * The signature data of all APKs in this package, which must be exactly the same across the + * base and splits. + */ + PackageParser.SigningDetails getSigningDetails(); + + /** + * TODO(b/135203078): Move split stuff to an inner data class + * @see ApplicationInfo#splitNames + * @see PackageInfo#splitNames + */ + @Nullable + String[] getSplitNames(); + + /** Flags of any split APKs; ordered by parsed splitName */ + @Nullable + int[] getSplitFlags(); + + /** @see R.styleable#AndroidManifestStaticLibrary_name */ + @Nullable + String getStaticSharedLibName(); + + /** @see R.styleable#AndroidManifestStaticLibrary_version */ + long getStaticSharedLibVersion(); + + /** + * {@link android.os.storage.StorageManager#convert(String)} version of + * {@link #getVolumeUuid()}. + * TODO(b/135203078): All usages call toString() on this. Can the string be returned directly, + * or does the parsing logic in StorageManager have to run? + */ + UUID getStorageUuid(); + + /** + * For use with {@link com.android.server.pm.KeySetManagerService}. Parsed in + * {@link PackageParser#TAG_KEY_SETS}. + * @see R.styleable#AndroidManifestUpgradeKeySet + */ + @NonNull + Set getUpgradeKeySets(); + + /** @see R.styleable#AndroidManifestUsesLibrary */ + @NonNull + List getUsesLibraries(); + + /** + * Like {@link #getUsesLibraries()}, but marked optional by setting + * {@link R.styleable#AndroidManifestUsesLibrary_required} to false . Application is expected + * to handle absence manually. + * @see R.styleable#AndroidManifestUsesLibrary + */ + @NonNull + List getUsesOptionalLibraries(); + + /** + * TODO(b/135203078): Move static library stuff to an inner data class + * @see R.styleable#AndroidManifestUsesStaticLibrary + */ + @NonNull + List getUsesStaticLibraries(); + + /** @see R.styleable#AndroidManifestUsesStaticLibrary_certDigest */ + @Nullable + String[][] getUsesStaticLibrariesCertDigests(); + + /** @see R.styleable#AndroidManifestUsesStaticLibrary_version */ + @Nullable + long[] getUsesStaticLibrariesVersions(); + + /** @see R.styleable#AndroidManifestApplication_forceQueryable */ + boolean isForceQueryable(); + + boolean isCrossProfile(); + + /** + * The install time abi override to choose 32bit abi's when multiple abi's + * are present. This is only meaningfull for multiarch applications. + * The use32bitAbi attribute is ignored if cpuAbiOverride is also set. + */ + boolean isUse32BitAbi(); + + /** + * Set if the any of components are visible to instant applications. + * @see R.styleable#AndroidManifestActivity_visibleToInstantApps + * @see R.styleable#AndroidManifestProvider_visibleToInstantApps + * @see R.styleable#AndroidManifestService_visibleToInstantApps + */ + boolean isVisibleToInstantApps(); + + /** + * Generates an {@link ApplicationInfo} object with only the data available in this object. + * + * TODO(b/135203078): Actually add this + * This does not contain any system or user state data, and should be avoided. Prefer + * com.android.server.pm.parsing.PackageInfoUtils#generateApplicationInfo( + * AndroidPackage, int, PackageUserState, int, com.android.server.pm.PackageSetting) + * + * @deprecated Access AndroidPackage fields directly. + */ + @Deprecated + @NonNull + ApplicationInfo toAppInfoWithoutState(); + + /** + * TODO(b/135203078): Remove usages? + * @return a mock of what the previous package.applicationInfo would've returned for logging + * @deprecated don't use this in any new code, just print package name directly + */ + @Deprecated + @NonNull + String toAppInfoToString(); + + @Deprecated + boolean isUpdatedSystemApp(); + + @Deprecated + boolean isHiddenUntilInstalled(); + + @Deprecated + long[] getLastPackageUsageTimeInMills(); + + @Deprecated + long getLatestForegroundPackageUseTimeInMills(); + + @Deprecated + long getLatestPackageUseTimeInMills(); +} diff --git a/services/core/java/com/android/server/pm/parsing/pkg/AndroidPackageUtils.java b/services/core/java/com/android/server/pm/parsing/pkg/AndroidPackageUtils.java new file mode 100644 index 0000000000000..781286e643fff --- /dev/null +++ b/services/core/java/com/android/server/pm/parsing/pkg/AndroidPackageUtils.java @@ -0,0 +1,238 @@ +/* + * Copyright (C) 2020 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 com.android.server.pm.parsing.pkg; + +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager; +import android.content.pm.PackageParser; +import android.content.pm.PackageParser.PackageParserException; +import android.content.pm.SharedLibraryInfo; +import android.content.pm.VersionedPackage; +import android.content.pm.dex.DexMetadataHelper; +import android.content.pm.parsing.ComponentParseUtils.ParsedActivity; +import android.content.pm.parsing.ComponentParseUtils.ParsedInstrumentation; +import android.content.pm.parsing.ComponentParseUtils.ParsedProvider; +import android.content.pm.parsing.ComponentParseUtils.ParsedService; +import android.content.pm.parsing.ParsingPackageRead; + +import com.android.internal.content.NativeLibraryHelper; +import com.android.internal.util.ArrayUtils; +import com.android.server.SystemConfig; +import com.android.server.pm.PackageSetting; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +/** @hide */ +public class AndroidPackageUtils { + + private AndroidPackageUtils() { + } + + public static List getAllCodePathsExcludingResourceOnly( + AndroidPackage aPkg) { + PackageImpl pkg = (PackageImpl) aPkg; + ArrayList paths = new ArrayList<>(); + if (pkg.isHasCode()) { + paths.add(pkg.getBaseCodePath()); + } + String[] splitCodePaths = pkg.getSplitCodePaths(); + if (!ArrayUtils.isEmpty(splitCodePaths)) { + for (int i = 0; i < splitCodePaths.length; i++) { + if ((pkg.getSplitFlags()[i] & ApplicationInfo.FLAG_HAS_CODE) != 0) { + paths.add(splitCodePaths[i]); + } + } + } + return paths; + } + + /** + * @return a list of the base and split code paths. + */ + public static List getAllCodePaths(AndroidPackage aPkg) { + PackageImpl pkg = (PackageImpl) aPkg; + ArrayList paths = new ArrayList<>(); + paths.add(pkg.getBaseCodePath()); + + String[] splitCodePaths = pkg.getSplitCodePaths(); + if (!ArrayUtils.isEmpty(splitCodePaths)) { + Collections.addAll(paths, splitCodePaths); + } + return paths; + } + + public static SharedLibraryInfo createSharedLibraryForStatic(AndroidPackage pkg) { + return new SharedLibraryInfo(null, pkg.getPackageName(), + AndroidPackageUtils.getAllCodePaths(pkg), + pkg.getStaticSharedLibName(), + pkg.getStaticSharedLibVersion(), + SharedLibraryInfo.TYPE_STATIC, + new VersionedPackage(pkg.getManifestPackageName(), + pkg.getLongVersionCode()), + null, null); + } + + public static SharedLibraryInfo createSharedLibraryForDynamic(AndroidPackage pkg, String name) { + return new SharedLibraryInfo(null, pkg.getPackageName(), + AndroidPackageUtils.getAllCodePaths(pkg), name, + SharedLibraryInfo.VERSION_UNDEFINED, + SharedLibraryInfo.TYPE_DYNAMIC, new VersionedPackage(pkg.getPackageName(), + pkg.getLongVersionCode()), + null, null); + } + + /** + * Return the dex metadata files for the given package as a map + * [code path -> dex metadata path]. + * + * NOTE: involves I/O checks. + */ + public static Map getPackageDexMetadata(AndroidPackage pkg) { + return DexMetadataHelper.buildPackageApkToDexMetadataMap + (AndroidPackageUtils.getAllCodePaths(pkg)); + } + + /** + * Validate the dex metadata files installed for the given package. + * + * @throws PackageParserException in case of errors. + */ + public static void validatePackageDexMetadata(AndroidPackage pkg) + throws PackageParserException { + Collection apkToDexMetadataList = getPackageDexMetadata(pkg).values(); + for (String dexMetadata : apkToDexMetadataList) { + DexMetadataHelper.validateDexMetadataFile(dexMetadata); + } + } + + public static NativeLibraryHelper.Handle createNativeLibraryHandle(AndroidPackage pkg) + throws IOException { + return NativeLibraryHelper.Handle.create( + AndroidPackageUtils.getAllCodePaths(pkg), + pkg.isMultiArch(), + pkg.isExtractNativeLibs(), + pkg.isDebuggable() + ); + } + + public static boolean canHaveOatDir(AndroidPackage pkg, boolean isUpdatedSystemApp) { + // The following app types CANNOT have oat directory + // - non-updated system apps + return !pkg.isSystem() || isUpdatedSystemApp; + } + + public static boolean hasComponentClassName(AndroidPackage pkg, String className) { + List activities = pkg.getActivities(); + int activitiesSize = activities.size(); + for (int index = 0; index < activitiesSize; index++) { + if (Objects.equals(className, activities.get(index).getName())) { + return true; + } + } + + List receivers = pkg.getReceivers(); + int receiversSize = receivers.size(); + for (int index = 0; index < receiversSize; index++) { + if (Objects.equals(className, receivers.get(index).getName())) { + return true; + } + } + + List providers = pkg.getProviders(); + int providersSize = providers.size(); + for (int index = 0; index < providersSize; index++) { + if (Objects.equals(className, providers.get(index).getName())) { + return true; + } + } + + List services = pkg.getServices(); + int servicesSize = services.size(); + for (int index = 0; index < servicesSize; index++) { + if (Objects.equals(className, services.get(index).getName())) { + return true; + } + } + + List instrumentations = pkg.getInstrumentations(); + int instrumentationsSize = instrumentations.size(); + for (int index = 0; index < instrumentationsSize; index++) { + if (Objects.equals(className, instrumentations.get(index).getName())) { + return true; + } + } + + return false; + } + + public static boolean isEncryptionAware(AndroidPackage pkg) { + return pkg.isDirectBootAware() || pkg.isPartiallyDirectBootAware(); + } + + public static boolean isLibrary(AndroidPackage pkg) { + // TODO(b/135203078): Can parsing just enforce these always match? + return pkg.getStaticSharedLibName() != null || !pkg.getLibraryNames().isEmpty(); + } + + public static int getHiddenApiEnforcementPolicy(AndroidPackage pkg) { + boolean isAllowedToUseHiddenApis; + if (pkg.isSignedWithPlatformKey()) { + isAllowedToUseHiddenApis = true; + } else if (pkg.isSystem() || pkg.isUpdatedSystemApp()) { + isAllowedToUseHiddenApis = pkg.isUsesNonSdkApi() + || SystemConfig.getInstance().getHiddenApiWhitelistedApps().contains( + pkg.getPackageName()); + } else { + isAllowedToUseHiddenApis = false; + } + + if (isAllowedToUseHiddenApis) { + return ApplicationInfo.HIDDEN_API_ENFORCEMENT_DISABLED; + } + + // TODO(b/135203078): Handle maybeUpdateHiddenApiEnforcementPolicy. Right now it's done + // entirely through ApplicationInfo and shouldn't touch this specific class, but that + // may not always hold true. +// if (mHiddenApiPolicy != ApplicationInfo.HIDDEN_API_ENFORCEMENT_DEFAULT) { +// return mHiddenApiPolicy; +// } + return ApplicationInfo.HIDDEN_API_ENFORCEMENT_ENABLED; + } + + public static int getIcon(ParsingPackageRead pkg) { + return (PackageParser.sUseRoundIcon && pkg.getRoundIconRes() != 0) + ? pkg.getRoundIconRes() : pkg.getIconRes(); + } + + public static long getLongVersionCode(AndroidPackage pkg) { + return PackageInfo.composeLongVersionCode(pkg.getVersionCodeMajor(), pkg.getVersionCode()); + } + + public static boolean isMatchForSystemOnly(AndroidPackage pkg, int flags) { + if ((flags & PackageManager.MATCH_SYSTEM_ONLY) != 0) { + return pkg.isSystem(); + } + return true; + } +} diff --git a/core/java/android/content/pm/parsing/AndroidPackageWrite.java b/services/core/java/com/android/server/pm/parsing/pkg/AndroidPackageWrite.java similarity index 95% rename from core/java/android/content/pm/parsing/AndroidPackageWrite.java rename to services/core/java/com/android/server/pm/parsing/pkg/AndroidPackageWrite.java index b7595d2dd7101..08bd1e709542a 100644 --- a/core/java/android/content/pm/parsing/AndroidPackageWrite.java +++ b/services/core/java/com/android/server/pm/parsing/pkg/AndroidPackageWrite.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 The Android Open Source Project + * Copyright (C) 2020 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. @@ -14,7 +14,7 @@ * limitations under the License. */ -package android.content.pm.parsing; +package com.android.server.pm.parsing.pkg; import android.annotation.Nullable; import android.content.pm.PackageParser; diff --git a/services/core/java/com/android/server/pm/parsing/pkg/PackageImpl.java b/services/core/java/com/android/server/pm/parsing/pkg/PackageImpl.java new file mode 100644 index 0000000000000..837cb3eaabb08 --- /dev/null +++ b/services/core/java/com/android/server/pm/parsing/pkg/PackageImpl.java @@ -0,0 +1,968 @@ +/* + * Copyright (C) 2020 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 com.android.server.pm.parsing.pkg; + +import android.annotation.NonNull; +import android.annotation.Nullable; +import android.content.pm.ActivityInfo; +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager; +import android.content.pm.PackageParser; +import android.content.pm.SharedLibraryInfo; +import android.content.pm.parsing.ComponentParseUtils.ParsedActivity; +import android.content.pm.parsing.ComponentParseUtils.ParsedProvider; +import android.content.pm.parsing.ComponentParseUtils.ParsedService; +import android.content.pm.parsing.ParsingPackage; +import android.content.pm.parsing.ParsingPackageImpl; +import android.content.res.TypedArray; +import android.os.Environment; +import android.os.Parcel; +import android.os.UserHandle; +import android.os.storage.StorageManager; +import android.text.TextUtils; + +import com.android.internal.annotations.VisibleForTesting; +import com.android.internal.util.CollectionUtils; +import com.android.internal.util.DataClass; +import com.android.internal.util.Parcelling; +import com.android.internal.util.Parcelling.BuiltIn.ForInternedString; +import com.android.server.pm.parsing.PackageInfoUtils; + +import java.util.List; +import java.util.UUID; + +/** + * Extensions to {@link ParsingPackageImpl} including fields/state contained in the system server + * and not exposed to the core SDK. + * + * Many of the fields contained here will eventually be moved inside + * {@link com.android.server.pm.PackageSetting} or {@link android.content.pm.PackageUserState}. + * + * @hide + */ +public final class PackageImpl extends ParsingPackageImpl implements ParsedPackage, + AndroidPackageWrite, AndroidPackage { + + public static PackageImpl forParsing(@NonNull String packageName, @NonNull String baseCodePath, + @NonNull String codePath, @NonNull TypedArray manifestArray, boolean isCoreApp) { + return new PackageImpl(packageName, baseCodePath, codePath, manifestArray, isCoreApp); + } + + /** + * Mock an unavailable {@link AndroidPackage} to use when + * removing + * a package from the system. + * This can occur if the package was installed on a storage device that has since been removed. + * Since the infrastructure uses {@link AndroidPackage}, but + * for + * this case only cares about + * volumeUuid, just fake it rather than having separate method paths. + */ + public static AndroidPackage buildFakeForDeletion(String packageName, String volumeUuid) { + return ((ParsedPackage) PackageImpl.forTesting(packageName) + .setVolumeUuid(volumeUuid) + .hideAsParsed()) + .hideAsFinal(); + } + + @VisibleForTesting + public static ParsingPackage forTesting(String packageName) { + return forTesting(packageName, ""); + } + + @VisibleForTesting + public static ParsingPackage forTesting(String packageName, String baseCodePath) { + return new PackageImpl(packageName, baseCodePath, baseCodePath, null, false); + } + + @NonNull + private long[] lastPackageUsageTimeInMills = + new long[PackageManager.NOTIFY_PACKAGE_USE_REASONS_COUNT]; + + @NonNull + @DataClass.ParcelWith(ForInternedString.class) + private final String manifestPackageName; + + private boolean updatedSystemApp; + + @Nullable + @DataClass.ParcelWith(ForInternedString.class) + protected String cpuAbiOverride; + + private boolean stub; + + @Nullable + @DataClass.ParcelWith(ForInternedString.class) + protected String nativeLibraryDir; + + @Nullable + @DataClass.ParcelWith(ForInternedString.class) + protected String nativeLibraryRootDir; + + private boolean nativeLibraryRootRequiresIsa; + + @Nullable + @DataClass.ParcelWith(ForInternedString.class) + protected String primaryCpuAbi; + @Nullable + @DataClass.ParcelWith(ForInternedString.class) + protected String secondaryCpuAbi; + @Nullable + @DataClass.ParcelWith(ForInternedString.class) + protected String secondaryNativeLibraryDir; + + @Nullable + @DataClass.ParcelWith(ForInternedString.class) + protected String seInfo; + @Nullable + @DataClass.ParcelWith(ForInternedString.class) + protected String seInfoUser; + + private boolean coreApp; + + private boolean system; + private boolean factoryTest; + + private boolean systemExt; + private boolean privileged; + private boolean oem; + private boolean vendor; + private boolean product; + private boolean odm; + + private boolean signedWithPlatformKey; + + @Deprecated + private boolean hiddenUntilInstalled; + + @Deprecated + @Nullable + private String credentialProtectedDataDir; + @Deprecated + @Nullable + private String dataDir; + @Deprecated + @Nullable + private String deviceProtectedDataDir; + + /** + * This is an appId, the uid if the userId is == USER_SYSTEM + */ + private int uid = -1; + + @Deprecated + @Nullable + private String[] usesLibraryFiles; + @Deprecated + @Nullable + private List usesLibraryInfos; + + @VisibleForTesting + public PackageImpl(@NonNull String packageName, @NonNull String baseCodePath, + @NonNull String codePath, @Nullable TypedArray manifestArray, boolean isCoreApp) { + super(packageName, baseCodePath, codePath, manifestArray); + this.manifestPackageName = this.packageName; + this.coreApp = isCoreApp; + } + + @Override + public ParsedPackage hideAsParsed() { + return this; + } + + @Override + public AndroidPackage hideAsFinal() { + // TODO(b/135203078): Lock as immutable + return this; + } + + @Override + public int getFlags() { + return PackageInfoUtils.appInfoFlags(this, null); + } + + @Override + public int getPrivateFlags() { + return PackageInfoUtils.appInfoPrivateFlags(this, null); + } + + @Override + public AndroidPackageWrite mutate() { + return this; + } + + @Override + public long getLongVersionCode() { + return PackageInfo.composeLongVersionCode(versionCodeMajor, versionCode); + } + + @Override + public PackageImpl removePermission(int index) { + this.permissions.remove(index); + return this; + } + + @Override + public PackageImpl addUsesOptionalLibrary(int index, String libraryName) { + this.usesOptionalLibraries = CollectionUtils.add(usesOptionalLibraries, index, + TextUtils.safeIntern(libraryName)); + return this; + } + + @Override + public PackageImpl addUsesLibrary(int index, String libraryName) { + this.usesLibraries = CollectionUtils.add(usesLibraries, index, + TextUtils.safeIntern(libraryName)); + return this; + } + + @Override + public PackageImpl removeUsesLibrary(String libraryName) { + this.usesLibraries = CollectionUtils.remove(this.usesLibraries, libraryName); + return this; + } + + @Override + public PackageImpl removeUsesOptionalLibrary(String libraryName) { + super.removeUsesOptionalLibrary(libraryName); + return this; + } + + @Override + public PackageImpl setSigningDetails(@Nullable PackageParser.SigningDetails value) { + super.setSigningDetails(value); + return this; + } + + @Override + public PackageImpl setRestrictUpdateHash(@Nullable byte... value) { + super.setRestrictUpdateHash(value); + return this; + } + + @Override + public PackageImpl setRealPackage(@Nullable String realPackage) { + super.setRealPackage(realPackage); + return this; + } + + @Override + public PackageImpl setPersistent(boolean value) { + super.setPersistent(value); + return this; + } + + @Override + public PackageImpl setDefaultToDeviceProtectedStorage(boolean value) { + super.setDefaultToDeviceProtectedStorage(value); + return this; + } + + @Override + public PackageImpl setDirectBootAware(boolean value) { + super.setDirectBootAware(value); + return this; + } + + @Override + public PackageImpl clearProtectedBroadcasts() { + protectedBroadcasts.clear(); + return this; + } + + @Override + public PackageImpl clearOriginalPackages() { + originalPackages.clear(); + return this; + } + + @Override + public PackageImpl clearAdoptPermissions() { + adoptPermissions.clear(); + return this; + } + + @Override + public PackageImpl setCodePath(@NonNull String value) { + this.codePath = value; + return this; + } + + // TODO(b/135203078): Move PackageManagerService#renameStaticSharedLibraryPackage + // into initial package parsing + @Override + public PackageImpl setPackageName(@NonNull String packageName) { + this.packageName = TextUtils.safeIntern(packageName); + + int permissionsSize = permissions.size(); + for (int index = 0; index < permissionsSize; index++) { + permissions.get(index).setPackageName(this.packageName); + } + + int permissionGroupsSize = permissionGroups.size(); + for (int index = 0; index < permissionGroupsSize; index++) { + permissionGroups.get(index).setPackageName(this.packageName); + } + + int activitiesSize = activities.size(); + for (int index = 0; index < activitiesSize; index++) { + activities.get(index).setPackageName(this.packageName); + } + + int receiversSize = receivers.size(); + for (int index = 0; index < receiversSize; index++) { + receivers.get(index).setPackageName(this.packageName); + } + + int providersSize = providers.size(); + for (int index = 0; index < providersSize; index++) { + providers.get(index).setPackageName(this.packageName); + } + + int servicesSize = services.size(); + for (int index = 0; index < servicesSize; index++) { + services.get(index).setPackageName(this.packageName); + } + + int instrumentationsSize = instrumentations.size(); + for (int index = 0; index < instrumentationsSize; index++) { + instrumentations.get(index).setPackageName(this.packageName); + } + + return this; + } + + @Override + public PackageImpl setAllComponentsDirectBootAware(boolean allComponentsDirectBootAware) { + int activitiesSize = activities.size(); + for (int index = 0; index < activitiesSize; index++) { + activities.get(index).directBootAware = allComponentsDirectBootAware; + } + + int receiversSize = receivers.size(); + for (int index = 0; index < receiversSize; index++) { + receivers.get(index).directBootAware = allComponentsDirectBootAware; + } + + int providersSize = providers.size(); + for (int index = 0; index < providersSize; index++) { + providers.get(index).directBootAware = allComponentsDirectBootAware; + } + + int servicesSize = services.size(); + for (int index = 0; index < servicesSize; index++) { + services.get(index).directBootAware = allComponentsDirectBootAware; + } + + return this; + } + + @Override + public PackageImpl setBaseCodePath(@NonNull String baseCodePath) { + this.baseCodePath = TextUtils.safeIntern(baseCodePath); + return this; + } + + @Override + public PackageImpl setCpuAbiOverride(@Nullable String cpuAbiOverride) { + this.cpuAbiOverride = TextUtils.safeIntern(cpuAbiOverride); + return this; + } + + @Override + public PackageImpl setNativeLibraryDir(@Nullable String nativeLibraryDir) { + this.nativeLibraryDir = TextUtils.safeIntern(nativeLibraryDir); + return this; + } + + @Override + public PackageImpl setNativeLibraryRootDir(@Nullable String nativeLibraryRootDir) { + this.nativeLibraryRootDir = TextUtils.safeIntern(nativeLibraryRootDir); + return this; + } + + @Override + public PackageImpl setPrimaryCpuAbi(@Nullable String primaryCpuAbi) { + this.primaryCpuAbi = TextUtils.safeIntern(primaryCpuAbi); + return this; + } + + @Override + public PackageImpl setSecondaryCpuAbi(@Nullable String secondaryCpuAbi) { + this.secondaryCpuAbi = TextUtils.safeIntern(secondaryCpuAbi); + return this; + } + + @Override + public PackageImpl setSecondaryNativeLibraryDir(@Nullable String secondaryNativeLibraryDir) { + this.secondaryNativeLibraryDir = TextUtils.safeIntern(secondaryNativeLibraryDir); + return this; + } + + @Override + public PackageImpl setSeInfo(@Nullable String seInfo) { + this.seInfo = TextUtils.safeIntern(seInfo); + return this; + } + + @Override + public PackageImpl setSeInfoUser(@Nullable String seInfoUser) { + this.seInfoUser = TextUtils.safeIntern(seInfoUser); + return this; + } + + @Override + public PackageImpl setSplitCodePaths(@Nullable String[] splitCodePaths) { + this.splitCodePaths = splitCodePaths; + if (splitCodePaths != null) { + int size = splitCodePaths.length; + for (int index = 0; index < size; index++) { + this.splitCodePaths[index] = TextUtils.safeIntern(this.splitCodePaths[index]); + } + } + return this; + } + + @Override + public PackageImpl capPermissionPriorities() { + int size = permissionGroups.size(); + for (int index = size - 1; index >= 0; --index) { + // TODO(b/135203078): Builder/immutability + permissionGroups.get(index).priority = 0; + } + return this; + } + + @Override + public PackageImpl markNotActivitiesAsNotExportedIfSingleUser() { + // ignore export request for single user receivers + int receiversSize = receivers.size(); + for (int index = 0; index < receiversSize; index++) { + ParsedActivity receiver = receivers.get(index); + if ((receiver.flags & ActivityInfo.FLAG_SINGLE_USER) != 0) { + receiver.exported = false; + } + } + + // ignore export request for single user services + int servicesSize = services.size(); + for (int index = 0; index < servicesSize; index++) { + ParsedService service = services.get(index); + if ((service.flags & ActivityInfo.FLAG_SINGLE_USER) != 0) { + service.exported = false; + } + } + + // ignore export request for single user providers + int providersSize = providers.size(); + for (int index = 0; index < providersSize; index++) { + ParsedProvider provider = providers.get(index); + if ((provider.getFlags() & ActivityInfo.FLAG_SINGLE_USER) != 0) { + provider.setExported(false); + } + } + + return this; + } + + @Override + public UUID getStorageUuid() { + return StorageManager.convert(volumeUuid); + } + + @Deprecated + @Override + public String toAppInfoToString() { + return "ApplicationInfo{" + + Integer.toHexString(System.identityHashCode(this)) + + " " + getPackageName() + "}"; + } + + @Override + public PackageImpl initForUser(int userId) { + // TODO(b/135203078): Move this user state to some other data structure + this.uid = UserHandle.getUid(userId, UserHandle.getAppId(this.uid)); + + if ("android".equals(packageName)) { + dataDir = Environment.getDataSystemDirectory().getAbsolutePath(); + return this; + } + + deviceProtectedDataDir = Environment + .getDataUserDePackageDirectory(volumeUuid, userId, packageName) + .getAbsolutePath(); + credentialProtectedDataDir = Environment + .getDataUserCePackageDirectory(volumeUuid, userId, packageName) + .getAbsolutePath(); + + if (isDefaultToDeviceProtectedStorage() + && PackageManager.APPLY_DEFAULT_TO_DEVICE_PROTECTED_STORAGE) { + dataDir = deviceProtectedDataDir; + } else { + dataDir = credentialProtectedDataDir; + } + return this; + } + + @Override + public PackageImpl setLastPackageUsageTimeInMills(int reason, long time) { + lastPackageUsageTimeInMills[reason] = time; + return this; + } + + @Override + public long getLatestPackageUseTimeInMills() { + long latestUse = 0L; + for (long use : lastPackageUsageTimeInMills) { + latestUse = Math.max(latestUse, use); + } + return latestUse; + } + + @Override + public long getLatestForegroundPackageUseTimeInMills() { + int[] foregroundReasons = { + PackageManager.NOTIFY_PACKAGE_USE_ACTIVITY, + PackageManager.NOTIFY_PACKAGE_USE_FOREGROUND_SERVICE + }; + + long latestUse = 0L; + for (int reason : foregroundReasons) { + latestUse = Math.max(latestUse, lastPackageUsageTimeInMills[reason]); + } + return latestUse; + } + + @Override + public long[] getLastPackageUsageTimeInMills() { + return lastPackageUsageTimeInMills; + } + + @Override + public PackageImpl setUsesLibraryInfos( + @Nullable List usesLibraryInfos) { + this.usesLibraryInfos = usesLibraryInfos; + return this; + } + + @Override + public PackageImpl setUsesLibraryFiles(@Nullable String[] usesLibraryFiles) { + this.usesLibraryFiles = usesLibraryFiles; + return this; + } + + @Override + public ParsedPackage setCoreApp(boolean coreApp) { + this.coreApp = coreApp; + return this; + } + + @Override + public ParsedPackage setVersionCode(int versionCode) { + this.versionCode = versionCode; + return this; + } + + @Override + public ParsedPackage setVersionCodeMajor(int versionCodeMajor) { + this.versionCodeMajor = versionCodeMajor; + return this; + } + + @Override + public ApplicationInfo toAppInfoWithoutState() { + ApplicationInfo appInfo = super.toAppInfoWithoutState(); + appInfo.flags = PackageInfoUtils.appInfoFlags(this, null); + appInfo.privateFlags = PackageInfoUtils.appInfoPrivateFlags(this, null); + appInfo.hiddenUntilInstalled = hiddenUntilInstalled; + appInfo.nativeLibraryDir = nativeLibraryDir; + appInfo.nativeLibraryRootDir = nativeLibraryRootDir; + appInfo.nativeLibraryRootRequiresIsa = nativeLibraryRootRequiresIsa; + appInfo.primaryCpuAbi = primaryCpuAbi; + appInfo.secondaryCpuAbi = secondaryCpuAbi; + appInfo.secondaryNativeLibraryDir = secondaryNativeLibraryDir; + appInfo.seInfo = seInfo; + appInfo.seInfoUser = seInfoUser; + appInfo.uid = uid; + appInfo.sharedLibraryFiles = usesLibraryFiles; + appInfo.sharedLibraryInfos = usesLibraryInfos; + appInfo.credentialProtectedDataDir = credentialProtectedDataDir; + appInfo.dataDir = dataDir; + appInfo.deviceProtectedDataDir = deviceProtectedDataDir; + return appInfo; + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + super.writeToParcel(dest, flags); + dest.writeBoolean(this.updatedSystemApp); + sForString.parcel(this.manifestPackageName, dest, flags); + sForString.parcel(this.cpuAbiOverride, dest, flags); + dest.writeBoolean(this.stub); + sForString.parcel(this.nativeLibraryDir, dest, flags); + sForString.parcel(this.nativeLibraryRootDir, dest, flags); + dest.writeBoolean(this.nativeLibraryRootRequiresIsa); + sForString.parcel(this.primaryCpuAbi, dest, flags); + sForString.parcel(this.secondaryCpuAbi, dest, flags); + sForString.parcel(this.secondaryNativeLibraryDir, dest, flags); + sForString.parcel(this.seInfo, dest, flags); + sForString.parcel(this.seInfoUser, dest, flags); + dest.writeInt(this.uid); + dest.writeBoolean(this.coreApp); + dest.writeBoolean(this.system); + dest.writeBoolean(this.factoryTest); + dest.writeBoolean(this.systemExt); + dest.writeBoolean(this.privileged); + dest.writeBoolean(this.oem); + dest.writeBoolean(this.vendor); + dest.writeBoolean(this.product); + dest.writeBoolean(this.odm); + dest.writeBoolean(this.signedWithPlatformKey); + dest.writeBoolean(this.hiddenUntilInstalled); + dest.writeString(this.credentialProtectedDataDir); + dest.writeString(this.dataDir); + dest.writeString(this.deviceProtectedDataDir); + dest.writeLongArray(this.lastPackageUsageTimeInMills); + dest.writeStringArray(this.usesLibraryFiles); + dest.writeTypedList(this.usesLibraryInfos); + } + + public PackageImpl(Parcel in) { + super(in); + this.updatedSystemApp = in.readBoolean(); + this.manifestPackageName = sForString.unparcel(in); + this.cpuAbiOverride = sForString.unparcel(in); + this.stub = in.readBoolean(); + this.nativeLibraryDir = sForString.unparcel(in); + this.nativeLibraryRootDir = sForString.unparcel(in); + this.nativeLibraryRootRequiresIsa = in.readBoolean(); + this.primaryCpuAbi = sForString.unparcel(in); + this.secondaryCpuAbi = sForString.unparcel(in); + this.secondaryNativeLibraryDir = sForString.unparcel(in); + this.seInfo = sForString.unparcel(in); + this.seInfoUser = sForString.unparcel(in); + this.uid = in.readInt(); + this.coreApp = in.readBoolean(); + this.system = in.readBoolean(); + this.factoryTest = in.readBoolean(); + this.systemExt = in.readBoolean(); + this.privileged = in.readBoolean(); + this.oem = in.readBoolean(); + this.vendor = in.readBoolean(); + this.product = in.readBoolean(); + this.odm = in.readBoolean(); + this.signedWithPlatformKey = in.readBoolean(); + this.hiddenUntilInstalled = in.readBoolean(); + this.credentialProtectedDataDir = in.readString(); + this.dataDir = in.readString(); + this.deviceProtectedDataDir = in.readString(); + this.lastPackageUsageTimeInMills = in.createLongArray(); + this.usesLibraryFiles = in.createStringArray(); + this.usesLibraryInfos = in.createTypedArrayList(SharedLibraryInfo.CREATOR); + } + + public static final Creator CREATOR = new Creator() { + @Override + public PackageImpl createFromParcel(Parcel source) { + return new PackageImpl(source); + } + + @Override + public PackageImpl[] newArray(int size) { + return new PackageImpl[size]; + } + }; + + @NonNull + @Override + public String getManifestPackageName() { + return manifestPackageName; + } + + @Override + public boolean isUpdatedSystemApp() { + return updatedSystemApp; + } + + @Nullable + @Override + public String getCpuAbiOverride() { + return cpuAbiOverride; + } + + @DataClass.Generated.Member + public boolean isStub() { + return stub; + } + + @Nullable + @Override + public String getNativeLibraryDir() { + return nativeLibraryDir; + } + + @Nullable + @Override + public String getNativeLibraryRootDir() { + return nativeLibraryRootDir; + } + + @Override + public boolean isNativeLibraryRootRequiresIsa() { + return nativeLibraryRootRequiresIsa; + } + + @Nullable + @Override + public String getPrimaryCpuAbi() { + return primaryCpuAbi; + } + + @Nullable + @Override + public String getSecondaryCpuAbi() { + return secondaryCpuAbi; + } + + @Nullable + @Override + public String getSecondaryNativeLibraryDir() { + return secondaryNativeLibraryDir; + } + + @Nullable + @Override + public String getSeInfo() { + return seInfo; + } + + @Nullable + @Override + public String getSeInfoUser() { + return seInfoUser; + } + + @Override + public boolean isCoreApp() { + return coreApp; + } + + @Override + public boolean isSystem() { + return system; + } + + @Override + public boolean isFactoryTest() { + return factoryTest; + } + + @Override + public boolean isSystemExt() { + return systemExt; + } + + @Override + public boolean isPrivileged() { + return privileged; + } + + @Override + public boolean isOem() { + return oem; + } + + @Override + public boolean isVendor() { + return vendor; + } + + @Override + public boolean isProduct() { + return product; + } + + @Override + public boolean isOdm() { + return odm; + } + + @Override + public boolean isSignedWithPlatformKey() { + return signedWithPlatformKey; + } + + @Deprecated + @Override + public boolean isHiddenUntilInstalled() { + return hiddenUntilInstalled; + } + + @Deprecated + @Nullable + @Override + public String getCredentialProtectedDataDir() { + return credentialProtectedDataDir; + } + + @Deprecated + @Nullable + @Override + public String getDataDir() { + return dataDir; + } + + @Deprecated + @Nullable + @Override + public String getDeviceProtectedDataDir() { + return deviceProtectedDataDir; + } + + /** + * This is an appId, the uid if the userId is == USER_SYSTEM + */ + @Override + public int getUid() { + return uid; + } + + @Deprecated + @Nullable + @Override + public String[] getUsesLibraryFiles() { + return usesLibraryFiles; + } + + @Deprecated + @Nullable + @Override + public List getUsesLibraryInfos() { + return usesLibraryInfos; + } + + @Override + public PackageImpl setUpdatedSystemApp(boolean value) { + updatedSystemApp = value; + return this; + } + + @DataClass.Generated.Member + public PackageImpl setStub(boolean value) { + stub = value; + return this; + } + + @Override + public PackageImpl setNativeLibraryRootRequiresIsa(boolean value) { + nativeLibraryRootRequiresIsa = value; + return this; + } + + @Override + public PackageImpl setSystem(boolean value) { + system = value; + return this; + } + + @Override + public PackageImpl setFactoryTest(boolean value) { + factoryTest = value; + return this; + } + + @Override + public PackageImpl setSystemExt(boolean value) { + systemExt = value; + return this; + } + + @Override + public PackageImpl setPrivileged(boolean value) { + privileged = value; + return this; + } + + @Override + public PackageImpl setOem(boolean value) { + oem = value; + return this; + } + + @Override + public PackageImpl setVendor(boolean value) { + vendor = value; + return this; + } + + @Override + public PackageImpl setProduct(boolean value) { + product = value; + return this; + } + + @Override + public PackageImpl setOdm(boolean value) { + odm = value; + return this; + } + + @Override + public PackageImpl setSignedWithPlatformKey(boolean value) { + signedWithPlatformKey = value; + return this; + } + + @DataClass.Generated.Member + public PackageImpl setHiddenUntilInstalled(@Deprecated boolean value) { + hiddenUntilInstalled = value; + return this; + } + + @DataClass.Generated.Member + public PackageImpl setCredentialProtectedDataDir(@Deprecated @Nullable String value) { + credentialProtectedDataDir = value; + return this; + } + + @DataClass.Generated.Member + public PackageImpl setDataDir(@Deprecated @Nullable String value) { + dataDir = value; + return this; + } + + @DataClass.Generated.Member + public PackageImpl setDeviceProtectedDataDir(@Deprecated @Nullable String value) { + deviceProtectedDataDir = value; + return this; + } + + /** + * This is an appId, the uid if the userId is == USER_SYSTEM + */ + @Override + public PackageImpl setUid(int value) { + uid = value; + return this; + } +} diff --git a/core/java/android/content/pm/parsing/ParsedPackage.java b/services/core/java/com/android/server/pm/parsing/pkg/ParsedPackage.java similarity index 75% rename from core/java/android/content/pm/parsing/ParsedPackage.java rename to services/core/java/com/android/server/pm/parsing/pkg/ParsedPackage.java index 05cf586522f2f..4d49b98289489 100644 --- a/core/java/android/content/pm/parsing/ParsedPackage.java +++ b/services/core/java/com/android/server/pm/parsing/pkg/ParsedPackage.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 The Android Open Source Project + * Copyright (C) 2020 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. @@ -14,8 +14,9 @@ * limitations under the License. */ -package android.content.pm.parsing; +package com.android.server.pm.parsing.pkg; +import android.annotation.Nullable; import android.content.pm.PackageParser; /** @@ -42,20 +43,6 @@ public interface ParsedPackage extends AndroidPackage { ParsedPackage clearProtectedBroadcasts(); - /** - * TODO(b/135203078): Use non-AppInfo method - * @deprecated use {@link #setCodePath(String)} - */ - @Deprecated - ParsedPackage setApplicationInfoCodePath(String applicationInfoCodePath); - - /** - * TODO(b/135203078): Use non-AppInfo method - * @deprecated use {@link #setCodePath(String)} - */ - @Deprecated - ParsedPackage setApplicationInfoResourcePath(String applicationInfoResourcePath); - ParsedPackage setBaseCodePath(String baseCodePath); ParsedPackage setCodePath(String codePath); @@ -70,9 +57,7 @@ public interface ParsedPackage extends AndroidPackage { ParsedPackage setPrimaryCpuAbi(String primaryCpuAbi); - ParsedPackage setProcessName(String processName); - - ParsedPackage setRealPackage(String realPackage); + ParsedPackage setRealPackage(@Nullable String realPackage); ParsedPackage setSecondaryCpuAbi(String secondaryCpuAbi); @@ -80,6 +65,7 @@ public interface ParsedPackage extends AndroidPackage { ParsedPackage setSplitCodePaths(String[] splitCodePaths); + @Deprecated ParsedPackage initForUser(int userId); ParsedPackage setNativeLibraryRootRequiresIsa(boolean nativeLibraryRootRequiresIsa); @@ -104,8 +90,6 @@ public interface ParsedPackage extends AndroidPackage { ParsedPackage setSystemExt(boolean systemExt); - ParsedPackage setUpdatedSystemApp(boolean updatedSystemApp); - ParsedPackage setVendor(boolean vendor); ParsedPackage removePermission(int index); @@ -114,19 +98,9 @@ public interface ParsedPackage extends AndroidPackage { ParsedPackage removeUsesOptionalLibrary(String libraryName); - ParsedPackage setApplicationInfoBaseResourcePath(String applicationInfoBaseResourcePath); - - ParsedPackage setApplicationInfoSplitResourcePaths( - String[] applicationInfoSplitResourcePaths); - - ParsedPackage setApplicationVolumeUuid(String applicationVolumeUuid); - ParsedPackage setCoreApp(boolean coreApp); - ParsedPackage setIsStub(boolean isStub); - - // TODO(b/135203078): Remove entirely - ParsedPackage setPackageSettingCallback(PackageSettingCallback packageSettingCallback); + ParsedPackage setStub(boolean isStub); ParsedPackage setRestrictUpdateHash(byte[] restrictUpdateHash); @@ -149,7 +123,6 @@ public interface ParsedPackage extends AndroidPackage { ParsedPackage setPersistent(boolean persistent); - interface PackageSettingCallback { - default void setAndroidPackage(AndroidPackage pkg){} - } + @Deprecated + ParsedPackage setUpdatedSystemApp(boolean updatedSystemApp); } diff --git a/services/core/java/com/android/server/pm/parsing/pkg/PkgAppInfo.java b/services/core/java/com/android/server/pm/parsing/pkg/PkgAppInfo.java new file mode 100644 index 0000000000000..0cb425f9243bd --- /dev/null +++ b/services/core/java/com/android/server/pm/parsing/pkg/PkgAppInfo.java @@ -0,0 +1,493 @@ +/* + * Copyright (C) 2020 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 com.android.server.pm.parsing.pkg; + +import android.annotation.NonNull; +import android.annotation.Nullable; +import android.content.pm.ApplicationInfo; +import android.util.SparseArray; + +import com.android.internal.R; + +/** + * Container for fields that are eventually exposed through {@link ApplicationInfo}. + * + * Done to separate the meaningless, re-directed JavaDoc for methods and to separate what's + * exposed vs not exposed to core. + * + * @hide + */ +interface PkgAppInfo { + + /** @see ApplicationInfo#PRIVATE_FLAG_CANT_SAVE_STATE */ + boolean isCantSaveState(); + + /** + * @see ApplicationInfo#appComponentFactory + * @see R.styleable#AndroidManifestApplication_appComponentFactory + */ + @Nullable + String getAppComponentFactory(); + + /** + * @see ApplicationInfo#backupAgentName + * @see R.styleable#AndroidManifestApplication_backupAgent + */ + @Nullable + String getBackupAgentName(); + + /** + * @see ApplicationInfo#banner + * @see R.styleable#AndroidManifestApplication_banner + */ + int getBanner(); + + /** + * @see ApplicationInfo#category + * @see R.styleable#AndroidManifestApplication_appCategory + */ + int getCategory(); + + /** + * @see ApplicationInfo#classLoaderName + * @see R.styleable#AndroidManifestApplication_classLoader + */ + @Nullable + String getClassLoaderName(); + + /** + * @see ApplicationInfo#className + * @see R.styleable#AndroidManifestApplication_name + */ + @Nullable + String getClassName(); + + /** + * @see ApplicationInfo#compatibleWidthLimitDp + * @see R.styleable#AndroidManifestSupportsScreens_compatibleWidthLimitDp + */ + int getCompatibleWidthLimitDp(); + + /** + * @see ApplicationInfo#compileSdkVersion + * @see R.styleable#AndroidManifest_compileSdkVersion + */ + int getCompileSdkVersion(); + + /** + * @see ApplicationInfo#compileSdkVersionCodename + * @see R.styleable#AndroidManifest_compileSdkVersionCodename + */ + @Nullable + String getCompileSdkVersionCodeName(); + + /** + * @see ApplicationInfo#descriptionRes + * @see R.styleable#AndroidManifestApplication_description + */ + int getDescriptionRes(); + + /** + * @see ApplicationInfo#fullBackupContent + * @see R.styleable#AndroidManifestApplication_fullBackupContent + */ + int getFullBackupContent(); + + /** + * @see ApplicationInfo#iconRes + * @see R.styleable#AndroidManifestApplication_icon + */ + int getIconRes(); + + /** + * @see ApplicationInfo#labelRes + * @see R.styleable#AndroidManifestApplication_label + */ + int getLabelRes(); + + /** + * @see ApplicationInfo#largestWidthLimitDp + * @see R.styleable#AndroidManifestSupportsScreens_largestWidthLimitDp + */ + int getLargestWidthLimitDp(); + + /** + * @see ApplicationInfo#logo + * @see R.styleable#AndroidManifestApplication_logo + */ + int getLogo(); + + /** + * @see ApplicationInfo#manageSpaceActivityName + * @see R.styleable#AndroidManifestApplication_manageSpaceActivity + */ + @Nullable + String getManageSpaceActivityName(); + + /** + * @see ApplicationInfo#maxAspectRatio + * @see R.styleable#AndroidManifestApplication_maxAspectRatio + */ + float getMaxAspectRatio(); + + /** + * @see ApplicationInfo#minAspectRatio + * @see R.styleable#AndroidManifestApplication_minAspectRatio + */ + float getMinAspectRatio(); + + /** + * @see ApplicationInfo#minSdkVersion + * @see R.styleable#AndroidManifestUsesSdk_minSdkVersion + */ + int getMinSdkVersion(); + + /** @see ApplicationInfo#nativeLibraryDir */ + @Nullable + String getNativeLibraryDir(); + + /** @see ApplicationInfo#nativeLibraryRootDir */ + @Nullable + String getNativeLibraryRootDir(); + + /** + * @see ApplicationInfo#networkSecurityConfigRes + * @see R.styleable#AndroidManifestApplication_networkSecurityConfig + */ + int getNetworkSecurityConfigRes(); + + /** + * If {@link R.styleable#AndroidManifestApplication_label} is a string literal, this is it. + * Otherwise, it's stored as {@link #getLabelRes()}. + * @see ApplicationInfo#nonLocalizedLabel + * @see R.styleable#AndroidManifestApplication_label + */ + @Nullable + CharSequence getNonLocalizedLabel(); + + /** + * @see ApplicationInfo#permission + * @see R.styleable#AndroidManifestApplication_permission + */ + @Nullable + String getPermission(); + + /** + * TODO(b/135203078): Hide this in the utility, should never be accessed directly + * @see ApplicationInfo#primaryCpuAbi + */ + @Nullable + String getPrimaryCpuAbi(); + + /** + * @see ApplicationInfo#processName + * @see R.styleable#AndroidManifestApplication_process + */ + @NonNull + String getProcessName(); + + /** + * @see ApplicationInfo#requiresSmallestWidthDp + * @see R.styleable#AndroidManifestSupportsScreens_requiresSmallestWidthDp + */ + int getRequiresSmallestWidthDp(); + + /** + * @see ApplicationInfo#roundIconRes + * @see R.styleable#AndroidManifestApplication_roundIcon + */ + int getRoundIconRes(); + + /** @see ApplicationInfo#seInfo */ + @Nullable + String getSeInfo(); + + /** @see ApplicationInfo#seInfoUser */ + @Nullable + String getSeInfoUser(); + + /** @see ApplicationInfo#secondaryCpuAbi */ + @Nullable + String getSecondaryCpuAbi(); + + /** @see ApplicationInfo#secondaryNativeLibraryDir */ + @Nullable + String getSecondaryNativeLibraryDir(); + + /** + * @see ApplicationInfo#installLocation + * @see R.styleable#AndroidManifest_installLocation + */ + int getInstallLocation(); + + /** + * @see ApplicationInfo#splitClassLoaderNames + * @see R.styleable#AndroidManifestApplication_classLoader + */ + @Nullable + String[] getSplitClassLoaderNames(); + + /** @see ApplicationInfo#splitSourceDirs */ + @Nullable + String[] getSplitCodePaths(); + + /** @see ApplicationInfo#splitDependencies */ + @Nullable + SparseArray getSplitDependencies(); + + /** + * @see ApplicationInfo#targetSandboxVersion + * @see R.styleable#AndroidManifest_targetSandboxVersion + */ + @Deprecated + int getTargetSandboxVersion(); + + /** + * @see ApplicationInfo#targetSdkVersion + * @see R.styleable#AndroidManifestUsesSdk_targetSdkVersion + */ + int getTargetSdkVersion(); + + /** + * @see ApplicationInfo#taskAffinity + * @see R.styleable#AndroidManifestApplication_taskAffinity + */ + @Nullable + String getTaskAffinity(); + + /** + * @see ApplicationInfo#theme + * @see R.styleable#AndroidManifestApplication_theme + */ + int getTheme(); + + /** + * @see ApplicationInfo#uiOptions + * @see R.styleable#AndroidManifestApplication_uiOptions + */ + int getUiOptions(); + + /** @see ApplicationInfo#uid */ + int getUid(); + + /** @see ApplicationInfo#longVersionCode */ + long getLongVersionCode(); + + /** @see ApplicationInfo#versionCode */ + @Deprecated + int getVersionCode(); + + /** @see ApplicationInfo#volumeUuid */ + @Nullable + String getVolumeUuid(); + + /** @see ApplicationInfo#zygotePreloadName */ + @Nullable + String getZygotePreloadName(); + + /** @see ApplicationInfo#FLAG_HAS_CODE */ + boolean isHasCode(); + + /** @see ApplicationInfo#FLAG_ALLOW_TASK_REPARENTING */ + boolean isAllowTaskReparenting(); + + /** @see ApplicationInfo#FLAG_MULTIARCH */ + boolean isMultiArch(); + + /** @see ApplicationInfo#FLAG_EXTRACT_NATIVE_LIBS */ + boolean isExtractNativeLibs(); + + /** @see ApplicationInfo#FLAG_DEBUGGABLE */ + boolean isDebuggable(); + + /** @see ApplicationInfo#FLAG_VM_SAFE_MODE */ + boolean isVmSafeMode(); + + /** @see ApplicationInfo#FLAG_PERSISTENT */ + boolean isPersistent(); + + /** @see ApplicationInfo#FLAG_ALLOW_BACKUP */ + boolean isAllowBackup(); + + /** @see ApplicationInfo#FLAG_TEST_ONLY */ + boolean isTestOnly(); + + /** @see ApplicationInfo#PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION */ + boolean isResizeableActivityViaSdkVersion(); + + /** @see ApplicationInfo#PRIVATE_FLAG_HAS_DOMAIN_URLS */ + boolean isHasDomainUrls(); + + /** @see ApplicationInfo#PRIVATE_FLAG_REQUEST_LEGACY_EXTERNAL_STORAGE */ + boolean isRequestLegacyExternalStorage(); + + /** @see ApplicationInfo#FLAG_HARDWARE_ACCELERATED */ + boolean isBaseHardwareAccelerated(); + + /** @see ApplicationInfo#PRIVATE_FLAG_DEFAULT_TO_DEVICE_PROTECTED_STORAGE */ + boolean isDefaultToDeviceProtectedStorage(); + + /** @see ApplicationInfo#PRIVATE_FLAG_DIRECT_BOOT_AWARE */ + boolean isDirectBootAware(); + + /** @see ApplicationInfo#PRIVATE_FLAG_PARTIALLY_DIRECT_BOOT_AWARE */ + boolean isPartiallyDirectBootAware(); + + /** @see ApplicationInfo#PRIVATE_FLAG_USE_EMBEDDED_DEX */ + boolean isUseEmbeddedDex(); + + /** @see ApplicationInfo#FLAG_EXTERNAL_STORAGE */ + boolean isExternalStorage(); + + /** @see ApplicationInfo#nativeLibraryRootRequiresIsa */ + boolean isNativeLibraryRootRequiresIsa(); + + /** @see ApplicationInfo#PRIVATE_FLAG_ODM */ + boolean isOdm(); + + /** @see ApplicationInfo#PRIVATE_FLAG_OEM */ + boolean isOem(); + + /** @see ApplicationInfo#PRIVATE_FLAG_PRIVILEGED */ + boolean isPrivileged(); + + /** @see ApplicationInfo#PRIVATE_FLAG_PRODUCT */ + boolean isProduct(); + + /** @see ApplicationInfo#PRIVATE_FLAG_PROFILEABLE_BY_SHELL */ + boolean isProfileableByShell(); + + /** @see ApplicationInfo#PRIVATE_FLAG_STATIC_SHARED_LIBRARY */ + boolean isStaticSharedLibrary(); + + /** @see ApplicationInfo#FLAG_SYSTEM */ + boolean isSystem(); + + /** @see ApplicationInfo#PRIVATE_FLAG_SYSTEM_EXT */ + boolean isSystemExt(); + + /** @see ApplicationInfo#PRIVATE_FLAG_VENDOR */ + boolean isVendor(); + + /** @see ApplicationInfo#PRIVATE_FLAG_ISOLATED_SPLIT_LOADING */ + boolean isIsolatedSplitLoading(); + + /** + * @see ApplicationInfo#enabled + * @see R.styleable#AndroidManifestApplication_enabled + */ + boolean isEnabled(); + + /** + * @see ApplicationInfo#PRIVATE_FLAG_IS_RESOURCE_OVERLAY + * @see ApplicationInfo#isResourceOverlay() + */ + boolean isOverlay(); + + /** @see ApplicationInfo#PRIVATE_FLAG_USES_NON_SDK_API */ + boolean isUsesNonSdkApi(); + + /** @see ApplicationInfo#PRIVATE_FLAG_SIGNED_WITH_PLATFORM_KEY */ + boolean isSignedWithPlatformKey(); + + /** @see ApplicationInfo#FLAG_KILL_AFTER_RESTORE */ + boolean isKillAfterRestore(); + + /** @see ApplicationInfo#FLAG_RESTORE_ANY_VERSION */ + boolean isRestoreAnyVersion(); + + /** @see ApplicationInfo#FLAG_FULL_BACKUP_ONLY */ + boolean isFullBackupOnly(); + + /** @see ApplicationInfo#FLAG_ALLOW_CLEAR_USER_DATA */ + boolean isAllowClearUserData(); + + /** @see ApplicationInfo#FLAG_LARGE_HEAP */ + boolean isLargeHeap(); + + /** @see ApplicationInfo#FLAG_USES_CLEARTEXT_TRAFFIC */ + boolean isUsesCleartextTraffic(); + + /** @see ApplicationInfo#FLAG_SUPPORTS_RTL */ + boolean isSupportsRtl(); + + /** @see ApplicationInfo#FLAG_IS_GAME */ + @Deprecated + boolean isGame(); + + /** @see ApplicationInfo#FLAG_FACTORY_TEST */ + boolean isFactoryTest(); + + /** + * If omitted from manifest, returns true if {@link #getTargetSdkVersion()} >= + * {@link android.os.Build.VERSION_CODES#DONUT}. + * @see R.styleable#AndroidManifestSupportsScreens_smallScreens + * @see ApplicationInfo#FLAG_SUPPORTS_SMALL_SCREENS + */ + boolean isSupportsSmallScreens(); + + /** + * If omitted from manifest, returns true. + * @see R.styleable#AndroidManifestSupportsScreens_normalScreens + * @see ApplicationInfo#FLAG_SUPPORTS_NORMAL_SCREENS + */ + boolean isSupportsNormalScreens(); + + /** + * If omitted from manifest, returns true if {@link #getTargetSdkVersion()} >= + * {@link android.os.Build.VERSION_CODES#DONUT}. + * @see R.styleable#AndroidManifestSupportsScreens_largeScreens + * @see ApplicationInfo#FLAG_SUPPORTS_LARGE_SCREENS + */ + boolean isSupportsLargeScreens(); + + /** + * If omitted from manifest, returns true if {@link #getTargetSdkVersion()} >= + * {@link android.os.Build.VERSION_CODES#GINGERBREAD}. + * @see R.styleable#AndroidManifestSupportsScreens_xlargeScreens + * @see ApplicationInfo#FLAG_SUPPORTS_XLARGE_SCREENS + */ + boolean isSupportsExtraLargeScreens(); + + /** + * If omitted from manifest, returns true if {@link #getTargetSdkVersion()} >= + * {@link android.os.Build.VERSION_CODES#DONUT}. + * @see R.styleable#AndroidManifestSupportsScreens_resizeable + * @see ApplicationInfo#FLAG_RESIZEABLE_FOR_SCREENS + */ + boolean isResizeable(); + + /** + * If omitted from manifest, returns true if {@link #getTargetSdkVersion()} >= + * {@link android.os.Build.VERSION_CODES#DONUT}. + * @see R.styleable#AndroidManifestSupportsScreens_anyDensity + * @see ApplicationInfo#FLAG_SUPPORTS_SCREEN_DENSITIES + */ + boolean isAnyDensity(); + + /** @see ApplicationInfo#PRIVATE_FLAG_BACKUP_IN_FOREGROUND */ + boolean isBackupInForeground(); + + /** @see ApplicationInfo#PRIVATE_FLAG_ALLOW_CLEAR_USER_DATA_ON_FAILED_RESTORE */ + boolean isAllowClearUserDataOnFailedRestore(); + + /** @see ApplicationInfo#PRIVATE_FLAG_ALLOW_AUDIO_PLAYBACK_CAPTURE */ + boolean isAllowAudioPlaybackCapture(); + + /** @see ApplicationInfo#PRIVATE_FLAG_HAS_FRAGILE_USER_DATA */ + boolean isHasFragileUserData(); +} diff --git a/services/core/java/com/android/server/pm/parsing/pkg/PkgPackageInfo.java b/services/core/java/com/android/server/pm/parsing/pkg/PkgPackageInfo.java new file mode 100644 index 0000000000000..54f1efa3a088d --- /dev/null +++ b/services/core/java/com/android/server/pm/parsing/pkg/PkgPackageInfo.java @@ -0,0 +1,225 @@ +/* + * Copyright (C) 2020 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 com.android.server.pm.parsing.pkg; + +import android.annotation.NonNull; +import android.annotation.Nullable; +import android.content.pm.ActivityInfo; +import android.content.pm.ConfigurationInfo; +import android.content.pm.FeatureGroupInfo; +import android.content.pm.FeatureInfo; +import android.content.pm.InstrumentationInfo; +import android.content.pm.PackageInfo; +import android.content.pm.PermissionInfo; +import android.content.pm.ProviderInfo; +import android.content.pm.ServiceInfo; +import android.content.pm.parsing.ComponentParseUtils.ParsedActivity; +import android.content.pm.parsing.ComponentParseUtils.ParsedInstrumentation; +import android.content.pm.parsing.ComponentParseUtils.ParsedPermission; +import android.content.pm.parsing.ComponentParseUtils.ParsedProvider; +import android.content.pm.parsing.ComponentParseUtils.ParsedService; + +import com.android.internal.R; + +import java.util.List; + +/** + * Container for fields that are eventually exposed through {@link PackageInfo}. + * + * Done to separate the meaningless, re-directed JavaDoc for methods and to separate what's + * exposed vs not exposed to core. + * + * @hide + */ +interface PkgPackageInfo { + + /** + * @see PackageInfo#overlayCategory + * @see R.styleable#AndroidManifestResourceOverlay_category + */ + @Nullable + String getOverlayCategory(); + + /** + * @see PackageInfo#overlayPriority + * @see R.styleable#AndroidManifestResourceOverlay_priority + */ + int getOverlayPriority(); + + /** + * @see PackageInfo#overlayTarget + * @see R.styleable#AndroidManifestResourceOverlay_targetPackage + */ + @Nullable + String getOverlayTarget(); + + /** + * @see PackageInfo#targetOverlayableName + * @see R.styleable#AndroidManifestResourceOverlay_targetName + */ + @Nullable + String getOverlayTargetName(); + + /** + * @see PackageInfo#sharedUserId + * @see R.styleable#AndroidManifest_sharedUserId + */ + @Deprecated + @Nullable + String getSharedUserId(); + + /** + * @see PackageInfo#sharedUserLabel + * @see R.styleable#AndroidManifest_sharedUserLabel + */ + @Deprecated + int getSharedUserLabel(); + + /** + * The required account type without which this application will not function. + * + * @see PackageInfo#requiredAccountType + * @see R.styleable#AndroidManifestApplication_requiredAccountType + */ + @Nullable + String getRequiredAccountType(); + + /** + * The restricted account authenticator type that is used by this application + * + * @see PackageInfo#restrictedAccountType + * @see R.styleable#AndroidManifestApplication_restrictedAccountType + */ + @Nullable + String getRestrictedAccountType(); + + /** @see PackageInfo#splitRevisionCodes */ + int[] getSplitRevisionCodes(); + + /** @see PackageInfo#getLongVersionCode() */ + long getLongVersionCode(); + + /** @see PackageInfo#versionCode */ + @Deprecated + int getVersionCode(); + + /** @see PackageInfo#versionCodeMajor */ + int getVersionCodeMajor(); + + /** @see PackageInfo#versionName */ + @Nullable + String getVersionName(); + + /** @see PackageInfo#mOverlayIsStatic */ + boolean isOverlayIsStatic(); + + /** + * @see PackageInfo#requiredForAllUsers + * @see R.styleable#AndroidManifestApplication_requiredForAllUsers + */ + boolean isRequiredForAllUsers(); + + /** + * @see PackageInfo#reqFeatures + * @see R.styleable#AndroidManifestUsesFeature + */ + @NonNull + List getReqFeatures(); + + /** + * @see PackageInfo#configPreferences + * @see R.styleable#AndroidManifestUsesConfiguration + */ + @NonNull + List getConfigPreferences(); + + /** + * @see PackageInfo#featureGroups + * @see R.styleable#AndroidManifestUsesFeature + */ + @NonNull + List getFeatureGroups(); + + /** + * Whether or not the package is a stub and must be replaced by the full version. + * + * @see PackageInfo#isStub + */ + boolean isStub(); + + /** + * For marking packages required for a minimal boot state, through the "coreApp" manifest + * attribute. + * @see PackageInfo#coreApp + */ + boolean isCoreApp(); + + /** + * All the permissions declared. This is an effective set, and may include permissions + * transformed from split/migrated permissions from previous versions, so may not be exactly + * what the package declares in its manifest. + * @see PackageInfo#requestedPermissions + * @see R.styleable#AndroidManifestUsesPermission + */ + @NonNull + List getRequestedPermissions(); + + /** + * @see ActivityInfo + * @see PackageInfo#activities + */ + @NonNull + List getActivities(); + + /** + * @see InstrumentationInfo + * @see PackageInfo#instrumentation + */ + @NonNull + List getInstrumentations(); + + /** + * @see PermissionInfo + * @see PackageInfo#permissions + */ + @NonNull + List getPermissions(); + + /** + * @see ProviderInfo + * @see PackageInfo#providers + */ + @NonNull + List getProviders(); + + /** + * Since they share several attributes, receivers are parsed as {@link ParsedActivity}, even + * though they represent different functionality. + * TODO(b/135203078): Reconsider this and maybe make ParsedReceiver so it's not so confusing + * @see ActivityInfo + * @see PackageInfo#receivers + */ + @NonNull + List getReceivers(); + + /** + * @see ServiceInfo + * @see PackageInfo#services + */ + @NonNull + List getServices(); +}