combov2: Catch exceptions thrown when the adapter is disabled / unavailable
This commit is contained in:
parent
c1058ad113
commit
6d998c8081
|
@ -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.BluetoothNotEnabledException
|
||||
import info.nightscout.comboctl.base.ComboException
|
||||
import info.nightscout.comboctl.base.DisplayFrame
|
||||
import info.nightscout.comboctl.base.NullDisplayFrame
|
||||
|
@ -305,6 +306,8 @@ class ComboV2Plugin @Inject constructor (
|
|||
permissionsToCheckFor = listOf("android.permission.BLUETOOTH_CONNECT")
|
||||
) {
|
||||
aapsLogger.debug(LTag.PUMP, "Setting up bluetooth interface")
|
||||
|
||||
try {
|
||||
bluetoothInterface!!.setup()
|
||||
|
||||
aapsLogger.debug(LTag.PUMP, "Setting up pump manager")
|
||||
|
@ -323,6 +326,14 @@ class ComboV2Plugin @Inject constructor (
|
|||
// 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()
|
||||
}
|
||||
|
||||
setDriverState(DriverState.Disconnected)
|
||||
|
||||
|
|
Loading…
Reference in a new issue