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

Commit 7d332218 authored by Hongwei Wang's avatar Hongwei Wang
Browse files

Fix the blank PiP window when unlock

When the keyguard is showing or animating with the surfaces behind,
there is no need for PiP to be shown or offset-by-shelf-height.

Video: http://recall/-/aaaaaabFQoRHlzixHdtY/g6b3BQS2iH7TibwA9eqq1x
Bug: 230638352
Test: follow the reproduce step, see video
Change-Id: Ia4264a8cac2b34a2f7e9b85b35ebee7f74842aa8
parent a2f6807a
Loading
Loading
Loading
Loading
+17 −5
Original line number Diff line number Diff line
@@ -43,11 +43,6 @@ public interface Pip {
    default void expandPip() {
    }

    /**
     * Hides the PIP menu.
     */
    default void hidePipMenu(Runnable onStartCallback, Runnable onEndCallback) {}

    /**
     * Called when configuration is changed.
     */
@@ -124,6 +119,23 @@ public interface Pip {
     */
    default void removePipExclusionBoundsChangeListener(Consumer<Rect> listener) { }

    /**
     * Called when the visibility of keyguard is changed.
     * @param showing {@code true} if keyguard is now showing, {@code false} otherwise.
     * @param animating {@code true} if system is animating between keyguard and surface behind,
     *                              this only makes sense when showing is {@code false}.
     */
    default void onKeyguardVisibilityChanged(boolean showing, boolean animating) { }

    /**
     * Called when the dismissing animation keyguard and surfaces behind is finished.
     * See also {@link #onKeyguardVisibilityChanged(boolean, boolean)}.
     *
     * TODO(b/206741900) deprecate this path once we're able to animate the PiP window as part of
     * keyguard dismiss animation.
     */
    default void onKeyguardDismissAnimationFinished() { }

    /**
     * Dump the current state and information if need.
     *
+11 −0
Original line number Diff line number Diff line
@@ -965,6 +965,17 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener,
        mDeferredAnimEndTransaction = null;
    }

    /** Explicitly set the visibility of PiP window. */
    public void setPipVisibility(boolean visible) {
        if (!isInPip()) {
            return;
        }
        final SurfaceControl.Transaction tx =
                mSurfaceControlTransactionFactory.getTransaction();
        mSurfaceTransactionHelper.alpha(tx, mLeash, visible ? 1f : 0f);
        tx.apply();
    }

    @Override
    public void onDisplayConfigurationChanged(int displayId, Configuration newConfig) {
        mCurrentRotation = newConfig.windowConfiguration.getRotation();
+44 −8
Original line number Diff line number Diff line
@@ -129,6 +129,8 @@ public class PipController implements PipTransitionController.PipTransitionCallb
    protected PinnedStackListenerForwarder.PinnedTaskListener mPinnedTaskListener =
            new PipControllerPinnedTaskListener();

    private boolean mIsKeyguardShowingOrAnimating;

    private interface PipAnimationListener {
        /**
         * Notifies the listener that the Pip animation is started.
@@ -592,6 +594,33 @@ public class PipController implements PipTransitionController.PipTransitionCallb
        mTouchHandler.showPictureInPictureMenu();
    }

    /**
     * If {@param keyguardShowing} is {@code false} and {@param animating} is {@code true},
     * we would wait till the dismissing animation of keyguard and surfaces behind to be
     * finished first to reset the visibility of PiP window.
     * See also {@link #onKeyguardDismissAnimationFinished()}
     */
    private void onKeyguardVisibilityChanged(boolean keyguardShowing, boolean animating) {
        if (!mPipTaskOrganizer.isInPip()) {
            return;
        }
        if (keyguardShowing) {
            mIsKeyguardShowingOrAnimating = true;
            hidePipMenu(null /* onStartCallback */, null /* onEndCallback */);
            mPipTaskOrganizer.setPipVisibility(false);
        } else if (!animating) {
            mIsKeyguardShowingOrAnimating = false;
            mPipTaskOrganizer.setPipVisibility(true);
        }
    }

    private void onKeyguardDismissAnimationFinished() {
        if (mPipTaskOrganizer.isInPip()) {
            mIsKeyguardShowingOrAnimating = false;
            mPipTaskOrganizer.setPipVisibility(true);
        }
    }

    /**
     * Sets a customized touch gesture that replaces the default one.
     */
@@ -603,8 +632,10 @@ public class PipController implements PipTransitionController.PipTransitionCallb
     * Sets both shelf visibility and its height.
     */
    private void setShelfHeight(boolean visible, int height) {
        if (!mIsKeyguardShowingOrAnimating) {
            setShelfHeightLocked(visible, height);
        }
    }

    private void setShelfHeightLocked(boolean visible, int height) {
        final int shelfHeight = visible ? height : 0;
@@ -833,13 +864,6 @@ public class PipController implements PipTransitionController.PipTransitionCallb
            return mIPip;
        }

        @Override
        public void hidePipMenu(Runnable onStartCallback, Runnable onEndCallback) {
            mMainExecutor.execute(() -> {
                PipController.this.hidePipMenu(onStartCallback, onEndCallback);
            });
        }

        @Override
        public void expandPip() {
            mMainExecutor.execute(() -> {
@@ -917,6 +941,18 @@ public class PipController implements PipTransitionController.PipTransitionCallb
            });
        }

        @Override
        public void onKeyguardVisibilityChanged(boolean showing, boolean animating) {
            mMainExecutor.execute(() -> {
                PipController.this.onKeyguardVisibilityChanged(showing, animating);
            });
        }

        @Override
        public void onKeyguardDismissAnimationFinished() {
            mMainExecutor.execute(PipController.this::onKeyguardDismissAnimationFinished);
        }

        @Override
        public void dump(PrintWriter pw) {
            try {
+24 −0
Original line number Diff line number Diff line
@@ -188,6 +188,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
    private static final int MSG_KEYGUARD_GOING_AWAY = 342;
    private static final int MSG_TIME_FORMAT_UPDATE = 344;
    private static final int MSG_REQUIRE_NFC_UNLOCK = 345;
    private static final int MSG_KEYGUARD_DISMISS_ANIMATION_FINISHED = 346;

    /** Biometric authentication state: Not listening. */
    private static final int BIOMETRIC_STATE_STOPPED = 0;
@@ -2005,6 +2006,9 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
                    case MSG_REQUIRE_NFC_UNLOCK:
                        handleRequireUnlockForNfc();
                        break;
                    case MSG_KEYGUARD_DISMISS_ANIMATION_FINISHED:
                        handleKeyguardDismissAnimationFinished();
                        break;
                    default:
                        super.handleMessage(msg);
                        break;
@@ -3276,6 +3280,19 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
        }
    }

    /**
     * Handle {@link #MSG_KEYGUARD_DISMISS_ANIMATION_FINISHED}
     */
    private void handleKeyguardDismissAnimationFinished() {
        Assert.isMainThread();
        for (int i = 0; i < mCallbacks.size(); i++) {
            KeyguardUpdateMonitorCallback cb = mCallbacks.get(i).get();
            if (cb != null) {
                cb.onKeyguardDismissAnimationFinished();
            }
        }
    }

    /**
     * Handle {@link #MSG_REPORT_EMERGENCY_CALL_ACTION}
     */
@@ -3614,6 +3631,13 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
        mHandler.sendMessage(mHandler.obtainMessage(MSG_KEYGUARD_GOING_AWAY, goingAway));
    }

    /**
     * Sends a message to notify the keyguard dismiss animation is finished.
     */
    public void dispatchKeyguardDismissAnimationFinished() {
        mHandler.sendEmptyMessage(MSG_KEYGUARD_DISMISS_ANIMATION_FINISHED);
    }

    public boolean isDeviceInteractive() {
        return mDeviceInteractive;
    }
+8 −0
Original line number Diff line number Diff line
@@ -108,6 +108,14 @@ public class KeyguardUpdateMonitorCallback {
     */
    public void onKeyguardBouncerFullyShowingChanged(boolean bouncerIsFullyShowing) { }

    /**
     * Called when the dismissing animation of keyguard and surfaces behind is finished.
     * If the surface behind is the Launcher, we may still be playing in-window animations
     * when this is called (since it's only called once we dismiss the keyguard and end the
     * remote animation).
     */
    public void onKeyguardDismissAnimationFinished() { }

    /**
     * Called when visibility of lockscreen clock changes, such as when
     * obscured by a widget.
Loading