return "Display " + mDisplayId + " name=\"" + mDisplayInfo.name + "\"";
}
+ /** Checks if stack with provided id is visible on this display. */
+ boolean isStackVisible(int stackId) {
+ final TaskStack stack = getStackById(stackId);
+ return (stack != null && stack.isVisible());
+ }
+
/**
* @return The docked stack, but only if it is visible, and {@code null} otherwise.
*/
: requestedPosition >= topChildPosition;
int targetPosition = requestedPosition;
- if (toTop
- && mService.isStackVisibleLocked(PINNED_STACK_ID)
- && stack.mStackId != PINNED_STACK_ID) {
+ if (toTop && isStackVisible(PINNED_STACK_ID) && stack.mStackId != PINNED_STACK_ID) {
// The pinned stack is always the top most stack (always-on-top) when it is visible.
TaskStack topStack = mChildren.get(topChildPosition);
if (topStack.mStackId != PINNED_STACK_ID) {
// So, stack is moved just below the pinned stack.
// When we're adding a new stack the target is the current pinned stack position.
// When we're positioning an existing stack the target is the position below pinned
- // stack, because WindowContainer#positionAt() first removes element and then adds it
- // to specified place.
+ // stack, because WindowContainer#positionAt() first removes element and then adds
+ // it to specified place.
targetPosition = adding ? topChildPosition : topChildPosition - 1;
}
if (DEBUG_STACK) Slog.i(TAG, "reParentTask: removing taskId=" + mTaskId
+ " from stack=" + mStack);
EventLog.writeEvent(WM_TASK_REMOVED, mTaskId, "reParentTask");
+ final DisplayContent prevDisplayContent = getDisplayContent();
+
getParent().removeChild(this);
stack.addTask(this, position, showForAllUsers(), false /* moveParents */);
+
+ // Relayout display(s).
+ final DisplayContent displayContent = stack.getDisplayContent();
+ displayContent.setLayoutNeeded();
+ if (prevDisplayContent != displayContent) {
+ onDisplayChanged(displayContent);
+ prevDisplayContent.setLayoutNeeded();
+ }
}
/** @see com.android.server.am.ActivityManagerService#positionTaskInStack(int, int, int). */
throw new IllegalArgumentException("reparent: could not find stackId=" + stackId);
}
mContainer.reparent(stack, position);
- final DisplayContent displayContent = stack.getDisplayContent();
- displayContent.setLayoutNeeded();
mService.mWindowPlacerLocked.performSurfacePlacement();
}
}
package com.android.server.wm;
import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
+import static android.view.DisplayAdjustments.DEFAULT_DISPLAY_ADJUSTMENTS;
import org.junit.Test;
import org.junit.runner.RunWith;
+import android.hardware.display.DisplayManagerGlobal;
import android.platform.test.annotations.Presubmit;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
+import android.view.Display;
+import android.view.DisplayInfo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
assertEquals(taskStackContainer.mChildren.get(pinnedStackPos), pinnedStack);
}
+ @Test
+ public void testReparentBetweenDisplays() throws Exception {
+ // Create first stack on primary display.
+ final TaskStack stack1 = createTaskStackOnDisplay(sDisplayContent);
+ final TestTaskWindowContainerController taskController =
+ new TestTaskWindowContainerController(stack1.mStackId);
+ final TestTask task1 = (TestTask) taskController.mContainer;
+ task1.mOnDisplayChangedCalled = false;
+
+ // Create second display and put second stack on it.
+ final Display display = new Display(DisplayManagerGlobal.getInstance(),
+ sDisplayContent.getDisplayId() + 1, new DisplayInfo(),
+ DEFAULT_DISPLAY_ADJUSTMENTS);
+ final DisplayContent dc = new DisplayContent(display, sWm, sLayersController,
+ new WallpaperController(sWm));
+ sWm.mRoot.addChild(dc, 1);
+ final TaskStack stack2 = createTaskStackOnDisplay(dc);
+
+ // Reparent and check state.DisplayContent.java:2572
+ sWm.moveStackToDisplay(stack1.mStackId, dc.getDisplayId());
+ assertEquals(dc, stack1.getDisplayContent());
+ final int stack1PositionInParent = stack1.getParent().mChildren.indexOf(stack1);
+ final int stack2PositionInParent = stack1.getParent().mChildren.indexOf(stack2);
+ assertEquals(stack1PositionInParent, stack2PositionInParent + 1);
+ assertTrue(task1.mOnDisplayChangedCalled);
+ }
+
private TaskStack addPinnedStack() {
TaskStack pinnedStack = sWm.mStackIdToStack.get(PINNED_STACK_ID);
if (pinnedStack == null) {
package com.android.server.wm;
+import static android.view.DisplayAdjustments.DEFAULT_DISPLAY_ADJUSTMENTS;
+
import org.junit.Test;
+import android.hardware.display.DisplayManagerGlobal;
import android.platform.test.annotations.Presubmit;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
+import android.view.Display;
+import android.view.DisplayInfo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
assertEquals(0, ((TestTask) taskController.mContainer).positionInParent());
assertEquals(1, ((TestTask) taskController2.mContainer).positionInParent());
}
+
+ @Test
+ public void testReparentBetweenDisplays() throws Exception {
+ // Create first stack on primary display.
+ final TaskStack stack1 = createTaskStackOnDisplay(sDisplayContent);
+ final TestTaskWindowContainerController taskController =
+ new TestTaskWindowContainerController(stack1.mStackId);
+ final TestTask task1 = (TestTask) taskController.mContainer;
+ task1.mOnDisplayChangedCalled = false;
+
+ // Create second display and put second stack on it.
+ final Display display = new Display(DisplayManagerGlobal.getInstance(),
+ sDisplayContent.getDisplayId() + 1, new DisplayInfo(),
+ DEFAULT_DISPLAY_ADJUSTMENTS);
+ final DisplayContent dc = new DisplayContent(display, sWm, sLayersController,
+ new WallpaperController(sWm));
+ sWm.mRoot.addChild(dc, 1);
+ final TaskStack stack2 = createTaskStackOnDisplay(dc);
+ final TestTaskWindowContainerController taskController2 =
+ new TestTaskWindowContainerController(stack2.mStackId);
+ final TestTask task2 = (TestTask) taskController2.mContainer;
+
+ // Reparent and check state
+ taskController.reparent(stack2.mStackId, 0);
+ assertEquals(stack2, task1.getParent());
+ assertEquals(0, task1.positionInParent());
+ assertEquals(1, task2.positionInParent());
+ assertTrue(task1.mOnDisplayChangedCalled);
+ }
}
class TestTask extends Task {
boolean mShouldDeferRemoval = false;
+ boolean mOnDisplayChangedCalled = false;
TestTask(int taskId, TaskStack stack, int userId, WindowManagerService service, Rect bounds,
Configuration overrideConfig, boolean isOnTopLauncher, int resizeMode,
int positionInParent() {
return getParent().mChildren.indexOf(this);
}
+
+ @Override
+ void onDisplayChanged(DisplayContent dc) {
+ super.onDisplayChanged(dc);
+ mOnDisplayChangedCalled = true;
+ }
}
/**