Merge "Merge "Merge "Modifies Self-Managed CS binding detection" into oreo-cts-dev am: ad51be6e44" into oreo-mr1-cts-dev am: 811f979208"
diff --git a/tests/tests/telecom/src/android/telecom/cts/CtsConnectionService.java b/tests/tests/telecom/src/android/telecom/cts/CtsConnectionService.java
index d93d431..c9e0c56 100644
--- a/tests/tests/telecom/src/android/telecom/cts/CtsConnectionService.java
+++ b/tests/tests/telecom/src/android/telecom/cts/CtsConnectionService.java
@@ -211,7 +211,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 b057648..e6070ce 100644
--- a/tests/tests/telecom/src/android/telecom/cts/CtsSelfManagedConnectionService.java
+++ b/tests/tests/telecom/src/android/telecom/cts/CtsSelfManagedConnectionService.java
@@ -198,7 +198,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;
}
@@ -207,31 +207,7 @@
* @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);
}
public TestUtils.InvokeCounter getOnCreateIncomingHandoverConnectionCounter() {
diff --git a/tests/tests/telecom/src/android/telecom/cts/TestUtils.java b/tests/tests/telecom/src/android/telecom/cts/TestUtils.java
index 3980f7f..31000de 100644
--- a/tests/tests/telecom/src/android/telecom/cts/TestUtils.java
+++ b/tests/tests/telecom/src/android/telecom/cts/TestUtils.java
@@ -255,17 +255,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 {