Modern Apps git

← Modern-Apps.git

findfamily: mirror the snapshot-alert filter into the phone protocol copy

Commit
fd5f5f859e17dad8b106e15a36b71973cc860dff
Author
Vayun Mathur <[email protected]>
When
2026-12-01 11:02 UTC (5 days ago)
Parents
fd95c06
Mirroring fd95c0609 into the deliberately identical phone
copy: snap() passed alerts through verbatim, so the phone
emitted alerts for people the byte cap had dropped
(rendered on the watch as '? at Home') and alerts never
shrunk toward the 90 KB cap. The copies are now identical
modulo the package line — alerts filtered to kept person
ids, place labels capped — and the normalized diff shows
no other semantic drift. The two wear regression tests came
across verbatim. (Wear's extra test breadth covers
watch-only relative-view helpers with no phone counterpart;
not production drift, and not ported.) Verified:
:findfamily:testDevUnitTest 347 tests pass; lint errors are
pre-existing on untouched files.

Diff

findfamily/src/main/java/com/vayunmathur/findfamily/domain/WearFindFamilyProtocol.kt
diff --git a/findfamily/src/main/java/com/vayunmathur/findfamily/domain/WearFindFamilyProtocol.kt b/findfamily/src/main/java/com/vayunmathur/findfamily/domain/WearFindFamilyProtocol.ktindex ffe7608dbc..7a185a7d3c 100644--- a/findfamily/src/main/java/com/vayunmathur/findfamily/domain/WearFindFamilyProtocol.kt+++ b/findfamily/src/main/java/com/vayunmathur/findfamily/domain/WearFindFamilyProtocol.kt@@ -247,7 +247,9 @@ fun wearRegionFor(people: List<WearPerson>): WearRegion {  * Builds the all-people snapshot: most-recently-updated first, field caps  * applied, then — only to fit [WearFindFamilyProtocol.MAX_JSON_BYTES] —  * tighter summarising, and only then dropping least-recent people with- * `truncated`/`droppedCount` set. Normal circles lose nobody.+ * `truncated`/`droppedCount` set. Normal circles lose nobody. Alerts are+ * kept only for people present in the snapshot (an alert the watch cannot+ * attribute to a named person is dropped, not rendered nameless).  */ fun buildWearSnapshot(     candidates: List<WearPerson>,@@ -263,16 +265,25 @@ fun buildWearSnapshot(             placeLabel = it.placeLabel.take(WearFindFamilyProtocol.MAX_PLACE_CHARS),         )     }-    fun snap(people: List<WearPerson>, dropped: Int) = WearFindFamilySnapshot(-        generatedAtMillis = generatedAtMillis,-        people = people,-        alerts = alerts,-        sharingEnabled = sharingEnabled,-        region = wearRegionFor(people),-        truncated = dropped > 0,-        droppedCount = dropped,-        totalPeople = sorted.size,-    )+    fun snap(people: List<WearPerson>, dropped: Int): WearFindFamilySnapshot {+        val keptIds = people.mapTo(HashSet()) { it.id }+        return WearFindFamilySnapshot(+            generatedAtMillis = generatedAtMillis,+            people = people,+            // An alert is only meaningful beside its person: drop alerts+            // whose person was capped out (or was never a candidate), so+            // the watch never renders an alert it cannot attribute, and+            // shrinking people also shrinks the payload toward the cap.+            alerts = alerts.filter { it.personId in keptIds }.map {+                it.copy(placeLabel = it.placeLabel.take(WearFindFamilyProtocol.MAX_PLACE_CHARS))+            },+            sharingEnabled = sharingEnabled,+            region = wearRegionFor(people),+            truncated = dropped > 0,+            droppedCount = dropped,+            totalPeople = sorted.size,+        )+    }     var kept = sorted     var snapshot = snap(kept, 0)     if (WearFindFamilyProtocol.json.encodeToString(snapshot).encodeToByteArray().size <=
findfamily/src/test/java/com/vayunmathur/findfamily/domain/WearFindFamilyProtocolTest.kt
diff --git a/findfamily/src/test/java/com/vayunmathur/findfamily/domain/WearFindFamilyProtocolTest.kt b/findfamily/src/test/java/com/vayunmathur/findfamily/domain/WearFindFamilyProtocolTest.ktindex 21e90ff9b4..f8b18fe205 100644--- a/findfamily/src/test/java/com/vayunmathur/findfamily/domain/WearFindFamilyProtocolTest.kt+++ b/findfamily/src/test/java/com/vayunmathur/findfamily/domain/WearFindFamilyProtocolTest.kt@@ -74,6 +74,42 @@ class WearFindFamilyProtocolTest {         assertTrue(bytes <= WearFindFamilyProtocol.MAX_JSON_BYTES, "snapshot $bytes over cap")     } +    @Test+    fun hardCapDropsAlertsForDroppedPeople() {+        val candidates = (1L..2_000L).map {+            person(it, it, name = "N".repeat(100), place = "P".repeat(120))+        }+        // The phone attaches one AT_PLACE alert per located person; the+        // oldest person also has a fired no-show. The byte cap drops the+        // oldest people, so their alerts must go with them: the watch+        // must never render an alert it cannot attribute to a person.+        val alerts = candidates.map {+            WearAlert(WearAlertKind.AT_PLACE, it.id, it.placeLabel, it.placeSinceMillis)+        } + WearAlert(WearAlertKind.NOSHOW, 1L, "School", 42L, fired = true)+        val snapshot = buildWearSnapshot(candidates, alerts = alerts, generatedAtMillis = 0L)+        assertTrue(snapshot.truncated)+        val keptIds = snapshot.people.map { it.id }.toSet()+        assertTrue(snapshot.alerts.isNotEmpty())+        assertTrue(snapshot.alerts.all { it.personId in keptIds })+        assertTrue(snapshot.alerts.none { it.kind == WearAlertKind.NOSHOW })+        val bytes = WearFindFamilyProtocol.json.encodeToString(snapshot).encodeToByteArray().size+        assertTrue(bytes <= WearFindFamilyProtocol.MAX_JSON_BYTES, "snapshot $bytes over cap")+    }++    @Test+    fun alertsForUnknownPeopleAreDropped() {+        val snapshot = buildWearSnapshot(+            listOf(person(1L, 10L), person(2L, 20L)),+            alerts = listOf(+                WearAlert(WearAlertKind.AT_PLACE, 1L, "Home", 5L),+                WearAlert(WearAlertKind.NOSHOW, 999L, "School", 6L, fired = true),+            ),+            generatedAtMillis = 0L,+        )+        assertFalse(snapshot.truncated)+        assertEquals(listOf(1L), snapshot.alerts.map { it.personId })+    }+     @Test     fun stalenessAndRelativeMath() {         val fresh = person(1L, 1_000_000L)