@Override public byte[] getOfflineLicenseKeySetId() { return keySetIdToRestore.asBytes(); }
public static KeySetId of(byte[] sessionId) { return new KeySetId(Arrays.copyOf(sessionId, sessionId.length)); }
@Override public int hashCode() { int result = mediaCrypto != null ? mediaCrypto.hashCode() : 0; result = 31 * result + (keySetIdToRestore != null ? keySetIdToRestore.hashCode() : 0); result = 31 * result + (sessionId != null ? sessionId.hashCode() : 0); return result; } }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } LocalDrmSession that = (LocalDrmSession) o; if (mediaCrypto != null ? !mediaCrypto.equals(that.mediaCrypto) : that.mediaCrypto != null) { return false; } if (keySetIdToRestore != null ? !keySetIdToRestore.equals(that.keySetIdToRestore) : that.keySetIdToRestore != null) { return false; } return sessionId != null ? sessionId.equals(that.sessionId) : that.sessionId == null; }
@SuppressWarnings("PMD.AvoidCatchingGenericException") // We are forced to catch Exception as ResourceBusyException is minSdk 19 @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) @Override public DrmSession<FrameworkMediaCrypto> acquireSession(Looper playbackLooper, DrmInitData drmInitData) { DrmSession<FrameworkMediaCrypto> drmSession; try { SessionId sessionId = SessionId.of(mediaDrm.openSession()); FrameworkMediaCrypto mediaCrypto = mediaDrm.createMediaCrypto(sessionId.asBytes()); mediaDrm.restoreKeys(sessionId.asBytes(), keySetIdToRestore.asBytes()); drmSession = new LocalDrmSession(mediaCrypto, keySetIdToRestore, sessionId); } catch (Exception exception) { drmSession = new InvalidDrmSession(new DrmSession.DrmSessionException(exception)); notifyErrorListener(drmSession); } return drmSession; }
@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()); }