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

Commit 82aa8ccd authored by Piotr Wilczyński's avatar Piotr Wilczyński
Browse files

TestLooperManager in DisplayManagerServiceTest

Make sure that both the display looper and the power looper are flushed. Don't use runWithScissors because it will create a deadlock if used with a looper that's managed by a TestLooperManager.

Bug: 416687474
Test: DisplayManagerServiceTest
Flag: EXEMPT bugfix
Change-Id: Ie5c2fee7af2c11f25a934859d2dbb490d38391b4
parent fab8de21
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);
    }
}