diff --git a/core/java/android/view/ImeFocusController.java b/core/java/android/view/ImeFocusController.java index fa647d7e9c004..bb6c78a8fe7a6 100644 --- a/core/java/android/view/ImeFocusController.java +++ b/core/java/android/view/ImeFocusController.java @@ -132,22 +132,16 @@ public final class ImeFocusController { } /** - * To handle the lifecycle of the input connection when the device interactivity state changed. - * (i.e. Calling IMS#onFinishInput when the device screen-off and Calling IMS#onStartInput - * when the device screen-on again). + * Calling IMS#onStartInput when the device screen-on again). */ @UiThread - public void onInteractiveChanged(boolean interactive) { + public void onInteractive() { final InputMethodManagerDelegate immDelegate = getImmDelegate(); if (!immDelegate.isCurrentRootView(mViewRootImpl)) { return; } - if (interactive) { - final View focusedView = mViewRootImpl.mView.findFocus(); - onViewFocusChanged(focusedView, focusedView != null); - } else { - mDelegate.finishInputAndReportToIme(); - } + final View focusedView = mViewRootImpl.mView.findFocus(); + onViewFocusChanged(focusedView, focusedView != null); } /** @@ -186,7 +180,6 @@ public final class ImeFocusController { void onViewDetachedFromWindow(View view, ViewRootImpl viewRootImpl); void onWindowDismissed(ViewRootImpl viewRootImpl); - void finishInputAndReportToIme(); boolean isCurrentRootView(ViewRootImpl rootView); } diff --git a/core/java/android/view/inputmethod/InputMethodManager.java b/core/java/android/view/inputmethod/InputMethodManager.java index 1f1e2e1dd3195..4a0a4bf39690c 100644 --- a/core/java/android/view/inputmethod/InputMethodManager.java +++ b/core/java/android/view/inputmethod/InputMethodManager.java @@ -741,26 +741,6 @@ public final class InputMethodManager { private final class DelegateImpl implements ImeFocusController.InputMethodManagerDelegate { - /** - * Used by {@link ImeFocusController} to finish input connection and callback - * {@link InputMethodService#onFinishInput()}. - * - * This method is especially for when ImeFocusController received device screen-off event to - * ensure the entire finish input connection and the connection lifecycle callback to - * IME can be done for security concern. - */ - @Override - public void finishInputAndReportToIme() { - synchronized (mH) { - finishInputLocked(); - if (isImeSessionAvailableLocked()) { - mCurBindState.mImeSession.finishInput(); - } - forAccessibilitySessionsLocked( - IAccessibilityInputMethodSessionInvoker::finishInput); - } - } - @Override public void onPreWindowGainedFocus(ViewRootImpl viewRootImpl) { synchronized (mH) { @@ -1203,14 +1183,24 @@ public final class InputMethodManager { mActive = interactive; mFullscreenMode = fullscreen; - // 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) { - return; + 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) { + return; + } + rootView.post(controller::onInteractive); + } else { + finishInputLocked(); + if (isImeSessionAvailableLocked()) { + mCurBindState.mImeSession.finishInput(); + } + forAccessibilitySessionsLocked( + IAccessibilityInputMethodSessionInvoker::finishInput); } - rootView.post(() -> controller.onInteractiveChanged(interactive)); } return; }