CaptureRequestWrapper


public interface CaptureRequestWrapper extends CaptureRequestMetadata

Known direct subclasses
FakeCaptureRequest

A fake implementation of CaptureRequestWrapper designed for unit testing.


A wrapper interface representing the settings applied to a specific camera capture request.

This interface provides a unified way to inspect the configuration parameters sent to the camera device during a capture session. It supports querying:

  1. Native Camera2 capture request keys via CaptureRequest.Key (using get).

  2. Extension or custom metadata keys via Metadata.Key (using Metadata.get, inherited from Metadata).

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

import androidx.camera.common.CaptureRequestWrapper
import androidx.camera.common.CaptureRequestWrappers
import androidx.camera.common.Metadata

// Wrap a native CaptureRequest into a CaptureRequestWrapper.
val requestWrapper: CaptureRequestWrapper = CaptureRequestWrappers.wrap(captureRequest)

// Query native Camera2 CaptureRequest keys:
val aeMode = requestWrapper[CaptureRequest.CONTROL_AE_MODE]

// Or attach custom library/application metadata to the request:
val customKey = Metadata.Key<String>("com.example.custom_request_tag")
val requestWithMetadata =
    CaptureRequestWrappers.wrap(
        captureRequest,
        metadata = mapOf(customKey to "sample_tag_value"),
    )
val customTagValue = requestWithMetadata[customKey]
import androidx.camera.common.CaptureRequestWrapper
import androidx.camera.common.Metadata
import androidx.camera.common.testing.FakeCaptureRequest

val customKey = Metadata.Key<Int>("com.example.custom_request_priority")

// Create a FakeCaptureRequest for unit testing without requiring a Camera2 device.
val fakeRequest: CaptureRequestWrapper =
    FakeCaptureRequest(
        requestParameters =
            mapOf(
                CaptureRequest.CONTROL_AE_MODE to CaptureRequest.CONTROL_AE_MODE_ON,
                CaptureRequest.CONTROL_AF_MODE to
                    CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE,
            ),
        requestMetadata = mapOf(customKey to 1),
    )

// Query values from the fake request in test assertions:
val aeMode = fakeRequest[CaptureRequest.CONTROL_AE_MODE]
val priority = fakeRequest[customKey]

Summary

Public methods

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

The list of all CaptureRequest.Keys that are set or supported by this capture request.

Inherited methods

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

Retrieves the value of the specified CaptureRequest.Key.

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

Retrieves the value of the specified CaptureRequest.Key, or returns default if the key is not present or its value is null.

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

getKeys

Added in 1.7.0-rc01
abstract @NonNull List<@NonNull CaptureRequest.Key<@NonNull ?>> getKeys()

The list of all CaptureRequest.Keys that are set or supported by this capture request.

See also
getKeys