Call onInputConnectionClosed synchronously

This ensures that, when switching focus from one view to another,
HandwritingInitiator will receive the onInputConnectionClosed callback
for the first view before receiving the onInputConnectionCreated for the
second view.

Bug: 275598091
Test: atest android.view.inputmethod.cts.StylusHandwritingTest
Change-Id: Ifafb9c3adbdd32a307de1ea65cc2d7384f4d8a71
This commit is contained in:
Justin Ghan
2023-03-29 13:46:01 -07:00
parent 9476c7d7ca
commit 0bcca218ac

View File

@@ -405,21 +405,15 @@ final class RemoteInputConnectionImpl extends IRemoteInputConnection.Stub {
}
if (handler.getLooper().isCurrentThread()) {
servedView.onInputConnectionClosedInternal();
final ViewRootImpl viewRoot = servedView.getViewRootImpl();
if (viewRoot != null) {
viewRoot.getHandwritingInitiator().onInputConnectionClosed(servedView);
}
} else {
handler.post(servedView::onInputConnectionClosedInternal);
handler.post(() -> {
final ViewRootImpl viewRoot = servedView.getViewRootImpl();
if (viewRoot != null) {
viewRoot.getHandwritingInitiator()
.onInputConnectionClosed(servedView);
}
});
}
}
final ViewRootImpl viewRoot = servedView.getViewRootImpl();
if (viewRoot != null) {
viewRoot.getHandwritingInitiator().onInputConnectionClosed(servedView);
}
}
});
}