Getting Bluetooth audio out of a Rabbit R1 on Android 13
On a Rabbit R1 running an Android 13 GSI, headphones pair but no music comes out. The cause is one MediaTek library listening on the wrong channel, and the fix is one file from a Pixel factory image.
Contents
I use a Rabbit R1 as a small voice-first device, running plain Android 13 instead of rabbitOS. Almost everything works: the screen, the wheel, the camera that flips, the SIM. Bluetooth works too, in the sense that headphones pair and connect. Then you press play and the music does not come out of them.
This post is how I found the cause and fixed it with a single file, without building an image or going near the bootloader. The scripts are in github.com/IgnacioLD/r1-bluetooth-audio.
The setup this applies to
- A Rabbit R1 (MediaTek MT6765) with the bootloader unlocked and an Android 13 GSI installed, the kind you get from the r1_escape project.
- Root over adb (
su). - The original vendor partition, which is Android 12, build
SP1A.210812.016.
Check the last one, because the whole fix depends on it:
adb shell getprop ro.vendor.build.fingerprint
# Rabbit/vnd_k65v1_64_bsp/k65v1_64_bsp:12/SP1A.210812.016/...:user/release-keys
If your R1 still runs rabbitOS, I would not expect this problem: there the system and the vendor partition come from the same place and agree with each other.
How Bluetooth audio is wired in Android
Three pieces are involved, and the bug lives in the gap between two of them.
- The Bluetooth stack. It is part of the system image. It handles pairing, the A2DP profile and the codec.
- The Bluetooth audio HAL. A HIDL interface,
android.hardware.bluetooth.audio, through which the stack says “I have a session open for these headphones, with this format”. It is served by the vendor’s audio process. - The Bluetooth audio module,
audio.bluetooth.default.so. This is what Android’s audio framework opens as an output device, like the speaker. When an app plays music, the PCM goes into this module, and the module hands it to the session that the stack opened in step 2.
Steps 2 and 3 live in the same process and meet in a small library that keeps the list of open sessions. The stack registers a session there; the module looks it up there.
On a GSI, piece 1 comes from the generic system image and pieces 2 and 3 come from the device’s vendor partition. That is the idea of Treble: the HIDL interface in the middle is the contract, and either side can be replaced.
What MediaTek did
Ask the R1 which Bluetooth audio interfaces it serves:
adb shell su 0 lshal | grep -i bluetooth.audio
[email protected]::IBluetoothAudioProvidersFactory/default
[email protected]::IBluetoothAudioProvidersFactory/default
[email protected]::IBluetoothAudioProvidersFactory/default
[email protected]::IBluetoothAudioProvidersFactory/default
There are two families. The first two lines are the standard AOSP interface. The last two are MediaTek’s own copy of it, with extensions. MediaTek’s Bluetooth stack, the one rabbitOS ships, talks to the vendor.mediatek one.
Each family has its own session library in /vendor/lib64:
libbluetooth_audio_session.so <- sessions opened through the AOSP interface
libbluetooth_audio_session_mediatek.so <- sessions opened through MediaTek's
So far this is fine. The vendor partition serves both interfaces, so both kinds of stack can open a session. The question is which of the two lists the audio module reads. Pull the module and look at what it links against:
adb exec-out su 0 cat /vendor/lib64/hw/audio.bluetooth.default.so > mtk.so
llvm-readelf -d mtk.so | grep NEEDED
[email protected]
[email protected]
libbluetooth_audio_session_mediatek.so
libaudioutils.so
...
Only MediaTek’s. There is no reference to libbluetooth_audio_session.so at all.
That is the whole bug. The GSI’s Bluetooth stack is AOSP’s, so it opens its session through [email protected], and the session lands in the AOSP list. The audio module looks for it in MediaTek’s list, never finds one, and has nowhere to send the music. Both halves work. They are waiting for each other in different rooms.
The fix: AOSP’s module
The module is not MediaTek’s invention. It is part of AOSP, and MediaTek’s is a fork of it. The unmodified one links against exactly what we need:
[email protected]
[email protected]
libbluetooth_audio_session.so
libaudioutils.so
...
Every one of those is already in the R1’s vendor partition, because MediaTek left the AOSP interface in place. So nothing else has to change: replace that one module with the stock one and it will read the list that the GSI’s stack writes to.
It has to be built for the same vendor API as the rest of the partition (VNDK 31, Android 12), or it will not load. The easy source for that is a Pixel: Google publishes factory images, and the Pixel 3 has one for SP1A.210812.016.A1, the same build the R1’s vendor was made from. Its vendor.img contains the stock audio.bluetooth.default.so.
I did not put the binary in the repo. fetch.sh downloads Google’s image, checks its SHA-256, takes that one file out of vendor.img and checks the file’s SHA-256 too:
git clone https://github.com/IgnacioLD/r1-bluetooth-audio
cd r1-bluetooth-audio
less fetch.sh apply.sh on-device.sh # read what you are about to run as root
./fetch.sh
It needs curl, unzip, python3 and debugfs (from e2fsprogs), and it downloads about 2 GB to keep 130 KB. The interesting part is short:
unzip -qo f.zip '*/image-*.zip'
unzip -qo */image-*.zip vendor.img
python3 unsparse.py vendor.img vendor.raw # Android sparse image -> plain ext4
debugfs -R "dump /lib64/hw/audio.bluetooth.default.so out.so" vendor.raw
debugfs reads a file out of an ext4 image without mounting it, which means no root and no loop devices on your computer, and it works the same on Linux and macOS.
Putting it on the R1 without flashing
The vendor partition is read-only and has almost no free space, and I did not want my first test to be a write to it. A bind mount is enough to try the idea: put the new file on top of the old one, in memory, and restart the audio service. If it goes wrong, a reboot undoes everything.
./apply.sh
It pushes the library, checks the checksum again on the device and then runs this as root:
TARGET=/vendor/lib64/hw/audio.bluetooth.default.so
NS="nsenter -t 1 -m --"
$NS mkdir -p /dev/r1-bt-audio
$NS mount -t tmpfs -o mode=0755 tmpfs /dev/r1-bt-audio
cp /data/local/tmp/audio.bluetooth.default.so /dev/r1-bt-audio/
chmod 644 /dev/r1-bt-audio/audio.bluetooth.default.so
chcon u:object_r:vendor_file:s0 /dev/r1-bt-audio/audio.bluetooth.default.so
$NS mount --bind /dev/r1-bt-audio/audio.bluetooth.default.so $TARGET
setprop ctl.restart vendor.audio-hal
Three details in there are easy to get wrong, so here is why each one exists.
nsenter -t 1 -m. A root shell obtained through su can have its own mount namespace. A bind mount made there is visible to your shell and to nothing else, so the audio service would keep loading the old file while sha256sum tells you the new one is in place. Entering the mount namespace of process 1 (init) makes the mount where services will see it, whatever your shell’s namespace is.
The tmpfs and chcon. The audio service runs confined by SELinux and may only load libraries labelled as vendor files. A file in /data/local/tmp carries the shell’s label, which a vendor service is not meant to load code from. A small tmpfs of our own lets us give the copy the vendor_file label, the same one the file it replaces has (ls -Z shows it).
Restarting only the audio service. vendor.audio-hal is the init service that hosts both the audio HAL and the Bluetooth audio HAL. Restarting it is enough for the module to be loaded again; Android’s audio server reconnects by itself. No reboot, which matters, because a reboot removes the mount.
The script stops before doing anything if the device is not an MT6765 or the vendor build is a different one, and it undoes the mount if the audio service does not come back.
Checking that it took
The path the audio service loads should now hold the stock library. Ask from init’s namespace, not from your shell’s:
adb shell su 0 nsenter -t 1 -m -- sha256sum /vendor/lib64/hw/audio.bluetooth.default.so
# 3576b51ff4d8099d161f5cdb0893ec19f476715de1cb537553ef553b66fad148
Then reconnect the headphones and play something. When music is going out over Bluetooth, the audio flinger says so:
adb shell dumpsys media.audio_flinger | grep A2DP
# Output devices: 0x80 (AUDIO_DEVICE_OUT_BLUETOOTH_A2DP)
On mine, music plays through the headphones and the media volume slider controls them. Absolute volume works as well: moving the slider one step sends the new level to the headphones over AVRCP, which you can watch in logcat as AvrcpVolumeManager: sendVolumeChanged.
Making it permanent
The bind mount is gone after a reboot. Once it has proved the idea, the same file can go into the vendor partition itself. The usual way to do that on a device with dynamic partitions is to rebuild super and flash it, which is a lot of machinery and risk for one 130 KB file. There is a smaller way, and it is what permanent.sh does:
./permanent.sh
adb reboot
- Copy the partition to the computer,
adb exec-out "su 0 cat /dev/block/mapper/vendor_a", and check the copy’s SHA-256 against the device’s. - Change the file in the copy with
debugfs -w: remove the old one, write the new one, and give it back the same owner, mode, dates and SELinux label (ea_set ... security.selinux). Thene2fsck -fnhas to pass. The R1’s vendor image is plain ext4, which is what makes this possible. Its system image is not: it has theshared_blocksfeature, where several files share the same blocks, and removing a file there can free blocks that another file still uses. The script refuses an image like that. - Compare the two images block by block. On mine 36 blocks of 4 KB differ: 32 with the library and 4 of filesystem bookkeeping. Both versions of those blocks are kept in
./backup. - Write only those blocks, from Android, with
dd ... seek=N conv=notruncon the mapper device afterblockdev --setrw. Then read the whole partition back and compare its SHA-256 with the image from step 2. If it differs, the old blocks go back.
Writing underneath a mounted filesystem sounds reckless, and normally it is. It is tolerable here for two reasons: the partition is mounted read-only, so the kernel never writes its own idea of it back, and you reboot straight away, so nothing keeps running on a stale view. Verity is off on this setup, or the changed blocks would be rejected.
./permanent.sh undo writes the original 36 blocks back with the same checks. I ran both directions on my R1, with a reboot after each. What I have not had to try is the bad case: if the device did not boot, the way back would be MediaTek’s download mode and a full backup of the partition, so have one before you start.
What this does not do
- It only replaces the 64-bit module. There is a 32-bit copy in
/vendor/lib/hwthat I left alone, because the audio service on the R1 is a 64-bit process and never loads it. - It is for this vendor build. With a different vendor partition, check
NEEDEDon both libraries before you trust it: the stock module only works here because MediaTek kept the AOSP interface and its session library in the partition. - It gives up MediaTek’s extensions. Whatever
[email protected]adds over AOSP is not used. That only matters if you go back to MediaTek’s Bluetooth stack, and then you would not want this fix anyway. - I only tested music (A2DP). Calls over Bluetooth use a different path (SCO), which this does not touch.
The general lesson
When a GSI pairs with something but the data does not flow, suspect a vendor that forked a HAL instead of extending it. The recipe is the same each time: lshal to see which interfaces are really served, readelf -d on the vendor module to see which family it was built against, and then look for the unmodified AOSP module from a Pixel on the same build. Reading logs is a poor way into a bug like this one, because nothing fails loudly enough to log an error. Each side is simply waiting.
Drafted with AI, edited by hand. I publish it when it sounds like me.