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

Commit 81330561 authored by Jorge Gil's avatar Jorge Gil
Browse files

Desks: Do not trigger taskbar anim on recents-finish out of desk

DesktopModeEnterExitTransitionListener#onExitDesktopModeTransitionStarted
is meant to notify the taskbar of a transition to exit desktop mode that
has just started but is not yet animated so that the taskbar animation
to hide itself can trigger (roughly) in sync with the transition.

I34b9a581db3af5e160e32b005d35742089f55cb7 added a change to trigger a
desk deactivation, and thus a |onExitDesktopModeTransitionStarted| call
in |onRecentsInDesktopAnimationFinishing| because with multiple desks,
a desk may need to be deactivated if finishing recents to home or
another non-desk task. However, the |onExitDesktopModeTransitionStarted|
call is not needed here as the taskbar does not need to be animated, and
it would also be too late to animate it, since this is called on
transit-finish, not on transit start. This change removes that call from
this path.

Also guards all calls to this interface behind a check for both the
frontend and backend flags, because this interface is deprecated when
both flags are enabled.

Flag: com.android.window.flags.enable_multiple_desktops_backend
Flag: com.android.window.flags.enable_multiple_desktops_frontend
Bug: 411597362
Test: ran systemui-desktopmode-enter-1-jank-suite locally
(EnterDesktopViaStaticDesktopOverviewTaskMicrobenchmark) and verify
latency increase is fixed.
Test: atest DesktopTasksControllerTest

Change-Id: I10188542e4a6575b1eebb202a1c6ea9cc83998d2
parent 6025b7d0
Loading
Loading
Loading
Loading
+48 −20
Original line number Diff line number Diff line
@@ -508,6 +508,8 @@ class DesktopTasksController(
                willExitDesktop = true,
                // No need to clean up the wallpaper / home when coming from a recents transition.
                skipWallpaperAndHomeOrdering = true,
                // This is a recents-finish, so taskbar animation on transit start does not apply.
                skipUpdatingExitDesktopListener = true,
            )
        runOnTransitStart?.invoke(transition)
    }
@@ -859,9 +861,12 @@ class DesktopTasksController(
            transition = enterDesktopTaskTransitionHandler.moveToDesktop(wct, transitionSource)
            invokeCallbackToOverview(transition, callback)
        }
        // Replaced by |IDesktopTaskListener#onActiveDeskChanged|.
        if (!desktopState.enableMultipleDesktops) {
            desktopModeEnterExitTransitionListener?.onEnterDesktopModeTransitionStarted(
                toDesktopAnimationDurationMs
            )
        }
        runOnTransitStart?.invoke(transition)
        exitResult.asExit()?.runOnTransitionStart?.invoke(transition)
        return true
