Skip to content

Colota - Android GPS Location tracker

Fix/restored pause hold (#532)

Max Dietrich17e7afd3691f
diff --git a/apps/mobile/android/app/src/main/java/com/colota/bridge/LocationServiceModule.kt b/apps/mobile/android/app/src/main/java/com/colota/bridge/LocationServiceModule.kt
index bdbe2ace..839fcda0 100644
--- a/apps/mobile/android/app/src/main/java/com/colota/bridge/LocationServiceModule.kt
+++ b/apps/mobile/android/app/src/main/java/com/colota/bridge/LocationServiceModule.kt
@@ -301,7 +301,6 @@ class LocationServiceModule(reactContext: ReactApplicationContext) :
val serviceConfig = ServiceConfig.fromReadableMap(config, dbHelper)
val serviceIntent = Intent(reactApplicationContext, LocationForegroundService::class.java)
serviceConfig.toIntent(serviceIntent)
- serviceIntent.putExtra(LocationForegroundService.EXTRA_USER_INITIATED, true)
try {
reactApplicationContext.startForegroundService(serviceIntent)
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 f5a4d97b..c1b248ca 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
@@ -165,8 +165,6 @@ class LocationForegroundService : Service() {
/** Internal stop request from triggers (broadcast receiver, shortcut activity). */
const val ACTION_STOP_REQUEST = "com.Colota.ACTION_STOP_REQUEST"
const val EXTRA_STOP_REASON = "stop_reason"
- /** Set by the bridge on an explicit user start so the restored-pause path can force-exit on no fix. */
- const val EXTRA_USER_INITIATED = "user_initiated"
/** Debug-only: directly inject a MotionState transition. `--es state STATIONARY|MOVING`. */
const val ACTION_DEBUG_FORCE_MOTION = "com.Colota.DEBUG_FORCE_MOTION"
@@ -338,7 +336,7 @@ class LocationForegroundService : Service() {
ACTION_STOP_REQUEST -> stopForegroundServiceWithReason(
intent.getStringExtra(EXTRA_STOP_REASON) ?: "Stopped"
)
- else -> handleStart(intent?.getBooleanExtra(EXTRA_USER_INITIATED, false) ?: false)
+ else -> handleStart()
}
return START_STICKY
@@ -374,14 +372,14 @@ class LocationForegroundService : Service() {
}
}
- private fun handleStart(userInitiated: Boolean) {
+ private fun handleStart() {
locationRestartJob?.cancel()
locationRestartJob = serviceScope?.launch {
withContext(Dispatchers.Main) {
stopLocationUpdates()
syncManager.stopPeriodicSync()
- setupLocationUpdates(userInitiated)
+ setupLocationUpdates()
syncManager.startPeriodicSync()
// Start after setup so profile evaluations don't race
@@ -432,7 +430,7 @@ class LocationForegroundService : Service() {
override fun onBind(intent: Intent?): IBinder? = null
- private fun setupLocationUpdates(userInitiatedStart: Boolean = false) {
+ private fun setupLocationUpdates() {
if (isWifiPaused || isMotionlessPaused) return // GPS intentionally stopped by a zone pause hold
val callback = object : LocationUpdateCallback {
@@ -465,20 +463,16 @@ class LocationForegroundService : Service() {
)
lastRequestedBypassOsFilter = bypassOsFilter
- // A restored pause must be re-checked against a fresh fix: a cached fix can only
- // re-enter, never exit, so a departed user would stay latched. On no usable fix an
- // explicit user start forces exit (stop/start "kick it loose"); an OS auto-restart stays
- // put so a restart while genuinely at home doesn't record a false point. Cold start latches
- // a pause only from a fresh last-known fix.
+ // A restored pause must be re-checked against a fresh fix: a cached fix can only re-enter,
+ // never exit, so a departed user would stay latched. A usable fix resumes only if it places
+ // us outside the zone (via recheck); with no usable fix, hold the pause - the watchdog resumes
+ // once a real fix confirms a departure. Cold start latches a pause only from a fresh last-known fix.
val restoredPause = insidePauseZone
if (restoredPause) {
requestFreshOrLastLocation { location, _ ->
if (location != null) {
lastKnownLocation = location
recheckZoneWithLocation(location)
- } else if (userInitiatedStart) {
- AppLogger.d(TAG, "User-initiated start with no usable fix - forcing exit from zone")
- exitPauseZone()
}
}
} else {
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 33c36d9f..79ef776e 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
@@ -922,32 +922,20 @@ class LocationForegroundServiceTest {
}
@Test
- fun `user-initiated start force-exits a restored pause when there is no usable fix`() {
+ fun `a restored pause with no usable fix holds and waits for the watchdog`() {
setField("insidePauseZone", true)
setField("currentZoneName", "Home")
setField("currentZoneGeofence", homeGeofence)
- // Fresh probe times out (default stub -> null) and last-known is unavailable.
+ // Fresh probe times out (default stub -> null) and last-known is unavailable, so no fix can
+ // confirm a departure. The pause must hold, not force a false exit - previously a user-initiated
+ // start force-exited here, unpausing at a poor-GPS home zone after a backup restore.
every { locationProvider.getLastLocation(any(), any()) } answers {
firstArg<(Location?) -> Unit>()(null)
}
- invokeSetupLocationUpdates(userInitiated = true)
-
- assertFalse("explicit stop/start must kick a stuck pause loose", getField("insidePauseZone"))
- }
-
- @Test
- fun `os auto-restart leaves a restored pause untouched when there is no usable fix`() {
- setField("insidePauseZone", true)
- setField("currentZoneName", "Home")
- setField("currentZoneGeofence", homeGeofence)
- every { locationProvider.getLastLocation(any(), any()) } answers {
- firstArg<(Location?) -> Unit>()(null)
- }
-
- invokeSetupLocationUpdates(userInitiated = false)
+ invokeSetupLocationUpdates()
- assertTrue("an OS restart at home with no fix must not record a false exit", getField("insidePauseZone"))
+ assertTrue("no usable fix must hold the pause, not force a false exit", getField("insidePauseZone"))
}
@Test
@@ -2343,11 +2331,11 @@ class LocationForegroundServiceTest {
method.invoke(service)
}
- private fun invokeSetupLocationUpdates(userInitiated: Boolean = false) {
+ private fun invokeSetupLocationUpdates() {
val method = LocationForegroundService::class.java
- .getDeclaredMethod("setupLocationUpdates", Boolean::class.javaPrimitiveType)
+ .getDeclaredMethod("setupLocationUpdates")
method.isAccessible = true
- method.invoke(service, userInitiated)
+ method.invoke(service)
}
private fun invokeHandleRecheckProfiles() {
diff --git a/fastlane/metadata/android/en-US/changelogs/43.txt b/fastlane/metadata/android/en-US/changelogs/43.txt
index aeff06ff..107238ef 100644
--- a/fastlane/metadata/android/en-US/changelogs/43.txt
+++ b/fastlane/metadata/android/en-US/changelogs/43.txt
@@ -1,4 +1,5 @@
- Map no longer over-zooms on single-point days
- Fixed a false pause at a stale location on startup
- FOSS: more reliable GPS on Android 12+ and a crash fix on GPS-less devices
+- Fixed a paused geofence wrongly resuming after a restart
- Fixed the Stationary profile getting stuck active while still driving