Skip to content

Commit 97cc563

Browse files
TebbeUbbencaspervk
authored andcommitted
Dash: Only call BluetoothGatt::connect when reusing the BluetoothGatt object
1 parent 4264e97 commit 97cc563

File tree

1 file changed

+9
-8
lines changed
  • pump/omnipod-dash/src/main/kotlin/app/aaps/pump/omnipod/dash/driver/comm/session

1 file changed

+9
-8
lines changed

pump/omnipod-dash/src/main/kotlin/app/aaps/pump/omnipod/dash/driver/comm/session/Connection.kt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,17 @@ class Connection(
7171
podState.connectionAttempts++
7272
podState.bluetoothConnectionState = OmnipodDashPodStateManager.BluetoothConnectionState.CONNECTING
7373
val autoConnect = false
74-
val gatt = gattConnection ?: podDevice.connectGatt(context, autoConnect, bleCommCallbacks, BluetoothDevice.TRANSPORT_LE)
75-
gattConnection = gatt
74+
var gatt = gattConnection
7675
if (gatt == null) {
77-
Thread.sleep(SLEEP_WHEN_FAILING_TO_CONNECT_GATT) // Do not retry too often
78-
throw FailedToConnectException("connectGatt() returned null")
76+
gatt = podDevice.connectGatt(context, autoConnect, bleCommCallbacks, BluetoothDevice.TRANSPORT_LE)
77+
if (gatt == null) {
78+
Thread.sleep(SLEEP_WHEN_FAILING_TO_CONNECT_GATT) // Do not retry too often
79+
throw FailedToConnectException("connectGatt() returned null")
80+
}
81+
gattConnection = gatt
82+
} else if (!gatt.connect()) {
83+
throw FailedToConnectException("connect() returned false")
7984
}
80-
gatt.connect()
81-
// if (!gatt.connect()) {
82-
// throw FailedToConnectException("connect() returned false")
83-
// }
8485
val before = SystemClock.elapsedRealtime()
8586
if (waitForConnection(connectionWaitCond) !is Connected) {
8687
podState.bluetoothConnectionState = OmnipodDashPodStateManager.BluetoothConnectionState.DISCONNECTED

0 commit comments

Comments
 (0)