dash ble: fix detekt issues

This commit is contained in:
Andrei Vereha 2021-03-03 14:10:33 +01:00
parent c9beb21404
commit 154e74fc22
5 changed files with 25 additions and 16 deletions

View file

@ -134,8 +134,8 @@ class OmnipodDashBleManagerImpl @Inject constructor(
// emitter.onNext(PodEvent.EstablishingSession) // emitter.onNext(PodEvent.EstablishingSession)
val EapAkaExchanger = EapAkaExchanger(aapsLogger, msgIO, ltk) val eapAkaExchanger = EapAkaExchanger(aapsLogger, msgIO, ltk)
val sessionKeys = EapAkaExchanger.negotiateSessionKeys() val sessionKeys = eapAkaExchanger.negotiateSessionKeys()
aapsLogger.info(LTag.PUMPCOMM, "CK: ${sessionKeys.ck.toHex()}") aapsLogger.info(LTag.PUMPCOMM, "CK: ${sessionKeys.ck.toHex()}")
aapsLogger.info(LTag.PUMPCOMM, "noncePrefix: ${sessionKeys.noncePrefix.toHex()}") aapsLogger.info(LTag.PUMPCOMM, "noncePrefix: ${sessionKeys.noncePrefix.toHex()}")
aapsLogger.info(LTag.PUMPCOMM, "SQN: ${sessionKeys.sqn.toHex()}") aapsLogger.info(LTag.PUMPCOMM, "SQN: ${sessionKeys.sqn.toHex()}")

View file

@ -45,18 +45,18 @@ class BleCommCallbacks(
} }
@Throws(InterruptedException::class) @Throws(InterruptedException::class)
fun waitForConnection(timeout_ms: Int) { fun waitForConnection(timeoutMs: Int) {
connected.await(timeout_ms.toLong(), TimeUnit.MILLISECONDS) connected.await(timeoutMs.toLong(), TimeUnit.MILLISECONDS)
} }
@Throws(InterruptedException::class) @Throws(InterruptedException::class)
fun waitForServiceDiscovery(timeout_ms: Int) { fun waitForServiceDiscovery(timeoutMs: Int) {
serviceDiscoveryComplete.await(timeout_ms.toLong(), TimeUnit.MILLISECONDS) serviceDiscoveryComplete.await(timeoutMs.toLong(), TimeUnit.MILLISECONDS)
} }
@Throws(InterruptedException::class, TimeoutException::class, CouldNotConfirmWriteException::class) @Throws(InterruptedException::class, TimeoutException::class, CouldNotConfirmWriteException::class)
fun confirmWrite(expectedPayload: ByteArray, timeout_ms: Int) { fun confirmWrite(expectedPayload: ByteArray, timeoutMs: Int) {
val received: CharacteristicWriteConfirmation = writeQueue.poll(timeout_ms.toLong(), TimeUnit.MILLISECONDS) val received: CharacteristicWriteConfirmation = writeQueue.poll(timeoutMs.toLong(), TimeUnit.MILLISECONDS)
?: throw TimeoutException() ?: throw TimeoutException()
when (received) { when (received) {
@ -116,9 +116,9 @@ class BleCommCallbacks(
} }
@Throws(InterruptedException::class, CouldNotConfirmDescriptorWriteException::class) @Throws(InterruptedException::class, CouldNotConfirmDescriptorWriteException::class)
fun confirmWriteDescriptor(descriptorUUID: String, timeout_ms: Int) { fun confirmWriteDescriptor(descriptorUUID: String, timeoutMs: Int) {
val confirmed: DescriptorWriteConfirmation = descriptorWriteQueue.poll( val confirmed: DescriptorWriteConfirmation = descriptorWriteQueue.poll(
timeout_ms.toLong(), timeoutMs.toLong(),
TimeUnit.MILLISECONDS TimeUnit.MILLISECONDS
) )
?: throw TimeoutException() ?: throw TimeoutException()

View file

@ -81,7 +81,16 @@ class BleIO(
* Called before sending a new message. * Called before sending a new message.
* The incoming queues should be empty, so we log when they are not. * The incoming queues should be empty, so we log when they are not.
*/ */
fun flushIncomingQueues() {} fun flushIncomingQueues() {
for (chr in CharacteristicType.values()) {
do {
val found = incomingPackets[chr]?.poll()
found?.let {
aapsLogger.warn(LTag.PUMPBTCOMM, "BleIO: CMD queue not empty, flushing: {${found.toHex()}")
}
} while (found != null)
}
}
/** /**
* Enable intentions on the characteristics. * Enable intentions on the characteristics.

View file

@ -70,8 +70,8 @@ data class MessagePacket(
companion object { companion object {
private val MAGIC_PATTERN = "TW" // all messages start with this string private const val MAGIC_PATTERN = "TW" // all messages start with this string
private val HEADER_SIZE = 16 private const val HEADER_SIZE = 16
fun parse(payload: ByteArray): MessagePacket { fun parse(payload: ByteArray): MessagePacket {
if (payload.size < HEADER_SIZE) { if (payload.size < HEADER_SIZE) {

View file

@ -12,7 +12,7 @@ class Milenage(
private val aapsLogger: AAPSLogger, private val aapsLogger: AAPSLogger,
private val k: ByteArray, private val k: ByteArray,
val sqn: ByteArray, val sqn: ByteArray,
val _rand: ByteArray? = null private val randParam: ByteArray? = null
) { ) {
init { init {
@ -27,10 +27,10 @@ class Milenage(
cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec) cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec)
} }
val rand = _rand ?: ByteArray(KEY_SIZE) val rand = randParam ?: ByteArray(KEY_SIZE)
init { init {
if (_rand == null) { if (randParam == null) {
val random = SecureRandom() val random = SecureRandom()
random.nextBytes(rand) random.nextBytes(rand)
} }