camera: Aperture-style zoom-factor lens pills, fix GS6 Pro duplicates (#876)
- Commit
e5bb1aa617d25a0296598f152bd8505c86c40ed8- Author
- Vayun Mathur <[email protected]>
- When
- 2026-10-31 18:52 UTC (1 month ago)
- Parents
a98e4b3
On the Murena GS6 Pro (0.4x/0.5x/1x back triple) the lens picker showed wrong, duplicated labels: both ultrawide lenses fell into the same coarse LensType bucket, so the pills read UW/UW (or UW plus a millimeter readout like UW 13mm that overflowed the fixed 36dp chip), never the .4/.5/1x the stock Aperture app shows. Root cause: LensBar derived its pill text from LensType buckets plus a 35mm-equivalent millimeter suffix (ui/LensBar.kt lensPillLabel), while the platform layer could surface the same physical lens twice (logical + physical camera IDs) and a logical multi-camera whose wide camera already covers the UW stop via zoom-out had no dedup path, so near-spaced lenses collided on one bucket and duplicates rendered as separate pills. Fix: compute each lens's zoom factor relative to its facing's main (1x) lens - 35mm-equivalent ratio first, then the CameraX intrinsic zoom ratio, then the nominal raw-focal ratio - and format it Aperture/Pixel style (.4/.5 under 1x, 1x/2x/2.5x at and above, one decimal with trailing zeros trimmed). Labels live in the new pure domain/LensLabels.kt: labelsFor adds a two-decimal fallback (.50, 2.03x) for the later lens whenever two factors would round to the same text, sortedByFactor orders pills ascending, dedupe collapses repeat enumerations of one physical lens, and dropCoveredUltrawides drops each UW stop the wide logical camera already reaches via zoom-out (partial coverage keeps the genuinely wider lens). LensBar pairs each lens with its label, sorts ascending, and steps 5-glyph precise labels down to 11sp so nothing clips the 36dp chip. PhysicalLens gains an optional intrinsicZoomRatio fed from CameraInfo.getIntrinsicZoomRatio; LensSelectionLogic.displayLabel is kept for non-picker readouts. User-visible effect: the picker now reads .4/.5/1x on the GS6 Pro (and .5/1x/2x/5x on Pixel-like phones), with no duplicated pills and no truncated text. Verification: :camera:compileDevKotlin and :camera:testDevUnitTest pass (LensLabelsTest 10 tests, LensSelectionLogicTest 8 tests, covering the GS6 Pro triple, Pixel-like families, eq/intrinsic/ nominal priority, near-collisions, UW coverage, dedupe, and sort order); :camera:lint passes and detekt reports no findings in the touched files (remaining module findings are pre-existing backlog). Needs on-device testing on a GS6 Pro and a Pixel-like phone to confirm the pills match the stock camera app.
Diff
camera/src/main/java/com/vayunmathur/camera/domain/LensLabels.kt
diff --git a/camera/src/main/java/com/vayunmathur/camera/domain/LensLabels.kt b/camera/src/main/java/com/vayunmathur/camera/domain/LensLabels.ktnew file mode 100644index 0000000000..e974c30c9c--- /dev/null+++ b/camera/src/main/java/com/vayunmathur/camera/domain/LensLabels.kt@@ -0,0 +1,188 @@+package com.vayunmathur.camera.domain++import kotlin.math.abs+import kotlin.math.roundToInt++/**+ * Aperture/Pixel-style zoom-factor labels for the physical-lens picker.+ *+ * Previously pills were derived from coarse [LensType] buckets plus a+ * 35mm-equivalent millimeter readout ("UW", "UW · 13mm"): on phones whose+ * back lenses sit close together — e.g. the Murena GS6 Pro's 0.4x/0.5x/1x+ * triple — near-spaced lenses collapsed into one bucket, so pills duplicated+ * ("UW", "UW") while the "short · mm" text overflowed the fixed 36dp chips.+ * These helpers instead compute each lens's zoom factor relative to its+ * facing's main (1x) lens and format it like Aperture/Pixel (".4", ".5",+ * "1x", "2x").+ *+ * Pure JVM (no Android/CameraX dependency); the platform layer in+ * `platform/LensSelector.kt` feeds the raw characteristics in.+ */+object LensLabels {++ /**+ * 35mm-equivalent zoom ratio of one lens against the 1x reference, or+ * null when either value is missing or unusable (so the caller falls+ * through to the intrinsic / nominal ratios).+ */+ private fun eqZoomRatio(lensEq35Mm: Float?, referenceEq35Mm: Float?): Float? {+ if (lensEq35Mm == null || referenceEq35Mm == null) return null+ if (lensEq35Mm <= 0f || referenceEq35Mm <= 0f) return null+ return lensEq35Mm / referenceEq35Mm+ }++ /**+ * Zoom factor of a lens relative to its facing's main (1x) lens.+ *+ * Prefers the 35mm-equivalent ratio (physical optics: focal length scaled+ * by each sensor's own diagonal, so lenses on different-sized sensors+ * compare correctly where raw focal-length ratios do not), then the+ * CameraX intrinsic zoom ratio, then the nominal raw-focal ratio. Falls+ * back to 1f only when every source is missing or non-positive.+ */+ fun zoomFactor(+ lensEq35Mm: Float?,+ referenceEq35Mm: Float?,+ intrinsicRatio: Float?,+ nominalRatio: Float,+ ): Float {+ val optical = eqZoomRatio(lensEq35Mm, referenceEq35Mm)+ if (optical != null) return optical+ if (intrinsicRatio != null && intrinsicRatio.isFinite() && intrinsicRatio > 0f) {+ return intrinsicRatio+ }+ if (nominalRatio.isFinite() && nominalRatio > 0f) {+ return nominalRatio+ }+ return 1f+ }++ /**+ * 35mm-equivalent focal length of the family's 1x reference (the WIDE+ * back lens, or the FRONT lens up front); null when the HAL did not+ * report a usable value, in which case every factor falls back to the+ * intrinsic/nominal ratios.+ */+ fun referenceEqMm(family: List<PhysicalLens>): Float? =+ family.firstOrNull { it.lensType == LensType.WIDE || it.lensType == LensType.FRONT }+ ?.focalLengthMm35Eq+ ?.takeIf { it.isFinite() && it > 0f }++ /**+ * Zoom factor per lens of one facing family, in input order. Handles+ * mixed-facing input by anchoring each lens to its own facing's+ * reference (front families resolve against their FRONT lens).+ */+ fun factorsFor(family: List<PhysicalLens>): List<Float> {+ val referenceByFacing = family.map { it.facing }.toSet()+ .associateWith { facing -> referenceEqMm(family.filter { it.facing == facing }) }+ return family.map {+ zoomFactor(it.focalLengthMm35Eq, referenceByFacing[it.facing], it.intrinsicZoomRatio, it.nominalZoomRatio)+ }+ }++ /**+ * One-decimal zoom label: ".4", ".5" under 1x, "1x", "2x", "2.5x" at and+ * above. Glyphs deliberately match the ZoomBar's `formatZoomLabel` so the+ * two pill rows read consistently.+ */+ fun formatZoom(ratio: Float): String {+ if (ratio < 1f) return ".${(ratio * 10f).roundToInt()}"+ val tenth = (ratio * 10f).roundToInt() / 10f+ return if (abs(tenth - tenth.roundToInt()) < 0.05f) "${tenth.roundToInt()}x"+ else "%.1fx".format(tenth)+ }++ /**+ * Extra-precision fallback for lenses that would otherwise share a label+ * (fixed two decimals: ".43", ".50", "2.03x"). Only distinct-looking+ * output is guaranteed when the factors actually differ at this+ * precision; genuinely identical factors (e.g. a mono sensor sharing the+ * wide optics) keep near-identical labels, truthfully. Factors at/above+ * 10x keep the short one-decimal form — a second decimal there would+ * overflow the fixed 36dp chip, and collisions at that range are+ * implausible in practice.+ */+ fun formatZoomPrecise(ratio: Float): String {+ if (ratio < 1f) return ".%02d".format((ratio * 100f).roundToInt().coerceIn(0, 99))+ if (ratio >= 10f) return formatZoom(ratio)+ return "%.2fx".format((ratio * 100f).roundToInt() / 100f)+ }++ /**+ * Zoom-factor label per lens of one facing family, in input order. The+ * first lens at each rounded value keeps the short label; later lenses+ * that would round to the same text get [formatZoomPrecise] instead, so+ * two pills never read identically unless their factors truly match.+ */+ fun labelsFor(family: List<PhysicalLens>): List<String> {+ if (family.isEmpty()) return emptyList()+ val factors = factorsFor(family)+ val labels = factors.map(::formatZoom).toMutableList()+ labels.indices.groupBy { labels[it] }.values.forEach { colliding ->+ colliding.drop(1).forEach { index -> labels[index] = formatZoomPrecise(factors[index]) }+ }+ return labels+ }++ /**+ * Picker order for one facing family: ascending zoom factor (".4", ".5",+ * "1x", …) like Aperture, regardless of enumeration order. Stable, so+ * equal-factor lenses keep their relative order.+ */+ fun sortedByFactor(family: List<PhysicalLens>): List<PhysicalLens> {+ if (family.size < 2) return family+ val factors = factorsFor(family)+ return family.indices.sortedBy { factors[it] }.map { family[it] }+ }++ /**+ * Whether an ultra-wide stop is already reachable by zooming out on the+ * main lens (logical multi-camera): when the wide logical camera reports+ * a minimum zoom ratio at or below the UW factor, a separate UW pill+ * would duplicate it, so the platform layer drops the UW entry (the zoom+ * bar's sub-1x floor already covers that stop).+ */+ fun isUltrawideCovered(factor: Float, wideMinZoom: Float?): Boolean {+ if (wideMinZoom == null || !wideMinZoom.isFinite()) return false+ return wideMinZoom <= factor + ULTRAWIDE_COVER_TOLERANCE+ }++ /**+ * Drops every [LensType.ULTRA_WIDE] entry whose stop the main lens+ * already serves through its zoom range (logical multi-camera): when the+ * wide logical camera reports a minimum zoom ratio at or below a UW zoom+ * factor, that UW pill would duplicate the zoom bar's sub-1x range, so+ * the platform layer drops it. Each stop is judged on its own factor, so+ * a partially covered set (e.g. the GS6 Pro's 0.4x + 0.5x against a 0.45x+ * floor) keeps its genuinely wider lens. An unknown floor (null/NaN)+ * drops nothing.+ */+ fun dropCoveredUltrawides(family: List<PhysicalLens>, wideMinZoom: Float?): List<PhysicalLens> {+ val referenceEq = referenceEqMm(family)+ return family.filterNot { lens ->+ lens.lensType == LensType.ULTRA_WIDE && isUltrawideCovered(+ zoomFactor(+ lens.focalLengthMm35Eq,+ referenceEq,+ lens.intrinsicZoomRatio,+ lens.nominalZoomRatio,+ ),+ wideMinZoom,+ )+ }+ }++ /**+ * Drops duplicate enumerations of one physical lens: same logical camera+ * ID twice, or identical characteristics (facing, type, 35mm-eq,+ * nominal ratio) surfacing under two IDs. Order-preserving.+ */+ fun dedupe(lenses: List<PhysicalLens>): List<PhysicalLens> {+ return lenses.distinctBy { it.logicalCameraId }+ .distinctBy { "${it.facing}/${it.lensType}/${it.focalLengthMm35Eq}/${it.nominalZoomRatio}" }+ }+}++/** Slack for float noise when comparing a UW factor against the wide zoom floor. */+private const val ULTRAWIDE_COVER_TOLERANCE = 0.02f
camera/src/main/java/com/vayunmathur/camera/domain/LensModel.kt
diff --git a/camera/src/main/java/com/vayunmathur/camera/domain/LensModel.kt b/camera/src/main/java/com/vayunmathur/camera/domain/LensModel.ktindex c8b1dfbd63..cd2a27e73b 100644--- a/camera/src/main/java/com/vayunmathur/camera/domain/LensModel.kt+++ b/camera/src/main/java/com/vayunmathur/camera/domain/LensModel.kt@@ -29,9 +29,13 @@ enum class LensType { * @param logicalCameraId the Camera2 logical camera ID backing this lens; used * by the platform selector filter to pin a bind to this module. * @param focalLengthMm35Eq 35mm-equivalent focal length when the HAL reports- * it; null when unavailable (label falls back to the nominal zoom ratio).+ * it; null when unavailable (the label math falls back to the intrinsic /+ * nominal zoom ratios, see `domain/LensLabels.kt`). * @param nominalZoomRatio zoom ratio of this lens relative to the wide (1x) * lens of the same facing, e.g. ~0.5 for UW, 1 for wide, 3+ for tele.+ * @param intrinsicZoomRatio `CameraInfo.getIntrinsicZoomRatio()` when the+ * CameraX implementation knows it (logical multi-camera); null /+ * `INTRINSIC_ZOOM_RATIO_UNKNOWN` otherwise. Refines the label math. * @param fallbackPriority lower wins when falling back within the same * facing (wide/front default = 0). * @param labelKey stable key for the display label ("ultrawide", "wide",@@ -43,6 +47,7 @@ data class PhysicalLens( val facing: LensFacing, val focalLengthMm35Eq: Float?, val nominalZoomRatio: Float,+ val intrinsicZoomRatio: Float? = null, val fallbackPriority: Int, val labelKey: String, )
camera/src/main/java/com/vayunmathur/camera/domain/LensSelectionLogic.kt
diff --git a/camera/src/main/java/com/vayunmathur/camera/domain/LensSelectionLogic.kt b/camera/src/main/java/com/vayunmathur/camera/domain/LensSelectionLogic.ktindex 7a87cb4e0f..7419ba42d3 100644--- a/camera/src/main/java/com/vayunmathur/camera/domain/LensSelectionLogic.kt+++ b/camera/src/main/java/com/vayunmathur/camera/domain/LensSelectionLogic.kt@@ -47,7 +47,9 @@ object LensSelectionLogic { /** * Display label for a lens: 35mm-equivalent focal length ("24mm") when- * known, else the nominal zoom ratio ("0.5x"/"1x"/"3x").+ * known, else the nominal zoom ratio ("0.5x"/"1x"/"3x"). Prefer+ * [LensLabels.labelsFor] for picker pills (zoom-factor style); this stays+ * for non-picker readouts and backward-compatible tests. */ fun displayLabel(lens: PhysicalLens): String { val mm = lens.focalLengthMm35Eq
camera/src/main/java/com/vayunmathur/camera/platform/LensSelector.kt
diff --git a/camera/src/main/java/com/vayunmathur/camera/platform/LensSelector.kt b/camera/src/main/java/com/vayunmathur/camera/platform/LensSelector.ktindex 19a2248696..b2565b2c09 100644--- a/camera/src/main/java/com/vayunmathur/camera/platform/LensSelector.kt+++ b/camera/src/main/java/com/vayunmathur/camera/platform/LensSelector.kt@@ -8,6 +8,7 @@ import androidx.camera.core.Camera import androidx.camera.core.CameraSelector import androidx.camera.lifecycle.ProcessCameraProvider import com.vayunmathur.camera.domain.LensFacing+import com.vayunmathur.camera.domain.LensLabels import com.vayunmathur.camera.domain.LensSelectionLogic import com.vayunmathur.camera.domain.LensType import com.vayunmathur.camera.domain.PhysicalLens@@ -42,7 +43,13 @@ fun Int.toLensFacing(): LensFacing? = when (this) { fun enumerateLenses(provider: ProcessCameraProvider): List<PhysicalLens> { val raws = provider.availableCameraInfos.mapNotNull { info -> readRawLens(info) } - return LensFacing.entries.flatMap { facing -> buildFamily(facing, raws) }+ // Logical multi-camera (e.g. a UW stop reachable via the wide camera's+ // zoom range) plus same-physical-lens duplicates would each render an+ // extra identical pill — `buildFamily` handles the former per facing,+ // and the dedupe collapses the latter (issue #876).+ return LensLabels.dedupe(+ LensFacing.entries.flatMap { facing -> buildFamily(facing, raws) }+ ) } /** Full-frame diagonal (mm) of 35mm film; wide-reference eq focal length + family ratios. */@@ -88,7 +95,14 @@ private fun readRawLensOrThrow(info: androidx.camera.core.CameraInfo): RawLens? val mono = cam2.getCameraCharacteristic( CameraCharacteristics.SENSOR_INFO_COLOR_FILTER_ARRANGEMENT ) == CameraMetadata.SENSOR_INFO_COLOR_FILTER_ARRANGEMENT_MONO- return RawLens(cam2.getCameraId(), facing, focal, eq35, mono)+ // Logical multi-camera reach: the UW stop served through the wide logical+ // camera's zoom range (intrinsic ratio < 1), so the picker can skip a+ // duplicate UW pill. Unknown on most HALs — the eq-35mm ratio stays primary.+ val intrinsic = info.intrinsicZoomRatio.takeUnless {+ it == androidx.camera.core.CameraInfo.INTRINSIC_ZOOM_RATIO_UNKNOWN+ }+ val zoomFloor = info.zoomState.value?.minZoomRatio+ return RawLens(cam2.getCameraId(), facing, focal, eq35, mono, intrinsic, zoomFloor) } private data class RawLens(@@ -97,6 +111,8 @@ private data class RawLens( val focalMm: Float, val eq35Mm: Float?, val mono: Boolean,+ val intrinsicZoomRatio: Float?,+ val minZoomRatio: Float?, ) /** Classifies one facing family into [PhysicalLens] entries with fallback priorities. */@@ -110,7 +126,15 @@ private fun buildFamily(facing: LensFacing, raws: List<RawLens>): List<PhysicalL } ?: nonMono.getOrNull(nonMono.size / 2) ?: family.first()- return family.map { raw -> classifyLens(raw, reference, facing) }+ val classified = family.map { raw -> classifyLens(raw, reference, facing) }+ // Logical multi-camera dedup: when the wide logical camera already+ // reaches a UW stop via zoom-out (min zoom at/below its factor),+ // a separate UW pill would duplicate the zoom bar's sub-1x range —+ // drop it (issue #876).+ val wideFloor = classified.firstOrNull {+ it.lensType == LensType.WIDE || it.lensType == LensType.FRONT+ }?.let { ref -> family.firstOrNull { it.id == ref.logicalCameraId }?.minZoomRatio }+ return LensLabels.dropCoveredUltrawides(classified, wideFloor) } /** Classifies one raw lens against the family reference into a [PhysicalLens]. */@@ -122,6 +146,7 @@ private fun classifyLens(raw: RawLens, reference: RawLens, facing: LensFacing): facing = facing, focalLengthMm35Eq = raw.eq35Mm, nominalZoomRatio = raw.focalMm / reference.focalMm,+ intrinsicZoomRatio = raw.intrinsicZoomRatio, fallbackPriority = priorityOf(type), labelKey = labelOf(type), )@@ -249,7 +274,10 @@ fun CameraViewModel.bindWithFallback( first = false val camera = bind(lensSelector(facingInt, candidate)) if (candidate != requested) {- Log.status("LensSelector", "Fell back to lens=${candidate?.labelKey} (requested=${requested?.labelKey})")+ Log.status(+ "LensSelector",+ "Fell back to lens=${candidate?.labelKey} (requested=${requested?.labelKey})",+ ) } return candidate to camera } catch (e: IllegalStateException) {
camera/src/main/java/com/vayunmathur/camera/ui/LensBar.kt
diff --git a/camera/src/main/java/com/vayunmathur/camera/ui/LensBar.kt b/camera/src/main/java/com/vayunmathur/camera/ui/LensBar.ktindex db92c28abd..0cbbd570aa 100644--- a/camera/src/main/java/com/vayunmathur/camera/ui/LensBar.kt+++ b/camera/src/main/java/com/vayunmathur/camera/ui/LensBar.kt@@ -10,6 +10,7 @@ import androidx.compose.foundation.layout.size import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.runtime.Composable+import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip@@ -21,15 +22,17 @@ import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import com.vayunmathur.camera.R-import com.vayunmathur.camera.domain.LensSelectionLogic+import com.vayunmathur.camera.domain.LensLabels import com.vayunmathur.camera.domain.PhysicalLens import com.vayunmathur.library.ui.Text /**- * Physical-lens picker: one pill per enumerated lens of the current facing- * (UW / wide / tele / mono), cloned from [ZoomBar] (row container, 36dp- * [selectedPill], 13sp labels). Hidden when fewer than two lenses are- * available. Stateless: the caller passes the family plus the selection.+ * Physical-lens picker: one pill per enumerated lens of the current facing,+ * labeled Aperture-style (".4", ".5", "1x", "2x"). Pills are fixed 36dp+ * circles with 13sp labels (mirroring [ZoomBar]), so labels stay short —+ * never the old "UW · 13mm" compound that truncated in the chip.+ * Hidden when fewer than two lenses are available. Stateless: the caller+ * passes the family plus the selection. */ @Composable fun LensBar(@@ -39,6 +42,13 @@ fun LensBar( modifier: Modifier = Modifier, ) { if (lenses.size < 2) return+ // Pair each lens with its zoom-factor label, then sort ascending (".4",+ // ".5", "1x", …) like Aperture regardless of enumeration order. Labels+ // are positional — sorted once so every pill matches its lens.+ val ordered = remember(lenses) {+ val sorted = LensLabels.sortedByFactor(LensLabels.dedupe(lenses))+ sorted.zip(LensLabels.labelsFor(sorted))+ } val pickerDescription = stringResource(R.string.lens_picker_description) Row( modifier = modifier@@ -48,7 +58,7 @@ fun LensBar( horizontalArrangement = Arrangement.spacedBy(2.dp), verticalAlignment = Alignment.CenterVertically, ) {- lenses.forEach { lens ->+ ordered.forEach { (lens, label) -> val isSelected = lens == selected Box( modifier = Modifier@@ -58,28 +68,17 @@ fun LensBar( .clickable { onSelect(lens) }, contentAlignment = Alignment.Center, ) {+ // Precise collision labels (".50", "2.03x") run to 5 glyphs:+ // step down to 11sp so they fit the fixed 36dp chip instead+ // of clipping (short labels stay at the 13sp ZoomBar size). Text(- lensPillLabel(lens),+ label, color = if (isSelected) Color.White else Color(0xFFBBBBBB),- fontSize = 13.sp,+ fontSize = if (label.length > 3) 11.sp else 13.sp, fontWeight = if (isSelected) FontWeight.Bold else FontWeight.Normal,+ maxLines = 1, ) } } } }--/** Pill text for one lens: localized short label plus the focal-length readout. */-@Composable-internal fun lensPillLabel(lens: PhysicalLens): String {- val short = when (lens.labelKey) {- "ultrawide" -> stringResource(R.string.lens_ultrawide)- "tele" -> stringResource(R.string.lens_tele)- "mono" -> stringResource(R.string.lens_mono)- "front" -> stringResource(R.string.lens_front)- else -> stringResource(R.string.lens_wide)- }- val focal = LensSelectionLogic.displayLabel(lens)- return if (focal == short || lens.labelKey == "wide" || lens.labelKey == "front") short- else "$short · $focal"-}
camera/src/test/java/com/vayunmathur/camera/domain/LensLabelsTest.kt
diff --git a/camera/src/test/java/com/vayunmathur/camera/domain/LensLabelsTest.kt b/camera/src/test/java/com/vayunmathur/camera/domain/LensLabelsTest.ktnew file mode 100644index 0000000000..bd964b3b5e--- /dev/null+++ b/camera/src/test/java/com/vayunmathur/camera/domain/LensLabelsTest.kt@@ -0,0 +1,171 @@+package com.vayunmathur.camera.domain++import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertFalse+import kotlin.test.assertTrue++/** Aperture-style zoom-factor labels ([LensLabels]): no Android/CameraX needed. */+class LensLabelsTest {++ private fun lens(+ id: String,+ type: LensType,+ facing: LensFacing = LensFacing.BACK,+ eq35Mm: Float? = null,+ ratio: Float = 1f,+ intrinsic: Float? = null,+ ) = PhysicalLens(+ logicalCameraId = id,+ lensType = type,+ facing = facing,+ focalLengthMm35Eq = eq35Mm,+ nominalZoomRatio = ratio,+ intrinsicZoomRatio = intrinsic,+ fallbackPriority = 0,+ labelKey = type.name.lowercase(),+ )++ // GS6 Pro back triple: nominal 0.4x/0.5x/1x lenses (13mm/16mm/27mm-eq).+ private fun gs6Back() = listOf(+ lens("0", LensType.ULTRA_WIDE, eq35Mm = 10.8f, ratio = 0.4f),+ lens("1", LensType.ULTRA_WIDE, eq35Mm = 13.5f, ratio = 0.5f),+ lens("2", LensType.WIDE, eq35Mm = 27f, ratio = 1f),+ )++ @Test+ fun gs6ProLabelsReadPointFourPointFiveOne() {+ assertEquals(listOf(".4", ".5", "1x"), LensLabels.labelsFor(gs6Back()))+ }++ @Test+ fun pixelLikeFamilyLabels() {+ // 13mm / 27mm / 55mm / 135mm-eq ≈ 0.5x / 1x / 2x / 5x.+ val family = listOf(+ lens("uw", LensType.ULTRA_WIDE, eq35Mm = 13.5f, ratio = 0.5f),+ lens("wide", LensType.WIDE, eq35Mm = 27f, ratio = 1f),+ lens("tele2", LensType.TELEPHOTO, eq35Mm = 55f, ratio = 2f),+ lens("tele5", LensType.TELEPHOTO, eq35Mm = 135f, ratio = 5f),+ )+ assertEquals(listOf(".5", "1x", "2x", "5x"), LensLabels.labelsFor(family))+ }++ @Test+ fun zoomFactorPrefersEqRatioThenIntrinsicThenNominal() {+ // Eq-35mm ratio wins even when the nominal ratio disagrees (different+ // sensor sizes make raw-focal ratios lie).+ assertEquals(0.5f, LensLabels.zoomFactor(13.5f, 27f, 0.6f, 0.6f))+ // No eq data: the intrinsic ratio (logical multi-camera) wins.+ assertEquals(0.45f, LensLabels.zoomFactor(null, null, 0.45f, 0.6f))+ // Neither: nominal raw-focal ratio.+ assertEquals(0.6f, LensLabels.zoomFactor(null, null, null, 0.6f))+ // Nothing usable: unity rather than a divide-by-zero.+ assertEquals(1f, LensLabels.zoomFactor(null, null, null, 0f))+ assertEquals(1f, LensLabels.zoomFactor(0f, 27f, null, 0f))+ }++ @Test+ fun formatRoundsLikeTheZoomBar() {+ assertEquals(".4", LensLabels.formatZoom(0.4f))+ assertEquals(".5", LensLabels.formatZoom(0.5f))+ assertEquals("1x", LensLabels.formatZoom(1f))+ assertEquals("2x", LensLabels.formatZoom(2f))+ assertEquals("1.5x", LensLabels.formatZoom(1.5f))+ assertEquals("2.5x", LensLabels.formatZoom(2.5f))+ assertEquals("5x", LensLabels.formatZoom(5.02f))+ assertEquals("2.03x", LensLabels.formatZoomPrecise(2.03f))+ assertEquals(".50", LensLabels.formatZoomPrecise(0.504f))+ // 10x+ keeps the short form so it still fits the 36dp chip.+ assertEquals("10x", LensLabels.formatZoomPrecise(10.02f))+ }++ @Test+ fun nearCollisionGainsPrecisionInsteadOfDuplicating() {+ // 13.4mm-eq and 13.6mm-eq against a 27mm-eq wide both round to ".5";+ // the second keeps extra precision instead of colliding.+ val family = listOf(+ lens("a", LensType.ULTRA_WIDE, eq35Mm = 13.4f, ratio = 0.496f),+ lens("b", LensType.ULTRA_WIDE, eq35Mm = 13.6f, ratio = 0.504f),+ lens("wide", LensType.WIDE, eq35Mm = 27f, ratio = 1f),+ )+ val labels = LensLabels.labelsFor(family)+ assertEquals(3, labels.size)+ assertEquals(labels.distinct().size, labels.size)+ // First at each rounded value keeps the short label.+ assertEquals(".5", labels[0])+ assertEquals(".50", labels[1])+ // Genuinely identical factors stay visually adjacent (".5"/".50")+ // rather than inventing a distinction that is not there.+ val twins = listOf(+ lens("a", LensType.ULTRA_WIDE, eq35Mm = 13.5f, ratio = 0.5f),+ lens("b", LensType.MONOCHROME, eq35Mm = 13.5f, ratio = 0.5f),+ lens("wide", LensType.WIDE, eq35Mm = 27f, ratio = 1f),+ )+ assertEquals(listOf(".5", ".50", "1x"), LensLabels.labelsFor(twins))+ }++ @Test+ fun ultrawideCoveredOnlyWhenWideZoomsOutThatFar() {+ assertTrue(LensLabels.isUltrawideCovered(0.5f, 0.5f))+ assertTrue(LensLabels.isUltrawideCovered(0.5f, 0.4f))+ assertFalse(LensLabels.isUltrawideCovered(0.5f, 0.55f))+ assertFalse(LensLabels.isUltrawideCovered(0.4f, 0.5f))+ assertFalse(LensLabels.isUltrawideCovered(0.5f, 1f))+ assertFalse(LensLabels.isUltrawideCovered(0.5f, null))+ assertFalse(LensLabels.isUltrawideCovered(0.5f, Float.NaN))+ }++ @Test+ fun dedupeCollapsesRepeatedPhysicalLens() {+ // Same logical ID twice.+ val twice = listOf(+ lens("0", LensType.WIDE, eq35Mm = 27f),+ lens("0", LensType.WIDE, eq35Mm = 27f),+ )+ assertEquals(1, LensLabels.dedupe(twice).size)+ // Same characteristics under two IDs (logical + physical alias).+ val aliased = listOf(+ lens("0", LensType.ULTRA_WIDE, eq35Mm = 13.5f, ratio = 0.5f),+ lens("2", LensType.ULTRA_WIDE, eq35Mm = 13.5f, ratio = 0.5f),+ lens("1", LensType.WIDE, eq35Mm = 27f),+ )+ assertEquals(listOf("0", "1"), LensLabels.dedupe(aliased).map { it.logicalCameraId })+ // Distinct lenses survive.+ assertEquals(3, LensLabels.dedupe(gs6Back()).size)+ }++ @Test+ fun sortedByFactorOrdersAscendingAndKeepsFrontAnchor() {+ // Deliberately scrambled enumeration order → Aperture order.+ val scrambled = listOf(gs6Back()[2], gs6Back()[0], gs6Back()[1])+ assertEquals(listOf(".4", ".5", "1x"), LensLabels.labelsFor(LensLabels.sortedByFactor(scrambled)))+ // Front lenses anchor to their own FRONT reference, not the back wide.+ val mixed = gs6Back() + lens("f", LensType.FRONT, facing = LensFacing.FRONT, eq35Mm = 25f)+ val factors = LensLabels.factorsFor(mixed)+ assertEquals(1f, factors[3])+ }++ @Test+ fun emptyFamilyLabelsEmpty() {+ assertEquals(emptyList(), LensLabels.labelsFor(emptyList()))+ }++ @Test+ fun dropCoveredUltrawidesJudgesEachStop() {+ // Logical multi-camera: wide floor 0.45 reaches the 0.5x stop but+ // not the genuinely wider 0.4x lens — the latter survives.+ val gs6 = gs6Back()+ assertEquals(+ listOf(gs6[0], gs6[2]),+ LensLabels.dropCoveredUltrawides(gs6, 0.45f),+ )+ // A floor at/above every UW stop (0.4 or lower) removes both.+ assertEquals(+ listOf(gs6[2]),+ LensLabels.dropCoveredUltrawides(gs6, 0.4f),+ )+ // An unknown floor drops nothing — the pills stay authoritative.+ assertEquals(gs6, LensLabels.dropCoveredUltrawides(gs6, null))+ assertEquals(gs6, LensLabels.dropCoveredUltrawides(gs6, Float.NaN))+ }+}
camera/src/test/java/com/vayunmathur/camera/domain/LensSelectionLogicTest.kt
diff --git a/camera/src/test/java/com/vayunmathur/camera/domain/LensSelectionLogicTest.kt b/camera/src/test/java/com/vayunmathur/camera/domain/LensSelectionLogicTest.ktindex e3bbd2b68d..66cd49cc66 100644--- a/camera/src/test/java/com/vayunmathur/camera/domain/LensSelectionLogicTest.kt+++ b/camera/src/test/java/com/vayunmathur/camera/domain/LensSelectionLogicTest.kt@@ -101,4 +101,16 @@ class LensSelectionLogicTest { assertEquals("1x", LensSelectionLogic.displayLabel(lens("wide", LensType.WIDE))) assertEquals(".5", LensSelectionLogic.displayLabel(lens("uw", LensType.ULTRA_WIDE, ratio = 0.5f))) }++ @Test+ fun gs6ProPickerLabelsReadPointFourPointFiveOne() {+ // Murena GS6 Pro back triple (issue #876): pills must read ".4",+ // ".5", "1x" — never duplicated "UW" buckets.+ val family = listOf(+ lens("0", LensType.ULTRA_WIDE, ratio = 0.4f).copy(focalLengthMm35Eq = 10.8f),+ lens("1", LensType.ULTRA_WIDE, ratio = 0.5f).copy(focalLengthMm35Eq = 13.5f),+ lens("2", LensType.WIDE).copy(focalLengthMm35Eq = 27f),+ )+ assertEquals(listOf(".4", ".5", "1x"), LensLabels.labelsFor(family))+ } }