Commit 255523b4 by olly Committed by Oliver Woodman

Call DrmSession methods on the session not the manager

The way it was before worked, but it's not really documented
that DrmSession methods implemented by DefaultDrmSessionManager
can be called after the session has been released, and it feels
wrong to do this.

At some point we should probably consider moving the DrmSession
part of DefaultDrmSessionManager into an inner class, to force
usage in the "normal" way.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=151003855
parent 42629701
...@@ -133,8 +133,7 @@ public final class OfflineLicenseHelper<T extends ExoMediaCrypto> { ...@@ -133,8 +133,7 @@ public final class OfflineLicenseHelper<T extends ExoMediaCrypto> {
public synchronized byte[] downloadLicense(DrmInitData drmInitData) throws IOException, public synchronized byte[] downloadLicense(DrmInitData drmInitData) throws IOException,
InterruptedException, DrmSessionException { InterruptedException, DrmSessionException {
Assertions.checkArgument(drmInitData != null); Assertions.checkArgument(drmInitData != null);
blockingKeyRequest(DefaultDrmSessionManager.MODE_DOWNLOAD, null, drmInitData); return blockingKeyRequest(DefaultDrmSessionManager.MODE_DOWNLOAD, null, drmInitData);
return drmSessionManager.getOfflineLicenseKeySetId();
} }
/** /**
...@@ -147,8 +146,7 @@ public final class OfflineLicenseHelper<T extends ExoMediaCrypto> { ...@@ -147,8 +146,7 @@ public final class OfflineLicenseHelper<T extends ExoMediaCrypto> {
public synchronized byte[] renewLicense(byte[] offlineLicenseKeySetId) public synchronized byte[] renewLicense(byte[] offlineLicenseKeySetId)
throws DrmSessionException { throws DrmSessionException {
Assertions.checkNotNull(offlineLicenseKeySetId); Assertions.checkNotNull(offlineLicenseKeySetId);
blockingKeyRequest(DefaultDrmSessionManager.MODE_DOWNLOAD, offlineLicenseKeySetId, null); return blockingKeyRequest(DefaultDrmSessionManager.MODE_DOWNLOAD, offlineLicenseKeySetId, null);
return drmSessionManager.getOfflineLicenseKeySetId();
} }
/** /**
...@@ -173,34 +171,43 @@ public final class OfflineLicenseHelper<T extends ExoMediaCrypto> { ...@@ -173,34 +171,43 @@ public final class OfflineLicenseHelper<T extends ExoMediaCrypto> {
public synchronized Pair<Long, Long> getLicenseDurationRemainingSec(byte[] offlineLicenseKeySetId) public synchronized Pair<Long, Long> getLicenseDurationRemainingSec(byte[] offlineLicenseKeySetId)
throws DrmSessionException { throws DrmSessionException {
Assertions.checkNotNull(offlineLicenseKeySetId); Assertions.checkNotNull(offlineLicenseKeySetId);
DrmSession<T> session = openBlockingKeyRequest(DefaultDrmSessionManager.MODE_QUERY, DrmSession<T> drmSession = openBlockingKeyRequest(DefaultDrmSessionManager.MODE_QUERY,
offlineLicenseKeySetId, null); offlineLicenseKeySetId, null);
DrmSessionException error = drmSession.getError();
Pair<Long, Long> licenseDurationRemainingSec = Pair<Long, Long> licenseDurationRemainingSec =
WidevineUtil.getLicenseDurationRemainingSec(drmSessionManager); WidevineUtil.getLicenseDurationRemainingSec(drmSession);
drmSessionManager.releaseSession(session); drmSessionManager.releaseSession(drmSession);
if (error != null) {
if (error.getCause() instanceof KeysExpiredException) {
return Pair.create(0L, 0L);
}
throw error;
}
return licenseDurationRemainingSec; return licenseDurationRemainingSec;
} }
private void blockingKeyRequest(@Mode int licenseMode, byte[] offlineLicenseKeySetId, private byte[] blockingKeyRequest(@Mode int licenseMode, byte[] offlineLicenseKeySetId,
DrmInitData drmInitData) throws DrmSessionException { DrmInitData drmInitData) throws DrmSessionException {
DrmSession<T> session = openBlockingKeyRequest(licenseMode, offlineLicenseKeySetId, DrmSession<T> drmSession = openBlockingKeyRequest(licenseMode, offlineLicenseKeySetId,
drmInitData); drmInitData);
DrmSessionException error = session.getError(); DrmSessionException error = drmSession.getError();
byte[] keySetId = drmSession.getOfflineLicenseKeySetId();
drmSessionManager.releaseSession(drmSession);
if (error != null) { if (error != null) {
throw error; throw error;
} }
drmSessionManager.releaseSession(session); return keySetId;
} }
private DrmSession<T> openBlockingKeyRequest(@Mode int licenseMode, byte[] offlineLicenseKeySetId, private DrmSession<T> openBlockingKeyRequest(@Mode int licenseMode, byte[] offlineLicenseKeySetId,
DrmInitData drmInitData) { DrmInitData drmInitData) {
drmSessionManager.setMode(licenseMode, offlineLicenseKeySetId); drmSessionManager.setMode(licenseMode, offlineLicenseKeySetId);
conditionVariable.close(); conditionVariable.close();
DrmSession<T> session = drmSessionManager.acquireSession(handlerThread.getLooper(), DrmSession<T> drmSession = drmSessionManager.acquireSession(handlerThread.getLooper(),
drmInitData); drmInitData);
// Block current thread until key loading is finished // Block current thread until key loading is finished
conditionVariable.block(); conditionVariable.block();
return session; return drmSession;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment