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

Commit d3ea0e6d authored by Qijing Yao's avatar Qijing Yao
Browse files

Disable drag indicator for non-desktop-mode-supported display

This commit adds a check on isDesktopModeSupportedOnDisplay before
rendering the drag indicator on that display.

Bug: 383069176
Test: manual; atest WMShellUnitTests:MultiDisplayDragMoveIndicatorControllerTest
Flag: com.android.window.flags.enable_connected_displays_window_drag
Change-Id: I40b82ac54b58d8e58b7a87c8fe3c68cdda480e3c
parent 51216ebd
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.graphics.RectF
import android.view.SurfaceControl
import com.android.wm.shell.RootTaskDisplayAreaOrganizer
import com.android.wm.shell.shared.annotations.ShellDesktopThread
import com.android.wm.shell.shared.desktopmode.DesktopState

/**
 * Controller to manage the indicators that show users the current position of the dragged window on
@@ -30,6 +31,7 @@ class MultiDisplayDragMoveIndicatorController(
    private val rootTaskDisplayAreaOrganizer: RootTaskDisplayAreaOrganizer,
    private val indicatorSurfaceFactory: MultiDisplayDragMoveIndicatorSurface.Factory,
    @ShellDesktopThread private val desktopExecutor: ShellExecutor,
    private val desktopState: DesktopState,
) {
    @ShellDesktopThread
    private val dragIndicators =
@@ -55,8 +57,12 @@ class MultiDisplayDragMoveIndicatorController(
    ) {
        desktopExecutor.execute {
            for (displayId in displayIds) {
                if (displayId == startDisplayId) {
                    // No need to render indicators on the original display where the drag started.
                if (
                    displayId == startDisplayId ||
                        !desktopState.isDesktopModeSupportedOnDisplay(displayId)
                ) {
                    // No need to render indicators on the original display where the drag started,
                    // or on displays that do not support desktop mode.
                    continue
                }
                val displayLayout = displayController.getDisplayLayout(displayId) ?: continue
+3 −2
Original line number Diff line number Diff line
@@ -1164,11 +1164,12 @@ public abstract class WMShellModule {
            RootTaskDisplayAreaOrganizer rootTaskDisplayAreaOrganizer,
            MultiDisplayDragMoveIndicatorSurface.Factory
                multiDisplayDragMoveIndicatorSurfaceFactory,
            @ShellDesktopThread ShellExecutor desktopExecutor
            @ShellDesktopThread ShellExecutor desktopExecutor,
            DesktopState desktopState
    ) {
        return new MultiDisplayDragMoveIndicatorController(
                displayController, rootTaskDisplayAreaOrganizer,
                multiDisplayDragMoveIndicatorSurfaceFactory, desktopExecutor);
                multiDisplayDragMoveIndicatorSurfaceFactory, desktopExecutor, desktopState);
    }

    @WMSingleton
+21 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import com.android.wm.shell.RootTaskDisplayAreaOrganizer
import com.android.wm.shell.ShellTestCase
import com.android.wm.shell.TestShellExecutor
import com.android.wm.shell.common.MultiDisplayTestUtil.TestDisplay
import com.android.wm.shell.shared.desktopmode.FakeDesktopState
import java.util.function.Supplier
import org.junit.Before
import org.junit.Test
@@ -51,6 +52,8 @@ class MultiDisplayDragMoveIndicatorControllerTest : ShellTestCase() {
    private val displayController = mock<DisplayController>()
    private val rootTaskDisplayAreaOrganizer = mock<RootTaskDisplayAreaOrganizer>()
    private val indicatorSurfaceFactory = mock<MultiDisplayDragMoveIndicatorSurface.Factory>()
    private val desktopState = FakeDesktopState()

    private val indicatorSurface0 = mock<MultiDisplayDragMoveIndicatorSurface>()
    private val indicatorSurface1 = mock<MultiDisplayDragMoveIndicatorSurface>()
    private val transaction = mock<SurfaceControl.Transaction>()
@@ -77,6 +80,7 @@ class MultiDisplayDragMoveIndicatorControllerTest : ShellTestCase() {
                rootTaskDisplayAreaOrganizer,
                indicatorSurfaceFactory,
                executor,
                desktopState,
            )

        val spyDisplayLayout0 = TestDisplay.DISPLAY_0.getSpyDisplayLayout(resources.resources)
@@ -91,6 +95,7 @@ class MultiDisplayDragMoveIndicatorControllerTest : ShellTestCase() {
        whenever(indicatorSurfaceFactory.create(eq(taskInfo), eq(display0), any())).thenReturn(indicatorSurface0)
        whenever(indicatorSurfaceFactory.create(eq(taskInfo), eq(display1), any())).thenReturn(indicatorSurface1)
        whenever(transactionSupplier.get()).thenReturn(transaction)
        desktopState.canEnterDesktopMode = true
    }

    @Test
@@ -121,6 +126,22 @@ class MultiDisplayDragMoveIndicatorControllerTest : ShellTestCase() {
        verify(indicatorSurfaceFactory, never()).create(any(), any(), any())
    }

    @Test
    fun onDrag_boundsIntersectWithDesktopModeUnsupportedDisplay_noIndicator() {
        desktopState.overrideDesktopModeSupportPerDisplay[1] = false

        controller.onDragMove(
            RectF(100f, -100f, 200f, 200f), // intersect with display 0 and 1
            currentDisplayId = 1,
            startDisplayId = 0,
            taskInfo,
            displayIds = setOf(0, 1),
        ) { transaction }
        executor.flushAll()

        verify(indicatorSurfaceFactory, never()).create(any(), any(), any())
    }

    @Test
    fun onDrag_boundsIntersectWithNonStartDisplay_showAndDisposeIndicator() {
        controller.onDragMove(