Modern Apps git

← Modern-Apps.git

findfamily: arrival auto-toggle now uses the accuracy-aware enter rule

Commit
08970d6831cc38ba568d68b34130294a806fd2ab
Author
Vayun Mathur <[email protected]>
When
2026-12-01 01:07 UTC (5 days ago)
Parents
965f1aa
The sender-side arrival auto-toggle ('flip sharing when I
arrive at a saved place') decided inside from the fix centre
alone — haversine(waypoint, me) < range — while every other
geofence consumer in the app uses the enter rule (the whole
error circle must fit: distance + accuracy < range), mirrored
on the receiver-side waypoint path. A fix centred exactly on
Home with 100 m accuracy against a 100 m place flipped a
peer's sharing off (or on) although that fix is equally
consistent with being 100 m outside: it cannot prove arrival,
and it consumed the one-shot trigger.

The heartbeat now feeds its arrival set through
NoShowPolicy.isEnterInside with the fix's accuracy, so a fix
that cannot say which side of the boundary it is on never
moves the answer; the atomic DAO flip is unchanged. Two
regression tests: a coarse centre fix must neither flip nor
consume the trigger (failed pre-fix), a tight centre fix
flips exactly once. Ingest sequencing, pair auth, invites,
no-show scheduling and spools were audited and cleared.
Verified: :findfamily:testDevUnitTest 583 tests pass; lint
errors are pre-existing on untouched files.

Diff

findfamily/src/main/java/com/vayunmathur/findfamily/platform/LocationTrackingHeartbeat.kt
diff --git a/findfamily/src/main/java/com/vayunmathur/findfamily/platform/LocationTrackingHeartbeat.kt b/findfamily/src/main/java/com/vayunmathur/findfamily/platform/LocationTrackingHeartbeat.ktindex dc0764f245..4b58876934 100644--- a/findfamily/src/main/java/com/vayunmathur/findfamily/platform/LocationTrackingHeartbeat.kt+++ b/findfamily/src/main/java/com/vayunmathur/findfamily/platform/LocationTrackingHeartbeat.kt@@ -178,10 +178,17 @@ private suspend fun LocationTrackingService.applyArrivalAutoToggles(     // Arrival auto-toggle check (GitHub #406): flip sharing for any user whose trigger     // points at a saved place that "Me" is currently inside. Uses the same atomic,     // waypoint-id-guarded update as the timer path so a stale snapshot cannot mis-flip.+    // "Inside" is the geofence *enter* rule ([NoShowPolicy.isEnterInside], the same+    // rule the receiver-side waypoint path and the no-show policy use): the whole+    // error circle must fit inside the radius. A centre-only `distance < range`+    // check flipped sharing on fixes that could not actually prove arrival — a+    // 100 m-accurate fix at a 100 m place's centre is consistent with being+    // 100 m outside it, yet it turned sharing on/off as if "Me" had arrived.     try {         val myCoord = Coord(location.latitude, location.longitude)+        val accuracy = location.accuracy.toDouble()         val insideWaypointIds = repository.waypointStore.getAll()-            .filter { havershine(it.coord, myCoord) < it.range }+            .filter { NoShowPolicy.isEnterInside(havershine(it.coord, myCoord), accuracy, it.range) }             .map { it.id }         if (insideWaypointIds.isNotEmpty()) {             val flippedArrival = repository.applyDueArrivalToggles(insideWaypointIds)
findfamily/src/test/java/com/vayunmathur/findfamily/util/LocationTrackingHeartbeatTest.kt
diff --git a/findfamily/src/test/java/com/vayunmathur/findfamily/util/LocationTrackingHeartbeatTest.kt b/findfamily/src/test/java/com/vayunmathur/findfamily/util/LocationTrackingHeartbeatTest.ktindex 610982b2a4..2ff9c029e8 100644--- a/findfamily/src/test/java/com/vayunmathur/findfamily/util/LocationTrackingHeartbeatTest.kt+++ b/findfamily/src/test/java/com/vayunmathur/findfamily/util/LocationTrackingHeartbeatTest.kt@@ -108,6 +108,38 @@ class LocationTrackingHeartbeatTest {         assertTrue(service.publishRoster.isEmpty())     } +    @Test+    fun syncHeartbeatArrivalToggleIgnoresFixThatCannotProveArrival() = runBlocking {+        // Regression: the arrival auto-toggle used a centre-only+        // `distance < range` check. A fix at the exact centre of a 100 m place+        // with 100 m accuracy satisfies that (0 < 100) but cannot prove arrival+        // — its error circle reaches 100 m outside the place — so the+        // geofence enter rule (`distance + accuracy < range`) must not flip+        // sharing or consume the trigger.+        val peer = repo.upsertUser(user("Peer"))+        val home = repo.waypointStore.upsert(Waypoint(name = "Home", range = 100.0, coord = Coord(51.5, -0.12)))+        repo.setSharingAutoToggleWaypointId(peer, home)+        service.lastKnownLocation = location(acc = 100f)+        service.syncHeartbeat()+        val after = repo.getUser(peer)+        assertEquals(true, after?.sendingEnabled)+        assertEquals(home, after?.sharingAutoToggleWaypointId)+    }++    @Test+    fun syncHeartbeatArrivalToggleFiresWhenWholeErrorCircleInside() = runBlocking {+        // Control: the same centre fix with tight accuracy is wholly inside+        // (0 + 10 < 100), so the toggle flips exactly once and clears itself.+        val peer = repo.upsertUser(user("Peer"))+        val home = repo.waypointStore.upsert(Waypoint(name = "Home", range = 100.0, coord = Coord(51.5, -0.12)))+        repo.setSharingAutoToggleWaypointId(peer, home)+        service.lastKnownLocation = location(acc = 10f)+        service.syncHeartbeat()+        val after = repo.getUser(peer)+        assertEquals(false, after?.sendingEnabled)+        assertEquals(null, after?.sharingAutoToggleWaypointId)+    }+     @Test     fun syncHeartbeatPublishesFixSpeed() = runBlocking {         service.lastKnownLocation = location().apply { speed = 13.5f }