@RequiresApi(value = 29)
@UnstableApi
class FakeExoMediaDrm : ExoMediaDrm


A fake implementation of ExoMediaDrm for use in tests.

LicenseServer can be used to respond to interactions stemming from getKeyRequest and provideKeyResponse.

Currently only supports streaming key requests.

Summary

Nested types

Builder for FakeExoMediaDrm instances.

An license server implementation to interact with FakeExoMediaDrm.

Constants

const ExoMediaDrm.ProvisionRequest!
const String!
KEY_STATUS_AVAILABLE = "AVAILABLE"

Value for use with the Map returned from queryKeyStatus.

const String!
KEY_STATUS_KEY = "KEY_STATUS"

Key for use with the Map returned from queryKeyStatus.

const String!
KEY_STATUS_UNAVAILABLE = "UNAVAILABLE"

Value for use with the Map returned from queryKeyStatus.

const ImmutableList<Byte!>!

Public constructors

This function is deprecated.

Use Builder instead.

FakeExoMediaDrm(maxConcurrentSessions: Int)

This function is deprecated.

Use Builder instead.

Public functions

Unit

Increments the reference count.

Unit
closeSession(sessionId: ByteArray!)

Closes a DRM session.

CryptoConfig!

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

Int

Returns the type of CryptoConfig instances returned by createCryptoConfig.

ExoMediaDrm.KeyRequest!
getKeyRequest(
    scope: ByteArray!,
    schemeDatas: (Mutable)List<DrmInitData.SchemeData!>?,
    keyType: Int,
    optionalParameters: HashMap<String!, String!>?
)

Generates a key request.

PersistableBundle?

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

ByteArray<Byte>!
getPropertyByteArray(propertyName: String!)

Returns the value of a byte array property.

String!
getPropertyString(propertyName: String!)

Returns the value of a string property.

ExoMediaDrm.ProvisionRequest!

Generates a provisioning request.

ByteArray<Byte>!

Opens a new DRM session.

ByteArray<Byte>!
provideKeyResponse(scope: ByteArray!, response: ByteArray!)

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

Unit

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

(Mutable)Map<String!, String!>!

Returns the key status for a given session, as {name, value} pairs.

Unit

Decrements the reference count.

Boolean
requiresSecureDecoder(sessionId: ByteArray!, mimeType: String!)

Returns whether the given session requires use of a secure decoder for the given MIME type.

Unit

Resets the provisioning state of this instance, so it requires provisionsRequired (possibly zero) provision operations before it's operational again.

Unit
restoreKeys(sessionId: ByteArray!, keySetId: ByteArray!)

Restores persisted offline keys into a session.

Unit

Sets the listener for DRM events.

Unit

Sets the listener for session expiration events.

Unit

Sets the listener for key status change events.

Unit
setPropertyByteArray(propertyName: String!, value: ByteArray!)

Sets the value of a byte array property.

Unit
setPropertyString(propertyName: String!, value: String!)

Sets the value of a string property.

Unit
triggerEvent(
    sessionIdPredicate: Predicate<ByteArray!>!,
    event: Int,
    extra: Int,
    data: ByteArray?
)

Calls onEvent on the attached listener (if present) once for each open session ID which passes sessionIdPredicate, passing the provided values for event, extra and data.

Public properties

Int

Inherited Constants

From androidx.media3.exoplayer.drm.ExoMediaDrm
const Int

Event indicating that keys have expired, and are no longer usable.

const Int

Event indicating that keys need to be requested from the license server.

const Int

Event indicating that a certificate needs to be requested from the provisioning server.

const Int

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

const Int

Key request type indicating that saved offline keys should be released.

const Int

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

Inherited functions

From androidx.media3.exoplayer.drm.ExoMediaDrm
(Mutable)List<ByteArray<Byte>!>!

Returns a list of the keySetIds for all offline licenses.

Unit

Removes an offline license.

Unit
setPlayerIdForSession(sessionId: ByteArray!, playerId: PlayerId!)

Sets the PlayerId of the player using a session.

Constants

FAKE_PROVISION_REQUEST

const val FAKE_PROVISION_REQUESTExoMediaDrm.ProvisionRequest!

KEY_STATUS_AVAILABLE

const val KEY_STATUS_AVAILABLE = "AVAILABLE": String!

Value for use with the Map returned from queryKeyStatus.

KEY_STATUS_KEY

const val KEY_STATUS_KEY = "KEY_STATUS": String!

Key for use with the Map returned from queryKeyStatus.

KEY_STATUS_UNAVAILABLE

const val KEY_STATUS_UNAVAILABLE = "UNAVAILABLE": String!

Value for use with the Map returned from queryKeyStatus.

VALID_PROVISION_RESPONSE

const val VALID_PROVISION_RESPONSEImmutableList<Byte!>!

Public constructors

FakeExoMediaDrm

FakeExoMediaDrm()

FakeExoMediaDrm

FakeExoMediaDrm(maxConcurrentSessions: Int)

Public functions

acquire

fun acquire(): Unit

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

fun closeSession(sessionId: ByteArray!): Unit

Closes a DRM session.

Parameters
sessionId: ByteArray!

The ID of the session to close.

createCryptoConfig

fun createCryptoConfig(sessionId: ByteArray!): CryptoConfig!

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

Parameters
sessionId: ByteArray!

The ID of the session.

Returns
CryptoConfig!

