2010-07-29 10:12:27 +09:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2010-09-20 23:40:41 +09:00
|
|
|
//#define LOG_NDEBUG 0
|
2010-07-29 10:12:27 +09:00
|
|
|
#define LOG_TAG "DrmManager(Native)"
|
|
|
|
#include "utils/Log.h"
|
|
|
|
|
|
|
|
#include <utils/String8.h>
|
|
|
|
#include <drm/DrmInfo.h>
|
|
|
|
#include <drm/DrmInfoEvent.h>
|
|
|
|
#include <drm/DrmRights.h>
|
|
|
|
#include <drm/DrmConstraints.h>
|
2010-11-16 13:56:11 +09:00
|
|
|
#include <drm/DrmMetadata.h>
|
2010-07-29 10:12:27 +09:00
|
|
|
#include <drm/DrmInfoStatus.h>
|
|
|
|
#include <drm/DrmInfoRequest.h>
|
|
|
|
#include <drm/DrmSupportInfo.h>
|
|
|
|
#include <drm/DrmConvertedStatus.h>
|
|
|
|
#include <IDrmEngine.h>
|
|
|
|
|
|
|
|
#include "DrmManager.h"
|
|
|
|
#include "ReadWriteUtils.h"
|
|
|
|
|
|
|
|
#define DECRYPT_FILE_ERROR -1
|
|
|
|
|
|
|
|
using namespace android;
|
|
|
|
|
|
|
|
const String8 DrmManager::EMPTY_STRING("");
|
|
|
|
|
|
|
|
DrmManager::DrmManager() :
|
|
|
|
mDecryptSessionId(0),
|
|
|
|
mConvertId(0) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
DrmManager::~DrmManager() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-07-21 15:10:22 -07:00
|
|
|
int DrmManager::addUniqueId(bool isNative) {
|
2011-03-04 14:45:03 -08:00
|
|
|
Mutex::Autolock _l(mLock);
|
2011-07-21 15:10:22 -07:00
|
|
|
|
|
|
|
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;
|
2010-09-20 23:40:41 +09:00
|
|
|
}
|
|
|
|
}
|
2011-07-21 15:10:22 -07:00
|
|
|
if (index == size) {
|
|
|
|
foundUniqueId = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
maxLoopTimes --;
|
|
|
|
LOG_FATAL_IF(maxLoopTimes <= 0, "cannot find an unique ID for this session");
|
2010-09-20 23:40:41 +09:00
|
|
|
}
|
2011-07-21 15:10:22 -07:00
|
|
|
|
|
|
|
mUniqueIdVector.push(temp);
|
|
|
|
return temp;
|
2010-09-20 23:40:41 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
void DrmManager::removeUniqueId(int uniqueId) {
|
2011-03-04 14:45:03 -08:00
|
|
|
Mutex::Autolock _l(mLock);
|
2010-09-20 23:40:41 +09:00
|
|
|
for (unsigned int i = 0; i < mUniqueIdVector.size(); i++) {
|
|
|
|
if (uniqueId == mUniqueIdVector.itemAt(i)) {
|
|
|
|
mUniqueIdVector.removeAt(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-08 23:05:49 +09:00
|
|
|
status_t DrmManager::loadPlugIns() {
|
2011-09-21 19:18:30 -07:00
|
|
|
|
|
|
|
String8 vendorPluginDirPath("/vendor/lib/drm");
|
|
|
|
loadPlugIns(vendorPluginDirPath);
|
|
|
|
|
2011-12-14 10:57:05 -08:00
|
|
|
String8 pluginDirPath("/system/lib/drm");
|
|
|
|
loadPlugIns(pluginDirPath);
|
2011-09-21 19:18:30 -07:00
|
|
|
return DRM_NO_ERROR;
|
|
|
|
|
2010-07-29 10:12:27 +09:00
|
|
|
}
|
|
|
|
|
2010-10-08 23:05:49 +09:00
|
|
|
status_t DrmManager::loadPlugIns(const String8& plugInDirPath) {
|
2011-09-21 19:18:30 -07:00
|
|
|
mPlugInManager.loadPlugIns(plugInDirPath);
|
|
|
|
Vector<String8> plugInPathList = mPlugInManager.getPlugInIdList();
|
|
|
|
for (unsigned int i = 0; i < plugInPathList.size(); ++i) {
|
|
|
|
String8 plugInPath = plugInPathList[i];
|
|
|
|
DrmSupportInfo* info = mPlugInManager.getPlugIn(plugInPath).getSupportInfo(0);
|
|
|
|
if (NULL != info) {
|
|
|
|
if (mSupportInfoToPlugInIdMap.indexOfKey(*info) < 0) {
|
2010-10-08 23:05:49 +09:00
|
|
|
mSupportInfoToPlugInIdMap.add(*info, plugInPath);
|
|
|
|
}
|
2011-09-21 19:18:30 -07:00
|
|
|
delete info;
|
2010-10-08 23:05:49 +09:00
|
|
|
}
|
2010-07-29 10:12:27 +09:00
|
|
|
}
|
2010-10-08 23:05:49 +09:00
|
|
|
return DRM_NO_ERROR;
|
|
|
|
}
|
2010-07-29 10:12:27 +09:00
|
|
|
|
2010-10-08 23:05:49 +09:00
|
|
|
status_t DrmManager::unloadPlugIns() {
|
2011-03-04 14:45:03 -08:00
|
|
|
Mutex::Autolock _l(mLock);
|
2010-10-08 23:05:49 +09:00
|
|
|
mConvertSessionMap.clear();
|
|
|
|
mDecryptSessionMap.clear();
|
|
|
|
mPlugInManager.unloadPlugIns();
|
|
|
|
mSupportInfoToPlugInIdMap.clear();
|
2010-07-29 10:12:27 +09:00
|
|
|
return DRM_NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t DrmManager::setDrmServiceListener(
|
|
|
|
int uniqueId, const sp<IDrmServiceListener>& drmServiceListener) {
|
2011-03-11 14:07:21 -08:00
|
|
|
Mutex::Autolock _l(mListenerLock);
|
2010-11-30 16:27:42 +09:00
|
|
|
if (NULL != drmServiceListener.get()) {
|
|
|
|
mServiceListeners.add(uniqueId, drmServiceListener);
|
|
|
|
} else {
|
|
|
|
mServiceListeners.removeItem(uniqueId);
|
|
|
|
}
|
2010-07-29 10:12:27 +09:00
|
|
|
return DRM_NO_ERROR;
|
|
|
|
}
|
|
|
|
|
2010-10-08 23:05:49 +09:00
|
|
|
void DrmManager::addClient(int uniqueId) {
|
2011-03-04 14:45:03 -08:00
|
|
|
Mutex::Autolock _l(mLock);
|
2010-10-08 23:05:49 +09:00
|
|
|
if (!mSupportInfoToPlugInIdMap.isEmpty()) {
|
|
|
|
Vector<String8> plugInIdList = mPlugInManager.getPlugInIdList();
|
|
|
|
for (unsigned int index = 0; index < plugInIdList.size(); index++) {
|
|
|
|
IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInIdList.itemAt(index));
|
|
|
|
rDrmEngine.initialize(uniqueId);
|
|
|
|
rDrmEngine.setOnInfoListener(uniqueId, this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-07-29 10:12:27 +09:00
|
|
|
|
2010-10-08 23:05:49 +09:00
|
|
|
void DrmManager::removeClient(int uniqueId) {
|
2011-03-04 14:45:03 -08:00
|
|
|
Mutex::Autolock _l(mLock);
|
2010-10-08 23:05:49 +09:00
|
|
|
Vector<String8> plugInIdList = mPlugInManager.getPlugInIdList();
|
2010-07-29 10:12:27 +09:00
|
|
|
for (unsigned int index = 0; index < plugInIdList.size(); index++) {
|
|
|
|
IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInIdList.itemAt(index));
|
|
|
|
rDrmEngine.terminate(uniqueId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DrmConstraints* DrmManager::getConstraints(int uniqueId, const String8* path, const int action) {
|
2011-03-04 14:45:03 -08:00
|
|
|
Mutex::Autolock _l(mLock);
|
2010-07-29 10:12:27 +09:00
|
|
|
const String8 plugInId = getSupportedPlugInIdFromPath(uniqueId, *path);
|
|
|
|
if (EMPTY_STRING != plugInId) {
|
|
|
|
IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId);
|
|
|
|
return rDrmEngine.getConstraints(uniqueId, path, action);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-11-16 13:56:11 +09:00
|
|
|
DrmMetadata* DrmManager::getMetadata(int uniqueId, const String8* path) {
|
2011-03-04 14:45:03 -08:00
|
|
|
Mutex::Autolock _l(mLock);
|
2010-11-16 13:56:11 +09:00
|
|
|
const String8 plugInId = getSupportedPlugInIdFromPath(uniqueId, *path);
|
|
|
|
if (EMPTY_STRING != plugInId) {
|
|
|
|
IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId);
|
|
|
|
return rDrmEngine.getMetadata(uniqueId, path);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-07-29 10:12:27 +09:00
|
|
|
status_t DrmManager::installDrmEngine(int uniqueId, const String8& absolutePath) {
|
2011-03-04 14:45:03 -08:00
|
|
|
Mutex::Autolock _l(mLock);
|
2010-07-29 10:12:27 +09:00
|
|
|
mPlugInManager.loadPlugIn(absolutePath);
|
|
|
|
|
|
|
|
IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(absolutePath);
|
|
|
|
rDrmEngine.initialize(uniqueId);
|
|
|
|
rDrmEngine.setOnInfoListener(uniqueId, this);
|
|
|
|
|
2010-10-08 23:05:49 +09:00
|
|
|
DrmSupportInfo* info = rDrmEngine.getSupportInfo(0);
|
2010-07-29 10:12:27 +09:00
|
|
|
mSupportInfoToPlugInIdMap.add(*info, absolutePath);
|
2011-04-24 12:38:35 -07:00
|
|
|
delete info;
|
2010-07-29 10:12:27 +09:00
|
|
|
|
|
|
|
return DRM_NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DrmManager::canHandle(int uniqueId, const String8& path, const String8& mimeType) {
|
2011-03-04 14:45:03 -08:00
|
|
|
Mutex::Autolock _l(mLock);
|
2010-07-29 10:12:27 +09:00
|
|
|
const String8 plugInId = getSupportedPlugInId(mimeType);
|
|
|
|
bool result = (EMPTY_STRING != plugInId) ? true : false;
|
|
|
|
|
2010-10-08 23:05:49 +09:00
|
|
|
if (0 < path.length()) {
|
2010-07-29 10:12:27 +09:00
|
|
|
if (result) {
|
|
|
|
IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId);
|
|
|
|
result = rDrmEngine.canHandle(uniqueId, path);
|
|
|
|
} else {
|
2011-03-02 12:33:00 -08:00
|
|
|
String8 extension = path.getPathExtension();
|
|
|
|
if (String8("") != extension) {
|
|
|
|
result = canHandle(uniqueId, path);
|
|
|
|
}
|
2010-07-29 10:12:27 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
DrmInfoStatus* DrmManager::processDrmInfo(int uniqueId, const DrmInfo* drmInfo) {
|
2011-03-04 14:45:03 -08:00
|
|
|
Mutex::Autolock _l(mLock);
|
2010-07-29 10:12:27 +09:00
|
|
|
const String8 plugInId = getSupportedPlugInId(drmInfo->getMimeType());
|
|
|
|
if (EMPTY_STRING != plugInId) {
|
|
|
|
IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId);
|
|
|
|
return rDrmEngine.processDrmInfo(uniqueId, drmInfo);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DrmManager::canHandle(int uniqueId, const String8& path) {
|
|
|
|
bool result = false;
|
|
|
|
Vector<String8> plugInPathList = mPlugInManager.getPlugInIdList();
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < plugInPathList.size(); ++i) {
|
|
|
|
IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInPathList[i]);
|
|
|
|
result = rDrmEngine.canHandle(uniqueId, path);
|
|
|
|
|
|
|
|
if (result) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
DrmInfo* DrmManager::acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest) {
|
2011-03-04 14:45:03 -08:00
|
|
|
Mutex::Autolock _l(mLock);
|
2010-07-29 10:12:27 +09:00
|
|
|
const String8 plugInId = getSupportedPlugInId(drmInfoRequest->getMimeType());
|
|
|
|
if (EMPTY_STRING != plugInId) {
|
|
|
|
IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId);
|
|
|
|
return rDrmEngine.acquireDrmInfo(uniqueId, drmInfoRequest);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-09-20 23:40:41 +09:00
|
|
|
status_t DrmManager::saveRights(int uniqueId, const DrmRights& drmRights,
|
2010-07-29 10:12:27 +09:00
|
|
|
const String8& rightsPath, const String8& contentPath) {
|
2011-03-04 14:45:03 -08:00
|
|
|
Mutex::Autolock _l(mLock);
|
2010-07-29 10:12:27 +09:00
|
|
|
const String8 plugInId = getSupportedPlugInId(drmRights.getMimeType());
|
2010-09-20 23:40:41 +09:00
|
|
|
status_t result = DRM_ERROR_UNKNOWN;
|
2010-07-29 10:12:27 +09:00
|
|
|
if (EMPTY_STRING != plugInId) {
|
|
|
|
IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId);
|
2010-09-20 23:40:41 +09:00
|
|
|
result = rDrmEngine.saveRights(uniqueId, drmRights, rightsPath, contentPath);
|
2010-07-29 10:12:27 +09:00
|
|
|
}
|
2010-09-20 23:40:41 +09:00
|
|
|
return result;
|
2010-07-29 10:12:27 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
String8 DrmManager::getOriginalMimeType(int uniqueId, const String8& path) {
|
2011-03-04 14:45:03 -08:00
|
|
|
Mutex::Autolock _l(mLock);
|
2010-07-29 10:12:27 +09:00
|
|
|
const String8 plugInId = getSupportedPlugInIdFromPath(uniqueId, path);
|
|
|
|
if (EMPTY_STRING != plugInId) {
|
|
|
|
IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId);
|
|
|
|
return rDrmEngine.getOriginalMimeType(uniqueId, path);
|
|
|
|
}
|
|
|
|
return EMPTY_STRING;
|
|
|
|
}
|
|
|
|
|
|
|
|
int DrmManager::getDrmObjectType(int uniqueId, const String8& path, const String8& mimeType) {
|
2011-03-04 14:45:03 -08:00
|
|
|
Mutex::Autolock _l(mLock);
|
2010-07-29 10:12:27 +09:00
|
|
|
const String8 plugInId = getSupportedPlugInId(uniqueId, path, mimeType);
|
|
|
|
if (EMPTY_STRING != plugInId) {
|
|
|
|
IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId);
|
|
|
|
return rDrmEngine.getDrmObjectType(uniqueId, path, mimeType);
|
|
|
|
}
|
|
|
|
return DrmObjectType::UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
int DrmManager::checkRightsStatus(int uniqueId, const String8& path, int action) {
|
2011-03-04 14:45:03 -08:00
|
|
|
Mutex::Autolock _l(mLock);
|
2010-07-29 10:12:27 +09:00
|
|
|
const String8 plugInId = getSupportedPlugInIdFromPath(uniqueId, path);
|
|
|
|
if (EMPTY_STRING != plugInId) {
|
|
|
|
IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId);
|
|
|
|
return rDrmEngine.checkRightsStatus(uniqueId, path, action);
|
|
|
|
}
|
|
|
|
return RightsStatus::RIGHTS_INVALID;
|
|
|
|
}
|
|
|
|
|
2010-09-20 23:40:41 +09:00
|
|
|
status_t DrmManager::consumeRights(
|
2010-07-29 10:12:27 +09:00
|
|
|
int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) {
|
2010-09-20 23:40:41 +09:00
|
|
|
status_t result = DRM_ERROR_UNKNOWN;
|
2011-03-04 14:45:03 -08:00
|
|
|
Mutex::Autolock _l(mDecryptLock);
|
2010-07-29 10:12:27 +09:00
|
|
|
if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) {
|
|
|
|
IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId);
|
2010-09-20 23:40:41 +09:00
|
|
|
result = drmEngine->consumeRights(uniqueId, decryptHandle, action, reserve);
|
2010-07-29 10:12:27 +09:00
|
|
|
}
|
2010-09-20 23:40:41 +09:00
|
|
|
return result;
|
2010-07-29 10:12:27 +09:00
|
|
|
}
|
|
|
|
|
2010-09-20 23:40:41 +09:00
|
|
|
status_t DrmManager::setPlaybackStatus(
|
2010-11-19 15:19:36 -08:00
|
|
|
int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int64_t position) {
|
2010-09-20 23:40:41 +09:00
|
|
|
status_t result = DRM_ERROR_UNKNOWN;
|
2011-03-04 14:45:03 -08:00
|
|
|
Mutex::Autolock _l(mDecryptLock);
|
2010-07-29 10:12:27 +09:00
|
|
|
if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) {
|
|
|
|
IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId);
|
2010-09-20 23:40:41 +09:00
|
|
|
result = drmEngine->setPlaybackStatus(uniqueId, decryptHandle, playbackStatus, position);
|
2010-07-29 10:12:27 +09:00
|
|
|
}
|
2010-09-20 23:40:41 +09:00
|
|
|
return result;
|
2010-07-29 10:12:27 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
bool DrmManager::validateAction(
|
|
|
|
int uniqueId, const String8& path, int action, const ActionDescription& description) {
|
2011-03-04 14:45:03 -08:00
|
|
|
Mutex::Autolock _l(mLock);
|
2010-07-29 10:12:27 +09:00
|
|
|
const String8 plugInId = getSupportedPlugInIdFromPath(uniqueId, path);
|
|
|
|
if (EMPTY_STRING != plugInId) {
|
|
|
|
IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId);
|
|
|
|
return rDrmEngine.validateAction(uniqueId, path, action, description);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-09-20 23:40:41 +09:00
|
|
|
status_t DrmManager::removeRights(int uniqueId, const String8& path) {
|
2011-03-04 14:45:03 -08:00
|
|
|
Mutex::Autolock _l(mLock);
|
2010-07-29 10:12:27 +09:00
|
|
|
const String8 plugInId = getSupportedPlugInIdFromPath(uniqueId, path);
|
2010-09-20 23:40:41 +09:00
|
|
|
status_t result = DRM_ERROR_UNKNOWN;
|
2010-07-29 10:12:27 +09:00
|
|
|
if (EMPTY_STRING != plugInId) {
|
|
|
|
IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId);
|
2010-09-20 23:40:41 +09:00
|
|
|
result = rDrmEngine.removeRights(uniqueId, path);
|
2010-07-29 10:12:27 +09:00
|
|
|
}
|
2010-09-20 23:40:41 +09:00
|
|
|
return result;
|
2010-07-29 10:12:27 +09:00
|
|
|
}
|
|
|
|
|
2010-09-20 23:40:41 +09:00
|
|
|
status_t DrmManager::removeAllRights(int uniqueId) {
|
2010-07-29 10:12:27 +09:00
|
|
|
Vector<String8> plugInIdList = mPlugInManager.getPlugInIdList();
|
2010-09-20 23:40:41 +09:00
|
|
|
status_t result = DRM_ERROR_UNKNOWN;
|
2010-07-29 10:12:27 +09:00
|
|
|
for (unsigned int index = 0; index < plugInIdList.size(); index++) {
|
|
|
|
IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInIdList.itemAt(index));
|
2010-09-20 23:40:41 +09:00
|
|
|
result = rDrmEngine.removeAllRights(uniqueId);
|
|
|
|
if (DRM_NO_ERROR != result) {
|
|
|
|
break;
|
|
|
|
}
|
2010-07-29 10:12:27 +09:00
|
|
|
}
|
2010-09-20 23:40:41 +09:00
|
|
|
return result;
|
2010-07-29 10:12:27 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
int DrmManager::openConvertSession(int uniqueId, const String8& mimeType) {
|
2011-03-04 14:45:03 -08:00
|
|
|
Mutex::Autolock _l(mConvertLock);
|
2010-07-29 10:12:27 +09:00
|
|
|
int convertId = -1;
|
|
|
|
|
|
|
|
const String8 plugInId = getSupportedPlugInId(mimeType);
|
|
|
|
if (EMPTY_STRING != plugInId) {
|
|
|
|
IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId);
|
|
|
|
|
2010-09-20 23:40:41 +09:00
|
|
|
if (DRM_NO_ERROR == rDrmEngine.openConvertSession(uniqueId, mConvertId + 1)) {
|
|
|
|
++mConvertId;
|
|
|
|
convertId = mConvertId;
|
|
|
|
mConvertSessionMap.add(convertId, &rDrmEngine);
|
|
|
|
}
|
2010-07-29 10:12:27 +09:00
|
|
|
}
|
|
|
|
return convertId;
|
|
|
|
}
|
|
|
|
|
|
|
|
DrmConvertedStatus* DrmManager::convertData(
|
|
|
|
int uniqueId, int convertId, const DrmBuffer* inputData) {
|
|
|
|
DrmConvertedStatus *drmConvertedStatus = NULL;
|
|
|
|
|
2011-03-04 14:45:03 -08:00
|
|
|
Mutex::Autolock _l(mConvertLock);
|
2010-07-29 10:12:27 +09:00
|
|
|
if (mConvertSessionMap.indexOfKey(convertId) != NAME_NOT_FOUND) {
|
|
|
|
IDrmEngine* drmEngine = mConvertSessionMap.valueFor(convertId);
|
|
|
|
drmConvertedStatus = drmEngine->convertData(uniqueId, convertId, inputData);
|
|
|
|
}
|
|
|
|
return drmConvertedStatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
DrmConvertedStatus* DrmManager::closeConvertSession(int uniqueId, int convertId) {
|
2011-03-04 14:45:03 -08:00
|
|
|
Mutex::Autolock _l(mConvertLock);
|
2010-07-29 10:12:27 +09:00
|
|
|
DrmConvertedStatus *drmConvertedStatus = NULL;
|
|
|
|
|
|
|
|
if (mConvertSessionMap.indexOfKey(convertId) != NAME_NOT_FOUND) {
|
|
|
|
IDrmEngine* drmEngine = mConvertSessionMap.valueFor(convertId);
|
|
|
|
drmConvertedStatus = drmEngine->closeConvertSession(uniqueId, convertId);
|
|
|
|
mConvertSessionMap.removeItem(convertId);
|
|
|
|
}
|
|
|
|
return drmConvertedStatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t DrmManager::getAllSupportInfo(
|
|
|
|
int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray) {
|
2011-03-04 14:45:03 -08:00
|
|
|
Mutex::Autolock _l(mLock);
|
2010-07-29 10:12:27 +09:00
|
|
|
Vector<String8> plugInPathList = mPlugInManager.getPlugInIdList();
|
|
|
|
int size = plugInPathList.size();
|
|
|
|
int validPlugins = 0;
|
|
|
|
|
|
|
|
if (0 < size) {
|
|
|
|
Vector<DrmSupportInfo> drmSupportInfoList;
|
|
|
|
|
|
|
|
for (int i = 0; i < size; ++i) {
|
|
|
|
String8 plugInPath = plugInPathList[i];
|
|
|
|
DrmSupportInfo* drmSupportInfo
|
2010-10-08 23:05:49 +09:00
|
|
|
= mPlugInManager.getPlugIn(plugInPath).getSupportInfo(0);
|
2010-07-29 10:12:27 +09:00
|
|
|
if (NULL != drmSupportInfo) {
|
|
|
|
drmSupportInfoList.add(*drmSupportInfo);
|
|
|
|
delete drmSupportInfo; drmSupportInfo = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
validPlugins = drmSupportInfoList.size();
|
|
|
|
if (0 < validPlugins) {
|
|
|
|
*drmSupportInfoArray = new DrmSupportInfo[validPlugins];
|
|
|
|
for (int i = 0; i < validPlugins; ++i) {
|
|
|
|
(*drmSupportInfoArray)[i] = drmSupportInfoList[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*length = validPlugins;
|
|
|
|
return DRM_NO_ERROR;
|
|
|
|
}
|
|
|
|
|
2012-01-10 08:24:37 -08:00
|
|
|
DecryptHandle* DrmManager::openDecryptSession(
|
|
|
|
int uniqueId, int fd, off64_t offset, off64_t length, const char* mime) {
|
|
|
|
|
2010-10-08 23:05:49 +09:00
|
|
|
Mutex::Autolock _l(mDecryptLock);
|
2010-07-29 10:12:27 +09:00
|
|
|
status_t result = DRM_ERROR_CANNOT_HANDLE;
|
|
|
|
Vector<String8> plugInIdList = mPlugInManager.getPlugInIdList();
|
|
|
|
|
|
|
|
DecryptHandle* handle = new DecryptHandle();
|
|
|
|
if (NULL != handle) {
|
|
|
|
handle->decryptId = mDecryptSessionId + 1;
|
|
|
|
|
|
|
|
for (unsigned int index = 0; index < plugInIdList.size(); index++) {
|
|
|
|
String8 plugInId = plugInIdList.itemAt(index);
|
|
|
|
IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId);
|
2012-01-10 08:24:37 -08:00
|
|
|
result = rDrmEngine.openDecryptSession(uniqueId, handle, fd, offset, length, mime);
|
2010-07-29 10:12:27 +09:00
|
|
|
|
|
|
|
if (DRM_NO_ERROR == result) {
|
|
|
|
++mDecryptSessionId;
|
|
|
|
mDecryptSessionMap.add(mDecryptSessionId, &rDrmEngine);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-09-20 23:40:41 +09:00
|
|
|
if (DRM_NO_ERROR != result) {
|
2010-07-29 10:12:27 +09:00
|
|
|
delete handle; handle = NULL;
|
|
|
|
}
|
2010-10-08 23:05:49 +09:00
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
2012-01-10 08:24:37 -08:00
|
|
|
DecryptHandle* DrmManager::openDecryptSession(
|
|
|
|
int uniqueId, const char* uri, const char* mime) {
|
2010-10-08 23:05:49 +09:00
|
|
|
Mutex::Autolock _l(mDecryptLock);
|
|
|
|
status_t result = DRM_ERROR_CANNOT_HANDLE;
|
|
|
|
Vector<String8> plugInIdList = mPlugInManager.getPlugInIdList();
|
2010-07-29 10:12:27 +09:00
|
|
|
|
2010-10-08 23:05:49 +09:00
|
|
|
DecryptHandle* handle = new DecryptHandle();
|
|
|
|
if (NULL != handle) {
|
|
|
|
handle->decryptId = mDecryptSessionId + 1;
|
|
|
|
|
|
|
|
for (unsigned int index = 0; index < plugInIdList.size(); index++) {
|
|
|
|
String8 plugInId = plugInIdList.itemAt(index);
|
|
|
|
IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId);
|
2012-01-10 08:24:37 -08:00
|
|
|
result = rDrmEngine.openDecryptSession(uniqueId, handle, uri, mime);
|
2010-07-29 10:12:27 +09:00
|
|
|
|
2010-10-08 23:05:49 +09:00
|
|
|
if (DRM_NO_ERROR == result) {
|
|
|
|
++mDecryptSessionId;
|
|
|
|
mDecryptSessionMap.add(mDecryptSessionId, &rDrmEngine);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (DRM_NO_ERROR != result) {
|
|
|
|
delete handle; handle = NULL;
|
2011-10-20 11:56:00 +01:00
|
|
|
ALOGV("DrmManager::openDecryptSession: no capable plug-in found");
|
2010-10-08 23:05:49 +09:00
|
|
|
}
|
2010-07-29 10:12:27 +09:00
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
2010-09-20 23:40:41 +09:00
|
|
|
status_t DrmManager::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) {
|
2010-10-08 23:05:49 +09:00
|
|
|
Mutex::Autolock _l(mDecryptLock);
|
2010-09-20 23:40:41 +09:00
|
|
|
status_t result = DRM_ERROR_UNKNOWN;
|
2010-07-29 10:12:27 +09:00
|
|
|
if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) {
|
|
|
|
IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId);
|
2010-09-20 23:40:41 +09:00
|
|
|
result = drmEngine->closeDecryptSession(uniqueId, decryptHandle);
|
|
|
|
if (DRM_NO_ERROR == result) {
|
|
|
|
mDecryptSessionMap.removeItem(decryptHandle->decryptId);
|
|
|
|
}
|
2010-07-29 10:12:27 +09:00
|
|
|
}
|
2010-09-20 23:40:41 +09:00
|
|
|
return result;
|
2010-07-29 10:12:27 +09:00
|
|
|
}
|
|
|
|
|
2010-09-20 23:40:41 +09:00
|
|
|
status_t DrmManager::initializeDecryptUnit(
|
2010-07-29 10:12:27 +09:00
|
|
|
int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo) {
|
2010-09-20 23:40:41 +09:00
|
|
|
status_t result = DRM_ERROR_UNKNOWN;
|
2011-03-04 14:45:03 -08:00
|
|
|
Mutex::Autolock _l(mDecryptLock);
|
2010-07-29 10:12:27 +09:00
|
|
|
if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) {
|
|
|
|
IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId);
|
2010-09-20 23:40:41 +09:00
|
|
|
result = drmEngine->initializeDecryptUnit(uniqueId, decryptHandle, decryptUnitId, headerInfo);
|
2010-07-29 10:12:27 +09:00
|
|
|
}
|
2010-09-20 23:40:41 +09:00
|
|
|
return result;
|
2010-07-29 10:12:27 +09:00
|
|
|
}
|
|
|
|
|
2010-09-20 23:40:41 +09:00
|
|
|
status_t DrmManager::decrypt(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId,
|
|
|
|
const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) {
|
|
|
|
status_t result = DRM_ERROR_UNKNOWN;
|
2011-03-04 14:45:03 -08:00
|
|
|
|
|
|
|
Mutex::Autolock _l(mDecryptLock);
|
2010-07-29 10:12:27 +09:00
|
|
|
if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) {
|
|
|
|
IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId);
|
2010-09-20 23:40:41 +09:00
|
|
|
result = drmEngine->decrypt(
|
|
|
|
uniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer, IV);
|
2010-07-29 10:12:27 +09:00
|
|
|
}
|
2010-09-20 23:40:41 +09:00
|
|
|
return result;
|
2010-07-29 10:12:27 +09:00
|
|
|
}
|
|
|
|
|
2010-09-20 23:40:41 +09:00
|
|
|
status_t DrmManager::finalizeDecryptUnit(
|
2010-07-29 10:12:27 +09:00
|
|
|
int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) {
|
2010-09-20 23:40:41 +09:00
|
|
|
status_t result = DRM_ERROR_UNKNOWN;
|
2011-03-04 14:45:03 -08:00
|
|
|
Mutex::Autolock _l(mDecryptLock);
|
2010-07-29 10:12:27 +09:00
|
|
|
if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) {
|
|
|
|
IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId);
|
2010-09-20 23:40:41 +09:00
|
|
|
result = drmEngine->finalizeDecryptUnit(uniqueId, decryptHandle, decryptUnitId);
|
2010-07-29 10:12:27 +09:00
|
|
|
}
|
2010-09-20 23:40:41 +09:00
|
|
|
return result;
|
2010-07-29 10:12:27 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t DrmManager::pread(int uniqueId, DecryptHandle* decryptHandle,
|
2010-11-19 15:19:36 -08:00
|
|
|
void* buffer, ssize_t numBytes, off64_t offset) {
|
2010-07-29 10:12:27 +09:00
|
|
|
ssize_t result = DECRYPT_FILE_ERROR;
|
|
|
|
|
2011-03-04 14:45:03 -08:00
|
|
|
Mutex::Autolock _l(mDecryptLock);
|
2010-07-29 10:12:27 +09:00
|
|
|
if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) {
|
|
|
|
IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId);
|
|
|
|
result = drmEngine->pread(uniqueId, decryptHandle, buffer, numBytes, offset);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
String8 DrmManager::getSupportedPlugInId(
|
|
|
|
int uniqueId, const String8& path, const String8& mimeType) {
|
|
|
|
String8 plugInId("");
|
|
|
|
|
|
|
|
if (EMPTY_STRING != mimeType) {
|
|
|
|
plugInId = getSupportedPlugInId(mimeType);
|
|
|
|
} else {
|
|
|
|
plugInId = getSupportedPlugInIdFromPath(uniqueId, path);
|
|
|
|
}
|
|
|
|
return plugInId;
|
|
|
|
}
|
|
|
|
|
|
|
|
String8 DrmManager::getSupportedPlugInId(const String8& mimeType) {
|
|
|
|
String8 plugInId("");
|
|
|
|
|
|
|
|
if (EMPTY_STRING != mimeType) {
|
|
|
|
for (unsigned int index = 0; index < mSupportInfoToPlugInIdMap.size(); index++) {
|
|
|
|
const DrmSupportInfo& drmSupportInfo = mSupportInfoToPlugInIdMap.keyAt(index);
|
|
|
|
|
|
|
|
if (drmSupportInfo.isSupportedMimeType(mimeType)) {
|
|
|
|
plugInId = mSupportInfoToPlugInIdMap.valueFor(drmSupportInfo);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return plugInId;
|
|
|
|
}
|
|
|
|
|
|
|
|
String8 DrmManager::getSupportedPlugInIdFromPath(int uniqueId, const String8& path) {
|
|
|
|
String8 plugInId("");
|
|
|
|
const String8 fileSuffix = path.getPathExtension();
|
|
|
|
|
|
|
|
for (unsigned int index = 0; index < mSupportInfoToPlugInIdMap.size(); index++) {
|
|
|
|
const DrmSupportInfo& drmSupportInfo = mSupportInfoToPlugInIdMap.keyAt(index);
|
|
|
|
|
|
|
|
if (drmSupportInfo.isSupportedFileSuffix(fileSuffix)) {
|
|
|
|
String8 key = mSupportInfoToPlugInIdMap.valueFor(drmSupportInfo);
|
|
|
|
IDrmEngine& drmEngine = mPlugInManager.getPlugIn(key);
|
|
|
|
|
|
|
|
if (drmEngine.canHandle(uniqueId, path)) {
|
|
|
|
plugInId = key;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return plugInId;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DrmManager::onInfo(const DrmInfoEvent& event) {
|
2011-03-11 14:07:21 -08:00
|
|
|
Mutex::Autolock _l(mListenerLock);
|
2010-07-29 10:12:27 +09:00
|
|
|
for (unsigned int index = 0; index < mServiceListeners.size(); index++) {
|
|
|
|
int uniqueId = mServiceListeners.keyAt(index);
|
|
|
|
|
|
|
|
if (uniqueId == event.getUniqueId()) {
|
|
|
|
sp<IDrmServiceListener> serviceListener = mServiceListeners.valueFor(uniqueId);
|
|
|
|
serviceListener->notify(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|