diff options
Diffstat (limited to 'drm/drmserver')
-rw-r--r-- | drm/drmserver/Android.mk | 1 | ||||
-rw-r--r-- | drm/drmserver/DrmManager.cpp | 71 | ||||
-rw-r--r-- | drm/drmserver/DrmManagerService.cpp | 5 |
3 files changed, 24 insertions, 53 deletions
diff --git a/drm/drmserver/Android.mk b/drm/drmserver/Android.mk index 96205a1..dc973da 100644 --- a/drm/drmserver/Android.mk +++ b/drm/drmserver/Android.mk @@ -24,6 +24,7 @@ LOCAL_SRC_FILES:= \ LOCAL_SHARED_LIBRARIES := \ libmedia \ libutils \ + liblog \ libbinder \ libdl diff --git a/drm/drmserver/DrmManager.cpp b/drm/drmserver/DrmManager.cpp index e7b0e90..dccd23d 100644 --- a/drm/drmserver/DrmManager.cpp +++ b/drm/drmserver/DrmManager.cpp @@ -42,7 +42,8 @@ const String8 DrmManager::EMPTY_STRING(""); DrmManager::DrmManager() : mDecryptSessionId(0), mConvertId(0) { - + srand(time(NULL)); + memset(mUniqueIdArray, 0, sizeof(bool) * kMaxNumUniqueIds); } DrmManager::~DrmManager() { @@ -52,48 +53,37 @@ DrmManager::~DrmManager() { int DrmManager::addUniqueId(bool isNative) { Mutex::Autolock _l(mLock); - int temp = 0; - bool foundUniqueId = false; - const int size = mUniqueIdVector.size(); - const int uniqueIdRange = 0xfff; - int maxLoopTimes = (uniqueIdRange - 1) / 2; - srand(time(NULL)); + int uniqueId = -1; + int random = rand(); - while (!foundUniqueId) { - temp = rand() & uniqueIdRange; - - if (isNative) { - // set a flag to differentiate DrmManagerClient - // created from native side and java side - temp |= 0x1000; - } + for (size_t index = 0; index < kMaxNumUniqueIds; ++index) { + int temp = (random + index) % kMaxNumUniqueIds; + if (!mUniqueIdArray[temp]) { + uniqueId = temp; + mUniqueIdArray[uniqueId] = true; - int index = 0; - for (; index < size; ++index) { - if (mUniqueIdVector.itemAt(index) == temp) { - foundUniqueId = false; - break; + if (isNative) { + // set a flag to differentiate DrmManagerClient + // created from native side and java side + uniqueId |= 0x1000; } + break; } - if (index == size) { - foundUniqueId = true; - } - - maxLoopTimes --; - LOG_FATAL_IF(maxLoopTimes <= 0, "cannot find an unique ID for this session"); } - mUniqueIdVector.push(temp); - return temp; + // -1 indicates that no unique id can be allocated. + return uniqueId; } void DrmManager::removeUniqueId(int uniqueId) { Mutex::Autolock _l(mLock); - for (unsigned int i = 0; i < mUniqueIdVector.size(); i++) { - if (uniqueId == mUniqueIdVector.itemAt(i)) { - mUniqueIdVector.removeAt(i); - break; - } + if (uniqueId & 0x1000) { + // clear the flag for the native side. + uniqueId &= ~(0x1000); + } + + if (uniqueId >= 0 && uniqueId < kMaxNumUniqueIds) { + mUniqueIdArray[uniqueId] = false; } } @@ -185,21 +175,6 @@ DrmMetadata* DrmManager::getMetadata(int uniqueId, const String8* path) { return NULL; } -status_t DrmManager::installDrmEngine(int uniqueId, const String8& absolutePath) { - Mutex::Autolock _l(mLock); - mPlugInManager.loadPlugIn(absolutePath); - - IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(absolutePath); - rDrmEngine.initialize(uniqueId); - rDrmEngine.setOnInfoListener(uniqueId, this); - - DrmSupportInfo* info = rDrmEngine.getSupportInfo(0); - mSupportInfoToPlugInIdMap.add(*info, absolutePath); - delete info; - - return DRM_NO_ERROR; -} - bool DrmManager::canHandle(int uniqueId, const String8& path, const String8& mimeType) { Mutex::Autolock _l(mLock); const String8 plugInId = getSupportedPlugInId(mimeType); diff --git a/drm/drmserver/DrmManagerService.cpp b/drm/drmserver/DrmManagerService.cpp index bbd3b7f..2b71904 100644 --- a/drm/drmserver/DrmManagerService.cpp +++ b/drm/drmserver/DrmManagerService.cpp @@ -87,11 +87,6 @@ status_t DrmManagerService::setDrmServiceListener( return DRM_NO_ERROR; } -status_t DrmManagerService::installDrmEngine(int uniqueId, const String8& drmEngineFile) { - ALOGV("Entering installDrmEngine"); - return mDrmManager->installDrmEngine(uniqueId, drmEngineFile); -} - DrmConstraints* DrmManagerService::getConstraints( int uniqueId, const String8* path, const int action) { ALOGV("Entering getConstraints from content"); |