Merge pull request #1838 from avereha/avereha/fix-disconnect
fix disconnect
This commit is contained in:
commit
b09dd0ed1d
3 changed files with 10 additions and 4 deletions
|
@ -27,9 +27,13 @@ class ServiceDiscoverer(
|
|||
fun discoverServices(connectionWaitCond: ConnectionWaitCondition): Map<CharacteristicType, BluetoothGattCharacteristic> {
|
||||
logger.debug(LTag.PUMPBTCOMM, "Discovering services")
|
||||
bleCallbacks.startServiceDiscovery()
|
||||
val discover = gatt.discoverServices()
|
||||
if (!discover) {
|
||||
throw ConnectException("Could not start discovering services`")
|
||||
try {
|
||||
val discover = gatt.discoverServices()
|
||||
if (!discover) {
|
||||
throw ConnectException("Could not start discovering services`")
|
||||
}
|
||||
} catch (ex: SecurityException) {
|
||||
throw ConnectException("Missing bluetooth permission")
|
||||
}
|
||||
connectionWaitCond.timeoutMs?.let {
|
||||
bleCallbacks.waitForServiceDiscovery(it)
|
||||
|
|
|
@ -40,7 +40,7 @@ class BleCommCallbacks(
|
|||
if (newState == BluetoothProfile.STATE_CONNECTED && status == BluetoothGatt.GATT_SUCCESS) {
|
||||
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.
|
||||
disconnectHandler.onConnectionLost(status)
|
||||
}
|
||||
|
|
|
@ -62,6 +62,7 @@ class Connection(
|
|||
@Volatile
|
||||
var msgIO: MessageIO? = null
|
||||
|
||||
@Synchronized
|
||||
fun connect(connectionWaitCond: ConnectionWaitCondition) {
|
||||
aapsLogger.debug("Connecting connectionWaitCond=$connectionWaitCond")
|
||||
podState.connectionAttempts++
|
||||
|
@ -118,6 +119,7 @@ class Connection(
|
|||
dataBleIO.readyToRead()
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun disconnect(closeGatt: Boolean) {
|
||||
aapsLogger.debug(LTag.PUMPBTCOMM, "Disconnecting closeGatt=$closeGatt")
|
||||
podState.bluetoothConnectionState = OmnipodDashPodStateManager.BluetoothConnectionState.DISCONNECTED
|
||||
|
|
Loading…
Reference in a new issue