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

Commit b61afc7f authored by Piotr Wilczyński's avatar Piotr Wilczyński Committed by Android (Google) Code Review
Browse files

Merge "TestLooperManager in DisplayManagerServiceTest" into main

parents f121b48e 82aa8ccd
Loading
Loading
Loading
Loading
+128 −135

File changed.

Preview size limit exceeded, changes collapsed.

+23 −0
Original line number Diff line number Diff line
@@ -15,6 +15,8 @@
 */
package com.android.server.testutils;

import android.os.Message;
import android.os.TestLooperManager;
import android.test.MoreAsserts;

import junit.framework.Assert;
@@ -60,4 +62,25 @@ public class TestUtils {
            throw new AssertionError("Unexpected invocation: " + invocation);
        });
    }

    /**
     * Dispatch all the ready looper messages. The loopers might depend on each other and send
     * messages to each other, so this method loops through all of them until there are no ready
     * messages left in any of them.
     * @param tlms The test looper managers
     */
    public static void flushLoopers(TestLooperManager... tlms) {
        boolean noMoreMessages;
        do {
            noMoreMessages = true;
            for (TestLooperManager tlm : tlms) {
                Message m = tlm.poll();
                if (m != null) {
                    tlm.execute(m);
                    tlm.recycle(m);
                    noMoreMessages = false;
                }
            }
        } while(!noMoreMessages);
    }
}