Merge "Merge "Modifies Self-Managed CS binding detection" into oreo-cts-dev am: ad51be6e44" into oreo-mr1-cts-dev
diff --git a/tests/tests/telecom/src/android/telecom/cts/CtsConnectionService.java b/tests/tests/telecom/src/android/telecom/cts/CtsConnectionService.java
index 329031a..b0caaf2 100644
--- a/tests/tests/telecom/src/android/telecom/cts/CtsConnectionService.java
+++ b/tests/tests/telecom/src/android/telecom/cts/CtsConnectionService.java
@@ -193,7 +193,6 @@
     }
 
     public static boolean waitForUnBinding() {
-        sServiceUnBoundLatch = TestUtils.waitForLock(sServiceUnBoundLatch);
-        return sServiceUnBoundLatch != null;
+        return TestUtils.waitForLatchCountDown(sServiceUnBoundLatch);
     }
 }
diff --git a/tests/tests/telecom/src/android/telecom/cts/CtsSelfManagedConnectionService.java b/tests/tests/telecom/src/android/telecom/cts/CtsSelfManagedConnectionService.java
index fada275..1334061 100644
--- a/tests/tests/telecom/src/android/telecom/cts/CtsSelfManagedConnectionService.java
+++ b/tests/tests/telecom/src/android/telecom/cts/CtsSelfManagedConnectionService.java
@@ -154,7 +154,7 @@
      *      timeout expired without the lock being released.
      */
     public boolean waitForUpdate(int lock) {
-        mLocks[lock] = waitForLock(mLocks[lock]);
+        mLocks[lock] = TestUtils.waitForLock(mLocks[lock]);
         return mLocks[lock] != null;
     }
 
@@ -163,30 +163,6 @@
      * @return {@code true} if binding happened within the time limit, or {@code false} otherwise.
      */
     public static boolean waitForBinding() {
-        sBindingLock = waitForLock(sBindingLock);
-        return sBindingLock != null;
-    }
-
-    /**
-     * Given a {@link CountDownLatch}, wait for the latch to reach zero for 5 seconds.  If the lock
-     * was released, return a new instance.  Otherwise, return null to indicate that the timeout
-     * expired without the lock being released.
-     *
-     * @param lock The lock to wait on.
-     * @return {@code true} if the lock was released, and {@code false} if it failed to be released.
-     */
-    private static CountDownLatch waitForLock(CountDownLatch lock) {
-        boolean success;
-        try {
-            success = lock.await(5000, TimeUnit.MILLISECONDS);
-        } catch (InterruptedException ie) {
-            return null;
-        }
-
-        if (success) {
-            return new CountDownLatch(1);
-        } else {
-            return null;
-        }
+        return TestUtils.waitForLatchCountDown(sBindingLock);
     }
 }
diff --git a/tests/tests/telecom/src/android/telecom/cts/TestUtils.java b/tests/tests/telecom/src/android/telecom/cts/TestUtils.java
index 81638f9..f3c54b3 100644
--- a/tests/tests/telecom/src/android/telecom/cts/TestUtils.java
+++ b/tests/tests/telecom/src/android/telecom/cts/TestUtils.java
@@ -223,17 +223,36 @@
         }
     }
 
-    public static CountDownLatch waitForLock(CountDownLatch lock) {
-        boolean success;
-        try {
-            if (lock == null) {
-                return null;
-            }
-            success = lock.await(5000, TimeUnit.MILLISECONDS);
-        } catch (InterruptedException ie) {
-            return null;
+    /**
+     * Waits for the {@link CountDownLatch} to count down to 0 and then returns without reseting
+     * the latch.
+     * @param lock the latch that the system will wait on.
+     * @return true if the latch was released successfully, false if the latch timed out before
+     * resetting.
+     */
+    public static boolean waitForLatchCountDown(CountDownLatch lock) {
+        if (lock == null) {
+            return false;
         }
 
+        boolean success;
+        try {
+            success = lock.await(5000, TimeUnit.MILLISECONDS);
+        } catch (InterruptedException ie) {
+            return false;
+        }
+
+        return success;
+    }
+
+    /**
+     * Waits for the {@link CountDownLatch} to count down to 0 and then returns a new reset latch.
+     * @param lock The lock that will await a countDown to 0.
+     * @return a new reset {@link CountDownLatch} if the lock successfully counted down to 0 or
+     * null if the operation timed out.
+     */
+    public static CountDownLatch waitForLock(CountDownLatch lock) {
+        boolean success = waitForLatchCountDown(lock);
         if (success) {
             return new CountDownLatch(1);
         } else {