From 0b957a7b1c4a3fec6270c4d8441696193e8a5190 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Sun, 28 Mar 2021 10:42:19 +0800 Subject: [PATCH] fix autobug --- .../java/com/geeksville/mesh/service/MeshService.kt | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/geeksville/mesh/service/MeshService.kt b/app/src/main/java/com/geeksville/mesh/service/MeshService.kt index 54175320e..426da258d 100644 --- a/app/src/main/java/com/geeksville/mesh/service/MeshService.kt +++ b/app/src/main/java/com/geeksville/mesh/service/MeshService.kt @@ -38,6 +38,7 @@ import kotlinx.coroutines.* import kotlinx.serialization.json.Json import java.util.* import kotlin.math.absoluteValue +import kotlin.math.max /** * Handles all the communication with android apps. Also keeps an internal model @@ -466,7 +467,7 @@ class MeshService : Service(), Logging { private var radioConfig: RadioConfigProtos.RadioConfig? = null - private var channels = fixupChannelList(listOf()).toTypedArray() + private var channels = fixupChannelList(listOf()) /// True after we've done our initial node db init @Volatile @@ -1384,20 +1385,21 @@ class MeshService : Service(), Logging { radioConfig = null // prefill the channel array with null channels - channels = fixupChannelList(listOf()).toTypedArray() + channels = fixupChannelList(listOf()) } /// scan the channel list and make sure it has one PRIMARY channel and is maxChannels long - private fun fixupChannelList(lIn: List): List { + private fun fixupChannelList(lIn: List): Array { + // When updating old firmware, we will briefly be told that there is zero channels val maxChannels = - myNodeInfo?.maxChannels ?: 8 // If we don't have my node info, assume 8 channels + max(myNodeInfo?.maxChannels ?: 8, 1) // If we don't have my node info, assume 8 channels var l = lIn while (l.size < maxChannels) { val b = ChannelProtos.Channel.newBuilder() b.index = l.size l += b.build() } - return l + return l.toTypedArray() }