Fix IME callback not being re-registered on screen off / on.

Bug:231917948
Bug:229355440
Test: atest InputMethodServiceLifecycleTest
Test: atest CtsInputMethodTestCases:InputMethodServiceTest
Test atest CtsInputMethodTestCases:KeyboardVisibilityControlTest

Change-Id: I8dc1425aa9338b37128d308bf58fd15c39d04a88
This commit is contained in:
Shan Huang
2022-05-10 16:09:13 +00:00
parent 89c3325804
commit c16b574055
2 changed files with 11 additions and 1 deletions

View File

@@ -1625,7 +1625,6 @@ public class InputMethodService extends AbstractInputMethodService {
// when IME developers are doing something unsupported.
InputMethodPrivilegedOperationsRegistry.remove(mToken);
}
unregisterCompatOnBackInvokedCallback();
mImeDispatcher = null;
}
@@ -2788,6 +2787,11 @@ public class InputMethodService extends AbstractInputMethodService {
if (mInkWindow != null) {
finishStylusHandwriting();
}
// Back callback is typically unregistered in {@link #hideWindow()}, but it's possible
// for {@link #doFinishInput()} to be called without {@link #hideWindow()} so we also
// unregister here.
// TODO(b/232341407): Add CTS to verify back behavior after screen on / off.
unregisterCompatOnBackInvokedCallback();
}
void doStartInput(InputConnection ic, EditorInfo attribute, boolean restarting) {

View File

@@ -158,6 +158,12 @@ public class ImeOnBackInvokedDispatcher implements OnBackInvokedDispatcher, Parc
/** Clears all registered callbacks on the instance. */
public void clear() {
// Unregister previously registered callbacks if there's any.
if (getReceivingDispatcher() != null) {
for (OnBackInvokedCallback callback : mImeCallbackMap.values()) {
getReceivingDispatcher().unregisterOnBackInvokedCallback(callback);
}
}
mImeCallbackMap.clear();
}