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
This commit is contained in:
@@ -30,6 +30,7 @@ import android.util.Slog;
|
||||
import android.util.SparseArray;
|
||||
import android.util.SparseIntArray;
|
||||
import android.view.InputDevice;
|
||||
import android.view.KeyCharacterMap;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.WindowManagerPolicyConstants;
|
||||
|
||||
@@ -55,7 +56,6 @@ public class MotionEventInjector extends BaseEventStreamTransformation implement
|
||||
*/
|
||||
private static final int EVENT_META_STATE = 0;
|
||||
private static final int EVENT_BUTTON_STATE = 0;
|
||||
private static final int EVENT_DEVICE_ID = 0;
|
||||
private static final int EVENT_EDGE_FLAGS = 0;
|
||||
private static final int EVENT_SOURCE = InputDevice.SOURCE_TOUCHSCREEN;
|
||||
private static final int EVENT_FLAGS = 0;
|
||||
@@ -122,9 +122,6 @@ public class MotionEventInjector extends BaseEventStreamTransformation implement
|
||||
return;
|
||||
}
|
||||
cancelAnyPendingInjectedEvents();
|
||||
// The events injected from outside of system_server are not trusted. Remove the flag to
|
||||
// prevent accessibility service from impersonating a real input device.
|
||||
policyFlags &= ~WindowManagerPolicyConstants.FLAG_INPUTFILTER_TRUSTED;
|
||||
// Indicate that the input event is injected from accessibility, to let applications
|
||||
// distinguish it from events injected by other means.
|
||||
policyFlags |= WindowManagerPolicyConstants.FLAG_INJECTED_FROM_ACCESSIBILITY;
|
||||
@@ -483,8 +480,8 @@ public class MotionEventInjector extends BaseEventStreamTransformation implement
|
||||
}
|
||||
return MotionEvent.obtain(downTime, eventTime, action, touchPointsSize,
|
||||
sPointerProps, sPointerCoords, EVENT_META_STATE, EVENT_BUTTON_STATE,
|
||||
EVENT_X_PRECISION, EVENT_Y_PRECISION, EVENT_DEVICE_ID, EVENT_EDGE_FLAGS,
|
||||
EVENT_SOURCE, EVENT_FLAGS);
|
||||
EVENT_X_PRECISION, EVENT_Y_PRECISION, KeyCharacterMap.VIRTUAL_KEYBOARD,
|
||||
EVENT_EDGE_FLAGS, EVENT_SOURCE, EVENT_FLAGS);
|
||||
}
|
||||
|
||||
private static int findPointByStrokeId(TouchPoint[] touchPoints, int touchPointsSize,
|
||||
|
||||
Reference in New Issue
Block a user