Class FakeExoMediaDrm
- java.lang.Object
-
- com.google.android.exoplayer2.testutil.FakeExoMediaDrm
-
- All Implemented Interfaces:
ExoMediaDrm
@RequiresApi(29) public final class FakeExoMediaDrm extends Object implements ExoMediaDrm
A fake implementation ofExoMediaDrmfor use in tests.FakeExoMediaDrm.LicenseServercan be used to respond to interactions stemming fromgetKeyRequest(byte[], List, int, HashMap)andprovideKeyResponse(byte[], byte[]).Currently only supports streaming key requests.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFakeExoMediaDrm.BuilderBuilder forFakeExoMediaDrminstances.static classFakeExoMediaDrm.LicenseServerAn license server implementation to interact withFakeExoMediaDrm.-
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.ProvisionRequestFAKE_PROVISION_REQUESTstatic StringKEY_STATUS_AVAILABLEValue for use with the Map returned fromqueryKeyStatus(byte[]).static StringKEY_STATUS_KEYKey for use with the Map returned fromqueryKeyStatus(byte[]).static StringKEY_STATUS_UNAVAILABLEValue for use with the Map returned fromqueryKeyStatus(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.UseFakeExoMediaDrm.Builderinstead.FakeExoMediaDrm(int maxConcurrentSessions)Deprecated.UseFakeExoMediaDrm.Builderinstead.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidacquire()Increments the reference count.voidcloseSession(byte[] sessionId)Closes a DRM session.CryptoConfigcreateCryptoConfig(byte[] sessionId)Creates aCryptoConfigthat can be passed to a compatible decoder to allow decryption of protected content using the specified session.@com.google.android.exoplayer2.C.CryptoType intgetCryptoType()ExoMediaDrm.KeyRequestgetKeyRequest(byte[] scope, List<DrmInitData.SchemeData> schemeDatas, int keyType, HashMap<String,String> optionalParameters)Generates a key request.PersistableBundlegetMetrics()Returns metrics data for this ExoMediaDrm instance, ornullif metrics are unavailable.byte[]getPropertyByteArray(String propertyName)Returns the value of a byte array property.StringgetPropertyString(String propertyName)Returns the value of a string property.ExoMediaDrm.ProvisionRequestgetProvisionRequest()Generates a provisioning request.intgetReferenceCount()byte[]openSession()Opens a new DRM session.byte[]provideKeyResponse(byte[] scope, byte[] response)Provides a key response for the last request to be generated usingExoMediaDrm.getKeyRequest(byte[], java.util.List<com.google.android.exoplayer2.drm.DrmInitData.SchemeData>, int, java.util.HashMap<java.lang.String, java.lang.String>).voidprovideProvisionResponse(byte[] response)Provides a provisioning response for the last request to be generated usingExoMediaDrm.getProvisionRequest().Map<String,String>queryKeyStatus(byte[] sessionId)Returns the key status for a given session, as {name, value} pairs.voidrelease()Decrements the reference count.booleanrequiresSecureDecoder(byte[] sessionId, String mimeType)Returns whether the given session requires use of a secure decoder for the given MIME type.voidresetProvisioning()Resets the provisioning state of this instance, so it requiresprovisionsRequired(possibly zero) provision operations before it's operational again.voidrestoreKeys(byte[] sessionId, byte[] keySetId)Restores persisted offline keys into a session.voidsetOnEventListener(ExoMediaDrm.OnEventListener listener)Sets the listener for DRM events.voidsetOnExpirationUpdateListener(ExoMediaDrm.OnExpirationUpdateListener listener)Sets the listener for session expiration events.voidsetOnKeyStatusChangeListener(ExoMediaDrm.OnKeyStatusChangeListener listener)Sets the listener for key status change events.voidsetPropertyByteArray(String propertyName, byte[] value)Sets the value of a byte array property.voidsetPropertyString(String propertyName, String value)Sets the value of a string property.voidtriggerEvent(Predicate<byte[]> sessionIdPredicate, int event, int extra, byte[] data)CallsExoMediaDrm.OnEventListener.onEvent(ExoMediaDrm, byte[], int, int, byte[])on the attached listener (if present) once for each open session ID which passessessionIdPredicate, passing the provided values forevent,extraanddata.-
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 FAKE_PROVISION_REQUEST
-
VALID_PROVISION_RESPONSE
public static final ImmutableList<Byte> VALID_PROVISION_RESPONSE
-
KEY_STATUS_KEY
public static final String KEY_STATUS_KEY
Key for use with the Map returned fromqueryKeyStatus(byte[]).- See Also:
- Constant Field Values
-
KEY_STATUS_AVAILABLE
public static final String KEY_STATUS_AVAILABLE
Value for use with the Map returned fromqueryKeyStatus(byte[]).- See Also:
- Constant Field Values
-
KEY_STATUS_UNAVAILABLE
public static final String KEY_STATUS_UNAVAILABLE
Value for use with the Map returned fromqueryKeyStatus(byte[]).- See Also:
- Constant Field Values
-
-
Constructor Detail
-
FakeExoMediaDrm
@Deprecated public FakeExoMediaDrm()
Deprecated.UseFakeExoMediaDrm.Builderinstead.
-
FakeExoMediaDrm
@Deprecated public FakeExoMediaDrm(int maxConcurrentSessions)
Deprecated.UseFakeExoMediaDrm.Builderinstead.
-
-
Method Detail
-
setOnEventListener
public void setOnEventListener(@Nullable ExoMediaDrm.OnEventListener listener)Description copied from interface:ExoMediaDrmSets the listener for DRM events.This is an optional method, and some implementations may only support it on certain Android API levels.
- Specified by:
setOnEventListenerin interfaceExoMediaDrm- Parameters:
listener- The listener to receive events, ornullto stop receiving events.- See Also:
MediaDrm.setOnEventListener(MediaDrm.OnEventListener)
-
setOnKeyStatusChangeListener
public void setOnKeyStatusChangeListener(@Nullable ExoMediaDrm.OnKeyStatusChangeListener listener)Description copied from interface:ExoMediaDrmSets 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:
setOnKeyStatusChangeListenerin interfaceExoMediaDrm- Parameters:
listener- The listener to receive events, ornullto stop receiving events.- See Also:
MediaDrm.setOnKeyStatusChangeListener(MediaDrm.OnKeyStatusChangeListener, Handler)
-
setOnExpirationUpdateListener
public void setOnExpirationUpdateListener(@Nullable ExoMediaDrm.OnExpirationUpdateListener listener)Description copied from interface:ExoMediaDrmSets 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:
setOnExpirationUpdateListenerin interfaceExoMediaDrm- Parameters:
listener- The listener to receive events, ornullto stop receiving events.- See Also:
MediaDrm.setOnExpirationUpdateListener(MediaDrm.OnExpirationUpdateListener, Handler)
-
openSession
public byte[] openSession() throws MediaDrmExceptionDescription copied from interface:ExoMediaDrmOpens a new DRM session. A session ID is returned.- Specified by:
openSessionin interfaceExoMediaDrm- Returns:
- 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:ExoMediaDrmCloses a DRM session.- Specified by:
closeSessionin interfaceExoMediaDrm- Parameters:
sessionId- The ID of the session to close.
-
getKeyRequest
public ExoMediaDrm.KeyRequest getKeyRequest(byte[] scope, @Nullable List<DrmInitData.SchemeData> schemeDatas, int keyType, @Nullable HashMap<String,String> optionalParameters) throws NotProvisionedException
Description copied from interface:ExoMediaDrmGenerates a key request.- Specified by:
getKeyRequestin interfaceExoMediaDrm- Parameters:
scope- IfkeyTypeisExoMediaDrm.KEY_TYPE_STREAMINGorExoMediaDrm.KEY_TYPE_OFFLINE, the ID of the session that the keys will be provided to. IfkeyTypeisExoMediaDrm.KEY_TYPE_RELEASE, thekeySetIdof the keys to release.schemeDatas- If key type isExoMediaDrm.KEY_TYPE_STREAMINGorExoMediaDrm.KEY_TYPE_OFFLINE, a list ofDrmInitData.SchemeDatainstances extracted from the media. Null otherwise.keyType- The type of the request. EitherExoMediaDrm.KEY_TYPE_STREAMINGto acquire keys for streaming,ExoMediaDrm.KEY_TYPE_OFFLINEto acquire keys for offline usage, orExoMediaDrm.KEY_TYPE_RELEASEto 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 benullif no additional parameters are to be sent.- Returns:
- The generated key request.
- Throws:
NotProvisionedException- See Also:
MediaDrm.getKeyRequest(byte[], byte[], String, int, HashMap)
-
provideKeyResponse
public byte[] provideKeyResponse(byte[] scope, byte[] response) throws NotProvisionedException, DeniedByServerExceptionDescription copied from interface:ExoMediaDrmProvides a key response for the last request to be generated usingExoMediaDrm.getKeyRequest(byte[], java.util.List<com.google.android.exoplayer2.drm.DrmInitData.SchemeData>, int, java.util.HashMap<java.lang.String, java.lang.String>).- Specified by:
provideKeyResponsein interfaceExoMediaDrm- Parameters:
scope- If the request had typeExoMediaDrm.KEY_TYPE_STREAMINGorExoMediaDrm.KEY_TYPE_OFFLINE, the ID of the session to provide the keys to. IfkeyTypeisExoMediaDrm.KEY_TYPE_RELEASE, thekeySetIdof the keys being released.response- The response data from the server.- Returns:
- If the request had type
ExoMediaDrm.KEY_TYPE_OFFLINE, thekeySetIdfor the offline keys. An empty byte array ornullmay 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 getProvisionRequest()
Description copied from interface:ExoMediaDrmGenerates a provisioning request.- Specified by:
getProvisionRequestin interfaceExoMediaDrm- Returns:
- The generated provisioning request.
-
provideProvisionResponse
public void provideProvisionResponse(byte[] response) throws DeniedByServerExceptionDescription copied from interface:ExoMediaDrmProvides a provisioning response for the last request to be generated usingExoMediaDrm.getProvisionRequest().- Specified by:
provideProvisionResponsein interfaceExoMediaDrm- Parameters:
response- The response data from the server.- Throws:
DeniedByServerException- If the response indicates that the server rejected the request.
-
queryKeyStatus
public Map<String,String> queryKeyStatus(byte[] sessionId)
Description copied from interface:ExoMediaDrmReturns 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:
queryKeyStatusin interfaceExoMediaDrm- Parameters:
sessionId- The ID of the session being queried.- Returns:
- The key status for the session.
-
requiresSecureDecoder
public boolean requiresSecureDecoder(byte[] sessionId, String mimeType)Description copied from interface:ExoMediaDrmReturns 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:
requiresSecureDecoderin interfaceExoMediaDrm- Parameters:
sessionId- The ID of the session.mimeType- The content MIME type to query.
-
acquire
public void acquire()
Description copied from interface:ExoMediaDrmIncrements the reference count. When the caller no longer needs to use the instance, it must callExoMediaDrm.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:
acquirein interfaceExoMediaDrm
-
release
public void release()
Description copied from interface:ExoMediaDrmDecrements the reference count. If the reference count drops to 0 underlying resources are released, and the instance cannot be re-used.- Specified by:
releasein interfaceExoMediaDrm
-
restoreKeys
public void restoreKeys(byte[] sessionId, byte[] keySetId)Description copied from interface:ExoMediaDrmRestores persisted offline keys into a session.- Specified by:
restoreKeysin interfaceExoMediaDrm- Parameters:
sessionId- The ID of the session into which the keys will be restored.keySetId- ThekeySetIdof the keys to restore, as provided by the call toExoMediaDrm.provideKeyResponse(byte[], byte[])that persisted them.
-
getMetrics
@Nullable public PersistableBundle getMetrics()
Description copied from interface:ExoMediaDrmReturns metrics data for this ExoMediaDrm instance, ornullif metrics are unavailable.- Specified by:
getMetricsin interfaceExoMediaDrm
-
getPropertyString
public String getPropertyString(String propertyName)
Description copied from interface:ExoMediaDrmReturns the value of a string property. For standard property names, seeMediaDrm.getPropertyString(java.lang.String).- Specified by:
getPropertyStringin interfaceExoMediaDrm- Parameters:
propertyName- The property name.- Returns:
- The property value.
-
getPropertyByteArray
public byte[] getPropertyByteArray(String propertyName)
Description copied from interface:ExoMediaDrmReturns the value of a byte array property. For standard property names, seeMediaDrm.getPropertyByteArray(java.lang.String).- Specified by:
getPropertyByteArrayin interfaceExoMediaDrm- Parameters:
propertyName- The property name.- Returns:
- The property value.
-
setPropertyString
public void setPropertyString(String propertyName, String value)
Description copied from interface:ExoMediaDrmSets the value of a string property.- Specified by:
setPropertyStringin interfaceExoMediaDrm- Parameters:
propertyName- The property name.value- The value.
-
setPropertyByteArray
public void setPropertyByteArray(String propertyName, byte[] value)
Description copied from interface:ExoMediaDrmSets the value of a byte array property.- Specified by:
setPropertyByteArrayin interfaceExoMediaDrm- Parameters:
propertyName- The property name.value- The value.
-
createCryptoConfig
public CryptoConfig createCryptoConfig(byte[] sessionId) throws MediaCryptoException
Description copied from interface:ExoMediaDrmCreates aCryptoConfigthat can be passed to a compatible decoder to allow decryption of protected content using the specified session.- Specified by:
createCryptoConfigin interfaceExoMediaDrm- Parameters:
sessionId- The ID of the session.- Returns:
- A
CryptoConfigfor the given session. - Throws:
MediaCryptoException- If aCryptoConfigcould not be created.
-
getCryptoType
public @com.google.android.exoplayer2.C.CryptoType int getCryptoType()
Description copied from interface:ExoMediaDrm- Specified by:
getCryptoTypein interfaceExoMediaDrm
-
getReferenceCount
public int getReferenceCount()
-
triggerEvent
public void triggerEvent(Predicate<byte[]> sessionIdPredicate, int event, int extra, @Nullable byte[] data)
CallsExoMediaDrm.OnEventListener.onEvent(ExoMediaDrm, byte[], int, int, byte[])on the attached listener (if present) once for each open session ID which passessessionIdPredicate, passing the provided values forevent,extraanddata.
-
resetProvisioning
public void resetProvisioning()
Resets the provisioning state of this instance, so it requiresprovisionsRequired(possibly zero) provision operations before it's operational again.
-
-