Flyview
Flyview

Reputation: 1959

Accessibility Service info not reported for apps where filterTouchesWhenObscured flag is true on Android 14

My app depends on accessibility events (for example, AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED or AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED) and the information in the AccessibiltyNodeInfo objects on screen in order to detect other apps in use.

Starting with Android 14, the system is no longer reporting any accessibility events for apps that have set the "filterTouchesWhenObscured" to true. The AccessibilityNodeInfos retrieved through getWindows() and accessibilityWindowInfo.getRoot() are also null!

Thankfully, this is only really an issue when the flag is set to the whole window of the activity, but some apps do this:

getWindow().getDecorView().setFilterTouchesWhenObscured(true);

I have no idea why this flag, which is supposed to prevent tapjacking when views are obscured, is affecting accessibility events.

Would someone please provide the connection so we can find a possible workaround or fix?

Upvotes: 0

Views: 94

Answers (1)

Flyview
Flyview

Reputation: 1959

I found this method in the View class of Android source code:

void calculateAccessibilityDataSensitive() {
    // Use the explicit value if set.
    if (mExplicitAccessibilityDataSensitive != ACCESSIBILITY_DATA_SENSITIVE_AUTO) {
        mInferredAccessibilityDataSensitive = mExplicitAccessibilityDataSensitive;
    } else if (getFilterTouchesWhenObscured()) {
        // Views that set filterTouchesWhenObscured default to accessibilityDataSensitive.
        mInferredAccessibilityDataSensitive = ACCESSIBILITY_DATA_SENSITIVE_YES;
    } else if (mParent instanceof View && ((View) mParent).isAccessibilityDataSensitive()) {
        // Descendants of accessibilityDataSensitive Views are also accessibilityDataSensitive.
        mInferredAccessibilityDataSensitive = ACCESSIBILITY_DATA_SENSITIVE_YES;
    } else {
        // Otherwise, default to not accessibilityDataSensitive.
        mInferredAccessibilityDataSensitive = ACCESSIBILITY_DATA_SENSITIVE_NO;
    }
}

Views that have set filterTouchesWhenObscured default to being considered accessibilityDataSensitive, which was added in Android 14. I'm not sure why they would default to setting accessibilityDataSensitive for views which have set filterTouchesWhenObscured, when they did not request it explicitly! Super annoying.

Upvotes: 0

Related Questions