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