# DrmUtil

Artifact: [androidx.media3:media3-exoplayer](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/exoplayer/drm/DrmUtil.java+class:androidx.media3.exoplayer.drm.DrmUtil)

*** ** * ** ***

<br />

```
@UnstableApi
class DrmUtil
```

<br />

*** ** * ** ***

DRM-related utility methods.

## Summary

| ### Nested types |
|---|
| `@https://developer.android.com/reference/java/lang/annotation/Documented.html @https://developer.android.com/reference/java/lang/annotation/Retention.html(value = https://developer.android.com/reference/java/lang/annotation/RetentionPolicy.html#SOURCE) @https://developer.android.com/reference/java/lang/annotation/Target.html(value = ) @https://developer.android.com/reference/kotlin/androidx/annotation/IntDef(value = ) annotation https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmUtil.ErrorSource` Identifies the operation which caused a DRM-related error. |

| ### Constants |
|---|---|
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmUtil#ERROR_SOURCE_EXO_MEDIA_DRM() = 1` Corresponds to failures caused by an `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/ExoMediaDrm` method call. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmUtil#ERROR_SOURCE_LICENSE_ACQUISITION() = 2` Corresponds to failures caused by an operation related to obtaining DRM licenses. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmUtil#ERROR_SOURCE_PROVISIONING() = 3` Corresponds to failures caused by an operation related to provisioning the device. |

| ### Public functions |
|---|---|
| `java-static https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/MediaDrmCallback.Response!` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmUtil#executePost(androidx.media3.datasource.DataSource,java.lang.String,byte[],java.util.Map<java.lang.String,java.lang.String>)( dataSource: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource!, url: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, httpBody: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>?, requestProperties: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-map/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-map/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!>! )` Executes a HTTP POST request with retry handling and returns the entire response in a byte buffer. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `@https://developer.android.com/reference/kotlin/androidx/media3/common/PlaybackException.ErrorCode https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmUtil#getErrorCodeForMediaDrmException(java.lang.Throwable,int)( exception: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-throwable/index.html!, @https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmUtil.ErrorSource errorSource: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html )` Returns the `https://developer.android.com/reference/kotlin/androidx/media3/common/PlaybackException.ErrorCode` that corresponds to the given DRM-related exception. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmUtil#isFailureToConstructNotProvisionedException(java.lang.Throwable)(e: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-throwable/index.html?)` Returns true if `e` represents a failure to construct a `https://developer.android.com/reference/android/media/NotProvisionedException.html`. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmUtil#isFailureToConstructResourceBusyException(java.lang.Throwable)(e: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-throwable/index.html?)` Returns true if `e` represents a failure to construct a `https://developer.android.com/reference/android/media/ResourceBusyException.html`. |

## Constants

### ERROR_SOURCE_EXO_MEDIA_DRM

```
const val ERROR_SOURCE_EXO_MEDIA_DRM = 1: Int
```

Corresponds to failures caused by an `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/ExoMediaDrm` method call.

### ERROR_SOURCE_LICENSE_ACQUISITION

```
const val ERROR_SOURCE_LICENSE_ACQUISITION = 2: Int
```

Corresponds to failures caused by an operation related to obtaining DRM licenses.

### ERROR_SOURCE_PROVISIONING

```
const val ERROR_SOURCE_PROVISIONING = 3: Int
```

Corresponds to failures caused by an operation related to provisioning the device.

## Public functions

### executePost

```
java-static fun executePost(
    dataSource: DataSource!,
    url: String!,
    httpBody: ByteArray<Byte>?,
    requestProperties: (Mutable)Map<String!, String!>!
): MediaDrmCallback.Response!
```

Executes a HTTP POST request with retry handling and returns the entire response in a byte buffer.

Note that this method is executing the request synchronously and blocks until finished.

The `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/LoadEventInfo` returned inside the `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/MediaDrmCallback.Response` will have the following fields unset, and they must be updated by caller before the `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/LoadEventInfo` is used elsewhere:

- `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/LoadEventInfo#loadTaskId()`
- `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/LoadEventInfo#loadDurationMs()`

| Parameters |
|---|---|
| `dataSource: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource!` | A `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource`. |
| `url: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | The requested URL. |
| `httpBody: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>?` | The HTTP request payload. |
| `requestProperties: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-map/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-map/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!>!` | A keyed map of HTTP header request properties. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/MediaDrmCallback.Response!` | A `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/MediaDrmCallback.Response` that holds the response payload, and `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/source/LoadEventInfo`. |

| Throws |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/MediaDrmCallbackException` | if an exception was encountered during the download. |

### getErrorCodeForMediaDrmException

```
@PlaybackException.ErrorCode
java-static fun getErrorCodeForMediaDrmException(
    exception: Throwable!,
    @DrmUtil.ErrorSource errorSource: Int
): Int
```

Returns the `https://developer.android.com/reference/kotlin/androidx/media3/common/PlaybackException.ErrorCode` that corresponds to the given DRM-related exception.

| Parameters |
|---|---|
| `exception: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-throwable/index.html!` | The DRM-related exception for which to obtain a corresponding `https://developer.android.com/reference/kotlin/androidx/media3/common/PlaybackException.ErrorCode`. |
| `@https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmUtil.ErrorSource errorSource: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/drm/DrmUtil.ErrorSource` for the given `exception`. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The `https://developer.android.com/reference/kotlin/androidx/media3/common/PlaybackException.ErrorCode` that corresponds to the given DRM-related exception. |

### isFailureToConstructNotProvisionedException

```
java-static fun isFailureToConstructNotProvisionedException(e: Throwable?): Boolean
```

Returns true if `e` represents a failure to construct a `https://developer.android.com/reference/android/media/NotProvisionedException.html`. See b/291440132.

### isFailureToConstructResourceBusyException

```
java-static fun isFailureToConstructResourceBusyException(e: Throwable?): Boolean
```

Returns true if `e` represents a failure to construct a `https://developer.android.com/reference/android/media/ResourceBusyException.html`. See b/291440132.