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

Commit 98384602 authored by Graciela Wissen Putri's avatar Graciela Wissen Putri
Browse files

Cascade freeform tasks if not visible

Apply cascading effect to tasks launched in freeform in desktop mode if
task has not been added to desktop yet via handleFullscreenTaskLaunch.
This can happen with a trampoline activity which will inherit freeform
windowing mode from its source task and launch via
handleFreeformTaskLaunch.

Flag: com.android.window.flags.enable_cascading_windows
Fix: 357645618
Test: atest DesktopTasksControllerTest
      Open Gmail -> Compose
      Open Play Store -> open installed app
      Open Chrome -> new window
Change-Id: Ifd282ac726f2f8486ab0be5ed7214f2922279f01
parent 0d20e8d9
Loading
Loading
Loading
Loading
+26 −11
Original line number Diff line number Diff line
@@ -1043,6 +1043,17 @@ class DesktopTasksController(
            wct.reorder(task.token, true)
            return wct
        }
        // If task is already visible, it must have been handled already and added to desktop mode.
        // Cascade task only if it's not visible yet.
        if (DesktopModeFlags.CASCADING_WINDOWS.isEnabled(context)
                && !taskRepository.isVisibleTask(task.taskId)) {
            val displayLayout = displayController.getDisplayLayout(task.displayId)
            if (displayLayout != null) {
                val initialBounds = Rect(task.configuration.windowConfiguration.bounds)
                cascadeWindow(task, initialBounds, displayLayout)
                wct.setBounds(task.token, initialBounds)
            }
        }
        if (useDesktopOverrideDensity()) {
            wct.setDensityDpi(task.token, DESKTOP_DENSITY_OVERRIDE)
        }
@@ -1127,18 +1138,9 @@ class DesktopTasksController(
        }

        if (DesktopModeFlags.CASCADING_WINDOWS.isEnabled(context)) {
            val stableBounds = Rect()
            displayLayout.getStableBoundsForDesktopMode(stableBounds)

            val activeTasks = taskRepository
                .getActiveNonMinimizedOrderedTasks(taskInfo.displayId)
            activeTasks.firstOrNull()?.let { activeTask ->
                shellTaskOrganizer.getRunningTaskInfo(activeTask)?.let {
                    cascadeWindow(context.resources, stableBounds,
                        it.configuration.windowConfiguration.bounds, initialBounds)
                }
            }
            cascadeWindow(taskInfo, initialBounds, displayLayout)
        }

        if (canChangeTaskPosition(taskInfo)) {
            wct.setBounds(taskInfo.token, initialBounds)
        }
@@ -1173,6 +1175,19 @@ class DesktopTasksController(
        }
    }

    private fun cascadeWindow(task: TaskInfo, bounds: Rect, displayLayout: DisplayLayout) {
        val stableBounds = Rect()
        displayLayout.getStableBoundsForDesktopMode(stableBounds)

        val activeTasks = taskRepository.getActiveNonMinimizedOrderedTasks(task.displayId)
        activeTasks.firstOrNull()?.let { activeTask ->
            shellTaskOrganizer.getRunningTaskInfo(activeTask)?.let {
                cascadeWindow(context.resources, stableBounds,
                    it.configuration.windowConfiguration.bounds, bounds)
            }
        }
    }

    /**
     * Adds split screen changes to a transaction. Note that bounds are not reset here due to
     * animation; see {@link onDesktopSplitSelectAnimComplete}
+41 −3
Original line number Diff line number Diff line
@@ -639,6 +639,41 @@ class DesktopTasksControllerTest : ShellTestCase() {
    assertThat(finalBounds).isEqualTo(Rect())
  }

  @Test
  @EnableFlags(Flags.FLAG_ENABLE_CASCADING_WINDOWS)
  fun handleRequest_newFreeformTaskLaunch_cascadeApplied() {
    assumeTrue(ENABLE_SHELL_TRANSITIONS)
    setUpLandscapeDisplay()
    val stableBounds = Rect()
    displayLayout.getStableBoundsForDesktopMode(stableBounds)

    setUpFreeformTask(bounds = DEFAULT_LANDSCAPE_BOUNDS)
    val freeformTask = setUpFreeformTask(bounds = DEFAULT_LANDSCAPE_BOUNDS, active = false)

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

    assertNotNull(wct, "should handle request")
    val finalBounds = findBoundsChange(wct, freeformTask)
    assertThat(stableBounds.getDesktopTaskPosition(finalBounds!!))
      .isEqualTo(DesktopTaskPosition.BottomRight)
  }

  @Test
  @EnableFlags(Flags.FLAG_ENABLE_CASCADING_WINDOWS)
  fun handleRequest_freeformTaskAlreadyExistsInDesktopMode_cascadeNotApplied() {
    assumeTrue(ENABLE_SHELL_TRANSITIONS)
    setUpLandscapeDisplay()
    val stableBounds = Rect()
    displayLayout.getStableBoundsForDesktopMode(stableBounds)

    setUpFreeformTask(bounds = DEFAULT_LANDSCAPE_BOUNDS)
    val freeformTask = setUpFreeformTask(bounds = DEFAULT_LANDSCAPE_BOUNDS)

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

    assertNull(wct, "should not handle request")
  }

  @Test
  @EnableFlags(Flags.FLAG_ENABLE_CASCADING_WINDOWS)
  fun addMoveToDesktopChanges_positionBottomRight() {
@@ -2691,14 +2726,17 @@ class DesktopTasksControllerTest : ShellTestCase() {

  private fun setUpFreeformTask(
      displayId: Int = DEFAULT_DISPLAY,
      bounds: Rect? = null
      bounds: Rect? = null,
      active: Boolean = true
  ): RunningTaskInfo {
    val task = createFreeformTask(displayId, bounds)
    val activityInfo = ActivityInfo()
    task.topActivityInfo = activityInfo
    whenever(shellTaskOrganizer.getRunningTaskInfo(task.taskId)).thenReturn(task)
    if (active) {
      taskRepository.addActiveTask(displayId, task.taskId)
      taskRepository.updateTaskVisibility(displayId, task.taskId, visible = true)
    }
    taskRepository.addOrMoveFreeformTaskToTop(displayId, task.taskId)
    runningTasks.add(task)
    return task