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

Commit e95067c5 authored by Kazuki Takise's avatar Kazuki Takise
Browse files

Make TaskStackListener work in freeform mode

Some callbacks of TaskStackListener aren't invoked in freeform
mode when they should be. For example, currently onFocusChanged()
is invoked in setResumedActivityUncheckLocked(), but this
incorrectly assume that focus change is only caused by an activity
getting resumed.

The main idea of this CL is to move the invocation of some
callbacks from the "caller" of the corresponding event to the
"callee" (or at least a bit deepr in the call stack) to ensure
that we don't forget to invoke them in all cases.

Bug: 268131581
Bug: 268130984
Test: atest CtsWindowManagerDeviceTestCases
Change-Id: I6b0cef7cf14fac161346c88250ab05ea50db6f9a
parent e17d89ba
Loading
Loading
Loading
Loading
+0 −7
Original line number Diff line number Diff line
@@ -4764,13 +4764,6 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
                mWindowManager.updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL,
                        true /*updateInputWindows*/);
            }
            if (task != prevFocusTask) {
                if (prevFocusTask != null) {
                    mTaskChangeNotificationController.notifyTaskFocusChanged(
                            prevFocusTask.mTaskId, false);
                }
                mTaskChangeNotificationController.notifyTaskFocusChanged(task.mTaskId, true);
            }
        }
        if (task != prevTask) {
            mTaskSupervisor.mRecentTasks.add(task);
+6 −8
Original line number Diff line number Diff line
@@ -1290,12 +1290,12 @@ class Task extends TaskFragment {
        return null;
    }

    void updateTaskMovement(boolean toTop, int position) {
    void updateTaskMovement(boolean toTop, boolean toBottom, int position) {
        EventLogTags.writeWmTaskMoved(mTaskId, getRootTaskId(), getDisplayId(), toTop ? 1 : 0,
                position);
        final TaskDisplayArea taskDisplayArea = getDisplayArea();
        if (taskDisplayArea != null && isLeafTask()) {
            taskDisplayArea.onLeafTaskMoved(this, toTop);
            taskDisplayArea.onLeafTaskMoved(this, toTop, toBottom);
        }
        if (isPersistable) {
            mLastTimeMoved = System.currentTimeMillis();
@@ -2561,7 +2561,7 @@ class Task extends TaskFragment {

        final Task task = child.asTask();
        if (task != null) {
            task.updateTaskMovement(toTop, position);
            task.updateTaskMovement(toTop, position == POSITION_BOTTOM, position);
        }
    }

@@ -4323,6 +4323,8 @@ class Task extends TaskFragment {
        dispatchTaskInfoChangedIfNeeded(false /* force */);
        final Task parentTask = getParent().asTask();
        if (parentTask != null) parentTask.dispatchTaskInfoChangedIfNeeded(false /* force */);

        mAtmService.getTaskChangeNotificationController().notifyTaskFocusChanged(mTaskId, hasFocus);
    }

    void onPictureInPictureParamsChanged() {
@@ -4655,13 +4657,9 @@ class Task extends TaskFragment {
                final Task lastFocusedTask = displayArea.getFocusedRootTask();
                displayArea.positionChildAt(POSITION_BOTTOM, this, false /*includingParents*/);
                displayArea.updateLastFocusedRootTask(lastFocusedTask, reason);
                mAtmService.getTaskChangeNotificationController().notifyTaskMovedToBack(
                        getTaskInfo());
            }
            if (task != null && task != this) {
                positionChildAtBottom(task);
                mAtmService.getTaskChangeNotificationController().notifyTaskMovedToBack(
                        task.getTaskInfo());
            }
            return;
        }
@@ -5923,7 +5921,7 @@ class Task extends TaskFragment {
        if (canBeLaunchedOnDisplay(newParent.getDisplayId())) {
            reparent(newParent, onTop ? POSITION_TOP : POSITION_BOTTOM);
            if (isLeafTask()) {
                newParent.onLeafTaskMoved(this, onTop);
                newParent.onLeafTaskMoved(this, onTop, !onTop);
            }
        } else {
            Slog.w(TAG, "Task=" + this + " can't reparent to " + newParent);
+7 −2
Original line number Diff line number Diff line
@@ -403,7 +403,7 @@ final class TaskDisplayArea extends DisplayArea<WindowContainer> {
                    this /* child */, true /* includingParents */);
        }

        child.updateTaskMovement(moveToTop, targetPosition);
        child.updateTaskMovement(moveToTop, moveToBottom, targetPosition);

        // The insert position may be adjusted to non-top when there is always-on-top root task.
        // Since the original position is preferred to be top, the root task should have higher
@@ -433,7 +433,12 @@ final class TaskDisplayArea extends DisplayArea<WindowContainer> {
        }
    }

    void onLeafTaskMoved(Task t, boolean toTop) {
    void onLeafTaskMoved(Task t, boolean toTop, boolean toBottom) {
        if (toBottom) {
            mAtmService.getTaskChangeNotificationController().notifyTaskMovedToBack(
                    t.getTaskInfo());
        }

        if (!toTop) {
            if (t.mTaskId == mLastLeafTaskToFrontId) {
                mLastLeafTaskToFrontId = INVALID_TASK_ID;