Back to Exoplayer

FakeExoMediaDrm (ExoPlayer library)

docs/doc/reference/com/google/android/exoplayer2/testutil/FakeExoMediaDrm.html

latest27.8 KB
Original Source

Package com.google.android.exoplayer2.testutil

Class FakeExoMediaDrm

  • java.lang.Object

    • com.google.android.exoplayer2.testutil.FakeExoMediaDrm
  • All Implemented Interfaces:ExoMediaDrm


@RequiresApi(29)
public final classFakeExoMediaDrmextends[Object](https://developer.android.com/reference/java/lang/Object.html "class or interface in java.lang")implements[ExoMediaDrm](../drm/ExoMediaDrm.html "interface in com.google.android.exoplayer2.drm")

A fake implementation of ExoMediaDrm for use in tests.

FakeExoMediaDrm.LicenseServer can be used to respond to interactions stemming from getKeyRequest(byte[], List, int, HashMap) and provideKeyResponse(byte[], byte[]).

Currently only supports streaming key requests.

Nested Class Summary

Nested Classes | Modifier and Type | Class | Description | | --- | --- | --- | | static class | FakeExoMediaDrm.Builder | Builder for FakeExoMediaDrm instances. | | static class | FakeExoMediaDrm.LicenseServer | An license server implementation to interact with FakeExoMediaDrm. |

- 

Nested classes/interfaces inherited from interface com.google.android.exoplayer2.drm.ExoMediaDrm

ExoMediaDrm.AppManagedProvider, ExoMediaDrm.KeyRequest, ExoMediaDrm.KeyStatus, ExoMediaDrm.OnEventListener, ExoMediaDrm.OnExpirationUpdateListener, ExoMediaDrm.OnKeyStatusChangeListener, ExoMediaDrm.Provider, ExoMediaDrm.ProvisionRequest

Field Summary

Fields | Modifier and Type | Field | Description | | --- | --- | --- | | static ExoMediaDrm.ProvisionRequest | FAKE_PROVISION_REQUEST | | | static String | KEY_STATUS_AVAILABLE | Value for use with the Map returned from queryKeyStatus(byte[]). | | static String | KEY_STATUS_KEY | Key for use with the Map returned from queryKeyStatus(byte[]). | | static String | KEY_STATUS_UNAVAILABLE | Value for use with the Map returned from queryKeyStatus(byte[]). | | static ImmutableList<Byte> | VALID_PROVISION_RESPONSE | |

- 

Fields inherited from interface com.google.android.exoplayer2.drm.ExoMediaDrm

EVENT_KEY_EXPIRED, EVENT_KEY_REQUIRED, EVENT_PROVISION_REQUIRED, KEY_TYPE_OFFLINE, KEY_TYPE_RELEASE, KEY_TYPE_STREAMING

Constructor Summary

Constructors | Constructor | Description | | --- | --- | | FakeExoMediaDrm() | Deprecated. Use FakeExoMediaDrm.Builder instead.

| | FakeExoMediaDrm​(int maxConcurrentSessions) | Deprecated. Use FakeExoMediaDrm.Builder instead.

|

Method Summary

All Methods Instance Methods Concrete Methods | Modifier and Type | Method | Description | | --- | --- | --- | | void | acquire() | 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. | | @com.google.android.exoplayer2.C.CryptoType int | getCryptoType() | Returns the type of CryptoConfig instances returned by ExoMediaDrm.createCryptoConfig(byte[]). | | ExoMediaDrm.KeyRequest | getKeyRequest​(byte[] scope, List<DrmInitData.SchemeData> schemeDatas, int keyType, HashMap<String,​String> optionalParameters) | Generates a key request. | | PersistableBundle | getMetrics() | Returns metrics data for this ExoMediaDrm instance, or null if metrics are unavailable. | | byte[] | getPropertyByteArray​(String propertyName) | Returns the value of a byte array property. | | String | getPropertyString​(String propertyName) | Returns the value of a string property. | | ExoMediaDrm.ProvisionRequest | getProvisionRequest() | Generates a provisioning request. | | int | getReferenceCount() | | | byte[] | openSession() | Opens a new DRM session. | | byte[] | provideKeyResponse​(byte[] scope, byte[] response) | Provides a key response for the last request to be generated using ExoMediaDrm.getKeyRequest(byte[], java.util.List<com.google.android.exoplayer2.drm.DrmInitData.SchemeData>, int, java.util.HashMap<java.lang.String, java.lang.String>). | | void | provideProvisionResponse​(byte[] response) | Provides a provisioning response for the last request to be generated using ExoMediaDrm.getProvisionRequest(). | | Map<String,​String> | queryKeyStatus​(byte[] sessionId) | Returns the key status for a given session, as {name, value} pairs. | | void | release() | 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 | resetProvisioning() | 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 | setOnEventListener​(ExoMediaDrm.OnEventListener listener) | Sets the listener for DRM events. | | void | setOnExpirationUpdateListener​(ExoMediaDrm.OnExpirationUpdateListener listener) | Sets the listener for session expiration events. | | void | setOnKeyStatusChangeListener​(ExoMediaDrm.OnKeyStatusChangeListener listener) | 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, byte[] data) | Calls ExoMediaDrm.OnEventListener.onEvent(ExoMediaDrm, byte[], int, int, byte[]) on the attached listener (if present) once for each open session ID which passes sessionIdPredicate, passing the provided values for event, extra and data. |

