diff options
author | Andrei Onea <andreionea@google.com> | 2020-01-15 19:09:52 +0000 |
---|---|---|
committer | Andrei Onea <andreionea@google.com> | 2020-01-23 19:03:35 +0000 |
commit | 855abe626de8178f5957a7218e1e6dc5b2cc71c6 (patch) | |
tree | c3bece197e967a3f774777b038f2568be442d18c /tests/PlatformCompatGating | |
parent | 09a87d3f9f007d89232b8d29e772d960dcb040e5 (diff) |
Add permissions for using PlatformCompat methods
READ_COMPAT_CHANGE_CONFIG is required to read the current state of the
config, and OVERRIDE_COMPAT_CHANGE_CONFIG is required to add overrides.
Bug: 142650523
Test: atest PlatformCompatTest
Change-Id: I1c8cbb656e065a3273518e4cc2f4cc704c58f69f
Diffstat (limited to 'tests/PlatformCompatGating')
-rw-r--r-- | tests/PlatformCompatGating/Android.bp | 1 | ||||
-rw-r--r-- | tests/PlatformCompatGating/test-rules/src/android/compat/testing/PlatformCompatChangeRule.java | 7 |
2 files changed, 7 insertions, 1 deletions
diff --git a/tests/PlatformCompatGating/Android.bp b/tests/PlatformCompatGating/Android.bp index 5e9ef8efc402..609896ea9e95 100644 --- a/tests/PlatformCompatGating/Android.bp +++ b/tests/PlatformCompatGating/Android.bp @@ -18,7 +18,6 @@ android_test { name: "PlatformCompatGating", // Only compile source java files in this apk. srcs: ["src/**/*.java"], - certificate: "platform", libs: [ "android.test.runner", "android.test.base", diff --git a/tests/PlatformCompatGating/test-rules/src/android/compat/testing/PlatformCompatChangeRule.java b/tests/PlatformCompatGating/test-rules/src/android/compat/testing/PlatformCompatChangeRule.java index 932ec643d478..c00aa2ac25b3 100644 --- a/tests/PlatformCompatGating/test-rules/src/android/compat/testing/PlatformCompatChangeRule.java +++ b/tests/PlatformCompatGating/test-rules/src/android/compat/testing/PlatformCompatChangeRule.java @@ -16,7 +16,9 @@ package android.compat.testing; +import android.Manifest; import android.app.Instrumentation; +import android.app.UiAutomation; import android.compat.Compatibility; import android.compat.Compatibility.ChangeConfig; import android.content.Context; @@ -83,12 +85,16 @@ public class PlatformCompatChangeRule extends CoreCompatChangeRule { @Override public void evaluate() throws Throwable { Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation(); + UiAutomation uiAutomation = instrumentation.getUiAutomation(); String packageName = instrumentation.getTargetContext().getPackageName(); IPlatformCompat platformCompat = IPlatformCompat.Stub .asInterface(ServiceManager.getService(Context.PLATFORM_COMPAT_SERVICE)); if (platformCompat == null) { throw new IllegalStateException("Could not get IPlatformCompat service!"); } + uiAutomation.adoptShellPermissionIdentity( + Manifest.permission.READ_COMPAT_CHANGE_CONFIG, + Manifest.permission.OVERRIDE_COMPAT_CHANGE_CONFIG); Compatibility.setOverrides(mConfig); try { platformCompat.setOverridesForTest(new CompatibilityChangeConfig(mConfig), @@ -101,6 +107,7 @@ public class PlatformCompatChangeRule extends CoreCompatChangeRule { } catch (RemoteException e) { throw new RuntimeException("Could not call IPlatformCompat binder method!", e); } finally { + uiAutomation.dropShellPermissionIdentity(); Compatibility.clearOverrides(); } } |