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

Commit c356266e authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Merge lock blocks around IMM#checkFocusInternal()

This CL removes unnecessary lock acquisitions when possible.

There must be no observable behavior change.

Bug: 234882948
Test: presubmit
Change-Id: I1b5e5870bdf7ace6a4585c640339c6196d78af42
parent 90ce33c3
Loading
Loading
Loading
Loading
+37 −38
Original line number Diff line number Diff line
@@ -776,20 +776,20 @@ public final class InputMethodManager {
                    "InputMethodManager.DelegateImpl#startInputAsyncOnWindowFocusGain",
                    InputMethodManager.this, null /* icProto */);

            final ViewRootImpl viewRootImpl;
            boolean checkFocusResult;
            synchronized (mH) {
                if (mCurRootView == null) {
                    return;
                }
                viewRootImpl = mCurRootView;
                if (mRestartOnNextWindowFocus) {
                    if (DEBUG) Log.v(TAG, "Restarting due to mRestartOnNextWindowFocus as true");
                    mRestartOnNextWindowFocus = false;
                    forceNewFocus = true;
                }
                checkFocusResult = checkFocusInternalLocked(forceNewFocus, mCurRootView);
            }

            if (checkFocusInternal(forceNewFocus, viewRootImpl)) {
            if (checkFocusResult) {
                // 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
@@ -825,10 +825,12 @@ public final class InputMethodManager {
        }

        @Override
        public void onScheduledCheckFocus(@NonNull ViewRootImpl viewRootImpl) {
            if (!checkFocusInternal(false, viewRootImpl)) {
        public void onScheduledCheckFocus(ViewRootImpl viewRootImpl) {
            synchronized (mH) {
                if (!checkFocusInternalLocked(false, viewRootImpl)) {
                    return;
                }
            }
            startInputOnWindowFocusGainInternal(StartInputReason.SCHEDULED_CHECK_FOCUS,
                    null /* focusedView */, 0 /* startInputFlags */, 0 /* softInputMode */,
                    0 /* windowFlags */);
@@ -1123,7 +1125,7 @@ public final class InputMethodManager {
                        if (mCurRootView == null) {
                            return;
                        }
                        if (!checkFocusInternal(mRestartOnNextWindowFocus, mCurRootView)) {
                        if (!checkFocusInternalLocked(mRestartOnNextWindowFocus, mCurRootView)) {
                            return;
                        }
                        final int reason = active ? StartInputReason.ACTIVATED_BY_IMMS
@@ -2657,16 +2659,14 @@ public final class InputMethodManager {
     */
    @UnsupportedAppUsage
    public void checkFocus() {
        final ViewRootImpl viewRootImpl;
        synchronized (mH) {
            if (mCurRootView == null) {
                return;
            }
            viewRootImpl = mCurRootView;
        }
        if (!checkFocusInternal(false /* forceNewFocus */, viewRootImpl)) {
            if (!checkFocusInternalLocked(false /* forceNewFocus */, mCurRootView)) {
                return;
            }
        }
        startInputOnWindowFocusGainInternal(StartInputReason.CHECK_FOCUS,
                null /* focusedView */,
                0 /* startInputFlags */, 0 /* softInputMode */, 0 /* windowFlags */);
@@ -2675,8 +2675,8 @@ public final class InputMethodManager {
    /**
     * Check the next served view if needs to start input.
     */
    private boolean checkFocusInternal(boolean forceNewFocus, ViewRootImpl viewRootImpl) {
        synchronized (mH) {
    @GuardedBy("mH")
    private boolean checkFocusInternalLocked(boolean forceNewFocus, ViewRootImpl viewRootImpl) {
        if (mCurRootView != viewRootImpl) {
            return false;
        }
@@ -2701,7 +2701,6 @@ public final class InputMethodManager {
        if (mServedInputConnection != null) {
            mServedInputConnection.finishComposingTextFromImm();
        }
        }
        return true;
    }