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

Commit c2e9b682 authored by Merissa Mitchell's avatar Merissa Mitchell
Browse files

[PiP on Desktop] Fix drag-to-desktop freezing when PiP is active

Recall: http://recall/clips/7ab57d60-a1b9-40ee-a2f7-1f632e22c486

Drag-to-desktop gesture starts two transitions, and when PiP is active,
a RESIZE_PIP transition is started when the drag gesture starts due to
KCA updates. The Pip transition comes in between the two desktop
transitions and blocks the second one from merging, causing the
transitions to not be finished.

This CL blocks a RESIZE_PIP transition from starting if there is ongoing
drag-to-desktop gesture. Further work will be done in a future CL to
trigger KCA updates once we are in the Desktop session.

Bug: 397765735
Test: atest PipDesktopStateTest PipTransitionStateTest
Flag: com.android.window.flags.enable_desktop_windowing_pip

Change-Id: I7a41cd0298e7e0cf1b58c9b8b2495b88c9f7ed6a
parent 3ea5169d
Loading
Loading
Loading
Loading
+16 −1
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.window.DisplayAreaInfo;
import com.android.window.flags.Flags;
import com.android.wm.shell.RootTaskDisplayAreaOrganizer;
import com.android.wm.shell.desktopmode.DesktopUserRepositories;
import com.android.wm.shell.desktopmode.DragToDesktopTransitionHandler;

import java.util.Optional;

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

    public PipDesktopState(PipDisplayLayoutState pipDisplayLayoutState,
            Optional<DesktopUserRepositories> desktopUserRepositoriesOptional,
            Optional<DragToDesktopTransitionHandler> dragToDesktopTransitionHandlerOptional,
            RootTaskDisplayAreaOrganizer rootTaskDisplayAreaOrganizer) {
        mPipDisplayLayoutState = pipDisplayLayoutState;
        mDesktopUserRepositoriesOptional = desktopUserRepositoriesOptional;
        mDragToDesktopTransitionHandlerOptional = dragToDesktopTransitionHandlerOptional;
        mRootTaskDisplayAreaOrganizer = rootTaskDisplayAreaOrganizer;
    }

@@ -46,9 +50,11 @@ public class PipDesktopState {
     * Returns whether PiP in Desktop Windowing is enabled by checking the following:
     * - Desktop Windowing in PiP flag is enabled
     * - DesktopUserRepositories is injected
     * - DragToDesktopTransitionHandler is injected
     */
    public boolean isDesktopWindowingPipEnabled() {
        return Flags.enableDesktopWindowingPip() && mDesktopUserRepositoriesOptional.isPresent();
        return Flags.enableDesktopWindowingPip() && mDesktopUserRepositoriesOptional.isPresent()
                && mDragToDesktopTransitionHandlerOptional.isPresent();
    }

    /** Returns whether PiP in Connected Displays is enabled by checking the flag. */
@@ -99,4 +105,13 @@ public class PipDesktopState {
        // By default, or if the task is going to fullscreen, reset the windowing mode to undefined.
        return WINDOWING_MODE_UNDEFINED;
    }

    /** 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;
        }
        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 −3
Original line number Diff line number Diff line
@@ -42,6 +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.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;
@@ -58,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;

@@ -208,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
@@ -237,9 +240,13 @@ public abstract class Pip2Module {
    static PipDesktopState providePipDesktopState(
            PipDisplayLayoutState pipDisplayLayoutState,
            Optional<DesktopUserRepositories> desktopUserRepositoriesOptional,
            Optional<DragToDesktopTransitionHandler> dragToDesktopTransitionHandlerOptional,
            RootTaskDisplayAreaOrganizer rootTaskDisplayAreaOrganizer
    ) {
        return new PipDesktopState(pipDisplayLayoutState, desktopUserRepositoriesOptional,
                rootTaskDisplayAreaOrganizer);
                dragToDesktopTransitionHandlerOptional, rootTaskDisplayAreaOrganizer);
    }

    @BindsOptionalOf
    abstract DragToDesktopTransitionHandler optionalDragToDesktopTransitionHandler();
}
+14 −5
Original line number Diff line number Diff line
@@ -26,9 +26,11 @@ import android.window.WindowContainerToken;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;

import com.android.internal.protolog.ProtoLog;
import com.android.internal.util.Preconditions;
import com.android.wm.shell.common.pip.PipDesktopState;
import com.android.wm.shell.protolog.ShellProtoLogGroup;
import com.android.wm.shell.shared.annotations.ShellMainThread;

@@ -123,6 +125,8 @@ public class PipTransitionState {
    @ShellMainThread
    private final Handler mMainHandler;

    private final PipDesktopState mPipDesktopState;

    //
    // Swipe up to enter PiP related state
    //
@@ -172,8 +176,9 @@ public class PipTransitionState {

    private final List<PipTransitionStateChangedListener> mCallbacks = new ArrayList<>();

    public PipTransitionState(@ShellMainThread Handler handler) {
    public PipTransitionState(@ShellMainThread Handler handler, PipDesktopState pipDesktopState) {
        mMainHandler = handler;
        mPipDesktopState = pipDesktopState;
    }

    /**
@@ -384,12 +389,16 @@ public class PipTransitionState {
        return ++mPrevCustomState;
    }

    private boolean shouldTransitionToState(@TransitionState int newState) {
    @VisibleForTesting
    boolean shouldTransitionToState(@TransitionState int newState) {
        switch (newState) {
            case SCHEDULED_BOUNDS_CHANGE:
                // Allow scheduling bounds change only while in PiP, except for if another bounds
                // change was scheduled but hasn't started playing yet.
                return isInPip();
                // Allow scheduling bounds change only when both of these are true:
                // - while in PiP, except for if another bounds change was scheduled but hasn't
                //   started playing yet
                // - there is no drag-to-desktop gesture in progress; otherwise the PiP resize
                //   transition will block the drag-to-desktop transitions from finishing
                return isInPip() && !mPipDesktopState.isDragToDesktopInProgress();
            default:
                return true;
        }
Loading