try to fix disconnects

This commit is contained in:
Andrei Vereha 2022-05-31 09:52:10 +02:00
parent 3f3496426b
commit 17d4f3e8ce
2 changed files with 3 additions and 1 deletions

View file

@ -40,7 +40,7 @@ class BleCommCallbacks(
if (newState == BluetoothProfile.STATE_CONNECTED && status == BluetoothGatt.GATT_SUCCESS) { if (newState == BluetoothProfile.STATE_CONNECTED && status == BluetoothGatt.GATT_SUCCESS) {
connected.countDown() connected.countDown()
} }
if (newState == BluetoothProfile.STATE_DISCONNECTED && status != BluetoothGatt.GATT_SUCCESS) { if (newState == BluetoothProfile.STATE_DISCONNECTED) {
// If status == SUCCESS, it means that we initiated the disconnect. // If status == SUCCESS, it means that we initiated the disconnect.
disconnectHandler.onConnectionLost(status) disconnectHandler.onConnectionLost(status)
} }

View file

@ -61,6 +61,7 @@ class Connection(
@Volatile @Volatile
var msgIO: MessageIO? = null var msgIO: MessageIO? = null
@Synchronized
fun connect(connectionWaitCond: ConnectionWaitCondition) { fun connect(connectionWaitCond: ConnectionWaitCondition) {
aapsLogger.debug("Connecting connectionWaitCond=$connectionWaitCond") aapsLogger.debug("Connecting connectionWaitCond=$connectionWaitCond")
podState.connectionAttempts++ podState.connectionAttempts++
@ -117,6 +118,7 @@ class Connection(
dataBleIO.readyToRead() dataBleIO.readyToRead()
} }
@Synchronized
fun disconnect(closeGatt: Boolean) { fun disconnect(closeGatt: Boolean) {
aapsLogger.debug(LTag.PUMPBTCOMM, "Disconnecting closeGatt=$closeGatt") aapsLogger.debug(LTag.PUMPBTCOMM, "Disconnecting closeGatt=$closeGatt")
podState.bluetoothConnectionState = OmnipodDashPodStateManager.BluetoothConnectionState.DISCONNECTED podState.bluetoothConnectionState = OmnipodDashPodStateManager.BluetoothConnectionState.DISCONNECTED