@RequiresApi(value = 29)
@UnstableApi
public final class FakeExoMediaDrm implements 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

static final ExoMediaDrm.ProvisionRequest
static final String
KEY_STATUS_AVAILABLE = "AVAILABLE"

Value for use with the Map returned from queryKeyStatus.

static final String
KEY_STATUS_KEY = "KEY_STATUS"

Key for use with the Map returned from queryKeyStatus.

static final String
KEY_STATUS_UNAVAILABLE = "UNAVAILABLE"

Value for use with the Map returned from queryKeyStatus.

static final ImmutableList<Byte>

Public fields

int

Public constructors

This method is deprecated.

Use Builder instead.

FakeExoMediaDrm(int maxConcurrentSessions)

This method is deprecated.

Use Builder instead.

Public methods

void

Increments the reference count.

void
closeSession(byte[] sessionId)

Closes a DRM session.

CryptoConfig
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

Returns the type of CryptoConfig instances returned by createCryptoConfig.

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

Generates a key request.

@Nullable PersistableBundle

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

byte[]

Returns the value of a byte array property.

String
getPropertyString(String propertyName)

Returns the value of a string property.

ExoMediaDrm.ProvisionRequest

Generates a provisioning request.

int
byte[]

Opens a new DRM session.

byte[]
provideKeyResponse(byte[] scope, byte[] response)

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

void
provideProvisionResponse(byte[] response)

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

Map<StringString>
queryKeyStatus(byte[] sessionId)

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

void

Decrements the reference count.

boolean
requiresSecureDecoder(byte[] sessionId, String mimeType)

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

void

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

void
restoreKeys(byte[] sessionId, byte[] keySetId)

Restores persisted offline keys into a session.

void

Sets the listener for DRM events.

void

Sets the listener for session expiration events.

void

Sets the listener for key status change events.

void
setPropertyByteArray(String propertyName, byte[] value)

Sets the value of a byte array property.

void
setPropertyString(String propertyName, String value)

Sets the value of a string property.

void
triggerEvent(
    Predicate<byte[]> sessionIdPredicate,
    int event,
    int extra,
    @Nullable byte[] data
)

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.

Inherited Constants

From androidx.media3.exoplayer.drm.ExoMediaDrm
static final int

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

static final int

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

static final int

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

static final int

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

static final int

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

static final int

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

Inherited methods

From androidx.media3.exoplayer.drm.ExoMediaDrm
List<byte[]>

Returns a list of the keySetIds for all offline licenses.

void
removeOfflineLicense(byte[] keySetId)

Removes an offline license.

void
setPlayerIdForSession(byte[] sessionId, PlayerId playerId)

Sets the PlayerId of the player using a session.

Constants

FAKE_PROVISION_REQUEST

public static final ExoMediaDrm.ProvisionRequest FAKE_PROVISION_REQUEST

KEY_STATUS_AVAILABLE

public static final String KEY_STATUS_AVAILABLE = "AVAILABLE"

Value for use with the Map returned from queryKeyStatus.

KEY_STATUS_KEY

public static final String KEY_STATUS_KEY = "KEY_STATUS"

Key for use with the Map returned from queryKeyStatus.

KEY_STATUS_UNAVAILABLE

public static final String KEY_STATUS_UNAVAILABLE = "UNAVAILABLE"

Value for use with the Map returned from queryKeyStatus.

VALID_PROVISION_RESPONSE

public static final ImmutableList<ByteVALID_PROVISION_RESPONSE

Public fields

referenceCount

public int referenceCount

Public constructors

FakeExoMediaDrm

public FakeExoMediaDrm()

FakeExoMediaDrm

public FakeExoMediaDrm(int maxConcurrentSessions)

Public methods

acquire

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

public void closeSession(byte[] sessionId)

Closes a DRM session.

Parameters
byte[] sessionId

The ID of the session to close.

createCryptoConfig

public CryptoConfig 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
CryptoConfig

A CryptoConfig for the given session.

Throws
android.media.MediaCryptoException

If a CryptoConfig could not be created.

getCryptoType

@C.CryptoType
public int getCryptoType()

Returns the type of CryptoConfig instances returned by createCryptoConfig.

getKeyRequest

public ExoMediaDrm.KeyRequest getKeyRequest(
    byte[] scope,
    @Nullable List<DrmInitData.SchemeData> schemeDatas,
    int keyType,
    @Nullable HashMap<StringString> 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<StringString> 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.

See also
getKeyRequest

getMetrics

public @Nullable PersistableBundle getMetrics()

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

getPropertyByteArray

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

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

public ExoMediaDrm.ProvisionRequest getProvisionRequest()

Generates a provisioning request.

Returns
ExoMediaDrm.ProvisionRequest

The generated provisioning request.

getReferenceCount

public int getReferenceCount()

openSession

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

public 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
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

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

public Map<StringStringqueryKeyStatus(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<StringString>

The key status for the session.

release

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.

requiresSecureDecoder

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.

resetProvisioning

public void resetProvisioning()

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

restoreKeys

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

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.

setOnExpirationUpdateListener

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.

setOnKeyStatusChangeListener

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.

setPropertyByteArray

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

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.

triggerEvent

public void triggerEvent(
    Predicate<byte[]> sessionIdPredicate,
    int event,
    int extra,
    @Nullable byte[] data
)

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.