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

Commit c4abd811 authored by Louis Chang's avatar Louis Chang
Browse files

Prevent doing redundant task movements

wm_task_moved log is now dumped for every task movements which
makes the redundant task movement obvious and can be easily
observed from event logs.

Bug: 134632511
Test: making activities switch and check event logs
Change-Id: Id2b77e79c5758bc50b48d990d918529cf00c1a60
parent 4b94029f
Loading
Loading
Loading
Loading
+9 −18
Original line number Diff line number Diff line
@@ -5264,14 +5264,12 @@ class Task extends WindowContainer<WindowContainer> {
            taskDisplayArea.moveHomeStackToFront(reason + " returnToHome");
        }

        if (isRootTask()) {
            taskDisplayArea.positionChildAt(POSITION_TOP, this, false /* includingParents */,
                    reason);
        }
        final Task lastFocusedTask = isRootTask() ? taskDisplayArea.getFocusedStack() : null;
        if (task == null) {
            task = this;
        }
        task.getParent().positionChildAt(POSITION_TOP, task, true /* includingParents */);
        taskDisplayArea.updateLastFocusedRootTask(lastFocusedTask, reason);
    }

    /**
@@ -5294,8 +5292,9 @@ class Task extends WindowContainer<WindowContainer> {
            if (parentTask != null) {
                parentTask.moveToBack(reason, this);
            } else {
                displayArea.positionChildAt(POSITION_BOTTOM, this, false /*includingParents*/,
                        reason);
                final Task lastFocusedTask = displayArea.getFocusedStack();
                displayArea.positionChildAt(POSITION_BOTTOM, this, false /*includingParents*/);
                displayArea.updateLastFocusedRootTask(lastFocusedTask, reason);
            }
            if (task != null && task != this) {
                positionChildAtBottom(task);
@@ -6822,13 +6821,10 @@ class Task extends WindowContainer<WindowContainer> {
            // get calculated incorrectly.
            mDisplayContent.deferUpdateImeTarget();

            // Shift all activities with this task up to the top
            // of the stack, keeping them in the same internal order.
            positionChildAtTop(tr);

            // Don't refocus if invisible to current user
            final ActivityRecord top = tr.getTopNonFinishingActivity();
            if (top == null || !top.okToShowLocked()) {
                positionChildAtTop(tr);
                if (top != null) {
                    mStackSupervisor.mRecentTasks.add(top.getTask());
                }
@@ -6836,20 +6832,15 @@ class Task extends WindowContainer<WindowContainer> {
                return;
            }

            // Set focus to the top running activity of this stack.
            final ActivityRecord r = topRunningActivity();
            if (r != null) {
                r.moveFocusableActivityToTop(reason);
            }
            // Set focus to the top running activity of this task and move all its parents to top.
            top.moveFocusableActivityToTop(reason);

            if (DEBUG_TRANSITION) Slog.v(TAG_TRANSITION, "Prepare to front transition: task=" + tr);
            if (noAnimation) {
                mDisplayContent.prepareAppTransitionOld(TRANSIT_OLD_NONE,
                        false /* alwaysKeepCurrent */);
                mDisplayContent.prepareAppTransition(TRANSIT_NONE);
                if (r != null) {
                    mStackSupervisor.mNoAnimActivities.add(r);
                }
                mStackSupervisor.mNoAnimActivities.add(top);
                ActivityOptions.abort(options);
            } else {
                updateTransitLocked(TRANSIT_OLD_TASK_TO_FRONT, TRANSIT_TO_FRONT,
+18 −23
Original line number Diff line number Diff line
@@ -334,29 +334,6 @@ final class TaskDisplayArea extends DisplayArea<Task> {
        return true;
    }

    void positionChildAt(int position, Task child, boolean includingParents,
            String updateLastFocusedTaskReason) {
        final Task prevFocusedTask = updateLastFocusedTaskReason != null ? getFocusedStack() : null;

        positionChildAt(position, child, includingParents);

        if (updateLastFocusedTaskReason == null) {
            return;
        }

        final Task currentFocusedStack = getFocusedStack();
        if (currentFocusedStack == prevFocusedTask) {
            return;
        }

        mLastFocusedStack = prevFocusedTask;
        EventLogTags.writeWmFocusedStack(mRootWindowContainer.mCurrentUser,
                mDisplayContent.mDisplayId,
                currentFocusedStack == null ? -1 : currentFocusedStack.getRootTaskId(),
                mLastFocusedStack == null ? -1 : mLastFocusedStack.getRootTaskId(),
                updateLastFocusedTaskReason);
    }

    @Override
    void positionChildAt(int position, Task child, boolean includingParents) {
        final boolean moveToTop = position >= getChildCount() - 1;
@@ -1189,6 +1166,24 @@ final class TaskDisplayArea extends DisplayArea<Task> {
        return mLastFocusedStack;
    }

    void updateLastFocusedRootTask(Task prevFocusedTask, String updateLastFocusedTaskReason) {
        if (updateLastFocusedTaskReason == null) {
            return;
        }

        final Task currentFocusedTask = getFocusedStack();
        if (currentFocusedTask == prevFocusedTask) {
            return;
        }

        mLastFocusedStack = prevFocusedTask;
        EventLogTags.writeWmFocusedStack(mRootWindowContainer.mCurrentUser,
                mDisplayContent.mDisplayId,
                currentFocusedTask == null ? -1 : currentFocusedTask.getRootTaskId(),
                mLastFocusedStack == null ? -1 : mLastFocusedStack.getRootTaskId(),
                updateLastFocusedTaskReason);
    }

    boolean allResumedActivitiesComplete() {
        for (int stackNdx = getStackCount() - 1; stackNdx >= 0; --stackNdx) {
            final ActivityRecord r = getStackAt(stackNdx).getResumedActivity();