FakeCameraExtensionCharacteristics


class FakeCameraExtensionCharacteristics : 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

Public companion functions

FakeCameraExtensionCharacteristics
create(
    cameraId: String,
    cameraExtension: Int,
    cameraCharacteristics: Map<CameraCharacteristics.Key<*>, Any?>,
    cameraMetadata: Map<Metadata.Key<*>, Any?>,
    captureRequestKeys: Set<CaptureRequest.Key<*>>,
    captureResultKeys: Set<CaptureResult.Key<*>>,
    isRestricted: Boolean,
    restrictedKeys: Set<CameraCharacteristics.Key<*>>,
    dynamicKeys: Set<CameraCharacteristics.Key<*>>,
    isPostviewSupported: Boolean,
    isCaptureProgressSupported: Boolean,
    outputSizesFormat: Map<IntSet<Size>>,
    outputSizesClass: Map<Class<*>, Set<Size>>,
    postviewSizes: Map<Pair<SizeInt>, Set<Size>>,
    latencies: Map<Pair<SizeInt>, Range<Long>?>
)

Creates a FakeCameraExtensionCharacteristics instance.

operator FakeCameraExtensionCharacteristics
invoke(
    cameraId: CameraId,
    cameraExtension: Int,
    cameraCharacteristics: Map<CameraCharacteristics.Key<*>, Any?>,
    cameraMetadata: Map<Metadata.Key<*>, Any?>,
    captureRequestKeys: Set<CaptureRequest.Key<*>>,
    captureResultKeys: Set<CaptureResult.Key<*>>,
    isRestricted: Boolean,
    restrictedKeys: Set<CameraCharacteristics.Key<*>>,
    dynamicKeys: Set<CameraCharacteristics.Key<*>>,
    isPostviewSupported: Boolean,
    isCaptureProgressSupported: Boolean,
    outputSizesFormat: Map<IntSet<Size>>,
    outputSizesClass: Map<Class<*>, Set<Size>>,
    postviewSizes: Map<Pair<SizeInt>, Set<Size>>,
    latencies: Map<Pair<SizeInt>, Range<Long>?>
)

Creates a FakeCameraExtensionCharacteristics instance.

Public functions

open operator T?

Retrieves the mock characteristics value for the given key.

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

Retrieves the mock metadata value for the given key.

open Range<Long>?
getEstimatedCaptureLatencyRangeMillis(
    captureSize: Size,
    imageFormat: Int
)

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

open T
<T : Any> getOrDefault(key: CameraCharacteristics.Key<T>, default: T)

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

open Set<Size>
getOutputSizes(imageFormat: Int)

Returns the mock output sizes for the given image format.

open Set<Size>
getOutputSizes(klass: Class<*>)

Returns the mock output sizes for the given output class.

open Set<Size>
getPostviewSizes(captureSize: Size, format: Int)

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

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

Unwraps this instance as the requested type if compatible.

Public properties

open Int

The camera extension mode represented by this characteristics instance.

open CameraId

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

open Set<CaptureRequest.Key<*>>

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

open Set<CaptureResult.Key<*>>

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

open Set<CameraCharacteristics.Key<*>>

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

open Boolean

Whether capture progress callbacks are supported for this extension mode.

open Boolean

Whether postview is supported for this extension mode.

open Boolean

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

open Set<CameraCharacteristics.Key<*>>

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

open Set<Metadata.Key<*>>

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

open Set<CameraCharacteristics.Key<*>>

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

Inherited functions

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,
    cameraExtension: Int = CameraExtensionCharacteristics.EXTENSION_AUTOMATIC,
    cameraCharacteristics: Map<CameraCharacteristics.Key<*>, Any?> = emptyMap(),
    cameraMetadata: Map<Metadata.Key<*>, Any?> = emptyMap(),
    captureRequestKeys: Set<CaptureRequest.Key<*>> = emptySet(),
    captureResultKeys: Set<CaptureResult.Key<*>> = emptySet(),
    isRestricted: Boolean = false,
    restrictedKeys: Set<CameraCharacteristics.Key<*>> = emptySet(),
    dynamicKeys: Set<CameraCharacteristics.Key<*>> = emptySet(),
    isPostviewSupported: Boolean = false,
    isCaptureProgressSupported: Boolean = false,
    outputSizesFormat: Map<IntSet<Size>> = emptyMap(),
    outputSizesClass: Map<Class<*>, Set<Size>> = emptyMap(),
    postviewSizes: Map<Pair<SizeInt>, Set<Size>> = emptyMap(),
    latencies: Map<Pair<SizeInt>, Range<Long>?> = emptyMap()
): FakeCameraExtensionCharacteristics

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
cameraId: String = FakeCameraIds.default.value

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

cameraExtension: Int = CameraExtensionCharacteristics.EXTENSION_AUTOMATIC

the extension mode (defaults to CameraExtensionCharacteristics.EXTENSION_AUTOMATIC).

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

the mock characteristics map.

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

the mock metadata map.

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

the supported capture request keys.

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

the supported capture result keys.

isRestricted: Boolean = false

whether the extension is restricted.

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

the restricted characteristics keys.

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

the dynamic characteristics keys.

isPostviewSupported: Boolean = false

whether postview is supported.

isCaptureProgressSupported: Boolean = false

whether capture progress is supported.

outputSizesFormat: Map<IntSet<Size>> = emptyMap()

mock output sizes map keyed by format.

outputSizesClass: Map<Class<*>, Set<Size>> = emptyMap()

mock output sizes map keyed by class.

postviewSizes: Map<Pair<SizeInt>, Set<Size>> = emptyMap()

