One more fix for Soyes XS phones (but see disclaimer below)

The bluetooth implementation of this phone calls the gatt callbacks
*before* the connect call returns to the client.  This is incorrect because
the client won't have a reference to the gatt at that time.

Fortunately, we only need to check gatt on disconnect, so I moved that later.

But one problem I've noticed in my testing.  Sometimes this phone stops
being able to scan for BLE devices.  The only fix I've found is to click to
turn bluetooth off briefly and then back on.

A major problem with this phone is that if you reboot the phone it seems
the time the phone has forgotten its paring data and devices must
be re-paired.  This is a huge bummer and I don't think my app can fix this.
pull/40/head
geeksville 2020-06-09 12:18:35 -07:00
rodzic d81f88eeb3
commit 590e76731f
1 zmienionych plików z 15 dodań i 16 usunięć

Wyświetl plik

@ -165,24 +165,23 @@ class SafeBluetooth(private val context: Context, private val device: BluetoothD
status: Int,
newState: Int
) = exceptionReporter {
info("new bluetooth connection state $newState, status $status")
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 =
newState // we only care about connected/disconnected - not the transitional states
when (newState) {
BluetoothProfile.STATE_CONNECTED -> {
state =
newState // we only care about connected/disconnected - not the transitional states
// If autoconnect is on and this connect attempt failed, hopefully some future attempt will succeed
if (status != BluetoothGatt.GATT_SUCCESS && autoConnect) {
errormsg("Connect attempt failed $status, not calling connect completion handler...")
} else
completeWork(status, Unit)
}
BluetoothProfile.STATE_DISCONNECTED -> {
// If autoconnect is on and this connect attempt failed, hopefully some future attempt will succeed
if (status != BluetoothGatt.GATT_SUCCESS && autoConnect) {
errormsg("Connect attempt failed $status, not calling connect completion handler...")
} else
completeWork(status, Unit)
}
BluetoothProfile.STATE_DISCONNECTED -> {
if (gatt == null)
info("No gatt: ignoring connection state $newState, status $status") // Probably just shutting down
else {
// cancel any queued ops if we were already connected
val oldstate = state
state = newState