Loading apct-tests/perftests/packagemanager/src/android/os/PackageParsingPerfTest.kt +6 −2 Original line number Diff line number Diff line Loading @@ -24,10 +24,11 @@ import android.content.pm.parsing.result.ParseTypeImpl import android.content.res.TypedArray import android.perftests.utils.BenchmarkState import android.perftests.utils.PerfStatusReporter import android.util.ArraySet import androidx.test.filters.LargeTest import com.android.internal.pm.parsing.pkg.PackageImpl import com.android.internal.pm.pkg.parsing.ParsingPackageUtils import com.android.internal.util.ConcurrentUtils import com.android.server.pm.parsing.pkg.PackageImpl import com.android.server.pm.pkg.parsing.ParsingPackageUtils import java.io.File import java.io.FileOutputStream import java.util.concurrent.ArrayBlockingQueue Loading Loading @@ -214,7 +215,10 @@ public class PackageParsingPerfTest { path, manifestArray, isCoreApp, this, ) override fun getHiddenApiWhitelistedApps() = ArraySet<String>() override fun getInstallConstraintsAllowlist() = ArraySet<String>() }) override fun parseImpl(file: File) = Loading core/java/com/android/internal/pm/parsing/AppInfoUtils.java 0 → 100644 +124 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 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.internal.pm.parsing; import android.annotation.CheckResult; import android.content.pm.ApplicationInfo; import com.android.internal.pm.parsing.pkg.AndroidPackageLegacyUtils; import com.android.internal.pm.pkg.parsing.ParsingPackageUtils; import com.android.server.pm.pkg.AndroidPackage; public class AppInfoUtils { /** * @see ApplicationInfo#flags */ public static int appInfoFlags(AndroidPackage pkg) { // @formatter:off int pkgWithoutStateFlags = flag(pkg.isExternalStorage(), ApplicationInfo.FLAG_EXTERNAL_STORAGE) | flag(pkg.isHardwareAccelerated(), ApplicationInfo.FLAG_HARDWARE_ACCELERATED) | flag(pkg.isBackupAllowed(), ApplicationInfo.FLAG_ALLOW_BACKUP) | flag(pkg.isKillAfterRestoreAllowed(), ApplicationInfo.FLAG_KILL_AFTER_RESTORE) | flag(pkg.isRestoreAnyVersion(), ApplicationInfo.FLAG_RESTORE_ANY_VERSION) | flag(pkg.isFullBackupOnly(), ApplicationInfo.FLAG_FULL_BACKUP_ONLY) | flag(pkg.isPersistent(), ApplicationInfo.FLAG_PERSISTENT) | flag(pkg.isDebuggable(), ApplicationInfo.FLAG_DEBUGGABLE) | flag(pkg.isVmSafeMode(), ApplicationInfo.FLAG_VM_SAFE_MODE) | flag(pkg.isDeclaredHavingCode(), ApplicationInfo.FLAG_HAS_CODE) | flag(pkg.isTaskReparentingAllowed(), ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING) | flag(pkg.isClearUserDataAllowed(), ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA) | flag(pkg.isLargeHeap(), ApplicationInfo.FLAG_LARGE_HEAP) | flag(pkg.isCleartextTrafficAllowed(), ApplicationInfo.FLAG_USES_CLEARTEXT_TRAFFIC) | flag(pkg.isRtlSupported(), ApplicationInfo.FLAG_SUPPORTS_RTL) | flag(pkg.isTestOnly(), ApplicationInfo.FLAG_TEST_ONLY) | flag(pkg.isMultiArch(), ApplicationInfo.FLAG_MULTIARCH) | flag(pkg.isExtractNativeLibrariesRequested(), ApplicationInfo.FLAG_EXTRACT_NATIVE_LIBS) | flag(pkg.isGame(), ApplicationInfo.FLAG_IS_GAME) | flag(pkg.isSmallScreensSupported(), ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS) | flag(pkg.isNormalScreensSupported(), ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS) | flag(pkg.isLargeScreensSupported(), ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS) | flag(pkg.isExtraLargeScreensSupported(), ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS) | flag(pkg.isResizeable(), ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS) | flag(pkg.isAnyDensity(), ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES) | flag(AndroidPackageLegacyUtils.isSystem(pkg), ApplicationInfo.FLAG_SYSTEM) | flag(pkg.isFactoryTest(), ApplicationInfo.FLAG_FACTORY_TEST); return pkgWithoutStateFlags; // @formatter:on } /** @see ApplicationInfo#privateFlags */ public static int appInfoPrivateFlags(AndroidPackage pkg) { // @formatter:off int pkgWithoutStateFlags = flag(pkg.isStaticSharedLibrary(), ApplicationInfo.PRIVATE_FLAG_STATIC_SHARED_LIBRARY) | flag(pkg.isResourceOverlay(), ApplicationInfo.PRIVATE_FLAG_IS_RESOURCE_OVERLAY) | flag(pkg.isIsolatedSplitLoading(), ApplicationInfo.PRIVATE_FLAG_ISOLATED_SPLIT_LOADING) | flag(pkg.isHasDomainUrls(), ApplicationInfo.PRIVATE_FLAG_HAS_DOMAIN_URLS) | flag(pkg.isProfileableByShell(), ApplicationInfo.PRIVATE_FLAG_PROFILEABLE_BY_SHELL) | flag(pkg.isBackupInForeground(), ApplicationInfo.PRIVATE_FLAG_BACKUP_IN_FOREGROUND) | flag(pkg.isUseEmbeddedDex(), ApplicationInfo.PRIVATE_FLAG_USE_EMBEDDED_DEX) | flag(pkg.isDefaultToDeviceProtectedStorage(), ApplicationInfo.PRIVATE_FLAG_DEFAULT_TO_DEVICE_PROTECTED_STORAGE) | flag(pkg.isDirectBootAware(), ApplicationInfo.PRIVATE_FLAG_DIRECT_BOOT_AWARE) | flag(pkg.isPartiallyDirectBootAware(), ApplicationInfo.PRIVATE_FLAG_PARTIALLY_DIRECT_BOOT_AWARE) | flag(pkg.isClearUserDataOnFailedRestoreAllowed(), ApplicationInfo.PRIVATE_FLAG_ALLOW_CLEAR_USER_DATA_ON_FAILED_RESTORE) | flag(pkg.isAllowAudioPlaybackCapture(), ApplicationInfo.PRIVATE_FLAG_ALLOW_AUDIO_PLAYBACK_CAPTURE) | flag(pkg.isRequestLegacyExternalStorage(), ApplicationInfo.PRIVATE_FLAG_REQUEST_LEGACY_EXTERNAL_STORAGE) | flag(pkg.isNonSdkApiRequested(), ApplicationInfo.PRIVATE_FLAG_USES_NON_SDK_API) | flag(pkg.isUserDataFragile(), ApplicationInfo.PRIVATE_FLAG_HAS_FRAGILE_USER_DATA) | flag(pkg.isSaveStateDisallowed(), ApplicationInfo.PRIVATE_FLAG_CANT_SAVE_STATE) | flag(pkg.isResizeableActivityViaSdkVersion(), ApplicationInfo.PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION) | flag(pkg.isAllowNativeHeapPointerTagging(), ApplicationInfo.PRIVATE_FLAG_ALLOW_NATIVE_HEAP_POINTER_TAGGING) | flag(AndroidPackageLegacyUtils.isSystemExt(pkg), ApplicationInfo.PRIVATE_FLAG_SYSTEM_EXT) | flag(AndroidPackageLegacyUtils.isPrivileged(pkg), ApplicationInfo.PRIVATE_FLAG_PRIVILEGED) | flag(AndroidPackageLegacyUtils.isOem(pkg), ApplicationInfo.PRIVATE_FLAG_OEM) | flag(AndroidPackageLegacyUtils.isVendor(pkg), ApplicationInfo.PRIVATE_FLAG_VENDOR) | flag(AndroidPackageLegacyUtils.isProduct(pkg), ApplicationInfo.PRIVATE_FLAG_PRODUCT) | flag(AndroidPackageLegacyUtils.isOdm(pkg), ApplicationInfo.PRIVATE_FLAG_ODM) | flag(pkg.isSignedWithPlatformKey(), ApplicationInfo.PRIVATE_FLAG_SIGNED_WITH_PLATFORM_KEY); Boolean resizeableActivity = pkg.getResizeableActivity(); if (resizeableActivity != null) { if (resizeableActivity) { pkgWithoutStateFlags |= ApplicationInfo.PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE; } else { pkgWithoutStateFlags |= ApplicationInfo.PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_UNRESIZEABLE; } } return pkgWithoutStateFlags; // @formatter:on } /** @see ApplicationInfo#privateFlagsExt */ public static int appInfoPrivateFlagsExt(AndroidPackage pkg, boolean isAllowlistedForHiddenApis) { // @formatter:off int pkgWithoutStateFlags = flag(pkg.isProfileable(), ApplicationInfo.PRIVATE_FLAG_EXT_PROFILEABLE) | flag(pkg.hasRequestForegroundServiceExemption(), ApplicationInfo.PRIVATE_FLAG_EXT_REQUEST_FOREGROUND_SERVICE_EXEMPTION) | flag(pkg.isAttributionsUserVisible(), ApplicationInfo.PRIVATE_FLAG_EXT_ATTRIBUTIONS_ARE_USER_VISIBLE) | flag(pkg.isOnBackInvokedCallbackEnabled(), ApplicationInfo.PRIVATE_FLAG_EXT_ENABLE_ON_BACK_INVOKED_CALLBACK) | flag(isAllowlistedForHiddenApis, ApplicationInfo.PRIVATE_FLAG_EXT_ALLOWLISTED_FOR_HIDDEN_APIS); return pkgWithoutStateFlags; // @formatter:on } @CheckResult private static int flag(boolean hasFlag, int flag) { return hasFlag ? flag : 0; } } core/java/com/android/internal/pm/parsing/PackageParserException.java 0 → 100644 +30 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 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.internal.pm.parsing; public class PackageParserException extends Exception { public final int error; public PackageParserException(int error, String detailMessage) { super(detailMessage); this.error = error; } public PackageParserException(int error, String detailMessage, Throwable throwable) { super(detailMessage, throwable); this.error = error; } } No newline at end of file core/java/com/android/internal/pm/parsing/pkg/AndroidPackageLegacyUtils.java 0 → 100644 +128 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 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.internal.pm.parsing.pkg; import android.annotation.NonNull; import android.annotation.Nullable; import android.content.pm.ApplicationInfo; import android.content.pm.PackageInfo; import com.android.internal.pm.pkg.parsing.ParsingPackageHidden; import com.android.server.pm.pkg.AndroidPackage; /** @hide */ public class AndroidPackageLegacyUtils { private AndroidPackageLegacyUtils() { } /** * Returns the primary ABI as parsed from the package. Used only during parsing and derivation. * Otherwise prefer {@link PackageState#getPrimaryCpuAbi()}. */ public static String getRawPrimaryCpuAbi(AndroidPackage pkg) { return ((AndroidPackageHidden) pkg).getPrimaryCpuAbi(); } /** * Returns the secondary ABI as parsed from the package. Used only during parsing and * derivation. Otherwise prefer {@link PackageState#getSecondaryCpuAbi()}. */ public static String getRawSecondaryCpuAbi(@NonNull AndroidPackage pkg) { return ((AndroidPackageHidden) pkg).getSecondaryCpuAbi(); } @Deprecated @NonNull public static ApplicationInfo generateAppInfoWithoutState(AndroidPackage pkg) { return ((AndroidPackageHidden) pkg).toAppInfoWithoutState(); } /** * Replacement of unnecessary legacy getRealPackage. Only returns a value if the package was * actually renamed. */ @Nullable public static String getRealPackageOrNull(@NonNull AndroidPackage pkg, boolean isSystem) { if (pkg.getOriginalPackages().isEmpty() || !isSystem) { return null; } return pkg.getManifestPackageName(); } public static void fillVersionCodes(@NonNull AndroidPackage pkg, @NonNull PackageInfo info) { info.versionCode = ((ParsingPackageHidden) pkg).getVersionCode(); info.versionCodeMajor = ((ParsingPackageHidden) pkg).getVersionCodeMajor(); } /** * @deprecated Use {@link PackageState#isSystem} */ @Deprecated public static boolean isSystem(@NonNull AndroidPackage pkg) { return ((AndroidPackageHidden) pkg).isSystem(); } /** * @deprecated Use {@link PackageState#isSystemExt} */ @Deprecated public static boolean isSystemExt(@NonNull AndroidPackage pkg) { return ((AndroidPackageHidden) pkg).isSystemExt(); } /** * @deprecated Use {@link PackageState#isPrivileged} */ @Deprecated public static boolean isPrivileged(@NonNull AndroidPackage pkg) { return ((AndroidPackageHidden) pkg).isPrivileged(); } /** * @deprecated Use {@link PackageState#isOem} */ @Deprecated public static boolean isOem(@NonNull AndroidPackage pkg) { return ((AndroidPackageHidden) pkg).isOem(); } /** * @deprecated Use {@link PackageState#isVendor} */ @Deprecated public static boolean isVendor(@NonNull AndroidPackage pkg) { return ((AndroidPackageHidden) pkg).isVendor(); } /** * @deprecated Use {@link PackageState#isProduct} */ @Deprecated public static boolean isProduct(@NonNull AndroidPackage pkg) { return ((AndroidPackageHidden) pkg).isProduct(); } /** * @deprecated Use {@link PackageState#isOdm} */ @Deprecated public static boolean isOdm(@NonNull AndroidPackage pkg) { return ((AndroidPackageHidden) pkg).isOdm(); } } services/core/java/com/android/server/pm/parsing/pkg/PackageImpl.java→core/java/com/android/internal/pm/parsing/pkg/PackageImpl.java +32 −27 Original line number Diff line number Diff line Loading @@ -14,7 +14,7 @@ * limitations under the License. */ package com.android.server.pm.parsing.pkg; package com.android.internal.pm.parsing.pkg; import static java.util.Collections.emptyList; import static java.util.Collections.emptyMap; Loading Loading @@ -50,47 +50,44 @@ import android.util.SparseIntArray; import com.android.internal.R; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.pm.parsing.pkg.AndroidPackageHidden; import com.android.internal.pm.parsing.pkg.AndroidPackageInternal; import com.android.internal.pm.parsing.pkg.ParsedPackage; import com.android.internal.pm.parsing.AppInfoUtils; import com.android.internal.pm.pkg.AndroidPackageSplitImpl; import com.android.internal.pm.pkg.SEInfoUtil; import com.android.internal.pm.pkg.component.ComponentMutateUtils; import com.android.internal.pm.pkg.component.ParsedActivity; import com.android.internal.pm.pkg.component.ParsedActivityImpl; import com.android.internal.pm.pkg.component.ParsedApexSystemService; import com.android.internal.pm.pkg.component.ParsedApexSystemServiceImpl; import com.android.internal.pm.pkg.component.ParsedAttribution; import com.android.internal.pm.pkg.component.ParsedAttributionImpl; import com.android.internal.pm.pkg.component.ParsedComponent; import com.android.internal.pm.pkg.component.ParsedInstrumentation; import com.android.internal.pm.pkg.component.ParsedInstrumentationImpl; import com.android.internal.pm.pkg.component.ParsedIntentInfo; import com.android.internal.pm.pkg.component.ParsedMainComponent; import com.android.internal.pm.pkg.component.ParsedPermission; import com.android.internal.pm.pkg.component.ParsedPermissionGroup; import com.android.internal.pm.pkg.component.ParsedPermissionGroupImpl; import com.android.internal.pm.pkg.component.ParsedPermissionImpl; import com.android.internal.pm.pkg.component.ParsedProcess; import com.android.internal.pm.pkg.component.ParsedProcessImpl; import com.android.internal.pm.pkg.component.ParsedProvider; import com.android.internal.pm.pkg.component.ParsedProviderImpl; import com.android.internal.pm.pkg.component.ParsedService; import com.android.internal.pm.pkg.component.ParsedServiceImpl; import com.android.internal.pm.pkg.component.ParsedUsesPermission; import com.android.internal.pm.pkg.component.ParsedUsesPermissionImpl; import com.android.internal.pm.pkg.parsing.ParsingPackage; import com.android.internal.pm.pkg.parsing.ParsingPackageHidden; import com.android.internal.pm.pkg.parsing.ParsingPackageUtils; import com.android.internal.pm.pkg.parsing.ParsingUtils; 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.ForInternedString; import com.android.server.pm.parsing.PackageInfoUtils; import com.android.server.pm.pkg.AndroidPackage; import com.android.server.pm.pkg.AndroidPackageSplit; import com.android.server.pm.pkg.SELinuxUtil; import com.android.server.pm.pkg.component.ComponentMutateUtils; import com.android.server.pm.pkg.component.ParsedActivityImpl; import com.android.server.pm.pkg.component.ParsedApexSystemServiceImpl; import com.android.server.pm.pkg.component.ParsedAttributionImpl; import com.android.server.pm.pkg.component.ParsedInstrumentationImpl; import com.android.server.pm.pkg.component.ParsedPermissionGroupImpl; import com.android.server.pm.pkg.component.ParsedPermissionImpl; import com.android.server.pm.pkg.component.ParsedProcessImpl; import com.android.server.pm.pkg.component.ParsedProviderImpl; import com.android.server.pm.pkg.component.ParsedServiceImpl; import com.android.server.pm.pkg.component.ParsedUsesPermissionImpl; import com.android.server.pm.pkg.parsing.ParsingPackageUtils; import com.android.server.pm.pkg.parsing.ParsingUtils; import libcore.util.EmptyArray; Loading Loading @@ -422,8 +419,10 @@ public class PackageImpl implements ParsedPackage, AndroidPackageInternal, @NonNull 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); @NonNull String codePath, @NonNull TypedArray manifestArray, boolean isCoreApp, @Nullable ParsingPackageUtils.Callback callback) { return new PackageImpl( packageName, baseCodePath, codePath, manifestArray, isCoreApp, callback); } /** Loading Loading @@ -453,7 +452,7 @@ public class PackageImpl implements ParsedPackage, AndroidPackageInternal, @NonNull @VisibleForTesting public static ParsingPackage forTesting(String packageName, String baseCodePath) { return new PackageImpl(packageName, baseCodePath, baseCodePath, null, false); return new PackageImpl(packageName, baseCodePath, baseCodePath, null, false, null); } @NonNull Loading Loading @@ -2694,12 +2693,16 @@ public class PackageImpl implements ParsedPackage, AndroidPackageInternal, private String mBaseAppDataCredentialProtectedDirForSystemUser; private String mBaseAppDataDeviceProtectedDirForSystemUser; ParsingPackageUtils.Callback mCallback; @VisibleForTesting public PackageImpl(@NonNull String packageName, @NonNull String baseApkPath, @NonNull String path, @Nullable TypedArray manifestArray, boolean isCoreApp) { @NonNull String path, @Nullable TypedArray manifestArray, boolean isCoreApp, @Nullable ParsingPackageUtils.Callback callback) { this.packageName = TextUtils.safeIntern(packageName); this.mBaseApkPath = baseApkPath; this.mPath = path; this.mCallback = callback; if (manifestArray != null) { versionCode = manifestArray.getInteger(R.styleable.AndroidManifest_versionCode, 0); Loading Loading @@ -2750,9 +2753,11 @@ public class PackageImpl implements ParsedPackage, AndroidPackageInternal, } private void assignDerivedFields2() { mBaseAppInfoFlags = PackageInfoUtils.appInfoFlags(this, null); mBaseAppInfoPrivateFlags = PackageInfoUtils.appInfoPrivateFlags(this, null); mBaseAppInfoPrivateFlagsExt = PackageInfoUtils.appInfoPrivateFlagsExt(this, null); mBaseAppInfoFlags = AppInfoUtils.appInfoFlags(this); mBaseAppInfoPrivateFlags = AppInfoUtils.appInfoPrivateFlags(this); mBaseAppInfoPrivateFlagsExt = AppInfoUtils.appInfoPrivateFlagsExt(this, mCallback == null ? false : mCallback.getHiddenApiWhitelistedApps().contains(this.packageName)); String baseAppDataDir = Environment.getDataDirectoryPath(getVolumeUuid()) + File.separator; String systemUserSuffix = File.separator + UserHandle.USER_SYSTEM + File.separator; mBaseAppDataCredentialProtectedDirForSystemUser = TextUtils.safeIntern( Loading Loading @@ -3087,7 +3092,7 @@ public class PackageImpl implements ParsedPackage, AndroidPackageInternal, appInfo.primaryCpuAbi = primaryCpuAbi; appInfo.secondaryCpuAbi = secondaryCpuAbi; appInfo.secondaryNativeLibraryDir = secondaryNativeLibraryDir; appInfo.seInfoUser = SELinuxUtil.COMPLETE_STR; appInfo.seInfoUser = SEInfoUtil.COMPLETE_STR; appInfo.uid = uid; return appInfo; } Loading Loading
apct-tests/perftests/packagemanager/src/android/os/PackageParsingPerfTest.kt +6 −2 Original line number Diff line number Diff line Loading @@ -24,10 +24,11 @@ import android.content.pm.parsing.result.ParseTypeImpl import android.content.res.TypedArray import android.perftests.utils.BenchmarkState import android.perftests.utils.PerfStatusReporter import android.util.ArraySet import androidx.test.filters.LargeTest import com.android.internal.pm.parsing.pkg.PackageImpl import com.android.internal.pm.pkg.parsing.ParsingPackageUtils import com.android.internal.util.ConcurrentUtils import com.android.server.pm.parsing.pkg.PackageImpl import com.android.server.pm.pkg.parsing.ParsingPackageUtils import java.io.File import java.io.FileOutputStream import java.util.concurrent.ArrayBlockingQueue Loading Loading @@ -214,7 +215,10 @@ public class PackageParsingPerfTest { path, manifestArray, isCoreApp, this, ) override fun getHiddenApiWhitelistedApps() = ArraySet<String>() override fun getInstallConstraintsAllowlist() = ArraySet<String>() }) override fun parseImpl(file: File) = Loading
core/java/com/android/internal/pm/parsing/AppInfoUtils.java 0 → 100644 +124 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 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.internal.pm.parsing; import android.annotation.CheckResult; import android.content.pm.ApplicationInfo; import com.android.internal.pm.parsing.pkg.AndroidPackageLegacyUtils; import com.android.internal.pm.pkg.parsing.ParsingPackageUtils; import com.android.server.pm.pkg.AndroidPackage; public class AppInfoUtils { /** * @see ApplicationInfo#flags */ public static int appInfoFlags(AndroidPackage pkg) { // @formatter:off int pkgWithoutStateFlags = flag(pkg.isExternalStorage(), ApplicationInfo.FLAG_EXTERNAL_STORAGE) | flag(pkg.isHardwareAccelerated(), ApplicationInfo.FLAG_HARDWARE_ACCELERATED) | flag(pkg.isBackupAllowed(), ApplicationInfo.FLAG_ALLOW_BACKUP) | flag(pkg.isKillAfterRestoreAllowed(), ApplicationInfo.FLAG_KILL_AFTER_RESTORE) | flag(pkg.isRestoreAnyVersion(), ApplicationInfo.FLAG_RESTORE_ANY_VERSION) | flag(pkg.isFullBackupOnly(), ApplicationInfo.FLAG_FULL_BACKUP_ONLY) | flag(pkg.isPersistent(), ApplicationInfo.FLAG_PERSISTENT) | flag(pkg.isDebuggable(), ApplicationInfo.FLAG_DEBUGGABLE) | flag(pkg.isVmSafeMode(), ApplicationInfo.FLAG_VM_SAFE_MODE) | flag(pkg.isDeclaredHavingCode(), ApplicationInfo.FLAG_HAS_CODE) | flag(pkg.isTaskReparentingAllowed(), ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING) | flag(pkg.isClearUserDataAllowed(), ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA) | flag(pkg.isLargeHeap(), ApplicationInfo.FLAG_LARGE_HEAP) | flag(pkg.isCleartextTrafficAllowed(), ApplicationInfo.FLAG_USES_CLEARTEXT_TRAFFIC) | flag(pkg.isRtlSupported(), ApplicationInfo.FLAG_SUPPORTS_RTL) | flag(pkg.isTestOnly(), ApplicationInfo.FLAG_TEST_ONLY) | flag(pkg.isMultiArch(), ApplicationInfo.FLAG_MULTIARCH) | flag(pkg.isExtractNativeLibrariesRequested(), ApplicationInfo.FLAG_EXTRACT_NATIVE_LIBS) | flag(pkg.isGame(), ApplicationInfo.FLAG_IS_GAME) | flag(pkg.isSmallScreensSupported(), ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS) | flag(pkg.isNormalScreensSupported(), ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS) | flag(pkg.isLargeScreensSupported(), ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS) | flag(pkg.isExtraLargeScreensSupported(), ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS) | flag(pkg.isResizeable(), ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS) | flag(pkg.isAnyDensity(), ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES) | flag(AndroidPackageLegacyUtils.isSystem(pkg), ApplicationInfo.FLAG_SYSTEM) | flag(pkg.isFactoryTest(), ApplicationInfo.FLAG_FACTORY_TEST); return pkgWithoutStateFlags; // @formatter:on } /** @see ApplicationInfo#privateFlags */ public static int appInfoPrivateFlags(AndroidPackage pkg) { // @formatter:off int pkgWithoutStateFlags = flag(pkg.isStaticSharedLibrary(), ApplicationInfo.PRIVATE_FLAG_STATIC_SHARED_LIBRARY) | flag(pkg.isResourceOverlay(), ApplicationInfo.PRIVATE_FLAG_IS_RESOURCE_OVERLAY) | flag(pkg.isIsolatedSplitLoading(), ApplicationInfo.PRIVATE_FLAG_ISOLATED_SPLIT_LOADING) | flag(pkg.isHasDomainUrls(), ApplicationInfo.PRIVATE_FLAG_HAS_DOMAIN_URLS) | flag(pkg.isProfileableByShell(), ApplicationInfo.PRIVATE_FLAG_PROFILEABLE_BY_SHELL) | flag(pkg.isBackupInForeground(), ApplicationInfo.PRIVATE_FLAG_BACKUP_IN_FOREGROUND) | flag(pkg.isUseEmbeddedDex(), ApplicationInfo.PRIVATE_FLAG_USE_EMBEDDED_DEX) | flag(pkg.isDefaultToDeviceProtectedStorage(), ApplicationInfo.PRIVATE_FLAG_DEFAULT_TO_DEVICE_PROTECTED_STORAGE) | flag(pkg.isDirectBootAware(), ApplicationInfo.PRIVATE_FLAG_DIRECT_BOOT_AWARE) | flag(pkg.isPartiallyDirectBootAware(), ApplicationInfo.PRIVATE_FLAG_PARTIALLY_DIRECT_BOOT_AWARE) | flag(pkg.isClearUserDataOnFailedRestoreAllowed(), ApplicationInfo.PRIVATE_FLAG_ALLOW_CLEAR_USER_DATA_ON_FAILED_RESTORE) | flag(pkg.isAllowAudioPlaybackCapture(), ApplicationInfo.PRIVATE_FLAG_ALLOW_AUDIO_PLAYBACK_CAPTURE) | flag(pkg.isRequestLegacyExternalStorage(), ApplicationInfo.PRIVATE_FLAG_REQUEST_LEGACY_EXTERNAL_STORAGE) | flag(pkg.isNonSdkApiRequested(), ApplicationInfo.PRIVATE_FLAG_USES_NON_SDK_API) | flag(pkg.isUserDataFragile(), ApplicationInfo.PRIVATE_FLAG_HAS_FRAGILE_USER_DATA) | flag(pkg.isSaveStateDisallowed(), ApplicationInfo.PRIVATE_FLAG_CANT_SAVE_STATE) | flag(pkg.isResizeableActivityViaSdkVersion(), ApplicationInfo.PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION) | flag(pkg.isAllowNativeHeapPointerTagging(), ApplicationInfo.PRIVATE_FLAG_ALLOW_NATIVE_HEAP_POINTER_TAGGING) | flag(AndroidPackageLegacyUtils.isSystemExt(pkg), ApplicationInfo.PRIVATE_FLAG_SYSTEM_EXT) | flag(AndroidPackageLegacyUtils.isPrivileged(pkg), ApplicationInfo.PRIVATE_FLAG_PRIVILEGED) | flag(AndroidPackageLegacyUtils.isOem(pkg), ApplicationInfo.PRIVATE_FLAG_OEM) | flag(AndroidPackageLegacyUtils.isVendor(pkg), ApplicationInfo.PRIVATE_FLAG_VENDOR) | flag(AndroidPackageLegacyUtils.isProduct(pkg), ApplicationInfo.PRIVATE_FLAG_PRODUCT) | flag(AndroidPackageLegacyUtils.isOdm(pkg), ApplicationInfo.PRIVATE_FLAG_ODM) | flag(pkg.isSignedWithPlatformKey(), ApplicationInfo.PRIVATE_FLAG_SIGNED_WITH_PLATFORM_KEY); Boolean resizeableActivity = pkg.getResizeableActivity(); if (resizeableActivity != null) { if (resizeableActivity) { pkgWithoutStateFlags |= ApplicationInfo.PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE; } else { pkgWithoutStateFlags |= ApplicationInfo.PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_UNRESIZEABLE; } } return pkgWithoutStateFlags; // @formatter:on } /** @see ApplicationInfo#privateFlagsExt */ public static int appInfoPrivateFlagsExt(AndroidPackage pkg, boolean isAllowlistedForHiddenApis) { // @formatter:off int pkgWithoutStateFlags = flag(pkg.isProfileable(), ApplicationInfo.PRIVATE_FLAG_EXT_PROFILEABLE) | flag(pkg.hasRequestForegroundServiceExemption(), ApplicationInfo.PRIVATE_FLAG_EXT_REQUEST_FOREGROUND_SERVICE_EXEMPTION) | flag(pkg.isAttributionsUserVisible(), ApplicationInfo.PRIVATE_FLAG_EXT_ATTRIBUTIONS_ARE_USER_VISIBLE) | flag(pkg.isOnBackInvokedCallbackEnabled(), ApplicationInfo.PRIVATE_FLAG_EXT_ENABLE_ON_BACK_INVOKED_CALLBACK) | flag(isAllowlistedForHiddenApis, ApplicationInfo.PRIVATE_FLAG_EXT_ALLOWLISTED_FOR_HIDDEN_APIS); return pkgWithoutStateFlags; // @formatter:on } @CheckResult private static int flag(boolean hasFlag, int flag) { return hasFlag ? flag : 0; } }
core/java/com/android/internal/pm/parsing/PackageParserException.java 0 → 100644 +30 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 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.internal.pm.parsing; public class PackageParserException extends Exception { public final int error; public PackageParserException(int error, String detailMessage) { super(detailMessage); this.error = error; } public PackageParserException(int error, String detailMessage, Throwable throwable) { super(detailMessage, throwable); this.error = error; } } No newline at end of file
core/java/com/android/internal/pm/parsing/pkg/AndroidPackageLegacyUtils.java 0 → 100644 +128 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 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.internal.pm.parsing.pkg; import android.annotation.NonNull; import android.annotation.Nullable; import android.content.pm.ApplicationInfo; import android.content.pm.PackageInfo; import com.android.internal.pm.pkg.parsing.ParsingPackageHidden; import com.android.server.pm.pkg.AndroidPackage; /** @hide */ public class AndroidPackageLegacyUtils { private AndroidPackageLegacyUtils() { } /** * Returns the primary ABI as parsed from the package. Used only during parsing and derivation. * Otherwise prefer {@link PackageState#getPrimaryCpuAbi()}. */ public static String getRawPrimaryCpuAbi(AndroidPackage pkg) { return ((AndroidPackageHidden) pkg).getPrimaryCpuAbi(); } /** * Returns the secondary ABI as parsed from the package. Used only during parsing and * derivation. Otherwise prefer {@link PackageState#getSecondaryCpuAbi()}. */ public static String getRawSecondaryCpuAbi(@NonNull AndroidPackage pkg) { return ((AndroidPackageHidden) pkg).getSecondaryCpuAbi(); } @Deprecated @NonNull public static ApplicationInfo generateAppInfoWithoutState(AndroidPackage pkg) { return ((AndroidPackageHidden) pkg).toAppInfoWithoutState(); } /** * Replacement of unnecessary legacy getRealPackage. Only returns a value if the package was * actually renamed. */ @Nullable public static String getRealPackageOrNull(@NonNull AndroidPackage pkg, boolean isSystem) { if (pkg.getOriginalPackages().isEmpty() || !isSystem) { return null; } return pkg.getManifestPackageName(); } public static void fillVersionCodes(@NonNull AndroidPackage pkg, @NonNull PackageInfo info) { info.versionCode = ((ParsingPackageHidden) pkg).getVersionCode(); info.versionCodeMajor = ((ParsingPackageHidden) pkg).getVersionCodeMajor(); } /** * @deprecated Use {@link PackageState#isSystem} */ @Deprecated public static boolean isSystem(@NonNull AndroidPackage pkg) { return ((AndroidPackageHidden) pkg).isSystem(); } /** * @deprecated Use {@link PackageState#isSystemExt} */ @Deprecated public static boolean isSystemExt(@NonNull AndroidPackage pkg) { return ((AndroidPackageHidden) pkg).isSystemExt(); } /** * @deprecated Use {@link PackageState#isPrivileged} */ @Deprecated public static boolean isPrivileged(@NonNull AndroidPackage pkg) { return ((AndroidPackageHidden) pkg).isPrivileged(); } /** * @deprecated Use {@link PackageState#isOem} */ @Deprecated public static boolean isOem(@NonNull AndroidPackage pkg) { return ((AndroidPackageHidden) pkg).isOem(); } /** * @deprecated Use {@link PackageState#isVendor} */ @Deprecated public static boolean isVendor(@NonNull AndroidPackage pkg) { return ((AndroidPackageHidden) pkg).isVendor(); } /** * @deprecated Use {@link PackageState#isProduct} */ @Deprecated public static boolean isProduct(@NonNull AndroidPackage pkg) { return ((AndroidPackageHidden) pkg).isProduct(); } /** * @deprecated Use {@link PackageState#isOdm} */ @Deprecated public static boolean isOdm(@NonNull AndroidPackage pkg) { return ((AndroidPackageHidden) pkg).isOdm(); } }
services/core/java/com/android/server/pm/parsing/pkg/PackageImpl.java→core/java/com/android/internal/pm/parsing/pkg/PackageImpl.java +32 −27 Original line number Diff line number Diff line Loading @@ -14,7 +14,7 @@ * limitations under the License. */ package com.android.server.pm.parsing.pkg; package com.android.internal.pm.parsing.pkg; import static java.util.Collections.emptyList; import static java.util.Collections.emptyMap; Loading Loading @@ -50,47 +50,44 @@ import android.util.SparseIntArray; import com.android.internal.R; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.pm.parsing.pkg.AndroidPackageHidden; import com.android.internal.pm.parsing.pkg.AndroidPackageInternal; import com.android.internal.pm.parsing.pkg.ParsedPackage; import com.android.internal.pm.parsing.AppInfoUtils; import com.android.internal.pm.pkg.AndroidPackageSplitImpl; import com.android.internal.pm.pkg.SEInfoUtil; import com.android.internal.pm.pkg.component.ComponentMutateUtils; import com.android.internal.pm.pkg.component.ParsedActivity; import com.android.internal.pm.pkg.component.ParsedActivityImpl; import com.android.internal.pm.pkg.component.ParsedApexSystemService; import com.android.internal.pm.pkg.component.ParsedApexSystemServiceImpl; import com.android.internal.pm.pkg.component.ParsedAttribution; import com.android.internal.pm.pkg.component.ParsedAttributionImpl; import com.android.internal.pm.pkg.component.ParsedComponent; import com.android.internal.pm.pkg.component.ParsedInstrumentation; import com.android.internal.pm.pkg.component.ParsedInstrumentationImpl; import com.android.internal.pm.pkg.component.ParsedIntentInfo; import com.android.internal.pm.pkg.component.ParsedMainComponent; import com.android.internal.pm.pkg.component.ParsedPermission; import com.android.internal.pm.pkg.component.ParsedPermissionGroup; import com.android.internal.pm.pkg.component.ParsedPermissionGroupImpl; import com.android.internal.pm.pkg.component.ParsedPermissionImpl; import com.android.internal.pm.pkg.component.ParsedProcess; import com.android.internal.pm.pkg.component.ParsedProcessImpl; import com.android.internal.pm.pkg.component.ParsedProvider; import com.android.internal.pm.pkg.component.ParsedProviderImpl; import com.android.internal.pm.pkg.component.ParsedService; import com.android.internal.pm.pkg.component.ParsedServiceImpl; import com.android.internal.pm.pkg.component.ParsedUsesPermission; import com.android.internal.pm.pkg.component.ParsedUsesPermissionImpl; import com.android.internal.pm.pkg.parsing.ParsingPackage; import com.android.internal.pm.pkg.parsing.ParsingPackageHidden; import com.android.internal.pm.pkg.parsing.ParsingPackageUtils; import com.android.internal.pm.pkg.parsing.ParsingUtils; 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.ForInternedString; import com.android.server.pm.parsing.PackageInfoUtils; import com.android.server.pm.pkg.AndroidPackage; import com.android.server.pm.pkg.AndroidPackageSplit; import com.android.server.pm.pkg.SELinuxUtil; import com.android.server.pm.pkg.component.ComponentMutateUtils; import com.android.server.pm.pkg.component.ParsedActivityImpl; import com.android.server.pm.pkg.component.ParsedApexSystemServiceImpl; import com.android.server.pm.pkg.component.ParsedAttributionImpl; import com.android.server.pm.pkg.component.ParsedInstrumentationImpl; import com.android.server.pm.pkg.component.ParsedPermissionGroupImpl; import com.android.server.pm.pkg.component.ParsedPermissionImpl; import com.android.server.pm.pkg.component.ParsedProcessImpl; import com.android.server.pm.pkg.component.ParsedProviderImpl; import com.android.server.pm.pkg.component.ParsedServiceImpl; import com.android.server.pm.pkg.component.ParsedUsesPermissionImpl; import com.android.server.pm.pkg.parsing.ParsingPackageUtils; import com.android.server.pm.pkg.parsing.ParsingUtils; import libcore.util.EmptyArray; Loading Loading @@ -422,8 +419,10 @@ public class PackageImpl implements ParsedPackage, AndroidPackageInternal, @NonNull 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); @NonNull String codePath, @NonNull TypedArray manifestArray, boolean isCoreApp, @Nullable ParsingPackageUtils.Callback callback) { return new PackageImpl( packageName, baseCodePath, codePath, manifestArray, isCoreApp, callback); } /** Loading Loading @@ -453,7 +452,7 @@ public class PackageImpl implements ParsedPackage, AndroidPackageInternal, @NonNull @VisibleForTesting public static ParsingPackage forTesting(String packageName, String baseCodePath) { return new PackageImpl(packageName, baseCodePath, baseCodePath, null, false); return new PackageImpl(packageName, baseCodePath, baseCodePath, null, false, null); } @NonNull Loading Loading @@ -2694,12 +2693,16 @@ public class PackageImpl implements ParsedPackage, AndroidPackageInternal, private String mBaseAppDataCredentialProtectedDirForSystemUser; private String mBaseAppDataDeviceProtectedDirForSystemUser; ParsingPackageUtils.Callback mCallback; @VisibleForTesting public PackageImpl(@NonNull String packageName, @NonNull String baseApkPath, @NonNull String path, @Nullable TypedArray manifestArray, boolean isCoreApp) { @NonNull String path, @Nullable TypedArray manifestArray, boolean isCoreApp, @Nullable ParsingPackageUtils.Callback callback) { this.packageName = TextUtils.safeIntern(packageName); this.mBaseApkPath = baseApkPath; this.mPath = path; this.mCallback = callback; if (manifestArray != null) { versionCode = manifestArray.getInteger(R.styleable.AndroidManifest_versionCode, 0); Loading Loading @@ -2750,9 +2753,11 @@ public class PackageImpl implements ParsedPackage, AndroidPackageInternal, } private void assignDerivedFields2() { mBaseAppInfoFlags = PackageInfoUtils.appInfoFlags(this, null); mBaseAppInfoPrivateFlags = PackageInfoUtils.appInfoPrivateFlags(this, null); mBaseAppInfoPrivateFlagsExt = PackageInfoUtils.appInfoPrivateFlagsExt(this, null); mBaseAppInfoFlags = AppInfoUtils.appInfoFlags(this); mBaseAppInfoPrivateFlags = AppInfoUtils.appInfoPrivateFlags(this); mBaseAppInfoPrivateFlagsExt = AppInfoUtils.appInfoPrivateFlagsExt(this, mCallback == null ? false : mCallback.getHiddenApiWhitelistedApps().contains(this.packageName)); String baseAppDataDir = Environment.getDataDirectoryPath(getVolumeUuid()) + File.separator; String systemUserSuffix = File.separator + UserHandle.USER_SYSTEM + File.separator; mBaseAppDataCredentialProtectedDirForSystemUser = TextUtils.safeIntern( Loading Loading @@ -3087,7 +3092,7 @@ public class PackageImpl implements ParsedPackage, AndroidPackageInternal, appInfo.primaryCpuAbi = primaryCpuAbi; appInfo.secondaryCpuAbi = secondaryCpuAbi; appInfo.secondaryNativeLibraryDir = secondaryNativeLibraryDir; appInfo.seInfoUser = SELinuxUtil.COMPLETE_STR; appInfo.seInfoUser = SEInfoUtil.COMPLETE_STR; appInfo.uid = uid; return appInfo; } Loading