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

Commit d9640493 authored by Brett Chabot's avatar Brett Chabot
Browse files

Simplify behavior of TestLooperManager#isBlockedOnSyncBarrier.

Previously isBlockedOnSyncBarrier would only return true if
the corresponding queue had a sync barrier as the next message,
AND a another message was waiting to be executed.

This is problematic for espresso (and I'd argue non-intuitive), which uses
isBlockedOnSyncBarrier to determine if queue is idle or not. The presence
of a sync barrier should make the queue idle.

This commit simplifies the definition and implementation of
isBlockedOnSyncBarrier to strictly mean 'the next message in the
queue is a sync barrier'.

Flag: android.os.message_queue_testability
Test: atest TestLooperManagerTest
Bug: 112000181
Change-Id: I443d3c8ed8d439f058136d55f70c9b8c2c444149
parent a51dcf16
Loading
Loading
Loading
Loading
+2 −46
Original line number Diff line number Diff line
@@ -36,7 +36,6 @@ import android.util.Printer;
import android.util.SparseArray;
import android.util.proto.ProtoOutputStream;

import com.android.internal.annotations.GuardedBy;
import com.android.internal.ravenwood.RavenwoodEnvironment;

import dalvik.annotation.optimization.NeverCompile;
@@ -1369,55 +1368,12 @@ public final class MessageQueue {
            Iterator<MessageNode> queueIter = mPriorityQueue.iterator();
            MessageNode queueNode = iterateNext(queueIter);

            if (queueNode != null && queueNode.isBarrier()) {
                long now = SystemClock.uptimeMillis();

                /* Look for a deliverable async node. If one exists we are not blocked. */
                Iterator<MessageNode> asyncQueueIter = mAsyncPriorityQueue.iterator();
                MessageNode asyncNode = iterateNext(asyncQueueIter);
                if (asyncNode != null && now >= asyncNode.getWhen()) {
                    return false;
                }
                /*
                 * Look for a deliverable sync node. In this case, if one exists we are blocked
                 * since the barrier prevents delivery of the Message.
                 */
                while (queueNode != null && queueNode.isBarrier()) {
                    queueNode = iterateNext(queueIter);
                }
                if (queueNode != null && now >= queueNode.getWhen()) {
                    return true;
                }
            }
            return (queueNode != null && queueNode.isBarrier());
        } else {
            Message msg = mMessages;
            if (msg != null && msg.target == null) {
                Message iter = msg;
                /* Look for a deliverable async node */
                do {
                    iter = iter.next;
                } while (iter != null && !iter.isAsynchronous());

                long now = SystemClock.uptimeMillis();
                if (iter != null && now >= iter.when) {
                    return false;
                }
                /*
                 * Look for a deliverable sync node. In this case, if one exists we are blocked
                 * since the barrier prevents delivery of the Message.
                 */
                iter = msg;
                do {
                    iter = iter.next;
                } while (iter != null && (iter.target == null || iter.isAsynchronous()));

                if (iter != null && now >= iter.when) {
                    return true;
            return msg != null && msg.target == null;
        }
    }
        }
        return false;
    }

    private static final class MatchHandlerWhatAndObject extends MessageCompare {
        @Override
+1 −22
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package android.os;

import android.annotation.FlaggedApi;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -1122,27 +1121,7 @@ public final class MessageQueue {
        Iterator<MessageNode> queueIter = mPriorityQueue.iterator();
        MessageNode queueNode = iterateNext(queueIter);

        if (queueNode != null && queueNode.isBarrier()) {
            long now = SystemClock.uptimeMillis();

            /* Look for a deliverable async node. If one exists we are not blocked. */
            Iterator<MessageNode> asyncQueueIter = mAsyncPriorityQueue.iterator();
            MessageNode asyncNode = iterateNext(asyncQueueIter);
            if (asyncNode != null && now >= asyncNode.getWhen()) {
                return false;
            }
            /*
             * Look for a deliverable sync node. In this case, if one exists we are blocked
             * since the barrier prevents delivery of the Message.
             */
            while (queueNode != null && queueNode.isBarrier()) {
                queueNode = iterateNext(queueIter);
            }
            if (queueNode != null && now >= queueNode.getWhen()) {
                return true;
            }
        }
        return false;
        return queueNode != null && queueNode.isBarrier();
    }

    private StateNode getStateNode(StackNode node) {
+3 −27
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package android.os;

import android.annotation.FlaggedApi;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -821,33 +820,10 @@ public final class MessageQueue {
     */
    boolean isBlockedOnSyncBarrier() {
        throwIfNotTest();
        synchronized (this) {
            Message msg = mMessages;
        if (msg != null && msg.target == null) {
            Message iter = msg;
            /* Look for a deliverable async node */
            do {
                iter = iter.next;
            } while (iter != null && !iter.isAsynchronous());

            long now = SystemClock.uptimeMillis();
            if (iter != null && now >= iter.when) {
                return false;
            return msg != null && msg.target == null;
        }
            /*
                * Look for a deliverable sync node. In this case, if one exists we are blocked
                * since the barrier prevents delivery of the Message.
                */
            iter = msg;
            do {
                iter = iter.next;
            } while (iter != null && (iter.target == null || iter.isAsynchronous()));

            if (iter != null && now >= iter.when) {
                return true;
            }
            return false;
        }
        return false;
    }

    boolean hasMessages(Handler h, int what, Object object) {
+0 −3
Original line number Diff line number Diff line
@@ -129,9 +129,6 @@ public class TestLooperManager {

    /**
     * Checks whether the Looper is currently blocked on a sync barrier.
     *
     * A Looper is blocked on a sync barrier if there is a Message in the Looper's
     * queue that is ready for execution but is behind a sync barrier
     */
    @FlaggedApi(Flags.FLAG_MESSAGE_QUEUE_TESTABILITY)
    public boolean isBlockedOnSyncBarrier() {