try to notice when user wants to go back to default settings

pull/262/head
Kevin Hester 2021-03-19 17:09:35 +08:00
rodzic a18343e30c
commit c405cdc200
3 zmienionych plików z 8 dodań i 19 usunięć

Wyświetl plik

@ -19,19 +19,15 @@ data class Channel(
val settings: ChannelProtos.ChannelSettings = ChannelProtos.ChannelSettings.getDefaultInstance()
) {
companion object {
// Note: this string _SHOULD NOT BE LOCALIZED_ because it directly hashes to values used on the device for the default channel name.
// FIXME - make this work with new channel name system
const val defaultChannelName = "Default"
// These bytes must match the well known and not secret bytes used the default channel AES128 key device code
val channelDefaultKey = byteArrayOfInts(
0xd4, 0xf1, 0xbb, 0x3a, 0x20, 0x29, 0x07, 0x59,
0xf0, 0xbc, 0xff, 0xab, 0xcf, 0x4e, 0x69, 0xbf
)
// Placeholder when emulating
val emulated = Channel(
ChannelProtos.ChannelSettings.newBuilder().setName(defaultChannelName)
// TH=he unsecured channel that devices ship with
val defaultChannel = Channel(
ChannelProtos.ChannelSettings.newBuilder()
.setModemConfig(ChannelProtos.ChannelSettings.ModemConfig.Bw125Cr45Sf128).build()
)
}

Wyświetl plik

@ -16,11 +16,6 @@ data class ChannelSet(
) {
companion object {
// Placeholder when emulating
val emulated = ChannelSet(
AppOnlyProtos.ChannelSet.newBuilder().addSettings(Channel.emulated.settings).build()
)
const val prefix = "https://www.meshtastic.org/d/#"
private const val base64Flags = Base64.URL_SAFE + Base64.NO_WRAP + Base64.NO_PADDING

Wyświetl plik

@ -169,12 +169,12 @@ class ChannelFragment : ScreenFragment("Channel"), Logging {
.setPositiveButton(getString(R.string.accept)) { _, _ ->
// Generate a new channel with only the changes the user can change in the GUI
model.channels.value?.primaryChannel?.let { oldPrimary ->
val newSettings = oldPrimary.settings.toBuilder()
var newSettings = oldPrimary.settings.toBuilder()
newSettings.name = binding.channelNameEdit.text.toString().trim()
// Generate a new AES256 key (for any channel not named Default)
// Generate a new AES256 key unleess the user is trying to go back to stock
if (!newSettings.name.equals(
Channel.defaultChannelName,
Channel.defaultChannel.name,
ignoreCase = true
)
) {
@ -184,10 +184,8 @@ class ChannelFragment : ScreenFragment("Channel"), Logging {
random.nextBytes(bytes)
newSettings.psk = ByteString.copyFrom(bytes)
} else {
debug("ASSIGNING NEW default AES128 KEY")
newSettings.name =
Channel.defaultChannelName // Fix any case errors
newSettings.psk = ByteString.copyFrom(Channel.channelDefaultKey)
debug("Switching back to default channel")
newSettings = Channel.defaultChannel.settings.toBuilder()
}
val selectedChannelOptionString =