summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Cosmin Băieș <cosminbaies@google.com> 2025-03-13 14:22:19 +0100
committer Cosmin Băieș <cosminbaies@google.com> 2025-03-13 14:38:49 +0100
commitd49faacf566f1347ee4971fda66618c7ecbbea3c (patch)
tree8d398d0f7b706352de082221cdd4668c3cf8c1cc
parent4a2e7e3a7fd57db0f02070d9e30ed834a432b3ec (diff)
Register IME back callback in doStartInput
Normally the IME back callback is registered at the end of showWindow. However, we can get a doStartInput call without a subsequent showWindow call, and doStartInput will first doFinishInput, which will unregister the callback. If showWindow was previously called, we should try to register the callback again, so that back navigation while the IME is shown will be processed by the IME first, before the activity underneath. This lead to the callback being left unregistered due to a race condition, with the failing case order being: * ImeInsetsSourceProvider#invokeOnImeRequestedChangedListener * IMM#startInputInner * DefaultImeVisibilityApplier#performShowIme (from ImeChangedListener) * IMMS#attachNewInputLocked (from startInputInner) * IME#showSoftInput (from performShowIme) * IME#registerDefaultOnBackInvokedCallback (from showSoftInput) * IME#dispatchStartInput (from attachNewInputLocked) * IME#unregisterDefaultOnBackInvokedCallback (from dispatchStartInput) and the passing case (expected) order being: * ImeInsetsSourceProvider#invokeOnImeRequestedChangedListener * IMM#startInputInner * IMMS#attachNewInputLocked (from startInputInner) * IME#dispatchStartInput (from attachNewInputLocked) * IME#unregisterDefaultOnBackInvokedCallback (from dispatchStartInput) * DefaultImeVisibilityApplier#performShowIme (from ImeChangedListener) * IME#showSoftInput (from performShowIme) * IME#registerDefaultOnBackInvokedCallback (from showSoftInput) Flag: EXEMPT bugfix: Test: atest KeyboardVisibilityControlTest#testIMEVisibleInSplitScreenWithWindowInsetsApi Bug: 402671709 Change-Id: I0d0f823a2998a08b8dfc2b0d6e39a0a9de521b14
-rw-r--r--core/java/android/inputmethodservice/InputMethodService.java4
1 files changed, 4 insertions, 0 deletions
diff --git a/core/java/android/inputmethodservice/InputMethodService.java b/core/java/android/inputmethodservice/InputMethodService.java
index 2e7bc6d9b9f7..84d96bd1e155 100644
--- a/core/java/android/inputmethodservice/InputMethodService.java
+++ b/core/java/android/inputmethodservice/InputMethodService.java
@@ -3504,6 +3504,10 @@ public class InputMethodService extends AbstractInputMethodService {
mInlineSuggestionSessionController.notifyOnStartInputView();
onStartInputView(mInputEditorInfo, restarting);
startExtractingText(true);
+ // Back callback is typically registered in {@link #showWindow()}, but it's possible
+ // for {@link #doStartInput()} to be called without {@link #showWindow()} so we also
+ // register here.
+ registerDefaultOnBackInvokedCallback();
} else if (mCandidatesVisibility == View.VISIBLE) {
if (DEBUG) Log.v(TAG, "CALL: onStartCandidatesView");
mCandidatesViewStarted = true;