format: klintFormat

This commit is contained in:
Andrei Vereha 2021-03-02 22:22:03 +01:00
parent ada3560f49
commit c9beb21404
8 changed files with 25 additions and 29 deletions

View file

@ -29,7 +29,7 @@ class PayloadJoiner(private val firstPacket: ByteArray) {
firstPacket.size < FirstBlePacket.HEADER_SIZE_WITHOUT_MIDDLE_PACKETS ->
throw IncorrectPacketException(0, firstPacket)
fullFragments == 0 -> {
fullFragments == 0 -> {
crc = ByteBuffer.wrap(firstPacket.copyOfRange(2, 6)).int.toUnsignedLong()
val rest = firstPacket[6]
val end = min(rest + FirstBlePacket.HEADER_SIZE_WITHOUT_MIDDLE_PACKETS, BlePacket.MAX_SIZE)
@ -41,10 +41,10 @@ class PayloadJoiner(private val firstPacket: ByteArray) {
}
// With middle packets
firstPacket.size < BlePacket.MAX_SIZE ->
firstPacket.size < BlePacket.MAX_SIZE ->
throw IncorrectPacketException(0, firstPacket)
else -> {
else -> {
fragments.add(
firstPacket.copyOfRange(
FirstBlePacket.HEADER_SIZE_WITH_MIDDLE_PACKETS,
@ -65,7 +65,7 @@ class PayloadJoiner(private val firstPacket: ByteArray) {
}
expectedIndex++
when {
idx < fullFragments -> { // this is a middle fragment
idx < fullFragments -> { // this is a middle fragment
if (packet.size < BlePacket.MAX_SIZE) {
throw IncorrectPacketException(idx.toByte(), packet)
}
@ -86,7 +86,7 @@ class PayloadJoiner(private val firstPacket: ByteArray) {
fragments.add(packet.copyOfRange(LastBlePacket.HEADER_SIZE, packet.size))
}
idx > fullFragments -> { // this is the extra fragment
idx > fullFragments -> { // this is the extra fragment
val size = packet[1].toInt()
if (packet.size < LastOptionalPlusOneBlePacket.HEADER_SIZE + size) {
throw IncorrectPacketException(idx.toByte(), packet)

View file

@ -18,15 +18,15 @@ class StringLengthPrefixEncoding {
var remaining = payload
for ((index, key) in keys.withIndex()) {
when {
remaining.size < key.length ->
remaining.size < key.length ->
throw MessageIOException("Payload too short: ${payload.toHex()} for key: $key")
!(remaining.copyOfRange(0, key.length).decodeToString() == key) ->
throw MessageIOException("Key not found: $key in ${payload.toHex()}")
// last key can be empty, no length
index == keys.size - 1 && remaining.size == key.length ->
index == keys.size - 1 && remaining.size == key.length ->
return ret
remaining.size < key.length + LENGTH_BYTES ->
remaining.size < key.length + LENGTH_BYTES ->
throw MessageIOException("Length not found: for $key in ${payload.toHex()}")
}
remaining = remaining.copyOfRange(key.length, remaining.size)

View file

@ -21,7 +21,8 @@ class BleDiscoveredDevice(val scanResult: ScanResult, private val scanRecord: Sc
throw DiscoveredInvalidPodException(
"The first exposed service UUID should be 4024, got " + extractUUID16(
serviceUuids[0]
), serviceUuids
),
serviceUuids
)
}
// TODO understand what is serviceUUIDs[1]. 0x2470. Alarms?

View file

@ -44,7 +44,7 @@ sealed class EapAkaAttribute {
ret.add(EapAkaAttributeRes.parse(tail.copyOfRange(2, size)))
EapAkaAttributeType.AT_CUSTOM_IV ->
ret.add(EapAkaAttributeCustomIV.parse(tail.copyOfRange(2, size)))
else ->
else ->
throw MessageIOException("Could not parse EAP attributes: ${payload.toHex()}. Expecting only AT_RES or CUSTOM_IV attribute types from the POD")
}
tail = tail.copyOfRange(size, tail.size)
@ -94,7 +94,6 @@ data class EapAkaAttributeRes(val payload: ByteArray) : EapAkaAttribute() {
override fun toByteArray(): ByteArray {
return byteArrayOf(EapAkaAttributeType.AT_RES.type, SIZE, 0, PAYLOAD_SIZE_BITS) + payload
}
companion object {

View file

@ -73,12 +73,11 @@ class EapAkaExchanger(private val aapsLogger: AAPSLogger, private val msgIO: Mes
}
private fun processChallengeResponse(challengeResponse: MessagePacket) {
//TODO verify that identifier matches identifer from the Challenge
// TODO verify that identifier matches identifer from the Challenge
val eapMsg = EapMessage.parse(aapsLogger, challengeResponse.payload)
if (eapMsg.attributes.size != 2) {
aapsLogger.debug(LTag.PUMPBTCOMM, "EAP-AKA: got RES message: $eapMsg")
throw SessionEstablishmentException("Expecting two attributes, got: ${eapMsg.attributes.size}")
}
for (attr in eapMsg.attributes) {
when (attr) {
@ -88,11 +87,10 @@ class EapAkaExchanger(private val aapsLogger: AAPSLogger, private val msgIO: Mes
}
is EapAkaAttributeCustomIV ->
nodeIV = attr.payload.copyOfRange(0, IV_SIZE)
else ->
throw SessionEstablishmentException("Unknown attribute received: ${attr}")
else ->
throw SessionEstablishmentException("Unknown attribute received: $attr")
}
}
}
private fun eapSuccess(): MessagePacket {
@ -119,4 +117,3 @@ class EapAkaExchanger(private val aapsLogger: AAPSLogger, private val msgIO: Mes
private const val IV_SIZE = 4
}
}

View file

@ -471,17 +471,17 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
private fun updateRefreshStatusButton() {
buttonBinding.buttonRefreshStatus.isEnabled =
podStateManager.isUniqueIdSet && podStateManager.activationProgress.isAtLeast(
ActivationProgress.PHASE_1_COMPLETED
) &&
isQueueEmpty()
ActivationProgress.PHASE_1_COMPLETED
) &&
isQueueEmpty()
}
private fun updateResumeDeliveryButton() {
if (podStateManager.isPodRunning && (
podStateManager.isSuspended || commandQueue.isCustomCommandInQueue(
podStateManager.isSuspended || commandQueue.isCustomCommandInQueue(
CommandResumeDelivery::class.java
)
)
)
) {
buttonBinding.buttonResumeDelivery.visibility = View.VISIBLE
buttonBinding.buttonResumeDelivery.isEnabled = isQueueEmpty()
@ -492,10 +492,10 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
private fun updateSilenceAlertsButton() {
if (isAutomaticallySilenceAlertsEnabled() && podStateManager.isPodRunning && (
podStateManager.activeAlerts!!.size > 0 || commandQueue.isCustomCommandInQueue(
podStateManager.activeAlerts!!.size > 0 || commandQueue.isCustomCommandInQueue(
CommandAcknowledgeAlerts::class.java
)
)
)
) {
buttonBinding.buttonSilenceAlerts.visibility = View.VISIBLE
buttonBinding.buttonSilenceAlerts.isEnabled = isQueueEmpty()
@ -507,10 +507,10 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
private fun updateSuspendDeliveryButton() {
// If the Pod is currently suspended, we show the Resume delivery button instead.
if (isSuspendDeliveryButtonEnabled() && podStateManager.isPodRunning && (
!podStateManager.isSuspended || commandQueue.isCustomCommandInQueue(
!podStateManager.isSuspended || commandQueue.isCustomCommandInQueue(
CommandSuspendDelivery::class.java
)
)
)
) {
buttonBinding.buttonSuspendDelivery.visibility = View.VISIBLE
buttonBinding.buttonSuspendDelivery.isEnabled =

View file

@ -47,5 +47,4 @@ class MilenageTest {
Assert.assertEquals(m.ck.toHex(), "8dd4b3ceb849a01766e37f9d86045c39")
Assert.assertEquals(m.autn.toHex(), "0e0264d056fcb9b9752227365a090955")
}
}