Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7cd7c2d3 authored by Andrii Kulian's avatar Andrii Kulian
Browse files

Notify task about display change when moved to new stack

Bug: 34176283
Test: android.server.cts.ActivityManagerDisplayTests
Test: #testMoveTaskBetweenDisplays
Test: bit FrameworksServicesTests:com.android.server.wm.TaskWindowContainerControllerTests
Test: bit FrameworksServicesTests:com.android.server.wm.TaskStackContainersTests
Change-Id: If085246926790089e014a94093d788805e812489
parent 7d13f29b
Loading
Loading
Loading
Loading
+9 −5
Original line number Diff line number Diff line
@@ -1437,6 +1437,12 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
        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.
     */
@@ -2565,9 +2571,7 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
                    : 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) {
@@ -2577,8 +2581,8 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
                // 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;
            }

+10 −0
Original line number Diff line number Diff line
@@ -186,8 +186,18 @@ class Task extends WindowContainer<AppWindowToken> implements DimLayer.DimLayerU
        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). */
+0 −2
Original line number Diff line number Diff line
@@ -117,8 +117,6 @@ public class TaskWindowContainerController
                throw new IllegalArgumentException("reparent: could not find stackId=" + stackId);
            }
            mContainer.reparent(stack, position);
            final DisplayContent displayContent = stack.getDisplayContent();
            displayContent.setLayoutNeeded();
            mService.mWindowPlacerLocked.performSurfacePlacement();
        }
    }
+31 −0
Original line number Diff line number Diff line
@@ -17,13 +17,17 @@
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;
@@ -88,6 +92,33 @@ public class TaskStackContainersTests extends WindowTestsBase {
        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) {
+34 −0
Original line number Diff line number Diff line
@@ -16,11 +16,16 @@

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;
@@ -106,4 +111,33 @@ public class TaskWindowContainerControllerTests extends WindowTestsBase {
        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);
    }
}
Loading