From 2d60f6ba7fd439394bcd46387861544caa083d33 Mon Sep 17 00:00:00 2001 From: Jerry Chang Date: Tue, 13 Jun 2023 12:48:15 +0000 Subject: [PATCH] Fix swipe-to-home not enter pip from split properly Unlick 3-button home-key to enter pip from split flow, if using gesture navigation, the flow is like: swipe to home -> handle as a TYPE_RECENTS_DURING_SPLIT -> finishTransition checks and triggers auto-pip -> create TRANSIT_PIP -> reparent task to TDA -> collect to new transition -> file TRANSIT_PIP Since the task was collected after reparent, shell-side unable to identify if it was in split when receiving TRANSIT_PIP. This checks if a TRANSIT_PIP implies empty one side of the split, so we can handle enter-pip-from-split properly. Fix: 287002454 Test: 1. Return to home from a split pair, the activity on the split can enter PiP and clear the split pair in overview. 2. Put a split pair in background, launch another fullscreen activity and request entering PiP, the log should not show: "Got a PiP-enter request while Split-Screen is active". Change-Id: Ifc129e85a69e7c05363204e72fe4cc6ba61b9b47 --- .../shell/splitscreen/StageCoordinator.java | 21 +++++++++++++++++++ .../shell/transition/DefaultMixedHandler.java | 11 +++++----- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/StageCoordinator.java b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/StageCoordinator.java index 79002bbb8cc63..48169588177a6 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/StageCoordinator.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/StageCoordinator.java @@ -364,6 +364,27 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler, return mMainStage.isActive(); } + /** @return whether the transition-request implies entering pip from split. */ + public boolean requestImpliesSplitToPip(TransitionRequestInfo request) { + if (!isSplitActive() || !mMixedHandler.requestHasPipEnter(request)) { + return false; + } + + if (request.getTriggerTask() != null && getSplitPosition( + request.getTriggerTask().taskId) != SPLIT_POSITION_UNDEFINED) { + return true; + } + + // If one of the splitting tasks support auto-pip, wm-core might reparent the task to TDA + // and file a TRANSIT_PIP transition when finishing transitions. + // @see com.android.server.wm.RootWindowContainer#moveActivityToPinnedRootTask + if (mMainStage.getChildCount() == 0 || mSideStage.getChildCount() == 0) { + return true; + } + + return false; + } + /** Checks if `transition` is a pending enter-split transition. */ public boolean isPendingEnter(IBinder transition) { return mSplitTransitions.isPendingEnter(transition); diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/transition/DefaultMixedHandler.java b/libs/WindowManager/Shell/src/com/android/wm/shell/transition/DefaultMixedHandler.java index 2aa9f20df7468..760023a8e1ff4 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/transition/DefaultMixedHandler.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/transition/DefaultMixedHandler.java @@ -24,7 +24,6 @@ import static android.view.WindowManager.TRANSIT_TO_BACK; import static android.window.TransitionInfo.FLAG_IS_WALLPAPER; import static com.android.wm.shell.common.split.SplitScreenConstants.FLAG_IS_DIVIDER_BAR; -import static com.android.wm.shell.common.split.SplitScreenConstants.SPLIT_POSITION_UNDEFINED; import static com.android.wm.shell.splitscreen.SplitScreen.STAGE_TYPE_UNDEFINED; import static com.android.wm.shell.splitscreen.SplitScreenController.EXIT_REASON_CHILD_TASK_ENTER_PIP; import static com.android.wm.shell.util.TransitionUtil.isOpeningType; @@ -33,7 +32,6 @@ import android.annotation.NonNull; import android.annotation.Nullable; import android.app.PendingIntent; import android.os.IBinder; -import android.util.Log; import android.util.Pair; import android.view.SurfaceControl; import android.view.WindowManager; @@ -161,9 +159,7 @@ public class DefaultMixedHandler implements Transitions.TransitionHandler, @Override public WindowContainerTransaction handleRequest(@NonNull IBinder transition, @NonNull TransitionRequestInfo request) { - if (mPipHandler.requestHasPipEnter(request) && mSplitHandler.isSplitActive() - && request.getTriggerTask() != null && mSplitHandler.getSplitItemPosition( - request.getTriggerTask().token) != SPLIT_POSITION_UNDEFINED) { + if (mSplitHandler.requestImpliesSplitToPip(request)) { ProtoLog.v(ShellProtoLogGroup.WM_SHELL_TRANSITIONS, " Got a PiP-enter request while " + "Split-Screen is active, so treat it as Mixed."); if (request.getRemoteTransition() != null) { @@ -606,6 +602,11 @@ public class DefaultMixedHandler implements Transitions.TransitionHandler, return false; } + /** @return whether the transition-request represents a pip-entry. */ + public boolean requestHasPipEnter(TransitionRequestInfo request) { + return mPipHandler.requestHasPipEnter(request); + } + @Override public void mergeAnimation(@NonNull IBinder transition, @NonNull TransitionInfo info, @NonNull SurfaceControl.Transaction t, @NonNull IBinder mergeTarget,