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

Commit 41ca53d5 authored by Omar Elmekkawy's avatar Omar Elmekkawy Committed by Android (Google) Code Review
Browse files

Merge "Fix a bug where tiling is initialized before window decor creation." into main

parents e3ac82a2 22270e7f
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -1034,14 +1034,15 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel,
        final DesktopRepository repository = mDesktopUserRepositories.getCurrent();
        final Integer leftTaskId = repository.getLeftTiledTask(deskId);
        final Integer rightTaskId = repository.getRightTiledTask(deskId);
        if (leftTaskId != null) {
        // if the decor wrapper is null, tiling will be initialised when the decor is created.
        if (leftTaskId != null && mWindowDecorByTaskId.get(leftTaskId) != null) {
            final WindowDecorationWrapper decor = mWindowDecorByTaskId.get(leftTaskId);
            final RunningTaskInfo taskInfo = decor.getTaskInfo();
            final Rect currentBounds = taskInfo.configuration.windowConfiguration.getBounds();
            snapPersistedTaskToHalfScreen(taskInfo, currentBounds, SnapPosition.LEFT);
        }

        if (rightTaskId != null) {
        if (rightTaskId != null && mWindowDecorByTaskId.get(rightTaskId) != null) {
            final WindowDecorationWrapper decor = mWindowDecorByTaskId.get(rightTaskId);
            final RunningTaskInfo taskInfo = decor.getTaskInfo();
            final Rect currentBounds = taskInfo.configuration.windowConfiguration.getBounds();
+42 −0
Original line number Diff line number Diff line
@@ -1483,6 +1483,48 @@ class DesktopModeWindowDecorViewModelTests : DesktopModeWindowDecorViewModelTest
        }
    }

    @Test
    fun nullDecor_shouldNotInitializeTiling() {
        mockDesktopRepository.stub { on { getLeftTiledTask(1) } doReturn 1 }
        mockDesktopRepository.stub { on { getRightTiledTask(2) } doReturn 2 }
        windowDecorByTaskIdSpy.stub { on { get(1) } doReturn null }
        windowDecorByTaskIdSpy.stub { on { get(2) } doReturn null }
        mockTilingWindowDecoration.stub { on { tilingDeskActive(any()) } doReturn false }

        desktopModeWindowDecorViewModel.onDeskActivated(1, 2)

        verify(mockTilingWindowDecoration, never()).snapToHalfScreen(
            taskInfo = any(),
            windowDecoration = any(),
            position = any(),
            currentBounds = any(),
            destinationBounds = any()
        )
    }

    @Test
    fun nonNullDecor_shouldInitializeTiling() {
        val task = createTask(windowingMode = WINDOWING_MODE_FREEFORM)
        val taskSurface = SurfaceControl()
        val decoration = setUpMockDecorationForTask(task)
        onTaskOpening(task, taskSurface)
        mockDesktopRepository.stub { on { getLeftTiledTask(1) } doReturn task.taskId }
        mockDesktopRepository.stub { on { getRightTiledTask(1) } doReturn task.taskId }
        mockTilingWindowDecoration.stub { on { tilingDeskActive(any()) } doReturn false }
        windowDecorByTaskIdSpy.stub { on { get(task.taskId) } doReturn decoration }
        decoration.stub { on { taskInfo } doReturn task }

        desktopModeWindowDecorViewModel.onDeskActivated(1, 2)

        verify(mockTilingWindowDecoration, times(2)).snapToHalfScreen(
            taskInfo = any(),
            windowDecoration = any(),
            position = any(),
            currentBounds = any(),
            destinationBounds = any()
        )
    }

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_BLOCK_NON_DESKTOP_DISPLAY_WINDOW_DRAG_BUGFIX)
    fun testOnFreeformWindowDragMove_toNonDesktopModeDisplay_setsNoDropIconAndKeepsBounds() {