From b42785efdf3ad0a73db9bd780581dd0ea70a9f54 Mon Sep 17 00:00:00 2001 From: Siarhei Vishniakou Date: Thu, 17 Jun 2021 23:27:48 +0000 Subject: Add FLAG_IS_ACCESSIBILITY_EVENT to KeyEvent and MotionEvent This flag indicates that the event was modified or generated by an accessibility service. It allows apps to tell apart real hardware events, events that are injected (device id == -1), and events coming from accessibility (has flag is_accessibility_event). Events that have gone into accessibility, and got reinjected without being modified will not be distinguishable from real hardware events. In the next release, we will make FLAG_IS_ACCESSIBILITY_EVENT public api. Until then, applications will have to hard-code its value (0x800) to use it. The value is the same for both KeyEvents and MotionEvents for convenience. Bug: 175069843 Bug: 152399927 Test: atest VerifiedMotionEventTest VerifiedKeyEventTest Test: atest AccessibilityGestureDispatchTest Test: atest inputflinger_tests libinput_tests GamepadWithAccessibilityTest Change-Id: I38ac2ab8e19e32cad927742c623f14f43ea0c588 --- core/java/android/view/VerifiedInputEvent.java | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'core/java/android/view/VerifiedInputEvent.java') diff --git a/core/java/android/view/VerifiedInputEvent.java b/core/java/android/view/VerifiedInputEvent.java index e2db50165f77..cc6fbe7f5171 100644 --- a/core/java/android/view/VerifiedInputEvent.java +++ b/core/java/android/view/VerifiedInputEvent.java @@ -20,6 +20,7 @@ import static java.lang.annotation.RetentionPolicy.SOURCE; import android.annotation.IntDef; import android.annotation.NonNull; +import android.annotation.Nullable; import android.annotation.SuppressLint; import android.os.Parcel; import android.os.Parcelable; @@ -157,4 +158,28 @@ public abstract class VerifiedInputEvent implements Parcelable { throw new IllegalArgumentException("Unexpected input event type in parcel."); } }; + + @Override + public boolean equals(@Nullable Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + @SuppressWarnings("unchecked") + VerifiedInputEvent that = (VerifiedInputEvent) o; + return mType == that.mType + && getDeviceId() == that.getDeviceId() + && getEventTimeNanos() == that.getEventTimeNanos() + && getSource() == that.getSource() + && getDisplayId() == that.getDisplayId(); + } + + @Override + public int hashCode() { + int _hash = 1; + _hash = 31 * _hash + mType; + _hash = 31 * _hash + getDeviceId(); + _hash = 31 * _hash + Long.hashCode(getEventTimeNanos()); + _hash = 31 * _hash + getSource(); + _hash = 31 * _hash + getDisplayId(); + return _hash; + } } -- cgit v1.2.3