Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 29869a5b authored by Prabir Pradhan's avatar Prabir Pradhan Committed by Android Build Cherrypicker Worker
Browse files

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
parent 8fa25802
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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 ArrayList<View> preorderedList = buildOrderedChildList();
            final boolean customOrder = preorderedList == null
+14 −5
Original line number Diff line number Diff line
@@ -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());
    }

    /**