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

Commit 6853ac83 authored by Jeff Brown's avatar Jeff Brown Committed by The Android Automerger
Browse files

Ensure looper quits after all other messages are handled.

Bug: 8596303
Change-Id: Ie8bfbbe810f5ade2afd870c8e675ce1353a80e5d
parent 8f38062b
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -201,8 +201,16 @@ public final class Looper {

    /**
     * Quits the looper.
     *
     * Causes the {@link #loop} method to terminate as soon as possible.
     * <p>
     * Causes the {@link #loop} method to terminate as soon as all remaining messages
     * in the message queue that are already due to be delivered have been handled.
     * However delayed messages with due times in the future may not be handled before
     * the loop terminates.
     * </p><p>
     * Any attempt to post messages to the queue after {@link #quit} has been called
     * will fail.  For example, the {@link Handler#sendMessage(Message)} method will
     * return false when the looper is being terminated.
     * </p>
     */
    public void quit() {
        mQueue.quit();
+6 −5
Original line number Diff line number Diff line
@@ -132,11 +132,6 @@ public final class MessageQueue {
            nativePollOnce(mPtr, nextPollTimeoutMillis);

            synchronized (this) {
                if (mQuiting) {
                    dispose();
                    return null;
                }

                // Try to retrieve the next message.  Return if found.
                final long now = SystemClock.uptimeMillis();
                Message prevMsg = null;
@@ -170,6 +165,12 @@ public final class MessageQueue {
                    nextPollTimeoutMillis = -1;
                }

                // Process the quit message now that all pending messages have been handled.
                if (mQuiting) {
                    dispose();
                    return null;
                }

                // If first time idle, then get the number of idlers to run.
                // Idle handles only run if the queue is empty or if the first message
                // in the queue (possibly a barrier) is due to be handled in the future.