FakeCameraCharacteristics


class FakeCameraCharacteristics : CameraCharacteristicsWrapper


A fake implementation of CameraCharacteristicsWrapper for testing.

Allows mock values to be configured for camera characteristics, custom metadata, supported keys, and physical camera IDs. This class is designed to be used in unit tests to mock camera behavior without needing a physical device or a real camera service.

Throws
IllegalArgumentException

If physicalCameraIds contains cameraId, or if any key in restrictedKeys or sessionKeys is not present in cameraCharacteristics.

Summary

Public companion functions

FakeCameraCharacteristics
create(
    cameraId: String,
    cameraCharacteristics: Map<CameraCharacteristics.Key<*>, Any?>,
    cameraMetadata: Map<Metadata.Key<*>, Any?>,
    captureRequestKeys: Set<CaptureRequest.Key<*>>,
    captureResultKeys: Set<CaptureResult.Key<*>>,
    sessionKeys: Set<CameraCharacteristics.Key<*>>,
    sessionCaptureRequestKeys: Set<CaptureRequest.Key<*>>,
    physicalCameraIds: Set<String>,
    physicalCaptureRequestKeys: Set<CaptureRequest.Key<*>>,
    isRestricted: Boolean,
    restrictedKeys: Set<CameraCharacteristics.Key<*>>,
    dynamicKeys: Set<CameraCharacteristics.Key<*>>
)

Creates a FakeCameraCharacteristics instance for Java compatibility.

Public constructors

FakeCameraCharacteristics(
    cameraId: CameraId,
    cameraCharacteristics: Map<CameraCharacteristics.Key<*>, Any?>,
    cameraMetadata: Map<Metadata.Key<*>, Any?>,
    captureRequestKeys: Set<CaptureRequest.Key<*>>,
    captureResultKeys: Set<CaptureResult.Key<*>>,
    sessionKeys: Set<CameraCharacteristics.Key<*>>,
    sessionCaptureRequestKeys: Set<CaptureRequest.Key<*>>,
    physicalCameraIds: Set<CameraId>,
    physicalCaptureRequestKeys: Set<CaptureRequest.Key<*>>,
    isRestricted: Boolean,
    restrictedKeys: Set<CameraCharacteristics.Key<*>>,
    dynamicKeys: Set<CameraCharacteristics.Key<*>>
)

Public functions

open operator T?

Retrieves the mock value for the specified CameraCharacteristics.Key.

open operator T?
<T : Any> get(key: Metadata.Key<T>)

Retrieves the mock value for the specified Metadata.Key.

open T?
<T : Any> unwrapAs(type: Class<T>)

Unwraps this instance to the requested type if compatible.

Public properties

open CameraId

The CameraId identifying this camera device.

open Set<CaptureRequest.Key<*>>

The set of CaptureRequest.Keys supported by this camera.

open Set<CaptureResult.Key<*>>

The set of CaptureResult.Keys supported by this camera.

open Set<CameraCharacteristics.Key<*>>

The set of CameraCharacteristics.Keys whose values can change depending on the device state.

open Boolean

Indicates whether the wrapper queried camera characteristics without camera permission.

open Set<CameraCharacteristics.Key<*>>

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

open Set<Metadata.Key<*>>

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

open Set<CameraId>

The set of physical CameraIds that this logical camera device is made up of.

open Set<CaptureRequest.Key<*>>

The set of physical CaptureRequest.Keys.

open Set<CameraCharacteristics.Key<*>>

The set of CameraCharacteristics.Keys that require camera permissions.

open Set<CaptureRequest.Key<*>>

The set of CaptureRequest.Keys that the camera device can pass as part of the capture session initialization.

open Set<CameraCharacteristics.Key<*>>

The set of CameraCharacteristics.Keys whose values are capture session specific.

Inherited functions

From androidx.camera.common.CameraCharacteristicsMetadata
open T
<T : Any> getOrDefault(key: CameraCharacteristics.Key<T>, default: T)

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
open T
<T : Any> getOrDefault(key: Metadata.Key<T>, default: T)

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

Public companion functions

create

