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

Commit 77b165f0 authored by Andrii Kulian's avatar Andrii Kulian Committed by Android (Google) Code Review
Browse files

Merge changes I2ac2cdba,I6ade7874

* changes:
  Fix crash when removing a display with activities
  Add positionChildAt method to WindowContainer
parents 6e8f439e 6cc1a1d6
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) {
+32 −32
Original line number Diff line number Diff line
@@ -712,19 +712,11 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
        if (prevDc == this) {
            return;
        }
        if (prevDc != null && prevDc.mTokenMap.remove(token.token) != null) {
            switch (token.windowType) {
                case TYPE_WALLPAPER:
                    prevDc.mBelowAppWindowsContainers.removeChild(token);
                    break;
                case TYPE_INPUT_METHOD:
                case TYPE_INPUT_METHOD_DIALOG:
                    prevDc.mImeWindowsContainers.removeChild(token);
                    break;
                default:
                    prevDc.mAboveAppWindowsContainers.removeChild(token);
                    break;
            }
        if (prevDc != null && prevDc.mTokenMap.remove(token.token) != null
                && token.asAppWindowToken() == null) {
            // Removed the token from the map, but made sure it's not an app token before removing
            // from parent.
            token.getParent().removeChild(token);
        }

        addWindowToken(token.token, token);
@@ -979,7 +971,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 +1026,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 +1048,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 +2497,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 +2515,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