@Before public void setUp() throws MediaDrmException, MediaCryptoException { frameworkMediaCrypto = FrameworkMediaCryptoFixture.aFrameworkMediaCrypto().build(); given(mediaDrm.openSession()).willReturn(SESSION_ID.asBytes()); localDrmSessionManager = new LocalDrmSessionManager( KEY_SET_ID_TO_RESTORE, mediaDrm, DRM_SCHEME, handler, eventListener ); }
@Test public void givenValidMediaDrm_whenAcquiringSession_thenRestoresKeys() throws MediaCryptoException { given(mediaDrm.createMediaCrypto(SESSION_ID.asBytes())).willReturn(frameworkMediaCrypto); localDrmSessionManager.acquireSession(IGNORED_LOOPER, IGNORED_DRM_DATA); verify(mediaDrm).restoreKeys(SESSION_ID.asBytes(), KEY_SET_ID_TO_RESTORE.asBytes()); }
@Test public void givenValidMediaDrm_whenAcquiringSession_thenReturnsLocalDrmSession() throws MediaCryptoException { given(mediaDrm.createMediaCrypto(SESSION_ID.asBytes())).willReturn(frameworkMediaCrypto); DrmSession<FrameworkMediaCrypto> drmSession = localDrmSessionManager.acquireSession(IGNORED_LOOPER, IGNORED_DRM_DATA); LocalDrmSession localDrmSession = new LocalDrmSession(frameworkMediaCrypto, KEY_SET_ID_TO_RESTORE, SESSION_ID); assertThat(drmSession).isEqualTo(localDrmSession); }
@Override public FrameworkMediaCrypto createMediaCrypto(byte[] initData) throws MediaCryptoException { // Work around a bug prior to Lollipop where L1 Widevine forced into L3 mode would still // indicate that it required secure video decoders [Internal ref: b/11428937]. boolean forceAllowInsecureDecoderComponents = Util.SDK_INT < 21 && C.WIDEVINE_UUID.equals(uuid) && "L3".equals(getPropertyString("securityLevel")); return new FrameworkMediaCrypto(new MediaCrypto(uuid, initData), forceAllowInsecureDecoderComponents); }
@Override public FrameworkMediaCrypto createMediaCrypto(UUID uuid, byte[] initData) throws MediaCryptoException { // Work around a bug prior to Lollipop where L1 Widevine forced into L3 mode would still // indicate that it required secure video decoders [Internal ref: b/11428937]. boolean forceAllowInsecureDecoderComponents = Util.SDK_INT < 21 && C.WIDEVINE_UUID.equals(uuid) && "L3".equals(getPropertyString("securityLevel")); return new FrameworkMediaCrypto(new MediaCrypto(uuid, initData), forceAllowInsecureDecoderComponents); }
@Override public FrameworkMediaCrypto createMediaCrypto(UUID uuid, byte[] initData) throws MediaCryptoException { return new FrameworkMediaCrypto(new MediaCrypto(uuid, initData)); }
private FrameworkMediaCryptoFixture() throws MediaCryptoException { // Static factory method. }
public static FrameworkMediaCryptoFixture aFrameworkMediaCrypto() throws MediaCryptoException { return new FrameworkMediaCryptoFixture(); }
static MediaDrmSession openSessionWithKeys(MediaDrm mediaDrm, OfflineKeySetStorage storage, byte[] initData) throws MediaDrmException, MediaCryptoException, FileNotFoundException { byte[] keySetId = storage.loadKeySetId(initData); MediaDrmSession session = MediaDrmSession.open(mediaDrm); session.restoreKeys(keySetId); Map<String, String> keyStatus = session.queryKeyStatus(); Log.d(TAG, "keyStatus: " + keyStatus); return session; }
/** * @see android.media.MediaCrypto#MediaCrypto(UUID, byte[]) * * @param uuid The UUID of the crypto scheme. * @param initData Opaque initialization data specific to the crypto scheme. * @return An object extends {@link ExoMediaCrypto}, using opaque crypto scheme specific data. * @throws MediaCryptoException */ T createMediaCrypto(UUID uuid, byte[] initData) throws MediaCryptoException;
/** * @see android.media.MediaCrypto#MediaCrypto(UUID, byte[]) * * @param initData Opaque initialization data specific to the crypto scheme. * @return An object extends {@link ExoMediaCrypto}, using opaque crypto scheme specific data. * @throws MediaCryptoException If the instance can't be created. */ T createMediaCrypto(byte[] initData) throws MediaCryptoException;