Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 43456eee authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

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

parents 1c0ca5ca f7dcf990
Loading
Loading
Loading
Loading
+21 −5
Original line number Diff line number Diff line
@@ -184,7 +184,12 @@ public class FullScreenMagnificationGestureHandler extends MagnificationGestureH
        mPanningScalingState.mScrollGestureDetector.onTouchEvent(event);
        mPanningScalingState.mScaleGestureDetector.onTouchEvent(event);

        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);
        }
    }
}