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

Commit 6854def7 authored by Jorge Gil's avatar Jorge Gil
Browse files

Desks: Update repository active desk even if with-task not found

It's possible an ActivateDeskWithTask transition does not contain the
change for the taskId initially requested to enter desktop, such as when
the requested task trampolines into another task. With this change, the
desk activation state is updated regardless. The task update is ok to
skip because DesktopTaskChangeListener handles individual task updates
anyway.

Flag: com.android.window.flags.enable_multiple_desktops_backend
Fix: 419744334
Test: atest DesksTransitionObserverTest
Test: in a desktop-first display, in Home, launch Calendar from taskbar
or all apps - verify desk is activated in repository.

Change-Id: I53ee968993d0fb7d0d05862ababd5b24b6517998
parent 570cc3f1
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -151,6 +151,10 @@ class DesksTransitionObserver(
                            deskChangeDisplayId,
                        )
                    }
                    desktopRepository.setActiveDesk(
                        displayId = deskTransition.displayId,
                        deskId = deskTransition.deskId,
                    )
                } else {
                    logW("ActivateDeskWithTask: did not find desk change")
                }
@@ -161,10 +165,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,
@@ -172,6 +172,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
@@ -240,6 +240,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(
@@ -260,6 +261,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() =