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

Commit e19a8d9b authored by Winson Chung's avatar Winson Chung
Browse files

Remove remaining cases where we cancel back to the app

- Until we have better infra we can't currently return to the app when
  canceling a recents transition as it can cause a deadlock blocking
  the processing of subsequent transitions.  In these cases though we
  are just merging a transtion that has already updated the WM hierarhcy
  so canceling to home is probably fine.

Fixes: 415541522
Bug: 346588978
Flag: EXEMPT bugfix
Test: atest RecentsTransitionHandlerTests (more cases to be added later)
Test: Repro steps from b/370682472
Change-Id: I2194d2b69da51fbf03ed22d23ac46fd5e66904b8
parent 813c9541
Loading
Loading
Loading
Loading
+5 −6
Original line number Diff line number Diff line
@@ -996,7 +996,7 @@ public class RecentsTransitionHandler implements Transitions.TransitionHandler,
                ProtoLog.v(ShellProtoLogGroup.WM_SHELL_RECENTS_TRANSITION,
                        "[%d] RecentsController.merge: transit_remove_pip", mInstanceId);
                // Cancel the merge if transition is removing PiP; PiP is on top of everything else.
                cancel(mWillFinishToHome /* toHome */, mWillFinishToHome /* withScreenshots */,
                cancel(true /* toHome */, mWillFinishToHome /* withScreenshots */,
                        "transit_remove_pip");
                return;
            }
@@ -1005,7 +1005,7 @@ public class RecentsTransitionHandler implements Transitions.TransitionHandler,
                ProtoLog.v(ShellProtoLogGroup.WM_SHELL_RECENTS_TRANSITION,
                        "[%d] RecentsController.merge: keyguard is locked", mInstanceId);
                // We will not accept new changes if we are swiping over the keyguard.
                cancel(true /* toHome */, false /* withScreenshots */, "keyguard_locked");
                cancel("keyguard_locked");
                return;
            }
            ProtoLog.v(ShellProtoLogGroup.WM_SHELL_RECENTS_TRANSITION,
@@ -1035,8 +1035,7 @@ public class RecentsTransitionHandler implements Transitions.TransitionHandler,
                        && taskInfo != null && taskInfo.lastParentTaskIdBeforePip > 0) {
                    // Pinned task is closing as a side effect of the removal of its original Task,
                    // such transition should be handled by PiP. So cancel the merge here.
                    cancel(false /* toHome */, false /* withScreenshots */,
                            "task #" + taskInfo.taskId + " is removed with its original parent");
                    cancel("task #" + taskInfo.taskId + " is removed with its original parent");
                    return;
                }
                final boolean isRootTask = taskInfo != null
@@ -1077,7 +1076,7 @@ public class RecentsTransitionHandler implements Transitions.TransitionHandler,
                            && info.getType() == TRANSIT_CHANGE) {
                        // This call to cancel will use the screenshots taken preemptively in
                        // handleMidTransitionRequest() prior to the display changing
                        cancel(mWillFinishToHome, true /* withScreenshots */, "display change");
                        cancel(true /* toHome */, true /* withScreenshots */, "display change");
                        return;
                    }
                    // Don't consider order-only & non-leaf changes as changing apps.
@@ -1269,7 +1268,7 @@ public class RecentsTransitionHandler implements Transitions.TransitionHandler,
                        + foundRecentsClosing + " recentsTaskId=" + mRecentsTaskId);
                if (foundRecentsClosing || mRecentsTaskId < 0) {
                    mWillFinishToHome = false;
                    cancel(false /* toHome */, false /* withScreenshots */, "didn't merge");
                    cancel("didn't merge");
                }
                return;
            }
+40 −1
Original line number Diff line number Diff line
@@ -21,14 +21,17 @@ import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD;
import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
import static android.view.WindowManager.TRANSIT_CLOSE;
import static android.view.WindowManager.TRANSIT_OPEN;
import static android.view.WindowManager.TRANSIT_SLEEP;
import static android.view.WindowManager.TRANSIT_TO_FRONT;

