> Documentation index: https://developer.android.com/reference/llms.txt

# FrameworkMediaDrm

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

*** ** * ** ***


```
public final class FrameworkMediaDrm implements ExoMediaDrm
```

<br />

*** ** * ** ***

An `ExoMediaDrm` implementation that wraps the framework `MediaDrm`.

## Summary

| ### Constants |
|---|---|
| `static final ExoMediaDrm.Provider` | `@UnstableApi DEFAULT_PROVIDER` `ExoMediaDrm.Provider` that returns a new `FrameworkMediaDrm` for the requested UUID. |

| ### Public methods |
|---|---|
| `synchronized void` | `@UnstableApi acquire()` Increments the reference count. |
| `void` | `@UnstableApi closeSession(byte[] sessionId)` Closes a DRM session. |
| `FrameworkCryptoConfig` | `@UnstableApi createCryptoConfig(byte[] sessionId)` Creates a `CryptoConfig` that can be passed to a compatible decoder to allow decryption of protected content using the specified session. |
| `int` | `@UnstableApi @C.CryptoType getCryptoType()` Returns the `type` of `CryptoConfig` instances returned by `createCryptoConfig`. |
| `ExoMediaDrm.KeyRequest` | `@UnstableApi getKeyRequest( byte[] scope, @Nullable List<DrmInitData.SchemeData> schemeDatas, int keyType, @Nullable HashMap<String, String> optionalParameters )` Generates a key request. |
| `@Nullable PersistableBundle` | `@UnstableApi getMetrics()` Returns metrics data for this ExoMediaDrm instance, or `null` if metrics are unavailable. |
| `List<byte[]>` | `@UnstableApi @RequiresApi(value = 29) getOfflineLicenseKeySetIds()` Returns a list of the `keySetIds` for all offline licenses. |
| `byte[]` | `@UnstableApi getPropertyByteArray(String propertyName)` Returns the value of a byte array property. |
| `String` | `@UnstableApi getPropertyString(String propertyName)` Returns the value of a string property. |
| `ExoMediaDrm.ProvisionRequest` | `@UnstableApi getProvisionRequest()` Generates a provisioning request. |
| `static boolean` | `isCryptoSchemeSupported(UUID uuid)` Returns whether the DRM scheme with the given UUID is supported on this device. |
| `static FrameworkMediaDrm` | `@UnstableApi newInstance(UUID uuid)` Creates an instance with an initial reference count of 1. |
| `byte[]` | `@UnstableApi openSession()` Opens a new DRM session. |
| `@Nullable byte[]` | `@UnstableApi provideKeyResponse(byte[] scope, byte[] response)` Provides a key response for the last request to be generated using `getKeyRequest`. |
| `void` | `@UnstableApi provideProvisionResponse(byte[] response)` Provides a provisioning response for the last request to be generated using `getProvisionRequest`. |
| `Map<String, String>` | `@UnstableApi queryKeyStatus(byte[] sessionId)` Returns the key status for a given session, as {name, value} pairs. |
| `synchronized void` | `@UnstableApi release()` Decrements the reference count. |
| `void` | `@UnstableApi @RequiresApi(value = 29) removeOfflineLicense(byte[] keySetId)` Removes an offline license. |
| `boolean` | `@UnstableApi requiresSecureDecoder(byte[] sessionId, String mimeType)` Returns whether the given session requires use of a secure decoder for the given MIME type. |
| `void` | `@UnstableApi restoreKeys(byte[] sessionId, byte[] keySetId)` Restores persisted offline keys into a session. |
| `void` | `@UnstableApi setOnEventListener(@Nullable ExoMediaDrm.OnEventListener listener)` Sets the listener for DRM events. |
| `void` | `@UnstableApi setOnExpirationUpdateListener( @Nullable ExoMediaDrm.OnExpirationUpdateListener listener )` Sets the listener for session expiration events. |
| `void` | `@UnstableApi setOnKeyStatusChangeListener( @Nullable ExoMediaDrm.OnKeyStatusChangeListener listener )` Sets the listener for key status change events. |
| `void` | `@UnstableApi setPlayerIdForSession(byte[] sessionId, PlayerId playerId)` Sets the `PlayerId` of the player using a session. |
| `void` | `@UnstableApi setPropertyByteArray(String propertyName, byte[] value)` Sets the value of a byte array property. |
| `void` | `@UnstableApi setPropertyString(String propertyName, String value)` Sets the value of a string property. |

### Inherited Constants

