From c4574fc01f04725bfc377269b43a04e784c1428e Mon Sep 17 00:00:00 2001 From: Prabir Pradhan Date: Wed, 12 Apr 2023 00:16:04 +0000 Subject: [PATCH] InkWindow: Provide a copy of the motion event to view root When a motion event is enqueued into the view root, the view root expects to own the event, which means it will finish and recycle the event if necessary. In the handwriting pipeline, this event actually comes from an InputEventReceiver that handles finishing the event, so there is a chance that the event is finished or recycled twice. Make sure the view root owns the event that is enqueued into it by providing it with a copy of the event. Bug: 277809922 Test: manual, HandwritingIme Change-Id: I65968d075640c1dd585d5d7b9eadb78e3dff9aa2 --- core/java/android/inputmethodservice/InkWindow.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/java/android/inputmethodservice/InkWindow.java b/core/java/android/inputmethodservice/InkWindow.java index 15ed45041d320..24d1c9577f82d 100644 --- a/core/java/android/inputmethodservice/InkWindow.java +++ b/core/java/android/inputmethodservice/InkWindow.java @@ -195,6 +195,7 @@ final class InkWindow extends PhoneWindow { Objects.requireNonNull(decor); final ViewRootImpl viewRoot = decor.getViewRootImpl(); Objects.requireNonNull(viewRoot); - viewRoot.enqueueInputEvent(event); + // The view root will own the event that we enqueue, so provide a copy of the event. + viewRoot.enqueueInputEvent(MotionEvent.obtain(event)); } }