mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
fix: address backfill issue on tcp connections; add logging (#3676)
Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com> Co-authored-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This commit is contained in:
parent
2a081f3c1f
commit
7369a9bf5d
3 changed files with 332 additions and 21 deletions
|
|
@ -21,6 +21,7 @@ import android.content.SharedPreferences
|
|||
import androidx.core.content.edit
|
||||
import org.meshtastic.core.prefs.NullableStringPrefDelegate
|
||||
import org.meshtastic.core.prefs.di.MeshSharedPreferences
|
||||
import java.util.Locale
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
|
|
@ -30,6 +31,10 @@ interface MeshPrefs {
|
|||
fun shouldProvideNodeLocation(nodeNum: Int?): Boolean
|
||||
|
||||
fun setShouldProvideNodeLocation(nodeNum: Int?, value: Boolean)
|
||||
|
||||
fun getStoreForwardLastRequest(address: String?): Int
|
||||
|
||||
fun setStoreForwardLastRequest(address: String?, value: Int)
|
||||
}
|
||||
|
||||
@Singleton
|
||||
|
|
@ -43,7 +48,30 @@ class MeshPrefsImpl @Inject constructor(@MeshSharedPreferences private val prefs
|
|||
prefs.edit { putBoolean(provideLocationKey(nodeNum), value) }
|
||||
}
|
||||
|
||||
override fun getStoreForwardLastRequest(address: String?): Int = prefs.getInt(storeForwardKey(address), 0)
|
||||
|
||||
override fun setStoreForwardLastRequest(address: String?, value: Int) {
|
||||
prefs.edit {
|
||||
if (value <= 0) {
|
||||
remove(storeForwardKey(address))
|
||||
} else {
|
||||
putInt(storeForwardKey(address), value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun provideLocationKey(nodeNum: Int?) = "provide-location-$nodeNum"
|
||||
|
||||
private fun storeForwardKey(address: String?): String = "store-forward-last-request-${normalizeAddress(address)}"
|
||||
|
||||
private fun normalizeAddress(address: String?): String {
|
||||
val raw = address?.trim()?.takeIf { it.isNotEmpty() }
|
||||
return when {
|
||||
raw == null -> "DEFAULT"
|
||||
raw.equals(NO_DEVICE_SELECTED, ignoreCase = true) -> "DEFAULT"
|
||||
else -> raw.uppercase(Locale.US).replace(":", "")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private const val NO_DEVICE_SELECTED = "n"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue