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

Commit 13cd100e authored by Annie Chin's avatar Annie Chin
Browse files

Catch IllegalArgumentException in CalculatorPadViewPager.

Test: Swipe/fling of panels still works with and without talkback enabled.
Fixes: 34804495

Prevent crashes resulting from invalid pointer ids (probably caused by
multitouch).

Change-Id: Icadcc91fe744e45cb66ada98d438cb778042f4e8
parent b61d00b7
Loading
Loading
Loading
Loading
+50 −39
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.graphics.Color;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.util.Log;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
@@ -186,6 +187,7 @@ public class CalculatorPadViewPager extends ViewPager {

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        try {
            // Always intercept touch events when a11y focused since otherwise they will be
            // incorrectly offset by a11y before being dispatched to children.
            if (isAccessibilityFocused() || super.onInterceptTouchEvent(ev)) {
@@ -228,14 +230,23 @@ public class CalculatorPadViewPager extends ViewPager {
            }

            return false;
        } catch (IllegalArgumentException e) {
            Log.e("Calculator", "Error intercepting touch event", e);
            return false;
        }
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        try {
            // Allow both the gesture detector and super to handle the touch event so they both see
            // the full sequence of events. This should be safe since the gesture detector only
            // handle clicks and super only handles swipes.
            mGestureDetector.onTouchEvent(ev);
            return super.onTouchEvent(ev);
        } catch (IllegalArgumentException e) {
            Log.e("Calculator", "Error processing touch event", e);
            return false;
        }
    }
}