mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-03-29 19:23:30 -04:00
new cleaner approach of not whacking services seems to aprox work
This commit is contained in:
@@ -58,6 +58,7 @@ interface IMeshService {
|
||||
String connectionState();
|
||||
|
||||
/// If a macaddress we will try to talk to our device, if null we will be idle.
|
||||
/// Any current connection will be dropped (even if the device address is the same) before reconnecting.
|
||||
/// Users should not call this directly, only used internally by the MeshUtil activity
|
||||
void setDeviceAddress(String deviceAddr);
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ interface IRadioInterfaceService {
|
||||
void writeOwner(in byte [] owner);
|
||||
|
||||
/// If a macaddress we will try to talk to our device, if null we will be idle.
|
||||
/// Any current connection will be dropped (even if the device address is the same) before reconnecting.
|
||||
/// Users should not call this directly, called only by MeshService
|
||||
void setDeviceAddress(String deviceAddr);
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ class MainActivity : AppCompatActivity(), Logging,
|
||||
bluetoothManager.adapter
|
||||
}
|
||||
|
||||
private val model: UIViewModel by viewModels()
|
||||
val model: UIViewModel by viewModels()
|
||||
|
||||
data class TabInfo(val text: String, val icon: Int, val content: Fragment)
|
||||
|
||||
@@ -176,7 +176,7 @@ class MainActivity : AppCompatActivity(), Logging,
|
||||
Manifest.permission.BLUETOOTH,
|
||||
Manifest.permission.BLUETOOTH_ADMIN,
|
||||
Manifest.permission.WAKE_LOCK
|
||||
|
||||
|
||||
// We only need this for logging to capture files for the simulator - turn off for most users
|
||||
// Manifest.permission.WRITE_EXTERNAL_STORAGE
|
||||
)
|
||||
|
||||
@@ -479,14 +479,14 @@ class MeshService : Service(), Logging {
|
||||
private fun loadSettings() {
|
||||
try {
|
||||
getPrefs().getString("json", null)?.let { asString ->
|
||||
discardNodeDB() // Get rid of any old state
|
||||
|
||||
val json = Json(JsonConfiguration.Default)
|
||||
val settings = json.parse(SavedSettings.serializer(), asString)
|
||||
myNodeInfo = settings.myInfo
|
||||
|
||||
// put our node array into our two different map representations
|
||||
nodeDBbyNodeNum.clear()
|
||||
nodeDBbyNodeNum.putAll(settings.nodeDB.map { Pair(it.num, it) })
|
||||
nodeDBbyID.clear()
|
||||
nodeDBbyID.putAll(settings.nodeDB.mapNotNull {
|
||||
it.user?.let { user -> // ignore records that don't have a valid user
|
||||
Pair(
|
||||
@@ -497,7 +497,6 @@ class MeshService : Service(), Logging {
|
||||
})
|
||||
// Note: we do not haveNodeDB = true because that means we've got a valid db from a real device (rather than this possibly stale hint)
|
||||
|
||||
recentDataPackets.clear()
|
||||
recentDataPackets.addAll(settings.messages)
|
||||
}
|
||||
} catch (ex: Exception) {
|
||||
@@ -505,6 +504,17 @@ class MeshService : Service(), Logging {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* discard entire node db & message state - used when changing radio channels
|
||||
*/
|
||||
private fun discardNodeDB() {
|
||||
myNodeInfo = null
|
||||
nodeDBbyNodeNum.clear()
|
||||
nodeDBbyID.clear()
|
||||
recentDataPackets.clear()
|
||||
haveNodeDB = false
|
||||
}
|
||||
|
||||
var myNodeInfo: MyNodeInfo? = null
|
||||
|
||||
private var radioConfig: MeshProtos.RadioConfig? = null
|
||||
@@ -1067,6 +1077,7 @@ class MeshService : Service(), Logging {
|
||||
|
||||
override fun setDeviceAddress(deviceAddr: String?) {
|
||||
debug("Passing through device change to radio service: $deviceAddr")
|
||||
discardNodeDB()
|
||||
connectedRadio.setDeviceAddress(deviceAddr)
|
||||
}
|
||||
|
||||
|
||||
@@ -36,9 +36,9 @@ object SLogging : Logging {}
|
||||
|
||||
/// Change to a new macaddr selection, updating GUI and radio
|
||||
fun changeDeviceSelection(context: MainActivity, newAddr: String?) {
|
||||
model.meshService?.let { service ->
|
||||
service.setDeviceAddress(context, newAddr)
|
||||
|
||||
// FIXME, this is a kinda yucky way to find the service
|
||||
context.model.meshService?.let { service ->
|
||||
service.setDeviceAddress(newAddr)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -317,8 +317,6 @@ class SettingsFragment : ScreenFragment("Settings"), Logging {
|
||||
reportError("Clicked Report A Bug")
|
||||
}
|
||||
.show()
|
||||
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user