From 829b606b988f679e6685148ac675f7ecb2ae7aa2 Mon Sep 17 00:00:00 2001 From: Daniel Frett Date: Wed, 25 Sep 2024 09:31:46 -0600 Subject: [PATCH] Handle the updated invalid touch event exceptions --- .../ccci/gto/android/common/util/view/ViewUtils.java | 7 +++++-- .../gto/android/common/util/view/ViewUtilsTest.java | 10 ++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/gto-support-util/src/main/java/org/ccci/gto/android/common/util/view/ViewUtils.java b/gto-support-util/src/main/java/org/ccci/gto/android/common/util/view/ViewUtils.java index 1dd500ccb..d20fc1574 100644 --- a/gto-support-util/src/main/java/org/ccci/gto/android/common/util/view/ViewUtils.java +++ b/gto-support-util/src/main/java/org/ccci/gto/android/common/util/view/ViewUtils.java @@ -62,7 +62,10 @@ public static boolean handleOnTouchEventException(@NonNull } private static boolean isMotionEventPointerIndexException(@NonNull final Throwable cause) { - return cause instanceof IllegalArgumentException && cause.getMessage() != null && - cause.getMessage().startsWith("pointerIndex out of range"); + if (!(cause instanceof IllegalArgumentException)) return false; + final String message = cause.getMessage(); + if (message == null) return false; + if (message.startsWith("pointerIndex out of range")) return true; + return message.startsWith("invalid pointerIndex"); } } diff --git a/gto-support-util/src/test/java/org/ccci/gto/android/common/util/view/ViewUtilsTest.java b/gto-support-util/src/test/java/org/ccci/gto/android/common/util/view/ViewUtilsTest.java index de2b8e3cb..95903d64e 100644 --- a/gto-support-util/src/test/java/org/ccci/gto/android/common/util/view/ViewUtilsTest.java +++ b/gto-support-util/src/test/java/org/ccci/gto/android/common/util/view/ViewUtilsTest.java @@ -1,19 +1,25 @@ package org.ccci.gto.android.common.util.view; -import org.junit.Test; - import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import org.junit.Test; + public class ViewUtilsTest { private static final Exception[] TOUCH_EXCEPTIONS_TO_SUPPRESS = { new IllegalArgumentException("pointerIndex out of range"), new IllegalArgumentException("pointerIndex out of range pointerIndex=-1 pointerCount=1"), + new IllegalArgumentException( + "invalid pointerIndex -1 for MotionEvent { action=MOVE, id[0]=1, x[0]=281.459, y[0]=212.818, " + + "historySize=2, eventTime=22300703589796, downTime=22299744899000, deviceId=3, " + + "source=TOUCHSCREEN, displayId=0, eventId=313846789}" + ) }; private static final Exception[] TOUCH_EXCEPTIONS_TO_PROPAGATE = { + new RuntimeException(), new IllegalArgumentException() };