kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
Merge pull request #90 from geeksville/dev
Don't bounce the interface if the UI changes to a device we are alrea…pull/91/head^2
commit
acd2090e6d
|
@ -62,7 +62,7 @@ interface IMeshService {
|
|||
/// 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);
|
||||
boolean setDeviceAddress(String deviceAddr);
|
||||
|
||||
/// Get basic device hardware info about our connected radio. Will never return NULL. Will throw
|
||||
/// RemoteException if no my node info is available
|
||||
|
|
|
@ -14,5 +14,5 @@ interface IRadioInterfaceService {
|
|||
/// 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);
|
||||
boolean setDeviceAddress(String deviceAddr);
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue