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
5 files changed