Modern Apps git

← Modern-Apps.git

contacts: order watch detail actions and add Delete contact

Commit
7f66455b64a4b53ae62d9991ac8e0c57e72276df
Author
Vayun Mathur <[email protected]>
When
2026-12-06 04:27 UTC (8 hours ago)
Parents
bf33568
The watch contact detail listed Open on phone before the call/message/video/email actions and had no delete at all. Actions now come first (with call/message/video/email icons tinted to the chip content color), then Open on phone, then the red Delete contact button directly after it. Delete asks for an inline confirmation, then sends a new /contacts/delete conduit message (WearDeleteContactRequest, golden-JSON pinned); the phone deletes the contact from the provider book via Contact.delete and republishes the snapshot so the watch converges. Nothing follows Delete. Wear screenshots regenerated.

Verified: :contacts:lint, :contacts:lintVitalRelease green; WearContactsProtocolTest green. Two compose UI tests (InsertOrEditIntentActivityPass2Test, DeepInteractionsPass2Test) fail identically on origin/main without this change.

Diff

contacts/AGENTS.md
diff --git a/contacts/AGENTS.md b/contacts/AGENTS.mdindex 5097772a15..01f6af11fd 100644--- a/contacts/AGENTS.md+++ b/contacts/AGENTS.md@@ -38,13 +38,13 @@ are no watch receivers in this module.  ## Wear sync (Watch conduit client) **Protocol:** shared wire types live in `:library:wearlink` at `com.vayunmathur.library.wearlink.contacts.WearContactsProtocol`; the golden-JSON test in this module (`domain/WearContactsProtocolTest`) pins the shared code's wire format.-- Snapshot: phone -> watch as chunked conduit data items plus a manifest (`/contacts/snapshot/...`); each row carries capped phones/emails, the messenger platforms the phone joins for that contact (call/message/video, `WearContactPlatforms`), and a downscaled photo (`photoBase64`: ≤96 px, ≤8,192 decoded bytes per contact, ≤512,000 decoded photo bytes per snapshot; absent/too-large degrades to the letter avatar); watch state: watch -> phone (`/contacts/watch-state`); snapshot request and call/message/video/email handoff (with platform + contact id, phone re-joins provider rows) are watch -> phone conduit messages.+- Snapshot: phone -> watch as chunked conduit data items plus a manifest (`/contacts/snapshot/...`); each row carries capped phones/emails, the messenger platforms the phone joins for that contact (call/message/video, `WearContactPlatforms`), and a downscaled photo (`photoBase64`: ≤96 px, ≤8,192 decoded bytes per contact, ≤512,000 decoded photo bytes per snapshot; absent/too-large degrades to the letter avatar); watch state: watch -> phone (`/contacts/watch-state`); snapshot request, call/message/video/email handoff (with platform + contact id, phone re-joins provider rows), and contact delete (`/contacts/delete`, phone deletes from the provider book and republishes) are watch -> phone conduit messages. - **Transport: Watch conduit client** — phone side `sync/WearContactsSync.kt` and watch side `sync/WearLinkBridge.kt` (with `sync/WearWatchStatePublisher.kt` publishing watch state / requests / handoffs) use `WearLinkClientNode` (Messenger to the Watch app's `watch_conduit` service, appId `contacts`); this app owns no RFCOMM link and holds no Bluetooth permission for this channel, so neither entry activity prompts for Bluetooth. With the Watch app absent the node reports `NotInstalled`/`Unavailable` and the sync stays idle and never crashes the phone UI; snapshots republish on conduit `Connected` and on book changes.-- **Push triggers:** the snapshot publish runs on (1) the phone Watch app's scheduled sync-trigger intent (`sync/ConduitSyncTriggerReceiver`, exported only under the `CONDUIT` signature permission, invoking `WearContactsSync.triggerPush()` — no UI, no prompt), (2) book changes (immediate publish from `MainActivity`), and (3) conduit `Connected`. The watch side has no user-data mutation: its outbound pushes are the immediate watch-state publish and call/message handoff requests via `WearWatchStatePublisher`. Snapshots arriving while the watch process is dead land in the watch conduit's persistent store and replay on registration; the watch copy itself persists in `data/WearContactsStore`.+- **Push triggers:** the snapshot publish runs on (1) the phone Watch app's scheduled sync-trigger intent (`sync/ConduitSyncTriggerReceiver`, exported only under the `CONDUIT` signature permission, invoking `WearContactsSync.triggerPush()` — no UI, no prompt), (2) book changes (immediate publish from `MainActivity`), and (3) conduit `Connected`. The watch side's user-data mutation is the contact-delete request: its outbound pushes are the immediate watch-state publish, call/message handoff requests, and delete requests via `WearWatchStatePublisher`. Snapshots arriving while the watch process is dead land in the watch conduit's persistent store and replay on registration; the watch copy itself persists in `data/WearContactsStore`.  ## Watch experience (in this module) - `ui/WearMainActivity` (a `WearShellActivity`) routes `ui/WearRoute` over the contact list and a detail carrying the contact id.-- `ui/WearContactsApp` dispatches that route to `ui/WearContactListScreen` (local search over the synced copy; photo/letter avatar per row) and `ui/WearContactDetailScreen` (photo/letter avatar plus the phone-parity call, message, video call and email actions — system and WhatsApp/Signal/Telegram/Meet platforms — filtered by `WearActionPolicy` to only what this watch can complete itself or hand off to a reachable phone; no dead taps, via `platform/WearDeviceCapabilities` including the Meet video-handler probe).+- `ui/WearContactsApp` dispatches that route to `ui/WearContactListScreen` (local search over the synced copy; photo/letter avatar per row) and `ui/WearContactDetailScreen` (photo/letter avatar plus the phone-parity call, message, video call and email actions — system and WhatsApp/Signal/Telegram/Meet platforms — filtered by `WearActionPolicy` to only what this watch can complete itself or hand off to a reachable phone; no dead taps, via `platform/WearDeviceCapabilities` including the Meet video-handler probe; Open on phone is the last action button, followed only by the red Delete contact button, which asks the phone to delete the contact after an inline confirmation). - Watch state persists in `data/WearContactsStore` (`contacts_snapshot.json` + `contacts_manifest.json` in filesDir). - Watch listing screenshots are the `group = "wear"` previews in `src/screenshotTest/.../ui/WearMetadataPreviews.kt`, collected by `:contacts:metadata` into `metadata_data/photos/contacts/wear/`; phone shots use the `phone` bucket. **Gotchas:**
contacts/src/main/java/com/vayunmathur/contacts/sync/WearContactsSync.kt
diff --git a/contacts/src/main/java/com/vayunmathur/contacts/sync/WearContactsSync.kt b/contacts/src/main/java/com/vayunmathur/contacts/sync/WearContactsSync.ktindex bc4f0613b5..e855309762 100644--- a/contacts/src/main/java/com/vayunmathur/contacts/sync/WearContactsSync.kt+++ b/contacts/src/main/java/com/vayunmathur/contacts/sync/WearContactsSync.kt@@ -15,6 +15,7 @@ import com.vayunmathur.contacts.ui.placePlatformCall import com.vayunmathur.library.wearlink.contacts.WearContactPlatforms import com.vayunmathur.library.wearlink.contacts.WearContactsManifest import com.vayunmathur.library.wearlink.contacts.WearContactsProtocol+import com.vayunmathur.library.wearlink.contacts.WearDeleteContactRequest import com.vayunmathur.library.wearlink.contacts.WearHandoffRequest import com.vayunmathur.library.wearlink.contacts.WearPresence import com.vayunmathur.library.wearlink.contacts.WearPresencePolicy@@ -140,6 +141,7 @@ class WearContactsSync(             when (path) {                 WearContactsProtocol.REQUEST_SNAPSHOT_PATH -> republish()                 WearContactsProtocol.HANDOFF_PATH -> handleHandoff(body)+                WearContactsProtocol.DELETE_PATH -> handleDelete(body)             }         }     }@@ -231,6 +233,21 @@ class WearContactsSync(         }     } +    /** Watch asked to delete a contact: delete it from the phone's provider book, then republish. */+    private fun handleDelete(data: ByteArray) {+        val request = runCatching {+            WearContactsProtocol.json.decodeFromString<WearDeleteContactRequest>(data.decodeToString())+        }.getOrNull() ?: return+        if (request.contactId == 0L) return+        scope.launch(Dispatchers.IO) {+            runCatching {+                val contact = Contact.getContact(context, request.contactId)+                if (contact != null) Contact.delete(context, contact)+            }.onFailure { Log.status(TAG, "watch delete failed: ${it.message}") }+            republish()+        }+    }+     private fun handleHandoff(data: ByteArray) {         val request = runCatching {             WearContactsProtocol.json.decodeFromString<WearHandoffRequest>(data.decodeToString())
contacts/src/main/java/com/vayunmathur/contacts/sync/WearWatchStatePublisher.kt
diff --git a/contacts/src/main/java/com/vayunmathur/contacts/sync/WearWatchStatePublisher.kt b/contacts/src/main/java/com/vayunmathur/contacts/sync/WearWatchStatePublisher.ktindex 89d3491eb2..b2edbbedc8 100644--- a/contacts/src/main/java/com/vayunmathur/contacts/sync/WearWatchStatePublisher.kt+++ b/contacts/src/main/java/com/vayunmathur/contacts/sync/WearWatchStatePublisher.kt@@ -3,6 +3,7 @@ package com.vayunmathur.contacts.sync import android.content.Context import com.vayunmathur.contacts.data.WearSnapshot import com.vayunmathur.library.wearlink.contacts.WearContactsProtocol+import com.vayunmathur.library.wearlink.contacts.WearDeleteContactRequest import com.vayunmathur.library.wearlink.contacts.WearHandoffRequest import com.vayunmathur.library.wearlink.contacts.WearWatchState import com.vayunmathur.library.log.Log@@ -32,6 +33,16 @@ object WearWatchStatePublisher {         sendToPhone(context, WearContactsProtocol.REQUEST_SNAPSHOT_PATH, byteArrayOf())     } +    /** Ask the phone to delete this contact (the phone owns the provider book). */+    suspend fun requestDelete(context: Context, contactId: Long) {+        sendToPhone(+            context,+            WearContactsProtocol.DELETE_PATH,+            WearContactsProtocol.json.encodeToString(WearDeleteContactRequest(contactId))+                .encodeToByteArray(),+        )+    }+     /** Ask the phone to start a call/message this watch cannot start itself. */     suspend fun requestHandoff(context: Context, request: WearHandoffRequest) {         sendToPhone(
contacts/src/main/java/com/vayunmathur/contacts/ui/WearContactDetailScreen.kt
diff --git a/contacts/src/main/java/com/vayunmathur/contacts/ui/WearContactDetailScreen.kt b/contacts/src/main/java/com/vayunmathur/contacts/ui/WearContactDetailScreen.ktindex 1b7e94a448..d8d0b51199 100644--- a/contacts/src/main/java/com/vayunmathur/contacts/ui/WearContactDetailScreen.kt+++ b/contacts/src/main/java/com/vayunmathur/contacts/ui/WearContactDetailScreen.kt@@ -9,7 +9,11 @@ import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.runtime.Composable+import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope+import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext@@ -20,13 +24,20 @@ import androidx.wear.compose.foundation.lazy.ScalingLazyColumn import androidx.wear.compose.foundation.lazy.items import androidx.wear.compose.material.Chip import androidx.wear.compose.material.ChipDefaults+import androidx.wear.compose.material.LocalContentColor import androidx.wear.compose.material.MaterialTheme import androidx.wear.compose.material.Scaffold import androidx.wear.compose.material.Text import androidx.wear.compose.material.TimeText import com.vayunmathur.contacts.platform.PackageUtils import com.vayunmathur.contacts.platform.WearDeviceCapabilities+import com.vayunmathur.library.ui.IconCall+import com.vayunmathur.library.ui.IconDelete+import com.vayunmathur.library.ui.IconMail import com.vayunmathur.library.ui.IconMobileArrowRight+import com.vayunmathur.library.ui.IconSms+import com.vayunmathur.library.ui.IconVideoCamera+import com.vayunmathur.library.wearlink.wearDeleteItem import com.vayunmathur.library.wearlink.wearOpenOnPhoneItem import com.vayunmathur.contacts.sync.WearLinkBridge import com.vayunmathur.contacts.sync.WearWatchStatePublisher@@ -49,7 +60,9 @@ import kotlinx.coroutines.launch fun WearContactDetailScreen(     contact: WearContact,     capabilities: WearDeviceCapabilities,+    onDeleted: () -> Unit = {}, ) {+    var confirmingDelete by remember { mutableStateOf(false) }     val context = LocalContext.current     val scope = rememberCoroutineScope()     val actions = WearActionPolicy.actionsFor(@@ -99,7 +112,6 @@ fun WearContactDetailScreen(                     modifier = Modifier.fillMaxWidth().padding(horizontal = 12.dp, vertical = 2.dp),                 )             }-            wearOpenOnPhoneItem(onClick = { scope.launch { WearLinkBridge.get(context).sendMessage("/contacts/open-on-phone", ByteArray(0)) } }, icon = { IconMobileArrowRight(tint = androidx.compose.ui.graphics.Color.White) })             items(actions) { option ->                 Chip(                     onClick = {@@ -110,14 +122,66 @@ fun WearContactDetailScreen(                         }                     },                     label = { Text(actionLabel(option), maxLines = 1) },+                    icon = { actionIcon(option) },                     colors = ChipDefaults.primaryChipColors(),                     modifier = Modifier.fillMaxWidth().padding(horizontal = 8.dp),                 )             }+            wearOpenOnPhoneItem(+                onClick = {+                    scope.launch {+                        WearLinkBridge.get(context)+                            .sendMessage("/contacts/open-on-phone", ByteArray(0))+                    }+                },+                icon = { IconMobileArrowRight(tint = LocalContentColor.current) },+            )+            if (confirmingDelete) {+                item {+                    Chip(+                        onClick = {+                            scope.launch {+                                WearWatchStatePublisher.requestDelete(context, contact.id)+                            }+                            onDeleted()+                        },+                        label = { Text("Confirm delete", maxLines = 1) },+                        icon = { IconDelete(tint = LocalContentColor.current) },+                        colors = ChipDefaults.primaryChipColors(),+                        modifier = Modifier.fillMaxWidth().padding(horizontal = 8.dp),+                    )+                }+                item {+                    Chip(+                        onClick = { confirmingDelete = false },+                        label = { Text("Cancel", maxLines = 1) },+                        colors = ChipDefaults.secondaryChipColors(),+                        modifier = Modifier.fillMaxWidth().padding(horizontal = 8.dp),+                    )+                }+            } else {+                wearDeleteItem(+                    label = "Delete contact",+                    onClick = { confirmingDelete = true },+                    icon = { IconDelete(tint = LocalContentColor.current) },+                )+            }         }     } } +/** Leading glyph for one comm action; tinted with the chip's content color by the caller seam. */+@Composable+private fun actionIcon(option: WearActionOption) {+    val tint = LocalContentColor.current+    when (option.action) {+        WearAction.CALL_ON_WATCH, WearAction.CALL_VIA_PHONE -> IconCall(tint = tint)+        WearAction.MESSAGE_ON_WATCH, WearAction.MESSAGE_VIA_PHONE -> IconSms(tint = tint)+        WearAction.VIDEO_ON_WATCH, WearAction.VIDEO_VIA_PHONE -> IconVideoCamera(tint = tint)+        WearAction.EMAIL_ON_WATCH, WearAction.EMAIL_VIA_PHONE -> IconMail(tint = tint)+    }+}+ private fun platformLabel(platform: String): String? = when (platform) {     WearContactsProtocol.PLATFORM_SIGNAL -> "Signal"     WearContactsProtocol.PLATFORM_WHATSAPP -> "WhatsApp"
contacts/src/main/java/com/vayunmathur/contacts/ui/WearContactsApp.kt
diff --git a/contacts/src/main/java/com/vayunmathur/contacts/ui/WearContactsApp.kt b/contacts/src/main/java/com/vayunmathur/contacts/ui/WearContactsApp.ktindex 43379c5da1..d2b9167664 100644--- a/contacts/src/main/java/com/vayunmathur/contacts/ui/WearContactsApp.kt+++ b/contacts/src/main/java/com/vayunmathur/contacts/ui/WearContactsApp.kt@@ -37,7 +37,10 @@ fun WearContactsApp(         is WearRoute.ContactDetail -> {             val contact = snapshot.contacts.firstOrNull { it.id == route.contactId }             if (contact != null) {-                WearContactDetailScreen(contact, capabilities)+                WearContactDetailScreen(+                    contact, capabilities,+                    onDeleted = { navigate(WearRoute.ContactList) },+                )             } else {                 // Contact left the snapshot (deleted/resynced): never a blank screen.                 ScalingLazyColumn {
contacts/src/test/java/com/vayunmathur/contacts/domain/WearContactsProtocolTest.kt
diff --git a/contacts/src/test/java/com/vayunmathur/contacts/domain/WearContactsProtocolTest.kt b/contacts/src/test/java/com/vayunmathur/contacts/domain/WearContactsProtocolTest.ktindex 84efdfd791..3828f20c35 100644--- a/contacts/src/test/java/com/vayunmathur/contacts/domain/WearContactsProtocolTest.kt+++ b/contacts/src/test/java/com/vayunmathur/contacts/domain/WearContactsProtocolTest.kt@@ -6,6 +6,7 @@ import com.vayunmathur.library.wearlink.contacts.WearActionPolicy import com.vayunmathur.library.wearlink.contacts.WearContact import com.vayunmathur.library.wearlink.contacts.WearContactPlatforms import com.vayunmathur.library.wearlink.contacts.WearContactSearch+import com.vayunmathur.library.wearlink.contacts.WearDeleteContactRequest import com.vayunmathur.library.wearlink.contacts.WearHandoffRequest import com.vayunmathur.library.wearlink.contacts.WearContactsChunk import com.vayunmathur.library.wearlink.contacts.WearContactsManifest@@ -40,6 +41,15 @@ class WearContactsProtocolTest {         assertNull(WearContactsProtocol.chunkIndexFromPath(WearContactsProtocol.MANIFEST_PATH))     } +    @Test+    fun `delete request wire json is stable`() {+        assertEquals("/contacts/delete", WearContactsProtocol.DELETE_PATH)+        assertEquals(+            "{\"contactId\":42}",+            WearContactsProtocol.json.encodeToString(WearDeleteContactRequest(42L)),+        )+    }+     @Test     fun `photo and platforms are additive and old snapshots still decode`() {         val withPhoto = WearContact(
library/wearlink/src/main/java/com/vayunmathur/library/wearlink/contacts/WearContactsProtocol.kt
diff --git a/library/wearlink/src/main/java/com/vayunmathur/library/wearlink/contacts/WearContactsProtocol.kt b/library/wearlink/src/main/java/com/vayunmathur/library/wearlink/contacts/WearContactsProtocol.ktindex 273103d4a8..f7aaafb538 100644--- a/library/wearlink/src/main/java/com/vayunmathur/library/wearlink/contacts/WearContactsProtocol.kt+++ b/library/wearlink/src/main/java/com/vayunmathur/library/wearlink/contacts/WearContactsProtocol.kt@@ -50,6 +50,9 @@ object WearContactsProtocol {     /** Message path (watch -> phone): start this call/message on the phone. */     const val HANDOFF_PATH = "/contacts/handoff" +    /** Message path (watch -> phone): delete this contact on the phone. */+    const val DELETE_PATH = "/contacts/delete"+     /** Hard cap on contacts ever sent to the watch. */     const val MAX_CONTACTS = 1_000 @@ -159,6 +162,13 @@ data class WearWatchState(     val receivedAtMillis: Long = 0L, ) +/** A contact the watch asks the phone to delete ([WearContactsProtocol.DELETE_PATH]). */+@Serializable+data class WearDeleteContactRequest(+    /** Snapshot contact id (the phone's provider contact id). */+    val contactId: Long = 0L,+)+ /** A call/message/video/email the watch asks the phone to start. */ @Serializable data class WearHandoffRequest(
metadata_data/photos/contacts/wear/1.png
diff --git a/metadata_data/photos/contacts/wear/1.png b/metadata_data/photos/contacts/wear/1.pngindex 18e236c892..3b40376952 100644Binary files a/metadata_data/photos/contacts/wear/1.png and b/metadata_data/photos/contacts/wear/1.png differ
metadata_data/photos/contacts/wear/2.png
diff --git a/metadata_data/photos/contacts/wear/2.png b/metadata_data/photos/contacts/wear/2.pngindex 6b70a10eeb..6d22268280 100644Binary files a/metadata_data/photos/contacts/wear/2.png and b/metadata_data/photos/contacts/wear/2.png differ