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

Commit beb46205 authored by Matt Sziklay's avatar Matt Sziklay
Browse files

Preserve global task focus on restoreDisplay.

When restoring a display on reconnect, ensure the globally focused task remains focused, regardless of whether or not it was restored.

Bug: 435312155
Test: Manual
Flag: com.android.window.flags.enable_display_reconnect_interaction
Change-Id: Id948aa5775abad5874336391c50e01b6e4aab565
parent 189d9880
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -983,6 +983,10 @@ class DesktopTasksController(
            TilingDisplayReconnectEventHandler(repository, snapEventHandler, transitions, displayId)
        val excludedTasks =
            getFocusedNonDesktopTasks(DEFAULT_DISPLAY, userId).map { task -> task.taskId }
        // Preserve focus state on reconnect, regardless if focused task is restored or not.
        val globallyFocusedTask = shellTaskOrganizer.getRunningTaskInfo(
            focusTransitionObserver.globallyFocusedTaskId
        )
        mainScope.launch {
            preservedTaskIdsByDeskId.forEach { (preservedDeskId, preservedTaskIds) ->
                val newDeskId =
@@ -1036,6 +1040,9 @@ class DesktopTasksController(
                    )
                }
            }
            globallyFocusedTask?.let {
                wct.reorder(it.token, /* onTop= */ true, /* includingParents= */ true)
            }
            val transition = transitions.startTransition(TRANSIT_CHANGE, wct, null)
            tilingReconnectHandler.activationBinder = transition
            runOnTransitStartList.forEach { it.invoke(transition) }
@@ -5800,7 +5807,6 @@ class DesktopTasksController(
                ) {
                    // Inherit parent's bounds.
                    newWindowBounds.set(taskInfo.configuration.windowConfiguration.bounds)

                } else {
                    newWindowBounds.set(calculateDefaultDesktopTaskBounds(displayLayout))
                }
+57 −0
Original line number Diff line number Diff line
@@ -11299,6 +11299,63 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()
            verify(transitions, never()).startTransition(anyInt(), any(), anyOrNull())
        }
    @Test
    @EnableFlags(
        Flags.FLAG_ENABLE_DISPLAY_DISCONNECT_INTERACTION,
        Flags.FLAG_ENABLE_DISPLAY_RECONNECT_INTERACTION,
        Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND,
    )
    fun restoreDisplay_globalFocusedTaskRetainsFocus() =
        testScope.runTest {
            val defaultDisplayTask = setUpFreeformTask()
            whenever(focusTransitionObserver.globallyFocusedTaskId)
                .thenReturn(defaultDisplayTask.taskId)
            taskRepository.addDesk(SECOND_DISPLAY, DISCONNECTED_DESK_ID)
            taskRepository.setActiveDesk(displayId = SECOND_DISPLAY, deskId = DISCONNECTED_DESK_ID)
            val firstTaskBounds = Rect(100, 300, 1000, 1200)
            val firstTask =
                setUpFreeformTask(
                    displayId = SECOND_DISPLAY,
                    deskId = DISCONNECTED_DESK_ID,
                    bounds = firstTaskBounds,
                )
            val secondTaskBounds = Rect(400, 400, 1600, 900)
            val secondTask =
                setUpFreeformTask(
                    displayId = SECOND_DISPLAY,
                    deskId = DISCONNECTED_DESK_ID,
                    bounds = secondTaskBounds,
                )
            val wctCaptor = argumentCaptor<WindowContainerTransaction>()
            taskRepository.preserveDisplay(SECOND_DISPLAY, SECOND_DISPLAY_UNIQUE_ID)
            taskRepository.onDeskDisplayChanged(
                DISCONNECTED_DESK_ID,
                DEFAULT_DISPLAY,
                DEFAULT_DISPLAY_UNIQUE_ID,
            )
            whenever(desksOrganizer.createDesk(eq(SECOND_DISPLAY_ON_RECONNECT), any(), any()))
                .thenAnswer { invocation ->
                    (invocation.arguments[2] as DesksOrganizer.OnCreateCallback).onCreated(
                        deskId = 5
                    )
                }
            val transition = Binder()
            whenever(transitions.startTransition(eq(TRANSIT_CHANGE), any(), anyOrNull()))
                .thenReturn(transition)
            controller.restoreDisplay(
                displayId = SECOND_DISPLAY_ON_RECONNECT,
                uniqueDisplayId = SECOND_DISPLAY_UNIQUE_ID,
                userId = taskRepository.userId,
            )
            runCurrent()
            verify(transitions).startTransition(anyInt(), wctCaptor.capture(), anyOrNull())
            val wct = wctCaptor.firstValue
            wct.assertReorder(defaultDisplayTask.token, toTop = true, includingParents = true)
        }
    @Test
    @EnableFlags(
        Flags.FLAG_ENABLE_DISPLAY_DISCONNECT_INTERACTION,