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

Commit 01435d6d authored by Ikram Gabiyev's avatar Ikram Gabiyev Committed by Android (Google) Code Review
Browse files

Merge changes I2a54711c,I3efdbf94 into main

* changes:
  Trigger PiP movement on KCA changes
  Update PipBoundsState when KCA height is set
parents 471b424a fceeaddf
Loading
Loading
Loading
Loading
+21 −1
Original line number Diff line number Diff line
@@ -332,6 +332,23 @@ public class PipController implements ConfigurationChangeListener,
        mPipRecentsAnimationListener.onPipAnimationStarted();
    }

    private void setLauncherKeepClearAreaHeight(boolean visible, int height) {
        ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
                "setLauncherKeepClearAreaHeight: visible=%b, height=%d", visible, height);
        if (visible) {
            Rect rect = new Rect(
                    0, mPipDisplayLayoutState.getDisplayBounds().bottom - height,
                    mPipDisplayLayoutState.getDisplayBounds().right,
                    mPipDisplayLayoutState.getDisplayBounds().bottom);
            mPipBoundsState.setNamedUnrestrictedKeepClearArea(
                    PipBoundsState.NAMED_KCA_LAUNCHER_SHELF, rect);
        } else {
            mPipBoundsState.setNamedUnrestrictedKeepClearArea(
                    PipBoundsState.NAMED_KCA_LAUNCHER_SHELF, null);
        }
        mPipTouchHandler.onShelfVisibilityChanged(visible, height);
    }

    @Override
    public void onPipTransitionStateChanged(@PipTransitionState.TransitionState int oldState,
            @PipTransitionState.TransitionState int newState, @Nullable Bundle extra) {
@@ -507,7 +524,10 @@ public class PipController implements ConfigurationChangeListener,
        public void setShelfHeight(boolean visible, int height) {}

        @Override
        public void setLauncherKeepClearAreaHeight(boolean visible, int height) {}
        public void setLauncherKeepClearAreaHeight(boolean visible, int height) {
            executeRemoteCallWithTaskPermission(mController, "setLauncherKeepClearAreaHeight",
                    (controller) -> controller.setLauncherKeepClearAreaHeight(visible, height));
        }

        @Override
        public void setLauncherAppIconSize(int iconSizePx) {}
+43 −1
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import android.graphics.Point;
import android.graphics.PointF;
import android.graphics.Rect;
import android.os.Bundle;
import android.os.SystemProperties;
import android.provider.DeviceConfig;
import android.util.Size;
import android.view.DisplayCutout;
@@ -78,6 +79,8 @@ public class PipTouchHandler implements PipTransitionState.PipTransitionStateCha

    private static final String TAG = "PipTouchHandler";
    private static final float DEFAULT_STASH_VELOCITY_THRESHOLD = 18000.f;
    private static final long PIP_KEEP_CLEAR_AREAS_DELAY =
            SystemProperties.getLong("persist.wm.debug.pip_keep_clear_areas_delay", 200);

    // Allow PIP to resize to a slightly bigger state upon touch
    private boolean mEnableResize;
@@ -134,6 +137,10 @@ public class PipTouchHandler implements PipTransitionState.PipTransitionStateCha
    // Temp vars
    private final Rect mTmpBounds = new Rect();

    // Callbacks
    private final Runnable mMoveOnShelVisibilityChanged;


    /**
     * A listener for the PIP menu activity.
     */
@@ -217,6 +224,26 @@ public class PipTouchHandler implements PipTransitionState.PipTransitionStateCha
                mPipPerfHintController);
        mPipBoundsState.addOnAspectRatioChangedCallback(this::updateMinMaxSize);

        mMoveOnShelVisibilityChanged = () -> {
            if (mIsImeShowing && mImeHeight > mShelfHeight) {
                // Early bail-out if IME is visible with a larger height present;
                // this should block unnecessary PiP movement since we delay checking for
                // KCA triggered movement to wait for other transitions (e.g. due to IME changes).
                return;
            }
            mPipTransitionState.setOnIdlePipTransitionStateRunnable(() -> {
                boolean hasUserInteracted = (mPipBoundsState.hasUserMovedPip()
                        || mPipBoundsState.hasUserResizedPip());
                int delta = mPipBoundsAlgorithm.getEntryDestinationBounds().top
                        - mPipBoundsState.getBounds().top;

                if (!mIsImeShowing && !hasUserInteracted && delta != 0) {
                    // If the user hasn't interacted with PiP, we respect the keep clear areas
                    mMotionHelper.animateToOffset(mPipBoundsState.getBounds(), delta);
                }
            });
        };

        if (PipUtils.isPip2ExperimentEnabled()) {
            shellInit.addInitCallback(this::onInit, this);
        }
@@ -356,9 +383,14 @@ public class PipTouchHandler implements PipTransitionState.PipTransitionStateCha
        mPipTransitionState.setOnIdlePipTransitionStateRunnable(() -> {
            int delta = mPipBoundsState.getMovementBounds().bottom
                    - mPipBoundsState.getBounds().top;

            boolean hasUserInteracted = (mPipBoundsState.hasUserMovedPip()
                    || mPipBoundsState.hasUserResizedPip());

            if (!imeVisible && !hasUserInteracted) {
                delta = mPipBoundsAlgorithm.getEntryDestinationBounds().top
                        - mPipBoundsState.getBounds().top;
            }

            if ((imeVisible && delta < 0) || (!imeVisible && !hasUserInteracted)) {
                // The policy is to ignore an IME disappearing if user has interacted with PiP.
                // Otherwise, only offset due to an appearing IME if PiP occludes it.
@@ -370,6 +402,16 @@ public class PipTouchHandler implements PipTransitionState.PipTransitionStateCha
    void onShelfVisibilityChanged(boolean shelfVisible, int shelfHeight) {
        mIsShelfShowing = shelfVisible;
        mShelfHeight = shelfHeight;

        // We need to remove the callback even if the shelf is visible, in case it the delayed
        // callback hasn't been executed yet to avoid the wrong final state.
        mMainExecutor.removeCallbacks(mMoveOnShelVisibilityChanged);
        if (shelfVisible) {
            mMoveOnShelVisibilityChanged.run();
        } else {
            // Postpone moving in response to hide of Launcher in case there's another change
            mMainExecutor.executeDelayed(mMoveOnShelVisibilityChanged, PIP_KEEP_CLEAR_AREAS_DELAY);
        }
    }

    /**