From 514a576b9e7b4d132b8d42744addcb1c9cbb6368 Mon Sep 17 00:00:00 2001 From: Tony Huang Date: Tue, 17 May 2022 17:49:28 +0800 Subject: [PATCH] Fix switching a background task into split screen unexpectedly If a task in split starts a new task or an adjacent task, it will put the current splitting task behine it in the split. But when users switch to the backgrond task, we would like to launch it in fullscreen since it's shoiwng as a fullscreen tile in overview. To fix this, the patch evicts any non-visible tasks in split when detecting it's going to recent. So background tasks won't be launched into split screen from overview anymore. Fix: 232497373 Test: manual Test: pass existing tests Change-Id: I577aeeabda76fab88cd734af32ea8a69083ad3d3 --- .../wm/shell/splitscreen/SplitScreenController.java | 7 +++++++ .../android/wm/shell/splitscreen/StageCoordinator.java | 5 +++++ .../android/wm/shell/splitscreen/StageTaskListener.java | 9 +++++++++ 3 files changed, 21 insertions(+) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/SplitScreenController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/SplitScreenController.java index ac76d17e2a512..31b510c38457b 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/SplitScreenController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/SplitScreenController.java @@ -414,6 +414,13 @@ public class SplitScreenController implements DragAndDropPolicy.Starter, } RemoteAnimationTarget[] onGoingToRecentsLegacy(RemoteAnimationTarget[] apps) { + if (isSplitScreenVisible()) { + // Evict child tasks except the top visible one under split root to ensure it could be + // launched as full screen when switching to it on recents. + final WindowContainerTransaction wct = new WindowContainerTransaction(); + mStageCoordinator.prepareEvictInvisibleChildTasks(wct); + mSyncQueue.queue(wct); + } return reparentSplitTasksForAnimation(apps, true /*splitExpectedToBeVisible*/); } 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 d543aa7423774..f86ecfcf6a130 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 @@ -533,6 +533,11 @@ class StageCoordinator implements SplitLayout.SplitLayoutHandler, } } + void prepareEvictInvisibleChildTasks(WindowContainerTransaction wct) { + mMainStage.evictInvisibleChildren(wct); + mSideStage.evictInvisibleChildren(wct); + } + Bundle resolveStartStage(@StageType int stage, @SplitPosition int position, @androidx.annotation.Nullable Bundle options, @androidx.annotation.Nullable WindowContainerTransaction wct) { diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/StageTaskListener.java b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/StageTaskListener.java index 9fd5d20038733..bf6cef36051e8 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/StageTaskListener.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/StageTaskListener.java @@ -343,6 +343,15 @@ class StageTaskListener implements ShellTaskOrganizer.TaskListener { } } + void evictInvisibleChildren(WindowContainerTransaction wct) { + for (int i = mChildrenTaskInfo.size() - 1; i >= 0; i--) { + final ActivityManager.RunningTaskInfo taskInfo = mChildrenTaskInfo.valueAt(i); + if (!taskInfo.isVisible) { + wct.reparent(taskInfo.token, null /* parent */, false /* onTop */); + } + } + } + void onSplitScreenListenerRegistered(SplitScreen.SplitScreenListener listener, @StageType int stage) { for (int i = mChildrenTaskInfo.size() - 1; i >= 0; --i) {