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

Commit 1e619aa8 authored by Adam Powell's avatar Adam Powell
Browse files

Describe API behavior guarantees provided by MessageQueue sync barriers

Add a comment in ViewRootImpl.java's usage of
MessageQueue.postSyncBarrier describing the public API behavior
guarantees it supports.

Bug: 428051877

Flag: DOCS_ONLY

Change-Id: I4f9ea99be4e65142ebfe9573d08b9258fc09a546
parent 709df92c
Loading
Loading
Loading
Loading
+18 −0
Original line number Original line Diff line number Diff line
@@ -3040,6 +3040,24 @@ public final class ViewRootImpl implements ViewParent,
    void scheduleTraversals() {
    void scheduleTraversals() {
        if (!mTraversalScheduled) {
        if (!mTraversalScheduled) {
            mTraversalScheduled = true;
            mTraversalScheduled = true;
            // The following behavior is load-bearing for public API correctness.
            // For example, the following code is defined to be correct and the
            // MessageQueue sync barrier mechanism and its usage here is
            // responsible for ensuring it:
            //
            //   textView.setText("Hello, world!");
            //   textView.getHandler().post(new Runnable() {
            //     public void run() {
            //       // This code will run after traversals have happened
            //       // and the TextView has been measured with its new text.
            //       reportNewTextWidth(textView.getWidth());
            //     }
            //   });
            //
            // Any message posted after scheduling traversals (e.g. via
            // View#requestLayout or View#invalidate) is guaranteed to run after
            // the scheduled traversals have occurred unless the message is
            // specifically "asynchronous" - see Message#setAsynchronous
            mTraversalBarrier = mQueue.postSyncBarrier();
            mTraversalBarrier = mQueue.postSyncBarrier();
            mChoreographer.postCallback(
            mChoreographer.postCallback(
                    Choreographer.CALLBACK_TRAVERSAL, mTraversalRunnable, null);
                    Choreographer.CALLBACK_TRAVERSAL, mTraversalRunnable, null);