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

Commit d276563b authored by Andrii Kulian's avatar Andrii Kulian
Browse files

Add positionChildAt method to WindowContainer

Added method to change the position of a child among siblings.
It accepts int value, which can either specify a target position
or POSITION_TOP/POSITION_BOTTOM.
When child is moved to top or bottom, there is an option to also
perform same action on parents. This will effectively move the
entire branch of the hierarchy tree to top/bottom.

Test: bit FrameworksServicesTests:com.android.server.wm.WindowContainerTests
Test: #testPositionChildAt
Test: #testPositionChildAtIncludeParents
Test: #testPositionChildAtInvalid
Test: bit FrameworksServicesTests:com.android.server.wm.TaskStackContainersTests
Test: bit FrameworksServicesTests:com.android.server.wm.TaskStackTests
Change-Id: I6ade787487055f1c9a305afea64270c243196614
parent 9a4d6267
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -453,6 +453,11 @@ interface IActivityManager {
    // Stop Binder transaction tracking for all applications and dump trace data to the given file
    // descriptor.
    boolean stopBinderTrackingAndDump(in ParcelFileDescriptor fd);
    /**
     * Try to place task to provided position. The final position might be different depending on
     * current user and stacks state. The task will be moved to target stack if it's currently in
     * different stack.
     */
    void positionTaskInStack(int taskId, int stackId, int position);
    int getActivityStackId(in IBinder token);
    void exitFreeformMode(in IBinder token);
+5 −0
Original line number Diff line number Diff line
@@ -10044,6 +10044,11 @@ public class ActivityManagerService extends IActivityManager.Stub
        }
    }
    /**
     * Try to place task to provided position. The final position might be different depending on
     * current user and stacks state. The task will be moved to target stack if it's currently in
     * different stack.
     */
    @Override
    public void positionTaskInStack(int taskId, int stackId, int position) {
        enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "positionTaskInStack()");
+5 −0
Original line number Diff line number Diff line
@@ -2547,6 +2547,10 @@ final class ActivityStack extends ConfigurationContainer {
        return null;
    }

    /**
     * Used from {@link ActivityStack#positionTask(TaskRecord, int)}.
     * @see ActivityManagerService#positionTaskInStack(int, int, int).
     */
    private void insertTaskAtPosition(TaskRecord task, int position) {
        if (position >= mTaskHistory.size()) {
            insertTaskAtTop(task, null);
@@ -4935,6 +4939,7 @@ final class ActivityStack extends ConfigurationContainer {
        postAddTask(task, prevStack);
    }

    /** @see ActivityManagerService#positionTaskInStack(int, int, int). */
    void positionTask(final TaskRecord task, int position) {
        final ActivityRecord topRunningActivity = task.topRunningActivityLocked();
        final boolean wasResumed = topRunningActivity == task.getStack().mResumedActivity;
+6 −3
Original line number Diff line number Diff line
@@ -2200,7 +2200,7 @@ public class ActivityStackSupervisor extends ConfigurationContainer
            } else {
                for (int i = size - 1; i >= 0; i--) {
                    positionTaskInStackLocked(tasks.get(i).taskId,
                            FULLSCREEN_WORKSPACE_STACK_ID, 0);
                            FULLSCREEN_WORKSPACE_STACK_ID, 0 /* position */);
                }
            }
        } finally {
@@ -2872,6 +2872,7 @@ public class ActivityStackSupervisor extends ConfigurationContainer
        return true;
    }

    /** @see ActivityManagerService#positionTaskInStack(int, int, int). */
    void positionTaskInStackLocked(int taskId, int stackId, int position) {
        final TaskRecord task = anyTaskForIdLocked(taskId);
        if (task == null) {
@@ -2882,6 +2883,8 @@ public class ActivityStackSupervisor extends ConfigurationContainer

        task.updateOverrideConfigurationForStack(stack);

        // TODO: Return final position from WM for AM to use instead of duplicating computations in
        // ActivityStack#insertTaskAtPosition.
        mWindowManager.positionTaskInStack(
                taskId, stackId, position, task.mBounds, task.getOverrideConfiguration());
        stack.positionTask(task, position);
@@ -4322,7 +4325,7 @@ public class ActivityStackSupervisor extends ConfigurationContainer
                if (activityDisplay == null) {
                    return;
                }
                addToDisplayLocked(activityDisplay, true);
                addToDisplayLocked(activityDisplay, true /* onTop */);
            }
        }

