From 2104d72b281ef4ee9f15aef333bd65a03f8f7eb4 Mon Sep 17 00:00:00 2001 From: Adam Bookatz Date: Wed, 29 Jul 2020 15:46:16 -0700 Subject: [PATCH] LauncherInstrumentation enables even when non-system user Attempting to run a tapl test while the device is in a secondary user currently fails because the test app doesn't get enabled for this secondary user. We fix that (at least one issue with it) in this cl. Test: make PlatformScenarioTests; adb root && adb install -r -g ${ANDROID_PRODUCT_OUT}/testcases/PlatformScenarioTests/$(get_build_var TARGET_ARCH)/PlatformScenarioTests.apk adb shell am instrument -w -r -e class android.platform.test.scenario.chrome.OpenApp android.platform.test.scenario/androidx.test.runner.AndroidJUnitRunner (Do this while the current user is SYSTEM as well as Guest) Bug: 162454040 Change-Id: If6d8e545b41eb20e3fed2935c39069ce97d8b6cd --- .../android/launcher3/tapl/LauncherInstrumentation.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java index a77c1c6b70..92ab9b8a16 100644 --- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java +++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java @@ -64,6 +64,7 @@ import androidx.test.uiautomator.Until; import com.android.launcher3.ResourceUtils; import com.android.launcher3.testing.TestProtocol; +import com.android.systemui.shared.system.ContextUtils; import com.android.systemui.shared.system.QuickStepContract; import org.junit.Assert; @@ -238,11 +239,12 @@ public final class LauncherInstrumentation { if (pm.getComponentEnabledSetting(cn) != COMPONENT_ENABLED_STATE_ENABLED) { if (TestHelpers.isInLauncherProcess()) { - getContext().getPackageManager().setComponentEnabledSetting( - cn, COMPONENT_ENABLED_STATE_ENABLED, DONT_KILL_APP); + pm.setComponentEnabledSetting(cn, COMPONENT_ENABLED_STATE_ENABLED, DONT_KILL_APP); } else { try { - mDevice.executeShellCommand("pm enable " + cn.flattenToString()); + final int userId = ContextUtils.getUserId(getContext()); + mDevice.executeShellCommand( + "pm enable --user " + userId + " " + cn.flattenToString()); } catch (IOException e) { fail(e.toString()); }