Skip to content

Commit 2ef6905

Browse files
committed
Client app crashes if accessibility service uses invalid focus type.
1. If an accessibility service uses an invalid focus type argument when trying to find where focus is the queried application crashes. The same happens if the serivce calls focus search with an invalid derection. While we need the argument check in the controller that runs in the app process the accessibility service has to be the palace where an exception is thown for the invalid argument so the developer can fix his code.: bug:6508797 Change-Id: Ib0d74f374fa60ee8fd6117f11c23af34f6c26ad3
1 parent 01827ce commit 2ef6905

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

core/java/android/view/accessibility/AccessibilityNodeInfo.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ public void setSource(View root, int virtualDescendantId) {
443443
*/
444444
public AccessibilityNodeInfo findFocus(int focus) {
445445
enforceSealed();
446+
enforceValidFocusType(focus);
446447
if (!canPerformRequestOverConnection(mSourceNodeId)) {
447448
return null;
448449
}
@@ -472,6 +473,7 @@ public AccessibilityNodeInfo findFocus(int focus) {
472473
*/
473474
public AccessibilityNodeInfo focusSearch(int direction) {
474475
enforceSealed();
476+
enforceValidFocusDirection(direction);
475477
if (!canPerformRequestOverConnection(mSourceNodeId)) {
476478
return null;
477479
}
@@ -1330,6 +1332,36 @@ protected void enforceSealed() {
13301332
}
13311333
}
13321334

1335+
private void enforceValidFocusDirection(int direction) {
1336+
switch (direction) {
1337+
case View.FOCUS_DOWN:
1338+
case View.FOCUS_UP:
1339+
case View.FOCUS_LEFT:
1340+
case View.FOCUS_RIGHT:
1341+
case View.FOCUS_FORWARD:
1342+
case View.FOCUS_BACKWARD:
1343+
case View.ACCESSIBILITY_FOCUS_DOWN:
1344+
case View.ACCESSIBILITY_FOCUS_UP:
1345+
case View.ACCESSIBILITY_FOCUS_LEFT:
1346+
case View.ACCESSIBILITY_FOCUS_RIGHT:
1347+
case View.ACCESSIBILITY_FOCUS_FORWARD:
1348+
case View.ACCESSIBILITY_FOCUS_BACKWARD:
1349+
return;
1350+
default:
1351+
throw new IllegalArgumentException("Unknown direction: " + direction);
1352+
}
1353+
}
1354+
1355+
private void enforceValidFocusType(int focusType) {
1356+
switch (focusType) {
1357+
case FOCUS_INPUT:
1358+
case FOCUS_ACCESSIBILITY:
1359+
return;
1360+
default:
1361+
throw new IllegalArgumentException("Unknown focus type: " + focusType);
1362+
}
1363+
}
1364+
13331365
/**
13341366
* Enforces that this instance is not sealed.
13351367
*

0 commit comments

Comments
 (0)