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

Commit 3ea5169d authored by Merissa Mitchell's avatar Merissa Mitchell
Browse files

Revert "[PiP2 on Desktop] Don't exit Desktop Mode when PiP is active."

This reverts commit f4ae6bf4.

Reason for revert: We no longer want this CUJ-- PiP should not influence desk close/deactivation at all

Test: atest DesktopTasksTransitionObserverTest DesktopRepositoryTest
DesktopTasksControllerTest PipSchedulerTest PipDesktopStateTest
Bug: 385207728
Bug: 399208646
Flag: com.android.window.flags.enable_desktop_windowing_pip

Change-Id: Idd6ab1981a868f143f2415a219e76bce87183492
parent e22a4ae1
Loading
Loading
Loading
Loading
+2 −60
Original line number Diff line number Diff line
@@ -19,18 +19,12 @@ package com.android.wm.shell.common.pip;
import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;

import android.app.ActivityManager;
import android.window.DesktopExperienceFlags;
import android.window.DisplayAreaInfo;
import android.window.WindowContainerToken;
import android.window.WindowContainerTransaction;

import com.android.window.flags.Flags;
import com.android.wm.shell.RootTaskDisplayAreaOrganizer;
import com.android.wm.shell.desktopmode.DesktopRepository;
import com.android.wm.shell.desktopmode.DesktopUserRepositories;
import com.android.wm.shell.desktopmode.desktopwallpaperactivity.DesktopWallpaperActivityTokenProvider;
import com.android.wm.shell.pip2.phone.PipTransition;

import java.util.Optional;

@@ -38,32 +32,23 @@ import java.util.Optional;
public class PipDesktopState {
    private final PipDisplayLayoutState mPipDisplayLayoutState;
    private final Optional<DesktopUserRepositories> mDesktopUserRepositoriesOptional;
    private final Optional<DesktopWallpaperActivityTokenProvider>
            mDesktopWallpaperActivityTokenProviderOptional;
    private final RootTaskDisplayAreaOrganizer mRootTaskDisplayAreaOrganizer;

    public PipDesktopState(PipDisplayLayoutState pipDisplayLayoutState,
            Optional<DesktopUserRepositories> desktopUserRepositoriesOptional,
            Optional<DesktopWallpaperActivityTokenProvider>
                    desktopWallpaperActivityTokenProviderOptional,
            RootTaskDisplayAreaOrganizer rootTaskDisplayAreaOrganizer) {
        mPipDisplayLayoutState = pipDisplayLayoutState;
        mDesktopUserRepositoriesOptional = desktopUserRepositoriesOptional;
        mDesktopWallpaperActivityTokenProviderOptional =
                desktopWallpaperActivityTokenProviderOptional;
        mRootTaskDisplayAreaOrganizer = rootTaskDisplayAreaOrganizer;
    }

    /**
     * Returns whether PiP in Desktop Windowing is enabled by checking the following:
     * - Desktop Windowing in PiP flag is enabled
     * - DesktopWallpaperActivityTokenProvider is injected
     * - DesktopUserRepositories is injected
     */
    public boolean isDesktopWindowingPipEnabled() {
        return Flags.enableDesktopWindowingPip()
                && mDesktopWallpaperActivityTokenProviderOptional.isPresent()
                && mDesktopUserRepositoriesOptional.isPresent();
        return Flags.enableDesktopWindowingPip() && mDesktopUserRepositoriesOptional.isPresent();
    }

