kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
fix an autobug - race condition on some phones BLE reconnect
rodzic
877006f26b
commit
0b7f853abc
|
@ -187,8 +187,10 @@ class SafeBluetooth(private val context: Context, private val device: BluetoothD
|
||||||
// Cancel any notifications - because when the device comes back it might have forgotten about us
|
// Cancel any notifications - because when the device comes back it might have forgotten about us
|
||||||
notifyHandlers.clear()
|
notifyHandlers.clear()
|
||||||
|
|
||||||
debug("calling lostConnect handler")
|
lostConnectCallback?.let {
|
||||||
lostConnectCallback?.invoke()
|
debug("calling lostConnect handler")
|
||||||
|
it.invoke()
|
||||||
|
}
|
||||||
|
|
||||||
// Queue a new connection attempt
|
// Queue a new connection attempt
|
||||||
val cb = connectionCallback
|
val cb = connectionCallback
|
||||||
|
@ -508,6 +510,10 @@ class SafeBluetooth(private val context: Context, private val device: BluetoothD
|
||||||
* cancelled and you'll need to recall connect to use this againt
|
* cancelled and you'll need to recall connect to use this againt
|
||||||
*/
|
*/
|
||||||
fun closeConnection() {
|
fun closeConnection() {
|
||||||
|
// Set these to null _before_ calling gatt.disconnect(), because we don't want the old lostConnectCallback to get called
|
||||||
|
lostConnectCallback = null
|
||||||
|
connectionCallback = null
|
||||||
|
|
||||||
failAllWork(BLEException("Connection closing"))
|
failAllWork(BLEException("Connection closing"))
|
||||||
|
|
||||||
if (gatt != null) {
|
if (gatt != null) {
|
||||||
|
@ -515,8 +521,6 @@ class SafeBluetooth(private val context: Context, private val device: BluetoothD
|
||||||
gatt!!.disconnect()
|
gatt!!.disconnect()
|
||||||
gatt!!.close()
|
gatt!!.close()
|
||||||
gatt = null
|
gatt = null
|
||||||
lostConnectCallback = null
|
|
||||||
connectionCallback = null
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue