Throw exception when invalid time stamps are detected in debug mode
Change-Id: I360b5bd09869bc85ab3bccb8a43a20fed0035d9b
This commit is contained in:
parent
19d68ce200
commit
f1074c508e
1 changed files with 22 additions and 0 deletions
|
@ -18,8 +18,11 @@ package com.android.inputmethod.latin;
|
||||||
|
|
||||||
import com.android.inputmethod.annotations.UsedForTesting;
|
import com.android.inputmethod.annotations.UsedForTesting;
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
// TODO: This class is not thread-safe.
|
// TODO: This class is not thread-safe.
|
||||||
public final class InputPointers {
|
public final class InputPointers {
|
||||||
|
private static final String TAG = InputPointers.class.getSimpleName();
|
||||||
private final int mDefaultCapacity;
|
private final int mDefaultCapacity;
|
||||||
private final ResizableIntArray mXCoordinates;
|
private final ResizableIntArray mXCoordinates;
|
||||||
private final ResizableIntArray mYCoordinates;
|
private final ResizableIntArray mYCoordinates;
|
||||||
|
@ -126,6 +129,11 @@ public final class InputPointers {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int[] getTimes() {
|
public int[] getTimes() {
|
||||||
|
if (LatinImeLogger.sDBG) {
|
||||||
|
if (!isValidTimeStamps()) {
|
||||||
|
throw new RuntimeException("Time stamps are invalid.");
|
||||||
|
}
|
||||||
|
}
|
||||||
return mTimes.getPrimitiveArray();
|
return mTimes.getPrimitiveArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,4 +142,18 @@ public final class InputPointers {
|
||||||
return "size=" + getPointerSize() + " id=" + mPointerIds + " time=" + mTimes
|
return "size=" + getPointerSize() + " id=" + mPointerIds + " time=" + mTimes
|
||||||
+ " x=" + mXCoordinates + " y=" + mYCoordinates;
|
+ " x=" + mXCoordinates + " y=" + mYCoordinates;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isValidTimeStamps() {
|
||||||
|
final int[] times = mTimes.getPrimitiveArray();
|
||||||
|
for (int i = 1; i < getPointerSize(); ++i) {
|
||||||
|
if (times[i] < times[i - 1]) {
|
||||||
|
// dump
|
||||||
|
for (int j = 0; j < times.length; ++j) {
|
||||||
|
Log.d(TAG, "--- (" + j + ") " + times[j]);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue