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

Commit 662b48b7 authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Switch back to sync IInputMethodManager

This CL logically reverts recent CLs [1][2][3][4][5][6][7][8][9] to
switch back to the previous sync IPC approach in IInputMethodManager
except for the following two IPCs.

 * reportPerceptibleAsync
 * removeImeSurfaceFromWindowAsync

Reason for revert:
We need more time to understand its performance implications.

 [1]: If4b40244a2e0e3b11c38c1da9340ba8e5166ad64
      b9590fa1
 [2]: If79e063641a01b325c63eb9f871f5b992d7c0b72
      5a5648dc
 [3]: I1547b98b2aacf764e33aadc9ab784f2013f58f2f
      d833f0da
 [4]: I646ef4ae0570aae1812ea267f309441fdec6938d
      38fd0206
 [5]: Iaa63e01453da4ff0e3f446eac036b3be3180cb73
      4a820ccc
 [6]: Id516fd1c961f43ac3e139c88d7ed004c188d458b
      0a32fd21
 [7]: Icb396ae5d74060af69c4ecb16723b2e37b9f2067
      c4663ba6
 [8]: I3eafbc28ed3acf3ba859885bf201cb06b3149b94
      f226a79f
 [9]: Ic584203c1221fbae17f5e2d8f09e3992df061646
      5e2d9f27

Bug: 163453493
Bug: 174892351
Fix: 190486491
Test: atest CtsInputMethodTestCases
Change-Id: If16ac0de536d9089eb04f6e07b1ee47378124658
parent c762d54a
Loading
Loading
Loading
Loading
+1 −5
Original line number Diff line number Diff line
@@ -27,8 +27,6 @@ import android.util.Log;
import android.util.proto.ProtoOutputStream;
import android.view.inputmethod.InputMethodManager;

import com.android.internal.inputmethod.Completable;
import com.android.internal.inputmethod.ResultCallbacks;
import com.android.internal.view.IInputMethodManager;

import java.io.PrintWriter;
@@ -92,9 +90,7 @@ public abstract class ImeTracing {
     * @param where
     */
    public void sendToService(byte[] protoDump, int source, String where) throws RemoteException {
        final Completable.Void value = Completable.createVoid();
        mService.startProtoDump(protoDump, source, where, ResultCallbacks.of(value));
        Completable.getResult(value);
        mService.startProtoDump(protoDump, source, where);
    }

    /**
+1 −6
Original line number Diff line number Diff line
@@ -24,9 +24,6 @@ import android.util.Log;
import android.util.proto.ProtoOutputStream;
import android.view.inputmethod.InputMethodManager;

import com.android.internal.inputmethod.Completable;
import com.android.internal.inputmethod.ResultCallbacks;

import java.io.PrintWriter;

/**
@@ -34,9 +31,7 @@ import java.io.PrintWriter;
 */
class ImeTracingClientImpl extends ImeTracing {
    ImeTracingClientImpl() throws ServiceNotFoundException, RemoteException {
        final Completable.Boolean value = Completable.createBoolean();
        mService.isImeTraceEnabled(ResultCallbacks.of(value));
        sEnabled = Completable.getResult(value);
        sEnabled = mService.isImeTraceEnabled();
    }

    @Override
+34 −104
Original line number Diff line number Diff line
@@ -88,10 +88,8 @@ import android.view.WindowManager.LayoutParams.SoftInputModeFlags;
import android.view.autofill.AutofillManager;

import com.android.internal.annotations.GuardedBy;
import com.android.internal.inputmethod.Completable;
import com.android.internal.inputmethod.InputMethodDebug;
import com.android.internal.inputmethod.InputMethodPrivilegedOperationsRegistry;
import com.android.internal.inputmethod.ResultCallbacks;
import com.android.internal.inputmethod.SoftInputShowHideReason;
import com.android.internal.inputmethod.StartInputFlags;
import com.android.internal.inputmethod.StartInputReason;
@@ -265,14 +263,6 @@ public final class InputMethodManager {

    private static final int NOT_A_SUBTYPE_ID = -1;

    /**
     * {@code true} to try to avoid blocking apps' UI thread by sending
     * {@link StartInputReason#WINDOW_FOCUS_GAIN_REPORT_WITH_CONNECTION} and
     * {@link StartInputReason#WINDOW_FOCUS_GAIN_REPORT_WITHOUT_CONNECTION} in a truly asynchronous
     * way. {@code false} to go back to the previous synchronous semantics.
     */
    private static final boolean USE_REPORT_WINDOW_GAINED_FOCUS_ASYNC = true;

    /**
     * A constant that represents Voice IME.
     *
@@ -686,17 +676,10 @@ public final class InputMethodManager {
                                + ", nextFocusIsServedView=" + nextFocusHasConnection);
                    }

                    if (USE_REPORT_WINDOW_GAINED_FOCUS_ASYNC) {
                        mService.reportWindowGainedFocusAsync(
                                nextFocusHasConnection, mClient, focusedView.getWindowToken(),
                                startInputFlags, softInputMode, windowFlags,
                                mCurRootView.mContext.getApplicationInfo().targetSdkVersion);
                    } else {
                    final int startInputReason = nextFocusHasConnection
                            ? WINDOW_FOCUS_GAIN_REPORT_WITH_CONNECTION
                            : WINDOW_FOCUS_GAIN_REPORT_WITHOUT_CONNECTION;
                        final Completable.InputBindResult value =
                                Completable.createInputBindResult();
                    // ignore the result
                    mService.startInputOrWindowGainedFocus(
                            startInputReason, mClient,
                            focusedView.getWindowToken(), startInputFlags, softInputMode,
@@ -704,10 +687,7 @@ public final class InputMethodManager {
                            null,
                            null,
                            0 /* missingMethodFlags */,
                                mCurRootView.mContext.getApplicationInfo().targetSdkVersion,
                                ResultCallbacks.of(value));
                        Completable.getResult(value); // ignore the result
                    }
                            mCurRootView.mContext.getApplicationInfo().targetSdkVersion);
                } catch (RemoteException e) {
                    throw e.rethrowFromSystemServer();
                }
