Skip to content

Colota - Android GPS Location tracker

fix: don't overwrite lastKnownLocation with heartbeat zone-center

Max Dietrich4e91243b78bb
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 a72c5da5..96595b78 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
@@ -937,8 +937,6 @@ class LocationForegroundService : Service() {
accuracy = 0f
time = System.currentTimeMillis()
}
- lastKnownLocation = location
-
val (battery, batteryStatus) = deviceInfoHelper.getCachedBatteryStatus()
val timestampSec = location.time / 1000
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 4b8fb420..e44d2479 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
@@ -2060,6 +2060,23 @@ class LocationForegroundServiceTest {
coVerify(exactly = 0) { networkManager.sendToEndpoint(any(), any(), any(), any(), any()) }
}
+ @Test
+ fun `sendHeartbeatLocation must not overwrite lastKnownLocation`() = testScope.runTest {
+ val realPreviousFix = mockLocation(lat = 52.50, lon = 13.40,
+ time = System.currentTimeMillis() - 60_000)
+ setField("currentZoneGeofence", homeGeofence)
+ setField("lastKnownLocation", realPreviousFix)
+ every { syncManager.isSyncAllowed() } returns true
+ coEvery { networkManager.sendToEndpoint(any(), any(), any(), any(), any()) } returns true
+ every { dbHelper.saveLocation(any(), any(), any(), any(), any(), any(),
+ any(), any(), any(), any()) } returns 1L
+
+ invokeSendHeartbeatLocation()
+
+ assertSame(realPreviousFix, getField<Location?>("lastKnownLocation"))
+ }
+
+
// =========================================================================
// Reflection helpers
// =========================================================================