Make PointerLocationView more resilient.
Right now it crashes if we miss an up event since the active pointer
won't get reset. We can't just clear this in onDetachedFromWindow
because of how it gets drawn in system_server, so instead we just check
before using the active pointer.
Bug: 109779280
Test: put settings into split screen, frequently enable / disable
Pointer Location while tapping in another app window. See that it
doesn't crash.
Change-Id: If2b1f3157574c962b24115b0ecf0a27feec8e84c
This commit is contained in:
committed by
Siarhei Vishniakou
parent
eb3c80bfdd
commit
93b3c57a13
@@ -66,15 +66,15 @@ public class PointerLocationView extends View implements InputDeviceListener,
|
||||
private float[] mTraceY = new float[32];
|
||||
private boolean[] mTraceCurrent = new boolean[32];
|
||||
private int mTraceCount;
|
||||
|
||||
|
||||
// True if the pointer is down.
|
||||
@UnsupportedAppUsage
|
||||
private boolean mCurDown;
|
||||
|
||||
|
||||
// Most recent coordinates.
|
||||
private PointerCoords mCoords = new PointerCoords();
|
||||
private int mToolType;
|
||||
|
||||
|
||||
// Most recent velocity.
|
||||
private float mXVelocity;
|
||||
private float mYVelocity;
|
||||
@@ -107,7 +107,7 @@ public class PointerLocationView extends View implements InputDeviceListener,
|
||||
float[] newTraceX = new float[traceCapacity];
|
||||
System.arraycopy(mTraceX, 0, newTraceX, 0, mTraceCount);
|
||||
mTraceX = newTraceX;
|
||||
|
||||
|
||||
float[] newTraceY = new float[traceCapacity];
|
||||
System.arraycopy(mTraceY, 0, newTraceY, 0, mTraceCount);
|
||||
mTraceY = newTraceY;
|
||||
@@ -116,7 +116,7 @@ public class PointerLocationView extends View implements InputDeviceListener,
|
||||
System.arraycopy(mTraceCurrent, 0, newTraceCurrent, 0, mTraceCount);
|
||||
mTraceCurrent= newTraceCurrent;
|
||||
}
|
||||
|
||||
|
||||
mTraceX[mTraceCount] = x;
|
||||
mTraceY[mTraceCount] = y;
|
||||
mTraceCurrent[mTraceCount] = current;
|
||||
@@ -162,7 +162,7 @@ public class PointerLocationView extends View implements InputDeviceListener,
|
||||
|
||||
@UnsupportedAppUsage
|
||||
private boolean mPrintCoords = true;
|
||||
|
||||
|
||||
public PointerLocationView(Context c) {
|
||||
super(c);
|
||||
setFocusableInTouchMode(true);
|
||||
@@ -211,7 +211,7 @@ public class PointerLocationView extends View implements InputDeviceListener,
|
||||
PointerState ps = new PointerState();
|
||||
mPointers.add(ps);
|
||||
mActivePointerId = 0;
|
||||
|
||||
|
||||
mVelocity = VelocityTracker.obtain();
|
||||
|
||||
String altStrategy = SystemProperties.get(ALT_STRATEGY_PROPERY_KEY);
|
||||
@@ -252,7 +252,7 @@ public class PointerLocationView extends View implements InputDeviceListener,
|
||||
+ " bottom=" + mTextMetrics.bottom);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Draw an oval. When angle is 0 radians, orients the major axis vertically,
|
||||
// angles less than or greater than 0 radians rotate the major axis left or right.
|
||||
private RectF mReusableOvalRect = new RectF();
|
||||
@@ -399,7 +399,7 @@ public class PointerLocationView extends View implements InputDeviceListener,
|
||||
}
|
||||
|
||||
private void drawLabels(Canvas canvas) {
|
||||
if (mActivePointerId < 0) {
|
||||
if (mActivePointerId < 0 || mActivePointerId >= mPointers.size()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -614,8 +614,8 @@ public class PointerLocationView extends View implements InputDeviceListener,
|
||||
NP++;
|
||||
}
|
||||
|
||||
if (mActivePointerId < 0 ||
|
||||
!mPointers.get(mActivePointerId).mCurDown) {
|
||||
if (mActivePointerId < 0 || mActivePointerId >= NP
|
||||
|| !mPointers.get(mActivePointerId).mCurDown) {
|
||||
mActivePointerId = id;
|
||||
}
|
||||
|
||||
@@ -710,7 +710,7 @@ public class PointerLocationView extends View implements InputDeviceListener,
|
||||
|
||||
invalidate();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
onPointerEvent(event);
|
||||
@@ -862,16 +862,16 @@ public class PointerLocationView extends View implements InputDeviceListener,
|
||||
private static final class FasterStringBuilder {
|
||||
private char[] mChars;
|
||||
private int mLength;
|
||||
|
||||
|
||||
public FasterStringBuilder() {
|
||||
mChars = new char[64];
|
||||
}
|
||||
|
||||
|
||||
public FasterStringBuilder clear() {
|
||||
mLength = 0;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public FasterStringBuilder append(String value) {
|
||||
final int valueLength = value.length();
|
||||
final int index = reserve(valueLength);
|
||||
@@ -879,11 +879,11 @@ public class PointerLocationView extends View implements InputDeviceListener,
|
||||
mLength += valueLength;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public FasterStringBuilder append(int value) {
|
||||
return append(value, 0);
|
||||
}
|
||||
|
||||
|
||||
public FasterStringBuilder append(int value, int zeroPadWidth) {
|
||||
final boolean negative = value < 0;
|
||||
if (negative) {
|
||||
@@ -893,16 +893,16 @@ public class PointerLocationView extends View implements InputDeviceListener,
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int index = reserve(11);
|
||||
final char[] chars = mChars;
|
||||
|
||||
|
||||
if (value == 0) {
|
||||
chars[index++] = '0';
|
||||
mLength += 1;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
if (negative) {
|
||||
chars[index++] = '-';
|
||||
}
|
||||
@@ -916,18 +916,18 @@ public class PointerLocationView extends View implements InputDeviceListener,
|
||||
chars[index++] = '0';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
do {
|
||||
int digit = value / divisor;
|
||||
value -= digit * divisor;
|
||||
divisor /= 10;
|
||||
chars[index++] = (char) (digit + '0');
|
||||
} while (divisor != 0);
|
||||
|
||||
|
||||
mLength = index;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public FasterStringBuilder append(float value, int precision) {
|
||||
int scale = 1;
|
||||
for (int i = 0; i < precision; i++) {
|
||||
@@ -947,15 +947,15 @@ public class PointerLocationView extends View implements InputDeviceListener,
|
||||
value -= Math.floor(value);
|
||||
append((int) (value * scale), precision);
|
||||
}
|
||||
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new String(mChars, 0, mLength);
|
||||
}
|
||||
|
||||
|
||||
private int reserve(int length) {
|
||||
final int oldLength = mLength;
|
||||
final int newLength = mLength + length;
|
||||
|
||||
Reference in New Issue
Block a user