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)
val EapAkaExchanger = EapAkaExchanger(aapsLogger, msgIO, ltk)
val sessionKeys = EapAkaExchanger.negotiateSessionKeys()
val eapAkaExchanger = EapAkaExchanger(aapsLogger, msgIO, ltk)
val sessionKeys = eapAkaExchanger.negotiateSessionKeys()
aapsLogger.info(LTag.PUMPCOMM, "CK: ${sessionKeys.ck.toHex()}")
aapsLogger.info(LTag.PUMPCOMM, "noncePrefix: ${sessionKeys.noncePrefix.toHex()}")
aapsLogger.info(LTag.PUMPCOMM, "SQN: ${sessionKeys.sqn.toHex()}")

View file

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

View file

@ -81,7 +81,16 @@ class BleIO(
* Called before sending a new message.
* 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.

View file

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

View file

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