Let IC#requestCursorUpdates() fail for cross-display connections
Since Android Q [1], it is intentional that when an IME client app is
running on a (virtual) display where IME should not be hosted, IME
will be hosted in the default display instead. This means that
cross-display App/IME interaction is an expected scenario now.
The problem is that CursorAnchorInfo API, which I introduced in
Android L [2], no longer works as intended in such a cross-display
scenario, because screen coordinates make sense only within the same
display.
The ultimate fallback strategy for this problem is forcing
InputConnection#requestCursorUpdates()
to always return false for such a cross-display scenario, which is
exactly what this CL does.
In subsequent CLs, we aim to introduce a special handling logic for
ActivityView, where the system may be able to keep maintaining
sufficient display hierarchy information so that
CursorAnchorInfo#getMatrix() can be automatically adjusted before it
is passed to the IME.
[1]: Iedd71e4ddf4983f90b02dd72e471e7fa8e838fbf
ef1965bd6d6061cb54bce305a4b99e640db19ddc
[2]: I61dec2f8fa671ba891da1d4af08975750e3acb04
1c7e66c97ce0a5d54e03abdee2f36fdce55944e6
Bug: 115693908
Fix: 131368625
Test: atest MultiDisplaySystemDecorationTests#testCrossDisplayBasicImeOperations
Change-Id: Ie2f7a5117cff3a13ad5c5806fd4b3abef7569549
diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java
index c2aade3..651ce7d 100644
--- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java
+++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java
@@ -2037,6 +2037,12 @@
if (mCurSeq <= 0) mCurSeq = 1;
mCurClient = cs;
mCurInputContext = inputContext;
+ if (cs.selfReportedDisplayId != displayIdToShowIme) {
+ // CursorAnchorInfo API does not work as-is for cross-display scenario. Pretend that
+ // InputConnection#requestCursorUpdates() is not implemented in the application so that
+ // IMEs will always receive false from this API.
+ missingMethods |= MissingMethodFlags.REQUEST_CURSOR_UPDATES;
+ }
mCurInputContextMissingMethods = missingMethods;
mCurAttribute = attribute;