Skip to content

Commit 429129b

Browse files
committed
Integrate BackportedFixManager to filter out JPEG_R format support
On some devices, there is color tone issue when capturing JPEG_R images. BackportedFixManager can help to check whether the issue has been fixed or not. Integrate it to make ImageCapture can correctly filter out the OUTPUT_FORMAT_JPEG_ULTRA_HDR format support. Androidx's minimal supported API level has been updated as 23. The code in StreamConfigurationMapCompatApi23Impl is integrated into StreamConfigurationMapCompatBaseImpl to remove the useless code. Bug: 436119518 Test: BackportedFixPixelJpegRSupportedQuirkTest Change-Id: Icce26b3bad4fdbdc55137bb0f6f075107955bcc4
1 parent 9f899b3 commit 429129b

22 files changed

Lines changed: 637 additions & 149 deletions

File tree

‎camera/camera-camera2-pipe-integration/build.gradle‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ dependencies {
4747
implementation('androidx.concurrent:concurrent-futures-ktx:1.1.0')
4848
implementation("androidx.annotation:annotation-experimental:1.4.1")
4949
implementation("androidx.arch.core:core-common:2.1.0")
50+
implementation("androidx.core:core-backported-fixes:1.0.0")
5051
implementation(libs.jspecify)
5152

5253
ksp(libs.daggerCompiler)

‎camera/camera-camera2-pipe-integration/src/androidTest/java/androidx/camera/camera2/pipe/integration/compat/StreamConfigurationMapCompatTest.kt‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@
1717
package androidx.camera.camera2.pipe.integration.compat
1818

1919
import android.content.Context
20+
import android.graphics.ImageFormat
2021
import android.hardware.camera2.CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP
2122
import android.hardware.camera2.params.StreamConfigurationMap
2223
import androidx.camera.camera2.pipe.CameraId
2324
import androidx.camera.camera2.pipe.CameraPipe
2425
import androidx.camera.camera2.pipe.integration.CameraPipeConfig
26+
import androidx.camera.camera2.pipe.integration.compat.quirk.DeviceQuirks
27+
import androidx.camera.camera2.pipe.integration.compat.quirk.PixelJpegRSupportedQuirk
2528
import androidx.camera.camera2.pipe.integration.compat.workaround.OutputSizesCorrector
2629
import androidx.camera.core.CameraSelector
2730
import androidx.camera.testing.impl.CameraUtil
@@ -71,6 +74,13 @@ class StreamConfigurationMapCompatTest {
7174
@Test
7275
fun canGetOutputFormats() {
7376
val formats = streamConfigurationMapCompat.getOutputFormats()!!.toList()
74-
assertThat(formats).containsExactlyElementsIn(streamConfigurationMap.outputFormats.toList())
77+
var expectedFormats = streamConfigurationMap.outputFormats.toList()
78+
79+
val quirk = DeviceQuirks[PixelJpegRSupportedQuirk::class.java]
80+
if (quirk != null) {
81+
expectedFormats = expectedFormats.filter { it != ImageFormat.JPEG_R }
82+
}
83+
84+
assertThat(formats).containsExactlyElementsIn(expectedFormats)
7585
}
7686
}

‎camera/camera-camera2-pipe-integration/src/main/java/androidx/camera/camera2/pipe/integration/compat/StreamConfigurationMapCompat.kt‎

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,12 @@ constructor(map: StreamConfigurationMap?, private val outputSizesCorrector: Outp
4242
private val cachedFormatOutputSizes = mutableMapOf<Int, Array<Size>>()
4343
private val cachedFormatHighResolutionOutputSizes = mutableMapOf<Int, Array<Size>?>()
4444
private val cachedClassOutputSizes = mutableMapOf<Class<*>, Array<Size>>()
45-
private var impl: StreamConfigurationMapCompatImpl
46-
47-
init {
48-
impl =
49-
if (Build.VERSION.SDK_INT >= 23) {
50-
StreamConfigurationMapCompatApi23Impl(map)
51-
} else {
52-
StreamConfigurationMapCompatBaseImpl(map)
53-
}
54-
}
45+
private var impl: StreamConfigurationMapCompatImpl =
46+
if (Build.VERSION.SDK_INT >= 34) {
47+
StreamConfigurationMapCompatApi34Impl(map)
48+
} else {
49+
StreamConfigurationMapCompatBaseImpl(map)
50+
}
5551

5652
/**
5753
* Get the image format output formats in this stream configuration.

‎camera/camera-camera2-pipe-integration/src/main/java/androidx/camera/camera2/pipe/integration/compat/StreamConfigurationMapCompatApi23Impl.kt‎

Lines changed: 0 additions & 37 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright 2026 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package androidx.camera.camera2.pipe.integration.compat
18+
19+
import android.graphics.ImageFormat
20+
import android.hardware.camera2.params.StreamConfigurationMap
21+
import android.util.Size
22+
import androidx.annotation.RequiresApi
23+
import androidx.camera.camera2.pipe.integration.compat.quirk.DeviceQuirks
24+
import androidx.camera.camera2.pipe.integration.compat.quirk.PixelJpegRSupportedQuirk
25+
26+
@RequiresApi(34)
27+
internal class StreamConfigurationMapCompatApi34Impl(map: StreamConfigurationMap?) :
28+
StreamConfigurationMapCompatBaseImpl(map) {
29+
30+
// Use `get()` to avoid storing a Boolean
31+
private val hasJpegRQuirk: Boolean
32+
get() = DeviceQuirks[PixelJpegRSupportedQuirk::class.java] != null
33+
34+
override fun getOutputFormats(): Array<Int>? {
35+
val formats = super.getOutputFormats()
36+
37+
if (hasJpegRQuirk) {
38+
return formats?.filter { it != ImageFormat.JPEG_R }?.toTypedArray()
39+
}
40+
41+
return formats
42+
}
43+
44+
override fun getOutputSizes(format: Int): Array<Size>? {
45+
// b/436119518: Return null if the device has the color tone issue and the format is JPEG_R.
46+
if (format == ImageFormat.JPEG_R && hasJpegRQuirk) {
47+
return null
48+
}
49+
return super.getOutputSizes(format)
50+
}
51+
52+
override fun getHighResolutionOutputSizes(format: Int): Array<Size>? {
53+
// b/436119518: Return null if the device has the color tone issue and the format is JPEG_R.
54+
if (format == ImageFormat.JPEG_R && hasJpegRQuirk) {
55+
return null
56+
}
57+
return super.getHighResolutionOutputSizes(format)
58+
}
59+
60+
override fun getOutputMinFrameDuration(format: Int, size: Size): Long {
61+
// b/436119518: Return 0 if the device has the color tone issue and the format is JPEG_R.
62+
if (format == ImageFormat.JPEG_R && hasJpegRQuirk) {
63+
return 0
64+
}
65+
66+
return super.getOutputMinFrameDuration(format, size)
67+
}
68+
}

‎camera/camera-camera2-pipe-integration/src/main/java/androidx/camera/camera2/pipe/integration/compat/StreamConfigurationMapCompatBaseImpl.kt‎

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,10 @@
1616

1717
package androidx.camera.camera2.pipe.integration.compat
1818

19-
import android.graphics.SurfaceTexture
2019
import android.hardware.camera2.params.StreamConfigurationMap
2120
import android.util.Range
2221
import android.util.Size
2322
import androidx.camera.core.Logger
24-
import androidx.camera.core.impl.ImageFormatConstants
2523

2624
private const val TAG = "StreamConfigurationMapCompatBaseImpl"
2725

@@ -47,26 +45,15 @@ internal open class StreamConfigurationMapCompatBaseImpl(
4745
}
4846

4947
override fun getOutputSizes(format: Int): Array<Size>? {
50-
val sizes: Array<Size> =
51-
if (format == ImageFormatConstants.INTERNAL_DEFINED_IMAGE_FORMAT_PRIVATE) {
52-
// This is a little tricky that 0x22 that is internal defined in
53-
// StreamConfigurationMap.java to be equal to ImageFormat.PRIVATE that is public
54-
// after Android level 23 but not public in Android L. Use {@link SurfaceTexture}
55-
// or {@link MediaCodec} will finally mapped to 0x22 in StreamConfigurationMap to
56-
// retrieve the output sizes information.
57-
streamConfigurationMap?.getOutputSizes(SurfaceTexture::class.java) ?: emptyArray()
58-
} else {
59-
streamConfigurationMap?.getOutputSizes(format) ?: emptyArray()
60-
}
61-
return sizes
48+
return streamConfigurationMap?.getOutputSizes(format)
6249
}
6350

6451
override fun <T> getOutputSizes(klass: Class<T>): Array<Size>? {
6552
return streamConfigurationMap?.getOutputSizes(klass) ?: emptyArray()
6653
}
6754

6855
override fun getHighResolutionOutputSizes(format: Int): Array<Size>? {
69-
return null
56+
return streamConfigurationMap?.getHighResolutionOutputSizes(format)
7057
}
7158

7259
override fun getHighSpeedVideoFpsRanges(): Array<Range<Int>>? {
@@ -86,17 +73,7 @@ internal open class StreamConfigurationMapCompatBaseImpl(
8673
}
8774

8875
override fun getOutputMinFrameDuration(format: Int, size: Size): Long {
89-
return if (format == ImageFormatConstants.INTERNAL_DEFINED_IMAGE_FORMAT_PRIVATE) {
90-
// This is a little tricky that 0x22 that is internal defined in
91-
// StreamConfigurationMap.java to be equal to ImageFormat.PRIVATE that is public
92-
// after Android level 23 but not public in Android L. Use {@link SurfaceTexture}
93-
// or {@link MediaCodec} will finally mapped to 0x22 in StreamConfigurationMap to
94-
// retrieve the output sizes information.
95-
streamConfigurationMap?.getOutputMinFrameDuration(SurfaceTexture::class.java, size)
96-
?: 0L
97-
} else {
98-
streamConfigurationMap?.getOutputMinFrameDuration(format, size) ?: 0L
99-
}
76+
return streamConfigurationMap?.getOutputMinFrameDuration(format, size) ?: 0L
10077
}
10178

10279
override fun unwrap(): StreamConfigurationMap? {

‎camera/camera-camera2-pipe-integration/src/main/java/androidx/camera/camera2/pipe/integration/compat/quirk/DeviceQuirksLoader.kt‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ public object DeviceQuirksLoader {
3030
val quirks: MutableList<Quirk> = mutableListOf()
3131

3232
// Load all device specific quirks, preferably in lexicographical order
33+
if (
34+
quirkSettings.shouldEnableQuirk(
35+
PixelJpegRSupportedQuirk::class.java,
36+
PixelJpegRSupportedQuirk.isEnabled(),
37+
)
38+
) {
39+
quirks.add(PixelJpegRSupportedQuirk())
40+
}
3341
if (
3442
quirkSettings.shouldEnableQuirk(
3543
CloseCameraDeviceOnCameraGraphCloseQuirk::class.java,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright 2026 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package androidx.camera.camera2.pipe.integration.compat.quirk
17+
18+
import android.annotation.SuppressLint
19+
import android.os.Build
20+
import androidx.camera.core.internal.compat.quirk.BackportedFixQuirk
21+
import androidx.core.backported.fixes.KnownIssue
22+
import androidx.core.backported.fixes.KnownIssues
23+
24+
/**
25+
* QuirkSummary
26+
* - Bug Id: b/436119518
27+
* - Description: Quirk to check JPEG_R support on Pixel devices. Abnormal color tone when capturing
28+
* JPEG-R images on some Pixel devices.
29+
* - Device(s): Pixel devices
30+
*/
31+
@SuppressLint("CameraXQuirksClassDetector")
32+
public class PixelJpegRSupportedQuirk : BackportedFixQuirk() {
33+
34+
override fun getKnownIssue(): KnownIssue {
35+
return KnownIssues.KI_398591036
36+
}
37+
38+
public companion object {
39+
@JvmStatic
40+
public fun isEnabled(): Boolean {
41+
return Build.VERSION.SDK_INT >= 34 && PixelJpegRSupportedQuirk().hasIssue()
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)