Fix for bug 3477330

This patch fixs a crash bug caused by using a NULL DecryptHandle pointer.
Fix by using sp<DecryptHandle> instead.

Change-Id: Icbd59858385e8256125a615a3c82656b25319d44
This commit is contained in:
Gloria Wang
2011-02-24 16:40:57 -08:00
parent 609ce04d29
commit b5ce361d19
19 changed files with 146 additions and 111 deletions

View File

@@ -621,11 +621,6 @@ status_t BpDrmManagerService::closeDecryptSession(int uniqueId, DecryptHandle* d
remote()->transact(CLOSE_DECRYPT_SESSION, data, &reply); remote()->transact(CLOSE_DECRYPT_SESSION, data, &reply);
if (NULL != decryptHandle->decryptInfo) {
LOGV("deleting decryptInfo");
delete decryptHandle->decryptInfo; decryptHandle->decryptInfo = NULL;
}
delete decryptHandle; decryptHandle = NULL;
return reply.readInt32(); return reply.readInt32();
} }

View File

@@ -77,13 +77,14 @@ int DrmManagerClient::checkRightsStatus(const String8& path, int action) {
return mDrmManagerClientImpl->checkRightsStatus(mUniqueId, path, action); return mDrmManagerClientImpl->checkRightsStatus(mUniqueId, path, action);
} }
status_t DrmManagerClient::consumeRights(DecryptHandle* decryptHandle, int action, bool reserve) { status_t DrmManagerClient::consumeRights(
sp<DecryptHandle> &decryptHandle, int action, bool reserve) {
Mutex::Autolock _l(mDecryptLock); Mutex::Autolock _l(mDecryptLock);
return mDrmManagerClientImpl->consumeRights(mUniqueId, decryptHandle, action, reserve); return mDrmManagerClientImpl->consumeRights(mUniqueId, decryptHandle, action, reserve);
} }
status_t DrmManagerClient::setPlaybackStatus( status_t DrmManagerClient::setPlaybackStatus(
DecryptHandle* decryptHandle, int playbackStatus, int64_t position) { sp<DecryptHandle> &decryptHandle, int playbackStatus, int64_t position) {
return mDrmManagerClientImpl return mDrmManagerClientImpl
->setPlaybackStatus(mUniqueId, decryptHandle, playbackStatus, position); ->setPlaybackStatus(mUniqueId, decryptHandle, playbackStatus, position);
} }
@@ -117,40 +118,42 @@ status_t DrmManagerClient::getAllSupportInfo(int* length, DrmSupportInfo** drmSu
return mDrmManagerClientImpl->getAllSupportInfo(mUniqueId, length, drmSupportInfoArray); return mDrmManagerClientImpl->getAllSupportInfo(mUniqueId, length, drmSupportInfoArray);
} }
DecryptHandle* DrmManagerClient::openDecryptSession(int fd, off64_t offset, off64_t length) { sp<DecryptHandle> DrmManagerClient::openDecryptSession(int fd, off64_t offset, off64_t length) {
return mDrmManagerClientImpl->openDecryptSession(mUniqueId, fd, offset, length); return mDrmManagerClientImpl->openDecryptSession(mUniqueId, fd, offset, length);
} }
DecryptHandle* DrmManagerClient::openDecryptSession(const char* uri) { sp<DecryptHandle> DrmManagerClient::openDecryptSession(const char* uri) {
return mDrmManagerClientImpl->openDecryptSession(mUniqueId, uri); return mDrmManagerClientImpl->openDecryptSession(mUniqueId, uri);
} }
status_t DrmManagerClient::closeDecryptSession(DecryptHandle* decryptHandle) { status_t DrmManagerClient::closeDecryptSession(sp<DecryptHandle> &decryptHandle) {
return mDrmManagerClientImpl->closeDecryptSession(mUniqueId, decryptHandle); return mDrmManagerClientImpl->closeDecryptSession(mUniqueId, decryptHandle);
} }
status_t DrmManagerClient::initializeDecryptUnit( status_t DrmManagerClient::initializeDecryptUnit(
DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo) { sp<DecryptHandle> &decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo) {
Mutex::Autolock _l(mDecryptLock); Mutex::Autolock _l(mDecryptLock);
return mDrmManagerClientImpl->initializeDecryptUnit( return mDrmManagerClientImpl->initializeDecryptUnit(
mUniqueId, decryptHandle, decryptUnitId, headerInfo); mUniqueId, decryptHandle, decryptUnitId, headerInfo);
} }
status_t DrmManagerClient::decrypt( status_t DrmManagerClient::decrypt(
DecryptHandle* decryptHandle, int decryptUnitId, sp<DecryptHandle> &decryptHandle, int decryptUnitId,
const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) { const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) {
Mutex::Autolock _l(mDecryptLock); Mutex::Autolock _l(mDecryptLock);
return mDrmManagerClientImpl->decrypt( return mDrmManagerClientImpl->decrypt(
mUniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer, IV); mUniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer, IV);
} }
status_t DrmManagerClient::finalizeDecryptUnit(DecryptHandle* decryptHandle, int decryptUnitId) { status_t DrmManagerClient::finalizeDecryptUnit(
sp<DecryptHandle> &decryptHandle, int decryptUnitId) {
Mutex::Autolock _l(mDecryptLock); Mutex::Autolock _l(mDecryptLock);
return mDrmManagerClientImpl->finalizeDecryptUnit(mUniqueId, decryptHandle, decryptUnitId); return mDrmManagerClientImpl->finalizeDecryptUnit(mUniqueId,
decryptHandle, decryptUnitId);
} }
ssize_t DrmManagerClient::pread( ssize_t DrmManagerClient::pread(
DecryptHandle* decryptHandle, void* buffer, ssize_t numBytes, off64_t offset) { sp<DecryptHandle> &decryptHandle, void* buffer, ssize_t numBytes, off64_t offset) {
Mutex::Autolock _l(mDecryptLock); Mutex::Autolock _l(mDecryptLock);
return mDrmManagerClientImpl->pread(mUniqueId, decryptHandle, buffer, numBytes, offset); return mDrmManagerClientImpl->pread(mUniqueId, decryptHandle, buffer, numBytes, offset);
} }

