summaryrefslogtreecommitdiffstats
path: root/drm/drmserver
diff options
context:
space:
mode:
Diffstat (limited to 'drm/drmserver')
-rw-r--r--drm/drmserver/DrmManager.cpp136
-rw-r--r--drm/drmserver/DrmManagerService.cpp69
-rw-r--r--drm/drmserver/StringTokenizer.cpp2
3 files changed, 135 insertions, 72 deletions
diff --git a/drm/drmserver/DrmManager.cpp b/drm/drmserver/DrmManager.cpp
index 44886f9..52527dc 100644
--- a/drm/drmserver/DrmManager.cpp
+++ b/drm/drmserver/DrmManager.cpp
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-#define LOG_NDEBUG 0
+//#define LOG_NDEBUG 0
#define LOG_TAG "DrmManager(Native)"
#include "utils/Log.h"
@@ -36,6 +36,7 @@
using namespace android;
+Vector<int> DrmManager::mUniqueIdVector;
const String8 DrmManager::EMPTY_STRING("");
DrmManager::DrmManager() :
@@ -48,6 +49,42 @@ DrmManager::~DrmManager() {
}
+int DrmManager::addUniqueId(int uniqueId) {
+ if (0 == uniqueId) {
+ int temp = 0;
+ bool foundUniqueId = false;
+ srand(time(NULL));
+
+ while (!foundUniqueId) {
+ const int size = mUniqueIdVector.size();
+ temp = rand() % 100;
+
+ int index = 0;
+ for (; index < size; ++index) {
+ if (mUniqueIdVector.itemAt(index) == temp) {
+ foundUniqueId = false;
+ break;
+ }
+ }
+ if (index == size) {
+ foundUniqueId = true;
+ }
+ }
+ uniqueId = temp;
+ }
+ mUniqueIdVector.push(uniqueId);
+ return uniqueId;
+}
+
+void DrmManager::removeUniqueId(int uniqueId) {
+ for (unsigned int i = 0; i < mUniqueIdVector.size(); i++) {
+ if (uniqueId == mUniqueIdVector.itemAt(i)) {
+ mUniqueIdVector.removeAt(i);
+ break;
+ }
+ }
+}
+
status_t DrmManager::loadPlugIns(int uniqueId) {
String8 pluginDirPath("/system/lib/drm/plugins/native");
return loadPlugIns(uniqueId, pluginDirPath);
@@ -82,10 +119,12 @@ status_t DrmManager::unloadPlugIns(int uniqueId) {
rDrmEngine.terminate(uniqueId);
}
- mConvertSessionMap.clear();
- mDecryptSessionMap.clear();
- mSupportInfoToPlugInIdMap.clear();
- mPlugInManager.unloadPlugIns();
+ if (0 >= mUniqueIdVector.size()) {
+ mConvertSessionMap.clear();
+ mDecryptSessionMap.clear();
+ mSupportInfoToPlugInIdMap.clear();
+ mPlugInManager.unloadPlugIns();
+ }
return DRM_NO_ERROR;
}
@@ -159,13 +198,15 @@ DrmInfo* DrmManager::acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoR
return NULL;
}
-void DrmManager::saveRights(int uniqueId, const DrmRights& drmRights,
+status_t DrmManager::saveRights(int uniqueId, const DrmRights& drmRights,
const String8& rightsPath, const String8& contentPath) {
const String8 plugInId = getSupportedPlugInId(drmRights.getMimeType());
+ status_t result = DRM_ERROR_UNKNOWN;
if (EMPTY_STRING != plugInId) {
IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId);
- rDrmEngine.saveRights(uniqueId, drmRights, rightsPath, contentPath);
+ result = rDrmEngine.saveRights(uniqueId, drmRights, rightsPath, contentPath);
}
+ return result;
}
String8 DrmManager::getOriginalMimeType(int uniqueId, const String8& path) {
@@ -195,21 +236,24 @@ int DrmManager::checkRightsStatus(int uniqueId, const String8& path, int action)
return RightsStatus::RIGHTS_INVALID;
}
-void DrmManager::consumeRights(
+status_t DrmManager::consumeRights(
int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) {
+ status_t result = DRM_ERROR_UNKNOWN;
if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) {
IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId);
- drmEngine->consumeRights(uniqueId, decryptHandle, action, reserve);
+ result = drmEngine->consumeRights(uniqueId, decryptHandle, action, reserve);
}
+ return result;
}
-void DrmManager::setPlaybackStatus(
+status_t DrmManager::setPlaybackStatus(
int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position) {
-
+ status_t result = DRM_ERROR_UNKNOWN;
if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) {
IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId);
- drmEngine->setPlaybackStatus(uniqueId, decryptHandle, playbackStatus, position);
+ result = drmEngine->setPlaybackStatus(uniqueId, decryptHandle, playbackStatus, position);
}
+ return result;
}
bool DrmManager::validateAction(
@@ -222,21 +266,27 @@ bool DrmManager::validateAction(
return false;
}
-void DrmManager::removeRights(int uniqueId, const String8& path) {
+status_t DrmManager::removeRights(int uniqueId, const String8& path) {
const String8 plugInId = getSupportedPlugInIdFromPath(uniqueId, path);
+ status_t result = DRM_ERROR_UNKNOWN;
if (EMPTY_STRING != plugInId) {
IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId);
- rDrmEngine.removeRights(uniqueId, path);
+ result = rDrmEngine.removeRights(uniqueId, path);
}
+ return result;
}
-void DrmManager::removeAllRights(int uniqueId) {
+status_t DrmManager::removeAllRights(int uniqueId) {
Vector<String8> plugInIdList = mPlugInManager.getPlugInIdList();
-
+ status_t result = DRM_ERROR_UNKNOWN;
for (unsigned int index = 0; index < plugInIdList.size(); index++) {
IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInIdList.itemAt(index));
- rDrmEngine.removeAllRights(uniqueId);
+ result = rDrmEngine.removeAllRights(uniqueId);
+ if (DRM_NO_ERROR != result) {
+ break;
+ }
}
+ return result;
}
int DrmManager::openConvertSession(int uniqueId, const String8& mimeType) {
@@ -246,12 +296,12 @@ int DrmManager::openConvertSession(int uniqueId, const String8& mimeType) {
if (EMPTY_STRING != plugInId) {
IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId);
- Mutex::Autolock _l(mConvertLock);
- ++mConvertId;
- convertId = mConvertId;
- mConvertSessionMap.add(mConvertId, &rDrmEngine);
-
- rDrmEngine.openConvertSession(uniqueId, mConvertId);
+ if (DRM_NO_ERROR == rDrmEngine.openConvertSession(uniqueId, mConvertId + 1)) {
+ Mutex::Autolock _l(mConvertLock);
+ ++mConvertId;
+ convertId = mConvertId;
+ mConvertSessionMap.add(convertId, &rDrmEngine);
+ }
}
return convertId;
}
@@ -310,7 +360,6 @@ status_t DrmManager::getAllSupportInfo(
}
DecryptHandle* DrmManager::openDecryptSession(int uniqueId, int fd, int offset, int length) {
- LOGV("Entering DrmManager::openDecryptSession");
status_t result = DRM_ERROR_CANNOT_HANDLE;
Vector<String8> plugInIdList = mPlugInManager.getPlugInIdList();
@@ -324,18 +373,15 @@ DecryptHandle* DrmManager::openDecryptSession(int uniqueId, int fd, int offset,
IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId);
result = rDrmEngine.openDecryptSession(uniqueId, handle, fd, offset, length);
- LOGV("plug-in %s return value = %d", plugInId.string(), result);
-
if (DRM_NO_ERROR == result) {
++mDecryptSessionId;
mDecryptSessionMap.add(mDecryptSessionId, &rDrmEngine);
- LOGV("plug-in %s is selected", plugInId.string());
break;
}
}
}
- if (DRM_ERROR_CANNOT_HANDLE == result) {
+ if (DRM_NO_ERROR != result) {
delete handle; handle = NULL;
LOGE("DrmManager::openDecryptSession: no capable plug-in found");
}
@@ -343,39 +389,47 @@ DecryptHandle* DrmManager::openDecryptSession(int uniqueId, int fd, int offset,
return handle;
}
-void DrmManager::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) {
+status_t DrmManager::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) {
+ status_t result = DRM_ERROR_UNKNOWN;
if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) {
IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId);
- drmEngine->closeDecryptSession(uniqueId, decryptHandle);
-
- mDecryptSessionMap.removeItem(decryptHandle->decryptId);
+ result = drmEngine->closeDecryptSession(uniqueId, decryptHandle);
+ if (DRM_NO_ERROR == result) {
+ mDecryptSessionMap.removeItem(decryptHandle->decryptId);
+ }
}
+ return result;
}
-void DrmManager::initializeDecryptUnit(
+status_t DrmManager::initializeDecryptUnit(
int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo) {
+ status_t result = DRM_ERROR_UNKNOWN;
if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) {
IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId);
- drmEngine->initializeDecryptUnit(uniqueId, decryptHandle, decryptUnitId, headerInfo);
+ result = drmEngine->initializeDecryptUnit(uniqueId, decryptHandle, decryptUnitId, headerInfo);
}
+ return result;
}
-status_t DrmManager::decrypt(int uniqueId, DecryptHandle* decryptHandle,
- int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer) {
- status_t status = DRM_ERROR_UNKNOWN;
+status_t DrmManager::decrypt(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId,
+ const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) {
+ status_t result = DRM_ERROR_UNKNOWN;
if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) {
IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId);
- status = drmEngine->decrypt(uniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer);
+ result = drmEngine->decrypt(
+ uniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer, IV);
}
- return status;
+ return result;
}
-void DrmManager::finalizeDecryptUnit(
+status_t DrmManager::finalizeDecryptUnit(
int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) {
+ status_t result = DRM_ERROR_UNKNOWN;
if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) {
IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId);
- drmEngine->finalizeDecryptUnit(uniqueId, decryptHandle, decryptUnitId);
+ result = drmEngine->finalizeDecryptUnit(uniqueId, decryptHandle, decryptUnitId);
}
+ return result;
}
ssize_t DrmManager::pread(int uniqueId, DecryptHandle* decryptHandle,
diff --git a/drm/drmserver/DrmManagerService.cpp b/drm/drmserver/DrmManagerService.cpp
index 9d000e9..843dddb 100644
--- a/drm/drmserver/DrmManagerService.cpp
+++ b/drm/drmserver/DrmManagerService.cpp
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-#define LOG_NDEBUG 0
+//#define LOG_NDEBUG 0
#define LOG_TAG "DrmManagerService(Native)"
#include <utils/Log.h>
@@ -29,20 +29,23 @@ using namespace android;
#define SUCCESS 0
#define DRM_DIRECTORY_PERMISSION 0700
+#define DRM_PLUGINS_ROOT "/data/drm/plugins"
+#define DRM_PLUGINS_NATIVE "/data/drm/plugins/native"
+#define DRM_PLUGINS_NATIVE_DATABASES "/data/drm/plugins/native/databases"
void DrmManagerService::instantiate() {
LOGV("instantiate");
- int res = mkdir("/data/drm/plugins", DRM_DIRECTORY_PERMISSION);
- if (SUCCESS == res || EEXIST == errno) {
- res = mkdir("/data/drm/plugins/native", DRM_DIRECTORY_PERMISSION);
- if (SUCCESS == res || EEXIST == errno) {
- res = mkdir("/data/drm/plugins/native/databases", DRM_DIRECTORY_PERMISSION);
- if (SUCCESS == res || EEXIST == errno) {
- defaultServiceManager()
- ->addService(String16("drm.drmManager"), new DrmManagerService());
- }
- }
+ int res = mkdir(DRM_PLUGINS_ROOT, DRM_DIRECTORY_PERMISSION);
+ if (SUCCESS == res || EEXIST == errno) {
+ res = mkdir(DRM_PLUGINS_NATIVE, DRM_DIRECTORY_PERMISSION);
+ if (SUCCESS == res || EEXIST == errno) {
+ res = mkdir(DRM_PLUGINS_NATIVE_DATABASES, DRM_DIRECTORY_PERMISSION);
+ if (SUCCESS == res || EEXIST == errno) {
+ defaultServiceManager()
+ ->addService(String16("drm.drmManager"), new DrmManagerService());
+ }
+ }
}
}
@@ -57,6 +60,14 @@ DrmManagerService::~DrmManagerService() {
delete mDrmManager; mDrmManager = NULL;
}
+int DrmManagerService::addUniqueId(int uniqueId) {
+ return mDrmManager->addUniqueId(uniqueId);
+}
+
+void DrmManagerService::removeUniqueId(int uniqueId) {
+ mDrmManager->removeUniqueId(uniqueId);
+}
+
status_t DrmManagerService::loadPlugIns(int uniqueId) {
LOGV("Entering load plugins");
return mDrmManager->loadPlugIns(uniqueId);
@@ -105,7 +116,7 @@ DrmInfo* DrmManagerService::acquireDrmInfo(int uniqueId, const DrmInfoRequest* d
return mDrmManager->acquireDrmInfo(uniqueId, drmInfoRequest);
}
-void DrmManagerService::saveRights(
+status_t DrmManagerService::saveRights(
int uniqueId, const DrmRights& drmRights,
const String8& rightsPath, const String8& contentPath) {
LOGV("Entering saveRights");
@@ -129,16 +140,16 @@ int DrmManagerService::checkRightsStatus(
return mDrmManager->checkRightsStatus(uniqueId, path, action);
}
-void DrmManagerService::consumeRights(
+status_t DrmManagerService::consumeRights(
int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) {
LOGV("Entering consumeRights");
- mDrmManager->consumeRights(uniqueId, decryptHandle, action, reserve);
+ return mDrmManager->consumeRights(uniqueId, decryptHandle, action, reserve);
}
-void DrmManagerService::setPlaybackStatus(
+status_t DrmManagerService::setPlaybackStatus(
int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position) {
LOGV("Entering setPlaybackStatus");
- mDrmManager->setPlaybackStatus(uniqueId, decryptHandle, playbackStatus, position);
+ return mDrmManager->setPlaybackStatus(uniqueId, decryptHandle, playbackStatus, position);
}
bool DrmManagerService::validateAction(
@@ -148,14 +159,14 @@ bool DrmManagerService::validateAction(
return mDrmManager->validateAction(uniqueId, path, action, description);
}
-void DrmManagerService::removeRights(int uniqueId, const String8& path) {
+status_t DrmManagerService::removeRights(int uniqueId, const String8& path) {
LOGV("Entering removeRights");
- mDrmManager->removeRights(uniqueId, path);
+ return mDrmManager->removeRights(uniqueId, path);
}
-void DrmManagerService::removeAllRights(int uniqueId) {
+status_t DrmManagerService::removeAllRights(int uniqueId) {
LOGV("Entering removeAllRights");
- mDrmManager->removeAllRights(uniqueId);
+ return mDrmManager->removeAllRights(uniqueId);
}
int DrmManagerService::openConvertSession(int uniqueId, const String8& mimeType) {
@@ -186,28 +197,28 @@ DecryptHandle* DrmManagerService::openDecryptSession(
return mDrmManager->openDecryptSession(uniqueId, fd, offset, length);
}
-void DrmManagerService::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) {
+status_t DrmManagerService::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) {
LOGV("Entering closeDecryptSession");
- mDrmManager->closeDecryptSession(uniqueId, decryptHandle);
+ return mDrmManager->closeDecryptSession(uniqueId, decryptHandle);
}
-void DrmManagerService::initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle,
+status_t DrmManagerService::initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle,
int decryptUnitId, const DrmBuffer* headerInfo) {
LOGV("Entering initializeDecryptUnit");
- mDrmManager->initializeDecryptUnit(uniqueId,decryptHandle, decryptUnitId, headerInfo);
+ return mDrmManager->initializeDecryptUnit(uniqueId,decryptHandle, decryptUnitId, headerInfo);
}
status_t DrmManagerService::decrypt(
- int uniqueId, DecryptHandle* decryptHandle,
- int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer) {
+ int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId,
+ const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) {
LOGV("Entering decrypt");
- return mDrmManager->decrypt(uniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer);
+ return mDrmManager->decrypt(uniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer, IV);
}
-void DrmManagerService::finalizeDecryptUnit(
+status_t DrmManagerService::finalizeDecryptUnit(
int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) {
LOGV("Entering finalizeDecryptUnit");
- mDrmManager->finalizeDecryptUnit(uniqueId, decryptHandle, decryptUnitId);
+ return mDrmManager->finalizeDecryptUnit(uniqueId, decryptHandle, decryptUnitId);
}
ssize_t DrmManagerService::pread(int uniqueId, DecryptHandle* decryptHandle,
diff --git a/drm/drmserver/StringTokenizer.cpp b/drm/drmserver/StringTokenizer.cpp
index 367c9bd..2130a00 100644
--- a/drm/drmserver/StringTokenizer.cpp
+++ b/drm/drmserver/StringTokenizer.cpp
@@ -45,12 +45,10 @@ StringTokenizer::Iterator StringTokenizer::iterator() {
StringTokenizer::Iterator::Iterator(const StringTokenizer::Iterator& iterator) :
mStringTokenizer(iterator.mStringTokenizer),
mIndex(iterator.mIndex) {
- LOGV("StringTokenizer::Iterator::Iterator");
}
StringTokenizer::Iterator& StringTokenizer::Iterator::operator=(
const StringTokenizer::Iterator& iterator) {
- LOGV("StringTokenizer::Iterator::operator=");
mStringTokenizer = iterator.mStringTokenizer;
mIndex = iterator.mIndex;
return *this;