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

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

Keep relaunched freeform tasks in freeform if default desktop

This CL prevents a relaunched freeform task from being in fullscreen if
the default-desktop flag is enabled.
Currently, when a freeform task is relaunched out of a desktop session,
it’s moved to fullscreen. But with default-desktop, we should keep it in
freeform.

Bug: 361419732
Flag: com.android.window.flags.enter_desktop_by_default_on_freeform_displays
Test: DesktopTasksControllerTest
Change-Id: I06ec124ffc3c27eb8bb62e07271f37b2b74f26ac
parent 8071ca44
Loading
Loading
Loading
Loading
+13 −9
Original line number Diff line number Diff line
@@ -303,13 +303,18 @@ class DesktopTasksController(
    private fun getSplitFocusedTask(task1: RunningTaskInfo, task2: RunningTaskInfo) =
        if (task1.taskId == task2.parentTaskId) task2 else task1

    private fun isFreeformDisplay(displayId: Int): Boolean {
    private fun forceEnterDesktop(displayId: Int): Boolean {
        if (!DesktopModeStatus.enterDesktopByDefaultOnFreeformDisplay(context)) {
            return false
        }

        val tdaInfo = rootTaskDisplayAreaOrganizer.getDisplayAreaInfo(displayId)
        requireNotNull(tdaInfo) {
            "This method can only be called with the ID of a display having non-null DisplayArea."
        }
        val tdaWindowingMode = tdaInfo.configuration.windowConfiguration.windowingMode
        return tdaWindowingMode == WINDOWING_MODE_FREEFORM
        val isFreeformDisplay = tdaWindowingMode == WINDOWING_MODE_FREEFORM
        return isFreeformDisplay
    }

    /** Moves task to desktop mode if task is running, else launches it in desktop mode. */
@@ -1189,10 +1194,11 @@ class DesktopTasksController(
        val wct = WindowContainerTransaction()
        if (!isDesktopModeShowing(task.displayId)) {
            logD("Bring desktop tasks to front on transition=taskId=%d", task.taskId)
            // We are outside of desktop mode and already existing desktop task is being launched.
            // We should make this task go to fullscreen instead of freeform. Note that this means
            // any re-launch of a freeform window outside of desktop will be in fullscreen.
            if (taskRepository.isActiveTask(task.taskId)) {
            if (taskRepository.isActiveTask(task.taskId) && !forceEnterDesktop(task.displayId)) {
                // We are outside of desktop mode and already existing desktop task is being
                // launched. We should make this task go to fullscreen instead of freeform. Note
                // that this means any re-launch of a freeform window outside of desktop will be in
                // fullscreen as long as default-desktop flag is disabled.
                addMoveToFullscreenChanges(wct, task)
                return wct
            }
@@ -1229,9 +1235,7 @@ class DesktopTasksController(
        transition: IBinder
    ): WindowContainerTransaction? {
        logV("handleFullscreenTaskLaunch")
        val forceEnterDesktop = DesktopModeStatus.enterDesktopByDefaultOnFreeformDisplay(context) &&
                isFreeformDisplay(task.displayId)
        if (isDesktopModeShowing(task.displayId) || forceEnterDesktop) {
        if (isDesktopModeShowing(task.displayId) || forceEnterDesktop(task.displayId)) {
            logD("Switch fullscreen task to freeform on transition: taskId=%d", task.taskId)
            return WindowContainerTransaction().also { wct ->
                addMoveToDesktopChanges(wct, task)
+39 −0
Original line number Diff line number Diff line
@@ -1758,6 +1758,37 @@ class DesktopTasksControllerTest : ShellTestCase() {
      .isEqualTo(WINDOWING_MODE_UNDEFINED)
  }

  @Test
  fun handleRequest_freeformTask_relaunchTask_enforceDesktop_freeformDisplay_noWinModeChange() {
    assumeTrue(ENABLE_SHELL_TRANSITIONS)
    whenever(DesktopModeStatus.enterDesktopByDefaultOnFreeformDisplay(context)).thenReturn(true)
    val tda = rootTaskDisplayAreaOrganizer.getDisplayAreaInfo(DEFAULT_DISPLAY)!!
    tda.configuration.windowConfiguration.windowingMode = WINDOWING_MODE_FREEFORM

    val freeformTask = setUpFreeformTask()
    markTaskHidden(freeformTask)
    val wct = controller.handleRequest(Binder(), createTransition(freeformTask))

    assertNotNull(wct, "should handle request")
    assertFalse(wct.anyWindowingModeChange(freeformTask.token))
  }

  @Test
  fun handleRequest_freeformTask_relaunchTask_enforceDesktop_fullscreenDisplay_becomesUndefined() {
    assumeTrue(ENABLE_SHELL_TRANSITIONS)
    whenever(DesktopModeStatus.enterDesktopByDefaultOnFreeformDisplay(context)).thenReturn(true)
    val tda = rootTaskDisplayAreaOrganizer.getDisplayAreaInfo(DEFAULT_DISPLAY)!!
    tda.configuration.windowConfiguration.windowingMode = WINDOWING_MODE_FULLSCREEN

    val freeformTask = setUpFreeformTask()
    markTaskHidden(freeformTask)
    val wct = controller.handleRequest(Binder(), createTransition(freeformTask))

    assertNotNull(wct, "should handle request")
    assertThat(wct.changes[freeformTask.token.asBinder()]?.windowingMode)
      .isEqualTo(WINDOWING_MODE_UNDEFINED)
  }

  @Test
  @DisableFlags(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_WALLPAPER_ACTIVITY)
  fun handleRequest_freeformTask_desktopWallpaperDisabled_freeformNotVisible_reorderedToTop() {
@@ -3488,6 +3519,14 @@ private fun WindowContainerTransaction?.anyDensityConfigChange(
  } ?: false
}

private fun WindowContainerTransaction?.anyWindowingModeChange(
  token: WindowContainerToken
): Boolean {
return this?.changes?.any { change ->
  change.key == token.asBinder() && change.value.windowingMode >= 0
} ?: false
}

private fun createTaskInfo(id: Int) =
    RecentTaskInfo().apply {
      taskId = id