mock postview sizes map keyed by capture size and format.

latencies: Map<Pair<SizeInt>, Range<Long>?> = emptyMap()

mock latencies map keyed by capture size and format.

invoke

Added in 1.7.0-alpha03
operator fun invoke(
    cameraId: CameraId = FakeCameraIds.default,
    cameraExtension: Int = CameraExtensionCharacteristics.EXTENSION_AUTOMATIC,
    cameraCharacteristics: Map<CameraCharacteristics.Key<*>, Any?> = emptyMap(),
    cameraMetadata: Map<Metadata.Key<*>, Any?> = emptyMap(),
    captureRequestKeys: Set<CaptureRequest.Key<*>> = emptySet(),
    captureResultKeys: Set<CaptureResult.Key<*>> = emptySet(),
    isRestricted: Boolean = false,
    restrictedKeys: Set<CameraCharacteristics.Key<*>> = emptySet(),
    dynamicKeys: Set<CameraCharacteristics.Key<*>> = emptySet(),
    isPostviewSupported: Boolean = false,
    isCaptureProgressSupported: Boolean = false,
    outputSizesFormat: Map<IntSet<Size>> = emptyMap(),
    outputSizesClass: Map<Class<*>, Set<Size>> = emptyMap(),
    postviewSizes: Map<Pair<SizeInt>, Set<Size>> = emptyMap(),
    latencies: Map<Pair<SizeInt>, Range<Long>?> = emptyMap()
): FakeCameraExtensionCharacteristics

Creates a FakeCameraExtensionCharacteristics instance.

This operator is designed for Kotlin usage. It supports the type-safe CameraId value class and default arguments.

Parameters
cameraId: CameraId = FakeCameraIds.default

the camera ID (defaults to FakeCameraIds.default).

cameraExtension: Int = CameraExtensionCharacteristics.EXTENSION_AUTOMATIC

the extension mode (defaults to CameraExtensionCharacteristics.EXTENSION_AUTOMATIC).

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

the mock characteristics map.

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

the mock metadata map.

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

the supported capture request keys.

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

the supported capture result keys.

isRestricted: Boolean = false

whether the extension is restricted.

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

the restricted characteristics keys.

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

the dynamic characteristics keys.

isPostviewSupported: Boolean = false

whether postview is supported.

isCaptureProgressSupported: Boolean = false

whether capture progress is supported.

outputSizesFormat: Map<IntSet<Size>> = emptyMap()

mock output sizes map keyed by format.

outputSizesClass: Map<Class<*>, Set<Size>> = emptyMap()

mock output sizes map keyed by class.

postviewSizes: Map<Pair<SizeInt>, Set<Size>> = emptyMap()

mock postview sizes map keyed by capture size and format.

latencies: Map<Pair<SizeInt>, Range<Long>?> = emptyMap()

mock latencies map keyed by capture size and format.

Public functions

get

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

Retrieves the mock characteristics value for the given key.

Parameters
key: CameraCharacteristics.Key<T>

the characteristics key.

Returns
T?

the mock value, or null if not set.

get

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

Retrieves the mock metadata value for the given key.

Parameters
key: Metadata.Key<T>

the metadata key.

Returns
T?

the mock value, or null if not set.

getEstimatedCaptureLatencyRangeMillis

Added in 1.7.0-alpha03
open fun getEstimatedCaptureLatencyRangeMillis(
    captureSize: Size,
    imageFormat: Int
): Range<Long>?

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

Parameters
captureSize: Size

the capture size.

imageFormat: Int

the image format.

Returns
Range<Long>?

the configured latency range, or null.

getOrDefault

open fun <T : Any> getOrDefault(key: CameraCharacteristics.Key<T>, default: T): T

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

Parameters
key: CameraCharacteristics.Key<T>

the characteristics key.

default: T

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

Returns
T

the mock value, or the default value.

getOutputSizes

Added in 1.7.0-alpha03
open fun getOutputSizes(imageFormat: Int): Set<Size>

Returns the mock output sizes for the given image format.

Parameters
imageFormat: Int

the image format.

Returns
Set<Size>

the set of configured output sizes.

getOutputSizes

Added in 1.7.0-alpha03
open fun getOutputSizes(klass: Class<*>): Set<Size>

Returns the mock output sizes for the given output class.

Parameters
klass: Class<*>

the output class.

Returns
Set<Size>

the set of configured output sizes.

getPostviewSizes

Added in 1.7.0-alpha03
open fun getPostviewSizes(captureSize: Size, format: Int): Set<Size>

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

Parameters
captureSize: Size

the capture size.

format: Int

the image format.

Returns
Set<Size>

the set of configured postview sizes.

unwrapAs

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

Unwraps this instance as the requested type if compatible.

Implements UnsafeWrapper.unwrapAs.

Parameters
type: Class<T>

the class of the expected type.

Returns
T?

this instance cast to T if compatible, or null.

Public properties

cameraExtension

Added in 1.7.0-alpha03
open val cameraExtensionInt

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).

cameraId

Added in 1.7.0-alpha03
open val cameraIdCameraId

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

captureRequestKeys

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

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

See also
CameraExtensionCharacteristics

#getAvailableCaptureRequestKeys

captureResultKeys

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

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

See also
CameraExtensionCharacteristics

#getAvailableCaptureResultKeys

dynamicKeys

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

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

isCaptureProgressSupported

Added in 1.7.0-alpha03
open val isCaptureProgressSupportedBoolean

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
open val isPostviewSupportedBoolean

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
open val isRestrictedBoolean

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.

keys

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

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

metadataKeys

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

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

restrictedKeys

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

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