From 401f2d4290a0a29fbb84b9c3d5b19ce551b5665e Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Fri, 5 Aug 2022 14:36:33 +0200 Subject: [PATCH] RL: fix indexoutofbounds --- .../common/hw/rileylink/ble/RileyLinkBLE.kt | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) 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 5a48ec26cf..09a7a68c49 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 @@ -217,15 +217,17 @@ class RileyLinkBLE @Inject constructor( // Tell Android that we want the notifications bluetoothConnectionGatt?.setCharacteristicNotification(chara, true) val list = chara.descriptors - if (gattDebugEnabled) for (i in list.indices) aapsLogger.debug(LTag.PUMPBTCOMM, "Found descriptor: " + list[i].toString()) - // Tell the remote device to send the notifications - mCurrentOperation = DescriptorWriteOperation(aapsLogger, bluetoothConnectionGatt, list[0], BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE) - mCurrentOperation?.execute(this) - when { - mCurrentOperation?.timedOut == true -> retValue.resultCode = BLECommOperationResult.RESULT_TIMEOUT - mCurrentOperation?.interrupted == true -> retValue.resultCode = BLECommOperationResult.RESULT_INTERRUPTED - else -> retValue.resultCode = BLECommOperationResult.RESULT_SUCCESS - } + if (list.size > 0) { + if (gattDebugEnabled) for (i in list.indices) aapsLogger.debug(LTag.PUMPBTCOMM, "Found descriptor: " + list[i].toString()) + // Tell the remote device to send the notifications + mCurrentOperation = DescriptorWriteOperation(aapsLogger, bluetoothConnectionGatt, list[0], BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE) + mCurrentOperation?.execute(this) + when { + mCurrentOperation?.timedOut == true -> retValue.resultCode = BLECommOperationResult.RESULT_TIMEOUT + mCurrentOperation?.interrupted == true -> retValue.resultCode = BLECommOperationResult.RESULT_INTERRUPTED + else -> retValue.resultCode = BLECommOperationResult.RESULT_SUCCESS + } + } else return retValue.apply { resultCode = BLECommOperationResult.RESULT_NONE } } mCurrentOperation = null gattOperationSema.release()