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

Commit d4cfd0f7 authored by Vania Desmonda's avatar Vania Desmonda
Browse files

Disallow stashing if a drag mirror is showing.

This is to prevent a PiP window from being stashed while a drag operation
that crosses displays is being performed.

Fixes: 414749818
Test: manual test and atest PipDisplayTransferHandlerTest
Flag: com.android.window.flags.enable_dragging_pip_across_displays
Change-Id: I906a78cd728afe820ea4128f8725eaefb59e1555
parent a73c04e8
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -71,7 +71,7 @@ public class PipDisplayTransferHandler implements
    ArrayMap<Integer, SurfaceControl> mOnDragMirrorPerDisplayId = new ArrayMap<>();
    @VisibleForTesting int mTargetDisplayId;
    private PipResizeAnimatorSupplier mPipResizeAnimatorSupplier;

    private boolean mIsMirrorShown;
    public PipDisplayTransferHandler(Context context, PipTransitionState pipTransitionState,
            PipScheduler pipScheduler, RootTaskDisplayAreaOrganizer rootTaskDisplayAreaOrganizer,
            PipBoundsState pipBoundsState, DisplayController displayController,
@@ -193,6 +193,7 @@ public class PipDisplayTransferHandler implements
     */
    public void showDragMirrorOnConnectedDisplays(RectF globalDpPipBounds, int focusedDisplayId) {
        final Transaction transaction = mSurfaceControlTransactionFactory.getTransaction();
        mIsMirrorShown = false;
        // Iterate through each connected display ID to ensure partial PiP bounds are shown on
        // all corresponding displays while dragging
        for (int displayId : mRootTaskDisplayAreaOrganizer.getDisplayIds()) {
@@ -229,6 +230,7 @@ public class PipDisplayTransferHandler implements
                    mPipBoundsState.getBounds(), boundsOnCurrentDisplay,
                    /* degrees= */ 0).setMirrorTransformations(transaction, mirror);
            mRootTaskDisplayAreaOrganizer.reparentToDisplayArea(displayId, mirror, transaction);
            mIsMirrorShown = true;
        }
        transaction.apply();
    }
@@ -258,6 +260,13 @@ public class PipDisplayTransferHandler implements
        mPipSurfaceTransactionHelper = surfaceTransactionHelper;
    }

    /**
     * Whether any of the drag mirror(s) are showing on any display other than the primary display.
     */
    boolean isMirrorShown() {
        return mIsMirrorShown;
    }

    @VisibleForTesting
    interface PipResizeAnimatorSupplier {
        PipResizeAnimator get(@NonNull Context context,
+5 −1
Original line number Diff line number Diff line
@@ -1071,7 +1071,11 @@ public class PipTouchHandler implements PipTransitionState.PipTransitionStateCha
            // PIP into stashed mode.
            final boolean stashFromDroppingOnEdge = droppingOnLeft || droppingOnRight;

            return stashFromFlingToEdge || stashFromDroppingOnEdge;
            // If dragging PiP across displays is allowed, then ensure that stashing only occurs
            // when no drag mirrors of the window are shown, meaning that it wasn't partially shown
            // on another display
            return (stashFromFlingToEdge || stashFromDroppingOnEdge)
                    && !mPipDisplayTransferHandler.isMirrorShown();
        }
    }

+7 −0
Original line number Diff line number Diff line
@@ -260,6 +260,7 @@ class PipDisplayTransferHandlerTest : ShellTestCase() {
        )
        verify(mockSurfaceTransactionHelper, never()).setMirrorTransformations(any(), any())
        verify(mockTransaction, times(1)).apply()
        assertThat(pipDisplayTransferHandler.isMirrorShown()).isFalse()
    }

    @Test
@@ -268,6 +269,7 @@ class PipDisplayTransferHandlerTest : ShellTestCase() {
            displayLayouts.get(ORIGIN_DISPLAY_ID)!!, START_DRAG_COORDINATES,
            PIP_BOUNDS, displayLayouts.get(TARGET_DISPLAY_ID)!!,
            TestDisplay.DISPLAY_1.bounds.centerX(), TestDisplay.DISPLAY_1.bounds.centerY())

        pipDisplayTransferHandler.showDragMirrorOnConnectedDisplays(
             globalDpBounds, TARGET_DISPLAY_ID
        )
@@ -281,6 +283,7 @@ class PipDisplayTransferHandlerTest : ShellTestCase() {
        )
        verify(mockSurfaceTransactionHelper, never()).setMirrorTransformations(any(), any())
        verify(mockTransaction, times(1)).apply()
        assertThat(pipDisplayTransferHandler.isMirrorShown()).isFalse()
    }

    @Test
@@ -290,6 +293,7 @@ class PipDisplayTransferHandlerTest : ShellTestCase() {
            PIP_BOUNDS, displayLayouts.get(TARGET_DISPLAY_ID)!!,
            TestDisplay.DISPLAY_1.bounds.centerX(), TestDisplay.DISPLAY_1.bounds.centerY()
        )

        pipDisplayTransferHandler.showDragMirrorOnConnectedDisplays(
            globalDpBounds, ORIGIN_DISPLAY_ID
        )
@@ -314,6 +318,7 @@ class PipDisplayTransferHandlerTest : ShellTestCase() {
        )
        verify(mockSurfaceTransactionHelper, times(1)).setMirrorTransformations(any(), any())
        verify(mockTransaction, times(1)).apply()
        assertThat(pipDisplayTransferHandler.isMirrorShown()).isTrue()
    }

    @Test
@@ -322,6 +327,7 @@ class PipDisplayTransferHandlerTest : ShellTestCase() {
            displayLayouts.get(ORIGIN_DISPLAY_ID)!!, START_DRAG_COORDINATES,
            PIP_BOUNDS, displayLayouts.get(TARGET_DISPLAY_ID)!!,
            1000f, -100f)

        pipDisplayTransferHandler.showDragMirrorOnConnectedDisplays(
            globalDpBounds, ORIGIN_DISPLAY_ID
        )
@@ -356,6 +362,7 @@ class PipDisplayTransferHandlerTest : ShellTestCase() {
        )
        verify(mockSurfaceTransactionHelper, times(2)).setMirrorTransformations(any(), any())
        verify(mockTransaction, times(1)).apply()
        assertThat(pipDisplayTransferHandler.isMirrorShown()).isTrue()
    }

    @Test