summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2020-01-08 03:26:00 +0000
committerHarry Zhang <harrytczhang@google.com>2020-01-08 22:03:59 +0000
commitc258f5645485edff5e4e8f487fb2f87277491096 (patch)
tree6204430aff1d8006cc7327554105bd883abaeec1
parent31b44b732f07c7c66d598b61cdae56de6b9f9683 (diff)
downloadplatform_testing-c258f5645485edff5e4e8f487fb2f87277491096.tar.gz
Optionally turn screen back on after the ScreenOff CUJ.
Also updated the CUJ to use platform-test-options. Bug: 144721773, 118122395 Test: Manual Change-Id: Id0bff1ed3bf93bf91a82147d423de4dfebac4614 (cherry picked from commit 706448be9cb8d00abb389936dafe8ba80ac36fd2)
-rw-r--r--tests/health/scenarios/src/android/platform/test/scenario/system/ScreenOff.java37
1 files changed, 21 insertions, 16 deletions
diff --git a/tests/health/scenarios/src/android/platform/test/scenario/system/ScreenOff.java b/tests/health/scenarios/src/android/platform/test/scenario/system/ScreenOff.java
index d3dc78022..1f5e23475 100644
--- a/tests/health/scenarios/src/android/platform/test/scenario/system/ScreenOff.java
+++ b/tests/health/scenarios/src/android/platform/test/scenario/system/ScreenOff.java
@@ -18,44 +18,49 @@ package android.platform.test.scenario.system;
import android.os.RemoteException;
import android.os.SystemClock;
+import android.platform.test.option.BooleanOption;
+import android.platform.test.option.LongOption;
import android.platform.test.scenario.annotation.Scenario;
import android.support.test.uiautomator.UiDevice;
import androidx.test.InstrumentationRegistry;
+import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
-/**
- * Shuts the screen off and waits for a specified amount of time.
- */
+/** Shuts the screen off and waits for a specified amount of time. */
@Scenario
@RunWith(JUnit4.class)
public class ScreenOff {
- private static final String DURATION_OPTION = "screenOffDurationMs";
- private static final String DURATION_DEFAULT = "1000";
+ @Rule public LongOption mDurationMs = new LongOption("screenOffDurationMs").setDefault(1000L);
+
+ @Rule
+ public BooleanOption mTurnScreenBackOn =
+ new BooleanOption("screenOffTurnScreenBackOnAfterTest").setDefault(false);
- private long mDurationMs = 0L;
private UiDevice mDevice;
@Before
public void setUp() {
mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
- String durationMsString =
- InstrumentationRegistry.getArguments().getString(DURATION_OPTION, DURATION_DEFAULT);
- try {
- mDurationMs = Long.parseLong(durationMsString);
- } catch (NumberFormatException e) {
- throw new IllegalArgumentException(
- String.format(
- "Failed to parse option %s: %s", DURATION_OPTION, durationMsString));
- }
}
@Test
public void testScreenOff() throws RemoteException {
mDevice.sleep();
- SystemClock.sleep(mDurationMs);
+ SystemClock.sleep(mDurationMs.get());
+ }
+
+ @After
+ public void tearDown() throws RemoteException {
+ if (mTurnScreenBackOn.get()) {
+ mDevice.wakeUp();
+ mDevice.waitForIdle();
+ mDevice.pressMenu();
+ mDevice.waitForIdle();
+ }
}
}