MotionEvent: add test API to identify resampled events
The VirtualTouchscreenTest#sendTouchEvent CTS test injects input events
and checks that they are delivered to an app correctly. However, we
think that performance issues in the test device fleet sometimes cause
these events to be delivered so slowly that they end up being resampled,
causing the test's assertions to fail. Exposing this API allows the test
to ignore resampled events.
I can't just make the raw field visible (like the others are), as
metalava complains if I do so.
Bug: 292544797
Test: see the CTS CL
Change-Id: I553d1daba65f1d9886cc778d4ac4bdccc29954b7
diff --git a/core/api/test-current.txt b/core/api/test-current.txt
index 642813f..fd59470 100644
--- a/core/api/test-current.txt
+++ b/core/api/test-current.txt
@@ -3504,6 +3504,10 @@
field public static final int FLAG_IS_ACCESSIBILITY_EVENT = 2048; // 0x800
}
+ public static final class MotionEvent.PointerCoords {
+ method public boolean isResampled();
+ }
+
@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME) @java.lang.annotation.Target({java.lang.annotation.ElementType.METHOD}) public @interface RemotableViewMethod {
method public abstract String asyncImpl() default "";
}
diff --git a/core/java/android/view/MotionEvent.java b/core/java/android/view/MotionEvent.java
index cdf5eec3..776eeda 100644
--- a/core/java/android/view/MotionEvent.java
+++ b/core/java/android/view/MotionEvent.java
@@ -18,7 +18,6 @@
import static android.os.IInputConstants.INPUT_EVENT_FLAG_IS_ACCESSIBILITY_EVENT;
import static android.view.Display.DEFAULT_DISPLAY;
-
import static java.lang.annotation.RetentionPolicy.SOURCE;
import android.annotation.IntDef;
@@ -4361,6 +4360,17 @@
public boolean isResampled;
/**
+ * Returns true if this pointer coords object was generated by resampling, rather than from
+ * an actual input event from the device at this time.
+ *
+ * @hide
+ */
+ @TestApi
+ public boolean isResampled() {
+ return isResampled;
+ }
+
+ /**
* Clears the contents of this object.
* Resets all axes to zero.
*/