# UnsafeWrapper

Artifact: [androidx.camera:camera-common](https://developer.android.com/jetpack/androidx/releases/camera) [View Source](https://cs.android.com/search?q=file:androidx/camera/common/UnsafeWrapper.kt+class:androidx.camera.common.UnsafeWrapper) Added in [1.7.0-rc02](https://developer.android.com/jetpack/androidx/releases/camera#1.7.0-rc02)

*** ** * ** ***


```
interface UnsafeWrapper
```

<br />

Known direct subclasses [CameraCharacteristicsMetadata](https://developer.android.com/reference/kotlin/androidx/camera/common/CameraCharacteristicsMetadata), [CameraExtensionCharacteristicsWrapper](https://developer.android.com/reference/kotlin/androidx/camera/common/CameraExtensionCharacteristicsWrapper), [CaptureRequestMetadata](https://developer.android.com/reference/kotlin/androidx/camera/common/CaptureRequestMetadata), [CaptureResultMetadata](https://developer.android.com/reference/kotlin/androidx/camera/common/CaptureResultMetadata), [ColorSpaceProfilesWrapper](https://developer.android.com/reference/kotlin/androidx/camera/common/ColorSpaceProfilesWrapper), [DynamicRangeProfilesWrapper](https://developer.android.com/reference/kotlin/androidx/camera/common/DynamicRangeProfilesWrapper), [ImagePlane](https://developer.android.com/reference/kotlin/androidx/camera/common/ImagePlane), [ImageWrapper](https://developer.android.com/reference/kotlin/androidx/camera/common/ImageWrapper), [StreamConfigurationMapWrapper](https://developer.android.com/reference/kotlin/androidx/camera/common/StreamConfigurationMapWrapper)

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/common/CameraCharacteristicsMetadata` | An interface that provides compatibility-focused, read-only query access to `https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics.html`. |
| `https://developer.android.com/reference/kotlin/androidx/camera/common/CameraExtensionCharacteristicsWrapper` | Compatibility wrapper around `https://developer.android.com/reference/android/hardware/camera2/CameraExtensionCharacteristics.html`. |
| `https://developer.android.com/reference/kotlin/androidx/camera/common/CaptureRequestMetadata` | An interface that provides compatibility-focused, read-only query access to the settings applied to a camera capture request. |
| `https://developer.android.com/reference/kotlin/androidx/camera/common/CaptureResultMetadata` | An interface that provides compatibility-focused, read-only query access to the results of a single image capture. |
| `https://developer.android.com/reference/kotlin/androidx/camera/common/ColorSpaceProfilesWrapper` | A compatibility wrapper for color space profiles. |
| `https://developer.android.com/reference/kotlin/androidx/camera/common/DynamicRangeProfilesWrapper` | Provides compatibility-focused access to `https://developer.android.com/reference/android/hardware/camera2/params/DynamicRangeProfiles.html`. |
| `https://developer.android.com/reference/kotlin/androidx/camera/common/ImagePlane` | A wrapper interface that mirrors `https://developer.android.com/reference/android/media/Image.Plane.html`. |
| `https://developer.android.com/reference/kotlin/androidx/camera/common/ImageWrapper` | A wrapper interface that mirrors the primary read-only properties of `https://developer.android.com/reference/android/media/Image.html`. |
| `https://developer.android.com/reference/kotlin/androidx/camera/common/StreamConfigurationMapWrapper` | A compatibility wrapper for `https://developer.android.com/reference/android/hardware/camera2/params/StreamConfigurationMap.html`. |

Known indirect subclasses [CameraCharacteristicsWrapper](https://developer.android.com/reference/kotlin/androidx/camera/common/CameraCharacteristicsWrapper), [CameraExtensionCharacteristicsWrapper](https://developer.android.com/reference/kotlin/androidx/camera/common/CameraExtensionCharacteristicsWrapper), [CaptureRequestWrapper](https://developer.android.com/reference/kotlin/androidx/camera/common/CaptureRequestWrapper), [CaptureResultWrapper](https://developer.android.com/reference/kotlin/androidx/camera/common/CaptureResultWrapper), [FakeCameraCharacteristics](https://developer.android.com/reference/kotlin/androidx/camera/common/testing/FakeCameraCharacteristics), [FakeCameraExtensionCharacteristics](https://developer.android.com/reference/kotlin/androidx/camera/common/testing/FakeCameraExtensionCharacteristics), [FakeCaptureRequest](https://developer.android.com/reference/kotlin/androidx/camera/common/testing/FakeCaptureRequest), [FakeCaptureResult](https://developer.android.com/reference/kotlin/androidx/camera/common/testing/FakeCaptureResult), [FakeColorSpaceProfiles](https://developer.android.com/reference/kotlin/androidx/camera/common/testing/FakeColorSpaceProfiles), [FakeDynamicRangeProfiles](https://developer.android.com/reference/kotlin/androidx/camera/common/testing/FakeDynamicRangeProfiles), [FakeImagePlane](https://developer.android.com/reference/kotlin/androidx/camera/common/testing/FakeImagePlane), [FakeImage](https://developer.android.com/reference/kotlin/androidx/camera/common/testing/FakeImage), [FakeStreamConfigurationMap](https://developer.android.com/reference/kotlin/androidx/camera/common/testing/FakeStreamConfigurationMap), [ImageProxy.PlaneProxy](https://developer.android.com/reference/kotlin/androidx/camera/core/ImageProxy.PlaneProxy), [ImageProxy](https://developer.android.com/reference/kotlin/androidx/camera/core/ImageProxy), [MutableImageWrapper](https://developer.android.com/reference/kotlin/androidx/camera/common/MutableImageWrapper)

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/common/CameraCharacteristicsWrapper` | Wrapper interface providing compatibility-focused access to `https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics.html`. |
| `https://developer.android.com/reference/kotlin/androidx/camera/common/CameraExtensionCharacteristicsWrapper` | Compatibility wrapper around `https://developer.android.com/reference/android/hardware/camera2/CameraExtensionCharacteristics.html`. |
| `https://developer.android.com/reference/kotlin/androidx/camera/common/CaptureRequestWrapper` | A wrapper interface representing the settings applied to a specific camera capture request. |
| `https://developer.android.com/reference/kotlin/androidx/camera/common/CaptureResultWrapper` | A wrapper interface providing compatibility-focused access to `https://developer.android.com/reference/android/hardware/camera2/CaptureResult.html` and custom metadata. |
| `https://developer.android.com/reference/kotlin/androidx/camera/common/testing/FakeCameraCharacteristics` | A fake implementation of `https://developer.android.com/reference/kotlin/androidx/camera/common/CameraCharacteristicsWrapper` for testing. |
| `https://developer.android.com/reference/kotlin/androidx/camera/common/testing/FakeCameraExtensionCharacteristics` | A fake implementation of `https://developer.android.com/reference/kotlin/androidx/camera/common/CameraExtensionCharacteristicsWrapper` for testing. |
| `https://developer.android.com/reference/kotlin/androidx/camera/common/testing/FakeCaptureRequest` | A fake implementation of `https://developer.android.com/reference/kotlin/androidx/camera/common/CaptureRequestWrapper` designed for unit testing. |
| `https://developer.android.com/reference/kotlin/androidx/camera/common/testing/FakeCaptureResult` | A fake implementation of `https://developer.android.com/reference/kotlin/androidx/camera/common/CaptureResultWrapper` for testing. |
| `https://developer.android.com/reference/kotlin/androidx/camera/common/testing/FakeColorSpaceProfiles` | A fake implementation of `https://developer.android.com/reference/kotlin/androidx/camera/common/ColorSpaceProfilesWrapper` for testing. |
| `https://developer.android.com/reference/kotlin/androidx/camera/common/testing/FakeDynamicRangeProfiles` | A fake implementation of `https://developer.android.com/reference/kotlin/androidx/camera/common/DynamicRangeProfilesWrapper` for testing. |
| `https://developer.android.com/reference/kotlin/androidx/camera/common/testing/FakeImagePlane` | Fake implementation of `https://developer.android.com/reference/kotlin/androidx/camera/common/ImagePlane` for testing classes that consume camera image planes. |
| `https://developer.android.com/reference/kotlin/androidx/camera/common/testing/FakeImage` | Fake implementation of `https://developer.android.com/reference/kotlin/androidx/camera/common/MutableImageWrapper` for testing. |
| `https://developer.android.com/reference/kotlin/androidx/camera/common/testing/FakeStreamConfigurationMap` | A fake implementation of `https://developer.android.com/reference/kotlin/androidx/camera/common/StreamConfigurationMapWrapper` for testing. |
| `https://developer.android.com/reference/kotlin/androidx/camera/core/ImageProxy.PlaneProxy` | A plane proxy which has an analogous interface as `https://developer.android.com/reference/android/media/Image.Plane.html`. |
| `https://developer.android.com/reference/kotlin/androidx/camera/core/ImageProxy` | An image proxy which has a similar interface as `https://developer.android.com/reference/android/media/Image.html`. |
| `https://developer.android.com/reference/kotlin/androidx/camera/common/MutableImageWrapper` | A mutable extension of `https://developer.android.com/reference/kotlin/androidx/camera/common/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 functions |
|---|---|
| `T?` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html> https://developer.android.com/reference/kotlin/androidx/camera/common/UnsafeWrapper#unwrapAs(java.lang.Class)(type: https://developer.android.com/reference/java/lang/Class.html<T>)` Attempts to unwrap this object into the specified underlying `https://developer.android.com/reference/kotlin/androidx/camera/common/UnsafeWrapper#unwrapAs(java.lang.Class)`. |

| ### Extension functions |
|---|---|
| `inline T?` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html> https://developer.android.com/reference/kotlin/androidx/camera/common/UnsafeWrapper.https://developer.android.com/reference/kotlin/androidx/camera/common/UnsafeWrapper#(androidx.camera.common.UnsafeWrapper).unwrapAs()()` Inline extension function to attempt to unwrap this object into the reified type `https://developer.android.com/reference/kotlin/androidx/camera/common/package-summary#(androidx.camera.common.UnsafeWrapper).unwrapAs()`. |

## Public functions

### unwrapAs

Added in [1.7.0-rc02](https://developer.android.com/jetpack/androidx/releases/camera#1.7.0-rc02)

```
fun <T : Any> unwrapAs(type: Class<T>): T?
```

Attempts to unwrap this object into the specified underlying `https://developer.android.com/reference/kotlin/androidx/camera/common/UnsafeWrapper#unwrapAs(java.lang.Class)`.

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

### Implementation Notes

- If the requested `https://developer.android.com/reference/kotlin/androidx/camera/common/UnsafeWrapper#unwrapAs(java.lang.Class)` 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 : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html>` | The expected type of the underlying object. |
| `type: https://developer.android.com/reference/java/lang/Class.html<T>` | The `https://developer.android.com/reference/java/lang/Class.html` representing the expected type of the underlying object. |

| Returns |
|---|---|
| `T?` | The underlying object cast to `https://developer.android.com/reference/kotlin/androidx/camera/common/UnsafeWrapper#unwrapAs(java.lang.Class)`, or `null` if the object cannot be unwrapped into the requested `https://developer.android.com/reference/kotlin/androidx/camera/common/UnsafeWrapper#unwrapAs(java.lang.Class)`. |

## Extension functions

### UnsafeWrapper.unwrapAs

Artifact: [androidx.camera:camera-common](https://developer.android.com/jetpack/androidx/releases/camera) [View Source](https://cs.android.com/search?q=file:androidx/camera/common/UnsafeWrapper.kt+function:unwrapAs)

```
inline fun <T : Any> UnsafeWrapper.unwrapAs(): T?
```

Inline extension function to attempt to unwrap this object into the reified type `https://developer.android.com/reference/kotlin/androidx/camera/common/package-summary#(androidx.camera.common.UnsafeWrapper).unwrapAs()`.

This is a Kotlin-friendly helper for `https://developer.android.com/reference/kotlin/androidx/camera/common/UnsafeWrapper#unwrapAs(java.lang.Class)`.

| Parameters |
|---|---|
| `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html>` | The expected type of the underlying object. |

| Returns |
|---|---|
| `T?` | The underlying object cast to `https://developer.android.com/reference/kotlin/androidx/camera/common/package-summary#(androidx.camera.common.UnsafeWrapper).unwrapAs()`, or `null` if the object cannot be unwrapped. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/common/UnsafeWrapper#unwrapAs(java.lang.Class)` |   |