combov2: Report error and abort driver start if Bluetooth is not supported

This commit is contained in:
Carlos Rafael Giani 2023-08-05 15:21:50 +02:00
parent 0f668472a4
commit 84f4303895
3 changed files with 17 additions and 0 deletions

View file

@ -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

View file

@ -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,

View file

@ -140,4 +140,5 @@ buttons at the same time to cancel pairing)\n
<string name="combov2_go_back">Go back</string>
<string name="combov2_cannot_pair_driver_not_initialized_explanation">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.</string>
<string name="combov2_bluetooth_disabled">Cannot start driver - Bluetooth is disabled</string>
<string name="combov2_bluetooth_not_supported">Driver cannot run - this device does not support Bluetooth</string>
</resources>