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 c7bed6c commit 67ceddd
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -481,16 +481,18 @@ class BluetoothPeripheral internal constructor(
Logger.d(TAG, "connect to '%s' (%s) using TRANSPORT_LE", name, address)
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")
cancelConnectionTimer()
null
}

bluetoothGatt?.let {
bluetoothGattCallback.onConnectionStateChange(it, HciStatus.SUCCESS.value, BluetoothProfile.STATE_CONNECTING)
connectTimestamp = SystemClock.elapsedRealtime()
startConnectionTimer(this@BluetoothPeripheral)
}
}
} else {
Expand Down

0 comments on commit 67ceddd

Please sign in to comment.