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

Commit fd5767fa authored by Wale Ogunwale's avatar Wale Ogunwale Committed by Android (Google) Code Review
Browse files

Merge "Remove duplicate move of home stack that can cause animation jank."

parents 15f78bbd d80c263e
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -2480,7 +2480,7 @@ public final class ActivityManagerService extends ActivityManagerNative
    }
    }
    final void setFocusedActivityLocked(ActivityRecord r, String reason) {
    final void setFocusedActivityLocked(ActivityRecord r, String reason) {
        if (mFocusedActivity != r) {
        if (r != null && mFocusedActivity != r) {
            if (DEBUG_FOCUS) Slog.d(TAG, "setFocusedActivityLocked: r=" + r);
            if (DEBUG_FOCUS) Slog.d(TAG, "setFocusedActivityLocked: r=" + r);
            mFocusedActivity = r;
            mFocusedActivity = r;
            if (r.task != null && r.task.voiceInteractor != null) {
            if (r.task != null && r.task.voiceInteractor != null) {
@@ -2488,7 +2488,7 @@ public final class ActivityManagerService extends ActivityManagerNative
            } else {
            } else {
                finishRunningVoiceLocked();
                finishRunningVoiceLocked();
            }
            }
            if (r != null && mStackSupervisor.setFocusedStack(r, reason + " setFocusedActivity")) {
            if (mStackSupervisor.setFocusedStack(r, reason + " setFocusedActivity")) {
                mWindowManager.setFocusedApp(r.appToken, true);
                mWindowManager.setFocusedApp(r.appToken, true);
            }
            }
            applyUpdateLockStateLocked(r);
            applyUpdateLockStateLocked(r);
+11 −4
Original line number Original line Diff line number Diff line
@@ -507,6 +507,8 @@ final class ActivityStack {
                mStacks.remove(this);
                mStacks.remove(this);
                mStacks.add(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.
            if (isOnHomeDisplay()) {
            if (isOnHomeDisplay()) {
                mStackSupervisor.moveHomeStack(homeStack, reason, lastFocusStack);
                mStackSupervisor.moveHomeStack(homeStack, reason, lastFocusStack);
            }
            }
@@ -2573,7 +2575,11 @@ final class ActivityStack {
                    }
                    }
                    // Move the home stack to the top if this stack is fullscreen or there is no
                    // Move the home stack to the top if this stack is fullscreen or there is no
                    // other visible stack.
                    // other visible stack.
                    mStackSupervisor.moveHomeStackTaskToTop(task.getTaskToReturnTo(), myReason);
                    if (mStackSupervisor.moveHomeStackTaskToTop(
                            task.getTaskToReturnTo(), myReason)) {
                        // Activity focus was already adjusted. Nothing else to do...
                        return;
                    }
                }
                }
            }
            }


@@ -3575,7 +3581,6 @@ final class ActivityStack {
                mTaskHistory.remove(taskNdx);
                mTaskHistory.remove(taskNdx);
                mTaskHistory.add(top, task);
                mTaskHistory.add(top, task);
                updateTaskMovement(task, true);
                updateTaskMovement(task, true);
                mWindowManager.moveTaskToTop(task.taskId);
                return;
                return;
            }
            }
        }
        }
