Skip to content

Colota - Android GPS Location tracker

fix(geofence): entry delay cap (#652)

Max Dietrich280531319ba7
diff --git a/apps/docs/docs/development/architecture.md b/apps/docs/docs/development/architecture.md
index e2a09162..f2554563 100644
--- a/apps/docs/docs/development/architecture.md
+++ b/apps/docs/docs/development/architecture.md
@@ -148,7 +148,7 @@ An Android foreground service that runs continuously for GPS tracking. Manages:
- GPS location capture via the `LocationProvider` abstraction
- Pause zone detection (geofencing)
-- Geofence entry delay - keeps recording for 3.5× the tracking interval before pausing on zone entry, logging real arrival points for backends like GeoPulse
+- Geofence entry delay - keeps recording for 3.5× the configured tracking interval before pausing on zone entry, logging real arrival points for backends like GeoPulse
- Anchor points - a synthetic location saved on zone exit as a clean start point for the departing trip, timestamped 1s before the first real GPS fix
- Battery critical shutdown (below 5% while unplugged), detected via a battery-broadcast receiver so it fires even while GPS is paused in a zone
- Location accuracy filtering
diff --git a/apps/docs/docs/guides/geofencing.md b/apps/docs/docs/guides/geofencing.md
index b5338861..b52070ce 100644
--- a/apps/docs/docs/guides/geofencing.md
+++ b/apps/docs/docs/guides/geofencing.md
@@ -79,7 +79,7 @@ See the [Deep Link Setup](deep-link-setup.md#geofences) guide for the full paylo
## How It Works
- Zone detection uses the Haversine formula (1-2ms per check)
-- When entering a pause zone, Colota keeps recording for 3.5× your tracking interval before pausing - this logs several real arrival points near the zone boundary, which backends like GeoPulse need to confirm a trip has ended
+- When entering a pause zone, Colota keeps recording for 3.5× your tracking interval before pausing - this logs several real arrival points near the zone boundary, which backends like GeoPulse need to confirm a trip has ended. The delay uses your configured interval.
- The notification shows "Paused: [Zone Name]" once the pause takes effect
- By default, GPS continues running inside the zone to detect when you leave. If **WiFi pause** or **motionless pause** is enabled, GPS stops entirely inside the zone and zone exit is detected when GPS resumes
- If you leave before the entry delay completes, the delay is cancelled and tracking continues uninterrupted
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 c93c222b..a4bd571d 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
@@ -1015,7 +1015,7 @@ class LocationForegroundService : Service() {
}
/**
- * Starts a delay of 3.5 tracking intervals before pausing GPS on geofence entry.
+ * Starts a delay of 3.5 configured tracking intervals before pausing GPS on geofence entry.
* Real GPS locations continue to be logged during the delay, giving backends
* like GeoPulse enough arrival points for reliable trip detection.
* If the device exits the zone before the delay completes, the delay is cancelled.
@@ -1030,7 +1030,7 @@ class LocationForegroundService : Service() {
return
}
- val delayMs = (config.interval * ENTRY_DELAY_MULTIPLIER).toLong()
+ val delayMs = (profileManager.defaultInterval * ENTRY_DELAY_MULTIPLIER).toLong()
AppLogger.d(TAG, "Geofence entry delay started for '${geofence.name}': ${delayMs}ms (${delayMs / 1000.0}s)")
entryDelayJob = scope.launch {
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 636b2775..aa525bf6 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
@@ -93,6 +93,7 @@ class LocationForegroundServiceTest {
every { syncManager.getCachedQueuedCount() } returns 0
every { syncManager.lastSuccessfulSyncTime } returns 0L
every { profileManager.getActiveProfileName() } returns null
+ every { profileManager.defaultInterval } returns 5000L
every { secureStorage.getAuthHeaders() } returns emptyMap()
mockkObject(AppLogger)
@@ -2857,11 +2858,7 @@ class LocationForegroundServiceTest {
@Test
fun `entry delay uses 3_5x tracking interval`() = testScope.runTest {
- setField("config", ServiceConfig(
- endpoint = "https://example.com",
- interval = 10000L,
- filterInaccurateLocations = false
- ))
+ every { profileManager.defaultInterval } returns 10000L
invokeStartEntryDelay(homeGeofence)
@@ -2874,6 +2871,23 @@ class LocationForegroundServiceTest {
assertTrue(getField("insidePauseZone"))
}
+ @Test
+ fun `entry delay ignores the active profile interval`() = testScope.runTest {
+ // A profile interval is a battery override, not an arrival cadence: an hourly profile
+ // must not hold GPS on for 3.5 hours before the zone pauses.
+ every { profileManager.defaultInterval } returns 10000L
+ setField("config", ServiceConfig(
+ endpoint = "https://example.com",
+ interval = 3600000L,
+ filterInaccurateLocations = false
+ ))
+
+ invokeStartEntryDelay(homeGeofence)
+
+ advanceTimeBy(35001L)
+ assertTrue(getField("insidePauseZone"))
+ }
+
// =========================================================================
// WiFi pause restore on service restart
// =========================================================================
diff --git a/fastlane/metadata/android/en-US/changelogs/49.txt b/fastlane/metadata/android/en-US/changelogs/49.txt
index 08ad3e6b..fc9e1212 100644
--- a/fastlane/metadata/android/en-US/changelogs/49.txt
+++ b/fastlane/metadata/android/en-US/changelogs/49.txt
@@ -1,2 +1,3 @@
- A notification now alerts you when tracking stops on its own, instead of appearing silently
- Unplugging at a low battery no longer restarts tracking in a loop
+- Pause zones no longer take hours to engage when a tracking profile is active