From [androidx.media3.exoplayer.drm.ExoMediaDrm](https://developer.android.com/reference/androidx/media3/exoplayer/drm/ExoMediaDrm.md.txt) `static final int` `@UnstableApi
EVENT_KEY_EXPIRED = 3`

Event indicating that keys have expired, and are no longer usable.
`static final int` `@UnstableApi
EVENT_KEY_REQUIRED = 2`

Event indicating that keys need to be requested from the license server.
`static final int` `@UnstableApi
EVENT_PROVISION_REQUIRED = 1`

Event indicating that a certificate needs to be requested from the provisioning server.
`static final int` `@UnstableApi
KEY_TYPE_OFFLINE = 2`

Key request type for keys that will be used for offline use.
`static final int` `@UnstableApi
KEY_TYPE_RELEASE = 3`

Key request type indicating that saved offline keys should be released.
`static final int` `@UnstableApi
KEY_TYPE_STREAMING = 1`

Key request type for keys that will be used for online use.

## Constants

### DEFAULT_PROVIDER

```
@UnstableApi
public static final ExoMediaDrm.Provider DEFAULT_PROVIDER
```

`ExoMediaDrm.Provider` that returns a new `FrameworkMediaDrm` for the requested UUID. Returns a `DummyExoMediaDrm` if the protection scheme identified by the given UUID is not supported by the device.

## Public methods

### acquire

```
@UnstableApi
synchronized public void acquire()
```

Increments the reference count. When the caller no longer needs to use the instance, it must call `release` to decrement the reference count.

A new instance will have an initial reference count of 1, and therefore it is not normally necessary for application code to call this method.

### closeSession

```
@UnstableApi
public void closeSession(byte[] sessionId)
```

Closes a DRM session.

| Parameters |
|---|---|
| `byte[] sessionId` | The ID of the session to close. |

### createCryptoConfig

```
@UnstableApi
public FrameworkCryptoConfig createCryptoConfig(byte[] sessionId)
```

Creates a `CryptoConfig` that can be passed to a compatible decoder to allow decryption of protected content using the specified session.

| Parameters |
|---|---|
| `byte[] sessionId` | The ID of the session. |

| Returns |
|---|---|
| `FrameworkCryptoConfig` | A `CryptoConfig` for the given session. |

| Throws |
|---|---|
| `android.media.MediaCryptoException` | If a `CryptoConfig` could not be created. |

### getCryptoType

```
@UnstableApi
@C.CryptoType
public int getCryptoType()
```

Returns the `type` of `CryptoConfig` instances returned by `createCryptoConfig`.

### getKeyRequest

```
@UnstableApi
public ExoMediaDrm.KeyRequest getKeyRequest(
    byte[] scope,
    @Nullable List<DrmInitData.SchemeData> schemeDatas,
    int keyType,
    @Nullable HashMap<String, String> optionalParameters
)
```

Generates a key request.

| Parameters |
|---|---|
| `byte[] scope` | If `keyType` is `KEY_TYPE_STREAMING` or `KEY_TYPE_OFFLINE`, the ID of the session that the keys will be provided to. If `keyType` is `KEY_TYPE_RELEASE`, the `keySetId` of the keys to release. |
| `@Nullable List<DrmInitData.SchemeData> schemeDatas` | If key type is `KEY_TYPE_STREAMING` or `KEY_TYPE_OFFLINE`, a list of `SchemeData` instances extracted from the media. Null otherwise. |
| `int keyType` | The type of the request. Either `KEY_TYPE_STREAMING` to acquire keys for streaming, `KEY_TYPE_OFFLINE` to acquire keys for offline usage, or `KEY_TYPE_RELEASE` to release acquired keys. Releasing keys invalidates them for all sessions. |
| `@Nullable HashMap<String, String> optionalParameters` | Are included in the key request message to allow a client application to provide additional message parameters to the server. This may be `null` if no additional parameters are to be sent. |

| Returns |
|---|---|
| `ExoMediaDrm.KeyRequest` | The generated key request. |

| Throws |
|---|---|
| `android.media.NotProvisionedException` |   |

| See also |
|---|---|
| `getKeyRequest` |   |

### getMetrics

```
@UnstableApi
public @Nullable PersistableBundle getMetrics()
```

Returns metrics data for this ExoMediaDrm instance, or `null` if metrics are unavailable.

### getOfflineLicenseKeySetIds

```
@UnstableApi
@RequiresApi(value = 29)
public List<byte[]> getOfflineLicenseKeySetIds()
```

Returns a list of the `keySetIds` for all offline licenses.

This is an optional method, and some implementations may only support it on certain Android API levels.

See `getOfflineLicenseKeySetIds` for more details.

| Returns |
|---|---|
| `List<byte[]>` | The list of `keySetIds` for all offline licenses. |

| Throws |
|---|---|
| `java.lang.UnsupportedOperationException` | if the implementation doesn't support this method. |

### getPropertyByteArray

```
@UnstableApi
public byte[] getPropertyByteArray(String propertyName)
```

Returns the value of a byte array property. For standard property names, see `getPropertyByteArray`.

| Parameters |
|---|---|
| `String propertyName` | The property name. |

| Returns |
|---|---|
| `byte[]` | The property value. |

| Throws |
|---|---|
| `java.lang.IllegalArgumentException` | If the underlying DRM plugin does not support the property. |

### getPropertyString

```
@UnstableApi
public String getPropertyString(String propertyName)
```

Returns the value of a string property. For standard property names, see `getPropertyString`.

| Parameters |
|---|---|
| `String propertyName` | The property name. |

| Returns |
|---|---|
| `String` | The property value. |

| Throws |
|---|---|
| `java.lang.IllegalArgumentException` | If the underlying DRM plugin does not support the property. |

### getProvisionRequest

```
@UnstableApi
public ExoMediaDrm.ProvisionRequest getProvisionRequest()
```

Generates a provisioning request.

| Returns |
|---|---|
| `ExoMediaDrm.ProvisionRequest` | The generated provisioning request. |

### isCryptoSchemeSupported

```
public static boolean isCryptoSchemeSupported(UUID uuid)
```

Returns whether the DRM scheme with the given UUID is supported on this device.

| See also |
|---|---|
| `isCryptoSchemeSupported` |   |

### newInstance

```
@UnstableApi
public static FrameworkMediaDrm newInstance(UUID uuid)
```

Creates an instance with an initial reference count of 1. `release` must be called on the instance when it's no longer required.

| Parameters |
|---|---|
| `UUID uuid` | The scheme uuid. |

| Returns |
|---|---|
| `FrameworkMediaDrm` | The created instance. |

| Throws |
|---|---|
| `androidx.media3.exoplayer.drm.UnsupportedDrmException` | If the DRM scheme is unsupported or cannot be instantiated. |

### openSession

```
@UnstableApi
public byte[] openSession()
```

Opens a new DRM session. A session ID is returned.

| Returns |
|---|---|
| `byte[]` | The session ID. |

| Throws |
|---|---|
| `android.media.NotProvisionedException` | If provisioning is needed. |
| `android.media.ResourceBusyException` | If required resources are in use. |
| `android.media.MediaDrmException` | If the session could not be opened. |

### provideKeyResponse

```
@UnstableApi
public @Nullable byte[] provideKeyResponse(byte[] scope, byte[] response)
```

Provides a key response for the last request to be generated using `getKeyRequest`.

| Parameters |
|---|---|
| `byte[] scope` | If the request had type `KEY_TYPE_STREAMING` or `KEY_TYPE_OFFLINE`, the ID of the session to provide the keys to. If `keyType` is `KEY_TYPE_RELEASE`, the `keySetId` of the keys being released. |
| `byte[] response` | The response data from the server. |

| Returns |
|---|---|
| `@Nullable byte[]` | If the request had type `KEY_TYPE_OFFLINE`, the `keySetId` for the offline keys. An empty byte array or `null` may be returned for other cases. |

| Throws |
|---|---|
| `android.media.NotProvisionedException` | If the response indicates that provisioning is needed. |
| `android.media.DeniedByServerException` | If the response indicates that the server rejected the request. |

### provideProvisionResponse

```
@UnstableApi
public void provideProvisionResponse(byte[] response)
```

Provides a provisioning response for the last request to be generated using `getProvisionRequest`.

| Parameters |
|---|---|
| `byte[] response` | The response data from the server. |

| Throws |
|---|---|
| `android.media.DeniedByServerException` | If the response indicates that the server rejected the request. |

### queryKeyStatus

```
@UnstableApi
public Map<String, String> queryKeyStatus(byte[] sessionId)
```

Returns the key status for a given session, as {name, value} pairs. Since DRM license policies vary by vendor, the returned entries depend on the DRM plugin being used. Refer to your DRM provider's documentation for more information.

| Parameters |
|---|---|
| `byte[] sessionId` | The ID of the session being queried. |

| Returns |
|---|---|
| `Map<String, String>` | The key status for the session. |

### release

```
@UnstableApi
synchronized public void release()
```

Decrements the reference count. If the reference count drops to 0 underlying resources are released, and the instance cannot be re-used.

### removeOfflineLicense

```
@UnstableApi
@RequiresApi(value = 29)
public void removeOfflineLicense(byte[] keySetId)
```

Removes an offline license.

This method is generally not needed, and should only be used if the preferred approach of generating a license release request by passing `KEY_TYPE_RELEASE` to `getKeyRequest` is not possible.

This is an optional method, and some implementations may only support it on certain Android API levels.

See `removeOfflineLicense` for more details.

| Parameters |
|---|---|
| `byte[] keySetId` | The `keySetId` of the license to remove. |

| Throws |
|---|---|
| `java.lang.UnsupportedOperationException` | if the implementation doesn't support this method. |

### requiresSecureDecoder

```
@UnstableApi
public boolean requiresSecureDecoder(byte[] sessionId, String mimeType)
```

Returns whether the given session requires use of a secure decoder for the given MIME type. Assumes a license policy that requires the highest level of security supported by the session.

| Parameters |
|---|---|
| `byte[] sessionId` | The ID of the session. |
| `String mimeType` | The content MIME type to query. |

### restoreKeys

```
@UnstableApi
public void restoreKeys(byte[] sessionId, byte[] keySetId)
```

Restores persisted offline keys into a session.

| Parameters |
|---|---|
| `byte[] sessionId` | The ID of the session into which the keys will be restored. |
| `byte[] keySetId` | The `keySetId` of the keys to restore, as provided by the call to `provideKeyResponse` that persisted them. |

### setOnEventListener

```
@UnstableApi
public void setOnEventListener(@Nullable ExoMediaDrm.OnEventListener listener)
```

Sets the listener for DRM events.

This is an optional method, and some implementations may only support it on certain Android API levels.

| Parameters |
|---|---|
| `@Nullable ExoMediaDrm.OnEventListener listener` | The listener to receive events, or `null` to stop receiving events. |

| Throws |
|---|---|
| `java.lang.UnsupportedOperationException` | if the implementation doesn't support this method. |

| See also |
|---|---|
| `setOnEventListener` |   |

### setOnExpirationUpdateListener

```
@UnstableApi
public void setOnExpirationUpdateListener(
    @Nullable ExoMediaDrm.OnExpirationUpdateListener listener
)
```

Sets the listener for session expiration events.

This is an optional method, and some implementations may only support it on certain Android API levels.

| Parameters |
|---|---|
| `@Nullable ExoMediaDrm.OnExpirationUpdateListener listener` | The listener to receive events, or `null` to stop receiving events. |

| Throws |
|---|---|
| `java.lang.UnsupportedOperationException` | if the implementation doesn't support this method. |

| See also |
|---|---|
| `setOnExpirationUpdateListener` |   |

### setOnKeyStatusChangeListener

```
@UnstableApi
public void setOnKeyStatusChangeListener(
    @Nullable ExoMediaDrm.OnKeyStatusChangeListener listener
)
```

Sets the listener for key status change events.

This is an optional method, and some implementations may only support it on certain Android API levels.

| Parameters |
|---|---|
| `@Nullable ExoMediaDrm.OnKeyStatusChangeListener listener` | The listener to receive events, or `null` to stop receiving events. |

| Throws |
|---|---|
| `java.lang.UnsupportedOperationException` | if the implementation doesn't support this method. |

| See also |
|---|---|
| `setOnKeyStatusChangeListener` |   |

### setPlayerIdForSession

```
@UnstableApi
public void setPlayerIdForSession(byte[] sessionId, PlayerId playerId)
```

Sets the `PlayerId` of the player using a session.

| Parameters |
|---|---|
| `byte[] sessionId` | The ID of the session. |
| `PlayerId playerId` | The `PlayerId` of the player using the session. |

### setPropertyByteArray

```
@UnstableApi
public void setPropertyByteArray(String propertyName, byte[] value)
```

Sets the value of a byte array property.

| Parameters |
|---|---|
| `String propertyName` | The property name. |
| `byte[] value` | The value. |

| Throws |
|---|---|
| `java.lang.IllegalArgumentException` | If the underlying DRM plugin does not support the property. |

### setPropertyString

```
@UnstableApi
public void setPropertyString(String propertyName, String value)
```

Sets the value of a string property.

| Parameters |
|---|---|
| `String propertyName` | The property name. |
| `String value` | The value. |

| Throws |
|---|---|
| `java.lang.IllegalArgumentException` | If the underlying DRM plugin does not support the property. |