import static com.android.window.flags.Flags.FLAG_ENABLE_DESKTOP_RECENTS_TRANSITIONS_CORNERS_BUGFIX;
import static com.android.wm.shell.Flags.FLAG_ENABLE_PIP2;
import static com.android.wm.shell.Flags.FLAG_ENABLE_RECENTS_BOOKEND_TRANSITION;
import static com.android.wm.shell.recents.RecentsTransitionStateListener.TRANSITION_STATE_ANIMATING;
import static com.android.wm.shell.recents.RecentsTransitionStateListener.TRANSITION_STATE_NOT_RUNNING;
import static com.android.wm.shell.recents.RecentsTransitionStateListener.TRANSITION_STATE_REQUESTED;
import static com.android.wm.shell.transition.Transitions.TRANSIT_END_RECENTS_TRANSITION;
import static com.android.wm.shell.transition.Transitions.TRANSIT_REMOVE_PIP;
import static com.android.wm.shell.transition.Transitions.TRANSIT_START_RECENTS_TRANSITION;

import static com.google.common.truth.Truth.assertThat;
@@ -321,7 +324,6 @@ public class RecentsTransitionHandlerTest extends ShellTestCase {
                .addChange(TRANSIT_OPEN, new TestRunningTaskInfoBuilder().build())
                .build();
        final IBinder transition = startRecentsTransition(/* synthetic= */ false, animationRunner);
        SurfaceControl.Transaction finishT = mock(SurfaceControl.Transaction.class);
        mRecentsTransitionHandler.startAnimation(
                transition, createTransitionInfo(), new StubTransaction(), new StubTransaction(),
                mock(Transitions.TransitionFinishCallback.class));
@@ -479,6 +481,43 @@ public class RecentsTransitionHandlerTest extends ShellTestCase {
        verify(finishT).setCornerRadius(leash, FREEFORM_TASK_CORNER_RADIUS_ON_CD);
    }

    @Test
    @EnableFlags(FLAG_ENABLE_RECENTS_BOOKEND_TRANSITION)
    public void testMerge_cancelToHome_onTransitSleep() throws Exception {
        TransitionInfo mergeTransitionInfo = new TransitionInfoBuilder(TRANSIT_SLEEP)
                .build();
        startTransitionAndMergeThenVerifyCanceled(mergeTransitionInfo);
    }

    @Test
    @EnableFlags({FLAG_ENABLE_RECENTS_BOOKEND_TRANSITION, FLAG_ENABLE_PIP2})
    public void testMerge_cancelToHome_onTransitRemovePip() throws Exception {
        TransitionInfo mergeTransitionInfo = new TransitionInfoBuilder(TRANSIT_REMOVE_PIP)
                .build();
        startTransitionAndMergeThenVerifyCanceled(mergeTransitionInfo);
    }

    private void startTransitionAndMergeThenVerifyCanceled(TransitionInfo mergeTransition)
            throws Exception {
        final IRecentsAnimationRunner animationRunner = mock(IRecentsAnimationRunner.class);
        final IBinder transition = startRecentsTransition(/* synthetic= */ false, animationRunner);
        mRecentsTransitionHandler.startAnimation(
                transition, createTransitionInfo(), new StubTransaction(), new StubTransaction(),
                mock(Transitions.TransitionFinishCallback.class));

        mRecentsTransitionHandler.findController(transition).merge(
                mergeTransition,
                new StubTransaction(),
                new StubTransaction(),
                mock(Transitions.TransitionFinishCallback.class));
        mMainExecutor.flushAll();

        // Verify that the runner was notified and that the cancel immediately took effect (and the
        // transition is finished)
        verify(animationRunner).onAnimationCanceled(any(), any());
        assertThat(mRecentsTransitionHandler.findController(transition)).isNull();
    }

    private IBinder startRecentsTransition(boolean synthetic) {
        return startRecentsTransition(synthetic, mock(IRecentsAnimationRunner.class));
    }