Skip to content

Commit 58dc9b6

Browse files
Jean-Baptiste QueruAndroid Git Automerger
authored andcommitted
am 790d340: am d86bebb: am 322b0a1: Merge "Protecting more views from (bad) MotionEvents"
* commit '790d34039df650d983c7c87a2a2e888e18edc2be': Protecting more views from (bad) MotionEvents
2 parents 058f003 + 790d340 commit 58dc9b6

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();
@@ -485,6 +488,12 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
485488
}
486489

487490
final int pointerIndex = ev.findPointerIndex(activePointerId);
491+
if (pointerIndex == -1) {
492+
Log.e(TAG, "Invalid pointerId=" + activePointerId
493+
+ " in onInterceptTouchEvent");
494+
break;
495+
}
496+
488497
final int y = (int) ev.getY(pointerIndex);
489498
final int yDiff = Math.abs(y - mLastMotionY);
490499
if (yDiff > mTouchSlop) {
@@ -592,6 +601,11 @@ public boolean onTouchEvent(MotionEvent ev) {
592601
}
593602
case MotionEvent.ACTION_MOVE:
594603
final int activePointerIndex = ev.findPointerIndex(mActivePointerId);
604+
if (activePointerIndex == -1) {
605+
Log.e(TAG, "Invalid pointerId=" + mActivePointerId + " in onTouchEvent");
606+
break;
607+
}
608+
595609
final int y = (int) ev.getY(activePointerIndex);
596610
int deltaY = mLastMotionY - y;
597611
if (!mIsBeingDragged && Math.abs(deltaY) > mTouchSlop) {

0 commit comments

Comments
 (0)