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

Commit 925d0d13 authored by Wale Ogunwale's avatar Wale Ogunwale
Browse files

Make home stack move like another stack.

Previously the home stack was either positioned at the top or bottom
of the stack list. This type of movement was okay when there was mainly
2 stacks (home and app), but doesn't work in all cases where we have
multiple stacks.
For example:
1. Launch any activity in the freeform stack
2. Press the home button
3. Launch a translucent or dialog activity
In this case you would except the home stack to be seen behind the
translucent activity since that is the stack the user is coming from,
but you see the freeform stack instead since the home stack was moved
to the bottom of all stacks when the translucent activity was launched.
We no longer move the home stack to the bottom when a new
activity/task/stack comes to the front.

Bug: 23626353
Change-Id: Ic506acc8528e63b8e7f999dd88a450bee6fb4552
parent 53b06950
Loading
Loading
Loading
Loading
+10 −17
Original line number Diff line number Diff line
@@ -528,21 +528,15 @@ final class ActivityStack {
     * */
    void moveToFront(String reason, TaskRecord task) {
        if (isAttached()) {
            final boolean homeStack = isHomeStack()
                    || (mActivityContainer.mParentActivity != null
                        && mActivityContainer.mParentActivity.isHomeActivity());
            ActivityStack lastFocusStack = null;
            if (!homeStack) {
            final ActivityStack lastFocusStack = mStacks.get(mStacks.size() - 1);
            // Need to move this stack to the front before calling
                // {@link ActivityStackSupervisor#moveHomeStack} below.
                lastFocusStack = mStacks.get(mStacks.size() - 1);
            // {@link ActivityStackSupervisor#setFocusStack} below.
            mStacks.remove(this);
            mStacks.add(this);
            }
            // TODO(multi-display): Focus stack currently adjusted in call to move home stack.
            // Needs to also work if focus is moving to the non-home display.

            // TODO(multi-display): Needs to also work if focus is moving to the non-home display.
            if (isOnHomeDisplay()) {
                mStackSupervisor.moveHomeStack(homeStack, reason, lastFocusStack);
                mStackSupervisor.setFocusStack(reason, lastFocusStack);
            }
            if (task != null) {
                insertTaskAtTop(task, null);
@@ -4536,18 +4530,17 @@ final class ActivityStack {

        if (mTaskHistory.isEmpty()) {
            if (DEBUG_STACK) Slog.i(TAG_STACK, "removeTask: removing stack=" + this);
            final boolean notHomeStack = !isHomeStack();
            if (isOnHomeDisplay()) {
                String myReason = reason + " leftTaskHistoryEmpty";
                if (mFullscreen || !adjustFocusToNextVisibleStackLocked(null, myReason)) {
                    mStackSupervisor.moveHomeStack(notHomeStack, myReason);
                    mStackSupervisor.moveHomeStackToFront(myReason);
                }
            }
            if (mStacks != null) {
                mStacks.remove(this);
                mStacks.add(0, this);
            }
            if (notHomeStack) {
            if (!isHomeStack()) {
                mActivityContainer.onTaskListEmptyLocked();
            }
        }
+11 −24
Original line number Diff line number Diff line
@@ -464,35 +464,22 @@ public final class ActivityStackSupervisor implements DisplayListener {
        return stack == mFocusedStack;
    }

    void moveHomeStack(boolean toFront, String reason) {
        moveHomeStack(toFront, reason, null);
    }

    void moveHomeStack(boolean toFront, String reason, ActivityStack lastFocusedStack) {
    void setFocusStack(String reason, ActivityStack lastFocusedStack) {
        ArrayList<ActivityStack> stacks = mHomeStack.mStacks;
        final int topNdx = stacks.size() - 1;
        if (topNdx <= 0) {
            return;
        }

        // The home stack should either be at the top or bottom of the stack list.
        if ((toFront && (stacks.get(topNdx) != mHomeStack))
                || (!toFront && (stacks.get(0) != mHomeStack))) {
            if (DEBUG_STACK) Slog.d(TAG_STACK, "moveHomeTask: topStack old="
                    + ((lastFocusedStack != null) ? lastFocusedStack : stacks.get(topNdx))
                    + " new=" + mFocusedStack);
            stacks.remove(mHomeStack);
            stacks.add(toFront ? topNdx : 0, mHomeStack);
        }

        final ActivityStack topStack = stacks.get(topNdx);
        mFocusedStack = topStack;
        if (lastFocusedStack != null) {
            mLastFocusedStack = lastFocusedStack;
        }
        mFocusedStack = stacks.get(topNdx);

        EventLog.writeEvent(EventLogTags.AM_HOME_STACK_MOVED,
                mCurrentUser, toFront ? 1 : 0, stacks.get(topNdx).getStackId(),
                mFocusedStack == null ? -1 : mFocusedStack.getStackId(), reason);
        EventLogTags.writeAmFocusedStack(
                mCurrentUser, mFocusedStack == null ? -1 : mFocusedStack.getStackId(),
                mLastFocusedStack == null ? -1 : mLastFocusedStack.getStackId(), reason);

        if (mService.mBooting || !mService.mBooted) {
            final ActivityRecord r = topRunningActivityLocked();
@@ -502,6 +489,10 @@ public final class ActivityStackSupervisor implements DisplayListener {
        }
    }

    void moveHomeStackToFront(String reason) {
        mHomeStack.moveToFront(reason);
    }

    /** Returns true if the focus activity was adjusted to the home stack top activity. */
    boolean moveHomeStackTaskToTop(int homeStackTaskType, String reason) {
        if (homeStackTaskType == RECENTS_ACTIVITY_TYPE) {
@@ -3650,11 +3641,7 @@ public final class ActivityStackSupervisor implements DisplayListener {
        }
        final boolean homeInFront = stack.isHomeStack();
        if (stack.isOnHomeDisplay()) {
            moveHomeStack(homeInFront, "switchUserOnHomeDisplay");
            TaskRecord task = stack.topTask();
            if (task != null) {
                mWindowManager.moveTaskToTop(task.taskId);
            }
            stack.moveToFront("switchUserOnHomeDisplay");
        } else {
            // Stack was moved to another display while user was swapped out.
            resumeHomeStackTask(HOME_ACTIVITY_TYPE, null, "switchUserOnOtherDisplay");
+2 −2
Original line number Diff line number Diff line
@@ -93,8 +93,8 @@ option java_package com.android.server.am
# Activity focused
30043 am_focused_activity (User|1|5),(Component Name|3)

# Home Stack brought to front or rear
30044 am_home_stack_moved (User|1|5),(To Front|1|5),(Top Stack Id|1|5),(Focused Stack Id|1|5),(Reason|3)
# Stack focus
30044 am_focused_stack (User|1|5),(Focused Stack Id|1|5),(Last Focused Stack Id|1|5),(Reason|3)

# Running pre boot receiver
30045 am_pre_boot (User|1|5),(Package|3)