am 964955e0: am 8a9b14d8: am 5aeb8587: Merge "DRM framwork bug fix: add an API to release resources"
* commit '964955e0bd98166c16f705811ce46d0151924cc8': DRM framwork bug fix: add an API to release resources
This commit is contained in:
committed by
Android Git Automerger
commit
f73222a39e
@@ -7496,6 +7496,7 @@ package android.drm {
|
|||||||
method public java.lang.String getOriginalMimeType(android.net.Uri);
|
method public java.lang.String getOriginalMimeType(android.net.Uri);
|
||||||
method public int openConvertSession(java.lang.String);
|
method public int openConvertSession(java.lang.String);
|
||||||
method public int processDrmInfo(android.drm.DrmInfo);
|
method public int processDrmInfo(android.drm.DrmInfo);
|
||||||
|
method public void release();
|
||||||
method public int removeAllRights();
|
method public int removeAllRights();
|
||||||
method public int removeRights(java.lang.String);
|
method public int removeRights(java.lang.String);
|
||||||
method public int removeRights(android.net.Uri);
|
method public int removeRights(android.net.Uri);
|
||||||
|
|||||||
@@ -49,6 +49,8 @@ public class DrmManagerClient {
|
|||||||
*/
|
*/
|
||||||
public static final int ERROR_UNKNOWN = -2000;
|
public static final int ERROR_UNKNOWN = -2000;
|
||||||
|
|
||||||
|
HandlerThread mInfoThread;
|
||||||
|
HandlerThread mEventThread;
|
||||||
private static final String TAG = "DrmManagerClient";
|
private static final String TAG = "DrmManagerClient";
|
||||||
|
|
||||||
static {
|
static {
|
||||||
@@ -105,6 +107,7 @@ public class DrmManagerClient {
|
|||||||
|
|
||||||
private int mUniqueId;
|
private int mUniqueId;
|
||||||
private int mNativeContext;
|
private int mNativeContext;
|
||||||
|
private boolean mReleased;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private InfoHandler mInfoHandler;
|
private InfoHandler mInfoHandler;
|
||||||
private EventHandler mEventHandler;
|
private EventHandler mEventHandler;
|
||||||
@@ -238,23 +241,63 @@ public class DrmManagerClient {
|
|||||||
*/
|
*/
|
||||||
public DrmManagerClient(Context context) {
|
public DrmManagerClient(Context context) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
|
mReleased = false;
|
||||||
HandlerThread infoThread = new HandlerThread("DrmManagerClient.InfoHandler");
|
|
||||||
infoThread.start();
|
|
||||||
mInfoHandler = new InfoHandler(infoThread.getLooper());
|
|
||||||
|
|
||||||
HandlerThread eventThread = new HandlerThread("DrmManagerClient.EventHandler");
|
|
||||||
eventThread.start();
|
|
||||||
mEventHandler = new EventHandler(eventThread.getLooper());
|
|
||||||
|
|
||||||
// save the unique id
|
// save the unique id
|
||||||
mUniqueId = _initialize(new WeakReference<DrmManagerClient>(this));
|
mUniqueId = _initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void finalize() {
|
protected void finalize() {
|
||||||
_finalize(mUniqueId);
|
if (!mReleased) {
|
||||||
|
Log.w(TAG, "You should have called release()");
|
||||||
|
release();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Releases resources associated with the current session of DrmManagerClient.
|
||||||
|
*
|
||||||
|
* It is considered good practice to call this method when the {@link DrmManagerClient} object
|
||||||
|
* is no longer needed in your application. After release() is called,
|
||||||
|
* {@link DrmManagerClient} is no longer usable since it has lost all of its required resource.
|
||||||
|
*/
|
||||||
|
public void release() {
|
||||||
|
if (mReleased) {
|
||||||
|
Log.w(TAG, "You have already called release()");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mReleased = true;
|
||||||
|
if (mEventHandler != null) {
|
||||||
|
mEventThread.quit();
|
||||||
|
mEventThread = null;
|
||||||
|
}
|
||||||
|
if (mInfoHandler != null) {
|
||||||
|
mInfoThread.quit();
|
||||||
|
mInfoThread = null;
|
||||||
|
}
|
||||||
|
mEventHandler = null;
|
||||||
|
mInfoHandler = null;
|
||||||
|
mOnEventListener = null;
|
||||||
|
mOnInfoListener = null;
|
||||||
|
mOnErrorListener = null;
|
||||||
|
_release(mUniqueId);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void createListeners() {
|
||||||
|
if (mEventHandler == null && mInfoHandler == null) {
|
||||||
|
mInfoThread = new HandlerThread("DrmManagerClient.InfoHandler");
|
||||||
|
mInfoThread.start();
|
||||||
|
mInfoHandler = new InfoHandler(mInfoThread.getLooper());
|
||||||
|
|
||||||
|
mEventThread = new HandlerThread("DrmManagerClient.EventHandler");
|
||||||
|
mEventThread.start();
|
||||||
|
mEventHandler = new EventHandler(mEventThread.getLooper());
|
||||||
|
_setListeners(mUniqueId, new WeakReference<DrmManagerClient>(this));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers an {@link DrmManagerClient.OnInfoListener} callback, which is invoked when the
|
* Registers an {@link DrmManagerClient.OnInfoListener} callback, which is invoked when the
|
||||||
* DRM framework sends status or warning information during registration or rights acquisition.
|
* DRM framework sends status or warning information during registration or rights acquisition.
|
||||||
@@ -262,8 +305,9 @@ public class DrmManagerClient {
|
|||||||
* @param infoListener Interface definition for the callback.
|
* @param infoListener Interface definition for the callback.
|
||||||
*/
|
*/
|
||||||
public synchronized void setOnInfoListener(OnInfoListener infoListener) {
|
public synchronized void setOnInfoListener(OnInfoListener infoListener) {
|
||||||
|
mOnInfoListener = infoListener;
|
||||||
if (null != infoListener) {
|
if (null != infoListener) {
|
||||||
mOnInfoListener = infoListener;
|
createListeners();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -274,8 +318,9 @@ public class DrmManagerClient {
|
|||||||
* @param eventListener Interface definition for the callback.
|
* @param eventListener Interface definition for the callback.
|
||||||
*/
|
*/
|
||||||
public synchronized void setOnEventListener(OnEventListener eventListener) {
|
public synchronized void setOnEventListener(OnEventListener eventListener) {
|
||||||
|
mOnEventListener = eventListener;
|
||||||
if (null != eventListener) {
|
if (null != eventListener) {
|
||||||
mOnEventListener = eventListener;
|
createListeners();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -286,8 +331,9 @@ public class DrmManagerClient {
|
|||||||
* @param errorListener Interface definition for the callback.
|
* @param errorListener Interface definition for the callback.
|
||||||
*/
|
*/
|
||||||
public synchronized void setOnErrorListener(OnErrorListener errorListener) {
|
public synchronized void setOnErrorListener(OnErrorListener errorListener) {
|
||||||
|
mOnErrorListener = errorListener;
|
||||||
if (null != errorListener) {
|
if (null != errorListener) {
|
||||||
mOnErrorListener = errorListener;
|
createListeners();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -792,9 +838,11 @@ public class DrmManagerClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// private native interfaces
|
// private native interfaces
|
||||||
private native int _initialize(Object weak_this);
|
private native int _initialize();
|
||||||
|
|
||||||
private native void _finalize(int uniqueId);
|
private native void _setListeners(int uniqueId, Object weak_this);
|
||||||
|
|
||||||
|
private native void _release(int uniqueId);
|
||||||
|
|
||||||
private native void _installDrmEngine(int uniqueId, String engineFilepath);
|
private native void _installDrmEngine(int uniqueId, String engineFilepath);
|
||||||
|
|
||||||
|
|||||||
@@ -225,25 +225,32 @@ static sp<DrmManagerClientImpl> getDrmManagerClientImpl(JNIEnv* env, jobject thi
|
|||||||
}
|
}
|
||||||
|
|
||||||
static jint android_drm_DrmManagerClient_initialize(
|
static jint android_drm_DrmManagerClient_initialize(
|
||||||
JNIEnv* env, jobject thiz, jobject weak_thiz) {
|
JNIEnv* env, jobject thiz) {
|
||||||
ALOGV("initialize - Enter");
|
ALOGV("initialize - Enter");
|
||||||
|
|
||||||
int uniqueId = 0;
|
int uniqueId = 0;
|
||||||
sp<DrmManagerClientImpl> drmManager = DrmManagerClientImpl::create(&uniqueId, false);
|
sp<DrmManagerClientImpl> drmManager = DrmManagerClientImpl::create(&uniqueId, false);
|
||||||
drmManager->addClient(uniqueId);
|
drmManager->addClient(uniqueId);
|
||||||
|
|
||||||
// Set the listener to DrmManager
|
|
||||||
sp<DrmManagerClient::OnInfoListener> listener = new JNIOnInfoListener(env, thiz, weak_thiz);
|
|
||||||
drmManager->setOnInfoListener(uniqueId, listener);
|
|
||||||
|
|
||||||
setDrmManagerClientImpl(env, thiz, drmManager);
|
setDrmManagerClientImpl(env, thiz, drmManager);
|
||||||
ALOGV("initialize - Exit");
|
ALOGV("initialize - Exit");
|
||||||
|
|
||||||
return uniqueId;
|
return uniqueId;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void android_drm_DrmManagerClient_finalize(JNIEnv* env, jobject thiz, jint uniqueId) {
|
static void android_drm_DrmManagerClient_setListeners(
|
||||||
ALOGV("finalize - Enter");
|
JNIEnv* env, jobject thiz, jint uniqueId, jobject weak_thiz) {
|
||||||
|
ALOGV("setListeners - Enter");
|
||||||
|
|
||||||
|
// Set the listener to DrmManager
|
||||||
|
sp<DrmManagerClient::OnInfoListener> listener = new JNIOnInfoListener(env, thiz, weak_thiz);
|
||||||
|
getDrmManagerClientImpl(env, thiz)->setOnInfoListener(uniqueId, listener);
|
||||||
|
|
||||||
|
ALOGV("setListeners - Exit");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void android_drm_DrmManagerClient_release(
|
||||||
|
JNIEnv* env, jobject thiz, jint uniqueId) {
|
||||||
|
ALOGV("release - Enter");
|
||||||
DrmManagerClientImpl::remove(uniqueId);
|
DrmManagerClientImpl::remove(uniqueId);
|
||||||
getDrmManagerClientImpl(env, thiz)->setOnInfoListener(uniqueId, NULL);
|
getDrmManagerClientImpl(env, thiz)->setOnInfoListener(uniqueId, NULL);
|
||||||
|
|
||||||
@@ -252,7 +259,7 @@ static void android_drm_DrmManagerClient_finalize(JNIEnv* env, jobject thiz, jin
|
|||||||
oldClient->setOnInfoListener(uniqueId, NULL);
|
oldClient->setOnInfoListener(uniqueId, NULL);
|
||||||
oldClient->removeClient(uniqueId);
|
oldClient->removeClient(uniqueId);
|
||||||
}
|
}
|
||||||
ALOGV("finalize - Exit");
|
ALOGV("release - Exit");
|
||||||
}
|
}
|
||||||
|
|
||||||
static jobject android_drm_DrmManagerClient_getConstraintsFromContent(
|
static jobject android_drm_DrmManagerClient_getConstraintsFromContent(
|
||||||
@@ -714,11 +721,14 @@ static jobject android_drm_DrmManagerClient_closeConvertSession(
|
|||||||
|
|
||||||
static JNINativeMethod nativeMethods[] = {
|
static JNINativeMethod nativeMethods[] = {
|
||||||
|
|
||||||
{"_initialize", "(Ljava/lang/Object;)I",
|
{"_initialize", "()I",
|
||||||
(void*)android_drm_DrmManagerClient_initialize},
|
(void*)android_drm_DrmManagerClient_initialize},
|
||||||
|
|
||||||
{"_finalize", "(I)V",
|
{"_setListeners", "(ILjava/lang/Object;)V",
|
||||||
(void*)android_drm_DrmManagerClient_finalize},
|
(void*)android_drm_DrmManagerClient_setListeners},
|
||||||
|
|
||||||
|
{"_release", "(I)V",
|
||||||
|
(void*)android_drm_DrmManagerClient_release},
|
||||||
|
|
||||||
{"_getConstraints", "(ILjava/lang/String;I)Landroid/content/ContentValues;",
|
{"_getConstraints", "(ILjava/lang/String;I)Landroid/content/ContentValues;",
|
||||||
(void*)android_drm_DrmManagerClient_getConstraintsFromContent},
|
(void*)android_drm_DrmManagerClient_getConstraintsFromContent},
|
||||||
|
|||||||
Reference in New Issue
Block a user