@@ -904,9 +909,12 @@ class DesktopTasksController(
            transition = enterDesktopTaskTransitionHandler.moveToDesktop(wct, transitionSource)
            invokeCallbackToOverview(transition, callback)
        }
        // Replaced by |IDesktopTaskListener#onActiveDeskChanged|.
        if (!desktopState.enableMultipleDesktops) {
            desktopModeEnterExitTransitionListener?.onEnterDesktopModeTransitionStarted(
                toDesktopAnimationDurationMs
            )
        }
        runOnTransitStart?.invoke(transition)
        exitResult.asExit()?.runOnTransitionStart?.invoke(transition)
        if (!DesktopExperienceFlags.ENABLE_MULTIPLE_DESKTOPS_BACKEND.isTrue) {
@@ -984,9 +992,12 @@ class DesktopTasksController(
                reason = DesktopImmersiveController.ExitReason.TASK_LAUNCH,
            )
        val transition = dragToDesktopTransitionHandler.finishDragToDesktopTransition(wct)
        // Replaced by |IDesktopTaskListener#onActiveDeskChanged|.
        if (!desktopState.enableMultipleDesktops) {
            desktopModeEnterExitTransitionListener?.onEnterDesktopModeTransitionStarted(
                DRAG_TO_DESKTOP_FINISH_ANIM_DURATION_MS.toInt()
            )
        }
        if (transition != null) {
            runOnTransitStart?.invoke(transition)
            exitResult.asExit()?.runOnTransitionStart?.invoke(transition)
@@ -1324,7 +1335,11 @@ class DesktopTasksController(
            !taskRepository.isOnlyVisibleNonClosingTask(task.taskId)
            // This callback is already invoked by |addMoveToFullscreenChanges| when this flag is
            // enabled.
            && !DesktopExperienceFlags.ENABLE_MULTIPLE_DESKTOPS_BACKEND.isTrue
            &&
                !DesktopExperienceFlags.ENABLE_MULTIPLE_DESKTOPS_BACKEND.isTrue
                // Replaced by |IDesktopTaskListener#onActiveDeskChanged|.
                &&
                !desktopState.enableMultipleDesktops
        ) {
            desktopModeEnterExitTransitionListener?.onExitDesktopModeTransitionStarted(
                FULLSCREEN_ANIMATION_DURATION,
@@ -1496,10 +1511,13 @@ class DesktopTasksController(
            // Desk activation must be handled before app launch-related transactions.
            activateDeskWct.merge(launchTransaction, /* transfer= */ true)
            launchTransaction = activateDeskWct
            // Replaced by |IDesktopTaskListener#onActiveDeskChanged|.
            if (!desktopState.enableMultipleDesktops) {
                desktopModeEnterExitTransitionListener?.onEnterDesktopModeTransitionStarted(
                    toDesktopAnimationDurationMs
                )
            }
        }
        val t =
            if (remoteTransition == null) {
                logV("startLaunchTransition -- no remoteTransition -- wct = $launchTransaction")
@@ -2338,12 +2356,19 @@ class DesktopTasksController(
        willExitDesktop: Boolean,
        shouldEndUpAtHome: Boolean = true,
        skipWallpaperAndHomeOrdering: Boolean = false,
        skipUpdatingExitDesktopListener: Boolean = false,
    ): RunOnTransitStart? {
        if (!willExitDesktop) return null
        if (
            !skipUpdatingExitDesktopListener &&
                // Replaced by |IDesktopTaskListener#onActiveDeskChanged|.
                !desktopState.enableMultipleDesktops
        ) {
            desktopModeEnterExitTransitionListener?.onExitDesktopModeTransitionStarted(
                FULLSCREEN_ANIMATION_DURATION,
                shouldEndUpAtHome,
            )
        }
        if (
            !skipWallpaperAndHomeOrdering ||
                !DesktopExperienceFlags.ENABLE_MULTIPLE_DESKTOPS_BACKEND.isTrue
@@ -3605,10 +3630,13 @@ class DesktopTasksController(
        handler?.setTransition(transition)
        runOnTransitStart?.invoke(transition)

        // Replaced by |IDesktopTaskListener#onActiveDeskChanged|.
        if (!desktopState.enableMultipleDesktops) {
            desktopModeEnterExitTransitionListener?.onEnterDesktopModeTransitionStarted(
                toDesktopAnimationDurationMs
            )
        }
    }

    /**
     * TODO: b/393978539 - Deactivation should not happen in desktop-first devices when going home.
+7 −15
Original line number Diff line number Diff line
@@ -40,10 +40,9 @@ import com.google.common.truth.Truth.assertThat
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.ArgumentMatchers.anyBoolean
import org.mockito.ArgumentMatchers.anyInt
import org.mockito.ArgumentMatchers.eq
import org.mockito.kotlin.any
import org.mockito.kotlin.anyOrNull
import org.mockito.kotlin.eq
import org.mockito.kotlin.mock
import org.mockito.kotlin.never
import org.mockito.kotlin.verify
@@ -83,9 +82,9 @@ class DesktopPipTransitionControllerTest(flags: FlagsParameterization) : ShellTe
    @Before
    fun setUp() {
        whenever(mockPipDesktopState.isDesktopWindowingPipEnabled()).thenReturn(true)
        whenever(mockDesktopUserRepositories.getProfile(anyInt())).thenReturn(mockDesktopRepository)
        whenever(mockDesktopRepository.isAnyDeskActive(anyInt())).thenReturn(true)
        whenever(mockDesktopRepository.getActiveDeskId(anyInt())).thenReturn(DESK_ID)
        whenever(mockDesktopUserRepositories.getProfile(any())).thenReturn(mockDesktopRepository)
        whenever(mockDesktopRepository.isAnyDeskActive(any())).thenReturn(true)
        whenever(mockDesktopRepository.getActiveDeskId(any())).thenReturn(DESK_ID)
        whenever(mockShellTaskOrganizer.getRunningTaskInfo(freeformParentTask.taskId))
            .thenReturn(freeformParentTask)
        whenever(mockShellTaskOrganizer.getRunningTaskInfo(fullscreenParentTask.taskId))
@@ -112,7 +111,7 @@ class DesktopPipTransitionControllerTest(flags: FlagsParameterization) : ShellTe
    @Test
    fun maybeUpdateParentInWct_nullParentInfo_noWctChanges() {
        val wct = WindowContainerTransaction()
        whenever(mockShellTaskOrganizer.getRunningTaskInfo(anyInt())).thenReturn(null)
        whenever(mockShellTaskOrganizer.getRunningTaskInfo(any())).thenReturn(null)

        controller.maybeUpdateParentInWct(wct, freeformParentTask.taskId)

@@ -225,14 +224,7 @@ class DesktopPipTransitionControllerTest(flags: FlagsParameterization) : ShellTe
                )
        } else {
            verify(mockDesktopTasksController, never())
                .performDesktopExitCleanUp(
                    any(),
                    anyInt(),
                    anyInt(),
                    anyBoolean(),
                    anyBoolean(),
                    anyBoolean(),
                )
                .performDesktopExitCleanUp(any(), anyOrNull(), any(), any(), any(), any(), any())
        }
    }

+0 −19
Original line number Diff line number Diff line
@@ -8921,25 +8921,6 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()
            .addPendingTransition(DeskTransition.DeactivateDesk(transition, deskId))
    }

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND)
    fun onRecentsInDesktopAnimationFinishing_deskStillActive_notReturningToDesk_notifiesDesktopExit() {
        val deskId = 0
        taskRepository.setActiveDesk(DEFAULT_DISPLAY, deskId)

        val transition = Binder()
        val finishWct = WindowContainerTransaction()
        controller.onRecentsInDesktopAnimationFinishing(
            transition = transition,
            finishWct = finishWct,
            returnToApp = false,
            activeDeskIdOnRecentsStart = deskId,
        )

        verify(desktopModeEnterExitTransitionListener)
            .onExitDesktopModeTransitionStarted(any(), any())
    }

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND)
    fun onRecentsInDesktopAnimationFinishing_deskStillActive_notReturningToDesk_doesNotBringUpWallpaperOrHome() {