camera: merge camera-wear into the single camera APK
- Commit
7e2c42988e02b586a6296ab0e01123752aeee7e6- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-04 18:11 UTC (1 day ago)
- Parents
5b49368
Owner directive: singular apps that detect when they are on a watch and adapt, instead of a separate *-wear APK per companion. This applies the merged clock pilot (adec0c398 + 31a81d3c5) to camera: camera-wear's watch experience moves into :camera and the camera-wear module is deleted, so one APK serves phones and watches. The merged :camera APK keeps applicationId com.vayunmathur.camera and the convention signing on both form factors, as the WearLink handshake requires; neither side's identity changed. Runtime detection is PackageManager.FEATURE_WATCH (platform/FormFactor): MainActivity, the sole launcher entry, forwards watches to ui/WearMainActivity before any phone state (CameraViewModel, phone WearCameraSync, permission gate) is touched, and phones keep the existing camera UI. The module declares no broadcast receivers, so that forward is the only form-factor gate: WearCameraSync starts only on MainActivity's phone path and sync/WearLinkBridge is created only by WearMainActivity. The capture pipeline is untouched; this change is the wear slice only. Manifest shape, following the clock pilot: no android.hardware.type.watch uses-feature is declared (required=true would block phone installs, required=false is disallowed for this feature), the standalone=false meta-data, WAKE_LOCK, and the watch activity are carried into the phone application element, and WearMainActivity is exported=false with no launcher filter of its own. One deliberate extra versus clock: android.hardware.camera is now required=false, because a watch has no camera of its own (the watch experience is a remote viewfinder entered before any camera use) and required=true would block watch installs; phones keep the permission-gated camera UI unchanged. All camera-wear sources move into camera's closed package roots (wear/data -> data, wear/sync -> sync, wear/ui -> ui), R references retarget to com.vayunmathur.camera.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 launcherIcon convention generates the phone's). The wear module's three WearCameraStore tests merge into :camera's existing WearCameraProtocolTest, which already pins the same golden JSON/frame bytes, and a new platform/FormFactorTest pins the routing signal. Watch screenshot previews become ui/WearMetadataPreviews with group="wear", rendering into metadata_data/photos/camera/wear/ (the old camera-wear bucket's three captures moved there). The camera-wear module, its settings include, and its AGENTS.md are deleted; root and camera AGENTS.md describe the merged state. Verified fresh on devvm21958 in this worktree: ./gradlew :camera:lint :camera:lintVitalRelease :camera:testDevUnitTest green (652 tests, 0 failures, including the moved watch store tests 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 6ed68055c0..3c8b9c51ce 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -49,7 +49,7 @@ Monorepo: ~100 Gradle modules + Rust workspace. Do scoped work only. ### Apps (Gradle key → dir) Reference: `backup/` satisfies every rule; `notes/` second + `intents/` demo. `camera` + `games/voxels` hand-commit screenshots. Full canonical index (Gradle key → dir + group + notes): `.llms/repo-map.md`.-`clock`, `notes`, `calendar`, `launcher`, `todo` and `maps` are single merged APKs for phone and watch (watch experience inside the phone app's module; the remaining `*-wear` modules are separate companion APKs with the phone app's applicationId/signing).+`clock`, `notes`, `calendar`, `launcher`, `todo`, `maps` and `camera` are single merged APKs for phone and watch (watch experience inside the phone app's module; the remaining `*-wear` modules are separate companion APKs with the phone app's applicationId/signing). `appstore→appstore/` `astronomy→astronomy/` `auto→auto/,auto/protocol/` `backup→backup/` `calculator→calculator/` `calendar→calendar/` `camera→camera/` `cast→cast/,cast/protocol/,cast/tv/` `clock→clock/` `code→code/` `communicate→communicate/` `contacts→contacts/` `education→education/` `email→email/` `emergency→emergency/` `euicc→euicc/` `everysync→everysync/` `files→files/` `findfamily→findfamily/` `findfamily-ios→apple/FindFamily/` (SwiftPM/xtool, not Gradle) `flashcards→flashcards/` `fooddelivery→fooddelivery/` `health→health/` `keyboard→keyboard/` `launcher→launcher/` `logviewer→logviewer/` `maps→maps/` `measure→measure/` `music→music/` `networklocation→networklocation/` `news→news/` `notes→notes/` `office→office/` `openassistant→openassistant/` `passwords→passwords/` `pdf→pdf/` `photos→photos/` `parentalcontrols→parentalcontrols/` `screentime→screentime/` `setupwizard→setupwizard/` `share→share/` `speech→speech/` `taxi→taxi/` `things→things/` `todo→todo/` `translate→translate/` `travel→travel/` `tuner→tuner/` `updater→updater/` `vpn→vpn/` `weather→weather/` `watch→watch/,watch-wear/` `web→web/` `youpipe→youpipe/,youpipe/extractor/` `games-hub→games/hub/` `games-arrows→games/arrows/` `games-chess→games/chess/` `games-logicgate→games/logicgate/` `games-minesweeper→games/minesweeper/` `games-nonogram→games/nonogram/` `games-pipes→games/pipes/` `games-solitaire→games/solitaire/` `games-sudoku→games/sudoku/` `games-unblockjam→games/unblockjam/` `games-voxels→games/voxels/` `games-wordmaker→games/wordmaker/` Slash == colon for Gradle (`games/voxels` == `games:voxels`).
camera-wear/AGENTS.md
diff --git a/camera-wear/AGENTS.md b/camera-wear/AGENTS.mddeleted file mode 100644index 9396e6456f..0000000000--- a/camera-wear/AGENTS.md+++ /dev/null@@ -1,51 +0,0 @@-# AGENTS.md — camera-wear/ (':camera-wear')--> Scoped supplement. Global rules in root `AGENTS.md` apply. Stay inside-> `camera-wear/` + `camera/` (the phone side of the same feature).--- Gradle: :camera-wear / dir: camera-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 Camera (`:camera`): a live viewfinder-streamed from the phone camera plus remote controls executed on the-phone. This module deliberately uses-`applicationId = "com.vayunmathur.camera"` (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 control. Bootstrap is a one-time-ADB sideload of this APK onto the watch. The watch has no camera here —-with no phone nearby the app says so; it never fakes a local camera.--## Protocol-The wire protocol (`WearCameraProtocol`, WCF1 preview frames) lives in-`:library:wearlink` at `com.vayunmathur.library.wearlink.camera` (shared-by `:camera` and `:camera-wear`; neither app module depends on the-other). Each side's `WearCameraProtocolTest` pins the same golden-JSON/frame bytes against that shared code.--- Mirrored state + last-capture thumbnail: WearLink data items- (`/camera/state`, `/camera/thumbnail` JPEG)-- Watch-originated controls: WearLink message (`/camera/op`)-- Live viewfinder: WearLink messages (`/camera/preview-frame`), NOT the- STREAM primitive — STREAM is a bounded file transfer (total size +- SHA-256 committed up front, verified at close, resumable by file- offset), which a live ephemeral frame sequence cannot satisfy. The- extension lives behind the camera protocol seam; :library:wearlink is- unchanged. Phone drops frames latest-only; watch drops stale sequences- and clears the live frame (and its rotation) when the link drops or the- mirrored state reports preview streaming stopped — a frozen frame is- never shown as live.-- Transport: :library:wearlink (RFCOMM, no Play services); app-lifecycle-bound--## Viewfinder design point-Phone analysis-stream frames downscaled to ≤320 px wide, JPEG-encoded-once at that size, adaptive ~2–8 fps (nominal 5) backing off when-encode+send exceeds the frame interval. Media stays on the phone.--## Verify (this module only)-```-./gradlew :camera-wear:assembleDev-./gradlew :camera-wear:testDebugUnitTest-```
camera-wear/build.gradle.kts
diff --git a/camera-wear/build.gradle.kts b/camera-wear/build.gradle.ktsdeleted file mode 100644index 7f875c7231..0000000000--- a/camera-wear/build.gradle.kts+++ /dev/null@@ -1,40 +0,0 @@-plugins {- id("common-conventions-wear")- id("common-conventions-preview-metadata")-}--launcherIcon {- symbol = "photo_camera"-}--// 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.camera.wear"- defaultConfig {- applicationId = "com.vayunmathur.camera"- // 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 Camera companion (see domain/WearCameraProtocol.kt, the- // copy of the phone protocol it must stay in step with).- implementation(libs.kotlinx.coroutines.android)- implementation(project(":library:wearlink"))- testImplementation(libs.kotlin.test)- testImplementation(libs.kotlin.test.junit)-}
camera-wear/src/main/AndroidManifest.xml
diff --git a/camera-wear/src/main/AndroidManifest.xml b/camera-wear/src/main/AndroidManifest.xmldeleted file mode 100644index 7ccb8c3001..0000000000--- a/camera-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>
camera-wear/src/main/res/values/colors.xml
diff --git a/camera-wear/src/main/res/values/colors.xml b/camera-wear/src/main/res/values/colors.xmldeleted file mode 100644index bfc7025d71..0000000000--- a/camera-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>
camera-wear/src/test/java/com/vayunmathur/camera/wear/domain/WearCameraProtocolTest.kt
diff --git a/camera-wear/src/test/java/com/vayunmathur/camera/wear/domain/WearCameraProtocolTest.kt b/camera-wear/src/test/java/com/vayunmathur/camera/wear/domain/WearCameraProtocolTest.ktdeleted file mode 100644index cd3276f1eb..0000000000--- a/camera-wear/src/test/java/com/vayunmathur/camera/wear/domain/WearCameraProtocolTest.kt+++ /dev/null@@ -1,230 +0,0 @@-package com.vayunmathur.camera.wear.domain---import com.vayunmathur.camera.wear.data.WearCameraStore-import com.vayunmathur.library.wearlink.camera.PreviewFrame-import com.vayunmathur.library.wearlink.camera.WearCameraOp-import com.vayunmathur.library.wearlink.camera.WearCameraState-import com.vayunmathur.library.wearlink.camera.WearOpDecision-import com.vayunmathur.library.wearlink.camera.WearOpKind-import com.vayunmathur.library.wearlink.camera.clampWearZoom-import com.vayunmathur.library.wearlink.camera.decodeWearCameraOp-import com.vayunmathur.library.wearlink.camera.decodeWearCameraState-import com.vayunmathur.library.wearlink.camera.encodeWearCameraOp-import com.vayunmathur.library.wearlink.camera.encodeWearCameraState-import com.vayunmathur.library.wearlink.camera.planWearCameraOp-import com.vayunmathur.library.wearlink.camera.wearZoomPreset-import kotlin.test.Test-import kotlin.test.assertEquals-import kotlin.test.assertFalse-import kotlin.test.assertNotNull-import kotlin.test.assertNull-import kotlin.test.assertTrue--class WearCameraProtocolTest {-- @Test- fun goldenStateJson() {- val state = WearCameraState(- mode = "VIDEO",- frontLens = true,- zoomRatio = 2f,- zoomPresets = listOf(1f, 2f),- zoomMin = 0.5f,- zoomMax = 10f,- flash = "AUTO",- torch = true,- timerSeconds = 3,- recording = true,- recordingSeconds = 65L,- previewStreaming = true,- lastCaptureAtMillis = 7L,- lastCaptureKind = "PHOTO",- )- assertEquals(- """{"mode":"VIDEO","frontLens":true,"zoomRatio":2.0,"zoomPresets":[1.0,2.0],"zoomMin":0.5,""" +- """"zoomMax":10.0,"flash":"AUTO","torch":true,"timerSeconds":3,"recording":true,""" +- """"recordingSeconds":65,"previewStreaming":true,"lastCaptureAtMillis":7,"lastCaptureKind":"PHOTO"}""",- encodeWearCameraState(state).decodeToString(),- )- }-- @Test- fun goldenOpJson() {- val op = WearCameraOp(WearOpKind.SET_ZOOM, zoomRatio = 2.5f)- assertEquals(- """{"kind":"SET_ZOOM","zoomRatio":2.5}""",- encodeWearCameraOp(op).decodeToString(),- )- }-- @Test- fun goldenPreviewFrameHeader() {- val frame = PreviewFrame.encode(- sequence = 0x01020304L,- timestampMillis = 0x05060708L,- width = 320,- height = 240,- rotationDegrees = 90,- jpeg = byteArrayOf(9, 8, 7),- )- assertEquals(- listOf(- 'W'.code, 'C'.code, 'F'.code, '1'.code,- 1, 2, 3, 4, 5, 6, 7, 8, 1, 64, 0, 240, 0, 90, 0, 0, 9, 8, 7,- ),- frame.map { it.toInt() and 0xFF },- )- val decoded = PreviewFrame.decode(frame)- assertNotNull(decoded)- assertEquals(0x01020304L, decoded.sequence)- assertEquals(320, decoded.width)- assertEquals(240, decoded.height)- assertEquals(90, decoded.rotationDegrees)- assertTrue(byteArrayOf(9, 8, 7).contentEquals(decoded.jpeg))- }-- @Test- fun stateAndOpRoundTripAndMalformedIgnored() {- val state = WearCameraState(mode = "PORTRAIT", zoomRatio = 1.5f)- assertEquals(state, decodeWearCameraState(encodeWearCameraState(state)))- val op = WearCameraOp(WearOpKind.SET_TIMER, timerSeconds = 5)- assertEquals(op, decodeWearCameraOp(encodeWearCameraOp(op)))- assertNull(decodeWearCameraState("not json".encodeToByteArray()))- assertNull(decodeWearCameraOp(byteArrayOf(0)))- assertNull(PreviewFrame.decode(byteArrayOf(1, 2, 3)))- assertNull(PreviewFrame.decode(PreviewFrame.encode(1L, 1L, 0, 240, 0, byteArrayOf(1))))- }-- @Test- fun planRejectsNonRemoteModesAndRecordingSwitches() {- val idle = WearCameraState(mode = "PHOTO")- assertEquals(- WearOpDecision.Apply,- planWearCameraOp(WearCameraOp(WearOpKind.SET_MODE, mode = "VIDEO"), idle),- )- assertTrue(- planWearCameraOp(WearCameraOp(WearOpKind.SET_MODE, mode = "PANORAMA"), idle)- is WearOpDecision.Reject,- )- val recording = idle.copy(recording = true)- assertTrue(- planWearCameraOp(WearCameraOp(WearOpKind.SET_MODE, mode = "VIDEO"), recording)- is WearOpDecision.Reject,- )- assertTrue(- planWearCameraOp(WearCameraOp(WearOpKind.FLIP_LENS), recording) is WearOpDecision.Reject,- )- // Shutter/record and torch stay live while recording.- assertEquals(WearOpDecision.Apply, planWearCameraOp(WearCameraOp(WearOpKind.RECORD_TOGGLE), recording))- assertEquals(- WearOpDecision.Apply,- planWearCameraOp(WearCameraOp(WearOpKind.SET_TORCH, torch = true), recording),- )- }-- @Test- fun planValidatesFlashTimerAndZoomLock() {- val state = WearCameraState(mode = "PHOTO")- assertEquals(- WearOpDecision.Apply,- planWearCameraOp(WearCameraOp(WearOpKind.SET_FLASH, flash = "AUTO"), state),- )- assertTrue(- planWearCameraOp(WearCameraOp(WearOpKind.SET_FLASH, flash = "STROBE"), state)- is WearOpDecision.Reject,- )- assertTrue(- planWearCameraOp(WearCameraOp(WearOpKind.SET_TIMER, timerSeconds = 7), state)- is WearOpDecision.Reject,- )- val pano = state.copy(mode = "PANORAMA")- assertTrue(- planWearCameraOp(WearCameraOp(WearOpKind.SET_ZOOM, zoomRatio = 2f), pano)- is WearOpDecision.Reject,- )- }-- @Test- fun zoomClampAndPresetLookup() {- val state = WearCameraState(zoomRatio = 1f, zoomPresets = listOf(0.5f, 1f, 2f), zoomMin = 0.5f, zoomMax = 10f)- assertEquals(10f, clampWearZoom(99f, state))- assertEquals(0.5f, clampWearZoom(0.1f, state))- assertEquals(1f, clampWearZoom(Float.NaN, state))- assertEquals(2f, wearZoomPreset(state, 2))- assertNull(wearZoomPreset(state, 5))- }-- @Test- fun storeMirrorsStateAndDropsStaleFrames() {- val store = WearCameraStore()- val first = WearCameraState(mode = "VIDEO", zoomRatio = 2f, recording = true, recordingSeconds = 12L)- store.applyState(first)- assertEquals(first, store.state.value)- // Mirroring replaces wholesale — nothing merges or lingers.- val second = WearCameraState(mode = "PHOTO")- store.applyState(second)- assertEquals(second, store.state.value)-- val frame1 = PreviewFrame.encode(1L, 1L, 320, 240, 0, byteArrayOf(1))- val frame2 = PreviewFrame.encode(2L, 2L, 320, 240, 90, byteArrayOf(2))- assertTrue(store.applyPreviewFrame(frame1))- assertTrue(store.applyPreviewFrame(frame2))- assertTrue(byteArrayOf(2).contentEquals(store.previewJpeg.value!!))- assertEquals(90, store.previewRotation.value)- // Stale and replayed sequences never replace the newest frame.- assertFalse(store.applyPreviewFrame(frame1))- assertFalse(store.applyPreviewFrame(frame2))- assertEquals(2L, store.droppedStaleFrames)- assertFalse(store.applyPreviewFrame(byteArrayOf(0, 1, 2)))-- store.applyThumbnail(byteArrayOf(5, 6))- assertTrue(byteArrayOf(5, 6).contentEquals(store.thumbnailJpeg.value!!))- store.applyThumbnail(ByteArray(0))- assertTrue(byteArrayOf(5, 6).contentEquals(store.thumbnailJpeg.value!!))- }-- @Test- fun streamingStopClearsLiveFrameButKeepsMirroredStateAndSequenceGuard() {- val store = WearCameraStore()- store.setLinkConnected(true)- store.applyState(WearCameraState(mode = "PHOTO", previewStreaming = true))- val frame7 = PreviewFrame.encode(7L, 7L, 320, 240, 90, byteArrayOf(7))- assertTrue(store.applyPreviewFrame(frame7))- assertTrue(byteArrayOf(7).contentEquals(store.previewJpeg.value!!))- assertEquals(90, store.previewRotation.value)-- // The phone reports it stopped streaming (e.g. the watch left the- // viewfinder and PREVIEW_STOP landed): the frozen frame is stale,- // not live, and must leave the viewfinder. Mirrored state stays.- store.applyState(WearCameraState(mode = "PHOTO", previewStreaming = false))- assertNull(store.previewJpeg.value)- assertEquals(0, store.previewRotation.value)- assertEquals("PHOTO", store.state.value.mode)-- // A late/replayed frame from the stopped stream must not resurrect- // the cleared frame; only a newer sequence may.- assertFalse(store.applyPreviewFrame(frame7))- assertNull(store.previewJpeg.value)- assertEquals(1L, store.droppedStaleFrames)-- // Streaming resumes: the next sequence is shown with its own rotation.- store.applyState(WearCameraState(mode = "PHOTO", previewStreaming = true))- val frame8 = PreviewFrame.encode(8L, 8L, 320, 240, 0, byteArrayOf(8))- assertTrue(store.applyPreviewFrame(frame8))- assertTrue(byteArrayOf(8).contentEquals(store.previewJpeg.value!!))- assertEquals(0, store.previewRotation.value)- }-- @Test- fun linkDownClearsLiveFrameButKeepsMirroredState() {- val store = WearCameraStore()- store.applyState(WearCameraState(mode = "VIDEO"))- store.applyPreviewFrame(PreviewFrame.encode(3L, 1L, 320, 240, 0, byteArrayOf(1)))- store.setLinkConnected(true)- assertEquals(true, store.linkConnected.value)- store.setLinkConnected(false)- assertNull(store.previewJpeg.value)- assertEquals("VIDEO", store.state.value.mode)- }-}
camera/AGENTS.md
diff --git a/camera/AGENTS.md b/camera/AGENTS.mdindex ac1fbcfffb..ff3196d296 100644--- a/camera/AGENTS.md+++ b/camera/AGENTS.md@@ -4,9 +4,9 @@ _Install: ./install camera (dev by default)._ - Gradle: :camera / dir: camera/-- Package roots present: ui, domain, platform-- Entry files: MainActivity.kt, Route.kt (`Route.Camera` / `Route.Settings`)-- Deps: :library:ml, :library:wearlink+- Package roots present: ui, domain, platform, data, sync+- Entry files: MainActivity.kt (sole launcher; routes watches to WearMainActivity), Route.kt (`Route.Camera` / `Route.Settings`), ui/WearMainActivity.kt+- Deps: :library:ml, :library:wearlink, :library:log, Wear Compose (material + foundation) - Metadata: metadata_data/camera.md (present) - Rust: yes / screenshotTest: yes (phone + large-tablet preview-rendered over a screenshot-only fake viewfinder scene) @@ -21,6 +21,31 @@ _Install: ./install camera (dev by default)._ **Architecture / data-flow:** Single-screen `ui/CameraScreen` + `platform/CameraViewModel` over per-mode `platform/` session objects on the `platform/camera2/` driver; `domain/` holds pure lens-selection logic, `platform/` capability queries; heavy work (stitch, night align, bokeh) goes through Rust JNI (`platform/StitchNative`) and lands in MediaStore via `data/MediaStoreSaver`. `onCreateBeforeContent` only honors the `ACTION_IMAGE_CAPTURE` capture-for-result intent; `Content()` sits behind a camera+mic permission gate. **Lens selection:** `platform/LensSelector.enumerateLenses` feeds `domain/LensDiscovery` with every top-level camera id plus each logical camera's `getPhysicalCameraIds()` sub-cameras (validated against their stream-configuration maps); the Camera2 preview always opens the facing's logical camera, so lens stops (sub-1x / tele included) are reached through the single continuous `ui/ZoomBar` row and pinch zoom, which apply the ratio to that session rather than opening a sub-camera id; live scrub/pinch moves go through `setZoomRatioLive` (no persistence, no lens sync), and only the committed final ratio (chip tap, scrub/pinch release, lens/Wear selection, via `setZoomRatio`) landing on a lens's nominal ratio syncs `selectedLens` to that lens (startup persistence + night-detection reset, via `syncSelectedLensToZoomStop`), while a ratio between stops leaves the selection alone. **Entry points + reading order:** `MainActivity.kt` → `Route.kt` (`Route.Camera`/`Settings`) → `ui/CameraScreen.kt` → `platform/CameraViewModel.kt` → `platform/CameraSessions.kt` → `platform/PanoramaEngine.kt` / `NightCaptureEngine.kt`.++## One APK, two form factors (phone + watch)+This module is the single Camera APK for phones and watches: same+`applicationId = "com.vayunmathur.camera"` 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), declares the+camera feature not-required (a watch has no camera; the watch+experience is a remote viewfinder streamed from the phone), and+carries `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 (CameraViewModel, phone wear sync, permission gate) is+touched; phones get the camera UI. The module declares no broadcast+receivers, so `MainActivity`'s forward is the only form-factor gate:+the phone-side `platform/WearCameraSync` starts only on the phone+path, and the watch-side `sync/WearLinkBridge` is created only by+`ui/WearMainActivity` (`exported=false`, no launcher filter).++## Watch experience (in this module)+- `ui/WearMainActivity` (a `WearShellActivity`) routes `ui/WearRoute` over viewfinder / controls / last capture; the watch has no camera of its own — with no phone nearby it says so, honestly. Mirrored truth is in-memory only in `data/WearCameraStore` (no offline copy: nothing is usable without the phone).+- Wire protocol (`WearCameraProtocol`, WCF1 preview frames) lives in `:library:wearlink` at `com.vayunmathur.library.wearlink.camera`; this module's `WearCameraProtocolTest` pins the golden JSON/frame bytes (including the watch store's stale-frame rules). Live viewfinder frames travel as `/camera/preview-frame` messages (never the bounded STREAM primitive); phone drops frames latest-only, watch drops stale sequences and clears the live frame when the link drops or streaming stops — a frozen frame is never shown as live.+- Watch listing screenshots are the `group = "wear"` previews in `src/screenshotTest/.../ui/WearMetadataPreviews.kt`, collected by `:camera:metadata` into `metadata_data/photos/camera/wear/`; phone/tablet shots keep their buckets. **Gotchas:** - Capture code lives in `platform/` (the Camera2 driver in `platform/camera2/`); there is no `util/` root in this module - Camera2 session reopen after a surface destroy (background/resume, size change) is serialized in `platform/camera2/`: a session parks a reopen until the previous device's real `onClosed` (device `close()` only initiates HAL teardown), and `PreviewSurfaceBridge` forgets its pinned stream size on destroy so a new `SurfaceTexture` is re-pinned before configure@@ -47,7 +72,7 @@ _Install: ./install camera (dev by default)._ - com/vayunmathur/camera/domain/MotionPhotoWriter.kt ### platform/ — capability queries - com/vayunmathur/camera/platform/CameraCapabilities.kt-- com/vayunmathur/camera/platform/WearCameraSync.kt — phone side of the wear companion; wire protocol `com.vayunmathur.library.wearlink.camera.WearCameraProtocol` (WCF1 frames) in `:library:wearlink` (shared with `:camera-wear`; each side's `WearCameraProtocolTest` pins the same golden JSON/frame bytes)+- com/vayunmathur/camera/platform/WearCameraSync.kt — phone side of the wear companion; wire protocol `com.vayunmathur.library.wearlink.camera.WearCameraProtocol` (WCF1 frames) in `:library:wearlink`; this module's `WearCameraProtocolTest` pins the golden JSON/frame bytes - com/vayunmathur/camera/platform/LensSelector.kt ### ui/ — single screen + settings + panes - com/vayunmathur/camera/ui/CameraScreen.kt@@ -107,6 +132,12 @@ _Install: ./install camera (dev by default)._ - com/vayunmathur/camera/platform/camera2/Camera2HighSpeedSession.kt - com/vayunmathur/camera/platform/camera2/StillCapture.kt - com/vayunmathur/camera/platform/camera2/StreamSelection.kt+### Watch experience (ui/ + data/ + sync/)+- com/vayunmathur/camera/ui/WearMainActivity.kt — watch entry (WearShellActivity)+- com/vayunmathur/camera/ui/WearRoute.kt, WearViewfinderScreen.kt, WearControlsScreen.kt, WearLastCaptureScreen.kt+- com/vayunmathur/camera/platform/FormFactor.kt — watch detection (`FEATURE_WATCH`)+- com/vayunmathur/camera/data/WearCameraStore.kt — mirrored phone state + newest preview frame/thumbnail (in-memory only)+- com/vayunmathur/camera/sync/WearLinkBridge.kt — watch conduit client node; mirrored state/thumbnail receive, preview frames, op sends ### data/ — settings + saving - com/vayunmathur/camera/data/MediaStoreSaver.kt - com/vayunmathur/camera/data/CameraSettings.kt
camera/build.gradle.kts
diff --git a/camera/build.gradle.kts b/camera/build.gradle.ktsindex 113a5e4acb..c58bbd53d7 100644--- a/camera/build.gradle.kts+++ b/camera/build.gradle.kts@@ -149,9 +149,19 @@ dependencies { // ncnn is gone from the whole tree, not just this app: `:translate` was the last consumer and // it now runs SMaLL-100 on `:library:ml` too, so `libncnn_android.so` is in no APK here. implementation(project(":library:ml"))- // Wear OS companion (live viewfinder + remote controls, :camera-wear):- // WearLink transport, RFCOMM with no Play services.+ // Wear OS experience (live viewfinder + remote controls) lives in this+ // one APK: phone side platform/WearCameraSync, watch side+ // sync/WearLinkBridge + ui/Wear*, same applicationId and signing as the+ // WearLink handshake requires; FEATURE_WATCH (platform/FormFactor)+ // picks the side at runtime. WearLink transport, RFCOMM with no Play+ // services. implementation(project(":library:wearlink"))+ // Watch experience (ui/Wear*): Wear Compose + the repo log facade the+ // watch 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) // Mockito is already a cataloged test dep used the same way by // sibling modules (e.g. :office): ContentResolver is final-method // heavy, so null-stream failure paths are tested with a mock.
camera/src/main/AndroidManifest.xml
diff --git a/camera/src/main/AndroidManifest.xml b/camera/src/main/AndroidManifest.xmlindex 907835d070..99db9dd674 100644--- a/camera/src/main/AndroidManifest.xml+++ b/camera/src/main/AndroidManifest.xml@@ -10,8 +10,25 @@ <uses-permission android:name="android.permission.INTERNET" tools:node="remove" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" tools:node="remove" /> - <uses-feature android:name="android.hardware.camera" android:required="true" />+ <!-- 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.+ The camera feature is likewise not required: a watch has no+ camera of its own (the watch experience is a remote viewfinder+ streamed from the phone, entered before any camera use), and+ phones keep the existing permission-gated camera UI. -->+ <uses-feature android:name="android.hardware.camera" android:required="false" /> <uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />+ <!-- Watch-local viewfinder/controls wake the watch CPU while linked. -->+ <uses-permission android:name="android.permission.WAKE_LOCK" /> <!-- Package visibility (API 30+): lets the eSIM universal link resolve to the LPA declaring esimsetup.android.com instead of failing visibility and@@ -31,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" /> <!-- Portrait-locked on purpose: the viewfinder layout never rotates, so capture controls stay in the same place in portrait and landscape; only the control icons rotate in place, and capture orientation is@@ -70,6 +92,18 @@ <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity>+ <!-- Watch experience: entered only via MainActivity's watch routing+ (no launcher filter of its own). Inert on a phone: it is+ reached only from MainActivity's FEATURE_WATCH forward, its+ WearLinkBridge is created only by this activity, and the+ phone-side WearCameraSync starts only on the phone path of+ MainActivity. This module declares no broadcast receivers, so+ there is no wrong-form-factor receiver surface to gate. -->+ <activity+ android:name=".ui.WearMainActivity"+ android:exported="false"+ android:taskAffinity=""+ android:theme="@android:style/Theme.Material.NoActionBar" /> </application> </manifest>
camera/src/main/java/com/vayunmathur/camera/MainActivity.kt
diff --git a/camera/src/main/java/com/vayunmathur/camera/MainActivity.kt b/camera/src/main/java/com/vayunmathur/camera/MainActivity.ktindex 3446d3bac1..c8144cecb8 100644--- a/camera/src/main/java/com/vayunmathur/camera/MainActivity.kt+++ b/camera/src/main/java/com/vayunmathur/camera/MainActivity.kt@@ -2,6 +2,7 @@ package com.vayunmathur.camera import android.Manifest import android.content.Intent+import android.os.Bundle import android.graphics.Bitmap import android.net.Uri import android.provider.MediaStore@@ -13,7 +14,9 @@ import androidx.compose.runtime.Composable import androidx.core.content.IntentCompat import com.vayunmathur.camera.ui.CameraScreen import com.vayunmathur.camera.ui.SettingsPage+import com.vayunmathur.camera.ui.WearMainActivity import com.vayunmathur.camera.platform.CameraViewModel+import com.vayunmathur.camera.platform.FormFactor import com.vayunmathur.camera.platform.triggerShutter import com.vayunmathur.library.ui.AppPermissionsGate import com.vayunmathur.library.ui.AppPermissionsSpec@@ -28,11 +31,31 @@ import com.vayunmathur.library.util.NavKey import com.vayunmathur.library.util.rememberNavBackStack import kotlinx.serialization.Serializable -/** Entry activity hosting the camera and settings screens. */+/**+ * Sole launcher entry of the single merged Camera APK, hosting the camera+ * and settings screens on a phone. On a watch (the+ * `android.hardware.type.watch` system feature, see [FormFactor]) it hands+ * off to [WearMainActivity] and finishes before any phone state (the+ * [CameraViewModel], the phone side of the wear sync, the permission gate)+ * is touched; the watch experience is a remote viewfinder and never opens+ * a local camera.+ */ class MainActivity : MaActivity() { private val viewModel: CameraViewModel by viewModels() private var captureForResult: Boolean = false + /** 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()+ }+ }+ override fun applyEdgeToEdge() { // Force a black three-button navigation bar even in light mode (the // camera UI is always dark), instead of the default light/transparent@@ -43,6 +66,7 @@ class MainActivity : MaActivity() { } override fun onCreateBeforeContent() {+ if (routedToWear) return // Honor the system "take a photo" intent (MediaStore.ACTION_IMAGE_CAPTURE) so other apps // can request a photo via startActivityForResult. Default to CANCELED so back/cancel // returns the right result to the caller.@@ -65,6 +89,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 AppPermissionsGate( spec = AppPermissionsSpec( title = getString(R.string.grant_camera_permission),
camera/src/main/java/com/vayunmathur/camera/data/WearCameraStore.kt
diff --git a/camera-wear/src/main/java/com/vayunmathur/camera/wear/data/WearCameraStore.kt b/camera/src/main/java/com/vayunmathur/camera/data/WearCameraStore.ktsimilarity index 98%rename from camera-wear/src/main/java/com/vayunmathur/camera/wear/data/WearCameraStore.ktrename to camera/src/main/java/com/vayunmathur/camera/data/WearCameraStore.ktindex d9b52d5f58..39833a1f57 100644--- a/camera-wear/src/main/java/com/vayunmathur/camera/wear/data/WearCameraStore.kt+++ b/camera/src/main/java/com/vayunmathur/camera/data/WearCameraStore.kt@@ -1,4 +1,4 @@-package com.vayunmathur.camera.wear.data+package com.vayunmathur.camera.data import com.vayunmathur.library.wearlink.camera.PreviewFrame import com.vayunmathur.library.wearlink.camera.WearCameraState
camera/src/main/java/com/vayunmathur/camera/platform/FormFactor.kt
diff --git a/camera/src/main/java/com/vayunmathur/camera/platform/FormFactor.kt b/camera/src/main/java/com/vayunmathur/camera/platform/FormFactor.ktnew file mode 100644index 0000000000..795c3333e3--- /dev/null+++ b/camera/src/main/java/com/vayunmathur/camera/platform/FormFactor.kt@@ -0,0 +1,25 @@+package com.vayunmathur.camera.platform++import android.content.Context+import android.content.pm.PackageManager++/**+ * Runtime form-factor detection for the single merged Camera 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+}
camera/src/main/java/com/vayunmathur/camera/sync/WearLinkBridge.kt
diff --git a/camera-wear/src/main/java/com/vayunmathur/camera/wear/sync/WearLinkBridge.kt b/camera/src/main/java/com/vayunmathur/camera/sync/WearLinkBridge.ktsimilarity index 97%rename from camera-wear/src/main/java/com/vayunmathur/camera/wear/sync/WearLinkBridge.ktrename to camera/src/main/java/com/vayunmathur/camera/sync/WearLinkBridge.ktindex bcaeac7713..dbbb6de2d2 100644--- a/camera-wear/src/main/java/com/vayunmathur/camera/wear/sync/WearLinkBridge.kt+++ b/camera/src/main/java/com/vayunmathur/camera/sync/WearLinkBridge.kt@@ -1,7 +1,7 @@-package com.vayunmathur.camera.wear.sync+package com.vayunmathur.camera.sync import android.content.Context-import com.vayunmathur.camera.wear.data.WearCameraStore+import com.vayunmathur.camera.data.WearCameraStore import com.vayunmathur.library.log.Log import com.vayunmathur.library.wearlink.WearLinkListener import com.vayunmathur.library.wearlink.WearLinkNode
camera/src/main/java/com/vayunmathur/camera/ui/WearControlsScreen.kt
diff --git a/camera-wear/src/main/java/com/vayunmathur/camera/wear/ui/WearControlsScreen.kt b/camera/src/main/java/com/vayunmathur/camera/ui/WearControlsScreen.ktsimilarity index 97%rename from camera-wear/src/main/java/com/vayunmathur/camera/wear/ui/WearControlsScreen.ktrename to camera/src/main/java/com/vayunmathur/camera/ui/WearControlsScreen.ktindex 07ad6ee42d..22a970de7b 100644--- a/camera-wear/src/main/java/com/vayunmathur/camera/wear/ui/WearControlsScreen.kt+++ b/camera/src/main/java/com/vayunmathur/camera/ui/WearControlsScreen.kt@@ -1,4 +1,4 @@-package com.vayunmathur.camera.wear.ui+package com.vayunmathur.camera.ui import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding@@ -17,9 +17,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.camera.wear.R-import com.vayunmathur.camera.wear.data.WearCameraStore-import com.vayunmathur.camera.wear.sync.WearLinkBridge+import com.vayunmathur.camera.R+import com.vayunmathur.camera.data.WearCameraStore+import com.vayunmathur.camera.sync.WearLinkBridge import com.vayunmathur.library.wearlink.camera.WearCameraOp import com.vayunmathur.library.wearlink.camera.WearCameraProtocol import com.vayunmathur.library.wearlink.camera.WearOpKind
camera/src/main/java/com/vayunmathur/camera/ui/WearLastCaptureScreen.kt
diff --git a/camera-wear/src/main/java/com/vayunmathur/camera/wear/ui/WearLastCaptureScreen.kt b/camera/src/main/java/com/vayunmathur/camera/ui/WearLastCaptureScreen.ktsimilarity index 96%rename from camera-wear/src/main/java/com/vayunmathur/camera/wear/ui/WearLastCaptureScreen.ktrename to camera/src/main/java/com/vayunmathur/camera/ui/WearLastCaptureScreen.ktindex 936c7bf12b..8a6e1dc694 100644--- a/camera-wear/src/main/java/com/vayunmathur/camera/wear/ui/WearLastCaptureScreen.kt+++ b/camera/src/main/java/com/vayunmathur/camera/ui/WearLastCaptureScreen.kt@@ -1,4 +1,4 @@-package com.vayunmathur.camera.wear.ui+package com.vayunmathur.camera.ui import android.graphics.BitmapFactory import androidx.compose.foundation.Image@@ -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.camera.wear.R-import com.vayunmathur.camera.wear.data.WearCameraStore+import com.vayunmathur.camera.R+import com.vayunmathur.camera.data.WearCameraStore /** Last-capture thumbnail pushed from the phone; the media itself stays on the phone. */ @Composable
camera/src/main/java/com/vayunmathur/camera/ui/WearMainActivity.kt
diff --git a/camera-wear/src/main/java/com/vayunmathur/camera/wear/ui/WearMainActivity.kt b/camera/src/main/java/com/vayunmathur/camera/ui/WearMainActivity.ktsimilarity index 88%rename from camera-wear/src/main/java/com/vayunmathur/camera/wear/ui/WearMainActivity.ktrename to camera/src/main/java/com/vayunmathur/camera/ui/WearMainActivity.ktindex ee65498d84..0e6f3af0a4 100644--- a/camera-wear/src/main/java/com/vayunmathur/camera/wear/ui/WearMainActivity.kt+++ b/camera/src/main/java/com/vayunmathur/camera/ui/WearMainActivity.kt@@ -1,8 +1,8 @@-package com.vayunmathur.camera.wear.ui+package com.vayunmathur.camera.ui import androidx.compose.runtime.Composable-import com.vayunmathur.camera.wear.data.WearCameraStore-import com.vayunmathur.camera.wear.sync.WearLinkBridge+import com.vayunmathur.camera.data.WearCameraStore+import com.vayunmathur.camera.sync.WearLinkBridge import com.vayunmathur.library.wearlink.WearShellActivity /**
camera/src/main/java/com/vayunmathur/camera/ui/WearRoute.kt
diff --git a/camera-wear/src/main/java/com/vayunmathur/camera/wear/ui/WearRoute.kt b/camera/src/main/java/com/vayunmathur/camera/ui/WearRoute.ktsimilarity index 92%rename from camera-wear/src/main/java/com/vayunmathur/camera/wear/ui/WearRoute.ktrename to camera/src/main/java/com/vayunmathur/camera/ui/WearRoute.ktindex 334707965f..e557f6aed5 100644--- a/camera-wear/src/main/java/com/vayunmathur/camera/wear/ui/WearRoute.kt+++ b/camera/src/main/java/com/vayunmathur/camera/ui/WearRoute.kt@@ -1,4 +1,4 @@-package com.vayunmathur.camera.wear.ui+package com.vayunmathur.camera.ui /** Watch navigation destinations. Screen changes only ever happen through these routes. */ sealed interface WearRoute {
camera/src/main/java/com/vayunmathur/camera/ui/WearViewfinderScreen.kt
diff --git a/camera-wear/src/main/java/com/vayunmathur/camera/wear/ui/WearViewfinderScreen.kt b/camera/src/main/java/com/vayunmathur/camera/ui/WearViewfinderScreen.ktsimilarity index 97%rename from camera-wear/src/main/java/com/vayunmathur/camera/wear/ui/WearViewfinderScreen.ktrename to camera/src/main/java/com/vayunmathur/camera/ui/WearViewfinderScreen.ktindex baea65734c..b632f92df7 100644--- a/camera-wear/src/main/java/com/vayunmathur/camera/wear/ui/WearViewfinderScreen.kt+++ b/camera/src/main/java/com/vayunmathur/camera/ui/WearViewfinderScreen.kt@@ -1,4 +1,4 @@-package com.vayunmathur.camera.wear.ui+package com.vayunmathur.camera.ui import android.graphics.BitmapFactory import androidx.compose.foundation.Image@@ -28,9 +28,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.camera.wear.R-import com.vayunmathur.camera.wear.data.WearCameraStore-import com.vayunmathur.camera.wear.sync.WearLinkBridge+import com.vayunmathur.camera.R+import com.vayunmathur.camera.data.WearCameraStore+import com.vayunmathur.camera.sync.WearLinkBridge import com.vayunmathur.library.wearlink.camera.WearCameraOp import com.vayunmathur.library.wearlink.camera.WearCameraProtocol import com.vayunmathur.library.wearlink.camera.WearOpKind
camera/src/main/res/values/wear_strings.xml
diff --git a/camera-wear/src/main/res/values/strings.xml b/camera/src/main/res/values/wear_strings.xmlsimilarity index 96%rename from camera-wear/src/main/res/values/strings.xmlrename to camera/src/main/res/values/wear_strings.xmlindex 1804389c8c..ea391a5550 100644--- a/camera-wear/src/main/res/values/strings.xml+++ b/camera/src/main/res/values/wear_strings.xml@@ -1,6 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> <resources>- <string name="app_name">Camera</string> <string name="wear_no_phone">No phone nearby</string> <string name="wear_no_phone_hint">Open Camera on your phone and keep it nearby — the viewfinder streams from the phone camera.</string> <string name="wear_connecting">Looking for your phone…</string>
camera/src/screenshotTest/kotlin/com/vayunmathur/camera/ui/WearMetadataPreviews.kt
diff --git a/camera-wear/src/screenshotTest/kotlin/com/vayunmathur/camera/wear/ui/MetadataPreviews.kt b/camera/src/screenshotTest/kotlin/com/vayunmathur/camera/ui/WearMetadataPreviews.ktsimilarity index 90%rename from camera-wear/src/screenshotTest/kotlin/com/vayunmathur/camera/wear/ui/MetadataPreviews.ktrename to camera/src/screenshotTest/kotlin/com/vayunmathur/camera/ui/WearMetadataPreviews.ktindex 0c74d4bd76..978574d296 100644--- a/camera-wear/src/screenshotTest/kotlin/com/vayunmathur/camera/wear/ui/MetadataPreviews.kt+++ b/camera/src/screenshotTest/kotlin/com/vayunmathur/camera/ui/WearMetadataPreviews.kt@@ -1,4 +1,4 @@-package com.vayunmathur.camera.wear.ui+package com.vayunmathur.camera.ui import androidx.compose.foundation.background import androidx.compose.foundation.layout.Box@@ -29,16 +29,16 @@ private val fixtureState = WearCameraState( ) /**- * Store listing images for `:camera-wear` — every top-level screen/route+ * Store listing images for `:camera` (watch experience) — every top-level screen/route * (viewfinder, controls, last capture). * * Exception (honest, not faked): the viewfinder's live frame is a JPEG streamed * from the phone camera and the last-capture thumbnail is phone media; Layoutlib * has no phone camera, so both captures render their real waiting/no-capture * states with all controls visible — no synthetic camera image is invented.- * `./gradlew :camera-wear:metadata` copies renders into `metadata_data/photos/camera-wear/wear/`.+ * `./gradlew :camera:metadata` copies renders into `metadata_data/photos/camera/wear/`. */-class MetadataPreviews {+class WearMetadataPreviews { @PreviewTest @Preview(name = "1-viewfinder-round", device = ROUND, group = "wear")
camera/src/test/java/com/vayunmathur/camera/domain/WearCameraProtocolTest.kt
diff --git a/camera/src/test/java/com/vayunmathur/camera/domain/WearCameraProtocolTest.kt b/camera/src/test/java/com/vayunmathur/camera/domain/WearCameraProtocolTest.ktindex 0c514cf09d..7975a59c35 100644--- a/camera/src/test/java/com/vayunmathur/camera/domain/WearCameraProtocolTest.kt+++ b/camera/src/test/java/com/vayunmathur/camera/domain/WearCameraProtocolTest.kt@@ -1,6 +1,7 @@ package com.vayunmathur.camera.domain +import com.vayunmathur.camera.data.WearCameraStore import com.vayunmathur.library.wearlink.camera.PreviewFrame import com.vayunmathur.library.wearlink.camera.WearCameraOp import com.vayunmathur.library.wearlink.camera.WearCameraState@@ -15,6 +16,7 @@ import com.vayunmathur.library.wearlink.camera.planWearCameraOp import com.vayunmathur.library.wearlink.camera.wearZoomPreset import kotlin.test.Test import kotlin.test.assertEquals+import kotlin.test.assertFalse import kotlin.test.assertNotNull import kotlin.test.assertNull import kotlin.test.assertTrue@@ -152,4 +154,77 @@ class WearCameraProtocolTest { assertEquals(2f, wearZoomPreset(state, 2)) assertNull(wearZoomPreset(state, 5)) }++ @Test+ fun storeMirrorsStateAndDropsStaleFrames() {+ val store = WearCameraStore()+ val first = WearCameraState(mode = "VIDEO", zoomRatio = 2f, recording = true, recordingSeconds = 12L)+ store.applyState(first)+ assertEquals(first, store.state.value)+ // Mirroring replaces wholesale — nothing merges or lingers.+ val second = WearCameraState(mode = "PHOTO")+ store.applyState(second)+ assertEquals(second, store.state.value)++ val frame1 = PreviewFrame.encode(1L, 1L, 320, 240, 0, byteArrayOf(1))+ val frame2 = PreviewFrame.encode(2L, 2L, 320, 240, 90, byteArrayOf(2))+ assertTrue(store.applyPreviewFrame(frame1))+ assertTrue(store.applyPreviewFrame(frame2))+ assertTrue(byteArrayOf(2).contentEquals(store.previewJpeg.value!!))+ assertEquals(90, store.previewRotation.value)+ // Stale and replayed sequences never replace the newest frame.+ assertFalse(store.applyPreviewFrame(frame1))+ assertFalse(store.applyPreviewFrame(frame2))+ assertEquals(2L, store.droppedStaleFrames)+ assertFalse(store.applyPreviewFrame(byteArrayOf(0, 1, 2)))++ store.applyThumbnail(byteArrayOf(5, 6))+ assertTrue(byteArrayOf(5, 6).contentEquals(store.thumbnailJpeg.value!!))+ store.applyThumbnail(ByteArray(0))+ assertTrue(byteArrayOf(5, 6).contentEquals(store.thumbnailJpeg.value!!))+ }++ @Test+ fun streamingStopClearsLiveFrameButKeepsMirroredStateAndSequenceGuard() {+ val store = WearCameraStore()+ store.setLinkConnected(true)+ store.applyState(WearCameraState(mode = "PHOTO", previewStreaming = true))+ val frame7 = PreviewFrame.encode(7L, 7L, 320, 240, 90, byteArrayOf(7))+ assertTrue(store.applyPreviewFrame(frame7))+ assertTrue(byteArrayOf(7).contentEquals(store.previewJpeg.value!!))+ assertEquals(90, store.previewRotation.value)++ // The phone reports it stopped streaming (e.g. the watch left the+ // viewfinder and PREVIEW_STOP landed): the frozen frame is stale,+ // not live, and must leave the viewfinder. Mirrored state stays.+ store.applyState(WearCameraState(mode = "PHOTO", previewStreaming = false))+ assertNull(store.previewJpeg.value)+ assertEquals(0, store.previewRotation.value)+ assertEquals("PHOTO", store.state.value.mode)++ // A late/replayed frame from the stopped stream must not resurrect+ // the cleared frame; only a newer sequence may.+ assertFalse(store.applyPreviewFrame(frame7))+ assertNull(store.previewJpeg.value)+ assertEquals(1L, store.droppedStaleFrames)++ // Streaming resumes: the next sequence is shown with its own rotation.+ store.applyState(WearCameraState(mode = "PHOTO", previewStreaming = true))+ val frame8 = PreviewFrame.encode(8L, 8L, 320, 240, 0, byteArrayOf(8))+ assertTrue(store.applyPreviewFrame(frame8))+ assertTrue(byteArrayOf(8).contentEquals(store.previewJpeg.value!!))+ assertEquals(0, store.previewRotation.value)+ }++ @Test+ fun linkDownClearsLiveFrameButKeepsMirroredState() {+ val store = WearCameraStore()+ store.applyState(WearCameraState(mode = "VIDEO"))+ store.applyPreviewFrame(PreviewFrame.encode(3L, 1L, 320, 240, 0, byteArrayOf(1)))+ store.setLinkConnected(true)+ assertEquals(true, store.linkConnected.value)+ store.setLinkConnected(false)+ assertNull(store.previewJpeg.value)+ assertEquals("VIDEO", store.state.value.mode)+ } }
camera/src/test/java/com/vayunmathur/camera/platform/FormFactorTest.kt
diff --git a/camera/src/test/java/com/vayunmathur/camera/platform/FormFactorTest.kt b/camera/src/test/java/com/vayunmathur/camera/platform/FormFactorTest.ktnew file mode 100644index 0000000000..ea339fa1b7--- /dev/null+++ b/camera/src/test/java/com/vayunmathur/camera/platform/FormFactorTest.kt@@ -0,0 +1,19 @@+package com.vayunmathur.camera.platform++import kotlin.test.Test+import kotlin.test.assertFalse+import kotlin.test.assertTrue++/** The watch system feature is the single-APK routing signal. */+class FormFactorTest {++ @Test+ fun watchFeatureMeansWatch() {+ assertTrue(FormFactor.isWatch(hasWatchSystemFeature = true))+ }++ @Test+ fun noWatchFeatureMeansPhone() {+ assertFalse(FormFactor.isWatch(hasWatchSystemFeature = false))+ }+}
metadata_data/photos/camera/wear/1.png
diff --git a/metadata_data/photos/camera-wear/wear/1.png b/metadata_data/photos/camera/wear/1.pngsimilarity index 100%rename from metadata_data/photos/camera-wear/wear/1.pngrename to metadata_data/photos/camera/wear/1.png
metadata_data/photos/camera/wear/2.png
diff --git a/metadata_data/photos/camera-wear/wear/2.png b/metadata_data/photos/camera/wear/2.pngsimilarity index 100%rename from metadata_data/photos/camera-wear/wear/2.pngrename to metadata_data/photos/camera/wear/2.png
metadata_data/photos/camera/wear/3.png
diff --git a/metadata_data/photos/camera-wear/wear/3.png b/metadata_data/photos/camera/wear/3.pngsimilarity index 100%rename from metadata_data/photos/camera-wear/wear/3.pngrename to metadata_data/photos/camera/wear/3.png
settings.gradle.kts
diff --git a/settings.gradle.kts b/settings.gradle.ktsindex d0a0e13321..fc9c459bc9 100644--- a/settings.gradle.kts+++ b/settings.gradle.kts@@ -129,7 +129,6 @@ include(":weather") include(":weather:wear") project(":weather:wear").projectDir = file("weather-wear") include(":camera")-include(":camera-wear") include(":sdk:openassistant") include(":sdk:games") include(":sdk:cast")