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

Commit de6c7f0d authored by Toshiki Kikuchi's avatar Toshiki Kikuchi
Browse files

Force fullscreen when another fullscreen is on desktop-first display

This CL avoids applying desktop-first policy for a new task when another
fullscreen app (not fullscreen-in-desk) is focused on the target
display.

Flag: com.android.window.flags.enable_desktop_first_top_fullscreen_bugfix
Bug: 431066262
Test: DesktopTasksControllerTests
Change-Id: I784b9b8eace2f7a43775e70be63e3748fd5416f0
parent 6e3b775d
Loading
Loading
Loading
Loading
+34 −0
Original line number Diff line number Diff line
@@ -3389,6 +3389,18 @@ class DesktopTasksController(
                // If there is an active desk on the target display, then it is already in desktop
                // windowing so the new task should also be placed in desktop windowing.
                anyDeskActive -> true
                DesktopExperienceFlags.ENABLE_DESKTOP_FIRST_TOP_FULLSCREEN_BUGFIX.isTrue ->
                    // Here we have no desk activated, but check if we really want to force a task
                    // into desktop.
                    if (rootTaskDisplayAreaOrganizer.isDisplayDesktopFirst(task.displayId)) {
                        // In desktop-first mode, we force to activate desk only when the
                        // desktop-first policy can be applied.
                        shouldForceEnterDesktop
                    } else {
                        // In touch-first mode, new tasks should be forced into desktop, while known
                        // desktop tasks should be moved outside of desktop.
                        !isKnownDesktopTask
                    }
                // If there is some desk on target display and it's been marked as a "desktop-first"
                // display, activate the desk and place the task in desktop windowing.
                shouldForceEnterDesktop -> true
@@ -3670,6 +3682,28 @@ class DesktopTasksController(
        }

        val isDesktopFirst = rootTaskDisplayAreaOrganizer.isDisplayDesktopFirst(targetDisplayId)
        if (DesktopExperienceFlags.ENABLE_DESKTOP_FIRST_TOP_FULLSCREEN_BUGFIX.isTrue) {
            val anyDeskActive = isAnyDeskActive(targetDisplayId)
            val focusedTask = focusTransitionObserver.getFocusedTaskOnDisplay(targetDisplayId)
            val isFullscreenFocused = focusedTask?.isFullscreen == true
            val isNonHomeFocused = focusedTask?.activityType != ACTIVITY_TYPE_HOME
            logV(
                "shouldForceEnterDesktopByDesktopFirstPolicy: anyDeskActive=%s " +
                    "isFullscreenFocused=%s isNonHomeFocused=%s",
                anyDeskActive,
                isFullscreenFocused,
                isNonHomeFocused,
            )
            if (isDesktopFirst && !anyDeskActive && isFullscreenFocused && isNonHomeFocused) {
                logV(
                    "shouldForceEnterDesktopByDesktopFirstPolicy: no switch as the other " +
                        "fullscreen task is focused on desktop-first display#%s",
                    targetDisplayId,
                )
                return false
            }
        }

        if (
            DesktopExperienceFlags.ENABLE_DESKTOP_FIRST_FULLSCREEN_REFOCUS_BUGFIX.isTrue &&
                isDesktopFirst &&
+47 −0
Original line number Diff line number Diff line
@@ -5552,6 +5552,29 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()
        verify(desksOrganizer).moveTaskToDesk(wct, deskId, fullscreenTask)
    }

    @Test
    @EnableFlags(
        Flags.FLAG_ENABLE_DESKTOP_WINDOWING_WALLPAPER_ACTIVITY,
        Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND,
        Flags.FLAG_ENABLE_DESKTOP_FIRST_BASED_DEFAULT_TO_DESKTOP_BUGFIX,
        Flags.FLAG_ENABLE_DESKTOP_FIRST_TOP_FULLSCREEN_BUGFIX,
    )
    fun handleRequest_fullscreenTask_fullscreenFocused_freeformDisplay_returnNull() {
        val deskId = 0
        taskRepository.setDeskInactive(deskId)
        whenever(desktopWallpaperActivityTokenProvider.getToken()).thenReturn(null)
        val tda = rootTaskDisplayAreaOrganizer.getDisplayAreaInfo(DEFAULT_DISPLAY)!!
        tda.configuration.windowConfiguration.windowingMode = WINDOWING_MODE_FREEFORM

        val focusedFullscreenTask = createFullscreenTask()
        whenever(focusTransitionObserver.getFocusedTaskOnDisplay(any()))
            .thenReturn(focusedFullscreenTask)

        val fullscreenTask = createFullscreenTask()

        assertThat(controller.handleRequest(Binder(), createTransition(fullscreenTask))).isNull()
    }

    @Test
    fun handleRequest_fullscreenTask_notInDesk_enforceDesktop_fullscreenDisplay_returnNull() {
        taskRepository.setDeskInactive(deskId = 0)
@@ -5908,6 +5931,30 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()
        verify(desksOrganizer).moveTaskToDesk(result, deskId = 0, freeformTask)
    }

    @Test
    @EnableFlags(
        Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND,
        Flags.FLAG_ENABLE_DESKTOP_FIRST_BASED_DEFAULT_TO_DESKTOP_BUGFIX,
        Flags.FLAG_ENABLE_DESKTOP_FIRST_TOP_FULLSCREEN_BUGFIX,
    )
    fun handleRequest_freeformTask_fullscreenFocused_freeformDisplay_moveToFullscreen() {
        val deskId = 0
        taskRepository.setDeskInactive(deskId)
        whenever(desktopWallpaperActivityTokenProvider.getToken()).thenReturn(null)
        val tda = rootTaskDisplayAreaOrganizer.getDisplayAreaInfo(DEFAULT_DISPLAY)!!
        tda.configuration.windowConfiguration.windowingMode = WINDOWING_MODE_FREEFORM

        val focusedFullscreenTask = createFullscreenTask()
        whenever(focusTransitionObserver.getFocusedTaskOnDisplay(any()))
            .thenReturn(focusedFullscreenTask)

        val freeformTask = createFreeformTask(displayId = DEFAULT_DISPLAY)

        val wct = controller.handleRequest(Binder(), createTransition(freeformTask))
        assertThat(wct?.changes[freeformTask.token.asBinder()]?.windowingMode)
            .isEqualTo(WINDOWING_MODE_FULLSCREEN)
    }

    @Test
    fun handleRequest_notOpenOrToFrontTransition_returnNull() {
        val task =