Don't wait forever to receive the intent from TestApp

Previously, to receive results from testApp, we would wait until the
latch counted down to zero. If testApp crashes, we will not receive an
intent from testApp, hence we wait forever. Device test would only
terminate when host test ends device test, which takes 10 mins. Since we
don't try to recover testApp crash, we can terminate device test if no
intent recieved within a certain time. This helps in early exit on
unexpected testApp error/exception/crash.

Added 10 seconds timeout for receiving intent from TestApp.

Bug: 158785221
Test: atest CtsScopedStorageHostTest
Change-Id: I49a6b8833bbd8ce1ae6234b4cb79f9648d3b4eb9
Merged-In: I49a6b8833bbd8ce1ae6234b4cb79f9648d3b4eb9
(cherry picked from commit 60f2b09c9d2685bf13118a36aa56e910c60bca62)
diff --git a/hostsidetests/scopedstorage/libs/ScopedStorageTestLib/src/android/scopedstorage/cts/lib/TestUtils.java b/hostsidetests/scopedstorage/libs/ScopedStorageTestLib/src/android/scopedstorage/cts/lib/TestUtils.java
index d43500a..f17cbbe 100644
--- a/hostsidetests/scopedstorage/libs/ScopedStorageTestLib/src/android/scopedstorage/cts/lib/TestUtils.java
+++ b/hostsidetests/scopedstorage/libs/ScopedStorageTestLib/src/android/scopedstorage/cts/lib/TestUtils.java
@@ -931,7 +931,11 @@
         intent.putExtra(INTENT_EXTRA_PATH, dirPath);
         intent.addCategory(Intent.CATEGORY_LAUNCHER);
         getContext().startActivity(intent);
-        latch.await();
+        if (!latch.await(POLLING_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)) {
+            final String errorMessage = "Timed out while waiting to receive " + actionName
+                    + " intent from " + packageName;
+            throw new TimeoutException(errorMessage);
+        }
         getContext().unregisterReceiver(broadcastReceiver);
     }