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

Commit 267eaead authored by Jorge Gil's avatar Jorge Gil Committed by Android (Google) Code Review
Browse files

Merge "Desks: Update repository active desk even if with-task not found" into main

parents a3cac0b7 6854def7
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -168,6 +168,10 @@ class DesksTransitionObserver(
                            deskChangeDisplayId,
                        )
                    }
                    desktopRepository.setActiveDesk(
                        displayId = deskTransition.displayId,
                        deskId = deskTransition.deskId,
                    )
                } else {
                    logW("ActivateDeskWithTask: did not find desk change")
                }
@@ -178,10 +182,6 @@ class DesksTransitionObserver(
                            desksOrganizer.getDeskAtEnd(change) == deskTransition.deskId
                    }
                if (taskChange != null) {
                    desktopRepository.setActiveDesk(
                        displayId = deskTransition.displayId,
                        deskId = deskTransition.deskId,
                    )
                    desktopRepository.addTaskToDesk(
                        displayId = deskTransition.displayId,
                        deskId = deskTransition.deskId,
@@ -189,6 +189,10 @@ class DesksTransitionObserver(
                        isVisible = true,
                    )
                } else {
                    // This is possible in cases where the task that was originally launched is a
                    // trampoline and a new task ends up being the one that appeared. It's ok as
                    // desktop task updates to the repository are handled by
                    // [DesktopTaskChangeListener].
                    logW("ActivateDeskWithTask: did not find task change")
                }
                deskTransition.runOnTransitEnd?.invoke()
+35 −0
Original line number Diff line number Diff line
@@ -294,6 +294,7 @@ class DesksTransitionObserverTest : ShellTestCase() {
            val task = createFreeformTask(DEFAULT_DISPLAY).apply { isVisibleRequested = true }
            val transition = Binder()
            val change = Change(mock(), mock()).apply { taskInfo = task }
            whenever(mockDesksOrganizer.isDeskChange(change, deskId = deskId)).thenReturn(true)
            whenever(mockDesksOrganizer.getDeskAtEnd(change)).thenReturn(deskId)
            val activateTransition =
                DeskTransition.ActivateDeskWithTask(
@@ -314,6 +315,40 @@ class DesksTransitionObserverTest : ShellTestCase() {
            assertThat(repository.getActiveTaskIdsInDesk(deskId)).contains(task.taskId)
        }

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND)
    fun onTransitionReady_activateDeskWithTask_trampolineTask_updatesRepositoryForDesk() =
        testScope.runTest {
            val deskId = 5
            val task = createFreeformTask(DEFAULT_DISPLAY).apply { isVisibleRequested = true }
            val task2 = createFreeformTask(DEFAULT_DISPLAY).apply { isVisibleRequested = true }
            val transition = Binder()
            val change = Change(mock(), mock()).apply { taskInfo = task2 }
            whenever(mockDesksOrganizer.isDeskChange(change, deskId = deskId)).thenReturn(true)
            whenever(mockDesksOrganizer.getDeskAtEnd(change)).thenReturn(deskId)
            val activateTransition =
                DeskTransition.ActivateDeskWithTask(
                    transition,
                    displayId = DEFAULT_DISPLAY,
                    deskId = deskId,
                    // Request was for |task|, but it will trampoline launch another task.
                    enterTaskId = task.taskId,
                )
            repository.addDesk(DEFAULT_DISPLAY, deskId = deskId)

            observer.addPendingTransition(activateTransition)
            observer.onTransitionReady(
                transition = transition,
                info =
                    TransitionInfo(TRANSIT_TO_FRONT, /* flags= */ 0)
                        // Actual task in change is |task2|.
                        .apply { addChange(change) },
            )

            // Desk is activated regardless of |task| not appearing in the transition.
            assertThat(repository.getActiveDeskId(DEFAULT_DISPLAY)).isEqualTo(deskId)
        }

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND)
    fun onTransitionReady_activateDeskWithTask_runsActivationCallback() =