Merge "Return early in removeTask if there is no task token" into udc-dev

This commit is contained in:
Mady Mellor
2023-05-09 23:55:59 +00:00
committed by Android (Google) Code Review
2 changed files with 32 additions and 0 deletions

View File

@@ -31,6 +31,7 @@ import android.content.pm.ShortcutInfo;
import android.graphics.Rect; import android.graphics.Rect;
import android.os.Binder; import android.os.Binder;
import android.util.CloseGuard; import android.util.CloseGuard;
import android.util.Slog;
import android.view.SurfaceControl; import android.view.SurfaceControl;
import android.window.WindowContainerToken; import android.window.WindowContainerToken;
import android.window.WindowContainerTransaction; import android.window.WindowContainerTransaction;
@@ -49,6 +50,8 @@ import java.util.concurrent.Executor;
*/ */
public class TaskViewTaskController implements ShellTaskOrganizer.TaskListener { public class TaskViewTaskController implements ShellTaskOrganizer.TaskListener {
private static final String TAG = TaskViewTaskController.class.getSimpleName();
private final CloseGuard mGuard = new CloseGuard(); private final CloseGuard mGuard = new CloseGuard();
private final ShellTaskOrganizer mTaskOrganizer; private final ShellTaskOrganizer mTaskOrganizer;
@@ -405,6 +408,11 @@ public class TaskViewTaskController implements ShellTaskOrganizer.TaskListener {
* Call to remove the task from window manager. This task will not appear in recents. * Call to remove the task from window manager. This task will not appear in recents.
*/ */
void removeTask() { void removeTask() {
if (mTaskToken == null) {
// Call to remove task before we have one, do nothing
Slog.w(TAG, "Trying to remove a task that was never added? (no taskToken)");
return;
}
WindowContainerTransaction wct = new WindowContainerTransaction(); WindowContainerTransaction wct = new WindowContainerTransaction();
wct.removeTask(mTaskToken); wct.removeTask(mTaskToken);
mTaskViewTransitions.closeTaskView(wct, this); mTaskViewTransitions.closeTaskView(wct, this);

View File

@@ -520,4 +520,28 @@ public class TaskViewTest extends ShellTestCase {
verify(mTaskViewTransitions).updateVisibilityState(eq(mTaskViewTaskController), eq(false)); verify(mTaskViewTransitions).updateVisibilityState(eq(mTaskViewTaskController), eq(false));
verify(mTaskViewTransitions, never()).updateBoundsState(eq(mTaskViewTaskController), any()); verify(mTaskViewTransitions, never()).updateBoundsState(eq(mTaskViewTaskController), any());
} }
@Test
public void testRemoveTaskView_noTask() {
assumeTrue(Transitions.ENABLE_SHELL_TRANSITIONS);
mTaskView.removeTask();
verify(mTaskViewTransitions, never()).closeTaskView(any(), any());
}
@Test
public void testRemoveTaskView() {
assumeTrue(Transitions.ENABLE_SHELL_TRANSITIONS);
mTaskView.surfaceCreated(mock(SurfaceHolder.class));
WindowContainerTransaction wct = new WindowContainerTransaction();
mTaskViewTaskController.prepareOpenAnimation(true /* newTask */,
new SurfaceControl.Transaction(), new SurfaceControl.Transaction(), mTaskInfo,
mLeash, wct);
verify(mViewListener).onTaskCreated(eq(mTaskInfo.taskId), any());
mTaskView.removeTask();
verify(mTaskViewTransitions).closeTaskView(any(), eq(mTaskViewTaskController));
}
} }