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
This commit is contained in:
Yohei Yukawa
2022-06-21 15:19:16 -07:00
parent 7a3cf53a16
commit c5af33d324
2 changed files with 20 additions and 4 deletions

View File

@@ -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

View File

@@ -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);
}
}