FakeCameraCharacteristics


public final class FakeCameraCharacteristics implements 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 constructors

FakeCameraCharacteristics(
    @NonNull CameraId cameraId,
    @NonNull Map<@NonNull CameraCharacteristics.Key<@NonNull ?>, Object> cameraCharacteristics,
    @NonNull Map<@NonNull Metadata.Key<@NonNull ?>, Object> cameraMetadata,
    @NonNull Set<@NonNull CaptureRequest.Key<@NonNull ?>> captureRequestKeys,
    @NonNull Set<@NonNull CaptureResult.Key<@NonNull ?>> captureResultKeys,
    @NonNull Set<@NonNull CameraCharacteristics.Key<@NonNull ?>> sessionKeys,
    @NonNull Set<@NonNull CaptureRequest.Key<@NonNull ?>> sessionCaptureRequestKeys,
    @NonNull Set<@NonNull CameraId> physicalCameraIds,
    @NonNull Set<@NonNull CaptureRequest.Key<@NonNull ?>> physicalCaptureRequestKeys,
    boolean isRestricted,
    @NonNull Set<@NonNull CameraCharacteristics.Key<@NonNull ?>> restrictedKeys,
    @NonNull Set<@NonNull CameraCharacteristics.Key<@NonNull ?>> dynamicKeys
)

Public methods

static final @NonNull FakeCameraCharacteristics
create(
    @NonNull String cameraId,
    @NonNull Map<@NonNull CameraCharacteristics.Key<@NonNull ?>, Object> cameraCharacteristics,
    @NonNull Map<@NonNull Metadata.Key<@NonNull ?>, Object> cameraMetadata,
    @NonNull Set<@NonNull CaptureRequest.Key<@NonNull ?>> captureRequestKeys,
    @NonNull Set<@NonNull CaptureResult.Key<@NonNull ?>> captureResultKeys,
    @NonNull Set<@NonNull CameraCharacteristics.Key<@NonNull ?>> sessionKeys,
    @NonNull Set<@NonNull CaptureRequest.Key<@NonNull ?>> sessionCaptureRequestKeys,
    @NonNull Set<@NonNull String> physicalCameraIds,
    @NonNull Set<@NonNull CaptureRequest.Key<@NonNull ?>> physicalCaptureRequestKeys,
    boolean isRestricted,
    @NonNull Set<@NonNull CameraCharacteristics.Key<@NonNull ?>> restrictedKeys,
    @NonNull Set<@NonNull CameraCharacteristics.Key<@NonNull ?>> dynamicKeys
)

Creates a FakeCameraCharacteristics instance for Java compatibility.

T

Retrieves the mock value for the specified CameraCharacteristics.Key.

T
<T extends Object> get(@NonNull Metadata.Key<@NonNull T> key)

Retrieves the mock value for the specified Metadata.Key.

@NonNull CameraId

The CameraId identifying this camera device.

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

The set of CaptureRequest.Keys supported by this camera.

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

The set of CaptureResult.Keys supported by this camera.

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

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

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

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

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

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

@NonNull Set<@NonNull CameraId>

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

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

The set of physical CaptureRequest.Keys.

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

The set of CameraCharacteristics.Keys that require camera permissions.

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

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

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

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

boolean

Indicates whether the wrapper queried camera characteristics without camera permission.

T
<T extends Object> unwrapAs(@NonNull Class<@NonNull T> type)

Unwraps this instance to the requested type if compatible.

Inherited methods

From androidx.camera.common.CameraCharacteristicsMetadata
@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
@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.

Public constructors

FakeCameraCharacteristics

Added in 1.7.0-alpha03
public FakeCameraCharacteristics(
    @NonNull CameraId cameraId,
    @NonNull Map<@NonNull CameraCharacteristics.Key<@NonNull ?>, Object> cameraCharacteristics,
    @NonNull Map<@NonNull Metadata.Key<@NonNull ?>, Object> cameraMetadata,
    @NonNull Set<@NonNull CaptureRequest.Key<@NonNull ?>> captureRequestKeys,
    @NonNull Set<@NonNull CaptureResult.Key<@NonNull ?>> captureResultKeys,
    @NonNull Set<@NonNull CameraCharacteristics.Key<@NonNull ?>> sessionKeys,
    @NonNull Set<@NonNull CaptureRequest.Key<@NonNull ?>> sessionCaptureRequestKeys,
    @NonNull Set<@NonNull CameraId> physicalCameraIds,
    @NonNull Set<@NonNull CaptureRequest.Key<@NonNull ?>> physicalCaptureRequestKeys,
    boolean isRestricted,
    @NonNull Set<@NonNull CameraCharacteristics.Key<@NonNull ?>> restrictedKeys,
    @NonNull Set<@NonNull CameraCharacteristics.Key<@NonNull ?>> dynamicKeys
)
Parameters
@NonNull CameraId cameraId

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

