ChannelSettings.defaultInstance is garbage, do not use it

1.2-legacy
Kevin Hester 2021-04-04 17:44:25 +08:00
rodzic a52e3db87b
commit 395bc59c9c
2 zmienionych plików z 6 dodań i 8 usunięć

Wyświetl plik

@ -7,9 +7,7 @@ import com.google.protobuf.ByteString
fun byteArrayOfInts(vararg ints: Int) = ByteArray(ints.size) { pos -> ints[pos].toByte() }
data class Channel(
val settings: ChannelProtos.ChannelSettings = ChannelProtos.ChannelSettings.getDefaultInstance()
) {
data class Channel(val settings: ChannelProtos.ChannelSettings) {
companion object {
// These bytes must match the well known and not secret bytes used the default channel AES128 key device code
val channelDefaultKey = byteArrayOfInts(
@ -22,7 +20,7 @@ data class Channel(
byteArrayOfInts(1) // a shortstring code to indicate we need our default PSK
// TH=he unsecured channel that devices ship with
val defaultChannel = Channel(
val default = Channel(
ChannelProtos.ChannelSettings.newBuilder()
.setModemConfig(ChannelProtos.ChannelSettings.ModemConfig.Bw125Cr48Sf4096)
.setPsk(ByteString.copyFrom(defaultPSK))

Wyświetl plik

@ -86,7 +86,7 @@ class ChannelFragment : ScreenFragment("Channel"), Logging {
// Only let buttons work if we are connected to the radio
binding.shareButton.isEnabled = connected
binding.resetButton.isEnabled = connected && Channel.defaultChannel != channel
binding.resetButton.isEnabled = connected && Channel.default != channel
binding.editableCheckbox.isChecked = false // start locked
if (channel != null) {
@ -197,7 +197,7 @@ class ChannelFragment : ScreenFragment("Channel"), Logging {
}
.setPositiveButton(R.string.apply) { _, _ ->
debug("Switching back to default channel")
installSettings(Channel.defaultChannel.settings)
installSettings(Channel.default.settings)
}
.show()
}
@ -226,7 +226,7 @@ class ChannelFragment : ScreenFragment("Channel"), Logging {
// Generate a new AES256 key unleess the user is trying to go back to stock
if (!newSettings.name.equals(
Channel.defaultChannel.name,
Channel.default.name,
ignoreCase = true
)
) {
@ -246,7 +246,7 @@ class ChannelFragment : ScreenFragment("Channel"), Logging {
newSettings.modemConfig = modemConfig
} else {
debug("Switching back to default channel")
newSettings = Channel.defaultChannel.settings.toBuilder()
newSettings = Channel.default.settings.toBuilder()
}
installSettings(newSettings.build())