FakeCameraExtensionCharacteristics


public final class FakeCameraExtensionCharacteristics implements CameraExtensionCharacteristicsWrapper


A fake implementation of CameraExtensionCharacteristicsWrapper for testing.

This class allows unit tests to mock and configure the characteristics and capabilities of camera extension modes without relying on native Android platform classes or a physical device.

To instantiate this class:

  • In Kotlin, use the companion invoke operator for idiomatic builder-like creation: ``kotlin val characteristics = FakeCameraExtensionCharacteristics( cameraId = CameraId("0"), cameraExtension = CameraExtensionCharacteristics.EXTENSION_BOKEH ) ``

  • In Java, use the static create factory method which takes a raw String camera ID: ``java FakeCameraExtensionCharacteristics characteristics = FakeCameraExtensionCharacteristics.create( "0", CameraExtensionCharacteristics.EXTENSION_BOKEH, // ... other parameters ); ``

Summary

Nested types

Public methods

static final @NonNull FakeCameraExtensionCharacteristics
create(
    @NonNull String cameraId,
    int cameraExtension,
    @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,
    boolean isRestricted,
    @NonNull Set<@NonNull CameraCharacteristics.Key<@NonNull ?>> restrictedKeys,
    @NonNull Set<@NonNull CameraCharacteristics.Key<@NonNull ?>> dynamicKeys,
    boolean isPostviewSupported,
    boolean isCaptureProgressSupported,
    @NonNull Map<@NonNull Integer, @NonNull Set<@NonNull Size>> outputSizesFormat,
    @NonNull Map<@NonNull Class<@NonNull ?>, @NonNull Set<@NonNull Size>> outputSizesClass,
    @NonNull Map<@NonNull Pair<@NonNull Size, @NonNull Integer>, @NonNull Set<@NonNull Size>> postviewSizes,
    @NonNull Map<@NonNull Pair<@NonNull Size, @NonNull Integer>, Range<@NonNull Long>> latencies
)

Creates a FakeCameraExtensionCharacteristics instance.

T

Retrieves the mock characteristics value for the given key.

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

Retrieves the mock metadata value for the given key.

int

The camera extension mode represented by this characteristics instance.

@NonNull CameraId

The ID of the camera device associated with these extension characteristics.

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

The set of capture request keys supported by this camera extension.

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

The set of capture result keys supported by this camera extension.

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

The set of camera characteristics keys that are dynamically updated for this extension.

Range<@NonNull Long>
getEstimatedCaptureLatencyRangeMillis(
    @NonNull Size captureSize,
    int imageFormat
)

Returns the mock estimated capture latency range in milliseconds for the given capture size and format.

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

The supported CameraCharacteristics.Keys defined in the mock characteristics map.

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

The supported Metadata.Keys defined in the mock metadata map.

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

Retrieves the mock characteristics value for the given key, returning the default if not set.

@NonNull Set<@NonNull Size>
getOutputSizes(int imageFormat)

Returns the mock output sizes for the given image format.

@NonNull Set<@NonNull Size>

Returns the mock output sizes for the given output class.

@NonNull Set<@NonNull Size>
getPostviewSizes(@NonNull Size captureSize, int format)

Returns the mock postview sizes for the given capture size and format.

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

The set of camera characteristics keys that require specific permissions to be accessed.

boolean

Whether capture progress callbacks are supported for this extension mode.

boolean

Whether postview is supported for this extension mode.

boolean

Whether access to some camera characteristics keys is restricted due to camera permissions.

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

Unwraps this instance as the requested type if compatible.

Inherited methods

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 methods

create

public static final @NonNull FakeCameraExtensionCharacteristics create(
    @NonNull String cameraId,
    int cameraExtension,
    @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,
    boolean isRestricted,
    @NonNull Set<@NonNull CameraCharacteristics.Key<@NonNull ?>> restrictedKeys,
    @NonNull Set<@NonNull CameraCharacteristics.Key<@NonNull ?>> dynamicKeys,
    boolean isPostviewSupported,
    boolean isCaptureProgressSupported,
    @NonNull Map<@NonNull Integer, @NonNull Set<@NonNull Size>> outputSizesFormat,
    @NonNull Map<@NonNull Class<@NonNull ?>, @NonNull Set<@NonNull Size>> outputSizesClass,
    @NonNull Map<@NonNull Pair<@NonNull Size, @NonNull Integer>, @NonNull Set<@NonNull Size>> postviewSizes,
    @NonNull Map<@NonNull Pair<@NonNull Size, @NonNull Integer>, Range<@NonNull Long>> latencies
)

Creates a FakeCameraExtensionCharacteristics instance.

This method is designed for Java interop. It takes a raw string for the camera ID and supports default parameters in Java via @JvmOverloads.

Parameters
@NonNull String cameraId

the camera ID string (defaults to FakeCameraIds.default).

int cameraExtension

the extension mode (defaults to CameraExtensionCharacteristics.EXTENSION_AUTOMATIC).

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

the mock characteristics map.

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

the mock metadata map.

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

the supported capture request keys.

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

the supported capture result keys.

boolean isRestricted

whether the extension is restricted.

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

the restricted characteristics keys.

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

the dynamic characteristics keys.

boolean isPostviewSupported

whether postview is supported.

boolean isCaptureProgressSupported

whether capture progress is supported.

@NonNull Map<@NonNull Integer, @NonNull Set<@NonNull Size>> outputSizesFormat

mock output sizes map keyed by format.

@NonNull Map<@NonNull Class<@NonNull ?>, @NonNull Set<@NonNull Size>> outputSizesClass

mock output sizes map keyed by class.

@NonNull Map<@NonNull Pair<@NonNull Size, @NonNull Integer>, @NonNull Set<@NonNull Size>> postviewSizes

mock postview sizes map keyed by capture size and format.

@NonNull Map<@NonNull Pair<@NonNull Size, @NonNull Integer>, Range<@NonNull Long>> latencies

mock latencies map keyed by capture size and format.

get

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

Retrieves the mock characteristics value for the given key.

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

the characteristics key.

Returns
T

the mock value, or null if not set.

get

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

Retrieves the mock metadata value for the given key.

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

the metadata key.

Returns
T

the mock value, or null if not set.

getCameraExtension

Added in 1.7.0-alpha03
public int getCameraExtension()

The camera extension mode represented by this characteristics instance.

Value is one of the native camera extension constants defined in CameraExtensionCharacteristics (e.g., CameraExtensionCharacteristics.EXTENSION_BOKEH, CameraExtensionCharacteristics.EXTENSION_HDR, CameraExtensionCharacteristics.EXTENSION_NIGHT, CameraExtensionCharacteristics.EXTENSION_FACE_RETOUCH, or CameraExtensionCharacteristics.EXTENSION_AUTOMATIC).

getCameraId

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

The ID of the camera device associated with these extension characteristics.

getCaptureRequestKeys

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

The set of capture request keys supported by this camera extension.

See also
CameraExtensionCharacteristics

#getAvailableCaptureRequestKeys

getCaptureResultKeys

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

The set of capture result keys supported by this camera extension.

See also
CameraExtensionCharacteristics

#getAvailableCaptureResultKeys

getDynamicKeys

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

The set of camera characteristics keys that are dynamically updated for this extension.

getEstimatedCaptureLatencyRangeMillis

Added in 1.7.0-alpha03
public Range<@NonNull LonggetEstimatedCaptureLatencyRangeMillis(
    @NonNull Size captureSize,
    int imageFormat
)

Returns the mock estimated capture latency range in milliseconds for the given capture size and format.

Parameters
@NonNull Size captureSize

the capture size.

int imageFormat

the image format.

Returns
Range<@NonNull Long>

the configured latency range, or null.

getKeys

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

The supported CameraCharacteristics.Keys defined in the mock characteristics map.

getMetadataKeys

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

The supported Metadata.Keys defined in the mock metadata map.

getOrDefault

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

Retrieves the mock characteristics value for the given key, returning the default if not set.

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

the characteristics key.

@NonNull T default

the default value to return if the key is not set.

Returns
@NonNull T

the mock value, or the default value.

getOutputSizes

Added in 1.7.0-alpha03
public @NonNull Set<@NonNull SizegetOutputSizes(int imageFormat)

Returns the mock output sizes for the given image format.

Parameters
int imageFormat

the image format.

Returns
@NonNull Set<@NonNull Size>

the set of configured output sizes.

getOutputSizes

Added in 1.7.0-alpha03
public @NonNull Set<@NonNull SizegetOutputSizes(@NonNull Class<@NonNull ?> klass)

Returns the mock output sizes for the given output class.

Parameters
@NonNull Class<@NonNull ?> klass

the output class.

Returns
@NonNull Set<@NonNull Size>

the set of configured output sizes.

getPostviewSizes

Added in 1.7.0-alpha03
public @NonNull Set<@NonNull SizegetPostviewSizes(@NonNull Size captureSize, int format)

Returns the mock postview sizes for the given capture size and format.

Parameters
@NonNull Size captureSize

the capture size.

int format

the image format.

Returns
@NonNull Set<@NonNull Size>

the set of configured postview sizes.

getRestrictedKeys

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

The set of camera characteristics keys that require specific permissions to be accessed.

isCaptureProgressSupported

Added in 1.7.0-alpha03
public boolean isCaptureProgressSupported()

Whether capture progress callbacks are supported for this extension mode.

If true, capture requests can report progress updates during the extension processing.

See also
CameraExtensionCharacteristics

#isCaptureProcessProgressSupported

isPostviewSupported

Added in 1.7.0-alpha03
public boolean isPostviewSupported()

Whether postview is supported for this extension mode.

A postview is a quickly available, lower-resolution preview of the captured image that can be displayed while the final high-quality capture is processing.

See also
CameraExtensionCharacteristics

#isPostviewSupported

isRestricted

Added in 1.7.0-alpha03
public boolean isRestricted()

Whether access to some camera characteristics keys is restricted due to camera permissions.

If true, querying restricted keys via get or getOrDefault may return null or default values, matching the behavior of restricted extension modes when CAMERA permission is not granted.

unwrapAs

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

Unwraps this instance as the requested type if compatible.

Implements UnsafeWrapper.unwrapAs.

Parameters
@NonNull Class<@NonNull T> type

the class of the expected type.

Returns
T

this instance cast to T if compatible, or null.