From e6fd79f477a102cb6dc9c53584b003f7ed1d9c7a Mon Sep 17 00:00:00 2001 From: geeksville Date: Tue, 30 Jun 2020 11:39:04 -0700 Subject: [PATCH] fix another autobug - clear gatt first, because close() can fail --- .../main/java/com/geeksville/mesh/service/SafeBluetooth.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/geeksville/mesh/service/SafeBluetooth.kt b/app/src/main/java/com/geeksville/mesh/service/SafeBluetooth.kt index 008fb0f99..aae882bb3 100644 --- a/app/src/main/java/com/geeksville/mesh/service/SafeBluetooth.kt +++ b/app/src/main/java/com/geeksville/mesh/service/SafeBluetooth.kt @@ -676,10 +676,11 @@ class SafeBluetooth(private val context: Context, private val device: BluetoothD msecsLeft -= 100 } - if (gatt != null) { + gatt?.let { g2 -> warn("Android onConnectionStateChange did not run, manually closing") - gatt?.close() - gatt = null + gatt = + null // clear gat before calling close, bcause close might throw dead object exception + g2.close() } } catch (ex: DeadObjectException) { warn("Ignoring dead object exception, probably bluetooth was just disabled")