    /** Returns whether PiP in Connected Displays is enabled by checking the flag. */
@@ -89,45 +74,10 @@ public class PipDesktopState {
            return false;
        }
        final int displayId = mPipDisplayLayoutState.getDisplayId();
        return getDesktopRepository().isAnyDeskActive(displayId)
                || getDesktopWallpaperActivityTokenProvider().isWallpaperActivityVisible(displayId)
        return mDesktopUserRepositoriesOptional.get().getCurrent().isAnyDeskActive(displayId)
                || isDisplayInFreeform();
    }

    /** Returns whether {@param pipTask} would be entering in a Desktop Mode session. */
    public boolean isPipEnteringInDesktopMode(ActivityManager.RunningTaskInfo pipTask) {
        // Early return if PiP in Desktop Windowing is not supported.
        if (!isDesktopWindowingPipEnabled()) {
            return false;
        }
        final DesktopRepository desktopRepository = getDesktopRepository();
        return desktopRepository.isAnyDeskActive(pipTask.getDisplayId())
                || desktopRepository.isMinimizedPipPresentInDisplay(pipTask.getDisplayId());
    }

    /**
     * Invoked when an EXIT_PiP transition is detected in {@link PipTransition}.
     * Returns whether the PiP exiting should also trigger the active Desktop Mode session to exit.
     */
    public boolean shouldExitPipExitDesktopMode() {
        // Early return if PiP in Desktop Windowing is not supported.
        if (!isDesktopWindowingPipEnabled()) {
            return false;
        }
        final int displayId = mPipDisplayLayoutState.getDisplayId();
        return !getDesktopRepository().isAnyDeskActive(displayId)
                && getDesktopWallpaperActivityTokenProvider().isWallpaperActivityVisible(displayId);
    }

    /**
     * Returns a {@link WindowContainerTransaction} that reorders the {@link WindowContainerToken}
     * of the DesktopWallpaperActivity for the display with the given {@param displayId}.
     */
    public WindowContainerTransaction getWallpaperActivityTokenWct(int displayId) {
        return new WindowContainerTransaction().reorder(
                getDesktopWallpaperActivityTokenProvider().getToken(displayId), /* onTop= */ false);
    }

    /**
     * The windowing mode to restore to when resizing out of PIP direction.
     * Defaults to undefined and can be overridden to restore to an alternate windowing mode.
@@ -149,12 +99,4 @@ public class PipDesktopState {
        // By default, or if the task is going to fullscreen, reset the windowing mode to undefined.
        return WINDOWING_MODE_UNDEFINED;
    }

    private DesktopRepository getDesktopRepository() {
        return mDesktopUserRepositoriesOptional.get().getCurrent();
    }

    private DesktopWallpaperActivityTokenProvider getDesktopWallpaperActivityTokenProvider() {
        return mDesktopWallpaperActivityTokenProviderOptional.get();
    }
}
+1 −4
Original line number Diff line number Diff line
@@ -42,7 +42,6 @@ import com.android.wm.shell.common.pip.SizeSpecSource;
import com.android.wm.shell.dagger.WMShellBaseModule;
import com.android.wm.shell.dagger.WMSingleton;
import com.android.wm.shell.desktopmode.DesktopUserRepositories;
import com.android.wm.shell.desktopmode.desktopwallpaperactivity.DesktopWallpaperActivityTokenProvider;
import com.android.wm.shell.pip2.phone.PhonePipMenuController;
import com.android.wm.shell.pip2.phone.PipController;
import com.android.wm.shell.pip2.phone.PipMotionHelper;
@@ -238,11 +237,9 @@ public abstract class Pip2Module {
    static PipDesktopState providePipDesktopState(
            PipDisplayLayoutState pipDisplayLayoutState,
            Optional<DesktopUserRepositories> desktopUserRepositoriesOptional,
            Optional<DesktopWallpaperActivityTokenProvider>
                    desktopWallpaperActivityTokenProviderOptional,
            RootTaskDisplayAreaOrganizer rootTaskDisplayAreaOrganizer
    ) {
        return new PipDesktopState(pipDisplayLayoutState, desktopUserRepositoriesOptional,
                desktopWallpaperActivityTokenProviderOptional, rootTaskDisplayAreaOrganizer);
                rootTaskDisplayAreaOrganizer);
    }
}
+1 −43
Original line number Diff line number Diff line
@@ -28,7 +28,6 @@ import androidx.core.util.forEach
import androidx.core.util.valueIterator
import com.android.internal.annotations.VisibleForTesting
import com.android.internal.protolog.ProtoLog
import com.android.window.flags.Flags
import com.android.wm.shell.desktopmode.persistence.DesktopPersistentRepository
import com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_DESKTOP_MODE
import com.android.wm.shell.shared.annotations.ShellMainThread
@@ -70,9 +69,6 @@ class DesktopRepository(
     *   fullscreen task launched on top of the desk. Cleared when the transparent task is closed or
     *   sent to back. (top is at index 0).
     * @property pipTaskId the task id of PiP task entered while in Desktop Mode.
     * @property pipShouldKeepDesktopActive whether an active PiP window should keep the desk
     *   active. Only false when we are explicitly exiting Desktop Mode (via user action) while
     *   there is an active PiP window.
     */
    private data class Desk(
        val deskId: Int,
@@ -86,8 +82,6 @@ class DesktopRepository(
        var fullImmersiveTaskId: Int? = null,
        var topTransparentFullscreenTaskId: Int? = null,
        var pipTaskId: Int? = null,
        // TODO: b/389960283 - consolidate this with [DesktopDisplay#activeDeskId].
        var pipShouldKeepDesktopActive: Boolean = true,
    ) {
        fun deepCopy(): Desk =
            Desk(
@@ -101,7 +95,6 @@ class DesktopRepository(
                fullImmersiveTaskId = fullImmersiveTaskId,
                topTransparentFullscreenTaskId = topTransparentFullscreenTaskId,
                pipTaskId = pipTaskId,
                pipShouldKeepDesktopActive = pipShouldKeepDesktopActive,
            )

        // TODO: b/362720497 - remove when multi-desktops is enabled where instances aren't
@@ -115,7 +108,6 @@ class DesktopRepository(
            fullImmersiveTaskId = null
            topTransparentFullscreenTaskId = null
            pipTaskId = null
            pipShouldKeepDesktopActive = true
        }
    }

@@ -625,7 +617,6 @@ class DesktopRepository(
                ?: error("Expected active desk in display: $displayId")
        if (enterPip) {
            activeDesk.pipTaskId = taskId
            activeDesk.pipShouldKeepDesktopActive = true
        } else {
            activeDesk.pipTaskId =
                if (activeDesk.pipTaskId == taskId) null
@@ -638,18 +629,8 @@ class DesktopRepository(
                    activeDesk.pipTaskId
                }
        }
        notifyVisibleTaskListeners(displayId, getVisibleTaskCount(displayId))
    }

    /**
     * Returns whether there is a PiP that was entered/minimized from Desktop in this display's
     * active desk.
     *
     * TODO: b/389960283 - add explicit [deskId] argument.
     */
    fun isMinimizedPipPresentInDisplay(displayId: Int): Boolean =
        desktopData.getActiveDesk(displayId)?.pipTaskId != null

    /**
     * Returns whether the given task is the Desktop-entered PiP task in this display's active desk.
     *
@@ -658,25 +639,6 @@ class DesktopRepository(
    fun isTaskMinimizedPipInDisplay(displayId: Int, taskId: Int): Boolean =
        desktopData.getActiveDesk(displayId)?.pipTaskId == taskId

    /**
     * Returns whether a desk should be active in this display due to active PiP.
     *
     * TODO: b/389960283 - add explicit [deskId] argument.
     */
    fun shouldDesktopBeActiveForPip(displayId: Int): Boolean =
        Flags.enableDesktopWindowingPip() &&
            isMinimizedPipPresentInDisplay(displayId) &&
            (desktopData.getActiveDesk(displayId)?.pipShouldKeepDesktopActive ?: false)

    /**
     * Saves whether a PiP window should keep Desktop session active in this display.
     *
     * TODO: b/389960283 - add explicit [deskId] argument.
     */
    fun setPipShouldKeepDesktopActive(displayId: Int, keepActive: Boolean) {
        desktopData.getActiveDesk(displayId)?.pipShouldKeepDesktopActive = keepActive
    }

    /**
     * Saves callback to handle a pending PiP transition being aborted.
     *
@@ -772,12 +734,8 @@ class DesktopRepository(
    }

    private fun notifyVisibleTaskListeners(displayId: Int, visibleTasksCount: Int) {
        val visibleAndPipTasksCount =
            if (shouldDesktopBeActiveForPip(displayId)) visibleTasksCount + 1 else visibleTasksCount
        visibleTasksListeners.forEach { (listener, executor) ->
            executor.execute {
                listener.onTasksVisibilityChanged(displayId, visibleAndPipTasksCount)
            }
            executor.execute { listener.onTasksVisibilityChanged(displayId, visibleTasksCount) }
        }
    }

+8 −40
Original line number Diff line number Diff line
@@ -343,45 +343,28 @@ class DesktopTasksController(
    fun isAnyDeskActive(displayId: Int): Boolean = taskRepository.isAnyDeskActive(displayId)

    /**
     * Returns true if any of the following is true:
     * - Any freeform tasks are visible
     * - A transparent fullscreen task exists on top in Desktop Mode
     * - PiP on Desktop Windowing is enabled, there is an active PiP window and the desktop
     *   wallpaper is visible.
     * Returns true if any freeform tasks are visible or if a transparent fullscreen task exists on
     * top in Desktop Mode.
     *
     * TODO: b/362720497 - consolidate with [isAnyDeskActive].
     *     - top-transparent-fullscreen case: should not be needed if we allow it to launch inside
     *       the desk in fullscreen instead of force-exiting desktop and having to trick this method
     *       into thinking it is in desktop mode when a task in this state exists.
     *     - PIP case: a PIP presence should influence desk activation, so
     *       [DesktopRepository#isAnyDeskActive] should be sufficient.
     */
    fun isDesktopModeShowing(displayId: Int): Boolean {
        val hasVisibleTasks = taskRepository.isAnyDeskActive(displayId)
        val hasTopTransparentFullscreenTask =
            taskRepository.getTopTransparentFullscreenTaskId(displayId) != null
        val hasMinimizedPip =
            Flags.enableDesktopWindowingPip() &&
                taskRepository.isMinimizedPipPresentInDisplay(displayId) &&
                desktopWallpaperActivityTokenProvider.isWallpaperActivityVisible(displayId)
        if (
            DesktopModeFlags.INCLUDE_TOP_TRANSPARENT_FULLSCREEN_TASK_IN_DESKTOP_HEURISTIC
                .isTrue() && DesktopModeFlags.ENABLE_DESKTOP_WINDOWING_MODALS_POLICY.isTrue()
        ) {
            logV(
                "isDesktopModeShowing: hasVisibleTasks=%s hasTopTransparentFullscreenTask=%s hasMinimizedPip=%s",
                "isDesktopModeShowing: hasVisibleTasks=%s hasTopTransparentFullscreenTask=%s",
                hasVisibleTasks,
                hasTopTransparentFullscreenTask,
                hasMinimizedPip,
            )
            return hasVisibleTasks || hasTopTransparentFullscreenTask || hasMinimizedPip
        } else if (Flags.enableDesktopWindowingPip()) {
            logV(
                "isDesktopModeShowing: hasVisibleTasks=%s hasMinimizedPip=%s",
                hasVisibleTasks,
                hasMinimizedPip,
            )
            return hasVisibleTasks || hasMinimizedPip
            return hasVisibleTasks || hasTopTransparentFullscreenTask
        }
        logV("isDesktopModeShowing: hasVisibleTasks=%s", hasVisibleTasks)
        return hasVisibleTasks
@@ -818,7 +801,6 @@ class DesktopTasksController(
                displayId = displayId,
                forceExitDesktop = false,
            )
        taskRepository.setPipShouldKeepDesktopActive(displayId, keepActive = true)
        val desktopExitRunnable =
            performDesktopExitCleanUp(
                wct = wct,
@@ -888,7 +870,6 @@ class DesktopTasksController(
        val wct = WindowContainerTransaction()

        snapEventHandler.removeTaskIfTiled(displayId, taskId)
        taskRepository.setPipShouldKeepDesktopActive(displayId, keepActive = true)
        val willExitDesktop = willExitDesktop(taskId, displayId, forceExitDesktop = false)
        val desktopExitRunnable =
            performDesktopExitCleanUp(
@@ -1003,11 +984,9 @@ class DesktopTasksController(
        // handles case where we are moving to full screen without closing all DW tasks.
        if (
            !taskRepository.isOnlyVisibleNonClosingTask(task.taskId)
            // This callback is already invoked by |addMoveToFullscreenChanges| when one of these
            // flags is enabled.
            &&
                !DesktopExperienceFlags.ENABLE_MULTIPLE_DESKTOPS_BACKEND.isTrue &&
                !Flags.enableDesktopWindowingPip()
            // This callback is already invoked by |addMoveToFullscreenChanges| when this flag is
            // enabled.
            && !DesktopExperienceFlags.ENABLE_MULTIPLE_DESKTOPS_BACKEND.isTrue
        ) {
            desktopModeEnterExitTransitionListener?.onExitDesktopModeTransitionStarted(
                FULLSCREEN_ANIMATION_DURATION
@@ -1911,11 +1890,7 @@ class DesktopTasksController(
        displayId: Int,
        forceExitDesktop: Boolean,
    ): Boolean {
        if (
            forceExitDesktop &&
                (Flags.enableDesktopWindowingPip() ||
                    DesktopExperienceFlags.ENABLE_MULTIPLE_DESKTOPS_BACKEND.isTrue)
        ) {
        if (forceExitDesktop && DesktopExperienceFlags.ENABLE_MULTIPLE_DESKTOPS_BACKEND.isTrue) {
            // |forceExitDesktop| is true when the callers knows we'll exit desktop, such as when
            // explicitly going fullscreen, so there's no point in checking the desktop state.
            return true
@@ -1924,11 +1899,6 @@ class DesktopTasksController(
            if (!taskRepository.isOnlyVisibleNonClosingTask(triggerTaskId, displayId)) {
                return false
            }
        } else if (
            Flags.enableDesktopWindowingPip() &&
                taskRepository.isMinimizedPipPresentInDisplay(displayId)
        ) {
            return false
        } else {
            if (!taskRepository.isOnlyVisibleNonClosingTask(triggerTaskId)) {
                return false
@@ -1945,7 +1915,6 @@ class DesktopTasksController(
        forceToFullscreen: Boolean,
        shouldEndUpAtHome: Boolean = true,
    ): RunOnTransitStart? {
        taskRepository.setPipShouldKeepDesktopActive(displayId, keepActive = !forceToFullscreen)
        if (!willExitDesktop(taskId, displayId, forceToFullscreen)) {
            return null
        }
@@ -2697,7 +2666,6 @@ class DesktopTasksController(
        if (DesktopExperienceFlags.ENABLE_MULTIPLE_DESKTOPS_BACKEND.isTrue) {
            wct.reparent(taskInfo.token, tdaInfo.token, /* onTop= */ true)
        }
        taskRepository.setPipShouldKeepDesktopActive(taskInfo.displayId, keepActive = false)
        val deskId = taskRepository.getDeskIdForTask(taskInfo.taskId)
        return performDesktopExitCleanUp(
            wct = wct,
+0 −15
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@ import android.view.WindowManager.TRANSIT_CLOSE
import android.view.WindowManager.TRANSIT_OPEN
import android.view.WindowManager.TRANSIT_PIP
import android.view.WindowManager.TRANSIT_TO_BACK
import android.view.WindowManager.TRANSIT_TO_FRONT
import android.window.DesktopExperienceFlags
import android.window.DesktopModeFlags
import android.window.DesktopModeFlags.ENABLE_DESKTOP_WALLPAPER_ACTIVITY_FOR_SYSTEM_USER
@@ -332,10 +331,6 @@ class DesktopTasksTransitionObserver(
                                taskInfo.token,
                                taskInfo.displayId,
                            )
                            desktopWallpaperActivityTokenProvider.setWallpaperActivityIsVisible(
                                isVisible = true,
                                taskInfo.displayId,
                            )
                            // After the task for the wallpaper is created, set it non-trimmable.
                            // This is important to prevent recents from trimming and removing the
                            // task.
@@ -346,16 +341,6 @@ class DesktopTasksTransitionObserver(
                        }
                        TRANSIT_CLOSE ->
                            desktopWallpaperActivityTokenProvider.removeToken(taskInfo.displayId)
                        TRANSIT_TO_FRONT ->
                            desktopWallpaperActivityTokenProvider.setWallpaperActivityIsVisible(
                                isVisible = true,
                                taskInfo.displayId,
                            )
                        TRANSIT_TO_BACK ->
                            desktopWallpaperActivityTokenProvider.setWallpaperActivityIsVisible(
                                isVisible = false,
                                taskInfo.displayId,
                            )
                        else -> {}
                    }
                }
Loading