Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b42785ef authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

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
parent a46f5245
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -2724,12 +2724,12 @@ package android.view {
  public final class InputDevice implements android.os.Parcelable {
    method @RequiresPermission("android.permission.DISABLE_INPUT_DEVICE") public void disable();
    method @RequiresPermission("android.permission.DISABLE_INPUT_DEVICE") public void enable();
    field public static final int ACCESSIBILITY_DEVICE_ID = -2; // 0xfffffffe
  }

  public class KeyEvent extends android.view.InputEvent implements android.os.Parcelable {
    method public static String actionToString(int);
    method public final void setDisplayId(int);
    field public static final int FLAG_IS_ACCESSIBILITY_EVENT = 2048; // 0x800
    field public static final int LAST_KEYCODE = 288; // 0x120
  }

@@ -2747,6 +2747,7 @@ package android.view {
    method public void setActionButton(int);
    method public void setButtonState(int);
    method public void setDisplayId(int);
    field public static final int FLAG_IS_ACCESSIBILITY_EVENT = 2048; // 0x800
  }

  @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME) @java.lang.annotation.Target({java.lang.annotation.ElementType.METHOD}) public @interface RemotableViewMethod {
+0 −7
Original line number Diff line number Diff line
@@ -444,13 +444,6 @@ public final class InputDevice implements Parcelable {

    private static final int VIBRATOR_ID_ALL = -1;

    /**
     * The device id of input events generated inside accessibility service.
     * @hide
     */
    @TestApi
    public static final int ACCESSIBILITY_DEVICE_ID = -2;

    public static final @android.annotation.NonNull Parcelable.Creator<InputDevice> CREATOR =
            new Parcelable.Creator<InputDevice>() {
        public InputDevice createFromParcel(Parcel in) {
+9 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.view;

import static android.os.IInputConstants.INPUT_EVENT_FLAG_IS_ACCESSIBILITY_EVENT;
import static android.view.Display.INVALID_DISPLAY;

import android.annotation.NonNull;
@@ -1221,6 +1222,14 @@ public class KeyEvent extends InputEvent implements Parcelable {
     */
    public static final int FLAG_FALLBACK = 0x400;

    /**
     * This flag indicates that this event was modified by or generated from an accessibility
     * service. Value = 0x800
     * @hide
     */
    @TestApi
    public static final int FLAG_IS_ACCESSIBILITY_EVENT = INPUT_EVENT_FLAG_IS_ACCESSIBILITY_EVENT;

    /**
     * Signifies that the key is being predispatched.
     * @hide
+9 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.view;

import static android.os.IInputConstants.INPUT_EVENT_FLAG_IS_ACCESSIBILITY_EVENT;
import static android.view.Display.DEFAULT_DISPLAY;

import static java.lang.annotation.RetentionPolicy.SOURCE;
@@ -493,6 +494,14 @@ public final class MotionEvent extends InputEvent implements Parcelable {
     */
    public static final int FLAG_NO_FOCUS_CHANGE = 0x40;

    /**
     * This flag indicates that this event was modified by or generated from an accessibility
     * service. Value = 0x800
     * @hide
     */
    @TestApi
    public static final int FLAG_IS_ACCESSIBILITY_EVENT = INPUT_EVENT_FLAG_IS_ACCESSIBILITY_EVENT;

    /**
     * Private flag that indicates when the system has detected that this motion event
     * may be inconsistent with respect to the sequence of previously delivered motion events,
+25 −0
Original line number Diff line number Diff line
@@ -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;
    }
}
Loading