
案例Android14横屏鼠标在屏幕右侧滑动事件失效BUG浏览器中横屏下鼠标在右侧无法滑动页面分析竖屏下鼠标是正常的横屏下只有右侧鼠标失效鼠标事件分发过程中坐标计算错误修改AOSP新版本上已修改ViewGroup.java中dispatchGenericPointerEvent方法Y轴应该使用event.getYDispatchLocation(0)获取https://cs.android.com/android/_/android/platform/frameworks/base//a7adeb7c86299754dfbd2a6a052cdb4a6712b411commit 29869a5b743add3c043acc1209cc030bbd4078b3 Author: Prabir Pradhanprabirmspgoogle.comDate: Mon Oct 9 21:55:11 2023 0000 ViewGroup: Fix dispatching of generic motion events The change I58a9c06b7651ebe97cd03447b083cc9887f863b1 introduced a self-apparent bug. We fix it and amend the test case so that the issue would have been caught. Bug: 281951190 Test: atest ViewGroupTest (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:c45197fb27ddce3886ae392465c759027f1795cd) Merged-In: I886a2594a091e5d1870e564b67d46ce5e4901ae5 Change-Id: I886a2594a091e5d1870e564b67d46ce5e4901ae5 diff --git a/core/java/android/view/ViewGroup.java b/core/java/android/view/ViewGroup.java index 0d0bfe3b8ab9..d70296353ff6 100644 --- a/core/java/android/view/ViewGroup.java b/core/java/android/view/ViewGroup.java -2536,7 2536,7 public abstract class ViewGroup extends View implements ViewParent, ViewManager final int childrenCount mChildrenCount; if (childrenCount ! 0) { final float x event.getXDispatchLocation(0); - final float y event.getXDispatchLocation(0); final float y event.getYDispatchLocation(0); final ArrayListViewpreorderedList buildOrderedChildList(); final boolean customOrder preorderedList null diff --git a/core/tests/coretests/src/android/view/ViewGroupTest.java b/core/tests/coretests/src/android/view/ViewGroupTest.java index b37c8fd8c34e..bce3f3e8f2e1 100644 --- a/core/tests/coretests/src/android/view/ViewGroupTest.java b/core/tests/coretests/src/android/view/ViewGroupTest.java -49,11 49,11 public class ViewGroupTest { public void testDispatchMouseEventsUnderCursor() { final Context context getInstrumentation().getContext(); final TestView viewGroup new TestView(context, 0 /* left */, 0 /* top */, - 200 /* right */, 200 /* bottom */); 200 /* right */, 100 /* bottom */); final TestView viewA spy(new TestView(context, 0 /* left */, 0 /* top */, - 100 /* right */, 200 /* bottom */)); 100 /* right */, 100 /* bottom */)); final TestView viewB spy(new TestView(context, 100 /* left */, 0 /* top */, - 200 /* right */, 200 /* bottom */)); 200 /* right */, 100 /* bottom */)); viewGroup.addView(viewA); viewGroup.addView(viewB); -73,10 73,10 public class ViewGroupTest { MotionEvent.PointerCoords[] coords new MotionEvent.PointerCoords[2]; coords[0] new MotionEvent.PointerCoords(); coords[0].x 80; - coords[0].y 100; coords[0].y 50; coords[1] new MotionEvent.PointerCoords(); coords[1].x 240; - coords[1].y 100; coords[1].y 50; MotionEvent event; // Make sure the down event is active with a pointer which coordinate is different from the -91,6 91,10 public class ViewGroupTest { viewGroup.onResolvePointerIcon(event, 0 /* pointerIndex */); verify(viewB).onResolvePointerIcon(event, 0); event.setAction(MotionEvent.ACTION_SCROLL); viewGroup.dispatchGenericMotionEvent(event); verify(viewB).dispatchGenericMotionEvent(event); event MotionEvent.obtain(0 /* downTime */, 0 /* eventTime */, MotionEvent.ACTION_POINTER_DOWN | (1 MotionEvent.ACTION_POINTER_INDEX_SHIFT), 2 /* pointerCount */, properties, coords, 0 /* metaState */, 0 /* buttonState */, -102,8 106,13 public class ViewGroupTest { viewGroup.onResolvePointerIcon(event, 1 /* pointerIndex */); verify(viewB).onResolvePointerIcon(event, 1); event.setAction(MotionEvent.ACTION_SCROLL); viewGroup.dispatchGenericMotionEvent(event); verify(viewB).dispatchGenericMotionEvent(event); verify(viewA, never()).dispatchTouchEvent(any()); verify(viewA, never()).onResolvePointerIcon(any(), anyInt()); verify(viewA, never()).dispatchGenericMotionEvent(any()); } /**