fun create(
    cameraId: String = FakeCameraIds.default.value,
    cameraCharacteristics: Map<CameraCharacteristics.Key<*>, Any?> = emptyMap(),
    cameraMetadata: Map<Metadata.Key<*>, Any?> = emptyMap(),
    captureRequestKeys: Set<CaptureRequest.Key<*>> = emptySet(),
    captureResultKeys: Set<CaptureResult.Key<*>> = emptySet(),
    sessionKeys: Set<CameraCharacteristics.Key<*>> = emptySet(),
    sessionCaptureRequestKeys: Set<CaptureRequest.Key<*>> = emptySet(),
    physicalCameraIds: Set<String> = emptySet(),
    physicalCaptureRequestKeys: Set<CaptureRequest.Key<*>> = emptySet(),
    isRestricted: Boolean = false,
    restrictedKeys: Set<CameraCharacteristics.Key<*>> = emptySet(),
    dynamicKeys: Set<CameraCharacteristics.Key<*>> = emptySet()
): FakeCameraCharacteristics

Creates a FakeCameraCharacteristics instance for Java compatibility.

Parameters
cameraId: String = FakeCameraIds.default.value

The camera ID string. Defaults to FakeCameraIds.default's value.

cameraCharacteristics: Map<CameraCharacteristics.Key<*>, Any?> = emptyMap()

The map of characteristics keys to their mock values.

cameraMetadata: Map<Metadata.Key<*>, Any?> = emptyMap()

The map of custom metadata keys to their mock values.

captureRequestKeys: Set<CaptureRequest.Key<*>> = emptySet()

The set of capture request keys supported by this camera.

captureResultKeys: Set<CaptureResult.Key<*>> = emptySet()

The set of capture result keys supported by this camera.

sessionKeys: Set<CameraCharacteristics.Key<*>> = emptySet()

The set of session characteristics keys. All keys in this set must also be present in cameraCharacteristics.

sessionCaptureRequestKeys: Set<CaptureRequest.Key<*>> = emptySet()

The set of session keys.

physicalCameraIds: Set<String> = emptySet()

The set of physical camera ID strings. Must not contain cameraId.

physicalCaptureRequestKeys: Set<CaptureRequest.Key<*>> = emptySet()

The set of physical capture request keys.

isRestricted: Boolean = false

True if the camera is operating in a restricted mode.

restrictedKeys: Set<CameraCharacteristics.Key<*>> = emptySet()

The set of keys that require camera permissions. All keys in this set must also be present in cameraCharacteristics.

dynamicKeys: Set<CameraCharacteristics.Key<*>> = emptySet()

The set of keys that can change dynamically.

Returns
FakeCameraCharacteristics

A configured FakeCameraCharacteristics instance.

Throws
IllegalArgumentException

If physicalCameraIds contains cameraId, or if any key in restrictedKeys or sessionKeys is not present in cameraCharacteristics.

Public constructors

FakeCameraCharacteristics

Added in 1.7.0-alpha03
FakeCameraCharacteristics(
    cameraId: CameraId = FakeCameraIds.default,
    cameraCharacteristics: Map<CameraCharacteristics.Key<*>, Any?> = emptyMap(),
    cameraMetadata: Map<Metadata.Key<*>, Any?> = emptyMap(),
    captureRequestKeys: Set<CaptureRequest.Key<*>> = emptySet(),
    captureResultKeys: Set<CaptureResult.Key<*>> = emptySet(),
    sessionKeys: Set<CameraCharacteristics.Key<*>> = emptySet(),
    sessionCaptureRequestKeys: Set<CaptureRequest.Key<*>> = emptySet(),
    physicalCameraIds: Set<CameraId> = emptySet(),
    physicalCaptureRequestKeys: Set<CaptureRequest.Key<*>> = emptySet(),
    isRestricted: Boolean = false,
    restrictedKeys: Set<CameraCharacteristics.Key<*>> = emptySet(),
    dynamicKeys: Set<CameraCharacteristics.Key<*>> = emptySet()
)
Parameters
cameraId: CameraId = FakeCameraIds.default

The CameraId identifying this camera device. Defaults to FakeCameraIds.default.

cameraCharacteristics: Map<CameraCharacteristics.Key<*>, Any?> = emptyMap()

A map of CameraCharacteristics.Key to their mock values. Any key queried via get will return the value from this map.

cameraMetadata: Map<Metadata.Key<*>, Any?> = emptyMap()

A map of custom Metadata.Key to their mock values. Any key queried via get will return the value from this map.

captureRequestKeys: Set<CaptureRequest.Key<*>> = emptySet()

The set of CaptureRequest.Keys supported by this camera.

captureResultKeys: Set<CaptureResult.Key<*>> = emptySet()

The set of CaptureResult.Keys supported by this camera.

sessionKeys: Set<CameraCharacteristics.Key<*>> = emptySet()

The set of CameraCharacteristics.Keys whose values are capture session specific. All keys in this set must also be present in cameraCharacteristics.

