diff options
3 files changed, 90 insertions, 79 deletions
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/taskview/TaskViewTaskController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/taskview/TaskViewTaskController.java index 556cfd2c841e..4e486016a23a 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/taskview/TaskViewTaskController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/taskview/TaskViewTaskController.java @@ -135,6 +135,10 @@ public class TaskViewTaskController implements ShellTaskOrganizer.TaskListener { return mTaskToken; } + void setResizeBgColor(SurfaceControl.Transaction t, int bgColor) { + mTaskViewBase.setResizeBgColor(t, bgColor); + } + /** * Only one listener may be set on the view, throws an exception otherwise. */ @@ -489,72 +493,23 @@ public class TaskViewTaskController implements ShellTaskOrganizer.TaskListener { resetTaskInfo(); } - void prepareOpenAnimation(final boolean newTask, - @NonNull SurfaceControl.Transaction startTransaction, - @NonNull SurfaceControl.Transaction finishTransaction, - ActivityManager.RunningTaskInfo taskInfo, SurfaceControl leash, - WindowContainerTransaction wct) { - prepareOpenAnimationInternal(newTask, startTransaction, finishTransaction, taskInfo, leash, - wct); - } - - private TaskViewRepository.TaskViewState getState() { - return mTaskViewTransitions.getRepository().byTaskView(this); - } - - private void prepareOpenAnimationInternal(final boolean newTask, - SurfaceControl.Transaction startTransaction, - SurfaceControl.Transaction finishTransaction, - ActivityManager.RunningTaskInfo taskInfo, SurfaceControl leash, - WindowContainerTransaction wct) { + /** + * Prepare this taskview to open {@param taskInfo}. + * @return The bounds of the task or {@code null} on failure (surface is destroyed) + */ + Rect prepareOpen(ActivityManager.RunningTaskInfo taskInfo, SurfaceControl leash) { mPendingInfo = null; mTaskInfo = taskInfo; mTaskToken = mTaskInfo.token; mTaskLeash = leash; - if (mSurfaceCreated) { - // Surface is ready, so just reparent the task to this surface control - startTransaction.reparent(mTaskLeash, mSurfaceControl) - .show(mTaskLeash); - // Also reparent on finishTransaction since the finishTransaction will reparent back - // to its "original" parent by default. - Rect boundsOnScreen = mTaskViewBase.getCurrentBoundsOnScreen(); - if (finishTransaction != null) { - finishTransaction.reparent(mTaskLeash, mSurfaceControl) - .setPosition(mTaskLeash, 0, 0) - // TODO: maybe once b/280900002 is fixed this will be unnecessary - .setWindowCrop(mTaskLeash, boundsOnScreen.width(), boundsOnScreen.height()); - } - if (TaskViewTransitions.useRepo()) { - final TaskViewRepository.TaskViewState state = getState(); - if (state != null) { - state.mBounds.set(boundsOnScreen); - state.mVisible = true; - } - } else { - mTaskViewTransitions.updateBoundsState(this, boundsOnScreen); - mTaskViewTransitions.updateVisibilityState(this, true /* visible */); - } - wct.setBounds(mTaskToken, boundsOnScreen); - applyCaptionInsetsIfNeeded(); - } else { - // The surface has already been destroyed before the task has appeared, - // so go ahead and hide the task entirely - wct.setHidden(mTaskToken, true /* hidden */); - mTaskViewTransitions.updateVisibilityState(this, false /* visible */); - // listener callback is below - } - if (newTask) { - mTaskOrganizer.setInterceptBackPressedOnTaskRoot(mTaskToken, true /* intercept */); - } - - if (mTaskInfo.taskDescription != null) { - int backgroundColor = mTaskInfo.taskDescription.getBackgroundColor(); - mTaskViewBase.setResizeBgColor(startTransaction, backgroundColor); + if (!mSurfaceCreated) { + return null; } + return mTaskViewBase.getCurrentBoundsOnScreen(); + } - // After the embedded task has appeared, set it to non-trimmable. This is important - // to prevent recents from trimming and removing the embedded task. - wct.setTaskTrimmableFromRecents(taskInfo.token, false /* isTrimmableFromRecents */); + /** Notify that the associated task has appeared. This will call appropriate listeners. */ + void notifyAppeared(final boolean newTask) { mTaskViewBase.onTaskAppeared(mTaskInfo, mTaskLeash); if (mListener != null) { final int taskId = mTaskInfo.taskId; diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/taskview/TaskViewTransitions.java b/libs/WindowManager/Shell/src/com/android/wm/shell/taskview/TaskViewTransitions.java index 7e9c194e56bf..13e4380a9171 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/taskview/TaskViewTransitions.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/taskview/TaskViewTransitions.java @@ -385,7 +385,7 @@ public class TaskViewTransitions implements Transitions.TransitionHandler { // and tracked correctly inside taskview. Which is done by calling // prepareOpenAnimationInternal() and then manually enqueuing the resulting window container // transaction. - destination.prepareOpenAnimation(true /* newTask */, mTransaction /* startTransaction */, + prepareOpenAnimation(destination, true /* newTask */, mTransaction /* startTransaction */, null /* finishTransaction */, taskInfo, leash, wct); mTransaction.apply(); mTransitions.startTransition(TRANSIT_CHANGE, wct, null); @@ -658,7 +658,7 @@ public class TaskViewTransitions implements Transitions.TransitionHandler { } } if (wct == null) wct = new WindowContainerTransaction(); - tv.prepareOpenAnimation(taskIsNew, startTransaction, finishTransaction, + prepareOpenAnimation(tv, taskIsNew, startTransaction, finishTransaction, chg.getTaskInfo(), chg.getLeash(), wct); changesHandled++; } else if (chg.getMode() == TRANSIT_CHANGE) { @@ -692,4 +692,60 @@ public class TaskViewTransitions implements Transitions.TransitionHandler { startNextTransition(); return true; } + + @VisibleForTesting + void prepareOpenAnimation(TaskViewTaskController taskView, + final boolean newTask, + SurfaceControl.Transaction startTransaction, + SurfaceControl.Transaction finishTransaction, + ActivityManager.RunningTaskInfo taskInfo, SurfaceControl leash, + WindowContainerTransaction wct) { + final Rect boundsOnScreen = taskView.prepareOpen(taskInfo, leash); + if (boundsOnScreen != null) { + final SurfaceControl tvSurface = taskView.getSurfaceControl(); + // Surface is ready, so just reparent the task to this surface control + startTransaction.reparent(leash, tvSurface) + .show(leash); + // Also reparent on finishTransaction since the finishTransaction will reparent back + // to its "original" parent by default. + if (finishTransaction != null) { + finishTransaction.reparent(leash, tvSurface) + .setPosition(leash, 0, 0) + // TODO: maybe once b/280900002 is fixed this will be unnecessary + .setWindowCrop(leash, boundsOnScreen.width(), boundsOnScreen.height()); + } + if (useRepo()) { + final TaskViewRepository.TaskViewState state = mTaskViewRepo.byTaskView(taskView); + if (state != null) { + state.mBounds.set(boundsOnScreen); + state.mVisible = true; + } + } else { + updateBoundsState(taskView, boundsOnScreen); + updateVisibilityState(taskView, true /* visible */); + } + wct.setBounds(taskInfo.token, boundsOnScreen); + taskView.applyCaptionInsetsIfNeeded(); + } else { + // The surface has already been destroyed before the task has appeared, + // so go ahead and hide the task entirely + wct.setHidden(taskInfo.token, true /* hidden */); + updateVisibilityState(taskView, false /* visible */); + // listener callback is below + } + if (newTask) { + mTaskOrganizer.setInterceptBackPressedOnTaskRoot(taskInfo.token, true /* intercept */); + } + + if (taskInfo.taskDescription != null) { + int backgroundColor = taskInfo.taskDescription.getBackgroundColor(); + taskView.setResizeBgColor(startTransaction, backgroundColor); + } + + // After the embedded task has appeared, set it to non-trimmable. This is important + // to prevent recents from trimming and removing the embedded task. + wct.setTaskTrimmableFromRecents(taskInfo.token, false /* isTrimmableFromRecents */); + + taskView.notifyAppeared(newTask); + } } diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/taskview/TaskViewTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/taskview/TaskViewTest.java index a9ad8d7d0316..6ac34d736f6f 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/taskview/TaskViewTest.java +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/taskview/TaskViewTest.java @@ -327,7 +327,7 @@ public class TaskViewTest extends ShellTestCase { public void testOnNewTask_noSurface() { assumeTrue(Transitions.ENABLE_SHELL_TRANSITIONS); WindowContainerTransaction wct = new WindowContainerTransaction(); - mTaskViewTaskController.prepareOpenAnimation(true /* newTask */, + mTaskViewTransitions.prepareOpenAnimation(mTaskViewTaskController, true /* newTask */, new SurfaceControl.Transaction(), new SurfaceControl.Transaction(), mTaskInfo, mLeash, wct); @@ -355,7 +355,7 @@ public class TaskViewTest extends ShellTestCase { assumeTrue(Transitions.ENABLE_SHELL_TRANSITIONS); mTaskView.surfaceCreated(mock(SurfaceHolder.class)); WindowContainerTransaction wct = new WindowContainerTransaction(); - mTaskViewTaskController.prepareOpenAnimation(true /* newTask */, + mTaskViewTransitions.prepareOpenAnimation(mTaskViewTaskController, true /* newTask */, new SurfaceControl.Transaction(), new SurfaceControl.Transaction(), mTaskInfo, mLeash, wct); @@ -367,7 +367,7 @@ public class TaskViewTest extends ShellTestCase { public void testSurfaceCreated_withTask() { assumeTrue(Transitions.ENABLE_SHELL_TRANSITIONS); WindowContainerTransaction wct = new WindowContainerTransaction(); - mTaskViewTaskController.prepareOpenAnimation(true /* newTask */, + mTaskViewTransitions.prepareOpenAnimation(mTaskViewTaskController, true /* newTask */, new SurfaceControl.Transaction(), new SurfaceControl.Transaction(), mTaskInfo, mLeash, wct); mTaskView.surfaceCreated(mock(SurfaceHolder.class)); @@ -375,7 +375,7 @@ public class TaskViewTest extends ShellTestCase { verify(mViewListener).onInitialized(); verify(mTaskViewTransitions).setTaskViewVisible(eq(mTaskViewTaskController), eq(true)); - mTaskViewTaskController.prepareOpenAnimation(false /* newTask */, + mTaskViewTransitions.prepareOpenAnimation(mTaskViewTaskController, false /* newTask */, new SurfaceControl.Transaction(), new SurfaceControl.Transaction(), mTaskInfo, mLeash, wct); @@ -397,7 +397,7 @@ public class TaskViewTest extends ShellTestCase { assumeTrue(Transitions.ENABLE_SHELL_TRANSITIONS); SurfaceHolder sh = mock(SurfaceHolder.class); WindowContainerTransaction wct = new WindowContainerTransaction(); - mTaskViewTaskController.prepareOpenAnimation(true /* newTask */, + mTaskViewTransitions.prepareOpenAnimation(mTaskViewTaskController, true /* newTask */, new SurfaceControl.Transaction(), new SurfaceControl.Transaction(), mTaskInfo, mLeash, wct); mTaskView.surfaceCreated(sh); @@ -415,7 +415,7 @@ public class TaskViewTest extends ShellTestCase { public void testOnReleased() { assumeTrue(Transitions.ENABLE_SHELL_TRANSITIONS); WindowContainerTransaction wct = new WindowContainerTransaction(); - mTaskViewTaskController.prepareOpenAnimation(true /* newTask */, + mTaskViewTransitions.prepareOpenAnimation(mTaskViewTaskController, true /* newTask */, new SurfaceControl.Transaction(), new SurfaceControl.Transaction(), mTaskInfo, mLeash, wct); mTaskView.surfaceCreated(mock(SurfaceHolder.class)); @@ -431,7 +431,7 @@ public class TaskViewTest extends ShellTestCase { public void testOnTaskVanished() { assumeTrue(Transitions.ENABLE_SHELL_TRANSITIONS); WindowContainerTransaction wct = new WindowContainerTransaction(); - mTaskViewTaskController.prepareOpenAnimation(true /* newTask */, + mTaskViewTransitions.prepareOpenAnimation(mTaskViewTaskController, true /* newTask */, new SurfaceControl.Transaction(), new SurfaceControl.Transaction(), mTaskInfo, mLeash, wct); mTaskView.surfaceCreated(mock(SurfaceHolder.class)); @@ -444,7 +444,7 @@ public class TaskViewTest extends ShellTestCase { public void testOnBackPressedOnTaskRoot() { assumeTrue(Transitions.ENABLE_SHELL_TRANSITIONS); WindowContainerTransaction wct = new WindowContainerTransaction(); - mTaskViewTaskController.prepareOpenAnimation(true /* newTask */, + mTaskViewTransitions.prepareOpenAnimation(mTaskViewTaskController, true /* newTask */, new SurfaceControl.Transaction(), new SurfaceControl.Transaction(), mTaskInfo, mLeash, wct); mTaskViewTaskController.onBackPressedOnTaskRoot(mTaskInfo); @@ -456,7 +456,7 @@ public class TaskViewTest extends ShellTestCase { public void testSetOnBackPressedOnTaskRoot() { assumeTrue(Transitions.ENABLE_SHELL_TRANSITIONS); WindowContainerTransaction wct = new WindowContainerTransaction(); - mTaskViewTaskController.prepareOpenAnimation(true /* newTask */, + mTaskViewTransitions.prepareOpenAnimation(mTaskViewTaskController, true /* newTask */, new SurfaceControl.Transaction(), new SurfaceControl.Transaction(), mTaskInfo, mLeash, wct); verify(mOrganizer).setInterceptBackPressedOnTaskRoot(eq(mTaskInfo.token), eq(true)); @@ -565,7 +565,7 @@ public class TaskViewTest extends ShellTestCase { // Make the task available / start prepareOpen WindowContainerTransaction wct = mock(WindowContainerTransaction.class); - mTaskViewTaskController.prepareOpenAnimation(true /* newTask */, + mTaskViewTransitions.prepareOpenAnimation(mTaskViewTaskController, true /* newTask */, new SurfaceControl.Transaction(), new SurfaceControl.Transaction(), mTaskInfo, mLeash, wct); @@ -595,7 +595,7 @@ public class TaskViewTest extends ShellTestCase { // Task is available, but the surface was never created WindowContainerTransaction wct = mock(WindowContainerTransaction.class); - mTaskViewTaskController.prepareOpenAnimation(true /* newTask */, + mTaskViewTransitions.prepareOpenAnimation(mTaskViewTaskController, true /* newTask */, new SurfaceControl.Transaction(), new SurfaceControl.Transaction(), mTaskInfo, mLeash, wct); @@ -629,7 +629,7 @@ public class TaskViewTest extends ShellTestCase { mTaskView.surfaceCreated(mock(SurfaceHolder.class)); WindowContainerTransaction wct = new WindowContainerTransaction(); - mTaskViewTaskController.prepareOpenAnimation(true /* newTask */, + mTaskViewTransitions.prepareOpenAnimation(mTaskViewTaskController, true /* newTask */, new SurfaceControl.Transaction(), new SurfaceControl.Transaction(), mTaskInfo, mLeash, wct); @@ -672,7 +672,7 @@ public class TaskViewTest extends ShellTestCase { mTaskView.surfaceCreated(mock(SurfaceHolder.class)); reset(mOrganizer); WindowContainerTransaction wct = new WindowContainerTransaction(); - mTaskViewTaskController.prepareOpenAnimation(true /* newTask */, + mTaskViewTransitions.prepareOpenAnimation(mTaskViewTaskController, true /* newTask */, new SurfaceControl.Transaction(), new SurfaceControl.Transaction(), mTaskInfo, mLeash, wct); mTaskView.onComputeInternalInsets(new ViewTreeObserver.InternalInsetsInfo()); @@ -689,7 +689,7 @@ public class TaskViewTest extends ShellTestCase { mTaskView.surfaceCreated(mock(SurfaceHolder.class)); WindowContainerTransaction wct = new WindowContainerTransaction(); - mTaskViewTaskController.prepareOpenAnimation(true /* newTask */, + mTaskViewTransitions.prepareOpenAnimation(mTaskViewTaskController, true /* newTask */, new SurfaceControl.Transaction(), new SurfaceControl.Transaction(), mTaskInfo, mLeash, wct); reset(mOrganizer); @@ -716,7 +716,7 @@ public class TaskViewTest extends ShellTestCase { }); WindowContainerTransaction wct = new WindowContainerTransaction(); - mTaskViewTaskController.prepareOpenAnimation(true /* newTask */, + mTaskViewTransitions.prepareOpenAnimation(mTaskViewTaskController, true /* newTask */, new SurfaceControl.Transaction(), new SurfaceControl.Transaction(), mTaskInfo, mLeash, wct); mTaskView.surfaceCreated(mock(SurfaceHolder.class)); @@ -764,7 +764,7 @@ public class TaskViewTest extends ShellTestCase { @Test public void testOnAppeared_setsTrimmableTask() { WindowContainerTransaction wct = new WindowContainerTransaction(); - mTaskViewTaskController.prepareOpenAnimation(true /* newTask */, + mTaskViewTransitions.prepareOpenAnimation(mTaskViewTaskController, true /* newTask */, new SurfaceControl.Transaction(), new SurfaceControl.Transaction(), mTaskInfo, mLeash, wct); @@ -774,7 +774,7 @@ public class TaskViewTest extends ShellTestCase { @Test public void testMoveToFullscreen_callsTaskRemovalStarted() { WindowContainerTransaction wct = new WindowContainerTransaction(); - mTaskViewTaskController.prepareOpenAnimation(true /* newTask */, + mTaskViewTransitions.prepareOpenAnimation(mTaskViewTaskController, true /* newTask */, new SurfaceControl.Transaction(), new SurfaceControl.Transaction(), mTaskInfo, mLeash, wct); mTaskView.surfaceCreated(mock(SurfaceHolder.class)); |