# CameraCharacteristicsWrappers

Artifact: [androidx.camera:camera-common](https://developer.android.com/jetpack/androidx/releases/camera) [View Source](https://cs.android.com/search?q=file:androidx/camera/common/CameraCharacteristicsWrapper.kt+class:androidx.camera.common.CameraCharacteristicsWrappers) Added in [1.7.0-rc02](https://developer.android.com/jetpack/androidx/releases/camera#1.7.0-rc02)

*** ** * ** ***


```
public static class CameraCharacteristicsWrappers
```

<br />

*** ** * ** ***

Custom metadata keys for `https://developer.android.com/reference/androidx/camera/common/CameraCharacteristicsWrapper`.

## Summary

| ### Public fields |
|---|---|
| `static @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/common/CameraCharacteristicsWrappers` | `https://developer.android.com/reference/androidx/camera/common/CameraCharacteristicsWrappers#INSTANCE()` |

| ### Public methods |
|---|---|
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/common/ColorSpaceProfilesWrapper` | `https://developer.android.com/reference/androidx/camera/common/CameraCharacteristicsWrappers#(androidx.camera.common.CameraCharacteristicsMetadata).getAvailableColorSpaceProfiles()( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/common/CameraCharacteristicsMetadata receiver )` Returns the `https://developer.android.com/reference/androidx/camera/common/ColorSpaceProfilesWrapper` supported by the camera device. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/common/DynamicRangeProfilesWrapper` | `https://developer.android.com/reference/androidx/camera/common/CameraCharacteristicsWrappers#(androidx.camera.common.CameraCharacteristicsMetadata).getAvailableDynamicRangeProfiles()( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/common/CameraCharacteristicsMetadata receiver )` Returns the `https://developer.android.com/reference/androidx/camera/common/DynamicRangeProfilesWrapper` supported by the camera device. |
| `static final https://developer.android.com/reference/androidx/camera/common/StreamConfigurationMapWrapper` | `https://developer.android.com/reference/androidx/camera/common/CameraCharacteristicsWrappers#(androidx.camera.common.CameraCharacteristicsMetadata).getStreamConfigurationMap()( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/common/CameraCharacteristicsMetadata receiver )` Extension property to query `https://developer.android.com/reference/androidx/camera/common/StreamConfigurationMapWrapper` directly. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/common/CameraCharacteristicsWrapper` | `https://developer.android.com/reference/androidx/camera/common/CameraCharacteristicsWrappers#loadFrom(android.content.Context,androidx.camera.common.CameraId,kotlin.collections.Set)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html context, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/common/CameraId cameraId, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Set.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics.Key.html<@https://developer.android.com/reference/androidx/annotation/NonNull ?>> dynamicKeys )` Loads `https://developer.android.com/reference/androidx/camera/common/CameraCharacteristicsWrapper` for the given `https://developer.android.com/reference/androidx/camera/common/CameraCharacteristicsWrappers#loadFrom(android.content.Context,androidx.camera.common.CameraId,kotlin.collections.Set)` using `https://developer.android.com/reference/android/content/Context.html`. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/common/CameraCharacteristicsWrapper` | `https://developer.android.com/reference/androidx/camera/common/CameraCharacteristicsWrappers#loadFrom(android.hardware.camera2.CameraManager,androidx.camera.common.CameraId,kotlin.Boolean,kotlin.collections.Set)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/hardware/camera2/CameraManager.html cameraManager, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/common/CameraId cameraId, boolean isRestricted, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Set.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics.Key.html<@https://developer.android.com/reference/androidx/annotation/NonNull ?>> dynamicKeys )` Loads `https://developer.android.com/reference/androidx/camera/common/CameraCharacteristicsWrapper` for the given `https://developer.android.com/reference/androidx/camera/common/CameraCharacteristicsWrappers#loadFrom(android.hardware.camera2.CameraManager,androidx.camera.common.CameraId,kotlin.Boolean,kotlin.collections.Set)` using `https://developer.android.com/reference/android/hardware/camera2/CameraManager.html`. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/common/CameraCharacteristicsWrapper` | `https://developer.android.com/reference/androidx/camera/common/CameraCharacteristicsWrappers#wrap(androidx.camera.common.CameraId,android.hardware.camera2.CameraCharacteristics,kotlin.Boolean,kotlin.collections.Set)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/common/CameraId cameraId, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics.html characteristics, boolean isRestricted, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Set.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics.Key.html<@https://developer.android.com/reference/androidx/annotation/NonNull ?>> dynamicKeys )` Wraps a native `https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics.html` into a `https://developer.android.com/reference/androidx/camera/common/CameraCharacteristicsWrapper`. |

## Public fields

### INSTANCE

Added in [1.7.0-rc02](https://developer.android.com/jetpack/androidx/releases/camera#1.7.0-rc02)

```
public static @NonNull CameraCharacteristicsWrappers INSTANCE
```

## Public methods

### getAvailableColorSpaceProfiles

Added in [1.7.0-rc02](https://developer.android.com/jetpack/androidx/releases/camera#1.7.0-rc02)

```
public static final @NonNull ColorSpaceProfilesWrapper getAvailableColorSpaceProfiles(
    @NonNull CameraCharacteristicsMetadata receiver
)
```

Returns the `https://developer.android.com/reference/androidx/camera/common/ColorSpaceProfilesWrapper` supported by the camera device.

```kotlin
import androidx.camera.common.CameraCharacteristicsWrappers.availableColorSpaceProfiles
import androidx.camera.common.CameraCharacteristicsWrappers.availableDynamicRangeProfiles
import androidx.camera.common.CameraCharacteristicsWrappers.streamConfigurationMap

// Access standard CameraCharacteristics keys using the get/bracket operator:
val sensorOrientation = cameraCharacteristics[CameraCharacteristics.SENSOR_ORIENTATION]
val lensFacing = cameraCharacteristics[CameraCharacteristics.LENS_FACING]

// Access extended/custom properties using the extension properties.
// Note: Querying these properties will query custom/compatibility metadata keys first
// (such as STREAM_CONFIGURATION_MAP, AVAILABLE_COLOR_SPACE_PROFILES,
// AVAILABLE_DYNAMIC_RANGE_PROFILES) and fallback to creating internal wrappers from the
// native platform characteristics. In unit tests, test fakes supply the custom wrapped
// versions via these metadata keys.
val streamConfigurationMap = cameraCharacteristics.streamConfigurationMap
val colorSpaceProfiles = cameraCharacteristics.availableColorSpaceProfiles
val dynamicRangeProfiles = cameraCharacteristics.availableDynamicRangeProfiles
```

### getAvailableDynamicRangeProfiles

Added in [1.7.0-rc02](https://developer.android.com/jetpack/androidx/releases/camera#1.7.0-rc02)

```
public static final @NonNull DynamicRangeProfilesWrapper getAvailableDynamicRangeProfiles(
    @NonNull CameraCharacteristicsMetadata receiver
)
```

Returns the `https://developer.android.com/reference/androidx/camera/common/DynamicRangeProfilesWrapper` supported by the camera device.

```kotlin
import androidx.camera.common.CameraCharacteristicsWrappers.availableColorSpaceProfiles
import androidx.camera.common.CameraCharacteristicsWrappers.availableDynamicRangeProfiles
import androidx.camera.common.CameraCharacteristicsWrappers.streamConfigurationMap

// Access standard CameraCharacteristics keys using the get/bracket operator:
val sensorOrientation = cameraCharacteristics[CameraCharacteristics.SENSOR_ORIENTATION]
val lensFacing = cameraCharacteristics[CameraCharacteristics.LENS_FACING]

// Access extended/custom properties using the extension properties.
// Note: Querying these properties will query custom/compatibility metadata keys first
// (such as STREAM_CONFIGURATION_MAP, AVAILABLE_COLOR_SPACE_PROFILES,
// AVAILABLE_DYNAMIC_RANGE_PROFILES) and fallback to creating internal wrappers from the
// native platform characteristics. In unit tests, test fakes supply the custom wrapped
// versions via these metadata keys.
val streamConfigurationMap = cameraCharacteristics.streamConfigurationMap
val colorSpaceProfiles = cameraCharacteristics.availableColorSpaceProfiles
val dynamicRangeProfiles = cameraCharacteristics.availableDynamicRangeProfiles
```

| See also |
|---|---|
| `https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics.html#REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES` |   |

### getStreamConfigurationMap

Added in [1.7.0-rc02](https://developer.android.com/jetpack/androidx/releases/camera#1.7.0-rc02)

```
public static final StreamConfigurationMapWrapper getStreamConfigurationMap(
    @NonNull CameraCharacteristicsMetadata receiver
)
```

Extension property to query `https://developer.android.com/reference/androidx/camera/common/StreamConfigurationMapWrapper` directly.

This is the preferred way to access the `https://developer.android.com/reference/androidx/camera/common/StreamConfigurationMapWrapper` in Kotlin. It will fallback to creating a wrapper from the standard `https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics.html#SCALER_STREAM_CONFIGURATION_MAP` if the compatibility key is not populated.

```kotlin
import androidx.camera.common.CameraCharacteristicsWrappers.availableColorSpaceProfiles
import androidx.camera.common.CameraCharacteristicsWrappers.availableDynamicRangeProfiles
import androidx.camera.common.CameraCharacteristicsWrappers.streamConfigurationMap

// Access standard CameraCharacteristics keys using the get/bracket operator:
val sensorOrientation = cameraCharacteristics[CameraCharacteristics.SENSOR_ORIENTATION]
val lensFacing = cameraCharacteristics[CameraCharacteristics.LENS_FACING]

// Access extended/custom properties using the extension properties.
// Note: Querying these properties will query custom/compatibility metadata keys first
// (such as STREAM_CONFIGURATION_MAP, AVAILABLE_COLOR_SPACE_PROFILES,
// AVAILABLE_DYNAMIC_RANGE_PROFILES) and fallback to creating internal wrappers from the
// native platform characteristics. In unit tests, test fakes supply the custom wrapped
// versions via these metadata keys.
val streamConfigurationMap = cameraCharacteristics.streamConfigurationMap
val colorSpaceProfiles = cameraCharacteristics.availableColorSpaceProfiles
val dynamicRangeProfiles = cameraCharacteristics.availableDynamicRangeProfiles
```

```kotlin
import androidx.camera.common.CameraCharacteristicsWrapper
import androidx.camera.common.CameraCharacteristicsWrappers.streamConfigurationMap
import androidx.camera.common.CameraId
import androidx.camera.common.testing.FakeCameraCharacteristics
import androidx.camera.common.testing.FakeStreamConfigurationMap
import androidx.camera.common.testing.FakeStreamConfigurationMap.OutputKey
import androidx.camera.common.testing.FakeStreamConfigurationMap.OutputValues

// Create a fake stream configuration map with custom resolutions and formats.
val fakeStreamConfigurationMap =
    FakeStreamConfigurationMap(
        outputsTable =
            linkedMapOf(
                OutputKey(ImageFormat.YUV_420_888, Size(1920, 1080)) to OutputValues(),
                OutputKey(ImageFormat.JPEG, Size(1920, 1080)) to
                    OutputValues(
                        stallDuration = 200_000_000L // 200ms stall duration
                    ),
            )
    )

// Supply the fake stream configuration map via STREAM_CONFIGURATION_MAP metadata key.
val fakeCharacteristics: CameraCharacteristicsWrapper =
    FakeCameraCharacteristics(
        cameraId = CameraId("0"),
        cameraCharacteristics =
            mapOf(
                CameraCharacteristics.LENS_FACING to CameraCharacteristics.LENS_FACING_BACK,
                CameraCharacteristics.SENSOR_ORIENTATION to 90,
            ),
        cameraMetadata =
            mapOf(
                CameraCharacteristicsWrapper.Keys.STREAM_CONFIGURATION_MAP to
                    fakeStreamConfigurationMap
            ),
    )

// The extension property accesses the wrapped version (STREAM_CONFIGURATION_MAP) first,
// returning the FakeStreamConfigurationMap in unit tests without needing real camera hardware.
val streamConfigMap = checkNotNull(fakeCharacteristics.streamConfigurationMap)
val supportedFormats = streamConfigMap.getOutputFormats()
val yuvSizes = streamConfigMap.getOutputSizes(ImageFormat.YUV_420_888)
```

### loadFrom

Added in [1.7.0-rc02](https://developer.android.com/jetpack/androidx/releases/camera#1.7.0-rc02)

```
public static final @NonNull CameraCharacteristicsWrapper loadFrom(
    @NonNull Context context,
    @NonNull CameraId cameraId,
    @NonNull Set<@NonNull CameraCharacteristics.Key<@NonNull ?>> dynamicKeys
)
```

Loads `https://developer.android.com/reference/androidx/camera/common/CameraCharacteristicsWrapper` for the given `https://developer.android.com/reference/androidx/camera/common/CameraCharacteristicsWrappers#loadFrom(android.content.Context,androidx.camera.common.CameraId,kotlin.collections.Set)` using `https://developer.android.com/reference/android/content/Context.html`.

This method will perform an instantaneous check to determine if the camera permission is granted, setting `https://developer.android.com/reference/androidx/camera/common/CameraCharacteristicsWrapper#isRestricted()` accordingly.

```kotlin
import androidx.camera.common.CameraCharacteristicsWrapper
import androidx.camera.common.CameraCharacteristicsWrappers
import androidx.camera.common.CameraId

val cameraId = CameraId(cameraIdString)

// Load CameraCharacteristicsWrapper directly using Context.
// This checks camera permissions and marks isRestricted accordingly.
val characteristicsFromContext: CameraCharacteristicsWrapper =
    CameraCharacteristicsWrappers.loadFrom(context, cameraId)

// Or load directly using CameraManager:
val cameraManager = context.getSystemService(Context.CAMERA_SERVICE) as CameraManager
val characteristicsFromManager: CameraCharacteristicsWrapper =
    CameraCharacteristicsWrappers.loadFrom(cameraManager, cameraId)
```

### loadFrom

Added in [1.7.0-rc02](https://developer.android.com/jetpack/androidx/releases/camera#1.7.0-rc02)

```
public static final @NonNull CameraCharacteristicsWrapper loadFrom(
    @NonNull CameraManager cameraManager,
    @NonNull CameraId cameraId,
    boolean isRestricted,
    @NonNull Set<@NonNull CameraCharacteristics.Key<@NonNull ?>> dynamicKeys
)
```

Loads `https://developer.android.com/reference/androidx/camera/common/CameraCharacteristicsWrapper` for the given `https://developer.android.com/reference/androidx/camera/common/CameraCharacteristicsWrappers#loadFrom(android.hardware.camera2.CameraManager,androidx.camera.common.CameraId,kotlin.Boolean,kotlin.collections.Set)` using `https://developer.android.com/reference/android/hardware/camera2/CameraManager.html`.

```kotlin
import androidx.camera.common.CameraCharacteristicsWrapper
import androidx.camera.common.CameraCharacteristicsWrappers
import androidx.camera.common.CameraId

val cameraId = CameraId(cameraIdString)

// Load CameraCharacteristicsWrapper directly using Context.
// This checks camera permissions and marks isRestricted accordingly.
val characteristicsFromContext: CameraCharacteristicsWrapper =
    CameraCharacteristicsWrappers.loadFrom(context, cameraId)

// Or load directly using CameraManager:
val cameraManager = context.getSystemService(Context.CAMERA_SERVICE) as CameraManager
val characteristicsFromManager: CameraCharacteristicsWrapper =
    CameraCharacteristicsWrappers.loadFrom(cameraManager, cameraId)
```

### wrap

Added in [1.7.0-rc02](https://developer.android.com/jetpack/androidx/releases/camera#1.7.0-rc02)

```
public static final @NonNull CameraCharacteristicsWrapper wrap(
    @NonNull CameraId cameraId,
    @NonNull CameraCharacteristics characteristics,
    boolean isRestricted,
    @NonNull Set<@NonNull CameraCharacteristics.Key<@NonNull ?>> dynamicKeys
)
```

Wraps a native `https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics.html` into a `https://developer.android.com/reference/androidx/camera/common/CameraCharacteristicsWrapper`.

```kotlin
import androidx.camera.common.CameraCharacteristicsWrapper
import androidx.camera.common.CameraCharacteristicsWrappers
import androidx.camera.common.CameraId

val cameraManager = context.getSystemService(Context.CAMERA_SERVICE) as CameraManager
val characteristics = cameraManager.getCameraCharacteristics(cameraIdString)
val cameraId = CameraId(cameraIdString)

// Wrap the native CameraCharacteristics instance into a CameraCharacteristicsWrapper.
val cameraCharacteristics: CameraCharacteristicsWrapper =
    CameraCharacteristicsWrappers.wrap(cameraId, characteristics)
```