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

Commit 94aeb784 authored by Toshiki Kikuchi's avatar Toshiki Kikuchi Committed by Android (Google) Code Review
Browse files

Merge "Force fullscreen when another fullscreen is on desktop-first display" into main

parents 37c132e3 de6c7f0d
Loading
Loading
Loading
Loading
+34 −0
Original line number Diff line number Diff line
@@ -3482,6 +3482,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
@@ -3771,6 +3783,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
@@ -5621,6 +5621,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)
@@ -5977,6 +6000,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 =