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

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

Merge "Keep relaunched freeform tasks in freeform if default desktop" into main

parents 824608bc e1662a1b
Loading
Loading
Loading
Loading
+13 −9
Original line number Diff line number Diff line
@@ -305,13 +305,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. */
@@ -1191,10 +1196,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
            }
@@ -1231,9 +1237,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
@@ -1763,6 +1763,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() {
@@ -3493,6 +3524,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