CameraCharacteristicsWrapper


public interface CameraCharacteristicsWrapper extends CameraCharacteristicsMetadata

Known direct subclasses
FakeCameraCharacteristics

A fake implementation of CameraCharacteristicsWrapper for testing.


Wrapper interface providing compatibility-focused access to CameraCharacteristics.

Use this interface to query camera capabilities, physical properties, and supported configurations. It abstracts OS version differences and caches expensive-to-retrieve properties to ensure efficient access across all API levels.

CameraCharacteristicsWrapper implements Metadata, allowing it to support type-safe retrieval of custom library-defined metadata keys via Metadata.Key in addition to native CameraCharacteristics.Key keys.

It also implements UnsafeWrapper, which allows unwrapping to the underlying native CameraCharacteristics using UnsafeWrapper.unwrapAs when platform-specific APIs are required. Note that bypassing the wrapper by unwrapping avoids compatibility fixes and caching.

Note: This interface is not stable for inheritance. Implementations should not be created directly by clients. For testing, use the fakes in androidx.camera.common.testing package (such as FakeCameraCharacteristics).

Example

Querying native and custom keys:

val characteristics: CameraCharacteristicsWrapper = ...

// Query a native CameraCharacteristics key:
val lensFacing: Int? = characteristics[CameraCharacteristics.LENS_FACING]

// Query a custom Metadata key:
val customValue: String? = characteristics[MY_CUSTOM_METADATA_KEY]

Unwrapping the native object (unsafe):

val nativeCharacteristics: CameraCharacteristics? = characteristics.unwrapAs()

Summary

Nested types

Public methods

abstract @NonNull CameraId

The CameraId identifying this camera device.

abstract @NonNull Set<@NonNull CaptureRequest.Key<@NonNull ?>>

A Set of all CaptureRequest.Keys supported by this camera device for CaptureRequests.

abstract @NonNull Set<@NonNull CaptureResult.Key<@NonNull ?>>

A Set of all CaptureResult.Keys supported by this camera device for CaptureResults.

abstract @NonNull Set<@NonNull CameraCharacteristics.Key<@NonNull ?>>

A Set of CameraCharacteristics.Keys whose values can change dynamically based on the physical state of the device.

abstract @NonNull Set<@NonNull CameraCharacteristics.Key<@NonNull ?>>

A Set of all CameraCharacteristics.Keys supported by this camera device.

abstract @NonNull Set<@NonNull CameraId>

A Set of physical camera IDs that this logical camera device is made up of.

abstract @NonNull Set<@NonNull CaptureRequest.Key<@NonNull ?>>

A Set of physical CaptureRequest.Keys that can be overridden for physical devices backing a logical multi-camera.

abstract @NonNull Set<@NonNull CameraCharacteristics.Key<@NonNull ?>>

A Set of CameraCharacteristics.Keys that require camera clients to obtain the Manifest.permission.CAMERA permission.

abstract @NonNull Set<@NonNull CaptureRequest.Key<@NonNull ?>>

A Set of CaptureRequest.Keys that the camera device can pass as part of the capture session initialization.

abstract @NonNull Set<@NonNull CameraCharacteristics.Key<@NonNull ?>>

A Set of CameraCharacteristics.Keys whose values are capture session specific.

abstract boolean

Indicates whether the wrapper queried camera characteristics without camera permission.

Inherited methods

From androidx.camera.common.CameraCharacteristicsMetadata
abstract T

Retrieves the value of the specified CameraCharacteristics.Key.

default @NonNull T
<T extends Object> getOrDefault(
    @NonNull CameraCharacteristics.Key<@NonNull T> key,
    @NonNull T default
)

Retrieves the value of the specified CameraCharacteristics.Key, or returns default if the value is null or the key is unsupported.

From androidx.camera.common.Metadata
abstract T
<T extends Object> get(@NonNull Metadata.Key<@NonNull T> key)

Retrieves the value associated with the specified Metadata.Key.

abstract @NonNull Set<@NonNull Metadata.Key<@NonNull ?>>

The set of all custom Metadata.Keys currently available in this container.

default @NonNull T
<T extends Object> getOrDefault(
    @NonNull Metadata.Key<@NonNull T> key,
    @NonNull T default
)

Retrieves the value associated with the specified Metadata.Key, or returns default if the key is not present.

