Remove references to MediaDrm from DefaultDrmSession classes

Everything should go through the ExoMediaDrm layer. We still
need to abstract away the android.media exception classes, but
this is left as future work.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=167710213
This commit is contained in:
olly 2017-09-06 05:58:56 -07:00 committed by Oliver Woodman
parent 013379fd3e
commit e7992513d3
4 changed files with 58 additions and 27 deletions

View file

@ -18,7 +18,6 @@ package com.google.android.exoplayer2.drm;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.media.DeniedByServerException;
import android.media.MediaDrm;
import android.media.NotProvisionedException;
import android.os.Handler;
import android.os.HandlerThread;
@ -36,7 +35,7 @@ import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean;
/**
* A {@link DrmSession} that supports playbacks using {@link MediaDrm}.
* A {@link DrmSession} that supports playbacks using {@link ExoMediaDrm}.
*/
@TargetApi(18)
/* package */ class DefaultDrmSession<T extends ExoMediaCrypto> implements DrmSession<T> {
@ -227,8 +226,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
onError(e);
}
} catch (Exception e) {
// MediaCryptoException
// ResourceBusyException only available on 19+
onError(e);
}
@ -278,7 +275,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
case DefaultDrmSessionManager.MODE_PLAYBACK:
case DefaultDrmSessionManager.MODE_QUERY:
if (offlineLicenseKeySetId == null) {
postKeyRequest(MediaDrm.KEY_TYPE_STREAMING);
postKeyRequest(ExoMediaDrm.KEY_TYPE_STREAMING);
} else {
if (restoreKeys()) {
long licenseDurationRemainingSec = getLicenseDurationRemainingSec();
@ -286,7 +283,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
&& licenseDurationRemainingSec <= MAX_LICENSE_DURATION_TO_RENEW) {
Log.d(TAG, "Offline license has expired or will expire soon. "
+ "Remaining seconds: " + licenseDurationRemainingSec);
postKeyRequest(MediaDrm.KEY_TYPE_OFFLINE);
postKeyRequest(ExoMediaDrm.KEY_TYPE_OFFLINE);
} else if (licenseDurationRemainingSec <= 0) {
onError(new KeysExpiredException());
} else {
@ -305,11 +302,11 @@ import java.util.concurrent.atomic.AtomicBoolean;
break;
case DefaultDrmSessionManager.MODE_DOWNLOAD:
if (offlineLicenseKeySetId == null) {
postKeyRequest(MediaDrm.KEY_TYPE_OFFLINE);
postKeyRequest(ExoMediaDrm.KEY_TYPE_OFFLINE);
} else {
// Renew
if (restoreKeys()) {
postKeyRequest(MediaDrm.KEY_TYPE_OFFLINE);
postKeyRequest(ExoMediaDrm.KEY_TYPE_OFFLINE);
}
}
break;
@ -317,7 +314,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
// It's not necessary to restore the key (and open a session to do that) before releasing it
// but this serves as a good sanity/fast-failure check.
if (restoreKeys()) {
postKeyRequest(MediaDrm.KEY_TYPE_RELEASE);
postKeyRequest(ExoMediaDrm.KEY_TYPE_RELEASE);
}
break;
default:
@ -345,7 +342,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
}
private void postKeyRequest(int type) {
byte[] scope = type == MediaDrm.KEY_TYPE_RELEASE ? offlineLicenseKeySetId : sessionId;
byte[] scope = type == ExoMediaDrm.KEY_TYPE_RELEASE ? offlineLicenseKeySetId : sessionId;
try {
KeyRequest request = mediaDrm.getKeyRequest(scope, initData, mimeType, type,
optionalKeyRequestParameters);
@ -439,16 +436,16 @@ import java.util.concurrent.atomic.AtomicBoolean;
return;
}
switch (what) {
case MediaDrm.EVENT_KEY_REQUIRED:
case ExoMediaDrm.EVENT_KEY_REQUIRED:
doLicense();
break;
case MediaDrm.EVENT_KEY_EXPIRED:
case ExoMediaDrm.EVENT_KEY_EXPIRED:
// When an already expired key is loaded MediaDrm sends this event immediately. Ignore
// this event if the state isn't STATE_OPENED_WITH_KEYS yet which means we're still
// waiting for key response.
onKeysExpired();
break;
case MediaDrm.EVENT_PROVISION_REQUIRED:
case ExoMediaDrm.EVENT_PROVISION_REQUIRED:
state = STATE_OPENED;
postProvisionRequest();
break;

View file

@ -17,7 +17,6 @@ package com.google.android.exoplayer2.drm;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.media.MediaDrm;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
@ -40,7 +39,7 @@ import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean;
/**
* A {@link DrmSessionManager} that supports playbacks using {@link MediaDrm}.
* A {@link DrmSessionManager} that supports playbacks using {@link ExoMediaDrm}.
*/
@TargetApi(18)
public class DefaultDrmSessionManager<T extends ExoMediaCrypto> implements DrmSessionManager<T>,
@ -120,7 +119,7 @@ public class DefaultDrmSessionManager<T extends ExoMediaCrypto> implements DrmSe
*
* @param callback Performs key and provisioning requests.
* @param optionalKeyRequestParameters An optional map of parameters to pass as the last argument
* to {@link MediaDrm#getKeyRequest(byte[], byte[], String, int, HashMap)}. May be null.
* to {@link ExoMediaDrm#getKeyRequest(byte[], byte[], String, int, HashMap)}. May be null.
* @param eventHandler A handler to use when delivering events to {@code eventListener}. May be
* null if delivery of events is not required.
* @param eventListener A listener of events. May be null if delivery of events is not required.
@ -166,7 +165,7 @@ public class DefaultDrmSessionManager<T extends ExoMediaCrypto> implements DrmSe
* @param uuid The UUID of the drm scheme.
* @param callback Performs key and provisioning requests.
* @param optionalKeyRequestParameters An optional map of parameters to pass as the last argument
* to {@link MediaDrm#getKeyRequest(byte[], byte[], String, int, HashMap)}. May be null.
* to {@link ExoMediaDrm#getKeyRequest(byte[], byte[], String, int, HashMap)}. May be null.
* @param eventHandler A handler to use when delivering events to {@code eventListener}. May be
* null if delivery of events is not required.
* @param eventListener A listener of events. May be null if delivery of events is not required.
@ -184,7 +183,7 @@ public class DefaultDrmSessionManager<T extends ExoMediaCrypto> implements DrmSe
* @param mediaDrm An underlying {@link ExoMediaDrm} for use by the manager.
* @param callback Performs key and provisioning requests.
* @param optionalKeyRequestParameters An optional map of parameters to pass as the last argument
* to {@link MediaDrm#getKeyRequest(byte[], byte[], String, int, HashMap)}. May be null.
* to {@link ExoMediaDrm#getKeyRequest(byte[], byte[], String, int, HashMap)}. May be null.
* @param eventHandler A handler to use when delivering events to {@code eventListener}. May be
* null if delivery of events is not required.
* @param eventListener A listener of events. May be null if delivery of events is not required.
@ -201,7 +200,7 @@ public class DefaultDrmSessionManager<T extends ExoMediaCrypto> implements DrmSe
* @param mediaDrm An underlying {@link ExoMediaDrm} for use by the manager.
* @param callback Performs key and provisioning requests.
* @param optionalKeyRequestParameters An optional map of parameters to pass as the last argument
* to {@link MediaDrm#getKeyRequest(byte[], byte[], String, int, HashMap)}. May be null.
* to {@link ExoMediaDrm#getKeyRequest(byte[], byte[], String, int, HashMap)}. May be null.
* @param eventHandler A handler to use when delivering events to {@code eventListener}. May be
* null if delivery of events is not required.
* @param eventListener A listener of events. May be null if delivery of events is not required.
@ -230,7 +229,7 @@ public class DefaultDrmSessionManager<T extends ExoMediaCrypto> implements DrmSe
}
/**
* Provides access to {@link MediaDrm#getPropertyString(String)}.
* Provides access to {@link ExoMediaDrm#getPropertyString(String)}.
* <p>
* This method may be called when the manager is in any state.
*
@ -242,7 +241,7 @@ public class DefaultDrmSessionManager<T extends ExoMediaCrypto> implements DrmSe
}
/**
* Provides access to {@link MediaDrm#setPropertyString(String, String)}.
* Provides access to {@link ExoMediaDrm#setPropertyString(String, String)}.
* <p>
* This method may be called when the manager is in any state.
*
@ -254,7 +253,7 @@ public class DefaultDrmSessionManager<T extends ExoMediaCrypto> implements DrmSe
}
/**
* Provides access to {@link MediaDrm#getPropertyByteArray(String)}.
* Provides access to {@link ExoMediaDrm#getPropertyByteArray(String)}.
* <p>
* This method may be called when the manager is in any state.
*
@ -266,7 +265,7 @@ public class DefaultDrmSessionManager<T extends ExoMediaCrypto> implements DrmSe
}
/**
* Provides access to {@link MediaDrm#setPropertyByteArray(String, byte[])}.
* Provides access to {@link ExoMediaDrm#setPropertyByteArray(String, byte[])}.
* <p>
* This method may be called when the manager is in any state.
*

View file

@ -15,19 +15,54 @@
*/
package com.google.android.exoplayer2.drm;
import android.annotation.TargetApi;
import android.media.DeniedByServerException;
import android.media.MediaCryptoException;
import android.media.MediaDrm;
import android.media.MediaDrmException;
import android.media.NotProvisionedException;
import android.media.ResourceBusyException;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
/**
* Used to obtain keys for decrypting protected media streams. See {@link android.media.MediaDrm}.
*/
@TargetApi(18)
public interface ExoMediaDrm<T extends ExoMediaCrypto> {
/**
* @see MediaDrm#EVENT_KEY_REQUIRED
*/
@SuppressWarnings("InlinedApi")
int EVENT_KEY_REQUIRED = MediaDrm.EVENT_KEY_REQUIRED;
/**
* @see MediaDrm#EVENT_KEY_EXPIRED
*/
@SuppressWarnings("InlinedApi")
int EVENT_KEY_EXPIRED = MediaDrm.EVENT_KEY_EXPIRED;
/**
* @see MediaDrm#EVENT_PROVISION_REQUIRED
*/
@SuppressWarnings("InlinedApi")
int EVENT_PROVISION_REQUIRED = MediaDrm.EVENT_PROVISION_REQUIRED;
/**
* @see MediaDrm#KEY_TYPE_STREAMING
*/
@SuppressWarnings("InlinedApi")
int KEY_TYPE_STREAMING = MediaDrm.KEY_TYPE_STREAMING;
/**
* @see MediaDrm#KEY_TYPE_OFFLINE
*/
@SuppressWarnings("InlinedApi")
int KEY_TYPE_OFFLINE = MediaDrm.KEY_TYPE_OFFLINE;
/**
* @see MediaDrm#KEY_TYPE_RELEASE
*/
@SuppressWarnings("InlinedApi")
int KEY_TYPE_RELEASE = MediaDrm.KEY_TYPE_RELEASE;
/**
* @see android.media.MediaDrm.OnEventListener
*/
@ -69,7 +104,7 @@ public interface ExoMediaDrm<T extends ExoMediaCrypto> {
/**
* @see MediaDrm#openSession()
*/
byte[] openSession() throws NotProvisionedException, ResourceBusyException;
byte[] openSession() throws MediaDrmException;
/**
* @see MediaDrm#closeSession(byte[])

View file

@ -20,8 +20,8 @@ import android.media.DeniedByServerException;
import android.media.MediaCrypto;
import android.media.MediaCryptoException;
import android.media.MediaDrm;
import android.media.MediaDrmException;
import android.media.NotProvisionedException;
import android.media.ResourceBusyException;
import android.media.UnsupportedSchemeException;
import android.support.annotation.NonNull;
import com.google.android.exoplayer2.C;
@ -79,7 +79,7 @@ public final class FrameworkMediaDrm implements ExoMediaDrm<FrameworkMediaCrypto
}
@Override
public byte[] openSession() throws NotProvisionedException, ResourceBusyException {
public byte[] openSession() throws MediaDrmException {
return mediaDrm.openSession();
}