diff options
author | Riddle Hsu <riddlehsu@google.com> | 2020-06-12 22:41:25 +0800 |
---|---|---|
committer | Riddle Hsu <riddlehsu@google.com> | 2020-06-12 22:42:12 +0800 |
commit | 9b1843eae3f8300e1a4d04934e638d559e688d9c (patch) | |
tree | 05f47d78c79a3567a724366cecd1bf731c148aa2 /apct-tests/perftests/windowmanager/src/android/wm/WindowManagerPerfTestBase.java | |
parent | 6dca466770a982bcc34df7813a8f86532eeec4d4 (diff) |
Avoid unexpected screen off during perf testing
The plugged-in type may be BATTERY_PLUGGED_AC in test environment.
And the precondition of the device may have set stay-on with any
type, then it is enough to keep device interactive. Previously
the usb type doesn't match the current state that causes device to
sleep if the screen off timeout has occurred.
Bug: 131727899
Test: atest WmPerfTests
Change-Id: Ia76a0f55e967a2d52fc4b1057b19a8af921260f3
Diffstat (limited to 'apct-tests/perftests/windowmanager/src/android/wm/WindowManagerPerfTestBase.java')
-rw-r--r-- | apct-tests/perftests/windowmanager/src/android/wm/WindowManagerPerfTestBase.java | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/apct-tests/perftests/windowmanager/src/android/wm/WindowManagerPerfTestBase.java b/apct-tests/perftests/windowmanager/src/android/wm/WindowManagerPerfTestBase.java index 9e17e940a06b..655d2f7f8aa7 100644 --- a/apct-tests/perftests/windowmanager/src/android/wm/WindowManagerPerfTestBase.java +++ b/apct-tests/perftests/windowmanager/src/android/wm/WindowManagerPerfTestBase.java @@ -19,11 +19,13 @@ package android.wm; import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; import android.app.Activity; +import android.app.KeyguardManager; import android.app.UiAutomation; import android.content.Context; import android.content.Intent; import android.os.BatteryManager; import android.os.ParcelFileDescriptor; +import android.os.PowerManager; import android.perftests.utils.PerfTestActivity; import android.provider.Settings; @@ -61,24 +63,32 @@ public class WindowManagerPerfTestBase { @BeforeClass public static void setUpOnce() { final Context context = getInstrumentation().getContext(); - sOriginalStayOnWhilePluggedIn = Settings.Global.getInt(context.getContentResolver(), + final int stayOnWhilePluggedIn = Settings.Global.getInt(context.getContentResolver(), Settings.Global.STAY_ON_WHILE_PLUGGED_IN, 0); - // Keep the device awake during testing. - setStayOnWhilePluggedIn(BatteryManager.BATTERY_PLUGGED_USB); + sOriginalStayOnWhilePluggedIn = -1; + if (stayOnWhilePluggedIn != BatteryManager.BATTERY_PLUGGED_ANY) { + sOriginalStayOnWhilePluggedIn = stayOnWhilePluggedIn; + // Keep the device awake during testing. + setStayOnWhilePluggedIn(BatteryManager.BATTERY_PLUGGED_ANY); + } if (!BASE_OUT_PATH.exists()) { executeShellCommand("mkdir -p " + BASE_OUT_PATH); } - // In order to be closer to the real use case. - executeShellCommand("input keyevent KEYCODE_WAKEUP"); - executeShellCommand("wm dismiss-keyguard"); + if (!context.getSystemService(PowerManager.class).isInteractive() + || context.getSystemService(KeyguardManager.class).isKeyguardLocked()) { + executeShellCommand("input keyevent KEYCODE_WAKEUP"); + executeShellCommand("wm dismiss-keyguard"); + } context.startActivity(new Intent(Intent.ACTION_MAIN) .addCategory(Intent.CATEGORY_HOME).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); } @AfterClass public static void tearDownOnce() { - setStayOnWhilePluggedIn(sOriginalStayOnWhilePluggedIn); + if (sOriginalStayOnWhilePluggedIn != -1) { + setStayOnWhilePluggedIn(sOriginalStayOnWhilePluggedIn); + } } private static void setStayOnWhilePluggedIn(int value) { |