UnsafeWrapper


public interface UnsafeWrapper

Known direct subclasses
CameraCharacteristicsMetadata

An interface that provides compatibility-focused, read-only query access to CameraCharacteristics.

CameraExtensionCharacteristicsWrapper

Compatibility wrapper around CameraExtensionCharacteristics.

CaptureRequestMetadata

An interface that provides compatibility-focused, read-only query access to the settings applied to a camera capture request.

CaptureResultMetadata

An interface that provides compatibility-focused, read-only query access to the results of a single image capture.

ColorSpaceProfilesWrapper

A compatibility wrapper for color space profiles.

DynamicRangeProfilesWrapper

Provides compatibility-focused access to android.hardware.camera2.params.DynamicRangeProfiles.

ImagePlane

A wrapper interface that mirrors Image.Plane.

ImageWrapper

A wrapper interface that mirrors the primary read-only properties of Image.

StreamConfigurationMapWrapper

A compatibility wrapper for android.hardware.camera2.params.StreamConfigurationMap.

Known indirect subclasses
CameraCharacteristicsWrapper

Wrapper interface providing compatibility-focused access to CameraCharacteristics.

CameraExtensionCharacteristicsWrapper

Compatibility wrapper around CameraExtensionCharacteristics.

CaptureRequestWrapper

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

CaptureResultWrapper

A wrapper interface providing compatibility-focused access to CaptureResult and custom metadata.

FakeCameraCharacteristics

A fake implementation of CameraCharacteristicsWrapper for testing.

FakeCameraExtensionCharacteristics

A fake implementation of CameraExtensionCharacteristicsWrapper for testing.

FakeCaptureRequest

A fake implementation of CaptureRequestWrapper designed for unit testing.

FakeCaptureResult

A fake implementation of CaptureResultWrapper for testing.

FakeColorSpaceProfiles

A fake implementation of ColorSpaceProfilesWrapper for testing.

FakeDynamicRangeProfiles

A fake implementation of DynamicRangeProfilesWrapper for testing.

FakeImagePlane

Fake implementation of ImagePlane for testing classes that consume camera image planes.

FakeImage

Fake implementation of MutableImageWrapper for testing.

FakeStreamConfigurationMap

A fake implementation of StreamConfigurationMapWrapper for testing.

ImageProxy.PlaneProxy

A plane proxy which has an analogous interface as android.media.Image.Plane.

ImageProxy

An image proxy which has a similar interface as android.media.Image.

MutableImageWrapper

A mutable extension of ImageWrapper that allows modifying properties of the image.


An interface for wrapper objects that hide underlying platform or implementation-specific types.

Classes implementing this interface wrap an underlying object (typically an Android platform type) and provide a mechanism to retrieve that object directly.

Usage Warning

Direct access to the underlying object bypasses the wrapper's management and abstraction. This is unsafe and should be done with caution:

  • Lifecycle Management: The library may manage the lifetime of the underlying object (e.g., closing or recycling it). Interacting with the unwrapped object outside the wrapper's control can lead to undefined behavior or crashes.

  • State Consistency: Modifying the state of the underlying object directly may cause the wrapper to become out of sync or behave unpredictably.

  • Test Compatibility: Test doubles (fakes, mocks) of the wrapper will typically return null when unwrapped. Code that relies on successful unwrapping may be harder to test.

Use this interface only when interoperability with other APIs requires the raw platform type, or as a temporary workaround for missing functionality in the wrapper API.

Summary

Public methods

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

Attempts to unwrap this object into the specified underlying type.

Extension functions

default final T

Inline extension function to attempt to unwrap this object into the reified type T.

Public methods

unwrapAs

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

Attempts to unwrap this object into the specified underlying type.

Callers should use this method to retrieve the wrapped platform object.

Implementation Notes

  • If the requested type is not supported by this wrapper, this method must return null.

  • Implementations designed for testing (e.g., fakes, mocks, or no-op wrappers) should return null to signal that no real underlying object is available.

Parameters
<T extends Object>

The expected type of the underlying object.

@NonNull Class<@NonNull T> type

The Class representing the expected type of the underlying object.

Returns
T

The underlying object cast to T, or null if the object cannot be unwrapped into the requested type.

Extension functions

UnsafeWrappers.unwrapAs

default final T <T extends Object> UnsafeWrappers.unwrapAs(@NonNull UnsafeWrapper receiver)

Inline extension function to attempt to unwrap this object into the reified type T.

This is a Kotlin-friendly helper for UnsafeWrapper.unwrapAs.

Parameters
<T extends Object>

The expected type of the underlying object.

Returns
T

The underlying object cast to T, or null if the object cannot be unwrapped.

See also
unwrapAs