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();
}
}
-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) {
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) {
DrmManagerClient::DrmManagerClient():
mUniqueId(0), mDrmManagerClientImpl(NULL) {
- mDrmManagerClientImpl = DrmManagerClientImpl::create(&mUniqueId);
+ mDrmManagerClientImpl = DrmManagerClientImpl::create(&mUniqueId, true);
mDrmManagerClientImpl->addClient(mUniqueId);
}
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();
}
virtual ~DrmManager();
public:
- int addUniqueId(int uniqueId);
+ int addUniqueId(bool isNative);
void removeUniqueId(int uniqueId);
DrmManagerClientImpl() { }
public:
- static DrmManagerClientImpl* create(int* pUniqueId);
+ static DrmManagerClientImpl* create(int* pUniqueId, bool isNative);
static void remove(int uniqueId);
virtual ~DrmManagerService();
public:
- int addUniqueId(int uniqueId);
+ int addUniqueId(bool isNative);
void removeUniqueId(int uniqueId);
DECLARE_META_INTERFACE(DrmManagerService);
public:
- virtual int addUniqueId(int uniqueId) = 0;
+ virtual int addUniqueId(bool isNative) = 0;
virtual void removeUniqueId(int uniqueId) = 0;
BpDrmManagerService(const sp<IBinder>& impl)
: BpInterface<IDrmManagerService>(impl) {}
- virtual int addUniqueId(int uniqueId);
+ virtual int addUniqueId(bool isNative);
virtual void removeUniqueId(int uniqueId);
* 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