commit
009b3467a5
1 changed files with 8 additions and 6 deletions
|
@ -30,9 +30,8 @@ class OmnipodDashBleManagerImpl @Inject constructor(
|
|||
) : OmnipodDashBleManager {
|
||||
|
||||
private val busy = AtomicBoolean(false)
|
||||
private val bluetoothManager: BluetoothManager =
|
||||
context.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager
|
||||
private val bluetoothAdapter: BluetoothAdapter = bluetoothManager.adapter
|
||||
private val bluetoothAdapter: BluetoothAdapter?
|
||||
get() = (context.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager?)?.adapter
|
||||
private var connection: Connection? = null
|
||||
private val ids = Ids(podState)
|
||||
|
||||
|
@ -123,7 +122,8 @@ class OmnipodDashBleManagerImpl @Inject constructor(
|
|||
val podAddress =
|
||||
podState.bluetoothAddress
|
||||
?: throw FailedToConnectException("Missing bluetoothAddress, activate the pod first")
|
||||
val podDevice = bluetoothAdapter.getRemoteDevice(podAddress)
|
||||
val podDevice = bluetoothAdapter?.getRemoteDevice(podAddress)
|
||||
?: throw ConnectException("Bluetooth not available")
|
||||
val conn = connection
|
||||
?: Connection(podDevice, aapsLogger, context, podState)
|
||||
connection = conn
|
||||
|
@ -193,7 +193,9 @@ class OmnipodDashBleManagerImpl @Inject constructor(
|
|||
aapsLogger.info(LTag.PUMPBTCOMM, "Starting new pod activation")
|
||||
|
||||
emitter.onNext(PodEvent.Scanning)
|
||||
val podScanner = PodScanner(aapsLogger, bluetoothAdapter)
|
||||
val adapter = bluetoothAdapter
|
||||
?: throw ConnectException("Bluetooth not available")
|
||||
val podScanner = PodScanner(aapsLogger, adapter)
|
||||
val podAddress = podScanner.scanForPod(
|
||||
PodScanner.SCAN_FOR_SERVICE_UUID,
|
||||
PodScanner.POD_ID_NOT_ACTIVATED
|
||||
|
@ -201,7 +203,7 @@ class OmnipodDashBleManagerImpl @Inject constructor(
|
|||
podState.bluetoothAddress = podAddress
|
||||
|
||||
emitter.onNext(PodEvent.BluetoothConnecting)
|
||||
val podDevice = bluetoothAdapter.getRemoteDevice(podAddress)
|
||||
val podDevice = adapter.getRemoteDevice(podAddress)
|
||||
val conn = Connection(podDevice, aapsLogger, context, podState)
|
||||
connection = conn
|
||||
conn.connect(ConnectionWaitCondition(timeoutMs = 3 * Connection.BASE_CONNECT_TIMEOUT_MS))
|
||||
|
|
Loading…
Reference in a new issue