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

Commit fc03fbd0 authored by Cosmin Băieș's avatar Cosmin Băieș Committed by Android (Google) Code Review
Browse files

Merge changes from topic "revert-20437706-revert-20313761-IME tracking -...

Merge changes from topic "revert-20437706-revert-20313761-IME tracking - hide-HZXGDCCPOZ-XOCVITMXNR"

* changes:
  Revert^2 "Input latency & reliability tracking - hide flow"
  Revert^2 "Input latency & reliability tracking"
parents 70453947 44ff0dd9
Loading
Loading
Loading
Loading
+25 −11
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.os.ResultReceiver;
import android.util.Log;
import android.view.InputChannel;
import android.view.MotionEvent;
import android.view.inputmethod.ImeTracker;
import android.view.inputmethod.InputBinding;
import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputMethod;
@@ -93,9 +94,10 @@ class IInputMethodWrapper extends IInputMethod.Stub
    final int mTargetSdkVersion;

    /**
     * This is not {@null} only between {@link #bindInput(InputBinding)} and {@link #unbindInput()}
     * so that {@link RemoteInputConnection} can query if {@link #unbindInput()} has already been
     * called or not, mainly to avoid unnecessary blocking operations.
     * This is not {@code null} only between {@link #bindInput(InputBinding)} and
     * {@link #unbindInput()} so that {@link RemoteInputConnection} can query if
     * {@link #unbindInput()} has already been called or not, mainly to avoid unnecessary
     * blocking operations.
     *
     * <p>This field must be set and cleared only from the binder thread(s), where the system
     * guarantees that {@link #bindInput(InputBinding)},
@@ -219,18 +221,26 @@ class IInputMethodWrapper extends IInputMethod.Stub
                return;
            case DO_SHOW_SOFT_INPUT: {
                final SomeArgs args = (SomeArgs) msg.obj;
                final ImeTracker.Token statsToken = (ImeTracker.Token) args.arg3;
                if (isValid(inputMethod, target, "DO_SHOW_SOFT_INPUT")) {
                    ImeTracker.get().onProgress(statsToken, ImeTracker.PHASE_IME_WRAPPER_DISPATCH);
                    inputMethod.showSoftInputWithToken(
                            msg.arg1, (ResultReceiver) args.arg2, (IBinder) args.arg1);
                            msg.arg1, (ResultReceiver) args.arg2, (IBinder) args.arg1, statsToken);
                } else {
                    ImeTracker.get().onFailed(statsToken, ImeTracker.PHASE_IME_WRAPPER_DISPATCH);
                }
                args.recycle();
                return;
            }
            case DO_HIDE_SOFT_INPUT: {
                final SomeArgs args = (SomeArgs) msg.obj;
                final ImeTracker.Token statsToken = (ImeTracker.Token) args.arg3;
                if (isValid(inputMethod, target, "DO_HIDE_SOFT_INPUT")) {
                    ImeTracker.get().onProgress(statsToken, ImeTracker.PHASE_IME_WRAPPER_DISPATCH);
                    inputMethod.hideSoftInputWithToken(msg.arg1, (ResultReceiver) args.arg2,
                            (IBinder) args.arg1);
                            (IBinder) args.arg1, statsToken);
                } else {
                    ImeTracker.get().onFailed(statsToken, ImeTracker.PHASE_IME_WRAPPER_DISPATCH);
                }
                args.recycle();
                return;
@@ -416,16 +426,20 @@ class IInputMethodWrapper extends IInputMethod.Stub

    @BinderThread
    @Override
    public void showSoftInput(IBinder showInputToken, int flags, ResultReceiver resultReceiver) {
        mCaller.executeOrSendMessage(mCaller.obtainMessageIOO(DO_SHOW_SOFT_INPUT,
                flags, showInputToken, resultReceiver));
    public void showSoftInput(IBinder showInputToken, @Nullable ImeTracker.Token statsToken,
            int flags, ResultReceiver resultReceiver) {
        ImeTracker.get().onProgress(statsToken, ImeTracker.PHASE_IME_WRAPPER);
        mCaller.executeOrSendMessage(mCaller.obtainMessageIOOO(DO_SHOW_SOFT_INPUT,
                flags, showInputToken, resultReceiver, statsToken));
    }

    @BinderThread
    @Override
    public void hideSoftInput(IBinder hideInputToken, int flags, ResultReceiver resultReceiver) {
        mCaller.executeOrSendMessage(mCaller.obtainMessageIOO(DO_HIDE_SOFT_INPUT,
                flags, hideInputToken, resultReceiver));
    public void hideSoftInput(IBinder hideInputToken, @Nullable ImeTracker.Token statsToken,
            int flags, ResultReceiver resultReceiver) {
        ImeTracker.get().onProgress(statsToken, ImeTracker.PHASE_IME_WRAPPER);
        mCaller.executeOrSendMessage(mCaller.obtainMessageIOOO(DO_HIDE_SOFT_INPUT,
                flags, hideInputToken, resultReceiver, statsToken));
    }

    @BinderThread
+27 −6
Original line number Diff line number Diff line
@@ -124,6 +124,7 @@ import android.view.inputmethod.CursorAnchorInfo;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.ExtractedText;
import android.view.inputmethod.ExtractedTextRequest;
import android.view.inputmethod.ImeTracker;
import android.view.inputmethod.InlineSuggestionsRequest;
import android.view.inputmethod.InlineSuggestionsResponse;
import android.view.inputmethod.InputBinding;
@@ -669,6 +670,10 @@ public class InputMethodService extends AbstractInputMethodService {
     */
    private IBinder mCurHideInputToken;

    /** The token tracking the current IME request or {@code null} otherwise. */
    @Nullable
    private ImeTracker.Token mCurStatsToken;

    final ViewTreeObserver.OnComputeInternalInsetsListener mInsetsComputer = info -> {
        onComputeInsets(mTmpInsets);
        if (!mViewsCreated) {
@@ -870,10 +875,12 @@ public class InputMethodService extends AbstractInputMethodService {
        @MainThread
        @Override
        public void hideSoftInputWithToken(int flags, ResultReceiver resultReceiver,
                IBinder hideInputToken) {
                IBinder hideInputToken, @Nullable ImeTracker.Token statsToken) {
            mSystemCallingHideSoftInput = true;
            mCurHideInputToken = hideInputToken;
            mCurStatsToken = statsToken;
            hideSoftInput(flags, resultReceiver);
            mCurStatsToken = null;
            mCurHideInputToken = null;
            mSystemCallingHideSoftInput = false;
        }
@@ -884,6 +891,7 @@ public class InputMethodService extends AbstractInputMethodService {
        @MainThread
        @Override
        public void hideSoftInput(int flags, ResultReceiver resultReceiver) {
            ImeTracker.get().onProgress(mCurStatsToken, ImeTracker.PHASE_IME_HIDE_SOFT_INPUT);
            if (DEBUG) Log.v(TAG, "hideSoftInput()");
            if (getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.R
                    && !mSystemCallingHideSoftInput) {
@@ -918,13 +926,18 @@ public class InputMethodService extends AbstractInputMethodService {
        @MainThread
        @Override
        public void showSoftInputWithToken(int flags, ResultReceiver resultReceiver,
                IBinder showInputToken) {
                IBinder showInputToken, @Nullable ImeTracker.Token statsToken) {
            mSystemCallingShowSoftInput = true;
            mCurShowInputToken = showInputToken;
            mCurStatsToken = statsToken;
            try {
                showSoftInput(flags, resultReceiver);
            } finally {
                mCurStatsToken = null;
                mCurShowInputToken = null;
                mSystemCallingShowSoftInput = false;
            }
        }

        /**
         * {@inheritDoc}
@@ -932,6 +945,7 @@ public class InputMethodService extends AbstractInputMethodService {
        @MainThread
        @Override
        public void showSoftInput(int flags, ResultReceiver resultReceiver) {
            ImeTracker.get().onProgress(mCurStatsToken, ImeTracker.PHASE_IME_SHOW_SOFT_INPUT);
            if (DEBUG) Log.v(TAG, "showSoftInput()");
            // TODO(b/148086656): Disallow IME developers from calling InputMethodImpl methods.
            if (getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.R
@@ -947,7 +961,12 @@ public class InputMethodService extends AbstractInputMethodService {
                    null /* icProto */);
            final boolean wasVisible = isInputViewShown();
            if (dispatchOnShowInputRequested(flags, false)) {
                ImeTracker.get().onProgress(mCurStatsToken,
                        ImeTracker.PHASE_IME_ON_SHOW_SOFT_INPUT_TRUE);
                showWindow(true);
            } else {
                ImeTracker.get().onFailed(mCurStatsToken,
                        ImeTracker.PHASE_IME_ON_SHOW_SOFT_INPUT_TRUE);
            }
            setImeWindowStatus(mapToImeWindowStatus(), mBackDisposition);

@@ -2923,8 +2942,10 @@ public class InputMethodService extends AbstractInputMethodService {
        ImeTracing.getInstance().triggerServiceDump(
                "InputMethodService#applyVisibilityInInsetsConsumerIfNecessary", mDumper,
                null /* icProto */);
        ImeTracker.get().onProgress(mCurStatsToken,
                ImeTracker.PHASE_IME_APPLY_VISIBILITY_INSETS_CONSUMER);
        mPrivOps.applyImeVisibilityAsync(setVisible
                ? mCurShowInputToken : mCurHideInputToken, setVisible);
                ? mCurShowInputToken : mCurHideInputToken, setVisible, mCurStatsToken);
    }

    private void finishViews(boolean finishingInput) {
+3 −2
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.view;
import android.content.ComponentName;
import android.view.InsetsSourceControl;
import android.view.InsetsState;
import android.view.inputmethod.ImeTracker;

/**
 * Singular controller of insets to use when there isn't another obvious controller available.
@@ -48,10 +49,10 @@ oneway interface IDisplayWindowInsetsController {
    /**
     * @see IWindow#showInsets
     */
    void showInsets(int types, boolean fromIme);
    void showInsets(int types, boolean fromIme, in @nullable ImeTracker.Token statsToken);

    /**
     * @see IWindow#hideInsets
     */
    void hideInsets(int types, boolean fromIme);
    void hideInsets(int types, boolean fromIme, in @nullable ImeTracker.Token statsToken);
}
+5 −2
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.view.InsetsState;
import android.view.IScrollCaptureResponseListener;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.inputmethod.ImeTracker;
import android.window.ClientWindowFrames;

import com.android.internal.os.IResultReceiver;
@@ -68,16 +69,18 @@ oneway interface IWindow {
     *
     * @param types internal insets types (WindowInsets.Type.InsetsType) to show
     * @param fromIme true if this request originated from IME (InputMethodService).
     * @param statsToken the token tracking the current IME show request or {@code null} otherwise.
     */
    void showInsets(int types, boolean fromIme);
    void showInsets(int types, boolean fromIme, in @nullable ImeTracker.Token statsToken);

    /**
     * Called when a set of insets source window should be hidden by policy.
     *
     * @param types internal insets types (WindowInsets.Type.InsetsType) to hide
     * @param fromIme true if this request originated from IME (InputMethodService).
     * @param statsToken the token tracking the current IME hide request or {@code null} otherwise.
     */
    void hideInsets(int types, boolean fromIme);
    void hideInsets(int types, boolean fromIme, in @nullable ImeTracker.Token statsToken);

    void moved(int newX, int newY);
    void dispatchAppVisibility(boolean visible);
+12 −3
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@ import android.view.WindowInsets.Type.InsetsType;
import android.view.WindowInsetsAnimation.Bounds;
import android.view.WindowManager.LayoutParams;
import android.view.animation.Interpolator;
import android.view.inputmethod.ImeTracker;

import com.android.internal.annotations.VisibleForTesting;

@@ -68,7 +69,7 @@ import java.util.Objects;
 * Implements {@link WindowInsetsAnimationController}
 * @hide
 */
@VisibleForTesting
@VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
public class InsetsAnimationControlImpl implements InternalInsetsAnimationController,
        InsetsAnimationControlRunner {

@@ -96,6 +97,8 @@ public class InsetsAnimationControlImpl implements InternalInsetsAnimationContro
    /** @see WindowInsetsAnimationController#hasZeroInsetsIme */
    private final boolean mHasZeroInsetsIme;
    private final CompatibilityInfo.Translator mTranslator;
    @Nullable
    private final ImeTracker.Token mStatsToken;
    private Insets mCurrentInsets;
    private Insets mPendingInsets;
    private float mPendingFraction;
@@ -114,7 +117,7 @@ public class InsetsAnimationControlImpl implements InternalInsetsAnimationContro
            @InsetsType int types, InsetsAnimationControlCallbacks controller, long durationMs,
            Interpolator interpolator, @AnimationType int animationType,
            @LayoutInsetsDuringAnimation int layoutInsetsDuringAnimation,
            CompatibilityInfo.Translator translator) {
            CompatibilityInfo.Translator translator, @Nullable ImeTracker.Token statsToken) {
        mControls = controls;
        mListener = listener;
        mTypes = types;
@@ -152,6 +155,7 @@ public class InsetsAnimationControlImpl implements InternalInsetsAnimationContro
        mAnimationType = animationType;
        mLayoutInsetsDuringAnimation = layoutInsetsDuringAnimation;
        mTranslator = translator;
        mStatsToken = statsToken;
        mController.startAnimation(this, listener, types, mAnimation,
                new Bounds(mHiddenInsets, mShownInsets));
    }
@@ -227,6 +231,11 @@ public class InsetsAnimationControlImpl implements InternalInsetsAnimationContro
        return mAnimationType;
    }

    @Override
    public ImeTracker.Token getStatsToken() {
        return mStatsToken;
    }

    @Override
    public void setInsetsAndAlpha(Insets insets, float alpha, float fraction) {
        setInsetsAndAlpha(insets, alpha, fraction, false /* allowWhenFinished */);
@@ -253,10 +262,10 @@ public class InsetsAnimationControlImpl implements InternalInsetsAnimationContro
        }
    }

    @VisibleForTesting
    /**
     * @return Whether the finish callback of this animation should be invoked.
     */
    @VisibleForTesting
    public boolean applyChangeInsets(@Nullable InsetsState outState) {
        if (mCancelled) {
            if (DEBUG) Log.d(TAG, "applyChangeInsets canceled");
Loading