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

Commit 6aad1e6e authored by Cosmin Băieș's avatar Cosmin Băieș
Browse files

Revert^2 "Remove synchronous startInputOrWindowGainedFocus"

This reverts commit 8ea1d0d3.

Reason for revert: fixing failure in
  StylusHandwritingTest#testOnViewClicked_withStylusHandwriting
  by removing oneway from the aidl method.

This removes the synchronous variant of startInputOrWindowGainedFocus,
resolving to the asynchronous method instead. The async one was
originally added in [1] as part of zero jank proxy. The flag was later
removed in [2], but the synchronous variant was kept due to one last
usage with WINDOW_FOCUS_GAIN_REPORT_ONLY.

This last synchronous call is now changed to be async, with the two
variants merged.

  [1]: I37fd585eeccab7c3b18fb509b3607c56d800c306
  [2]: Idbbb3c64511cb38275a4ad9c2bd7e33299ef4b56

Flag: EXEMPT cleanup
Test: atest CtsInputMethodTestCases
Bug: 418839448
Bug: 433931944
Change-Id: I72d6d791224e8b5c4299b64eaf15d685260c440b
parent 539679cd
Loading
Loading
Loading
Loading
+2 −30
Original line number Diff line number Diff line
@@ -40,7 +40,6 @@ import com.android.internal.inputmethod.IImeTracker;
import com.android.internal.inputmethod.IInputMethodClient;
import com.android.internal.inputmethod.IRemoteAccessibilityInputConnection;
import com.android.internal.inputmethod.IRemoteInputConnection;
import com.android.internal.inputmethod.InputBindResult;
import com.android.internal.inputmethod.InputMethodInfoSafeList;
import com.android.internal.inputmethod.SoftInputShowHideReason;
import com.android.internal.inputmethod.StartInputFlags;
@@ -285,39 +284,12 @@ final class IInputMethodManagerGlobalInvoker {
        }
    }

    @AnyThread
    @NonNull
    @RequiresPermission(value = Manifest.permission.INTERACT_ACROSS_USERS_FULL, conditional = true)
    static InputBindResult startInputOrWindowGainedFocus(@StartInputReason int startInputReason,
            @NonNull IInputMethodClient client, @Nullable IBinder windowToken,
            @StartInputFlags int startInputFlags,
            @WindowManager.LayoutParams.SoftInputModeFlags int softInputMode,
            @WindowManager.LayoutParams.Flags int windowFlags, @Nullable EditorInfo editorInfo,
            @Nullable IRemoteInputConnection remoteInputConnection,
            @Nullable IRemoteAccessibilityInputConnection remoteAccessibilityInputConnection,
            int unverifiedTargetSdkVersion, @UserIdInt int userId,
            @NonNull ImeOnBackInvokedDispatcher imeDispatcher, boolean imeRequestedVisible) {
        final IInputMethodManager service = getService();
        if (service == null) {
            return InputBindResult.NULL;
        }
        try {
            return service.startInputOrWindowGainedFocus(startInputReason, client, windowToken,
                    startInputFlags, softInputMode, windowFlags, editorInfo, remoteInputConnection,
                    remoteAccessibilityInputConnection, unverifiedTargetSdkVersion, userId,
                    imeDispatcher, imeRequestedVisible);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Returns a sequence number for startInput.
     */
    @AnyThread
    @NonNull
    @RequiresPermission(value = Manifest.permission.INTERACT_ACROSS_USERS_FULL, conditional = true)
    static int startInputOrWindowGainedFocusAsync(@StartInputReason int startInputReason,
    static int startInputOrWindowGainedFocus(@StartInputReason int startInputReason,
            @NonNull IInputMethodClient client, @Nullable IBinder windowToken,
            @StartInputFlags int startInputFlags,
            @WindowManager.LayoutParams.SoftInputModeFlags int softInputMode,
@@ -331,7 +303,7 @@ final class IInputMethodManagerGlobalInvoker {
            return -1;
        }
        try {
            service.startInputOrWindowGainedFocusAsync(startInputReason, client, windowToken,
            service.startInputOrWindowGainedFocus(startInputReason, client, windowToken,
                    startInputFlags, softInputMode, windowFlags, editorInfo, remoteInputConnection,
                    remoteAccessibilityInputConnection, unverifiedTargetSdkVersion, userId,
                    imeDispatcher, imeRequestedVisible, advanceAngGetStartInputSequenceNumber());
+8 −13
Original line number Diff line number Diff line
@@ -308,11 +308,8 @@ public final class InputMethodManager {
    private static final String SUBTYPE_MODE_VOICE = "voice";

    /**
     * Provide this to {@link IInputMethodManagerGlobalInvoker#startInputOrWindowGainedFocus(int,
     * IInputMethodClient, IBinder, int, int, int, EditorInfo,
     * com.android.internal.inputmethod.IRemoteInputConnection, IRemoteAccessibilityInputConnection,
     * int, int, ImeOnBackInvokedDispatcher)} to receive
     * {@link android.window.OnBackInvokedCallback} registrations from IME.
     * Provide this to {@link IInputMethodManagerGlobalInvoker#startInputOrWindowGainedFocus}
     * to receive {@link android.window.OnBackInvokedCallback} registrations from IME.
     */
    private final ImeOnBackInvokedDispatcher mImeDispatcher =
            new ImeOnBackInvokedDispatcher(Handler.getMain()) {
@@ -326,12 +323,12 @@ public final class InputMethodManager {

    /**
     * A runnable that reports {@link InputConnection} opened event for calls to
     * {@link IInputMethodManagerGlobalInvoker#startInputOrWindowGainedFocusAsync}.
     * {@link IInputMethodManagerGlobalInvoker#startInputOrWindowGainedFocus}.
     */
    private abstract static class ReportInputConnectionOpenedRunner implements Runnable {
        /**
         * Sequence number to track startInput requests to
         * {@link IInputMethodManagerGlobalInvoker#startInputOrWindowGainedFocusAsync}
         * {@link IInputMethodManagerGlobalInvoker#startInputOrWindowGainedFocus}
         */
        int mSequenceNum;
        ReportInputConnectionOpenedRunner(int sequenceNum) {
@@ -939,7 +936,6 @@ public final class InputMethodManager {

                // ignore the result
                Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "IMM.startInputOrWindowGainedFocus");
                //TODO(b/418839448): use async method.
                IInputMethodManagerGlobalInvoker.startInputOrWindowGainedFocus(
                        StartInputReason.WINDOW_FOCUS_GAIN_REPORT_ONLY, mClient,
                        viewForWindowFocus.getWindowToken(), startInputFlags, softInputMode,
@@ -3615,7 +3611,7 @@ public final class InputMethodManager {

            // async result delivered via MSG_START_INPUT_RESULT.
            final int startInputSeq =
                    IInputMethodManagerGlobalInvoker.startInputOrWindowGainedFocusAsync(
                    IInputMethodManagerGlobalInvoker.startInputOrWindowGainedFocus(
                            startInputReason, mClient, windowGainingFocus, startInputFlags,
                            softInputMode, windowFlags, editorInfo, servedInputConnection,
                            servedInputConnection == null ? null
@@ -3627,9 +3623,8 @@ public final class InputMethodManager {
            // Create a runnable for delayed notification to the app that the InputConnection is
            // initialized and ready for use.
            if (ic != null) {
                final int seqId = startInputSeq;
                if (Flags.invalidateInputCallsRestart()) {
                    mLastPendingStartSeqId = seqId;
                    mLastPendingStartSeqId = startInputSeq;
                }
                mReportInputConnectionOpenedRunner =
                        new ReportInputConnectionOpenedRunner(startInputSeq) {
@@ -3639,13 +3634,13 @@ public final class InputMethodManager {
                                    ProtoLog.v(INPUT_METHOD_MANAGER_DEBUG,
                                            "Calling View.onInputConnectionOpened: view=%s, ic=%s, "
                                                    + "editorInfo=%s, handler=%s, startInputSeq=%s",
                                            view, ic, editorInfo, icHandler, seqId);
                                            view, ic, editorInfo, icHandler, startInputSeq);
                                } else if (DEBUG) {
                                    Log.v(TAG, "Calling View.onInputConnectionOpened: view= "
                                            + view
                                            + ", ic=" + ic + ", editorInfo=" + editorInfo
                                            + ", handler="
                                            + icHandler + ", startInputSeq=" + seqId);
                                            + icHandler + ", startInputSeq=" + startInputSeq);
                                }
                                reportInputConnectionOpened(ic, editorInfo, icHandler, view);
                            }
+2 −19
Original line number Diff line number Diff line
@@ -83,29 +83,12 @@ interface IInputMethodManager {
            + "android.Manifest.permission.TEST_INPUT_METHOD)")
    oneway void hideSoftInputFromServerForTest();

    // TODO(b/418839448): merge with startInputOrWindowGainedFocus once
    //                    WINDOW_FOCUS_GAIN_REPORT_ONLY uses async method.
    // TODO(b/434184668): convert to oneway
    // If windowToken is null, this just does startInput().  Otherwise this reports that a window
    // has gained focus, and if 'editorInfo' is non-null then also does startInput.
    // @NonNull
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(value = "
            + "android.Manifest.permission.INTERACT_ACROSS_USERS_FULL, conditional = true)")
    InputBindResult startInputOrWindowGainedFocus(
            /* @StartInputReason */ int startInputReason,
            in IInputMethodClient client, in @nullable IBinder windowToken,
            /* @StartInputFlags */ int startInputFlags,
            /* @android.view.WindowManager.LayoutParams.SoftInputModeFlags */ int softInputMode,
            /* @android.view.WindowManager.LayoutParams.Flags */ int windowFlags,
            in @nullable EditorInfo editorInfo, in @nullable IRemoteInputConnection inputConnection,
            in @nullable IRemoteAccessibilityInputConnection remoteAccessibilityInputConnection,
            int unverifiedTargetSdkVersion, int userId,
            in ImeOnBackInvokedDispatcher imeDispatcher, boolean imeRequestedVisible);

    // If windowToken is null, this just does startInput().  Otherwise this reports that a window
    // has gained focus, and if 'editorInfo' is non-null then also does startInput.
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(value = "
            + "android.Manifest.permission.INTERACT_ACROSS_USERS_FULL, conditional = true)")
    void startInputOrWindowGainedFocusAsync(
    void startInputOrWindowGainedFocus(
            /* @StartInputReason */ int startInputReason,
            in IInputMethodClient client, in @nullable IBinder windowToken,
            /* @StartInputFlags */ int startInputFlags,
+7 −34
Original line number Diff line number Diff line
@@ -44,7 +44,6 @@ import com.android.internal.inputmethod.IImeTracker;
import com.android.internal.inputmethod.IInputMethodClient;
import com.android.internal.inputmethod.IRemoteAccessibilityInputConnection;
import com.android.internal.inputmethod.IRemoteInputConnection;
import com.android.internal.inputmethod.InputBindResult;
import com.android.internal.inputmethod.InputMethodInfoSafeList;
import com.android.internal.inputmethod.StartInputFlags;
import com.android.internal.inputmethod.StartInputReason;
@@ -113,27 +112,17 @@ final class IInputMethodManagerImpl extends IInputMethodManager.Stub {
        @PermissionVerified(Manifest.permission.TEST_INPUT_METHOD)
        void hideSoftInputFromServerForTest();

        void startInputOrWindowGainedFocusAsync(
                @StartInputReason int startInputReason, IInputMethodClient client,
                IBinder windowToken, @StartInputFlags int startInputFlags,
        void startInputOrWindowGainedFocus(
                @StartInputReason int startInputReason, @NonNull IInputMethodClient client,
                @Nullable IBinder windowToken, @StartInputFlags int startInputFlags,
                @WindowManager.LayoutParams.SoftInputModeFlags int softInputMode,
                @WindowManager.LayoutParams.Flags int windowFlags, @Nullable EditorInfo editorInfo,
                IRemoteInputConnection inputConnection,
                IRemoteAccessibilityInputConnection remoteAccessibilityInputConnection,
                @Nullable IRemoteInputConnection inputConnection,
                @Nullable IRemoteAccessibilityInputConnection remoteAccessibilityInputConnection,
                int unverifiedTargetSdkVersion, @UserIdInt int userId,
                @NonNull ImeOnBackInvokedDispatcher imeDispatcher, boolean imeRequestedVisible,
                int startInputSeq);

        InputBindResult startInputOrWindowGainedFocus(
                @StartInputReason int startInputReason, IInputMethodClient client,
                IBinder windowToken, @StartInputFlags int startInputFlags,
                @WindowManager.LayoutParams.SoftInputModeFlags int softInputMode,
                @WindowManager.LayoutParams.Flags int windowFlags, @Nullable EditorInfo editorInfo,
                IRemoteInputConnection inputConnection,
                IRemoteAccessibilityInputConnection remoteAccessibilityInputConnection,
                int unverifiedTargetSdkVersion, @UserIdInt int userId,
                @NonNull ImeOnBackInvokedDispatcher imeDispatcher, boolean imeRequestedVisible);

        void showInputMethodPickerFromClient(IInputMethodClient client, int auxiliarySubtypeMode);

        @PermissionVerified(allOf = {
@@ -282,23 +271,7 @@ final class IInputMethodManagerImpl extends IInputMethodManager.Stub {
    }

    @Override
    public InputBindResult startInputOrWindowGainedFocus(
            @StartInputReason int startInputReason, IInputMethodClient client, IBinder windowToken,
            @StartInputFlags int startInputFlags,
            @WindowManager.LayoutParams.SoftInputModeFlags int softInputMode,
            @WindowManager.LayoutParams.Flags int windowFlags, @Nullable EditorInfo editorInfo,
            IRemoteInputConnection inputConnection,
            IRemoteAccessibilityInputConnection remoteAccessibilityInputConnection,
            int unverifiedTargetSdkVersion, @UserIdInt int userId,
            @NonNull ImeOnBackInvokedDispatcher imeDispatcher, boolean imeRequestedVisible) {
        return mCallback.startInputOrWindowGainedFocus(
                startInputReason, client, windowToken, startInputFlags, softInputMode,
                windowFlags, editorInfo, inputConnection, remoteAccessibilityInputConnection,
                unverifiedTargetSdkVersion, userId, imeDispatcher, imeRequestedVisible);
    }

    @Override
    public void startInputOrWindowGainedFocusAsync(@StartInputReason int startInputReason,
    public void startInputOrWindowGainedFocus(@StartInputReason int startInputReason,
            IInputMethodClient client, IBinder windowToken,
            @StartInputFlags int startInputFlags,
            @WindowManager.LayoutParams.SoftInputModeFlags int softInputMode,
@@ -308,7 +281,7 @@ final class IInputMethodManagerImpl extends IInputMethodManager.Stub {
            int unverifiedTargetSdkVersion, @UserIdInt int userId,
            @NonNull ImeOnBackInvokedDispatcher imeDispatcher, boolean imeRequestedVisible,
            int startInputSeq) {
        mCallback.startInputOrWindowGainedFocusAsync(
        mCallback.startInputOrWindowGainedFocus(
                startInputReason, client, windowToken, startInputFlags, softInputMode,
                windowFlags, editorInfo, inputConnection, remoteAccessibilityInputConnection,
                unverifiedTargetSdkVersion, userId, imeDispatcher, imeRequestedVisible,
+30 −12
Original line number Diff line number Diff line
@@ -218,7 +218,7 @@ import java.util.function.IntFunction;
 * This class provides a system service that manages input methods.
 */
public final class InputMethodManagerService implements IInputMethodManagerImpl.Callback,
        ZeroJankProxy.Callback, Handler.Callback {
        Handler.Callback {

    // Virtual device id for test.
    private static final Integer VIRTUAL_STYLUS_ID_FOR_TEST = 999999;
@@ -1815,10 +1815,10 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
        }
    }

    @VisibleForTesting
    @Nullable
    @GuardedBy("ImfLock.class")
    @Override
    public ClientState getClientStateLocked(IInputMethodClient client) {
    ClientState getClientStateLocked(@NonNull IInputMethodClient client) {
        return mClientController.getClient(client.asBinder());
    }

@@ -3557,24 +3557,42 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
        return imeClientFocus == WindowManagerInternal.ImeClientFocusResult.HAS_IME_FOCUS;
    }

    //TODO(b/418839448): merge with startInputOrWindowGainedFocus once WINDOW_FOCUS_GAIN_REPORT_ONLY
    // uses async method.
    @Override
    public void startInputOrWindowGainedFocusAsync(@StartInputReason int startInputReason,
            IInputMethodClient client, IBinder windowToken, @StartInputFlags int startInputFlags,
    public void startInputOrWindowGainedFocus(
            @StartInputReason int startInputReason, @NonNull IInputMethodClient client,
            @Nullable IBinder windowToken, @StartInputFlags int startInputFlags,
            @SoftInputModeFlags int softInputMode,
            @WindowManager.LayoutParams.Flags int windowFlags, @Nullable EditorInfo editorInfo,
            IRemoteInputConnection inputConnection,
            IRemoteAccessibilityInputConnection remoteAccessibilityInputConnection,
            @Nullable IRemoteInputConnection inputConnection,
            @Nullable IRemoteAccessibilityInputConnection remoteAccessibilityInputConnection,
            int unverifiedTargetSdkVersion, @UserIdInt int userId,
            @NonNull ImeOnBackInvokedDispatcher imeDispatcher, boolean imeRequestedVisible,
            int startInputSeq) {
        // implemented by ZeroJankProxy
        final var res = startInputOrWindowGainedFocusWithResult(startInputReason, client,
                windowToken, startInputFlags, softInputMode, windowFlags, editorInfo,
                inputConnection, remoteAccessibilityInputConnection, unverifiedTargetSdkVersion,
                userId, imeDispatcher, imeRequestedVisible);
        synchronized (ImfLock.class) {
            final ClientState cs = mClientController.getClient(client.asBinder());
            if (cs != null) {
                cs.mClient.onStartInputResult(res, startInputSeq);
                // For first-time client bind, MSG_BIND should arrive after MSG_START_INPUT_RESULT.
                if (res.result == InputBindResult.ResultCode.SUCCESS_WAITING_IME_SESSION) {
                    requestClientSessionLocked(cs, userId);
                    requestClientSessionForAccessibilityLocked(cs);
                }
            } else {
                // client is unbound.
                Slog.i(TAG, "Client that requested startInputOrWindowGainedFocus is no longer"
                        + " bound. InputBindResult: " + res + " for startInputSeq: "
                        + startInputSeq);
            }
        }
    }

    @VisibleForTesting
    @NonNull
    @Override
    public InputBindResult startInputOrWindowGainedFocus(
    InputBindResult startInputOrWindowGainedFocusWithResult(
            @StartInputReason int startInputReason, IInputMethodClient client, IBinder windowToken,
            @StartInputFlags int startInputFlags, @SoftInputModeFlags int softInputMode,
            @WindowManager.LayoutParams.Flags int windowFlags, @Nullable EditorInfo editorInfo,
Loading