@@ -4538,7 +4541,7 @@ public class ActivityStackSupervisor extends ConfigurationContainer
                        new VirtualActivityDisplay(width, height, density);
                mActivityDisplay = virtualActivityDisplay;
                mActivityDisplays.put(virtualActivityDisplay.mDisplayId, virtualActivityDisplay);
                addToDisplayLocked(virtualActivityDisplay, true);
                addToDisplayLocked(virtualActivityDisplay, true /* onTop */);
            }

            if (mSurface != null) {
+27 −19
Original line number Diff line number Diff line
@@ -979,7 +979,10 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
                // It's already attached to the display...clear mDeferRemoval and move stack to
                // appropriate z-order on display as needed.
                stack.mDeferRemoval = false;
                moveStack(stack, onTop);
                // We're not moving the display to front when we're adding stacks, only when
                // requested to change the position of stack explicitly.
                mTaskStackContainers.positionChildAt(onTop ? POSITION_TOP : POSITION_BOTTOM, stack,
                        false /* includingParents */);
                attachedToDisplay = true;
            } else {
                stack = new TaskStack(mService, stackId);
@@ -1031,10 +1034,6 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
        return addStackToDisplay(stack.mStackId, true /* onTop */);
    }

    void moveStack(TaskStack stack, boolean toTop) {
        mTaskStackContainers.moveStack(stack, toTop);
    }

    @Override
    protected void addChild(DisplayChildWindowContainer child,
            Comparator<DisplayChildWindowContainer> comparator) {
@@ -1057,6 +1056,13 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
        throw new UnsupportedOperationException("See DisplayChildWindowContainer");
    }

    @Override
    void positionChildAt(int position, DisplayChildWindowContainer child, boolean includingParents) {
        // Children of the display are statically ordered, so the real intention here is to perform
        // the operation on the display and not the static direct children.
        getParent().positionChildAt(position, this, includingParents);
    }

    int taskIdFromPoint(int x, int y) {
        for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
            final TaskStack stack = mTaskStackContainers.get(stackNdx);
@@ -2499,20 +2505,6 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
            stack.onRemovedFromDisplay();
        }

        void moveStack(TaskStack stack, boolean toTop) {
            if (StackId.isAlwaysOnTop(stack.mStackId) && !toTop) {
                // This stack is always-on-top silly...
                Slog.w(TAG_WM, "Ignoring move of always-on-top stack=" + stack + " to bottom");
                return;
            }

            if (!mChildren.contains(stack)) {
                Slog.wtf(TAG_WM, "moving stack that was not added: " + stack, new Throwable());
            }
            removeChild(stack);
            addChild(stack, toTop);
        }

        private void addChild(TaskStack stack, boolean toTop) {
            int addIndex = toTop ? mChildren.size() : 0;

@@ -2531,6 +2523,22 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
            setLayoutNeeded();
        }

        @Override
        void positionChildAt(int position, TaskStack child, boolean includingParents) {
            if (StackId.isAlwaysOnTop(child.mStackId) && position != POSITION_TOP) {
                // This stack is always-on-top, override the default behavior.
                Slog.w(TAG_WM, "Ignoring move of always-on-top stack=" + this + " to bottom");

                // Moving to its current position, as we must call super but we don't want to
                // perform any meaningful action.
                final int currentPosition = mChildren.indexOf(child);
                super.positionChildAt(currentPosition, child, false /* includingParents */);
                return;
            }

            super.positionChildAt(position, child, includingParents);
        }

        @Override
        boolean forAllWindows(ToBooleanFunction<WindowState> callback,
                boolean traverseTopToBottom) {
Loading