Fix Android cleanup on gatt disconnect (#109)
This commit is contained in:
@@ -178,9 +178,9 @@ fun <T> SparseArray<T>.toList(): List<Pair<Int, T>> {
|
|||||||
fun BluetoothGatt.getCharacteristic(
|
fun BluetoothGatt.getCharacteristic(
|
||||||
service: String,
|
service: String,
|
||||||
characteristic: String,
|
characteristic: String,
|
||||||
): BluetoothGattCharacteristic? =
|
): BluetoothGattCharacteristic? {
|
||||||
getService(UUID.fromString(service)).getCharacteristic(UUID.fromString(characteristic))
|
return getService(UUID.fromString(service))?.getCharacteristic(UUID.fromString(characteristic))
|
||||||
|
}
|
||||||
|
|
||||||
fun subscriptionFailedError(error: String? = null): Result<Unit> {
|
fun subscriptionFailedError(error: String? = null): Result<Unit> {
|
||||||
return Result.failure(
|
return Result.failure(
|
||||||
|
|||||||
@@ -716,7 +716,6 @@ class UniversalBlePlugin : UniversalBlePlatformChannel, BluetoothGattCallback(),
|
|||||||
private fun cleanConnection(gatt: BluetoothGatt) {
|
private fun cleanConnection(gatt: BluetoothGatt) {
|
||||||
knownGatts.remove(gatt)
|
knownGatts.remove(gatt)
|
||||||
gatt.disconnect()
|
gatt.disconnect()
|
||||||
gatt.close()
|
|
||||||
|
|
||||||
readResultFutureList.removeAll {
|
readResultFutureList.removeAll {
|
||||||
if (it.deviceId == gatt.device.address) {
|
if (it.deviceId == gatt.device.address) {
|
||||||
@@ -885,6 +884,8 @@ class UniversalBlePlugin : UniversalBlePlatformChannel, BluetoothGattCallback(),
|
|||||||
gatt.device.address, false, status.parseHciErrorCode()
|
gatt.device.address, false, status.parseHciErrorCode()
|
||||||
) {}
|
) {}
|
||||||
}
|
}
|
||||||
|
Log.d(TAG, "Closing gatt for ${gatt.device.name}")
|
||||||
|
gatt.close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user