Skip to content

Colota - Android GPS Location tracker

fix(service): keep good fixes after a coarse reference fix (#947)

Max Dietrichaa17edab8b28
diff --git a/apps/mobile/android/app/src/main/java/com/colota/service/LocationForegroundService.kt b/apps/mobile/android/app/src/main/java/com/colota/service/LocationForegroundService.kt
index cfdb5cdc..c782a3d0 100644
--- a/apps/mobile/android/app/src/main/java/com/colota/service/LocationForegroundService.kt
+++ b/apps/mobile/android/app/src/main/java/com/colota/service/LocationForegroundService.kt
@@ -148,6 +148,8 @@ class LocationForegroundService : Service() {
private const val POSITION_JUMP_FILTER_MIN_IMPLIED_MPS = 20f
/** Implied speed must exceed chip-Doppler by this factor to count as a jump. */
private const val POSITION_JUMP_FILTER_RATIO = 5f
+ /** A reference coarser than this, like a cell-based probe fix after a Wi-Fi drop, cannot prove a jump. */
+ private const val POSITION_JUMP_FILTER_MAX_REFERENCE_ACCURACY_M = 200f
/** Gaps above this bypass the filter so post-resume fixes aren't dropped. */
private const val POSITION_JUMP_FILTER_WINDOW_MS = 300_000L
@@ -943,7 +945,7 @@ class LocationForegroundService : Service() {
// Position-jump filter: chip-reported and implied speed are independent signals; large disagreement means the chip hallucinated position.
// Kept active while paused too: a real departure passes it anyway (implied speed agrees with
// chip, or is below the floor), but one hallucinated jump must not fake a departure.
- if (prev != null && location.hasSpeed()) {
+ if (prev != null && location.hasSpeed() && prev.accuracy <= POSITION_JUMP_FILTER_MAX_REFERENCE_ACCURACY_M) {
val dt = location.time - prev.time
if (dt in 1000..POSITION_JUMP_FILTER_WINDOW_MS) {
val distance = prev.distanceTo(location)
diff --git a/apps/mobile/android/app/src/test/java/com/Colota/service/LocationForegroundServiceTest.kt b/apps/mobile/android/app/src/test/java/com/Colota/service/LocationForegroundServiceTest.kt
index cce01f07..1c5dae65 100644
--- a/apps/mobile/android/app/src/test/java/com/Colota/service/LocationForegroundServiceTest.kt
+++ b/apps/mobile/android/app/src/test/java/com/Colota/service/LocationForegroundServiceTest.kt
@@ -380,6 +380,21 @@ class LocationForegroundServiceTest {
assertEquals(prev, getField<Location?>("lastKnownLocation"))
}
+ /** After a Wi-Fi drop the probe can land kilometres off; the good fixes after it are not jumps. */
+ @Test
+ fun `position-jump filter keeps a good fix after a coarse reference`() = testScope.runTest {
+ val now = System.currentTimeMillis()
+ val coarse = mockLocation(accuracy = 18_673f, time = now - 10_000, distanceTo = 1_100f)
+ setField("lastKnownLocation", coarse)
+ every { dbHelper.saveLocation(any(), any(), any(), any(), any(), any(), any(), any(), any(), any()) } returns 1L
+
+ val good = mockLocation(accuracy = 8f, hasSpeed = true, speed = 0f, time = now)
+ invokeHandleLocationUpdate(good)
+
+ verify(exactly = 1) { dbHelper.saveLocation(any(), any(), any(), any(), any(), any(), any(), any(), any(), any()) }
+ assertEquals(good, getField<Location?>("lastKnownLocation"))
+ }
+
@Test
fun `position-jump filter keeps flight cruise where chip and implied agree`() = testScope.runTest {
// ~250 m/s (900 km/h) cruise. Both measurements agree -> ratio check passes.
diff --git a/fastlane/metadata/android/en-US/changelogs/52.txt b/fastlane/metadata/android/en-US/changelogs/52.txt
index 654abfe5..738828db 100644
--- a/fastlane/metadata/android/en-US/changelogs/52.txt
+++ b/fastlane/metadata/android/en-US/changelogs/52.txt
@@ -5,3 +5,4 @@
- A setup link applied while tracking now takes effect at once instead of after the next start
- After a rate limit, sync waits as long as the server asks and Sync now says so
- Tracking profiles can switch on Wi-Fi, either any network or one you name
+- No more lost points after a Wi-Fi drop at home