library: maps, appstore and contacts wear protocols move into wearlink
- Commit
9121c136538814a19bf7c4a11621a0241f5fc044- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-01 17:24 UTC (4 days ago)
- Parents
b6ccdfa
LOC Phase 2, pairs 7-9. All three verified byte-identical
modulo package. Maps first gained its missing dedicated
phone golden test (golden snapshot JSON, round-trip,
quantization half-step) at parity with the wear side.
Moved to com.vayunmathur.library.wearlink.{maps,appstore,
contacts} with the same symbol names; both copies deleted;
a scoped grep for the old FQNs afterwards finds zero
protocol hits (wear-native WearMapProjection and contacts'
ContactSorting correctly stayed). Appstore's unrelated
data.installer.InstallResult was excluded from the move.
Net: maps -102, appstore -269, contacts -304.
structure_check wear: 4 pairs remain (camera, communicate,
findfamily, todo). Verified: wearlink 9/9, all wear suites,
all phone protocol classes, compiles/assembles/screenshot
compiles; maps:lint and appstore:lint red only on
pre-existing detector errors in unmodified files.Diff
appstore/src/main/java/com/vayunmathur/appstore/platform/AppStoreUiContract.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/platform/AppStoreUiContract.kt b/appstore/src/main/java/com/vayunmathur/appstore/platform/AppStoreUiContract.ktindex a006a1183e..15dec1b58b 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/platform/AppStoreUiContract.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/platform/AppStoreUiContract.kt@@ -108,8 +108,8 @@ data class AppDetailUiState( /** True when a watch running the Wear OS App Store is connected. */ val watchConnected: Boolean = false, /** This app's sync state on the watch; NOT_DOWNLOADED when unknown/absent. */- val wearState: com.vayunmathur.appstore.domain.PhoneWearState =- com.vayunmathur.appstore.domain.PhoneWearState.NOT_DOWNLOADED,+ val wearState: com.vayunmathur.library.wearlink.appstore.PhoneWearState =+ com.vayunmathur.library.wearlink.appstore.PhoneWearState.NOT_DOWNLOADED, /** Why this app cannot be sent to the watch, or null when it can. */ val wearIneligibleReason: String? = null, /** Plain-language detail for the last wear send/install result, where any. */
appstore/src/main/java/com/vayunmathur/appstore/platform/AppStoreViewModel.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/platform/AppStoreViewModel.kt b/appstore/src/main/java/com/vayunmathur/appstore/platform/AppStoreViewModel.ktindex 70c38272a5..528e02a42f 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/platform/AppStoreViewModel.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/platform/AppStoreViewModel.kt@@ -39,7 +39,7 @@ import com.vayunmathur.appstore.data.priority import com.vayunmathur.appstore.data.searchCandidate import com.vayunmathur.appstore.data.security.ApkCertificates import com.vayunmathur.appstore.data.security.VerificationResult-import com.vayunmathur.appstore.domain.PhoneWearState+import com.vayunmathur.library.wearlink.appstore.PhoneWearState import com.vayunmathur.appstore.domain.SearchRanking import com.vayunmathur.appstore.sync.WearSyncManager import com.vayunmathur.library.util.AppMessages
appstore/src/main/java/com/vayunmathur/appstore/sync/WearSyncManager.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/sync/WearSyncManager.kt b/appstore/src/main/java/com/vayunmathur/appstore/sync/WearSyncManager.ktindex db6ab48709..b348cee549 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/sync/WearSyncManager.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/sync/WearSyncManager.kt@@ -2,17 +2,17 @@ package com.vayunmathur.appstore.sync import android.content.Context import com.vayunmathur.appstore.data.UnifiedApp-import com.vayunmathur.appstore.domain.ApkHash-import com.vayunmathur.appstore.domain.ApkOffer-import com.vayunmathur.appstore.domain.InstallResult-import com.vayunmathur.appstore.domain.PhoneWearEvent-import com.vayunmathur.appstore.domain.PhoneWearMachine-import com.vayunmathur.appstore.domain.PhoneWearState-import com.vayunmathur.appstore.domain.WatchState-import com.vayunmathur.appstore.domain.WearCatalog-import com.vayunmathur.appstore.domain.WearCatalogApp-import com.vayunmathur.appstore.domain.WearSyncProtocol-import com.vayunmathur.appstore.domain.watchSendEligibility+import com.vayunmathur.library.wearlink.appstore.ApkHash+import com.vayunmathur.library.wearlink.appstore.ApkOffer+import com.vayunmathur.library.wearlink.appstore.InstallResult+import com.vayunmathur.library.wearlink.appstore.PhoneWearEvent+import com.vayunmathur.library.wearlink.appstore.PhoneWearMachine+import com.vayunmathur.library.wearlink.appstore.PhoneWearState+import com.vayunmathur.library.wearlink.appstore.WatchState+import com.vayunmathur.library.wearlink.appstore.WearCatalog+import com.vayunmathur.library.wearlink.appstore.WearCatalogApp+import com.vayunmathur.library.wearlink.appstore.WearSyncProtocol+import com.vayunmathur.library.wearlink.appstore.watchSendEligibility import com.vayunmathur.library.log.Log import com.vayunmathur.library.network.NetworkClient import com.vayunmathur.library.wearlink.FileStreamSource
appstore/src/main/java/com/vayunmathur/appstore/ui/AppDetailSections.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/ui/AppDetailSections.kt b/appstore/src/main/java/com/vayunmathur/appstore/ui/AppDetailSections.ktindex 2b309b7f20..d48f4a95ac 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/ui/AppDetailSections.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/ui/AppDetailSections.kt@@ -144,15 +144,15 @@ internal fun AppWearSection( else -> { Text( when (state.wearState) {- com.vayunmathur.appstore.domain.PhoneWearState.SENDING ->+ com.vayunmathur.library.wearlink.appstore.PhoneWearState.SENDING -> stringResource(R.string.wear_sending)- com.vayunmathur.appstore.domain.PhoneWearState.ON_WATCH ->+ com.vayunmathur.library.wearlink.appstore.PhoneWearState.ON_WATCH -> stringResource(R.string.wear_on_watch)- com.vayunmathur.appstore.domain.PhoneWearState.INSTALL_REQUESTED ->+ com.vayunmathur.library.wearlink.appstore.PhoneWearState.INSTALL_REQUESTED -> stringResource(R.string.wear_install_requested)- com.vayunmathur.appstore.domain.PhoneWearState.INSTALLED ->+ com.vayunmathur.library.wearlink.appstore.PhoneWearState.INSTALLED -> stringResource(R.string.wear_installed)- com.vayunmathur.appstore.domain.PhoneWearState.FAILED ->+ com.vayunmathur.library.wearlink.appstore.PhoneWearState.FAILED -> stringResource( R.string.wear_failed, state.wearMessage ?: "",@@ -162,11 +162,11 @@ internal fun AppWearSection( style = MaterialTheme.typography.bodySmall, ) when (state.wearState) {- com.vayunmathur.appstore.domain.PhoneWearState.ON_WATCH ->+ com.vayunmathur.library.wearlink.appstore.PhoneWearState.ON_WATCH -> FilledTonalButton( onClick = { actions.requestWatchInstall(app.packageName) }, ) { Text(stringResource(R.string.wear_request_install)) }- com.vayunmathur.appstore.domain.PhoneWearState.SENDING -> Unit+ com.vayunmathur.library.wearlink.appstore.PhoneWearState.SENDING -> Unit else -> FilledTonalButton( onClick = { actions.sendToWatch(app) }, ) { Text(stringResource(R.string.wear_send)) }
appstore/src/test/java/com/vayunmathur/appstore/domain/WearSyncProtocolTest.kt
diff --git a/appstore/src/test/java/com/vayunmathur/appstore/domain/WearSyncProtocolTest.kt b/appstore/src/test/java/com/vayunmathur/appstore/domain/WearSyncProtocolTest.ktindex 5671fcfe72..3e1e26e29b 100644--- a/appstore/src/test/java/com/vayunmathur/appstore/domain/WearSyncProtocolTest.kt+++ b/appstore/src/test/java/com/vayunmathur/appstore/domain/WearSyncProtocolTest.kt@@ -1,5 +1,19 @@ package com.vayunmathur.appstore.domain +import com.vayunmathur.library.wearlink.appstore.ApkHash+import com.vayunmathur.library.wearlink.appstore.ApkOffer+import com.vayunmathur.library.wearlink.appstore.InstallResult+import com.vayunmathur.library.wearlink.appstore.PhoneWearEvent+import com.vayunmathur.library.wearlink.appstore.PhoneWearMachine+import com.vayunmathur.library.wearlink.appstore.PhoneWearState+import com.vayunmathur.library.wearlink.appstore.WatchAppEntry+import com.vayunmathur.library.wearlink.appstore.WatchAppEvent+import com.vayunmathur.library.wearlink.appstore.WatchAppMachine+import com.vayunmathur.library.wearlink.appstore.WatchAppPhase+import com.vayunmathur.library.wearlink.appstore.WearCatalog+import com.vayunmathur.library.wearlink.appstore.WearCatalogApp+import com.vayunmathur.library.wearlink.appstore.WearSyncProtocol+import com.vayunmathur.library.wearlink.appstore.watchSendEligibility import java.io.File import kotlin.test.Test import kotlin.test.assertEquals
appstore/wear/AGENTS.md
diff --git a/appstore/wear/AGENTS.md b/appstore/wear/AGENTS.mdindex 2fca7d65ee..a78fc812e8 100644--- a/appstore/wear/AGENTS.md+++ b/appstore/wear/AGENTS.md@@ -16,9 +16,11 @@ sides, so changing either breaks phone<->watch sync. Bootstrap is a one-time ADB sideload of this APK onto the watch. ## Protocol-`domain/WearSyncProtocol.kt` is a byte-identical copy of the phone's file-(Gradle cannot depend on another app module). Change both copies together;-each side's `WearSyncProtocolTest` pins the same golden JSON.+The wire protocol lives in `:library:wearlink` at+`com.vayunmathur.library.wearlink.appstore.WearSyncProtocol` (shared by+`:appstore` and `:appstore:wear`; neither app module depends on the other).+Each side's `WearSyncProtocolTest` pins the same golden JSON against+that shared code. - Catalog + watch-state sync: WearLink data items (`/appstore/catalog`, `/appstore/watch-state`) - Offers / install requests / results: WearLink messages
appstore/wear/build.gradle.kts
diff --git a/appstore/wear/build.gradle.kts b/appstore/wear/build.gradle.ktsindex d4580ae1ec..efdc22f282 100644--- a/appstore/wear/build.gradle.kts+++ b/appstore/wear/build.gradle.kts@@ -24,8 +24,7 @@ android { } dependencies {- // Watch side of the Wear OS sync (see domain/WearSyncProtocol.kt, the- // byte-identical copy of the phone protocol it must stay in step with).+ // Watch side of the Wear OS sync (protocol in :library:wearlink). implementation(libs.kotlinx.coroutines.android) implementation(project(":library:wearlink")) testImplementation(libs.kotlin.test)
appstore/wear/src/main/java/com/vayunmathur/appstore/wear/data/WearStore.kt
diff --git a/appstore/wear/src/main/java/com/vayunmathur/appstore/wear/data/WearStore.kt b/appstore/wear/src/main/java/com/vayunmathur/appstore/wear/data/WearStore.ktindex f2e3544cc4..e4b2522239 100644--- a/appstore/wear/src/main/java/com/vayunmathur/appstore/wear/data/WearStore.kt+++ b/appstore/wear/src/main/java/com/vayunmathur/appstore/wear/data/WearStore.kt@@ -1,15 +1,15 @@ package com.vayunmathur.appstore.wear.data import android.content.Context-import com.vayunmathur.appstore.wear.domain.ApkOffer-import com.vayunmathur.appstore.wear.domain.WatchAppEntry-import com.vayunmathur.appstore.wear.domain.WatchAppMachine-import com.vayunmathur.appstore.wear.domain.WatchAppEvent-import com.vayunmathur.appstore.wear.domain.WatchAppPhase-import com.vayunmathur.appstore.wear.domain.WatchState-import com.vayunmathur.appstore.wear.domain.WearCatalog-import com.vayunmathur.appstore.wear.domain.WearCatalogApp-import com.vayunmathur.appstore.wear.domain.WearSyncProtocol+import com.vayunmathur.library.wearlink.appstore.ApkOffer+import com.vayunmathur.library.wearlink.appstore.WatchAppEntry+import com.vayunmathur.library.wearlink.appstore.WatchAppMachine+import com.vayunmathur.library.wearlink.appstore.WatchAppEvent+import com.vayunmathur.library.wearlink.appstore.WatchAppPhase+import com.vayunmathur.library.wearlink.appstore.WatchState+import com.vayunmathur.library.wearlink.appstore.WearCatalog+import com.vayunmathur.library.wearlink.appstore.WearCatalogApp+import com.vayunmathur.library.wearlink.appstore.WearSyncProtocol import com.vayunmathur.appstore.wear.sync.WearLinkBridge import com.vayunmathur.library.log.Log import java.io.File
appstore/wear/src/main/java/com/vayunmathur/appstore/wear/domain/WearSyncProtocol.kt
diff --git a/appstore/wear/src/main/java/com/vayunmathur/appstore/wear/domain/WearSyncProtocol.kt b/appstore/wear/src/main/java/com/vayunmathur/appstore/wear/domain/WearSyncProtocol.ktdeleted file mode 100644index 079dde4bbe..0000000000--- a/appstore/wear/src/main/java/com/vayunmathur/appstore/wear/domain/WearSyncProtocol.kt+++ /dev/null@@ -1,295 +0,0 @@-package com.vayunmathur.appstore.wear.domain--import java.io.File-import java.io.InputStream-import java.security.MessageDigest-import kotlinx.serialization.Serializable-import kotlinx.serialization.json.Json--/**- * Phone <-> watch sync protocol for the Wear OS App Store.- *- * SINGLE SOURCE OF TRUTH, DELIBERATELY DUPLICATED: Gradle cannot let one- * application module depend on another, so the wear module- * (`:appstore:wear`, applicationId `com.vayunmathur.appstore`) carries a- * byte-identical copy of this file under `com.vayunmathur.appstore.wear.domain`.- * Change both copies together; each side's unit tests pin the same golden JSON- * so a one-sided edit fails loudly on the side that was not updated.- *- * Transport (WearLink, :library:wearlink — RFCOMM, no Play services):- * - Presence is a completed handshake for [CAPABILITY] (the appId).- * - Data items carry the small state documents: [CATALOG_PATH] phone ->- * watch and [WATCH_STATE_PATH] watch -> phone. Delivery needs a live- * session; each side persists what it receives and republishes on- * reconnect, reconciling the two sides when they meet again.- * - Messages carry ephemeral commands/results ([OFFER_PATH],- * [INSTALL_RESULT_PATH], [REQUEST_STATE_PATH]).- * - A stream ([apkChannelPath]) carries the APK itself, verified against- * the preceding offer's size+SHA-256 before PackageInstaller sees it.- *- * Install honesty: nothing here can install silently. The watch verifies the- * stream against [ApkOffer.sha256], then a person on the watch taps Install- * and confirms the system PackageInstaller prompt. States say exactly that —- * there is no state that claims an install the OS has not confirmed.- */-object WearSyncProtocol {- /** WearLink appId the phone requires in the peer handshake. */- const val CAPABILITY = "appstore_wear_store"-- /** Data-item path (phone -> watch): the [WearCatalog] JSON snapshot. */- const val CATALOG_PATH = "/appstore/catalog"-- /** Data-item path (watch -> phone): the [WatchState] JSON snapshot. */- const val WATCH_STATE_PATH = "/appstore/watch-state"-- /** Message path (phone -> watch): an [ApkOffer] precedes every stream. */- const val OFFER_PATH = "/appstore/apk-offer"-- /** Message path (watch -> phone): an [InstallResult] after the OS answers. */- const val INSTALL_RESULT_PATH = "/appstore/install-result"-- /** Message path (phone -> watch): ask the watch to republish [WATCH_STATE_PATH]. */- const val REQUEST_STATE_PATH = "/appstore/request-state"-- /**- * Message path (phone -> watch): ask the watch to surface its Install- * action for the package named in the payload. This only *asks* — a person- * on the watch still taps Install and confirms the system prompt.- */- const val REQUEST_INSTALL_PATH = "/appstore/request-install"-- /** Stream path prefix (phone -> watch); the package name is the last segment. */- const val APK_CHANNEL_PREFIX = "/appstore/apk/"-- /** Largest single APK this slice will stream (a watch has little storage to spare). */- const val MAX_APK_BYTES = 200L * 1024 * 1024-- /** Stream path streaming [packageName]'s APK. */- fun apkChannelPath(packageName: String): String = APK_CHANNEL_PREFIX + packageName-- /** The package a stream path streams, or null when [path] is not an APK stream. */- fun packageFromChannelPath(path: String): String? =- path.takeIf { it.startsWith(APK_CHANNEL_PREFIX) }- ?.removePrefix(APK_CHANNEL_PREFIX)- ?.takeIf { it.isNotBlank() && '/' !in it }-- /** Wire JSON: unknown keys ignored so a newer side never breaks an older one. */- val json: Json = Json { ignoreUnknownKeys = true }-}--/** One catalog row the phone offers the watch. Mirrors the phone catalog, trimmed to watch size. */-@Serializable-data class WearCatalogApp(- val packageName: String,- val name: String,- val versionName: String? = null,- val versionCode: Long = 0L,- val sizeBytes: Long = 0L,-)--/** The phone's catalog snapshot for the watch ([WearSyncProtocol.CATALOG_PATH]). */-@Serializable-data class WearCatalog(val apps: List<WearCatalogApp> = emptyList())--/**- * Metadata announced by message immediately before an APK stream opens.- * The watch refuses bytes that do not match [sizeBytes]/[sha256] — the channel- * itself carries no metadata, so this offer is the integrity contract.- */-@Serializable-data class ApkOffer(- val packageName: String,- val name: String,- val versionCode: Long,- val sizeBytes: Long,- /** Lowercase hex SHA-256 of the exact bytes about to be streamed. */- val sha256: String,-)--/** Per-app truth as the watch knows it, published in [WatchState]. */-@Serializable-data class WatchAppEntry(- val packageName: String,- /** The APK for this version is fully received and hash-verified on the watch. */- val downloadedVersionCode: Long = 0L,- /** The version the watch's PackageManager reports installed, 0 when absent. */- val installedVersionCode: Long = 0L,- /** True while a verified APK sits waiting for the user to tap Install. */- val installPending: Boolean = false,-)--/** The watch's downloaded/installed snapshot ([WearSyncProtocol.WATCH_STATE_PATH]). */-@Serializable-data class WatchState(val apps: List<WatchAppEntry> = emptyList())--/** The OS install verdict, sent watch -> phone once PackageInstaller answers. */-@Serializable-data class InstallResult(- val packageName: String,- val versionCode: Long,- val installed: Boolean,- /** Plain-language failure from the OS/status, empty on success. */- val message: String = "",-)--/** Per-app sync state on the phone, per package. */-enum class PhoneWearState {- /** No watch, or the watch has never been offered this app. */- NOT_DOWNLOADED,- /** The APK channel is open and bytes are moving. */- SENDING,- /** Verified APK is on the watch; nobody has asked to install it yet. */- ON_WATCH,- /** Install was requested; the watch still owes a user tap + OS confirmation. */- INSTALL_REQUESTED,- /** The watch's PackageManager confirms this (or a newer) version installed. */- INSTALLED,- /** The last send/verify/install step failed; see the message kept beside the state. */- FAILED,-}--/** Events that move the phone-side per-app state. */-sealed interface PhoneWearEvent {- data object SendStarted : PhoneWearEvent- data class SendFinished(val success: Boolean) : PhoneWearEvent- data object InstallRequested : PhoneWearEvent- data class ResultReceived(val result: InstallResult) : PhoneWearEvent- data class Reconciled(val entry: WatchAppEntry?, val catalogVersionCode: Long) : PhoneWearEvent- data object WatchGone : PhoneWearEvent-}--/** Pure phone-side state machine; the Android transport only feeds it events. */-object PhoneWearMachine {- fun reduce(state: PhoneWearState, event: PhoneWearEvent): PhoneWearState = when (event) {- PhoneWearEvent.SendStarted -> PhoneWearState.SENDING- is PhoneWearEvent.SendFinished ->- if (event.success) PhoneWearState.ON_WATCH else PhoneWearState.FAILED- PhoneWearEvent.InstallRequested ->- if (state == PhoneWearState.ON_WATCH) PhoneWearState.INSTALL_REQUESTED else state- is PhoneWearEvent.ResultReceived ->- if (event.result.installed) PhoneWearState.INSTALLED else PhoneWearState.FAILED- is PhoneWearEvent.Reconciled -> reconcile(state, event.entry, event.catalogVersionCode)- PhoneWearEvent.WatchGone ->- if (state == PhoneWearState.SENDING) PhoneWearState.FAILED else state- }-- /**- * Fold the watch's published truth into the local state. A live transfer- * ([PhoneWearState.SENDING]) is never overwritten by a stale snapshot; an- * install the watch confirms wins over everything else.- */- private fun reconcile(- state: PhoneWearState,- entry: WatchAppEntry?,- catalogVersionCode: Long,- ): PhoneWearState {- if (state == PhoneWearState.SENDING) return state- if (entry == null) {- return if (state == PhoneWearState.INSTALLED) PhoneWearState.NOT_DOWNLOADED else state- }- return when {- entry.installedVersionCode >= catalogVersionCode && catalogVersionCode > 0 ->- PhoneWearState.INSTALLED- entry.installPending -> PhoneWearState.INSTALL_REQUESTED- entry.downloadedVersionCode >= catalogVersionCode && catalogVersionCode > 0 ->- PhoneWearState.ON_WATCH- entry.downloadedVersionCode > 0 -> PhoneWearState.ON_WATCH- else -> state- }- }-}--/** Per-app state on the watch, per package. */-enum class WatchAppPhase {- /** Offered in the catalog; no bytes yet. */- LISTED,- /** Channel open, bytes arriving. */- RECEIVING,- /** Stream arrived but failed the size/hash contract; bytes deleted. */- REJECTED,- /** Verified APK on disk, waiting for the user to tap Install. */- READY_TO_INSTALL,- /** PackageInstaller session committed; waiting for the OS verdict. */- INSTALLING,- /** PackageManager confirms the package installed. */- INSTALLED,- /** Install was attempted and the OS (or user) said no. */- INSTALL_FAILED,-}--/** Events that move the watch-side per-app state. */-sealed interface WatchAppEvent {- data object ReceiveStarted : WatchAppEvent- data class ReceiveFinished(val verified: Boolean) : WatchAppEvent- data object InstallTapped : WatchAppEvent- data class InstallFinished(val installed: Boolean) : WatchAppEvent- data object BecameInstalled : WatchAppEvent-}--/** Pure watch-side state machine; services/installers only feed it events. */-object WatchAppMachine {- fun reduce(phase: WatchAppPhase, event: WatchAppEvent): WatchAppPhase = when (event) {- WatchAppEvent.ReceiveStarted -> WatchAppPhase.RECEIVING- is WatchAppEvent.ReceiveFinished ->- if (event.verified) WatchAppPhase.READY_TO_INSTALL else WatchAppPhase.REJECTED- WatchAppEvent.InstallTapped ->- if (phase == WatchAppPhase.READY_TO_INSTALL ||- phase == WatchAppPhase.INSTALL_FAILED- ) {- WatchAppPhase.INSTALLING- } else {- phase- }- is WatchAppEvent.InstallFinished ->- if (event.installed) WatchAppPhase.INSTALLED else WatchAppPhase.INSTALL_FAILED- WatchAppEvent.BecameInstalled -> WatchAppPhase.INSTALLED- }-}--/**- * Whether the phone can offer this catalog row to the watch at all.- *- * The catalog cannot prove a phone UI will be usable on a watch, and this does- * not pretend otherwise: the gate is purely technical — one streamable APK- * (split sets need a multi-file session protocol this slice does not carry)- * with known bytes to hash. A truly incompatible APK is refused by the watch's- * PackageManager at install time and that verdict is reported, not hidden.- */-fun watchSendEligibility(- apkUrl: String?,- splitCount: Int,- sizeBytes: Long,-): String? = when {- apkUrl.isNullOrBlank() -> "this source published no downloadable APK"- splitCount > 0 -> "split APK sets cannot be sent to the watch yet"- sizeBytes > WearSyncProtocol.MAX_APK_BYTES -> "too large for the watch"- else -> null-}--/** Streaming SHA-256 helpers: the offer/watch verification contract. */-object ApkHash {- private const val BUFFER_SIZE = 64 * 1024-- /** Lowercase hex SHA-256 of [input]'s contents (consumed, not closed). */- fun sha256Hex(input: InputStream): String {- val digest = MessageDigest.getInstance("SHA-256")- val buffer = ByteArray(BUFFER_SIZE)- while (true) {- val read = input.read(buffer)- if (read < 0) break- if (read > 0) digest.update(buffer, 0, read)- }- return digest.digest().joinToString("") { "%02x".format(it) }- }-- /** Lowercase hex SHA-256 of [file]. */- fun sha256Hex(file: File): String = file.inputStream().buffered().use { sha256Hex(it) }-- /**- * True when [file] is exactly [offer]'s bytes. A mismatch (or a truncated- * stream, which the size check catches first) means the bytes are refused:- * callers delete the file and never hand it to PackageInstaller.- */- fun verify(file: File, offer: ApkOffer): Boolean =- file.length() == offer.sizeBytes && sha256Hex(file) == offer.sha256.lowercase()-}
appstore/wear/src/main/java/com/vayunmathur/appstore/wear/platform/InstallResultReceiver.kt
diff --git a/appstore/wear/src/main/java/com/vayunmathur/appstore/wear/platform/InstallResultReceiver.kt b/appstore/wear/src/main/java/com/vayunmathur/appstore/wear/platform/InstallResultReceiver.ktindex 59fe4b5a6f..3357677bdf 100644--- a/appstore/wear/src/main/java/com/vayunmathur/appstore/wear/platform/InstallResultReceiver.kt+++ b/appstore/wear/src/main/java/com/vayunmathur/appstore/wear/platform/InstallResultReceiver.kt@@ -6,8 +6,8 @@ import android.content.Intent import android.content.pm.PackageInstaller import android.os.Build import com.vayunmathur.appstore.wear.data.WearStore-import com.vayunmathur.appstore.wear.domain.InstallResult-import com.vayunmathur.appstore.wear.domain.WatchAppEvent+import com.vayunmathur.library.wearlink.appstore.InstallResult+import com.vayunmathur.library.wearlink.appstore.WatchAppEvent import com.vayunmathur.library.log.Log /**
appstore/wear/src/main/java/com/vayunmathur/appstore/wear/platform/WearInstaller.kt
diff --git a/appstore/wear/src/main/java/com/vayunmathur/appstore/wear/platform/WearInstaller.kt b/appstore/wear/src/main/java/com/vayunmathur/appstore/wear/platform/WearInstaller.ktindex e031406273..3d2ca63f92 100644--- a/appstore/wear/src/main/java/com/vayunmathur/appstore/wear/platform/WearInstaller.kt+++ b/appstore/wear/src/main/java/com/vayunmathur/appstore/wear/platform/WearInstaller.kt@@ -5,7 +5,7 @@ import android.content.Context import android.content.Intent import android.content.pm.PackageInstaller import com.vayunmathur.appstore.wear.data.WearStore-import com.vayunmathur.appstore.wear.domain.WatchAppEvent+import com.vayunmathur.library.wearlink.appstore.WatchAppEvent import com.vayunmathur.library.log.Log import java.io.File
appstore/wear/src/main/java/com/vayunmathur/appstore/wear/sync/WearLinkBridge.kt
diff --git a/appstore/wear/src/main/java/com/vayunmathur/appstore/wear/sync/WearLinkBridge.kt b/appstore/wear/src/main/java/com/vayunmathur/appstore/wear/sync/WearLinkBridge.ktindex 6a10790911..5dc79846be 100644--- a/appstore/wear/src/main/java/com/vayunmathur/appstore/wear/sync/WearLinkBridge.kt+++ b/appstore/wear/src/main/java/com/vayunmathur/appstore/wear/sync/WearLinkBridge.kt@@ -3,11 +3,11 @@ package com.vayunmathur.appstore.wear.sync import android.content.Context import android.content.Intent import com.vayunmathur.appstore.wear.data.WearStore-import com.vayunmathur.appstore.wear.domain.ApkOffer-import com.vayunmathur.appstore.wear.domain.InstallResult-import com.vayunmathur.appstore.wear.domain.WatchAppEvent-import com.vayunmathur.appstore.wear.domain.WearCatalog-import com.vayunmathur.appstore.wear.domain.WearSyncProtocol+import com.vayunmathur.library.wearlink.appstore.ApkOffer+import com.vayunmathur.library.wearlink.appstore.InstallResult+import com.vayunmathur.library.wearlink.appstore.WatchAppEvent+import com.vayunmathur.library.wearlink.appstore.WearCatalog+import com.vayunmathur.library.wearlink.appstore.WearSyncProtocol import com.vayunmathur.appstore.wear.ui.WearMainActivity import com.vayunmathur.library.log.Log import com.vayunmathur.library.wearlink.StreamSink
appstore/wear/src/main/java/com/vayunmathur/appstore/wear/ui/WearMainActivity.kt
diff --git a/appstore/wear/src/main/java/com/vayunmathur/appstore/wear/ui/WearMainActivity.kt b/appstore/wear/src/main/java/com/vayunmathur/appstore/wear/ui/WearMainActivity.ktindex bd030698f3..ac8c9bdd77 100644--- a/appstore/wear/src/main/java/com/vayunmathur/appstore/wear/ui/WearMainActivity.kt+++ b/appstore/wear/src/main/java/com/vayunmathur/appstore/wear/ui/WearMainActivity.kt@@ -21,7 +21,7 @@ import androidx.wear.compose.material.MaterialTheme import androidx.wear.compose.material.Text import com.vayunmathur.appstore.wear.R import com.vayunmathur.appstore.wear.data.WearStore-import com.vayunmathur.appstore.wear.domain.WatchAppPhase+import com.vayunmathur.library.wearlink.appstore.WatchAppPhase import com.vayunmathur.appstore.wear.platform.WearInstaller /**
appstore/wear/src/screenshotTest/kotlin/com/vayunmathur/appstore/wear/ui/MetadataPreviews.kt
diff --git a/appstore/wear/src/screenshotTest/kotlin/com/vayunmathur/appstore/wear/ui/MetadataPreviews.kt b/appstore/wear/src/screenshotTest/kotlin/com/vayunmathur/appstore/wear/ui/MetadataPreviews.ktindex 0152d4d8c1..ce36d95ceb 100644--- a/appstore/wear/src/screenshotTest/kotlin/com/vayunmathur/appstore/wear/ui/MetadataPreviews.kt+++ b/appstore/wear/src/screenshotTest/kotlin/com/vayunmathur/appstore/wear/ui/MetadataPreviews.kt@@ -11,8 +11,8 @@ import androidx.compose.ui.tooling.preview.Preview import androidx.wear.compose.material.MaterialTheme import com.android.tools.screenshot.PreviewTest import com.vayunmathur.appstore.wear.data.WearRow-import com.vayunmathur.appstore.wear.domain.WatchAppPhase-import com.vayunmathur.appstore.wear.domain.WearCatalogApp+import com.vayunmathur.library.wearlink.appstore.WatchAppPhase+import com.vayunmathur.library.wearlink.appstore.WearCatalogApp /** Round watch, 454x454px class (227dp at 320dpi). */ private const val ROUND = "spec:width=227dp,height=227dp,dpi=320"
appstore/wear/src/test/java/com/vayunmathur/appstore/wear/domain/WearSyncProtocolTest.kt
diff --git a/appstore/wear/src/test/java/com/vayunmathur/appstore/wear/domain/WearSyncProtocolTest.kt b/appstore/wear/src/test/java/com/vayunmathur/appstore/wear/domain/WearSyncProtocolTest.ktindex 068f1922d4..0416814149 100644--- a/appstore/wear/src/test/java/com/vayunmathur/appstore/wear/domain/WearSyncProtocolTest.kt+++ b/appstore/wear/src/test/java/com/vayunmathur/appstore/wear/domain/WearSyncProtocolTest.kt@@ -1,5 +1,19 @@ package com.vayunmathur.appstore.wear.domain +import com.vayunmathur.library.wearlink.appstore.ApkHash+import com.vayunmathur.library.wearlink.appstore.ApkOffer+import com.vayunmathur.library.wearlink.appstore.InstallResult+import com.vayunmathur.library.wearlink.appstore.PhoneWearEvent+import com.vayunmathur.library.wearlink.appstore.PhoneWearMachine+import com.vayunmathur.library.wearlink.appstore.PhoneWearState+import com.vayunmathur.library.wearlink.appstore.WatchAppEntry+import com.vayunmathur.library.wearlink.appstore.WatchAppEvent+import com.vayunmathur.library.wearlink.appstore.WatchAppMachine+import com.vayunmathur.library.wearlink.appstore.WatchAppPhase+import com.vayunmathur.library.wearlink.appstore.WearCatalog+import com.vayunmathur.library.wearlink.appstore.WearCatalogApp+import com.vayunmathur.library.wearlink.appstore.WearSyncProtocol+import com.vayunmathur.library.wearlink.appstore.watchSendEligibility import java.io.File import kotlin.test.Test import kotlin.test.assertEquals
contacts-wear/AGENTS.md
diff --git a/contacts-wear/AGENTS.md b/contacts-wear/AGENTS.mdindex 155506e5c1..a90e0180bb 100644--- a/contacts-wear/AGENTS.md+++ b/contacts-wear/AGENTS.md@@ -7,8 +7,11 @@ - 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: `domain/WearContactsProtocol.kt` is a deliberate copy of the phone- file in `contacts/domain/`; change both together (golden-JSON tests pin it).+- 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/src/main/java/com/vayunmathur/contacts/wear/data/WearContactsStore.kt
diff --git a/contacts-wear/src/main/java/com/vayunmathur/contacts/wear/data/WearContactsStore.kt b/contacts-wear/src/main/java/com/vayunmathur/contacts/wear/data/WearContactsStore.ktindex 4a171febdd..6f970cd19c 100644--- a/contacts-wear/src/main/java/com/vayunmathur/contacts/wear/data/WearContactsStore.kt+++ b/contacts-wear/src/main/java/com/vayunmathur/contacts/wear/data/WearContactsStore.kt@@ -1,10 +1,10 @@ package com.vayunmathur.contacts.wear.data import android.content.Context-import com.vayunmathur.contacts.wear.domain.WearContact-import com.vayunmathur.contacts.wear.domain.WearContactsChunk-import com.vayunmathur.contacts.wear.domain.WearContactsManifest-import com.vayunmathur.contacts.wear.domain.WearContactsProtocol+import com.vayunmathur.library.wearlink.contacts.WearContact+import com.vayunmathur.library.wearlink.contacts.WearContactsChunk+import com.vayunmathur.library.wearlink.contacts.WearContactsManifest+import com.vayunmathur.library.wearlink.contacts.WearContactsProtocol import java.io.File import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow
contacts-wear/src/main/java/com/vayunmathur/contacts/wear/domain/WearContactsProtocol.kt
diff --git a/contacts-wear/src/main/java/com/vayunmathur/contacts/wear/domain/WearContactsProtocol.kt b/contacts-wear/src/main/java/com/vayunmathur/contacts/wear/domain/WearContactsProtocol.ktdeleted file mode 100644index 5f60ff07f7..0000000000--- a/contacts-wear/src/main/java/com/vayunmathur/contacts/wear/domain/WearContactsProtocol.kt+++ /dev/null@@ -1,324 +0,0 @@-package com.vayunmathur.contacts.wear.domain--import kotlinx.serialization.Serializable-import kotlinx.serialization.json.Json--/**- * Phone <-> watch contacts protocol.- *- * SINGLE SOURCE OF TRUTH, DELIBERATELY DUPLICATED: Gradle cannot let- * one application module depend on another, so `:contacts-wear`- * (applicationId `com.vayunmathur.contacts`, same debug/release signing as the- * phone app) carries a byte-identical copy under- * `com.vayunmathur.contacts.wear.domain`. Change both copies together; each- * side's tests pin the same golden JSON.- *- * Large-address-book honesty: the watch does NOT get the whole book verbatim.- * [WearSnapshotBuilder] caps the snapshot at [WearContactsProtocol.MAX_CONTACTS]- * contacts (favourites first, then A-Z), at most 3 phones + 3 emails each, with- * every field truncated. The manifest says how many contacts exist vs how many- * were sent, so the watch can show "1,000 of 4,213 contacts" instead of- * pretending the rest do not exist. Each chunk is one WearLink data item- * (transport-chunked again underneath by :library:wearlink); chunks arrive- * in any order and are only applied once the manifest's chunk count is- * complete.- */-object WearContactsProtocol {- /** WearLink appId the phone requires in the peer handshake. */- const val CAPABILITY = "contacts_wear_companion"-- /** Data-item manifest path for the current snapshot generation. */- const val MANIFEST_PATH = "/contacts/snapshot/manifest"-- /** Data-item prefix for chunk paths: [chunkPath] appends the chunk index. */- const val CHUNK_PREFIX = "/contacts/snapshot/chunk/"-- /** Data-item path (watch -> phone): the watch's received-state snapshot. */- const val WATCH_STATE_PATH = "/contacts/watch-state"-- /** Message path (watch -> phone): republish the snapshot. */- const val REQUEST_SNAPSHOT_PATH = "/contacts/request-snapshot"-- /** Message path (watch -> phone): start this call/message on the phone. */- const val HANDOFF_PATH = "/contacts/handoff"-- /** Hard cap on contacts ever sent to the watch. */- const val MAX_CONTACTS = 1_000-- /** Per-contact caps: a watch row never needs a fourth number. */- const val MAX_PHONES_PER_CONTACT = 3- const val MAX_EMAILS_PER_CONTACT = 3-- /** Field caps, in characters, applied before serialisation. */- const val MAX_NAME_CHARS = 80- const val MAX_PHONE_CHARS = 40- const val MAX_EMAIL_CHARS = 80-- /** Target ceiling for one chunk's JSON bytes (kept near the old 100 KB item cap). */- const val MAX_CHUNK_BYTES = 50_000-- /** Chunk path for chunk [index] of the current generation. */- fun chunkPath(index: Int): String = CHUNK_PREFIX + index-- /** Chunk index encoded by [path], or null when [path] is not a chunk path. */- fun chunkIndexFromPath(path: String): Int? =- path.takeIf { it.startsWith(CHUNK_PREFIX) }- ?.removePrefix(CHUNK_PREFIX)- ?.toIntOrNull()- ?.takeIf { it >= 0 }-- /** Wire JSON: unknown keys ignored so a newer side never breaks an older one. */- val json: Json = Json { ignoreUnknownKeys = true }-}--/** One watch-sized contact row: display name plus capped phone/email lists. */-@Serializable-data class WearContact(- val id: Long,- val name: String,- val phones: List<String> = emptyList(),- val emails: List<String> = emptyList(),- val isFavorite: Boolean = false,-)--/** One data item's payload: chunk [index] of generation [generation]. */-@Serializable-data class WearContactsChunk(- val generation: Long,- val index: Int,- val contacts: List<WearContact> = emptyList(),-)--/** The manifest data item: what a complete snapshot looks like. */-@Serializable-data class WearContactsManifest(- val generation: Long,- val chunkCount: Int,- /** Contacts that exist on the phone (before the cap). */- val totalContacts: Int,- /** Contacts actually sent (after the cap). */- val includedContacts: Int,- /** True when [includedContacts] < [totalContacts]: the watch shows a subset. */- val truncated: Boolean,- val sentAtMillis: Long,-)--/** The watch's received-state snapshot ([WearContactsProtocol.WATCH_STATE_PATH]). */-@Serializable-data class WearWatchState(- val contactCount: Int = 0,- val generation: Long = 0L,- val receivedAtMillis: Long = 0L,-)--/** A call/message the watch asks the phone to start (it cannot, or prefers not to). */-@Serializable-data class WearHandoffRequest(- /** "call" or "message"; anything else is ignored by the phone. */- val kind: String,- /** Phone number (call/message) or email address. */- val value: String,-) {- companion object {- const val KIND_CALL = "call"- const val KIND_MESSAGE = "message"- }-}--/** Pure snapshot builder: cap, truncate, sort, chunk. No Android types. */-object WearSnapshotBuilder {-- /**- * Build the capped contact list: favourites first, then A-Z by name- * (case-insensitive), ties by id. Blank-valued phones/emails are dropped,- * duplicates collapsed, every list and field capped per the protocol.- */- fun select(contacts: List<WearContact>): List<WearContact> =- contacts- .map { normalise(it) }- .filter { it.name.isNotBlank() || it.phones.isNotEmpty() || it.emails.isNotEmpty() }- .distinctBy { it.id }- .sortedWith(- compareByDescending<WearContact> { it.isFavorite }- .thenBy { it.name.lowercase() }- .thenBy { it.id },- )- .take(WearContactsProtocol.MAX_CONTACTS)-- /** Manifest for [selected] out of [totalContacts] contacts, in [chunkCount] chunks. */- fun manifest(- generation: Long,- totalContacts: Int,- selected: List<WearContact>,- chunkCount: Int,- sentAtMillis: Long,- ): WearContactsManifest = WearContactsManifest(- generation = generation,- chunkCount = chunkCount,- totalContacts = totalContacts,- includedContacts = selected.size,- truncated = selected.size < totalContacts,- sentAtMillis = sentAtMillis,- )-- /**- * Split [selected] into chunks whose encoded JSON stays at or under- * [WearContactsProtocol.MAX_CHUNK_BYTES]. Greedy: a contact joins the open- * chunk while it fits, otherwise it opens a new one. Field caps guarantee a- * single contact always fits in an empty chunk.- */- fun chunk(generation: Long, selected: List<WearContact>): List<WearContactsChunk> {- if (selected.isEmpty()) {- return listOf(WearContactsChunk(generation, 0, emptyList()))- }- val chunks = mutableListOf<WearContactsChunk>()- var current = mutableListOf<WearContact>()- var currentBytes = emptyChunkBytes(generation, 0)- for (contact in selected) {- val contactBytes = encodedSize(contact)- if (current.isNotEmpty() &&- currentBytes + contactBytes + 1 > WearContactsProtocol.MAX_CHUNK_BYTES- ) {- chunks += WearContactsChunk(generation, chunks.size, current)- current = mutableListOf()- currentBytes = emptyChunkBytes(generation, chunks.size)- }- current += contact- currentBytes += contactBytes + 1 // comma between array elements- }- if (current.isNotEmpty()) {- chunks += WearContactsChunk(generation, chunks.size, current)- }- return chunks- }-- /** Serialised sizes are measured, never guessed: encode and count UTF-8 bytes. */- private fun encodedSize(contact: WearContact): Int =- WearContactsProtocol.json.encodeToString(contact).encodeToByteArray().size-- private fun emptyChunkBytes(generation: Long, index: Int): Int =- WearContactsProtocol.json- .encodeToString(WearContactsChunk(generation, index, emptyList()))- .encodeToByteArray().size-- private fun normalise(contact: WearContact): WearContact = WearContact(- id = contact.id,- name = contact.name.trim().take(WearContactsProtocol.MAX_NAME_CHARS),- phones = contact.phones- .map { it.trim().take(WearContactsProtocol.MAX_PHONE_CHARS) }- .filter { it.isNotBlank() }- .distinct()- .take(WearContactsProtocol.MAX_PHONES_PER_CONTACT),- emails = contact.emails- .map { it.trim().take(WearContactsProtocol.MAX_EMAIL_CHARS) }- .filter { it.isNotBlank() }- .distinct()- .take(WearContactsProtocol.MAX_EMAILS_PER_CONTACT),- isFavorite = contact.isFavorite,- )-}--/** In-memory search over the watch's local copy. Same token rule as the phone list. */-object WearContactSearch {-- /**- * Every whitespace-separated token must match the name, a phone, or an email.- * Digit tokens also match against the digits-only form of each phone, so- * "415 555" finds "+1 (415) 555-0100". Blank query returns all contacts,- * in the order given (the store keeps snapshot order).- */- fun filter(contacts: List<WearContact>, query: String): List<WearContact> {- val tokens = query.trim().lowercase().split(WHITESPACE).filter { it.isNotBlank() }- if (tokens.isEmpty()) return contacts- return contacts.filter { contact -> tokens.all { token -> matches(contact, token) } }- }-- private fun matches(contact: WearContact, token: String): Boolean {- if (contact.name.lowercase().contains(token)) return true- val tokenDigits = token.filter { it.isDigit() }- return contact.phones.any { phone ->- phone.lowercase().contains(token) ||- (tokenDigits.isNotEmpty() && phone.filter { it.isDigit() }.contains(tokenDigits))- } || contact.emails.any { it.lowercase().contains(token) }- }-- private val WHITESPACE = Regex("\\s+")-}--/** What the watch can honestly offer for one contact, given this device. */-enum class WearAction {- /** Place the call on the watch itself (it has telephony + a dialer). */- CALL_ON_WATCH,-- /** Ask the phone to place the call (watch cannot, phone is reachable). */- CALL_VIA_PHONE,-- /** Open the watch's own SMS composer. */- MESSAGE_ON_WATCH,-- /** Ask the phone to open its SMS composer. */- MESSAGE_VIA_PHONE,-- /** Open the watch's own mail composer. */- EMAIL_ON_WATCH,-}--object WearActionPolicy {-- /**- * Actions for [contact], in display order. A button exists only when the- * platform can actually complete it: direct actions need a local handler,- * phone-handoff actions need a reachable phone. No handler + no phone- * means no button — never a dead tap. Email never hands off (the phone's- * composer is not a better answer than silence here; the address is shown- * as text so it can be read aloud / typed elsewhere).- */- fun actionsFor(- contact: WearContact,- hasTelephony: Boolean,- hasSmsHandler: Boolean,- hasEmailHandler: Boolean,- phoneReachable: Boolean,- ): List<WearAction> {- val actions = mutableListOf<WearAction>()- val hasPhone = contact.phones.isNotEmpty()- if (hasPhone && hasTelephony) actions += WearAction.CALL_ON_WATCH- else if (hasPhone && phoneReachable) actions += WearAction.CALL_VIA_PHONE- if (hasPhone && hasSmsHandler) actions += WearAction.MESSAGE_ON_WATCH- else if (hasPhone && phoneReachable) actions += WearAction.MESSAGE_VIA_PHONE- if (contact.emails.isNotEmpty() && hasEmailHandler) actions += WearAction.EMAIL_ON_WATCH- return actions- }-}--/** Phone-side presence of the watch companion, as the phone UI reports it. */-enum class WearPresence {- /** No reachable node advertises the wear capability (or no WearLink session). */- NO_WATCH,-- /** A watch advertises the capability but has not published state yet. */- WATCH_CONNECTED,-- /** The watch published state for the current (or an older) generation. */- SYNCED,-}--object WearPresencePolicy {-- /** Presence from capability nodes + the last watch state heard, if any. */- fun presence(nodeCount: Int, watchState: WearWatchState?): WearPresence = when {- nodeCount <= 0 -> WearPresence.NO_WATCH- watchState == null -> WearPresence.WATCH_CONNECTED- else -> WearPresence.SYNCED- }-- /** One-line status for the phone UI; states only what is known. */- fun statusText(presence: WearPresence, watchState: WearWatchState?): String = when (presence) {- WearPresence.NO_WATCH ->- "No Wear OS watch with Contacts found. Install Contacts on the watch, then open it once."- WearPresence.WATCH_CONNECTED ->- "Watch found. Contacts will sync to it; open Contacts on the watch to check."- WearPresence.SYNCED ->- "Watch has ${watchState?.contactCount ?: 0} contacts from the last sync."- }-}
contacts-wear/src/main/java/com/vayunmathur/contacts/wear/sync/WearLinkBridge.kt
diff --git a/contacts-wear/src/main/java/com/vayunmathur/contacts/wear/sync/WearLinkBridge.kt b/contacts-wear/src/main/java/com/vayunmathur/contacts/wear/sync/WearLinkBridge.ktindex b675b0ae2a..c945f9f3ac 100644--- a/contacts-wear/src/main/java/com/vayunmathur/contacts/wear/sync/WearLinkBridge.kt+++ b/contacts-wear/src/main/java/com/vayunmathur/contacts/wear/sync/WearLinkBridge.kt@@ -2,9 +2,9 @@ package com.vayunmathur.contacts.wear.sync import android.content.Context import com.vayunmathur.contacts.wear.data.WearContactsStore-import com.vayunmathur.contacts.wear.domain.WearContactsChunk-import com.vayunmathur.contacts.wear.domain.WearContactsManifest-import com.vayunmathur.contacts.wear.domain.WearContactsProtocol+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.log.Log import com.vayunmathur.library.wearlink.WearLinkListener import com.vayunmathur.library.wearlink.WearLinkNode
contacts-wear/src/main/java/com/vayunmathur/contacts/wear/sync/WearWatchStatePublisher.kt
diff --git a/contacts-wear/src/main/java/com/vayunmathur/contacts/wear/sync/WearWatchStatePublisher.kt b/contacts-wear/src/main/java/com/vayunmathur/contacts/wear/sync/WearWatchStatePublisher.ktindex 098978fc6c..6e5724e2d0 100644--- a/contacts-wear/src/main/java/com/vayunmathur/contacts/wear/sync/WearWatchStatePublisher.kt+++ b/contacts-wear/src/main/java/com/vayunmathur/contacts/wear/sync/WearWatchStatePublisher.kt@@ -2,9 +2,9 @@ package com.vayunmathur.contacts.wear.sync import android.content.Context import com.vayunmathur.contacts.wear.data.WearSnapshot-import com.vayunmathur.contacts.wear.domain.WearContactsProtocol-import com.vayunmathur.contacts.wear.domain.WearHandoffRequest-import com.vayunmathur.contacts.wear.domain.WearWatchState+import com.vayunmathur.library.wearlink.contacts.WearContactsProtocol+import com.vayunmathur.library.wearlink.contacts.WearHandoffRequest+import com.vayunmathur.library.wearlink.contacts.WearWatchState import com.vayunmathur.library.log.Log import kotlinx.serialization.encodeToString
contacts-wear/src/main/java/com/vayunmathur/contacts/wear/ui/ContactDetailScreen.kt
diff --git a/contacts-wear/src/main/java/com/vayunmathur/contacts/wear/ui/ContactDetailScreen.kt b/contacts-wear/src/main/java/com/vayunmathur/contacts/wear/ui/ContactDetailScreen.ktindex 3f0cd28cfa..d14bb04716 100644--- a/contacts-wear/src/main/java/com/vayunmathur/contacts/wear/ui/ContactDetailScreen.kt+++ b/contacts-wear/src/main/java/com/vayunmathur/contacts/wear/ui/ContactDetailScreen.kt@@ -21,10 +21,10 @@ 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.domain.WearAction-import com.vayunmathur.contacts.wear.domain.WearActionPolicy-import com.vayunmathur.contacts.wear.domain.WearContact-import com.vayunmathur.contacts.wear.domain.WearHandoffRequest+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 kotlinx.coroutines.launch
contacts-wear/src/main/java/com/vayunmathur/contacts/wear/ui/ContactListScreen.kt
diff --git a/contacts-wear/src/main/java/com/vayunmathur/contacts/wear/ui/ContactListScreen.kt b/contacts-wear/src/main/java/com/vayunmathur/contacts/wear/ui/ContactListScreen.ktindex e4a4f7d470..d97363d41e 100644--- a/contacts-wear/src/main/java/com/vayunmathur/contacts/wear/ui/ContactListScreen.kt+++ b/contacts-wear/src/main/java/com/vayunmathur/contacts/wear/ui/ContactListScreen.kt@@ -20,8 +20,8 @@ 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.wear.domain.WearContact-import com.vayunmathur.contacts.wear.domain.WearContactSearch+import com.vayunmathur.library.wearlink.contacts.WearContact+import com.vayunmathur.library.wearlink.contacts.WearContactSearch /** * Round-screen contact list over the locally synced copy: works fully offline.@@ -49,8 +49,6 @@ fun ContactListScreen( ) } item {- // SCAFFOLD SEARCH EXCEPTION: Wear Compose Material Scaffold has no- // search slot; this is the watch's only (round-screen) search field. BasicTextField( value = query, onValueChange = onQueryChange,
contacts-wear/src/screenshotTest/kotlin/com/vayunmathur/contacts/wear/ui/MetadataPreviews.kt
diff --git a/contacts-wear/src/screenshotTest/kotlin/com/vayunmathur/contacts/wear/ui/MetadataPreviews.kt b/contacts-wear/src/screenshotTest/kotlin/com/vayunmathur/contacts/wear/ui/MetadataPreviews.ktindex fdb85b4950..b9e4a3143b 100644--- a/contacts-wear/src/screenshotTest/kotlin/com/vayunmathur/contacts/wear/ui/MetadataPreviews.kt+++ b/contacts-wear/src/screenshotTest/kotlin/com/vayunmathur/contacts/wear/ui/MetadataPreviews.kt@@ -11,7 +11,7 @@ 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.wear.domain.WearContact+import com.vayunmathur.library.wearlink.contacts.WearContact import com.vayunmathur.contacts.wear.platform.WearDeviceCapabilities /** Round watch, 454x454px class (227dp at 320dpi). */
contacts-wear/src/test/java/com/vayunmathur/contacts/wear/data/WearSnapshotReassemblerTest.kt
diff --git a/contacts-wear/src/test/java/com/vayunmathur/contacts/wear/data/WearSnapshotReassemblerTest.kt b/contacts-wear/src/test/java/com/vayunmathur/contacts/wear/data/WearSnapshotReassemblerTest.ktindex 78e820929d..d4b4d065ae 100644--- a/contacts-wear/src/test/java/com/vayunmathur/contacts/wear/data/WearSnapshotReassemblerTest.kt+++ b/contacts-wear/src/test/java/com/vayunmathur/contacts/wear/data/WearSnapshotReassemblerTest.kt@@ -1,9 +1,9 @@ package com.vayunmathur.contacts.wear.data -import com.vayunmathur.contacts.wear.domain.WearContact-import com.vayunmathur.contacts.wear.domain.WearContactsChunk-import com.vayunmathur.contacts.wear.domain.WearContactsManifest+import com.vayunmathur.library.wearlink.contacts.WearContact+import com.vayunmathur.library.wearlink.contacts.WearContactsChunk+import com.vayunmathur.library.wearlink.contacts.WearContactsManifest import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertNull
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.ktindex a6c2f74ed5..03c7b1aa14 100644--- 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.kt@@ -1,5 +1,15 @@ 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
contacts/src/main/java/com/vayunmathur/contacts/sync/WearContactsSync.kt
diff --git a/contacts/src/main/java/com/vayunmathur/contacts/sync/WearContactsSync.kt b/contacts/src/main/java/com/vayunmathur/contacts/sync/WearContactsSync.ktindex 0eaf6bad7a..4ffd2c1a1b 100644--- a/contacts/src/main/java/com/vayunmathur/contacts/sync/WearContactsSync.kt+++ b/contacts/src/main/java/com/vayunmathur/contacts/sync/WearContactsSync.kt@@ -4,14 +4,14 @@ import android.content.Context import android.content.Intent import android.net.Uri import com.vayunmathur.contacts.data.Contact-import com.vayunmathur.contacts.domain.WearContactsManifest-import com.vayunmathur.contacts.domain.WearContactsProtocol-import com.vayunmathur.contacts.domain.WearHandoffRequest-import com.vayunmathur.contacts.domain.WearPresence-import com.vayunmathur.contacts.domain.WearPresencePolicy-import com.vayunmathur.contacts.domain.WearSnapshotBuilder-import com.vayunmathur.contacts.domain.WearWatchState-import com.vayunmathur.contacts.domain.WearContact+import com.vayunmathur.library.wearlink.contacts.WearContactsManifest+import com.vayunmathur.library.wearlink.contacts.WearContactsProtocol+import com.vayunmathur.library.wearlink.contacts.WearHandoffRequest+import com.vayunmathur.library.wearlink.contacts.WearPresence+import com.vayunmathur.library.wearlink.contacts.WearPresencePolicy+import com.vayunmathur.library.wearlink.contacts.WearSnapshotBuilder+import com.vayunmathur.library.wearlink.contacts.WearWatchState+import com.vayunmathur.library.wearlink.contacts.WearContact import com.vayunmathur.library.log.Log import com.vayunmathur.library.wearlink.WearLinkListener import com.vayunmathur.library.wearlink.WearLinkNode
contacts/src/main/java/com/vayunmathur/contacts/ui/SettingsPage.kt
diff --git a/contacts/src/main/java/com/vayunmathur/contacts/ui/SettingsPage.kt b/contacts/src/main/java/com/vayunmathur/contacts/ui/SettingsPage.ktindex a7b98c3957..a95d6cc2fe 100644--- a/contacts/src/main/java/com/vayunmathur/contacts/ui/SettingsPage.kt+++ b/contacts/src/main/java/com/vayunmathur/contacts/ui/SettingsPage.kt@@ -245,7 +245,7 @@ fun SettingsPage(viewModel: ContactViewModel, backStack: NavBackStack<Route>) { val wearPresence by wearSync.presence.collectAsStateWithLifecycle() val wearState by wearSync.watchState.collectAsStateWithLifecycle() SettingsRow(- title = com.vayunmathur.contacts.domain.WearPresencePolicy.statusText(wearPresence, wearState),+ title = com.vayunmathur.library.wearlink.contacts.WearPresencePolicy.statusText(wearPresence, wearState), supportingText = "Up to 1,000 contacts (favourites first) are kept on the watch for offline use.", trailingContent = { Button(onClick = { wearSync.publish(allContactsForExport) }) {
contacts/src/test/java/com/vayunmathur/contacts/domain/WearContactsProtocolTest.kt
diff --git a/contacts/src/test/java/com/vayunmathur/contacts/domain/WearContactsProtocolTest.kt b/contacts/src/test/java/com/vayunmathur/contacts/domain/WearContactsProtocolTest.ktindex 5c4420c179..24c838895e 100644--- a/contacts/src/test/java/com/vayunmathur/contacts/domain/WearContactsProtocolTest.kt+++ b/contacts/src/test/java/com/vayunmathur/contacts/domain/WearContactsProtocolTest.kt@@ -1,5 +1,15 @@ package com.vayunmathur.contacts.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
docs/structure/wear-protocol-pairs.tsv
diff --git a/docs/structure/wear-protocol-pairs.tsv b/docs/structure/wear-protocol-pairs.tsvindex 645692709e..db43921966 100644--- a/docs/structure/wear-protocol-pairs.tsv+++ b/docs/structure/wear-protocol-pairs.tsv@@ -11,11 +11,11 @@ # (com.vayunmathur.library.wearlink.calendar), weather # (com.vayunmathur.library.wearlink.weather), music # (com.vayunmathur.library.wearlink.music), notes-# (com.vayunmathur.library.wearlink.notes).-appstore appstore/src/main/java/com/vayunmathur/appstore/domain/WearSyncProtocol.kt appstore/wear/src/main/java/com/vayunmathur/appstore/wear/domain/WearSyncProtocol.kt+# (com.vayunmathur.library.wearlink.notes), maps+# (com.vayunmathur.library.wearlink.maps), appstore+# (com.vayunmathur.library.wearlink.appstore), contacts+# (com.vayunmathur.library.wearlink.contacts). camera camera/src/main/java/com/vayunmathur/camera/domain/WearCameraProtocol.kt camera-wear/src/main/java/com/vayunmathur/camera/wear/domain/WearCameraProtocol.kt communicate communicate/src/main/java/com/vayunmathur/communicate/domain/WearCommunicateProtocol.kt communicate-wear/src/main/java/com/vayunmathur/communicate/wear/domain/WearCommunicateProtocol.kt-contacts contacts/src/main/java/com/vayunmathur/contacts/domain/WearContactsProtocol.kt contacts-wear/src/main/java/com/vayunmathur/contacts/wear/domain/WearContactsProtocol.kt findfamily findfamily/src/main/java/com/vayunmathur/findfamily/domain/WearFindFamilyProtocol.kt findfamily-wear/src/main/java/com/vayunmathur/findfamily/wear/domain/WearFindFamilyProtocol.kt-maps maps/src/main/java/com/vayunmathur/maps/domain/WearMapsProtocol.kt maps-wear/src/main/java/com/vayunmathur/maps/wear/domain/WearMapsProtocol.kt todo todo/src/main/java/com/vayunmathur/todo/domain/WearTodoProtocol.kt todo-wear/src/main/java/com/vayunmathur/todo/wear/domain/WearTodoProtocol.kt
library/wearlink/AGENTS.md
diff --git a/library/wearlink/AGENTS.md b/library/wearlink/AGENTS.mdindex 86bcde4ef1..549ddc2c56 100644--- a/library/wearlink/AGENTS.md+++ b/library/wearlink/AGENTS.md@@ -17,7 +17,7 @@ duplicated per app pair: each migrated protocol lives in `com.vayunmathur.library.wearlink.<app>` and is consumed by both the phone and wear app modules (which may not depend on each other). Golden-JSON tests stay in each app module and pin the shared code's wire format.-Migrated: clock, launcher, calendar, weather, music, notes. Remaining pairs are listed in+Migrated: clock, launcher, calendar, weather, music, notes, maps, appstore, contacts. Remaining pairs are listed in `docs/structure/wear-protocol-pairs.tsv`. ## Verify
library/wearlink/src/main/java/com/vayunmathur/library/wearlink/appstore/WearSyncProtocol.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/domain/WearSyncProtocol.kt b/library/wearlink/src/main/java/com/vayunmathur/library/wearlink/appstore/WearSyncProtocol.ktsimilarity index 96%rename from appstore/src/main/java/com/vayunmathur/appstore/domain/WearSyncProtocol.ktrename to library/wearlink/src/main/java/com/vayunmathur/library/wearlink/appstore/WearSyncProtocol.ktindex 64b8b53344..b035772f7f 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/domain/WearSyncProtocol.kt+++ b/library/wearlink/src/main/java/com/vayunmathur/library/wearlink/appstore/WearSyncProtocol.kt@@ -1,4 +1,4 @@-package com.vayunmathur.appstore.domain+package com.vayunmathur.library.wearlink.appstore import java.io.File import java.io.InputStream@@ -9,12 +9,9 @@ import kotlinx.serialization.json.Json /** * Phone <-> watch sync protocol for the Wear OS App Store. *- * SINGLE SOURCE OF TRUTH, DELIBERATELY DUPLICATED: Gradle cannot let one- * application module depend on another, so the wear module- * (`:appstore:wear`, applicationId `com.vayunmathur.appstore`) carries a- * byte-identical copy of this file under `com.vayunmathur.appstore.wear.domain`.- * Change both copies together; each side's unit tests pin the same golden JSON- * so a one-sided edit fails loudly on the side that was not updated.+ * Shared by the phone (`:appstore`) and the watch (`:appstore:wear`)+ * through `:library:wearlink`; neither app module depends on the other.+ * Each side's unit tests pin the same golden JSON against this code. * * Transport (WearLink, :library:wearlink — RFCOMM, no Play services): * - Presence is a completed handshake for [CAPABILITY] (the appId).
library/wearlink/src/main/java/com/vayunmathur/library/wearlink/contacts/WearContactsProtocol.kt
diff --git a/contacts/src/main/java/com/vayunmathur/contacts/domain/WearContactsProtocol.kt b/library/wearlink/src/main/java/com/vayunmathur/library/wearlink/contacts/WearContactsProtocol.ktsimilarity index 96%rename from contacts/src/main/java/com/vayunmathur/contacts/domain/WearContactsProtocol.ktrename to library/wearlink/src/main/java/com/vayunmathur/library/wearlink/contacts/WearContactsProtocol.ktindex 69cc409b78..d0ecaf710b 100644--- a/contacts/src/main/java/com/vayunmathur/contacts/domain/WearContactsProtocol.kt+++ b/library/wearlink/src/main/java/com/vayunmathur/library/wearlink/contacts/WearContactsProtocol.kt@@ -1,4 +1,4 @@-package com.vayunmathur.contacts.domain+package com.vayunmathur.library.wearlink.contacts import kotlinx.serialization.Serializable import kotlinx.serialization.json.Json@@ -6,12 +6,9 @@ import kotlinx.serialization.json.Json /** * Phone <-> watch contacts protocol. *- * SINGLE SOURCE OF TRUTH, DELIBERATELY DUPLICATED: Gradle cannot let- * one application module depend on another, so `:contacts-wear`- * (applicationId `com.vayunmathur.contacts`, same debug/release signing as the- * phone app) carries a byte-identical copy under- * `com.vayunmathur.contacts.wear.domain`. Change both copies together; each- * side's tests pin the same golden JSON.+ * Shared by the phone (`:contacts`) and the watch (`:contacts-wear`)+ * through `:library:wearlink`; neither app module depends on the other.+ * Each side's tests pin the same golden JSON against this code. * * Large-address-book honesty: the watch does NOT get the whole book verbatim. * [WearSnapshotBuilder] caps the snapshot at [WearContactsProtocol.MAX_CONTACTS]
library/wearlink/src/main/java/com/vayunmathur/library/wearlink/maps/WearMapsProtocol.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/domain/WearMapsProtocol.kt b/library/wearlink/src/main/java/com/vayunmathur/library/wearlink/maps/WearMapsProtocol.ktsimilarity index 95%rename from maps/src/main/java/com/vayunmathur/maps/domain/WearMapsProtocol.ktrename to library/wearlink/src/main/java/com/vayunmathur/library/wearlink/maps/WearMapsProtocol.ktindex 93882fba4f..99d0942d91 100644--- a/maps/src/main/java/com/vayunmathur/maps/domain/WearMapsProtocol.kt+++ b/library/wearlink/src/main/java/com/vayunmathur/library/wearlink/maps/WearMapsProtocol.kt@@ -1,4 +1,4 @@-package com.vayunmathur.maps.domain+package com.vayunmathur.library.wearlink.maps import kotlinx.serialization.Serializable import kotlinx.serialization.json.Json@@ -7,11 +7,9 @@ import kotlin.math.cos /** * Phone <-> watch protocol for the Wear OS Maps companion. *- * SINGLE SOURCE OF TRUTH, DELIBERATELY DUPLICATED: Gradle cannot let one- * application module depend on another, so the wear module (`:maps:wear`,- * applicationId `com.vayunmathur.maps`) carries a copy of this file under- * `com.vayunmathur.maps.wear.domain`. Change both copies together; each- * side's unit tests pin the same golden JSON so a one-sided edit fails.+ * Shared by the phone (`:maps`) and the watch (`:maps:wear`) through+ * `:library:wearlink`; neither app module depends on the other. Each+ * side's unit tests pin the same golden JSON against this code. * * Transport (WearLink, :library:wearlink — RFCOMM, no Play services): * - Presence is a completed handshake for [CAPABILITY] (the appId).
maps-wear/AGENTS.md
diff --git a/maps-wear/AGENTS.md b/maps-wear/AGENTS.mdindex 2bcac5a866..b9e3ee693c 100644--- a/maps-wear/AGENTS.md+++ b/maps-wear/AGENTS.md@@ -16,9 +16,11 @@ changing either breaks phone<->watch sync. Bootstrap is a one-time ADB sideload of this APK onto the watch. ## Protocol-`domain/WearMapsProtocol.kt` is a copy of the phone's file (Gradle cannot-depend on another app module). Change both copies together; each side's-`WearMapsProtocolTest` pins the same golden JSON.+The wire protocol lives in `:library:wearlink` at+`com.vayunmathur.library.wearlink.maps.WearMapsProtocol` (shared by+`:maps` and `:maps:wear`; neither app module depends on the other).+Each side's `WearMapsProtocolTest` pins the same golden JSON against+that shared code. - Region snapshot: WearLink data item (`/maps/region`, phone -> watch) — bounded, simplified, quantized vector geometry for a Canvas renderer;
maps-wear/src/main/java/com/vayunmathur/maps/wear/data/WearMapsStore.kt
diff --git a/maps-wear/src/main/java/com/vayunmathur/maps/wear/data/WearMapsStore.kt b/maps-wear/src/main/java/com/vayunmathur/maps/wear/data/WearMapsStore.ktindex 27e9c39789..83418f5957 100644--- a/maps-wear/src/main/java/com/vayunmathur/maps/wear/data/WearMapsStore.kt+++ b/maps-wear/src/main/java/com/vayunmathur/maps/wear/data/WearMapsStore.kt@@ -2,11 +2,11 @@ package com.vayunmathur.maps.wear.data import android.content.Context import com.vayunmathur.library.log.Log-import com.vayunmathur.maps.wear.domain.WearMapSnapshot-import com.vayunmathur.maps.wear.domain.WearMapsProtocol-import com.vayunmathur.maps.wear.domain.WearPosition-import com.vayunmathur.maps.wear.domain.WearRouteState-import com.vayunmathur.maps.wear.domain.WearWatchState+import com.vayunmathur.library.wearlink.maps.WearMapSnapshot+import com.vayunmathur.library.wearlink.maps.WearMapsProtocol+import com.vayunmathur.library.wearlink.maps.WearPosition+import com.vayunmathur.library.wearlink.maps.WearRouteState+import com.vayunmathur.library.wearlink.maps.WearWatchState import java.io.File import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow
maps-wear/src/main/java/com/vayunmathur/maps/wear/domain/WearMapProjection.kt
diff --git a/maps-wear/src/main/java/com/vayunmathur/maps/wear/domain/WearMapProjection.kt b/maps-wear/src/main/java/com/vayunmathur/maps/wear/domain/WearMapProjection.ktindex 517e00b425..123c26f662 100644--- a/maps-wear/src/main/java/com/vayunmathur/maps/wear/domain/WearMapProjection.kt+++ b/maps-wear/src/main/java/com/vayunmathur/maps/wear/domain/WearMapProjection.kt@@ -1,5 +1,14 @@ package com.vayunmathur.maps.wear.domain +import com.vayunmathur.library.wearlink.maps.WearLineKind+import com.vayunmathur.library.wearlink.maps.WearMapLine+import com.vayunmathur.library.wearlink.maps.WearMapSnapshot+import com.vayunmathur.library.wearlink.maps.WearMapsProtocol+import com.vayunmathur.library.wearlink.maps.WearRouteState+import com.vayunmathur.library.wearlink.maps.WearSavedPlace+import com.vayunmathur.library.wearlink.maps.wearDequantize+import com.vayunmathur.library.wearlink.maps.wearMetersEast+import com.vayunmathur.library.wearlink.maps.wearMetersNorth import kotlin.math.sqrt /**
maps-wear/src/main/java/com/vayunmathur/maps/wear/domain/WearMapsProtocol.kt
diff --git a/maps-wear/src/main/java/com/vayunmathur/maps/wear/domain/WearMapsProtocol.kt b/maps-wear/src/main/java/com/vayunmathur/maps/wear/domain/WearMapsProtocol.ktdeleted file mode 100644index 4037d6fb75..0000000000--- a/maps-wear/src/main/java/com/vayunmathur/maps/wear/domain/WearMapsProtocol.kt+++ /dev/null@@ -1,202 +0,0 @@-package com.vayunmathur.maps.wear.domain--import kotlinx.serialization.Serializable-import kotlinx.serialization.json.Json-import kotlin.math.cos--/**- * Phone <-> watch protocol for the Wear OS Maps companion.- *- * SINGLE SOURCE OF TRUTH, DELIBERATELY DUPLICATED: Gradle cannot let one- * application module depend on another, so the wear module (`:maps:wear`,- * applicationId `com.vayunmathur.maps`) carries a copy of this file under- * `com.vayunmathur.maps.wear.domain`. Change both copies together; each- * side's unit tests pin the same golden JSON so a one-sided edit fails.- *- * Transport (WearLink, :library:wearlink — RFCOMM, no Play services):- * - Presence is a completed handshake for [CAPABILITY] (the appId).- * - Data items: [REGION_PATH] phone -> watch (bounded vector snapshot of- * the area around the user), [ROUTE_PATH] phone -> watch (navigation- * overlay, or `active=false` to clear it), [POSITION_PATH] phone ->- * watch (small frequent user position inside the current region) and- * [WATCH_STATE_PATH] watch -> phone (what the watch last applied).- * - Messages: [REQUEST_REGION_PATH] watch -> phone (ask for a fresh- * region; delivery needs a live session, nothing wakes a dead process).- *- * What a snapshot contains — and what it honestly does not:- * Coordinates are quantized metres east/north of the snapshot centre- * ([QUANT_STEP_M] per unit, so round-trip error is at most half a step).- * Lines carry roads/paths/water/buildings/route geometry from- * `:library:map`'s Kotlin geometry API (`MapGeometry`, decoding the- * downloaded `.mamaps` archive through the renderer's own codec);- * points carry POIs from the offline index and saved places.- * [WearMapSnapshot.degraded] names kinds that are *unavailable* - no- * readable archive - never kinds that were read and simply have no- * features in this region (an ocean bbox is a complete, empty map).- * The watch renders whatever lines it is given.- *- * Position source is the PHONE. The watch does not run its own GPS in- * this design (a watch fix would cost watch battery for a worse antenna- * and would disagree with the phone map the user navigates by); the- * phone's location manager / navigation session is the single source.- */-object WearMapsProtocol {- /** WearLink appId the phone requires in the peer handshake. */- const val CAPABILITY = "maps_wear_companion"-- /** Data-item path (phone -> watch): the [WearMapSnapshot] JSON. */- const val REGION_PATH = "/maps/region"-- /** Data-item path (phone -> watch): the [WearRouteState] JSON. */- const val ROUTE_PATH = "/maps/route"-- /** Data-item path (phone -> watch): the [WearPosition] JSON. */- const val POSITION_PATH = "/maps/position"-- /** Data-item path (watch -> phone): the [WearWatchState] JSON. */- const val WATCH_STATE_PATH = "/maps/watch-state"-- /** Message path (watch -> phone): ask the phone to republish the region. */- const val REQUEST_REGION_PATH = "/maps/request-region"-- /** Radius (m) of the square region a snapshot covers around its centre. */- const val REGION_RADIUS_M = 600-- /** Metres per quantized coordinate unit (round-trip error <= half). */- const val QUANT_STEP_M = 2.0-- /** Largest region JSON in UTF-8 bytes; extraction degrades to fit. */- const val MAX_JSON_BYTES = 48_000-- /** Largest route JSON in UTF-8 bytes; route extraction decimates to fit. */- const val MAX_ROUTE_JSON_BYTES = 24_000-- /** A snapshot older than this (watch clock vs [WearMapSnapshot.generatedAtMillis]) reads stale. */- const val STALE_AFTER_MS = 90_000L-- /** Wire JSON: unknown keys ignored so a newer side never breaks an older one. */- val json: Json = Json { ignoreUnknownKeys = true }-}--/** Geometry kind of a [WearMapLine]; the watch strokes/fills by kind. */-@Serializable-enum class WearLineKind { ROAD, PATH, WATER, BUILDING, ROUTE }--/**- * One simplified polyline/polygon, quantized metres east/north of the- * snapshot (or route) origin as a flat `[dx, dy, dx, dy, ...]` list in- * [WearMapsProtocol.QUANT_STEP_M] units. [closed] polygons fill.- */-@Serializable-data class WearMapLine(- val kind: WearLineKind,- val pts: List<Int> = emptyList(),- val closed: Boolean = false,- val name: String = "",-)--/** One POI point, quantized metres east/north of the snapshot centre. */-@Serializable-data class WearMapPoint(- /** Offline POI type id (phone `PoiCategories` numbering); -1 for saved. */- val type: Int = 0,- val name: String = "",- val dx: Int = 0,- val dy: Int = 0,-)--/** One saved place (absolute coords: the glance list needs distance, not just on-map position). */-@Serializable-data class WearSavedPlace(- val name: String = "",- val latE7: Int = 0,- val lonE7: Int = 0,-)--/**- * The phone's bounded vector snapshot for the watch ([WearMapsProtocol.REGION_PATH]).- * Centre is E7 degrees; all geometry is quantized metres relative to it.- */-@Serializable-data class WearMapSnapshot(- val generatedAtMillis: Long = 0L,- val centerLatE7: Int = 0,- val centerLonE7: Int = 0,- val radiusM: Int = WearMapsProtocol.REGION_RADIUS_M,- val lines: List<WearMapLine> = emptyList(),- val points: List<WearMapPoint> = emptyList(),- val saved: List<WearSavedPlace> = emptyList(),- /** True when the byte cap dropped or coarsened geometry. */- val truncated: Boolean = false,- /**- * Human-honest names of what is unavailable/coarser, e.g. "roads",- * "detail". A basemap kind appears here only when it could not be- * sourced (no readable archive), not when it was read and the- * region simply contains none. Empty = full.- */- val degraded: List<String> = emptyList(),- /** User bearing (degrees clockwise from north) at publish, -1 = unknown. */- val userBearingDeg: Int = -1,-)--/** The phone's current user position ([WearMapsProtocol.POSITION_PATH]); -1 bearing = unknown. */-@Serializable-data class WearPosition(- val latE7: Int = 0,- val lonE7: Int = 0,- val bearingDeg: Int = -1,- val atMillis: Long = 0L,-)--/** One maneuver in the route-detail list. */-@Serializable-data class WearManeuver(- val text: String = "",- /** Maneuver kind name from the phone router (e.g. TURN_LEFT); may be empty. */- val kind: String = "",- /** Cumulative distance from route start (m) at which this maneuver occurs. */- val distanceFromStartM: Int = 0,-)--/**- * Navigation overlay for the watch ([WearMapsProtocol.ROUTE_PATH]).- * `active=false` is the explicit clear: route ended/arrived/stopped.- * [routePts] are quantized metres relative to ([routeOriginLatE7],- * [routeOriginLonE7]), independent of any region snapshot's centre, so a- * region republish can never misalign the overlay.- */-@Serializable-data class WearRouteState(- val active: Boolean = false,- val destinationName: String = "",- val routeOriginLatE7: Int = 0,- val routeOriginLonE7: Int = 0,- val routePts: List<Int> = emptyList(),- val maneuvers: List<WearManeuver> = emptyList(),- val nextText: String = "",- val distanceToNextM: Int = 0,- val distanceRemainingM: Int = 0,- val etaEpochMs: Long = 0L,- val generatedAtMillis: Long = 0L,-)--/** What the watch last applied, published at [WearMapsProtocol.WATCH_STATE_PATH]. */-@Serializable-data class WearWatchState(- val appliedGeneratedAtMillis: Long = 0L,- val hasRegion: Boolean = false,- val routeActive: Boolean = false,-)--/** Metres east of [originLon] for [lon] at [originLat] (equirectangular; fine at region scale). */-fun wearMetersEast(originLat: Double, originLon: Double, lon: Double): Double =- (lon - originLon) * 111_320.0 * cos(Math.toRadians(originLat))--/** Metres north of [originLat] for [lat]. */-fun wearMetersNorth(originLat: Double, lat: Double): Double = (lat - originLat) * 110_540.0--/** Quantize metres to [WearMapsProtocol.QUANT_STEP_M] units. */-fun wearQuantize(meters: Double): Int = Math.round(meters / WearMapsProtocol.QUANT_STEP_M).toInt()--/** Inverse of [wearQuantize]. */-fun wearDequantize(units: Int): Double = units * WearMapsProtocol.QUANT_STEP_M
maps-wear/src/main/java/com/vayunmathur/maps/wear/sync/WearLinkBridge.kt
diff --git a/maps-wear/src/main/java/com/vayunmathur/maps/wear/sync/WearLinkBridge.kt b/maps-wear/src/main/java/com/vayunmathur/maps/wear/sync/WearLinkBridge.ktindex 4d07b41b39..83793f2628 100644--- a/maps-wear/src/main/java/com/vayunmathur/maps/wear/sync/WearLinkBridge.kt+++ b/maps-wear/src/main/java/com/vayunmathur/maps/wear/sync/WearLinkBridge.kt@@ -6,10 +6,10 @@ import com.vayunmathur.library.wearlink.WearLinkListener import com.vayunmathur.library.wearlink.WearLinkNode import com.vayunmathur.library.wearlink.WearLinkState import com.vayunmathur.maps.wear.data.WearMapsStore-import com.vayunmathur.maps.wear.domain.WearMapSnapshot-import com.vayunmathur.maps.wear.domain.WearMapsProtocol-import com.vayunmathur.maps.wear.domain.WearPosition-import com.vayunmathur.maps.wear.domain.WearRouteState+import com.vayunmathur.library.wearlink.maps.WearMapSnapshot+import com.vayunmathur.library.wearlink.maps.WearMapsProtocol+import com.vayunmathur.library.wearlink.maps.WearPosition+import com.vayunmathur.library.wearlink.maps.WearRouteState import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.SupervisorJob
maps-wear/src/main/java/com/vayunmathur/maps/wear/ui/WearMapCanvas.kt
diff --git a/maps-wear/src/main/java/com/vayunmathur/maps/wear/ui/WearMapCanvas.kt b/maps-wear/src/main/java/com/vayunmathur/maps/wear/ui/WearMapCanvas.ktindex d016fd06a8..26fa4580b2 100644--- a/maps-wear/src/main/java/com/vayunmathur/maps/wear/ui/WearMapCanvas.kt+++ b/maps-wear/src/main/java/com/vayunmathur/maps/wear/ui/WearMapCanvas.kt@@ -9,13 +9,13 @@ import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Path import androidx.compose.ui.graphics.PathEffect import androidx.compose.ui.graphics.drawscope.Stroke-import com.vayunmathur.maps.wear.domain.WearLineKind+import com.vayunmathur.library.wearlink.maps.WearLineKind+import com.vayunmathur.library.wearlink.maps.WearMapSnapshot+import com.vayunmathur.library.wearlink.maps.WearPosition+import com.vayunmathur.library.wearlink.maps.WearRouteState+import com.vayunmathur.library.wearlink.maps.wearDequantize import com.vayunmathur.maps.wear.domain.WearMapProjection-import com.vayunmathur.maps.wear.domain.WearMapSnapshot-import com.vayunmathur.maps.wear.domain.WearPosition-import com.vayunmathur.maps.wear.domain.WearRouteState import com.vayunmathur.maps.wear.domain.wearBasemapLines-import com.vayunmathur.maps.wear.domain.wearDequantize import com.vayunmathur.maps.wear.domain.wearOffsetInSnapshot import com.vayunmathur.maps.wear.domain.wearRoutePointInSnapshot import kotlin.math.cos
maps-wear/src/main/java/com/vayunmathur/maps/wear/ui/WearMapScreen.kt
diff --git a/maps-wear/src/main/java/com/vayunmathur/maps/wear/ui/WearMapScreen.kt b/maps-wear/src/main/java/com/vayunmathur/maps/wear/ui/WearMapScreen.ktindex 4a848dcb83..3b3aadc7e0 100644--- a/maps-wear/src/main/java/com/vayunmathur/maps/wear/ui/WearMapScreen.kt+++ b/maps-wear/src/main/java/com/vayunmathur/maps/wear/ui/WearMapScreen.kt@@ -52,9 +52,9 @@ fun WearMapScreen( /** Stateless map behind [WearMapScreen]: snapshot/route/position are parameters for previews. */ @Composable internal fun WearMapContent(- snapshot: com.vayunmathur.maps.wear.domain.WearMapSnapshot?,- route: com.vayunmathur.maps.wear.domain.WearRouteState?,- position: com.vayunmathur.maps.wear.domain.WearPosition?,+ snapshot: com.vayunmathur.library.wearlink.maps.WearMapSnapshot?,+ route: com.vayunmathur.library.wearlink.maps.WearRouteState?,+ position: com.vayunmathur.library.wearlink.maps.WearPosition?, connected: Boolean, nowMillis: Long, onOpenRoute: () -> Unit,
maps-wear/src/main/java/com/vayunmathur/maps/wear/ui/WearRouteDetailScreen.kt
diff --git a/maps-wear/src/main/java/com/vayunmathur/maps/wear/ui/WearRouteDetailScreen.kt b/maps-wear/src/main/java/com/vayunmathur/maps/wear/ui/WearRouteDetailScreen.ktindex 5c5756a783..ed87023cbb 100644--- a/maps-wear/src/main/java/com/vayunmathur/maps/wear/ui/WearRouteDetailScreen.kt+++ b/maps-wear/src/main/java/com/vayunmathur/maps/wear/ui/WearRouteDetailScreen.kt@@ -31,7 +31,7 @@ fun WearRouteDetailScreen( /** Stateless route detail behind [WearRouteDetailScreen]: route is a parameter for previews. */ @Composable-internal fun WearRouteDetailContent(route: com.vayunmathur.maps.wear.domain.WearRouteState?, onBack: () -> Unit) {+internal fun WearRouteDetailContent(route: com.vayunmathur.library.wearlink.maps.WearRouteState?, onBack: () -> Unit) { val listState = rememberScalingLazyListState() ScalingLazyColumn(state = listState) { item {
maps-wear/src/main/java/com/vayunmathur/maps/wear/ui/WearSavedScreen.kt
diff --git a/maps-wear/src/main/java/com/vayunmathur/maps/wear/ui/WearSavedScreen.kt b/maps-wear/src/main/java/com/vayunmathur/maps/wear/ui/WearSavedScreen.ktindex ee060b5cc9..66ea29cfab 100644--- a/maps-wear/src/main/java/com/vayunmathur/maps/wear/ui/WearSavedScreen.kt+++ b/maps-wear/src/main/java/com/vayunmathur/maps/wear/ui/WearSavedScreen.kt@@ -37,7 +37,7 @@ fun WearSavedScreen( /** Stateless saved places behind [WearSavedScreen]: snapshot/position are parameters for previews. */ @Composable-internal fun WearSavedContent(snapshot: com.vayunmathur.maps.wear.domain.WearMapSnapshot?, position: com.vayunmathur.maps.wear.domain.WearPosition?, onBack: () -> Unit) {+internal fun WearSavedContent(snapshot: com.vayunmathur.library.wearlink.maps.WearMapSnapshot?, position: com.vayunmathur.library.wearlink.maps.WearPosition?, onBack: () -> Unit) { val listState = rememberScalingLazyListState() ScalingLazyColumn(state = listState) { item {
maps-wear/src/screenshotTest/kotlin/com/vayunmathur/maps/wear/ui/MetadataPreviews.kt
diff --git a/maps-wear/src/screenshotTest/kotlin/com/vayunmathur/maps/wear/ui/MetadataPreviews.kt b/maps-wear/src/screenshotTest/kotlin/com/vayunmathur/maps/wear/ui/MetadataPreviews.ktindex 71b0554b32..5f86b69daf 100644--- a/maps-wear/src/screenshotTest/kotlin/com/vayunmathur/maps/wear/ui/MetadataPreviews.kt+++ b/maps-wear/src/screenshotTest/kotlin/com/vayunmathur/maps/wear/ui/MetadataPreviews.kt@@ -10,14 +10,14 @@ 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.maps.wear.domain.WearLineKind-import com.vayunmathur.maps.wear.domain.WearManeuver-import com.vayunmathur.maps.wear.domain.WearMapLine-import com.vayunmathur.maps.wear.domain.WearMapPoint-import com.vayunmathur.maps.wear.domain.WearMapSnapshot-import com.vayunmathur.maps.wear.domain.WearPosition-import com.vayunmathur.maps.wear.domain.WearRouteState-import com.vayunmathur.maps.wear.domain.WearSavedPlace+import com.vayunmathur.library.wearlink.maps.WearLineKind+import com.vayunmathur.library.wearlink.maps.WearManeuver+import com.vayunmathur.library.wearlink.maps.WearMapLine+import com.vayunmathur.library.wearlink.maps.WearMapPoint+import com.vayunmathur.library.wearlink.maps.WearMapSnapshot+import com.vayunmathur.library.wearlink.maps.WearPosition+import com.vayunmathur.library.wearlink.maps.WearRouteState+import com.vayunmathur.library.wearlink.maps.WearSavedPlace /** Round watch, 454x454px class (227dp at 320dpi). */ private const val ROUND = "spec:width=227dp,height=227dp,dpi=320"
maps-wear/src/test/java/com/vayunmathur/maps/wear/domain/WearMapsProtocolTest.kt
diff --git a/maps-wear/src/test/java/com/vayunmathur/maps/wear/domain/WearMapsProtocolTest.kt b/maps-wear/src/test/java/com/vayunmathur/maps/wear/domain/WearMapsProtocolTest.ktindex e422e71b1d..34b93d1970 100644--- a/maps-wear/src/test/java/com/vayunmathur/maps/wear/domain/WearMapsProtocolTest.kt+++ b/maps-wear/src/test/java/com/vayunmathur/maps/wear/domain/WearMapsProtocolTest.kt@@ -1,5 +1,14 @@ package com.vayunmathur.maps.wear.domain +import com.vayunmathur.library.wearlink.maps.WearLineKind+import com.vayunmathur.library.wearlink.maps.WearMapLine+import com.vayunmathur.library.wearlink.maps.WearMapPoint+import com.vayunmathur.library.wearlink.maps.WearMapSnapshot+import com.vayunmathur.library.wearlink.maps.WearMapsProtocol+import com.vayunmathur.library.wearlink.maps.WearRouteState+import com.vayunmathur.library.wearlink.maps.WearSavedPlace+import com.vayunmathur.library.wearlink.maps.wearDequantize+import com.vayunmathur.library.wearlink.maps.wearQuantize import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFalse
maps/src/main/java/com/vayunmathur/maps/domain/WearMapRegion.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/domain/WearMapRegion.kt b/maps/src/main/java/com/vayunmathur/maps/domain/WearMapRegion.ktindex 38ea6451f3..c51b1f8f3f 100644--- a/maps/src/main/java/com/vayunmathur/maps/domain/WearMapRegion.kt+++ b/maps/src/main/java/com/vayunmathur/maps/domain/WearMapRegion.kt@@ -3,6 +3,17 @@ package com.vayunmathur.maps.domain import com.vayunmathur.library.map.GeoPoint import com.vayunmathur.library.map.MapGeometryKind import com.vayunmathur.library.map.MapGeometryResult+import com.vayunmathur.library.wearlink.maps.WearLineKind+import com.vayunmathur.library.wearlink.maps.WearManeuver+import com.vayunmathur.library.wearlink.maps.WearMapLine+import com.vayunmathur.library.wearlink.maps.WearMapPoint+import com.vayunmathur.library.wearlink.maps.WearMapSnapshot+import com.vayunmathur.library.wearlink.maps.WearMapsProtocol+import com.vayunmathur.library.wearlink.maps.WearRouteState+import com.vayunmathur.library.wearlink.maps.WearSavedPlace+import com.vayunmathur.library.wearlink.maps.wearMetersEast+import com.vayunmathur.library.wearlink.maps.wearMetersNorth+import com.vayunmathur.library.wearlink.maps.wearQuantize import kotlinx.serialization.encodeToString import kotlin.math.abs import kotlin.math.hypot
maps/src/main/java/com/vayunmathur/maps/platform/WearMapsSync.kt
diff --git a/maps/src/main/java/com/vayunmathur/maps/platform/WearMapsSync.kt b/maps/src/main/java/com/vayunmathur/maps/platform/WearMapsSync.ktindex 6fb5f23cce..99440ac0b0 100644--- a/maps/src/main/java/com/vayunmathur/maps/platform/WearMapsSync.kt+++ b/maps/src/main/java/com/vayunmathur/maps/platform/WearMapsSync.kt@@ -13,16 +13,16 @@ import com.vayunmathur.maps.data.MapTileCache import com.vayunmathur.maps.data.PoiIndex import com.vayunmathur.maps.data.SavedPlaceStore import com.vayunmathur.maps.data.inViewport-import com.vayunmathur.maps.domain.WearLineKind-import com.vayunmathur.maps.domain.WearMapSnapshot-import com.vayunmathur.maps.domain.WearMapsProtocol-import com.vayunmathur.maps.domain.WearManeuver-import com.vayunmathur.maps.domain.WearPosition+import com.vayunmathur.library.wearlink.maps.WearLineKind+import com.vayunmathur.library.wearlink.maps.WearMapSnapshot+import com.vayunmathur.library.wearlink.maps.WearMapsProtocol+import com.vayunmathur.library.wearlink.maps.WearManeuver+import com.vayunmathur.library.wearlink.maps.WearPosition+import com.vayunmathur.library.wearlink.maps.WearRouteState+import com.vayunmathur.library.wearlink.maps.WearSavedPlace import com.vayunmathur.maps.domain.WearRawLine import com.vayunmathur.maps.domain.WearRawPoint import com.vayunmathur.maps.domain.WearRegionHysteresis-import com.vayunmathur.maps.domain.WearRouteState-import com.vayunmathur.maps.domain.WearSavedPlace import com.vayunmathur.maps.domain.buildWearMapSnapshot import com.vayunmathur.maps.domain.buildWearRouteState import com.vayunmathur.maps.domain.toWearRawLines
maps/src/test/java/com/vayunmathur/maps/domain/WearMapRegionTest.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/domain/WearMapRegionTest.kt b/maps/src/test/java/com/vayunmathur/maps/domain/WearMapRegionTest.ktindex a83b347e24..b839d81308 100644--- a/maps/src/test/java/com/vayunmathur/maps/domain/WearMapRegionTest.kt+++ b/maps/src/test/java/com/vayunmathur/maps/domain/WearMapRegionTest.kt@@ -4,6 +4,15 @@ import com.vayunmathur.library.map.GeoPoint import com.vayunmathur.library.map.MapGeometryFeature import com.vayunmathur.library.map.MapGeometryKind import com.vayunmathur.library.map.MapGeometryResult+import com.vayunmathur.library.wearlink.maps.WearLineKind+import com.vayunmathur.library.wearlink.maps.WearManeuver+import com.vayunmathur.library.wearlink.maps.WearMapLine+import com.vayunmathur.library.wearlink.maps.WearMapPoint+import com.vayunmathur.library.wearlink.maps.WearMapSnapshot+import com.vayunmathur.library.wearlink.maps.WearMapsProtocol+import com.vayunmathur.library.wearlink.maps.WearRouteState+import com.vayunmathur.library.wearlink.maps.wearDequantize+import com.vayunmathur.library.wearlink.maps.wearQuantize import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFalse
maps/src/test/java/com/vayunmathur/maps/domain/WearMapsProtocolTest.kt
diff --git a/maps/src/test/java/com/vayunmathur/maps/domain/WearMapsProtocolTest.kt b/maps/src/test/java/com/vayunmathur/maps/domain/WearMapsProtocolTest.ktnew file mode 100644index 0000000000..a911e7d0ee--- /dev/null+++ b/maps/src/test/java/com/vayunmathur/maps/domain/WearMapsProtocolTest.kt@@ -0,0 +1,62 @@+package com.vayunmathur.maps.domain++import com.vayunmathur.library.wearlink.maps.WearLineKind+import com.vayunmathur.library.wearlink.maps.WearMapLine+import com.vayunmathur.library.wearlink.maps.WearMapPoint+import com.vayunmathur.library.wearlink.maps.WearMapSnapshot+import com.vayunmathur.library.wearlink.maps.WearMapsProtocol+import com.vayunmathur.library.wearlink.maps.WearRouteState+import com.vayunmathur.library.wearlink.maps.WearSavedPlace+import com.vayunmathur.library.wearlink.maps.wearDequantize+import com.vayunmathur.library.wearlink.maps.wearQuantize+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertTrue+import kotlinx.serialization.encodeToString++class WearMapsProtocolTest {++ @Test+ fun goldenSnapshotJson() {+ // Must match the wear copy's golden string byte-for-byte.+ val snapshot = WearMapSnapshot(+ generatedAtMillis = 1_000L,+ centerLatE7 = 340_522_350,+ centerLonE7 = -1_182_436_830,+ lines = listOf(WearMapLine(WearLineKind.ROAD, listOf(0, 0, 10, 0))),+ points = listOf(WearMapPoint(0, "Cafe", 5, -3)),+ )+ assertEquals(+ """{"generatedAtMillis":1000,"centerLatE7":340522350,"centerLonE7":-1182436830,""" ++ """"lines":[{"kind":"ROAD","pts":[0,0,10,0]}],""" ++ """"points":[{"name":"Cafe","dx":5,"dy":-3}]}""",+ WearMapsProtocol.json.encodeToString(snapshot),+ )+ }++ @Test+ fun snapshotAndRouteRoundTrip() {+ val snapshot = WearMapSnapshot(9L, 10, 20, saved = listOf(WearSavedPlace("Home", 1, 2)))+ assertEquals(+ snapshot,+ WearMapsProtocol.json.decodeFromString<WearMapSnapshot>(+ WearMapsProtocol.json.encodeToString(snapshot),+ ),+ )+ val route = WearRouteState(active = true, destinationName = "Work", routePts = listOf(0, 0, 5, 5))+ assertEquals(+ route,+ WearMapsProtocol.json.decodeFromString<WearRouteState>(+ WearMapsProtocol.json.encodeToString(route),+ ),+ )+ }++ @Test+ fun quantizationRoundTripWithinHalfStep() {+ for (meters in listOf(0.0, 1.0, 3.0, 57.0, -123.0, 599.0)) {+ val back = wearDequantize(wearQuantize(meters))+ assertTrue(kotlin.math.abs(back - meters) <= WearMapsProtocol.QUANT_STEP_M / 2 + 1e-9)+ }+ }+}