下面列出了android.media.MediaCrypto#android.media.NotProvisionedException 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public KeyRequest getKeyRequest(byte[] scope, byte[] init, String mimeType, int keyType,
HashMap<String, String> optionalParameters) throws NotProvisionedException {
final MediaDrm.KeyRequest request = mediaDrm.getKeyRequest(scope, init, mimeType, keyType,
optionalParameters);
return new KeyRequest() {
@Override
public byte[] getData() {
return request.getData();
}
@Override
public String getDefaultUrl() {
return request.getDefaultUrl();
}
};
}
private void onKeysError(Exception e) {
if (e instanceof NotProvisionedException) {
provisioningManager.provisionRequired(this);
} else {
onError(e);
}
}
@Override
public KeyRequest getKeyRequest(
byte[] scope,
@Nullable List<SchemeData> schemeDatas,
int keyType,
@Nullable HashMap<String, String> optionalParameters)
throws NotProvisionedException {
SchemeData schemeData = null;
byte[] initData = null;
String mimeType = null;
if (schemeDatas != null) {
schemeData = getSchemeData(uuid, schemeDatas);
initData = adjustRequestInitData(uuid, Assertions.checkNotNull(schemeData.data));
mimeType = adjustRequestMimeType(uuid, schemeData.mimeType);
}
MediaDrm.KeyRequest request =
mediaDrm.getKeyRequest(scope, initData, mimeType, keyType, optionalParameters);
byte[] requestData = adjustRequestData(uuid, request.getData());
String licenseServerUrl = request.getDefaultUrl();
if (MOCK_LA_URL_VALUE.equals(licenseServerUrl)) {
licenseServerUrl = "";
}
if (TextUtils.isEmpty(licenseServerUrl)
&& schemeData != null
&& !TextUtils.isEmpty(schemeData.licenseServerUrl)) {
licenseServerUrl = schemeData.licenseServerUrl;
}
return new KeyRequest(requestData, licenseServerUrl);
}
@Nullable
@Override
public byte[] provideKeyResponse(byte[] scope, byte[] response)
throws NotProvisionedException, DeniedByServerException {
if (C.CLEARKEY_UUID.equals(uuid)) {
response = ClearKeyUtil.adjustResponseData(response);
}
return mediaDrm.provideKeyResponse(scope, response);
}
private void onKeysError(Exception e) {
if (e instanceof NotProvisionedException) {
provisioningManager.provisionRequired(this);
} else {
onError(e);
}
}
@Override
public KeyRequest getKeyRequest(byte[] scope, byte[] init, String mimeType, int keyType,
HashMap<String, String> optionalParameters) throws NotProvisionedException {
// Prior to L the Widevine CDM required data to be extracted from the PSSH atom. Some Amazon
// devices also required data to be extracted from the PSSH atom for PlayReady.
if ((Util.SDK_INT < 21 && C.WIDEVINE_UUID.equals(uuid))
|| (C.PLAYREADY_UUID.equals(uuid)
&& "Amazon".equals(Util.MANUFACTURER)
&& ("AFTB".equals(Util.MODEL) // Fire TV Gen 1
|| "AFTS".equals(Util.MODEL) // Fire TV Gen 2
|| "AFTM".equals(Util.MODEL)))) { // Fire TV Stick Gen 1
byte[] psshData = PsshAtomUtil.parseSchemeSpecificData(init, uuid);
if (psshData == null) {
// Extraction failed. schemeData isn't a PSSH atom, so leave it unchanged.
} else {
init = psshData;
}
}
// Prior to API level 26 the ClearKey CDM only accepted "cenc" as the scheme for MP4.
if (Util.SDK_INT < 26
&& C.CLEARKEY_UUID.equals(uuid)
&& (MimeTypes.VIDEO_MP4.equals(mimeType) || MimeTypes.AUDIO_MP4.equals(mimeType))) {
mimeType = CENC_SCHEME_MIME_TYPE;
}
final MediaDrm.KeyRequest request = mediaDrm.getKeyRequest(scope, init, mimeType, keyType,
optionalParameters);
byte[] requestData = request.getData();
if (C.CLEARKEY_UUID.equals(uuid)) {
requestData = ClearKeyUtil.adjustRequestData(requestData);
}
return new DefaultKeyRequest(requestData, request.getDefaultUrl());
}
@Override
public byte[] provideKeyResponse(byte[] scope, byte[] response)
throws NotProvisionedException, DeniedByServerException {
if (C.CLEARKEY_UUID.equals(uuid)) {
response = ClearKeyUtil.adjustResponseData(response);
}
return mediaDrm.provideKeyResponse(scope, response);
}
/** @see MediaDrm#getKeyRequest(byte[], byte[], String, int, HashMap) */
KeyRequest getKeyRequest(
byte[] scope,
byte[] init,
String mimeType,
int keyType,
HashMap<String, String> optionalParameters)
throws NotProvisionedException;
private void onKeysError(Exception e) {
if (e instanceof NotProvisionedException) {
provisioningManager.provisionRequired(this);
} else {
onError(e);
}
}
@Override
public KeyRequest getKeyRequest(byte[] scope, byte[] init, String mimeType, int keyType,
HashMap<String, String> optionalParameters) throws NotProvisionedException {
// Prior to L the Widevine CDM required data to be extracted from the PSSH atom. Some Amazon
// devices also required data to be extracted from the PSSH atom for PlayReady.
if ((Util.SDK_INT < 21 && C.WIDEVINE_UUID.equals(uuid))
|| (C.PLAYREADY_UUID.equals(uuid)
&& "Amazon".equals(Util.MANUFACTURER)
&& ("AFTB".equals(Util.MODEL) // Fire TV Gen 1
|| "AFTS".equals(Util.MODEL) // Fire TV Gen 2
|| "AFTM".equals(Util.MODEL)))) { // Fire TV Stick Gen 1
byte[] psshData = PsshAtomUtil.parseSchemeSpecificData(init, uuid);
if (psshData == null) {
// Extraction failed. schemeData isn't a PSSH atom, so leave it unchanged.
} else {
init = psshData;
}
}
// Prior to API level 26 the ClearKey CDM only accepted "cenc" as the scheme for MP4.
if (Util.SDK_INT < 26
&& C.CLEARKEY_UUID.equals(uuid)
&& (MimeTypes.VIDEO_MP4.equals(mimeType) || MimeTypes.AUDIO_MP4.equals(mimeType))) {
mimeType = CENC_SCHEME_MIME_TYPE;
}
final MediaDrm.KeyRequest request = mediaDrm.getKeyRequest(scope, init, mimeType, keyType,
optionalParameters);
byte[] requestData = request.getData();
if (C.CLEARKEY_UUID.equals(uuid)) {
requestData = ClearKeyUtil.adjustRequestData(requestData);
}
return new DefaultKeyRequest(requestData, request.getDefaultUrl());
}
@Override
public byte[] provideKeyResponse(byte[] scope, byte[] response)
throws NotProvisionedException, DeniedByServerException {
if (C.CLEARKEY_UUID.equals(uuid)) {
response = ClearKeyUtil.adjustResponseData(response);
}
return mediaDrm.provideKeyResponse(scope, response);
}
/** @see MediaDrm#getKeyRequest(byte[], byte[], String, int, HashMap) */
KeyRequest getKeyRequest(
byte[] scope,
byte[] init,
String mimeType,
int keyType,
HashMap<String, String> optionalParameters)
throws NotProvisionedException;
private void onKeysError(Exception e) {
if (e instanceof NotProvisionedException) {
postProvisionRequest();
} else {
onError(e);
}
}
private void postKeyRequest() {
KeyRequest keyRequest;
try {
keyRequest = mediaDrm.getKeyRequest(sessionId, schemePsshData, mimeType,
MediaDrm.KEY_TYPE_STREAMING, optionalKeyRequestParameters);
postRequestHandler.obtainMessage(MSG_KEYS, keyRequest).sendToTarget();
} catch (NotProvisionedException e) {
onKeysError(e);
}
}
private void onKeysError(Exception e) {
if (e instanceof NotProvisionedException) {
postProvisionRequest();
} else {
onError(e);
}
}
private void onKeysError(Exception e) {
if (e instanceof NotProvisionedException) {
provisioningManager.provisionRequired(this);
} else {
onError(e);
}
}
@Override
public KeyRequest getKeyRequest(
byte[] scope,
@Nullable List<DrmInitData.SchemeData> schemeDatas,
int keyType,
@Nullable HashMap<String, String> optionalParameters)
throws NotProvisionedException {
SchemeData schemeData = null;
byte[] initData = null;
String mimeType = null;
if (schemeDatas != null) {
schemeData = getSchemeData(uuid, schemeDatas);
initData = adjustRequestInitData(uuid, Assertions.checkNotNull(schemeData.data));
mimeType = adjustRequestMimeType(uuid, schemeData.mimeType);
}
MediaDrm.KeyRequest request =
mediaDrm.getKeyRequest(scope, initData, mimeType, keyType, optionalParameters);
byte[] requestData = adjustRequestData(uuid, request.getData());
String licenseServerUrl = request.getDefaultUrl();
if (MOCK_LA_URL_VALUE.equals(licenseServerUrl)) {
licenseServerUrl = "";
}
if (TextUtils.isEmpty(licenseServerUrl)
&& schemeData != null
&& !TextUtils.isEmpty(schemeData.licenseServerUrl)) {
licenseServerUrl = schemeData.licenseServerUrl;
}
return new KeyRequest(requestData, licenseServerUrl);
}
@Nullable
@Override
public byte[] provideKeyResponse(byte[] scope, byte[] response)
throws NotProvisionedException, DeniedByServerException {
if (C.CLEARKEY_UUID.equals(uuid)) {
response = ClearKeyUtil.adjustResponseData(response);
}
return mediaDrm.provideKeyResponse(scope, response);
}
private void onKeysError(Exception e) {
if (e instanceof NotProvisionedException) {
provisioningManager.provisionRequired(this);
} else {
onError(e);
}
}
@Override
public KeyRequest getKeyRequest(
byte[] scope,
@Nullable List<DrmInitData.SchemeData> schemeDatas,
int keyType,
@Nullable HashMap<String, String> optionalParameters)
throws NotProvisionedException {
SchemeData schemeData = null;
byte[] initData = null;
String mimeType = null;
if (schemeDatas != null) {
schemeData = getSchemeData(uuid, schemeDatas);
initData = adjustRequestInitData(uuid, Assertions.checkNotNull(schemeData.data));
mimeType = adjustRequestMimeType(uuid, schemeData.mimeType);
}
MediaDrm.KeyRequest request =
mediaDrm.getKeyRequest(scope, initData, mimeType, keyType, optionalParameters);
byte[] requestData = adjustRequestData(uuid, request.getData());
String licenseServerUrl = request.getDefaultUrl();
if (MOCK_LA_URL_VALUE.equals(licenseServerUrl)) {
licenseServerUrl = "";
}
if (TextUtils.isEmpty(licenseServerUrl)
&& schemeData != null
&& !TextUtils.isEmpty(schemeData.licenseServerUrl)) {
licenseServerUrl = schemeData.licenseServerUrl;
}
return new KeyRequest(requestData, licenseServerUrl);
}
@Nullable
@Override
public byte[] provideKeyResponse(byte[] scope, byte[] response)
throws NotProvisionedException, DeniedByServerException {
if (C.CLEARKEY_UUID.equals(uuid)) {
response = ClearKeyUtil.adjustResponseData(response);
}
return mediaDrm.provideKeyResponse(scope, response);
}
/** @see MediaDrm#provideKeyResponse(byte[], byte[]) */
@Nullable
byte[] provideKeyResponse(byte[] scope, byte[] response)
throws NotProvisionedException, DeniedByServerException;
/** @see MediaDrm#provideKeyResponse(byte[], byte[]) */
byte[] provideKeyResponse(byte[] scope, byte[] response)
throws NotProvisionedException, DeniedByServerException;
/** @see MediaDrm#provideKeyResponse(byte[], byte[]) */
byte[] provideKeyResponse(byte[] scope, byte[] response)
throws NotProvisionedException, DeniedByServerException;
@Override
public byte[] openSession() throws NotProvisionedException, ResourceBusyException {
return mediaDrm.openSession();
}
@Override
public byte[] provideKeyResponse(byte[] scope, byte[] response)
throws NotProvisionedException, DeniedByServerException {
return mediaDrm.provideKeyResponse(scope, response);
}
/** @see MediaDrm#provideKeyResponse(byte[], byte[]) */
@Nullable
byte[] provideKeyResponse(byte[] scope, byte[] response)
throws NotProvisionedException, DeniedByServerException;
/** @see MediaDrm#provideKeyResponse(byte[], byte[]) */
@Nullable
byte[] provideKeyResponse(byte[] scope, byte[] response)
throws NotProvisionedException, DeniedByServerException;
/**
* Generates a key request.
*
* @param scope If {@code keyType} is {@link #KEY_TYPE_STREAMING} or {@link #KEY_TYPE_OFFLINE},
* the session id that the keys will be provided to. If {@code keyType} is {@link
* #KEY_TYPE_RELEASE}, the keySetId of the keys to release.
* @param schemeDatas If key type is {@link #KEY_TYPE_STREAMING} or {@link #KEY_TYPE_OFFLINE}, a
* list of {@link SchemeData} instances extracted from the media. Null otherwise.
* @param keyType The type of the request. Either {@link #KEY_TYPE_STREAMING} to acquire keys for
* streaming, {@link #KEY_TYPE_OFFLINE} to acquire keys for offline usage, or {@link
* #KEY_TYPE_RELEASE} to release acquired keys. Releasing keys invalidates them for all
* sessions.
* @param optionalParameters Are included in the key request message to allow a client application
* to provide additional message parameters to the server. This may be {@code null} if no
* additional parameters are to be sent.
* @return The generated key request.
* @see MediaDrm#getKeyRequest(byte[], byte[], String, int, HashMap)
*/
KeyRequest getKeyRequest(
byte[] scope,
@Nullable List<SchemeData> schemeDatas,
int keyType,
@Nullable HashMap<String, String> optionalParameters)
throws NotProvisionedException;
/**
* Generates a key request.
*
* @param scope If {@code keyType} is {@link #KEY_TYPE_STREAMING} or {@link #KEY_TYPE_OFFLINE},
* the session id that the keys will be provided to. If {@code keyType} is {@link
* #KEY_TYPE_RELEASE}, the keySetId of the keys to release.
* @param schemeDatas If key type is {@link #KEY_TYPE_STREAMING} or {@link #KEY_TYPE_OFFLINE}, a
* list of {@link SchemeData} instances extracted from the media. Null otherwise.
* @param keyType The type of the request. Either {@link #KEY_TYPE_STREAMING} to acquire keys for
* streaming, {@link #KEY_TYPE_OFFLINE} to acquire keys for offline usage, or {@link
* #KEY_TYPE_RELEASE} to release acquired keys. Releasing keys invalidates them for all
* sessions.
* @param optionalParameters Are included in the key request message to allow a client application
* to provide additional message parameters to the server. This may be {@code null} if no
* additional parameters are to be sent.
* @return The generated key request.
* @see MediaDrm#getKeyRequest(byte[], byte[], String, int, HashMap)
*/
KeyRequest getKeyRequest(
byte[] scope,
@Nullable List<SchemeData> schemeDatas,
int keyType,
@Nullable HashMap<String, String> optionalParameters)
throws NotProvisionedException;