combov2: Catch exceptions thrown when the adapter is disabled / unavailable
This commit is contained in:
parent
c1058ad113
commit
6d998c8081
1 changed files with 27 additions and 16 deletions
|
@ -12,6 +12,7 @@ import dagger.android.HasAndroidInjector
|
||||||
import info.nightscout.comboctl.android.AndroidBluetoothInterface
|
import info.nightscout.comboctl.android.AndroidBluetoothInterface
|
||||||
import info.nightscout.comboctl.base.BasicProgressStage
|
import info.nightscout.comboctl.base.BasicProgressStage
|
||||||
import info.nightscout.comboctl.base.BluetoothException
|
import info.nightscout.comboctl.base.BluetoothException
|
||||||
|
import info.nightscout.comboctl.base.BluetoothNotEnabledException
|
||||||
import info.nightscout.comboctl.base.ComboException
|
import info.nightscout.comboctl.base.ComboException
|
||||||
import info.nightscout.comboctl.base.DisplayFrame
|
import info.nightscout.comboctl.base.DisplayFrame
|
||||||
import info.nightscout.comboctl.base.NullDisplayFrame
|
import info.nightscout.comboctl.base.NullDisplayFrame
|
||||||
|
@ -305,25 +306,35 @@ class ComboV2Plugin @Inject constructor (
|
||||||
permissionsToCheckFor = listOf("android.permission.BLUETOOTH_CONNECT")
|
permissionsToCheckFor = listOf("android.permission.BLUETOOTH_CONNECT")
|
||||||
) {
|
) {
|
||||||
aapsLogger.debug(LTag.PUMP, "Setting up bluetooth interface")
|
aapsLogger.debug(LTag.PUMP, "Setting up bluetooth interface")
|
||||||
bluetoothInterface!!.setup()
|
|
||||||
|
|
||||||
aapsLogger.debug(LTag.PUMP, "Setting up pump manager")
|
try {
|
||||||
pumpManager = ComboCtlPumpManager(bluetoothInterface!!, pumpStateStore)
|
bluetoothInterface!!.setup()
|
||||||
pumpManager!!.setup {
|
|
||||||
_pairedStateUIFlow.value = false
|
aapsLogger.debug(LTag.PUMP, "Setting up pump manager")
|
||||||
unpairing = false
|
pumpManager = ComboCtlPumpManager(bluetoothInterface!!, pumpStateStore)
|
||||||
|
pumpManager!!.setup {
|
||||||
|
_pairedStateUIFlow.value = false
|
||||||
|
unpairing = false
|
||||||
|
}
|
||||||
|
|
||||||
|
// UI flows that must have defined values right
|
||||||
|
// at start are initialized here.
|
||||||
|
|
||||||
|
// The paired state UI flow is special in that it is also
|
||||||
|
// used as the backing store for the isPaired() function,
|
||||||
|
// so setting up that UI state flow equals updating that
|
||||||
|
// paired state.
|
||||||
|
val paired = pumpManager!!.getPairedPumpAddresses().isNotEmpty()
|
||||||
|
_pairedStateUIFlow.value = paired
|
||||||
|
} catch (_: BluetoothNotEnabledException) {
|
||||||
|
// If the user currently has Bluetooth disabled, retry until
|
||||||
|
// the user turns it on. AAPS will automatically show a dialog
|
||||||
|
// box which requests the user to enable Bluetooth. Upon
|
||||||
|
// catching this exception, runWithPermissionCheck() will wait
|
||||||
|
// a bit before retrying, so no delay() call is needed here.
|
||||||
|
throw RetryPermissionCheckException()
|
||||||
}
|
}
|
||||||
|
|
||||||
// UI flows that must have defined values right
|
|
||||||
// at start are initialized here.
|
|
||||||
|
|
||||||
// The paired state UI flow is special in that it is also
|
|
||||||
// used as the backing store for the isPaired() function,
|
|
||||||
// so setting up that UI state flow equals updating that
|
|
||||||
// paired state.
|
|
||||||
val paired = pumpManager!!.getPairedPumpAddresses().isNotEmpty()
|
|
||||||
_pairedStateUIFlow.value = paired
|
|
||||||
|
|
||||||
setDriverState(DriverState.Disconnected)
|
setDriverState(DriverState.Disconnected)
|
||||||
|
|
||||||
aapsLogger.info(LTag.PUMP, "combov2 driver start complete")
|
aapsLogger.info(LTag.PUMP, "combov2 driver start complete")
|
||||||
|
|
Loading…
Reference in a new issue