Using grantRuntimePermission()
"pm grant" is considered obsolete
Bug: 145686584
Change-Id: Ieeec76b2fdb666f89957a0a3039956bd69e9f315
diff --git a/tests/AndroidManifest-common.xml b/tests/AndroidManifest-common.xml
index 56eca6d..1c8f095 100644
--- a/tests/AndroidManifest-common.xml
+++ b/tests/AndroidManifest-common.xml
@@ -22,6 +22,7 @@
<uses-permission android:name="android.permission.PACKAGE_USAGE_STATS"/>
<uses-permission android:name="android.permission.READ_LOGS"/>
+ <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS"/>
<application android:debuggable="true">
<uses-library android:name="android.test.runner"/>
diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
index b715de0..d57de09 100644
--- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
+++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
@@ -183,13 +183,8 @@
.authority(testProviderAuthority)
.build();
- try {
- mDevice.executeShellCommand("pm grant " + testPackage +
- " android.permission.WRITE_SECURE_SETTINGS");
- } catch (IOException e) {
- fail(e.toString());
- }
-
+ mInstrumentation.getUiAutomation().grantRuntimePermission(
+ testPackage, "android.permission.WRITE_SECURE_SETTINGS");
PackageManager pm = getContext().getPackageManager();
ProviderInfo pi = pm.resolveContentProvider(
@@ -336,14 +331,11 @@
private String getSystemHealthMessage() {
final String testPackage = getContext().getPackageName();
- try {
- mDevice.executeShellCommand("pm grant " + testPackage +
- " android.permission.READ_LOGS");
- mDevice.executeShellCommand("pm grant " + testPackage +
- " android.permission.PACKAGE_USAGE_STATS");
- } catch (IOException e) {
- e.printStackTrace();
- }
+
+ mInstrumentation.getUiAutomation().grantRuntimePermission(
+ testPackage, "android.permission.READ_LOGS");
+ mInstrumentation.getUiAutomation().grantRuntimePermission(
+ testPackage, "android.permission.PACKAGE_USAGE_STATS");
return mSystemHealthSupplier != null
? mSystemHealthSupplier.apply(START_TIME)