1 /* 2 * Copyright (C) 2020 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.view; 18 19 import static android.view.MotionEvent.FLAG_IS_ACCESSIBILITY_EVENT; 20 import static android.view.MotionEvent.FLAG_WINDOW_IS_OBSCURED; 21 import static android.view.MotionEvent.FLAG_WINDOW_IS_PARTIALLY_OBSCURED; 22 23 import static java.lang.annotation.RetentionPolicy.SOURCE; 24 25 import android.annotation.IntDef; 26 import android.annotation.Nullable; 27 import android.annotation.SuppressLint; 28 import android.os.Parcel; 29 import android.os.Parcelable; 30 31 import com.android.internal.util.DataClass; 32 33 import java.lang.annotation.Retention; 34 35 /** 36 * MotionEvent that has been verified by the system. 37 * The data contained in this class is always a subset of a {@link MotionEvent}. Use this class to 38 * check which data has been confirmed by the system to be authentic. 39 * 40 * Most applications do not need to use this class. 41 * 42 * {@see android.hardware.input.InputManager#verifyInputEvent} 43 */ 44 @DataClass(genHiddenConstructor = true, genEqualsHashCode = true) 45 public final class VerifiedMotionEvent extends VerifiedInputEvent implements Parcelable { 46 private static final String TAG = "VerifiedMotionEvent"; 47 48 /** 49 * The raw X coordinate of the primary pointer. 50 * @see MotionEvent#getRawX() 51 */ 52 private float mRawX; 53 54 /** 55 * The raw Y coordinate of the primary pointer. 56 * @see MotionEvent#getRawY() 57 */ 58 private float mRawY; 59 60 /** @hide */ 61 @Retention(SOURCE) 62 @IntDef({MotionEvent.ACTION_DOWN, MotionEvent.ACTION_POINTER_DOWN, MotionEvent.ACTION_CANCEL, 63 MotionEvent.ACTION_POINTER_UP, MotionEvent.ACTION_UP}) 64 public @interface MotionEventAction {}; 65 66 /** 67 * The masked action being performed, without pointer index information. 68 * 69 * @see MotionEvent#getActionMasked() 70 */ 71 @MotionEventAction 72 private int mActionMasked; 73 74 /** 75 * The time that the gesture started, in nanoseconds. 76 * Uses the same time base as {@link android.os.SystemClock#uptimeMillis()} 77 * 78 * @see MotionEvent#getDownTime() 79 */ 80 @SuppressLint({"MethodNameUnits"}) 81 private long mDownTimeNanos; 82 83 /** 84 * Returns the flags for this motion event. 85 * 86 * @see MotionEvent#getFlags() 87 * @see MotionEvent#FLAG_IS_ACCESSIBILITY_EVENT 88 * @see MotionEvent#FLAG_WINDOW_IS_OBSCURED 89 * @see MotionEvent#FLAG_WINDOW_IS_PARTIALLY_OBSCURED 90 * @hide 91 */ 92 private int mFlags; 93 94 /** 95 * The state of any meta / modifier keys that were in effect when the event was generated. 96 * 97 * @see MotionEvent#getMetaState() 98 */ 99 private int mMetaState; 100 101 /** 102 * The state of all buttons that are pressed such as a mouse or stylus button. 103 * 104 * @see MotionEvent#getButtonState() 105 */ 106 private int mButtonState; 107 108 /** 109 * Get a specific flag of this motion event, if possible. Return null if the flag value could 110 * not be checked. 111 * 112 * @param flag the flag of interest 113 * @return Boolean(true) if the motion event has the requested flag 114 * Boolean(false) if the motion event does not have the requested flag 115 * null if the flag value could not be checked 116 * 117 * @see MotionEvent#FLAG_WINDOW_IS_OBSCURED 118 * @see MotionEvent#FLAG_WINDOW_IS_PARTIALLY_OBSCURED 119 */ getFlag(int flag)120 public @Nullable Boolean getFlag(int flag) { 121 switch(flag) { 122 // InputDispatcher only verifies a subset of the MotionEvent flags. 123 // These values must be kept in sync with Input.cpp 124 case FLAG_IS_ACCESSIBILITY_EVENT: 125 case FLAG_WINDOW_IS_OBSCURED: 126 case FLAG_WINDOW_IS_PARTIALLY_OBSCURED: 127 return (mFlags & flag) != 0; 128 } 129 return null; 130 } 131 132 // The codegen tool doesn't fully support subclasses, since it works on a per-file basis. 133 // To modify this file: 134 // 1. run codegen on this file 135 // 2. edit the constructor signature 136 // 3. add the "super" call for constructor that receives a Parcel 137 // 4. add the "super" call to the writeToParcel method 138 // 5. Update "equals" and "hashcode" methods to include VerifiedInputEvent fields 139 140 141 142 // Code below generated by codegen v1.0.20. 143 // 144 // DO NOT MODIFY! 145 // CHECKSTYLE:OFF Generated code 146 // 147 // To regenerate run: 148 // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/view/VerifiedMotionEvent.java 149 // 150 // To exclude the generated code from IntelliJ auto-formatting enable (one-time): 151 // Settings > Editor > Code Style > Formatter Control 152 //@formatter:off 153 154 155 /** 156 * Creates a new VerifiedMotionEvent. 157 * 158 * @param rawX 159 * The raw X coordinate of the primary pointer. 160 * @param rawY 161 * The raw Y coordinate of the primary pointer. 162 * @param actionMasked 163 * The masked action being performed, without pointer index information. 164 * @param downTimeNanos 165 * The time that the gesture started, in nanoseconds. 166 * Uses the same time base as {@link android.os.SystemClock#uptimeMillis()} 167 * @param flags 168 * Returns the flags for this motion event. 169 * @param metaState 170 * The state of any meta / modifier keys that were in effect when the event was generated. 171 * @param buttonState 172 * The state of all buttons that are pressed such as a mouse or stylus button. 173 * @hide 174 */ 175 @DataClass.Generated.Member VerifiedMotionEvent( int deviceId, long eventTimeNanos, int source, int displayId, float rawX, float rawY, @MotionEventAction int actionMasked, @SuppressLint({ R }) long downTimeNanos, int flags, int metaState, int buttonState)176 public VerifiedMotionEvent( 177 int deviceId, long eventTimeNanos, int source, int displayId, 178 float rawX, 179 float rawY, 180 @MotionEventAction int actionMasked, 181 @SuppressLint({ "MethodNameUnits" }) long downTimeNanos, 182 int flags, 183 int metaState, 184 int buttonState) { 185 super(VERIFIED_MOTION, deviceId, eventTimeNanos, source, displayId); 186 this.mRawX = rawX; 187 this.mRawY = rawY; 188 this.mActionMasked = actionMasked; 189 com.android.internal.util.AnnotationValidations.validate( 190 MotionEventAction.class, null, mActionMasked); 191 this.mDownTimeNanos = downTimeNanos; 192 this.mFlags = flags; 193 this.mMetaState = metaState; 194 this.mButtonState = buttonState; 195 196 // onConstructed(); // You can define this method to get a callback 197 } 198 199 /** 200 * The raw X coordinate of the primary pointer. 201 * 202 * @see MotionEvent#getRawX() 203 */ 204 @DataClass.Generated.Member getRawX()205 public float getRawX() { 206 return mRawX; 207 } 208 209 /** 210 * The raw Y coordinate of the primary pointer. 211 * 212 * @see MotionEvent#getRawY() 213 */ 214 @DataClass.Generated.Member getRawY()215 public float getRawY() { 216 return mRawY; 217 } 218 219 /** 220 * The masked action being performed, without pointer index information. 221 * 222 * @see MotionEvent#getActionMasked() 223 */ 224 @DataClass.Generated.Member getActionMasked()225 public @MotionEventAction int getActionMasked() { 226 return mActionMasked; 227 } 228 229 /** 230 * The time that the gesture started, in nanoseconds. 231 * Uses the same time base as {@link android.os.SystemClock#uptimeMillis()} 232 * 233 * @see MotionEvent#getDownTime() 234 */ 235 @DataClass.Generated.Member getDownTimeNanos()236 public @SuppressLint({ "MethodNameUnits" }) long getDownTimeNanos() { 237 return mDownTimeNanos; 238 } 239 240 /** 241 * Returns the flags for this motion event. 242 * 243 * @see MotionEvent#getFlags() 244 * @hide 245 */ 246 @DataClass.Generated.Member getFlags()247 public int getFlags() { 248 return mFlags; 249 } 250 251 /** 252 * The state of any meta / modifier keys that were in effect when the event was generated. 253 * 254 * @see MotionEvent#getMetaState() 255 */ 256 @DataClass.Generated.Member getMetaState()257 public int getMetaState() { 258 return mMetaState; 259 } 260 261 /** 262 * The state of all buttons that are pressed such as a mouse or stylus button. 263 * 264 * @see MotionEvent#getButtonState() 265 */ 266 @DataClass.Generated.Member getButtonState()267 public int getButtonState() { 268 return mButtonState; 269 } 270 271 @Override 272 @DataClass.Generated.Member equals(@ullable Object o)273 public boolean equals(@Nullable Object o) { 274 // You can override field equality logic by defining either of the methods like: 275 // boolean fieldNameEquals(VerifiedMotionEvent other) { ... } 276 // boolean fieldNameEquals(FieldType otherValue) { ... } 277 278 if (this == o) return true; 279 if (o == null || getClass() != o.getClass()) return false; 280 @SuppressWarnings("unchecked") 281 VerifiedMotionEvent that = (VerifiedMotionEvent) o; 282 //noinspection PointlessBooleanExpression 283 return true 284 && super.equals(that) 285 && mRawX == that.mRawX 286 && mRawY == that.mRawY 287 && mActionMasked == that.mActionMasked 288 && mDownTimeNanos == that.mDownTimeNanos 289 && mFlags == that.mFlags 290 && mMetaState == that.mMetaState 291 && mButtonState == that.mButtonState; 292 } 293 294 @Override 295 @DataClass.Generated.Member hashCode()296 public int hashCode() { 297 // You can override field hashCode logic by defining methods like: 298 // int fieldNameHashCode() { ... } 299 300 int _hash = 1; 301 _hash = 31 * _hash + super.hashCode(); 302 _hash = 31 * _hash + Float.hashCode(mRawX); 303 _hash = 31 * _hash + Float.hashCode(mRawY); 304 _hash = 31 * _hash + mActionMasked; 305 _hash = 31 * _hash + Long.hashCode(mDownTimeNanos); 306 _hash = 31 * _hash + mFlags; 307 _hash = 31 * _hash + mMetaState; 308 _hash = 31 * _hash + mButtonState; 309 return _hash; 310 } 311 312 @Override 313 @DataClass.Generated.Member writeToParcel(@ndroid.annotation.NonNull Parcel dest, int flags)314 public void writeToParcel(@android.annotation.NonNull Parcel dest, int flags) { 315 // You can override field parcelling by defining methods like: 316 // void parcelFieldName(Parcel dest, int flags) { ... } 317 super.writeToParcel(dest, flags); 318 319 dest.writeFloat(mRawX); 320 dest.writeFloat(mRawY); 321 dest.writeInt(mActionMasked); 322 dest.writeLong(mDownTimeNanos); 323 dest.writeInt(mFlags); 324 dest.writeInt(mMetaState); 325 dest.writeInt(mButtonState); 326 } 327 328 @Override 329 @DataClass.Generated.Member describeContents()330 public int describeContents() { return 0; } 331 332 /** @hide */ 333 @SuppressWarnings({"unchecked", "RedundantCast"}) 334 @DataClass.Generated.Member VerifiedMotionEvent(@ndroid.annotation.NonNull Parcel in)335 /* package-private */ VerifiedMotionEvent(@android.annotation.NonNull Parcel in) { 336 // You can override field unparcelling by defining methods like: 337 // static FieldType unparcelFieldName(Parcel in) { ... } 338 super(in, VERIFIED_MOTION); 339 340 float rawX = in.readFloat(); 341 float rawY = in.readFloat(); 342 int actionMasked = in.readInt(); 343 long downTimeNanos = in.readLong(); 344 int flags = in.readInt(); 345 int metaState = in.readInt(); 346 int buttonState = in.readInt(); 347 348 this.mRawX = rawX; 349 this.mRawY = rawY; 350 this.mActionMasked = actionMasked; 351 com.android.internal.util.AnnotationValidations.validate( 352 MotionEventAction.class, null, mActionMasked); 353 this.mDownTimeNanos = downTimeNanos; 354 this.mFlags = flags; 355 this.mMetaState = metaState; 356 this.mButtonState = buttonState; 357 358 // onConstructed(); // You can define this method to get a callback 359 } 360 361 @DataClass.Generated.Member 362 public static final @android.annotation.NonNull Parcelable.Creator<VerifiedMotionEvent> CREATOR 363 = new Parcelable.Creator<VerifiedMotionEvent>() { 364 @Override 365 public VerifiedMotionEvent[] newArray(int size) { 366 return new VerifiedMotionEvent[size]; 367 } 368 369 @Override 370 public VerifiedMotionEvent createFromParcel(@android.annotation.NonNull Parcel in) { 371 return new VerifiedMotionEvent(in); 372 } 373 }; 374 375 @DataClass.Generated( 376 time = 1604509199368L, 377 codegenVersion = "1.0.20", 378 sourceFile = "frameworks/base/core/java/android/view/VerifiedMotionEvent.java", 379 inputSignatures = "private static final java.lang.String TAG\nprivate float mRawX\nprivate float mRawY\nprivate @android.view.VerifiedMotionEvent.MotionEventAction int mActionMasked\nprivate @android.annotation.SuppressLint long mDownTimeNanos\nprivate int mFlags\nprivate int mMetaState\nprivate int mButtonState\npublic @android.annotation.Nullable java.lang.Boolean getFlag(int)\nclass VerifiedMotionEvent extends android.view.VerifiedInputEvent implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genHiddenConstructor=true, genEqualsHashCode=true)") 380 @Deprecated __metadata()381 private void __metadata() {} 382 383 384 //@formatter:on 385 // End of generated code 386 387 } 388