Search code examples
androidaccessibilityserviceandroid-audiorecordaccessibility

AccessibilityService turned on causes silence from microphone on Android 10


I'm diving into new project which is using a microphone input to transmit voice. Audio is recorded by Service, capturing may be started from UI (e.g. Activity), but also from server side (some kind of eavesdropping) or by broadcast from another app. Feature works well across all versions of Android.

Now I've got task to handle some keys (KeyEvent), even when app is in background, but above mentioned foreground service is running. So I've made AccessibilityService with overriden onKeyEvent(KeyEvent event), checking inside is service running and handling proper keys if needed. This feature works fine also.

BUT I've just noticed strange behavior on Android 10 - silence from mic when AccessibilityService is turned on... When I'm turing it off mic starts working. On Android 9 and below audio capture works always no matter of on/off state.

I've found guide in docs with some info about changed behavior of handling audio input and dispatching it, but I don't see any related section to my situation. Audio capture feature and accessibility service belong to one app and this service is needed only for keys handling. So the question is why my service breaks down mic on Android 10 and how I can prevent this?

As a bonus - XML with configuration

<?xml version="1.0" encoding="utf-8"?>
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
    android:accessibilityEventTypes=""
    android:accessibilityFeedbackType="feedbackSpoken|feedbackHaptic"
    android:accessibilityFlags="flagRequestFilterKeyEvents"
    android:canRequestFilterKeyEvents="true"
    android:canRetrieveWindowContent="false"
    android:description="@string/accessibility_permission_desc"
    android:notificationTimeout="25"
    android:packageNames="my.package.name"
    android:settingsActivity="" />

Solution

  • after some tests on different devices (indicated by @Bernardo Ruz comment) turned out that described problem is happening (probably) only on Google Pixels with Android 10. looks like some bug on system level.

    today Google released Android 11 and all Pixels are getting updates. I've checked Pixel 3 and same app without reinstall or any update and it started working, so looks like it has been fixed

    edit: as we have very fragmented market, there is a chance that some manufacturers shipped first release/commit of Android 10 (e.g. promissed to customers) and just forgot about model, never shipped further patches (e.g. security). every device must stop on some Android OS release, looks like some units will be problematic forever (as long as 10 will be present on market)