From f55f40d624d9ac27c70b7297f541ce95d6154f55 Mon Sep 17 00:00:00 2001 From: geeksville Date: Mon, 24 Feb 2020 20:08:18 -0800 Subject: [PATCH] fix crashlytics autoreport: if we lose comms while sending gps pos, mark connection closed --- TODO.md | 4 +- .../geeksville/mesh/service/MeshService.kt | 56 ++++++++++--------- 2 files changed, 33 insertions(+), 27 deletions(-) diff --git a/TODO.md b/TODO.md index 1ea99a24e..fcb29cd9f 100644 --- a/TODO.md +++ b/TODO.md @@ -14,7 +14,6 @@ MVP features required for first public alpha * add screenshots and text to play store entry # Medium priority - Features for future builds * describe user experience: devices always point to each other and show distance, you can send texts between nodes @@ -61,7 +60,8 @@ Do this "Signal app compatible" release relatively soon after the alpha release Things for the betaish period. * let users save old channels -* make sw update work while node is connected to mesh (at least shutdown the other bluetooth services) +* make sw update work while node is connected to mesh - the problem is there are _two_ instances of SafeBluetooth at that moment and therefore we violate undocumented android mutex +rules at the BluetoothDevice level. Either make SafeBluetooth lock at the device level or (not as good) make SafeBluetooth a singleton. * Use LocationRequest.setSmallestDisplacement to save battery and decrease net activity * MeshService.reinitFromRadio can take 300 ms, run it in a worker thread instead * show user icons in chat 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 019be0cb9..d6402242e 100644 --- a/app/src/main/java/com/geeksville/mesh/service/MeshService.kt +++ b/app/src/main/java/com/geeksville/mesh/service/MeshService.kt @@ -109,35 +109,41 @@ class MeshService : Service(), Logging { private var lastSendMsec = 0L override fun onLocationResult(locationResult: LocationResult) { - super.onLocationResult(locationResult) - var l = locationResult.lastLocation + exceptionReporter { + super.onLocationResult(locationResult) + var l = locationResult.lastLocation - // Docs say lastLocation should always be !null if there are any locations, but that's not the case - if (l == null) { - // try to only look at the accurate locations - val locs = - locationResult.locations.filter { !it.hasAccuracy() || it.accuracy < 200 } - l = locs.lastOrNull() - } - if (l != null) { - info("got location $l") - if (l.hasAccuracy() && l.accuracy >= 200) // if more than 200 meters off we won't use it - warn("accuracy ${l.accuracy} is too poor to use") - else { - val now = System.currentTimeMillis() + // Docs say lastLocation should always be !null if there are any locations, but that's not the case + if (l == null) { + // try to only look at the accurate locations + val locs = + locationResult.locations.filter { !it.hasAccuracy() || it.accuracy < 200 } + l = locs.lastOrNull() + } + if (l != null) { + info("got location $l") + if (l.hasAccuracy() && l.accuracy >= 200) // if more than 200 meters off we won't use it + warn("accuracy ${l.accuracy} is too poor to use") + else { + val now = System.currentTimeMillis() - // we limit our sends onto the lora net to a max one once every FIXME - val sendLora = (now - lastSendMsec >= 30 * 1000) - if (sendLora) - lastSendMsec = now - sendPosition( - l.latitude, l.longitude, l.altitude.toInt(), - destNum = if (sendLora) NODENUM_BROADCAST else myNodeNum, - wantResponse = sendLora - ) + // we limit our sends onto the lora net to a max one once every FIXME + val sendLora = (now - lastSendMsec >= 30 * 1000) + if (sendLora) + lastSendMsec = now + try { + sendPosition( + l.latitude, l.longitude, l.altitude.toInt(), + destNum = if (sendLora) NODENUM_BROADCAST else myNodeNum, + wantResponse = sendLora + ) + } catch (ex: RadioNotConnectedException) { + warn("Lost connection to radio, stopping location requests") + onConnectionChanged(false) + } + } } } - } }