Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7d8b56b8 authored by Lorenzo Colitti's avatar Lorenzo Colitti Committed by android-build-merger
Browse files

Attempt to make waitForIdleHandler reliable. am: ae3ce81c am: 8780a8af am: 94380838

am: 8e371845

Change-Id: Ia2d7a4405ce60ca99b1ee6c80c0babf93983cf64
parents 026d0b22 8e371845
Loading
Loading
Loading
Loading
+4 −16
Original line number Diff line number Diff line
@@ -155,25 +155,13 @@ public class ConnectivityServiceTest extends AndroidTestCase {
    /**
     * 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 MessageQueue queue = handler.getLooper().getQueue();
        final IdleHandler idleHandler = () -> {
            synchronized (queue) {
                cv.open();
                return false; // Remove the idleHandler.
            }
        };
        synchronized (queue) {
            if (queue.isIdle()) {
                return;
            }
            queue.addIdleHandler(idleHandler);
        }
        final Handler handler = new Handler(handlerThread.getLooper());
        handler.post(() -> cv.open());
        if (!cv.block(timeoutMs)) {
            fail("HandlerThread " + handler.getName() +
            fail("HandlerThread " + handlerThread.getName() +
                    " did not become idle after " + timeoutMs + " ms");
            queue.removeIdleHandler(idleHandler);
        }
    }