From androidx.camera.common.UnsafeWrapper
abstract T
<T extends Object> unwrapAs(@NonNull Class<@NonNull T> type)

Attempts to unwrap this object into the specified underlying type.

Public methods

getCameraId

Added in 1.7.0-alpha03
abstract @NonNull CameraId getCameraId()

The CameraId identifying this camera device.

This corresponds to the camera ID used to open the camera with android.hardware.camera2.CameraManager.openCamera.

getCaptureRequestKeys

Added in 1.7.0-alpha03
abstract @NonNull Set<@NonNull CaptureRequest.Key<@NonNull ?>> getCaptureRequestKeys()

A Set of all CaptureRequest.Keys supported by this camera device for CaptureRequests.

This property is equivalent to calling CameraCharacteristics.getAvailableCaptureRequestKeys, but may be cached for efficiency.

getCaptureResultKeys

Added in 1.7.0-alpha03
abstract @NonNull Set<@NonNull CaptureResult.Key<@NonNull ?>> getCaptureResultKeys()

A Set of all CaptureResult.Keys supported by this camera device for CaptureResults.

This property is equivalent to calling CameraCharacteristics.getAvailableCaptureResultKeys, but may be cached for efficiency.

getDynamicKeys

Added in 1.7.0-alpha03
abstract @NonNull Set<@NonNull CameraCharacteristics.Key<@NonNull ?>> getDynamicKeys()

A Set of CameraCharacteristics.Keys whose values can change dynamically based on the physical state of the device.

Do not cache values retrieved using these keys. The values can change at runtime, for example when a foldable device changes its posture.

At present, only the SENSOR_ORIENTATION key on foldable devices can change based on the posture of the device, but may be expanded in the future if other camera properties change dynamically based on the posture or other physical state of the device.

The primary purpose of this property is to indicate which keys should not be cached.

getKeys

Added in 1.7.0-alpha03
abstract @NonNull Set<@NonNull CameraCharacteristics.Key<@NonNull ?>> getKeys()

A Set of all CameraCharacteristics.Keys supported by this camera device.

This property is equivalent to calling android.hardware.camera2.CameraCharacteristics.getKeys on the underlying camera characteristics, but may be cached for efficiency.

See also
getKeys

getPhysicalCameraIds

Added in 1.7.0-alpha03
abstract @NonNull Set<@NonNull CameraIdgetPhysicalCameraIds()

A Set of physical camera IDs that this logical camera device is made up of.

On API levels prior to 28 (Android P), this property returns an empty set.

getPhysicalCaptureRequestKeys

Added in 1.7.0-alpha03
abstract @NonNull Set<@NonNull CaptureRequest.Key<@NonNull ?>> getPhysicalCaptureRequestKeys()

A Set of physical CaptureRequest.Keys that can be overridden for physical devices backing a logical multi-camera.

On API levels prior to 28 (Android P), this property returns an empty set.

getRestrictedKeys

Added in 1.7.0-alpha03
abstract @NonNull Set<@NonNull CameraCharacteristics.Key<@NonNull ?>> getRestrictedKeys()

A Set of CameraCharacteristics.Keys that require camera clients to obtain the Manifest.permission.CAMERA permission.

On API levels prior to 29 (Android Q), this property returns an empty set.

getSessionCaptureRequestKeys

Added in 1.7.0-alpha03
abstract @NonNull Set<@NonNull CaptureRequest.Key<@NonNull ?>> getSessionCaptureRequestKeys()

A Set of CaptureRequest.Keys that the camera device can pass as part of the capture session initialization.

On API levels prior to 28 (Android P), this property returns an empty set.

getSessionKeys

Added in 1.7.0-alpha03
abstract @NonNull Set<@NonNull CameraCharacteristics.Key<@NonNull ?>> getSessionKeys()

A Set of CameraCharacteristics.Keys whose values are capture session specific.

On API levels prior to 35 (Android 15), this property returns an empty set.

isRestricted

Added in 1.7.0-alpha03
abstract boolean isRestricted()

Indicates whether the wrapper queried camera characteristics without camera permission.

When true, the application did not hold the android.Manifest.permission.CAMERA permission when this instance was created. In this restricted mode, querying keys listed in restrictedKeys may return null or empty values.