Skip to content

Commit 322b0a1

Browse files
Jean-Baptiste Queruandroid code review
authored andcommitted
Merge "Protecting more views from (bad) MotionEvents"
2 parents 8f7100a + 0dc291e commit 322b0a1

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

core/java/android/widget/HorizontalScrollView.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import android.graphics.Rect;
2323
import android.os.Bundle;
2424
import android.util.AttributeSet;
25+
import android.util.Log;
2526
import android.view.FocusFinder;
2627
import android.view.InputDevice;
2728
import android.view.KeyEvent;
@@ -62,6 +63,7 @@ public class HorizontalScrollView extends FrameLayout {
6263

6364
private static final float MAX_SCROLL_FACTOR = ScrollView.MAX_SCROLL_FACTOR;
6465

66+
private static final String TAG = "HorizontalScrollView";
6567

6668
private long mLastScroll;
6769

@@ -456,6 +458,12 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
456458
}
457459

458460
final int pointerIndex = ev.findPointerIndex(activePointerId);
461+
if (pointerIndex == -1) {
462+
Log.e(TAG, "Invalid pointerId=" + activePointerId
463+
+ " in onInterceptTouchEvent");
464+
break;
465+
}
466+
459467
final int x = (int) ev.getX(pointerIndex);
460468
final int xDiff = (int) Math.abs(x - mLastMotionX);
461469
if (xDiff > mTouchSlop) {
@@ -557,6 +565,11 @@ public boolean onTouchEvent(MotionEvent ev) {
557565
}
558566
case MotionEvent.ACTION_MOVE:
559567
final int activePointerIndex = ev.findPointerIndex(mActivePointerId);
568+
if (activePointerIndex == -1) {
569+
Log.e(TAG, "Invalid pointerId=" + mActivePointerId + " in onTouchEvent");
570+
break;
571+
}
572+
560573
final int x = (int) ev.getX(activePointerIndex);
561574
int deltaX = mLastMotionX - x;
562575
if (!mIsBeingDragged && Math.abs(deltaX) > mTouchSlop) {

core/java/android/widget/ScrollView.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import android.os.Bundle;
2626
import android.os.StrictMode;
2727
import android.util.AttributeSet;
28+
import android.util.Log;
2829
import android.view.FocusFinder;
2930
import android.view.InputDevice;
3031
import android.view.KeyEvent;
@@ -69,6 +70,8 @@ public class ScrollView extends FrameLayout {
6970

7071
static final float MAX_SCROLL_FACTOR = 0.5f;
7172

73+
private static final String TAG = "ScrollView";
74+
7275
private long mLastScroll;
7376

7477
private final Rect mTempRect = new Rect();
@@ -478,6 +481,12 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
478481
}
479482

480483
final int pointerIndex = ev.findPointerIndex(activePointerId);
484+
if (pointerIndex == -1) {
485+
Log.e(TAG, "Invalid pointerId=" + activePointerId
486+
+ " in onInterceptTouchEvent");
487+
break;
488+
}
489+
481490
final int y = (int) ev.getY(pointerIndex);
482491
final int yDiff = Math.abs(y - mLastMotionY);
483492
if (yDiff > mTouchSlop) {
@@ -585,6 +594,11 @@ public boolean onTouchEvent(MotionEvent ev) {
585594
}
586595
case MotionEvent.ACTION_MOVE:
587596
final int activePointerIndex = ev.findPointerIndex(mActivePointerId);
597+
if (activePointerIndex == -1) {
598+
Log.e(TAG, "Invalid pointerId=" + mActivePointerId + " in onTouchEvent");
599+
break;
600+
}
601+
588602
final int y = (int) ev.getY(activePointerIndex);
589603
int deltaY = mLastMotionY - y;
590604
if (!mIsBeingDragged && Math.abs(deltaY) > mTouchSlop) {

0 commit comments

Comments
 (0)