From def5cd30a1be030ba359b5e214914cca9680aaa6 Mon Sep 17 00:00:00 2001 From: Wilson Wu Date: Fri, 16 Sep 2022 18:01:30 +0800 Subject: [PATCH] Prevent InputMethodManager call into DelegateImpl (1/N) InputMethodManager#DelegateImpl is a delegation for ImeFocusController to call into InputMethodManager. Ideally IMM don't need to rely on DelegateImpl. Move the IMM#hasActiveInputConnection implemetation from DelegateImpl to make consistency. Bug: 243778447 Bug: 182259171 Test: atest CtsInputMethodTestCases Change-Id: I4246fd077b8ddf741311defb7a1b9175136bb769 --- .../view/inputmethod/InputMethodManager.java | 41 +++++++++++-------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/core/java/android/view/inputmethod/InputMethodManager.java b/core/java/android/view/inputmethod/InputMethodManager.java index 0c7c1639e6c73..c966e93a71c5f 100644 --- a/core/java/android/view/inputmethod/InputMethodManager.java +++ b/core/java/android/view/inputmethod/InputMethodManager.java @@ -788,7 +788,7 @@ public final class InputMethodManager { // we'll just do a window focus gain and call it a day. View servedView = controller.getServedView(); boolean nextFocusHasConnection = servedView != null && servedView == focusedView - && hasActiveConnection(focusedView); + && hasActiveInputConnectionInternal(focusedView); if (DEBUG) { Log.v(TAG, "Reporting focus gain, without startInput" + ", nextFocusIsServedView=" + nextFocusHasConnection); @@ -861,22 +861,11 @@ public final class InputMethodManager { /** * Checks whether the active input connection (if any) is for the given view. * - * TODO(b/182259171): Clean-up hasActiveConnection to simplify the logic. - * - * Note that this method is only intended for restarting input after focus gain - * (e.g. b/160391516), DO NOT leverage this method to do another check. + * @see #hasActiveInputConnectionInternal(View)} */ @Override public boolean hasActiveConnection(View view) { - synchronized (mH) { - if (!hasServedByInputMethodLocked(view) || !isImeSessionAvailableLocked()) { - return false; - } - - return mServedInputConnection != null - && mServedInputConnection.isActive() - && mServedInputConnection.getServedView() == view; - } + return hasActiveInputConnectionInternal(view); } } @@ -889,11 +878,31 @@ public final class InputMethodManager { * Checks whether the active input connection (if any) is for the given view. * * @hide - * @see ImeFocusController#getImmDelegate()#hasActiveInputConnection(View) + * @see #hasActiveInputConnectionInternal(View)} */ @TestApi public boolean hasActiveInputConnection(@Nullable View view) { - return mDelegate.hasActiveConnection(view); + return hasActiveInputConnectionInternal(view); + } + + /** + * Checks whether the active input connection (if any) is for the given view. + * + * TODO(b/182259171): Clean-up hasActiveConnection to simplify the logic. + * + * Note that this method is only intended for restarting input after focus gain + * (e.g. b/160391516), DO NOT leverage this method to do another check. + */ + private boolean hasActiveInputConnectionInternal(@Nullable View view) { + synchronized (mH) { + if (!hasServedByInputMethodLocked(view) || !isImeSessionAvailableLocked()) { + return false; + } + + return mServedInputConnection != null + && mServedInputConnection.isActive() + && mServedInputConnection.getServedView() == view; + } } @GuardedBy("mH")