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

Commit fe616ad2 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Desks: Only deactivate pre-recents desk" into main

parents 26103e5d 4db46a16
Loading
Loading
Loading
Loading
+24 −7
Original line number Diff line number Diff line
@@ -385,6 +385,9 @@ class DesktopTasksController(
    /** Returns whether the given display has an active desk. */
    fun isAnyDeskActive(displayId: Int): Boolean = taskRepository.isAnyDeskActive(displayId)

    /** Returns the id of the active desk in [displayId]. */
    fun getActiveDeskId(displayId: Int): Int? = taskRepository.getActiveDeskId(displayId)

    /**
     * Moves focused task to desktop mode for given [displayId].
     *
@@ -476,20 +479,34 @@ class DesktopTasksController(
        transition: IBinder,
        finishWct: WindowContainerTransaction,
        returnToApp: Boolean,
        activeDeskIdOnRecentsStart: Int?,
    ) {
        if (!DesktopExperienceFlags.ENABLE_MULTIPLE_DESKTOPS_BACKEND.isTrue) return
        logV("onRecentsInDesktopAnimationFinishing returnToApp=%b", returnToApp)
        if (returnToApp) return
        // Home/Recents only exists in the default display.
        val activeDesk = taskRepository.getActiveDeskId(DEFAULT_DISPLAY) ?: return
        // Not going back to the active desk, deactivate it.
        logV(
            "onRecentsInDesktopAnimationFinishing returnToApp=%b activeDeskIdOnRecentsStart=%d",
            returnToApp,
            activeDeskIdOnRecentsStart,
        )
        if (returnToApp) {
            // Returning to the same desk, nothing to do.
            return
        }
        if (
            activeDeskIdOnRecentsStart == null ||
                !taskRepository.isDeskActive(activeDeskIdOnRecentsStart)
        ) {
            // No desk was active or it is already inactive.
            return
        }
        // At this point the recents transition is either finishing to home, to another non-desktop
        // task or to a different desk than the one that was active when recents started. For all
        // of those the desk that was active needs to be deactivated.
        val runOnTransitStart =
            performDesktopExitCleanUp(
                wct = finishWct,
                deskId = activeDesk,
                deskId = activeDeskIdOnRecentsStart,
                displayId = DEFAULT_DISPLAY,
                willExitDesktop = true,
                shouldEndUpAtHome = true,
                // No need to clean up the wallpaper / home when coming from a recents transition.
                skipWallpaperAndHomeOrdering = true,
            )
+11 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.wm.shell.transition;

import static android.view.Display.DEFAULT_DISPLAY;
import static android.view.WindowManager.TRANSIT_FLAG_KEYGUARD_UNOCCLUDING;

import static com.android.wm.shell.shared.split.SplitScreenConstants.SPLIT_POSITION_UNDEFINED;
@@ -42,6 +43,13 @@ class RecentsMixedTransition extends DefaultMixedHandler.MixedTransition {
    private final RecentsTransitionHandler mRecentsHandler;
    private final DesktopTasksController mDesktopTasksController;

    /**
     * The id of the desk that was active when the transition started. Only set when {@link #mType}
     * is {@link DefaultMixedHandler.MixedTransition#TYPE_RECENTS_DURING_DESKTOP}.
     */
    @Nullable
    private final Integer mActiveDeskIdOnStart;

    RecentsMixedTransition(int type, IBinder transition, Transitions player,
            MixedTransitionHandler mixedHandler, PipTransitionController pipHandler,
            StageCoordinator splitHandler, KeyguardTransitionHandler keyguardHandler,
@@ -51,6 +59,8 @@ class RecentsMixedTransition extends DefaultMixedHandler.MixedTransition {
        mRecentsHandler = recentsHandler;
        mDesktopTasksController = desktopTasksController;
        mLeftoversHandler = mRecentsHandler;
        mActiveDeskIdOnStart = mType == TYPE_RECENTS_DURING_DESKTOP
                ? mDesktopTasksController.getActiveDeskId(DEFAULT_DISPLAY) : null;
    }

    @Override
@@ -204,7 +214,7 @@ class RecentsMixedTransition extends DefaultMixedHandler.MixedTransition {
    void onAnimateRecentsDuringDesktopFinishing(boolean returnToApp,
            @NonNull WindowContainerTransaction finishWct) {
        mDesktopTasksController.onRecentsInDesktopAnimationFinishing(mTransition, finishWct,
                returnToApp);
                returnToApp, mActiveDeskIdOnStart);
    }

    @Override
+9 −4
Original line number Diff line number Diff line
@@ -8736,6 +8736,7 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()
            transition = transition,
            finishWct = finishWct,
            returnToApp = true,
            activeDeskIdOnRecentsStart = deskId,
        )

        verify(desksOrganizer, never()).deactivateDesk(finishWct, deskId)
@@ -8747,7 +8748,7 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()

    @Test
    @EnableFlags(Flags.FLAG_ENABLE_MULTIPLE_DESKTOPS_BACKEND)
    fun onRecentsInDesktopAnimationFinishing_noActiveDesk_noDeskDeactivation() {
    fun onRecentsInDesktopAnimationFinishing_deskNoLongerActive_noDeskDeactivation() {
        val deskId = 0
        taskRepository.setDeskInactive(deskId)

@@ -8757,6 +8758,7 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()
            transition = transition,
            finishWct = finishWct,
            returnToApp = false,
            activeDeskIdOnRecentsStart = deskId,
        )

        verify(desksOrganizer, never()).deactivateDesk(finishWct, deskId)
@@ -8768,7 +8770,7 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()

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

@@ -8778,6 +8780,7 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()
            transition = transition,
            finishWct = finishWct,
            returnToApp = false,
            activeDeskIdOnRecentsStart = deskId,
        )

        verify(desksOrganizer).deactivateDesk(finishWct, deskId)
@@ -8787,7 +8790,7 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()

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

@@ -8797,6 +8800,7 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()
            transition = transition,
            finishWct = finishWct,
            returnToApp = false,
            activeDeskIdOnRecentsStart = deskId,
        )

        verify(desktopModeEnterExitTransitionListener)
@@ -8805,7 +8809,7 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()

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

@@ -8815,6 +8819,7 @@ class DesktopTasksControllerTest(flags: FlagsParameterization) : ShellTestCase()
            transition = transition,
            finishWct = finishWct,
            returnToApp = false,
            activeDeskIdOnRecentsStart = deskId,
        )

        finishWct.assertWithoutHop { hop ->