If you're trying out anything and learn something that would have helped, please extend this wiki page.
This provides a brief overview of how Android audio HALs configure the ALSA mixer.
Android devices can have an assortment mixer configurations such as headphones, speakers, or microphones. For a particular device the audio route configurations are defined in mixer_paths.xml. For an example see the mixer path XML for Nexus 5 (hammerhead).
Android audio HALs make use of tinyalsa and audio_route. Tinyalsa is a small standalone library to interface with ALSA in the Linux kernel. Audio HALs call the audio_route library which loads audio routes from an XML and controls the mixer through tinyalsa.
ALSA controls are defined by ctl elements.
Audio routes are defined by path elements. A path element contains a collection of ctl elements as well as other path elements.
The path name attribute is used to select an audio route.
Android kernels use switch_class kernel driver to notify the Android frameworks of headphone jack events. The driver source code can be located at: drivers/switch/switch_class.c or drivers/staging/android/switch/switch_class.c. Note that the switch class driver is an Android specific driver. It has not been upstreamed to the mainline kernel.
In userspace the WiredAccessoryManager monitors the /sys/class/switch/h2w for uevents when the headphone is (un)plugged.
This section is incomplete. It requires a reference to more complete documentation of the device config XML format.
The audio routes in Linux userspace can be defined in ALSA UCM configuration files. There is a tool called xml2ucm which will convert the Android mixer_paths.xml and a device config XML to UCM files. The xml2ucm tool introduces the device config XML which provides necessary routing information that was hardcoded in the audio HAL on Android.
The mixer_path.xml is commonly found in the Android device repository. (e.g. android_device_lge_hammerhead). You must write the device config XML for your device.
A device config XML describes a sound card with use cases and sets of audio routes. In the examples available at the moment there is only one use case named HiFi. Under each <use-case> there are multiple <device> elements. In this context a <device> means audio route(s) which comprise a logical audio device (e.g. Headphone, Headset, Speaker).
Android audio HALs can and do select multiple audio routes at once. For example a headset can have a headphone output route and a microphone input route. To handle this a <device> element (the headset) can contain multiple <path> elements (audio routes). Example device config XML files are provided in the xml2ucm repository.
The ctl-device must be the name of the sound card which can be obtained using aplay. In the following example from the Samsung p4wifi the ctl-device is the sound card named wm8994aif1.
This method may work for non-Android devices as well, as long as you see an audio device in alsamixer. Just boot the normal OS, save the volume settings somehow, then restore them.
For other devices the configuration might need to be adapted. On the Samsung Galaxy Note 8.0 for example, the audio device is named "Kona_WM1811". Replacing all occurrences in file names and file contents of Midas by Kona worked.
This page was last edited on 28 February 2019, at 04:06.