@@ -1249,9 +1229,7 @@ public final class InputMethodManager {
            // We intentionally do not use UserHandle.getCallingUserId() here because for system
            // services InputMethodManagerInternal.getInputMethodListAsUser() should be used
            // instead.
            final Completable.InputMethodInfoList value = Completable.createInputMethodInfoList();
            mService.getInputMethodList(UserHandle.myUserId(), ResultCallbacks.of(value));
            return Completable.getResult(value);
            return mService.getInputMethodList(UserHandle.myUserId());
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -1269,9 +1247,7 @@ public final class InputMethodManager {
    @NonNull
    public List<InputMethodInfo> getInputMethodListAsUser(@UserIdInt int userId) {
        try {
            final Completable.InputMethodInfoList value = Completable.createInputMethodInfoList();
            mService.getInputMethodList(userId,  ResultCallbacks.of(value));
            return Completable.getResult(value);
            return mService.getInputMethodList(userId);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -1289,9 +1265,7 @@ public final class InputMethodManager {
            // We intentionally do not use UserHandle.getCallingUserId() here because for system
            // services InputMethodManagerInternal.getEnabledInputMethodListAsUser() should be used
            // instead.
            final Completable.InputMethodInfoList value = Completable.createInputMethodInfoList();
            mService.getEnabledInputMethodList(UserHandle.myUserId(), ResultCallbacks.of(value));
            return Completable.getResult(value);
            return mService.getEnabledInputMethodList(UserHandle.myUserId());
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -1307,9 +1281,7 @@ public final class InputMethodManager {
    @RequiresPermission(INTERACT_ACROSS_USERS_FULL)
    public List<InputMethodInfo> getEnabledInputMethodListAsUser(@UserIdInt int userId) {
        try {
            final Completable.InputMethodInfoList value = Completable.createInputMethodInfoList();
            mService.getEnabledInputMethodList(userId, ResultCallbacks.of(value));
            return Completable.getResult(value);
            return mService.getEnabledInputMethodList(userId);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -1328,13 +1300,9 @@ public final class InputMethodManager {
    public List<InputMethodSubtype> getEnabledInputMethodSubtypeList(InputMethodInfo imi,
            boolean allowsImplicitlySelectedSubtypes) {
        try {
            final Completable.InputMethodSubtypeList value =
                    Completable.createInputMethodSubtypeList();
            mService.getEnabledInputMethodSubtypeList(
            return mService.getEnabledInputMethodSubtypeList(
                    imi == null ? null : imi.getId(),
                    allowsImplicitlySelectedSubtypes,
                    ResultCallbacks.of(value));
            return Completable.getResult(value);
                    allowsImplicitlySelectedSubtypes);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -1669,15 +1637,12 @@ public final class InputMethodManager {
            try {
                Log.d(TAG, "showSoftInput() view=" + view + " flags=" + flags + " reason="
                        + InputMethodDebug.softInputDisplayReasonToString(reason));
                final Completable.Boolean value = Completable.createBoolean();
                mService.showSoftInput(
                return mService.showSoftInput(
                        mClient,
                        view.getWindowToken(),
                        flags,
                        resultReceiver,
                        reason,
                        ResultCallbacks.of(value));
                return Completable.getResult(value);
                        reason);
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
@@ -1704,15 +1669,12 @@ public final class InputMethodManager {
                    Log.w(TAG, "No current root view, ignoring showSoftInputUnchecked()");
                    return;
                }
                final Completable.Boolean value = Completable.createBoolean();
                mService.showSoftInput(
                        mClient,
                        mCurRootView.getView().getWindowToken(),
                        flags,
                        resultReceiver,
                        SoftInputShowHideReason.SHOW_SOFT_INPUT,
                        ResultCallbacks.of(value));
                Completable.getResult(value); // ignore the result
                        SoftInputShowHideReason.SHOW_SOFT_INPUT);
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
@@ -1791,10 +1753,7 @@ public final class InputMethodManager {
            }

            try {
                final Completable.Boolean value = Completable.createBoolean();
                mService.hideSoftInput(mClient, windowToken, flags, resultReceiver, reason,
                        ResultCallbacks.of(value));
                return Completable.getResult(value);
                return mService.hideSoftInput(mClient, windowToken, flags, resultReceiver, reason);
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
@@ -2030,13 +1989,10 @@ public final class InputMethodManager {
                        + InputMethodDebug.startInputFlagsToString(startInputFlags));
            }
            try {
                final Completable.InputBindResult value = Completable.createInputBindResult();
                mService.startInputOrWindowGainedFocus(
                res = mService.startInputOrWindowGainedFocus(
                        startInputReason, mClient, windowGainingFocus, startInputFlags,
                        softInputMode, windowFlags, tba, servedContext, missingMethodFlags,
                        view.getContext().getApplicationInfo().targetSdkVersion,
                        ResultCallbacks.of(value));
                res = Completable.getResult(value);
                        view.getContext().getApplicationInfo().targetSdkVersion);
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
@@ -2144,15 +2100,12 @@ public final class InputMethodManager {
                return;
            }
            try {
                final Completable.Boolean value = Completable.createBoolean();
                mService.hideSoftInput(
                        mClient,
                        mCurRootView.getView().getWindowToken(),
                        HIDE_NOT_ALWAYS,
                        null,
                        SoftInputShowHideReason.HIDE_SOFT_INPUT,
                        ResultCallbacks.of(value));
                Completable.getResult(value); // ignore the result
                        SoftInputShowHideReason.HIDE_SOFT_INPUT);
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
@@ -2832,10 +2785,7 @@ public final class InputMethodManager {
                ? SHOW_IM_PICKER_MODE_INCLUDE_AUXILIARY_SUBTYPES
                : SHOW_IM_PICKER_MODE_EXCLUDE_AUXILIARY_SUBTYPES;
        try {
            final Completable.Void value = Completable.createVoid();
            mService.showInputMethodPickerFromSystem(
                    mClient, mode, displayId, ResultCallbacks.of(value));
            Completable.getResult(value);
            mService.showInputMethodPickerFromSystem(mClient, mode, displayId);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -2843,10 +2793,7 @@ public final class InputMethodManager {

    private void showInputMethodPickerLocked() {
        try {
            final Completable.Void value = Completable.createVoid();
            mService.showInputMethodPickerFromClient(
                    mClient, SHOW_IM_PICKER_MODE_AUTO, ResultCallbacks.of(value));
            Completable.getResult(value);
            mService.showInputMethodPickerFromClient(mClient, SHOW_IM_PICKER_MODE_AUTO);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -2866,9 +2813,7 @@ public final class InputMethodManager {
    @TestApi
    public boolean isInputMethodPickerShown() {
        try {
            final Completable.Boolean value = Completable.createBoolean();
            mService.isInputMethodPickerShownForTest(ResultCallbacks.of(value));
            return Completable.getResult(value);
            return mService.isInputMethodPickerShownForTest();
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -2882,10 +2827,7 @@ public final class InputMethodManager {
     */
    public void showInputMethodAndSubtypeEnabler(String imiId) {
        try {
            final Completable.Void value = Completable.createVoid();
            mService.showInputMethodAndSubtypeEnablerFromClient(
                    mClient, imiId, ResultCallbacks.of(value));
            Completable.getResult(value);
            mService.showInputMethodAndSubtypeEnablerFromClient(mClient, imiId);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -2898,9 +2840,7 @@ public final class InputMethodManager {
     */
    public InputMethodSubtype getCurrentInputMethodSubtype() {
        try {
            final Completable.InputMethodSubtype value = Completable.createInputMethodSubtype();
            mService.getCurrentInputMethodSubtype(ResultCallbacks.of(value));
            return Completable.getResult(value);
            return mService.getCurrentInputMethodSubtype();
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -2949,11 +2889,7 @@ public final class InputMethodManager {
        }
        final List<InputMethodSubtype> enabledSubtypes;
        try {
            final Completable.InputMethodSubtypeList value =
                    Completable.createInputMethodSubtypeList();
            mService.getEnabledInputMethodSubtypeList(
                    imeId, true, ResultCallbacks.of(value));
            enabledSubtypes = Completable.getResult(value);
            enabledSubtypes = mService.getEnabledInputMethodSubtypeList(imeId, true);
        } catch (RemoteException e) {
            return false;
        }
@@ -3021,9 +2957,7 @@ public final class InputMethodManager {
    @UnsupportedAppUsage
    public int getInputMethodWindowVisibleHeight() {
        try {
            final Completable.Int value = Completable.createInt();
            mService.getInputMethodWindowVisibleHeight(ResultCallbacks.of(value));
            return Completable.getIntResult(value);
            return mService.getInputMethodWindowVisibleHeight();
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -3118,9 +3052,7 @@ public final class InputMethodManager {
    @Deprecated
    public void setAdditionalInputMethodSubtypes(String imiId, InputMethodSubtype[] subtypes) {
        try {
            final Completable.Void value = Completable.createVoid();
            mService.setAdditionalInputMethodSubtypes(imiId, subtypes, ResultCallbacks.of(value));
            Completable.getResult(value);
            mService.setAdditionalInputMethodSubtypes(imiId, subtypes);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
@@ -3128,9 +3060,7 @@ public final class InputMethodManager {

    public InputMethodSubtype getLastInputMethodSubtype() {
        try {
            final Completable.InputMethodSubtype value = Completable.createInputMethodSubtype();
            mService.getLastInputMethodSubtype(ResultCallbacks.of(value));
            return Completable.getResult(value);
            return mService.getLastInputMethodSubtype();
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
+25 −45
Original line number Diff line number Diff line
@@ -24,13 +24,6 @@ import android.view.inputmethod.EditorInfo;
import com.android.internal.view.InputBindResult;
import com.android.internal.view.IInputContext;
import com.android.internal.view.IInputMethodClient;
import com.android.internal.inputmethod.IBooleanResultCallback;
import com.android.internal.inputmethod.IInputBindResultResultCallback;
import com.android.internal.inputmethod.IInputMethodInfoListResultCallback;
import com.android.internal.inputmethod.IInputMethodSubtypeResultCallback;
import com.android.internal.inputmethod.IInputMethodSubtypeListResultCallback;
import com.android.internal.inputmethod.IIntResultCallback;
import com.android.internal.inputmethod.IVoidResultCallback;

/**
 * Public interface to the global input method manager, used by all client
@@ -41,64 +34,51 @@ interface IInputMethodManager {
            int untrustedDisplayId);

    // TODO: Use ParceledListSlice instead
    oneway void getInputMethodList(int userId,
            in IInputMethodInfoListResultCallback resultCallback);
    List<InputMethodInfo> getInputMethodList(int userId);
    // TODO: Use ParceledListSlice instead
    oneway void getEnabledInputMethodList(int userId,
            in IInputMethodInfoListResultCallback resultCallback);
    oneway void getEnabledInputMethodSubtypeList(in String imiId,
            boolean allowsImplicitlySelectedSubtypes,
            in IInputMethodSubtypeListResultCallback resultCallback);
    oneway void getLastInputMethodSubtype(in IInputMethodSubtypeResultCallback resultCallback);
    List<InputMethodInfo> getEnabledInputMethodList(int userId);
    List<InputMethodSubtype> getEnabledInputMethodSubtypeList(in String imiId,
            boolean allowsImplicitlySelectedSubtypes);
    InputMethodSubtype getLastInputMethodSubtype();

    oneway void showSoftInput(in IInputMethodClient client, IBinder windowToken, int flags,
            in ResultReceiver resultReceiver, int reason, in IBooleanResultCallback resultCallback);
    oneway void hideSoftInput(in IInputMethodClient client, IBinder windowToken, int flags,
            in ResultReceiver resultReceiver, int reason, in IBooleanResultCallback resultCallback);
    boolean showSoftInput(in IInputMethodClient client, IBinder windowToken, int flags,
            in ResultReceiver resultReceiver, int reason);
    boolean hideSoftInput(in IInputMethodClient client, IBinder windowToken, int flags,
            in ResultReceiver resultReceiver, int reason);
    // If windowToken is null, this just does startInput().  Otherwise this reports that a window
    // has gained focus, and if 'attribute' is non-null then also does startInput.
    // @NonNull
    oneway void startInputOrWindowGainedFocus(
    InputBindResult startInputOrWindowGainedFocus(
            /* @StartInputReason */ int startInputReason,
            in IInputMethodClient client, in IBinder windowToken,
            /* @StartInputFlags */ int startInputFlags,
            /* @android.view.WindowManager.LayoutParams.SoftInputModeFlags */ int softInputMode,
            int windowFlags, in EditorInfo attribute, IInputContext inputContext,
            /* @InputConnectionInspector.MissingMethodFlags */ int missingMethodFlags,
            int unverifiedTargetSdkVersion,
            in IInputBindResultResultCallback inputBindResult);
            int unverifiedTargetSdkVersion);

    oneway void reportWindowGainedFocusAsync(
            boolean nextFocusHasConnection, in IInputMethodClient client, in IBinder windowToken,
            /* @StartInputFlags */ int startInputFlags,
            /* @android.view.WindowManager.LayoutParams.SoftInputModeFlags */ int softInputMode,
            int windowFlags, int unverifiedTargetSdkVersion);

    oneway void showInputMethodPickerFromClient(in IInputMethodClient client,
            int auxiliarySubtypeMode, in IVoidResultCallback resultCallback);
    oneway void showInputMethodPickerFromSystem(in IInputMethodClient client,
            int auxiliarySubtypeMode, int displayId, in IVoidResultCallback resultCallback);
    oneway void showInputMethodAndSubtypeEnablerFromClient(in IInputMethodClient client,
            String topId, in IVoidResultCallback resultCallback);
    oneway void isInputMethodPickerShownForTest(in IBooleanResultCallback resultCallback);
    oneway void getCurrentInputMethodSubtype(in IInputMethodSubtypeResultCallback resultCallback);
    oneway void setAdditionalInputMethodSubtypes(String id, in InputMethodSubtype[] subtypes,
            in IVoidResultCallback resultCallback);
    void showInputMethodPickerFromClient(in IInputMethodClient client,
            int auxiliarySubtypeMode);
    void showInputMethodPickerFromSystem(in IInputMethodClient client,
            int auxiliarySubtypeMode, int displayId);
    void showInputMethodAndSubtypeEnablerFromClient(in IInputMethodClient client, String topId);
    boolean isInputMethodPickerShownForTest();
    InputMethodSubtype getCurrentInputMethodSubtype();
    void setAdditionalInputMethodSubtypes(String id, in InputMethodSubtype[] subtypes);
    // This is kept due to @UnsupportedAppUsage.
    // TODO(Bug 113914148): Consider removing this.
    oneway void getInputMethodWindowVisibleHeight(IIntResultCallback resultCallback);
    int getInputMethodWindowVisibleHeight();

    oneway void reportPerceptibleAsync(in IBinder windowToken, boolean perceptible);
    /** Remove the IME surface. Requires INTERNAL_SYSTEM_WINDOW permission. */
    oneway void removeImeSurface(in IVoidResultCallback resultCallback);
    void removeImeSurface();
    /** Remove the IME surface. Requires passing the currently focused window. */
    oneway void removeImeSurfaceFromWindowAsync(in IBinder windowToken);
    oneway void startProtoDump(in byte[] protoDump, int source, String where,
            in IVoidResultCallback resultCallback);
    oneway void isImeTraceEnabled(in IBooleanResultCallback resultCallback);
    void startProtoDump(in byte[] protoDump, int source, String where);
    boolean isImeTraceEnabled();

    // Starts an ime trace.
    oneway void startImeTrace(in IVoidResultCallback resultCallback);
    void startImeTrace();
    // Stops an ime trace.
    oneway void stopImeTrace(in IVoidResultCallback resultCallback);
    void stopImeTrace();
}
+1 −5
Original line number Diff line number Diff line
@@ -42,8 +42,6 @@ import android.view.animation.PathInterpolator;
import androidx.annotation.BinderThread;
import androidx.annotation.VisibleForTesting;

import com.android.internal.inputmethod.Completable;
import com.android.internal.inputmethod.ResultCallbacks;
import com.android.internal.view.IInputMethodManager;

import java.util.ArrayList;
@@ -540,9 +538,7 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged
            try {
                // Remove the IME surface to make the insets invisible for
                // non-client controlled insets.
                final Completable.Void value = Completable.createVoid();
                imms.removeImeSurface(ResultCallbacks.of(value));
                Completable.getResult(value);
                imms.removeImeSurface();
            } catch (RemoteException e) {
                Slog.e(TAG, "Failed to remove IME surface.", e);
            }
Loading