Bug fix SignificantMotion test.

Bug: 23206214
Change-Id: I5c1cd2ef8d211aba51b0708a506252be560f4c10
diff --git a/apps/CtsVerifier/src/com/android/cts/verifier/sensors/SignificantMotionTestActivity.java b/apps/CtsVerifier/src/com/android/cts/verifier/sensors/SignificantMotionTestActivity.java
index f8f1a9a..6dbf8cc 100644
--- a/apps/CtsVerifier/src/com/android/cts/verifier/sensors/SignificantMotionTestActivity.java
+++ b/apps/CtsVerifier/src/com/android/cts/verifier/sensors/SignificantMotionTestActivity.java
@@ -302,8 +302,9 @@
      * It cannot be reused.
      */
     private class TriggerVerifier extends TriggerEventListener {
-        private volatile CountDownLatch mCountDownLatch = new CountDownLatch(1);
+        private volatile CountDownLatch mCountDownLatch;
         private volatile TriggerEventRegistry mEventRegistry;
+        private volatile long mTimestampForTriggeredEvent = 0;
 
         // TODO: refactor out if needed
         private class TriggerEventRegistry {
@@ -329,10 +330,7 @@
         }
 
         public long getTimeStampForTriggerEvent() {
-            if (mEventRegistry != null && mEventRegistry.triggerEvent != null) {
-                return mEventRegistry.triggerEvent.timestamp;
-            }
-            return 0;
+            return mTimestampForTriggeredEvent;
         }
 
         public String verifyEventTriggered() throws Throwable {
@@ -388,9 +386,16 @@
         }
 
         private TriggerEventRegistry awaitForEvent() throws InterruptedException {
+            mCountDownLatch = new CountDownLatch(1);
             mCountDownLatch.await(TRIGGER_MAX_DELAY_SECONDS, TimeUnit.SECONDS);
             TriggerEventRegistry registry = mEventRegistry;
 
+            // Save the last timestamp when the event triggered.
+            if (mEventRegistry != null && mEventRegistry.triggerEvent != null) {
+                mTimestampForTriggeredEvent = mEventRegistry.triggerEvent.timestamp;
+            }
+
+            mEventRegistry = null;
             playSound();
             return registry != null ? registry : new TriggerEventRegistry(null, 0);
         }