How to force audio to Bluetooth via adb or terminal

1.6k Views Asked by At

I would like to change the output device of my Android 9 LineageOS device because I'm constantly facing the problem that audio is being played through the phone's speakers instead of my Bluetooth headphones. I don't know why Android sometimes decides not to use the connected audio device, but I assume it is a bug as it only happens sometimes.

As a workaround I would like to use the terminal in order to fix this whenever it happens.

My idea: Find out which service manages audio output, figure out which method I have to call and what the parameters need to be and then use the service utility from a shell script or terminal (which has root access).

I think my service is simply called "audio" (IAudioService). In the source code, the 35th method is "setBluetoothScoOn" which sounds like it could be what I'm looking for. It accepts one parameter (a boolean which I want to be true). So I ran this in my root terminal:

service call audio 35 i32 1

#audio: service name
#35: setBluetoothScoOn is the 35th method in in the IAudioServicesource code
#i32: data type to be used for the first parameter (boolean)
#1: means true in this context

The source code file I was talking about: https://android.googlesource.com/platform/frameworks/base/+/android-9.0.0_r1/media/java/android/media/IAudioService.aidl

Unfortunately nothing happens when I run my command. It just returns:

Result: Parcel(00000000    '....')

Any ideas what I'm doing wrong?

Edit:

When I am successfully connected having music being played (using VLC) through my Bluetooth headphones and run service call audio 38, I get the following response:

Result: Parcel(00000000 00000001   '........')

When I then run service call audio 37 i32 0 my phone immediately plays the audio through the phone's speakers instead of the Bluetooth headphones.

Then when I run service call audio 38 I get the following response:

Result: Parcel(00000000 00000000   '........')

As soon as I play the next song, audio plays through the Bluetooth headphones again though. And service call audio 38 returns this again:

Result: Parcel(00000000 00000001   '........')

This makes me wonder if 37 responds to setBluetoothScoOn and 38 to isBluetoothScoOn.

In a different situation, when I run service call audio 38 while I have my standard issues of having the Bluetooth headset connected and music plays through the speakers and refuses to play through the Bluetooth headphones, I still always get:

Result: Parcel(00000000 00000001   '........')

Until I run service call audio 37 i32 0, then it temporarily returns:

Result: Parcel(00000000 00000000   '........')

again until I play the next song, but at no point is audio playing through the Bluetooth headphones.

So essentially

service call audio 37 i32 1 only causes service call audio 38 to temporarily return:

Result: Parcel(00000000 00000001   '........')

Just like service call audio 37 i32 0 causes it to return:

Result: Parcel(00000000 00000000   '........')

But while plaxing music through Blurtooth, service call audio 37 i32 0 also temporarily plays audio through the speakers until I play the next song.

0

There are 0 best solutions below