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

Commit 7c3ede36 authored by Winson Chung's avatar Winson Chung
Browse files

Fixing crash when enforcing top stack.

- When updating the stack list, the insert index should take the
  always-on-top stacks when calculating the stack index to insert into.

Test: android.server.cts.ActivityManagerAssistantStackTests
Change-Id: I30aee7395a12c983fe9b778ef57dea9f76008dde
parent 38303862
Loading
Loading
Loading
Loading
+22 −11
Original line number Diff line number Diff line
@@ -66,6 +66,7 @@ import static com.android.server.am.ActivityRecord.APPLICATION_ACTIVITY_TYPE;
import static com.android.server.am.ActivityRecord.ASSISTANT_ACTIVITY_TYPE;
import static com.android.server.am.ActivityRecord.HOME_ACTIVITY_TYPE;
import static com.android.server.am.ActivityStackSupervisor.FindTaskResult;
import static com.android.server.am.ActivityStackSupervisor.ON_TOP;
import static com.android.server.am.ActivityStackSupervisor.PRESERVE_WINDOWS;
import static com.android.server.wm.AppTransition.TRANSIT_ACTIVITY_CLOSE;
import static com.android.server.wm.AppTransition.TRANSIT_ACTIVITY_OPEN;
@@ -505,7 +506,7 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
        }
        onParentChanged();

        activityDisplay.attachStack(this, onTop);
        activityDisplay.attachStack(this, findStackInsertIndex(onTop));
        if (mStackId == DOCKED_STACK_ID) {
            // If we created a docked stack we want to resize it so it resizes all other stacks
            // in the system.
@@ -799,16 +800,7 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
        }

        mStacks.remove(this);
        int addIndex = mStacks.size();
        if (addIndex > 0) {
            final ActivityStack topStack = mStacks.get(addIndex - 1);
            if (StackId.isAlwaysOnTop(topStack.mStackId) && topStack != this) {
                // If the top stack is always on top, we move this stack just below it.
                addIndex--;
            }
        }

        mStacks.add(addIndex, this);
        mStacks.add(findStackInsertIndex(ON_TOP), this);
        mStackSupervisor.setFocusStackUnchecked(reason, this);
        if (task != null) {
            insertTaskAtTop(task, null);
@@ -841,6 +833,25 @@ class ActivityStack<T extends StackWindowController> extends ConfigurationContai
        }
    }

    /**
     * @return the index to insert a new stack into, taking the always-on-top stacks into account.
     */
    private int findStackInsertIndex(boolean onTop) {
        if (onTop) {
            int addIndex = mStacks.size();
            if (addIndex > 0) {
                final ActivityStack topStack = mStacks.get(addIndex - 1);
                if (StackId.isAlwaysOnTop(topStack.mStackId) && topStack != this) {
                    // If the top stack is always on top, we move this stack just below it.
                    addIndex--;
                }
            }
            return addIndex;
        } else {
            return 0;
        }
    }

    boolean isFocusable() {
        if (StackId.canReceiveKeys(mStackId)) {
            return true;
+3 −7
Original line number Diff line number Diff line
@@ -4654,14 +4654,10 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D
            mDisplayId = display.getDisplayId();
        }

        void attachStack(ActivityStack stack, boolean onTop) {
        void attachStack(ActivityStack stack, int position) {
            if (DEBUG_STACK) Slog.v(TAG_STACK, "attachStack: attaching " + stack
                    + " to displayId=" + mDisplayId + " onTop=" + onTop);
            if (onTop) {
                mStacks.add(stack);
            } else {
                mStacks.add(0, stack);
            }
                    + " to displayId=" + mDisplayId + " position=" + position);
            mStacks.add(position, stack);
        }

        void detachStack(ActivityStack stack) {