Skip to content

Commit

Permalink
Fix race condition for connection timer
Browse files Browse the repository at this point in the history
  • Loading branch information
weliem committed Jul 27, 2024
1 parent 4573fa3 commit 470f5c4
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -568,16 +568,17 @@ class BluetoothPeripheral internal constructor(
registerBondingBroadcastReceivers()
discoveryStarted = false
connectTimestamp = SystemClock.elapsedRealtime()
startConnectionTimer(this@BluetoothPeripheral)
bluetoothGatt = try {
device.connectGatt(context, false, bluetoothGattCallback, BluetoothDevice.TRANSPORT_LE)
} catch (e: SecurityException) {
Logger.d(TAG, "exception when calling connectGatt")
cancelConnectionTimer()
null
}

bluetoothGatt?.let {
bluetoothGattCallback.onConnectionStateChange(bluetoothGatt, HciStatus.SUCCESS.value, BluetoothProfile.STATE_CONNECTING)
startConnectionTimer(this@BluetoothPeripheral)
}
}, DIRECT_CONNECTION_DELAY_IN_MS.toLong())
} else {
Expand Down

0 comments on commit 470f5c4

Please sign in to comment.