# ExtensionsManager

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

*** ** * ** ***


```
class ExtensionsManager
```

<br />

*** ** * ** ***

Provides interfaces for third party app developers to get capabilities info of extension functions.

Many Android devices contain powerful cameras, with manufacturers devoting a lot of effort to build many cutting-edge features, or special effects, into these camera devices. `CameraX Extensions` allows third party apps to enable the available extension modes on the supported devices. The extension modes which might be supported via `CameraX Extensions` are `https://developer.android.com/reference/kotlin/androidx/camera/extensions/ExtensionMode#BOKEH()`, `https://developer.android.com/reference/kotlin/androidx/camera/extensions/ExtensionMode#HDR()`, `https://developer.android.com/reference/kotlin/androidx/camera/extensions/ExtensionMode#NIGHT()`, `https://developer.android.com/reference/kotlin/androidx/camera/extensions/ExtensionMode#FACE_RETOUCH()` and `https://developer.android.com/reference/kotlin/androidx/camera/extensions/ExtensionMode#AUTO()`. The known supported devices are listed in the [Supported devices](https://developer.android.com/training/camera/supported-devices) page.

`CameraX Extensions` are built on the top of `CameraX Core` libraries. To enable an extension mode, an `https://developer.android.com/reference/kotlin/androidx/camera/extensions/ExtensionsManager` instance needs to be retrieved first. For kotlin users, it is recommended to use `https://developer.android.com/reference/kotlin/androidx/camera/extensions/ExtensionsManager#getInstance(android.content.Context,androidx.camera.core.CameraProvider)` which is a suspend function. For Java users, please use `https://developer.android.com/reference/kotlin/androidx/camera/extensions/ExtensionsManager#getInstanceAsync(android.content.Context,androidx.camera.core.CameraProvider)`.

After retrieving the `https://developer.android.com/reference/kotlin/androidx/camera/extensions/ExtensionsManager` instance, the availability of a specific extension mode can be checked by `https://developer.android.com/reference/kotlin/androidx/camera/extensions/ExtensionsManager#isExtensionAvailable(androidx.camera.core.CameraSelector,kotlin.Int)`. For an available extension mode, an `https://developer.android.com/reference/kotlin/androidx/camera/extensions/ExtensionSessionConfig` can be created and bound to a camera using `https://developer.android.com/reference/kotlin/androidx/camera/lifecycle/ProcessCameraProvider#bindToLifecycle(androidx.lifecycle.LifecycleOwner,androidx.camera.core.CameraSelector,kotlin.Array)`. The extension mode will be applied to the bound `https://developer.android.com/reference/kotlin/androidx/camera/core/Preview` and `https://developer.android.com/reference/kotlin/androidx/camera/core/ImageCapture`. The following sample code describes how to enable an extension mode for use cases.

```kotlin
import androidx.camera.core.CameraSelector
import androidx.camera.core.ImageCapture
import androidx.camera.core.Preview
import androidx.camera.extensions.ExtensionMode
import androidx.camera.extensions.ExtensionSessionConfig
import androidx.camera.extensions.ExtensionsManager
import androidx.camera.lifecycle.ProcessCameraProvider
import androidx.camera.lifecycle.awaitInstance

// Create a camera provider.
val cameraProvider = ProcessCameraProvider.awaitInstance(context)

// Retrieve the ExtensionsManager instance.
val extensionsManager = ExtensionsManager.getInstance(context, cameraProvider)

val cameraSelector = CameraSelector.DEFAULT_BACK_CAMERA
// Query if extension is available.
if (extensionsManager.isExtensionAvailable(cameraSelector, ExtensionMode.BOKEH)) {
    // Create an ExtensionSessionConfig.
    val imageCapture = ImageCapture.Builder().build()
    val preview = Preview.Builder().build()
    val sessionConfig =
        ExtensionSessionConfig(ExtensionMode.BOKEH, extensionsManager, imageCapture, preview)
    cameraProvider.bindToLifecycle(lifecycleOwner, cameraSelector, sessionConfig)
}
```

Without enabling `CameraX Extensions`, any device should be able to support the use cases combination of `https://developer.android.com/reference/kotlin/androidx/camera/core/ImageCapture`, `https://developer.android.com/reference/kotlin/androidx/camera/core/Preview` and `https://developer.android.com/reference/kotlin/androidx/camera/core/ImageAnalysis`. To support the `CameraX Extensions` functionality, the `https://developer.android.com/reference/kotlin/androidx/camera/core/ImageCapture` or `https://developer.android.com/reference/kotlin/androidx/camera/core/Preview` might need to occupy a different format of stream. This might restrict the app to not be able to bind `https://developer.android.com/reference/kotlin/androidx/camera/core/ImageCapture`, `https://developer.android.com/reference/kotlin/androidx/camera/core/Preview` and `https://developer.android.com/reference/kotlin/androidx/camera/core/ImageAnalysis` at the same time if the device's hardware level is not `https://developer.android.com/reference/android/hardware/camera2/CameraMetadata.html#INFO_SUPPORTED_HARDWARE_LEVEL_FULL` or above. If enabling an extension mode is more important and the `https://developer.android.com/reference/kotlin/androidx/camera/core/ImageAnalysis` could be optional to the app design, the extension mode can be enabled successfully when only binding `https://developer.android.com/reference/kotlin/androidx/camera/core/ImageCapture`, `https://developer.android.com/reference/kotlin/androidx/camera/core/Preview` even if the device's hardware level is `https://developer.android.com/reference/android/hardware/camera2/CameraMetadata.html#INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED`.

While `CameraX Extensions` dose not directly support `https://developer.android.com/reference/kotlin/androidx/camera/video/VideoCapture`, `https://developer.android.com/reference/kotlin/androidx/camera/video/VideoCapture` can still be used when any extension mode is enabled. When the app binds `https://developer.android.com/reference/kotlin/androidx/camera/video/VideoCapture` and enables any extension mode, `https://developer.android.com/reference/kotlin/androidx/camera/video/VideoCapture` can obtain the shared stream of `https://developer.android.com/reference/kotlin/androidx/camera/core/Preview` and record it as a video.

For some devices, the vendor library implementation might only support a subset of the all supported sizes retrieved by `https://developer.android.com/reference/android/hardware/camera2/params/StreamConfigurationMap.html#getOutputSizes(int)`. `CameraX` will select the supported sizes for the use cases according to the use cases' configuration and combination.

## Summary

| ### Public companion functions |
|---|---|
| `suspend https://developer.android.com/reference/kotlin/androidx/camera/extensions/ExtensionsManager` | `https://developer.android.com/reference/kotlin/androidx/camera/extensions/ExtensionsManager#getInstance(android.content.Context,androidx.camera.core.CameraProvider)(context: https://developer.android.com/reference/android/content/Context.html, cameraProvider: https://developer.android.com/reference/kotlin/androidx/camera/core/CameraProvider)` Retrieves the `https://developer.android.com/reference/kotlin/androidx/camera/extensions/ExtensionsManager`. |
| `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/kotlin/androidx/camera/extensions/ExtensionsManager>` | `https://developer.android.com/reference/kotlin/androidx/camera/extensions/ExtensionsManager#getInstanceAsync(android.content.Context,androidx.camera.core.CameraProvider)(context: https://developer.android.com/reference/android/content/Context.html, cameraProvider: https://developer.android.com/reference/kotlin/androidx/camera/core/CameraProvider)` Retrieves the `https://developer.android.com/reference/kotlin/androidx/camera/extensions/ExtensionsManager` associated with the current process. |

| ### Public functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/extensions/CameraExtensionsControl?` | `https://developer.android.com/reference/kotlin/androidx/camera/extensions/ExtensionsManager#getCameraExtensionsControl(androidx.camera.core.CameraControl)(cameraControl: https://developer.android.com/reference/kotlin/androidx/camera/core/CameraControl)` Retrieves a `https://developer.android.com/reference/kotlin/androidx/camera/extensions/CameraExtensionsControl` object that allows customization of capture request settings for supported camera extensions. |
| `https://developer.android.com/reference/kotlin/androidx/camera/extensions/CameraExtensionsInfo` | `https://developer.android.com/reference/kotlin/androidx/camera/extensions/ExtensionsManager#getCameraExtensionsInfo(androidx.camera.core.CameraInfo)(cameraInfo: https://developer.android.com/reference/kotlin/androidx/camera/core/CameraInfo)` Retrieves a `https://developer.android.com/reference/kotlin/androidx/camera/extensions/CameraExtensionsInfo` object that allows to observe or monitor capture request settings and results for supported camera extensions. |
| `https://developer.android.com/reference/android/util/Range.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html>?` | `https://developer.android.com/reference/kotlin/androidx/camera/extensions/ExtensionsManager#getEstimatedCaptureLatencyRange(androidx.camera.core.CameraSelector,kotlin.Int)( cameraSelector: https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector, mode: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html )` Returns the estimated capture latency range in milliseconds for the target camera and extension mode. |
| `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector` | `[getExtensionEnabledCameraSelector](https://developer.android.com/reference/kotlin/androidx/camera/extensions/ExtensionsManager#getExtensionEnabledCameraSelector(androidx.camera.core.CameraSelector,kotlin.Int))( cameraSelector: https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector, mode: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html )` **This function is deprecated.** Use ExtensionSessionConfig instead. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/camera/extensions/ExtensionsManager#isExtensionAvailable(androidx.camera.core.CameraSelector,kotlin.Int)(cameraSelector: https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector, mode: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Checks if a specific extension mode is available for a given `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/camera/extensions/ExtensionsManager#isImageAnalysisSupported(androidx.camera.core.CameraSelector,kotlin.Int)(cameraSelector: https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector, mode: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Returns whether the given extension mode supports the `https://developer.android.com/reference/kotlin/androidx/camera/core/ImageAnalysis` use case on the camera specified by the given `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector`. |

## Public companion functions

### getInstance

```
suspend fun getInstance(context: Context, cameraProvider: CameraProvider): ExtensionsManager
```

Retrieves the `https://developer.android.com/reference/kotlin/androidx/camera/extensions/ExtensionsManager`.

| Parameters |
|---|---|
| `context: https://developer.android.com/reference/android/content/Context.html` | The application context. |
| `cameraProvider: https://developer.android.com/reference/kotlin/androidx/camera/core/CameraProvider` | A `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraProvider` will be used to query the information of cameras on the device. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/extensions/ExtensionsManager` | A fully initialized `https://developer.android.com/reference/kotlin/androidx/camera/extensions/ExtensionsManager` for the current process. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/extensions/ExtensionsManager#getInstanceAsync(android.content.Context,androidx.camera.core.CameraProvider)` |   |

### getInstanceAsync

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

```
fun getInstanceAsync(context: Context, cameraProvider: CameraProvider): ListenableFuture<ExtensionsManager>
```

Retrieves the `https://developer.android.com/reference/kotlin/androidx/camera/extensions/ExtensionsManager` associated with the current process.

An application must wait until the `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html` completes to get an `https://developer.android.com/reference/kotlin/androidx/camera/extensions/ExtensionsManager` instance. The `https://developer.android.com/reference/kotlin/androidx/camera/extensions/ExtensionsManager` instance can be used to access the extensions related functions.

| Parameters |
|---|---|
| `context: https://developer.android.com/reference/android/content/Context.html` | The context to initialize the extensions library. |
| `cameraProvider: https://developer.android.com/reference/kotlin/androidx/camera/core/CameraProvider` | A `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraProvider` will be used to query the information of cameras on the device. The `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraProvider` can be the `https://developer.android.com/reference/kotlin/androidx/camera/lifecycle/ProcessCameraProvider` which is obtained by `https://developer.android.com/reference/kotlin/androidx/camera/lifecycle/ProcessCameraProvider#getInstance(android.content.Context)`. |

## Public functions

### getCameraExtensionsControl

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

```
fun getCameraExtensionsControl(cameraControl: CameraControl): CameraExtensionsControl?
```

Retrieves a `https://developer.android.com/reference/kotlin/androidx/camera/extensions/CameraExtensionsControl` object that allows customization of capture request settings for supported camera extensions.

| Parameters |
|---|---|
| `cameraControl: https://developer.android.com/reference/kotlin/androidx/camera/core/CameraControl` | the camera control for a camera with a specific extension mode turned on. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/extensions/CameraExtensionsControl?` | a `https://developer.android.com/reference/kotlin/androidx/camera/extensions/CameraExtensionsControl` object to manage extension-related settings. Or returns `null` if the provided `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraControl` doesn't represent a camera with enabled extensions. |

### getCameraExtensionsInfo

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

```
fun getCameraExtensionsInfo(cameraInfo: CameraInfo): CameraExtensionsInfo
```

Retrieves a `https://developer.android.com/reference/kotlin/androidx/camera/extensions/CameraExtensionsInfo` object that allows to observe or monitor capture request settings and results for supported camera extensions.

If the provided `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraInfo` doesn't represent a camera with enabled extensions, a placeholder `https://developer.android.com/reference/kotlin/androidx/camera/extensions/CameraExtensionsInfo` object will be returned, indicating no extension type and strength support.

| Parameters |
|---|---|
| `cameraInfo: https://developer.android.com/reference/kotlin/androidx/camera/core/CameraInfo` | the camera info for a camera with a specific extension mode turned on. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/extensions/CameraExtensionsInfo` | a `https://developer.android.com/reference/kotlin/androidx/camera/extensions/CameraExtensionsInfo` object for observing extension-specific capture request settings and results. |

### getEstimatedCaptureLatencyRange

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

```
fun getEstimatedCaptureLatencyRange(
    cameraSelector: CameraSelector,
    mode: Int
): Range<Long>?
```

Returns the estimated capture latency range in milliseconds for the target camera and extension mode.

This includes the time spent processing the multi-frame capture request along with any additional time for encoding of the processed buffer in the framework if necessary.

| Parameters |
|---|---|
| `cameraSelector: https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector` | The `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector` to find a camera which supports the specified extension mode. |
| `mode: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The extension mode to check. |

| Returns |
|---|---|
| `https://developer.android.com/reference/android/util/Range.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html>?` | the range of estimated minimal and maximal capture latency in milliseconds. Returns null if no capture latency info can be provided or if the device doesn't support the extension mode on this camera. |

### getExtensionEnabledCameraSelector

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

```
fun [getExtensionEnabledCameraSelector](https://developer.android.com/reference/kotlin/androidx/camera/extensions/ExtensionsManager#getExtensionEnabledCameraSelector(androidx.camera.core.CameraSelector,kotlin.Int))(
    cameraSelector: CameraSelector,
    mode: Int
): CameraSelector
```

> [!CAUTION]
> **This function is deprecated.**   
> Use ExtensionSessionConfig instead, use this instead:
>
> ```kotlin
> ExtensionSessionConfig
> ```

Returns a modified `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector` that will enable the specified extension mode.

The returned extension `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector` can be used to bind use cases to a desired `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner` and then the specified extension mode will be enabled on the camera.

Enable extension modes by creating an `https://developer.android.com/reference/kotlin/androidx/camera/extensions/ExtensionSessionConfig` and binding it to a lifecycle via `https://developer.android.com/reference/kotlin/androidx/camera/lifecycle/ProcessCameraProvider#bindToLifecycle(androidx.lifecycle.LifecycleOwner,androidx.camera.core.CameraSelector,kotlin.Array)`.

| Parameters |
|---|---|
| `cameraSelector: https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector` | The base `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector` on top of which the extension config is applied. `https://developer.android.com/reference/kotlin/androidx/camera/extensions/ExtensionsManager#isExtensionAvailable(androidx.camera.core.CameraSelector,kotlin.Int)` can be used to check whether any camera can support the specified extension mode for the base camera selector. |
| `mode: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The target extension mode. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector` | a `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector` for the specified Extensions mode. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | If this device doesn't support extensions function, no camera can be found to support the specified extension mode, or the base `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector` has contained extension related configuration in it. |

### isExtensionAvailable

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

```
fun isExtensionAvailable(cameraSelector: CameraSelector, mode: Int): Boolean
```

Checks if a specific extension mode is available for a given `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector`.

To use Ultra HDR, you must first check for support and then enable the format. This feature is available on capable devices starting from API level 34.

1. Obtain a `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraInfo` instance by calling `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraProvider#getCameraInfo(androidx.camera.core.CameraSelector)` with an `https://developer.android.com/reference/kotlin/androidx/camera/extensions/ExtensionSessionConfig` containing the desired extension mode.

2. Use this `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraInfo` to get the `https://developer.android.com/reference/kotlin/androidx/camera/core/ImageCaptureCapabilities` via `https://developer.android.com/reference/kotlin/androidx/camera/core/ImageCapture#getImageCaptureCapabilities(androidx.camera.core.CameraInfo)`.

3. Check the supported formats by calling `https://developer.android.com/reference/kotlin/androidx/camera/core/ImageCaptureCapabilities#getSupportedOutputFormats()`. The presence of `https://developer.android.com/reference/kotlin/androidx/camera/core/ImageCapture#OUTPUT_FORMAT_JPEG_ULTRA_HDR()` indicates Ultra HDR support.

4. When Ultra HDR is supported, configure the `https://developer.android.com/reference/kotlin/androidx/camera/core/ImageCapture` to use it by calling `https://developer.android.com/reference/kotlin/androidx/camera/core/ImageCapture.Builder#setOutputFormat(int)` with `https://developer.android.com/reference/kotlin/androidx/camera/core/ImageCapture#OUTPUT_FORMAT_JPEG_ULTRA_HDR()`.

**Note:** Camera extensions do not support 10-bit preview or video capture. When using extensions, the dynamic range must be `https://developer.android.com/reference/kotlin/androidx/camera/core/DynamicRange#SDR()` (the default).

| Parameters |
|---|---|
| `cameraSelector: https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector` | The base `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector` used to select the camera. |
| `mode: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The extension mode to verify. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `true` if the extension mode is available for the camera selector, `false` otherwise. |

### isImageAnalysisSupported

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

```
fun isImageAnalysisSupported(cameraSelector: CameraSelector, mode: Int): Boolean
```

Returns whether the given extension mode supports the `https://developer.android.com/reference/kotlin/androidx/camera/core/ImageAnalysis` use case on the camera specified by the given `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector`. If it returns false, invoking `ProcessCameraProvider.bindToLifecycle` with an `https://developer.android.com/reference/kotlin/androidx/camera/core/ImageAnalysis` use case will throw an `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html`.

| Parameters |
|---|---|
| `cameraSelector: https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector` | The `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector` to find a camera which supports the specified extension mode. |
| `mode: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The extension mode to check. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true if `https://developer.android.com/reference/kotlin/androidx/camera/core/ImageAnalysis` can be bound when the specified extension mode is enabled on the camera specified by the given `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector`. Returns false otherwise. If the device doesn't support this extension mode on this camera, it will also return false. |