@@ -3600,12 +3605,14 @@ final class ActivityStack {
        // Shift all activities with this task up to the top
        // Shift all activities with this task up to the top
        // of the stack, keeping them in the same internal order.
        // of the stack, keeping them in the same internal order.
        insertTaskAtTop(tr);
        insertTaskAtTop(tr);
        moveToFront(reason);

        // Set focus to the top running activity of this stack.
        ActivityRecord r = topRunningActivityLocked(null);
        mService.setFocusedActivityLocked(r, reason);


        if (DEBUG_TRANSITION) Slog.v(TAG, "Prepare to front transition: task=" + tr);
        if (DEBUG_TRANSITION) Slog.v(TAG, "Prepare to front transition: task=" + tr);
        if (noAnimation) {
        if (noAnimation) {
            mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE, false);
            mWindowManager.prepareAppTransition(AppTransition.TRANSIT_NONE, false);
            ActivityRecord r = topRunningActivityLocked(null);
            if (r != null) {
            if (r != null) {
                mNoAnimActivities.add(r);
                mNoAnimActivities.add(r);
            }
            }
+34 −23
Original line number Original line Diff line number Diff line
@@ -17,6 +17,8 @@
package com.android.server.am;
package com.android.server.am;


import static android.Manifest.permission.START_ANY_ACTIVITY;
import static android.Manifest.permission.START_ANY_ACTIVITY;
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TASK;
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
import static android.content.Intent.FLAG_ACTIVITY_TASK_ON_HOME;
import static android.content.Intent.FLAG_ACTIVITY_TASK_ON_HOME;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
@@ -441,13 +443,21 @@ public final class ActivityStackSupervisor implements DisplayListener {
        }
        }
    }
    }


    void moveHomeStackTaskToTop(int homeStackTaskType, String 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) {
        if (homeStackTaskType == RECENTS_ACTIVITY_TYPE) {
            mWindowManager.showRecentApps();
            mWindowManager.showRecentApps();
            return;
            return false;
        }
        }
        moveHomeStack(true, reason);

        mHomeStack.moveHomeStackTaskToTop(homeStackTaskType);
        mHomeStack.moveHomeStackTaskToTop(homeStackTaskType);

        final ActivityRecord top = mHomeStack.topRunningActivityLocked(null);
        if (top == null) {
            return false;
        }
        mService.setFocusedActivityLocked(top, reason);
        return true;
    }
    }


    boolean resumeHomeStackTask(int homeStackTaskType, ActivityRecord prev, String reason) {
    boolean resumeHomeStackTask(int homeStackTaskType, ActivityRecord prev, String reason) {
@@ -460,14 +470,13 @@ public final class ActivityStackSupervisor implements DisplayListener {
            mWindowManager.showRecentApps();
            mWindowManager.showRecentApps();
            return false;
            return false;
        }
        }
        moveHomeStackTaskToTop(homeStackTaskType, reason);

        if (prev != null) {
        if (prev != null) {
            prev.task.setTaskToReturnTo(APPLICATION_ACTIVITY_TYPE);
            prev.task.setTaskToReturnTo(APPLICATION_ACTIVITY_TYPE);
        }
        }


        ActivityRecord r = mHomeStack.topRunningActivityLocked(null);
        ActivityRecord r = mHomeStack.topRunningActivityLocked(null);
        // if (r != null && (r.isHomeActivity() || r.isRecentsActivity())) {
        if (r != null) {
        if (r != null && r.isHomeActivity()) {
            mService.setFocusedActivityLocked(r, reason);
            mService.setFocusedActivityLocked(r, reason);
            return resumeTopActivitiesLocked(mHomeStack, prev, null);
            return resumeTopActivitiesLocked(mHomeStack, prev, null);
        }
        }
@@ -1874,11 +1883,6 @@ public final class ActivityStackSupervisor implements DisplayListener {
                    if (r.task == null) {
                    if (r.task == null) {
                        r.task = intentActivity.task;
                        r.task = intentActivity.task;
                    }
                    }
                    targetStack = intentActivity.task.stack;
                    targetStack.mLastPausedActivity = null;
                    if (DEBUG_TASKS) Slog.d(TAG, "Bring to front target: " + targetStack
                            + " from " + intentActivity);
                    targetStack.moveToFront("intentActivityFound");
                    if (intentActivity.task.intent == null) {
                    if (intentActivity.task.intent == null) {
                        // This task was started because of movement of
                        // This task was started because of movement of
                        // the activity based on affinity...  now that we
                        // the activity based on affinity...  now that we
@@ -1886,29 +1890,31 @@ public final class ActivityStackSupervisor implements DisplayListener {
                        // base intent.
                        // base intent.
                        intentActivity.task.setIntent(r);
                        intentActivity.task.setIntent(r);
                    }
                    }
                    targetStack = intentActivity.task.stack;
                    targetStack.mLastPausedActivity = null;
                    // If the target task is not in the front, then we need
                    // If the target task is not in the front, then we need
                    // to bring it to the front...  except...  well, with
                    // to bring it to the front...  except...  well, with
                    // SINGLE_TASK_LAUNCH it's not entirely clear.  We'd like
                    // SINGLE_TASK_LAUNCH it's not entirely clear.  We'd like
                    // to have the same behavior as if a new instance was
                    // to have the same behavior as if a new instance was
                    // being started, which means not bringing it to the front
                    // being started, which means not bringing it to the front
                    // if the caller is not itself in the front.
                    // if the caller is not itself in the front.
                    final ActivityStack lastStack = getLastStack();
                    final ActivityStack focusStack = getFocusedStack();
                    ActivityRecord curTop = lastStack == null?
                    ActivityRecord curTop = (focusStack == null)
                            null : lastStack.topRunningNonDelayedActivityLocked(notTop);
                            ? null : focusStack.topRunningNonDelayedActivityLocked(notTop);
                    boolean movedToFront = false;
                    boolean movedToFront = false;
                    if (curTop != null && (curTop.task != intentActivity.task ||
                    if (curTop != null && (curTop.task != intentActivity.task ||
                            curTop.task != lastStack.topTask())) {
                            curTop.task != focusStack.topTask())) {
                        r.intent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
                        r.intent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
                        if (sourceRecord == null || (sourceStack.topActivity() != null &&
                        if (sourceRecord == null || (sourceStack.topActivity() != null &&
                                sourceStack.topActivity().task == sourceRecord.task)) {
                                sourceStack.topActivity().task == sourceRecord.task)) {
                            // We really do want to push this one into the
                            // We really do want to push this one into the user's face, right now.
                            // user's face, right now.
                            if (launchTaskBehind && sourceRecord != null) {
                            if (launchTaskBehind && sourceRecord != null) {
                                intentActivity.setTaskToAffiliateWith(sourceRecord.task);
                                intentActivity.setTaskToAffiliateWith(sourceRecord.task);
                            }
                            }
                            movedHome = true;
                            movedHome = true;
                            targetStack.moveTaskToFrontLocked(intentActivity.task, noAnimation,
                            targetStack.moveTaskToFrontLocked(intentActivity.task, noAnimation,
                                    options, "bringingFoundTaskToFront");
                                    options, "bringingFoundTaskToFront");
                            movedToFront = true;
                            if ((launchFlags &
                            if ((launchFlags &
                                    (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_TASK_ON_HOME))
                                    (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_TASK_ON_HOME))
                                    == (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_TASK_ON_HOME)) {
                                    == (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_TASK_ON_HOME)) {
@@ -1916,9 +1922,14 @@ public final class ActivityStackSupervisor implements DisplayListener {
                                intentActivity.task.setTaskToReturnTo(HOME_ACTIVITY_TYPE);
                                intentActivity.task.setTaskToReturnTo(HOME_ACTIVITY_TYPE);
                            }
                            }
                            options = null;
                            options = null;
                            movedToFront = true;
                        }
                        }
                    }
                    }
                    if (!movedToFront) {
                        if (DEBUG_TASKS) Slog.d(TAG, "Bring to front target: " + targetStack
                                + " from " + intentActivity);
                        targetStack.moveToFront("intentActivityFound");
                    }

                    // If the caller has requested that the target task be
                    // If the caller has requested that the target task be
                    // reset, then do so.
                    // reset, then do so.
                    if ((launchFlags&Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) != 0) {
                    if ((launchFlags&Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) != 0) {
@@ -1943,15 +1954,15 @@ public final class ActivityStackSupervisor implements DisplayListener {
                        return ActivityManager.START_RETURN_INTENT_TO_CALLER;
                        return ActivityManager.START_RETURN_INTENT_TO_CALLER;
                    }
                    }
                    if ((launchFlags &
                    if ((launchFlags &
                            (Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TASK))
                            (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK))
                            == (Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TASK)) {
                            == (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK)) {
                        // The caller has requested to completely replace any
                        // The caller has requested to completely replace any
                        // existing task with its new activity.  Well that should
                        // existing task with its new activity.  Well that should
                        // not be too hard...
                        // not be too hard...
                        reuseTask = intentActivity.task;
                        reuseTask = intentActivity.task;
                        reuseTask.performClearTaskLocked();
                        reuseTask.performClearTaskLocked();
                        reuseTask.setIntent(r);
                        reuseTask.setIntent(r);
                    } else if ((launchFlags&Intent.FLAG_ACTIVITY_CLEAR_TOP) != 0
                    } else if ((launchFlags & FLAG_ACTIVITY_CLEAR_TOP) != 0
                            || launchSingleInstance || launchSingleTask) {
                            || launchSingleInstance || launchSingleTask) {
                        // In this situation we want to remove all activities
                        // In this situation we want to remove all activities
                        // from the task up to the one being started.  In most
                        // from the task up to the one being started.  In most
@@ -2120,8 +2131,8 @@ public final class ActivityStackSupervisor implements DisplayListener {
            }
            }
            if (!movedHome) {
            if (!movedHome) {
                if ((launchFlags &
                if ((launchFlags &
                        (Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_TASK_ON_HOME))
                        (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_TASK_ON_HOME))
                        == (Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_TASK_ON_HOME)) {
                        == (FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_TASK_ON_HOME)) {
                    // Caller wants to appear on home activity, so before starting
                    // Caller wants to appear on home activity, so before starting
                    // their own activity we will bring home to the front.
                    // their own activity we will bring home to the front.
                    r.task.setTaskToReturnTo(HOME_ACTIVITY_TYPE);
                    r.task.setTaskToReturnTo(HOME_ACTIVITY_TYPE);