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

Commit 90ce33c3 authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Introduce StartInputReason.SCHEDULED_CHECK_FOCUS

With this CL,

  adb shell dumpsys input_method,

tells us about whether startInputInner() is triggered by

  InputMethodManager.DelegateImpl#onScheduledCheckFocus()

or

  InputMethodManager#checkFocus().

Other than that there must be no observable behavior change.

Bug: 234882948
Test: presubmit
Change-Id: I54ebf1a4e1f749ce265756908ef52fc63f1218e5
parent 26b50d8f
Loading
Loading
Loading
Loading
+16 −14
Original line number Diff line number Diff line
@@ -789,7 +789,7 @@ public final class InputMethodManager {
                }
            }

            if (checkFocusInternal(forceNewFocus, false, viewRootImpl)) {
            if (checkFocusInternal(forceNewFocus, viewRootImpl)) {
                // We need to restart input on the current focus view.  This
                // should be done in conjunction with telling the system service
                // about the window gaining focus, to help make the transition
@@ -826,7 +826,12 @@ public final class InputMethodManager {

        @Override
        public void onScheduledCheckFocus(@NonNull ViewRootImpl viewRootImpl) {
            checkFocusInternal(false, true, viewRootImpl);
            if (!checkFocusInternal(false, viewRootImpl)) {
                return;
            }
            startInputOnWindowFocusGainInternal(StartInputReason.SCHEDULED_CHECK_FOCUS,
                    null /* focusedView */, 0 /* startInputFlags */, 0 /* softInputMode */,
                    0 /* windowFlags */);
        }

        @Override
@@ -1118,7 +1123,7 @@ public final class InputMethodManager {
                        if (mCurRootView == null) {
                            return;
                        }
                        if (!checkFocusInternal(mRestartOnNextWindowFocus, false, mCurRootView)) {
                        if (!checkFocusInternal(mRestartOnNextWindowFocus, mCurRootView)) {
                            return;
                        }
                        final int reason = active ? StartInputReason.ACTIVATED_BY_IMMS
@@ -2338,8 +2343,7 @@ public final class InputMethodManager {
    }

    /**
     * Called from {@link #checkFocusInternal(boolean, boolean, ViewRootImpl)},
     * {@link #restartInput(View)}, {@link #MSG_BIND} or {@link #MSG_UNBIND}.
     * Starts an input connection from the served view that gains the window focus.
     * Note that this method should *NOT* be called inside of {@code mH} lock to prevent start input
     * background thread may blocked by other methods which already inside {@code mH} lock.
     */
@@ -2660,14 +2664,18 @@ public final class InputMethodManager {
            }
            viewRootImpl = mCurRootView;
        }
        checkFocusInternal(false /* forceNewFocus */, true /* startInput */, viewRootImpl);
        if (!checkFocusInternal(false /* forceNewFocus */, viewRootImpl)) {
            return;
        }
        startInputOnWindowFocusGainInternal(StartInputReason.CHECK_FOCUS,
                null /* focusedView */,
                0 /* startInputFlags */, 0 /* softInputMode */, 0 /* windowFlags */);
    }

    /**
     * Check the next served view if needs to start input.
     */
    private boolean checkFocusInternal(boolean forceNewFocus, boolean startInput,
            ViewRootImpl viewRootImpl) {
    private boolean checkFocusInternal(boolean forceNewFocus, ViewRootImpl viewRootImpl) {
        synchronized (mH) {
            if (mCurRootView != viewRootImpl) {
                return false;
@@ -2694,12 +2702,6 @@ public final class InputMethodManager {
                mServedInputConnection.finishComposingTextFromImm();
            }
        }

        if (startInput) {
            startInputOnWindowFocusGainInternal(StartInputReason.CHECK_FOCUS,
                    null /* focusedView */,
                    0 /* startInputFlags */, 0 /* softInputMode */, 0 /* windowFlags */);
        }
        return true;
    }

+2 −0
Original line number Diff line number Diff line
@@ -49,6 +49,8 @@ public final class InputMethodDebug {
                return "WINDOW_FOCUS_GAIN";
            case StartInputReason.WINDOW_FOCUS_GAIN_REPORT_ONLY:
                return "WINDOW_FOCUS_GAIN_REPORT_ONLY";
            case StartInputReason.SCHEDULED_CHECK_FOCUS:
                return "SCHEDULED_CHECK_FOCUS";
            case StartInputReason.APP_CALLED_RESTART_INPUT_API:
                return "APP_CALLED_RESTART_INPUT_API";
            case StartInputReason.CHECK_FOCUS:
+6 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import java.lang.annotation.Retention;
        StartInputReason.UNSPECIFIED,
        StartInputReason.WINDOW_FOCUS_GAIN,
        StartInputReason.WINDOW_FOCUS_GAIN_REPORT_ONLY,
        StartInputReason.SCHEDULED_CHECK_FOCUS,
        StartInputReason.APP_CALLED_RESTART_INPUT_API,
        StartInputReason.CHECK_FOCUS,
        StartInputReason.BOUND_TO_IMMS,
@@ -57,6 +58,11 @@ public @interface StartInputReason {
     * this window focus change event to sync IME input target for system.
     */
    int WINDOW_FOCUS_GAIN_REPORT_ONLY = 2;
    /**
     * Similar to {@link #CHECK_FOCUS}, but the one scheduled with
     * {@link android.view.ViewRootImpl#dispatchCheckFocus()}.
     */
    int SCHEDULED_CHECK_FOCUS = 3;
    /**
     * {@link android.view.inputmethod.InputMethodManager#restartInput(android.view.View)} is
     * either explicitly called by the application or indirectly called by some Framework class