summaryrefslogtreecommitdiffstats
path: root/drm/drmserver/DrmManager.cpp
diff options
context:
space:
mode:
authorGloria Wang <gwang@google.com>2011-07-21 15:10:22 -0700
committerGloria Wang <gwang@google.com>2011-07-25 16:09:58 -0700
commit8f00151cbe693d52f3e233757c57fab3b6396d21 (patch)
treee23cc93514f43af27aa3e2d7bcfce1b88d614a2b /drm/drmserver/DrmManager.cpp
parent60c93010e8f96a179574ec66c00ec47a675319e3 (diff)
downloadframeworks_av-8f00151cbe693d52f3e233757c57fab3b6396d21.zip
frameworks_av-8f00151cbe693d52f3e233757c57fab3b6396d21.tar.gz
frameworks_av-8f00151cbe693d52f3e233757c57fab3b6396d21.tar.bz2
Fix for bug 4371230.
- Generate unique ID for each DrmManagerClient in native side - Fix the bug where multiple clients could use the same ID - Return the correct unique ID back to Java - Add a flag in the unique ID to separate native client and Java client Change-Id: Ia4574b6b0a526f2335a65380975dc62f9a6e7f9b
Diffstat (limited to 'drm/drmserver/DrmManager.cpp')
-rw-r--r--drm/drmserver/DrmManager.cpp54
1 files changed, 32 insertions, 22 deletions
diff --git a/drm/drmserver/DrmManager.cpp b/drm/drmserver/DrmManager.cpp
index 1809619..3e4fe8c 100644
--- a/drm/drmserver/DrmManager.cpp
+++ b/drm/drmserver/DrmManager.cpp
@@ -49,32 +49,42 @@ DrmManager::~DrmManager() {
}
-int DrmManager::addUniqueId(int uniqueId) {
+int DrmManager::addUniqueId(bool isNative) {
Mutex::Autolock _l(mLock);
- 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;
+
+ int temp = 0;
+ bool foundUniqueId = false;
+ const int size = mUniqueIdVector.size();
+ const int uniqueIdRange = 0xfff;
+ int maxLoopTimes = (uniqueIdRange - 1) / 2;
+ srand(time(NULL));
+
+ while (!foundUniqueId) {
+ temp = rand() & uniqueIdRange;
+
+ if (isNative) {
+ // set a flag to differentiate DrmManagerClient
+ // created from native side and java side
+ temp |= 0x1000;
+ }
+
+ int index = 0;
+ for (; index < size; ++index) {
+ if (mUniqueIdVector.itemAt(index) == temp) {
+ foundUniqueId = false;
+ break;
}
}
- uniqueId = temp;
+ if (index == size) {
+ foundUniqueId = true;
+ }
+
+ maxLoopTimes --;
+ LOG_FATAL_IF(maxLoopTimes <= 0, "cannot find an unique ID for this session");
}
- mUniqueIdVector.push(uniqueId);
- return uniqueId;
+
+ mUniqueIdVector.push(temp);
+ return temp;
}
void DrmManager::removeUniqueId(int uniqueId) {