Skip to content

Commit 345b7b9

Browse files
authored
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
1 parent fa30d3c commit 345b7b9

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

android/app/src/main/java/me/kavishdevar/librepods/services/AirPodsService.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2708,9 +2708,11 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList
27082708
override fun onServiceConnected(profile: Int, proxy: BluetoothProfile) {
27092709
if (profile == BluetoothProfile.HEADSET) {
27102710
try {
2711-
val method =
2711+
val policyMethod = proxy.javaClass.getMethod("setConnectionPolicy", BluetoothDevice::class.java, Int::class.java)
2712+
policyMethod.invoke(proxy, device, 100)
2713+
val connectMethod =
27122714
proxy.javaClass.getMethod("connect", BluetoothDevice::class.java)
2713-
method.invoke(proxy, device)
2715+
connectMethod.invoke(proxy, device)
27142716
} catch (e: Exception) {
27152717
e.printStackTrace()
27162718
} finally {

0 commit comments

Comments
 (0)