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

Commit f59c93b2 authored by Wilson Wu's avatar Wilson Wu
Browse files

Prevent InputMethodManager call into DelegateImpl (2/N)

InputMethodManager#DelegateImpl is a delegation for the
ImeFocusController to call InputMethodManager.

Wrap the DelegateImpl#startInput implemetation into a
dedicated method so InputMethodManger don't need to
rely on the delegation class.

Bug: 243778447
Test: atest CtsInputMethodTestCases
Change-Id: I0f98dfa5f08d51f6e9627c84f0921161374ad0e3
parent 9dc49539
Loading
Loading
Loading
Loading
+18 −11
Original line number Diff line number Diff line
@@ -718,14 +718,8 @@ public final class InputMethodManager {
            ImeTracing.getInstance().triggerClientDump(
                    "InputMethodManager.DelegateImpl#startInput", InputMethodManager.this,
                    null /* icProto */);
            synchronized (mH) {
                mCurrentEditorInfo = null;
                mCompletions = null;
                mServedConnecting = true;
            }
            return startInputInner(startInputReason,
                    focusedView != null ? focusedView.getWindowToken() : null, startInputFlags,
                    softInputMode, windowFlags);
            return startInputOnWindowFocusGainInternal(startInputReason, focusedView,
                    startInputFlags, softInputMode, windowFlags);
        }

        /**
@@ -800,7 +794,7 @@ public final class InputMethodManager {
                // should be done in conjunction with telling the system service
                // about the window gaining focus, to help make the transition
                // smooth.
                if (startInput(StartInputReason.WINDOW_FOCUS_GAIN,
                if (startInputOnWindowFocusGainInternal(StartInputReason.WINDOW_FOCUS_GAIN,
                        focusedView, startInputFlags, softInputMode, windowFlags)) {
                    return;
                }
@@ -924,6 +918,19 @@ public final class InputMethodManager {
        }
    }

    private boolean startInputOnWindowFocusGainInternal(@StartInputReason int startInputReason,
            View focusedView, @StartInputFlags int startInputFlags,
            @SoftInputModeFlags int softInputMode, int windowFlags) {
        synchronized (mH) {
            mCurrentEditorInfo = null;
            mCompletions = null;
            mServedConnecting = true;
        }
        return startInputInner(startInputReason,
                focusedView != null ? focusedView.getWindowToken() : null, startInputFlags,
                softInputMode, windowFlags);
    }

    @GuardedBy("mH")
    private View getServedViewLocked() {
        return mCurRootView != null ? mCurRootView.getImeFocusController().getServedViewLocked()
@@ -1136,7 +1143,7 @@ public final class InputMethodManager {
                                    .checkFocus(mRestartOnNextWindowFocus, false)) {
                                final int reason = active ? StartInputReason.ACTIVATED_BY_IMMS
                                        : StartInputReason.DEACTIVATED_BY_IMMS;
                                mDelegate.startInput(reason, null, 0, 0, 0);
                                startInputOnWindowFocusGainInternal(reason, null, 0, 0, 0);
                            }
                        }
                    }
@@ -2357,7 +2364,7 @@ public final class InputMethodManager {
            // The view is running on a different thread than our own, so
            // we need to reschedule our work for over there.
            if (DEBUG) Log.v(TAG, "Starting input: reschedule to view thread");
            vh.post(() -> mDelegate.startInput(startInputReason, null, 0, 0, 0));
            vh.post(() -> startInputOnWindowFocusGainInternal(startInputReason, null, 0, 0, 0));
            return false;
        }