From 2892de61dcbe83d39b75329a5919162f1c75db48 Mon Sep 17 00:00:00 2001 From: Harry Cutts Date: Thu, 3 Nov 2022 15:38:39 +0000 Subject: [PATCH] Add MotionEvent#obtain overload for classification Bug: 257028305 Test: atest CtsHardwareTestCases (no new failures) Change-Id: I3255b01fb136b11f4afecc6db4b26725ca3a36d5 --- core/java/android/view/MotionEvent.java | 48 +++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/core/java/android/view/MotionEvent.java b/core/java/android/view/MotionEvent.java index a08a5a8892c09..bf40bdcd7e37d 100644 --- a/core/java/android/view/MotionEvent.java +++ b/core/java/android/view/MotionEvent.java @@ -1779,16 +1779,18 @@ public final class MotionEvent extends InputEvent implements Parcelable { * @param source The source of this event. * @param displayId The display ID associated with this event. * @param flags The motion event flags. + * @param classification The classification to give this event. * @hide */ - static public MotionEvent obtain(long downTime, long eventTime, + public static MotionEvent obtain(long downTime, long eventTime, int action, int pointerCount, PointerProperties[] pointerProperties, PointerCoords[] pointerCoords, int metaState, int buttonState, float xPrecision, float yPrecision, int deviceId, - int edgeFlags, int source, int displayId, int flags) { + int edgeFlags, int source, int displayId, int flags, + @Classification int classification) { MotionEvent ev = obtain(); final boolean success = ev.initialize(deviceId, source, displayId, action, flags, edgeFlags, - metaState, buttonState, CLASSIFICATION_NONE, 0, 0, xPrecision, yPrecision, + metaState, buttonState, classification, 0, 0, xPrecision, yPrecision, downTime * NS_PER_MS, eventTime * NS_PER_MS, pointerCount, pointerProperties, pointerCoords); if (!success) { @@ -1799,6 +1801,46 @@ public final class MotionEvent extends InputEvent implements Parcelable { return ev; } + /** + * Create a new MotionEvent, filling in all of the basic values that + * define the motion. + * + * @param downTime The time (in ms) when the user originally pressed down to start + * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}. + * @param eventTime The the time (in ms) when this specific event was generated. This + * must be obtained from {@link SystemClock#uptimeMillis()}. + * @param action The kind of action being performed, such as {@link #ACTION_DOWN}. + * @param pointerCount The number of pointers that will be in this event. + * @param pointerProperties An array of pointerCount values providing + * a {@link PointerProperties} property object for each pointer, which must + * include the pointer identifier. + * @param pointerCoords An array of pointerCount values providing + * a {@link PointerCoords} coordinate object for each pointer. + * @param metaState The state of any meta / modifier keys that were in effect when + * the event was generated. + * @param buttonState The state of buttons that are pressed. + * @param xPrecision The precision of the X coordinate being reported. + * @param yPrecision The precision of the Y coordinate being reported. + * @param deviceId The id for the device that this event came from. An id of + * zero indicates that the event didn't come from a physical device; other + * numbers are arbitrary and you shouldn't depend on the values. + * @param edgeFlags A bitfield indicating which edges, if any, were touched by this + * MotionEvent. + * @param source The source of this event. + * @param displayId The display ID associated with this event. + * @param flags The motion event flags. + * @hide + */ + public static MotionEvent obtain(long downTime, long eventTime, + int action, int pointerCount, PointerProperties[] pointerProperties, + PointerCoords[] pointerCoords, int metaState, int buttonState, + float xPrecision, float yPrecision, int deviceId, + int edgeFlags, int source, int displayId, int flags) { + return obtain(downTime, eventTime, action, pointerCount, pointerProperties, pointerCoords, + metaState, buttonState, xPrecision, yPrecision, deviceId, edgeFlags, source, + displayId, flags, CLASSIFICATION_NONE); + } + /** * Create a new MotionEvent, filling in all of the basic values that * define the motion.