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

Commit 96a43d64 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Instrument latency and jank for IME"

parents a68dbada f6862470
Loading
Loading
Loading
Loading
+10 −6
Original line number Original line Diff line number Diff line
@@ -223,11 +223,13 @@ class IInputMethodWrapper extends IInputMethod.Stub
                final SomeArgs args = (SomeArgs) msg.obj;
                final SomeArgs args = (SomeArgs) msg.obj;
                final ImeTracker.Token statsToken = (ImeTracker.Token) args.arg3;
                final ImeTracker.Token statsToken = (ImeTracker.Token) args.arg3;
                if (isValid(inputMethod, target, "DO_SHOW_SOFT_INPUT")) {
                if (isValid(inputMethod, target, "DO_SHOW_SOFT_INPUT")) {
                    ImeTracker.get().onProgress(statsToken, ImeTracker.PHASE_IME_WRAPPER_DISPATCH);
                    ImeTracker.forLogging().onProgress(
                            statsToken, ImeTracker.PHASE_IME_WRAPPER_DISPATCH);
                    inputMethod.showSoftInputWithToken(
                    inputMethod.showSoftInputWithToken(
                            msg.arg1, (ResultReceiver) args.arg2, (IBinder) args.arg1, statsToken);
                            msg.arg1, (ResultReceiver) args.arg2, (IBinder) args.arg1, statsToken);
                } else {
                } else {
                    ImeTracker.get().onFailed(statsToken, ImeTracker.PHASE_IME_WRAPPER_DISPATCH);
                    ImeTracker.forLogging().onFailed(
                            statsToken, ImeTracker.PHASE_IME_WRAPPER_DISPATCH);
                }
                }
                args.recycle();
                args.recycle();
                return;
                return;
@@ -236,11 +238,13 @@ class IInputMethodWrapper extends IInputMethod.Stub
                final SomeArgs args = (SomeArgs) msg.obj;
                final SomeArgs args = (SomeArgs) msg.obj;
                final ImeTracker.Token statsToken = (ImeTracker.Token) args.arg3;
                final ImeTracker.Token statsToken = (ImeTracker.Token) args.arg3;
                if (isValid(inputMethod, target, "DO_HIDE_SOFT_INPUT")) {
                if (isValid(inputMethod, target, "DO_HIDE_SOFT_INPUT")) {
                    ImeTracker.get().onProgress(statsToken, ImeTracker.PHASE_IME_WRAPPER_DISPATCH);
                    ImeTracker.forLogging().onProgress(
                            statsToken, ImeTracker.PHASE_IME_WRAPPER_DISPATCH);
                    inputMethod.hideSoftInputWithToken(msg.arg1, (ResultReceiver) args.arg2,
                    inputMethod.hideSoftInputWithToken(msg.arg1, (ResultReceiver) args.arg2,
                            (IBinder) args.arg1, statsToken);
                            (IBinder) args.arg1, statsToken);
                } else {
                } else {
                    ImeTracker.get().onFailed(statsToken, ImeTracker.PHASE_IME_WRAPPER_DISPATCH);
                    ImeTracker.forLogging().onFailed(
                            statsToken, ImeTracker.PHASE_IME_WRAPPER_DISPATCH);
                }
                }
                args.recycle();
                args.recycle();
                return;
                return;
@@ -428,7 +432,7 @@ class IInputMethodWrapper extends IInputMethod.Stub
    @Override
    @Override
    public void showSoftInput(IBinder showInputToken, @Nullable ImeTracker.Token statsToken,
    public void showSoftInput(IBinder showInputToken, @Nullable ImeTracker.Token statsToken,
            int flags, ResultReceiver resultReceiver) {
            int flags, ResultReceiver resultReceiver) {
        ImeTracker.get().onProgress(statsToken, ImeTracker.PHASE_IME_WRAPPER);
        ImeTracker.forLogging().onProgress(statsToken, ImeTracker.PHASE_IME_WRAPPER);
        mCaller.executeOrSendMessage(mCaller.obtainMessageIOOO(DO_SHOW_SOFT_INPUT,
        mCaller.executeOrSendMessage(mCaller.obtainMessageIOOO(DO_SHOW_SOFT_INPUT,
                flags, showInputToken, resultReceiver, statsToken));
                flags, showInputToken, resultReceiver, statsToken));
    }
    }
