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

Commit a45822f4 authored by Matt Sziklay's avatar Matt Sziklay Committed by Android (Google) Code Review
Browse files

Merge "Preserve global task focus on restoreDisplay." into main

parents 18e2e91f beb46205
Loading
Loading
Loading
Loading
+7 −0
Original line number Original line Diff line number Diff line
@@ -1023,6 +1023,10 @@ class DesktopTasksController(
            TilingDisplayReconnectEventHandler(repository, snapEventHandler, transitions, displayId)
            TilingDisplayReconnectEventHandler(repository, snapEventHandler, transitions, displayId)
        val excludedTasks =
        val excludedTasks =
            getFocusedNonDesktopTasks(DEFAULT_DISPLAY, userId).map { task -> task.taskId }
            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 {
        mainScope.launch {
            preservedTaskIdsByDeskId.forEach { (preservedDeskId, preservedTaskIds) ->
            preservedTaskIdsByDeskId.forEach { (preservedDeskId, preservedTaskIds) ->
                val newDeskId =
                val newDeskId =
@@ -1076,6 +1080,9 @@ class DesktopTasksController(
                    )
                    )
                }
                }
            }
            }
            globallyFocusedTask?.let {
                wct.reorder(it.token, /* onTop= */ true, /* includingParents= */ true)
            }
            val transition = transitions.startTransition(TRANSIT_CHANGE, wct, null)
            val transition = transitions.startTransition(TRANSIT_CHANGE, wct, null)
            tilingReconnectHandler.activationBinder = transition
            tilingReconnectHandler.activationBinder = transition
            runOnTransitStartList.forEach { it.invoke(transition) }
            runOnTransitStartList.forEach { it.invoke(transition) }
+57 −0
Original line number Original line Diff line number Diff line
@@ -11477,6 +11477,63 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()
            verify(transitions, never()).startTransition(anyInt(), any(), anyOrNull())
            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
    @Test
    @EnableFlags(
    @EnableFlags(
        Flags.FLAG_ENABLE_DISPLAY_DISCONNECT_INTERACTION,
        Flags.FLAG_ENABLE_DISPLAY_DISCONNECT_INTERACTION,