Update of DRM framework.

- Change "void" type of return value to "int" for returning status.
  - Add some of overloaded Java APIs which accept database Uri as input.
  - Add asynchronous APIs
  - Add OnEventListener and OnErrorListener for asynchronous APIs
  - Disable debug log
  - Change decrypt() API to accept an optional buffer needed by some of DRM schemes

Changes are incorporated by Sony Corporation.

Change-Id: I414a165e22cc79be6ea7cd28041788aa2b6b8f7c
This commit is contained in:
Takeshi Aimi
2010-09-20 23:40:41 +09:00
parent 0335b70c6c
commit 2272ee27d9
27 changed files with 622 additions and 382 deletions

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
#define LOG_NDEBUG 0
//#define LOG_NDEBUG 0
#define LOG_TAG "DrmManagerClientImpl(Native)"
#include <utils/Log.h>
@@ -29,44 +29,21 @@ using namespace android;
#define INVALID_VALUE -1
Mutex DrmManagerClientImpl::mMutex;
Vector<int> DrmManagerClientImpl::mUniqueIdVector;
sp<IDrmManagerService> DrmManagerClientImpl::mDrmManagerService;
const String8 DrmManagerClientImpl::EMPTY_STRING("");
DrmManagerClientImpl* DrmManagerClientImpl::create(int* pUniqueId) {
if (0 == *pUniqueId) {
int uniqueId = 0;
bool foundUniqueId = false;
srand(time(NULL));
while (!foundUniqueId) {
const int size = mUniqueIdVector.size();
uniqueId = rand() % 100;
int index = 0;
for (; index < size; ++index) {
if (mUniqueIdVector.itemAt(index) == uniqueId) {
foundUniqueId = false;
break;
}
}
if (index == size) {
foundUniqueId = true;
}
}
int uniqueId = getDrmManagerService()->addUniqueId(*pUniqueId);
*pUniqueId = uniqueId;
} else {
getDrmManagerService()->addUniqueId(*pUniqueId);
}
mUniqueIdVector.push(*pUniqueId);
return new DrmManagerClientImpl();
}
void DrmManagerClientImpl::remove(int uniqueId) {
for (int i = 0; i < mUniqueIdVector.size(); i++) {
if (uniqueId == mUniqueIdVector.itemAt(i)) {
mUniqueIdVector.removeAt(i);
break;
}
}
getDrmManagerService()->removeUniqueId(uniqueId);
}
DrmManagerClientImpl::DrmManagerClientImpl() {
@@ -164,11 +141,13 @@ DrmInfo* DrmManagerClientImpl::acquireDrmInfo(int uniqueId, const DrmInfoRequest
return drmInfo;
}
void DrmManagerClientImpl::saveRights(int uniqueId, const DrmRights& drmRights,
status_t DrmManagerClientImpl::saveRights(int uniqueId, const DrmRights& drmRights,
const String8& rightsPath, const String8& contentPath) {
status_t status = DRM_ERROR_UNKNOWN;
if (EMPTY_STRING != contentPath) {
getDrmManagerService()->saveRights(uniqueId, drmRights, rightsPath, contentPath);
status = getDrmManagerService()->saveRights(uniqueId, drmRights, rightsPath, contentPath);
}
return status;
}
String8 DrmManagerClientImpl::getOriginalMimeType(int uniqueId, const String8& path) {
@@ -197,19 +176,23 @@ int DrmManagerClientImpl::checkRightsStatus(
return rightsStatus;
}
void DrmManagerClientImpl::consumeRights(
status_t DrmManagerClientImpl::consumeRights(
int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) {
status_t status = DRM_ERROR_UNKNOWN;
if (NULL != decryptHandle) {
getDrmManagerService()->consumeRights(uniqueId, decryptHandle, action, reserve);
status = getDrmManagerService()->consumeRights(uniqueId, decryptHandle, action, reserve);
}
return status;
}
void DrmManagerClientImpl::setPlaybackStatus(
status_t DrmManagerClientImpl::setPlaybackStatus(
int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position) {
status_t status = DRM_ERROR_UNKNOWN;
if (NULL != decryptHandle) {
getDrmManagerService()->setPlaybackStatus(
status = getDrmManagerService()->setPlaybackStatus(
uniqueId, decryptHandle, playbackStatus, position);
}
return status;
}
bool DrmManagerClientImpl::validateAction(
@@ -221,14 +204,16 @@ bool DrmManagerClientImpl::validateAction(
return retCode;
}
void DrmManagerClientImpl::removeRights(int uniqueId, const String8& path) {
status_t DrmManagerClientImpl::removeRights(int uniqueId, const String8& path) {
status_t status = DRM_ERROR_UNKNOWN;
if (EMPTY_STRING != path) {
getDrmManagerService()->removeRights(uniqueId, path);
status = getDrmManagerService()->removeRights(uniqueId, path);
}
return status;
}
void DrmManagerClientImpl::removeAllRights(int uniqueId) {
getDrmManagerService()->removeAllRights(uniqueId);
status_t DrmManagerClientImpl::removeAllRights(int uniqueId) {
return getDrmManagerService()->removeAllRights(uniqueId);
}
int DrmManagerClientImpl::openConvertSession(int uniqueId, const String8& mimeType) {
@@ -263,40 +248,46 @@ status_t DrmManagerClientImpl::getAllSupportInfo(
DecryptHandle* DrmManagerClientImpl::openDecryptSession(
int uniqueId, int fd, int offset, int length) {
LOGV("Entering DrmManagerClientImpl::openDecryptSession");
return getDrmManagerService()->openDecryptSession(uniqueId, fd, offset, length);
}
void DrmManagerClientImpl::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) {
if (NULL != decryptHandle) {
getDrmManagerService()->closeDecryptSession( uniqueId, decryptHandle);
}
}
void DrmManagerClientImpl::initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle,
int decryptUnitId, const DrmBuffer* headerInfo) {
if ((NULL != decryptHandle) && (NULL != headerInfo)) {
getDrmManagerService()->initializeDecryptUnit(
uniqueId, decryptHandle, decryptUnitId, headerInfo);
}
}
status_t DrmManagerClientImpl::decrypt(int uniqueId, DecryptHandle* decryptHandle,
int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer) {
status_t DrmManagerClientImpl::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) {
status_t status = DRM_ERROR_UNKNOWN;
if ((NULL != decryptHandle) && (NULL != encBuffer)
&& (NULL != decBuffer) && (NULL != *decBuffer)) {
status = getDrmManagerService()->decrypt(
uniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer);
if (NULL != decryptHandle) {
status = getDrmManagerService()->closeDecryptSession( uniqueId, decryptHandle);
}
return status;
}
void DrmManagerClientImpl::finalizeDecryptUnit(
int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) {
if (NULL != decryptHandle) {
getDrmManagerService()->finalizeDecryptUnit(uniqueId, decryptHandle, decryptUnitId);
status_t DrmManagerClientImpl::initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle,
int decryptUnitId, const DrmBuffer* headerInfo) {
status_t status = DRM_ERROR_UNKNOWN;
if ((NULL != decryptHandle) && (NULL != headerInfo)) {
status = getDrmManagerService()->initializeDecryptUnit(
uniqueId, decryptHandle, decryptUnitId, headerInfo);
}
return status;
}
status_t DrmManagerClientImpl::decrypt(int uniqueId, DecryptHandle* decryptHandle,
int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) {
status_t status = DRM_ERROR_UNKNOWN;
if ((NULL != decryptHandle) && (NULL != encBuffer)
&& (NULL != decBuffer) && (NULL != *decBuffer)) {
status = getDrmManagerService()->decrypt(
uniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer, IV);
}
return status;
}
status_t DrmManagerClientImpl::finalizeDecryptUnit(
int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) {
status_t status = DRM_ERROR_UNKNOWN;
if (NULL != decryptHandle) {
status
= getDrmManagerService()->finalizeDecryptUnit(uniqueId, decryptHandle, decryptUnitId);
}
return status;
}
ssize_t DrmManagerClientImpl::pread(int uniqueId, DecryptHandle* decryptHandle,