From 17d4f3e8ce25283285f4a22760028e66c0953bca Mon Sep 17 00:00:00 2001 From: Andrei Vereha Date: Tue, 31 May 2022 09:52:10 +0200 Subject: [PATCH 1/2] try to fix disconnects --- .../pump/omnipod/dash/driver/comm/callbacks/BleCommCallbacks.kt | 2 +- .../plugins/pump/omnipod/dash/driver/comm/session/Connection.kt | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/callbacks/BleCommCallbacks.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/callbacks/BleCommCallbacks.kt index 83ee2346b4..3724341c89 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/callbacks/BleCommCallbacks.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/callbacks/BleCommCallbacks.kt @@ -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) } diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/session/Connection.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/session/Connection.kt index b403cb7af2..3b934510ed 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/session/Connection.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/session/Connection.kt @@ -61,6 +61,7 @@ class Connection( @Volatile var msgIO: MessageIO? = null + @Synchronized fun connect(connectionWaitCond: ConnectionWaitCondition) { aapsLogger.debug("Connecting connectionWaitCond=$connectionWaitCond") podState.connectionAttempts++ @@ -117,6 +118,7 @@ class Connection( dataBleIO.readyToRead() } + @Synchronized fun disconnect(closeGatt: Boolean) { aapsLogger.debug(LTag.PUMPBTCOMM, "Disconnecting closeGatt=$closeGatt") podState.bluetoothConnectionState = OmnipodDashPodStateManager.BluetoothConnectionState.DISCONNECTED From bf889793f0de9dcd91a028a013f91dba20bbf4e8 Mon Sep 17 00:00:00 2001 From: Andrei Vereha Date: Fri, 17 Jun 2022 17:58:21 +0200 Subject: [PATCH 2/2] make it compile --- .../pump/omnipod/dash/driver/comm/ServiceDiscoverer.kt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/ServiceDiscoverer.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/ServiceDiscoverer.kt index cd35a45bdb..ca371fafac 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/ServiceDiscoverer.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/ServiceDiscoverer.kt @@ -27,9 +27,13 @@ class ServiceDiscoverer( fun discoverServices(connectionWaitCond: ConnectionWaitCondition): Map { 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)