A CryptoConfig for the given session.

Throws
android.media.MediaCryptoException

If a CryptoConfig could not be created.

getCryptoType

@C.CryptoType
fun getCryptoType(): Int

Returns the type of CryptoConfig instances returned by createCryptoConfig.

getKeyRequest

fun getKeyRequest(
    scope: ByteArray!,
    schemeDatas: (Mutable)List<DrmInitData.SchemeData!>?,
    keyType: Int,
    optionalParameters: HashMap<String!, String!>?
): ExoMediaDrm.KeyRequest!

Generates a key request.

Parameters
scope: ByteArray!

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.

schemeDatas: (Mutable)List<DrmInitData.SchemeData!>?

If key type is KEY_TYPE_STREAMING or KEY_TYPE_OFFLINE, a list of SchemeData instances extracted from the media. Null otherwise.

keyType: Int

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.

optionalParameters: HashMap<String!, String!>?

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.

See also
getKeyRequest

getMetrics

fun getMetrics(): PersistableBundle?

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

getPropertyByteArray

fun getPropertyByteArray(propertyName: String!): ByteArray<Byte>!

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

Parameters
propertyName: String!

The property name.

Returns
ByteArray<Byte>!

The property value.

Throws
java.lang.IllegalArgumentException

If the underlying DRM plugin does not support the property.

getPropertyString

fun getPropertyString(propertyName: String!): String!

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

Parameters
propertyName: String!

The property name.

Returns
String!

The property value.

Throws
java.lang.IllegalArgumentException

If the underlying DRM plugin does not support the property.

getProvisionRequest

fun getProvisionRequest(): ExoMediaDrm.ProvisionRequest!

Generates a provisioning request.

Returns
ExoMediaDrm.ProvisionRequest!

The generated provisioning request.

openSession

fun openSession(): ByteArray<Byte>!

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

Returns
ByteArray<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

fun provideKeyResponse(scope: ByteArray!, response: ByteArray!): ByteArray<Byte>!

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

Parameters
scope: ByteArray!

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.

response: ByteArray!

The response data from the server.

Returns
ByteArray<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

fun provideProvisionResponse(response: ByteArray!): Unit

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

Parameters
response: ByteArray!

The response data from the server.

Throws
android.media.DeniedByServerException

If the response indicates that the server rejected the request.

queryKeyStatus

fun queryKeyStatus(sessionId: ByteArray!): (Mutable)Map<String!, String!>!

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
sessionId: ByteArray!

The ID of the session being queried.

Returns
(Mutable)Map<String!, String!>!

The key status for the session.

release

fun release(): Unit

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

requiresSecureDecoder

fun requiresSecureDecoder(sessionId: ByteArray!, mimeType: String!): Boolean

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
sessionId: ByteArray!

The ID of the session.

mimeType: String!

The content MIME type to query.

resetProvisioning

fun resetProvisioning(): Unit

Resets the provisioning state of this instance, so it requires provisionsRequired (possibly zero) provision operations before it's operational again.

restoreKeys

fun restoreKeys(sessionId: ByteArray!, keySetId: ByteArray!): Unit

Restores persisted offline keys into a session.

Parameters
sessionId: ByteArray!

The ID of the session into which the keys will be restored.

keySetId: ByteArray!

The keySetId of the keys to restore, as provided by the call to provideKeyResponse that persisted them.

setOnEventListener

fun setOnEventListener(listener: ExoMediaDrm.OnEventListener?): Unit

Sets the listener for DRM events.

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

Parameters
listener: ExoMediaDrm.OnEventListener?

The listener to receive events, or null to stop receiving events.

Throws
java.lang.UnsupportedOperationException

if the implementation doesn't support this method.

setOnExpirationUpdateListener

fun setOnExpirationUpdateListener(
    listener: ExoMediaDrm.OnExpirationUpdateListener?
): Unit

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
listener: ExoMediaDrm.OnExpirationUpdateListener?

The listener to receive events, or null to stop receiving events.

Throws
java.lang.UnsupportedOperationException

if the implementation doesn't support this method.

setOnKeyStatusChangeListener

fun setOnKeyStatusChangeListener(
    listener: ExoMediaDrm.OnKeyStatusChangeListener?
): Unit

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
listener: ExoMediaDrm.OnKeyStatusChangeListener?

The listener to receive events, or null to stop receiving events.

Throws
java.lang.UnsupportedOperationException

if the implementation doesn't support this method.

setPropertyByteArray

fun setPropertyByteArray(propertyName: String!, value: ByteArray!): Unit

Sets the value of a byte array property.

Parameters
propertyName: String!

The property name.

value: ByteArray!

The value.

Throws
java.lang.IllegalArgumentException

If the underlying DRM plugin does not support the property.

setPropertyString

fun setPropertyString(propertyName: String!, value: String!): Unit

Sets the value of a string property.

Parameters
propertyName: String!

The property name.

value: String!

The value.

Throws
java.lang.IllegalArgumentException

If the underlying DRM plugin does not support the property.

triggerEvent

fun triggerEvent(
    sessionIdPredicate: Predicate<ByteArray!>!,
    event: Int,
    extra: Int,
    data: ByteArray?
): Unit

Calls onEvent on the attached listener (if present) once for each open session ID which passes sessionIdPredicate, passing the provided values for event, extra and data.

Public properties

referenceCount

val referenceCountInt