diff --git a/core/java/android/view/inputmethod/InputMethodManager.java b/core/java/android/view/inputmethod/InputMethodManager.java index be501055681bf..7840d4cacc255 100644 --- a/core/java/android/view/inputmethod/InputMethodManager.java +++ b/core/java/android/view/inputmethod/InputMethodManager.java @@ -1116,14 +1116,19 @@ public final class InputMethodManager { // Check focus again in case that "onWindowFocus" is called before // handling this message. final View servedView = getServedViewLocked(); - if (servedView != null && canStartInput(servedView)) { - if (mCurRootView != null && mCurRootView.getImeFocusController() - .checkFocus(mRestartOnNextWindowFocus, false)) { - final int reason = active ? StartInputReason.ACTIVATED_BY_IMMS - : StartInputReason.DEACTIVATED_BY_IMMS; - startInputOnWindowFocusGainInternal(reason, null, 0, 0, 0); - } + if (servedView == null || !canStartInput(servedView)) { + return; } + if (mCurRootView == null) { + return; + } + if (!mCurRootView.getImeFocusController().checkFocus( + mRestartOnNextWindowFocus, false)) { + return; + } + final int reason = active ? StartInputReason.ACTIVATED_BY_IMMS + : StartInputReason.DEACTIVATED_BY_IMMS; + startInputOnWindowFocusGainInternal(reason, null, 0, 0, 0); } return; }