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

Commit 30ddb7d9 authored by Omar Elmekkawy's avatar Omar Elmekkawy
Browse files

Stop depending on transitions for task limit tile handling.

A bug was introduced when changing the transition for minimizing a task
when the task limit is reached from TRANSIT_OPEN to
TRANSIT_DESKTOP_MODE_TASK_LIMIT_MINIMIZE which broke the signal tiling was
expecting to handle this minimize event.

This CL abandons depending on transitions for this event and migrates the
signaling to DesktopTasksLimiter to avoid future changes breaking tiling.

Flag: com.android.window.flags.enable_tile_resizing
Test: Unit tests and on device testing
Bug: 419445881
Change-Id: I5f76eafb60ecdfc6fe78aa4a04a5cb59d42018fd
parent d987f495
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -370,6 +370,7 @@ class DesktopTasksController(
    /** Setter to handle snap events */
    fun setSnapEventHandler(handler: SnapEventHandler) {
        snapEventHandler = handler
        desktopTasksLimiter.ifPresent { it.snapEventHandler = snapEventHandler }
    }

    /** Returns the transition type for the given remote transition. */
+3 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_DESKTOP_MODE
import com.android.wm.shell.sysui.UserChangeListener
import com.android.wm.shell.transition.Transitions
import com.android.wm.shell.transition.Transitions.TransitionObserver
import com.android.wm.shell.windowdecor.tiling.SnapEventHandler

/**
 * Keeps track of minimized tasks and limits the number of tasks shown in Desktop Mode.
@@ -57,6 +58,7 @@ class DesktopTasksLimiter(
    @VisibleForTesting val leftoverMinimizedTasksRemover = LeftoverMinimizedTasksRemover()

    private var userId: Int
    lateinit var snapEventHandler: SnapEventHandler

    init {
        maxTasksLimit?.let {
@@ -196,6 +198,7 @@ class DesktopTasksLimiter(
            logV("triggerMinimizeTransition, found running task -> start transition, %s", task)
            val wct = WindowContainerTransaction()
            addMinimizeChange(deskId, task, wct)
            snapEventHandler.removeTaskIfTiled(task.displayId, task.taskId)
            val transition =
                desktopMixedTransitionHandler.startTaskLimitMinimizeTransition(wct, task.taskId)
            addPendingMinimizeChange(
+2 −4
Original line number Diff line number Diff line
@@ -500,10 +500,8 @@ class DesktopTilingWindowDecoration(
        }
    }

    private fun isMinimized(changeMode: Int, infoType: Int): Boolean {
        return changeMode == TRANSIT_TO_BACK &&
            (infoType == TRANSIT_MINIMIZE || infoType == TRANSIT_OPEN)
    }
    private fun isMinimized(changeMode: Int, infoType: Int): Boolean =
        changeMode == TRANSIT_TO_BACK && infoType == TRANSIT_MINIMIZE

    private fun isEnteringPip(change: Change, transitType: Int): Boolean {
        if (change.taskInfo != null && change.taskInfo?.windowingMode == WINDOWING_MODE_PINNED) {
+5 −0
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ import com.android.wm.shell.sysui.ShellInit
import com.android.wm.shell.transition.TransitionInfoBuilder
import com.android.wm.shell.transition.Transitions
import com.android.wm.shell.util.StubTransaction
import com.android.wm.shell.windowdecor.tiling.SnapEventHandler
import com.google.common.truth.Truth.assertThat
import kotlin.test.assertFailsWith
import kotlinx.coroutines.CoroutineScope
@@ -99,6 +100,7 @@ class DesktopTasksLimiterTest : ShellTestCase() {
    @Mock lateinit var userManager: UserManager
    @Mock lateinit var shellController: ShellController
    @Mock lateinit var desktopMixedTransitionHandler: DesktopMixedTransitionHandler
    @Mock lateinit var snapEventHandler: SnapEventHandler

    private lateinit var desktopTasksLimiter: DesktopTasksLimiter
    private lateinit var userRepositories: DesktopUserRepositories
@@ -136,6 +138,7 @@ class DesktopTasksLimiterTest : ShellTestCase() {
                desktopMixedTransitionHandler,
                MAX_TASK_LIMIT,
            )
        desktopTasksLimiter.snapEventHandler = snapEventHandler
    }

    @After
@@ -722,6 +725,8 @@ class DesktopTasksLimiterTest : ShellTestCase() {
        verify(desktopMixedTransitionHandler).startTaskLimitMinimizeTransition(any(), any())
        assertThat(desktopTasksLimiter.getMinimizingTask(minimizeTransition)?.taskId)
            .isEqualTo(existingTasks.first().taskId)
        verify(snapEventHandler)
            .removeTaskIfTiled(existingTasks.first().displayId, existingTasks.first().taskId)
    }

    @Test
+0 −50
Original line number Diff line number Diff line
@@ -25,9 +25,7 @@ import android.testing.AndroidTestingRunner
import android.view.MotionEvent
import android.view.SurfaceControl
import android.view.WindowManager.TRANSIT_CHANGE
import android.view.WindowManager.TRANSIT_OPEN
import android.view.WindowManager.TRANSIT_PIP
import android.view.WindowManager.TRANSIT_TO_BACK
import android.view.WindowManager.TRANSIT_TO_FRONT
import android.window.TransitionInfo
import android.window.TransitionInfo.Change
@@ -659,39 +657,6 @@ class DesktopTilingWindowDecorationTest : ShellTestCase() {
        verify(tiledTaskHelper, times(1)).dispose()
    }

    @Test
    fun taskTiled_shouldBeRemoved_whenBeingMinimisedAppLimit() {
        val task1 = createPipTask()
        val stableBounds = STABLE_BOUNDS_MOCK
        whenever(displayController.getDisplayLayout(any())).thenReturn(displayLayout)
        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(tiledTaskHelper.taskInfo).thenReturn(task1)
        whenever(tiledTaskHelper.desktopModeWindowDecoration).thenReturn(desktopWindowDecoration)
        tilingDecoration.onAppTiled(
            task1,
            desktopWindowDecoration,
            DesktopTasksController.SnapPosition.LEFT,
            BOUNDS,
            destinationBoundsOverride = null,
        )
        tilingDecoration.leftTaskResizingHelper = tiledTaskHelper
        val changeInfo = createMinimiseOpenChangeTransition(task1)

        tilingDecoration.onTransitionReady(
            transition = mock(),
            info = changeInfo,
            startTransaction = mock(),
            finishTransaction = mock(),
        )

        assertThat(tilingDecoration.leftTaskResizingHelper).isNull()
        verify(tiledTaskHelper, times(1)).dispose()
    }

    @Test
    fun tilingDivider_shouldBeShown_whenTiledTasksBecomeVisible() {
        val task1 = createVisibleTask()
@@ -932,21 +897,6 @@ class DesktopTilingWindowDecorationTest : ShellTestCase() {
            )
        }

    private fun createMinimiseOpenChangeTransition(
        task: RunningTaskInfo?,
        type: Int = TRANSIT_OPEN,
    ) =
        TransitionInfo(type, /* flags= */ 0).apply {
            addChange(
                Change(mock(), mock()).apply {
                    mode = TRANSIT_TO_BACK
                    parent = null
                    taskInfo = task
                    flags = flags
                }
            )
        }

    private fun createTransitFrontTransition(
        task1: RunningTaskInfo?,
        task2: RunningTaskInfo?,