2424package me.kavishdevar.librepods.utils
2525
2626import android.annotation.SuppressLint
27+ import android.bluetooth.BluetoothAdapter
2728import android.bluetooth.BluetoothDevice
2829import android.bluetooth.BluetoothSocket
2930import android.os.ParcelUuid
@@ -49,7 +50,7 @@ enum class ATTCCCDHandles(val value: Int) {
4950 HEARING_AID (ATTHandles .HEARING_AID .value + 1 ),
5051}
5152
52- class ATTManager (private val device : BluetoothDevice ) {
53+ class ATTManager (private val adapter : BluetoothAdapter , private val device : BluetoothDevice ) {
5354 companion object {
5455 private const val TAG = " ATTManager"
5556
@@ -72,7 +73,7 @@ class ATTManager(private val device: BluetoothDevice) {
7273 HiddenApiBypass .addHiddenApiExemptions(" Landroid/bluetooth/BluetoothSocket;" )
7374 val uuid = ParcelUuid .fromString(" 00000000-0000-0000-0000-000000000000" )
7475
75- socket = createBluetoothSocket(device, uuid)
76+ socket = createBluetoothSocket(adapter, device, uuid)
7677 socket!! .connect()
7778 input = socket!! .inputStream
7879 output = socket!! .outputStream
@@ -195,9 +196,10 @@ class ATTManager(private val device: BluetoothDevice) {
195196 }
196197 }
197198
198- private fun createBluetoothSocket (device : BluetoothDevice , uuid : ParcelUuid ): BluetoothSocket {
199+ private fun createBluetoothSocket (adapter : BluetoothAdapter , device : BluetoothDevice , uuid : ParcelUuid ): BluetoothSocket {
199200 val type = 3 // L2CAP
200201 val constructorSpecs = listOf (
202+ arrayOf(adapter, device, type, true , 31 , uuid),
201203 arrayOf(device, type, true , true , 31 , uuid),
202204 arrayOf(device, type, 1 , true , true , 31 , uuid),
203205 arrayOf(type, 1 , true , true , device, 31 , uuid),
0 commit comments