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

Commit fe2468ee authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Defer committing visible until transition ready

So some logic depend on ActivityRecord#isVisible() won't be called
earlier before transition ready that may delay the animation.
Such as updateFocusedWindow in activityPaused and
updateSystemBarAttributes when starting window performs relayout.

Skip the assertion pipAppWindowAlwaysVisible for "swipe up and
fade in pip" because either "always visible" or "visible->invisible
->visible" is fine for internal state. The visual appearance is
still asserted by layer visibility.

Bug: 260059642
Test: TransitionTests
Test: OpenAppMicrobenchmark with shell transition.

Change-Id: I294a40cfb43ede763f3c91204ae1d7f2d8ff8035
parent 8e6e692f
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -66,6 +66,18 @@ class EnterPipOnUserLeaveHintTest(flicker: FlickerTest) : EnterPipTest(flicker)
            transitions { tapl.goHome() }
        }

    @Presubmit
    @Test
    override fun pipAppWindowAlwaysVisible() {
        // In gestural nav the pip will first move behind home and then above home. The visual
        // appearance visible->invisible->visible is asserted by pipAppLayerAlwaysVisible().
        // But the internal states of activity don't need to follow that, such as a temporary
        // visibility state can be changed quickly outside a transaction so the test doesn't
        // detect that. Hence, skip the case to avoid restricting the internal implementation.
        Assume.assumeFalse(flicker.scenario.isGesturalNavigation)
        super.pipAppWindowAlwaysVisible()
    }

    @Presubmit
    @Test
    override fun pipAppLayerAlwaysVisible() {
+14 −3
Original line number Diff line number Diff line
@@ -5249,9 +5249,9 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
            transferStartingWindowFromHiddenAboveTokenIfNeeded();
        }

        // If in a transition, defer commits for activities that are going invisible
        if (!visible && inTransition()) {
            if (mTransitionController.inPlayingTransition(this)
        // Defer committing visibility until transition starts.
        if (inTransition()) {
            if (!visible && mTransitionController.inPlayingTransition(this)
                    && mTransitionController.isCollecting(this)) {
                mTransitionChangeFlags |= FLAG_IS_OCCLUDED;
            }
@@ -5501,6 +5501,17 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        }
    }

    /** Updates draw state and shows drawn windows. */
    void commitFinishDrawing(SurfaceControl.Transaction t) {
        boolean committed = false;
        for (int i = mChildren.size() - 1; i >= 0; i--) {
            committed |= mChildren.get(i).commitFinishDrawing(t);
        }
        if (committed) {
            requestUpdateWallpaperIfNeeded();
        }
    }

    /**
     * Check if visibility of this {@link ActivityRecord} should be updated as part of an app
     * transition.
+19 −1
Original line number Diff line number Diff line
@@ -834,7 +834,7 @@ class Transition implements BLASTSyncEngine.TransactionReadyListener {
            final ActivityRecord ar = mParticipants.valueAt(i).asActivityRecord();
            if (ar == null || !ar.isVisible() || ar.getParent() == null) continue;
            if (inputSinkTransaction == null) {
                inputSinkTransaction = new SurfaceControl.Transaction();
                inputSinkTransaction = ar.mWmService.mTransactionFactory.get();
            }
            ar.mActivityRecordInputSink.applyChangesToSurfaceIfChanged(inputSinkTransaction);
        }
@@ -957,6 +957,11 @@ class Transition implements BLASTSyncEngine.TransactionReadyListener {
            return;
        }

        // Commit the visibility of visible activities before calculateTransitionInfo(), so the
        // TaskInfo can be visible. Also it needs to be done before moveToPlaying(), otherwise
        // ActivityRecord#canShowWindows() may reject to show its window.
        commitVisibleActivities(transaction);

        mState = STATE_PLAYING;
        mStartTransaction = transaction;
        mFinishTransaction = mController.mAtm.mWindowManager.mTransactionFactory.get();
@@ -1118,6 +1123,19 @@ class Transition implements BLASTSyncEngine.TransactionReadyListener {
        }
    }

    /** The transition is ready to play. Make the start transaction show the surfaces. */
    private void commitVisibleActivities(SurfaceControl.Transaction transaction) {
        for (int i = mParticipants.size() - 1; i >= 0; --i) {
            final ActivityRecord ar = mParticipants.valueAt(i).asActivityRecord();
            if (ar == null || !ar.isVisibleRequested()) {
                continue;
            }
            ar.commitVisibility(true /* visible */, false /* performLayout */,
                    true /* fromTransition */);
            ar.commitFinishDrawing(transaction);
        }
    }

    /** @see RecentsAnimationController#attachNavigationBarToApp */
    private void handleLegacyRecentsStartBehavior(DisplayContent dc, TransitionInfo info) {
        if ((mFlags & TRANSIT_FLAG_IS_RECENTS) == 0) {
+13 −0
Original line number Diff line number Diff line
@@ -4624,6 +4624,19 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
        }
    }

    /** Makes the surface of drawn window (COMMIT_DRAW_PENDING) to be visible. */
    boolean commitFinishDrawing(SurfaceControl.Transaction t) {
        boolean committed = mWinAnimator.commitFinishDrawingLocked();
        if (committed) {
            // Ensure that the visibility of buffer layer is set.
            mWinAnimator.prepareSurfaceLocked(t);
        }
        for (int i = mChildren.size() - 1; i >= 0; i--) {
            committed |= mChildren.get(i).commitFinishDrawing(t);
        }
        return committed;
    }

    // This must be called while inside a transaction.
    boolean performShowLocked() {
        if (!showToCurrentUser()) {
+6 −3
Original line number Diff line number Diff line
@@ -564,20 +564,23 @@ public class TransitionTests extends WindowTestsBase {
        final WindowProcessController delegateProc = mSystemServicesTestRule.addProcess(
                "pkg.delegate", "proc.delegate", 6000 /* pid */, 6000 /* uid */);
        doReturn(mock(IBinder.class)).when(delegateProc.getThread()).asBinder();
        final ActivityRecord app = new ActivityBuilder(mAtm).setCreateTask(true).build();
        final ActivityRecord app = new ActivityBuilder(mAtm).setCreateTask(true)
                .setVisible(false).build();
        app.setVisibleRequested(true);
        final TransitionController controller = app.mTransitionController;
        final Transition transition = controller.createTransition(TRANSIT_OPEN);
        final RemoteTransition remoteTransition = new RemoteTransition(
                mock(IRemoteTransition.class));
        remoteTransition.setAppThread(delegateProc.getThread());
        transition.collectExistenceChange(app.getTask());
        controller.requestStartTransition(transition, app.getTask(), remoteTransition,
        transition.collect(app);
        controller.requestStartTransition(transition, null /* startTask */, remoteTransition,
                null /* displayChange */);
        testPlayer.startTransition();
        testPlayer.onTransactionReady(app.getSyncTransaction());
        assertTrue(playerProc.isRunningRemoteTransition());
        assertTrue(delegateProc.isRunningRemoteTransition());
        assertTrue(controller.mRemotePlayer.reportRunning(delegateProc.getThread()));
        assertTrue(app.isVisible());

        testPlayer.finish();
        assertFalse(playerProc.isRunningRemoteTransition());