@NonNull Map<@NonNull CameraCharacteristics.Key<@NonNull ?>, Object> cameraCharacteristics

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

@NonNull Map<@NonNull Metadata.Key<@NonNull ?>, Object> cameraMetadata

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

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

The set of CaptureRequest.Keys supported by this camera.

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

The set of CaptureResult.Keys supported by this camera.

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

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

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

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

@NonNull Set<@NonNull CameraId> physicalCameraIds

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

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

The set of physical CaptureRequest.Keys.

boolean isRestricted

Indicates whether the wrapper queried camera characteristics without camera permission.

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

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

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

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

Public methods

create

public static final @NonNull FakeCameraCharacteristics create(
    @NonNull String cameraId,
    @NonNull Map<@NonNull CameraCharacteristics.Key<@NonNull ?>, Object> cameraCharacteristics,
    @NonNull Map<@NonNull Metadata.Key<@NonNull ?>, Object> cameraMetadata,
    @NonNull Set<@NonNull CaptureRequest.Key<@NonNull ?>> captureRequestKeys,
    @NonNull Set<@NonNull CaptureResult.Key<@NonNull ?>> captureResultKeys,
    @NonNull Set<@NonNull CameraCharacteristics.Key<@NonNull ?>> sessionKeys,
    @NonNull Set<@NonNull CaptureRequest.Key<@NonNull ?>> sessionCaptureRequestKeys,
    @NonNull Set<@NonNull String> physicalCameraIds,
    @NonNull Set<@NonNull CaptureRequest.Key<@NonNull ?>> physicalCaptureRequestKeys,
    boolean isRestricted,
    @NonNull Set<@NonNull CameraCharacteristics.Key<@NonNull ?>> restrictedKeys,
    @NonNull Set<@NonNull CameraCharacteristics.Key<@NonNull ?>> dynamicKeys
)

Creates a FakeCameraCharacteristics instance for Java compatibility.

Parameters
@NonNull String cameraId

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

@NonNull Map<@NonNull CameraCharacteristics.Key<@NonNull ?>, Object> cameraCharacteristics

The map of characteristics keys to their mock values.

@NonNull Map<@NonNull Metadata.Key<@NonNull ?>, Object> cameraMetadata

The map of custom metadata keys to their mock values.

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

The set of capture request keys supported by this camera.

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

The set of capture result keys supported by this camera.

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

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

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

The set of session keys.

@NonNull Set<@NonNull String> physicalCameraIds

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

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

The set of physical capture request keys.

boolean isRestricted

True if the camera is operating in a restricted mode.

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

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

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

The set of keys that can change dynamically.

Throws
IllegalArgumentException

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

get

Added in 1.7.0-alpha03
public T <T extends Object> get(@NonNull CameraCharacteristics.Key<@NonNull T> key)

Retrieves the mock value for the specified CameraCharacteristics.Key.

Parameters
@NonNull CameraCharacteristics.Key<@NonNull T> key

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
public T <T extends Object> get(@NonNull Metadata.Key<@NonNull T> key)

Retrieves the mock value for the specified Metadata.Key.

Parameters
@NonNull Metadata.Key<@NonNull T> key

The custom metadata key to query.

Returns
T

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

getCameraId

Added in 1.7.0-alpha03
public @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
public @NonNull Set<@NonNull CaptureRequest.Key<@NonNull ?>> getCaptureRequestKeys()

The set of CaptureRequest.Keys supported by this camera.

getCaptureResultKeys

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

The set of CaptureResult.Keys supported by this camera.

getDynamicKeys

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

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

getKeys

Added in 1.7.0-alpha03
public @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

getMetadataKeys

Added in 1.7.0-alpha03
public @NonNull Set<@NonNull Metadata.Key<@NonNull ?>> getMetadataKeys()

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.

getPhysicalCameraIds

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

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

getPhysicalCaptureRequestKeys

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

The set of physical CaptureRequest.Keys.

getRestrictedKeys

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

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

getSessionCaptureRequestKeys

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

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

getSessionKeys

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

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

isRestricted

Added in 1.7.0-alpha03
public boolean isRestricted()

Indicates whether the wrapper queried camera characteristics without camera permission.

unwrapAs

Added in 1.7.0-alpha03
public T <T extends Object> unwrapAs(@NonNull Class<@NonNull T> type)

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
@NonNull Class<@NonNull T> type

The class of the type to unwrap to.

Returns
T

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