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

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

Limit transition handling to displays with desktop mode support

Also simplify the code by checking early if there is a trigger task we
can rely on to determine what needs to happen.

Fix: 405412244
Test: atest ActivityLifecycleTopResumedStateTests
Test: atest DesktopTasksControllerTest
Flag: EXEMPT (bug fix)
Change-Id: I235277d701e385d3969ce33cf52a52d5edaf90d7
parent 65e91daf
Loading
Loading
Loading
Loading
+35 −28
Original line number Diff line number Diff line
@@ -2019,6 +2019,11 @@ class DesktopTasksController(
        return false
    }

    private fun taskDisplaySupportDesktopMode(triggerTask: RunningTaskInfo) =
        displayController.getDisplay(triggerTask.displayId)?.let { display ->
            DesktopModeStatus.isDesktopModeSupportedOnDisplay(context, display)
        } ?: false

    override fun handleRequest(
        transition: IBinder,
        request: TransitionRequestInfo,
@@ -2027,13 +2032,22 @@ class DesktopTasksController(
        // Check if we should skip handling this transition
        var reason = ""
        val triggerTask = request.triggerTask
        // Skipping early if the trigger task is null
        if (triggerTask == null) {
            logV("skipping handleRequest reason=triggerTask is null", reason)
            return null
        }
        val recentsAnimationRunning =
            RecentsTransitionStateListener.isAnimating(recentsTransitionState)
        var shouldHandleMidRecentsFreeformLaunch =
        val shouldHandleMidRecentsFreeformLaunch =
            recentsAnimationRunning && isFreeformRelaunch(triggerTask, request)
        val isDragAndDropFullscreenTransition = taskContainsDragAndDropCookie(triggerTask)
        val shouldHandleRequest =
            when {
                !taskDisplaySupportDesktopMode(triggerTask) -> {
                    reason = "triggerTask's display doesn't support desktop mode"
                    false
                }
                // Handle freeform relaunch during recents animation
                shouldHandleMidRecentsFreeformLaunch -> true
                recentsAnimationRunning -> {
@@ -2054,11 +2068,6 @@ class DesktopTasksController(
                    reason = "transition type not handled (${request.type})"
                    false
                }
                // Only handle when it is a task transition
                triggerTask == null -> {
                    reason = "triggerTask is null"
                    false
                }
                // Only handle standard type tasks
                triggerTask.activityType != ACTIVITY_TYPE_STANDARD -> {
                    reason = "activityType not handled (${triggerTask.activityType})"
@@ -2079,25 +2088,24 @@ class DesktopTasksController(
        }

        val result =
            triggerTask?.let { task ->
            when {
                // Check if freeform task launch during recents should be handled
                shouldHandleMidRecentsFreeformLaunch ->
                        handleMidRecentsFreeformTaskLaunch(task, transition)
                    handleMidRecentsFreeformTaskLaunch(triggerTask, transition)
                // Check if the closing task needs to be handled
                TransitionUtil.isClosingType(request.type) ->
                        handleTaskClosing(task, transition, request.type)
                    handleTaskClosing(triggerTask, transition, request.type)
                // Check if the top task shouldn't be allowed to enter desktop mode
                    isIncompatibleTask(task) -> handleIncompatibleTaskLaunch(task, transition)
                isIncompatibleTask(triggerTask) ->
                    handleIncompatibleTaskLaunch(triggerTask, transition)
                // Check if fullscreen task should be updated
                    task.isFullscreen -> handleFullscreenTaskLaunch(task, transition)
                triggerTask.isFullscreen -> handleFullscreenTaskLaunch(triggerTask, transition)
                // Check if freeform task should be updated
                    task.isFreeform -> handleFreeformTaskLaunch(task, transition)
                triggerTask.isFreeform -> handleFreeformTaskLaunch(triggerTask, transition)
                else -> {
                    null
                }
            }
            }
        logV("handleRequest result=%s", result)
        return result
    }
@@ -2160,8 +2168,8 @@ class DesktopTasksController(
        )
    }

    private fun taskContainsDragAndDropCookie(taskInfo: RunningTaskInfo?) =
        taskInfo?.launchCookies?.any { it == dragAndDropFullscreenCookie } ?: false
    private fun taskContainsDragAndDropCookie(taskInfo: RunningTaskInfo) =
        taskInfo.launchCookies?.any { it == dragAndDropFullscreenCookie } ?: false

    /**
     * Applies the proper surface states (rounded corners) to tasks when desktop mode is active.
@@ -2185,9 +2193,8 @@ class DesktopTasksController(
    }

    /** Returns whether an existing desktop task is being relaunched in freeform or not. */
    private fun isFreeformRelaunch(triggerTask: RunningTaskInfo?, request: TransitionRequestInfo) =
        (triggerTask != null &&
            triggerTask.windowingMode == WINDOWING_MODE_FREEFORM &&
    private fun isFreeformRelaunch(triggerTask: RunningTaskInfo, request: TransitionRequestInfo) =
        (triggerTask.windowingMode == WINDOWING_MODE_FREEFORM &&
            TransitionUtil.isOpeningType(request.type) &&
            taskRepository.isActiveTask(triggerTask.taskId))

+12 −0
Original line number Diff line number Diff line
@@ -315,6 +315,7 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()
                .spyStatic(Toast::class.java)
                .startMocking()
        doReturn(true).`when` { DesktopModeStatus.canEnterDesktopMode(any()) }
        doReturn(true).`when` { DesktopModeStatus.isDesktopModeSupportedOnDisplay(any(), any()) }

        testScope = CoroutineScope(Dispatchers.Unconfined + SupervisorJob())
        spyContext = spy(mContext)
@@ -5307,6 +5308,17 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()
        assertNull(result, "Should not handle request")
    }

    @Test
    fun handleRequest_freeformTask_displayDoesntHandleDesktop_returnNull() {
        doReturn(false).`when` { DesktopModeStatus.isDesktopModeSupportedOnDisplay(any(), any()) }
        val task1 = createFreeformTask(displayId = SECOND_DISPLAY)

        val result =
            controller.handleRequest(Binder(), createTransition(task1, type = TRANSIT_OPEN))

        assertNull(result, "Should not handle request")
    }

    @Test
    @DisableFlags(Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND)
    fun moveFocusedTaskToDesktop_fullscreenTaskIsMovedToDesktop_multiDesksDisabled() {