diff options
author | Jeff Tinker <jtinker@google.com> | 2015-05-13 16:53:52 -0700 |
---|---|---|
committer | Jeff Tinker <jtinker@google.com> | 2015-05-15 01:44:59 +0000 |
commit | 5ffbae64920bf38e16c5831996f00c3d28ae1186 (patch) | |
tree | 78439cbc9b0f20d799b224ab9c50fdd475c7895c /media | |
parent | 5fccffd573395bbd21c477f064de7c25100c3f8a (diff) | |
download | frameworks_base-5ffbae64920bf38e16c5831996f00c3d28ae1186.zip frameworks_base-5ffbae64920bf38e16c5831996f00c3d28ae1186.tar.gz frameworks_base-5ffbae64920bf38e16c5831996f00c3d28ae1186.tar.bz2 |
MediaDrm API Updates per api council review
bug: 21044671
Change-Id: Ifb34e7b8cb53f7bd5737c0869fc6c1f731ba1c9c
Diffstat (limited to 'media')
-rw-r--r-- | media/java/android/media/MediaDrm.java | 165 | ||||
-rw-r--r-- | media/jni/android_media_MediaDrm.cpp | 22 |
2 files changed, 96 insertions, 91 deletions
diff --git a/media/java/android/media/MediaDrm.java b/media/java/android/media/MediaDrm.java index acff301..52ba9ec 100644 --- a/media/java/android/media/MediaDrm.java +++ b/media/java/android/media/MediaDrm.java @@ -110,10 +110,10 @@ public final class MediaDrm { private static final String PERMISSION = android.Manifest.permission.ACCESS_DRM_CERTIFICATES; private EventHandler mEventHandler; - private EventHandler mOnKeysChangeEventHandler; + private EventHandler mOnKeyStatusChangeEventHandler; private EventHandler mOnExpirationUpdateEventHandler; private OnEventListener mOnEventListener; - private OnKeysChangeListener mOnKeysChangeListener; + private OnKeyStatusChangeListener mOnKeyStatusChangeListener; private OnExpirationUpdateListener mOnExpirationUpdateListener; private long mNativeContext; @@ -297,8 +297,8 @@ public final class MediaDrm { * @param handler the handler on which the listener should be invoked, or * null if the listener should be invoked on the calling thread's looper. */ - public void setOnKeysChangeListener( - @Nullable OnKeysChangeListener listener, @Nullable Handler handler) { + public void setOnKeyStatusChangeListener( + @Nullable OnKeyStatusChangeListener listener, @Nullable Handler handler) { if (listener != null) { Looper looper = handler != null ? handler.getLooper() : Looper.myLooper(); if (looper != null) { @@ -307,14 +307,14 @@ public final class MediaDrm { } } } - mOnKeysChangeListener = listener; + mOnKeyStatusChangeListener = listener; } /** * Interface definition for a callback to be invoked when the keys in a drm * session change states. */ - public interface OnKeysChangeListener + public interface OnKeyStatusChangeListener { /** * Called when the keys in a session change status, such as when the license @@ -328,64 +328,64 @@ public final class MediaDrm { * which may trigger an attempt to resume playback on the media stream * if it is currently blocked waiting for a key. */ - void onKeysChange( + void onKeyStatusChange( @NonNull MediaDrm md, @NonNull byte[] sessionId, @NonNull List<KeyStatus> keyInformation, boolean hasNewUsableKey); } /** - * The key is currently usable to decrypt media data - */ - public static final int KEY_STATUS_USABLE = 0; - - /** - * The key is no longer usable to decrypt media data because its - * expiration time has passed. - */ - public static final int KEY_STATUS_EXPIRED = 1; - - /** - * The key is not currently usable to decrypt media data because its - * output requirements cannot currently be met. - */ - public static final int KEY_STATUS_OUTPUT_NOT_ALLOWED = 2; - - /** - * The status of the key is not yet known and is being determined. - * The status will be updated with the actual status when it has - * been determined. - */ - public static final int KEY_STATUS_PENDING = 3; - - /** - * The key is not currently usable to decrypt media data because of an - * internal error in processing unrelated to input parameters. This error - * is not actionable by an app. - */ - public static final int KEY_STATUS_INTERNAL_ERROR = 4; - - /** @hide */ - @IntDef({ - KEY_STATUS_USABLE, - KEY_STATUS_EXPIRED, - KEY_STATUS_OUTPUT_NOT_ALLOWED, - KEY_STATUS_PENDING, - KEY_STATUS_INTERNAL_ERROR, - }) - @Retention(RetentionPolicy.SOURCE) - public @interface KeyStatusCode {} - - /** * Defines the status of a key. * A KeyStatus for each key in a session is provided to the - * {@link OnKeysChangeListener#onKeysChange} + * {@link OnKeyStatusChangeListener#onKeyStatusChange} * listener. */ public static final class KeyStatus { private final byte[] mKeyId; private final int mStatusCode; + /** + * The key is currently usable to decrypt media data + */ + public static final int STATUS_USABLE = 0; + + /** + * The key is no longer usable to decrypt media data because its + * expiration time has passed. + */ + public static final int STATUS_EXPIRED = 1; + + /** + * The key is not currently usable to decrypt media data because its + * output requirements cannot currently be met. + */ + public static final int STATUS_OUTPUT_NOT_ALLOWED = 2; + + /** + * The status of the key is not yet known and is being determined. + * The status will be updated with the actual status when it has + * been determined. + */ + public static final int STATUS_PENDING = 3; + + /** + * The key is not currently usable to decrypt media data because of an + * internal error in processing unrelated to input parameters. This error + * is not actionable by an app. + */ + public static final int STATUS_INTERNAL_ERROR = 4; + + /** @hide */ + @IntDef({ + STATUS_USABLE, + STATUS_EXPIRED, + STATUS_OUTPUT_NOT_ALLOWED, + STATUS_PENDING, + STATUS_INTERNAL_ERROR, + }) + @Retention(RetentionPolicy.SOURCE) + public @interface KeyStatusCode {} + KeyStatus(@NonNull byte[] keyId, @KeyStatusCode int statusCode) { mKeyId = keyId; mStatusCode = statusCode; @@ -393,6 +393,9 @@ public final class MediaDrm { /** * Returns the status code for the key + * @return one of {@link #STATUS_USABLE}, {@link #STATUS_EXPIRED}, + * {@link #STATUS_OUTPUT_NOT_ALLOWED}, {@link #STATUS_PENDING} + * or {@link #STATUS_INTERNAL_ERROR}. */ @KeyStatusCode public int getStatusCode() { return mStatusCode; } @@ -484,7 +487,7 @@ public final class MediaDrm { private static final int DRM_EVENT = 200; private static final int EXPIRATION_UPDATE = 201; - private static final int KEYS_CHANGE = 202; + private static final int KEY_STATUS_CHANGE = 202; private class EventHandler extends Handler { @@ -522,8 +525,8 @@ public final class MediaDrm { } return; - case KEYS_CHANGE: - if (mOnKeysChangeListener != null) { + case KEY_STATUS_CHANGE: + if (mOnKeyStatusChangeListener != null) { if (msg.obj != null && msg.obj instanceof Parcel) { Parcel parcel = (Parcel)msg.obj; byte[] sessionId = parcel.createByteArray(); @@ -531,9 +534,9 @@ public final class MediaDrm { List<KeyStatus> keyStatusList = keyStatusListFromParcel(parcel); boolean hasNewUsableKey = (parcel.readInt() != 0); - Log.i(TAG, "Drm keys change"); - mOnKeysChangeListener.onKeysChange(mMediaDrm, sessionId, keyStatusList, - hasNewUsableKey); + Log.i(TAG, "Drm key status changed"); + mOnKeyStatusChangeListener.onKeyStatusChange(mMediaDrm, sessionId, + keyStatusList, hasNewUsableKey); } } } @@ -641,30 +644,6 @@ public final class MediaDrm { public @interface KeyType {} /** - * Key request type is initial license request - */ - public static final int REQUEST_TYPE_INITIAL = 0; - - /** - * Key request type is license renewal - */ - public static final int REQUEST_TYPE_RENEWAL = 1; - - /** - * Key request type is license release - */ - public static final int REQUEST_TYPE_RELEASE = 2; - - /** @hide */ - @IntDef({ - REQUEST_TYPE_INITIAL, - REQUEST_TYPE_RENEWAL, - REQUEST_TYPE_RELEASE, - }) - @Retention(RetentionPolicy.SOURCE) - public @interface RequestType {} - - /** * Contains the opaque data an app uses to request keys from a license server */ public static final class KeyRequest { @@ -672,6 +651,30 @@ public final class MediaDrm { private String mDefaultUrl; private int mRequestType; + /** + * Key request type is initial license request + */ + public static final int REQUEST_TYPE_INITIAL = 0; + + /** + * Key request type is license renewal + */ + public static final int REQUEST_TYPE_RENEWAL = 1; + + /** + * Key request type is license release + */ + public static final int REQUEST_TYPE_RELEASE = 2; + + /** @hide */ + @IntDef({ + REQUEST_TYPE_INITIAL, + REQUEST_TYPE_RENEWAL, + REQUEST_TYPE_RELEASE, + }) + @Retention(RetentionPolicy.SOURCE) + public @interface RequestType {} + KeyRequest() {} /** @@ -707,6 +710,8 @@ public final class MediaDrm { /** * Get the type of the request + * @return one of {@link #REQUEST_TYPE_INITIAL}, + * {@link #REQUEST_TYPE_RENEWAL} or {@link #REQUEST_TYPE_RELEASE} */ @RequestType public int getRequestType() { return mRequestType; } diff --git a/media/jni/android_media_MediaDrm.cpp b/media/jni/android_media_MediaDrm.cpp index f8146a7..d456dc1 100644 --- a/media/jni/android_media_MediaDrm.cpp +++ b/media/jni/android_media_MediaDrm.cpp @@ -99,7 +99,7 @@ struct EventTypes { struct EventWhat { jint kWhatDrmEvent; jint kWhatExpirationUpdate; - jint kWhatKeysChange; + jint kWhatKeyStatusChange; } gEventWhat; struct KeyTypes { @@ -221,7 +221,7 @@ void JNIDrmListener::notify(DrmPlugin::EventType eventType, int extra, jwhat = gEventWhat.kWhatExpirationUpdate; break; case DrmPlugin::kDrmPluginEventKeysChange: - jwhat = gEventWhat.kWhatKeysChange; + jwhat = gEventWhat.kWhatKeyStatusChange; break; default: ALOGE("Invalid event DrmPlugin::EventType %d, ignored", (int)eventType); @@ -609,8 +609,8 @@ static void android_media_MediaDrm_native_init(JNIEnv *env) { gEventWhat.kWhatDrmEvent = env->GetStaticIntField(clazz, field); GET_STATIC_FIELD_ID(field, clazz, "EXPIRATION_UPDATE", "I"); gEventWhat.kWhatExpirationUpdate = env->GetStaticIntField(clazz, field); - GET_STATIC_FIELD_ID(field, clazz, "KEYS_CHANGE", "I"); - gEventWhat.kWhatKeysChange = env->GetStaticIntField(clazz, field); + GET_STATIC_FIELD_ID(field, clazz, "KEY_STATUS_CHANGE", "I"); + gEventWhat.kWhatKeyStatusChange = env->GetStaticIntField(clazz, field); GET_STATIC_FIELD_ID(field, clazz, "KEY_TYPE_STREAMING", "I"); gKeyTypes.kKeyTypeStreaming = env->GetStaticIntField(clazz, field); @@ -619,13 +619,6 @@ static void android_media_MediaDrm_native_init(JNIEnv *env) { GET_STATIC_FIELD_ID(field, clazz, "KEY_TYPE_RELEASE", "I"); gKeyTypes.kKeyTypeRelease = env->GetStaticIntField(clazz, field); - GET_STATIC_FIELD_ID(field, clazz, "REQUEST_TYPE_INITIAL", "I"); - gKeyRequestTypes.kKeyRequestTypeInitial = env->GetStaticIntField(clazz, field); - GET_STATIC_FIELD_ID(field, clazz, "REQUEST_TYPE_RENEWAL", "I"); - gKeyRequestTypes.kKeyRequestTypeRenewal = env->GetStaticIntField(clazz, field); - GET_STATIC_FIELD_ID(field, clazz, "REQUEST_TYPE_RELEASE", "I"); - gKeyRequestTypes.kKeyRequestTypeRelease = env->GetStaticIntField(clazz, field); - GET_STATIC_FIELD_ID(field, clazz, "CERTIFICATE_TYPE_NONE", "I"); gCertificateTypes.kCertificateTypeNone = env->GetStaticIntField(clazz, field); GET_STATIC_FIELD_ID(field, clazz, "CERTIFICATE_TYPE_X509", "I"); @@ -636,6 +629,13 @@ static void android_media_MediaDrm_native_init(JNIEnv *env) { GET_FIELD_ID(gFields.keyRequest.defaultUrl, clazz, "mDefaultUrl", "Ljava/lang/String;"); GET_FIELD_ID(gFields.keyRequest.requestType, clazz, "mRequestType", "I"); + GET_STATIC_FIELD_ID(field, clazz, "REQUEST_TYPE_INITIAL", "I"); + gKeyRequestTypes.kKeyRequestTypeInitial = env->GetStaticIntField(clazz, field); + GET_STATIC_FIELD_ID(field, clazz, "REQUEST_TYPE_RENEWAL", "I"); + gKeyRequestTypes.kKeyRequestTypeRenewal = env->GetStaticIntField(clazz, field); + GET_STATIC_FIELD_ID(field, clazz, "REQUEST_TYPE_RELEASE", "I"); + gKeyRequestTypes.kKeyRequestTypeRelease = env->GetStaticIntField(clazz, field); + FIND_CLASS(clazz, "android/media/MediaDrm$ProvisionRequest"); GET_FIELD_ID(gFields.provisionRequest.data, clazz, "mData", "[B"); GET_FIELD_ID(gFields.provisionRequest.defaultUrl, clazz, "mDefaultUrl", "Ljava/lang/String;"); |