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
Kevin Hester 2020-07-04 17:03:44 -07:00 zatwierdzone przez GitHub
commit acd2090e6d
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
4 zmienionych plików z 45 dodań i 29 usunięć

Wyświetl plik

@ -62,7 +62,7 @@ interface IMeshService {
/// If a macaddress we will try to talk to our device, if null we will be idle. /// 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. /// 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 /// 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 /// Get basic device hardware info about our connected radio. Will never return NULL. Will throw
/// RemoteException if no my node info is available /// RemoteException if no my node info is available

Wyświetl plik

@ -14,5 +14,5 @@ interface IRadioInterfaceService {
/// If a macaddress we will try to talk to our device, if null we will be idle. /// 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. /// 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 /// Users should not call this directly, called only by MeshService
void setDeviceAddress(String deviceAddr); boolean setDeviceAddress(String deviceAddr);
} }

Wyświetl plik

@ -608,6 +608,7 @@ class MeshService : Service(), Logging {
* discard entire node db & message state - used when downloading a new db from the device * discard entire node db & message state - used when downloading a new db from the device
*/ */
private fun discardNodeDB() { private fun discardNodeDB() {
debug("Discarding NodeDB")
myNodeInfo = null myNodeInfo = null
nodeDBbyNodeNum.clear() nodeDBbyNodeNum.clear()
nodeDBbyID.clear() nodeDBbyID.clear()
@ -1508,8 +1509,12 @@ class MeshService : Service(), Logging {
override fun setDeviceAddress(deviceAddr: String?) = toRemoteExceptions { override fun setDeviceAddress(deviceAddr: String?) = toRemoteExceptions {
debug("Passing through device change to radio service: $deviceAddr") 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 // Note: bound methods don't get properly exception caught/logged, so do that with a wrapper

Wyświetl plik

@ -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") @SuppressLint("NewApi")
private fun setBondedDeviceAddress(address: String?) { private fun setBondedDeviceAddress(address: String?): Boolean {
// Record that this use has configured a radio return if (getBondedDeviceAddress(this) == address && isConnected) {
GeeksvilleApplication.analytics.track( warn("Ignoring setBondedDevice $address, because we are already using that device")
"mesh_bond" 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 // Ignore any errors that happen while closing old device
ignoreException { ignoreException {
stopInterface() 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() { private val binder = object : IRadioInterfaceService.Stub() {
override fun setDeviceAddress(deviceAddr: String?) = toRemoteExceptions { override fun setDeviceAddress(deviceAddr: String?): Boolean = toRemoteExceptions {
setBondedDeviceAddress(deviceAddr) setBondedDeviceAddress(deviceAddr)
} }