Skip to content

Colota - Android GPS Location tracker

fix(geofence): record the pause-zone heartbeat even when it cannot be sent (#579)

Max Dietrichb22b3871105d
diff --git a/apps/docs/docs/development/architecture.md b/apps/docs/docs/development/architecture.md
index fc9515ac..5bc15d48 100644
--- a/apps/docs/docs/development/architecture.md
+++ b/apps/docs/docs/development/architecture.md
@@ -226,7 +226,7 @@ Each geofence supports three independent GPS pause modes, configured per zone:
- **WiFi pause** - Stops GPS entirely when connected to an unmetered network (WiFi/Ethernet). Implemented via `ConnectivityManager.NetworkCallback`, which fires immediately on network availability changes. An active network counter handles devices with multiple simultaneous unmetered networks - GPS only resumes once all of them are gone, after a short debounce.
- **Motionless pause** - Stops GPS after the device has been still for the configured per-zone dwell window (default 1 minute). Stillness is detected by `RawSensorMotionDetector` (batched accelerometer variance + parallel SIG_MOTION); any motion above the variance threshold resets the timer. The same detector fires GPS resume when movement returns.
-A per-zone **stationary heartbeat** can send periodic location updates while paused. It sends the geofence center as a synthetic anchor point - no GPS wake required - bypassing sync conditions. Configured via `heartbeatEnabled` and `heartbeatIntervalMinutes` per geofence.
+A per-zone **stationary heartbeat** records a point at the geofence center at a relaxed interval while paused. The point is a synthetic fix, so no GPS wake is required. The save is unconditional and transmission goes through `SyncManager.queueAndSend`, so offline mode and sync conditions gate the upload without dropping the recording. It fires once on zone entry; restoring a zone after a service restart schedules the interval without recording, so repeated restarts cannot stack duplicate points. Configured via `heartbeatEnabled` and `heartbeatIntervalMinutes` per geofence.
Separately, a **Stationary tracking profile** drives its own heartbeat via `StationaryHeartbeatScheduler` (an allow-while-idle alarm delivered through `StationaryHeartbeatReceiver`): a still device produces no passive fixes, so it wakes at the profile's interval, requests a real GPS fix and records it through the normal path.
diff --git a/apps/docs/docs/guides/deep-link-setup.md b/apps/docs/docs/guides/deep-link-setup.md
index 3f721398..79ea8aec 100644
--- a/apps/docs/docs/guides/deep-link-setup.md
+++ b/apps/docs/docs/guides/deep-link-setup.md
@@ -80,7 +80,7 @@ Each entry in the `geofences` array describes one pause zone. `name`, `lat`, `lo
| `pauseOnWifi` | boolean | `false` | Also stop GPS while connected to Wi-Fi or Ethernet |
| `pauseOnMotionless` | boolean | `false` | Also stop GPS after no motion for `motionlessTimeoutMinutes` |
| `motionlessTimeoutMinutes` | number | `10` | Minutes of stillness before motionless pause kicks in |
-| `heartbeatEnabled` | boolean | `false` | Send periodic location updates while paused |
+| `heartbeatEnabled` | boolean | `false` | Record a point at the zone center while paused |
| `heartbeatIntervalMinutes` | number | `15` | Heartbeat interval in minutes |
Imported geofences are appended by default. The import confirmation screen has a "Replace zones with the same name" toggle that deletes existing zones whose names match before creating the incoming ones.
diff --git a/apps/docs/docs/guides/geofencing.md b/apps/docs/docs/guides/geofencing.md
index d1dc0bc8..5baf39d4 100644
--- a/apps/docs/docs/guides/geofencing.md
+++ b/apps/docs/docs/guides/geofencing.md
@@ -43,7 +43,9 @@ Stops GPS after the device has been still for the configured time (default 1 min
### Stationary heartbeat
-Sends a periodic location update to your server while paused inside the zone. Useful as a proof-of-presence signal so your backend knows the device is still there. The heartbeat sends the geofence center as a synthetic anchor point (no GPS wake), bypassing normal sync conditions like Wi-Fi only. The first heartbeat fires immediately on zone entry, then repeats at the configured interval. Minimum 1 minute, default 15.
+Records a point at the geofence center at a set interval while paused inside the zone, as a synthetic fix that does not wake GPS. Useful as a proof-of-presence signal so your backend knows the device is still there.
+
+The point is always saved on the device, including in offline mode and when the server is unreachable. Sending it is separate: it goes out under your normal sync rules, so a Wi-Fi-only or SSID condition still governs the upload while the stay is recorded either way. The first point is recorded on zone entry, then one per interval. Minimum 1 minute, default 15.
### Combined behavior
diff --git a/apps/mobile/android/app/src/main/java/com/colota/data/SettingsKeys.kt b/apps/mobile/android/app/src/main/java/com/colota/data/SettingsKeys.kt
index 3a8a5f93..b22048e9 100644
--- a/apps/mobile/android/app/src/main/java/com/colota/data/SettingsKeys.kt
+++ b/apps/mobile/android/app/src/main/java/com/colota/data/SettingsKeys.kt
@@ -14,4 +14,8 @@ object SettingsKeys {
/** True when a low-battery (<5%) stop paused tracking - armed for charger auto-resume. */
const val STOPPED_BY_BATTERY = "stopped_by_battery"
+
+ /** Epoch ms of the last geofence heartbeat, so a service restart resumes the interval
+ * instead of restarting it and starving a device that respawns often. */
+ const val HEARTBEAT_LAST_AT = "heartbeat_last_at"
}
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 a0988a69..845534ce 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
@@ -299,7 +299,10 @@ class LocationForegroundService : Service() {
AppLogger.d(TAG, "Restored motionless pause state")
}
if (restoredGeofence?.heartbeatEnabled == true) {
- startHeartbeat(restoredGeofence.heartbeatIntervalMinutes)
+ startHeartbeat(
+ restoredGeofence.heartbeatIntervalMinutes,
+ firstDelayMs = remainingHeartbeatDelay(restoredGeofence.heartbeatIntervalMinutes)
+ )
AppLogger.d(TAG, "Restored heartbeat: ${restoredGeofence.heartbeatIntervalMinutes}min")
}
ensureMotionDetectorRunning()
@@ -756,7 +759,11 @@ class LocationForegroundService : Service() {
* Called on RECHECK when already inside the zone so editor changes take effect immediately.
*/
private fun applyZoneSettingsIfChanged(zone: GeofenceHelper.Geofence) {
- val heartbeatChanged = currentZoneGeofence?.heartbeatIntervalMinutes != zone.heartbeatIntervalMinutes
+ val previousZone = currentZoneGeofence
+ val heartbeatChanged = previousZone?.heartbeatIntervalMinutes != zone.heartbeatIntervalMinutes
+ // Switching the heartbeat on from the editor is an arrival as far as the user is concerned,
+ // so it records at once. A restore or an interval change is not.
+ val heartbeatJustEnabled = previousZone?.heartbeatEnabled != true && zone.heartbeatEnabled
currentZoneGeofence = zone
if (zone.pauseOnWifi && wifiCallback == null) {
@@ -776,7 +783,9 @@ class LocationForegroundService : Service() {
ensureMotionDetectorRunning()
if (zone.heartbeatEnabled && (heartbeatJob == null || heartbeatChanged)) {
- startHeartbeat(zone.heartbeatIntervalMinutes)
+ val firstDelayMs =
+ if (heartbeatJustEnabled) 0L else remainingHeartbeatDelay(zone.heartbeatIntervalMinutes)
+ startHeartbeat(zone.heartbeatIntervalMinutes, firstDelayMs)
} else if (!zone.heartbeatEnabled) {
cancelHeartbeat()
}
@@ -1000,7 +1009,7 @@ class LocationForegroundService : Service() {
*/
private fun startZoneHolds(zone: GeofenceHelper.Geofence) {
if (zone.pauseOnWifi) registerWifiPause()
- if (zone.heartbeatEnabled) startHeartbeat(zone.heartbeatIntervalMinutes)
+ if (zone.heartbeatEnabled) startHeartbeat(zone.heartbeatIntervalMinutes, firstDelayMs = 0L)
ensureMotionDetectorRunning()
}
@@ -1107,22 +1116,38 @@ class LocationForegroundService : Service() {
}
/**
- * Starts a heartbeat that sends a location update to the server at a relaxed
- * interval while paused in a geofence zone. Fires one send immediately so the
- * backend sees zone entry without waiting a full interval.
+ * Starts a heartbeat that records a point at the zone center at a relaxed interval
+ * while paused in a geofence zone.
+ *
+ * [firstDelayMs] is 0 for an arrival, so the backend sees it without waiting an interval.
+ * A restore passes the time still owed on the running interval - see [remainingHeartbeatDelay].
+ * Restarting the clock there would starve a device that respawns the service more often than
+ * the interval, and recording on every restore would stack duplicates for one stay.
*/
- private fun startHeartbeat(intervalMinutes: Int) {
+ private fun startHeartbeat(intervalMinutes: Int, firstDelayMs: Long) {
cancelHeartbeat()
- AppLogger.i(TAG, "Heartbeat started: ${intervalMinutes}min interval")
+ AppLogger.i(TAG, "Heartbeat started: ${intervalMinutes}min interval, first in ${firstDelayMs}ms")
heartbeatJob = serviceScope?.launch {
- sendHeartbeatLocation()
+ delay(firstDelayMs)
+ recordHeartbeatLocation()
while (isActive) {
delay(intervalMinutes * 60_000L)
- sendHeartbeatLocation()
+ recordHeartbeatLocation()
}
}
}
+ /**
+ * Time left on the interval that was running before this service instance existed.
+ * No stored timestamp means record now and establish one, which self-corrects on the
+ * next restart rather than leaving the heartbeat permanently silent.
+ */
+ private fun remainingHeartbeatDelay(intervalMinutes: Int): Long {
+ val lastAt = dbHelper.getSetting(SettingsKeys.HEARTBEAT_LAST_AT)?.toLongOrNull() ?: return 0L
+ val elapsed = System.currentTimeMillis() - lastAt
+ return (intervalMinutes * 60_000L - elapsed).coerceIn(0L, intervalMinutes * 60_000L)
+ }
+
private fun cancelHeartbeat() {
if (heartbeatJob == null) return
heartbeatJob?.cancel()
@@ -1130,9 +1155,16 @@ class LocationForegroundService : Service() {
AppLogger.i(TAG, "Heartbeat cancelled")
}
- private suspend fun sendHeartbeatLocation() {
- if (config.endpoint.isBlank()) {
- AppLogger.d(TAG, "Heartbeat skipped: no endpoint")
+ /**
+ * Records a point at the current zone center. Mirrors [saveAnchorPoint]: the point is
+ * saved unconditionally and handed to [SyncManager], which owns whether it goes out now,
+ * waits in the queue or stays local in offline mode. Recording and sending are separate
+ * concerns here - gating the save on a successful send loses the stay entirely whenever
+ * the server is unreachable or sync is not allowed.
+ */
+ private suspend fun recordHeartbeatLocation() {
+ if (!::config.isInitialized) {
+ AppLogger.w(TAG, "Config not yet initialized, skipping heartbeat")
return
}
@@ -1142,11 +1174,6 @@ class LocationForegroundService : Service() {
return
}
- if (!syncManager.isSyncAllowed()) {
- AppLogger.d(TAG, "Heartbeat skipped: sync condition not met")
- return
- }
-
val location = Location("geofence").apply {
latitude = zone.lat
longitude = zone.lon
@@ -1156,33 +1183,29 @@ class LocationForegroundService : Service() {
val (battery, batteryStatus) = deviceInfoHelper.getCachedBatteryStatus()
val timestampSec = location.time / 1000
- val payload = PayloadBuilder.buildLocationPayload(location, timestampSec, battery, batteryStatus, payloadFieldMap, payloadCustomFields, config.apiFormat)
-
- val sent = networkManager.sendToEndpoint(
- payload, config.endpoint, secureStorage.getAuthHeaders(),
- config.httpMethod, config.apiFormat
+ val locationId = dbHelper.saveLocation(
+ latitude = location.latitude,
+ longitude = location.longitude,
+ accuracy = location.accuracy.toDouble(),
+ altitude = if (location.hasAltitude()) location.altitude.toInt() else null,
+ speed = 0.0,
+ bearing = 0.0,
+ battery = battery,
+ battery_status = batteryStatus,
+ timestamp = timestampSec,
+ endpoint = config.endpoint
)
- if (sent) {
- // Only persist to DB on successful send
- val locationId = dbHelper.saveLocation(
- latitude = location.latitude,
- longitude = location.longitude,
- accuracy = location.accuracy.toDouble(),
- altitude = if (location.hasAltitude()) location.altitude.toInt() else null,
- speed = 0.0,
- bearing = 0.0,
- battery = battery,
- battery_status = batteryStatus,
- timestamp = timestampSec,
- endpoint = config.endpoint
- )
- dbHelper.markLocationsSent(listOf(locationId))
- LocationServiceModule.sendLocationEvent(location, battery, batteryStatus)
- AppLogger.i(TAG, "Heartbeat sent for zone '${zone.name}'")
- } else {
- AppLogger.d(TAG, "Heartbeat failed: server unreachable, will retry next cycle")
- }
+ // Emit before queueAndSend: an instant-mode send blocks on the network, and the map
+ // should not wait out a timeout to show a point that is already saved.
+ LocationServiceModule.sendLocationEvent(location, battery, batteryStatus)
+
+ dbHelper.saveSetting(SettingsKeys.HEARTBEAT_LAST_AT, location.time.toString())
+
+ val payload = PayloadBuilder.buildLocationPayload(location, timestampSec, battery, batteryStatus, payloadFieldMap, payloadCustomFields, config.apiFormat)
+ syncManager.queueAndSend(locationId, payload)
+
+ AppLogger.i(TAG, "Heartbeat recorded for zone '${zone.name}'")
}
/**
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 15823c17..2fef344b 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
@@ -6,6 +6,7 @@ import android.location.Location
import com.Colota.bridge.LocationServiceModule
import com.Colota.data.DatabaseHelper
import com.Colota.data.GeofenceHelper
+import com.Colota.data.SettingsKeys
import com.Colota.location.LocationProvider
import com.Colota.location.LocationUpdateCallback
import com.Colota.sync.PayloadBuilder
@@ -2610,59 +2611,153 @@ class LocationForegroundServiceTest {
}
// =========================================================================
- // sendHeartbeatLocation - sync condition check
+ // recordHeartbeatLocation - recording is independent of sending (#524)
// =========================================================================
@Test
- fun `sendHeartbeatLocation skips send when sync condition not met`() = testScope.runTest {
+ fun `recordHeartbeatLocation records the point even when the sync condition is not met`() = testScope.runTest {
+ // The stay must survive offline mode and a disallowed connection. Whether it also goes
+ // out is SyncManager's call, which still honours the SSID condition (fdw's fix).
every { syncManager.isSyncAllowed() } returns false
+ every { dbHelper.saveLocation(any(), any(), any(), any(), any(), any(), any(), any(), any(), any()) } returns 1L
setField("currentZoneGeofence", homeGeofence)
- invokeSendHeartbeatLocation()
+ invokeRecordHeartbeatLocation()
- coVerify(exactly = 0) { networkManager.sendToEndpoint(any(), any(), any(), any(), any()) }
- verify { AppLogger.d("LocationService", "Heartbeat skipped: sync condition not met") }
+ verify { dbHelper.saveLocation(any(), any(), any(), any(), any(), any(), any(), any(), any(), any()) }
+ coVerify { syncManager.queueAndSend(1L, any()) }
}
@Test
- fun `sendHeartbeatLocation sends when sync condition is met`() = testScope.runTest {
+ fun `recordHeartbeatLocation never sends around SyncManager`() = testScope.runTest {
+ // Going straight to networkManager would bypass the sync condition entirely
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
setField("currentZoneGeofence", homeGeofence)
- invokeSendHeartbeatLocation()
+ invokeRecordHeartbeatLocation()
- coVerify { networkManager.sendToEndpoint(any(), "https://example.com", any(), any(), any()) }
- verify { AppLogger.i("LocationService", "Heartbeat sent for zone 'Home'") }
+ coVerify(exactly = 0) { networkManager.sendToEndpoint(any(), any(), any(), any(), any()) }
+ verify { AppLogger.i("LocationService", "Heartbeat recorded for zone 'Home'") }
}
@Test
- fun `sendHeartbeatLocation skips when no current zone`() = testScope.runTest {
- every { syncManager.isSyncAllowed() } returns true
+ fun `recordHeartbeatLocation skips when no current zone`() = testScope.runTest {
setField("currentZoneGeofence", null)
- invokeSendHeartbeatLocation()
+ invokeRecordHeartbeatLocation()
- coVerify(exactly = 0) { networkManager.sendToEndpoint(any(), any(), any(), any(), any()) }
+ verify(exactly = 0) { dbHelper.saveLocation(any(), any(), any(), any(), any(), any(), any(), any(), any(), any()) }
+ coVerify(exactly = 0) { syncManager.queueAndSend(any(), any()) }
}
@Test
- fun `sendHeartbeatLocation must not overwrite lastKnownLocation`() = testScope.runTest {
+ fun `recordHeartbeatLocation 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()
+ invokeRecordHeartbeatLocation()
assertSame(realPreviousFix, getField<Location?>("lastKnownLocation"))
}
+ @Test
+ fun `startHeartbeat records at once on zone entry`() = runServiceTest {
+ every { dbHelper.saveLocation(any(), any(), any(), any(), any(), any(), any(), any(), any(), any()) } returns 1L
+ setField("currentZoneGeofence", homeGeofence)
+
+ invokeStartHeartbeat(15, firstDelayMs = 0L)
+ advanceTimeBy(1_000)
+
+ verify(exactly = 1) { dbHelper.saveLocation(any(), any(), any(), any(), any(), any(), any(), any(), any(), any()) }
+ }
+
+ @Test
+ fun `restore resumes the running interval instead of restarting it`() {
+ // A device that respawns the service more often than the interval would otherwise never
+ // reach a heartbeat at all, which is worse than the duplicate this replaced
+ every { dbHelper.getSetting(SettingsKeys.HEARTBEAT_LAST_AT) } returns
+ (System.currentTimeMillis() - 10 * 60_000L).toString()
+
+ val remaining = invokeRemainingHeartbeatDelay(15)
+
+ assertTrue("Expected about 5 min left, got ${remaining}ms", remaining in 4 * 60_000L..5 * 60_000L)
+ }
+
+ @Test
+ fun `restore records at once when no heartbeat was ever taken`() {
+ // Self-correcting: recording establishes the timestamp the next restart reads
+ every { dbHelper.getSetting(SettingsKeys.HEARTBEAT_LAST_AT) } returns null
+
+ assertEquals(0L, invokeRemainingHeartbeatDelay(15))
+ }
+
+ @Test
+ fun `restore records at once when the interval already elapsed`() {
+ every { dbHelper.getSetting(SettingsKeys.HEARTBEAT_LAST_AT) } returns
+ (System.currentTimeMillis() - 60 * 60_000L).toString()
+
+ assertEquals(0L, invokeRemainingHeartbeatDelay(15))
+ }
+
+ @Test
+ fun `entering a zone with the heartbeat on records a point at once`() = runServiceTest {
+ every { dbHelper.saveLocation(any(), any(), any(), any(), any(), any(), any(), any(), any(), any()) } returns 1L
+
+ invokeEnterPauseZone(geofence("Home", heartbeatEnabled = true))
+ advanceTimeBy(1_000)
+
+ verify(exactly = 1) { dbHelper.saveLocation(any(), any(), any(), any(), any(), any(), any(), any(), any(), any()) }
+ }
+
+ @Test
+ fun `switching the heartbeat on from the editor records a point at once`() = runServiceTest {
+ // The editor promises changes take effect immediately, and the interval is unchanged here,
+ // so nothing else in applyZoneSettingsIfChanged marks this as new
+ every { dbHelper.saveLocation(any(), any(), any(), any(), any(), any(), any(), any(), any(), any()) } returns 1L
+ setField("currentZoneGeofence", geofence("Home", heartbeatEnabled = false))
+
+ invokeApplyZoneSettingsIfChanged(geofence("Home", heartbeatEnabled = true))
+ advanceTimeBy(1_000)
+
+ verify(exactly = 1) { dbHelper.saveLocation(any(), any(), any(), any(), any(), any(), any(), any(), any(), any()) }
+ }
+
+ @Test
+ fun `re-applying an unchanged zone does not record another point`() = runServiceTest {
+ // RECHECK fires on unrelated edits too; each one must not stack a duplicate on an
+ // interval that is already running
+ every { dbHelper.saveLocation(any(), any(), any(), any(), any(), any(), any(), any(), any(), any()) } returns 1L
+ every { dbHelper.getSetting(SettingsKeys.HEARTBEAT_LAST_AT) } returns
+ (System.currentTimeMillis() - 60_000L).toString()
+ setField("currentZoneGeofence", geofence("Home", heartbeatEnabled = true))
+
+ invokeApplyZoneSettingsIfChanged(geofence("Home", heartbeatEnabled = true))
+ advanceTimeBy(1_000)
+
+ verify(exactly = 0) { dbHelper.saveLocation(any(), any(), any(), any(), any(), any(), any(), any(), any(), any()) }
+ }
+
+ @Test
+ fun `startHeartbeat waits a full interval when restoring a zone`() = runServiceTest {
+ // Every service restart restores the zone. Recording here would add a duplicate point,
+ // and POST one, for a stay the previous instance already covered.
+ every { dbHelper.saveLocation(any(), any(), any(), any(), any(), any(), any(), any(), any(), any()) } returns 1L
+ setField("currentZoneGeofence", homeGeofence)
+
+ invokeStartHeartbeat(15, firstDelayMs = 15 * 60_000L)
+ advanceTimeBy(1_000)
+
+ verify(exactly = 0) { dbHelper.saveLocation(any(), any(), any(), any(), any(), any(), any(), any(), any(), any()) }
+
+ advanceTimeBy(15 * 60_000L)
+ verify(exactly = 1) { dbHelper.saveLocation(any(), any(), any(), any(), any(), any(), any(), any(), any(), any()) }
+ }
+
// =========================================================================
// Reflection helpers
@@ -2725,12 +2820,33 @@ class LocationForegroundServiceTest {
radius: Double = 100.0,
pauseOnWifi: Boolean = false,
pauseOnMotionless: Boolean = false,
- motionlessTimeoutMinutes: Int = 10
- ) = GeofenceHelper.Geofence(name, lat, lon, radius, pauseOnWifi, pauseOnMotionless, motionlessTimeoutMinutes)
+ motionlessTimeoutMinutes: Int = 10,
+ heartbeatEnabled: Boolean = false,
+ heartbeatIntervalMinutes: Int = 15
+ ) = GeofenceHelper.Geofence(
+ name, lat, lon, radius, pauseOnWifi, pauseOnMotionless, motionlessTimeoutMinutes,
+ heartbeatEnabled, heartbeatIntervalMinutes
+ )
+
+ private fun invokeRemainingHeartbeatDelay(intervalMinutes: Int): Long {
+ val method = LocationForegroundService::class.java.getDeclaredMethod(
+ "remainingHeartbeatDelay", Int::class.java
+ )
+ method.isAccessible = true
+ return method.invoke(service, intervalMinutes) as Long
+ }
+
+ private fun invokeStartHeartbeat(intervalMinutes: Int, firstDelayMs: Long) {
+ val method = LocationForegroundService::class.java.getDeclaredMethod(
+ "startHeartbeat", Int::class.java, Long::class.java
+ )
+ method.isAccessible = true
+ method.invoke(service, intervalMinutes, firstDelayMs)
+ }
- private fun invokeSendHeartbeatLocation() = runBlocking {
+ private fun invokeRecordHeartbeatLocation() = runBlocking {
val method = LocationForegroundService::class.java.getDeclaredMethod(
- "sendHeartbeatLocation", kotlin.coroutines.Continuation::class.java
+ "recordHeartbeatLocation", kotlin.coroutines.Continuation::class.java
)
method.isAccessible = true
suspendCancellableCoroutine<Unit> { cont ->
diff --git a/apps/mobile/src/screens/GeofenceEditorScreen.tsx b/apps/mobile/src/screens/GeofenceEditorScreen.tsx
index 6e72113f..ed2ef6da 100644
--- a/apps/mobile/src/screens/GeofenceEditorScreen.tsx
+++ b/apps/mobile/src/screens/GeofenceEditorScreen.tsx
@@ -302,7 +302,7 @@ export function GeofenceEditorScreen({ navigation, route }: RootScreenProps<"Geo
<SettingRow
label="Stationary heartbeat"
- hint="Periodic server update while paused"
+ hint="Periodic point at the zone center while paused"
style={[styles.toggleRow, !pauseTracking && styles.disabledRow]}
>
<Switch
@@ -317,7 +317,7 @@ export function GeofenceEditorScreen({ navigation, route }: RootScreenProps<"Geo
{pauseTracking && heartbeatEnabled && (
<View style={[styles.nestedSetting, { borderLeftColor: colors.border }]}>
- <SettingRow label="Interval (min)" hint="How often to send a location update">
+ <SettingRow label="Interval (min)" hint="How often to record a point">
<TextInput
testID="heartbeat-interval-input"
style={[inputStyle, styles.numInput]}
diff --git a/fastlane/metadata/android/en-US/changelogs/45.txt b/fastlane/metadata/android/en-US/changelogs/45.txt
index 740be132..0fb8ad7e 100644
--- a/fastlane/metadata/android/en-US/changelogs/45.txt
+++ b/fastlane/metadata/android/en-US/changelogs/45.txt
@@ -1 +1,3 @@
- Large point counts stay on one line in the settings summary, shown as 123K or 2.0M
+- Geofence heartbeat now records points in offline mode and when the server is unreachable
+- No duplicate heartbeat point after the app restarts in the background