Skip to content

Bugfix: Propagate dynamic range and image format diffs to CameraSystem - #574

Open
Kimblebee wants to merge 1 commit into
mainfrom
kim/propagate-dynamic-range-image-format
Open

Kimblebee wants to merge 1 commit into
mainfrom
kim/propagate-dynamic-range-image-format

Conversation

@Kimblebee

Copy link
Copy Markdown
Collaborator

TLDR:
🐛 Problem: Currently, when settings are updated from SettingsRepository, CameraAppSettings.applyDiffs propagates changed preferences to CameraSystem. It currently omits dynamicRange and imageFormat.
Solution: this PR includes dynamicRange and imageFormat in CameraAppSettings.applyDiffs tests.
note: HDR controls aren't currently included in JCA's dedicated settings screen.

Longer description:

  • ⭐ Adds diff propagation for dynamicRange and imageFormat in CameraAppSettings.applyDiffs.
  • Adds unit tests in CameraSystemTest verifying applyDiffs correctly updates CameraSystem on setting changes and skips unchanged settings.
  • Adds unit tests in PreviewViewModelTest confirming end-to-end propagation from SettingsRepository through applyDiffs to CameraSystem.
  • Adds parameterized on-device tests in CameraSystemApplyDiffsDeviceTest executing across all available lenses (BACK, FRONT), verifying live diff application and skipping gracefully when unsupported by hardware constraints.

When settings are updated from SettingsRepository, CameraAppSettings.applyDiffs
propagates changed preferences to CameraSystem, but previously omitted dynamicRange
and imageFormat.

This change:
- Adds diff propagation for dynamicRange and imageFormat in CameraAppSettings.applyDiffs.
- Adds unit tests in CameraSystemTest verifying applyDiffs correctly updates
  CameraSystem on setting changes and skips unchanged settings.
- Adds unit tests in PreviewViewModelTest confirming end-to-end propagation from
  SettingsRepository through applyDiffs to CameraSystem.
- Adds parameterized on-device tests in CameraSystemApplyDiffsDeviceTest executing
  across all available lenses (BACK, FRONT), verifying live diff application
  and skipping gracefully when unsupported by hardware constraints.

Test: ./gradlew :core📷testStableUnitTest :feature:preview:testStableUnitTest
Test: ./gradlew :core📷connectedStableDebugAndroidTest

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for propagating dynamicRange and imageFormat changes in CameraSystem.applyDiffs, accompanied by new unit and instrumented tests to verify the behavior. The review feedback suggests restricting the visibility of the new test classes to internal to align with the repository's style guide, and using distinctUntilChanged() on the settings flow in the instrumented tests to prevent potential flakiness.

*/
@LargeTest
@RunWith(Parameterized::class)
class CameraSystemApplyDiffsDeviceTest(private val lensFacing: LensFacing) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

According to the repository style guide, all new classes should use the most restrictive visibility modifier possible. Since this test class does not need to be publicly accessible, it should be declared as internal.

Suggested change
class CameraSystemApplyDiffsDeviceTest(private val lensFacing: LensFacing) {
internal class CameraSystemApplyDiffsDeviceTest(private val lensFacing: LensFacing) {
References
  1. Proper Visibility Modifiers: Ensure all new functions, properties, and classes use the most restrictive visibility modifier possible (e.g., private, internal) while still allowing necessary access. Avoid public visibility unless explicitly required for external API exposure. (link)

Comment on lines +129 to +132
val dynamicRangeCheck = cameraSystem.getCurrentSettings()
.filterNotNull()
.map { it.dynamicRange }
.produceIn(this)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To prevent potential flakiness and avoid buffering duplicate values in the channel (e.g., if other unrelated settings change and trigger emissions), it is recommended to use distinctUntilChanged() on the flow before producing the channel.

Suggested change
val dynamicRangeCheck = cameraSystem.getCurrentSettings()
.filterNotNull()
.map { it.dynamicRange }
.produceIn(this)
val dynamicRangeCheck = cameraSystem.getCurrentSettings()
.filterNotNull()
.map { it.dynamicRange }
.distinctUntilChanged()
.produceIn(this)

Comment on lines +190 to +193
val imageFormatCheck = cameraSystem.getCurrentSettings()
.filterNotNull()
.map { it.imageFormat }
.produceIn(this)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To prevent potential flakiness and avoid buffering duplicate values in the channel (e.g., if other unrelated settings change and trigger emissions), it is recommended to use distinctUntilChanged() on the flow before producing the channel.

Suggested change
val imageFormatCheck = cameraSystem.getCurrentSettings()
.filterNotNull()
.map { it.imageFormat }
.produceIn(this)
val imageFormatCheck = cameraSystem.getCurrentSettings()
.filterNotNull()
.map { it.imageFormat }
.distinctUntilChanged()
.produceIn(this)

* Unit tests for [CameraSystem] extension functions, specifically [CameraAppSettings.applyDiffs].
*/
@RunWith(JUnit4::class)
class CameraSystemTest {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

According to the repository style guide, all new classes should use the most restrictive visibility modifier possible. Since this test class does not need to be publicly accessible, it should be declared as internal.

Suggested change
class CameraSystemTest {
internal class CameraSystemTest {
References
  1. Proper Visibility Modifiers: Ensure all new functions, properties, and classes use the most restrictive visibility modifier possible (e.g., private, internal) while still allowing necessary access. Avoid public visibility unless explicitly required for external API exposure. (link)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant