Merge "Fix flaky AppFocusTest" into rvc-dev
diff --git a/tests/carservice_test/src/com/android/car/AppFocusTest.java b/tests/carservice_test/src/com/android/car/AppFocusTest.java
index c7ee982..390acf2 100644
--- a/tests/carservice_test/src/com/android/car/AppFocusTest.java
+++ b/tests/carservice_test/src/com/android/car/AppFocusTest.java
@@ -46,6 +46,7 @@
         manager.requestAppFocus(CarAppFocusManager.APP_FOCUS_TYPE_NAVIGATION, ownershipListener);
         listener.waitForFocusChangeAndAssert(DEFAULT_WAIT_TIMEOUT_MS,
                 CarAppFocusManager.APP_FOCUS_TYPE_NAVIGATION, true);
+        listener.resetWait();
         manager.abandonAppFocus(ownershipListener, CarAppFocusManager.APP_FOCUS_TYPE_NAVIGATION);
         listener.waitForFocusChangeAndAssert(DEFAULT_WAIT_TIMEOUT_MS,
                 CarAppFocusManager.APP_FOCUS_TYPE_NAVIGATION, false);
@@ -57,7 +58,7 @@
         private boolean mLastChangeAppActive;
         private final Semaphore mChangeWait = new Semaphore(0);
 
-        public boolean waitForFocusChangeAndAssert(long timeoutMs, int expectedAppType,
+        private boolean waitForFocusChangeAndAssert(long timeoutMs, int expectedAppType,
                 boolean expectedAppActive) throws Exception {
             if (!mChangeWait.tryAcquire(timeoutMs, TimeUnit.MILLISECONDS)) {
                 return false;
@@ -67,6 +68,10 @@
             return true;
         }
 
+        private void resetWait() {
+            mChangeWait.drainPermits();
+        }
+
         @Override
         public void onAppFocusChanged(int appType, boolean active) {
             Log.i(TAG, "onAppFocusChanged appType=" + appType + " active=" + active);