Modern Apps git

← Modern-Apps.git

camera: split session/state files for release lint (round 2)

Commit
1873b030e9fd8c3aef3ecfffe7a889b18cd9607b
Author
Vayun Mathur <[email protected]>
When
2026-11-22 22:15 UTC (13 days ago)
Parents
ab55bce
The Camera2 analysis/night wiring regrew Camera2Session
(867) and CameraScreenState (380) past the limits.
Session configuration plumbing moves verbatim to
Camera2SessionConfigure.kt (extensions, following the
still-delivery pattern) and the state composable to
RememberCameraScreenState.kt; member visibility widened
private -> internal only where the move requires it.

Verified: lintVitalRelease + assembleRelease green;
16 targeted tests pass.

Diff

camera/src/main/java/com/vayunmathur/camera/platform/camera2/Camera2Session.kt
diff --git a/camera/src/main/java/com/vayunmathur/camera/platform/camera2/Camera2Session.kt b/camera/src/main/java/com/vayunmathur/camera/platform/camera2/Camera2Session.ktindex 3147c9ab6b..ede69b52a8 100644--- a/camera/src/main/java/com/vayunmathur/camera/platform/camera2/Camera2Session.kt+++ b/camera/src/main/java/com/vayunmathur/camera/platform/camera2/Camera2Session.kt@@ -1,6 +1,5 @@ package com.vayunmathur.camera.platform.camera2 -import android.graphics.ImageFormat import android.view.Surface  /**@@ -43,15 +42,15 @@ import android.view.Surface  * from a `DisposableEffect`). [close] is idempotent and terminal.  */ class Camera2Session(-    private val driver: Camera2Driver,+    internal val driver: Camera2Driver,     internal val executor: Camera2Executor,-    private val snapshot: LensCharacteristicsSnapshot,+    internal val snapshot: LensCharacteristicsSnapshot,     private val stateMachine: SessionStateMachine = SessionStateMachine(),     private val listener: Listener? = null,-    private val ringConfig: ReprocessRingConfig = ReprocessRingConfig.DISABLED,-    private val rawRingConfig: RawRingConfig = RawRingConfig.DISABLED,+    internal val ringConfig: ReprocessRingConfig = ReprocessRingConfig.DISABLED,+    internal val rawRingConfig: RawRingConfig = RawRingConfig.DISABLED,     /** Plane consumer for the analysis stream; null = no analysis output. */-    private val analysisConsumer: AnalysisConsumer? = null,+    internal val analysisConsumer: AnalysisConsumer? = null, ) {      /** Session lifecycle notifications; all fire on the executor thread. */@@ -84,22 +83,22 @@ class Camera2Session(      private var device: DeviceHandle? = null     private var captureSession: CaptureSessionHandle? = null-    private var previewSurface: Surface? = null+    internal var previewSurface: Surface? = null     private var previewSize: FrameSize? = null-    private var stillOutput: StillOutput? = null-    private var stillSize: FrameSize? = null-    private var ultraHdrOutput: StillOutput? = null-    private var ultraHdrSize: FrameSize? = null-    private var ringOutput: RingOutput? = null-    private var ringSize: FrameSize? = null+    internal var stillOutput: StillOutput? = null+    internal var stillSize: FrameSize? = null+    internal var ultraHdrOutput: StillOutput? = null+    internal var ultraHdrSize: FrameSize? = null+    internal var ringOutput: RingOutput? = null+    internal var ringSize: FrameSize? = null     private val ring = ReprocessRing<RingHeldFrame>(ringConfig.capacity)-    private var analysisOutput: AnalysisOutput? = null-    private var analysisSize: FrameSize? = null+    internal var analysisOutput: AnalysisOutput? = null+    internal var analysisSize: FrameSize? = null     /** Set once a configure failure has dropped analysis: never re-add it. */-    private var analysisComboDropped: Boolean = false-    private var rawRingOutput: RawRingOutput? = null-    private var rawRingSize: FrameSize? = null-    private var rawRingFormat: RingFormat? = null+    internal var analysisComboDropped: Boolean = false+    internal var rawRingOutput: RawRingOutput? = null+    internal var rawRingSize: FrameSize? = null+    internal var rawRingFormat: RingFormat? = null     private val rawRing = ReprocessRing<RawHeldFrame>(rawRingConfig.capacity)     private var latestPreviewTimestampNs: Long? = null     private val previewMetas = LinkedHashMap<Long, RawStillMetadata>()@@ -513,7 +512,7 @@ class Camera2Session(      // Still byte/result pairing + delivery lives in Camera2SessionStillDelivery.kt. -    private fun onRingFrame(frame: RingHeldFrame) {+    internal fun onRingFrame(frame: RingHeldFrame) {         try {             executor.execute {                 val evicted = ring.offer(frame.meta, frame)@@ -531,7 +530,7 @@ class Camera2Session(         }     } -    private fun onRawRingFrame(frame: RawHeldFrame) {+    internal fun onRawRingFrame(frame: RawHeldFrame) {         try {             executor.execute {                 val evicted = rawRing.offer(frame.meta, frame)@@ -629,150 +628,15 @@ class Camera2Session(         }.onFailure { reportError("setRepeatingPreview failed: ${it.message}") }     } -    private fun configureSession(opened: DeviceHandle, gen: Long, reuseOutputs: Boolean = false) {-        val surface = previewSurface ?: return-        if (transition(SessionEvent.CONFIGURE_REQUESTED) !is TransitionResult.Applied) return-        if (reuseOutputs) {-            // Retry after a stream-combo failure dropped analysis: every-            // other output already exists; only the capture session is new.-            createCaptureSessionWithAnalysisFallback(opened, gen)-            return-        }-        // Second output: the JPEG still reader, when the lens reports JPEG-        // sizes and the driver can create it. Failure degrades to-        // preview-only (capture() then fails cleanly, policy excludes it).-        val jpegSize = StreamSelection.selectJpegSize(snapshot)-        val output = jpegSize?.let { size ->-            runCatching { driver.createStillOutput(size) }.getOrNull()?.also { created ->-                created.setListener(JpegImageListener { bytes, width, height, _ ->-                    onJpegAvailable(bytes, width, height)-                })-            }-        }-        stillOutput = output-        stillSize = if (output != null) jpegSize else null-        // Additional output: the JPEG_R (Ultra HDR) reader, only when the-        // facade advertises JPEG_R sizes. Failure degrades to no Ultra HDR-        // output (captures requesting it fall back to the JPEG output).-        val jpegRSize = if (snapshot.supportsJpegR) {-            StreamSelection.selectJpegRSize(snapshot)-        } else {-            null-        }-        val createdUltraHdr = jpegRSize?.let { size ->-            runCatching { driver.createUltraHdrStillOutput(size) }.getOrNull()?.also { created ->-                created.setListener(JpegImageListener { bytes, width, height, _ ->-                    onUltraHdrJpegAvailable(bytes, width, height)-                })-            }-        }-        ultraHdrOutput = createdUltraHdr-        ultraHdrSize = if (createdUltraHdr != null) jpegRSize else null-        // Third output: the YUV ring, only when this session was built-        // with the ring enabled. Failure degrades to no-ring (the-        // policy then excludes the ring path, capture stays Phase 4a).-        val selectedRingSize = if (ringConfig.enabled) {-            StreamSelection.selectRingSize(snapshot)-        } else {-            null-        }-        val createdRing = selectedRingSize?.let { size ->-            runCatching { driver.createRingOutput(size) }.getOrNull()?.also { created ->-                created.setListener(RingFrameListener { frame -> onRingFrame(frame) })-            }-        }-        ringOutput = createdRing-        ringSize = if (createdRing != null) selectedRingSize else null-        // Fourth output: the RAW ring, only when built with it enabled and-        // the facade proves RAW. RAW stream combos vary wildly per HAL, so-        // failure degrades to no RAW ring (policy excludes the RAW path).-        val selectedRawSize = if (rawRingConfig.enabled) {-            StreamSelection.selectRawRingSize(snapshot)-        } else {-            null-        }-        val selectedRawFormat = snapshot.rawRingFormat-        val createdRawRing = if (selectedRawSize != null && selectedRawFormat != null) {-            runCatching {-                driver.createRawRingOutput(selectedRawSize, selectedRawFormat)-            }.getOrNull()?.also { created ->-                created.setListener(RawRingFrameListener { frame -> onRawRingFrame(frame) })-            }-        } else {-            null-        }-        rawRingOutput = createdRawRing-        rawRingSize = if (createdRawRing != null) selectedRawSize else null-        rawRingFormat = if (createdRawRing != null) selectedRawFormat else null-        // Optional analysis output: only when a consumer was supplied.-        // Failure degrades to no analysis (preview/still unaffected).-        val consumer = analysisConsumer-        val selectedAnalysisSize = if (consumer != null && !analysisComboDropped) {-            StreamSelection.selectAnalysisSize(snapshot)-        } else {-            null-        }-        val createdAnalysis = if (selectedAnalysisSize != null && consumer != null) {-            runCatching { driver.createAnalysisOutput(selectedAnalysisSize, consumer) }.getOrNull()-        } else {-            null-        }-        analysisOutput = createdAnalysis-        analysisSize = if (createdAnalysis != null) selectedAnalysisSize else null-        createCaptureSessionWithAnalysisFallback(opened, gen)-    }--    /** Surfaces for one configure attempt: preview + every live output. */-    private fun configuredSurfaces(): List<Surface> = listOfNotNull(-        previewSurface, stillOutput?.surface, ultraHdrOutput?.surface,-        ringOutput?.surface, rawRingOutput?.surface, analysisOutput?.surface,-    )--    /**-     * Creates the capture session over [configuredSurfaces]. A synchronous-     * create failure with analysis present drops analysis and retries once-     * without it; an asynchronous configure failure takes the same path in-     * [SessionCallbackImpl.onConfigureFailed]. Analysis never costs preview.-     */-    private fun createCaptureSessionWithAnalysisFallback(opened: DeviceHandle, gen: Long) {-        val callback = SessionCallbackImpl(gen)-        val ringSize = ringSize-        runCatching {-            if (ringOutput != null && ringSize != null && snapshot.supportsYuvRingReprocess) {-                opened.createReprocessableCaptureSession(-                    ReprocessInputConfig(ringSize.width, ringSize.height, ImageFormat.YUV_420_888),-                    configuredSurfaces(),-                    callback,-                )-            } else {-                opened.createCaptureSession(configuredSurfaces(), callback)-            }-        }.onFailure {-            if (analysisOutput != null && !analysisComboDropped) {-                dropAnalysisOutput()-                createCaptureSessionWithAnalysisFallback(opened, gen)-            } else {-                dispatch(gen, SessionEvent.CONFIGURE_FAILED)-                reportError("createCaptureSession failed: ${it.message}")-            }-        }-    }--    /** Drops the analysis output (combo degrade); preview/still keep serving. */-    private fun dropAnalysisOutput() {-        analysisComboDropped = true-        runCatching { analysisOutput?.close() }-        analysisOutput = null-        analysisSize = null-    }--    private fun transition(event: SessionEvent): TransitionResult {+    // Session configuration (outputs + capture-session creation) lives in+    // Camera2SessionConfigure.kt.+    internal fun transition(event: SessionEvent): TransitionResult {         val result = stateMachine.transition(event)         if (result is TransitionResult.Applied) notifyState()         return result     } -    private fun dispatch(gen: Long, event: SessionEvent): TransitionResult {+    internal fun dispatch(gen: Long, event: SessionEvent): TransitionResult {         val result = stateMachine.dispatch(gen, event)         if (result is TransitionResult.Applied) notifyState()         return result@@ -782,7 +646,7 @@ class Camera2Session(         listener?.onStateChanged(stateMachine.state)     } -    private fun reportError(message: String) {+    internal fun reportError(message: String) {         listener?.onError(message)     } @@ -824,7 +688,7 @@ class Camera2Session(         }     } -    private inner class SessionCallbackImpl(+    internal inner class SessionCallbackImpl(         private val gen: Long,     ) : CaptureSessionCallback {         override fun onConfigured(session: CaptureSessionHandle) {
camera/src/main/java/com/vayunmathur/camera/platform/camera2/Camera2SessionConfigure.kt
diff --git a/camera/src/main/java/com/vayunmathur/camera/platform/camera2/Camera2SessionConfigure.kt b/camera/src/main/java/com/vayunmathur/camera/platform/camera2/Camera2SessionConfigure.ktnew file mode 100644index 0000000000..ea2d89ee74--- /dev/null+++ b/camera/src/main/java/com/vayunmathur/camera/platform/camera2/Camera2SessionConfigure.kt@@ -0,0 +1,150 @@+package com.vayunmathur.camera.platform.camera2++import android.graphics.ImageFormat+import android.view.Surface++/**+ * Session-configuration plumbing for [Camera2Session]: creating the+ * still/ring/analysis outputs for one open and creating the capture+ * session over them (with the analysis-combo fallback). Moved verbatim+ * from the session as extensions, following+ * `Camera2SessionStillDelivery.kt`; all state is touched only on the+ * session executor, as before.+ */++internal fun Camera2Session.configureSession(opened: DeviceHandle, gen: Long, reuseOutputs: Boolean = false) {+    val surface = previewSurface ?: return+    if (transition(SessionEvent.CONFIGURE_REQUESTED) !is TransitionResult.Applied) return+    if (reuseOutputs) {+        // Retry after a stream-combo failure dropped analysis: every+        // other output already exists; only the capture session is new.+        createCaptureSessionWithAnalysisFallback(opened, gen)+        return+    }+    // Second output: the JPEG still reader, when the lens reports JPEG+    // sizes and the driver can create it. Failure degrades to+    // preview-only (capture() then fails cleanly, policy excludes it).+    val jpegSize = StreamSelection.selectJpegSize(snapshot)+    val output = jpegSize?.let { size ->+        runCatching { driver.createStillOutput(size) }.getOrNull()?.also { created ->+            created.setListener(JpegImageListener { bytes, width, height, _ ->+                onJpegAvailable(bytes, width, height)+            })+        }+    }+    stillOutput = output+    stillSize = if (output != null) jpegSize else null+    // Additional output: the JPEG_R (Ultra HDR) reader, only when the+    // facade advertises JPEG_R sizes. Failure degrades to no Ultra HDR+    // output (captures requesting it fall back to the JPEG output).+    val jpegRSize = if (snapshot.supportsJpegR) {+        StreamSelection.selectJpegRSize(snapshot)+    } else {+        null+    }+    val createdUltraHdr = jpegRSize?.let { size ->+        runCatching { driver.createUltraHdrStillOutput(size) }.getOrNull()?.also { created ->+            created.setListener(JpegImageListener { bytes, width, height, _ ->+                onUltraHdrJpegAvailable(bytes, width, height)+            })+        }+    }+    ultraHdrOutput = createdUltraHdr+    ultraHdrSize = if (createdUltraHdr != null) jpegRSize else null+    // Third output: the YUV ring, only when this session was built+    // with the ring enabled. Failure degrades to no-ring (the+    // policy then excludes the ring path, capture stays Phase 4a).+    val selectedRingSize = if (ringConfig.enabled) {+        StreamSelection.selectRingSize(snapshot)+    } else {+        null+    }+    val createdRing = selectedRingSize?.let { size ->+        runCatching { driver.createRingOutput(size) }.getOrNull()?.also { created ->+            created.setListener(RingFrameListener { frame -> onRingFrame(frame) })+        }+    }+    ringOutput = createdRing+    ringSize = if (createdRing != null) selectedRingSize else null+    // Fourth output: the RAW ring, only when built with it enabled and+    // the facade proves RAW. RAW stream combos vary wildly per HAL, so+    // failure degrades to no RAW ring (policy excludes the RAW path).+    val selectedRawSize = if (rawRingConfig.enabled) {+        StreamSelection.selectRawRingSize(snapshot)+    } else {+        null+    }+    val selectedRawFormat = snapshot.rawRingFormat+    val createdRawRing = if (selectedRawSize != null && selectedRawFormat != null) {+        runCatching {+            driver.createRawRingOutput(selectedRawSize, selectedRawFormat)+        }.getOrNull()?.also { created ->+            created.setListener(RawRingFrameListener { frame -> onRawRingFrame(frame) })+        }+    } else {+        null+    }+    rawRingOutput = createdRawRing+    rawRingSize = if (createdRawRing != null) selectedRawSize else null+    rawRingFormat = if (createdRawRing != null) selectedRawFormat else null+    // Optional analysis output: only when a consumer was supplied.+    // Failure degrades to no analysis (preview/still unaffected).+    val consumer = analysisConsumer+    val selectedAnalysisSize = if (consumer != null && !analysisComboDropped) {+        StreamSelection.selectAnalysisSize(snapshot)+    } else {+        null+    }+    val createdAnalysis = if (selectedAnalysisSize != null && consumer != null) {+        runCatching { driver.createAnalysisOutput(selectedAnalysisSize, consumer) }.getOrNull()+    } else {+        null+    }+    analysisOutput = createdAnalysis+    analysisSize = if (createdAnalysis != null) selectedAnalysisSize else null+    createCaptureSessionWithAnalysisFallback(opened, gen)+}++/** Surfaces for one configure attempt: preview + every live output. */+internal fun Camera2Session.configuredSurfaces(): List<Surface> = listOfNotNull(+    previewSurface, stillOutput?.surface, ultraHdrOutput?.surface,+    ringOutput?.surface, rawRingOutput?.surface, analysisOutput?.surface,+)++/**+ * Creates the capture session over [configuredSurfaces]. A synchronous+ * create failure with analysis present drops analysis and retries once+ * without it; an asynchronous configure failure takes the same path in+ * [SessionCallbackImpl.onConfigureFailed]. Analysis never costs preview.+ */+internal fun Camera2Session.createCaptureSessionWithAnalysisFallback(opened: DeviceHandle, gen: Long) {+    val callback = SessionCallbackImpl(gen)+    val ringSize = ringSize+    runCatching {+        if (ringOutput != null && ringSize != null && snapshot.supportsYuvRingReprocess) {+            opened.createReprocessableCaptureSession(+                ReprocessInputConfig(ringSize.width, ringSize.height, ImageFormat.YUV_420_888),+                configuredSurfaces(),+                callback,+            )+        } else {+            opened.createCaptureSession(configuredSurfaces(), callback)+        }+    }.onFailure {+        if (analysisOutput != null && !analysisComboDropped) {+            dropAnalysisOutput()+            createCaptureSessionWithAnalysisFallback(opened, gen)+        } else {+            dispatch(gen, SessionEvent.CONFIGURE_FAILED)+            reportError("createCaptureSession failed: ${it.message}")+        }+    }+}++/** Drops the analysis output (combo degrade); preview/still keep serving. */+internal fun Camera2Session.dropAnalysisOutput() {+    analysisComboDropped = true+    runCatching { analysisOutput?.close() }+    analysisOutput = null+    analysisSize = null+}
camera/src/main/java/com/vayunmathur/camera/ui/CameraScreenState.kt
diff --git a/camera/src/main/java/com/vayunmathur/camera/ui/CameraScreenState.kt b/camera/src/main/java/com/vayunmathur/camera/ui/CameraScreenState.ktindex 8073f34d0e..e5e89d05b2 100644--- a/camera/src/main/java/com/vayunmathur/camera/ui/CameraScreenState.kt+++ b/camera/src/main/java/com/vayunmathur/camera/ui/CameraScreenState.kt@@ -2,14 +2,9 @@ package com.vayunmathur.camera.ui  import android.graphics.Bitmap import androidx.camera.core.CameraSelector-import androidx.compose.runtime.Composable-import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue-import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.MutableIntState import androidx.compose.runtime.MutableState-import androidx.compose.runtime.mutableStateOf-import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import com.vayunmathur.camera.platform.AspectRatioOption import com.vayunmathur.camera.platform.AudioCodec@@ -19,7 +14,6 @@ import com.vayunmathur.camera.platform.CameraViewModel import com.vayunmathur.camera.platform.FlashMode import com.vayunmathur.camera.platform.TimerDuration import com.vayunmathur.camera.platform.VideoCodec-import com.vayunmathur.camera.platform.BokehAnalyzer  /**  * All UI state read by [CameraScreen], collected from [CameraViewModel] flows in one@@ -219,161 +213,3 @@ import com.vayunmathur.camera.platform.BokehAnalyzer         hasFlashUnit,     ) }--@Composable-internal fun rememberCameraScreenState(viewModel: CameraViewModel): CameraScreenState {-    val cameraMode by viewModel.cameraMode.collectAsState()-    val lensFacing by viewModel.lensFacing.collectAsState()-    val selectedLens by viewModel.selectedLens.collectAsState()-    val availableLenses by viewModel.availableLenses.collectAsState()-    val hasFlashUnit by viewModel.hasFlashUnit.collectAsState()-    val flashMode by viewModel.flashMode.collectAsState()-    val torchEnabled by viewModel.torchEnabled.collectAsState()-    val videoCodec by viewModel.videoCodec.collectAsState()-    val audioCodec by viewModel.audioCodec.collectAsState()-    val audioInputSource by viewModel.audioInputSource.collectAsState()-    val isRecording by viewModel.isRecording.collectAsState()-    val recordingDuration by viewModel.recordingDurationSec.collectAsState()-    val timerCountdown by viewModel.timerCountdown.collectAsState()-    val qrResult by viewModel.qrResult.collectAsState()-    val aspectRatio by viewModel.aspectRatio.collectAsState()-    val zoomRatio by viewModel.zoomRatio.collectAsState()-    val mirrorFront by viewModel.mirrorFront.collectAsState()-    val timerDuration by viewModel.timerDuration.collectAsState()-    val isCapturing by viewModel.isCapturing.collectAsState()-    val burstActive by viewModel.burstActive.collectAsState()-    val burstCount by viewModel.burstCount.collectAsState()-    val focusLocked by viewModel.focusLocked.collectAsState()-    val recordingPaused by viewModel.recordingPaused.collectAsState()-    val micMuted by viewModel.micMuted.collectAsState()-    val videoSnapshotSupported by viewModel.videoSnapshotSupported.collectAsState()-    val lastCaptureUri by viewModel.lastCaptureUri.collectAsState()-    val gridEnabled by viewModel.gridEnabled.collectAsState()-    val levelEnabled by viewModel.levelEnabled.collectAsState()-    val roll by viewModel.roll.collectAsState()-    val blurStrength by viewModel.blurStrength.collectAsState()-    val exposureComp by viewModel.exposureCompensation.collectAsState()-    val warmth by viewModel.warmth.collectAsState()-    val shadows by viewModel.shadows.collectAsState()-    val exposureTimeIndex by viewModel.exposureTimeIndex.collectAsState()-    val manualIsoIndex by viewModel.manualIsoIndex.collectAsState()-    val isoStops by viewModel.isoStops.collectAsState()-    val longExposureProgress by viewModel.longExposureProgress.collectAsState()-    val longExposureRemaining by viewModel.longExposureRemaining.collectAsState()-    val lowLightDetected by viewModel.lowLightDetected.collectAsState()-    val nightModeActive by viewModel.nightModeActive.collectAsState()-    val extensionStrength by viewModel.extensionStrength.collectAsState()-    val sloMoSupported by viewModel.sloMoSupported.collectAsState()-    val highSpeedActive by viewModel.highSpeedActive.collectAsState()-    val photoSessionActive by viewModel.photoSessionActive.collectAsState()-    val analysisStreamActive by viewModel.analysisStreamActive.collectAsState()-    val nightExtAvailable by viewModel.nightExtensionUsable.collectAsState()-    val surfaceRequest by viewModel.surfaceRequest.collectAsState()-    val camera2PreviewEnabled by viewModel.camera2PreviewEnabled.collectAsState()-    val camera2FallbackBindKey by viewModel.camera2FallbackBindKey.collectAsState()-    val camera2NightSessionActive by viewModel.camera2NightSessionActive.collectAsState()-    val camera2NightEnabled by viewModel.camera2NightEnabled.collectAsState()-    val camera2NightFallbackBindKey by viewModel.camera2NightFallbackBindKey.collectAsState()-    val sessionBindFailed by viewModel.sessionBindFailed.collectAsState()-    val sessionBindRetry by viewModel.sessionBindRetry.collectAsState()-    val availableZoomLevels by viewModel.availableZoomLevels.collectAsState()-    val galleryBitmap by viewModel.galleryThumbnail.collectAsState()--    val panoSweeping by viewModel.panoramaEngine.isSweeping.collectAsState()-    val panoStitching by viewModel.panoramaEngine.isStitching.collectAsState()-    val panoDots by viewModel.panoramaEngine.guideDots.collectAsState()-    val panoCurrentAngle by viewModel.panoramaEngine.currentAngle.collectAsState()-    val panoDirection by viewModel.panoramaEngine.sweepDirection.collectAsState()-    val panoPitch by viewModel.panoramaEngine.currentPitch.collectAsState()--    // Kept OUTSIDE the remember(keys) below so they survive holder recreation. Without this-    // the portrait bokeh mask (written from BokehAnalyzer's background thread) is reset to-    // null every time a collected value like roll changes, and the preview never blurs.-    val activeSettingState = remember { mutableStateOf<CameraSetting?>(null) }-    val maskBitmapState = remember { mutableStateOf<Bitmap?>(null) }-    val deviceRotationState = remember { mutableIntStateOf(0) }--    return remember(-        cameraMode, lensFacing, selectedLens, availableLenses, hasFlashUnit, flashMode, torchEnabled, videoCodec, audioCodec, audioInputSource, mirrorFront, isRecording, recordingDuration,-        timerCountdown, qrResult, aspectRatio, zoomRatio, timerDuration,-        isCapturing, burstActive, burstCount, focusLocked, recordingPaused, micMuted,-        videoSnapshotSupported, lastCaptureUri, gridEnabled, levelEnabled, roll,-        blurStrength, exposureComp, warmth, shadows, exposureTimeIndex, manualIsoIndex,-        isoStops, longExposureProgress, longExposureRemaining, lowLightDetected,-        nightModeActive, extensionStrength, sloMoSupported, highSpeedActive,-        photoSessionActive, analysisStreamActive, nightExtAvailable, surfaceRequest,-        camera2PreviewEnabled, camera2FallbackBindKey, camera2NightSessionActive,-        camera2NightEnabled, camera2NightFallbackBindKey,-        sessionBindFailed, sessionBindRetry,-        availableZoomLevels, galleryBitmap, panoSweeping, panoStitching, panoDots,-        panoCurrentAngle, panoDirection, panoPitch,-    ) {-        CameraScreenState(-            cameraMode = cameraMode,-            lensFacing = lensFacing,-            selectedLens = selectedLens,-            availableLenses = availableLenses,-            hasFlashUnit = hasFlashUnit,-            flashMode = flashMode,-            torchEnabled = torchEnabled,-            videoCodec = videoCodec,-            audioCodec = audioCodec,-            audioInputSource = audioInputSource,-            isRecording = isRecording,-            recordingDuration = recordingDuration,-            timerCountdown = timerCountdown,-            qrResult = qrResult,-            aspectRatio = aspectRatio,-            zoomRatio = zoomRatio,-            mirrorFront = mirrorFront,-            timerDuration = timerDuration,-            isCapturing = isCapturing,-            burstActive = burstActive,-            burstCount = burstCount,-            focusLocked = focusLocked,-            recordingPaused = recordingPaused,-            micMuted = micMuted,-            videoSnapshotSupported = videoSnapshotSupported,-            lastCaptureUri = lastCaptureUri,-            gridEnabled = gridEnabled,-            levelEnabled = levelEnabled,-            roll = roll,-            blurStrength = blurStrength,-            exposureComp = exposureComp,-            warmth = warmth,-            shadows = shadows,-            exposureTimeIndex = exposureTimeIndex,-            manualIsoIndex = manualIsoIndex,-            isoStops = isoStops,-            longExposureProgress = longExposureProgress,-            longExposureRemaining = longExposureRemaining,-            lowLightDetected = lowLightDetected,-            nightModeActive = nightModeActive,-            extensionStrength = extensionStrength,-            sloMoSupported = sloMoSupported,-            highSpeedActive = highSpeedActive,-            photoSessionActive = photoSessionActive,-            analysisStreamActive = analysisStreamActive,-            nightExtAvailable = nightExtAvailable,-            surfaceRequest = surfaceRequest,-            availableZoomLevels = availableZoomLevels,-            galleryBitmap = galleryBitmap,-            panoSweeping = panoSweeping,-            panoStitching = panoStitching,-            panoDots = panoDots,-            panoCurrentAngle = panoCurrentAngle,-            panoDirection = panoDirection,-            panoPitch = panoPitch,-            activeSettingState = activeSettingState,-            maskBitmapState = maskBitmapState,-            deviceRotationState = deviceRotationState,-            sessionBindFailed = sessionBindFailed,-            sessionBindRetry = sessionBindRetry,-            camera2PreviewEnabled = camera2PreviewEnabled,-            camera2FallbackBindKey = camera2FallbackBindKey,-            camera2NightSessionActive = camera2NightSessionActive,-            camera2NightEnabled = camera2NightEnabled,-            camera2NightFallbackBindKey = camera2NightFallbackBindKey,-        )-    }-}
camera/src/main/java/com/vayunmathur/camera/ui/RememberCameraScreenState.kt
diff --git a/camera/src/main/java/com/vayunmathur/camera/ui/RememberCameraScreenState.kt b/camera/src/main/java/com/vayunmathur/camera/ui/RememberCameraScreenState.ktnew file mode 100644index 0000000000..38ec552aab--- /dev/null+++ b/camera/src/main/java/com/vayunmathur/camera/ui/RememberCameraScreenState.kt@@ -0,0 +1,173 @@+package com.vayunmathur.camera.ui++import android.graphics.Bitmap+import androidx.compose.runtime.Composable+import androidx.compose.runtime.collectAsState+import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableIntStateOf+import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.remember+import com.vayunmathur.camera.platform.CameraViewModel++/**+ * Collects every [CameraViewModel] flow that [CameraScreenState] reads+ * into the holder in one place. Extracted verbatim from+ * `CameraScreenState.kt`; the holder class itself stays there.+ */+@Composable+internal fun rememberCameraScreenState(viewModel: CameraViewModel): CameraScreenState {+    val cameraMode by viewModel.cameraMode.collectAsState()+    val lensFacing by viewModel.lensFacing.collectAsState()+    val selectedLens by viewModel.selectedLens.collectAsState()+    val availableLenses by viewModel.availableLenses.collectAsState()+    val hasFlashUnit by viewModel.hasFlashUnit.collectAsState()+    val flashMode by viewModel.flashMode.collectAsState()+    val torchEnabled by viewModel.torchEnabled.collectAsState()+    val videoCodec by viewModel.videoCodec.collectAsState()+    val audioCodec by viewModel.audioCodec.collectAsState()+    val audioInputSource by viewModel.audioInputSource.collectAsState()+    val isRecording by viewModel.isRecording.collectAsState()+    val recordingDuration by viewModel.recordingDurationSec.collectAsState()+    val timerCountdown by viewModel.timerCountdown.collectAsState()+    val qrResult by viewModel.qrResult.collectAsState()+    val aspectRatio by viewModel.aspectRatio.collectAsState()+    val zoomRatio by viewModel.zoomRatio.collectAsState()+    val mirrorFront by viewModel.mirrorFront.collectAsState()+    val timerDuration by viewModel.timerDuration.collectAsState()+    val isCapturing by viewModel.isCapturing.collectAsState()+    val burstActive by viewModel.burstActive.collectAsState()+    val burstCount by viewModel.burstCount.collectAsState()+    val focusLocked by viewModel.focusLocked.collectAsState()+    val recordingPaused by viewModel.recordingPaused.collectAsState()+    val micMuted by viewModel.micMuted.collectAsState()+    val videoSnapshotSupported by viewModel.videoSnapshotSupported.collectAsState()+    val lastCaptureUri by viewModel.lastCaptureUri.collectAsState()+    val gridEnabled by viewModel.gridEnabled.collectAsState()+    val levelEnabled by viewModel.levelEnabled.collectAsState()+    val roll by viewModel.roll.collectAsState()+    val blurStrength by viewModel.blurStrength.collectAsState()+    val exposureComp by viewModel.exposureCompensation.collectAsState()+    val warmth by viewModel.warmth.collectAsState()+    val shadows by viewModel.shadows.collectAsState()+    val exposureTimeIndex by viewModel.exposureTimeIndex.collectAsState()+    val manualIsoIndex by viewModel.manualIsoIndex.collectAsState()+    val isoStops by viewModel.isoStops.collectAsState()+    val longExposureProgress by viewModel.longExposureProgress.collectAsState()+    val longExposureRemaining by viewModel.longExposureRemaining.collectAsState()+    val lowLightDetected by viewModel.lowLightDetected.collectAsState()+    val nightModeActive by viewModel.nightModeActive.collectAsState()+    val extensionStrength by viewModel.extensionStrength.collectAsState()+    val sloMoSupported by viewModel.sloMoSupported.collectAsState()+    val highSpeedActive by viewModel.highSpeedActive.collectAsState()+    val photoSessionActive by viewModel.photoSessionActive.collectAsState()+    val analysisStreamActive by viewModel.analysisStreamActive.collectAsState()+    val nightExtAvailable by viewModel.nightExtensionUsable.collectAsState()+    val surfaceRequest by viewModel.surfaceRequest.collectAsState()+    val camera2PreviewEnabled by viewModel.camera2PreviewEnabled.collectAsState()+    val camera2FallbackBindKey by viewModel.camera2FallbackBindKey.collectAsState()+    val camera2NightSessionActive by viewModel.camera2NightSessionActive.collectAsState()+    val camera2NightEnabled by viewModel.camera2NightEnabled.collectAsState()+    val camera2NightFallbackBindKey by viewModel.camera2NightFallbackBindKey.collectAsState()+    val sessionBindFailed by viewModel.sessionBindFailed.collectAsState()+    val sessionBindRetry by viewModel.sessionBindRetry.collectAsState()+    val availableZoomLevels by viewModel.availableZoomLevels.collectAsState()+    val galleryBitmap by viewModel.galleryThumbnail.collectAsState()++    val panoSweeping by viewModel.panoramaEngine.isSweeping.collectAsState()+    val panoStitching by viewModel.panoramaEngine.isStitching.collectAsState()+    val panoDots by viewModel.panoramaEngine.guideDots.collectAsState()+    val panoCurrentAngle by viewModel.panoramaEngine.currentAngle.collectAsState()+    val panoDirection by viewModel.panoramaEngine.sweepDirection.collectAsState()+    val panoPitch by viewModel.panoramaEngine.currentPitch.collectAsState()++    // Kept OUTSIDE the remember(keys) below so they survive holder recreation. Without this+    // the portrait bokeh mask (written from BokehAnalyzer's background thread) is reset to+    // null every time a collected value like roll changes, and the preview never blurs.+    val activeSettingState = remember { mutableStateOf<CameraSetting?>(null) }+    val maskBitmapState = remember { mutableStateOf<Bitmap?>(null) }+    val deviceRotationState = remember { mutableIntStateOf(0) }++    return remember(+        cameraMode, lensFacing, selectedLens, availableLenses, hasFlashUnit, flashMode, torchEnabled, videoCodec, audioCodec, audioInputSource, mirrorFront, isRecording, recordingDuration,+        timerCountdown, qrResult, aspectRatio, zoomRatio, timerDuration,+        isCapturing, burstActive, burstCount, focusLocked, recordingPaused, micMuted,+        videoSnapshotSupported, lastCaptureUri, gridEnabled, levelEnabled, roll,+        blurStrength, exposureComp, warmth, shadows, exposureTimeIndex, manualIsoIndex,+        isoStops, longExposureProgress, longExposureRemaining, lowLightDetected,+        nightModeActive, extensionStrength, sloMoSupported, highSpeedActive,+        photoSessionActive, analysisStreamActive, nightExtAvailable, surfaceRequest,+        camera2PreviewEnabled, camera2FallbackBindKey, camera2NightSessionActive,+        camera2NightEnabled, camera2NightFallbackBindKey,+        sessionBindFailed, sessionBindRetry,+        availableZoomLevels, galleryBitmap, panoSweeping, panoStitching, panoDots,+        panoCurrentAngle, panoDirection, panoPitch,+    ) {+        CameraScreenState(+            cameraMode = cameraMode,+            lensFacing = lensFacing,+            selectedLens = selectedLens,+            availableLenses = availableLenses,+            hasFlashUnit = hasFlashUnit,+            flashMode = flashMode,+            torchEnabled = torchEnabled,+            videoCodec = videoCodec,+            audioCodec = audioCodec,+            audioInputSource = audioInputSource,+            isRecording = isRecording,+            recordingDuration = recordingDuration,+            timerCountdown = timerCountdown,+            qrResult = qrResult,+            aspectRatio = aspectRatio,+            zoomRatio = zoomRatio,+            mirrorFront = mirrorFront,+            timerDuration = timerDuration,+            isCapturing = isCapturing,+            burstActive = burstActive,+            burstCount = burstCount,+            focusLocked = focusLocked,+            recordingPaused = recordingPaused,+            micMuted = micMuted,+            videoSnapshotSupported = videoSnapshotSupported,+            lastCaptureUri = lastCaptureUri,+            gridEnabled = gridEnabled,+            levelEnabled = levelEnabled,+            roll = roll,+            blurStrength = blurStrength,+            exposureComp = exposureComp,+            warmth = warmth,+            shadows = shadows,+            exposureTimeIndex = exposureTimeIndex,+            manualIsoIndex = manualIsoIndex,+            isoStops = isoStops,+            longExposureProgress = longExposureProgress,+            longExposureRemaining = longExposureRemaining,+            lowLightDetected = lowLightDetected,+            nightModeActive = nightModeActive,+            extensionStrength = extensionStrength,+            sloMoSupported = sloMoSupported,+            highSpeedActive = highSpeedActive,+            photoSessionActive = photoSessionActive,+            analysisStreamActive = analysisStreamActive,+            nightExtAvailable = nightExtAvailable,+            surfaceRequest = surfaceRequest,+            availableZoomLevels = availableZoomLevels,+            galleryBitmap = galleryBitmap,+            panoSweeping = panoSweeping,+            panoStitching = panoStitching,+            panoDots = panoDots,+            panoCurrentAngle = panoCurrentAngle,+            panoDirection = panoDirection,+            panoPitch = panoPitch,+            activeSettingState = activeSettingState,+            maskBitmapState = maskBitmapState,+            deviceRotationState = deviceRotationState,+            sessionBindFailed = sessionBindFailed,+            sessionBindRetry = sessionBindRetry,+            camera2PreviewEnabled = camera2PreviewEnabled,+            camera2FallbackBindKey = camera2FallbackBindKey,+            camera2NightSessionActive = camera2NightSessionActive,+            camera2NightEnabled = camera2NightEnabled,+            camera2NightFallbackBindKey = camera2NightFallbackBindKey,+        )+    }+}