summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Powell <adamp@google.com>2012-09-28 12:05:10 -0700
committerAdam Powell <adamp@google.com>2012-09-28 12:05:10 -0700
commitf3a2bf8edd2e070a24f0d7c105d78b38576e14ac (patch)
tree5d6d8b6c1dacb34e42482d161f5911d2fba63f9a
parent9dbbfcda81f251f23aded866f7f9d49d8a744c75 (diff)
downloadframeworks_base-f3a2bf8edd2e070a24f0d7c105d78b38576e14ac.zip
frameworks_base-f3a2bf8edd2e070a24f0d7c105d78b38576e14ac.tar.gz
frameworks_base-f3a2bf8edd2e070a24f0d7c105d78b38576e14ac.tar.bz2
ScaleGestureDetector does the safety dance.
Warn in the event of possibly bogus event streams and don't try to clear empty history. Bug 7241640 Bug 7243006 Change-Id: I037cf1334cab790ef5998ca5f8f6b323ed5f4459
-rw-r--r--core/java/android/view/ScaleGestureDetector.java22
1 files changed, 20 insertions, 2 deletions
diff --git a/core/java/android/view/ScaleGestureDetector.java b/core/java/android/view/ScaleGestureDetector.java
index b0a2711..4873860 100644
--- a/core/java/android/view/ScaleGestureDetector.java
+++ b/core/java/android/view/ScaleGestureDetector.java
@@ -19,6 +19,7 @@ package android.view;
import android.content.Context;
import android.os.SystemClock;
import android.util.FloatMath;
+import android.util.Log;
import java.util.Arrays;
@@ -223,10 +224,14 @@ public class ScaleGestureDetector {
* @param id pointer id to clear
* @see #addTouchHistory(MotionEvent)
*/
- private void removeTouchHistoryForId(int id) {
+ private boolean removeTouchHistoryForId(int id) {
+ if (id >= mTouchHistoryLastAccepted.length) {
+ return false;
+ }
mTouchHistoryLastAccepted[id] = Float.NaN;
mTouchHistoryDirection[id] = 0;
mTouchHistoryLastAcceptedTime[id] = 0;
+ return true;
}
/**
@@ -236,6 +241,11 @@ public class ScaleGestureDetector {
* @see #addTouchHistory(MotionEvent)
*/
private float getAdjustedTouchHistory(int id) {
+ if (id >= mTouchHistoryLastAccepted.length) {
+ Log.e(TAG, "Error retrieving adjusted touch history for id=" + id +
+ " - incomplete event stream?");
+ return 0;
+ }
return mTouchHistoryLastAccepted[id];
}
@@ -244,6 +254,10 @@ public class ScaleGestureDetector {
* @see #addTouchHistory(MotionEvent)
*/
private void clearTouchHistory() {
+ if (mTouchHistoryLastAccepted == null) {
+ // All three arrays will be null if this is the case; nothing to do.
+ return;
+ }
Arrays.fill(mTouchHistoryLastAccepted, Float.NaN);
Arrays.fill(mTouchHistoryDirection, 0);
Arrays.fill(mTouchHistoryLastAcceptedTime, 0);
@@ -333,7 +347,11 @@ public class ScaleGestureDetector {
final float focusY = sumY / div;
if (pointerUp) {
- removeTouchHistoryForId(event.getPointerId(event.getActionIndex()));
+ final int id = event.getPointerId(event.getActionIndex());
+ if (!removeTouchHistoryForId(id)) {
+ Log.e(TAG, "Got ACTION_POINTER_UP for previously unknown id=" + id +
+ " - incomplete event stream?");
+ }
} else {
addTouchHistory(event);
}