Search code examples
androidaccessibilityserviceandroid-12

Some packages not visible even after adding <queries> tag to AndroidManifest.xml (Android 12 device)


I have implemented some code in my app in order to get a list of accessibility services installed on my device using AccessibilityManager.getInstalledAccessibilityServiceList. Since devices running Android 11 and above are subjected to package visibility filtering, I added a <queries> tag in my manifest like this:

<queries>
        <intent>
            <action android:name="android.accessibilityservice.AccessibilityService" />
        </intent>
</queries>

Unfortunately there are one or two installed accessibility services that are still not showing up but I can see them from the Accessibility menu in my device settings screen (like the ones belonging to com.dashlane and Voice Access).

I have checked that these missing accessibility services do show up correctly if I declare the QUERY_ALL_PACKAGES permission in my app's manifest instead of using the <queries> tag to get visibility to installed apps, so this seems like a package visibility filtering issue. Does anyone know why the <queries> tag is somehow filtering out these missing packages and their accessibility services?


Solution

  • The reason why it was not working may be because the accessibility service of the apps that are not showing up is not exported (android:exported="false") in the manifest, which interfered with the output somehow.

    For example:

    <service android:enabled="@bool/is_accessibility_supported" android:exported="false" android:name="com.random.name.AccessibilityService" android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
        <intent-filter>
            <action android:name="android.accessibilityservice.AccessibilityService"/>
        </intent-filter>
        <meta-data android:name="android.accessibilityservice" android:resource="@xml/accessibility_service_meta"/>
    </service>
    

    The workaround is to use a combination of some other tags in the manifest like <action android:name="android.intent.action.MAIN" />, or as mentioned in the question, to declare the QUERY_ALL_PACKAGES permission.