From 991471b66d1dced23b0962b6440314ae7c4a787d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=A2=93=E8=90=8C?= Date: Mon, 20 Jun 2022 20:31:59 +0800 Subject: [PATCH 1/2] Fix PlatformView multiple pointer crash caused by toMotionEvent --- .../io/flutter/plugin/platform/PlatformViewsController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java b/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java index 4f78a732d1fe1..794d339c79452 100644 --- a/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java +++ b/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java @@ -626,7 +626,7 @@ public MotionEvent toMotionEvent( return MotionEvent.obtain( trackedEvent.getDownTime(), trackedEvent.getEventTime(), - trackedEvent.getAction(), + touch.action, touch.pointerCount, pointerProperties, pointerCoords, From 9959c864a91c5b6c6b6081b241e9db2fef585025 Mon Sep 17 00:00:00 2001 From: zzm Date: Mon, 8 Aug 2022 14:33:13 +0800 Subject: [PATCH 2/2] add test --- .../platform/PlatformViewsControllerTest.java | 48 ++++++++++++++++++- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsControllerTest.java b/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsControllerTest.java index d3fb9a8659efe..824c148a70086 100644 --- a/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsControllerTest.java +++ b/shell/platform/android/test/io/flutter/plugin/platform/PlatformViewsControllerTest.java @@ -172,6 +172,51 @@ public void itUsesActionEventTypeFromFrameworkEventForVirtualDisplays() { assertNotEquals(resolvedEvent.getAction(), original.getAction()); } + @Test + public void itUsesActionEventTypeFromFrameworkEventAsActionChanged() { + MotionEventTracker motionEventTracker = MotionEventTracker.getInstance(); + PlatformViewsController platformViewsController = new PlatformViewsController(); + + MotionEvent original = + MotionEvent.obtain( + 10, // downTime + 10, // eventTime + 261, // action + 0, // x + 0, // y + 0 // metaState + ); + + MotionEventTracker.MotionEventId motionEventId = motionEventTracker.track(original); + + PlatformViewTouch frameWorkTouch = + new PlatformViewTouch( + 0, // viewId + original.getDownTime(), + original.getEventTime(), + 0, // action + 1, // pointerCount + Arrays.asList(Arrays.asList(0, 0)), // pointer properties + Arrays.asList(Arrays.asList(0., 1., 2., 3., 4., 5., 6., 7., 8.)), // pointer coords + original.getMetaState(), + original.getButtonState(), + original.getXPrecision(), + original.getYPrecision(), + original.getDeviceId(), + original.getEdgeFlags(), + original.getSource(), + original.getFlags(), + motionEventId.getId()); + MotionEvent resolvedEvent = + platformViewsController.toMotionEvent( + 1, // density + frameWorkTouch, + false // usingVirtualDisplays + ); + assertEquals(resolvedEvent.getAction(), frameWorkTouch.action); + assertNotEquals(resolvedEvent.getAction(), original.getAction()); + } + @Ignore @Test public void itUsesActionEventTypeFromMotionEventForHybridPlatformViews() { @@ -214,8 +259,7 @@ public void itUsesActionEventTypeFromMotionEventForHybridPlatformViews() { platformViewsController.toMotionEvent( /*density=*/ 1, frameWorkTouch, /*usingVirtualDisplay=*/ false); - assertNotEquals(resolvedEvent.getAction(), frameWorkTouch.action); - assertEquals(resolvedEvent.getAction(), original.getAction()); + assertEquals(resolvedEvent.getAction(), frameWorkTouch.action); } @Test