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

Commit e0eb24a7 authored by Pierre Barbier de Reuille's avatar Pierre Barbier de Reuille
Browse files

Make sure Tiling knows when a task is focused

Currently, if the task gets the focused from the `moveToFront` method in
`DesktopModeWindowDecorViewModel`, the task info hasn't been updated
with the focus information yet, so the tiling thinks that task lost the
focus. Coupled with the fact that the signal from the focus listener
seems often lost, we often didn't know the tiled tasked had the focus.

Fix: 378129032
Flag: com.android.window.flags.enable_tile_resizing
Test: atest DesktopTilingWindowDecorationTest
Test: Manual test on Pixel tablets
Change-Id: I4d70074939aa4926b5e1b3c2d94c745dcd353838
parent b87170e4
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -103,7 +103,7 @@ class DesktopTilingDecorViewModel(
    fun moveTaskToFrontIfTiled(taskInfo: RunningTaskInfo): Boolean {
        return tilingTransitionHandlerByDisplayId
            .get(taskInfo.displayId)
            ?.moveTiledPairToFront(taskInfo) ?: false
            ?.moveTiledPairToFront(taskInfo, isTaskFocused = true) ?: false
    }

    fun onOverviewAnimationStateChange(isRunning: Boolean) {
+18 −8
Original line number Diff line number Diff line
@@ -230,14 +230,14 @@ class DesktopTilingWindowDecoration(
            ResizeTrigger.TILING_DIVIDER,
            motionEvent,
            leftTiledTask.taskInfo,
            displayController
            displayController,
        )

        desktopModeEventLogger.logTaskResizingStarted(
            ResizeTrigger.TILING_DIVIDER,
            motionEvent,
            rightTiledTask.taskInfo,
            displayController
            displayController,
        )
    }

@@ -303,7 +303,7 @@ class DesktopTilingWindowDecoration(
            leftTiledTask.taskInfo,
            leftTiledTask.newBounds.height(),
            leftTiledTask.newBounds.width(),
            displayController
            displayController,
        )

        desktopModeEventLogger.logTaskResizingEnded(
@@ -312,7 +312,7 @@ class DesktopTilingWindowDecoration(
            rightTiledTask.taskInfo,
            rightTiledTask.newBounds.height(),
            rightTiledTask.newBounds.width(),
            displayController
            displayController,
        )

        if (leftTiledTask.newBounds == leftTiledTask.bounds) {
@@ -471,9 +471,9 @@ class DesktopTilingWindowDecoration(
        }
    }

    // Only called if [taskInfo] relates to a focused task
    private fun isTilingFocusRemoved(taskInfo: RunningTaskInfo): Boolean {
        return taskInfo.isFocused &&
            isTilingFocused &&
        return isTilingFocused &&
            taskInfo.taskId != leftTaskResizingHelper?.taskInfo?.taskId &&
            taskInfo.taskId != rightTaskResizingHelper?.taskInfo?.taskId
    }
@@ -484,9 +484,9 @@ class DesktopTilingWindowDecoration(
        }
    }

    // Only called if [taskInfo] relates to a focused task
    private fun isTilingRefocused(taskInfo: RunningTaskInfo): Boolean {
        return !isTilingFocused &&
            taskInfo.isFocused &&
            (taskInfo.taskId == leftTaskResizingHelper?.taskInfo?.taskId ||
                taskInfo.taskId == rightTaskResizingHelper?.taskInfo?.taskId)
    }
@@ -573,9 +573,19 @@ class DesktopTilingWindowDecoration(
        removeTaskIfTiled(taskId, taskVanished = true, shouldDelayUpdate = true)
    }

    fun moveTiledPairToFront(taskInfo: RunningTaskInfo): Boolean {
    /**
     * Moves the tiled pair to the front of the task stack, if the [taskInfo] is focused and one of
     * the two tiled tasks.
     *
     * If specified, [isTaskFocused] will override [RunningTaskInfo.isFocused]. This is to be used
     * when called when the task will be focused, but the [taskInfo] hasn't been updated yet.
     */
    fun moveTiledPairToFront(taskInfo: RunningTaskInfo, isTaskFocused: Boolean? = null): Boolean {
        if (!isTilingManagerInitialised) return false

        val isFocused = isTaskFocused ?: taskInfo.isFocused
        if (!isFocused) return false

        // If a task that isn't tiled is being focused, let the generic handler do the work.
        if (isTilingFocusRemoved(taskInfo)) {
            isTilingFocused = false
+3 −2
Original line number Diff line number Diff line
@@ -24,8 +24,8 @@ import com.android.wm.shell.ShellTaskOrganizer
import com.android.wm.shell.ShellTestCase
import com.android.wm.shell.common.DisplayController
import com.android.wm.shell.common.SyncTransactionQueue
import com.android.wm.shell.desktopmode.DesktopRepository
import com.android.wm.shell.desktopmode.DesktopModeEventLogger
import com.android.wm.shell.desktopmode.DesktopRepository
import com.android.wm.shell.desktopmode.DesktopTasksController
import com.android.wm.shell.desktopmode.DesktopTestHelpers.Companion.createFreeformTask
import com.android.wm.shell.desktopmode.ReturnToDragStartAnimator
@@ -130,7 +130,8 @@ class DesktopTilingDecorViewModelTest : ShellTestCase() {
        )
        desktopTilingDecorViewModel.moveTaskToFrontIfTiled(task1)

        verify(desktopTilingDecoration, times(1)).moveTiledPairToFront(any())
        verify(desktopTilingDecoration, times(1))
            .moveTiledPairToFront(any(), isTaskFocused = eq(true))
    }

    @Test
+31 −0
Original line number Diff line number Diff line
@@ -327,6 +327,37 @@ class DesktopTilingWindowDecorationTest : ShellTestCase() {
        verify(transitions, times(1)).startTransition(eq(TRANSIT_TO_FRONT), any(), eq(null))
    }

    @Test
    fun taskTiled_broughtToFront_taskInfoNotUpdated_bringToFront() {
        val task1 = createFreeformTask()
        val task2 = createFreeformTask()
        val task3 = createFreeformTask()
        val stableBounds = STABLE_BOUNDS_MOCK
        whenever(displayLayout.getStableBounds(any())).thenAnswer { i ->
            (i.arguments.first() as Rect).set(stableBounds)
        }
        whenever(context.resources).thenReturn(resources)
        whenever(resources.getDimensionPixelSize(any())).thenReturn(split_divider_width)
        whenever(desktopWindowDecoration.getLeash()).thenReturn(surfaceControlMock)
        whenever(desktopRepository.isVisibleTask(any())).thenReturn(true)
        tilingDecoration.onAppTiled(
            task1,
            desktopWindowDecoration,
            DesktopTasksController.SnapPosition.RIGHT,
            BOUNDS,
        )
        tilingDecoration.onAppTiled(
            task2,
            desktopWindowDecoration,
            DesktopTasksController.SnapPosition.LEFT,
            BOUNDS,
        )

        assertThat(tilingDecoration.moveTiledPairToFront(task3, isTaskFocused = true)).isFalse()
        assertThat(tilingDecoration.moveTiledPairToFront(task1, isTaskFocused = true)).isTrue()
        verify(transitions, times(1)).startTransition(eq(TRANSIT_TO_FRONT), any(), eq(null))
    }

    @Test
    fun taskTiledTasks_NotResized_BeforeTouchEndArrival() {
        // Setup