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

Commit 5188c033 authored by Jorge Gil's avatar Jorge Gil
Browse files

Desks: Force freeform-incompatible tasks to fullscreen

When not in desktop, but the TDA is freeform and an incompatible task
launches in freeform mode by default, it should be forced out into
fullscreen mode otherwise it will remain in freeform but won't belong to
any desk. This can later lead to a NPE trying to add the freeform task
to the DesktopRepository that has no desks in it.

Flag: com.android.window.flags.enable_multiple_desktops_backend
Bug: 410731810
Test: test launching incompatible freeform task in touch-first display
that has 0 desks - verify it launches in fullscreen and there is no
crash

Change-Id: I562adba92c69af9a0f894601a723b0514ef2340d
parent b8661f84
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -2993,12 +2993,15 @@ class DesktopTasksController(
        val displayId = task.displayId
        val inDesktop = isAnyDeskActive(displayId)
        val isTransparentTask = desktopModeCompatPolicy.isTransparentTask(task)
        val isFreeform = task.isFreeform
        logV(
            "handleIncompatibleTaskLaunch taskId=%d displayId=%d isTransparent=%b inDesktop=%b",
            "handleIncompatibleTaskLaunch taskId=%d displayId=%d isTransparent=%b inDesktop=%b" +
                " isFreeform=%b",
            taskId,
            displayId,
            isTransparentTask,
            inDesktop,
            isFreeform,
        )
        if (!DesktopExperienceFlags.ENABLE_MULTIPLE_DESKTOPS_BACKEND.isTrue) {
            if (!inDesktop && !forceEnterDesktop(displayId)) return null
@@ -3026,14 +3029,14 @@ class DesktopTasksController(
            runOnTransitStart?.invoke(transition)
            return wct
        }
        if (!inDesktop) {
            logD("handleIncompatibleTaskLaunch not in desktop, nothing to do")
        if (!inDesktop && !isFreeform) {
            logD("handleIncompatibleTaskLaunch not in desktop, not a freeform task, nothing to do")
            return null
        }
        // Both opaque and transparent incompatible tasks need to be forced to fullscreen, but
        // opaque ones force-exit the desktop while transparent ones are just shown on top of the
        // desktop while keeping it active.
        val willExitDesktop = !isTransparentTask
        val willExitDesktop = inDesktop && !isTransparentTask
        if (willExitDesktop) {
            logD("handleIncompatibleTaskLaunch forcing task to fullscreen and exiting desktop")
        } else {
+32 −0
Original line number Diff line number Diff line
@@ -5226,6 +5226,38 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()
        verify(desksOrganizer).moveTaskToDesk(wct, deskId, task)
    }

    @Test
    @EnableFlags(
        Flags.FLAG_ENABLE_DESKTOP_WINDOWING_MODALS_POLICY,
        Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND,
    )
    fun handleRequest_exemptFromDesktopFreeformTask_notInDesktop_returnSwitchToFullscreenWCT() {
        taskRepository.setDeskInactive(deskId = 0)
        val tda =
            DisplayAreaInfo(MockToken().token(), DEFAULT_DISPLAY, /* featureId= */ 0).apply {
                configuration.windowConfiguration.windowingMode = WINDOWING_MODE_FREEFORM
            }
        whenever(rootTaskDisplayAreaOrganizer.getDisplayAreaInfo(DEFAULT_DISPLAY)).thenReturn(tda)
        val freeformExemptTask =
            createFreeformTask(displayId = DEFAULT_DISPLAY).apply {
                baseActivity =
                    ComponentName(
                        context.resources.getString(com.android.internal.R.string.config_systemUi),
                        /* cls= */ "",
                    )
            }

        val wct = controller.handleRequest(Binder(), createTransition(freeformExemptTask))

        assertNotNull(wct, "Should handle request")
        val mode =
            assertNotNull(
                wct.changes[freeformExemptTask.token.asBinder()]?.windowingMode,
                "Should have change for freeform task",
            )
        assertThat(mode).isEqualTo(WINDOWING_MODE_FULLSCREEN)
    }

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_MODALS_POLICY)
    @DisableFlags(