- 

Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

- 

Methods inherited from interface com.google.android.exoplayer2.drm.ExoMediaDrm

setPlayerIdForSession

Field Detail

- 

FAKE_PROVISION_REQUEST

public static final[ExoMediaDrm.ProvisionRequest](../drm/ExoMediaDrm.ProvisionRequest.html "class in com.google.android.exoplayer2.drm")FAKE_PROVISION_REQUEST
- 

VALID_PROVISION_RESPONSE

public static final[ImmutableList](https://guava.dev/releases/31.1-android/api/docs/com/google/common/collect/ImmutableList.html?is-external=true "class or interface in com.google.common.collect")<[Byte](https://developer.android.com/reference/java/lang/Byte.html "class or interface in java.lang")> VALID_PROVISION_RESPONSE
- 

KEY_STATUS_KEY

public static final[String](https://developer.android.com/reference/java/lang/String.html "class or interface in java.lang")KEY_STATUS_KEY

Key for use with the Map returned from queryKeyStatus(byte[]). See Also:Constant Field Values

- 

KEY_STATUS_AVAILABLE

public static final[String](https://developer.android.com/reference/java/lang/String.html "class or interface in java.lang")KEY_STATUS_AVAILABLE

Value for use with the Map returned from queryKeyStatus(byte[]). See Also:Constant Field Values

- 

KEY_STATUS_UNAVAILABLE

public static final[String](https://developer.android.com/reference/java/lang/String.html "class or interface in java.lang")KEY_STATUS_UNAVAILABLE

Value for use with the Map returned from queryKeyStatus(byte[]). See Also:Constant Field Values

Constructor Detail

- 

FakeExoMediaDrm

[@Deprecated](https://developer.android.com/reference/java/lang/Deprecated.html "class or interface in java.lang")public FakeExoMediaDrm()

Deprecated. Use FakeExoMediaDrm.Builder instead.

- 

FakeExoMediaDrm

[@Deprecated](https://developer.android.com/reference/java/lang/Deprecated.html "class or interface in java.lang")public FakeExoMediaDrm​(int maxConcurrentSessions)

Deprecated. Use FakeExoMediaDrm.Builder instead.

Method Detail

- 

setOnEventListener

public void setOnEventListener​(@Nullable[ExoMediaDrm.OnEventListener](../drm/ExoMediaDrm.OnEventListener.html "interface in com.google.android.exoplayer2.drm")listener)

Description copied from interface: ExoMediaDrm

Sets the listener for DRM events.

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

Specified by:setOnEventListener in interface ExoMediaDrmParameters:listener - The listener to receive events, or null to stop receiving events.See Also:MediaDrm.setOnEventListener(MediaDrm.OnEventListener)

- 

setOnKeyStatusChangeListener

public void setOnKeyStatusChangeListener​(@Nullable[ExoMediaDrm.OnKeyStatusChangeListener](../drm/ExoMediaDrm.OnKeyStatusChangeListener.html "interface in com.google.android.exoplayer2.drm")listener)

Description copied from interface: ExoMediaDrm

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.

Specified by:setOnKeyStatusChangeListener in interface ExoMediaDrmParameters:listener - The listener to receive events, or null to stop receiving events.See Also:MediaDrm.setOnKeyStatusChangeListener(MediaDrm.OnKeyStatusChangeListener, Handler)

- 

setOnExpirationUpdateListener

public void setOnExpirationUpdateListener​(@Nullable[ExoMediaDrm.OnExpirationUpdateListener](../drm/ExoMediaDrm.OnExpirationUpdateListener.html "interface in com.google.android.exoplayer2.drm")listener)

Description copied from interface: ExoMediaDrm

Sets the listener for session expiration events.

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

Specified by:setOnExpirationUpdateListener in interface ExoMediaDrmParameters:listener - The listener to receive events, or null to stop receiving events.See Also:MediaDrm.setOnExpirationUpdateListener(MediaDrm.OnExpirationUpdateListener, Handler)

- 

openSession

public byte[] openSession()
                   throws[MediaDrmException](https://developer.android.com/reference/android/media/MediaDrmException.html "class or interface in android.media")

Description copied from interface: ExoMediaDrm

Opens a new DRM session. A session ID is returned. Specified by:openSession in interface ExoMediaDrmReturns:The session ID.Throws:NotProvisionedException - If provisioning is needed.ResourceBusyException - If required resources are in use.MediaDrmException - If the session could not be opened.

- 

closeSession

public void closeSession​(byte[] sessionId)

Description copied from interface: ExoMediaDrm

Closes a DRM session. Specified by:closeSession in interface ExoMediaDrmParameters:sessionId - The ID of the session to close.

- 

getKeyRequest

public[ExoMediaDrm.KeyRequest](../drm/ExoMediaDrm.KeyRequest.html "class in com.google.android.exoplayer2.drm")getKeyRequest​(byte[] scope,
                                            @Nullable[List](https://developer.android.com/reference/java/util/List.html "class or interface in java.util")<[DrmInitData.SchemeData](../drm/DrmInitData.SchemeData.html "class in com.google.android.exoplayer2.drm")> schemeDatas,
                                            int keyType,
                                            @Nullable[HashMap](https://developer.android.com/reference/java/util/HashMap.html "class or interface in java.util")<[String](https://developer.android.com/reference/java/lang/String.html?is-external=true "class or interface in java.lang"),​[String](https://developer.android.com/reference/java/lang/String.html?is-external=true "class or interface in java.lang")> optionalParameters)
                                     throws[NotProvisionedException](https://developer.android.com/reference/android/media/NotProvisionedException.html "class or interface in android.media")

Description copied from interface: ExoMediaDrm

Generates a key request. Specified by:getKeyRequest in interface ExoMediaDrmParameters:scope - If keyType is ExoMediaDrm.KEY_TYPE_STREAMING or ExoMediaDrm.KEY_TYPE_OFFLINE, the ID of the session that the keys will be provided to. If keyType is ExoMediaDrm.KEY_TYPE_RELEASE, the keySetId of the keys to release.schemeDatas - If key type is ExoMediaDrm.KEY_TYPE_STREAMING or ExoMediaDrm.KEY_TYPE_OFFLINE, a list of DrmInitData.SchemeData instances extracted from the media. Null otherwise.keyType - The type of the request. Either ExoMediaDrm.KEY_TYPE_STREAMING to acquire keys for streaming, ExoMediaDrm.KEY_TYPE_OFFLINE to acquire keys for offline usage, or ExoMediaDrm.KEY_TYPE_RELEASE to release acquired keys. Releasing keys invalidates them for all sessions.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:The generated key request.Throws:NotProvisionedExceptionSee Also:MediaDrm.getKeyRequest(byte[], byte[], String, int, HashMap)

- 

provideKeyResponse

public byte[] provideKeyResponse​(byte[] scope,
                                 byte[] response)
                          throws[NotProvisionedException](https://developer.android.com/reference/android/media/NotProvisionedException.html "class or interface in android.media"),[DeniedByServerException](https://developer.android.com/reference/android/media/DeniedByServerException.html "class or interface in android.media")

Description copied from interface: ExoMediaDrm

Provides a key response for the last request to be generated using ExoMediaDrm.getKeyRequest(byte[], java.util.List<com.google.android.exoplayer2.drm.DrmInitData.SchemeData>, int, java.util.HashMap<java.lang.String, java.lang.String>). Specified by:provideKeyResponse in interface ExoMediaDrmParameters:scope - If the request had type ExoMediaDrm.KEY_TYPE_STREAMING or ExoMediaDrm.KEY_TYPE_OFFLINE, the ID of the session to provide the keys to. If keyType is ExoMediaDrm.KEY_TYPE_RELEASE, the keySetId of the keys being released.response - The response data from the server.Returns:If the request had type ExoMediaDrm.KEY_TYPE_OFFLINE, the keySetId for the offline keys. An empty byte array or null may be returned for other cases.Throws:NotProvisionedException - If the response indicates that provisioning is needed.DeniedByServerException - If the response indicates that the server rejected the request.

- 

getProvisionRequest

public[ExoMediaDrm.ProvisionRequest](../drm/ExoMediaDrm.ProvisionRequest.html "class in com.google.android.exoplayer2.drm")getProvisionRequest()

Description copied from interface: ExoMediaDrm

Generates a provisioning request. Specified by:getProvisionRequest in interface ExoMediaDrmReturns:The generated provisioning request.

- 

provideProvisionResponse

public void provideProvisionResponse​(byte[] response)
                              throws[DeniedByServerException](https://developer.android.com/reference/android/media/DeniedByServerException.html "class or interface in android.media")

Description copied from interface: ExoMediaDrm

Provides a provisioning response for the last request to be generated using ExoMediaDrm.getProvisionRequest(). Specified by:provideProvisionResponse in interface ExoMediaDrmParameters:response - The response data from the server.Throws:DeniedByServerException - If the response indicates that the server rejected the request.

- 

queryKeyStatus

public[Map](https://developer.android.com/reference/java/util/Map.html "class or interface in java.util")<[String](https://developer.android.com/reference/java/lang/String.html?is-external=true "class or interface in java.lang"),​[String](https://developer.android.com/reference/java/lang/String.html?is-external=true "class or interface in java.lang")> queryKeyStatus​(byte[] sessionId)

Description copied from interface: ExoMediaDrm

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. Specified by:queryKeyStatus in interface ExoMediaDrmParameters:sessionId - The ID of the session being queried.Returns:The key status for the session.

- 

requiresSecureDecoder

public boolean requiresSecureDecoder​(byte[] sessionId,[String](https://developer.android.com/reference/java/lang/String.html "class or interface in java.lang")mimeType)

Description copied from interface: ExoMediaDrm

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. Specified by:requiresSecureDecoder in interface ExoMediaDrmParameters:sessionId - The ID of the session.mimeType - The content MIME type to query.

- 

acquire

public void acquire()

Description copied from interface: ExoMediaDrm

Increments the reference count. When the caller no longer needs to use the instance, it must call ExoMediaDrm.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.

Specified by:acquire in interface ExoMediaDrm

- 

release

public void release()

Description copied from interface: ExoMediaDrm

Decrements the reference count. If the reference count drops to 0 underlying resources are released, and the instance cannot be re-used. Specified by:release in interface ExoMediaDrm

- 

restoreKeys

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

Description copied from interface: ExoMediaDrm

Restores persisted offline keys into a session. Specified by:restoreKeys in interface ExoMediaDrmParameters:sessionId - The ID of the session into which the keys will be restored.keySetId - The keySetId of the keys to restore, as provided by the call to ExoMediaDrm.provideKeyResponse(byte[], byte[]) that persisted them.

- 

getMetrics

@Nullable
public[PersistableBundle](https://developer.android.com/reference/android/os/PersistableBundle.html "class or interface in android.os")getMetrics()

Description copied from interface: ExoMediaDrm

Returns metrics data for this ExoMediaDrm instance, or null if metrics are unavailable. Specified by:getMetrics in interface ExoMediaDrm

- 

getPropertyString

public[String](https://developer.android.com/reference/java/lang/String.html "class or interface in java.lang")getPropertyString​([String](https://developer.android.com/reference/java/lang/String.html?is-external=true "class or interface in java.lang")propertyName)

Description copied from interface: ExoMediaDrm

Returns the value of a string property. For standard property names, see MediaDrm.getPropertyString(java.lang.String). Specified by:getPropertyString in interface ExoMediaDrmParameters:propertyName - The property name.Returns:The property value.

- 

getPropertyByteArray

public byte[] getPropertyByteArray​([String](https://developer.android.com/reference/java/lang/String.html "class or interface in java.lang")propertyName)

Description copied from interface: ExoMediaDrm

Returns the value of a byte array property. For standard property names, see MediaDrm.getPropertyByteArray(java.lang.String). Specified by:getPropertyByteArray in interface ExoMediaDrmParameters:propertyName - The property name.Returns:The property value.

- 

setPropertyString

public void setPropertyString​([String](https://developer.android.com/reference/java/lang/String.html "class or interface in java.lang")propertyName,[String](https://developer.android.com/reference/java/lang/String.html "class or interface in java.lang")value)

Description copied from interface: ExoMediaDrm

Sets the value of a string property. Specified by:setPropertyString in interface ExoMediaDrmParameters:propertyName - The property name.value - The value.

- 

setPropertyByteArray

public void setPropertyByteArray​([String](https://developer.android.com/reference/java/lang/String.html "class or interface in java.lang")propertyName,
                                 byte[] value)

Description copied from interface: ExoMediaDrm

Sets the value of a byte array property. Specified by:setPropertyByteArray in interface ExoMediaDrmParameters:propertyName - The property name.value - The value.

- 

createCryptoConfig

public[CryptoConfig](../decoder/CryptoConfig.html "interface in com.google.android.exoplayer2.decoder")createCryptoConfig​(byte[] sessionId)
                                throws[MediaCryptoException](https://developer.android.com/reference/android/media/MediaCryptoException.html "class or interface in android.media")

Description copied from interface: ExoMediaDrm

Creates a CryptoConfig that can be passed to a compatible decoder to allow decryption of protected content using the specified session. Specified by:createCryptoConfig in interface ExoMediaDrmParameters:sessionId - The ID of the session.Returns:A CryptoConfig for the given session.Throws:MediaCryptoException - If a CryptoConfig could not be created.

- 

getCryptoType

public @com.google.android.exoplayer2.C.CryptoType int getCryptoType()

Description copied from interface: ExoMediaDrm

Returns the type of CryptoConfig instances returned by ExoMediaDrm.createCryptoConfig(byte[]). Specified by:getCryptoType in interface ExoMediaDrm

- 

getReferenceCount

public int getReferenceCount()
- 

triggerEvent

public void triggerEvent​([Predicate](https://guava.dev/releases/31.1-android/api/docs/com/google/common/base/Predicate.html?is-external=true "class or interface in com.google.common.base")<byte[]> sessionIdPredicate,
                         int event,
                         int extra,
                         @Nullable
                         byte[] data)

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

- 

resetProvisioning

public void resetProvisioning()

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