diff --git a/core/java/android/view/ImeFocusController.java b/core/java/android/view/ImeFocusController.java index bb6c78a8fe7a6..4de7c4fdd5134 100644 --- a/core/java/android/view/ImeFocusController.java +++ b/core/java/android/view/ImeFocusController.java @@ -131,19 +131,6 @@ public final class ImeFocusController { mHasImeFocus = false; } - /** - * Calling IMS#onStartInput when the device screen-on again). - */ - @UiThread - public void onInteractive() { - final InputMethodManagerDelegate immDelegate = getImmDelegate(); - if (!immDelegate.isCurrentRootView(mViewRootImpl)) { - return; - } - final View focusedView = mViewRootImpl.mView.findFocus(); - onViewFocusChanged(focusedView, focusedView != null); - } - /** * @param windowAttribute {@link WindowManager.LayoutParams} to be checked. * @return Whether the window is in local focus mode or not. @@ -179,8 +166,6 @@ public final class ImeFocusController { boolean checkFocus(boolean forceNewFocus, boolean startInput, ViewRootImpl viewRootImpl); void onViewDetachedFromWindow(View view, ViewRootImpl viewRootImpl); void onWindowDismissed(ViewRootImpl viewRootImpl); - - boolean isCurrentRootView(ViewRootImpl rootView); } /** diff --git a/core/java/android/view/inputmethod/InputMethodManager.java b/core/java/android/view/inputmethod/InputMethodManager.java index 848f6f46dc8bd..2d44756399813 100644 --- a/core/java/android/view/inputmethod/InputMethodManager.java +++ b/core/java/android/view/inputmethod/InputMethodManager.java @@ -902,18 +902,6 @@ public final class InputMethodManager { mImeDispatcher.switchRootView(mCurRootView, rootView); mCurRootView = rootView; } - - /** - * Used for {@link ImeFocusController} to return if the root view from the - * controller is this {@link InputMethodManager} currently focused. - * TODO: Address event-order problem when get current root view in multi-threads. - */ - @Override - public boolean isCurrentRootView(ViewRootImpl rootView) { - synchronized (mH) { - return mCurRootView == rootView; - } - } } /** @hide */ @@ -1181,17 +1169,24 @@ public final class InputMethodManager { synchronized (mH) { mActive = interactive; mFullscreenMode = fullscreen; - if (interactive) { - // Report active state to ImeFocusController to handle IME input - // connection lifecycle callback when it allowed. - final ImeFocusController controller = getFocusController(); final View rootView = mCurRootView != null ? mCurRootView.getView() : null; - if (controller == null || rootView == null) { + if (rootView == null) { return; } - rootView.post(controller::onInteractive); + // Find the next view focus to start the input connection when the + // device was interactive. + final ViewRootImpl currentViewRootImpl = mCurRootView; + rootView.post(() -> { + synchronized (mH) { + if (mCurRootView != currentViewRootImpl) { + return; + } + } + final View focusedView = currentViewRootImpl.getView().findFocus(); + onViewFocusChangedInternal(focusedView, focusedView != null); + }); } else { finishInputLocked(); if (isImeSessionAvailableLocked()) {