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
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user