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

Commit 14ad6b49 authored by Merissa Mitchell's avatar Merissa Mitchell
Browse files

[PiP on CD] Fix PiP dismiss target on external display.

This CL implements getting the correct WindowManager for the associated
display where PiP is active so that the PiP dismiss target shows up in
the correct display.

Bug: 391699824
Test: Manually check that the dismiss target shows up on the correct
display when dragging PiP on the external display
Flag: com.android.window.flags.enable_connected_displays_pip

Change-Id: I08615d90e3f6cf21697f6cbd66effba94377ca3e
parent d6958dde
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -180,6 +180,7 @@ public abstract class Pip2Module {
            @NonNull PipScheduler pipScheduler,
            @NonNull SizeSpecSource sizeSpecSource,
            @NonNull PipDisplayLayoutState pipDisplayLayoutState,
            DisplayController displayController,
            PipMotionHelper pipMotionHelper,
            FloatingContentCoordinator floatingContentCoordinator,
            PipUiEventLogger pipUiEventLogger,
@@ -187,8 +188,9 @@ public abstract class Pip2Module {
            Optional<PipPerfHintController> pipPerfHintControllerOptional) {
        return new PipTouchHandler(context, shellInit, shellCommandHandler, menuPhoneController,
                pipBoundsAlgorithm, pipBoundsState, pipTransitionState, pipScheduler,
                sizeSpecSource, pipDisplayLayoutState, pipMotionHelper, floatingContentCoordinator,
                pipUiEventLogger, mainExecutor, pipPerfHintControllerOptional);
                sizeSpecSource, pipDisplayLayoutState, displayController, pipMotionHelper,
                floatingContentCoordinator, pipUiEventLogger, mainExecutor,
                pipPerfHintControllerOptional);
    }

    @WMSingleton
+30 −4
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.content.res.Resources;
import android.graphics.PixelFormat;
import android.graphics.Point;
import android.graphics.Rect;
import android.view.Display;
import android.view.MotionEvent;
import android.view.SurfaceControl;
import android.view.View;
@@ -34,7 +35,9 @@ import androidx.annotation.NonNull;

import com.android.wm.shell.R;
import com.android.wm.shell.bubbles.DismissViewUtils;
import com.android.wm.shell.common.DisplayController;
import com.android.wm.shell.common.ShellExecutor;
import com.android.wm.shell.common.pip.PipDisplayLayoutState;
import com.android.wm.shell.common.pip.PipUiEventLogger;
import com.android.wm.shell.shared.bubbles.DismissCircleView;
import com.android.wm.shell.shared.bubbles.DismissView;
@@ -50,6 +53,9 @@ public class PipDismissTargetHandler implements ViewTreeObserver.OnPreDrawListen
    /* The multiplier to apply scale the target size by when applying the magnetic field radius */
    private static final float MAGNETIC_FIELD_RADIUS_MULTIPLIER = 1.25f;

    /* The window type to apply to the display */
    private static final int WINDOW_TYPE = WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL;

    /**
     * MagnetizedObject wrapper for PIP. This allows the magnetic target library to locate and move
     * PIP.
@@ -84,16 +90,22 @@ public class PipDismissTargetHandler implements ViewTreeObserver.OnPreDrawListen
    private final Context mContext;
    private final PipMotionHelper mMotionHelper;
    private final PipUiEventLogger mPipUiEventLogger;
    private final WindowManager mWindowManager;
    private WindowManager mWindowManager;
    /** The display id for the display that is associated with mWindowManager. */
    private int mWindowManagerDisplayId = -1;
    private final PipDisplayLayoutState mPipDisplayLayoutState;
    private final DisplayController mDisplayController;
    private final ShellExecutor mMainExecutor;

    public PipDismissTargetHandler(Context context, PipUiEventLogger pipUiEventLogger,
            PipMotionHelper motionHelper, ShellExecutor mainExecutor) {
            PipMotionHelper motionHelper, PipDisplayLayoutState pipDisplayLayoutState,
            DisplayController displayController, ShellExecutor mainExecutor) {
        mContext = context;
        mPipUiEventLogger = pipUiEventLogger;
        mMotionHelper = motionHelper;
        mPipDisplayLayoutState = pipDisplayLayoutState;
        mDisplayController = displayController;
        mMainExecutor = mainExecutor;
        mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
    }

    void init() {
@@ -240,6 +252,8 @@ public class PipDismissTargetHandler implements ViewTreeObserver.OnPreDrawListen

    /** Adds the magnetic target view to the WindowManager so it's ready to be animated in. */
    public void createOrUpdateDismissTarget() {
        getWindowManager();

        if (mTargetViewContainer.getParent() == null) {
            mTargetViewContainer.cancelAnimators();

@@ -262,7 +276,7 @@ public class PipDismissTargetHandler implements ViewTreeObserver.OnPreDrawListen
                WindowManager.LayoutParams.MATCH_PARENT,
                height,
                0, windowSize.y - height,
                WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL,
                WINDOW_TYPE,
                WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
                        | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
                        | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
@@ -308,4 +322,16 @@ public class PipDismissTargetHandler implements ViewTreeObserver.OnPreDrawListen
            mWindowManager.removeViewImmediate(mTargetViewContainer);
        }
    }

    /** Sets mWindowManager to WindowManager associated with the display where PiP is active on. */
    private void getWindowManager() {
        final int pipDisplayId = mPipDisplayLayoutState.getDisplayId();
        if (mWindowManager != null && pipDisplayId == mWindowManagerDisplayId) {
            return;
        }
        mWindowManagerDisplayId = pipDisplayId;
        Display display = mDisplayController.getDisplay(mWindowManagerDisplayId);
        Context uiContext = mContext.createWindowContext(display, WINDOW_TYPE, null);
        mWindowManager = uiContext.getSystemService(WindowManager.class);
    }
}
+3 −1
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@ import android.view.accessibility.AccessibilityWindowInfo;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.protolog.ProtoLog;
import com.android.wm.shell.R;
import com.android.wm.shell.common.DisplayController;
import com.android.wm.shell.common.FloatingContentCoordinator;
import com.android.wm.shell.common.ShellExecutor;
import com.android.wm.shell.common.pip.PipBoundsAlgorithm;
@@ -186,6 +187,7 @@ public class PipTouchHandler implements PipTransitionState.PipTransitionStateCha
            @NonNull PipScheduler pipScheduler,
            @NonNull SizeSpecSource sizeSpecSource,
            @NonNull PipDisplayLayoutState pipDisplayLayoutState,
            DisplayController displayController,
            PipMotionHelper pipMotionHelper,
            FloatingContentCoordinator floatingContentCoordinator,
            PipUiEventLogger pipUiEventLogger,
@@ -212,7 +214,7 @@ public class PipTouchHandler implements PipTransitionState.PipTransitionStateCha
        mMotionHelper = pipMotionHelper;
        mPipScheduler.setUpdateMovementBoundsRunnable(this::updateMovementBounds);
        mPipDismissTargetHandler = new PipDismissTargetHandler(context, pipUiEventLogger,
                mMotionHelper, mainExecutor);
                mMotionHelper, mPipDisplayLayoutState, displayController, mainExecutor);
        mTouchState = new PipTouchState(ViewConfiguration.get(context),
                () -> {
                    mMenuController.showMenuWithPossibleDelay(MENU_STATE_FULL,