mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-05 06:33:52 -04:00
Don't bounce the interface if the UI changes to a device we are already using
This commit is contained in:
@@ -608,6 +608,7 @@ class MeshService : Service(), Logging {
|
||||
* discard entire node db & message state - used when downloading a new db from the device
|
||||
*/
|
||||
private fun discardNodeDB() {
|
||||
debug("Discarding NodeDB")
|
||||
myNodeInfo = null
|
||||
nodeDBbyNodeNum.clear()
|
||||
nodeDBbyID.clear()
|
||||
@@ -1508,8 +1509,12 @@ class MeshService : Service(), Logging {
|
||||
|
||||
override fun setDeviceAddress(deviceAddr: String?) = toRemoteExceptions {
|
||||
debug("Passing through device change to radio service: $deviceAddr")
|
||||
discardNodeDB()
|
||||
radio.service.setDeviceAddress(deviceAddr)
|
||||
|
||||
val res = radio.service.setDeviceAddress(deviceAddr)
|
||||
if (res) {
|
||||
discardNodeDB()
|
||||
}
|
||||
res
|
||||
}
|
||||
|
||||
// Note: bound methods don't get properly exception caught/logged, so do that with a wrapper
|
||||
|
||||
@@ -250,38 +250,49 @@ class RadioInterfaceService : Service(), Logging {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Change to a new device
|
||||
*
|
||||
* @return true if the device changed, false if no change
|
||||
*/
|
||||
@SuppressLint("NewApi")
|
||||
private fun setBondedDeviceAddress(address: String?) {
|
||||
// Record that this use has configured a radio
|
||||
GeeksvilleApplication.analytics.track(
|
||||
"mesh_bond"
|
||||
)
|
||||
private fun setBondedDeviceAddress(address: String?): Boolean {
|
||||
return if (getBondedDeviceAddress(this) == address && isConnected) {
|
||||
warn("Ignoring setBondedDevice $address, because we are already using that device")
|
||||
false
|
||||
} else {
|
||||
// Record that this use has configured a new radio
|
||||
GeeksvilleApplication.analytics.track(
|
||||
"mesh_bond"
|
||||
)
|
||||
|
||||
// Ignore any errors that happen while closing old device
|
||||
ignoreException {
|
||||
stopInterface()
|
||||
// Ignore any errors that happen while closing old device
|
||||
ignoreException {
|
||||
stopInterface()
|
||||
}
|
||||
|
||||
// The device address "n" can be used to mean none
|
||||
|
||||
debug("Setting bonded device to $address")
|
||||
|
||||
getPrefs(this).edit(commit = true) {
|
||||
this.remove(DEVADDR_KEY_OLD) // remove any old version of the key
|
||||
|
||||
if (address == null)
|
||||
this.remove(DEVADDR_KEY)
|
||||
else
|
||||
putString(DEVADDR_KEY, address)
|
||||
}
|
||||
|
||||
// Force the service to reconnect
|
||||
startInterface()
|
||||
true
|
||||
}
|
||||
|
||||
// The device address "n" can be used to mean none
|
||||
|
||||
debug("Setting bonded device to $address")
|
||||
|
||||
getPrefs(this).edit(commit = true) {
|
||||
this.remove(DEVADDR_KEY_OLD) // remove any old version of the key
|
||||
|
||||
if (address == null)
|
||||
this.remove(DEVADDR_KEY)
|
||||
else
|
||||
putString(DEVADDR_KEY, address)
|
||||
}
|
||||
|
||||
// Force the service to reconnect
|
||||
startInterface()
|
||||
}
|
||||
|
||||
private val binder = object : IRadioInterfaceService.Stub() {
|
||||
|
||||
override fun setDeviceAddress(deviceAddr: String?) = toRemoteExceptions {
|
||||
override fun setDeviceAddress(deviceAddr: String?): Boolean = toRemoteExceptions {
|
||||
setBondedDeviceAddress(deviceAddr)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user