fix(magnification): don't crash when reciving unexpected motion events.
This fixes an issue where the device was crashing and rebooting when triple tapping to activate magnification at the same time as covering the proxmity sensor while on a voice call. Bug: b/236875528 Test: manual: 1. Perform a voice call 2. While on voice call, execute the "Triple tap on screen" gesture, holding down your finger on the last tap and then cover the proximity sensor. 3. The device should not crash Change-Id: I9415c5b378b32342c016b17dfcef12cde45ce237
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user