fix autobug - if gatt is closed while we are shutting down it is not an error

This commit is contained in:
geeksville 2020-08-30 12:01:38 -07:00
parent bd29a93a71
commit a5678392f5
2 changed files with 8 additions and 4 deletions

View file

@ -409,9 +409,12 @@ class BluetoothInterface(val service: RadioInterfaceService, val address: String
}
}
} catch (ex: BLEException) {
scheduleReconnect(
"Unexpected error discovering services, forcing disconnect $ex"
)
if (s.gatt == null)
warn("GATT was closed while discovering, assume we are shutting down")
else
scheduleReconnect(
"Unexpected error discovering services, forcing disconnect $ex"
)
}
}
}

View file

@ -613,7 +613,8 @@ class SafeBluetooth(private val context: Context, private val device: BluetoothD
private fun queueDiscoverServices(cont: Continuation<Unit>, timeout: Long = 0) {
queueWork("discover", cont, timeout) {
gatt?.discoverServices() ?: throw BLEException("GATT is null")
gatt?.discoverServices()
?: false // throw BLEException("GATT is null") - if we return false here it is probably because the device is being torn down
}
}