问题
I want to build an accessibility service that can capture audio even when other applications are using the microphone (video camera, phone, voice recorder, Shazam, etc). Android 10 introduced audio sharing, but it's not clear whether third-party accessibility services can capture audio from other apps.
https://developer.android.com/guide/topics/media/sharing-audio-input
For the purpose of capturing audio, Android distinguishes two kinds of apps:
- "Ordinary" apps are installed by the user.
- "Privileged" apps come pre-installed on the device. These include the Google Assistant, and all accessibility services.
A third-party accessibility service is installed by the user, therefore it's an ordinary app.
The prioritization rules for using and sharing audio input are as follows:
- Privileged apps have higher priority than ordinary apps.
- Apps with visible foreground UIs have higher priority than background apps.
- Apps capturing audio from a privacy-sensitive source have higher priority than apps that are not.
- Two ordinary apps can never capture audio at the same time. In some situations, a privileged app can share audio input with another app. If two background apps of same priority are capturing audio, the last one started has higher priority.
A third-party accessibility service is an ordinary app, therefore it can't capture audio at the same time as another app.
Accessibility service + ordinary app
Android shares the input audio according to these rules:
If the service's UI is on top, both the service and the app receive audio input. This behavior offers functionality like controlling a voice call or video capture with voice commands.
If the service is not on top, this case is treated like the ordinary two-app case below.
This section introduces a distinction between an accessibility service, an ordinary app, and a privileged apps. Does that mean that a third-party accessibility service with its UI on top can receive audio from ordinary apps?
来源:https://stackoverflow.com/questions/59761791/can-a-third-party-accessibility-service-capture-audio-on-android-10