Allow IME to register callbacks with negative priorities.

It's perfectly valid to register system callbacks (which have negative
priority) from the IME process from framework code, once it is opted in.

We should still reject negative priority for registration through public APIs though. Will follow up separately in b/262930093.

Test: atest android.view.inputmethod.cts.KeyboardVisibilityControlTest#testHideImeAfterBackPressed_legacyAppMigratedIme
Fixes: 262727745
Change-Id: Ie13c738d0d4a10f4265fbf116ff7b4206d3bfc62
This commit is contained in:
Shan Huang
2022-12-16 16:14:30 -08:00
parent aab3180666
commit 8ec05512be

View File

@@ -123,7 +123,7 @@ public class ImeOnBackInvokedDispatcher implements OnBackInvokedDispatcher, Parc
private void receive(
int resultCode, Bundle resultData,
@NonNull OnBackInvokedDispatcher receivingDispatcher) {
@NonNull WindowOnBackInvokedDispatcher receivingDispatcher) {
final int callbackId = resultData.getInt(RESULT_KEY_ID);
if (resultCode == RESULT_CODE_REGISTER) {
int priority = resultData.getInt(RESULT_KEY_PRIORITY);
@@ -140,11 +140,11 @@ public class ImeOnBackInvokedDispatcher implements OnBackInvokedDispatcher, Parc
@NonNull IOnBackInvokedCallback iCallback,
@OnBackInvokedDispatcher.Priority int priority,
int callbackId,
@NonNull OnBackInvokedDispatcher receivingDispatcher) {
@NonNull WindowOnBackInvokedDispatcher receivingDispatcher) {
final ImeOnBackInvokedCallback imeCallback =
new ImeOnBackInvokedCallback(iCallback, callbackId, priority);
mImeCallbacks.add(imeCallback);
receivingDispatcher.registerOnBackInvokedCallback(priority, imeCallback);
receivingDispatcher.registerOnBackInvokedCallbackUnchecked(imeCallback, priority);
}
private void unregisterReceivedCallback(