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

Commit 5bc9431f authored by Merissa Mitchell's avatar Merissa Mitchell Committed by Android (Google) Code Review
Browse files

Merge changes I7a41cd02,Idd6ab198 into main

* changes:
  [PiP on Desktop] Fix drag-to-desktop freezing when PiP is active
  Revert "[PiP2 on Desktop] Don't exit Desktop Mode when PiP is active."
parents adbc43c2 c2e9b682
Loading
Loading
Loading
Loading
+15 −58
Original line number Diff line number Diff line
@@ -19,18 +19,13 @@ 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 com.android.wm.shell.desktopmode.DragToDesktopTransitionHandler;

import java.util.Optional;

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

    public PipDesktopState(PipDisplayLayoutState pipDisplayLayoutState,
            Optional<DesktopUserRepositories> desktopUserRepositoriesOptional,
            Optional<DesktopWallpaperActivityTokenProvider>
                    desktopWallpaperActivityTokenProviderOptional,
            Optional<DragToDesktopTransitionHandler> dragToDesktopTransitionHandlerOptional,
            RootTaskDisplayAreaOrganizer rootTaskDisplayAreaOrganizer) {
        mPipDisplayLayoutState = pipDisplayLayoutState;
        mDesktopUserRepositoriesOptional = desktopUserRepositoriesOptional;
        mDesktopWallpaperActivityTokenProviderOptional =
                desktopWallpaperActivityTokenProviderOptional;
        mDragToDesktopTransitionHandlerOptional = dragToDesktopTransitionHandlerOptional;
        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
     * - DragToDesktopTransitionHandler is injected
     */
    public boolean isDesktopWindowingPipEnabled() {
        return Flags.enableDesktopWindowingPip()
                && mDesktopWallpaperActivityTokenProviderOptional.isPresent()
                && mDesktopUserRepositoriesOptional.isPresent();
        return Flags.enableDesktopWindowingPip() && mDesktopUserRepositoriesOptional.isPresent()
                && mDragToDesktopTransitionHandlerOptional.isPresent();
    }

    /** Returns whether PiP in Connected Displays is enabled by checking the flag. */
@@ -89,45 +80,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.
@@ -150,11 +106,12 @@ public class PipDesktopState {
        return WINDOWING_MODE_UNDEFINED;
    }

    private DesktopRepository getDesktopRepository() {
        return mDesktopUserRepositoriesOptional.get().getCurrent();
    /** Returns whether there is a drag-to-desktop transition in progress. */
    public boolean isDragToDesktopInProgress() {
        // Early return if PiP in Desktop Windowing is not supported.
        if (!isDesktopWindowingPipEnabled()) {
            return false;
        }

    private DesktopWallpaperActivityTokenProvider getDesktopWallpaperActivityTokenProvider() {
        return mDesktopWallpaperActivityTokenProviderOptional.get();
        return mDragToDesktopTransitionHandlerOptional.get().getInProgress();
    }
}
+2 −17
Original line number Diff line number Diff line
@@ -1052,23 +1052,8 @@ public abstract class WMShellBaseModule {
        });
    }

    @WMSingleton
    @Provides
    static DesktopWallpaperActivityTokenProvider provideDesktopWallpaperActivityTokenProvider() {
        return new DesktopWallpaperActivityTokenProvider();
    }

    @WMSingleton
    @Provides
    static Optional<DesktopWallpaperActivityTokenProvider>
            provideOptionalDesktopWallpaperActivityTokenProvider(
            Context context,
            DesktopWallpaperActivityTokenProvider desktopWallpaperActivityTokenProvider) {
        if (DesktopModeStatus.canEnterDesktopMode(context)) {
            return Optional.of(desktopWallpaperActivityTokenProvider);
        }
        return Optional.empty();
    }
    @BindsOptionalOf
    abstract DesktopWallpaperActivityTokenProvider optionalDesktopWallpaperActivityTokenProvider();

    //
    // App zoom out (optional feature)
+6 −0
Original line number Diff line number Diff line
@@ -936,6 +936,12 @@ public abstract class WMShellModule {
                        interactionJankMonitor, bubbleController);
    }

    @WMSingleton
    @Provides
    static DesktopWallpaperActivityTokenProvider provideDesktopWallpaperActivityTokenProvider() {
        return new DesktopWallpaperActivityTokenProvider();
    }

    @WMSingleton
    @Provides
    static DragToDisplayTransitionHandler provideDragToDisplayTransitionHandler() {
+10 −6
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@ 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.desktopmode.DragToDesktopTransitionHandler;
import com.android.wm.shell.pip2.phone.PhonePipMenuController;
import com.android.wm.shell.pip2.phone.PipController;
import com.android.wm.shell.pip2.phone.PipMotionHelper;
@@ -59,6 +59,7 @@ import com.android.wm.shell.sysui.ShellController;
import com.android.wm.shell.sysui.ShellInit;
import com.android.wm.shell.transition.Transitions;

import dagger.BindsOptionalOf;
import dagger.Module;
import dagger.Provides;

@@ -209,8 +210,9 @@ public abstract class Pip2Module {

    @WMSingleton
    @Provides
    static PipTransitionState providePipTransitionState(@ShellMainThread Handler handler) {
        return new PipTransitionState(handler);
    static PipTransitionState providePipTransitionState(@ShellMainThread Handler handler,
            PipDesktopState pipDesktopState) {
        return new PipTransitionState(handler, pipDesktopState);
    }

    @WMSingleton
@@ -238,11 +240,13 @@ public abstract class Pip2Module {
    static PipDesktopState providePipDesktopState(
            PipDisplayLayoutState pipDisplayLayoutState,
            Optional<DesktopUserRepositories> desktopUserRepositoriesOptional,
            Optional<DesktopWallpaperActivityTokenProvider>
                    desktopWallpaperActivityTokenProviderOptional,
            Optional<DragToDesktopTransitionHandler> dragToDesktopTransitionHandlerOptional,
            RootTaskDisplayAreaOrganizer rootTaskDisplayAreaOrganizer
    ) {
        return new PipDesktopState(pipDisplayLayoutState, desktopUserRepositoriesOptional,
                desktopWallpaperActivityTokenProviderOptional, rootTaskDisplayAreaOrganizer);
                dragToDesktopTransitionHandlerOptional, rootTaskDisplayAreaOrganizer);
    }

    @BindsOptionalOf
    abstract DragToDesktopTransitionHandler optionalDragToDesktopTransitionHandler();
}
+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) }
        }
    }

Loading