Search code examples
androidandroid-serviceaccessibility

Why does my accessibility service ask for full screen control?


I have the following accessibility configuration file where window retrieval is disabled and I only want to filter the key events:

<?xml version="1.0" encoding="utf-8"?>
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
    android:accessibilityFlags="flagRequestFilterKeyEvents"
    android:canRequestFilterKeyEvents="true"
    android:canRequestTouchExplorationMode="false"
    android:canRetrieveWindowContent="false"
    android:description="@string/permissions_accessibility_description"
    android:settingsActivity="" />

However, Android keeps saying I want to read the content on the screen and display content over other apps:

enter image description here

Is there any way I can get rid of the "View and control screen" warning I'm not interested in at all?


Solution

  • I was curious about this as well, because I am writing an accessibility service that does not "view" or "control" the screen in any way, requests no such permissions in the AndroidManifest.xml file, and was therefore surprised by this seeing this dialog for my service.

    It turns out that this dialog is shown for your AccessibilityService because the dialog is essentially hard-coded to appear when enabling any accessibility service.

    It would be reasonable if the Android documentation mentioned this in any way, or explained to developers why the dialog appears, but the Android documentation does not.

    If we explore the source code of this screen, there are 3 cases for issuing the (same) warning for enabling the service, 1 case for issuing a warning when disabling the service, and a default case (which is likely there as a "good practice" for Java code, and that I doubt is ever actually executed as code).

    It is not a "real" solution, but as a compromise, we can always mention the description XML attribute of the accessibility-service XML tag that Android is flat-out lying about our apps needing any (or all) of these functionalities, link to our source code, etc.