notes: merge notes-wear into the single notes APK
- Commit
445183fcdafb0987997a39e44f6ed201d528d8e9- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-04 17:57 UTC (1 day ago)
- Parents
de47de2
Owner directive: singular apps that detect when they are on a watch and adapt, instead of a separate *-wear APK per companion. Notes follows the merged clock pilot (same shape, same applicationId com.vayunmathur.notes and 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 (Room, phone conduit sync) is touched, and phones keep the existing list/detail UI. The manifest deliberately declares no android.hardware.type.watch uses-feature: required=true would block phone installs and required=false is disallowed for this feature (InvalidWearFeatureAttribute; Google's packaging model does not support a single Wear/non-Wear APK through Play). Distribution here is sideload/F-Droid, not Play's watch channel, so installation on a watch needs no feature declaration; the standalone=false meta-data and touchscreen-not-required are carried into the phone application element. The old wear WAKE_LOCK is not carried: no watch code path in this app acquires a wake lock. All notes-wear sources move into notes' closed package roots (wear/data -> data, wear/sync -> sync, wear/ui -> ui), R references retarget to com.vayunmathur.notes.R, and wear strings merge as res/values/wear_strings.xml (duplicate app_name dropped; the wear ic_launcher_background color is dropped because the phone module's launcherIcon convention already generates it). The sync is unchanged: sync/WearNotesSync publishes /notes/snapshot from the phone experience, sync/WearLinkBridge receives it in the watch experience, appId notes. The wear launcher activity loses its LAUNCHER filter (exported=false, reachable only via MainActivity's watch routing). This module declares no broadcast receivers, so no wrong-form-factor receiver can fire; every entry point is inert on the wrong form factor by construction. The wear WearNotesProtocolTest copy is dropped because :notes already pins the same golden JSON. Watch screenshot previews become ui/WearMetadataPreviews with group=wear, so :notes:metadata renders them into metadata_data/photos/notes/wear/ (the old notes-wear bucket's captures move there unchanged until the next fresh render). The notes-wear module and its settings include are deleted; root and notes AGENTS.md describe the merged state. Verified fresh on devvm21958 in the worktree: ./gradlew :notes:lint :notes:lintVitalRelease :notes:testDevUnitTest green (BUILD SUCCESSFUL, including the moved watch code and the new FormFactorTest). Only a real watch can confirm install, FEATURE_WATCH routing, and the Wear OS launcher surface.
Diff
AGENTS.md
diff --git a/AGENTS.md b/AGENTS.mdindex 5ff8d1b00b..d97e787814 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` is a single merged APK for phone and watch (watch experience inside `clock/`; the other `*-wear` modules are separate companion APKs with the phone app's applicationId/signing).+`clock` and `notes` are single merged APKs for phone and watch (watch experience inside `clock/` and `notes/` respectively; the other `*-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`).
metadata_data/photos/notes/wear/1.png
diff --git a/metadata_data/photos/notes-wear/wear/1.png b/metadata_data/photos/notes/wear/1.pngsimilarity index 100%rename from metadata_data/photos/notes-wear/wear/1.pngrename to metadata_data/photos/notes/wear/1.png
metadata_data/photos/notes/wear/2.png
diff --git a/metadata_data/photos/notes-wear/wear/2.png b/metadata_data/photos/notes/wear/2.pngsimilarity index 100%rename from metadata_data/photos/notes-wear/wear/2.pngrename to metadata_data/photos/notes/wear/2.png
metadata_data/photos/notes/wear/3.png
diff --git a/metadata_data/photos/notes-wear/wear/3.png b/metadata_data/photos/notes/wear/3.pngsimilarity index 100%rename from metadata_data/photos/notes-wear/wear/3.pngrename to metadata_data/photos/notes/wear/3.png
notes-wear/AGENTS.md
diff --git a/notes-wear/AGENTS.md b/notes-wear/AGENTS.mddeleted file mode 100644index 2ab901097a..0000000000--- a/notes-wear/AGENTS.md+++ /dev/null@@ -1,47 +0,0 @@-# AGENTS.md — notes-wear/ (':notes-wear')--> Scoped supplement. Global rules in root `AGENTS.md` apply. Stay inside-> `notes-wear/` + `notes/` (the phone side of the same feature).--- Gradle: :notes-wear / dir: notes-wear/ (convention: `common-conventions-wear`)-- Package roots present: ui, data, domain, sync-- Entry file: ui/WearMainActivity.kt--## Why this module exists (read before changing identity)-Wear OS companion of the phone Notes (`:notes`). This module deliberately-uses `applicationId = "com.vayunmathur.notes"` (the phone app's) with the-shared dev/release signing from the convention plugins: WearLink's-handshake token requires the same signing certificate on both sides, so-changing either breaks phone<->watch sync. Bootstrap is a one-time ADB-sideload of this APK onto the watch.--## Protocol-The wire protocol lives in `:library:wearlink` at-`com.vayunmathur.library.wearlink.notes.WearNotesProtocol` (shared by-`:notes` and `:notes-wear`; neither app module depends on the other).-Each side's `WearNotesProtocolTest` pins the same golden JSON against-that shared code.--- Snapshot + watch-state sync: WearLink data items (`/notes/snapshot`, `/notes/watch-state`)-- Watch-originated ops: WearLink message (`/notes/op`, create/edit/delete)-- Sync request: WearLink message (`/notes/request-sync`), watch -> phone only-- Transport: :library:wearlink (RFCOMM, no Play services); app-lifecycle-bound--## Sync semantics (stated, not implied)-- Phone -> watch: bounded snapshot — 50 most recent notes, title ≤120- chars, body ≤4000 chars, ≤90_000 JSON bytes (`truncated` flags loss).- The watch persists it and reads fully offline.-- Watch -> phone: create/edit/delete ops flow over the link and apply on- the phone only. Conflict policy is last-writer-wins per note by- `updatedAt` (ties: tombstone, then larger title/body) — no text merge.-- Honest writes: notes with image/ink blocks on the phone (`textOnly =- false`) are read-only on the watch except delete; watch creates/edits- become single-text-block notes on the phone. An op stays *pending* on- the watch (persisted, resent on reconnect) until a phone snapshot- reflects it — the UI never claims "synced" before that.--## Verify (this module only)-```-./gradlew :notes-wear:assembleDev-./gradlew :notes-wear:testDebugUnitTest-```
notes-wear/build.gradle.kts
diff --git a/notes-wear/build.gradle.kts b/notes-wear/build.gradle.ktsdeleted file mode 100644index 0ed68a0325..0000000000--- a/notes-wear/build.gradle.kts+++ /dev/null@@ -1,39 +0,0 @@-plugins {- id("common-conventions-wear")- id("common-conventions-preview-metadata")-}--launcherIcon {- symbol = "subject"-}--// 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 WearLink handshake only connects apps that share a package name and- // signing certificate, so this module MUST ship as the phone app's package:- // same applicationId (below) and the same signing config the convention- // plugins already apply to both (debug key for dev, release key for- // release). The namespace only names this module's own R/resources.- namespace = "com.vayunmathur.notes.wear"- defaultConfig {- applicationId = "com.vayunmathur.notes"- // Convention defaults to 30, but :library:log (pulled in by the wear- // convention) requires 31, so the watch floor is 31.- minSdk = 31- versionCode = wearVersionCode- versionName = wearVersionName- }-}--dependencies {- // Watch side of the Wear OS sync (protocol in :library:wearlink).- implementation(libs.kotlinx.coroutines.android)- implementation(project(":library:wearlink"))- testImplementation(libs.kotlin.test)- testImplementation(libs.kotlin.test.junit)-}
notes-wear/src/main/AndroidManifest.xml
diff --git a/notes-wear/src/main/AndroidManifest.xml b/notes-wear/src/main/AndroidManifest.xmldeleted file mode 100644index 7ccb8c3001..0000000000--- a/notes-wear/src/main/AndroidManifest.xml+++ /dev/null@@ -1,40 +0,0 @@-<?xml version="1.0" encoding="utf-8"?>-<manifest xmlns:android="http://schemas.android.com/apk/res/android">-- <!-- Wear OS form factor. Declaring the watch hardware makes this build- installable on Wear OS; the touchscreen is not required there. -->- <uses-feature- android:name="android.hardware.type.watch"- android:required="true" />- <uses-feature- android:name="android.hardware.touchscreen"- android:required="false" />-- <uses-permission android:name="android.permission.WAKE_LOCK" />-- <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.Material.NoActionBar">-- <!-- Paired with the phone app, not a standalone watch app. -->- <meta-data- android:name="com.google.android.wearable.standalone"- android:value="false" />-- <activity- android:name=".ui.WearMainActivity"- android:exported="true"- android:taskAffinity="">- <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>
notes-wear/src/main/res/values/colors.xml
diff --git a/notes-wear/src/main/res/values/colors.xml b/notes-wear/src/main/res/values/colors.xmldeleted file mode 100644index bfc7025d71..0000000000--- a/notes-wear/src/main/res/values/colors.xml+++ /dev/null@@ -1,5 +0,0 @@-<?xml version="1.0" encoding="utf-8"?>-<!-- Background for the generated adaptive launcher icon (see LauncherIconGen). -->-<resources>- <color name="ic_launcher_background">#FFFFFF</color>-</resources>
notes-wear/src/test/java/com/vayunmathur/notes/wear/domain/WearNotesProtocolTest.kt
diff --git a/notes-wear/src/test/java/com/vayunmathur/notes/wear/domain/WearNotesProtocolTest.kt b/notes-wear/src/test/java/com/vayunmathur/notes/wear/domain/WearNotesProtocolTest.ktdeleted file mode 100644index 90d8448bcb..0000000000--- a/notes-wear/src/test/java/com/vayunmathur/notes/wear/domain/WearNotesProtocolTest.kt+++ /dev/null@@ -1,179 +0,0 @@-package com.vayunmathur.notes.wear.domain-import com.vayunmathur.library.wearlink.notes.WearNote-import com.vayunmathur.library.wearlink.notes.WearNoteOp-import com.vayunmathur.library.wearlink.notes.WearNotesProtocol-import com.vayunmathur.library.wearlink.notes.WearNotesSnapshot-import com.vayunmathur.library.wearlink.notes.WearOpKind-import com.vayunmathur.library.wearlink.notes.buildWearSnapshot-import com.vayunmathur.library.wearlink.notes.mergeWearSnapshot-import com.vayunmathur.library.wearlink.notes.reflectedOps-import com.vayunmathur.library.wearlink.notes.wearNoteWins--import kotlin.test.Test-import kotlin.test.assertEquals-import kotlin.test.assertFalse-import kotlin.test.assertTrue-import kotlinx.serialization.encodeToString--class WearNotesProtocolTest {-- private fun note(- syncId: String,- updatedAt: Long,- title: String = "Note $syncId",- body: String = "Body $syncId",- deleted: Boolean = false,- ) = WearNote(syncId = syncId, title = title, body = body, updatedAt = updatedAt, deleted = deleted)-- @Test- fun goldenSnapshotJson() {- val snapshot = WearNotesSnapshot(- generatedAtMillis = 1_000L,- notes = listOf(note("abc", 900L, title = "Shopping", body = "Milk")),- )- assertEquals(- """{"generatedAtMillis":1000,"notes":[{"syncId":"abc","title":"Shopping",""" +- """"body":"Milk","updatedAt":900}]}""",- WearNotesProtocol.json.encodeToString(snapshot),- )- }-- @Test- fun goldenOpJson() {- val op = WearNoteOp(WearOpKind.UPSERT, note("abc", 900L, title = "Shopping", body = "Milk"))- assertEquals(- """{"kind":"UPSERT","note":{"syncId":"abc","title":"Shopping","body":"Milk","updatedAt":900}}""",- WearNotesProtocol.json.encodeToString(op),- )- }-- @Test- fun snapshotAndOpRoundTrip() {- val snapshot = WearNotesSnapshot(9L, listOf(note("a", 1L), note("b", 2L)), truncated = true)- assertEquals(- snapshot,- WearNotesProtocol.json.decodeFromString<WearNotesSnapshot>(- WearNotesProtocol.json.encodeToString(snapshot),- ),- )- val op = WearNoteOp(WearOpKind.DELETE, note("a", 3L, deleted = true))- assertEquals(- op,- WearNotesProtocol.json.decodeFromString<WearNoteOp>(- WearNotesProtocol.json.encodeToString(op),- ),- )- }-- @Test- fun buildKeepsMostRecentAndDropsDeleted() {- val snapshot = buildWearSnapshot(- candidates = listOf(note("old", 100L), note("new", 300L), note("gone", 400L, deleted = true)),- generatedAtMillis = 500L,- )- assertEquals(listOf("new", "old"), snapshot.notes.map { it.syncId })- assertFalse(snapshot.truncated)- }-- @Test- fun buildCapsCountFieldsAndBytes() {- val candidates = (1..(WearNotesProtocol.MAX_NOTES + 20)).map {- note("n$it", it.toLong(), title = "t".repeat(300), body = "b".repeat(5_000))- }- val snapshot = buildWearSnapshot(candidates, 0L)- assertTrue(snapshot.notes.size <= WearNotesProtocol.MAX_NOTES)- assertTrue(snapshot.truncated)- assertTrue(snapshot.notes.all {- it.title.length == WearNotesProtocol.MAX_TITLE_CHARS &&- it.body.length == WearNotesProtocol.MAX_BODY_CHARS && it.bodyTruncated- })- val bytes = WearNotesProtocol.json.encodeToString(snapshot).encodeToByteArray().size- assertTrue(bytes <= WearNotesProtocol.MAX_JSON_BYTES, "snapshot $bytes bytes over cap")- // Most recent survives the caps.- assertEquals("n${WearNotesProtocol.MAX_NOTES + 20}", snapshot.notes.first().syncId)- }-- @Test- fun lwwNewerWinsOlderLoses() {- val incumbent = note("a", 200L, title = "Phone")- assertTrue(wearNoteWins(note("a", 300L, title = "Watch"), incumbent))- assertFalse(wearNoteWins(note("a", 100L, title = "Watch"), incumbent))- assertFalse(wearNoteWins(incumbent, incumbent))- }-- @Test- fun lwwTieBreaksTombstoneThenLargerText() {- val live = note("a", 200L, title = "Same", body = "same")- assertTrue(wearNoteWins(live.copy(deleted = true), live))- assertFalse(wearNoteWins(live, live.copy(deleted = true)))- assertTrue(wearNoteWins(live.copy(title = "Zebra"), live))- assertTrue(wearNoteWins(live.copy(body = "zebra"), live))- }-- @Test- fun mergeKeepsWinningPendingOpAndHidesPendingDelete() {- val snapshot = WearNotesSnapshot(- 1_000L,- listOf(note("a", 100L, title = "Phone"), note("b", 100L)),- )- val edited = note("a", 200L, title = "Watch edit")- val merged = mergeWearSnapshot(- snapshot,- listOf(- WearNoteOp(WearOpKind.UPSERT, edited),- WearNoteOp(WearOpKind.DELETE, note("b", 200L, deleted = true)),- ),- )- assertEquals(listOf(edited), merged)- }-- @Test- fun mergeDropsPendingOpThatLosesToSnapshot() {- val phone = note("a", 300L, title = "Phone newer")- val snapshot = WearNotesSnapshot(1_000L, listOf(phone))- val stale = note("a", 200L, title = "Watch stale")- assertEquals(- listOf(phone),- mergeWearSnapshot(snapshot, listOf(WearNoteOp(WearOpKind.UPSERT, stale))),- )- // Reflected: the stale op is safe to drop; a winning op is not.- assertEquals(- listOf(WearNoteOp(WearOpKind.UPSERT, stale)),- reflectedOps(snapshot, listOf(WearNoteOp(WearOpKind.UPSERT, stale))),- )- assertEquals(- emptyList(),- reflectedOps(snapshot, listOf(WearNoteOp(WearOpKind.UPSERT, note("a", 400L)))),- )- // A delete is reflected once the note is absent from the live snapshot.- assertEquals(- 1,- reflectedOps(- WearNotesSnapshot(1_000L, emptyList()),- listOf(WearNoteOp(WearOpKind.DELETE, note("a", 200L, deleted = true))),- ).size,- )- }-- @Test- fun deleteIsNotReflectedByAbsenceFromTruncatedSnapshot() {- // Truncated means the count/byte caps dropped notes: "a" may still be- // live on the phone at 100L, just outside the snapshot window. Dropping- // the pending delete here would lose it, and "a" would resurrect on- // the watch when a later snapshot includes it again.- val delete = WearNoteOp(WearOpKind.DELETE, note("a", 200L, deleted = true))- val truncated = WearNotesSnapshot(1_000L, listOf(note("b", 300L)), truncated = true)- assertEquals(emptyList(), reflectedOps(truncated, listOf(delete)))- // The still-pending delete keeps hiding any snapshot copy meanwhile.- assertEquals(- listOf(note("b", 300L)),- mergeWearSnapshot(- WearNotesSnapshot(1_100L, listOf(note("a", 100L), note("b", 300L))),- listOf(delete),- ),- )- // A complete snapshot without the note does reflect the delete.- val complete = WearNotesSnapshot(1_200L, listOf(note("b", 300L)), truncated = false)- assertEquals(listOf(delete), reflectedOps(complete, listOf(delete)))- }-}
notes/AGENTS.md
diff --git a/notes/AGENTS.md b/notes/AGENTS.mdindex 793f9453c8..581c8bf534 100644--- a/notes/AGENTS.md+++ b/notes/AGENTS.md@@ -5,8 +5,8 @@ _Install: ./install notes (dev by default)._ - Gradle: :notes / dir: notes/ - Package roots present: ui, data, domain, platform, intents, sync-- Entry files: MainActivity.kt, Route.kt, Navigation.kt-- Deps: :library:room, :library:ink, :library:image+- Entry files: MainActivity.kt (sole launcher; routes watches to WearMainActivity), Route.kt, Navigation.kt, ui/WearMainActivity.kt+- Deps: :library:room, :library:ink, :library:image, :library:wearlink, :library:log, Wear Compose (material + foundation) - Metadata: metadata_data/notes.md (present) - Rust: no / screenshotTest: yes @@ -18,6 +18,34 @@ _Install: ./install notes (dev by default)._ - OpenAssistant read/add via `intents/`; local backup/restore via the in-app backup buttons (`BackupButtons`, no backup agent) **Architecture / data-flow:** `ui/` Compose list/detail → `platform/NotesViewModel` (+ `NotesUiContract`) → `data/NotesRepository` singleton over Room (`Note`/`NoteBlock`/`NoteDatabase`). `MainActivity.onCreateBeforeContent`: repo init → one-time legacy-notes clear + image `img_<uuid>.jpg → sha256.jpg` migration with block-reference rewrite → `ready` gate before `Navigation`. **Entry points + reading order:** `Route` (`NotesList` / `Note(id)` / `ExternalNote(uri)`) → `MainActivity.kt` → `Navigation.kt` → `platform/NotesViewModel.kt` → `data/NotesRepository.kt`.++## One APK, two form factors (phone + watch)+This module is the single Notes APK for phones and watches: same+`applicationId = "com.vayunmathur.notes"` 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=false`; 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 UI. This module+declares no broadcast receivers; the watch activity carries no+launcher filter (`exported=false`) and is reachable only through that+routing, so every entry point is inert on the wrong form factor.++## Wear sync (phone + watch in this module)+**Protocol:** shared wire types live in `:library:wearlink` at `com.vayunmathur.library.wearlink.notes.WearNotesProtocol`; the golden-JSON tests in this module pin the shared code's wire format. Transport is :library:wearlink (RFCOMM, no Play services), app-lifecycle-bound on both sides.+- Snapshot + watch-state sync: WearLink data items (`/notes/snapshot` phone -> watch, `/notes/watch-state` watch -> phone)+- Watch-originated ops: WearLink message (`/notes/op`, create/edit/delete)+- Sync request: WearLink message (`/notes/request-sync`), watch -> phone only+- **Sync semantics:** phone -> watch is a bounded snapshot — 50 most recent notes, title ≤120 chars, body ≤4000 chars, ≤90_000 JSON bytes (`truncated` flags loss); the watch persists it and reads fully offline. Watch -> phone create/edit/delete ops apply on the phone only, last-writer-wins per note by `updatedAt` (ties: tombstone, then larger title/body), no text merge. Notes with image/ink blocks (`textOnly = false`) are read-only on the watch except delete; watch creates/edits become single-text-block notes on the phone. An op stays pending on the watch (persisted, resent on reconnect) until a phone snapshot reflects it, so the watch UI never claims "synced" before that.++## Watch experience (in this module)+- `ui/WearMainActivity` (a `WearShellActivity`) routes `ui/WearRoute` over the recent-notes list / note view / quick-note editor, rendered only from `data/WearNotesStore` (`wear-notes-snapshot.json` + `wear-notes-pending.json`) so it works with the phone absent.+- Watch listing screenshots are the `group = "wear"` previews in `src/screenshotTest/.../ui/WearMetadataPreviews.kt`, collected by `:notes:metadata` into `metadata_data/photos/notes/wear/`; phone shots use the `phone` bucket. **Gotchas:** - Migrations must finish before `ready = true` — image references break if skipped - External/shared URIs enter via the `ExternalNote` route, not the list@@ -52,6 +80,15 @@ _Install: ./install notes (dev by default)._ - com/vayunmathur/notes/ui/components/NoteEditorComponents.kt - com/vayunmathur/notes/ui/dialogs/RenameTagDialog.kt - com/vayunmathur/notes/ui/dialogs/DeleteTagDialog.kt+### sync/ — wear sync (both sides)+- com/vayunmathur/notes/sync/WearNotesSync.kt — phone side: snapshot publish, watch-state receive, watch-op apply under LWW+- com/vayunmathur/notes/sync/WearLinkBridge.kt — watch side: snapshot receive into the store, pending-op flush, watch-state publish+- com/vayunmathur/notes/sync/RelayNoteProvider.kt+### Watch experience (ui/ + data/ + platform/)+- com/vayunmathur/notes/ui/WearMainActivity.kt — watch entry (WearShellActivity)+- com/vayunmathur/notes/ui/WearRoute.kt, WearNotesListScreen.kt, WearNoteScreen.kt, WearNoteEditorScreen.kt+- com/vayunmathur/notes/data/WearNotesStore.kt — watch local truth: persisted snapshot merged with pending ops+- com/vayunmathur/notes/platform/FormFactor.kt — watch detection (`FEATURE_WATCH`) ### intents/ — assistant IPC demo (copy this pattern) - com/vayunmathur/notes/intents/GetIntent.kt - com/vayunmathur/notes/intents/InsertIntent.kt@@ -59,6 +96,6 @@ _Install: ./install notes (dev by default)._ ## Verify (this module only) ``` ./gradlew :notes:compileDevKotlin-./gradlew :notes:lint+./gradlew :notes:lint :notes:lintVitalRelease :notes:testDevUnitTest ./gradlew :notes:checkMetadata ```
notes/build.gradle.kts
diff --git a/notes/build.gradle.kts b/notes/build.gradle.ktsindex eae81a2d52..2a253c3660 100644--- a/notes/build.gradle.kts+++ b/notes/build.gradle.kts@@ -22,9 +22,15 @@ dependencies { implementation(project(":library:room")) implementation(project(":library:ink")) implementation(project(":library:image"))- // Phone side of the Wear OS sync (sync/WearNotesSync): snapshot publish- // and watch-originated ops to :notes-wear, which shares this app's- // applicationId and signing certificate.+ // Both sides of the Wear OS sync live in this one APK (same+ // applicationId and signing, as the WearLink handshake requires):+ // sync/WearNotesSync publishes the phone snapshot, sync/WearLinkBridge+ // receives it on a watch. FormFactor picks the side at runtime. implementation(project(":library:wearlink"))+ // Watch experience (ui/Wear*): Wear Compose + the repo log facade the+ // watch data/sync code writes through.+ implementation(libs.androidx.wear.compose.material)+ implementation(libs.androidx.wear.compose.foundation)+ implementation(project(":library:log")) implementation(libs.kotlinx.coroutines.android) }\ No newline at end of file
notes/src/main/AndroidManifest.xml
diff --git a/notes/src/main/AndroidManifest.xml b/notes/src/main/AndroidManifest.xmlindex c74ece569c..39bce04945 100644--- a/notes/src/main/AndroidManifest.xml+++ b/notes/src/main/AndroidManifest.xml@@ -11,6 +11,21 @@ <uses-permission android:name="com.vayunmathur.permission.SENSORS_OPTOUT" /> <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-permission android:name="android.permission.INTERNET" tools:node="remove" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" tools:node="remove" /> @@ -33,6 +48,11 @@ android:roundIcon="@mipmap/ic_launcher" android:supportsRtl="true" android:theme="@style/Theme.General">++ <!-- Watch experience is paired with the phone app, not standalone. -->+ <meta-data+ android:name="com.google.android.wearable.standalone"+ android:value="false" /> <activity android:configChanges="mcc|mnc|colorMode|density|fontScale|fontWeightAdjustment|keyboard|keyboardHidden|layoutDirection|navigation|orientation|screenLayout|screenSize|smallestScreenSize|touchscreen|uiMode" android:name=".MainActivity"@@ -74,6 +94,15 @@ </intent-filter> </activity> + <!-- Watch experience: entered only via MainActivity's watch routing+ (no launcher filter of its own). It is inert on a phone: only+ the watch-routed MainActivity can start it. -->+ <activity+ android:name=".ui.WearMainActivity"+ android:exported="false"+ android:taskAffinity=""+ android:theme="@android:style/Theme.Material.NoActionBar" />+ <activity android:name=".intents.GetIntent" android:exported="true"
notes/src/main/java/com/vayunmathur/notes/MainActivity.kt
diff --git a/notes/src/main/java/com/vayunmathur/notes/MainActivity.kt b/notes/src/main/java/com/vayunmathur/notes/MainActivity.ktindex 81f65f320a..e77529feb4 100644--- a/notes/src/main/java/com/vayunmathur/notes/MainActivity.kt+++ b/notes/src/main/java/com/vayunmathur/notes/MainActivity.kt@@ -1,6 +1,7 @@ package com.vayunmathur.notes import android.content.Intent+import android.os.Bundle import androidx.activity.viewModels import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxSize@@ -12,9 +13,11 @@ import com.vayunmathur.library.ui.Text import com.vayunmathur.library.util.IntentHelper import com.vayunmathur.library.util.onFileDrop import com.vayunmathur.notes.data.NotesRepository+import com.vayunmathur.notes.platform.FormFactor import com.vayunmathur.notes.platform.NoteImageStore import com.vayunmathur.notes.platform.NotesViewModel import com.vayunmathur.notes.platform.NotesViewModelFactory+import com.vayunmathur.notes.ui.WearMainActivity import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext@@ -23,8 +26,27 @@ import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -/** Entry activity that initialises the notes repository before showing navigation. */+/**+ * Sole launcher entry of the single merged Notes APK. On a watch (the+ * `android.hardware.type.watch` system feature, see [FormFactor]) it hands+ * off to [WearMainActivity] and finishes before any phone state (Room,+ * phone sync) is touched; on a phone it initialises the notes repository+ * before showing navigation.+ */ 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 lateinit var notesRepository: NotesRepository private val notesViewModel: NotesViewModel by viewModels { NotesViewModelFactory(application, notesRepository)@@ -32,6 +54,7 @@ class MainActivity : MaActivity() { private var ready by mutableStateOf(false) override fun onCreateBeforeContent() {+ if (routedToWear) return com.vayunmathur.library.wearlink.WearLinkPermissions.requestIfNeeded(this) // Wear companion sync lives and dies with this process (WearLink has // no system wakeup); it publishes once the repository is ready below.@@ -65,6 +88,9 @@ class MainActivity : MaActivity() { @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 Box(Modifier.fillMaxSize().onFileDrop { uris -> notesViewModel.importFiles(uris) }) {
notes/src/main/java/com/vayunmathur/notes/data/WearNotesStore.kt
diff --git a/notes-wear/src/main/java/com/vayunmathur/notes/wear/data/WearNotesStore.kt b/notes/src/main/java/com/vayunmathur/notes/data/WearNotesStore.ktsimilarity index 96%rename from notes-wear/src/main/java/com/vayunmathur/notes/wear/data/WearNotesStore.ktrename to notes/src/main/java/com/vayunmathur/notes/data/WearNotesStore.ktindex 9774392aa8..883733cab6 100644--- a/notes-wear/src/main/java/com/vayunmathur/notes/wear/data/WearNotesStore.kt+++ b/notes/src/main/java/com/vayunmathur/notes/data/WearNotesStore.kt@@ -1,4 +1,4 @@-package com.vayunmathur.notes.wear.data+package com.vayunmathur.notes.data import android.content.Context import com.vayunmathur.library.log.Log@@ -67,7 +67,7 @@ class WearNotesStore private constructor(private val context: Context) { } _notes.value = mergeWearSnapshot(snapshot, _pendingOps.value) persistSnapshot()- com.vayunmathur.notes.wear.sync.WearLinkBridge.publishWatchState(context)+ com.vayunmathur.notes.sync.WearLinkBridge.publishWatchState(context) } /** Creates a note locally and queues its op; visible immediately, pending until reflected. */@@ -118,7 +118,7 @@ class WearNotesStore private constructor(private val context: Context) { _pendingOps.value = _pendingOps.value.filter { it.note.syncId != op.note.syncId } + op persistPending() _notes.value = mergeWearSnapshot(lastSnapshot, _pendingOps.value)- com.vayunmathur.notes.wear.sync.WearLinkBridge.flushPending(context)+ com.vayunmathur.notes.sync.WearLinkBridge.flushPending(context) } private fun loadSnapshot(): WearNotesSnapshot = runCatching {
notes/src/main/java/com/vayunmathur/notes/platform/FormFactor.kt
diff --git a/notes/src/main/java/com/vayunmathur/notes/platform/FormFactor.kt b/notes/src/main/java/com/vayunmathur/notes/platform/FormFactor.ktnew file mode 100644index 0000000000..45138ebb53--- /dev/null+++ b/notes/src/main/java/com/vayunmathur/notes/platform/FormFactor.kt@@ -0,0 +1,25 @@+package com.vayunmathur.notes.platform++import android.content.Context+import android.content.pm.PackageManager++/**+ * Runtime form-factor detection for the single merged Notes 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+}
notes/src/main/java/com/vayunmathur/notes/sync/WearLinkBridge.kt
diff --git a/notes-wear/src/main/java/com/vayunmathur/notes/wear/sync/WearLinkBridge.kt b/notes/src/main/java/com/vayunmathur/notes/sync/WearLinkBridge.ktsimilarity index 97%rename from notes-wear/src/main/java/com/vayunmathur/notes/wear/sync/WearLinkBridge.ktrename to notes/src/main/java/com/vayunmathur/notes/sync/WearLinkBridge.ktindex 7ac2843c2b..04393e3217 100644--- a/notes-wear/src/main/java/com/vayunmathur/notes/wear/sync/WearLinkBridge.kt+++ b/notes/src/main/java/com/vayunmathur/notes/sync/WearLinkBridge.kt@@ -1,11 +1,11 @@-package com.vayunmathur.notes.wear.sync+package com.vayunmathur.notes.sync import android.content.Context import com.vayunmathur.library.log.Log import com.vayunmathur.library.wearlink.WearLinkListener import com.vayunmathur.library.wearlink.WearLinkNode import com.vayunmathur.library.wearlink.WearLinkState-import com.vayunmathur.notes.wear.data.WearNotesStore+import com.vayunmathur.notes.data.WearNotesStore import com.vayunmathur.library.wearlink.notes.WearNoteOp import com.vayunmathur.library.wearlink.notes.WearNotesProtocol import com.vayunmathur.library.wearlink.notes.WearNotesSnapshot
notes/src/main/java/com/vayunmathur/notes/ui/WearMainActivity.kt
diff --git a/notes-wear/src/main/java/com/vayunmathur/notes/wear/ui/WearMainActivity.kt b/notes/src/main/java/com/vayunmathur/notes/ui/WearMainActivity.ktsimilarity index 92%rename from notes-wear/src/main/java/com/vayunmathur/notes/wear/ui/WearMainActivity.ktrename to notes/src/main/java/com/vayunmathur/notes/ui/WearMainActivity.ktindex 0ad6d02ccc..3e0aaff7d8 100644--- a/notes-wear/src/main/java/com/vayunmathur/notes/wear/ui/WearMainActivity.kt+++ b/notes/src/main/java/com/vayunmathur/notes/ui/WearMainActivity.kt@@ -1,9 +1,9 @@-package com.vayunmathur.notes.wear.ui+package com.vayunmathur.notes.ui import androidx.compose.runtime.Composable import com.vayunmathur.library.wearlink.WearShellActivity-import com.vayunmathur.notes.wear.data.WearNotesStore-import com.vayunmathur.notes.wear.sync.WearLinkBridge+import com.vayunmathur.notes.data.WearNotesStore+import com.vayunmathur.notes.sync.WearLinkBridge /** * Watch notes entry: recent list, note view and quick-note creation,
notes/src/main/java/com/vayunmathur/notes/ui/WearNoteEditorScreen.kt
diff --git a/notes-wear/src/main/java/com/vayunmathur/notes/wear/ui/WearNoteEditorScreen.kt b/notes/src/main/java/com/vayunmathur/notes/ui/WearNoteEditorScreen.ktsimilarity index 97%rename from notes-wear/src/main/java/com/vayunmathur/notes/wear/ui/WearNoteEditorScreen.ktrename to notes/src/main/java/com/vayunmathur/notes/ui/WearNoteEditorScreen.ktindex 72791bc93d..5ee5dbdf98 100644--- a/notes-wear/src/main/java/com/vayunmathur/notes/wear/ui/WearNoteEditorScreen.kt+++ b/notes/src/main/java/com/vayunmathur/notes/ui/WearNoteEditorScreen.kt@@ -1,4 +1,4 @@-package com.vayunmathur.notes.wear.ui+package com.vayunmathur.notes.ui import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding@@ -20,8 +20,8 @@ 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.notes.wear.R-import com.vayunmathur.notes.wear.data.WearNotesStore+import com.vayunmathur.notes.R+import com.vayunmathur.notes.data.WearNotesStore /** * Quick-note create (syncId = null) and text-only edit. The text fields use
notes/src/main/java/com/vayunmathur/notes/ui/WearNoteScreen.kt
diff --git a/notes-wear/src/main/java/com/vayunmathur/notes/wear/ui/WearNoteScreen.kt b/notes/src/main/java/com/vayunmathur/notes/ui/WearNoteScreen.ktsimilarity index 97%rename from notes-wear/src/main/java/com/vayunmathur/notes/wear/ui/WearNoteScreen.ktrename to notes/src/main/java/com/vayunmathur/notes/ui/WearNoteScreen.ktindex 584b564bdc..a2fbf82b48 100644--- a/notes-wear/src/main/java/com/vayunmathur/notes/wear/ui/WearNoteScreen.kt+++ b/notes/src/main/java/com/vayunmathur/notes/ui/WearNoteScreen.kt@@ -1,4 +1,4 @@-package com.vayunmathur.notes.wear.ui+package com.vayunmathur.notes.ui import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding@@ -15,8 +15,8 @@ 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.notes.wear.R-import com.vayunmathur.notes.wear.data.WearNotesStore+import com.vayunmathur.notes.R+import com.vayunmathur.notes.data.WearNotesStore /** * One note: title plus its (bounded) full text. Edit is offered only for
notes/src/main/java/com/vayunmathur/notes/ui/WearNotesListScreen.kt
diff --git a/notes-wear/src/main/java/com/vayunmathur/notes/wear/ui/WearNotesListScreen.kt b/notes/src/main/java/com/vayunmathur/notes/ui/WearNotesListScreen.ktsimilarity index 96%rename from notes-wear/src/main/java/com/vayunmathur/notes/wear/ui/WearNotesListScreen.ktrename to notes/src/main/java/com/vayunmathur/notes/ui/WearNotesListScreen.ktindex 4353dafe16..d468e42a9f 100644--- a/notes-wear/src/main/java/com/vayunmathur/notes/wear/ui/WearNotesListScreen.kt+++ b/notes/src/main/java/com/vayunmathur/notes/ui/WearNotesListScreen.kt@@ -1,4 +1,4 @@-package com.vayunmathur.notes.wear.ui+package com.vayunmathur.notes.ui import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding@@ -21,9 +21,9 @@ 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.notes.wear.R-import com.vayunmathur.notes.wear.data.WearNotesStore-import com.vayunmathur.notes.wear.sync.WearLinkBridge+import com.vayunmathur.notes.R+import com.vayunmathur.notes.data.WearNotesStore+import com.vayunmathur.notes.sync.WearLinkBridge import kotlinx.coroutines.launch /** Round-screen recent-notes list: most recently updated first, from the local store (offline-safe). */
notes/src/main/java/com/vayunmathur/notes/ui/WearRoute.kt
diff --git a/notes-wear/src/main/java/com/vayunmathur/notes/wear/ui/WearRoute.kt b/notes/src/main/java/com/vayunmathur/notes/ui/WearRoute.ktsimilarity index 93%rename from notes-wear/src/main/java/com/vayunmathur/notes/wear/ui/WearRoute.ktrename to notes/src/main/java/com/vayunmathur/notes/ui/WearRoute.ktindex e28dd73168..508b80339b 100644--- a/notes-wear/src/main/java/com/vayunmathur/notes/wear/ui/WearRoute.kt+++ b/notes/src/main/java/com/vayunmathur/notes/ui/WearRoute.kt@@ -1,4 +1,4 @@-package com.vayunmathur.notes.wear.ui+package com.vayunmathur.notes.ui /** Watch navigation destinations: detail/editor routes carry the note syncId, never selection state. */ sealed interface WearRoute {
notes/src/main/res/values/wear_strings.xml
diff --git a/notes-wear/src/main/res/values/strings.xml b/notes/src/main/res/values/wear_strings.xmlsimilarity index 96%rename from notes-wear/src/main/res/values/strings.xmlrename to notes/src/main/res/values/wear_strings.xmlindex 6806db4da4..0325f66dc7 100644--- a/notes-wear/src/main/res/values/strings.xml+++ b/notes/src/main/res/values/wear_strings.xml@@ -1,6 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> <resources>- <string name="app_name">Notes</string> <string name="wear_empty">No notes synced yet. Open Notes on your phone to sync this watch.</string> <string name="wear_new_note">New note</string> <string name="wear_request_sync">Sync now</string>
notes/src/screenshotTest/kotlin/com/vayunmathur/notes/ui/WearMetadataPreviews.kt
diff --git a/notes-wear/src/screenshotTest/kotlin/com/vayunmathur/notes/wear/ui/MetadataPreviews.kt b/notes/src/screenshotTest/kotlin/com/vayunmathur/notes/ui/WearMetadataPreviews.ktsimilarity index 90%rename from notes-wear/src/screenshotTest/kotlin/com/vayunmathur/notes/wear/ui/MetadataPreviews.ktrename to notes/src/screenshotTest/kotlin/com/vayunmathur/notes/ui/WearMetadataPreviews.ktindex be67d652ef..baab8bbd37 100644--- a/notes-wear/src/screenshotTest/kotlin/com/vayunmathur/notes/wear/ui/MetadataPreviews.kt+++ b/notes/src/screenshotTest/kotlin/com/vayunmathur/notes/ui/WearMetadataPreviews.kt@@ -1,4 +1,4 @@-package com.vayunmathur.notes.wear.ui+package com.vayunmathur.notes.ui import androidx.compose.foundation.background import androidx.compose.foundation.layout.Box@@ -22,11 +22,11 @@ private val fixtureNotes = listOf( ) /**- * Store listing images for `:notes-wear` — every top-level screen/route+ * Store listing images for the watch experience of `:notes` — every top-level screen/route * (list, note detail, editor; create and edit share the editor screen).- * `./gradlew :notes-wear:metadata` copies renders into `metadata_data/photos/notes-wear/wear/`.+ * `./gradlew :notes:metadata` copies renders into `metadata_data/photos/notes/wear/`. */-class MetadataPreviews {+class WearMetadataPreviews { @PreviewTest @Preview(name = "1-list-round", device = ROUND, group = "wear")
notes/src/test/java/com/vayunmathur/notes/platform/FormFactorTest.kt
diff --git a/notes/src/test/java/com/vayunmathur/notes/platform/FormFactorTest.kt b/notes/src/test/java/com/vayunmathur/notes/platform/FormFactorTest.ktnew file mode 100644index 0000000000..85f25143d9--- /dev/null+++ b/notes/src/test/java/com/vayunmathur/notes/platform/FormFactorTest.kt@@ -0,0 +1,19 @@+package com.vayunmathur.notes.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))+ }+}
settings.gradle.kts
diff --git a/settings.gradle.kts b/settings.gradle.ktsindex 14cd69aead..02f2689b89 100644--- a/settings.gradle.kts+++ b/settings.gradle.kts@@ -97,7 +97,6 @@ include(":openassistant") include(":office") include(":passwords") include(":notes")-include(":notes-wear") include(":news") include(":flashcards") include(":files")