@@ -437,7 +441,7 @@ class IInputMethodWrapper extends IInputMethod.Stub
    @Override
    @Override
    public void hideSoftInput(IBinder hideInputToken, @Nullable ImeTracker.Token statsToken,
    public void hideSoftInput(IBinder hideInputToken, @Nullable ImeTracker.Token statsToken,
            int flags, ResultReceiver resultReceiver) {
            int flags, ResultReceiver resultReceiver) {
        ImeTracker.get().onProgress(statsToken, ImeTracker.PHASE_IME_WRAPPER);
        ImeTracker.forLogging().onProgress(statsToken, ImeTracker.PHASE_IME_WRAPPER);
        mCaller.executeOrSendMessage(mCaller.obtainMessageIOOO(DO_HIDE_SOFT_INPUT,
        mCaller.executeOrSendMessage(mCaller.obtainMessageIOOO(DO_HIDE_SOFT_INPUT,
                flags, hideInputToken, resultReceiver, statsToken));
                flags, hideInputToken, resultReceiver, statsToken));
    }
    }
+7 −5
Original line number Original line Diff line number Diff line
@@ -896,7 +896,8 @@ public class InputMethodService extends AbstractInputMethodService {
        @MainThread
        @MainThread
        @Override
        @Override
        public void hideSoftInput(int flags, ResultReceiver resultReceiver) {
        public void hideSoftInput(int flags, ResultReceiver resultReceiver) {
            ImeTracker.get().onProgress(mCurStatsToken, ImeTracker.PHASE_IME_HIDE_SOFT_INPUT);
            ImeTracker.forLogging().onProgress(
                    mCurStatsToken, ImeTracker.PHASE_IME_HIDE_SOFT_INPUT);
            if (DEBUG) Log.v(TAG, "hideSoftInput()");
            if (DEBUG) Log.v(TAG, "hideSoftInput()");
            if (getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.R
            if (getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.R
                    && !mSystemCallingHideSoftInput) {
                    && !mSystemCallingHideSoftInput) {
@@ -950,7 +951,8 @@ public class InputMethodService extends AbstractInputMethodService {
        @MainThread
        @MainThread
        @Override
        @Override
        public void showSoftInput(int flags, ResultReceiver resultReceiver) {
        public void showSoftInput(int flags, ResultReceiver resultReceiver) {
            ImeTracker.get().onProgress(mCurStatsToken, ImeTracker.PHASE_IME_SHOW_SOFT_INPUT);
            ImeTracker.forLogging().onProgress(
                    mCurStatsToken, ImeTracker.PHASE_IME_SHOW_SOFT_INPUT);
            if (DEBUG) Log.v(TAG, "showSoftInput()");
            if (DEBUG) Log.v(TAG, "showSoftInput()");
            // TODO(b/148086656): Disallow IME developers from calling InputMethodImpl methods.
            // TODO(b/148086656): Disallow IME developers from calling InputMethodImpl methods.
            if (getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.R
            if (getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.R
@@ -966,11 +968,11 @@ public class InputMethodService extends AbstractInputMethodService {
                    null /* icProto */);
                    null /* icProto */);
            final boolean wasVisible = isInputViewShown();
            final boolean wasVisible = isInputViewShown();
            if (dispatchOnShowInputRequested(flags, false)) {
            if (dispatchOnShowInputRequested(flags, false)) {
                ImeTracker.get().onProgress(mCurStatsToken,
                ImeTracker.forLogging().onProgress(mCurStatsToken,
                        ImeTracker.PHASE_IME_ON_SHOW_SOFT_INPUT_TRUE);
                        ImeTracker.PHASE_IME_ON_SHOW_SOFT_INPUT_TRUE);
                showWindow(true);
                showWindow(true);
            } else {
            } else {
                ImeTracker.get().onFailed(mCurStatsToken,
                ImeTracker.forLogging().onFailed(mCurStatsToken,
                        ImeTracker.PHASE_IME_ON_SHOW_SOFT_INPUT_TRUE);
                        ImeTracker.PHASE_IME_ON_SHOW_SOFT_INPUT_TRUE);
            }
            }
            setImeWindowStatus(mapToImeWindowStatus(), mBackDisposition);
            setImeWindowStatus(mapToImeWindowStatus(), mBackDisposition);
@@ -2979,7 +2981,7 @@ public class InputMethodService extends AbstractInputMethodService {
        ImeTracing.getInstance().triggerServiceDump(
        ImeTracing.getInstance().triggerServiceDump(
                "InputMethodService#applyVisibilityInInsetsConsumerIfNecessary", mDumper,
                "InputMethodService#applyVisibilityInInsetsConsumerIfNecessary", mDumper,
                null /* icProto */);
                null /* icProto */);
        ImeTracker.get().onProgress(mCurStatsToken,
        ImeTracker.forLogging().onProgress(mCurStatsToken,
                ImeTracker.PHASE_IME_APPLY_VISIBILITY_INSETS_CONSUMER);
                ImeTracker.PHASE_IME_APPLY_VISIBILITY_INSETS_CONSUMER);
        mPrivOps.applyImeVisibilityAsync(setVisible
        mPrivOps.applyImeVisibilityAsync(setVisible
                ? mCurShowInputToken : mCurHideInputToken, setVisible, mCurStatsToken);
                ? mCurShowInputToken : mCurHideInputToken, setVisible, mCurStatsToken);
+4 −3
Original line number Original line Diff line number Diff line
@@ -123,7 +123,7 @@ public final class ImeInsetsSourceConsumer extends InsetsSourceConsumer {


        // TODO: ResultReceiver for IME.
        // TODO: ResultReceiver for IME.
        // TODO: Set mShowOnNextImeRender to automatically show IME and guard it with a flag.
        // TODO: Set mShowOnNextImeRender to automatically show IME and guard it with a flag.
        ImeTracker.get().onProgress(statsToken,
        ImeTracker.forLogging().onProgress(statsToken,
                ImeTracker.PHASE_CLIENT_INSETS_CONSUMER_REQUEST_SHOW);
                ImeTracker.PHASE_CLIENT_INSETS_CONSUMER_REQUEST_SHOW);


        if (getControl() == null) {
        if (getControl() == null) {
@@ -165,12 +165,13 @@ public final class ImeInsetsSourceConsumer extends InsetsSourceConsumer {
        //  - we do already have one, but we have control and use the passed in token
        //  - we do already have one, but we have control and use the passed in token
        //      for the insets animation already.
        //      for the insets animation already.
        if (statsToken == null || getControl() != null) {
        if (statsToken == null || getControl() != null) {
            statsToken = ImeTracker.get().onRequestHide(null /* component */, Process.myUid(),
            statsToken = ImeTracker.forLogging().onRequestHide(null /* component */,
                    Process.myUid(),
                    ImeTracker.ORIGIN_CLIENT_HIDE_SOFT_INPUT,
                    ImeTracker.ORIGIN_CLIENT_HIDE_SOFT_INPUT,
                    SoftInputShowHideReason.HIDE_SOFT_INPUT_BY_INSETS_API);
                    SoftInputShowHideReason.HIDE_SOFT_INPUT_BY_INSETS_API);
        }
        }


        ImeTracker.get().onProgress(statsToken,
        ImeTracker.forLogging().onProgress(statsToken,
                ImeTracker.PHASE_CLIENT_INSETS_CONSUMER_NOTIFY_HIDDEN);
                ImeTracker.PHASE_CLIENT_INSETS_CONSUMER_NOTIFY_HIDDEN);


        getImm().notifyImeHidden(mController.getHost().getWindowToken(), statsToken);
        getImm().notifyImeHidden(mController.getHost().getWindowToken(), statsToken);
+99 −24
Original line number Original line Diff line number Diff line
@@ -26,6 +26,7 @@ import static android.view.WindowInsets.Type.LAST;
import static android.view.WindowInsets.Type.all;
import static android.view.WindowInsets.Type.all;
import static android.view.WindowInsets.Type.captionBar;
import static android.view.WindowInsets.Type.captionBar;
import static android.view.WindowInsets.Type.ime;
import static android.view.WindowInsets.Type.ime;
import static android.view.inputmethod.ImeTracker.PHASE_CLIENT_ANIMATION_CANCEL;


import android.animation.AnimationHandler;
import android.animation.AnimationHandler;
import android.animation.Animator;
import android.animation.Animator;
@@ -35,6 +36,8 @@ import android.animation.ValueAnimator;
import android.annotation.IntDef;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Nullable;
import android.app.ActivityThread;
import android.content.Context;
import android.content.res.CompatibilityInfo;
import android.content.res.CompatibilityInfo;
import android.graphics.Insets;
import android.graphics.Insets;
import android.graphics.Rect;
import android.graphics.Rect;
@@ -59,6 +62,7 @@ import android.view.animation.Interpolator;
import android.view.animation.LinearInterpolator;
import android.view.animation.LinearInterpolator;
import android.view.animation.PathInterpolator;
import android.view.animation.PathInterpolator;
import android.view.inputmethod.ImeTracker;
import android.view.inputmethod.ImeTracker;
import android.view.inputmethod.ImeTracker.InputMethodJankContext;
import android.view.inputmethod.InputMethodManager;
import android.view.inputmethod.InputMethodManager;


import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.annotations.VisibleForTesting;
@@ -185,6 +189,14 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
        @Nullable
        @Nullable
        String getRootViewTitle();
        String getRootViewTitle();


        /**
         * @return the context related to the rootView.
         */
        @Nullable
        default Context getRootViewContext() {
            return null;
        }

        /** @see ViewRootImpl#dipToPx */
        /** @see ViewRootImpl#dipToPx */
        int dipToPx(int dips);
        int dipToPx(int dips);


@@ -308,7 +320,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
    @Retention(RetentionPolicy.SOURCE)
    @Retention(RetentionPolicy.SOURCE)
    @IntDef(value = {ANIMATION_TYPE_NONE, ANIMATION_TYPE_SHOW, ANIMATION_TYPE_HIDE,
    @IntDef(value = {ANIMATION_TYPE_NONE, ANIMATION_TYPE_SHOW, ANIMATION_TYPE_HIDE,
            ANIMATION_TYPE_USER, ANIMATION_TYPE_RESIZE})
            ANIMATION_TYPE_USER, ANIMATION_TYPE_RESIZE})
    @interface AnimationType {
    public @interface AnimationType {
    }
    }


    /**
    /**
@@ -323,6 +335,25 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
    /** Logging listener. */
    /** Logging listener. */
    private WindowInsetsAnimationControlListener mLoggingListener;
    private WindowInsetsAnimationControlListener mLoggingListener;


    /** Context for {@link android.view.inputmethod.ImeTracker.ImeJankTracker} to monitor jank. */
    private final InputMethodJankContext mJankContext = new InputMethodJankContext() {
        @Override
        public Context getDisplayContext() {
            return mHost != null ? mHost.getRootViewContext() : null;
        }

        @Override
        public SurfaceControl getTargetSurfaceControl() {
            final InsetsSourceControl imeSourceControl = getImeSourceConsumer().getControl();
            return imeSourceControl != null ? imeSourceControl.getLeash() : null;
        }

        @Override
        public String getHostPackageName() {
            return mHost != null ? mHost.getRootViewContext().getPackageName() : null;
        }
    };

    /**
    /**
     * The default implementation of listener, to be used by InsetsController and InsetsPolicy to
     * The default implementation of listener, to be used by InsetsController and InsetsPolicy to
     * animate insets.
     * animate insets.
@@ -340,6 +371,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
        private final boolean mDisable;
        private final boolean mDisable;
        private final int mFloatingImeBottomInset;
        private final int mFloatingImeBottomInset;
        private final WindowInsetsAnimationControlListener mLoggingListener;
        private final WindowInsetsAnimationControlListener mLoggingListener;
        private final InputMethodJankContext mInputMethodJankContext;


        private final ThreadLocal<AnimationHandler> mSfAnimationHandlerThreadLocal =
        private final ThreadLocal<AnimationHandler> mSfAnimationHandlerThreadLocal =
                new ThreadLocal<AnimationHandler>() {
                new ThreadLocal<AnimationHandler>() {
@@ -353,7 +385,8 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation


        public InternalAnimationControlListener(boolean show, boolean hasAnimationCallbacks,
        public InternalAnimationControlListener(boolean show, boolean hasAnimationCallbacks,
                @InsetsType int requestedTypes, @Behavior int behavior, boolean disable,
                @InsetsType int requestedTypes, @Behavior int behavior, boolean disable,
                int floatingImeBottomInset, WindowInsetsAnimationControlListener loggingListener) {
                int floatingImeBottomInset, WindowInsetsAnimationControlListener loggingListener,
                @Nullable InputMethodJankContext jankContext) {
            mShow = show;
            mShow = show;
            mHasAnimationCallbacks = hasAnimationCallbacks;
            mHasAnimationCallbacks = hasAnimationCallbacks;
            mRequestedTypes = requestedTypes;
            mRequestedTypes = requestedTypes;
@@ -362,6 +395,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
            mDisable = disable;
            mDisable = disable;
            mFloatingImeBottomInset = floatingImeBottomInset;
            mFloatingImeBottomInset = floatingImeBottomInset;
            mLoggingListener = loggingListener;
            mLoggingListener = loggingListener;
            mInputMethodJankContext = jankContext;
        }
        }


        @Override
        @Override
@@ -408,10 +442,26 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
                        + insetsFraction);
                        + insetsFraction);
            });
            });
            mAnimator.addListener(new AnimatorListenerAdapter() {
            mAnimator.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationStart(Animator animation) {
                    if (mInputMethodJankContext == null) return;
                    ImeTracker.forJank().onRequestAnimation(
                            mInputMethodJankContext,
                            mShow ? ANIMATION_TYPE_SHOW : ANIMATION_TYPE_HIDE,
                            !mHasAnimationCallbacks);
                }

                @Override
                public void onAnimationCancel(Animator animation) {
                    if (mInputMethodJankContext == null) return;
                    ImeTracker.forJank().onCancelAnimation();
                }


                @Override
                @Override
                public void onAnimationEnd(Animator animation) {
                public void onAnimationEnd(Animator animation) {
                    onAnimationFinish();
                    onAnimationFinish();
                    if (mInputMethodJankContext == null) return;
                    ImeTracker.forJank().onFinishAnimation();
                }
                }
            });
            });
            if (!mHasAnimationCallbacks) {
            if (!mHasAnimationCallbacks) {
@@ -897,7 +947,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation


    /**
    /**
     * @see InsetsState#calculateInsets(Rect, InsetsState, boolean, boolean, int, int, int, int,
     * @see InsetsState#calculateInsets(Rect, InsetsState, boolean, boolean, int, int, int, int,
     *      int, SparseIntArray)
     *      int, android.util.SparseIntArray)
     */
     */
    @VisibleForTesting
    @VisibleForTesting
    public WindowInsets calculateInsets(boolean isScreenRound, boolean alwaysConsumeSystemBars,
    public WindowInsets calculateInsets(boolean isScreenRound, boolean alwaysConsumeSystemBars,
@@ -1005,7 +1055,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
    public void show(@InsetsType int types) {
    public void show(@InsetsType int types) {
        ImeTracker.Token statsToken = null;
        ImeTracker.Token statsToken = null;
        if ((types & ime()) != 0) {
        if ((types & ime()) != 0) {
            statsToken = ImeTracker.get().onRequestShow(null /* component */,
            statsToken = ImeTracker.forLogging().onRequestShow(null /* component */,
                    Process.myUid(), ImeTracker.ORIGIN_CLIENT_SHOW_SOFT_INPUT,
                    Process.myUid(), ImeTracker.ORIGIN_CLIENT_SHOW_SOFT_INPUT,
                    SoftInputShowHideReason.SHOW_SOFT_INPUT_BY_INSETS_API);
                    SoftInputShowHideReason.SHOW_SOFT_INPUT_BY_INSETS_API);
        }
        }
@@ -1030,6 +1080,9 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
        }
        }
        // Handle pending request ready in case there was one set.
        // Handle pending request ready in case there was one set.
        if (fromIme && mPendingImeControlRequest != null) {
        if (fromIme && mPendingImeControlRequest != null) {
            if ((types & Type.ime()) != 0) {
                ImeTracker.forLatency().onShown(statsToken, ActivityThread::currentApplication);
            }
            handlePendingControlRequest(statsToken);
            handlePendingControlRequest(statsToken);
            return;
            return;
        }
        }
@@ -1052,7 +1105,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
                        "show ignored for type: %d animType: %d requestedVisible: %s",
                        "show ignored for type: %d animType: %d requestedVisible: %s",
                        type, animationType, requestedVisible));
                        type, animationType, requestedVisible));
                if (isImeAnimation) {
                if (isImeAnimation) {
                    ImeTracker.get().onCancelled(statsToken,
                    ImeTracker.forLogging().onCancelled(statsToken,
                            ImeTracker.PHASE_CLIENT_APPLY_ANIMATION);
                            ImeTracker.PHASE_CLIENT_APPLY_ANIMATION);
                }
                }
                continue;
                continue;
@@ -1060,16 +1113,21 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
            if (fromIme && animationType == ANIMATION_TYPE_USER) {
            if (fromIme && animationType == ANIMATION_TYPE_USER) {
                // App is already controlling the IME, don't cancel it.
                // App is already controlling the IME, don't cancel it.
                if (isImeAnimation) {
                if (isImeAnimation) {
                    ImeTracker.get().onFailed(statsToken, ImeTracker.PHASE_CLIENT_APPLY_ANIMATION);
                    ImeTracker.forLogging().onFailed(
                            statsToken, ImeTracker.PHASE_CLIENT_APPLY_ANIMATION);
                }
                }
                continue;
                continue;
            }
            }
            if (isImeAnimation) {
            if (isImeAnimation) {
                ImeTracker.get().onProgress(statsToken, ImeTracker.PHASE_CLIENT_APPLY_ANIMATION);
                ImeTracker.forLogging().onProgress(
                        statsToken, ImeTracker.PHASE_CLIENT_APPLY_ANIMATION);
            }
            }
            typesReady |= type;
            typesReady |= type;
        }
        }
        if (DEBUG) Log.d(TAG, "show typesReady: " + typesReady);
        if (DEBUG) Log.d(TAG, "show typesReady: " + typesReady);
        if (fromIme && (typesReady & Type.ime()) != 0) {
            ImeTracker.forLatency().onShown(statsToken, ActivityThread::currentApplication);
        }
        applyAnimation(typesReady, true /* show */, fromIme, statsToken);
        applyAnimation(typesReady, true /* show */, fromIme, statsToken);
    }
    }


@@ -1098,7 +1156,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
    public void hide(@InsetsType int types) {
    public void hide(@InsetsType int types) {
        ImeTracker.Token statsToken = null;
        ImeTracker.Token statsToken = null;
        if ((types & ime()) != 0) {
        if ((types & ime()) != 0) {
            statsToken = ImeTracker.get().onRequestHide(null /* component */,
            statsToken = ImeTracker.forLogging().onRequestHide(null /* component */,
                    Process.myUid(), ImeTracker.ORIGIN_CLIENT_HIDE_SOFT_INPUT,
                    Process.myUid(), ImeTracker.ORIGIN_CLIENT_HIDE_SOFT_INPUT,
                    SoftInputShowHideReason.HIDE_SOFT_INPUT_BY_INSETS_API);
                    SoftInputShowHideReason.HIDE_SOFT_INPUT_BY_INSETS_API);
        }
        }
@@ -1147,13 +1205,14 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
                // no-op: already hidden or animating out (because window visibility is
                // no-op: already hidden or animating out (because window visibility is
                // applied before starting animation).
                // applied before starting animation).
                if (isImeAnimation) {
                if (isImeAnimation) {
                    ImeTracker.get().onCancelled(statsToken,
                    ImeTracker.forLogging().onCancelled(statsToken,
                            ImeTracker.PHASE_CLIENT_APPLY_ANIMATION);
                            ImeTracker.PHASE_CLIENT_APPLY_ANIMATION);
                }
                }
                continue;
                continue;
            }
            }
            if (isImeAnimation) {
            if (isImeAnimation) {
                ImeTracker.get().onProgress(statsToken, ImeTracker.PHASE_CLIENT_APPLY_ANIMATION);
                ImeTracker.forLogging().onProgress(
                        statsToken, ImeTracker.PHASE_CLIENT_APPLY_ANIMATION);
            }
            }
            typesReady |= type;
            typesReady |= type;
        }
        }
@@ -1225,8 +1284,19 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
            @AnimationType int animationType,
            @AnimationType int animationType,
            @LayoutInsetsDuringAnimation int layoutInsetsDuringAnimation,
            @LayoutInsetsDuringAnimation int layoutInsetsDuringAnimation,
            boolean useInsetsAnimationThread, @Nullable ImeTracker.Token statsToken) {
            boolean useInsetsAnimationThread, @Nullable ImeTracker.Token statsToken) {
        ImeTracker.get().onProgress(statsToken, ImeTracker.PHASE_CLIENT_CONTROL_ANIMATION);
        ImeTracker.forLogging().onProgress(statsToken, ImeTracker.PHASE_CLIENT_CONTROL_ANIMATION);
        if ((types & mTypesBeingCancelled) != 0) {
        if ((types & mTypesBeingCancelled) != 0) {
            final boolean monitoredAnimation =
                    animationType == ANIMATION_TYPE_SHOW || animationType == ANIMATION_TYPE_HIDE;
            if (monitoredAnimation && (types & Type.ime()) != 0) {
                if (animationType == ANIMATION_TYPE_SHOW) {
                    ImeTracker.forLatency().onShowCancelled(statsToken,
                            PHASE_CLIENT_ANIMATION_CANCEL, ActivityThread::currentApplication);
                } else {
                    ImeTracker.forLatency().onHideCancelled(statsToken,
                            PHASE_CLIENT_ANIMATION_CANCEL, ActivityThread::currentApplication);
                }
            }
            throw new IllegalStateException("Cannot start a new insets animation of "
            throw new IllegalStateException("Cannot start a new insets animation of "
                    + Type.toString(types)
                    + Type.toString(types)
                    + " while an existing " + Type.toString(mTypesBeingCancelled)
                    + " while an existing " + Type.toString(mTypesBeingCancelled)
@@ -1238,7 +1308,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
            types &= ~mDisabledUserAnimationInsetsTypes;
            types &= ~mDisabledUserAnimationInsetsTypes;


            if ((disabledTypes & ime()) != 0) {
            if ((disabledTypes & ime()) != 0) {
                ImeTracker.get().onFailed(statsToken,
                ImeTracker.forLogging().onFailed(statsToken,
                        ImeTracker.PHASE_CLIENT_DISABLED_USER_ANIMATION);
                        ImeTracker.PHASE_CLIENT_DISABLED_USER_ANIMATION);


                if (fromIme
                if (fromIme
@@ -1260,7 +1330,8 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
            Trace.asyncTraceEnd(TRACE_TAG_VIEW, "IC.showRequestFromApiToImeReady", 0);
            Trace.asyncTraceEnd(TRACE_TAG_VIEW, "IC.showRequestFromApiToImeReady", 0);
            return;
            return;
        }
        }
        ImeTracker.get().onProgress(statsToken, ImeTracker.PHASE_CLIENT_DISABLED_USER_ANIMATION);
        ImeTracker.forLogging().onProgress(statsToken,
                ImeTracker.PHASE_CLIENT_DISABLED_USER_ANIMATION);
        if (DEBUG) Log.d(TAG, "controlAnimation types: " + types);
        if (DEBUG) Log.d(TAG, "controlAnimation types: " + types);
        mLastStartedAnimTypes |= types;
        mLastStartedAnimTypes |= types;


@@ -1327,8 +1398,11 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
        if ((typesReady & WindowInsets.Type.ime()) != 0) {
        if ((typesReady & WindowInsets.Type.ime()) != 0) {
            ImeTracing.getInstance().triggerClientDump("InsetsAnimationControlImpl",
            ImeTracing.getInstance().triggerClientDump("InsetsAnimationControlImpl",
                    mHost.getInputMethodManager(), null /* icProto */);
                    mHost.getInputMethodManager(), null /* icProto */);
            if (animationType == ANIMATION_TYPE_HIDE) {
                ImeTracker.forLatency().onHidden(statsToken, ActivityThread::currentApplication);
            }
        }
        }
        ImeTracker.get().onProgress(statsToken, ImeTracker.PHASE_CLIENT_ANIMATION_RUNNING);
        ImeTracker.forLogging().onProgress(statsToken, ImeTracker.PHASE_CLIENT_ANIMATION_RUNNING);
        mRunningAnimations.add(new RunningAnimation(runner, animationType));
        mRunningAnimations.add(new RunningAnimation(runner, animationType));
        if (DEBUG) Log.d(TAG, "Animation added to runner. useInsetsAnimationThread: "
        if (DEBUG) Log.d(TAG, "Animation added to runner. useInsetsAnimationThread: "
                + useInsetsAnimationThread);
                + useInsetsAnimationThread);
@@ -1368,7 +1442,8 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
    private Pair<Integer, Boolean> collectSourceControls(boolean fromIme, @InsetsType int types,
    private Pair<Integer, Boolean> collectSourceControls(boolean fromIme, @InsetsType int types,
            SparseArray<InsetsSourceControl> controls, @AnimationType int animationType,
            SparseArray<InsetsSourceControl> controls, @AnimationType int animationType,
            @Nullable ImeTracker.Token statsToken) {
            @Nullable ImeTracker.Token statsToken) {
        ImeTracker.get().onProgress(statsToken, ImeTracker.PHASE_CLIENT_COLLECT_SOURCE_CONTROLS);
        ImeTracker.forLogging().onProgress(statsToken,
                ImeTracker.PHASE_CLIENT_COLLECT_SOURCE_CONTROLS);


        int typesReady = 0;
        int typesReady = 0;
        boolean imeReady = true;
        boolean imeReady = true;
@@ -1471,13 +1546,13 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
        }
        }
        final ImeTracker.Token statsToken = runner.getStatsToken();
        final ImeTracker.Token statsToken = runner.getStatsToken();
        if (shown) {
        if (shown) {
            ImeTracker.get().onProgress(statsToken,
            ImeTracker.forLogging().onProgress(statsToken,
                    ImeTracker.PHASE_CLIENT_ANIMATION_FINISHED_SHOW);
                    ImeTracker.PHASE_CLIENT_ANIMATION_FINISHED_SHOW);
            ImeTracker.get().onShown(statsToken);
            ImeTracker.forLogging().onShown(statsToken);
        } else {
        } else {
            ImeTracker.get().onProgress(statsToken,
            ImeTracker.forLogging().onProgress(statsToken,
                    ImeTracker.PHASE_CLIENT_ANIMATION_FINISHED_HIDE);
                    ImeTracker.PHASE_CLIENT_ANIMATION_FINISHED_HIDE);
            ImeTracker.get().onHidden(statsToken);
            ImeTracker.forLogging().onHidden(statsToken);
        }
        }
        reportRequestedVisibleTypes();
        reportRequestedVisibleTypes();
    }
    }
@@ -1503,13 +1578,13 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation


    private void cancelAnimation(InsetsAnimationControlRunner control, boolean invokeCallback) {
    private void cancelAnimation(InsetsAnimationControlRunner control, boolean invokeCallback) {
        if (invokeCallback) {
        if (invokeCallback) {
            ImeTracker.get().onCancelled(control.getStatsToken(),
            ImeTracker.forLogging().onCancelled(control.getStatsToken(),
                    ImeTracker.PHASE_CLIENT_ANIMATION_CANCEL);
                    PHASE_CLIENT_ANIMATION_CANCEL);
            control.cancel();
            control.cancel();
        } else {
        } else {
            // Succeeds if invokeCallback is false (i.e. when called from notifyFinished).
            // Succeeds if invokeCallback is false (i.e. when called from notifyFinished).
            ImeTracker.get().onProgress(control.getStatsToken(),
            ImeTracker.forLogging().onProgress(control.getStatsToken(),
                    ImeTracker.PHASE_CLIENT_ANIMATION_CANCEL);
                    PHASE_CLIENT_ANIMATION_CANCEL);
        }
        }
        if (DEBUG) {
        if (DEBUG) {
            Log.d(TAG, TextUtils.formatSimple(
            Log.d(TAG, TextUtils.formatSimple(
@@ -1674,7 +1749,7 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
        final InternalAnimationControlListener listener = new InternalAnimationControlListener(
        final InternalAnimationControlListener listener = new InternalAnimationControlListener(
                show, hasAnimationCallbacks, types, mHost.getSystemBarsBehavior(),
                show, hasAnimationCallbacks, types, mHost.getSystemBarsBehavior(),
                skipAnim || mAnimationsDisabled, mHost.dipToPx(FLOATING_IME_BOTTOM_INSET_DP),
                skipAnim || mAnimationsDisabled, mHost.dipToPx(FLOATING_IME_BOTTOM_INSET_DP),
                mLoggingListener);
                mLoggingListener, mJankContext);


        // We are about to playing the default animation (show/hide). Passing a null frame indicates
        // We are about to playing the default animation (show/hide). Passing a null frame indicates
        // the controlled types should be animated regardless of the frame.
        // the controlled types should be animated regardless of the frame.
+6 −6
Original line number Original line Diff line number Diff line
@@ -5815,7 +5815,7 @@ public final class ViewRootImpl implements ViewParent,
                }
                }
                case MSG_SHOW_INSETS: {
                case MSG_SHOW_INSETS: {
                    final ImeTracker.Token statsToken = (ImeTracker.Token) msg.obj;
                    final ImeTracker.Token statsToken = (ImeTracker.Token) msg.obj;
                    ImeTracker.get().onProgress(statsToken,
                    ImeTracker.forLogging().onProgress(statsToken,
                            ImeTracker.PHASE_CLIENT_HANDLE_SHOW_INSETS);
                            ImeTracker.PHASE_CLIENT_HANDLE_SHOW_INSETS);
                    if (mView == null) {
                    if (mView == null) {
                        Log.e(TAG,
                        Log.e(TAG,
@@ -5828,7 +5828,7 @@ public final class ViewRootImpl implements ViewParent,
                }
                }
                case MSG_HIDE_INSETS: {
                case MSG_HIDE_INSETS: {
                    final ImeTracker.Token statsToken = (ImeTracker.Token) msg.obj;
                    final ImeTracker.Token statsToken = (ImeTracker.Token) msg.obj;
                    ImeTracker.get().onProgress(statsToken,
                    ImeTracker.forLogging().onProgress(statsToken,
                            ImeTracker.PHASE_CLIENT_HANDLE_HIDE_INSETS);
                            ImeTracker.PHASE_CLIENT_HANDLE_HIDE_INSETS);
                    mInsetsController.hide(msg.arg1, msg.arg2 == 1, statsToken);
                    mInsetsController.hide(msg.arg1, msg.arg2 == 1, statsToken);
                    break;
                    break;
@@ -10407,10 +10407,10 @@ public final class ViewRootImpl implements ViewParent,
                        null /* icProto */);
                        null /* icProto */);
            }
            }
            if (viewAncestor != null) {
            if (viewAncestor != null) {
                ImeTracker.get().onProgress(statsToken, ImeTracker.PHASE_CLIENT_SHOW_INSETS);
                ImeTracker.forLogging().onProgress(statsToken, ImeTracker.PHASE_CLIENT_SHOW_INSETS);
                viewAncestor.showInsets(types, fromIme, statsToken);
                viewAncestor.showInsets(types, fromIme, statsToken);
            } else {
            } else {
                ImeTracker.get().onFailed(statsToken, ImeTracker.PHASE_CLIENT_SHOW_INSETS);
                ImeTracker.forLogging().onFailed(statsToken, ImeTracker.PHASE_CLIENT_SHOW_INSETS);
            }
            }
        }
        }


@@ -10424,10 +10424,10 @@ public final class ViewRootImpl implements ViewParent,
                        null /* icProto */);
                        null /* icProto */);
            }
            }
            if (viewAncestor != null) {
            if (viewAncestor != null) {
                ImeTracker.get().onProgress(statsToken, ImeTracker.PHASE_CLIENT_HIDE_INSETS);
                ImeTracker.forLogging().onProgress(statsToken, ImeTracker.PHASE_CLIENT_HIDE_INSETS);
                viewAncestor.hideInsets(types, fromIme, statsToken);
                viewAncestor.hideInsets(types, fromIme, statsToken);
            } else {
            } else {
                ImeTracker.get().onFailed(statsToken, ImeTracker.PHASE_CLIENT_HIDE_INSETS);
                ImeTracker.forLogging().onFailed(statsToken, ImeTracker.PHASE_CLIENT_HIDE_INSETS);
            }
            }
        }
        }


Loading