Skip to content

Commit

Permalink
Replace hard coded UUID in OfflineLicenseHelper with a parameter
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=176102179
  • Loading branch information
erdemguven authored and ojw28 committed Nov 17, 2017
1 parent 0a8d242 commit 8940e7b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import android.util.Pair;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.drm.DrmInitData.SchemeData;
import com.google.android.exoplayer2.upstream.HttpDataSource;
import java.util.HashMap;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
Expand All @@ -34,15 +33,15 @@
public class OfflineLicenseHelperTest extends InstrumentationTestCase {

private OfflineLicenseHelper<?> offlineLicenseHelper;
@Mock private HttpDataSource httpDataSource;
@Mock private MediaDrmCallback mediaDrmCallback;
@Mock private ExoMediaDrm<ExoMediaCrypto> mediaDrm;

@Override
protected void setUp() throws Exception {
setUpMockito(this);
when(mediaDrm.openSession()).thenReturn(new byte[] {1, 2, 3});
offlineLicenseHelper = new OfflineLicenseHelper<>(mediaDrm, mediaDrmCallback, null);
offlineLicenseHelper = new OfflineLicenseHelper<>(C.WIDEVINE_UUID, mediaDrm, mediaDrmCallback,
null);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import com.google.android.exoplayer2.upstream.HttpDataSource;
import com.google.android.exoplayer2.upstream.HttpDataSource.Factory;
import com.google.android.exoplayer2.util.Assertions;
import java.io.IOException;
import java.util.HashMap;
import java.util.UUID;

/**
* Helper class to download, renew and release offline licenses.
Expand Down Expand Up @@ -96,22 +96,24 @@ public static OfflineLicenseHelper<FrameworkMediaCrypto> newWidevineInstance(
String defaultLicenseUrl, boolean forceDefaultLicenseUrl, Factory httpDataSourceFactory,
HashMap<String, String> optionalKeyRequestParameters)
throws UnsupportedDrmException {
return new OfflineLicenseHelper<>(FrameworkMediaDrm.newInstance(C.WIDEVINE_UUID),
return new OfflineLicenseHelper<>(C.WIDEVINE_UUID,
FrameworkMediaDrm.newInstance(C.WIDEVINE_UUID),
new HttpMediaDrmCallback(defaultLicenseUrl, forceDefaultLicenseUrl, httpDataSourceFactory),
optionalKeyRequestParameters);
}

/**
* Constructs an instance. Call {@link #release()} when the instance is no longer required.
*
* @param uuid The UUID of the drm scheme.
* @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.
* @see DefaultDrmSessionManager#DefaultDrmSessionManager(java.util.UUID, ExoMediaDrm,
* MediaDrmCallback, HashMap, Handler, EventListener)
*/
public OfflineLicenseHelper(ExoMediaDrm<T> mediaDrm, MediaDrmCallback callback,
public OfflineLicenseHelper(UUID uuid, ExoMediaDrm<T> mediaDrm, MediaDrmCallback callback,
HashMap<String, String> optionalKeyRequestParameters) {
handlerThread = new HandlerThread("OfflineLicenseHelper");
handlerThread.start();
Expand All @@ -137,7 +139,7 @@ public void onDrmKeysRemoved() {
conditionVariable.open();
}
};
drmSessionManager = new DefaultDrmSessionManager<>(C.WIDEVINE_UUID, mediaDrm, callback,
drmSessionManager = new DefaultDrmSessionManager<>(uuid, mediaDrm, callback,
optionalKeyRequestParameters, new Handler(handlerThread.getLooper()), eventListener);
}

Expand Down Expand Up @@ -174,12 +176,9 @@ public synchronized void setPropertyString(String key, String value) {
*
* @param drmInitData The {@link DrmInitData} for the content whose license is to be downloaded.
* @return The key set id for the downloaded license.
* @throws IOException If an error occurs reading data from the stream.
* @throws InterruptedException If the thread has been interrupted.
* @throws DrmSessionException Thrown when a DRM session error occurs.
*/
public synchronized byte[] downloadLicense(DrmInitData drmInitData) throws IOException,
InterruptedException, DrmSessionException {
public synchronized byte[] downloadLicense(DrmInitData drmInitData) throws DrmSessionException {
Assertions.checkArgument(drmInitData != null);
return blockingKeyRequest(DefaultDrmSessionManager.MODE_DOWNLOAD, null, drmInitData);
}
Expand Down

0 comments on commit 8940e7b

Please sign in to comment.