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

Commit bb39993b authored by Winson Chung's avatar Winson Chung Committed by Android (Google) Code Review
Browse files

Merge "Skip waiting for idle if the message queue is already idle" into ub-launcher3-master

parents 8625d0d8 cebfec62
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -300,8 +300,8 @@ public abstract class BaseLoaderResults {

    public LooperIdleLock newIdleLock(Object lock) {
        LooperIdleLock idleLock = new LooperIdleLock(lock, Looper.getMainLooper());
        // If we are not binding, there is no reason to wait for idle.
        if (mCallbacks.get() == null) {
        // If we are not binding or if the main looper is already idle, there is no reason to wait
        if (mCallbacks.get() == null || Looper.getMainLooper().getQueue().isIdle()) {
            idleLock.queueIdle();
        }
        return idleLock;
+7 −6
Original line number Diff line number Diff line
@@ -22,29 +22,30 @@ import android.os.MessageQueue;
/**
 * Utility class to block execution until the UI looper is idle.
 */
public class LooperIdleLock implements MessageQueue.IdleHandler, Runnable {
public class LooperIdleLock implements MessageQueue.IdleHandler {

    private final Object mLock;

    private boolean mIsLocked;
    private Looper mLooper;

    public LooperIdleLock(Object lock, Looper looper) {
        mLock = lock;
        mLooper = looper;
        mIsLocked = true;
        looper.getQueue().addIdleHandler(this);
    }

    @Override
    public void run() {
        Looper.myQueue().addIdleHandler(this);
    }

    @Override
    public boolean queueIdle() {
        synchronized (mLock) {
            mIsLocked = false;
            mLock.notify();
        }
        // Manually remove from the list in case we're calling this outside of the idle callbacks
        // (this is Ok in the normal flow as well because MessageQueue makes a copy of all handlers
        // before calling back)
        mLooper.getQueue().removeIdleHandler(this);
        return false;
    }