diff --git a/android/app/src/main/java/me/kavishdevar/librepods/services/AirPodsService.kt b/android/app/src/main/java/me/kavishdevar/librepods/services/AirPodsService.kt index d890e88f2..7d67fb773 100644 --- a/android/app/src/main/java/me/kavishdevar/librepods/services/AirPodsService.kt +++ b/android/app/src/main/java/me/kavishdevar/librepods/services/AirPodsService.kt @@ -29,6 +29,7 @@ import android.app.NotificationManager import android.app.PendingIntent import android.app.Service import android.appwidget.AppWidgetManager +import android.bluetooth.BluetoothAdapter import android.bluetooth.BluetoothDevice import android.bluetooth.BluetoothHeadset import android.bluetooth.BluetoothManager @@ -2353,8 +2354,12 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList } private fun createBluetoothSocket(device: BluetoothDevice, uuid: ParcelUuid): BluetoothSocket { - val type = 3 // L2CAP + val type = BluetoothSocket.TYPE_L2CAP + val adapter = HiddenApiBypass.getInstanceFields(device.javaClass) + .firstOrNull { it.name == "mAdapter" } + ?.run { isAccessible = true; get(device) as BluetoothAdapter } val constructorSpecs = listOf( + arrayOf(adapter, device, type, true, true, 0x1001, uuid), arrayOf(device, type, true, true, 0x1001, uuid), arrayOf(device, type, 1, true, true, 0x1001, uuid), arrayOf(type, 1, true, true, device, 0x1001, uuid), @@ -2392,7 +2397,7 @@ class AirPodsService : Service(), SharedPreferences.OnSharedPreferenceChangeList @SuppressLint("MissingPermission", "UnspecifiedRegisterReceiverFlag") fun connectToSocket(device: BluetoothDevice, manual: Boolean = false) { Log.d(TAG, " Connecting to socket") - HiddenApiBypass.addHiddenApiExemptions("Landroid/bluetooth/BluetoothSocket;") + HiddenApiBypass.addHiddenApiExemptions("Landroid/bluetooth/BluetoothSocket;", "Landroid/bluetooth/BluetoothDevice;") val uuid: ParcelUuid = ParcelUuid.fromString("74ec2172-0bad-4d01-8f77-997b2be0722a") if (!isConnectedLocally) { socket = try { diff --git a/android/app/src/main/java/me/kavishdevar/librepods/utils/ATTManager.kt b/android/app/src/main/java/me/kavishdevar/librepods/utils/ATTManager.kt index af95ec989..f8dfb5293 100644 --- a/android/app/src/main/java/me/kavishdevar/librepods/utils/ATTManager.kt +++ b/android/app/src/main/java/me/kavishdevar/librepods/utils/ATTManager.kt @@ -24,6 +24,7 @@ package me.kavishdevar.librepods.utils import android.annotation.SuppressLint +import android.bluetooth.BluetoothAdapter import android.bluetooth.BluetoothDevice import android.bluetooth.BluetoothSocket import android.os.ParcelUuid @@ -69,7 +70,7 @@ class ATTManager(private val device: BluetoothDevice) { @SuppressLint("MissingPermission") fun connect() { - HiddenApiBypass.addHiddenApiExemptions("Landroid/bluetooth/BluetoothSocket;") + HiddenApiBypass.addHiddenApiExemptions("Landroid/bluetooth/BluetoothSocket;", "Landroid/bluetooth/BluetoothDevice;") val uuid = ParcelUuid.fromString("00000000-0000-0000-0000-000000000000") socket = createBluetoothSocket(device, uuid) @@ -196,8 +197,12 @@ class ATTManager(private val device: BluetoothDevice) { } private fun createBluetoothSocket(device: BluetoothDevice, uuid: ParcelUuid): BluetoothSocket { - val type = 3 // L2CAP + val type = BluetoothSocket.TYPE_L2CAP + val adapter = HiddenApiBypass.getInstanceFields(device.javaClass) + .firstOrNull { it.name == "mAdapter" } + ?.run { isAccessible = true; get(device) as BluetoothAdapter } val constructorSpecs = listOf( + arrayOf(adapter, device, type, true, true, 31, uuid), arrayOf(device, type, true, true, 31, uuid), arrayOf(device, type, 1, true, true, 31, uuid), arrayOf(type, 1, true, true, device, 31, uuid),