diff options
| -rw-r--r-- | services/core/java/com/android/server/wm/DisplayContent.java | 12 | ||||
| -rw-r--r-- | services/tests/servicestests/src/com/android/server/wm/TaskStackContainersTests.java | 18 |
2 files changed, 30 insertions, 0 deletions
diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java index 5d0101f88c69..ac6582634bf8 100644 --- a/services/core/java/com/android/server/wm/DisplayContent.java +++ b/services/core/java/com/android/server/wm/DisplayContent.java @@ -3606,6 +3606,18 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo final int targetPosition = findPositionForStack(position, child, false /* adding */); super.positionChildAt(targetPosition, child, includingParents); + if (includingParents) { + // We still want to move the display of this stack container to top because even the + // target position is adjusted to non-top, the intention of the condition is to have + // higher z-order to gain focus (e.g. moving a task of a fullscreen stack to front + // in a non-top display which is using picture-in-picture mode). + final int topChildPosition = getChildCount() - 1; + if (targetPosition < topChildPosition && position >= topChildPosition) { + getParent().positionChildAt(POSITION_TOP, this /* child */, + true /* includingParents */); + } + } + setLayoutNeeded(); } diff --git a/services/tests/servicestests/src/com/android/server/wm/TaskStackContainersTests.java b/services/tests/servicestests/src/com/android/server/wm/TaskStackContainersTests.java index 9fa5ba42204f..ea44279b46a9 100644 --- a/services/tests/servicestests/src/com/android/server/wm/TaskStackContainersTests.java +++ b/services/tests/servicestests/src/com/android/server/wm/TaskStackContainersTests.java @@ -109,4 +109,22 @@ public class TaskStackContainersTests extends WindowTestsBase { assertEquals(taskStackContainer.mChildren.get(stackPos), stack1); assertEquals(taskStackContainer.mChildren.get(pinnedStackPos), mPinnedStack); } + + @Test + public void testDisplayPositionWithPinnedStack() { + // The display contains pinned stack that was added in {@link #setUp}. + final TaskStack stack = createTaskStackOnDisplay(mDisplayContent); + final Task task = createTaskInStack(stack, 0 /* userId */); + + // Add another display at top. + sWm.mRoot.positionChildAt(WindowContainer.POSITION_TOP, createNewDisplay(), + false /* includingParents */); + + // Move the task of {@code mDisplayContent} to top. + stack.positionChildAt(WindowContainer.POSITION_TOP, task, true /* includingParents */); + final int indexOfDisplayWithPinnedStack = sWm.mRoot.mChildren.indexOf(mDisplayContent); + + assertEquals("The testing DisplayContent should be moved to top with task", + sWm.mRoot.getChildCount() - 1, indexOfDisplayWithPinnedStack); + } } |