diff options
| author | 2023-02-10 06:06:56 +0000 | |
|---|---|---|
| committer | 2023-02-21 19:13:53 +0000 | |
| commit | eb60a2559f47b35ba0b5973b61d87948409c6e7f (patch) | |
| tree | ec58be99d33cd923ffc5902a4c964fe38c384ee0 | |
| parent | 921ecfe4497b1b899b6673da6fcf78a63ca6cffb (diff) | |
Add int range for touchscreen pointer id.
We are validating touch point id from ag/21078609, it's necessary to
enforce this from the API to prevent silent failures.
Test: atest VirtualInputDeviceConfigTest VirtualTouchscreenTest
Bug: 259554911
Change-Id: Ica8a3b5cc46517e6773c8c3a9d46e5606c63c00d
Merged-In: Ica8a3b5cc46517e6773c8c3a9d46e5606c63c00d
| -rw-r--r-- | core/api/system-current.txt | 2 | ||||
| -rw-r--r-- | core/java/android/hardware/input/VirtualTouchEvent.java | 15 |
2 files changed, 15 insertions, 2 deletions
diff --git a/core/api/system-current.txt b/core/api/system-current.txt index 6581c421f970..664961fa8346 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -5117,7 +5117,7 @@ package android.hardware.input { method @NonNull public android.hardware.input.VirtualTouchEvent build(); method @NonNull public android.hardware.input.VirtualTouchEvent.Builder setAction(int); method @NonNull public android.hardware.input.VirtualTouchEvent.Builder setMajorAxisSize(@FloatRange(from=0.0f) float); - method @NonNull public android.hardware.input.VirtualTouchEvent.Builder setPointerId(int); + method @NonNull public android.hardware.input.VirtualTouchEvent.Builder setPointerId(@IntRange(from=0, to=0x10 - 1) int); method @NonNull public android.hardware.input.VirtualTouchEvent.Builder setPressure(@FloatRange(from=0.0f) float); method @NonNull public android.hardware.input.VirtualTouchEvent.Builder setToolType(int); method @NonNull public android.hardware.input.VirtualTouchEvent.Builder setX(float); diff --git a/core/java/android/hardware/input/VirtualTouchEvent.java b/core/java/android/hardware/input/VirtualTouchEvent.java index 9b1e6e84a022..a2bb382e9950 100644 --- a/core/java/android/hardware/input/VirtualTouchEvent.java +++ b/core/java/android/hardware/input/VirtualTouchEvent.java @@ -18,6 +18,7 @@ package android.hardware.input; import android.annotation.FloatRange; import android.annotation.IntDef; +import android.annotation.IntRange; import android.annotation.NonNull; import android.annotation.SystemApi; import android.os.Parcel; @@ -82,6 +83,10 @@ public final class VirtualTouchEvent implements Parcelable { @Retention(RetentionPolicy.SOURCE) public @interface Action {} + // The maximum number of pointers that can be touching the screen at once. (See MAX_POINTERS + // in frameworks/native/include/input/Input.h) + private static final int MAX_POINTERS = 16; + private final int mPointerId; private final @ToolType int mToolType; private final @Action int mAction; @@ -214,9 +219,17 @@ public final class VirtualTouchEvent implements Parcelable { /** * Sets the pointer id of the event. * + * <p>A Valid pointer id need to be in the range of 0 to 15. + * * @return this builder, to allow for chaining of calls */ - public @NonNull Builder setPointerId(int pointerId) { + public @NonNull Builder setPointerId( + @IntRange(from = 0, to = MAX_POINTERS - 1) int pointerId) { + if (pointerId < 0 || pointerId > 15) { + throw new IllegalArgumentException( + "The pointer id must be in the range 0 - " + (MAX_POINTERS - 1) + + "inclusive, but was: " + pointerId); + } mPointerId = pointerId; return this; } |