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

Commit 3c1d8be8 authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Pass InputMethodBindingController when possible in IMMS

This is a mechcanical refactoring CL that aims to simplify the code by
taking advantage of per-user InputMethodBindingController instance we
recently introduced [1].

There must be no observable behavior change.

 [1]: Id6e9eca6caaa8edde8c4a405448c31c0ca986509
      2238ecd4

Bug: 325515685
Test: presubmit
Change-Id: Ic0b99af73343078696097dc966993212bca623fc
parent e03efadb
Loading
Loading
Loading
Loading
+14 −15
Original line number Diff line number Diff line
@@ -2037,7 +2037,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
            @StartInputReason int startInputReason,
            int unverifiedTargetSdkVersion,
            @NonNull ImeOnBackInvokedDispatcher imeDispatcher,
            @NonNull UserDataRepository.UserData userData) {
            @NonNull InputMethodBindingController bindingController) {

        // Compute the final shown display ID with validated cs.selfReportedDisplayId for this
        // session & other conditions.
@@ -2078,7 +2078,6 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
        final boolean connectionWasActive = mCurInputConnection != null;

        // Bump up the sequence for this client and attach it.
        final var bindingController = userData.mBindingController;
        bindingController.advanceSequenceNumber();

        mCurClient = cs;
@@ -2138,7 +2137,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
                        (startInputFlags & StartInputFlags.INITIAL_CONNECTION) != 0);
            }

            InputBindResult bindResult = tryReuseConnectionLocked(userData, cs);
            InputBindResult bindResult = tryReuseConnectionLocked(bindingController, cs);
            if (bindResult != null) {
                return bindResult;
            }
@@ -2252,9 +2251,8 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.

    @GuardedBy("ImfLock.class")
    @Nullable
    private InputBindResult tryReuseConnectionLocked(@NonNull UserDataRepository.UserData userData,
            @NonNull ClientState cs) {
        final var bindingController = userData.mBindingController;
    private InputBindResult tryReuseConnectionLocked(
            @NonNull InputMethodBindingController bindingController, @NonNull ClientState cs) {
        if (bindingController.hasMainConnection()) {
            if (getCurMethodLocked() != null) {
                // Return to client, and we will get back with it when
@@ -3641,7 +3639,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
                    result = startInputOrWindowGainedFocusInternalLocked(startInputReason,
                            client, windowToken, startInputFlags, softInputMode, windowFlags,
                            editorInfo, inputConnection, remoteAccessibilityInputConnection,
                            unverifiedTargetSdkVersion, userData, imeDispatcher, cs);
                            unverifiedTargetSdkVersion, bindingController, imeDispatcher, cs);
                } finally {
                    Binder.restoreCallingIdentity(ident);
                }
@@ -3669,7 +3667,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
            @SoftInputModeFlags int softInputMode, int windowFlags, EditorInfo editorInfo,
            IRemoteInputConnection inputContext,
            @Nullable IRemoteAccessibilityInputConnection remoteAccessibilityInputConnection,
            int unverifiedTargetSdkVersion, @NonNull UserDataRepository.UserData userData,
            int unverifiedTargetSdkVersion, @NonNull InputMethodBindingController bindingController,
            @NonNull ImeOnBackInvokedDispatcher imeDispatcher, @NonNull ClientState cs) {
        if (DEBUG) {
            Slog.v(TAG, "startInputOrWindowGainedFocusInternalLocked: reason="
@@ -3682,7 +3680,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
                    + " softInputMode=" + InputMethodDebug.softInputModeToString(softInputMode)
                    + " windowFlags=#" + Integer.toHexString(windowFlags)
                    + " unverifiedTargetSdkVersion=" + unverifiedTargetSdkVersion
                    + " userData=" + userData
                    + " bindingController=" + bindingController
                    + " imeDispatcher=" + imeDispatcher
                    + " cs=" + cs);
        }
@@ -3711,15 +3709,16 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
            if (editorInfo != null) {
                return startInputUncheckedLocked(cs, inputContext,
                        remoteAccessibilityInputConnection, editorInfo, startInputFlags,
                        startInputReason, unverifiedTargetSdkVersion, imeDispatcher, userData);
                        startInputReason, unverifiedTargetSdkVersion, imeDispatcher,
                        bindingController);
            }
            return new InputBindResult(
                    InputBindResult.ResultCode.SUCCESS_REPORT_WINDOW_FOCUS_ONLY,
                    null, null, null, null, -1, false);
        }

        mImeBindingState = new ImeBindingState(userData.mUserId, windowToken, softInputMode, cs,
                editorInfo);
        mImeBindingState = new ImeBindingState(bindingController.mUserId, windowToken,
                softInputMode, cs, editorInfo);
        mFocusedWindowPerceptible.put(windowToken, true);

        // We want to start input before showing the IME, but after closing
@@ -3744,7 +3743,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
                        res = startInputUncheckedLocked(cs, inputContext,
                                remoteAccessibilityInputConnection, editorInfo, startInputFlags,
                                startInputReason, unverifiedTargetSdkVersion,
                                imeDispatcher, userData);
                                imeDispatcher, bindingController);
                        didStart = true;
                    }
                    break;
@@ -3759,7 +3758,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
                // Note that we can trust client's display ID as long as it matches
                // to the display ID obtained from the window.
                if (cs.mSelfReportedDisplayId != getCurTokenDisplayIdLocked()) {
                    userData.mBindingController.unbindCurrentMethod();
                    bindingController.unbindCurrentMethod();
                }
            }
        }
@@ -3768,7 +3767,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
                res = startInputUncheckedLocked(cs, inputContext,
                        remoteAccessibilityInputConnection, editorInfo, startInputFlags,
                        startInputReason, unverifiedTargetSdkVersion,
                        imeDispatcher, userData);
                        imeDispatcher, bindingController);
            } else {
                res = InputBindResult.NULL_EDITOR_INFO;
            }