From 84f4303895ca3f0f271c04f3c632b972f3d82ed5 Mon Sep 17 00:00:00 2001 From: Carlos Rafael Giani Date: Sat, 5 Aug 2023 15:21:50 +0200 Subject: [PATCH] combov2: Report error and abort driver start if Bluetooth is not supported --- .../interfaces/notifications/Notification.kt | 1 + .../info/nightscout/pump/combov2/ComboV2Plugin.kt | 15 +++++++++++++++ pump/combov2/src/main/res/values/strings.xml | 1 + 3 files changed, 17 insertions(+) diff --git a/core/interfaces/src/main/java/info/nightscout/interfaces/notifications/Notification.kt b/core/interfaces/src/main/java/info/nightscout/interfaces/notifications/Notification.kt index b15459c9b0..6509fb7f61 100644 --- a/core/interfaces/src/main/java/info/nightscout/interfaces/notifications/Notification.kt +++ b/core/interfaces/src/main/java/info/nightscout/interfaces/notifications/Notification.kt @@ -137,6 +137,7 @@ open class Notification { const val PATCH_NOT_ACTIVE = 83 const val PUMP_SETTINGS_FAILED = 84 const val PUMP_TIMEZONE_UPDATE_FAILED = 85 + const val BLUETOOTH_NOT_SUPPORTED = 86 const val USER_MESSAGE = 1000 diff --git a/pump/combov2/src/main/kotlin/info/nightscout/pump/combov2/ComboV2Plugin.kt b/pump/combov2/src/main/kotlin/info/nightscout/pump/combov2/ComboV2Plugin.kt index 39a9e6e2c1..0fd7b2c9ff 100644 --- a/pump/combov2/src/main/kotlin/info/nightscout/pump/combov2/ComboV2Plugin.kt +++ b/pump/combov2/src/main/kotlin/info/nightscout/pump/combov2/ComboV2Plugin.kt @@ -12,6 +12,7 @@ import dagger.android.HasAndroidInjector import info.nightscout.comboctl.android.AndroidBluetoothInterface import info.nightscout.comboctl.base.BasicProgressStage import info.nightscout.comboctl.base.BluetoothException +import info.nightscout.comboctl.base.BluetoothNotAvailableException import info.nightscout.comboctl.base.BluetoothNotEnabledException import info.nightscout.comboctl.base.ComboException import info.nightscout.comboctl.base.DisplayFrame @@ -346,6 +347,20 @@ class ComboV2Plugin @Inject constructor ( _pairedStateUIFlow.value = paired pumpManager = newPumpManager + } catch (_: BluetoothNotAvailableException) { + uiInteraction.addNotification( + Notification.BLUETOOTH_NOT_SUPPORTED, + text = rh.gs(R.string.combov2_bluetooth_not_supported), + level = Notification.URGENT + ) + + // Deliberately _not_ setting the driver state here before + // exiting this scope. We are essentially aborting the start + // since Bluetooth is not supported by the hardware, so the + // driver cannot do anything, and therefore cannot leave the + // DriverState.NotInitialized state. + aapsLogger.error(LTag.PUMP, "combov2 driver start cannot be completed since the hardware does not support Bluetooth") + return@runWithPermissionCheck } catch (_: BluetoothNotEnabledException) { uiInteraction.addNotification( Notification.BLUETOOTH_NOT_ENABLED, diff --git a/pump/combov2/src/main/res/values/strings.xml b/pump/combov2/src/main/res/values/strings.xml index e1e2432874..3051413bcd 100644 --- a/pump/combov2/src/main/res/values/strings.xml +++ b/pump/combov2/src/main/res/values/strings.xml @@ -140,4 +140,5 @@ buttons at the same time to cancel pairing)\n Go back Cannot perform pairing because the driver is not initialized. This typically happens because the necessary Bluetooth permissions have not been granted. Go back, grant the Bluetooth permissions, then try again to pair. Cannot start driver - Bluetooth is disabled + Driver cannot run - this device does not support Bluetooth