From aad54ab68640afff2e0987ec09cba489878f5b2b Mon Sep 17 00:00:00 2001 From: vadimt Date: Tue, 7 Jan 2020 14:54:53 -0800 Subject: [PATCH] Using grantRuntimePermission() "pm grant" is considered obsolete Bug: 145686584 Change-Id: Ieeec76b2fdb666f89957a0a3039956bd69e9f315 --- tests/AndroidManifest-common.xml | 1 + .../tapl/LauncherInstrumentation.java | 22 ++++++------------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/tests/AndroidManifest-common.xml b/tests/AndroidManifest-common.xml index 56eca6dd58..1c8f095810 100644 --- a/tests/AndroidManifest-common.xml +++ b/tests/AndroidManifest-common.xml @@ -22,6 +22,7 @@ + diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java index b715de0b68..d57de096c0 100644 --- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java +++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java @@ -183,13 +183,8 @@ public final class LauncherInstrumentation { .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 @@ public final class LauncherInstrumentation { 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)