@@ -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