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

Commit ae4b8e0f authored by Tiger Huang's avatar Tiger Huang Committed by Android (Google) Code Review
Browse files

Merge "Don't play insets animation without a leash" into main

parents 700a5bb9 9defbb6e
Loading
Loading
Loading
Loading
+37 −52
Original line number Diff line number Diff line
@@ -291,17 +291,11 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged
            if (hadImeSourceControl != hasImeSourceControl) {
                dispatchImeControlTargetChanged(mDisplayId, hasImeSourceControl);
            }
            final boolean hasImeLeash = hasImeSourceControl && imeSourceControl.getLeash() != null;

            boolean pendingImeStartAnimation = false;
            boolean canAnimate;
            if (android.view.inputmethod.Flags.refactorInsetsController()) {
                canAnimate = hasImeSourceControl && imeSourceControl.getLeash() != null;
            } else {
                canAnimate = hasImeSourceControl;
            }

            boolean positionChanged = false;
            if (canAnimate) {
            if (hasImeLeash) {
                if (mAnimation != null) {
                    final Point lastSurfacePosition = hadImeSourceControl
                            ? mImeSourceControl.getSurfacePosition() : null;
@@ -325,6 +319,13 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged
                // continue the bar to slide to the end (even without visible IME)
                mAnimation.cancel();
            }

            // Make mImeSourceControl point to the new control before starting the animation.
            if (hadImeSourceControl && mImeSourceControl != imeSourceControl) {
                mImeSourceControl.release(SurfaceControl::release);
            }
            mImeSourceControl = imeSourceControl;

            if (positionChanged) {
                if (android.view.inputmethod.Flags.refactorInsetsController()) {
                    // For showing the IME, the leash has to be available first. Hiding
@@ -338,11 +339,6 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged
                }
            }

            if (hadImeSourceControl && mImeSourceControl != imeSourceControl) {
                mImeSourceControl.release(SurfaceControl::release);
            }
            mImeSourceControl = imeSourceControl;

            if (android.view.inputmethod.Flags.refactorInsetsController()) {
                if (pendingImeStartAnimation) {
                    startAnimation(true, true /* forceRestart */);
@@ -465,11 +461,12 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged

        private void startAnimation(final boolean show, final boolean forceRestart,
                @NonNull final ImeTracker.Token statsToken) {
            if (android.view.inputmethod.Flags.refactorInsetsController()) {
            if (mImeSourceControl == null || mImeSourceControl.getLeash() == null) {
                if (DEBUG) Slog.d(TAG, "No leash available, not starting the animation.");
                return;
                } else if (!mImeRequestedVisible && show) {
            }
            if (android.view.inputmethod.Flags.refactorInsetsController()) {
                if (!mImeRequestedVisible && show) {
                    // we have a control with leash, but the IME was not requested visible before,
                    // therefore aborting the show animation.
                    Slog.e(TAG, "IME was not requested visible, not starting the show animation.");
@@ -478,7 +475,7 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged
                }
            }
            final InsetsSource imeSource = mInsetsState.peekSource(InsetsSource.ID_IME);
            if (imeSource == null || mImeSourceControl == null) {
            if (imeSource == null) {
                ImeTracker.forLogging().onFailed(statsToken, ImeTracker.PHASE_WM_ANIMATION_CREATE);
                return;
            }
@@ -515,8 +512,10 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged
                }
                mAnimation.cancel();
            }
            final float defaultY = mImeSourceControl.getSurfacePosition().y;
            final float x = mImeSourceControl.getSurfacePosition().x;
            final InsetsSourceControl animatingControl = new InsetsSourceControl(mImeSourceControl);
            final SurfaceControl animatingLeash = animatingControl.getLeash();
            final float defaultY = animatingControl.getSurfacePosition().y;
            final float x = animatingControl.getSurfacePosition().x;
            final float hiddenY = defaultY + mImeFrame.height();
            final float shownY = defaultY;
            final float startY = show ? hiddenY : shownY;
@@ -538,13 +537,10 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged
            mAnimation.addUpdateListener(animation -> {
                SurfaceControl.Transaction t = mTransactionPool.acquire();
                float value = (float) animation.getAnimatedValue();
                if (!android.view.inputmethod.Flags.refactorInsetsController() || (
                        mImeSourceControl != null && mImeSourceControl.getLeash() != null)) {
                    t.setPosition(mImeSourceControl.getLeash(), x, value);
                t.setPosition(animatingLeash, x, value);
                final float alpha = (mAnimateAlpha || isFloating)
                            ? (value - hiddenY) / (shownY - hiddenY) : 1.f;
                    t.setAlpha(mImeSourceControl.getLeash(), alpha);
                }
                        ? (value - hiddenY) / (shownY - hiddenY) : 1f;
                t.setAlpha(animatingLeash, alpha);
                dispatchPositionChanged(mDisplayId, imeTop(value), t);
                t.apply();
                mTransactionPool.release(t);
@@ -561,7 +557,7 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged
                    ValueAnimator valueAnimator = (ValueAnimator) animation;
                    float value = (float) valueAnimator.getAnimatedValue();
                    SurfaceControl.Transaction t = mTransactionPool.acquire();
                    t.setPosition(mImeSourceControl.getLeash(), x, value);
                    t.setPosition(animatingLeash, x, value);
                    if (DEBUG) {
                        Slog.d(TAG, "onAnimationStart d:" + mDisplayId + " top:"
                                + imeTop(hiddenY) + "->" + imeTop(shownY)
@@ -573,19 +569,19 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged
                    final float alpha = (mAnimateAlpha || isFloating)
                            ? (value - hiddenY) / (shownY - hiddenY)
                            : 1.f;
                    t.setAlpha(mImeSourceControl.getLeash(), alpha);
                    t.setAlpha(animatingLeash, alpha);
                    if (mAnimationDirection == DIRECTION_SHOW) {
                        ImeTracker.forLogging().onProgress(mStatsToken,
                                ImeTracker.PHASE_WM_ANIMATION_RUNNING);
                        t.show(mImeSourceControl.getLeash());
                        t.show(animatingLeash);
                    }
                    if (DEBUG_IME_VISIBILITY) {
                        EventLog.writeEvent(IMF_IME_REMOTE_ANIM_START,
                                mStatsToken != null ? mStatsToken.getTag() : ImeTracker.TOKEN_NONE,
                                mDisplayId, mAnimationDirection, alpha, value, endY,
                                Objects.toString(mImeSourceControl.getLeash()),
                                Objects.toString(mImeSourceControl.getInsetsHint()),
                                Objects.toString(mImeSourceControl.getSurfacePosition()),
                                Objects.toString(animatingLeash),
                                Objects.toString(animatingControl.getInsetsHint()),
                                Objects.toString(animatingControl.getSurfacePosition()),
                                Objects.toString(mImeFrame));
                    }
                    t.apply();
@@ -599,31 +595,23 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged
                        EventLog.writeEvent(IMF_IME_REMOTE_ANIM_CANCEL,
                                mStatsToken != null ? mStatsToken.getTag() : ImeTracker.TOKEN_NONE,
                                mDisplayId,
                                Objects.toString(mImeSourceControl.getInsetsHint()));
                                Objects.toString(animatingControl.getInsetsHint()));
                    }
                }

                @Override
                public void onAnimationEnd(Animator animation) {
                    boolean hasLeash =
                            mImeSourceControl != null && mImeSourceControl.getLeash() != null;
                    if (DEBUG) Slog.d(TAG, "onAnimationEnd " + mCancelled);
                    SurfaceControl.Transaction t = mTransactionPool.acquire();
                    if (!mCancelled) {
                        if (!android.view.inputmethod.Flags.refactorInsetsController()
                                || hasLeash) {
                            t.setPosition(mImeSourceControl.getLeash(), x, endY);
                            t.setAlpha(mImeSourceControl.getLeash(), 1.f);
                        }
                        t.setPosition(animatingLeash, x, endY);
                        t.setAlpha(animatingLeash, 1.f);
                    }
                    dispatchEndPositioning(mDisplayId, mCancelled, t);
                    if (mAnimationDirection == DIRECTION_HIDE && !mCancelled) {
                        ImeTracker.forLogging().onProgress(mStatsToken,
                                ImeTracker.PHASE_WM_ANIMATION_RUNNING);
                        if (!android.view.inputmethod.Flags.refactorInsetsController()
                                || hasLeash) {
                            t.hide(mImeSourceControl.getLeash());
                        }
                        t.hide(animatingLeash);
                        removeImeSurface(mDisplayId);
                        ImeTracker.forLogging().onHidden(mStatsToken);
                    } else if (mAnimationDirection == DIRECTION_SHOW && !mCancelled) {
@@ -636,13 +624,9 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged
                        EventLog.writeEvent(IMF_IME_REMOTE_ANIM_END,
                                mStatsToken != null ? mStatsToken.getTag() : ImeTracker.TOKEN_NONE,
                                mDisplayId, mAnimationDirection, endY,
                                Objects.toString(
                                        mImeSourceControl != null ? mImeSourceControl.getLeash()
                                                : "null"),
                                Objects.toString(mImeSourceControl != null
                                        ? mImeSourceControl.getInsetsHint() : "null"),
                                Objects.toString(mImeSourceControl != null
                                        ? mImeSourceControl.getSurfacePosition() : "null"),
                                Objects.toString(animatingLeash),
                                Objects.toString(animatingControl.getInsetsHint()),
                                Objects.toString(animatingControl.getSurfacePosition()),
                                Objects.toString(mImeFrame));
                    }
                    t.apply();
@@ -650,6 +634,7 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged

                    mAnimationDirection = DIRECTION_NONE;
                    mAnimation = null;
                    animatingControl.release(SurfaceControl::release);
                }
            });
            if (!show) {