View File

@@ -78,14 +78,16 @@ void DrmManagerClientImpl::removeClient(int uniqueId) {
} }
status_t DrmManagerClientImpl::setOnInfoListener( status_t DrmManagerClientImpl::setOnInfoListener(
int uniqueId, const sp<DrmManagerClient::OnInfoListener>& infoListener) { int uniqueId,
const sp<DrmManagerClient::OnInfoListener>& infoListener) {
Mutex::Autolock _l(mLock); Mutex::Autolock _l(mLock);
mOnInfoListener = infoListener; mOnInfoListener = infoListener;
return getDrmManagerService()->setDrmServiceListener(uniqueId, return getDrmManagerService()->setDrmServiceListener(uniqueId,
(NULL != infoListener.get()) ? this : NULL); (NULL != infoListener.get()) ? this : NULL);
} }
status_t DrmManagerClientImpl::installDrmEngine(int uniqueId, const String8& drmEngineFile) { status_t DrmManagerClientImpl::installDrmEngine(
int uniqueId, const String8& drmEngineFile) {
status_t status = DRM_ERROR_UNKNOWN; status_t status = DRM_ERROR_UNKNOWN;
if (EMPTY_STRING != drmEngineFile) { if (EMPTY_STRING != drmEngineFile) {
status = getDrmManagerService()->installDrmEngine(uniqueId, drmEngineFile); status = getDrmManagerService()->installDrmEngine(uniqueId, drmEngineFile);
@@ -97,7 +99,8 @@ DrmConstraints* DrmManagerClientImpl::getConstraints(
int uniqueId, const String8* path, const int action) { int uniqueId, const String8* path, const int action) {
DrmConstraints *drmConstraints = NULL; DrmConstraints *drmConstraints = NULL;
if ((NULL != path) && (EMPTY_STRING != *path)) { if ((NULL != path) && (EMPTY_STRING != *path)) {
drmConstraints = getDrmManagerService()->getConstraints(uniqueId, path, action); drmConstraints =
getDrmManagerService()->getConstraints(uniqueId, path, action);
} }
return drmConstraints; return drmConstraints;
} }
@@ -110,7 +113,8 @@ DrmMetadata* DrmManagerClientImpl::getMetadata(int uniqueId, const String8* path
return drmMetadata; return drmMetadata;
} }
bool DrmManagerClientImpl::canHandle(int uniqueId, const String8& path, const String8& mimeType) { bool DrmManagerClientImpl::canHandle(
int uniqueId, const String8& path, const String8& mimeType) {
bool retCode = false; bool retCode = false;
if ((EMPTY_STRING != path) || (EMPTY_STRING != mimeType)) { if ((EMPTY_STRING != path) || (EMPTY_STRING != mimeType)) {
retCode = getDrmManagerService()->canHandle(uniqueId, path, mimeType); retCode = getDrmManagerService()->canHandle(uniqueId, path, mimeType);
@@ -118,7 +122,8 @@ bool DrmManagerClientImpl::canHandle(int uniqueId, const String8& path, const St
return retCode; return retCode;
} }
DrmInfoStatus* DrmManagerClientImpl::processDrmInfo(int uniqueId, const DrmInfo* drmInfo) { DrmInfoStatus* DrmManagerClientImpl::processDrmInfo(
int uniqueId, const DrmInfo* drmInfo) {
DrmInfoStatus *drmInfoStatus = NULL; DrmInfoStatus *drmInfoStatus = NULL;
if (NULL != drmInfo) { if (NULL != drmInfo) {
drmInfoStatus = getDrmManagerService()->processDrmInfo(uniqueId, drmInfo); drmInfoStatus = getDrmManagerService()->processDrmInfo(uniqueId, drmInfo);
@@ -126,7 +131,8 @@ DrmInfoStatus* DrmManagerClientImpl::processDrmInfo(int uniqueId, const DrmInfo*
return drmInfoStatus; return drmInfoStatus;
} }
DrmInfo* DrmManagerClientImpl::acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest) { DrmInfo* DrmManagerClientImpl::acquireDrmInfo(
int uniqueId, const DrmInfoRequest* drmInfoRequest) {
DrmInfo* drmInfo = NULL; DrmInfo* drmInfo = NULL;
if (NULL != drmInfoRequest) { if (NULL != drmInfoRequest) {
drmInfo = getDrmManagerService()->acquireDrmInfo(uniqueId, drmInfoRequest); drmInfo = getDrmManagerService()->acquireDrmInfo(uniqueId, drmInfoRequest);
@@ -138,12 +144,14 @@ status_t DrmManagerClientImpl::saveRights(int uniqueId, const DrmRights& drmRigh
const String8& rightsPath, const String8& contentPath) { const String8& rightsPath, const String8& contentPath) {
status_t status = DRM_ERROR_UNKNOWN; status_t status = DRM_ERROR_UNKNOWN;
if (EMPTY_STRING != contentPath) { if (EMPTY_STRING != contentPath) {
status = getDrmManagerService()->saveRights(uniqueId, drmRights, rightsPath, contentPath); status = getDrmManagerService()->saveRights(
uniqueId, drmRights, rightsPath, contentPath);
} }
return status; return status;
} }
String8 DrmManagerClientImpl::getOriginalMimeType(int uniqueId, const String8& path) { String8 DrmManagerClientImpl::getOriginalMimeType(
int uniqueId, const String8& path) {
String8 mimeType = EMPTY_STRING; String8 mimeType = EMPTY_STRING;
if (EMPTY_STRING != path) { if (EMPTY_STRING != path) {
mimeType = getDrmManagerService()->getOriginalMimeType(uniqueId, path); mimeType = getDrmManagerService()->getOriginalMimeType(uniqueId, path);
@@ -155,7 +163,8 @@ int DrmManagerClientImpl::getDrmObjectType(
int uniqueId, const String8& path, const String8& mimeType) { int uniqueId, const String8& path, const String8& mimeType) {
int drmOjectType = DrmObjectType::UNKNOWN; int drmOjectType = DrmObjectType::UNKNOWN;
if ((EMPTY_STRING != path) || (EMPTY_STRING != mimeType)) { if ((EMPTY_STRING != path) || (EMPTY_STRING != mimeType)) {
drmOjectType = getDrmManagerService()->getDrmObjectType(uniqueId, path, mimeType); drmOjectType =
getDrmManagerService()->getDrmObjectType(uniqueId, path, mimeType);
} }
return drmOjectType; return drmOjectType;
} }
@@ -164,35 +173,41 @@ int DrmManagerClientImpl::checkRightsStatus(
int uniqueId, const String8& path, int action) { int uniqueId, const String8& path, int action) {
int rightsStatus = RightsStatus::RIGHTS_INVALID; int rightsStatus = RightsStatus::RIGHTS_INVALID;
if (EMPTY_STRING != path) { if (EMPTY_STRING != path) {
rightsStatus = getDrmManagerService()->checkRightsStatus(uniqueId, path, action); rightsStatus =
getDrmManagerService()->checkRightsStatus(uniqueId, path, action);
} }
return rightsStatus; return rightsStatus;
} }
status_t DrmManagerClientImpl::consumeRights( status_t DrmManagerClientImpl::consumeRights(
int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) { int uniqueId, sp<DecryptHandle> &decryptHandle,
int action, bool reserve) {
status_t status = DRM_ERROR_UNKNOWN; status_t status = DRM_ERROR_UNKNOWN;
if (NULL != decryptHandle) { if (NULL != decryptHandle.get()) {
status = getDrmManagerService()->consumeRights(uniqueId, decryptHandle, action, reserve); status = getDrmManagerService()->consumeRights(
uniqueId, decryptHandle.get(), action, reserve);
} }
return status; return status;
} }
status_t DrmManagerClientImpl::setPlaybackStatus( status_t DrmManagerClientImpl::setPlaybackStatus(
int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int64_t position) { int uniqueId, sp<DecryptHandle> &decryptHandle,
int playbackStatus, int64_t position) {
status_t status = DRM_ERROR_UNKNOWN; status_t status = DRM_ERROR_UNKNOWN;
if (NULL != decryptHandle) { if (NULL != decryptHandle.get()) {
status = getDrmManagerService()->setPlaybackStatus( status = getDrmManagerService()->setPlaybackStatus(
uniqueId, decryptHandle, playbackStatus, position); uniqueId, decryptHandle.get(), playbackStatus, position);
} }
return status; return status;
} }
bool DrmManagerClientImpl::validateAction( bool DrmManagerClientImpl::validateAction(
int uniqueId, const String8& path, int action, const ActionDescription& description) { int uniqueId, const String8& path,
int action, const ActionDescription& description) {
bool retCode = false; bool retCode = false;
if (EMPTY_STRING != path) { if (EMPTY_STRING != path) {
retCode = getDrmManagerService()->validateAction(uniqueId, path, action, description); retCode = getDrmManagerService()->validateAction(
uniqueId, path, action, description);
} }
return retCode; return retCode;
} }
@@ -209,7 +224,8 @@ status_t DrmManagerClientImpl::removeAllRights(int uniqueId) {
return getDrmManagerService()->removeAllRights(uniqueId); return getDrmManagerService()->removeAllRights(uniqueId);
} }
int DrmManagerClientImpl::openConvertSession(int uniqueId, const String8& mimeType) { int DrmManagerClientImpl::openConvertSession(
int uniqueId, const String8& mimeType) {
int retCode = INVALID_VALUE; int retCode = INVALID_VALUE;
if (EMPTY_STRING != mimeType) { if (EMPTY_STRING != mimeType) {
retCode = getDrmManagerService()->openConvertSession(uniqueId, mimeType); retCode = getDrmManagerService()->openConvertSession(uniqueId, mimeType);
@@ -221,12 +237,14 @@ DrmConvertedStatus* DrmManagerClientImpl::convertData(
int uniqueId, int convertId, const DrmBuffer* inputData) { int uniqueId, int convertId, const DrmBuffer* inputData) {
DrmConvertedStatus* drmConvertedStatus = NULL; DrmConvertedStatus* drmConvertedStatus = NULL;
if (NULL != inputData) { if (NULL != inputData) {
drmConvertedStatus = getDrmManagerService()->convertData(uniqueId, convertId, inputData); drmConvertedStatus =
getDrmManagerService()->convertData(uniqueId, convertId, inputData);
} }
return drmConvertedStatus; return drmConvertedStatus;
} }
DrmConvertedStatus* DrmManagerClientImpl::closeConvertSession(int uniqueId, int convertId) { DrmConvertedStatus* DrmManagerClientImpl::closeConvertSession(
int uniqueId, int convertId) {
return getDrmManagerService()->closeConvertSession(uniqueId, convertId); return getDrmManagerService()->closeConvertSession(uniqueId, convertId);
} }
@@ -234,17 +252,19 @@ status_t DrmManagerClientImpl::getAllSupportInfo(
int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray) { int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray) {
status_t status = DRM_ERROR_UNKNOWN; status_t status = DRM_ERROR_UNKNOWN;
if ((NULL != drmSupportInfoArray) && (NULL != length)) { if ((NULL != drmSupportInfoArray) && (NULL != length)) {
status = getDrmManagerService()->getAllSupportInfo(uniqueId, length, drmSupportInfoArray); status = getDrmManagerService()->getAllSupportInfo(
uniqueId, length, drmSupportInfoArray);
} }
return status; return status;
} }
DecryptHandle* DrmManagerClientImpl::openDecryptSession( sp<DecryptHandle> DrmManagerClientImpl::openDecryptSession(
int uniqueId, int fd, off64_t offset, off64_t length) { int uniqueId, int fd, off64_t offset, off64_t length) {
return getDrmManagerService()->openDecryptSession(uniqueId, fd, offset, length); return getDrmManagerService()->openDecryptSession(uniqueId, fd, offset, length);
} }
DecryptHandle* DrmManagerClientImpl::openDecryptSession(int uniqueId, const char* uri) { sp<DecryptHandle> DrmManagerClientImpl::openDecryptSession(
int uniqueId, const char* uri) {
DecryptHandle* handle = NULL; DecryptHandle* handle = NULL;
if (NULL != uri) { if (NULL != uri) {
handle = getDrmManagerService()->openDecryptSession(uniqueId, uri); handle = getDrmManagerService()->openDecryptSession(uniqueId, uri);
@@ -252,50 +272,57 @@ DecryptHandle* DrmManagerClientImpl::openDecryptSession(int uniqueId, const char
return handle; return handle;
} }
status_t DrmManagerClientImpl::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) { status_t DrmManagerClientImpl::closeDecryptSession(
int uniqueId, sp<DecryptHandle> &decryptHandle) {
status_t status = DRM_ERROR_UNKNOWN; status_t status = DRM_ERROR_UNKNOWN;
if (NULL != decryptHandle) { if (NULL != decryptHandle.get()) {
status = getDrmManagerService()->closeDecryptSession( uniqueId, decryptHandle); status = getDrmManagerService()->closeDecryptSession(
uniqueId, decryptHandle.get());
} }
return status; return status;
} }
status_t DrmManagerClientImpl::initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, status_t DrmManagerClientImpl::initializeDecryptUnit(
int decryptUnitId, const DrmBuffer* headerInfo) { int uniqueId, sp<DecryptHandle> &decryptHandle,
int decryptUnitId, const DrmBuffer* headerInfo) {
status_t status = DRM_ERROR_UNKNOWN; status_t status = DRM_ERROR_UNKNOWN;
if ((NULL != decryptHandle) && (NULL != headerInfo)) { if ((NULL != decryptHandle.get()) && (NULL != headerInfo)) {
status = getDrmManagerService()->initializeDecryptUnit( status = getDrmManagerService()->initializeDecryptUnit(
uniqueId, decryptHandle, decryptUnitId, headerInfo); uniqueId, decryptHandle.get(), decryptUnitId, headerInfo);
} }
return status; return status;
} }
status_t DrmManagerClientImpl::decrypt(int uniqueId, DecryptHandle* decryptHandle, status_t DrmManagerClientImpl::decrypt(
int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) { int uniqueId, sp<DecryptHandle> &decryptHandle,
int decryptUnitId, const DrmBuffer* encBuffer,
DrmBuffer** decBuffer, DrmBuffer* IV) {
status_t status = DRM_ERROR_UNKNOWN; status_t status = DRM_ERROR_UNKNOWN;
if ((NULL != decryptHandle) && (NULL != encBuffer) if ((NULL != decryptHandle.get()) && (NULL != encBuffer)
&& (NULL != decBuffer) && (NULL != *decBuffer)) { && (NULL != decBuffer) && (NULL != *decBuffer)) {
status = getDrmManagerService()->decrypt( status = getDrmManagerService()->decrypt(
uniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer, IV); uniqueId, decryptHandle.get(), decryptUnitId,
encBuffer, decBuffer, IV);
} }
return status; return status;
} }
status_t DrmManagerClientImpl::finalizeDecryptUnit( status_t DrmManagerClientImpl::finalizeDecryptUnit(
int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) { int uniqueId, sp<DecryptHandle> &decryptHandle, int decryptUnitId) {
status_t status = DRM_ERROR_UNKNOWN; status_t status = DRM_ERROR_UNKNOWN;
if (NULL != decryptHandle) { if (NULL != decryptHandle.get()) {
status status = getDrmManagerService()->finalizeDecryptUnit(
= getDrmManagerService()->finalizeDecryptUnit(uniqueId, decryptHandle, decryptUnitId); uniqueId, decryptHandle.get(), decryptUnitId);
} }
return status; return status;
} }
ssize_t DrmManagerClientImpl::pread(int uniqueId, DecryptHandle* decryptHandle, ssize_t DrmManagerClientImpl::pread(int uniqueId, sp<DecryptHandle> &decryptHandle,
void* buffer, ssize_t numBytes, off64_t offset) { void* buffer, ssize_t numBytes, off64_t offset) {
ssize_t retCode = INVALID_VALUE; ssize_t retCode = INVALID_VALUE;
if ((NULL != decryptHandle) && (NULL != buffer) && (0 < numBytes)) { if ((NULL != decryptHandle.get()) && (NULL != buffer) && (0 < numBytes)) {
retCode = getDrmManagerService()->pread(uniqueId, decryptHandle, buffer, numBytes, offset); retCode = getDrmManagerService()->pread(
uniqueId, decryptHandle.get(), buffer, numBytes, offset);
} }
return retCode; return retCode;
} }

View File

@@ -189,7 +189,7 @@ public:
* @return status_t * @return status_t
* Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
*/ */
status_t consumeRights(int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve); status_t consumeRights(int uniqueId, sp<DecryptHandle> &decryptHandle, int action, bool reserve);
/** /**
* Informs the DRM engine about the playback actions performed on the DRM files. * Informs the DRM engine about the playback actions performed on the DRM files.
@@ -203,7 +203,7 @@ public:
* Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
*/ */
status_t setPlaybackStatus( status_t setPlaybackStatus(
int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int64_t position); int uniqueId, sp<DecryptHandle> &decryptHandle, int playbackStatus, int64_t position);
/** /**
* Validates whether an action on the DRM content is allowed or not. * Validates whether an action on the DRM content is allowed or not.
@@ -303,7 +303,7 @@ public:
* @return * @return
* Handle for the decryption session * Handle for the decryption session
*/ */
DecryptHandle* openDecryptSession(int uniqueId, int fd, off64_t offset, off64_t length); sp<DecryptHandle> openDecryptSession(int uniqueId, int fd, off64_t offset, off64_t length);
/** /**
* Open the decrypt session to decrypt the given protected content * Open the decrypt session to decrypt the given protected content
@@ -313,7 +313,7 @@ public:
* @return * @return
* Handle for the decryption session * Handle for the decryption session
*/ */
DecryptHandle* openDecryptSession(int uniqueId, const char* uri); sp<DecryptHandle> openDecryptSession(int uniqueId, const char* uri);
/** /**
* Close the decrypt session for the given handle * Close the decrypt session for the given handle
@@ -323,7 +323,7 @@ public:
* @return status_t * @return status_t
* Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
*/ */
status_t closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle); status_t closeDecryptSession(int uniqueId, sp<DecryptHandle> &decryptHandle);
/** /**
* Initialize decryption for the given unit of the protected content * Initialize decryption for the given unit of the protected content
@@ -335,7 +335,7 @@ public:
* @return status_t * @return status_t
* Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
*/ */
status_t initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, status_t initializeDecryptUnit(int uniqueId, sp<DecryptHandle> &decryptHandle,
int decryptUnitId, const DrmBuffer* headerInfo); int decryptUnitId, const DrmBuffer* headerInfo);
/** /**
@@ -355,7 +355,7 @@ public:
* DRM_ERROR_SESSION_NOT_OPENED, DRM_ERROR_DECRYPT_UNIT_NOT_INITIALIZED, * DRM_ERROR_SESSION_NOT_OPENED, DRM_ERROR_DECRYPT_UNIT_NOT_INITIALIZED,
* DRM_ERROR_DECRYPT for failure. * DRM_ERROR_DECRYPT for failure.
*/ */
status_t decrypt(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, status_t decrypt(int uniqueId, sp<DecryptHandle> &decryptHandle, int decryptUnitId,
const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV); const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV);
/** /**
@@ -367,7 +367,7 @@ public:
* @return status_t * @return status_t
* Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
*/ */
status_t finalizeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId); status_t finalizeDecryptUnit(int uniqueId, sp<DecryptHandle> &decryptHandle, int decryptUnitId);
/** /**
* Reads the specified number of bytes from an open DRM file. * Reads the specified number of bytes from an open DRM file.
@@ -380,7 +380,7 @@ public:
* *
* @return Number of bytes read. Returns -1 for Failure. * @return Number of bytes read. Returns -1 for Failure.
*/ */
ssize_t pread(int uniqueId, DecryptHandle* decryptHandle, ssize_t pread(int uniqueId, sp<DecryptHandle> &decryptHandle,
void* buffer, ssize_t numBytes, off64_t offset); void* buffer, ssize_t numBytes, off64_t offset);
/** /**

View File

@@ -69,7 +69,7 @@ public:
* @return * @return
* Handle for the decryption session * Handle for the decryption session
*/ */
DecryptHandle* openDecryptSession(int fd, off64_t offset, off64_t length); sp<DecryptHandle> openDecryptSession(int fd, off64_t offset, off64_t length);
/** /**
* Open the decrypt session to decrypt the given protected content * Open the decrypt session to decrypt the given protected content
@@ -78,7 +78,7 @@ public:
* @return * @return
* Handle for the decryption session * Handle for the decryption session
*/ */
DecryptHandle* openDecryptSession(const char* uri); sp<DecryptHandle> openDecryptSession(const char* uri);
/** /**
* Close the decrypt session for the given handle * Close the decrypt session for the given handle
@@ -87,7 +87,7 @@ public:
* @return status_t * @return status_t
* Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
*/ */
status_t closeDecryptSession(DecryptHandle* decryptHandle); status_t closeDecryptSession(sp<DecryptHandle> &decryptHandle);
/** /**
* Consumes the rights for a content. * Consumes the rights for a content.
@@ -101,7 +101,7 @@ public:
* Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure. * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure.
* In case license has been expired, DRM_ERROR_LICENSE_EXPIRED will be returned. * In case license has been expired, DRM_ERROR_LICENSE_EXPIRED will be returned.
*/ */
status_t consumeRights(DecryptHandle* decryptHandle, int action, bool reserve); status_t consumeRights(sp<DecryptHandle> &decryptHandle, int action, bool reserve);
/** /**
* Informs the DRM engine about the playback actions performed on the DRM files. * Informs the DRM engine about the playback actions performed on the DRM files.
@@ -113,7 +113,8 @@ public:
* @return status_t * @return status_t
* Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
*/ */
status_t setPlaybackStatus(DecryptHandle* decryptHandle, int playbackStatus, int64_t position); status_t setPlaybackStatus(
sp<DecryptHandle> &decryptHandle, int playbackStatus, int64_t position);
/** /**
* Initialize decryption for the given unit of the protected content * Initialize decryption for the given unit of the protected content
@@ -125,7 +126,7 @@ public:
* Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
*/ */
status_t initializeDecryptUnit( status_t initializeDecryptUnit(
DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo); sp<DecryptHandle> &decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo);
/** /**
* Decrypt the protected content buffers for the given unit * Decrypt the protected content buffers for the given unit
@@ -144,7 +145,7 @@ public:
* DRM_ERROR_DECRYPT for failure. * DRM_ERROR_DECRYPT for failure.
*/ */
status_t decrypt( status_t decrypt(
DecryptHandle* decryptHandle, int decryptUnitId, sp<DecryptHandle> &decryptHandle, int decryptUnitId,
const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV = NULL); const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV = NULL);
/** /**
@@ -155,7 +156,8 @@ public:
* @return status_t * @return status_t
* Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
*/ */
status_t finalizeDecryptUnit(DecryptHandle* decryptHandle, int decryptUnitId); status_t finalizeDecryptUnit(
sp<DecryptHandle> &decryptHandle, int decryptUnitId);
/** /**
* Reads the specified number of bytes from an open DRM file. * Reads the specified number of bytes from an open DRM file.
@@ -167,7 +169,8 @@ public:
* *
* @return Number of bytes read. Returns -1 for Failure. * @return Number of bytes read. Returns -1 for Failure.
*/ */
ssize_t pread(DecryptHandle* decryptHandle, void* buffer, ssize_t numBytes, off64_t offset); ssize_t pread(sp<DecryptHandle> &decryptHandle,
void* buffer, ssize_t numBytes, off64_t offset);
/** /**
* Validates whether an action on the DRM content is allowed or not. * Validates whether an action on the DRM content is allowed or not.

View File

@@ -19,6 +19,7 @@
#include <utils/Vector.h> #include <utils/Vector.h>
#include <utils/KeyedVector.h> #include <utils/KeyedVector.h>
#include <utils/RefBase.h>
#include <utils/String8.h> #include <utils/String8.h>
#include <utils/Errors.h> #include <utils/Errors.h>
@@ -240,7 +241,7 @@ public:
/** /**
* Defines decryption handle * Defines decryption handle
*/ */
class DecryptHandle { class DecryptHandle : public RefBase {
public: public:
/** /**
* Decryption session Handle * Decryption session Handle
@@ -285,10 +286,15 @@ public:
decryptId(INVALID_VALUE), decryptId(INVALID_VALUE),
mimeType(""), mimeType(""),
decryptApiType(INVALID_VALUE), decryptApiType(INVALID_VALUE),
status(INVALID_VALUE) { status(INVALID_VALUE),
decryptInfo(NULL) {
} }
~DecryptHandle() {
delete decryptInfo; decryptInfo = NULL;
}
bool operator<(const DecryptHandle& handle) const { bool operator<(const DecryptHandle& handle) const {
return (decryptId < handle.decryptId); return (decryptId < handle.decryptId);
} }

View File

@@ -75,10 +75,10 @@ public:
static void RegisterDefaultSniffers(); static void RegisterDefaultSniffers();
// for DRM // for DRM
virtual DecryptHandle* DrmInitialization() { virtual sp<DecryptHandle> DrmInitialization() {
return NULL; return NULL;
} }
virtual void getDrmInfo(DecryptHandle **handle, DrmManagerClient **client) {}; virtual void getDrmInfo(sp<DecryptHandle> &handle, DrmManagerClient **client) {};
virtual String8 getUri() { virtual String8 getUri() {
return String8(); return String8();

View File

@@ -38,9 +38,9 @@ public:
virtual status_t getSize(off64_t *size); virtual status_t getSize(off64_t *size);
virtual DecryptHandle* DrmInitialization(); virtual sp<DecryptHandle> DrmInitialization();
virtual void getDrmInfo(DecryptHandle **handle, DrmManagerClient **client); virtual void getDrmInfo(sp<DecryptHandle> &handle, DrmManagerClient **client);
protected: protected:
virtual ~FileSource(); virtual ~FileSource();
@@ -52,7 +52,7 @@ private:
Mutex mLock; Mutex mLock;
/*for DRM*/ /*for DRM*/
DecryptHandle *mDecryptHandle; sp<DecryptHandle> mDecryptHandle;
DrmManagerClient *mDrmManagerClient; DrmManagerClient *mDrmManagerClient;
int64_t mDrmBufOffset; int64_t mDrmBufOffset;
int64_t mDrmBufSize; int64_t mDrmBufSize;

View File

@@ -303,7 +303,7 @@ status_t AwesomePlayer::setDataSource_l(
return UNKNOWN_ERROR; return UNKNOWN_ERROR;
} }
dataSource->getDrmInfo(&mDecryptHandle, &mDrmManagerClient); dataSource->getDrmInfo(mDecryptHandle, &mDrmManagerClient);
if (mDecryptHandle != NULL) { if (mDecryptHandle != NULL) {
CHECK(mDrmManagerClient); CHECK(mDrmManagerClient);
if (RightsStatus::RIGHTS_VALID != mDecryptHandle->status) { if (RightsStatus::RIGHTS_VALID != mDecryptHandle->status) {
@@ -1689,7 +1689,8 @@ status_t AwesomePlayer::finishSetDataSource_l() {
return UNKNOWN_ERROR; return UNKNOWN_ERROR;
} }
dataSource->getDrmInfo(&mDecryptHandle, &mDrmManagerClient); dataSource->getDrmInfo(mDecryptHandle, &mDrmManagerClient);
if (mDecryptHandle != NULL) { if (mDecryptHandle != NULL) {
CHECK(mDrmManagerClient); CHECK(mDrmManagerClient);
if (RightsStatus::RIGHTS_VALID == mDecryptHandle->status) { if (RightsStatus::RIGHTS_VALID == mDecryptHandle->status) {

View File

@@ -41,7 +41,7 @@ namespace android {
class DRMSource : public MediaSource { class DRMSource : public MediaSource {
public: public:
DRMSource(const sp<MediaSource> &mediaSource, DRMSource(const sp<MediaSource> &mediaSource,
DecryptHandle *decryptHandle, const sp<DecryptHandle> &decryptHandle,
DrmManagerClient *managerClient, DrmManagerClient *managerClient,
int32_t trackId, DrmBuffer *ipmpBox); int32_t trackId, DrmBuffer *ipmpBox);
@@ -56,7 +56,7 @@ protected:
private: private:
sp<MediaSource> mOriginalMediaSource; sp<MediaSource> mOriginalMediaSource;
DecryptHandle* mDecryptHandle; sp<DecryptHandle> mDecryptHandle;
DrmManagerClient* mDrmManagerClient; DrmManagerClient* mDrmManagerClient;
size_t mTrackId; size_t mTrackId;
mutable Mutex mDRMLock; mutable Mutex mDRMLock;
@@ -70,7 +70,7 @@ private:
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
DRMSource::DRMSource(const sp<MediaSource> &mediaSource, DRMSource::DRMSource(const sp<MediaSource> &mediaSource,
DecryptHandle *decryptHandle, const sp<DecryptHandle> &decryptHandle,
DrmManagerClient *managerClient, DrmManagerClient *managerClient,
int32_t trackId, DrmBuffer *ipmpBox) int32_t trackId, DrmBuffer *ipmpBox)
: mOriginalMediaSource(mediaSource), : mOriginalMediaSource(mediaSource),
@@ -245,7 +245,7 @@ DRMExtractor::DRMExtractor(const sp<DataSource> &source, const char* mime)
mOriginalExtractor->setDrmFlag(true); mOriginalExtractor->setDrmFlag(true);
mOriginalExtractor->getMetaData()->setInt32(kKeyIsDRM, 1); mOriginalExtractor->getMetaData()->setInt32(kKeyIsDRM, 1);
source->getDrmInfo(&mDecryptHandle, &mDrmManagerClient); source->getDrmInfo(mDecryptHandle, &mDrmManagerClient);
} }
DRMExtractor::~DRMExtractor() { DRMExtractor::~DRMExtractor() {
@@ -281,7 +281,7 @@ sp<MetaData> DRMExtractor::getMetaData() {
bool SniffDRM( bool SniffDRM(
const sp<DataSource> &source, String8 *mimeType, float *confidence, const sp<DataSource> &source, String8 *mimeType, float *confidence,
sp<AMessage> *) { sp<AMessage> *) {
DecryptHandle *decryptHandle = source->DrmInitialization(); sp<DecryptHandle> decryptHandle = source->DrmInitialization();
if (decryptHandle != NULL) { if (decryptHandle != NULL) {
if (decryptHandle->decryptApiType == DecryptApiType::CONTAINER_BASED) { if (decryptHandle->decryptApiType == DecryptApiType::CONTAINER_BASED) {

View File

@@ -125,7 +125,7 @@ status_t FileSource::getSize(off64_t *size) {
return OK; return OK;
} }
DecryptHandle* FileSource::DrmInitialization() { sp<DecryptHandle> FileSource::DrmInitialization() {
if (mDrmManagerClient == NULL) { if (mDrmManagerClient == NULL) {
mDrmManagerClient = new DrmManagerClient(); mDrmManagerClient = new DrmManagerClient();
} }
@@ -147,8 +147,8 @@ DecryptHandle* FileSource::DrmInitialization() {
return mDecryptHandle; return mDecryptHandle;
} }
void FileSource::getDrmInfo(DecryptHandle **handle, DrmManagerClient **client) { void FileSource::getDrmInfo(sp<DecryptHandle> &handle, DrmManagerClient **client) {
*handle = mDecryptHandle; handle = mDecryptHandle;
*client = mDrmManagerClient; *client = mDrmManagerClient;
} }

View File

@@ -477,11 +477,11 @@ void NuCachedSource2::resumeFetchingIfNecessary() {
restartPrefetcherIfNecessary_l(true /* ignore low water threshold */); restartPrefetcherIfNecessary_l(true /* ignore low water threshold */);
} }
DecryptHandle* NuCachedSource2::DrmInitialization() { sp<DecryptHandle> NuCachedSource2::DrmInitialization() {
return mSource->DrmInitialization(); return mSource->DrmInitialization();
} }
void NuCachedSource2::getDrmInfo(DecryptHandle **handle, DrmManagerClient **client) { void NuCachedSource2::getDrmInfo(sp<DecryptHandle> &handle, DrmManagerClient **client) {
mSource->getDrmInfo(handle, client); mSource->getDrmInfo(handle, client);
} }

View File

@@ -530,7 +530,7 @@ void NuHTTPDataSource::addBandwidthMeasurement_l(
} }
} }
DecryptHandle* NuHTTPDataSource::DrmInitialization() { sp<DecryptHandle> NuHTTPDataSource::DrmInitialization() {
if (mDrmManagerClient == NULL) { if (mDrmManagerClient == NULL) {
mDrmManagerClient = new DrmManagerClient(); mDrmManagerClient = new DrmManagerClient();
} }
@@ -554,8 +554,8 @@ DecryptHandle* NuHTTPDataSource::DrmInitialization() {
return mDecryptHandle; return mDecryptHandle;
} }
void NuHTTPDataSource::getDrmInfo(DecryptHandle **handle, DrmManagerClient **client) { void NuHTTPDataSource::getDrmInfo(sp<DecryptHandle> &handle, DrmManagerClient **client) {
*handle = mDecryptHandle; handle = mDecryptHandle;
*client = mDrmManagerClient; *client = mDrmManagerClient;
} }

View File

@@ -273,7 +273,7 @@ bool ChromiumHTTPDataSource::estimateBandwidth(int32_t *bandwidth_bps) {
return true; return true;
} }
DecryptHandle *ChromiumHTTPDataSource::DrmInitialization() { sp<DecryptHandle> ChromiumHTTPDataSource::DrmInitialization() {
Mutex::Autolock autoLock(mLock); Mutex::Autolock autoLock(mLock);
if (mDrmManagerClient == NULL) { if (mDrmManagerClient == NULL) {
@@ -301,10 +301,10 @@ DecryptHandle *ChromiumHTTPDataSource::DrmInitialization() {
} }
void ChromiumHTTPDataSource::getDrmInfo( void ChromiumHTTPDataSource::getDrmInfo(
DecryptHandle **handle, DrmManagerClient **client) { sp<DecryptHandle> &handle, DrmManagerClient **client) {
Mutex::Autolock autoLock(mLock); Mutex::Autolock autoLock(mLock);
*handle = mDecryptHandle; handle = mDecryptHandle;
*client = mDrmManagerClient; *client = mDrmManagerClient;
} }

View File

@@ -217,7 +217,7 @@ private:
sp<ARTSPController> mConnectingRTSPController; sp<ARTSPController> mConnectingRTSPController;
DrmManagerClient *mDrmManagerClient; DrmManagerClient *mDrmManagerClient;
DecryptHandle *mDecryptHandle; sp<DecryptHandle> mDecryptHandle;
status_t setDataSource_l( status_t setDataSource_l(
const char *uri, const char *uri,

View File

@@ -45,9 +45,9 @@ struct ChromiumHTTPDataSource : public HTTPBase {
virtual bool estimateBandwidth(int32_t *bandwidth_bps); virtual bool estimateBandwidth(int32_t *bandwidth_bps);
virtual DecryptHandle *DrmInitialization(); virtual sp<DecryptHandle> DrmInitialization();
virtual void getDrmInfo(DecryptHandle **handle, DrmManagerClient **client); virtual void getDrmInfo(sp<DecryptHandle> &handle, DrmManagerClient **client);
virtual String8 getUri(); virtual String8 getUri();
@@ -95,7 +95,7 @@ private:
int64_t mTotalTransferTimeUs; int64_t mTotalTransferTimeUs;
size_t mTotalTransferBytes; size_t mTotalTransferBytes;
DecryptHandle *mDecryptHandle; sp<DecryptHandle> mDecryptHandle;
DrmManagerClient *mDrmManagerClient; DrmManagerClient *mDrmManagerClient;
void disconnect_l(); void disconnect_l();

View File

@@ -45,7 +45,7 @@ private:
sp<DataSource> mDataSource; sp<DataSource> mDataSource;
sp<MediaExtractor> mOriginalExtractor; sp<MediaExtractor> mOriginalExtractor;
DecryptHandle* mDecryptHandle; sp<DecryptHandle> mDecryptHandle;
DrmManagerClient* mDrmManagerClient; DrmManagerClient* mDrmManagerClient;
DRMExtractor(const DRMExtractor &); DRMExtractor(const DRMExtractor &);

View File

@@ -37,8 +37,8 @@ struct NuCachedSource2 : public DataSource {
virtual status_t getSize(off64_t *size); virtual status_t getSize(off64_t *size);
virtual uint32_t flags(); virtual uint32_t flags();
virtual DecryptHandle* DrmInitialization(); virtual sp<DecryptHandle> DrmInitialization();
virtual void getDrmInfo(DecryptHandle **handle, DrmManagerClient **client); virtual void getDrmInfo(sp<DecryptHandle> &handle, DrmManagerClient **client);
virtual String8 getUri(); virtual String8 getUri();
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////

View File

@@ -47,8 +47,8 @@ struct NuHTTPDataSource : public HTTPBase {
// false otherwise. // false otherwise.
virtual bool estimateBandwidth(int32_t *bandwidth_bps); virtual bool estimateBandwidth(int32_t *bandwidth_bps);
virtual DecryptHandle* DrmInitialization(); virtual sp<DecryptHandle> DrmInitialization();
virtual void getDrmInfo(DecryptHandle **handle, DrmManagerClient **client); virtual void getDrmInfo(sp<DecryptHandle> &handle, DrmManagerClient **client);
virtual String8 getUri(); virtual String8 getUri();
protected: protected:
@@ -94,7 +94,7 @@ private:
int64_t mTotalTransferTimeUs; int64_t mTotalTransferTimeUs;
size_t mTotalTransferBytes; size_t mTotalTransferBytes;
DecryptHandle *mDecryptHandle; sp<DecryptHandle> mDecryptHandle;
DrmManagerClient *mDrmManagerClient; DrmManagerClient *mDrmManagerClient;
status_t connect( status_t connect(