Modern Apps git

← Modern-Apps.git

camera: Settings route gets a real screenshot capture

Commit
3d8850f0436c84f4603e2f78b69dfdfc7b60859d
Author
Vayun Mathur <[email protected]>
When
2026-11-30 21:35 UTC (5 days ago)
Parents
744ed5b
RouteScreenshotCoverage (fatal) flagged Route.Settings: no
capture existed. The settings form is extracted from SettingsPage
into a stateless CameraSettingsContent (all values + callbacks),
which SettingsPage feeds from the ViewModel while keeping the
side-effectful plumbing (permission request, folder picker, audio
device callback, foregroundRoute). screenshotTest renders that
content with literal fixtures as '3-settings' — the real slice,
not a fake and not an exemption marker.

Verified: :camera:lint BUILD SUCCESSFUL, :camera:testDevUnitTest
passes, and the release build was installed to the owner's phone
(./install camera, 20.4 MB, session install succeeded).

Diff

camera/AGENTS.md
diff --git a/camera/AGENTS.md b/camera/AGENTS.mdindex 490201b7df..55dce0954d 100644--- a/camera/AGENTS.md+++ b/camera/AGENTS.md@@ -24,7 +24,7 @@ _Install: ./install camera (dev by default)._ **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-- Listing screenshots are preview-rendered (`:camera:metadata`): Layoutlib can't open a camera, so `src/screenshotTest` draws the deterministic `FakeCameraPreview` scene behind the real top bar/grid/shutter/mode controls. The `screenshotFakePreview` parameter on `CameraScreen`/`CameraPreviewSurface` is the same seam in `main` — production-default null, never passed by `MainActivity`, so no fake frame can appear on device+- Listing screenshots are preview-rendered (`:camera:metadata`): Layoutlib can't open a camera, so `src/screenshotTest` draws the deterministic `FakeCameraPreview` scene behind the real top bar/grid/shutter/mode controls. `Route.Settings` is captured from the stateless `CameraSettingsContent` slice in `ui/SettingsPage.kt` with literal fixtures. The `screenshotFakePreview` parameter on `CameraScreen`/`CameraPreviewSurface` is the same seam in `main` — production-default null, never passed by `MainActivity`, so no fake frame can appear on device - Volume keys act as the shutter, gated on the camera route being foreground; Esc/space covers desktop keyboards - `.maml` model assets ship uncompressed (`noCompress`) — never compress them - Capture rotation is one decision in `domain/CaptureRotation.kt` (sensor orientation from characteristics + physical display rotation + facing), consumed by stills (`StillCapturePlanner`), analysis frames, and video/slo-mo/Motion-Photo muxer hints. The activity is portrait-locked, so the window display rotation is always 0 and must never orient captures: the physical quadrant comes from the `OrientationEventListener` (fed to sessions via `CameraViewModel.setCaptureDisplayRotationDegrees`); preview sizing/metering keep the window rotation. Metadata convention: JPEG/JPEG_R keep sensor pixels + EXIF orientation (flip-carrying for mirrored raw front pixels), AVIF bakes rotation/mirror into pixels with EXIF Normal and no `irot`, MP4 carries only the muxer orientation hint, night/pano RGB outputs bake pixels upright. No DNG writer is wired (`DngMetadata` only assembles requirements)
camera/src/main/java/com/vayunmathur/camera/ui/SettingsPage.kt
diff --git a/camera/src/main/java/com/vayunmathur/camera/ui/SettingsPage.kt b/camera/src/main/java/com/vayunmathur/camera/ui/SettingsPage.ktindex 265c784431..a234fc2a35 100644--- a/camera/src/main/java/com/vayunmathur/camera/ui/SettingsPage.kt+++ b/camera/src/main/java/com/vayunmathur/camera/ui/SettingsPage.kt@@ -31,6 +31,11 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import com.vayunmathur.camera.R import com.vayunmathur.camera.platform.CameraViewModel+import com.vayunmathur.camera.platform.MotionPhotoDuration+import com.vayunmathur.camera.platform.PhotoFormat+import com.vayunmathur.camera.platform.VideoCodec+import com.vayunmathur.camera.platform.camera2.AudioInputDeviceOption+import com.vayunmathur.camera.platform.camera2.AudioInputDeviceSelection import com.vayunmathur.camera.platform.requestedStillFormat import com.vayunmathur.camera.data.SafDocuments import com.vayunmathur.camera.data.SaveTarget@@ -144,13 +149,21 @@ fun <T : NavKey> SettingsPage(backStack: NavBackStack<T>, viewModel: CameraViewM         // Cap the form at a readable measure when the detail pane is wide         // (large tablet beside the viewfinder); narrower panes pass through.         DesktopMaxWidthContainer(modifier = Modifier.padding(padding)) {-        Column(-            modifier = Modifier-                .fillMaxSize()-                .verticalScroll(rememberScrollState())-        ) {-            SaveLocationSection(+            CameraSettingsContent(                 saveTarget = saveTarget,+                videoCodec = videoCodec,+                audioInputDevice = effectiveAudioDevice,+                audioInputDeviceOptions = audioDeviceOptions,+                mirrorFront = mirrorFront,+                photoFormat = photoFormat,+                noiseReductionEnabled = noiseReductionEnabled,+                edgeSharpeningEnabled = edgeSharpeningEnabled,+                motionPhotoDuration = motionPhotoDuration,+                // Effective AVIF only (native encoder present): a JPEG-fallback+                // AVIF selection leaves Motion Photo available, as at capture.+                motionPhotoBlockedByAvif = com.vayunmathur.camera.domain.StillFormatRouting+                    .avifPrecludesMotionPhoto(viewModel.requestedStillFormat(), com.vayunmathur.camera.platform.StitchNative.isAvailable),+                locationEnabled = locationEnabled,                 onChooseFolder = {                     val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE).apply {                         addFlags(@@ -164,56 +177,107 @@ fun <T : NavKey> SettingsPage(backStack: NavBackStack<T>, viewModel: CameraViewM                             messenger.show(saveLocationError)                         }                 },-                onReset = { viewModel.clearSaveTreeUri() },-            )-            CameraCodecSettings(-                videoCodec = videoCodec,-                audioInputDevice = effectiveAudioDevice,-                audioInputDeviceOptions = audioDeviceOptions,+                onResetSaveLocation = { viewModel.clearSaveTreeUri() },                 onVideoCodecChange = { viewModel.setVideoCodec(it); noteIfDeferred() },                 onAudioInputDeviceChange = { viewModel.setAudioInputDevice(it); noteIfDeferred() },-            )--            SettingsSection(title = stringResource(R.string.settings_mirror_front)) {-                SettingsSwitchRow(-                    title = stringResource(R.string.settings_mirror_front_description),-                    checked = mirrorFront,-                    onCheckedChange = { viewModel.setMirrorFront(it); noteIfDeferred() },-                )-            }--            CameraPhotoFormatSettings(-                photoFormat = photoFormat,+                onMirrorFrontChange = { viewModel.setMirrorFront(it); noteIfDeferred() },                 onPhotoFormatChange = { viewModel.setPhotoFormat(it); noteIfDeferred() },-            )--            CameraPostProcessingSettings(-                noiseReductionEnabled = noiseReductionEnabled,-                edgeSharpeningEnabled = edgeSharpeningEnabled,-                motionPhotoDuration = motionPhotoDuration,-                // Effective AVIF only (native encoder present): a JPEG-fallback-                // AVIF selection leaves Motion Photo available, as at capture.-                motionPhotoBlockedByAvif = com.vayunmathur.camera.domain.StillFormatRouting-                    .avifPrecludesMotionPhoto(viewModel.requestedStillFormat(), com.vayunmathur.camera.platform.StitchNative.isAvailable),                 onNoiseReductionChange = { viewModel.setNoiseReductionEnabled(it) },                 onEdgeSharpeningChange = { viewModel.setEdgeSharpeningEnabled(it) },                 onMotionDurationChange = { viewModel.setMotionPhotoDuration(it) },+                onLocationEnabledChange = { enabled ->+                    if (enabled) {+                        requestLocation()+                    } else {+                        viewModel.setLocationEnabled(false)+                    }+                },             )+        }+    }+} -            SettingsSection(title = stringResource(R.string.settings_location)) {-                SettingsSwitchRow(-                    title = stringResource(R.string.settings_location_description),-                    checked = locationEnabled,-                    onCheckedChange = { enabled ->-                        if (enabled) {-                            requestLocation()-                        } else {-                            viewModel.setLocationEnabled(false)-                        }-                    },-                )-            }+/**+ * The settings form itself, stateless: every value is passed in and every+ * change is reported through a callback, so the screen renders identically+ * from the ViewModel (in [SettingsPage]) or from literal fixtures (the+ * `src/screenshotTest` capture for `Route.Settings`). All side-effectful+ * plumbing — the location-permission request, the folder picker, the+ * audio-device callback, the deferred-recording note and the foreground+ * route — stays in [SettingsPage]; this composable only lays out the rows.+ */+@Composable+internal fun CameraSettingsContent(+    saveTarget: SaveTarget,+    videoCodec: VideoCodec,+    audioInputDevice: AudioInputDeviceSelection,+    audioInputDeviceOptions: List<AudioInputDeviceOption>,+    mirrorFront: Boolean,+    photoFormat: PhotoFormat,+    noiseReductionEnabled: Boolean,+    edgeSharpeningEnabled: Boolean,+    motionPhotoDuration: MotionPhotoDuration,+    motionPhotoBlockedByAvif: Boolean,+    locationEnabled: Boolean,+    onChooseFolder: () -> Unit,+    onResetSaveLocation: () -> Unit,+    onVideoCodecChange: (VideoCodec) -> Unit,+    onAudioInputDeviceChange: (AudioInputDeviceSelection) -> Unit,+    onMirrorFrontChange: (Boolean) -> Unit,+    onPhotoFormatChange: (PhotoFormat) -> Unit,+    onNoiseReductionChange: (Boolean) -> Unit,+    onEdgeSharpeningChange: (Boolean) -> Unit,+    onMotionDurationChange: (MotionPhotoDuration) -> Unit,+    onLocationEnabledChange: (Boolean) -> Unit,+    modifier: Modifier = Modifier,+) {+    Column(+        modifier = modifier+            .fillMaxSize()+            .verticalScroll(rememberScrollState())+    ) {+        SaveLocationSection(+            saveTarget = saveTarget,+            onChooseFolder = onChooseFolder,+            onReset = onResetSaveLocation,+        )+        CameraCodecSettings(+            videoCodec = videoCodec,+            audioInputDevice = audioInputDevice,+            audioInputDeviceOptions = audioInputDeviceOptions,+            onVideoCodecChange = onVideoCodecChange,+            onAudioInputDeviceChange = onAudioInputDeviceChange,+        )++        SettingsSection(title = stringResource(R.string.settings_mirror_front)) {+            SettingsSwitchRow(+                title = stringResource(R.string.settings_mirror_front_description),+                checked = mirrorFront,+                onCheckedChange = onMirrorFrontChange,+            )         }++        CameraPhotoFormatSettings(+            photoFormat = photoFormat,+            onPhotoFormatChange = onPhotoFormatChange,+        )++        CameraPostProcessingSettings(+            noiseReductionEnabled = noiseReductionEnabled,+            edgeSharpeningEnabled = edgeSharpeningEnabled,+            motionPhotoDuration = motionPhotoDuration,+            motionPhotoBlockedByAvif = motionPhotoBlockedByAvif,+            onNoiseReductionChange = onNoiseReductionChange,+            onEdgeSharpeningChange = onEdgeSharpeningChange,+            onMotionDurationChange = onMotionDurationChange,+        )++        SettingsSection(title = stringResource(R.string.settings_location)) {+            SettingsSwitchRow(+                title = stringResource(R.string.settings_location_description),+                checked = locationEnabled,+                onCheckedChange = onLocationEnabledChange,+            )         }     } }
camera/src/screenshotTest/kotlin/com/vayunmathur/camera/ui/MetadataPreviews.kt
diff --git a/camera/src/screenshotTest/kotlin/com/vayunmathur/camera/ui/MetadataPreviews.kt b/camera/src/screenshotTest/kotlin/com/vayunmathur/camera/ui/MetadataPreviews.ktindex afe1a2e3e0..abbf66be53 100644--- a/camera/src/screenshotTest/kotlin/com/vayunmathur/camera/ui/MetadataPreviews.kt+++ b/camera/src/screenshotTest/kotlin/com/vayunmathur/camera/ui/MetadataPreviews.kt@@ -1,20 +1,32 @@ package com.vayunmathur.camera.ui +import android.media.AudioDeviceInfo import androidx.compose.foundation.background import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.padding import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color+import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview import com.android.tools.screenshot.PreviewTest+import com.vayunmathur.camera.data.SaveTarget import com.vayunmathur.camera.platform.AspectRatioOption import com.vayunmathur.camera.platform.CameraMode import com.vayunmathur.camera.platform.FlashMode+import com.vayunmathur.camera.platform.MotionPhotoDuration+import com.vayunmathur.camera.platform.PhotoFormat import com.vayunmathur.camera.platform.TimerDuration+import com.vayunmathur.camera.platform.VideoCodec+import com.vayunmathur.camera.platform.camera2.AudioInputDeviceOption+import com.vayunmathur.camera.platform.camera2.AudioInputDeviceSelection+import com.vayunmathur.library.ui.AppScaffold+import com.vayunmathur.library.ui.DesktopMaxWidthContainer import com.vayunmathur.library.ui.DynamicTheme+import com.vayunmathur.library.ui.R as UiR  /** Phone-shaped, roughly 1080x2340 at xxhdpi — comfortably above the F-Droid minimum. */ private const val PHONE = "spec:width=411dp,height=891dp,dpi=420"@@ -42,6 +54,11 @@ private const val EXPANDED = "spec:width=1280dp,height=800dp,dpi=240"  * `./gradlew :camera:metadata` renders these previews and collects them into  * `metadata_data/photos/camera/phone/` and `.../large-tablet/`.  *+ * Coverage: `Route.Camera` on phone (`2-camera`) and large-tablet+ * (`1-wide-controls-expanded`), plus `Route.Settings` on phone (`3-settings`)+ * rendering the real stateless [CameraSettingsContent] slice with literal+ * fixture values inside the same `AppScaffold` chrome `SettingsPage` uses.+ *  * Rules (same as every other module's MetadataPreviews): order comes from the  * function names, each preview needs `@PreviewTest` plus a `group`, and previews  * are class members.@@ -112,8 +129,61 @@ class MetadataPreviews {             }         }     }++    @PreviewTest+    @Preview(name = "3-settings", device = PHONE, group = "phone", showSystemUi = true)+    @Composable+    fun Preview3Settings() {+        DynamicTheme(darkTheme = true) {+            // The real settings form (CameraSettingsContent) with literal+            // fixture values, in the same scaffold chrome SettingsPage uses.+            AppScaffold(+                title = stringResource(UiR.string.settings),+                onNavigateBack = {},+            ) { padding ->+                DesktopMaxWidthContainer(modifier = Modifier.padding(padding)) {+                    CameraSettingsContent(+                        saveTarget = SaveTarget.MediaStoreDefault,+                        videoCodec = VideoCodec.AVC,+                        audioInputDevice = FIXTURE_AUDIO_DEVICE,+                        audioInputDeviceOptions = listOf(FIXTURE_AUDIO_DEVICE_OPTION),+                        mirrorFront = true,+                        photoFormat = PhotoFormat.JPEG,+                        noiseReductionEnabled = true,+                        edgeSharpeningEnabled = true,+                        motionPhotoDuration = MotionPhotoDuration.THREE,+                        motionPhotoBlockedByAvif = false,+                        locationEnabled = true,+                        onChooseFolder = {},+                        onResetSaveLocation = {},+                        onVideoCodecChange = {},+                        onAudioInputDeviceChange = {},+                        onMirrorFrontChange = {},+                        onPhotoFormatChange = {},+                        onNoiseReductionChange = {},+                        onEdgeSharpeningChange = {},+                        onMotionDurationChange = {},+                        onLocationEnabledChange = {},+                    )+                }+            }+        }+    } } +/** The one fixture microphone: a literal built-in mic, selected in the picker. */+private val FIXTURE_AUDIO_DEVICE = AudioInputDeviceSelection(+    deviceId = 3,+    deviceType = AudioDeviceInfo.TYPE_BUILTIN_MIC,+    productName = "Built-in microphone",+)++private val FIXTURE_AUDIO_DEVICE_OPTION = AudioInputDeviceOption(+    selection = FIXTURE_AUDIO_DEVICE,+    label = "Built-in microphone",+    description = "This device",+)+ @Composable private fun FixtureShutterPane() {     CameraShutterPane(