Modern Apps git

← Modern-Apps.git

wearlink: add email and securemail watch protocols

Commit
2b5102486f9bb471677106bf51aaad6eebc6fd7e
Author
Vayun Mathur <[email protected]>
When
2026-12-06 03:50 UTC (5 hours ago)
Parents
79156c4
Shared phone<->watch wire types for the merged Email and SecureMail Wear OS experiences, following the notes/contacts pattern in :library:wearlink.

Email: bounded recent-inbox snapshot (30 messages, sender/subject capped, plain-text body capped at 4,000 chars, 90,000 JSON bytes), watch state, and a mark read/unread op. No archive op is defined: the phone Email app has no IMAP archive/move primitive (only seen-flag, expunge-delete and snooze), so a watch archive would be fake.

SecureMail: metadata-only snapshot (sender, date, read state, folder, decrypted/unencrypted flags) and a mark read/unread op. Decrypted subject/body/preview never leave the phone; PGP keys and the biometric-gated passphrase stay phone-side, so no decrypted field exists on the wire type.

Also updates the root merged-apk app list, the wearlink migrated-protocol list, and the wear protocol pairs registry.

Verified: :library:wearlink:testDevUnitTest green as part of the combined lint/test run for :email and :securemail.

Diff

AGENTS.md
diff --git a/AGENTS.md b/AGENTS.mdindex 15550e4d82..f29c0c591a 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -49,7 +49,7 @@ Monorepo: ~100 Gradle modules + Rust workspace. Do scoped work only. ### Apps (Gradle key → dir) Reference: `backup/` satisfies every rule; `notes/` second + `intents/` demo. `camera` + `games/voxels` hand-commit screenshots. Full canonical index (Gradle key → dir + group + notes): `.llms/repo-map.md`.-`clock`, `notes`, `calendar`, `launcher`, `todo`, `maps`, `camera`, `findfamily`, `contacts`, `appstore`, `weather`, `communicate` and `music` are single merged APKs for phone and watch (watch experience inside the phone app's module; the remaining `*-wear` modules are separate companion APKs with the phone app's applicationId/signing).+`clock`, `notes`, `calendar`, `launcher`, `todo`, `maps`, `camera`, `findfamily`, `contacts`, `appstore`, `weather`, `communicate`, `music`, `email` and `securemail` are single merged APKs for phone and watch (watch experience inside the phone app's module; the remaining `*-wear` modules are separate companion APKs with the phone app's applicationId/signing). `appstore→appstore/` `astronomy→astronomy/` `auto→auto/,auto/protocol/` `backup→backup/` `calculator→calculator/` `calendar→calendar/` `camera→camera/` `cast→cast/,cast/protocol/,cast/tv/` `clock→clock/` `code→code/` `communicate→communicate/` `contacts→contacts/` `education→education/` `email→email/` `emergency→emergency/` `euicc→euicc/` `everysync→everysync/` `files→files/` `findfamily→findfamily/` `findfamily-ios→apple/FindFamily/` (SwiftPM/xtool, not Gradle) `flashcards→flashcards/` `fooddelivery→fooddelivery/` `health→health/` `keyboard→keyboard/` `launcher→launcher/` `logviewer→logviewer/` `maps→maps/` `measure→measure/` `music→music/` `networklocation→networklocation/` `news→news/` `notes→notes/` `office→office/` `openassistant→openassistant/` `passwords→passwords/` `pdf→pdf/` `photos→photos/` `parentalcontrols→parentalcontrols/` `screentime→screentime/` `setupwizard→setupwizard/` `share→share/` `speech→speech/` `taxi→taxi/` `things→things/` `todo→todo/` `translate→translate/` `travel→travel/` `tuner→tuner/` `updater→updater/` `vpn→vpn/` `weather→weather/` `watch→watch/,watch-wear/` `web→web/` `youpipe→youpipe/,youpipe/extractor/` `games-hub→games/hub/` `games-kart→games/kart/` `games-arrows→games/arrows/` `games-chess→games/chess/` `games-logicgate→games/logicgate/` `games-minesweeper→games/minesweeper/` `games-nonogram→games/nonogram/` `games-pipes→games/pipes/` `games-solitaire→games/solitaire/` `games-sudoku→games/sudoku/` `games-unblockjam→games/unblockjam/` `games-voxels→games/voxels/` `games-wordmaker→games/wordmaker/` Slash == colon for Gradle (`games/voxels` == `games:voxels`). 
docs/structure/wear-protocol-pairs.tsv
diff --git a/docs/structure/wear-protocol-pairs.tsv b/docs/structure/wear-protocol-pairs.tsvindex 9438c47c40..5d2b375d55 100644--- a/docs/structure/wear-protocol-pairs.tsv+++ b/docs/structure/wear-protocol-pairs.tsv@@ -18,4 +18,6 @@ # (com.vayunmathur.library.wearlink.findfamily), todo # (com.vayunmathur.library.wearlink.todo), communicate # (com.vayunmathur.library.wearlink.communicate), camera-# (com.vayunmathur.library.wearlink.camera).+# (com.vayunmathur.library.wearlink.camera), email+# (com.vayunmathur.library.wearlink.email), securemail+# (com.vayunmathur.library.wearlink.securemail).
library/wearlink/AGENTS.md
diff --git a/library/wearlink/AGENTS.md b/library/wearlink/AGENTS.mdindex 3ab6caf1ff..83ae14fa09 100644--- a/library/wearlink/AGENTS.md+++ b/library/wearlink/AGENTS.md@@ -31,7 +31,7 @@ duplicated per app pair: each migrated protocol lives in `com.vayunmathur.library.wearlink.<app>` and is consumed by both the phone and wear app modules (which may not depend on each other). Golden-JSON tests stay in each app module and pin the shared code's wire format.-Migrated: clock, launcher, calendar, weather, music, notes, maps, appstore, contacts, findfamily, todo, communicate, camera. Remaining pairs are listed in+Migrated: clock, launcher, calendar, weather, music, notes, maps, appstore, contacts, findfamily, todo, communicate, camera, email, securemail. Remaining pairs are listed in `docs/structure/wear-protocol-pairs.tsv`. The contacts protocol (`contacts/WearContactsProtocol`) carries, additively, each contact's joined messenger platforms per action (call/message/video)
library/wearlink/src/main/java/com/vayunmathur/library/wearlink/email/WearEmailProtocol.kt
diff --git a/library/wearlink/src/main/java/com/vayunmathur/library/wearlink/email/WearEmailProtocol.kt b/library/wearlink/src/main/java/com/vayunmathur/library/wearlink/email/WearEmailProtocol.ktnew file mode 100644index 0000000000..a6725e8286--- /dev/null+++ b/library/wearlink/src/main/java/com/vayunmathur/library/wearlink/email/WearEmailProtocol.kt@@ -0,0 +1,95 @@+package com.vayunmathur.library.wearlink.email++import kotlinx.serialization.Serializable+import kotlinx.serialization.encodeToString+import kotlinx.serialization.json.Json++/**+ * Phone <-> watch protocol for the merged Wear OS Email experience.+ *+ * Shared by both sides of the single merged `:email` APK through+ * `:library:wearlink`. Transport is the Watch conduit+ * (`WearLinkClientNode`, appId `email`): the phone publishes a bounded+ * recent-inbox snapshot as a data item, the watch publishes its+ * received state, and watch-originated ops / snapshot requests are+ * messages. The phone app has no IMAP archive/move primitive (only+ * seen-flag, expunge-delete and snooze), so the only watch write op is+ * mark read/unread; offering a fake archive would either delete mail+ * or hide it under a snooze it would resurface from.+ */+object WearEmailProtocol {+    const val SNAPSHOT_PATH = "/email/snapshot"+    const val WATCH_STATE_PATH = "/email/watch-state"+    const val OP_PATH = "/email/op"+    const val REQUEST_SYNC_PATH = "/email/request-sync"+    const val MAX_MESSAGES = 30+    const val MAX_JSON_BYTES = 90_000+    const val MAX_SENDER_CHARS = 80+    const val MAX_SUBJECT_CHARS = 120+    const val MAX_BODY_CHARS = 4_000+    val json: Json = Json { ignoreUnknownKeys = true }+}++/** One inbox message trimmed to watch size. [id] is `account|folder|uid`. */+@Serializable+data class WearEmailMessage(+    val id: String,+    val accountEmail: String,+    val folderName: String,+    val uid: Long,+    val sender: String,+    val subject: String,+    val dateMillis: Long = 0L,+    val isRead: Boolean = false,+    val body: String = "",+    val bodyTruncated: Boolean = false,+)++@Serializable+data class WearEmailSnapshot(+    val generatedAtMillis: Long = 0L,+    val messages: List<WearEmailMessage> = emptyList(),+    val truncated: Boolean = false,+)++@Serializable+data class WearEmailWatchState(+    val appliedGeneratedAtMillis: Long = 0L,+    val messageCount: Int = 0,+    val pendingOps: Int = 0,+)++@Serializable+enum class WearEmailOpKind { MARK_READ }++@Serializable+data class WearEmailOp(+    val kind: WearEmailOpKind,+    val messageId: String,+    val accountEmail: String,+    val folderName: String,+    val uid: Long,+    val read: Boolean,+)++/** Bounded snapshot: newest first, field caps, then count/byte caps drop oldest. */+fun buildWearEmailSnapshot(candidates: List<WearEmailMessage>, generatedAtMillis: Long): WearEmailSnapshot {+    val sorted = candidates.sortedWith(compareByDescending<WearEmailMessage> { it.dateMillis }.thenByDescending { it.uid })+        .map { m ->+            m.copy(+                sender = m.sender.take(WearEmailProtocol.MAX_SENDER_CHARS),+                subject = m.subject.take(WearEmailProtocol.MAX_SUBJECT_CHARS),+                body = m.body.take(WearEmailProtocol.MAX_BODY_CHARS),+                bodyTruncated = m.bodyTruncated || m.body.length > WearEmailProtocol.MAX_BODY_CHARS,+            )+        }+    var kept = sorted.take(WearEmailProtocol.MAX_MESSAGES)+    var truncated = kept.size < sorted.size+    var snapshot = WearEmailSnapshot(generatedAtMillis, kept, truncated)+    while (kept.isNotEmpty() && WearEmailProtocol.json.encodeToString(snapshot).encodeToByteArray().size > WearEmailProtocol.MAX_JSON_BYTES) {+        kept = kept.dropLast(1)+        truncated = true+        snapshot = snapshot.copy(messages = kept, truncated = true)+    }+    return snapshot+}
library/wearlink/src/main/java/com/vayunmathur/library/wearlink/securemail/WearSecureMailProtocol.kt
diff --git a/library/wearlink/src/main/java/com/vayunmathur/library/wearlink/securemail/WearSecureMailProtocol.kt b/library/wearlink/src/main/java/com/vayunmathur/library/wearlink/securemail/WearSecureMailProtocol.ktnew file mode 100644index 0000000000..c178b4a0db--- /dev/null+++ b/library/wearlink/src/main/java/com/vayunmathur/library/wearlink/securemail/WearSecureMailProtocol.kt@@ -0,0 +1,79 @@+package com.vayunmathur.library.wearlink.securemail++import kotlinx.serialization.Serializable+import kotlinx.serialization.encodeToString+import kotlinx.serialization.json.Json++/**+ * Phone <-> watch protocol for the merged Wear OS SecureMail experience.+ *+ * Security model (stricter, deliberate): PGP private keys and the+ * biometric-gated passphrase stay on the phone, and decrypted content+ * never leaves the phone. The snapshot therefore carries envelope+ * metadata only (sender, date, read state, folder, whether the phone+ * has decrypted the message) — no subject, no body, no preview, all of+ * which are decrypted content in SecureMail. The watch detail shows+ * that metadata plus Open on phone; the only watch write op is mark+ * read/unread, which needs no decrypted data.+ */+object WearSecureMailProtocol {+    const val SNAPSHOT_PATH = "/securemail/snapshot"+    const val WATCH_STATE_PATH = "/securemail/watch-state"+    const val OP_PATH = "/securemail/op"+    const val REQUEST_SYNC_PATH = "/securemail/request-sync"+    const val MAX_MESSAGES = 30+    const val MAX_JSON_BYTES = 90_000+    const val MAX_SENDER_CHARS = 80+    val json: Json = Json { ignoreUnknownKeys = true }+}++/** Envelope metadata only — see [WearSecureMailProtocol] for why there is no subject/body. */+@Serializable+data class WearSecureMessage(+    val id: String,+    val sender: String,+    val dateMillis: Long = 0L,+    val isRead: Boolean = false,+    val folder: String = "INBOX",+    val hasDecryptedBody: Boolean = false,+    val unencrypted: Boolean = false,+)++@Serializable+data class WearSecureMailSnapshot(+    val generatedAtMillis: Long = 0L,+    val messages: List<WearSecureMessage> = emptyList(),+    val truncated: Boolean = false,+)++@Serializable+data class WearSecureMailWatchState(+    val appliedGeneratedAtMillis: Long = 0L,+    val messageCount: Int = 0,+    val pendingOps: Int = 0,+)++@Serializable+enum class WearSecureMailOpKind { MARK_READ }++@Serializable+data class WearSecureMailOp(+    val kind: WearSecureMailOpKind,+    val messageId: String,+    val read: Boolean,+)++/** Bounded metadata snapshot: newest first, sender cap, then count/byte caps. */+fun buildWearSecureMailSnapshot(candidates: List<WearSecureMessage>, generatedAtMillis: Long): WearSecureMailSnapshot {+    val sorted = candidates.sortedByDescending { it.dateMillis }+        .map { it.copy(sender = it.sender.take(WearSecureMailProtocol.MAX_SENDER_CHARS)) }+    var kept = sorted.take(WearSecureMailProtocol.MAX_MESSAGES)+    var truncated = kept.size < sorted.size+    var snapshot = WearSecureMailSnapshot(generatedAtMillis, kept, truncated)+    while (kept.isNotEmpty() && WearSecureMailProtocol.json.encodeToString(snapshot).encodeToByteArray().size > WearSecureMailProtocol.MAX_JSON_BYTES) {+        kept = kept.dropLast(1)+        truncated = true+        snapshot = snapshot.copy(messages = kept, truncated = true)+    }+    return snapshot+}