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

Commit e7e2e869 authored by Maryam Dehaini's avatar Maryam Dehaini Committed by Android (Google) Code Review
Browse files

Merge "Do not throw IllegalStateException when second drag to desktop...

Merge "Do not throw IllegalStateException when second drag to desktop transition is started" into main
parents fc04788c 51f8ed2a
Loading
Loading
Loading
Loading
+17 −1
Original line number Diff line number Diff line
@@ -99,7 +99,11 @@ class DragToDesktopTransitionHandler(
            windowDecoration: DesktopModeWindowDecoration
    ) {
        if (inProgress) {
            error("A drag to desktop is already in progress")
            KtProtoLog.v(
                    ShellProtoLogGroup.WM_SHELL_DESKTOP_MODE,
                    "DragToDesktop: Drag to desktop transition already in progress."
            )
            return
        }

        val options = ActivityOptions.makeBasic().apply {
@@ -144,6 +148,12 @@ class DragToDesktopTransitionHandler(
     * inside the desktop drop zone.
     */
    fun finishDragToDesktopTransition(wct: WindowContainerTransaction) {
        if (!inProgress) {
            // Don't attempt to finish a drag to desktop transition since there is no transition in
            // progress which means that the drag to desktop transition was never successfully
            // started.
            return
        }
        if (requireTransitionState().startAborted) {
            // Don't attempt to complete the drag-to-desktop since the start transition didn't
            // succeed as expected. Just reset the state as if nothing happened.
@@ -161,6 +171,12 @@ class DragToDesktopTransitionHandler(
     * means the user wants to remain in their current windowing mode.
     */
    fun cancelDragToDesktopTransition() {
        if (!inProgress) {
            // Don't attempt to cancel a drag to desktop transition since there is no transition in
            // progress which means that the drag to desktop transition was never successfully
            // started.
            return
        }
        val state = requireTransitionState()
        if (state.startAborted) {
            // Don't attempt to cancel the drag-to-desktop since the start transition didn't
+44 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import org.mockito.ArgumentMatchers.eq
import org.mockito.Mock
import org.mockito.kotlin.mock
import org.mockito.kotlin.never
import org.mockito.kotlin.times
import org.mockito.kotlin.verify
import org.mockito.kotlin.verifyZeroInteractions
import org.mockito.kotlin.whenever
@@ -149,6 +150,23 @@ class DragToDesktopTransitionHandlerTest : ShellTestCase() {
        assertFalse(handler.inProgress)
    }

    @Test
    fun startDragToDesktop_anotherTransitionInProgress_startDropped() {
        val task = createTask()
        val dragAnimator = mock<MoveToDesktopAnimator>()

        // Simulate attempt to start two drag to desktop transitions.
        startDragToDesktopTransition(task, dragAnimator)
        startDragToDesktopTransition(task, dragAnimator)

        // Verify transition only started once.
        verify(transitions, times(1)).startTransition(
                eq(TRANSIT_DESKTOP_MODE_START_DRAG_TO_DESKTOP),
                any(),
                eq(handler)
        )
    }

    @Test
    fun cancelDragToDesktop_startWasReady_cancel() {
        val task = createTask()
@@ -189,6 +207,32 @@ class DragToDesktopTransitionHandlerTest : ShellTestCase() {
        verifyZeroInteractions(dragAnimator)
    }

    @Test
    fun cancelDragToDesktop_transitionNotInProgress_dropCancel() {
        // Then cancel is called before the transition was started.
        handler.cancelDragToDesktopTransition()

        // Verify cancel is dropped.
        verify(transitions, never()).startTransition(
                eq(TRANSIT_DESKTOP_MODE_CANCEL_DRAG_TO_DESKTOP),
                any(),
                eq(handler)
        )
    }

    @Test
    fun finishDragToDesktop_transitionNotInProgress_dropFinish() {
        // Then finish is called before the transition was started.
        handler.finishDragToDesktopTransition(WindowContainerTransaction())

        // Verify finish is dropped.
        verify(transitions, never()).startTransition(
                eq(TRANSIT_DESKTOP_MODE_END_DRAG_TO_DESKTOP),
                any(),
                eq(handler)
        )
    }

    private fun startDragToDesktopTransition(
        task: RunningTaskInfo,
        dragAnimator: MoveToDesktopAnimator