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

Commit 9be4be61 authored by Vairavan Srinivasan's avatar Vairavan Srinivasan Committed by Steve Kondik
Browse files

frameworks/base: Protecting views from (bad) MotionEvents

When handling MotionEvents, the method findPointerIndex can return -1
if the current pointer id can't be translated to a pointer index.
Several views are not handling this, which will lead to an
out-of-index crash.

CRs-Fixed: 275381

Change-Id: Ica4446e4eb18ffb26de92b44465c249f230719f1
parent 880fa938
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -2218,6 +2218,10 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te

        case MotionEvent.ACTION_MOVE: {
            final int pointerIndex = ev.findPointerIndex(mActivePointerId);
            if (pointerIndex == -1) {
                break;
            }

            final int y = (int) ev.getY(pointerIndex);
            deltaY = y - mMotionY;
            switch (mTouchMode) {
@@ -2726,6 +2730,10 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
            switch (mTouchMode) {
            case TOUCH_MODE_DOWN:
                final int pointerIndex = ev.findPointerIndex(mActivePointerId);
                if (pointerIndex == -1) {
                    break;
                }

                final int y = (int) ev.getY(pointerIndex);
                if (startScrollIfNeeded(y - mMotionY)) {
                    return true;
+8 −0
Original line number Diff line number Diff line
@@ -430,6 +430,10 @@ public class HorizontalScrollView extends FrameLayout {
                }

                final int pointerIndex = ev.findPointerIndex(activePointerId);
                if (pointerIndex == -1) {
                    break;
                }

                final float x = ev.getX(pointerIndex);
                final int xDiff = (int) Math.abs(x - mLastMotionX);
                if (xDiff > mTouchSlop) {
@@ -524,6 +528,10 @@ public class HorizontalScrollView extends FrameLayout {
                if (mIsBeingDragged) {
                    // Scroll to follow the motion event
                    final int activePointerIndex = ev.findPointerIndex(mActivePointerId);
                    if (activePointerIndex == -1) {
                        break;
                    }

                    final float x = ev.getX(activePointerIndex);
                    final int deltaX = (int) (mLastMotionX - x);
                    mLastMotionX = x;
+8 −0
Original line number Diff line number Diff line
@@ -426,6 +426,10 @@ public class ScrollView extends FrameLayout {
                }

                final int pointerIndex = ev.findPointerIndex(activePointerId);
                if (pointerIndex == -1) {
                    break;
                }

                final float y = ev.getY(pointerIndex);
                final int yDiff = (int) Math.abs(y - mLastMotionY);
                if (yDiff > mTouchSlop) {
@@ -519,6 +523,10 @@ public class ScrollView extends FrameLayout {
                if (mIsBeingDragged) {
                    // Scroll to follow the motion event
                    final int activePointerIndex = ev.findPointerIndex(mActivePointerId);
                    if (activePointerIndex == -1) {
                        break;
                    }

                    final float y = ev.getY(activePointerIndex);
                    final int deltaY = (int) (mLastMotionY - y);
                    mLastMotionY = y;