sessionCaptureRequestKeys: Set<CaptureRequest.Key<*>> = emptySet()

The set of CaptureRequest.Keys that the camera device can pass as part of the capture session initialization.

physicalCameraIds: Set<CameraId> = emptySet()

The set of physical CameraIds that this logical camera device is made up of. Must not contain cameraId.

physicalCaptureRequestKeys: Set<CaptureRequest.Key<*>> = emptySet()

The set of physical CaptureRequest.Keys.

isRestricted: Boolean = false

Indicates whether the wrapper queried camera characteristics without camera permission.

restrictedKeys: Set<CameraCharacteristics.Key<*>> = emptySet()

The set of CameraCharacteristics.Keys that require camera permissions. All keys in this set must also be present in cameraCharacteristics.

dynamicKeys: Set<CameraCharacteristics.Key<*>> = emptySet()

The set of CameraCharacteristics.Keys whose values can change depending on the device state.

Public functions

get

Added in 1.7.0-alpha03
open operator fun <T : Any> get(key: CameraCharacteristics.Key<T>): T?

Retrieves the mock value for the specified CameraCharacteristics.Key.

Parameters
key: CameraCharacteristics.Key<T>

The native characteristics key to query.

Returns
T?

The mock value configured in cameraCharacteristics, or null if not present.

get

Added in 1.7.0-alpha03
open operator fun <T : Any> get(key: Metadata.Key<T>): T?

Retrieves the mock value for the specified Metadata.Key.

Parameters
key: Metadata.Key<T>

The custom metadata key to query.

Returns
T?

The mock value configured in cameraMetadata, or null if not present.

unwrapAs

Added in 1.7.0-alpha03
open fun <T : Any> unwrapAs(type: Class<T>): T?

Unwraps this instance to the requested type if compatible.

Since this is a fake implementation, it can only be unwrapped to FakeCameraCharacteristics itself or its supertypes (e.g., CameraCharacteristicsWrapper). It cannot be unwrapped to a native android.hardware.camera2.CameraCharacteristics.

Parameters
type: Class<T>

The class of the type to unwrap to.

Returns
T?

This instance cast to T if compatible, or null otherwise.

Public properties

cameraId

Added in 1.7.0-alpha03
open val cameraIdCameraId

The CameraId identifying this camera device.

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

captureRequestKeys

Added in 1.7.0-alpha03
open val captureRequestKeysSet<CaptureRequest.Key<*>>

The set of CaptureRequest.Keys supported by this camera.

captureResultKeys

Added in 1.7.0-alpha03
open val captureResultKeysSet<CaptureResult.Key<*>>

The set of CaptureResult.Keys supported by this camera.

dynamicKeys

Added in 1.7.0-alpha03
open val dynamicKeysSet<CameraCharacteristics.Key<*>>

The set of CameraCharacteristics.Keys whose values can change depending on the device state.

isRestricted

Added in 1.7.0-alpha03
open val isRestrictedBoolean

Indicates whether the wrapper queried camera characteristics without camera permission.

keys

Added in 1.7.0-alpha03
open val keysSet<CameraCharacteristics.Key<*>>

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

metadataKeys

Added in 1.7.0-alpha03
open val metadataKeysSet<Metadata.Key<*>>

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

Note that this set contains only custom library-defined keys. It does not include platform-specific keys (such as android.hardware.camera2.CameraCharacteristics.Key or android.hardware.camera2.CaptureResult.Key), which are managed separately by the implementing wrappers.

physicalCameraIds

Added in 1.7.0-alpha03
open val physicalCameraIdsSet<CameraId>

The set of physical CameraIds that this logical camera device is made up of. Must not contain cameraId.

physicalCaptureRequestKeys

Added in 1.7.0-alpha03
open val physicalCaptureRequestKeysSet<CaptureRequest.Key<*>>

The set of physical CaptureRequest.Keys.

restrictedKeys

Added in 1.7.0-alpha03
open val restrictedKeysSet<CameraCharacteristics.Key<*>>

The set of CameraCharacteristics.Keys that require camera permissions. All keys in this set must also be present in cameraCharacteristics.

sessionCaptureRequestKeys

Added in 1.7.0-alpha03
open val sessionCaptureRequestKeysSet<CaptureRequest.Key<*>>

The set of CaptureRequest.Keys that the camera device can pass as part of the capture session initialization.

sessionKeys

Added in 1.7.0-alpha03
open val sessionKeysSet<CameraCharacteristics.Key<*>>

The set of CameraCharacteristics.Keys whose values are capture session specific. All keys in this set must also be present in cameraCharacteristics.