Fix Android cleanup on gatt disconnect (#109)

This commit is contained in:
Rohit Sangwan
2024-12-05 15:56:46 +05:30
committed by GitHub
parent 8524b94f19
commit 9acb13f106
2 changed files with 5 additions and 4 deletions
@@ -178,9 +178,9 @@ fun <T> SparseArray<T>.toList(): List<Pair<Int, T>> {
fun BluetoothGatt.getCharacteristic(
service: String,
characteristic: String,
): BluetoothGattCharacteristic? =
getService(UUID.fromString(service)).getCharacteristic(UUID.fromString(characteristic))
): BluetoothGattCharacteristic? {
return getService(UUID.fromString(service))?.getCharacteristic(UUID.fromString(characteristic))
}
fun subscriptionFailedError(error: String? = null): Result<Unit> {
return Result.failure(
@@ -716,7 +716,6 @@ class UniversalBlePlugin : UniversalBlePlatformChannel, BluetoothGattCallback(),
private fun cleanConnection(gatt: BluetoothGatt) {
knownGatts.remove(gatt)
gatt.disconnect()
gatt.close()
readResultFutureList.removeAll {
if (it.deviceId == gatt.device.address) {
@@ -885,6 +884,8 @@ class UniversalBlePlugin : UniversalBlePlatformChannel, BluetoothGattCallback(),
gatt.device.address, false, status.parseHciErrorCode()
) {}
}
Log.d(TAG, "Closing gatt for ${gatt.device.name}")
gatt.close()
}
}