From c5af33d324384e427cf3fa97b7574b3cde7d5d90 Mon Sep 17 00:00:00 2001 From: Yohei Yukawa Date: Tue, 21 Jun 2022 15:19:16 -0700 Subject: [PATCH] Deprecate mRequestUpdateCursorAnchorInfoMonitorMode part 1 This is the initial step towards deprecating InputMethodManager#mRequestUpdateCursorAnchorInfoMonitorMode, which was introduced as a minimum implementation to support CursorAnchorInfo API in EditText [1] Before this CL, there is a behavior discrepancy in MSG_UPDATE_VIRTUAL_DISPLAY_TO_SCREEN_MATRIX handler because mRequestUpdateCursorAnchorInfoMonitorMode has a valid value when and only when the editor component is EditText. With this CL, the same behavior will be applied to non-View based editors. [1]: I3c6b69bd9d79b199afe68d838f25effa6048e5cc cf8421df856a5950729ff1d0e73f21d480aa98fb Bug: 236713697 Test: presubmit Change-Id: I8d42aef4ffd81253181ba876f8970179643d834c --- .../view/inputmethod/InputMethodManager.java | 4 +--- .../RemoteInputConnectionImpl.java | 20 ++++++++++++++++++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/core/java/android/view/inputmethod/InputMethodManager.java b/core/java/android/view/inputmethod/InputMethodManager.java index dfcc6f6568b8a..72981b1296f23 100644 --- a/core/java/android/view/inputmethod/InputMethodManager.java +++ b/core/java/android/view/inputmethod/InputMethodManager.java @@ -1131,9 +1131,7 @@ public final class InputMethodManager { || mServedInputConnection == null) { return; } - final boolean isMonitoring = (mRequestUpdateCursorAnchorInfoMonitorMode - & InputConnection.CURSOR_UPDATE_MONITOR) != 0; - if (!isMonitoring) { + if (!mServedInputConnection.isCursorAnchorInfoMonitoring()) { return; } // Since the host VirtualDisplay is moved, we need to issue diff --git a/core/java/com/android/internal/inputmethod/RemoteInputConnectionImpl.java b/core/java/com/android/internal/inputmethod/RemoteInputConnectionImpl.java index cb18ccc9788a1..09394c1ebf419 100644 --- a/core/java/com/android/internal/inputmethod/RemoteInputConnectionImpl.java +++ b/core/java/com/android/internal/inputmethod/RemoteInputConnectionImpl.java @@ -176,6 +176,8 @@ public final class RemoteInputConnectionImpl extends IRemoteInputConnection.Stub private final AtomicInteger mCurrentSessionId = new AtomicInteger(0); private final AtomicBoolean mHasPendingInvalidation = new AtomicBoolean(); + private final AtomicBoolean mIsCursorAnchorInfoMonitoring = new AtomicBoolean(false); + public RemoteInputConnectionImpl(@NonNull Looper looper, @NonNull InputConnection inputConnection, @NonNull InputMethodManager inputMethodManager, @Nullable View servedView) { @@ -222,6 +224,16 @@ public final class RemoteInputConnectionImpl extends IRemoteInputConnection.Stub return mServedView.get(); } + /** + * @return {@code true} if there is any active request for + * {@link android.view.inputmethod.CursorAnchorInfo} with + * {@link InputConnection#CURSOR_UPDATE_MONITOR} flag. + */ + @AnyThread + public boolean isCursorAnchorInfoMonitoring() { + return mIsCursorAnchorInfoMonitoring.get(); + } + /** * Schedule a task to execute * {@link InputMethodManager#doInvalidateInput(RemoteInputConnectionImpl, TextSnapshot, int)} @@ -998,11 +1010,17 @@ public final class RemoteInputConnectionImpl extends IRemoteInputConnection.Stub // requestCursorUpdates() is not currently supported across displays. return false; } + final boolean hasMonitoring = + (cursorUpdateMode & InputConnection.CURSOR_UPDATE_MONITOR) != 0; + boolean result = false; try { - return ic.requestCursorUpdates(cursorUpdateMode, cursorUpdateFilter); + result = ic.requestCursorUpdates(cursorUpdateMode, cursorUpdateFilter); + return result; } catch (AbstractMethodError ignored) { // TODO(b/199934664): See if we can remove this by providing a default impl. return false; + } finally { + mIsCursorAnchorInfoMonitoring.set(result && hasMonitoring); } }