am a41d414: AI 147545: CTS: Handle timeout issues in unexpected tests

Merge commit 'a41d41458defd0cb87fd167b88b9d1cecf4f51dc' into donut

* commit 'a41d41458defd0cb87fd167b88b9d1cecf4f51dc':
  AI 147545: CTS: Handle timeout issues in unexpected tests
diff --git a/tools/host/src/com/android/cts/TestDevice.java b/tools/host/src/com/android/cts/TestDevice.java
index 70f671d..f4693cb 100644
--- a/tools/host/src/com/android/cts/TestDevice.java
+++ b/tools/host/src/com/android/cts/TestDevice.java
@@ -1409,8 +1409,9 @@
                             CtsTestResult.CODE_FAIL, mFailedMsg, mStackTrace));
                     break;
                 }
-                mTestPackage.notifyTestStatus(mTest, status);
             }
+            // report status even if no matching test was found
+            mTestPackage.notifyTestStatus(mTest, status);
         }
 
         /**
diff --git a/tools/host/src/com/android/cts/TestPackage.java b/tools/host/src/com/android/cts/TestPackage.java
index 719001f..a67a88c 100644
--- a/tools/host/src/com/android/cts/TestPackage.java
+++ b/tools/host/src/com/android/cts/TestPackage.java
@@ -492,7 +492,8 @@
     /**
      * Update Test running status when running in batch mode.
      *
-     * @param test The Test to update.
+     * @param test The Test to update. May be null if a status gets reported on a test that is not
+     * in the test plan.
      * @param status The status to be updated.
      */
     public void notifyTestStatus(final Test test, final String status) {
@@ -503,18 +504,20 @@
         if (mIsInBatchMode) {
             if (status.equals(START)) {
                 if ((mCurrentTest != null) && (mCurrentTest.getResult().isNotExecuted())) {
-                    Log.d("Err: not received FINISH msg for test " + mCurrentTest.getFullName());
+                    Log.d("Err: Missing FINISH msg for test " + mCurrentTest.getFullName());
                     handleMissingFinishEvent();
                 }
                 mCurrentTest = test;
-                print(mCurrentTest.getFullName() + "...");
-                mProgressObserver.start();
-                mTimeOutTimer.restart(new TimeOutTask(this), TimeOutTask.DELAY);
-            } else{
+                if (test != null) {
+                    print(mCurrentTest.getFullName() + "...");
+                    mProgressObserver.start();
+                }
+            } else {
                 mProgressObserver.stop();
-                mTimeOutTimer.cancel(false);
                 mCurrentTest = null;
             }
+            // restart the timer even for unexpected tests
+            mTimeOutTimer.restart(new TimeOutTask(this), TimeOutTask.DELAY);
         }
     }