diff options
author | Gloria Wang <gwang@google.com> | 2011-07-21 15:10:22 -0700 |
---|---|---|
committer | Gloria Wang <gwang@google.com> | 2011-07-25 16:09:58 -0700 |
commit | a17d454fd0d20d14cf1fbc09f0f296cb6cbb870b (patch) | |
tree | e7ecaa5d516248aee80cf5887f50c5b75e91a0f4 /drm | |
parent | ae5df05f2246515a652f0c935c6deb85a0bdee01 (diff) | |
download | frameworks_base-a17d454fd0d20d14cf1fbc09f0f296cb6cbb870b.zip frameworks_base-a17d454fd0d20d14cf1fbc09f0f296cb6cbb870b.tar.gz frameworks_base-a17d454fd0d20d14cf1fbc09f0f296cb6cbb870b.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')
-rw-r--r-- | drm/common/IDrmManagerService.cpp | 4 | ||||
-rw-r--r-- | drm/drmserver/DrmManager.cpp | 54 | ||||
-rw-r--r-- | drm/drmserver/DrmManagerService.cpp | 4 | ||||
-rwxr-xr-x | drm/java/android/drm/DrmManagerClient.java | 6 | ||||
-rw-r--r-- | drm/jni/android_drm_DrmManagerClient.cpp | 11 | ||||
-rw-r--r-- | drm/libdrmframework/DrmManagerClient.cpp | 2 | ||||
-rw-r--r-- | drm/libdrmframework/DrmManagerClientImpl.cpp | 11 | ||||
-rw-r--r-- | drm/libdrmframework/include/DrmManager.h | 2 | ||||
-rw-r--r-- | drm/libdrmframework/include/DrmManagerClientImpl.h | 2 | ||||
-rw-r--r-- | drm/libdrmframework/include/DrmManagerService.h | 2 | ||||
-rw-r--r-- | drm/libdrmframework/include/IDrmManagerService.h | 4 | ||||
-rw-r--r-- | drm/libdrmframework/plugins/common/include/DrmEngineBase.h | 8 |
12 files changed, 62 insertions, 48 deletions
diff --git a/drm/common/IDrmManagerService.cpp b/drm/common/IDrmManagerService.cpp index 2d8e877..986f32c 100644 --- a/drm/common/IDrmManagerService.cpp +++ b/drm/common/IDrmManagerService.cpp @@ -110,11 +110,11 @@ static void clearDecryptHandle(DecryptHandle* handle) { handle->extendedData.clear(); } -int BpDrmManagerService::addUniqueId(int uniqueId) { +int BpDrmManagerService::addUniqueId(bool isNative) { LOGV("add uniqueid"); Parcel data, reply; data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); - data.writeInt32(uniqueId); + data.writeInt32(isNative); remote()->transact(ADD_UNIQUEID, data, &reply); return reply.readInt32(); } 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) { diff --git a/drm/drmserver/DrmManagerService.cpp b/drm/drmserver/DrmManagerService.cpp index 583669e..7ebcac3 100644 --- a/drm/drmserver/DrmManagerService.cpp +++ b/drm/drmserver/DrmManagerService.cpp @@ -78,8 +78,8 @@ DrmManagerService::~DrmManagerService() { delete mDrmManager; mDrmManager = NULL; } -int DrmManagerService::addUniqueId(int uniqueId) { - return mDrmManager->addUniqueId(uniqueId); +int DrmManagerService::addUniqueId(bool isNative) { + return mDrmManager->addUniqueId(isNative); } void DrmManagerService::removeUniqueId(int uniqueId) { diff --git a/drm/java/android/drm/DrmManagerClient.java b/drm/java/android/drm/DrmManagerClient.java index f3a0343..9a7194c 100755 --- a/drm/java/android/drm/DrmManagerClient.java +++ b/drm/java/android/drm/DrmManagerClient.java @@ -248,9 +248,7 @@ public class DrmManagerClient { mEventHandler = new EventHandler(eventThread.getLooper()); // save the unique id - mUniqueId = hashCode(); - - _initialize(mUniqueId, new WeakReference<DrmManagerClient>(this)); + mUniqueId = _initialize(new WeakReference<DrmManagerClient>(this)); } protected void finalize() { @@ -794,7 +792,7 @@ public class DrmManagerClient { } // private native interfaces - private native void _initialize(int uniqueId, Object weak_this); + private native int _initialize(Object weak_this); private native void _finalize(int uniqueId); diff --git a/drm/jni/android_drm_DrmManagerClient.cpp b/drm/jni/android_drm_DrmManagerClient.cpp index e131839..80a8447 100644 --- a/drm/jni/android_drm_DrmManagerClient.cpp +++ b/drm/jni/android_drm_DrmManagerClient.cpp @@ -224,11 +224,12 @@ static sp<DrmManagerClientImpl> getDrmManagerClientImpl(JNIEnv* env, jobject thi return sp<DrmManagerClientImpl>(client); } -static void android_drm_DrmManagerClient_initialize( - JNIEnv* env, jobject thiz, jint uniqueId, jobject weak_thiz) { +static jint android_drm_DrmManagerClient_initialize( + JNIEnv* env, jobject thiz, jobject weak_thiz) { LOGV("initialize - Enter"); - sp<DrmManagerClientImpl> drmManager = DrmManagerClientImpl::create(&uniqueId); + int uniqueId = 0; + sp<DrmManagerClientImpl> drmManager = DrmManagerClientImpl::create(&uniqueId, false); drmManager->addClient(uniqueId); // Set the listener to DrmManager @@ -237,6 +238,8 @@ static void android_drm_DrmManagerClient_initialize( setDrmManagerClientImpl(env, thiz, drmManager); LOGV("initialize - Exit"); + + return uniqueId; } static void android_drm_DrmManagerClient_finalize(JNIEnv* env, jobject thiz, jint uniqueId) { @@ -711,7 +714,7 @@ static jobject android_drm_DrmManagerClient_closeConvertSession( static JNINativeMethod nativeMethods[] = { - {"_initialize", "(ILjava/lang/Object;)V", + {"_initialize", "(Ljava/lang/Object;)I", (void*)android_drm_DrmManagerClient_initialize}, {"_finalize", "(I)V", diff --git a/drm/libdrmframework/DrmManagerClient.cpp b/drm/libdrmframework/DrmManagerClient.cpp index b50199f..c9c0d57 100644 --- a/drm/libdrmframework/DrmManagerClient.cpp +++ b/drm/libdrmframework/DrmManagerClient.cpp @@ -24,7 +24,7 @@ using namespace android; DrmManagerClient::DrmManagerClient(): mUniqueId(0), mDrmManagerClientImpl(NULL) { - mDrmManagerClientImpl = DrmManagerClientImpl::create(&mUniqueId); + mDrmManagerClientImpl = DrmManagerClientImpl::create(&mUniqueId, true); mDrmManagerClientImpl->addClient(mUniqueId); } diff --git a/drm/libdrmframework/DrmManagerClientImpl.cpp b/drm/libdrmframework/DrmManagerClientImpl.cpp index a36bd4a..67f58ca 100644 --- a/drm/libdrmframework/DrmManagerClientImpl.cpp +++ b/drm/libdrmframework/DrmManagerClientImpl.cpp @@ -33,13 +33,10 @@ sp<IDrmManagerService> DrmManagerClientImpl::sDrmManagerService; sp<DrmManagerClientImpl::DeathNotifier> DrmManagerClientImpl::sDeathNotifier; const String8 DrmManagerClientImpl::EMPTY_STRING(""); -DrmManagerClientImpl* DrmManagerClientImpl::create(int* pUniqueId) { - if (0 == *pUniqueId) { - int uniqueId = getDrmManagerService()->addUniqueId(*pUniqueId); - *pUniqueId = uniqueId; - } else { - getDrmManagerService()->addUniqueId(*pUniqueId); - } +DrmManagerClientImpl* DrmManagerClientImpl::create( + int* pUniqueId, bool isNative) { + *pUniqueId = getDrmManagerService()->addUniqueId(isNative); + return new DrmManagerClientImpl(); } diff --git a/drm/libdrmframework/include/DrmManager.h b/drm/libdrmframework/include/DrmManager.h index af2c2a8..ac2b946 100644 --- a/drm/libdrmframework/include/DrmManager.h +++ b/drm/libdrmframework/include/DrmManager.h @@ -53,7 +53,7 @@ public: virtual ~DrmManager(); public: - int addUniqueId(int uniqueId); + int addUniqueId(bool isNative); void removeUniqueId(int uniqueId); diff --git a/drm/libdrmframework/include/DrmManagerClientImpl.h b/drm/libdrmframework/include/DrmManagerClientImpl.h index 564896b..e3338d9 100644 --- a/drm/libdrmframework/include/DrmManagerClientImpl.h +++ b/drm/libdrmframework/include/DrmManagerClientImpl.h @@ -38,7 +38,7 @@ private: DrmManagerClientImpl() { } public: - static DrmManagerClientImpl* create(int* pUniqueId); + static DrmManagerClientImpl* create(int* pUniqueId, bool isNative); static void remove(int uniqueId); diff --git a/drm/libdrmframework/include/DrmManagerService.h b/drm/libdrmframework/include/DrmManagerService.h index 227496a..9cb5804 100644 --- a/drm/libdrmframework/include/DrmManagerService.h +++ b/drm/libdrmframework/include/DrmManagerService.h @@ -46,7 +46,7 @@ private: virtual ~DrmManagerService(); public: - int addUniqueId(int uniqueId); + int addUniqueId(bool isNative); void removeUniqueId(int uniqueId); diff --git a/drm/libdrmframework/include/IDrmManagerService.h b/drm/libdrmframework/include/IDrmManagerService.h index 7727e55..b9618bb 100644 --- a/drm/libdrmframework/include/IDrmManagerService.h +++ b/drm/libdrmframework/include/IDrmManagerService.h @@ -81,7 +81,7 @@ public: DECLARE_META_INTERFACE(DrmManagerService); public: - virtual int addUniqueId(int uniqueId) = 0; + virtual int addUniqueId(bool isNative) = 0; virtual void removeUniqueId(int uniqueId) = 0; @@ -167,7 +167,7 @@ public: BpDrmManagerService(const sp<IBinder>& impl) : BpInterface<IDrmManagerService>(impl) {} - virtual int addUniqueId(int uniqueId); + virtual int addUniqueId(bool isNative); virtual void removeUniqueId(int uniqueId); diff --git a/drm/libdrmframework/plugins/common/include/DrmEngineBase.h b/drm/libdrmframework/plugins/common/include/DrmEngineBase.h index b61e3d3..4a5afcf 100644 --- a/drm/libdrmframework/plugins/common/include/DrmEngineBase.h +++ b/drm/libdrmframework/plugins/common/include/DrmEngineBase.h @@ -143,7 +143,13 @@ protected: * Register a callback to be invoked when the caller required to * receive necessary information * - * @param[in] uniqueId Unique identifier for a session + * @param[in] uniqueId Unique identifier for a session. uniqueId is a random + * number generated in the DRM service. If the DrmManagerClient + * is created in native code, uniqueId will be a number ranged + * from 0x1000 to 0x1fff. If it comes from Java code, the uniqueId + * will be a number ranged from 0x00 to 0xfff. So bit 0x1000 in + * uniqueId could be used in DRM plugins to differentiate native + * OnInfoListener and Java OnInfoListener. * @param[in] infoListener Listener * @return status_t * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure |