Skip to content

Commit f05913a

Browse files
author
Takeshi Aimi
committed
DRM Framework bug fixes.
- Make sure to clean-up obsolete listeners. - Close cursor after using it. - Add virtual destructor to the base class of OnInfoListener. Changes are made by SEMC and Sony. Change-Id: Ibb6dd625ef48e3597188f0d7c90f9d4c780b6139
1 parent f0f6c54 commit f05913a

File tree

5 files changed

+38
-21
lines changed

5 files changed

+38
-21
lines changed

drm/drmserver/DrmManager.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,11 @@ status_t DrmManager::unloadPlugIns() {
117117
status_t DrmManager::setDrmServiceListener(
118118
int uniqueId, const sp<IDrmServiceListener>& drmServiceListener) {
119119
Mutex::Autolock _l(mLock);
120-
mServiceListeners.add(uniqueId, drmServiceListener);
120+
if (NULL != drmServiceListener.get()) {
121+
mServiceListeners.add(uniqueId, drmServiceListener);
122+
} else {
123+
mServiceListeners.removeItem(uniqueId);
124+
}
121125
return DRM_NO_ERROR;
122126
}
123127

drm/java/android/drm/DrmManagerClient.java

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -738,26 +738,34 @@ private int getErrorType(int infoType) {
738738
*/
739739
private String convertUriToPath(Uri uri) {
740740
String path = null;
741-
String scheme = uri.getScheme();
742-
if (null == scheme || scheme.equals("") || scheme.equals(ContentResolver.SCHEME_FILE)) {
743-
path = uri.getPath();
744-
} else if (scheme.equals(ContentResolver.SCHEME_CONTENT)) {
745-
String[] projection = new String[] {MediaStore.MediaColumns.DATA};
746-
Cursor cursor = null;
747-
try {
748-
cursor = mContext.getContentResolver().query(uri, projection, null, null, null);
749-
} catch (SQLiteException e) {
750-
throw new IllegalArgumentException("Given Uri is not formatted in a way " +
751-
"so that it can be found in media store.");
752-
}
753-
if (null == cursor || 0 == cursor.getCount() || !cursor.moveToFirst()) {
754-
throw new IllegalArgumentException("Given Uri could not be found in media store");
741+
if (null != uri) {
742+
String scheme = uri.getScheme();
743+
if (null == scheme || scheme.equals("") ||
744+
scheme.equals(ContentResolver.SCHEME_FILE)) {
745+
path = uri.getPath();
746+
} else if (scheme.equals(ContentResolver.SCHEME_CONTENT)) {
747+
String[] projection = new String[] {MediaStore.MediaColumns.DATA};
748+
Cursor cursor = null;
749+
try {
750+
cursor = mContext.getContentResolver().query(uri, projection, null,
751+
null, null);
752+
if (null == cursor || 0 == cursor.getCount() || !cursor.moveToFirst()) {
753+
throw new IllegalArgumentException("Given Uri could not be found" +
754+
" in media store");
755+
}
756+
int pathIndex = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA);
757+
path = cursor.getString(pathIndex);
758+
} catch (SQLiteException e) {
759+
throw new IllegalArgumentException("Given Uri is not formatted in a way " +
760+
"so that it can be found in media store.");
761+
} finally {
762+
if (null != cursor) {
763+
cursor.close();
764+
}
765+
}
766+
} else {
767+
throw new IllegalArgumentException("Given Uri scheme is not supported");
755768
}
756-
int pathIndex = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA);
757-
path = cursor.getString(pathIndex);
758-
cursor.close();
759-
} else {
760-
throw new IllegalArgumentException("Given Uri scheme is not supported");
761769
}
762770
return path;
763771
}

drm/libdrmframework/DrmManagerClient.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ DrmManagerClient::DrmManagerClient():
3131
DrmManagerClient::~DrmManagerClient() {
3232
DrmManagerClientImpl::remove(mUniqueId);
3333
mDrmManagerClientImpl->removeClient(mUniqueId);
34+
mDrmManagerClientImpl->setOnInfoListener(mUniqueId, NULL);
3435
delete mDrmManagerClientImpl; mDrmManagerClientImpl = NULL;
3536
}
3637

drm/libdrmframework/DrmManagerClientImpl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ status_t DrmManagerClientImpl::setOnInfoListener(
8181
int uniqueId, const sp<DrmManagerClient::OnInfoListener>& infoListener) {
8282
Mutex::Autolock _l(mLock);
8383
mOnInfoListener = infoListener;
84-
return getDrmManagerService()->setDrmServiceListener(uniqueId, this);
84+
return getDrmManagerService()->setDrmServiceListener(uniqueId,
85+
(NULL != infoListener.get()) ? this : NULL);
8586
}
8687

8788
status_t DrmManagerClientImpl::installDrmEngine(int uniqueId, const String8& drmEngineFile) {

include/drm/DrmManagerClient.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ class DrmManagerClient {
4848
public:
4949
class OnInfoListener: virtual public RefBase {
5050

51+
public:
52+
virtual ~OnInfoListener() {}
53+
5154
public:
5255
virtual void onInfo(const DrmInfoEvent& event) = 0;
5356
};

0 commit comments

Comments
 (0)