android(fix): set HSP/HFP policy to allow when connecting to audio (#318)

* android: use setConnectionProfile instead of (dis)connect on BluetoothProfile

this prevents android from trying to reconnect to audio itself after we disconnect. this is essentially the same as toggling the 'Media Audio' and 'Phone Calls' settings in the android settings

* android(fix): set HSP/HFP policy to allow when connecting to audio

forgot to change it
This commit is contained in:
Kavish Devar
2025-11-24 14:59:01 +05:30
committed by GitHub
parent fa30d3c09a
commit 345b7b9051

View File

@@ -2708,9 +2708,11 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
override fun onServiceConnected(profile: Int, proxy: BluetoothProfile) {
if (profile == BluetoothProfile.HEADSET) {
try {
val method =
val policyMethod = proxy.javaClass.getMethod("setConnectionPolicy", BluetoothDevice::class.java, Int::class.java)
policyMethod.invoke(proxy, device, 100)
val connectMethod =
proxy.javaClass.getMethod("connect", BluetoothDevice::class.java)
method.invoke(proxy, device)
connectMethod.invoke(proxy, device)
} catch (e: Exception) {
e.printStackTrace()
} finally {