From b944f19d5040f967f55e620458cdfa9fac182b13 Mon Sep 17 00:00:00 2001 From: Evan Rosky Date: Thu, 4 Mar 2021 13:42:23 -0800 Subject: [PATCH] Fix some legacy-transition timing issues in split-screen This does 2 things: 1. Leash-setup was originally made asymmetric to handle tasks switching between organized and non-organized; however, now the tasks don't do that so we can symmetrize this again. 2. TaskInfoChanged reporting was added to ensureActivityVisibility. This causes noise as it can repeatedly send unchanged TaskInfos to shell. The result is that the legacy split organizer will reposition its surface while it is on an animation leash. To avoid this, keep track of the last positions and only update it if it changes. This maintains a contract that as long as the task's actual position doesn't change (ie. during an animation), the shell won't clobber changes made by legacy-transition's leashing. This can be cleaned up once we move to shell transitions where ownership is better defined. Bug: 172840531 Test: open 2 apps in split and observe no offset in launcher Change-Id: I262e3a53b7497192e234d4a8ba215e10ed73a145 --- .../LegacySplitScreenTaskListener.java | 18 +++++++++++++++--- .../core/java/com/android/server/wm/Task.java | 1 - 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/legacysplitscreen/LegacySplitScreenTaskListener.java b/libs/WindowManager/Shell/src/com/android/wm/shell/legacysplitscreen/LegacySplitScreenTaskListener.java index 05526018d73f0..f4c0f9384705b 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/legacysplitscreen/LegacySplitScreenTaskListener.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/legacysplitscreen/LegacySplitScreenTaskListener.java @@ -52,6 +52,9 @@ class LegacySplitScreenTaskListener implements ShellTaskOrganizer.TaskListener { private final SyncTransactionQueue mSyncQueue; private final SparseArray mLeashByTaskId = new SparseArray<>(); + // TODO(shell-transitions): Remove when switched to shell-transitions. + private final SparseArray mPositionByTaskId = new SparseArray<>(); + RunningTaskInfo mPrimary; RunningTaskInfo mSecondary; SurfaceControl mPrimarySurface; @@ -167,6 +170,7 @@ class LegacySplitScreenTaskListener implements ShellTaskOrganizer.TaskListener { @Override public void onTaskVanished(RunningTaskInfo taskInfo) { synchronized (this) { + mPositionByTaskId.remove(taskInfo.taskId); if (taskInfo.hasParentTask()) { mLeashByTaskId.remove(taskInfo.taskId); return; @@ -200,16 +204,24 @@ class LegacySplitScreenTaskListener implements ShellTaskOrganizer.TaskListener { } synchronized (this) { if (taskInfo.hasParentTask()) { + // changed messages are noisy since it reports on every ensureVisibility. This + // conflicts with legacy app-transitions which "swaps" the position to a + // leash. For now, only update when position actually changes to avoid + // poorly-timed duplicate calls. + if (taskInfo.positionInParent.equals(mPositionByTaskId.get(taskInfo.taskId))) { + return; + } handleChildTaskChanged(taskInfo); - return; + } else { + handleTaskInfoChanged(taskInfo); } - - handleTaskInfoChanged(taskInfo); + mPositionByTaskId.put(taskInfo.taskId, new Point(taskInfo.positionInParent)); } } private void handleChildTaskAppeared(RunningTaskInfo taskInfo, SurfaceControl leash) { mLeashByTaskId.put(taskInfo.taskId, leash); + mPositionByTaskId.put(taskInfo.taskId, new Point(taskInfo.positionInParent)); if (Transitions.ENABLE_SHELL_TRANSITIONS) return; updateChildTaskSurface(taskInfo, leash, true /* firstAppeared */); } diff --git a/services/core/java/com/android/server/wm/Task.java b/services/core/java/com/android/server/wm/Task.java index 5efbb0956823b..c4087a8ce699e 100644 --- a/services/core/java/com/android/server/wm/Task.java +++ b/services/core/java/com/android/server/wm/Task.java @@ -3625,7 +3625,6 @@ class Task extends WindowContainer { @Override void resetSurfacePositionForAnimationLeash(SurfaceControl.Transaction t) { - if (isOrganized()) return; super.resetSurfacePositionForAnimationLeash(t); }