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

Commit 7e47111a authored by Vania Desmonda's avatar Vania Desmonda
Browse files

Remove PiP drag mirrors on ACTION_CANCEL.

Fixes: 408981327
Test: manual and atest PipTouchHandlerTest
Flag: com.android.window.flags.enable_dragging_pip_across_displays
Change-Id: I091f59e60a49c10c71320518c87161c58b180c83
parent aaaab629
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -237,7 +237,6 @@ public class PipDisplayTransferHandler implements
    /**
     * Remove all drag indicator mirrors from each connected display.
     */
    // TODO(b/408981327): Remove mirrors on screen lock
    // TODO(b/408982524): Remove mirrors on opening app while dragging
    public void removeMirrors() {
        final Transaction transaction = mSurfaceControlTransactionFactory.getTransaction();
+3 −0
Original line number Diff line number Diff line
@@ -609,6 +609,9 @@ public class PipTouchHandler implements PipTransitionState.PipTransitionStateCha
            }
            // Fall through to clean up
            case MotionEvent.ACTION_CANCEL: {
                if (mPipDesktopState.isDraggingPipAcrossDisplaysEnabled()) {
                    mPipDisplayTransferHandler.removeMirrors();
                }
                shouldDeliverToMenu = !mTouchState.startedDragging() && !mTouchState.isDragging();
                mTouchState.reset();
                break;
+35 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.testing.TestableLooper.RunWithLooper
import android.view.InputDevice.SOURCE_MOUSE
import android.view.InputDevice.SOURCE_TOUCHSCREEN
import android.view.MotionEvent
import android.view.MotionEvent.ACTION_CANCEL
import android.view.SurfaceControl
import androidx.test.filters.SmallTest
import com.android.dx.mockito.inline.extended.ExtendedMockito
@@ -50,6 +51,7 @@ import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.ArgumentMatchers.anyInt
import org.mockito.kotlin.any
import org.mockito.kotlin.doNothing
import org.mockito.kotlin.eq
import org.mockito.kotlin.mock
import org.mockito.kotlin.never
@@ -91,6 +93,7 @@ class PipTouchHandlerTest : ShellTestCase() {
    private val mockPipSurfaceTransactionHelper = mock<PipSurfaceTransactionHelper>()
    private val mockMotionEvent = mock<MotionEvent>()
    private val mockPipDismissTargetHandler = mock<PipDismissTargetHandler>()
    private val mockPipResizeGestureHandler = mock<PipResizeGestureHandler>()

    private lateinit var pipTouchHandler: PipTouchHandler
    private lateinit var pipTouchGesture: PipTouchGesture
@@ -115,6 +118,7 @@ class PipTouchHandlerTest : ShellTestCase() {
        pipTouchGesture = pipTouchHandler.touchGesture
        pipTouchHandler.setPipTouchState(pipTouchState)
        pipTouchHandler.setPipDismissTargetHandler(mockPipDismissTargetHandler)
        pipTouchHandler.pipResizeGestureHandler = mockPipResizeGestureHandler

        whenever(pipTouchState.downTouchPosition).thenReturn(mockTouchPosition)
        whenever(pipTouchState.velocity).thenReturn(mockTouchPosition)
@@ -259,6 +263,37 @@ class PipTouchHandlerTest : ShellTestCase() {
        verify(mockPipDismissTargetHandler, never()).showDismissTargetMaybe()
    }


    @Test
    fun handleTouchEvent_crossDisplayDragFlagEnabled_actionCancel_removesMirrors() {
        whenever(mockPipDesktopState.isDraggingPipAcrossDisplaysEnabled()).thenReturn(true)
        whenever(pipTouchState.startedDragging()).thenReturn(true)
        whenever(mockPipResizeGestureHandler.willStartResizeGesture(any())).thenReturn(false)
        whenever(mockPipResizeGestureHandler.hasOngoingGesture()).thenReturn(false)
        doNothing().`when`(pipTouchState).onTouchEvent(any())
        doNothing().`when`(pipTouchState).reset()
        whenever(mockMotionEvent.action).thenReturn(ACTION_CANCEL)

        pipTouchHandler.handleTouchEvent(mockMotionEvent)

        verify(mockPipDisplayTransferHandler).removeMirrors()
    }

    @Test
    fun handleTouchEvent_crossDisplayDragFlagDisabled_actionCancel_doesNotRemoveMirrors() {
        whenever(mockPipDesktopState.isDraggingPipAcrossDisplaysEnabled()).thenReturn(false)
        whenever(pipTouchState.startedDragging()).thenReturn(true)
        whenever(mockPipResizeGestureHandler.willStartResizeGesture(any())).thenReturn(false)
        whenever(mockPipResizeGestureHandler.hasOngoingGesture()).thenReturn(false)
        doNothing().`when`(pipTouchState).onTouchEvent(any())
        doNothing().`when`(pipTouchState).reset()
        whenever(mockMotionEvent.action).thenReturn(ACTION_CANCEL)

        pipTouchHandler.handleTouchEvent(mockMotionEvent)

        verify(mockPipDisplayTransferHandler, never()).removeMirrors()
    }

    private companion object {
        const val ORIGIN_DISPLAY_ID = 0
        const val TARGET_DISPLAY_ID = 1