Skip to content

Commit

Permalink
Revert "feat(android): Clear the gatt cache before discover devices (R…
Browse files Browse the repository at this point in the history
…eedyuk#143)"

This reverts commit ec37c4b.
  • Loading branch information
kwiky authored Nov 4, 2024
1 parent 1530003 commit a9e4f56
Showing 1 changed file with 6 additions and 26 deletions.
32 changes: 6 additions & 26 deletions library/src/androidMain/kotlin/dev/bluefalcon/BlueFalcon.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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")
Expand All @@ -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 {
Expand Down

0 comments on commit a9e4f56

Please sign in to comment.