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,10 +27,14 @@ class ServiceDiscoverer(
|
||||||
fun discoverServices(connectionWaitCond: ConnectionWaitCondition): Map<CharacteristicType, BluetoothGattCharacteristic> {
|
fun discoverServices(connectionWaitCond: ConnectionWaitCondition): Map<CharacteristicType, BluetoothGattCharacteristic> {
|
||||||
logger.debug(LTag.PUMPBTCOMM, "Discovering services")
|
logger.debug(LTag.PUMPBTCOMM, "Discovering services")
|
||||||
bleCallbacks.startServiceDiscovery()
|
bleCallbacks.startServiceDiscovery()
|
||||||
|
try {
|
||||||
val discover = gatt.discoverServices()
|
val discover = gatt.discoverServices()
|
||||||
if (!discover) {
|
if (!discover) {
|
||||||
throw ConnectException("Could not start discovering services`")
|
throw ConnectException("Could not start discovering services`")
|
||||||
}
|
}
|
||||||
|
} catch (ex: SecurityException) {
|
||||||
|
throw ConnectException("Missing bluetooth permission")
|
||||||
|
}
|
||||||
connectionWaitCond.timeoutMs?.let {
|
connectionWaitCond.timeoutMs?.let {
|
||||||
bleCallbacks.waitForServiceDiscovery(it)
|
bleCallbacks.waitForServiceDiscovery(it)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,6 +62,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++
|
||||||
|
@ -118,6 +119,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
|
||||||
|
|
Loading…
Reference in a new issue