Skip to content

Commit 8a1be91

Browse files
committed
Tracks whether an injected MotionEvent came from an accessibility tool.
This property can be checked by the View to allow sensitive views to ignore gestures injected by non-tool accessibility services. Sensitive views should continue responding to gestures injected by Accessibility Tools. Note: The files in this change do not reference the new flag, but this change is a no-op if the flag is not enabled. See other change in this topic. Bug: 284180538 Flag: android.view.accessibility.prevent_a11y_nontool_from_injecting_into_sensitive_views Test: atest InputDispatcher_test.cpp Test: See other change in topic for tests using this property Change-Id: I40ba79852045aaefe84f7ab87d5e08c42509f1e7
1 parent c09f9fa commit 8a1be91

6 files changed

Lines changed: 66 additions & 8 deletions

File tree

include/input/Input.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,23 @@ enum {
9292
static_cast<int32_t>(android::os::MotionEventFlag::NO_FOCUS_CHANGE),
9393

9494
/**
95-
* This event was generated or modified by accessibility service.
95+
* This event was injected from some AccessibilityService, which may be either an
96+
* Accessibility Tool OR a service using that API for purposes other than assisting users
97+
* with disabilities.
9698
*/
9799
AMOTION_EVENT_FLAG_IS_ACCESSIBILITY_EVENT =
98100
static_cast<int32_t>(android::os::MotionEventFlag::IS_ACCESSIBILITY_EVENT),
99101

102+
/**
103+
* This event was injected from an AccessibilityService with the
104+
* AccessibilityServiceInfo#isAccessibilityTool property set to true. These services (known as
105+
* "Accessibility Tools") are used to assist users with disabilities, so events from these
106+
* services should be able to reach all Views including Views which set
107+
* View#isAccessibilityDataSensitive to true.
108+
*/
109+
AMOTION_EVENT_FLAG_INJECTED_FROM_ACCESSIBILITY_TOOL =
110+
static_cast<int32_t>(android::os::MotionEventFlag::INJECTED_FROM_ACCESSIBILITY_TOOL),
111+
100112
AMOTION_EVENT_FLAG_TARGET_ACCESSIBILITY_FOCUS =
101113
static_cast<int32_t>(android::os::MotionEventFlag::TARGET_ACCESSIBILITY_FOCUS),
102114

@@ -347,6 +359,9 @@ enum {
347359
POLICY_FLAG_INJECTED_FROM_ACCESSIBILITY =
348360
android::os::IInputConstants::POLICY_FLAG_INJECTED_FROM_ACCESSIBILITY,
349361

362+
POLICY_FLAG_INJECTED_FROM_ACCESSIBILITY_TOOL =
363+
android::os::IInputConstants::POLICY_FLAG_INJECTED_FROM_ACCESSIBILITY_TOOL,
364+
350365
/* These flags are set by the input dispatcher. */
351366

352367
// Indicates that the input event was injected.

libs/input/android/os/IInputConstants.aidl

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ interface IInputConstants
4343
const int INVALID_INPUT_DEVICE_ID = -2;
4444

4545
/**
46-
* The input event was injected from accessibility. Used in policyFlags for input event
47-
* injection.
46+
* The input event was injected from some AccessibilityService, which may be either an
47+
* Accessibility Tool OR a service using that API for purposes other than assisting users with
48+
* disabilities. Used in policyFlags for input event injection.
4849
*/
4950
const int POLICY_FLAG_INJECTED_FROM_ACCESSIBILITY = 0x20000;
5051

@@ -54,18 +55,33 @@ interface IInputConstants
5455
*/
5556
const int POLICY_FLAG_KEY_GESTURE_TRIGGERED = 0x40000;
5657

58+
/**
59+
* The input event was injected from an AccessibilityService with the
60+
* AccessibilityServiceInfo#isAccessibilityTool property set to true. These services (known as
61+
* "Accessibility Tools") are used to assist users with disabilities, so events from these
62+
* services should be able to reach all Views including Views which set
63+
* View#isAccessibilityDataSensitive to true. Used in policyFlags for input event injection.
64+
*/
65+
const int POLICY_FLAG_INJECTED_FROM_ACCESSIBILITY_TOOL = 0x80000;
66+
5767
/**
5868
* Common input event flag used for both motion and key events for a gesture or pointer being
5969
* canceled.
6070
*/
6171
const int INPUT_EVENT_FLAG_CANCELED = 0x20;
6272

6373
/**
64-
* Common input event flag used for both motion and key events, indicating that the event
65-
* was generated or modified by accessibility service.
74+
* Input event flag used for both motion and key events.
75+
* See POLICY_FLAG_INJECTED_FROM_ACCESSIBILITY for more information.
6676
*/
6777
const int INPUT_EVENT_FLAG_IS_ACCESSIBILITY_EVENT = 0x800;
6878

79+
/**
80+
* Input event flag used for motion events.
81+
* See POLICY_FLAG_INJECTED_FROM_ACCESSIBILITY_TOOL for more information.
82+
*/
83+
const int INPUT_EVENT_FLAG_INJECTED_FROM_ACCESSIBILITY_TOOL = 0x1000;
84+
6985
/**
7086
* Common input event flag used for both motion and key events, indicating that the system has
7187
* detected this event may be inconsistent with the current event sequence or gesture, such as

libs/input/android/os/MotionEventFlag.aidl

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,23 @@ enum MotionEventFlag {
118118
PRIVATE_FLAG_SUPPORTS_DIRECTIONAL_ORIENTATION = 0x100,
119119

120120
/**
121-
* The input event was generated or modified by accessibility service.
122-
* Shared by both KeyEvent and MotionEvent flags, so this value should not overlap with either
123-
* set of flags, including in input/Input.h and in android/input.h.
121+
* The input event was injected from some AccessibilityService, which may be either an
122+
* Accessibility Tool OR a service using that API for purposes other than assisting users with
123+
* disabilities. Shared by both KeyEvent and MotionEvent flags, so this value should not
124+
* overlap with either set of flags, including in input/Input.h and in android/input.h.
124125
*/
125126
IS_ACCESSIBILITY_EVENT = IInputConstants.INPUT_EVENT_FLAG_IS_ACCESSIBILITY_EVENT,
126127

128+
/**
129+
* The input event was injected from an AccessibilityService with the
130+
* AccessibilityServiceInfo#isAccessibilityTool property set to true. These services (known as
131+
* "Accessibility Tools") are used to assist users with disabilities, so events from these
132+
* services should be able to reach all Views including Views which set
133+
* View#isAccessibilityDataSensitive to true. Only used by MotionEvent flags.
134+
*/
135+
INJECTED_FROM_ACCESSIBILITY_TOOL =
136+
IInputConstants.INPUT_EVENT_FLAG_INJECTED_FROM_ACCESSIBILITY_TOOL,
137+
127138
/**
128139
* Private flag that indicates when the system has detected that this motion event
129140
* may be inconsistent with respect to the sequence of previously delivered motion events,

libs/input/rust/input.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,9 @@ bitflags! {
219219
MotionEventFlag::PRIVATE_FLAG_SUPPORTS_DIRECTIONAL_ORIENTATION.0 as u32;
220220
/// FLAG_IS_ACCESSIBILITY_EVENT
221221
const IS_ACCESSIBILITY_EVENT = MotionEventFlag::IS_ACCESSIBILITY_EVENT.0 as u32;
222+
/// FLAG_INJECTED_FROM_ACCESSIBILITY_TOOL
223+
const INJECTED_FROM_ACCESSIBILITY_TOOL =
224+
MotionEventFlag::INJECTED_FROM_ACCESSIBILITY_TOOL.0 as u32;
222225
/// FLAG_TAINTED
223226
const TAINTED = MotionEventFlag::TAINTED.0 as u32;
224227
/// FLAG_TARGET_ACCESSIBILITY_FOCUS

services/inputflinger/dispatcher/InputDispatcher.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4870,6 +4870,10 @@ InputEventInjectionResult InputDispatcher::injectInputEvent(const InputEvent* ev
48704870
flags |= AMOTION_EVENT_FLAG_IS_ACCESSIBILITY_EVENT;
48714871
}
48724872

4873+
if (policyFlags & POLICY_FLAG_INJECTED_FROM_ACCESSIBILITY_TOOL) {
4874+
flags |= AMOTION_EVENT_FLAG_INJECTED_FROM_ACCESSIBILITY_TOOL;
4875+
}
4876+
48734877
mLock.lock();
48744878

48754879
if (shouldRejectInjectedMotionLocked(motionEvent, resolvedDeviceId, displayId,

services/inputflinger/tests/InputDispatcher_test.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9890,6 +9890,15 @@ TEST_F(InputFilterInjectionPolicyTest,
98909890
AMOTION_EVENT_FLAG_IS_ACCESSIBILITY_EVENT);
98919891
}
98929892

9893+
TEST_F(InputFilterInjectionPolicyTest,
9894+
MotionEventsInjectedFromAccessibilityTool_HaveAccessibilityFlags) {
9895+
testInjectedMotion(POLICY_FLAG_FILTERED | POLICY_FLAG_INJECTED_FROM_ACCESSIBILITY |
9896+
POLICY_FLAG_INJECTED_FROM_ACCESSIBILITY_TOOL,
9897+
/*injectedDeviceId=*/3, /*resolvedDeviceId=*/3,
9898+
AMOTION_EVENT_FLAG_IS_ACCESSIBILITY_EVENT |
9899+
AMOTION_EVENT_FLAG_INJECTED_FROM_ACCESSIBILITY_TOOL);
9900+
}
9901+
98939902
TEST_F(InputFilterInjectionPolicyTest, RegularInjectedEvents_ReceiveVirtualDeviceId) {
98949903
testInjectedKey(/*policyFlags=*/0, /*injectedDeviceId=*/3,
98959904
/*resolvedDeviceId=*/VIRTUAL_KEYBOARD_ID, /*flags=*/0);

0 commit comments

Comments
 (0)