Attempt to make waitForIdleHandler reliable. am: 572f1a3185 am: b18bd6bd3d
am: e160fe177d
Change-Id: I2369fbd693b467283232f47703fd471c8ff60c1f
This commit is contained in:
@@ -155,25 +155,13 @@ public class ConnectivityServiceTest extends AndroidTestCase {
|
|||||||
/**
|
/**
|
||||||
* Block until the given handler becomes idle, or until timeoutMs has passed.
|
* Block until the given handler becomes idle, or until timeoutMs has passed.
|
||||||
*/
|
*/
|
||||||
private static void waitForIdleHandler(HandlerThread handler, int timeoutMs) {
|
private static void waitForIdleHandler(HandlerThread handlerThread, int timeoutMs) {
|
||||||
final ConditionVariable cv = new ConditionVariable();
|
final ConditionVariable cv = new ConditionVariable();
|
||||||
final MessageQueue queue = handler.getLooper().getQueue();
|
final Handler handler = new Handler(handlerThread.getLooper());
|
||||||
final IdleHandler idleHandler = () -> {
|
handler.post(() -> cv.open());
|
||||||
synchronized (queue) {
|
|
||||||
cv.open();
|
|
||||||
return false; // Remove the idleHandler.
|
|
||||||
}
|
|
||||||
};
|
|
||||||
synchronized (queue) {
|
|
||||||
if (queue.isIdle()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
queue.addIdleHandler(idleHandler);
|
|
||||||
}
|
|
||||||
if (!cv.block(timeoutMs)) {
|
if (!cv.block(timeoutMs)) {
|
||||||
fail("HandlerThread " + handler.getName() +
|
fail("HandlerThread " + handlerThread.getName() +
|
||||||
" did not become idle after " + timeoutMs + " ms");
|
" did not become idle after " + timeoutMs + " ms");
|
||||||
queue.removeIdleHandler(idleHandler);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user