From ccc693141207fbfb8157e1cdcb342d15874b535d Mon Sep 17 00:00:00 2001 From: Yohei Yukawa Date: Sat, 15 Oct 2022 14:54:40 -0700 Subject: [PATCH] Further simplify FINISH_INPUT_NO_FALLBACK_CONNECTION handling This CL aims to further simplify what MSG_SET_INTERACTIVE handler needs to do, which was introduced in my previous CL [1]. So redispatching the task to the UI thread is necessary when and only when "interactive" parameter is true. If it's false, we can directly invoke DelegateImpl#finishInputAndReportToIme(). [1]: I0c95d7e70357ac98b336cd1b51a7405ba92a9a6f Bug: 234882948 Test: presubmit Change-Id: I19e14526a094900c80d9c3fc00f576e3a50cafb2 --- .../java/android/view/ImeFocusController.java | 15 ++----- .../view/inputmethod/InputMethodManager.java | 44 +++++++------------ 2 files changed, 21 insertions(+), 38 deletions(-) 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 6fb7e78a11b9c..848f6f46dc8bd 100644 --- a/core/java/android/view/inputmethod/InputMethodManager.java +++ b/core/java/android/view/inputmethod/InputMethodManager.java @@ -740,26 +740,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) { @@ -1202,14 +1182,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; }