autobug, prevent redundant notifcations from onConnectChanged

pull/40/head
geeksville 2020-05-24 11:38:33 -07:00
rodzic 238ae9a06c
commit 4d6ca25caf
1 zmienionych plików z 61 dodań i 54 usunięć

Wyświetl plik

@ -164,7 +164,12 @@ class SafeBluetooth(private val context: Context, private val device: BluetoothD
status: Int,
newState: Int
) = exceptionReporter {
if (gatt == null)
info("No gatt: ignoring connection state $newState, status $status") // Probably just shutting down
else {
info("new bluetooth connection state $newState, status $status")
when (newState) {
BluetoothProfile.STATE_CONNECTED -> {
state =
@ -223,6 +228,7 @@ class SafeBluetooth(private val context: Context, private val device: BluetoothD
}
}
}
}
override fun onServicesDiscovered(gatt: BluetoothGatt, status: Int) {
// For testing lie and claim failure
@ -619,11 +625,12 @@ class SafeBluetooth(private val context: Context, private val device: BluetoothD
failAllWork(BLEException("Connection closing"))
if (gatt != null) {
gatt?.let { g ->
info("Closing our GATT connection")
gatt!!.disconnect()
gatt!!.close()
gatt = null
gatt =
null // Clear this first so the onConnectionChange callback can ignore while we are shutting down
g.disconnect()
g.close()
}
}