Modern Apps git

← Modern-Apps.git

contacts: merge contacts-wear into the single contacts APK

Commit
b01c0dec75d7599155bfcca77226ae6657fbc621
Author
Vayun Mathur <[email protected]>
When
2026-12-04 18:20 UTC (1 day ago)
Parents
72f9aef
Owner directive: singular apps that detect when they are on a watch
and adapt, instead of a separate *-wear APK per companion. Contacts
follows the merged clock pilot.

The merged :contacts APK keeps applicationId
com.vayunmathur.contacts and the convention signing on both form
factors, as the WearLink handshake requires; neither side's identity
changed. Runtime detection is PackageManager.FEATURE_WATCH
(platform/FormFactor): MainActivity, the sole launcher entry,
forwards watches to ui/WearMainActivity before any phone state
(contacts permission gate, phone snapshot sync, pick/import flows)
is touched, and phones keep the existing list/detail/edit UI,
including SIM contacts and calendar birthday sync. The wear launcher
activity loses its LAUNCHER filter (exported=false); there are no
watch receivers in this module. The manifest declares no
android.hardware.type.watch feature (required=true would block
phones, required=false is disallowed for it), plus touchscreen
not-required and standalone=true for the watch's offline copy.

All contacts-wear sources move into contacts' closed package roots
(wear/data -> data, wear/platform -> platform, wear/sync -> sync,
wear/ui -> ui as Wear* screens routed by ui/WearRoute through the
WearShellActivity instead of a separate Navigation3 stack), and the
wear snapshot reassembler tests move with them. The wear
WearContactsProtocolTest copy is dropped because :contacts already
pins the same golden JSON. Watch screenshot previews become
ui/WearMetadataPreviews with group=wear, so :contacts:metadata
renders them into metadata_data/photos/contacts/wear/ (the old
contacts-wear bucket's captures move there). The contacts-wear
module, its settings include and its AGENTS.md are deleted; root
and contacts AGENTS.md describe the merged state.

Verified fresh on devvm21958: :contacts:clean plus
:contacts:lint and :contacts:lintVitalRelease green, and
:contacts:compileDevScreenshotTestKotlin green. Baseline at HEAD
had :contacts:testDevUnitTest at 602 tests with 2 failures
(InsertOrEditIntentActivityPass2Test.insertOrEditShowsNumber and
DeepInteractionsPass2Test.insertOrEditShowsContactsAndCreateNewRoutes);
the merged run has 608 tests (the moved reassembler tests plus new
FormFactorTest) with those same 2 failures plus
CropCanvasPass2Test.cropCanvasDrawsAndHandlesDrag, which passes in
isolation and touches no wear code, i.e. no new test regression.
Only a real watch can confirm install, FEATURE_WATCH routing and
the Wear OS surface.

Diff

AGENTS.md
diff --git a/AGENTS.md b/AGENTS.mdindex 97dc773dbe..89c95faa7b 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` and `findfamily` 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` and `contacts` 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-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`). 
contacts-wear/AGENTS.md
diff --git a/contacts-wear/AGENTS.md b/contacts-wear/AGENTS.mddeleted file mode 100644index a90e0180bb..0000000000--- a/contacts-wear/AGENTS.md+++ /dev/null@@ -1,17 +0,0 @@-# AGENTS.md — contacts-wear/ (':contacts-wear')--> Scoped supplement. Global rules in root `AGENTS.md` apply. Stay inside-> `contacts-wear/` + `contacts/` (phone side) only.--- Gradle: :contacts-wear / dir: contacts-wear/-- applicationId: `com.vayunmathur.contacts` — MUST stay equal to `:contacts`;-  WearLink's handshake requires same signing on phone and watch (same package kept).-- Package: `com.vayunmathur.contacts.wear` (domain/data/sync/ui/platform)-- Protocol: the wire protocol lives in `:library:wearlink` at-  `com.vayunmathur.library.wearlink.contacts.WearContactsProtocol` (shared by-  `:contacts` and `:contacts-wear`; neither app module depends on the other).-  Each side's `WearContactsProtocolTest` pins the same golden JSON against-  that shared code.-- Verify: `./gradlew :contacts-wear:assembleDev :contacts-wear:testDebugUnitTest`-  (wear convention has no `dev` testBuildType wiring beyond its build types;-  use the test task Gradle registers for the module.)
contacts-wear/build.gradle.kts
diff --git a/contacts-wear/build.gradle.kts b/contacts-wear/build.gradle.ktsdeleted file mode 100644index 20af656b42..0000000000--- a/contacts-wear/build.gradle.kts+++ /dev/null@@ -1,38 +0,0 @@-plugins {-    id("common-conventions-wear")-    id("common-conventions-preview-metadata")-}--launcherIcon {-    symbol = "person"-}--// Version shared with the phone app (root version.txt), read directly because-// common-conventions-wear inlines 1/"1.0" until a wear consumer wires the shared reader.-val wearVersionLines = file("../version.txt").readLines()-val wearVersionCode = wearVersionLines[0].trim().toInt()-val wearVersionName = wearVersionLines[1].trim()--android {-    // The convention derives a hyphenated namespace from the project path; pin the real one.-    namespace = "com.vayunmathur.contacts.wear"-    defaultConfig {-        // CRITICAL: Wearable Data Layer only connects same package + same signing.-        // This must equal :contacts' applicationId; dev builds on both sides use-        // the debug key, release builds on both sides use the same release key.-        applicationId = "com.vayunmathur.contacts"-        // Repo libraries (:library:log) are minSdk 31; the wear convention's 30 cannot merge.-        minSdk = 31-        versionCode = wearVersionCode-        versionName = wearVersionName-    }-}--dependencies {-    implementation(libs.kotlinx.coroutines.android)-    implementation(project(":library:wearlink"))-    implementation(libs.androidx.navigation3.runtime)-    implementation(libs.androidx.navigation3.ui)-    testImplementation(libs.kotlin.test)-    testImplementation(libs.kotlin.test.junit)-}
contacts-wear/src/main/AndroidManifest.xml
diff --git a/contacts-wear/src/main/AndroidManifest.xml b/contacts-wear/src/main/AndroidManifest.xmldeleted file mode 100644index b741198992..0000000000--- a/contacts-wear/src/main/AndroidManifest.xml+++ /dev/null@@ -1,36 +0,0 @@-<?xml version="1.0" encoding="utf-8"?>-<manifest xmlns:android="http://schemas.android.com/apk/res/android">--    <!-- Wear OS watch hardware: this APK only installs on watches. -->-    <uses-feature android:name="android.hardware.type.watch" android:required="true" />--    <!-- Direct calls are attempted only when telephony is present (checked at runtime). -->-    <uses-feature android:name="android.hardware.telephony" android:required="false" />--    <uses-permission android:name="android.permission.CALL_PHONE" />--    <application-        android:allowBackup="false"-        android:icon="@mipmap/ic_launcher"-        android:label="@string/app_name"-        android:roundIcon="@mipmap/ic_launcher"-        android:supportsRtl="true"-        android:theme="@android:style/Theme.DeviceDefault">-        <!-- Standalone: renders/searches its locally synced copy without the phone. -->-        <meta-data-            android:name="com.google.android.wearable.standalone"-            android:value="true" />--        <activity-            android:name=".MainActivity"-            android:exported="true"-            android:theme="@android:style/Theme.DeviceDefault.NoActionBar">-            <intent-filter>-                <action android:name="android.intent.action.MAIN" />-                <category android:name="android.intent.category.LAUNCHER" />-            </intent-filter>-        </activity>--        <!-- WearLink delivery is app-lifecycle-bound; no system listener service. -->-    </application>-</manifest>
contacts-wear/src/main/java/com/vayunmathur/contacts/wear/Route.kt
diff --git a/contacts-wear/src/main/java/com/vayunmathur/contacts/wear/Route.kt b/contacts-wear/src/main/java/com/vayunmathur/contacts/wear/Route.ktdeleted file mode 100644index 6edbcb68c8..0000000000--- a/contacts-wear/src/main/java/com/vayunmathur/contacts/wear/Route.kt+++ /dev/null@@ -1,14 +0,0 @@-package com.vayunmathur.contacts.wear--import androidx.navigation3.runtime.NavKey-import kotlinx.serialization.Serializable--/** Navigation destinations for the wear companion: list, and detail carrying its contact id. */-sealed interface Route : NavKey {--    @Serializable-    data object ContactList : Route--    @Serializable-    data class ContactDetail(val contactId: Long) : Route-}
contacts-wear/src/main/java/com/vayunmathur/contacts/wear/ui/WearContactsApp.kt
diff --git a/contacts-wear/src/main/java/com/vayunmathur/contacts/wear/ui/WearContactsApp.kt b/contacts-wear/src/main/java/com/vayunmathur/contacts/wear/ui/WearContactsApp.ktdeleted file mode 100644index 3d2c134561..0000000000--- a/contacts-wear/src/main/java/com/vayunmathur/contacts/wear/ui/WearContactsApp.kt+++ /dev/null@@ -1,80 +0,0 @@-package com.vayunmathur.contacts.wear.ui--import androidx.compose.foundation.layout.fillMaxWidth-import androidx.compose.foundation.layout.padding-import androidx.compose.runtime.Composable-import androidx.compose.runtime.getValue-import androidx.compose.runtime.mutableStateOf-import androidx.compose.runtime.remember-import androidx.compose.runtime.setValue-import androidx.compose.ui.Modifier-import androidx.compose.ui.text.style.TextAlign-import androidx.compose.ui.unit.dp-import androidx.navigation3.runtime.entryProvider-import androidx.navigation3.runtime.rememberNavBackStack-import androidx.navigation3.ui.NavDisplay-import androidx.wear.compose.foundation.lazy.ScalingLazyColumn-import androidx.wear.compose.material.Chip-import androidx.wear.compose.material.ChipDefaults-import androidx.wear.compose.material.MaterialTheme-import androidx.wear.compose.material.Text-import com.vayunmathur.contacts.wear.Route-import com.vayunmathur.contacts.wear.data.WearSnapshot-import com.vayunmathur.contacts.wear.platform.WearDeviceCapabilities--/** Wear app root: Navigation3 back stack (list -> detail carrying the contact id). */-@Composable-fun WearContactsApp(-    snapshot: WearSnapshot,-    capabilities: WearDeviceCapabilities,-) {-    val backStack = rememberNavBackStack(Route.ContactList)-    var query by remember { mutableStateOf("") }-    MaterialTheme {-        NavDisplay(-            backStack = backStack,-            onBack = { if (backStack.size > 1) backStack.removeAt(backStack.lastIndex) },-            entryProvider = entryProvider {-                entry<Route.ContactList> {-                    ContactListScreen(-                        snapshot = snapshot,-                        query = query,-                        onQueryChange = { query = it },-                        onContactClick = { backStack.add(Route.ContactDetail(it.id)) },-                    )-                }-                entry<Route.ContactDetail> { route ->-                    val contact = snapshot.contacts.firstOrNull { it.id == route.contactId }-                    if (contact != null) {-                        ContactDetailScreen(contact, capabilities)-                    } else {-                        // Contact left the snapshot (deleted/resynced): never a blank screen.-                        ScalingLazyColumn {-                            item {-                                Text(-                                    text = "This contact is no longer on this watch.",-                                    style = MaterialTheme.typography.body2,-                                    textAlign = TextAlign.Center,-                                    modifier = Modifier.fillMaxWidth()-                                        .padding(horizontal = 12.dp, vertical = 4.dp),-                                )-                            }-                            item {-                                Chip(-                                    onClick = {-                                        if (backStack.size > 1) {-                                            backStack.removeAt(backStack.lastIndex)-                                        }-                                    },-                                    label = { Text("Back", maxLines = 1) },-                                    colors = ChipDefaults.secondaryChipColors(),-                                    modifier = Modifier.fillMaxWidth().padding(horizontal = 8.dp),-                                )-                            }-                        }-                    }-                }-            },-        )-    }-}
contacts-wear/src/main/res/values/ic_launcher_background.xml
diff --git a/contacts-wear/src/main/res/values/ic_launcher_background.xml b/contacts-wear/src/main/res/values/ic_launcher_background.xmldeleted file mode 100644index ddfa876dd8..0000000000--- a/contacts-wear/src/main/res/values/ic_launcher_background.xml+++ /dev/null@@ -1,5 +0,0 @@-<?xml version="1.0" encoding="utf-8"?>-<resources>-    <!-- Generated adaptive icon (launcherIcon symbol) references this; :library provides it on phones. -->-    <color name="ic_launcher_background">#FFFFFF</color>-</resources>
contacts-wear/src/main/res/values/strings.xml
diff --git a/contacts-wear/src/main/res/values/strings.xml b/contacts-wear/src/main/res/values/strings.xmldeleted file mode 100644index a800fdf005..0000000000--- a/contacts-wear/src/main/res/values/strings.xml+++ /dev/null@@ -1,4 +0,0 @@-<?xml version="1.0" encoding="utf-8"?>-<resources>-    <string name="app_name">Contacts</string>-</resources>
contacts-wear/src/test/java/com/vayunmathur/contacts/wear/domain/WearContactsProtocolTest.kt
diff --git a/contacts-wear/src/test/java/com/vayunmathur/contacts/wear/domain/WearContactsProtocolTest.kt b/contacts-wear/src/test/java/com/vayunmathur/contacts/wear/domain/WearContactsProtocolTest.ktdeleted file mode 100644index 03c7b1aa14..0000000000--- a/contacts-wear/src/test/java/com/vayunmathur/contacts/wear/domain/WearContactsProtocolTest.kt+++ /dev/null@@ -1,119 +0,0 @@-package com.vayunmathur.contacts.wear.domain--import com.vayunmathur.library.wearlink.contacts.WearAction-import com.vayunmathur.library.wearlink.contacts.WearActionPolicy-import com.vayunmathur.library.wearlink.contacts.WearContact-import com.vayunmathur.library.wearlink.contacts.WearContactSearch-import com.vayunmathur.library.wearlink.contacts.WearContactsChunk-import com.vayunmathur.library.wearlink.contacts.WearContactsManifest-import com.vayunmathur.library.wearlink.contacts.WearContactsProtocol-import com.vayunmathur.library.wearlink.contacts.WearPresence-import com.vayunmathur.library.wearlink.contacts.WearPresencePolicy-import com.vayunmathur.library.wearlink.contacts.WearSnapshotBuilder-import kotlin.test.Test-import kotlin.test.assertEquals-import kotlin.test.assertFalse-import kotlin.test.assertNull-import kotlin.test.assertTrue-import kotlinx.serialization.encodeToString--class WearContactsProtocolTest {--    @Test-    fun `golden wire json is stable across both apps`() {-        // The wear module pins these exact strings in its own copy of this test.-        val chunk = WearContactsChunk(7L, 0, listOf(WearContact(1L, "Ada", listOf("123"), emptyList(), true)))-        assertEquals(-            """{"generation":7,"index":0,"contacts":[{"id":1,"name":"Ada","phones":["123"],"isFavorite":true}]}""",-            WearContactsProtocol.json.encodeToString(chunk),-        )-        val manifest = WearContactsManifest(7L, 2, 3000, 1000, true, 99L)-        assertEquals(-            """{"generation":7,"chunkCount":2,"totalContacts":3000,"includedContacts":1000,"truncated":true,"sentAtMillis":99}""",-            WearContactsProtocol.json.encodeToString(manifest),-        )-        assertEquals("/contacts/snapshot/chunk/3", WearContactsProtocol.chunkPath(3))-        assertEquals(3, WearContactsProtocol.chunkIndexFromPath("/contacts/snapshot/chunk/3"))-        assertNull(WearContactsProtocol.chunkIndexFromPath(WearContactsProtocol.MANIFEST_PATH))-    }--    @Test-    fun `cap keeps favourites first then A-Z and says it truncated`() {-        val many = (1..1_005).map { WearContact(it.toLong(), "Person %04d".format(it)) } +-            WearContact(9_999L, "Zed Favourite", isFavorite = true)-        val selected = WearSnapshotBuilder.select(many)-        assertEquals(WearContactsProtocol.MAX_CONTACTS, selected.size)-        assertEquals("Zed Favourite", selected.first().name)-        assertEquals("Person 0001", selected[1].name)-        val manifest = WearSnapshotBuilder.manifest(1L, many.size, selected, 1, 0L)-        assertTrue(manifest.truncated)-        assertEquals(many.size, manifest.totalContacts)-    }--    @Test-    fun `per-contact lists and fields are capped`() {-        val raw = WearContact(-            id = 1L,-            name = "N".repeat(200),-            phones = listOf("1", "2", "3", "4", "1", "  "),-            emails = listOf("a@x", "b@x", "c@x", "d@x"),-        )-        val selected = WearSnapshotBuilder.select(listOf(raw)).single()-        assertEquals(WearContactsProtocol.MAX_NAME_CHARS, selected.name.length)-        assertEquals(listOf("1", "2", "3"), selected.phones)-        assertEquals(3, selected.emails.size)-    }--    @Test-    fun `chunks stay under the byte cap and cover every contact once`() {-        val selected = WearSnapshotBuilder.select(-            (1..600).map {-                WearContact(it.toLong(), "Person Number $it With A Fairly Long Name", listOf("+1 415 555 %04d".format(it)), listOf("[email protected]"))-            },-        )-        val chunks = WearSnapshotBuilder.chunk(42L, selected)-        assertTrue(chunks.size > 1, "600 contacts must chunk")-        for (chunk in chunks) {-            val bytes = WearContactsProtocol.json.encodeToString(chunk).encodeToByteArray().size-            assertTrue(bytes <= WearContactsProtocol.MAX_CHUNK_BYTES, "chunk ${chunk.index} is $bytes bytes")-        }-        assertEquals(selected, chunks.flatMap { it.contacts })-        assertEquals(chunks.indices.toList(), chunks.map { it.index })-        assertTrue(chunks.all { it.generation == 42L })-    }--    @Test-    fun `search matches name phone digits and email by token`() {-        val contacts = listOf(-            WearContact(1L, "Ada Lovelace", listOf("+1 (415) 555-0100"), listOf("[email protected]")),-            WearContact(2L, "Grace Hopper", listOf("+1 202 555 0199")),-        )-        assertEquals(contacts, WearContactSearch.filter(contacts, ""))-        assertEquals(listOf(contacts[0]), WearContactSearch.filter(contacts, "ada"))-        assertEquals(listOf(contacts[0]), WearContactSearch.filter(contacts, "415 0100"))-        assertEquals(listOf(contacts[0]), WearContactSearch.filter(contacts, "ADA example"))-        assertEquals(emptyList(), WearContactSearch.filter(contacts, "hopper 0100"))-    }--    @Test-    fun `capability absent means no watch presence and no dead buttons`() {-        assertEquals(WearPresence.NO_WATCH, WearPresencePolicy.presence(0, null))-        assertFalse(WearPresencePolicy.statusText(WearPresence.NO_WATCH, null).contains("synced", ignoreCase = true))-        val contact = WearContact(1L, "Ada", listOf("123"), listOf("a@x"))-        // No handlers, no phone: nothing is offered.-        assertEquals(-            emptyList(),-            WearActionPolicy.actionsFor(contact, hasTelephony = false, hasSmsHandler = false, hasEmailHandler = false, phoneReachable = false),-        )-        // Phone reachable only: handoffs, never a fake on-watch call.-        assertEquals(-            listOf(WearAction.CALL_VIA_PHONE, WearAction.MESSAGE_VIA_PHONE),-            WearActionPolicy.actionsFor(contact, hasTelephony = false, hasSmsHandler = false, hasEmailHandler = false, phoneReachable = true),-        )-        // Telephony watch prefers its own call; email needs a handler.-        assertEquals(-            listOf(WearAction.CALL_ON_WATCH),-            WearActionPolicy.actionsFor(contact, hasTelephony = true, hasSmsHandler = false, hasEmailHandler = false, phoneReachable = false),-        )-    }-}
contacts/AGENTS.md
diff --git a/contacts/AGENTS.md b/contacts/AGENTS.mdindex 5a60f8e9f1..414f887847 100644--- a/contacts/AGENTS.md+++ b/contacts/AGENTS.md@@ -4,9 +4,9 @@  _Install: ./install contacts (dev by default)._ - Gradle: :contacts / dir: contacts/-- Package roots present: ui, data, intents, platform-- Entry files: MainActivity.kt, Route.kt, Navigation.kt-- Deps: (none — contacts provider + account framework only)+- Package roots present: ui, data, domain, intents, platform, sync+- Entry files: MainActivity.kt (sole launcher; routes watches to WearMainActivity), Route.kt, Navigation.kt, ui/WearMainActivity.kt+- Deps: :library:wearlink, Wear Compose (material + foundation), androidx.work — plus contacts provider + account framework - Metadata: metadata_data/contacts.md (present) - Rust: no / screenshotTest: yes @@ -18,6 +18,33 @@ _Install: ./install contacts (dev by default)._ - Optional calendar birthday sync (`CalendarSyncHelper` + `CalendarWorker`); everysync is the sync story, not this app **Architecture / data-flow:** `ui/` list/detail/edit pages (+ `ui/dialogs/`) → `util/ContactViewModel` (+ split `Accounts`/`Draft` helpers, `ContactsUiContract`) → `data/` models over the system contacts provider (`Contact`/`ContactGroup`, `ContactPrefill`, `SimContacts`); persistence is the provider, not Room — there is no database here. **Entry points + reading order:** `MainActivity.kt` → `ui/ContactListScreen.kt` → `ui/ContactDetailsPage.kt` → `ui/EditContactPage.kt` → `util/ContactViewModel.kt` → `data/Contact.kt`.++## One APK, two form factors (phone + watch)+This module is the single Contacts APK for phones and watches: same+`applicationId = "com.vayunmathur.contacts"` and signing on both, as the+WearLink handshake requires. The manifest deliberately declares no+`android.hardware.type.watch` feature (required=true would block+phones; required=false is disallowed for this feature), plus+touchscreen not-required and+`com.google.android.wearable.standalone=true`; distribution is+sideload/F-Droid, not Play's watch channel, so the APK installs on+phones and watches alike. `platform/FormFactor.kt`+reads `PackageManager.FEATURE_WATCH` at runtime: `MainActivity` (the+sole launcher entry) forwards watches to `ui/WearMainActivity` before+any phone state loads; phones get the list/detail/edit UI. The watch+activity has no launcher entry of its own (`exported=false`). There+are no watch receivers in this module.++## Wear sync (WearLink)+**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 data items plus a manifest (`/contacts/snapshot/...`); watch state: watch -> phone (`/contacts/watch-state`); snapshot request and call/message handoff are watch -> phone messages.+- Phone side `sync/WearContactsSync.kt` publishes the snapshot from `MainActivity` whenever the book changes; watch side `sync/WearLinkBridge.kt` feeds `data/WearContactsStore`'s reassembler and `sync/WearWatchStatePublisher.kt` publishes watch state / requests / handoffs. With no watch or no live WearLink session the sync stays idle and never crashes the phone UI.++## 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) and `ui/WearContactDetailScreen` (only actions `WearActionPolicy` says this watch can complete; no dead taps, via `platform/WearDeviceCapabilities`).+- 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:** - Contact load is per-source isolated (`data/ContactSourceLoader`): device and SIM contacts publish independently under a per-source timeout, the loaded flag flips as soon as the contacts land, and the one-time migrations plus provider-accounts/default-account refresh run after that under the same timeout — a throwing or never-answering SIM/provider source reads as empty for that source only and never blanks the list or holds the loading state - `util/` is NOT a closed package root — don't add more files there@@ -28,6 +55,8 @@ _Install: ./install contacts (dev by default)._ ### Root + platform/ — entry and account framework - com/vayunmathur/contacts/MainActivity.kt - com/vayunmathur/contacts/platform/Authenticator.kt+- com/vayunmathur/contacts/platform/FormFactor.kt — watch detection (`FEATURE_WATCH`)+- com/vayunmathur/contacts/platform/WearDeviceCapabilities.kt — watch telephony/handler/reachability probe ### data/ — provider-backed models (no Room) - com/vayunmathur/contacts/data/Contact.kt - com/vayunmathur/contacts/data/ContactGroup.kt@@ -85,6 +114,13 @@ _Install: ./install contacts (dev by default)._ - com/vayunmathur/contacts/ui/dialogs/AddGroupDialog.kt - com/vayunmathur/contacts/ui/dialogs/DeleteGroupDialog.kt - com/vayunmathur/contacts/ui/dialogs/DeleteSelectedContactsDialog.kt+### Watch experience (ui/ + data/ + sync/)+- com/vayunmathur/contacts/ui/WearMainActivity.kt — watch entry (WearShellActivity, exported=false)+- com/vayunmathur/contacts/ui/WearRoute.kt, WearContactsApp.kt, WearContactListScreen.kt, WearContactDetailScreen.kt+- com/vayunmathur/contacts/data/WearContactsStore.kt — watch snapshot store + reassembler+- com/vayunmathur/contacts/sync/WearContactsSync.kt — phone snapshot publisher+- com/vayunmathur/contacts/sync/WearLinkBridge.kt — watch snapshot receiver+- com/vayunmathur/contacts/sync/WearWatchStatePublisher.kt — watch state / request / handoff publisher ### intents/ — assistant IPC - com/vayunmathur/contacts/intents/GetIntent.kt - com/vayunmathur/contacts/intents/InsertIntent.kt@@ -92,6 +128,6 @@ _Install: ./install contacts (dev by default)._ ## Verify (this module only) ``` ./gradlew :contacts:compileDevKotlin-./gradlew :contacts:lint+./gradlew :contacts:lint :contacts:lintVitalRelease :contacts:testDevUnitTest ./gradlew :contacts:checkMetadata ```
contacts/build.gradle.kts
diff --git a/contacts/build.gradle.kts b/contacts/build.gradle.ktsindex da812d4130..aa594734be 100644--- a/contacts/build.gradle.kts+++ b/contacts/build.gradle.kts@@ -22,7 +22,14 @@ android { dependencies {     // VCF export/import now uses java.io BufferedReader/Writer – no okio needed     implementation(libs.libphonenumber)+    // Both sides of the Wear OS sync live in this one APK (same+    // applicationId and signing, as the WearLink handshake requires):+    // sync/WearContactsSync publishes the phone snapshot, sync/WearLinkBridge+    // receives it on a watch. FormFactor picks the side at runtime.     implementation(project(":library:wearlink"))     implementation(libs.androidx.work.runtime.ktx)-    // Wear OS companion (:contacts-wear, same applicationId + signing): Data Layer sync.+    // Watch experience (ui/Wear*): Wear Compose for the watch screens.+    implementation(libs.androidx.wear.compose.material)+    implementation(libs.androidx.wear.compose.foundation)+    implementation(libs.kotlinx.coroutines.android) }
contacts/src/main/AndroidManifest.xml
diff --git a/contacts/src/main/AndroidManifest.xml b/contacts/src/main/AndroidManifest.xmlindex fc46696c73..d3b732cd55 100644--- a/contacts/src/main/AndroidManifest.xml+++ b/contacts/src/main/AndroidManifest.xml@@ -21,6 +21,21 @@     <uses-permission android:name="android.permission.READ_PHONE_STATE" />     <uses-permission android:name="android.permission.POST_NOTIFICATIONS" /> +    <!-- Single APK for phone and watch. Deliberately NO+         android.hardware.type.watch uses-feature here: required="true"+         would block every phone install, and required="false" is+         disallowed for this feature (lint InvalidWearFeatureAttribute;+         Google's packaging model does not support one APK for Wear and+         non-Wear via Play). This app does not distribute through Play's+         watch channel — it is sideloaded / F-Droid-installed, where no+         feature declaration is needed to install on a watch — so the+         APK carries no watch feature filter at all and+         FormFactor.isWatch (PackageManager.FEATURE_WATCH, still+         reported by watch hardware at runtime) routes the experience. -->+    <uses-feature+        android:name="android.hardware.touchscreen"+        android:required="false" />+     <uses-feature         android:name="android.hardware.telephony"         android:required="false" />@@ -44,6 +59,11 @@         android:roundIcon="@mipmap/ic_launcher"         android:supportsRtl="true"         android:theme="@style/Theme.General">++        <!-- Watch experience renders/searches its locally synced copy without the phone. -->+        <meta-data+            android:name="com.google.android.wearable.standalone"+            android:value="true" />         <provider             android:name="androidx.core.content.FileProvider"             android:authorities="${applicationId}.provider"@@ -197,6 +217,14 @@          <!-- WearLink delivery is app-lifecycle-bound; no system listener service. --> +        <!-- Watch experience: entered only via MainActivity's watch routing+             (no launcher filter of its own). Inert on a phone: it is reached+             only from MainActivity after the FEATURE_WATCH check. -->+        <activity+            android:name=".ui.WearMainActivity"+            android:exported="false"+            android:theme="@android:style/Theme.DeviceDefault.NoActionBar" />+         <service android:name=".platform.AuthenticatorService" android:exported="false">             <intent-filter>                 <action android:name="android.accounts.AccountAuthenticator" />
contacts/src/main/java/com/vayunmathur/contacts/MainActivity.kt
diff --git a/contacts/src/main/java/com/vayunmathur/contacts/MainActivity.kt b/contacts/src/main/java/com/vayunmathur/contacts/MainActivity.ktindex 444bb72332..53772c85bc 100644--- a/contacts/src/main/java/com/vayunmathur/contacts/MainActivity.kt+++ b/contacts/src/main/java/com/vayunmathur/contacts/MainActivity.kt@@ -5,6 +5,7 @@ import com.vayunmathur.contacts.intents.buildInsertPrefill  import android.Manifest import android.content.Intent+import android.os.Bundle import android.content.ClipData import android.content.ContentUris import android.net.Uri@@ -54,6 +55,8 @@ import com.vayunmathur.contacts.ui.InsertOrEditContactScreen import com.vayunmathur.contacts.ui.SettingsPage import com.vayunmathur.contacts.ui.dialogs.EventDatePickerDialog import com.vayunmathur.contacts.platform.ContactViewModel+import com.vayunmathur.contacts.platform.FormFactor+import com.vayunmathur.contacts.ui.WearMainActivity import com.vayunmathur.contacts.platform.loadAccounts import com.vayunmathur.contacts.platform.setEditDraftPhotoFromBitmap import com.vayunmathur.library.ui.ExperimentalMaterial3Api@@ -72,10 +75,27 @@ import kotlinx.datetime.LocalDate import kotlinx.serialization.Serializable  /**- * Contacts entry activity: gates on contacts permissions, then hosts the pager+ * Sole launcher entry of the single merged Contacts APK. On a watch (the+ * `android.hardware.type.watch` system feature, see [FormFactor]) it hands+ * off to [WearMainActivity] and finishes before any phone state (contacts+ * permission gate, WearContactsSync, pick/import flows) is touched; on a+ * phone it gates on contacts permissions, then hosts the pager  * navigation and pick/import intent flows.  */ class MainActivity : MaActivity() {++    /** True on a watch, where this activity only forwards to [WearMainActivity]. */+    private var routedToWear = false++    override fun onCreate(savedInstanceState: Bundle?) {+        routedToWear = FormFactor.isWatch(this)+        super.onCreate(savedInstanceState)+        if (routedToWear) {+            startActivity(Intent(this, WearMainActivity::class.java))+            finish()+        }+    }+     private val importUris = mutableStateOf<List<String>>(emptyList())     private val externalRoute = mutableStateOf<Route?>(null) @@ -86,12 +106,16 @@ class MainActivity : MaActivity() {     }      override fun onCreateBeforeContent() {+        if (routedToWear) return         com.vayunmathur.library.wearlink.WearLinkPermissions.requestIfNeeded(this)         handleIntent(intent)     }      @Composable     override fun Content() {+        // On a watch this activity is finishing towards WearMainActivity;+        // compose nothing (and touch no phone state) in the meantime.+        if (routedToWear) return         AppPermissionsGate(             spec = AppPermissionsSpec(                 title = stringResource(R.string.grant_contacts_permission),
contacts/src/main/java/com/vayunmathur/contacts/data/WearContactsStore.kt
diff --git a/contacts-wear/src/main/java/com/vayunmathur/contacts/wear/data/WearContactsStore.kt b/contacts/src/main/java/com/vayunmathur/contacts/data/WearContactsStore.ktsimilarity index 99%rename from contacts-wear/src/main/java/com/vayunmathur/contacts/wear/data/WearContactsStore.ktrename to contacts/src/main/java/com/vayunmathur/contacts/data/WearContactsStore.ktindex 6f970cd19c..17538661b2 100644--- a/contacts-wear/src/main/java/com/vayunmathur/contacts/wear/data/WearContactsStore.kt+++ b/contacts/src/main/java/com/vayunmathur/contacts/data/WearContactsStore.kt@@ -1,4 +1,4 @@-package com.vayunmathur.contacts.wear.data+package com.vayunmathur.contacts.data  import android.content.Context import com.vayunmathur.library.wearlink.contacts.WearContact
contacts/src/main/java/com/vayunmathur/contacts/platform/FormFactor.kt
diff --git a/contacts/src/main/java/com/vayunmathur/contacts/platform/FormFactor.kt b/contacts/src/main/java/com/vayunmathur/contacts/platform/FormFactor.ktnew file mode 100644index 0000000000..edb0c4cbae--- /dev/null+++ b/contacts/src/main/java/com/vayunmathur/contacts/platform/FormFactor.kt@@ -0,0 +1,25 @@+package com.vayunmathur.contacts.platform++import android.content.Context+import android.content.pm.PackageManager++/**+ * Runtime form-factor detection for the single merged Contacts APK.+ *+ * One APK ships to phones and watches (same applicationId and signing, as+ * the WearLink handshake requires). [PackageManager.FEATURE_WATCH] is the+ * canonical signal: Wear OS devices report the `android.hardware.type.watch`+ * system feature, phones and tablets do not. The manifest deliberately+ * declares no such uses-feature (required=true would block phones,+ * required=false is disallowed for this feature), so the same APK+ * installs on both; this runtime check is what routes the experience.+ */+object FormFactor {++    /** True when this device reports the watch system feature. */+    fun isWatch(context: Context): Boolean =+        isWatch(context.packageManager.hasSystemFeature(PackageManager.FEATURE_WATCH))++    /** Pure core of [isWatch], split out so unit tests need no Android runtime. */+    fun isWatch(hasWatchSystemFeature: Boolean): Boolean = hasWatchSystemFeature+}
contacts/src/main/java/com/vayunmathur/contacts/platform/WearDeviceCapabilities.kt
diff --git a/contacts-wear/src/main/java/com/vayunmathur/contacts/wear/platform/WearDeviceCapabilities.kt b/contacts/src/main/java/com/vayunmathur/contacts/platform/WearDeviceCapabilities.ktsimilarity index 94%rename from contacts-wear/src/main/java/com/vayunmathur/contacts/wear/platform/WearDeviceCapabilities.ktrename to contacts/src/main/java/com/vayunmathur/contacts/platform/WearDeviceCapabilities.ktindex 1bd4ff11ee..8bcbd625b9 100644--- a/contacts-wear/src/main/java/com/vayunmathur/contacts/wear/platform/WearDeviceCapabilities.kt+++ b/contacts/src/main/java/com/vayunmathur/contacts/platform/WearDeviceCapabilities.kt@@ -1,10 +1,10 @@-package com.vayunmathur.contacts.wear.platform+package com.vayunmathur.contacts.platform  import android.content.Context import android.content.Intent import android.content.pm.PackageManager import android.net.Uri-import com.vayunmathur.contacts.wear.sync.WearLinkBridge+import com.vayunmathur.contacts.sync.WearLinkBridge  /** What this watch hardware/software can actually do, probed honestly at runtime. */ data class WearDeviceCapabilities(
contacts/src/main/java/com/vayunmathur/contacts/sync/WearLinkBridge.kt
diff --git a/contacts-wear/src/main/java/com/vayunmathur/contacts/wear/sync/WearLinkBridge.kt b/contacts/src/main/java/com/vayunmathur/contacts/sync/WearLinkBridge.ktsimilarity index 96%rename from contacts-wear/src/main/java/com/vayunmathur/contacts/wear/sync/WearLinkBridge.ktrename to contacts/src/main/java/com/vayunmathur/contacts/sync/WearLinkBridge.ktindex c945f9f3ac..68cc88a311 100644--- a/contacts-wear/src/main/java/com/vayunmathur/contacts/wear/sync/WearLinkBridge.kt+++ b/contacts/src/main/java/com/vayunmathur/contacts/sync/WearLinkBridge.kt@@ -1,7 +1,7 @@-package com.vayunmathur.contacts.wear.sync+package com.vayunmathur.contacts.sync  import android.content.Context-import com.vayunmathur.contacts.wear.data.WearContactsStore+import com.vayunmathur.contacts.data.WearContactsStore import com.vayunmathur.library.wearlink.contacts.WearContactsChunk import com.vayunmathur.library.wearlink.contacts.WearContactsManifest import com.vayunmathur.library.wearlink.contacts.WearContactsProtocol
contacts/src/main/java/com/vayunmathur/contacts/sync/WearWatchStatePublisher.kt
diff --git a/contacts-wear/src/main/java/com/vayunmathur/contacts/wear/sync/WearWatchStatePublisher.kt b/contacts/src/main/java/com/vayunmathur/contacts/sync/WearWatchStatePublisher.ktsimilarity index 95%rename from contacts-wear/src/main/java/com/vayunmathur/contacts/wear/sync/WearWatchStatePublisher.ktrename to contacts/src/main/java/com/vayunmathur/contacts/sync/WearWatchStatePublisher.ktindex 6e5724e2d0..fdc2d5c492 100644--- a/contacts-wear/src/main/java/com/vayunmathur/contacts/wear/sync/WearWatchStatePublisher.kt+++ b/contacts/src/main/java/com/vayunmathur/contacts/sync/WearWatchStatePublisher.kt@@ -1,7 +1,7 @@-package com.vayunmathur.contacts.wear.sync+package com.vayunmathur.contacts.sync  import android.content.Context-import com.vayunmathur.contacts.wear.data.WearSnapshot+import com.vayunmathur.contacts.data.WearSnapshot import com.vayunmathur.library.wearlink.contacts.WearContactsProtocol import com.vayunmathur.library.wearlink.contacts.WearHandoffRequest import com.vayunmathur.library.wearlink.contacts.WearWatchState
contacts/src/main/java/com/vayunmathur/contacts/ui/WearContactDetailScreen.kt
diff --git a/contacts-wear/src/main/java/com/vayunmathur/contacts/wear/ui/ContactDetailScreen.kt b/contacts/src/main/java/com/vayunmathur/contacts/ui/WearContactDetailScreen.ktsimilarity index 96%rename from contacts-wear/src/main/java/com/vayunmathur/contacts/wear/ui/ContactDetailScreen.ktrename to contacts/src/main/java/com/vayunmathur/contacts/ui/WearContactDetailScreen.ktindex d14bb04716..cbdaf42a0b 100644--- a/contacts-wear/src/main/java/com/vayunmathur/contacts/wear/ui/ContactDetailScreen.kt+++ b/contacts/src/main/java/com/vayunmathur/contacts/ui/WearContactDetailScreen.kt@@ -1,4 +1,4 @@-package com.vayunmathur.contacts.wear.ui+package com.vayunmathur.contacts.ui  import android.Manifest import android.content.Intent@@ -25,8 +25,8 @@ import com.vayunmathur.library.wearlink.contacts.WearAction import com.vayunmathur.library.wearlink.contacts.WearActionPolicy import com.vayunmathur.library.wearlink.contacts.WearContact import com.vayunmathur.library.wearlink.contacts.WearHandoffRequest-import com.vayunmathur.contacts.wear.platform.WearDeviceCapabilities-import com.vayunmathur.contacts.wear.sync.WearWatchStatePublisher+import com.vayunmathur.contacts.platform.WearDeviceCapabilities+import com.vayunmathur.contacts.sync.WearWatchStatePublisher import kotlinx.coroutines.launch  /**@@ -35,7 +35,7 @@ import kotlinx.coroutines.launch  * with no completable action shows no buttons at all — never a dead tap.  */ @Composable-fun ContactDetailScreen(+fun WearContactDetailScreen(     contact: WearContact,     capabilities: WearDeviceCapabilities, ) {
contacts/src/main/java/com/vayunmathur/contacts/ui/WearContactListScreen.kt
diff --git a/contacts-wear/src/main/java/com/vayunmathur/contacts/wear/ui/ContactListScreen.kt b/contacts/src/main/java/com/vayunmathur/contacts/ui/WearContactListScreen.ktsimilarity index 97%rename from contacts-wear/src/main/java/com/vayunmathur/contacts/wear/ui/ContactListScreen.ktrename to contacts/src/main/java/com/vayunmathur/contacts/ui/WearContactListScreen.ktindex d97363d41e..5b060e0e97 100644--- a/contacts-wear/src/main/java/com/vayunmathur/contacts/wear/ui/ContactListScreen.kt+++ b/contacts/src/main/java/com/vayunmathur/contacts/ui/WearContactListScreen.kt@@ -1,4 +1,4 @@-package com.vayunmathur.contacts.wear.ui+package com.vayunmathur.contacts.ui  import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding@@ -19,7 +19,7 @@ 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.wear.data.WearSnapshot+import com.vayunmathur.contacts.data.WearSnapshot import com.vayunmathur.library.wearlink.contacts.WearContact import com.vayunmathur.library.wearlink.contacts.WearContactSearch @@ -28,7 +28,7 @@ import com.vayunmathur.library.wearlink.contacts.WearContactSearch  * Search is local (every token must match name/phone/email).  */ @Composable-fun ContactListScreen(+fun WearContactListScreen(     snapshot: WearSnapshot,     query: String,     onQueryChange: (String) -> Unit,
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.ktnew file mode 100644index 0000000000..1dde639bde--- /dev/null+++ b/contacts/src/main/java/com/vayunmathur/contacts/ui/WearContactsApp.kt@@ -0,0 +1,65 @@+package com.vayunmathur.contacts.ui++import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.padding+import androidx.compose.runtime.Composable+import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.remember+import androidx.compose.runtime.setValue+import androidx.compose.ui.Modifier+import androidx.compose.ui.text.style.TextAlign+import androidx.compose.ui.unit.dp+import androidx.wear.compose.foundation.lazy.ScalingLazyColumn+import androidx.wear.compose.material.Chip+import androidx.wear.compose.material.ChipDefaults+import androidx.wear.compose.material.MaterialTheme+import androidx.wear.compose.material.Text+import com.vayunmathur.contacts.data.WearSnapshot+import com.vayunmathur.contacts.platform.WearDeviceCapabilities++/** Wear app root: [WearRoute] dispatch (list -> detail carrying the contact id). */+@Composable+fun WearContactsApp(+    snapshot: WearSnapshot,+    capabilities: WearDeviceCapabilities,+    route: WearRoute,+    navigate: (WearRoute) -> Unit,+) {+    var query by remember { mutableStateOf("") }+    when (route) {+        WearRoute.ContactList -> WearContactListScreen(+            snapshot = snapshot,+            query = query,+            onQueryChange = { query = it },+            onContactClick = { navigate(WearRoute.ContactDetail(it.id)) },+        )+        is WearRoute.ContactDetail -> {+            val contact = snapshot.contacts.firstOrNull { it.id == route.contactId }+            if (contact != null) {+                WearContactDetailScreen(contact, capabilities)+            } else {+                // Contact left the snapshot (deleted/resynced): never a blank screen.+                ScalingLazyColumn {+                    item {+                        Text(+                            text = "This contact is no longer on this watch.",+                            style = MaterialTheme.typography.body2,+                            textAlign = TextAlign.Center,+                            modifier = Modifier.fillMaxWidth()+                                .padding(horizontal = 12.dp, vertical = 4.dp),+                        )+                    }+                    item {+                        Chip(+                            onClick = { navigate(WearRoute.ContactList) },+                            label = { Text("Back", maxLines = 1) },+                            colors = ChipDefaults.secondaryChipColors(),+                            modifier = Modifier.fillMaxWidth().padding(horizontal = 8.dp),+                        )+                    }+                }+            }+        }+    }+}
contacts/src/main/java/com/vayunmathur/contacts/ui/WearMainActivity.kt
diff --git a/contacts-wear/src/main/java/com/vayunmathur/contacts/wear/MainActivity.kt b/contacts/src/main/java/com/vayunmathur/contacts/ui/WearMainActivity.ktsimilarity index 59%rename from contacts-wear/src/main/java/com/vayunmathur/contacts/wear/MainActivity.ktrename to contacts/src/main/java/com/vayunmathur/contacts/ui/WearMainActivity.ktindex 049ac409b5..0a188031bd 100644--- a/contacts-wear/src/main/java/com/vayunmathur/contacts/wear/MainActivity.kt+++ b/contacts/src/main/java/com/vayunmathur/contacts/ui/WearMainActivity.kt@@ -1,4 +1,4 @@-package com.vayunmathur.contacts.wear+package com.vayunmathur.contacts.ui  import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState@@ -6,28 +6,30 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue import androidx.lifecycle.lifecycleScope-import com.vayunmathur.contacts.wear.data.WearContactsStore-import com.vayunmathur.contacts.wear.platform.WearDeviceCapabilities-import com.vayunmathur.contacts.wear.platform.WearDeviceCapabilitiesProbe-import com.vayunmathur.contacts.wear.sync.WearWatchStatePublisher-import com.vayunmathur.contacts.wear.ui.WearContactsApp+import com.vayunmathur.contacts.data.WearContactsStore+import com.vayunmathur.contacts.platform.WearDeviceCapabilities+import com.vayunmathur.contacts.platform.WearDeviceCapabilitiesProbe+import com.vayunmathur.contacts.sync.WearLinkBridge+import com.vayunmathur.contacts.sync.WearWatchStatePublisher import com.vayunmathur.library.wearlink.WearShellActivity import kotlinx.coroutines.launch  /**  * Wear Contacts entry: renders the locally synced copy (offline-capable) and,  * on an empty first launch, asks the phone to republish its snapshot.+ * Entered only via the phone activity's watch routing (no launcher filter+ * of its own); on a phone it is never started.  */-class MainActivity : WearShellActivity<Unit, WearContactsStore>(Unit) {+class WearMainActivity : WearShellActivity<WearRoute, WearContactsStore>(WearRoute.ContactList) {      private var capabilities by mutableStateOf(WearDeviceCapabilities())      override fun createStore(): WearContactsStore {-        val created = com.vayunmathur.contacts.wear.sync.WearLinkBridge.store(applicationContext)-        com.vayunmathur.contacts.wear.sync.WearLinkBridge.get(applicationContext)+        val created = WearLinkBridge.store(applicationContext)+        WearLinkBridge.get(applicationContext)         capabilities = WearDeviceCapabilitiesProbe.probeHandlers(this)         lifecycleScope.launch {-            capabilities = WearDeviceCapabilitiesProbe.probe(this@MainActivity)+            capabilities = WearDeviceCapabilitiesProbe.probe(this@WearMainActivity)             if (created.snapshot.value.contacts.isEmpty()) {                 WearWatchStatePublisher.requestSnapshot(applicationContext)             }@@ -36,17 +38,17 @@ class MainActivity : WearShellActivity<Unit, WearContactsStore>(Unit) {     }      @Composable-    override fun Screen(route: Unit, navigate: (Unit) -> Unit) {+    override fun Screen(route: WearRoute, navigate: (WearRoute) -> Unit) {         val snapshot by store.snapshot.collectAsState()-        WearContactsApp(snapshot, capabilities)+        WearContactsApp(snapshot, capabilities, route, navigate)     }      override fun onResume() {         super.onResume()-        if (::store.isInitialized) store.reload()+        runCatching { store.reload() }         capabilities = WearDeviceCapabilitiesProbe.probeHandlers(this)         lifecycleScope.launch {-            capabilities = WearDeviceCapabilitiesProbe.probe(this@MainActivity)+            capabilities = WearDeviceCapabilitiesProbe.probe(this@WearMainActivity)         }     } }
contacts/src/main/java/com/vayunmathur/contacts/ui/WearRoute.kt
diff --git a/contacts/src/main/java/com/vayunmathur/contacts/ui/WearRoute.kt b/contacts/src/main/java/com/vayunmathur/contacts/ui/WearRoute.ktnew file mode 100644index 0000000000..d572c17aac--- /dev/null+++ b/contacts/src/main/java/com/vayunmathur/contacts/ui/WearRoute.kt@@ -0,0 +1,8 @@+package com.vayunmathur.contacts.ui++/** Watch navigation destinations: detail is a route carrying the contact id, never selection state. */+sealed interface WearRoute {+    data object ContactList : WearRoute++    data class ContactDetail(val contactId: Long) : WearRoute+}
contacts/src/screenshotTest/kotlin/com/vayunmathur/contacts/ui/WearMetadataPreviews.kt
diff --git a/contacts-wear/src/screenshotTest/kotlin/com/vayunmathur/contacts/wear/ui/MetadataPreviews.kt b/contacts/src/screenshotTest/kotlin/com/vayunmathur/contacts/ui/WearMetadataPreviews.ktsimilarity index 79%rename from contacts-wear/src/screenshotTest/kotlin/com/vayunmathur/contacts/wear/ui/MetadataPreviews.ktrename to contacts/src/screenshotTest/kotlin/com/vayunmathur/contacts/ui/WearMetadataPreviews.ktindex b9e4a3143b..5d5b79fd9e 100644--- a/contacts-wear/src/screenshotTest/kotlin/com/vayunmathur/contacts/wear/ui/MetadataPreviews.kt+++ b/contacts/src/screenshotTest/kotlin/com/vayunmathur/contacts/ui/WearMetadataPreviews.kt@@ -1,4 +1,4 @@-package com.vayunmathur.contacts.wear.ui+package com.vayunmathur.contacts.ui  import androidx.compose.foundation.background import androidx.compose.foundation.layout.Box@@ -10,9 +10,9 @@ import androidx.compose.ui.draw.clip import androidx.compose.ui.tooling.preview.Preview import androidx.wear.compose.material.MaterialTheme import com.android.tools.screenshot.PreviewTest-import com.vayunmathur.contacts.wear.data.WearSnapshot+import com.vayunmathur.contacts.data.WearSnapshot+import com.vayunmathur.contacts.platform.WearDeviceCapabilities import com.vayunmathur.library.wearlink.contacts.WearContact-import com.vayunmathur.contacts.wear.platform.WearDeviceCapabilities  /** Round watch, 454x454px class (227dp at 320dpi). */ private const val ROUND = "spec:width=227dp,height=227dp,dpi=320"@@ -24,18 +24,19 @@ private val fixtureContacts = listOf( )  /**- * Store listing images for `:contacts-wear` — every top-level screen (list, detail).- * Both screens are already stateless, so no Content extraction was needed.- * `./gradlew :contacts-wear:metadata` copies renders into `metadata_data/photos/contacts-wear/wear/`.+ * Store listing images for the watch experience of `:contacts` — every+ * top-level screen (list, detail). Both screens are already stateless, so+ * no Content extraction was needed.+ * `./gradlew :contacts:metadata` copies renders into `metadata_data/photos/contacts/wear/`.  */-class MetadataPreviews {+class WearMetadataPreviews {      @PreviewTest     @Preview(name = "1-list-round", device = ROUND, group = "wear")     @Composable     fun Preview1ListRound() {         RoundPreview {-            ContactListScreen(+            WearContactListScreen(                 snapshot = WearSnapshot(contacts = fixtureContacts),                 query = "",                 onQueryChange = {},@@ -49,7 +50,7 @@ class MetadataPreviews {     @Composable     fun Preview2DetailRound() {         RoundPreview {-            ContactDetailScreen(+            WearContactDetailScreen(                 contact = fixtureContacts[0],                 capabilities = WearDeviceCapabilities(hasTelephony = true, hasDialer = true, hasSmsHandler = true, hasEmailHandler = true, phoneReachable = true),             )
contacts/src/test/java/com/vayunmathur/contacts/data/WearSnapshotReassemblerTest.kt
diff --git a/contacts-wear/src/test/java/com/vayunmathur/contacts/wear/data/WearSnapshotReassemblerTest.kt b/contacts/src/test/java/com/vayunmathur/contacts/data/WearSnapshotReassemblerTest.ktsimilarity index 98%rename from contacts-wear/src/test/java/com/vayunmathur/contacts/wear/data/WearSnapshotReassemblerTest.ktrename to contacts/src/test/java/com/vayunmathur/contacts/data/WearSnapshotReassemblerTest.ktindex d4b4d065ae..c5f4843242 100644--- a/contacts-wear/src/test/java/com/vayunmathur/contacts/wear/data/WearSnapshotReassemblerTest.kt+++ b/contacts/src/test/java/com/vayunmathur/contacts/data/WearSnapshotReassemblerTest.kt@@ -1,4 +1,4 @@-package com.vayunmathur.contacts.wear.data+package com.vayunmathur.contacts.data   import com.vayunmathur.library.wearlink.contacts.WearContact
contacts/src/test/java/com/vayunmathur/contacts/platform/FormFactorTest.kt
diff --git a/contacts/src/test/java/com/vayunmathur/contacts/platform/FormFactorTest.kt b/contacts/src/test/java/com/vayunmathur/contacts/platform/FormFactorTest.ktnew file mode 100644index 0000000000..94ed7d9bc8--- /dev/null+++ b/contacts/src/test/java/com/vayunmathur/contacts/platform/FormFactorTest.kt@@ -0,0 +1,19 @@+package com.vayunmathur.contacts.platform++import kotlin.test.Test+import kotlin.test.assertFalse+import kotlin.test.assertTrue++/** The watch system feature is the single-APK routing signal. */+class FormFactorTest {++    @Test+    fun watchFeatureMeansWatch() {+        assertTrue(FormFactor.isWatch(hasWatchSystemFeature = true))+    }++    @Test+    fun noWatchFeatureMeansPhone() {+        assertFalse(FormFactor.isWatch(hasWatchSystemFeature = false))+    }+}
metadata_data/photos/contacts/wear/1.png
diff --git a/metadata_data/photos/contacts-wear/wear/1.png b/metadata_data/photos/contacts/wear/1.pngsimilarity index 100%rename from metadata_data/photos/contacts-wear/wear/1.pngrename to metadata_data/photos/contacts/wear/1.png
metadata_data/photos/contacts/wear/2.png
diff --git a/metadata_data/photos/contacts-wear/wear/2.png b/metadata_data/photos/contacts/wear/2.pngsimilarity index 100%rename from metadata_data/photos/contacts-wear/wear/2.pngrename to metadata_data/photos/contacts/wear/2.png
settings.gradle.kts
diff --git a/settings.gradle.kts b/settings.gradle.ktsindex ee7ebb53ae..5a50142905 100644--- a/settings.gradle.kts+++ b/settings.gradle.kts@@ -89,7 +89,6 @@ project(":watch:wear").projectDir = file("watch-wear") include(":library:carhost") include(":calendar") include(":contacts")-include(":contacts-wear") include(":pdf") include(":openassistant") include(":office")