Merge "Fix IME callback not unregistered when IME is up during an IMM client switch." into tm-dev am: 4357250002

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/18699773

Change-Id: I3157cb9e63e7e89b46a53b1cdace90cb1cadb224
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Shan Huang
2022-06-02 06:19:54 +00:00
committed by Automerger Merge Worker

View File

@@ -806,11 +806,6 @@ public class InputMethodService extends AbstractInputMethodService {
@NonNull EditorInfo editorInfo, boolean restarting, @NonNull EditorInfo editorInfo, boolean restarting,
@NonNull IBinder startInputToken, @InputMethodNavButtonFlags int navButtonFlags, @NonNull IBinder startInputToken, @InputMethodNavButtonFlags int navButtonFlags,
@NonNull ImeOnBackInvokedDispatcher imeDispatcher) { @NonNull ImeOnBackInvokedDispatcher imeDispatcher) {
mImeDispatcher = imeDispatcher;
if (mWindow != null) {
mWindow.getOnBackInvokedDispatcher().setImeOnBackInvokedDispatcher(
imeDispatcher);
}
mPrivOps.reportStartInputAsync(startInputToken); mPrivOps.reportStartInputAsync(startInputToken);
mNavigationBarController.onNavButtonFlagsChanged(navButtonFlags); mNavigationBarController.onNavButtonFlagsChanged(navButtonFlags);
if (restarting) { if (restarting) {
@@ -818,6 +813,15 @@ public class InputMethodService extends AbstractInputMethodService {
} else { } else {
startInput(inputConnection, editorInfo); startInput(inputConnection, editorInfo);
} }
// Update the IME dispatcher last, so that the previously registered back callback
// (if any) can be unregistered using the old dispatcher if {@link #doFinishInput()}
// is called from {@link #startInput(InputConnection, EditorInfo)} or
// {@link #restartInput(InputConnection, EditorInfo)}.
mImeDispatcher = imeDispatcher;
if (mWindow != null) {
mWindow.getOnBackInvokedDispatcher().setImeOnBackInvokedDispatcher(
imeDispatcher);
}
} }
/** /**
@@ -3860,6 +3864,11 @@ public class InputMethodService extends AbstractInputMethodService {
}; };
private void compatHandleBack() { private void compatHandleBack() {
if (!mDecorViewVisible) {
Log.e(TAG, "Back callback invoked on a hidden IME. Removing the callback...");
unregisterCompatOnBackInvokedCallback();
return;
}
final KeyEvent downEvent = createBackKeyEvent( final KeyEvent downEvent = createBackKeyEvent(
KeyEvent.ACTION_DOWN, false /* isTracking */); KeyEvent.ACTION_DOWN, false /* isTracking */);
onKeyDown(KeyEvent.KEYCODE_BACK, downEvent); onKeyDown(KeyEvent.KEYCODE_BACK, downEvent);