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

Commit 0045d810 authored by Jiaming Liu's avatar Jiaming Liu
Browse files

[Bubbles] Run the hide-TaskView WCT after the current method execution

The WCT to hide TaskView may take significant time. If executed in the
removeView method call, it might result in missed frames. Before
ag/34380975, it was executed after the removeView call because
`startNextTransition` picks up a different wct in the queue (the CHANGE
transition caused by TaskView bounds update). After ag/34380975, because
of the elimination of the extra CHANGE transition, the hide-TaskView WCT
is executed synchronously on the animation callback, causing missed
frames. This CL posts the wct execution to the ShellHandler so that it
doesn't block the thread.

Bug: 431100601
Bug: 424205239
Test: atest TaskViewTransitionsTest BubbleControllerTest
Flag: EXEMPT bugfix
Change-Id: I8e25a3e8ce775e5564d2d49f3a6f844b6fb1866d
parent 6c27a6b3
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -386,6 +386,7 @@ class BubbleControllerTest(flags: FlagsParameterization) {
                true, /* visible */
                true, /* reorder */
                false, /* syncHiddenWithVisibilityOnReorder */
                false, /* nonBlockingIfPossible */
            )
        } else {
            verify(baseTransitions).setTaskViewVisible(taskView, true /* visible */)
@@ -407,6 +408,7 @@ class BubbleControllerTest(flags: FlagsParameterization) {
            any(), /* visible */
            any(), /* reorder */
            any(), /* syncHiddenWithVisibilityOnReorder */
            any(), /* nonBlockingIfPossible */
        )
    }

+4 −1
Original line number Diff line number Diff line
@@ -3744,9 +3744,12 @@ public class BubbleController implements ConfigurationChangeListener,
                if (!visible && !mBubbleData.hasBubbleInStackWithTaskView(taskView)) {
                    return;
                }
                // The transaction to hide the TaskView can be executed on the executor to avoid
                // blocking the calling thread.
                final boolean nonBlocking = !visible;
                // Use reorder instead of always-on-top with hidden.
                mBaseTransitions.setTaskViewVisible(taskView, visible, true /* reorder */,
                        false /* toggleHiddenOnReorder */);
                        false /* toggleHiddenOnReorder */, nonBlocking);
            } else {
                mBaseTransitions.setTaskViewVisible(taskView, visible);
            }
+21 −2
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@ import androidx.annotation.VisibleForTesting;
import com.android.internal.protolog.ProtoLog;
import com.android.wm.shell.Flags;
import com.android.wm.shell.ShellTaskOrganizer;
import com.android.wm.shell.common.ShellExecutor;
import com.android.wm.shell.common.SyncTransactionQueue;
import com.android.wm.shell.shared.TransitionUtil;
import com.android.wm.shell.shared.bubbles.BubbleAnythingFlagHelper;
@@ -456,6 +457,15 @@ public class TaskViewTransitions implements Transitions.TransitionHandler, TaskV
                true /* syncHiddenWithVisibilityOnReorder */);
    }

    /**
     * See {@link #setTaskViewVisible(TaskViewTaskController, boolean, boolean, boolean, boolean)}.
     */
    public void setTaskViewVisible(TaskViewTaskController taskView, boolean visible,
            boolean reorder, boolean syncHiddenWithVisibilityOnReorder) {
        setTaskViewVisible(taskView, visible, reorder, syncHiddenWithVisibilityOnReorder,
                false /* nonBlockingIfPossible */);
    }

    /**
     * Starts a new transition to make the given {@code taskView} visible and optionally
     * reordering it.
@@ -468,11 +478,16 @@ public class TaskViewTransitions implements Transitions.TransitionHandler, TaskV
     *                                          the task with the target visibility when
     *                                          reordering. This only takes effect if {@code
     *                                          reorder} is {@code true}.
     * @param nonBlockingIfPossible If true, the wct will be executed in a non-blocking way when
     *                              possible. It is possible if {@link #mShellExecutor} is an
     *                              instance of {@link ShellExecutor} that supports posting a
     *                              Runnable after the current execution.
     * @throws IllegalStateException If the flag {@link FLAG_ENABLE_CREATE_ANY_BUBBLE} is not
     *                               enabled.
     */
    public void setTaskViewVisible(TaskViewTaskController taskView, boolean visible,
            boolean reorder, boolean syncHiddenWithVisibilityOnReorder) {
            boolean reorder, boolean syncHiddenWithVisibilityOnReorder,
            boolean nonBlockingIfPossible) {
        final TaskViewRepository.TaskViewState state = useRepo()
                ? mTaskViewRepo.byTaskView(taskView)
                : mTaskViews.get(taskView);
@@ -504,7 +519,11 @@ public class TaskViewTransitions implements Transitions.TransitionHandler, TaskV
        final PendingTransition pending = new PendingTransition(
                visible ? TRANSIT_TO_FRONT : TRANSIT_TO_BACK, wct, taskView, null /* cookie */);
        mPending.add(pending);
        if (nonBlockingIfPossible && mShellExecutor instanceof ShellExecutor executor) {
            executor.executeDelayed(this::startNextTransition, 0);
        } else {
            startNextTransition();
        }
        // visibility is reported in transition.
    }