From 5d552c4b7fffb63d9bc4c26ca222d43bb57b359d Mon Sep 17 00:00:00 2001 From: Siarhei Vishniakou Date: Fri, 21 May 2021 05:02:22 +0000 Subject: Use the injected device id for events that are a11y trusted If an event is a trusted event coming from accessibility, then allow the device id that's provided in the InputEvent to be used during injection. That means, events injected from accessibility will not always have device id == -1 (VIRTUAL_DEVICE_ID). The only exception are the events coming from external accessibility services (MotionEventInjector). For simplicity, we mark all of those events as untrusted. The flow is as follows: 1. When a11y is enabled, mInputFilterEnabled is set in InputDispatcher 2. Every event processed by dispatcher is first sent to InputFilter (=== accessibility). 3. The event from dispatcher sent to a11y has new flag, POLICY_FLAG_ACCESSIBILITY_TRUSTED. 4. By default, a11y passes all the policy flags back to inputdispatcher when it tries to reinject the event. 5. If a11y hits a path where untrusted events may be injected, it removes the FLAG_A11Y_TRUSTED from the policyFlags and continues the event handling. 6. Eventually, if a11y does not handle the input event, it sends it back to InputDispatcher using 'injectInputEvent(..., policyFlags)'. 7. InputDispatcher will look at the policyFlags of the injected event. If the new flag is present, InputDispatcher will create EventEntry with the provided device id. Otherwise, it will create EventEntry with the virtual device id (-1). 8. The events received by the apps will now have the original device id if a11y is enabled. Test: atest CtsInputTestCases:android.input.cts.GamepadWithAccessibilityTest Test: atest VerifyInputEventTest Bug: 175069843 Change-Id: Ie6399654f4434fdc8232e50373b6277d2f43a864 --- include/input/InputDevice.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include/input/InputDevice.h') diff --git a/include/input/InputDevice.h b/include/input/InputDevice.h index 1fec08027f..acf1b8e00c 100644 --- a/include/input/InputDevice.h +++ b/include/input/InputDevice.h @@ -322,6 +322,8 @@ extern std::string getInputDeviceConfigurationFilePathByName( const std::string& name, InputDeviceConfigurationFileType type); enum ReservedInputDeviceId : int32_t { + // Device id assigned to input events generated inside accessibility service + ACCESSIBILITY_DEVICE_ID = -2, // Device id of a special "virtual" keyboard that is always present. VIRTUAL_KEYBOARD_ID = -1, // Device id of the "built-in" keyboard if there is one. -- cgit v1.2.3-59-g8ed1b