diaconn: prevent NPE

This commit is contained in:
Milos Kozak 2022-01-02 12:52:34 +01:00
parent 9596c49968
commit 31458fb2ba
2 changed files with 4 additions and 1 deletions

View file

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

View file

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