From 4d21919347a41b6128e02f75d90f034d77287b00 Mon Sep 17 00:00:00 2001 From: Steve Grosbois Date: Mon, 4 Nov 2024 11:53:39 +0100 Subject: [PATCH] Revert "feat(android): Clear the gatt cache before discover devices (#143)" (#145) --- .../kotlin/dev/bluefalcon/BlueFalcon.kt | 32 ++++--------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/library/src/androidMain/kotlin/dev/bluefalcon/BlueFalcon.kt b/library/src/androidMain/kotlin/dev/bluefalcon/BlueFalcon.kt index 734a869..4e6ace2 100644 --- a/library/src/androidMain/kotlin/dev/bluefalcon/BlueFalcon.kt +++ b/library/src/androidMain/kotlin/dev/bluefalcon/BlueFalcon.kt @@ -7,14 +7,12 @@ import android.bluetooth.le.* import android.content.Context import android.os.Build import android.os.ParcelUuid -import android.os.RemoteException import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.MutableStateFlow import java.nio.ByteBuffer import java.util.* - actual class BlueFalcon actual constructor( private val log: Logger, private val context: ApplicationContext @@ -33,12 +31,12 @@ actual class BlueFalcon actual constructor( actual fun connect(bluetoothPeripheral: BluetoothPeripheral, autoConnect: Boolean) { log.info("connect") - bluetoothPeripheral.bluetoothDevice.connectGatt( - context, - autoConnect, - mGattClientCallback, - transportMethod - ) + bluetoothPeripheral.bluetoothDevice.connectGatt( + context, + autoConnect, + mGattClientCallback, + transportMethod + ) } actual fun disconnect(bluetoothPeripheral: BluetoothPeripheral) { @@ -286,23 +284,6 @@ actual class BlueFalcon actual constructor( fun gattForDevice(bluetoothDevice: BluetoothDevice): BluetoothGatt? = gatts.firstOrNull { it.device == bluetoothDevice } - /** - * Clears the internal cache and forces a refresh of the services from the - * remote device. - * @hide - */ - private fun refresh(gatt: BluetoothGatt): Boolean { - try { - val refresh = gatt.javaClass.getMethod("refresh") - refresh.invoke(gatt) - } catch (e: RemoteException) { - log.error("Could not execute refresh", e) - return false - } - - return true - } - override fun onConnectionStateChange(gatt: BluetoothGatt?, status: Int, newState: Int) { super.onConnectionStateChange(gatt, status, newState) log.info("onConnectionStateChange") @@ -311,7 +292,6 @@ actual class BlueFalcon actual constructor( //BluetoothProfile#STATE_DISCONNECTED} or {@link BluetoothProfile#STATE_CONNECTED} if (newState == STATE_CONNECTED) { addGatt(bluetoothGatt) - refresh(bluetoothGatt) bluetoothGatt.readRemoteRssi() bluetoothGatt.discoverServices() delegates.forEach {