# 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)

*** ** * ** ***


```
@UnstableApi
public final 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/androidx/annotation/IntDef(value = ) public annotation https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmUtil.ErrorSource` Identifies the operation which caused a DRM-related error. |

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

| ### Public methods |
|---|---|
| `static https://developer.android.com/reference/androidx/media3/exoplayer/drm/MediaDrmCallback.Response` | `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmUtil#executePost(androidx.media3.datasource.DataSource,java.lang.String,byte[],java.util.Map<java.lang.String,java.lang.String>)( https://developer.android.com/reference/androidx/media3/datasource/DataSource dataSource, https://developer.android.com/reference/java/lang/String.html url, @https://developer.android.com/reference/androidx/annotation/Nullable byte[] httpBody, https://developer.android.com/reference/java/util/Map.html<https://developer.android.com/reference/java/lang/String.html, https://developer.android.com/reference/java/lang/String.html> requestProperties )` Executes a HTTP POST request with retry handling and returns the entire response in a byte buffer. |
| `static int` | `@https://developer.android.com/reference/androidx/media3/common/PlaybackException.ErrorCode https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmUtil#getErrorCodeForMediaDrmException(java.lang.Throwable,int)( https://developer.android.com/reference/java/lang/Throwable.html exception, @https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmUtil.ErrorSource int errorSource )` Returns the `https://developer.android.com/reference/androidx/media3/common/PlaybackException.ErrorCode` that corresponds to the given DRM-related exception. |
| `static boolean` | `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmUtil#isFailureToConstructNotProvisionedException(java.lang.Throwable)(@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/Throwable.html e)` Returns true if `e` represents a failure to construct a `https://developer.android.com/reference/android/media/NotProvisionedException.html`. |
| `static boolean` | `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmUtil#isFailureToConstructResourceBusyException(java.lang.Throwable)(@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/Throwable.html e)` 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

```
public static final int ERROR_SOURCE_EXO_MEDIA_DRM = 1
```

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

### ERROR_SOURCE_LICENSE_ACQUISITION

```
public static final int ERROR_SOURCE_LICENSE_ACQUISITION = 2
```

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

### ERROR_SOURCE_PROVISIONING

```
public static final int ERROR_SOURCE_PROVISIONING = 3
```

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

## Public methods

### executePost

```
public static MediaDrmCallback.Response executePost(
    DataSource dataSource,
    String url,
    @Nullable byte[] httpBody,
    Map<String, String> requestProperties
)
```

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/androidx/media3/exoplayer/source/LoadEventInfo` returned inside the `https://developer.android.com/reference/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/androidx/media3/exoplayer/source/LoadEventInfo` is used elsewhere:

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

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/datasource/DataSource dataSource` | A `https://developer.android.com/reference/androidx/media3/datasource/DataSource`. |
| `https://developer.android.com/reference/java/lang/String.html url` | The requested URL. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable byte[] httpBody` | The HTTP request payload. |
| `https://developer.android.com/reference/java/util/Map.html<https://developer.android.com/reference/java/lang/String.html, https://developer.android.com/reference/java/lang/String.html> requestProperties` | A keyed map of HTTP header request properties. |

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

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

### getErrorCodeForMediaDrmException

```
@PlaybackException.ErrorCode
public static int getErrorCodeForMediaDrmException(
    Throwable exception,
    @DrmUtil.ErrorSource int errorSource
)
```

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

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/lang/Throwable.html exception` | The DRM-related exception for which to obtain a corresponding `https://developer.android.com/reference/androidx/media3/common/PlaybackException.ErrorCode`. |
| `@https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmUtil.ErrorSource int errorSource` | The `https://developer.android.com/reference/androidx/media3/exoplayer/drm/DrmUtil.ErrorSource` for the given `exception`. |

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

### isFailureToConstructNotProvisionedException

```
public static boolean isFailureToConstructNotProvisionedException(@Nullable Throwable e)
```

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

### isFailureToConstructResourceBusyException

```
public static boolean isFailureToConstructResourceBusyException(@Nullable Throwable e)
```

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