From 31458fb2bab93fefbb2fb97b9287a9bcd3ff0d96 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 2 Jan 2022 12:52:34 +0100 Subject: [PATCH] diaconn: prevent NPE --- .../nightscout/androidaps/diaconn/service/BLECommonService.kt | 4 +++- .../plugins/pump/common/hw/rileylink/ble/RileyLinkBLE.kt | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/diaconn/src/main/java/info/nightscout/androidaps/diaconn/service/BLECommonService.kt b/diaconn/src/main/java/info/nightscout/androidaps/diaconn/service/BLECommonService.kt index d8b1edd5c2..9e059045ea 100644 --- a/diaconn/src/main/java/info/nightscout/androidaps/diaconn/service/BLECommonService.kt +++ b/diaconn/src/main/java/info/nightscout/androidaps/diaconn/service/BLECommonService.kt @@ -105,9 +105,11 @@ class BLECommonService @Inject internal constructor( scheduledDisconnection?.cancel(false) scheduledDisconnection = null - if (bluetoothAdapter == null || bluetoothGatt == null) { + if (bluetoothAdapter == null || bluetoothGatt == null || uartIndicate == null) { aapsLogger.error("disconnect is not possible: (mBluetoothAdapter == null) " + (bluetoothAdapter == null)) aapsLogger.error("disconnect is not possible: (mBluetoothGatt == null) " + (bluetoothGatt == null)) + aapsLogger.error("disconnect is not possible: (uartIndicate == null) " + (uartIndicate == null)) + isConnected = false return } bluetoothGatt?.setCharacteristicNotification(uartIndicate, false) diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RileyLinkBLE.kt b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RileyLinkBLE.kt index 0a557d79ed..ef8d8bb34e 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RileyLinkBLE.kt +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RileyLinkBLE.kt @@ -43,6 +43,7 @@ class RileyLinkBLE @Inject constructor(private val context: Context) { private val gattDebugEnabled = true private var manualDisconnect = false + //val bluetoothAdapter: BluetoothAdapter = BluetoothAdapter.getDefaultAdapter() val bluetoothAdapter: BluetoothAdapter? get() = (context.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager?)?.adapter private val bluetoothGattCallback: BluetoothGattCallback var rileyLinkDevice: BluetoothDevice? = null