From 0bcca218ac495a3a42cfbe724c290fb1f807628a Mon Sep 17 00:00:00 2001 From: Justin Ghan Date: Wed, 29 Mar 2023 13:46:01 -0700 Subject: [PATCH] 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 --- .../inputmethod/RemoteInputConnectionImpl.java | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/core/java/android/view/inputmethod/RemoteInputConnectionImpl.java b/core/java/android/view/inputmethod/RemoteInputConnectionImpl.java index eb91d08dc2789..ec50c697ae9a4 100644 --- a/core/java/android/view/inputmethod/RemoteInputConnectionImpl.java +++ b/core/java/android/view/inputmethod/RemoteInputConnectionImpl.java @@ -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); + } } }); }