Merge "fix(magnification): don't crash when reciving unexpected motion events." into tm-qpr-dev

This commit is contained in:
TreeHugger Robot
2022-07-01 22:37:53 +00:00
committed by Android (Google) Code Review

View File

@@ -184,7 +184,12 @@ public class FullScreenMagnificationGestureHandler extends MagnificationGestureH
mPanningScalingState.mScrollGestureDetector.onTouchEvent(event);
mPanningScalingState.mScaleGestureDetector.onTouchEvent(event);
stateHandler.onMotionEvent(event, rawEvent, policyFlags);
try {
stateHandler.onMotionEvent(event, rawEvent, policyFlags);
} catch (GestureException e) {
Slog.e(mLogTag, "Error processing motion event", e);
clearAndTransitionToStateDetecting();
}
}
@Override
@@ -281,7 +286,8 @@ public class FullScreenMagnificationGestureHandler extends MagnificationGestureH
}
interface State {
void onMotionEvent(MotionEvent event, MotionEvent rawEvent, int policyFlags);
void onMotionEvent(MotionEvent event, MotionEvent rawEvent, int policyFlags)
throws GestureException;
default void clear() {}
@@ -439,7 +445,8 @@ public class FullScreenMagnificationGestureHandler extends MagnificationGestureH
private boolean mLastMoveOutsideMagnifiedRegion;
@Override
public void onMotionEvent(MotionEvent event, MotionEvent rawEvent, int policyFlags) {
public void onMotionEvent(MotionEvent event, MotionEvent rawEvent, int policyFlags)
throws GestureException {
final int action = event.getActionMasked();
switch (action) {
case ACTION_POINTER_DOWN: {
@@ -449,7 +456,7 @@ public class FullScreenMagnificationGestureHandler extends MagnificationGestureH
break;
case ACTION_MOVE: {
if (event.getPointerCount() != 1) {
throw new IllegalStateException("Should have one pointer down.");
throw new GestureException("Should have one pointer down.");
}
final float eventX = event.getX();
final float eventY = event.getY();
@@ -475,7 +482,7 @@ public class FullScreenMagnificationGestureHandler extends MagnificationGestureH
case ACTION_DOWN:
case ACTION_POINTER_UP: {
throw new IllegalArgumentException(
throw new GestureException(
"Unexpected event type: " + MotionEvent.actionToString(action));
}
}
@@ -1087,4 +1094,13 @@ public class FullScreenMagnificationGestureHandler extends MagnificationGestureH
mGestureHandler.mDetectingState.setShortcutTriggered(false);
}
}
/**
* Indicates an error with a gesture handler or state.
*/
private static class GestureException extends Exception {
GestureException(String message) {
super(message);
}
}
}