How to enable USB "Audio Source" option on Android 9+?


Question

A lot of screenshots in the Internet mention a 'audio source' USB configuration for Android. For example, this one from Google:





However, I cannot see this option with my SM-A510F with Android 9 (LineageOS 16).



Is there something I can do to enable it? Is it definitively gone from Android?


Answer

Android devices can work in USB host or device mode. Host is the one which controls USB communication. PCs mostly operate in host mode. Device is the one which is being powered and controlled by the host. Flash drive is a common example of USB device. Linux/Android kernel supports device mode through different gadget drivers. UMS, MTP, ADB are different gadget modes on Android devices.


Audio over USB in Device Mode


On Android devices, technically it's possible to stream Audio over USB both in host and device mode. Since Android 4.1 the latter mode is “provided by Android Open Accessory (AOA) 2.0 and provides limited audio capability”. It uses the USB Audio Gadget Driver in kernel (built with CONFIG_USB_AUDIO option) and the accessories supporting AOAv2 protocol are built using Accessory Development Kit (ADK). Custom Accessories page states:



AOA protocol specifies how an accessory can establish communication with an Android device via USB. Due to the low power output of Android devices, AOA requires the accessory to act as a USB host, meaning the connecting accessory must power the bus.



But as per official documentation:



Accessory mode audio has not been widely adopted, and is not currently recommended for new designs.



And the AOA protocol documentation warns:



Caution: AOAv2 audio support has been deprecated in Android 8.0.



It means Android 9+ devices won't be able to function in device mode while streaming audio over USB. So the Audio Source USB configuration option is no more there.


Audio over USB in Host Mode


However Android devices support audio peripherals in host mode (kernel must be built with CONFIG_SND_USB_AUDIO). Since AOA is specific to Android, such accessories aren't usable with other hosts like PCs. So there was a demand from audio peripheral manufacturers, device OEMs and ROM developers community to support standard USB audio out capability in host mode (e.g. see this, this and this). Support for a subset of USB audio class 1 (UAC1) features was added in Android 5.0.


USB Device classes specify the standard protocols for USB peripheral functions so that the host can inter-operate with them without requiring any hardware-specifc driver (i.e. in driverless mode). USB Mass Storage (UMS) is a common example. All Mass Storage Class (MSC) compliant thumb drives work on all OSes including Linux, Android and Windows, irrespective of the device vendor. In the same way the USB audio peripherals which are USB Audio Class 1 compliant work with Android devices like on any other USB hosts e.g. PCs.


So host mode USB audio covers wide range of USB-based peripherals including the headsets that follow the USB headset specification.


When a UAC1 compatible peripheral device (like a DAC) is connected to USB port on Android device, digital audio is automatically routed to that peripheral. However if an app wants to use advanced USB host APIs to interact with the peripheral (and not simply the audio routing) , it's possible to Disable USB audio routing in Developer Options.


Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes