summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author David Brazdil <dbrazdil@google.com> 2018-08-31 03:28:30 -0700
committer android-build-merger <android-build-merger@google.com> 2018-08-31 03:28:30 -0700
commita872cb1fcc26d6003d99ea5853ea972f9864ff8c (patch)
treecb3b0708f000a7b515e5c7600d68cb9c2bdde5cb
parentf106a9a2c74d0a80ddd0e0f939943666d464c462 (diff)
parent9446fbbeb8da5eb5761056c4a7ed86628e29df76 (diff)
Merge "Add android:usesNonSdkApi manifest attribute"
am: 9446fbbeb8 Change-Id: I53b5c85fc16cdea5413b35ba4ddeec0d64f22b11
-rw-r--r--core/java/android/content/pm/ApplicationInfo.java16
-rw-r--r--core/java/android/content/pm/PackageParser.java3
-rw-r--r--core/res/res/values/attrs_manifest.xml5
-rw-r--r--core/res/res/values/public.xml5
-rw-r--r--services/core/java/com/android/server/am/ActivityManagerService.java4
5 files changed, 29 insertions, 4 deletions
diff --git a/core/java/android/content/pm/ApplicationInfo.java b/core/java/android/content/pm/ApplicationInfo.java
index c30e306d7a3a..76d06c089a70 100644
--- a/core/java/android/content/pm/ApplicationInfo.java
+++ b/core/java/android/content/pm/ApplicationInfo.java
@@ -1001,6 +1001,13 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
public String appComponentFactory;
/**
+ * Indicates whether this package requires access to non-SDK APIs. Only system apps
+ * and tests are allowed to use this property.
+ * @hide
+ */
+ public boolean usesNonSdkApi;
+
+ /**
* The category of this app. Categories are used to cluster multiple apps
* together into meaningful groups, such as when summarizing battery,
* network, or disk usage. Apps should only define this value when they fit
@@ -1704,8 +1711,13 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
}
private boolean isAllowedToUseHiddenApis() {
- return isSignedWithPlatformKey()
- || (isPackageWhitelistedForHiddenApis() && (isSystemApp() || isUpdatedSystemApp()));
+ if (isSignedWithPlatformKey()) {
+ return true;
+ } else if (isSystemApp() || isUpdatedSystemApp()) {
+ return usesNonSdkApi || isPackageWhitelistedForHiddenApis();
+ } else {
+ return false;
+ }
}
/**
diff --git a/core/java/android/content/pm/PackageParser.java b/core/java/android/content/pm/PackageParser.java
index faf5d78d1252..54cfc8044e91 100644
--- a/core/java/android/content/pm/PackageParser.java
+++ b/core/java/android/content/pm/PackageParser.java
@@ -3588,6 +3588,9 @@ public class PackageParser {
ai.appComponentFactory = buildClassName(ai.packageName, factory, outError);
}
+ ai.usesNonSdkApi = sa.getBoolean(
+ com.android.internal.R.styleable.AndroidManifestApplication_usesNonSdkApi, false);
+
if (outError[0] == null) {
CharSequence pname;
if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
diff --git a/core/res/res/values/attrs_manifest.xml b/core/res/res/values/attrs_manifest.xml
index c4fa190b228d..9e0cff3c4728 100644
--- a/core/res/res/values/attrs_manifest.xml
+++ b/core/res/res/values/attrs_manifest.xml
@@ -1385,6 +1385,8 @@
instantiates items without it.-->
<attr name="appComponentFactory" format="string" />
+ <attr name="usesNonSdkApi" format="boolean" />
+
<!-- The <code>manifest</code> tag is the root of an
<code>AndroidManifest.xml</code> file,
describing the contents of an Android package (.apk) file. One
@@ -1558,6 +1560,9 @@
<attr name="appComponentFactory" />
+ <!-- Declares that this application should be invoked without non-SDK API enforcement -->
+ <attr name="usesNonSdkApi" />
+
</declare-styleable>
<!-- The <code>permission</code> tag declares a security permission that can be
used to control access from other packages to specific components or
diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml
index 997575fc4743..48ba0676c753 100644
--- a/core/res/res/values/public.xml
+++ b/core/res/res/values/public.xml
@@ -2905,6 +2905,11 @@
<public-group type="attr" first-id="0x01010587">
</public-group>
+ <public-group type="attr" first-id="0x0101058d">
+ <!-- @hide For use by platform and tools only. Developers should not specify this value. -->
+ <public name="usesNonSdkApi" />
+ </public-group>
+
<public-group type="style" first-id="0x010302e2">
</public-group>
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index c3782d0d8f63..1dec3bf66ba6 100644
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -21999,8 +21999,8 @@ public class ActivityManagerService extends IActivityManager.Stub
activeInstr.mUiAutomationConnection = uiAutomationConnection;
activeInstr.mResultClass = className;
- boolean disableHiddenApiChecks =
- (flags & INSTRUMENTATION_FLAG_DISABLE_HIDDEN_API_CHECKS) != 0;
+ boolean disableHiddenApiChecks = ai.usesNonSdkApi
+ || (flags & INSTRUMENTATION_FLAG_DISABLE_HIDDEN_API_CHECKS) != 0;
if (disableHiddenApiChecks) {
enforceCallingPermission(android.Manifest.permission.DISABLE_HIDDEN_API_CHECKS,
"disable hidden API checks");