From e95067c57f31835ce750aefcb3e3d1790b24943f Mon Sep 17 00:00:00 2001 From: Kazuki Takise Date: Fri, 17 Feb 2023 15:05:20 +0900 Subject: [PATCH] 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 --- .../server/wm/ActivityTaskManagerService.java | 7 ------- services/core/java/com/android/server/wm/Task.java | 14 ++++++-------- .../com/android/server/wm/TaskDisplayArea.java | 9 +++++++-- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/services/core/java/com/android/server/wm/ActivityTaskManagerService.java b/services/core/java/com/android/server/wm/ActivityTaskManagerService.java index 5c20cedbee7cd..8d671f768e87a 100644 --- a/services/core/java/com/android/server/wm/ActivityTaskManagerService.java +++ b/services/core/java/com/android/server/wm/ActivityTaskManagerService.java @@ -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); diff --git a/services/core/java/com/android/server/wm/Task.java b/services/core/java/com/android/server/wm/Task.java index 10e4929ded6a9..c2d78632a9361 100644 --- a/services/core/java/com/android/server/wm/Task.java +++ b/services/core/java/com/android/server/wm/Task.java @@ -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); diff --git a/services/core/java/com/android/server/wm/TaskDisplayArea.java b/services/core/java/com/android/server/wm/TaskDisplayArea.java index a0608db35952f..8cbd553fbebd8 100644 --- a/services/core/java/com/android/server/wm/TaskDisplayArea.java +++ b/services/core/java/com/android/server/wm/TaskDisplayArea.java @@ -403,7 +403,7 @@ final class TaskDisplayArea extends DisplayArea { 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 { } } - 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;