Skip to content

Colota - Android GPS Location tracker

fix(service): label a held tracking service as paused, not stopped (#613)

Max Dietrichb448dc694b31
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 acdabd45..0b5d4d98 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
@@ -651,13 +651,12 @@ class LocationForegroundService : Service() {
setupLocationUpdates()
}
- /** Wifi and motionless are holds inside a zone pause, so they're checked first. Without
- * PAUSED(zone) a latched pause reads as ACTIVE in an exported log. */
+ /** Holds come first: both stop the stream, which is what a null callback means. */
private fun trackingStateLabel(): String = when {
- locationUpdateCallback == null -> "STOPPED"
isWifiPaused && isMotionlessPaused -> "PAUSED(wifi+motionless)"
isWifiPaused -> "PAUSED(wifi)"
isMotionlessPaused -> "PAUSED(motionless)"
+ locationUpdateCallback == null -> "STOPPED"
insidePauseZone -> "PAUSED(zone)"
else -> "ACTIVE"
}
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 64472cd7..1e79c427 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
@@ -2093,15 +2093,43 @@ class LocationForegroundServiceTest {
assertEquals("PAUSED(zone)", invokeTrackingStateLabel())
}
+ /** A hold stops the stream, so a live callback here would pin a state that cannot occur. */
@Test
- fun `trackingStateLabel reports the wifi hold ahead of the zone pause`() {
- setField("locationUpdateCallback", mockk<LocationUpdateCallback>(relaxed = true))
+ fun `trackingStateLabel reports the wifi hold rather than a stop`() {
+ setField("locationUpdateCallback", null)
setField("insidePauseZone", true)
setField("isWifiPaused", true)
assertEquals("PAUSED(wifi)", invokeTrackingStateLabel())
}
+ @Test
+ fun `trackingStateLabel reports the motionless hold rather than a stop`() {
+ setField("locationUpdateCallback", null)
+ setField("insidePauseZone", true)
+ setField("isMotionlessPaused", true)
+
+ assertEquals("PAUSED(motionless)", invokeTrackingStateLabel())
+ }
+
+ @Test
+ fun `trackingStateLabel names both holds when both are active`() {
+ setField("locationUpdateCallback", null)
+ setField("insidePauseZone", true)
+ setField("isWifiPaused", true)
+ setField("isMotionlessPaused", true)
+
+ assertEquals("PAUSED(wifi+motionless)", invokeTrackingStateLabel())
+ }
+
+ /** With no hold to explain it, a null callback really is a stop. */
+ @Test
+ fun `trackingStateLabel reports a genuine stop`() {
+ setField("locationUpdateCallback", null)
+
+ assertEquals("STOPPED", invokeTrackingStateLabel())
+ }
+
@Test
fun `trackingStateLabel reports ACTIVE while tracking outside every zone`() {
setField("locationUpdateCallback", mockk<LocationUpdateCallback>(relaxed = true))