Skip to content

Commit f491aa5

Browse files
Daniel-NormanAndroid (Google) Code Review
authored andcommitted
Merge "Tracks whether an injected MotionEvent came from an accessibility tool." into main
2 parents 32cf36e + 8a1be91 commit f491aa5

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
@@ -4856,6 +4856,10 @@ InputEventInjectionResult InputDispatcher::injectInputEvent(const InputEvent* ev
48564856
flags |= AMOTION_EVENT_FLAG_IS_ACCESSIBILITY_EVENT;
48574857
}
48584858

4859+
if (policyFlags & POLICY_FLAG_INJECTED_FROM_ACCESSIBILITY_TOOL) {
4860+
flags |= AMOTION_EVENT_FLAG_INJECTED_FROM_ACCESSIBILITY_TOOL;
4861+
}
4862+
48594863
mLock.lock();
48604864

48614865
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
@@ -9905,6 +9905,15 @@ TEST_F(InputFilterInjectionPolicyTest,
99059905
AMOTION_EVENT_FLAG_IS_ACCESSIBILITY_EVENT);
99069906
}
99079907

9908+
TEST_F(InputFilterInjectionPolicyTest,
9909+
MotionEventsInjectedFromAccessibilityTool_HaveAccessibilityFlags) {
9910+
testInjectedMotion(POLICY_FLAG_FILTERED | POLICY_FLAG_INJECTED_FROM_ACCESSIBILITY |
9911+
POLICY_FLAG_INJECTED_FROM_ACCESSIBILITY_TOOL,
9912+
/*injectedDeviceId=*/3, /*resolvedDeviceId=*/3,
9913+
AMOTION_EVENT_FLAG_IS_ACCESSIBILITY_EVENT |
9914+
AMOTION_EVENT_FLAG_INJECTED_FROM_ACCESSIBILITY_TOOL);
9915+
}
9916+
99089917
TEST_F(InputFilterInjectionPolicyTest, RegularInjectedEvents_ReceiveVirtualDeviceId) {
99099918
testInjectedKey(/*policyFlags=*/0, /*injectedDeviceId=*/3,
99109919
/*resolvedDeviceId=*/VIRTUAL_KEYBOARD_ID, /*flags=*/0);

0 commit comments

Comments
 (0)