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

Commit 50daced2 authored by Mady Mellor's avatar Mady Mellor
Browse files

Return early in removeTask if there is no task token

Test: atest TaskViewTest
Bug: 280957479
Change-Id: I6fbcb47f6fc88d0d77443989a8e2f3ca0780bae4
parent ab363773
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.content.pm.ShortcutInfo;
import android.graphics.Rect;
import android.os.Binder;
import android.util.CloseGuard;
import android.util.Slog;
import android.view.SurfaceControl;
import android.window.WindowContainerToken;
import android.window.WindowContainerTransaction;
@@ -49,6 +50,8 @@ import java.util.concurrent.Executor;
 */
public class TaskViewTaskController implements ShellTaskOrganizer.TaskListener {

    private static final String TAG = TaskViewTaskController.class.getSimpleName();

    private final CloseGuard mGuard = new CloseGuard();

    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.
     */
    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();
        wct.removeTask(mTaskToken);
        mTaskViewTransitions.closeTaskView(wct, this);
+24 −0
Original line number Diff line number Diff line
@@ -520,4 +520,28 @@ public class TaskViewTest extends ShellTestCase {
        verify(mTaskViewTransitions).updateVisibilityState(eq(mTaskViewTaskController), eq(false));
        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));
    }
}