From 6e6b1b8ab6cfc6bac43685327eabed97a3f456f6 Mon Sep 17 00:00:00 2001 From: andrekir Date: Mon, 29 Aug 2022 12:50:29 -0300 Subject: [PATCH] improve handling minAppVersion --- app/src/main/java/com/geeksville/mesh/MainActivity.kt | 2 +- .../java/com/geeksville/mesh/service/MeshService.kt | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/geeksville/mesh/MainActivity.kt b/app/src/main/java/com/geeksville/mesh/MainActivity.kt index ed14accb0..230d43702 100644 --- a/app/src/main/java/com/geeksville/mesh/MainActivity.kt +++ b/app/src/main/java/com/geeksville/mesh/MainActivity.kt @@ -658,7 +658,7 @@ class MainActivity : BaseActivity(), Logging, if (!isUpdating) { val curVer = DeviceVersion(info.firmwareVersion ?: "0.0.0") - if (curVer < MeshService.minFirmwareVersion) + if (curVer < MeshService.minDeviceVersion) showAlert(R.string.firmware_too_old, R.string.firmware_old) else { // If our app is too old/new, we probably don't understand the new DeviceConfig messages, so we don't read them until here diff --git a/app/src/main/java/com/geeksville/mesh/service/MeshService.kt b/app/src/main/java/com/geeksville/mesh/service/MeshService.kt index 67ce6ac48..07e88e99e 100644 --- a/app/src/main/java/com/geeksville/mesh/service/MeshService.kt +++ b/app/src/main/java/com/geeksville/mesh/service/MeshService.kt @@ -110,7 +110,7 @@ class MeshService : Service(), Logging { /** The minimmum firmware version we know how to talk to. We'll still be able to talk to 1.0 firmwares but only well enough to ask them to firmware update */ - val minFirmwareVersion = DeviceVersion("1.3.0") + val minDeviceVersion = DeviceVersion("1.3.0") } enum class ConnectionState { @@ -374,6 +374,8 @@ class MeshService : Service(), Logging { /// val deviceVersion get() = DeviceVersion(myNodeInfo?.firmwareVersion ?: "") + val appVersion get() = BuildConfig.VERSION_CODE + val minAppVersion get() = myNodeInfo?.minAppVersion ?: 0 /// Map a nodenum to a node, or throw an exception if not found private fun toNodeInfo(n: Int) = nodeDBbyNodeNum[n] ?: throw NodeNumNotFoundException( @@ -1341,8 +1343,8 @@ class MeshService : Service(), Logging { sendAnalytics() - if (deviceVersion < minFirmwareVersion) { - info("Device firmware is too old, faking config so firmware update can occur") + if (deviceVersion < minDeviceVersion || appVersion < minAppVersion) { + info("Device firmware or app is too old, faking config so firmware update can occur") clearLocalConfig() onHasSettings() } else requestChannel(0) // Now start reading channels @@ -1443,7 +1445,7 @@ class MeshService : Service(), Logging { /** Send our current radio config to the device */ private fun sendDeviceConfig(c: ConfigProtos.Config) { - if (deviceVersion < minFirmwareVersion) return + if (deviceVersion < minDeviceVersion) return debug("Setting new radio config!") sendToRadio(newMeshPacketTo(myNodeNum).buildAdminPacket { setConfig = c