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

Commit 12199ddb authored by Mateusz Cicheński's avatar Mateusz Cicheński
Browse files

Delay PiP movement in response to keep clear areas changed.

This prevents erratic movements caused by animations that update layout each
frame, effectively reporting new keep clear area bounds every frame and
triggerring the movement multiple times. This will now wait for the keep
clear areas to stabilize before moving away.

Can be customized via system property.

Video before: http://recall/-/g8x7ZkgdfbqscttAA9wzl9/hwr0OrO4Pq8cvLw9bgwLff
Video after: http://recall/-/g8x7ZkgdfbqscttAA9wzl9/bGTKo0oqCKUwtvBdBYOB9w

Bug: 183746978
Test: manually, e.g. open PiP and slowly swipe up to go to overview, which
causes Hotseat to animate away triggering keep clear areas changed multiple
times, but the PiP moves only once

Change-Id: I2214e2250fb3cace8fee117285fd8ffbd27a3870
parent e9b5e1d6
Loading
Loading
Loading
Loading
+20 −8
Original line number Diff line number Diff line
@@ -112,6 +112,9 @@ public class PipController implements PipTransitionController.PipTransitionCallb
        UserChangeListener {
    private static final String TAG = "PipController";

    private static final long PIP_KEEP_CLEAR_AREAS_DELAY =
            SystemProperties.getLong("persist.wm.debug.pip_keep_clear_areas_delay", 200);

    private boolean mEnablePipKeepClearAlgorithm =
            SystemProperties.getBoolean("persist.wm.debug.enable_pip_keep_clear_algorithm", false);

@@ -143,6 +146,8 @@ public class PipController implements PipTransitionController.PipTransitionCallb
    private final Rect mTmpInsetBounds = new Rect();
    private final int mEnterAnimationDuration;

    private final Runnable mMovePipInResponseToKeepClearAreasChangeCallback;

    private boolean mIsInFixedRotation;
    private PipAnimationListener mPinnedStackAnimationRecentsCallback;

@@ -274,14 +279,12 @@ public class PipController implements PipTransitionController.PipTransitionCallb
                    if (mPipBoundsState.getDisplayId() == displayId) {
                        if (mEnablePipKeepClearAlgorithm) {
                            mPipBoundsState.setKeepClearAreas(restricted, unrestricted);
                            // only move if already in pip, other transitions account for keep clear
                            // areas
                            if (mPipTransitionState.hasEnteredPip()) {
                                Rect destBounds = mPipKeepClearAlgorithm.adjust(mPipBoundsState,
                                        mPipBoundsAlgorithm);
                                mPipTaskOrganizer.scheduleAnimateResizePip(destBounds,
                                        mEnterAnimationDuration, null);
                            }

                            mMainExecutor.removeCallbacks(
                                    mMovePipInResponseToKeepClearAreasChangeCallback);
                            mMainExecutor.executeDelayed(
                                    mMovePipInResponseToKeepClearAreasChangeCallback,
                                    PIP_KEEP_CLEAR_AREAS_DELAY);
                        }
                    }
                }
@@ -406,6 +409,15 @@ public class PipController implements PipTransitionController.PipTransitionCallb

        mEnterAnimationDuration = mContext.getResources()
                .getInteger(R.integer.config_pipEnterAnimationDuration);
        mMovePipInResponseToKeepClearAreasChangeCallback = () -> {
            // only move if already in pip, other transitions account for keep clear areas
            if (mPipTransitionState.hasEnteredPip()) {
                Rect destBounds = mPipKeepClearAlgorithm.adjust(mPipBoundsState,
                        mPipBoundsAlgorithm);
                mPipTaskOrganizer.scheduleAnimateResizePip(destBounds,
                        mEnterAnimationDuration, null);
            }
        };
        mPipParamsChangedForwarder = pipParamsChangedForwarder;

        shellInit.addInitCallback(this::onInit, this);