From a4e60d74df7eeb2e904701cd9cde66d72eef4aad Mon Sep 17 00:00:00 2001 From: wilsonshih Date: Wed, 3 Jun 2020 23:06:10 +0800 Subject: [PATCH] Fix the root task of secondary split screen could be overwritten. When external display removed, the remaining tasks should be reparent to correct parents depends on the status of default display, if secondary split screen exists, reparent it to the root task instead of display area. Bug: 158067169 Test: atest MultiDisplayPolicyTests Test: after test complete, verify the root of home task doesn't remain in secondary-split-screen. Change-Id: Ic4b836263f9acadad2641a19bd369a44aa806d96 --- .../android/server/wm/TaskDisplayArea.java | 31 +++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/services/core/java/com/android/server/wm/TaskDisplayArea.java b/services/core/java/com/android/server/wm/TaskDisplayArea.java index 102c2a6364f4e..9a6fc8c5950ba 100644 --- a/services/core/java/com/android/server/wm/TaskDisplayArea.java +++ b/services/core/java/com/android/server/wm/TaskDisplayArea.java @@ -1741,21 +1741,23 @@ final class TaskDisplayArea extends DisplayArea { // reparenting stack finished. // Keep the order from bottom to top. int numStacks = getStackCount(); + + final boolean splitScreenActivated = toDisplayArea.isSplitScreenModeActivated(); + final ActivityStack rootStack = splitScreenActivated ? toDisplayArea + .getTopStackInWindowingMode(WINDOWING_MODE_SPLIT_SCREEN_SECONDARY) : null; for (int stackNdx = 0; stackNdx < numStacks; stackNdx++) { final ActivityStack stack = getStackAt(stackNdx); // Always finish non-standard type stacks. if (destroyContentOnRemoval || !stack.isActivityTypeStandardOrUndefined()) { stack.finishAllActivitiesImmediately(); } else { - // If default display is in split-window mode, set windowing mode of the - // stack to split-screen secondary. Otherwise, set the windowing mode to - // undefined by default to let stack inherited the windowing mode from the - // new display. - final int windowingMode = toDisplayArea.isSplitScreenModeActivated() - ? WINDOWING_MODE_SPLIT_SCREEN_SECONDARY - : WINDOWING_MODE_UNDEFINED; - stack.reparent(toDisplayArea, true /* onTop */); - stack.setWindowingMode(windowingMode); + // Reparent the stack to the root task of secondary-split-screen or display area. + stack.reparent(stack.supportsSplitScreenWindowingMode() && rootStack != null + ? rootStack : toDisplayArea, POSITION_TOP); + + // Set the windowing mode to undefined by default to let the stack inherited the + // windowing mode. + stack.setWindowingMode(WINDOWING_MODE_UNDEFINED); lastReparentedStack = stack; } // Stacks may be removed from this display. Ensure each stack will be processed @@ -1763,6 +1765,17 @@ final class TaskDisplayArea extends DisplayArea { stackNdx -= numStacks - getStackCount(); numStacks = getStackCount(); } + if (lastReparentedStack != null && splitScreenActivated) { + if (!lastReparentedStack.supportsSplitScreenWindowingMode()) { + mAtmService.getTaskChangeNotificationController() + .notifyActivityDismissingDockedStack(); + toDisplayArea.onSplitScreenModeDismissed(lastReparentedStack); + } else if (rootStack != null) { + // update focus + rootStack.moveToFront("display-removed"); + } + } + mRemoved = true; return lastReparentedStack;