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

Commit 17b79c09 authored by Ben Lin's avatar Ben Lin
Browse files

PiP: Update DisplayInfo and movement bounds if display is different.

Although there are multiple places to watch out for display change in
PiP, when a task enters PiP, it's possible there has been no display
change, but simply a display addition. That being the case, it's
possible that PiP enters in a secondary display, and so we need to
update all the relevant information of the secondary display.

Bug: 133179171
Test: Enter PiP on a secondary display, default bounds is correct
Change-Id: I3eef2ef5c6b6be99105a876f7e8d43fbba39cbb2
parent e23a6745
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -120,6 +120,13 @@ public class PipBoundsHandler {
        mDisplayLayout.set(newDisplayLayout);
    }

    /**
     * Get the current saved display info.
     */
    public DisplayInfo getDisplayInfo() {
        return mDisplayInfo;
    }

    /**
     * Update the Min edge size for {@link PipSnapAlgorithm} to calculate corresponding bounds
     * @param minEdgeSize
+16 −0
Original line number Diff line number Diff line
@@ -77,6 +77,7 @@ import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.IntConsumer;

/**
 * Manages PiP tasks such as resize and offset.
@@ -246,6 +247,7 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener,
    private PipSurfaceTransactionHelper.SurfaceControlTransactionFactory
            mSurfaceControlTransactionFactory;
    private PictureInPictureParams mPictureInPictureParams;
    private IntConsumer mOnDisplayIdChangeCallback;

    /**
     * If set to {@code true}, the entering animation will be skipped and we will wait for
@@ -312,6 +314,13 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener,
        mPipTransitionCallbacks.add(callback);
    }

    /**
     * Registers a callback when a display change has been detected when we enter PiP.
     */
    public void registerOnDisplayIdChangeCallback(IntConsumer onDisplayIdChangeCallback) {
        mOnDisplayIdChangeCallback = onDisplayIdChangeCallback;
    }

    /**
     * Sets the preferred animation type for one time.
     * This is typically used to set the animation type to
@@ -469,6 +478,13 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener,
        mPipUiEventLoggerLogger.setTaskInfo(mTaskInfo);
        mPipUiEventLoggerLogger.log(PipUiEventLogger.PipUiEventEnum.PICTURE_IN_PICTURE_ENTER);

        // If the displayId of the task is different than what PipBoundsHandler has, then update
        // it. This is possible if we entered PiP on an external display.
        if (info.displayId != mPipBoundsHandler.getDisplayInfo().displayId
                && mOnDisplayIdChangeCallback != null) {
            mOnDisplayIdChangeCallback.accept(info.displayId);
        }

        if (mShouldIgnoreEnteringPipTransition) {
            // Animation has been finished together with Recents, directly apply the sync
            // transaction to PiP here.
+8 −0
Original line number Diff line number Diff line
@@ -222,6 +222,14 @@ public class PipController implements Pip, PipTaskOrganizer.PipTransitionCallbac
        mPipBoundsState = pipBoundsState;
        mPipTaskOrganizer = pipTaskOrganizer;
        mPipTaskOrganizer.registerPipTransitionCallback(this);
        mPipTaskOrganizer.registerOnDisplayIdChangeCallback((int displayId) -> {
            final DisplayInfo newDisplayInfo = new DisplayInfo();
            displayController.getDisplay(displayId).getDisplayInfo(newDisplayInfo);
            mPipBoundsHandler.onDisplayInfoChanged(newDisplayInfo);
            updateMovementBounds(null /* toBounds */, false /* fromRotation */,
                    false /* fromImeAdjustment */, false /* fromShelfAdustment */,
                    null /* wct */);
        });
        mMediaController = pipMediaController;
        mMenuController = pipMenuActivityController;
        mTouchHandler = pipTouchHandler;