CtsVerifier: add countdown to make off-body test easier

Bug: 62354427
Test: ran off-body sensor test

Change-Id: I540bc5a40d70a59f7260ffa55cf2cdb1dd671aeb
diff --git a/apps/CtsVerifier/res/values/strings.xml b/apps/CtsVerifier/res/values/strings.xml
index 95f4d60..c43ac31 100755
--- a/apps/CtsVerifier/res/values/strings.xml
+++ b/apps/CtsVerifier/res/values/strings.xml
@@ -937,7 +937,8 @@
     <string name="snsr_offbody_state_change">Offbody state changed to %1$d. Timestamp=%2$d.</string>
     <string name="snsr_start_offbody_sensor_test_instr">Put watch on your wrist and then click Next button.</string>
     <string name="snsr_start_onbody_sensor_test_instr">Remove the watch from your wrist and then click Next button.</string>
-    <string name="snsr_offbody_detect_test_instr">Click Next button, then immediate remove the watch from your wrist.</string>
+    <string name="snsr_offbody_detect_test_instr">Click Next button, then immediate remove the watch from your wrist after the countdown reaches 0.</string>
+    <string name="snsr_offbody_detect_test_countdown">Countdown: %1$d.</string>
     <string name="snsr_onbody_detect_test_instr">Click Next button, then immediately attach the watch on your wrist.</string>
     <string name="snsr_ap_wake_offbody_detect_test_instr">Click Next button, then palm the screen. Wait a few seconds after screen blackens, then remove watch from wrist.</string>
 
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/sensors/OffBodySensorTestActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/sensors/OffBodySensorTestActivity.java
index c3c976e..8318d16 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/sensors/OffBodySensorTestActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/sensors/OffBodySensorTestActivity.java
@@ -28,7 +28,6 @@
 import android.hardware.cts.helpers.SensorNotSupportedException;
 import android.hardware.cts.helpers.SuspendStateMonitor;
 import android.os.PowerManager;
-import android.os.PowerManager.WakeLock;
 import android.os.SystemClock;
 import android.support.v4.content.LocalBroadcastManager;
 import android.util.Log;
@@ -55,10 +54,12 @@
     private static String ACTION_ALARM = "OffBodySensorTestActivity.ACTION_ALARM";
     private static final int MAX_OFF_BODY_EVENT_LATENCY_MS = 1000;
     private static final int MAX_ON_BODY_EVENT_LATENCY_MS = 5000;
+    private static final int COUNTDOWN_INTERVAL_MS = 1000;
     private static final int LLOB_EVENT_MAX_DELAY_SEC = 20;
     private static final long MAX_ALLOWED_DELAY_MS = TimeUnit.SECONDS.toMillis(1);
     private static final long RESULT_REPORT_SHOW_TIME_MS = TimeUnit.SECONDS.toMillis(5);
     private static final int OFFBODY_EVENT_VALUES_LENGTH = 1;
+    private static final int COUNTDOWN_NUM_INTERVALS = 3;
 
     private static final float OFF_BODY_EVENT_VALUE = 0;
     private static final float ON_BODY_EVENT_VALUE = 1;
@@ -423,6 +424,18 @@
             // Instruct user on how to perform offbody detect test
             logger.logInstructions(R.string.snsr_offbody_detect_test_instr);
             waitForUserToBegin();
+
+            // Count down before actually starting, leaving time to react after pressing the Next
+            // button.
+            for (int i = 0; i < COUNTDOWN_NUM_INTERVALS; i++) {
+                try {
+                    Thread.sleep(COUNTDOWN_INTERVAL_MS);
+                } catch (InterruptedException e) {
+                    // Ignore the interrupt and continue counting down.
+                }
+                logger.logInstructions(R.string.snsr_offbody_detect_test_countdown,
+                        COUNTDOWN_NUM_INTERVALS - i - 1);
+            }
             mTestStartTimestampMs = SystemClock.elapsedRealtime();
 
             // Verify off-body event latency is within spec