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

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

Remove synchronous startInputOrWindowGainedFocus

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. Additionally, the aidl method is now marked oneway.

  [1]: I37fd585eeccab7c3b18fb509b3607c56d800c306
  [2]: Idbbb3c64511cb38275a4ad9c2bd7e33299ef4b56

Flag: EXEMPT cleanup
Test: atest CtsInputMethodTestCases
Bug: 418839448
Change-Id: Idf95bdd274a78243a86958286d9ba6a140957515
parent e3131a9b
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;
@@ -308,39 +307,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,
@@ -354,7 +326,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
@@ -307,11 +307,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()) {
@@ -325,12 +322,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) {
@@ -934,7 +931,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,
@@ -3588,7 +3584,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
@@ -3600,9 +3596,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) {
@@ -3612,13 +3607,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);
                            }
+1 −19
Original line number Diff line number Diff line
@@ -83,29 +83,11 @@ interface IInputMethodManager {
            + "android.Manifest.permission.TEST_INPUT_METHOD)")
    void hideSoftInputFromServerForTest();

    // TODO(b/418839448): merge with startInputOrWindowGainedFocus once
    //                    WINDOW_FOCUS_GAIN_REPORT_ONLY uses async method.
    // 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(
    oneway 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 = {
@@ -287,23 +276,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,
@@ -313,7 +286,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,
+27 −9
Original line number Diff line number Diff line
@@ -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 = getClientStateLocked(client);
            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