Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2ef69050 authored by Svetoslav Ganov's avatar Svetoslav Ganov
Browse files

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
parent 01827ce9
Loading
Loading
Loading
Loading
+32 −0
Original line number Diff line number Diff line
@@ -443,6 +443,7 @@ public class AccessibilityNodeInfo implements Parcelable {
     */
    public AccessibilityNodeInfo findFocus(int focus) {
        enforceSealed();
        enforceValidFocusType(focus);
        if (!canPerformRequestOverConnection(mSourceNodeId)) {
            return null;
        }
@@ -472,6 +473,7 @@ public class AccessibilityNodeInfo implements Parcelable {
     */
    public AccessibilityNodeInfo focusSearch(int direction) {
        enforceSealed();
        enforceValidFocusDirection(direction);
        if (!canPerformRequestOverConnection(mSourceNodeId)) {
            return null;
        }
@@ -1330,6 +1332,36 @@ public class AccessibilityNodeInfo implements Parcelable {
        }
    }

    private void enforceValidFocusDirection(int direction) {
        switch (direction) {
            case View.FOCUS_DOWN:
            case View.FOCUS_UP:
            case View.FOCUS_LEFT:
            case View.FOCUS_RIGHT:
            case View.FOCUS_FORWARD:
            case View.FOCUS_BACKWARD:
            case View.ACCESSIBILITY_FOCUS_DOWN:
            case View.ACCESSIBILITY_FOCUS_UP:
            case View.ACCESSIBILITY_FOCUS_LEFT:
            case View.ACCESSIBILITY_FOCUS_RIGHT:
            case View.ACCESSIBILITY_FOCUS_FORWARD:
            case View.ACCESSIBILITY_FOCUS_BACKWARD:
                return;
            default:
                throw new IllegalArgumentException("Unknown direction: " + direction);
        }
    }

    private void enforceValidFocusType(int focusType) {
        switch (focusType) {
            case FOCUS_INPUT:
            case FOCUS_ACCESSIBILITY:
                return;
            default:
                throw new IllegalArgumentException("Unknown focus type: " + focusType);
        }
    }

    /**
     * Enforces that this instance is not sealed.
     *