diff options
Diffstat (limited to 'android/content/pm/ApplicationInfo.java')
-rw-r--r-- | android/content/pm/ApplicationInfo.java | 102 |
1 files changed, 85 insertions, 17 deletions
diff --git a/android/content/pm/ApplicationInfo.java b/android/content/pm/ApplicationInfo.java index e85058df..d65e051b 100644 --- a/android/content/pm/ApplicationInfo.java +++ b/android/content/pm/ApplicationInfo.java @@ -26,6 +26,7 @@ import android.content.Context; import android.content.pm.PackageManager.NameNotFoundException; import android.content.res.Resources; import android.graphics.drawable.Drawable; +import android.os.Build; import android.os.Environment; import android.os.Parcel; import android.os.Parcelable; @@ -590,26 +591,33 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable { public static final int PRIVATE_FLAG_VIRTUAL_PRELOAD = 1 << 16; /** - * Value for {@linl #privateFlags}: whether this app is pre-installed on the + * Value for {@link #privateFlags}: whether this app is pre-installed on the * OEM partition of the system image. * @hide */ public static final int PRIVATE_FLAG_OEM = 1 << 17; /** - * Value for {@linl #privateFlags}: whether this app is pre-installed on the + * Value for {@link #privateFlags}: whether this app is pre-installed on the * vendor partition of the system image. * @hide */ public static final int PRIVATE_FLAG_VENDOR = 1 << 18; /** - * Value for {@linl #privateFlags}: whether this app is pre-installed on the + * Value for {@link #privateFlags}: whether this app is pre-installed on the * product partition of the system image. * @hide */ public static final int PRIVATE_FLAG_PRODUCT = 1 << 19; + /** + * Value for {@link #privateFlags}: whether this app is signed with the + * platform key. + * @hide + */ + public static final int PRIVATE_FLAG_SIGNED_WITH_PLATFORM_KEY = 1 << 20; + /** @hide */ @IntDef(flag = true, prefix = { "PRIVATE_FLAG_" }, value = { PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE, @@ -629,6 +637,7 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable { PRIVATE_FLAG_PRIVILEGED, PRIVATE_FLAG_PRODUCT, PRIVATE_FLAG_REQUIRED_FOR_SYSTEM_USER, + PRIVATE_FLAG_SIGNED_WITH_PLATFORM_KEY, PRIVATE_FLAG_STATIC_SHARED_LIBRARY, PRIVATE_FLAG_VENDOR, PRIVATE_FLAG_VIRTUAL_PRELOAD, @@ -904,7 +913,17 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable { * The app's declared version code. * @hide */ - public long versionCode; + public long longVersionCode; + + /** + * An integer representation of the app's declared version code. This is being left in place as + * some apps were using reflection to access it before the move to long in + * {@link android.os.Build.VERSION_CODES#P} + * @deprecated Use {@link #longVersionCode} instead. + * @hide + */ + @Deprecated + public int versionCode; /** * The user-visible SDK version (ex. 26) of the framework against which the application claims @@ -1114,11 +1133,12 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable { */ public static final int HIDDEN_API_ENFORCEMENT_NONE = 0; /** - * Light grey list enforcement, the strictest option. Enforces the light grey, dark grey and - * black lists. + * No API enforcement, but enable the detection logic and warnings. Observed behaviour is the + * same as {@link #HIDDEN_API_ENFORCEMENT_NONE} but you may see warnings in the log when APIs + * are accessed. * @hide * */ - public static final int HIDDEN_API_ENFORCEMENT_ALL_LISTS = 1; + public static final int HIDDEN_API_ENFORCEMENT_JUST_WARN = 1; /** * Dark grey list enforcement. Enforces the dark grey and black lists * @hide @@ -1140,14 +1160,15 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable { @IntDef(prefix = { "HIDDEN_API_ENFORCEMENT_" }, value = { HIDDEN_API_ENFORCEMENT_DEFAULT, HIDDEN_API_ENFORCEMENT_NONE, - HIDDEN_API_ENFORCEMENT_ALL_LISTS, + HIDDEN_API_ENFORCEMENT_JUST_WARN, HIDDEN_API_ENFORCEMENT_DARK_GREY_AND_BLACK, HIDDEN_API_ENFORCEMENT_BLACK, }) @Retention(RetentionPolicy.SOURCE) public @interface HiddenApiEnforcementPolicy {} - private boolean isValidHiddenApiEnforcementPolicy(int policy) { + /** @hide */ + public static boolean isValidHiddenApiEnforcementPolicy(int policy) { return policy >= HIDDEN_API_ENFORCEMENT_DEFAULT && policy <= HIDDEN_API_ENFORCEMENT_MAX; } @@ -1214,7 +1235,7 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable { pw.println(prefix + "enabled=" + enabled + " minSdkVersion=" + minSdkVersion + " targetSdkVersion=" + targetSdkVersion - + " versionCode=" + versionCode + + " versionCode=" + longVersionCode + " targetSandboxVersion=" + targetSandboxVersion); if ((dumpFlags & DUMP_FLAG_DETAILS) != 0) { if (manageSpaceActivityName != null) { @@ -1287,7 +1308,7 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable { proto.write(ApplicationInfoProto.Version.ENABLED, enabled); proto.write(ApplicationInfoProto.Version.MIN_SDK_VERSION, minSdkVersion); proto.write(ApplicationInfoProto.Version.TARGET_SDK_VERSION, targetSdkVersion); - proto.write(ApplicationInfoProto.Version.VERSION_CODE, versionCode); + proto.write(ApplicationInfoProto.Version.VERSION_CODE, longVersionCode); proto.write(ApplicationInfoProto.Version.TARGET_SANDBOX_VERSION, targetSandboxVersion); proto.end(versionToken); @@ -1421,7 +1442,7 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable { uid = orig.uid; minSdkVersion = orig.minSdkVersion; targetSdkVersion = orig.targetSdkVersion; - versionCode = orig.versionCode; + setVersionCode(orig.longVersionCode); enabled = orig.enabled; enabledSetting = orig.enabledSetting; installLocation = orig.installLocation; @@ -1495,7 +1516,7 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable { dest.writeInt(uid); dest.writeInt(minSdkVersion); dest.writeInt(targetSdkVersion); - dest.writeLong(versionCode); + dest.writeLong(longVersionCode); dest.writeInt(enabled ? 1 : 0); dest.writeInt(enabledSetting); dest.writeInt(installLocation); @@ -1566,7 +1587,7 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable { uid = source.readInt(); minSdkVersion = source.readInt(); targetSdkVersion = source.readInt(); - versionCode = source.readLong(); + setVersionCode(source.readLong()); enabled = source.readInt() != 0; enabledSetting = source.readInt(); installLocation = source.readInt(); @@ -1658,17 +1679,26 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable { return SystemConfig.getInstance().getHiddenApiWhitelistedApps().contains(packageName); } + private boolean isAllowedToUseHiddenApis() { + return isSignedWithPlatformKey() + || (isPackageWhitelistedForHiddenApis() && (isSystemApp() || isUpdatedSystemApp())); + } + /** * @hide */ public @HiddenApiEnforcementPolicy int getHiddenApiEnforcementPolicy() { + if (isAllowedToUseHiddenApis()) { + return HIDDEN_API_ENFORCEMENT_NONE; + } if (mHiddenApiPolicy != HIDDEN_API_ENFORCEMENT_DEFAULT) { return mHiddenApiPolicy; } - if (isPackageWhitelistedForHiddenApis() && (isSystemApp() || isUpdatedSystemApp())) { - return HIDDEN_API_ENFORCEMENT_NONE; + if (targetSdkVersion < Build.VERSION_CODES.P) { + return HIDDEN_API_ENFORCEMENT_BLACK; + } else { + return HIDDEN_API_ENFORCEMENT_DARK_GREY_AND_BLACK; } - return HIDDEN_API_ENFORCEMENT_BLACK; } /** @@ -1682,6 +1712,39 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable { } /** + * Updates the hidden API enforcement policy for this app from the given values, if appropriate. + * + * This will have no effect if this app is not subject to hidden API enforcement, i.e. if it + * is on the package whitelist. + * + * @param policyPreP configured policy for pre-P apps, or {@link + * #HIDDEN_API_ENFORCEMENT_DEFAULT} if nothing configured. + * @param policyP configured policy for apps targeting P or later, or {@link + * #HIDDEN_API_ENFORCEMENT_DEFAULT} if nothing configured. + * @hide + */ + public void maybeUpdateHiddenApiEnforcementPolicy( + @HiddenApiEnforcementPolicy int policyPreP, @HiddenApiEnforcementPolicy int policyP) { + if (isPackageWhitelistedForHiddenApis()) { + return; + } + if (targetSdkVersion < Build.VERSION_CODES.P) { + setHiddenApiEnforcementPolicy(policyPreP); + } else if (targetSdkVersion >= Build.VERSION_CODES.P) { + setHiddenApiEnforcementPolicy(policyP); + } + + } + + /** + * @hide + */ + public void setVersionCode(long newVersionCode) { + longVersionCode = newVersionCode; + versionCode = (int) newVersionCode; + } + + /** * @hide */ @Override @@ -1758,6 +1821,11 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable { } /** @hide */ + public boolean isSignedWithPlatformKey() { + return (privateFlags & ApplicationInfo.PRIVATE_FLAG_SIGNED_WITH_PLATFORM_KEY) != 0; + } + + /** @hide */ @TestApi public boolean isPrivilegedApp() { return (privateFlags & ApplicationInfo.PRIVATE_FLAG_PRIVILEGED) != 0; |