From 27ed8ad2db653f6ac07dcf8bcc05e2409c8bb024 Mon Sep 17 00:00:00 2001 From: aimitakeshi Date: Thu, 29 Jul 2010 10:12:27 +0900 Subject: Initial contribution from Sony Corporation. Add DRM Framework to support DRM content playback together with StageFright. - DRM Framework code is added - include/drm - drm - api/current.xml is updated to include DRM Framework Java APIs - cmds/servicemanager/service_manager.c is modified to add drmManager and drmIOService. Change-Id: I6d7bc9c7067362b500e530988a9ce241761866fb --- drm/drmserver/Android.mk | 39 +++ drm/drmserver/DrmManager.cpp | 473 ++++++++++++++++++++++++++++++++++++ drm/drmserver/DrmManagerService.cpp | 218 +++++++++++++++++ drm/drmserver/StringTokenizer.cpp | 68 ++++++ drm/drmserver/main_drmserver.cpp | 40 +++ 5 files changed, 838 insertions(+) create mode 100644 drm/drmserver/Android.mk create mode 100644 drm/drmserver/DrmManager.cpp create mode 100644 drm/drmserver/DrmManagerService.cpp create mode 100644 drm/drmserver/StringTokenizer.cpp create mode 100644 drm/drmserver/main_drmserver.cpp (limited to 'drm/drmserver') diff --git a/drm/drmserver/Android.mk b/drm/drmserver/Android.mk new file mode 100644 index 0000000..d2ebe8e --- /dev/null +++ b/drm/drmserver/Android.mk @@ -0,0 +1,39 @@ +# +# 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. +# +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_SRC_FILES:= \ + main_drmserver.cpp \ + DrmManager.cpp \ + DrmManagerService.cpp \ + StringTokenizer.cpp + +LOCAL_SHARED_LIBRARIES := \ + libutils \ + libbinder \ + libdl + +LOCAL_STATIC_LIBRARIES := libdrmframeworkcommon + +LOCAL_C_INCLUDES := \ + $(TOP)/frameworks/base/include \ + $(TOP)/frameworks/base/drm/libdrmframework/include \ + $(TOP)/frameworks/base/drm/libdrmframework/plugins/common/include + +LOCAL_MODULE:= drmserver + +include $(BUILD_EXECUTABLE) diff --git a/drm/drmserver/DrmManager.cpp b/drm/drmserver/DrmManager.cpp new file mode 100644 index 0000000..44886f9 --- /dev/null +++ b/drm/drmserver/DrmManager.cpp @@ -0,0 +1,473 @@ +/* + * 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. + */ + +#define LOG_NDEBUG 0 +#define LOG_TAG "DrmManager(Native)" +#include "utils/Log.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#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() { + +} + +status_t DrmManager::loadPlugIns(int uniqueId) { + String8 pluginDirPath("/system/lib/drm/plugins/native"); + return loadPlugIns(uniqueId, pluginDirPath); +} + +status_t DrmManager::loadPlugIns(int uniqueId, const String8& plugInDirPath) { + if (mSupportInfoToPlugInIdMap.isEmpty()) { + mPlugInManager.loadPlugIns(plugInDirPath); + + initializePlugIns(uniqueId); + + populate(uniqueId); + } else { + initializePlugIns(uniqueId); + } + + return DRM_NO_ERROR; +} + +status_t DrmManager::setDrmServiceListener( + int uniqueId, const sp& drmServiceListener) { + Mutex::Autolock _l(mLock); + mServiceListeners.add(uniqueId, drmServiceListener); + return DRM_NO_ERROR; +} + +status_t DrmManager::unloadPlugIns(int uniqueId) { + Vector plugInIdList = mPlugInManager.getPlugInIdList(); + + for (unsigned int index = 0; index < plugInIdList.size(); index++) { + IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInIdList.itemAt(index)); + rDrmEngine.terminate(uniqueId); + } + + mConvertSessionMap.clear(); + mDecryptSessionMap.clear(); + mSupportInfoToPlugInIdMap.clear(); + mPlugInManager.unloadPlugIns(); + return DRM_NO_ERROR; +} + +DrmConstraints* DrmManager::getConstraints(int uniqueId, const String8* path, const int action) { + const String8 plugInId = getSupportedPlugInIdFromPath(uniqueId, *path); + if (EMPTY_STRING != plugInId) { + IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); + return rDrmEngine.getConstraints(uniqueId, path, action); + } + return NULL; +} + +status_t DrmManager::installDrmEngine(int uniqueId, const String8& absolutePath) { + mPlugInManager.loadPlugIn(absolutePath); + + IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(absolutePath); + rDrmEngine.initialize(uniqueId); + rDrmEngine.setOnInfoListener(uniqueId, this); + + DrmSupportInfo* info = rDrmEngine.getSupportInfo(uniqueId); + mSupportInfoToPlugInIdMap.add(*info, absolutePath); + + return DRM_NO_ERROR; +} + +bool DrmManager::canHandle(int uniqueId, const String8& path, const String8& mimeType) { + const String8 plugInId = getSupportedPlugInId(mimeType); + bool result = (EMPTY_STRING != plugInId) ? true : false; + + if (NULL != path) { + if (result) { + IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); + result = rDrmEngine.canHandle(uniqueId, path); + } else { + result = canHandle(uniqueId, path); + } + } + return result; +} + +DrmInfoStatus* DrmManager::processDrmInfo(int uniqueId, const DrmInfo* drmInfo) { + 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 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) { + const String8 plugInId = getSupportedPlugInId(drmInfoRequest->getMimeType()); + if (EMPTY_STRING != plugInId) { + IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); + return rDrmEngine.acquireDrmInfo(uniqueId, drmInfoRequest); + } + return NULL; +} + +void DrmManager::saveRights(int uniqueId, const DrmRights& drmRights, + const String8& rightsPath, const String8& contentPath) { + const String8 plugInId = getSupportedPlugInId(drmRights.getMimeType()); + if (EMPTY_STRING != plugInId) { + IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); + rDrmEngine.saveRights(uniqueId, drmRights, rightsPath, contentPath); + } +} + +String8 DrmManager::getOriginalMimeType(int uniqueId, const String8& path) { + 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) { + 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) { + 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; +} + +void DrmManager::consumeRights( + int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) { + if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) { + IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId); + drmEngine->consumeRights(uniqueId, decryptHandle, action, reserve); + } +} + +void DrmManager::setPlaybackStatus( + int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position) { + + if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) { + IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId); + drmEngine->setPlaybackStatus(uniqueId, decryptHandle, playbackStatus, position); + } +} + +bool DrmManager::validateAction( + int uniqueId, const String8& path, int action, const ActionDescription& description) { + const String8 plugInId = getSupportedPlugInIdFromPath(uniqueId, path); + if (EMPTY_STRING != plugInId) { + IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); + return rDrmEngine.validateAction(uniqueId, path, action, description); + } + return false; +} + +void DrmManager::removeRights(int uniqueId, const String8& path) { + const String8 plugInId = getSupportedPlugInIdFromPath(uniqueId, path); + if (EMPTY_STRING != plugInId) { + IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); + rDrmEngine.removeRights(uniqueId, path); + } +} + +void DrmManager::removeAllRights(int uniqueId) { + Vector plugInIdList = mPlugInManager.getPlugInIdList(); + + for (unsigned int index = 0; index < plugInIdList.size(); index++) { + IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInIdList.itemAt(index)); + rDrmEngine.removeAllRights(uniqueId); + } +} + +int DrmManager::openConvertSession(int uniqueId, const String8& mimeType) { + int convertId = -1; + + const String8 plugInId = getSupportedPlugInId(mimeType); + if (EMPTY_STRING != plugInId) { + IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); + + Mutex::Autolock _l(mConvertLock); + ++mConvertId; + convertId = mConvertId; + mConvertSessionMap.add(mConvertId, &rDrmEngine); + + rDrmEngine.openConvertSession(uniqueId, mConvertId); + } + return convertId; +} + +DrmConvertedStatus* DrmManager::convertData( + int uniqueId, int convertId, const DrmBuffer* inputData) { + DrmConvertedStatus *drmConvertedStatus = NULL; + + 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) { + 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) { + Vector plugInPathList = mPlugInManager.getPlugInIdList(); + int size = plugInPathList.size(); + int validPlugins = 0; + + if (0 < size) { + Vector drmSupportInfoList; + + for (int i = 0; i < size; ++i) { + String8 plugInPath = plugInPathList[i]; + DrmSupportInfo* drmSupportInfo + = mPlugInManager.getPlugIn(plugInPath).getSupportInfo(uniqueId); + 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; +} + +DecryptHandle* DrmManager::openDecryptSession(int uniqueId, int fd, int offset, int length) { + LOGV("Entering DrmManager::openDecryptSession"); + status_t result = DRM_ERROR_CANNOT_HANDLE; + Vector plugInIdList = mPlugInManager.getPlugInIdList(); + + DecryptHandle* handle = new DecryptHandle(); + if (NULL != handle) { + Mutex::Autolock _l(mDecryptLock); + handle->decryptId = mDecryptSessionId + 1; + + for (unsigned int index = 0; index < plugInIdList.size(); index++) { + String8 plugInId = plugInIdList.itemAt(index); + IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); + result = rDrmEngine.openDecryptSession(uniqueId, handle, fd, offset, length); + + LOGV("plug-in %s return value = %d", plugInId.string(), result); + + if (DRM_NO_ERROR == result) { + ++mDecryptSessionId; + mDecryptSessionMap.add(mDecryptSessionId, &rDrmEngine); + LOGV("plug-in %s is selected", plugInId.string()); + break; + } + } + } + + if (DRM_ERROR_CANNOT_HANDLE == result) { + delete handle; handle = NULL; + LOGE("DrmManager::openDecryptSession: no capable plug-in found"); + } + + return handle; +} + +void DrmManager::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) { + if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) { + IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId); + drmEngine->closeDecryptSession(uniqueId, decryptHandle); + + mDecryptSessionMap.removeItem(decryptHandle->decryptId); + } +} + +void DrmManager::initializeDecryptUnit( + int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo) { + if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) { + IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId); + drmEngine->initializeDecryptUnit(uniqueId, decryptHandle, decryptUnitId, headerInfo); + } +} + +status_t DrmManager::decrypt(int uniqueId, DecryptHandle* decryptHandle, + int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer) { + status_t status = DRM_ERROR_UNKNOWN; + if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) { + IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId); + status = drmEngine->decrypt(uniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer); + } + return status; +} + +void DrmManager::finalizeDecryptUnit( + int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) { + if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) { + IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId); + drmEngine->finalizeDecryptUnit(uniqueId, decryptHandle, decryptUnitId); + } +} + +ssize_t DrmManager::pread(int uniqueId, DecryptHandle* decryptHandle, + void* buffer, ssize_t numBytes, off_t offset) { + ssize_t result = DECRYPT_FILE_ERROR; + + if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) { + IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId); + result = drmEngine->pread(uniqueId, decryptHandle, buffer, numBytes, offset); + } + return result; +} + +void DrmManager::initializePlugIns(int uniqueId) { + Vector 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); + } +} + +void DrmManager::populate(int uniqueId) { + Vector plugInPathList = mPlugInManager.getPlugInIdList(); + + for (unsigned int i = 0; i < plugInPathList.size(); ++i) { + String8 plugInPath = plugInPathList[i]; + DrmSupportInfo* info = mPlugInManager.getPlugIn(plugInPath).getSupportInfo(uniqueId); + if (NULL != info) { + mSupportInfoToPlugInIdMap.add(*info, plugInPath); + } + } +} + +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) { + Mutex::Autolock _l(mLock); + for (unsigned int index = 0; index < mServiceListeners.size(); index++) { + int uniqueId = mServiceListeners.keyAt(index); + + if (uniqueId == event.getUniqueId()) { + sp serviceListener = mServiceListeners.valueFor(uniqueId); + serviceListener->notify(event); + } + } +} + diff --git a/drm/drmserver/DrmManagerService.cpp b/drm/drmserver/DrmManagerService.cpp new file mode 100644 index 0000000..9d000e9 --- /dev/null +++ b/drm/drmserver/DrmManagerService.cpp @@ -0,0 +1,218 @@ +/* + * 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. + */ + +#define LOG_NDEBUG 0 +#define LOG_TAG "DrmManagerService(Native)" +#include + +#include +#include +#include +#include +#include "DrmManagerService.h" +#include "DrmManager.h" + +using namespace android; + +#define SUCCESS 0 +#define DRM_DIRECTORY_PERMISSION 0700 + +void DrmManagerService::instantiate() { + LOGV("instantiate"); + + int res = mkdir("/data/drm/plugins", DRM_DIRECTORY_PERMISSION); + if (SUCCESS == res || EEXIST == errno) { + res = mkdir("/data/drm/plugins/native", DRM_DIRECTORY_PERMISSION); + if (SUCCESS == res || EEXIST == errno) { + res = mkdir("/data/drm/plugins/native/databases", DRM_DIRECTORY_PERMISSION); + if (SUCCESS == res || EEXIST == errno) { + defaultServiceManager() + ->addService(String16("drm.drmManager"), new DrmManagerService()); + } + } + } +} + +DrmManagerService::DrmManagerService() { + LOGV("created"); + mDrmManager = NULL; + mDrmManager = new DrmManager(); +} + +DrmManagerService::~DrmManagerService() { + LOGV("Destroyed"); + delete mDrmManager; mDrmManager = NULL; +} + +status_t DrmManagerService::loadPlugIns(int uniqueId) { + LOGV("Entering load plugins"); + return mDrmManager->loadPlugIns(uniqueId); +} + +status_t DrmManagerService::loadPlugIns(int uniqueId, const String8& plugInDirPath) { + LOGV("Entering load plugins from path"); + return mDrmManager->loadPlugIns(uniqueId, plugInDirPath); +} + +status_t DrmManagerService::setDrmServiceListener( + int uniqueId, const sp& drmServiceListener) { + LOGV("Entering setDrmServiceListener"); + mDrmManager->setDrmServiceListener(uniqueId, drmServiceListener); + return DRM_NO_ERROR; +} + +status_t DrmManagerService::unloadPlugIns(int uniqueId) { + LOGV("Entering unload plugins"); + return mDrmManager->unloadPlugIns(uniqueId); +} + +status_t DrmManagerService::installDrmEngine(int uniqueId, const String8& drmEngineFile) { + LOGV("Entering installDrmEngine"); + return mDrmManager->installDrmEngine(uniqueId, drmEngineFile); +} + +DrmConstraints* DrmManagerService::getConstraints( + int uniqueId, const String8* path, const int action) { + LOGV("Entering getConstraints from content"); + return mDrmManager->getConstraints(uniqueId, path, action); +} + +bool DrmManagerService::canHandle(int uniqueId, const String8& path, const String8& mimeType) { + LOGV("Entering canHandle"); + return mDrmManager->canHandle(uniqueId, path, mimeType); +} + +DrmInfoStatus* DrmManagerService::processDrmInfo(int uniqueId, const DrmInfo* drmInfo) { + LOGV("Entering processDrmInfo"); + return mDrmManager->processDrmInfo(uniqueId, drmInfo); +} + +DrmInfo* DrmManagerService::acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest) { + LOGV("Entering acquireDrmInfo"); + return mDrmManager->acquireDrmInfo(uniqueId, drmInfoRequest); +} + +void DrmManagerService::saveRights( + int uniqueId, const DrmRights& drmRights, + const String8& rightsPath, const String8& contentPath) { + LOGV("Entering saveRights"); + return mDrmManager->saveRights(uniqueId, drmRights, rightsPath, contentPath); +} + +String8 DrmManagerService::getOriginalMimeType(int uniqueId, const String8& path) { + LOGV("Entering getOriginalMimeType"); + return mDrmManager->getOriginalMimeType(uniqueId, path); +} + +int DrmManagerService::getDrmObjectType( + int uniqueId, const String8& path, const String8& mimeType) { + LOGV("Entering getDrmObjectType"); + return mDrmManager->getDrmObjectType(uniqueId, path, mimeType); +} + +int DrmManagerService::checkRightsStatus( + int uniqueId, const String8& path, int action) { + LOGV("Entering checkRightsStatus"); + return mDrmManager->checkRightsStatus(uniqueId, path, action); +} + +void DrmManagerService::consumeRights( + int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) { + LOGV("Entering consumeRights"); + mDrmManager->consumeRights(uniqueId, decryptHandle, action, reserve); +} + +void DrmManagerService::setPlaybackStatus( + int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position) { + LOGV("Entering setPlaybackStatus"); + mDrmManager->setPlaybackStatus(uniqueId, decryptHandle, playbackStatus, position); +} + +bool DrmManagerService::validateAction( + int uniqueId, const String8& path, + int action, const ActionDescription& description) { + LOGV("Entering validateAction"); + return mDrmManager->validateAction(uniqueId, path, action, description); +} + +void DrmManagerService::removeRights(int uniqueId, const String8& path) { + LOGV("Entering removeRights"); + mDrmManager->removeRights(uniqueId, path); +} + +void DrmManagerService::removeAllRights(int uniqueId) { + LOGV("Entering removeAllRights"); + mDrmManager->removeAllRights(uniqueId); +} + +int DrmManagerService::openConvertSession(int uniqueId, const String8& mimeType) { + LOGV("Entering openConvertSession"); + return mDrmManager->openConvertSession(uniqueId, mimeType); +} + +DrmConvertedStatus* DrmManagerService::convertData( + int uniqueId, int convertId, const DrmBuffer* inputData) { + LOGV("Entering convertData"); + return mDrmManager->convertData(uniqueId, convertId, inputData); +} + +DrmConvertedStatus* DrmManagerService::closeConvertSession(int uniqueId, int convertId) { + LOGV("Entering closeConvertSession"); + return mDrmManager->closeConvertSession(uniqueId, convertId); +} + +status_t DrmManagerService::getAllSupportInfo( + int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray) { + LOGV("Entering getAllSupportInfo"); + return mDrmManager->getAllSupportInfo(uniqueId, length, drmSupportInfoArray); +} + +DecryptHandle* DrmManagerService::openDecryptSession( + int uniqueId, int fd, int offset, int length) { + LOGV("Entering DrmManagerService::openDecryptSession"); + return mDrmManager->openDecryptSession(uniqueId, fd, offset, length); +} + +void DrmManagerService::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) { + LOGV("Entering closeDecryptSession"); + mDrmManager->closeDecryptSession(uniqueId, decryptHandle); +} + +void DrmManagerService::initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, + int decryptUnitId, const DrmBuffer* headerInfo) { + LOGV("Entering initializeDecryptUnit"); + mDrmManager->initializeDecryptUnit(uniqueId,decryptHandle, decryptUnitId, headerInfo); +} + +status_t DrmManagerService::decrypt( + int uniqueId, DecryptHandle* decryptHandle, + int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer) { + LOGV("Entering decrypt"); + return mDrmManager->decrypt(uniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer); +} + +void DrmManagerService::finalizeDecryptUnit( + int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) { + LOGV("Entering finalizeDecryptUnit"); + mDrmManager->finalizeDecryptUnit(uniqueId, decryptHandle, decryptUnitId); +} + +ssize_t DrmManagerService::pread(int uniqueId, DecryptHandle* decryptHandle, + void* buffer, ssize_t numBytes, off_t offset) { + LOGV("Entering pread"); + return mDrmManager->pread(uniqueId, decryptHandle, buffer, numBytes, offset); +} + diff --git a/drm/drmserver/StringTokenizer.cpp b/drm/drmserver/StringTokenizer.cpp new file mode 100644 index 0000000..367c9bd --- /dev/null +++ b/drm/drmserver/StringTokenizer.cpp @@ -0,0 +1,68 @@ +/* + * 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. + */ + +#include "StringTokenizer.h" + +using namespace android; + +StringTokenizer::StringTokenizer(const String8& string, const String8& delimiter) { + splitString(string, delimiter); +} + +void StringTokenizer::splitString(const String8& string, const String8& delimiter) { + for (unsigned int i = 0; i < string.length(); i++) { + unsigned int position = string.find(delimiter.string(), i); + if (string.length() != position) { + String8 token(string.string()+i, position-i); + if (token.length()) { + mStringTokenizerVector.push(token); + i = position + delimiter.length() - 1; + } + } else { + mStringTokenizerVector.push(String8(string.string()+i, string.length()-i)); + break; + } + } +} + +StringTokenizer::Iterator StringTokenizer::iterator() { + return Iterator(this); +} + +StringTokenizer::Iterator::Iterator(const StringTokenizer::Iterator& iterator) : + mStringTokenizer(iterator.mStringTokenizer), + mIndex(iterator.mIndex) { + LOGV("StringTokenizer::Iterator::Iterator"); +} + +StringTokenizer::Iterator& StringTokenizer::Iterator::operator=( + const StringTokenizer::Iterator& iterator) { + LOGV("StringTokenizer::Iterator::operator="); + mStringTokenizer = iterator.mStringTokenizer; + mIndex = iterator.mIndex; + return *this; +} + +bool StringTokenizer::Iterator::hasNext() { + return mIndex < mStringTokenizer->mStringTokenizerVector.size(); +} + +String8& StringTokenizer::Iterator::next() { + String8& value = mStringTokenizer->mStringTokenizerVector.editItemAt(mIndex); + mIndex++; + return value; +} + diff --git a/drm/drmserver/main_drmserver.cpp b/drm/drmserver/main_drmserver.cpp new file mode 100644 index 0000000..6d10646 --- /dev/null +++ b/drm/drmserver/main_drmserver.cpp @@ -0,0 +1,40 @@ +/* + * 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. + */ + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include + +using namespace android; + +int main(int argc, char** argv) +{ + sp proc(ProcessState::self()); + sp sm = defaultServiceManager(); + LOGI("ServiceManager: %p", sm.get()); + DrmManagerService::instantiate(); + ProcessState::self()->startThreadPool(); + IPCThreadState::self()->joinThreadPool(); +} + -- cgit v1.1 From a4f8842d67004f168b53fc684d4622679e19a3df Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Queru Date: Thu, 9 Sep 2010 16:02:22 -0700 Subject: fix build Change-Id: I4aba42eabb2f959b5301bfd16f65fa6141d86ddc --- drm/drmserver/Android.mk | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'drm/drmserver') diff --git a/drm/drmserver/Android.mk b/drm/drmserver/Android.mk index d2ebe8e..46a51bc 100644 --- a/drm/drmserver/Android.mk +++ b/drm/drmserver/Android.mk @@ -24,8 +24,13 @@ LOCAL_SRC_FILES:= \ LOCAL_SHARED_LIBRARIES := \ libutils \ - libbinder \ - libdl + libbinder + +ifeq ($(TARGET_SIMULATOR),true) + LOCAL_LDLIBS += -ldl +else + LOCAL_SHARED_LIBRARIES += libdl +endif LOCAL_STATIC_LIBRARIES := libdrmframeworkcommon -- cgit v1.1 From 0335b70c6cdbe96650d4bed817f9233cd8db1c6d Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Queru Date: Fri, 10 Sep 2010 12:46:57 -0700 Subject: Make DRM libraries optional Change-Id: I0b591b75a035bc6d8049c85b595966845fedaa15 --- drm/drmserver/Android.mk | 2 ++ 1 file changed, 2 insertions(+) (limited to 'drm/drmserver') diff --git a/drm/drmserver/Android.mk b/drm/drmserver/Android.mk index 46a51bc..5df2ff8 100644 --- a/drm/drmserver/Android.mk +++ b/drm/drmserver/Android.mk @@ -41,4 +41,6 @@ LOCAL_C_INCLUDES := \ LOCAL_MODULE:= drmserver +LOCAL_MODULE_TAGS := optional + include $(BUILD_EXECUTABLE) -- cgit v1.1 From 2272ee27d9022d173b6eab45c409b3c3f57f30ec Mon Sep 17 00:00:00 2001 From: Takeshi Aimi Date: Mon, 20 Sep 2010 23:40:41 +0900 Subject: Update of DRM framework. - Change "void" type of return value to "int" for returning status. - Add some of overloaded Java APIs which accept database Uri as input. - Add asynchronous APIs - Add OnEventListener and OnErrorListener for asynchronous APIs - Disable debug log - Change decrypt() API to accept an optional buffer needed by some of DRM schemes Changes are incorporated by Sony Corporation. Change-Id: I414a165e22cc79be6ea7cd28041788aa2b6b8f7c --- drm/drmserver/DrmManager.cpp | 136 +++++++++++++++++++++++++----------- drm/drmserver/DrmManagerService.cpp | 69 ++++++++++-------- drm/drmserver/StringTokenizer.cpp | 2 - 3 files changed, 135 insertions(+), 72 deletions(-) (limited to 'drm/drmserver') diff --git a/drm/drmserver/DrmManager.cpp b/drm/drmserver/DrmManager.cpp index 44886f9..52527dc 100644 --- a/drm/drmserver/DrmManager.cpp +++ b/drm/drmserver/DrmManager.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#define LOG_NDEBUG 0 +//#define LOG_NDEBUG 0 #define LOG_TAG "DrmManager(Native)" #include "utils/Log.h" @@ -36,6 +36,7 @@ using namespace android; +Vector DrmManager::mUniqueIdVector; const String8 DrmManager::EMPTY_STRING(""); DrmManager::DrmManager() : @@ -48,6 +49,42 @@ DrmManager::~DrmManager() { } +int DrmManager::addUniqueId(int uniqueId) { + 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; + } + } + uniqueId = temp; + } + mUniqueIdVector.push(uniqueId); + return uniqueId; +} + +void DrmManager::removeUniqueId(int uniqueId) { + for (unsigned int i = 0; i < mUniqueIdVector.size(); i++) { + if (uniqueId == mUniqueIdVector.itemAt(i)) { + mUniqueIdVector.removeAt(i); + break; + } + } +} + status_t DrmManager::loadPlugIns(int uniqueId) { String8 pluginDirPath("/system/lib/drm/plugins/native"); return loadPlugIns(uniqueId, pluginDirPath); @@ -82,10 +119,12 @@ status_t DrmManager::unloadPlugIns(int uniqueId) { rDrmEngine.terminate(uniqueId); } - mConvertSessionMap.clear(); - mDecryptSessionMap.clear(); - mSupportInfoToPlugInIdMap.clear(); - mPlugInManager.unloadPlugIns(); + if (0 >= mUniqueIdVector.size()) { + mConvertSessionMap.clear(); + mDecryptSessionMap.clear(); + mSupportInfoToPlugInIdMap.clear(); + mPlugInManager.unloadPlugIns(); + } return DRM_NO_ERROR; } @@ -159,13 +198,15 @@ DrmInfo* DrmManager::acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoR return NULL; } -void DrmManager::saveRights(int uniqueId, const DrmRights& drmRights, +status_t DrmManager::saveRights(int uniqueId, const DrmRights& drmRights, const String8& rightsPath, const String8& contentPath) { const String8 plugInId = getSupportedPlugInId(drmRights.getMimeType()); + status_t result = DRM_ERROR_UNKNOWN; if (EMPTY_STRING != plugInId) { IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); - rDrmEngine.saveRights(uniqueId, drmRights, rightsPath, contentPath); + result = rDrmEngine.saveRights(uniqueId, drmRights, rightsPath, contentPath); } + return result; } String8 DrmManager::getOriginalMimeType(int uniqueId, const String8& path) { @@ -195,21 +236,24 @@ int DrmManager::checkRightsStatus(int uniqueId, const String8& path, int action) return RightsStatus::RIGHTS_INVALID; } -void DrmManager::consumeRights( +status_t DrmManager::consumeRights( int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) { + status_t result = DRM_ERROR_UNKNOWN; if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) { IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId); - drmEngine->consumeRights(uniqueId, decryptHandle, action, reserve); + result = drmEngine->consumeRights(uniqueId, decryptHandle, action, reserve); } + return result; } -void DrmManager::setPlaybackStatus( +status_t DrmManager::setPlaybackStatus( int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position) { - + status_t result = DRM_ERROR_UNKNOWN; if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) { IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId); - drmEngine->setPlaybackStatus(uniqueId, decryptHandle, playbackStatus, position); + result = drmEngine->setPlaybackStatus(uniqueId, decryptHandle, playbackStatus, position); } + return result; } bool DrmManager::validateAction( @@ -222,21 +266,27 @@ bool DrmManager::validateAction( return false; } -void DrmManager::removeRights(int uniqueId, const String8& path) { +status_t DrmManager::removeRights(int uniqueId, const String8& path) { const String8 plugInId = getSupportedPlugInIdFromPath(uniqueId, path); + status_t result = DRM_ERROR_UNKNOWN; if (EMPTY_STRING != plugInId) { IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); - rDrmEngine.removeRights(uniqueId, path); + result = rDrmEngine.removeRights(uniqueId, path); } + return result; } -void DrmManager::removeAllRights(int uniqueId) { +status_t DrmManager::removeAllRights(int uniqueId) { Vector plugInIdList = mPlugInManager.getPlugInIdList(); - + status_t result = DRM_ERROR_UNKNOWN; for (unsigned int index = 0; index < plugInIdList.size(); index++) { IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInIdList.itemAt(index)); - rDrmEngine.removeAllRights(uniqueId); + result = rDrmEngine.removeAllRights(uniqueId); + if (DRM_NO_ERROR != result) { + break; + } } + return result; } int DrmManager::openConvertSession(int uniqueId, const String8& mimeType) { @@ -246,12 +296,12 @@ int DrmManager::openConvertSession(int uniqueId, const String8& mimeType) { if (EMPTY_STRING != plugInId) { IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); - Mutex::Autolock _l(mConvertLock); - ++mConvertId; - convertId = mConvertId; - mConvertSessionMap.add(mConvertId, &rDrmEngine); - - rDrmEngine.openConvertSession(uniqueId, mConvertId); + if (DRM_NO_ERROR == rDrmEngine.openConvertSession(uniqueId, mConvertId + 1)) { + Mutex::Autolock _l(mConvertLock); + ++mConvertId; + convertId = mConvertId; + mConvertSessionMap.add(convertId, &rDrmEngine); + } } return convertId; } @@ -310,7 +360,6 @@ status_t DrmManager::getAllSupportInfo( } DecryptHandle* DrmManager::openDecryptSession(int uniqueId, int fd, int offset, int length) { - LOGV("Entering DrmManager::openDecryptSession"); status_t result = DRM_ERROR_CANNOT_HANDLE; Vector plugInIdList = mPlugInManager.getPlugInIdList(); @@ -324,18 +373,15 @@ DecryptHandle* DrmManager::openDecryptSession(int uniqueId, int fd, int offset, IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); result = rDrmEngine.openDecryptSession(uniqueId, handle, fd, offset, length); - LOGV("plug-in %s return value = %d", plugInId.string(), result); - if (DRM_NO_ERROR == result) { ++mDecryptSessionId; mDecryptSessionMap.add(mDecryptSessionId, &rDrmEngine); - LOGV("plug-in %s is selected", plugInId.string()); break; } } } - if (DRM_ERROR_CANNOT_HANDLE == result) { + if (DRM_NO_ERROR != result) { delete handle; handle = NULL; LOGE("DrmManager::openDecryptSession: no capable plug-in found"); } @@ -343,39 +389,47 @@ DecryptHandle* DrmManager::openDecryptSession(int uniqueId, int fd, int offset, return handle; } -void DrmManager::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) { +status_t DrmManager::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) { + status_t result = DRM_ERROR_UNKNOWN; if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) { IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId); - drmEngine->closeDecryptSession(uniqueId, decryptHandle); - - mDecryptSessionMap.removeItem(decryptHandle->decryptId); + result = drmEngine->closeDecryptSession(uniqueId, decryptHandle); + if (DRM_NO_ERROR == result) { + mDecryptSessionMap.removeItem(decryptHandle->decryptId); + } } + return result; } -void DrmManager::initializeDecryptUnit( +status_t DrmManager::initializeDecryptUnit( int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo) { + status_t result = DRM_ERROR_UNKNOWN; if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) { IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId); - drmEngine->initializeDecryptUnit(uniqueId, decryptHandle, decryptUnitId, headerInfo); + result = drmEngine->initializeDecryptUnit(uniqueId, decryptHandle, decryptUnitId, headerInfo); } + return result; } -status_t DrmManager::decrypt(int uniqueId, DecryptHandle* decryptHandle, - int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer) { - status_t status = DRM_ERROR_UNKNOWN; +status_t DrmManager::decrypt(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, + const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) { + status_t result = DRM_ERROR_UNKNOWN; if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) { IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId); - status = drmEngine->decrypt(uniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer); + result = drmEngine->decrypt( + uniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer, IV); } - return status; + return result; } -void DrmManager::finalizeDecryptUnit( +status_t DrmManager::finalizeDecryptUnit( int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) { + status_t result = DRM_ERROR_UNKNOWN; if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) { IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId); - drmEngine->finalizeDecryptUnit(uniqueId, decryptHandle, decryptUnitId); + result = drmEngine->finalizeDecryptUnit(uniqueId, decryptHandle, decryptUnitId); } + return result; } ssize_t DrmManager::pread(int uniqueId, DecryptHandle* decryptHandle, diff --git a/drm/drmserver/DrmManagerService.cpp b/drm/drmserver/DrmManagerService.cpp index 9d000e9..843dddb 100644 --- a/drm/drmserver/DrmManagerService.cpp +++ b/drm/drmserver/DrmManagerService.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#define LOG_NDEBUG 0 +//#define LOG_NDEBUG 0 #define LOG_TAG "DrmManagerService(Native)" #include @@ -29,20 +29,23 @@ using namespace android; #define SUCCESS 0 #define DRM_DIRECTORY_PERMISSION 0700 +#define DRM_PLUGINS_ROOT "/data/drm/plugins" +#define DRM_PLUGINS_NATIVE "/data/drm/plugins/native" +#define DRM_PLUGINS_NATIVE_DATABASES "/data/drm/plugins/native/databases" void DrmManagerService::instantiate() { LOGV("instantiate"); - int res = mkdir("/data/drm/plugins", DRM_DIRECTORY_PERMISSION); - if (SUCCESS == res || EEXIST == errno) { - res = mkdir("/data/drm/plugins/native", DRM_DIRECTORY_PERMISSION); - if (SUCCESS == res || EEXIST == errno) { - res = mkdir("/data/drm/plugins/native/databases", DRM_DIRECTORY_PERMISSION); - if (SUCCESS == res || EEXIST == errno) { - defaultServiceManager() - ->addService(String16("drm.drmManager"), new DrmManagerService()); - } - } + int res = mkdir(DRM_PLUGINS_ROOT, DRM_DIRECTORY_PERMISSION); + if (SUCCESS == res || EEXIST == errno) { + res = mkdir(DRM_PLUGINS_NATIVE, DRM_DIRECTORY_PERMISSION); + if (SUCCESS == res || EEXIST == errno) { + res = mkdir(DRM_PLUGINS_NATIVE_DATABASES, DRM_DIRECTORY_PERMISSION); + if (SUCCESS == res || EEXIST == errno) { + defaultServiceManager() + ->addService(String16("drm.drmManager"), new DrmManagerService()); + } + } } } @@ -57,6 +60,14 @@ DrmManagerService::~DrmManagerService() { delete mDrmManager; mDrmManager = NULL; } +int DrmManagerService::addUniqueId(int uniqueId) { + return mDrmManager->addUniqueId(uniqueId); +} + +void DrmManagerService::removeUniqueId(int uniqueId) { + mDrmManager->removeUniqueId(uniqueId); +} + status_t DrmManagerService::loadPlugIns(int uniqueId) { LOGV("Entering load plugins"); return mDrmManager->loadPlugIns(uniqueId); @@ -105,7 +116,7 @@ DrmInfo* DrmManagerService::acquireDrmInfo(int uniqueId, const DrmInfoRequest* d return mDrmManager->acquireDrmInfo(uniqueId, drmInfoRequest); } -void DrmManagerService::saveRights( +status_t DrmManagerService::saveRights( int uniqueId, const DrmRights& drmRights, const String8& rightsPath, const String8& contentPath) { LOGV("Entering saveRights"); @@ -129,16 +140,16 @@ int DrmManagerService::checkRightsStatus( return mDrmManager->checkRightsStatus(uniqueId, path, action); } -void DrmManagerService::consumeRights( +status_t DrmManagerService::consumeRights( int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) { LOGV("Entering consumeRights"); - mDrmManager->consumeRights(uniqueId, decryptHandle, action, reserve); + return mDrmManager->consumeRights(uniqueId, decryptHandle, action, reserve); } -void DrmManagerService::setPlaybackStatus( +status_t DrmManagerService::setPlaybackStatus( int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position) { LOGV("Entering setPlaybackStatus"); - mDrmManager->setPlaybackStatus(uniqueId, decryptHandle, playbackStatus, position); + return mDrmManager->setPlaybackStatus(uniqueId, decryptHandle, playbackStatus, position); } bool DrmManagerService::validateAction( @@ -148,14 +159,14 @@ bool DrmManagerService::validateAction( return mDrmManager->validateAction(uniqueId, path, action, description); } -void DrmManagerService::removeRights(int uniqueId, const String8& path) { +status_t DrmManagerService::removeRights(int uniqueId, const String8& path) { LOGV("Entering removeRights"); - mDrmManager->removeRights(uniqueId, path); + return mDrmManager->removeRights(uniqueId, path); } -void DrmManagerService::removeAllRights(int uniqueId) { +status_t DrmManagerService::removeAllRights(int uniqueId) { LOGV("Entering removeAllRights"); - mDrmManager->removeAllRights(uniqueId); + return mDrmManager->removeAllRights(uniqueId); } int DrmManagerService::openConvertSession(int uniqueId, const String8& mimeType) { @@ -186,28 +197,28 @@ DecryptHandle* DrmManagerService::openDecryptSession( return mDrmManager->openDecryptSession(uniqueId, fd, offset, length); } -void DrmManagerService::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) { +status_t DrmManagerService::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) { LOGV("Entering closeDecryptSession"); - mDrmManager->closeDecryptSession(uniqueId, decryptHandle); + return mDrmManager->closeDecryptSession(uniqueId, decryptHandle); } -void DrmManagerService::initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, +status_t DrmManagerService::initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo) { LOGV("Entering initializeDecryptUnit"); - mDrmManager->initializeDecryptUnit(uniqueId,decryptHandle, decryptUnitId, headerInfo); + return mDrmManager->initializeDecryptUnit(uniqueId,decryptHandle, decryptUnitId, headerInfo); } status_t DrmManagerService::decrypt( - int uniqueId, DecryptHandle* decryptHandle, - int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer) { + int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, + const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) { LOGV("Entering decrypt"); - return mDrmManager->decrypt(uniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer); + return mDrmManager->decrypt(uniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer, IV); } -void DrmManagerService::finalizeDecryptUnit( +status_t DrmManagerService::finalizeDecryptUnit( int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) { LOGV("Entering finalizeDecryptUnit"); - mDrmManager->finalizeDecryptUnit(uniqueId, decryptHandle, decryptUnitId); + return mDrmManager->finalizeDecryptUnit(uniqueId, decryptHandle, decryptUnitId); } ssize_t DrmManagerService::pread(int uniqueId, DecryptHandle* decryptHandle, diff --git a/drm/drmserver/StringTokenizer.cpp b/drm/drmserver/StringTokenizer.cpp index 367c9bd..2130a00 100644 --- a/drm/drmserver/StringTokenizer.cpp +++ b/drm/drmserver/StringTokenizer.cpp @@ -45,12 +45,10 @@ StringTokenizer::Iterator StringTokenizer::iterator() { StringTokenizer::Iterator::Iterator(const StringTokenizer::Iterator& iterator) : mStringTokenizer(iterator.mStringTokenizer), mIndex(iterator.mIndex) { - LOGV("StringTokenizer::Iterator::Iterator"); } StringTokenizer::Iterator& StringTokenizer::Iterator::operator=( const StringTokenizer::Iterator& iterator) { - LOGV("StringTokenizer::Iterator::operator="); mStringTokenizer = iterator.mStringTokenizer; mIndex = iterator.mIndex; return *this; -- cgit v1.1 From d6d4ba97bcb39bf6d0cde32ce7bef1753e420548 Mon Sep 17 00:00:00 2001 From: Gloria Wang Date: Tue, 26 Oct 2010 12:11:55 -0700 Subject: Do not create drm directory here. Fix for bug 3134576. Change-Id: I1e26ff32b1c2d97464d544c2455eab0a726e3294 --- drm/drmserver/DrmManagerService.cpp | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) (limited to 'drm/drmserver') diff --git a/drm/drmserver/DrmManagerService.cpp b/drm/drmserver/DrmManagerService.cpp index 843dddb..cf9bab1 100644 --- a/drm/drmserver/DrmManagerService.cpp +++ b/drm/drmserver/DrmManagerService.cpp @@ -28,25 +28,10 @@ using namespace android; #define SUCCESS 0 -#define DRM_DIRECTORY_PERMISSION 0700 -#define DRM_PLUGINS_ROOT "/data/drm/plugins" -#define DRM_PLUGINS_NATIVE "/data/drm/plugins/native" -#define DRM_PLUGINS_NATIVE_DATABASES "/data/drm/plugins/native/databases" void DrmManagerService::instantiate() { LOGV("instantiate"); - - int res = mkdir(DRM_PLUGINS_ROOT, DRM_DIRECTORY_PERMISSION); - if (SUCCESS == res || EEXIST == errno) { - res = mkdir(DRM_PLUGINS_NATIVE, DRM_DIRECTORY_PERMISSION); - if (SUCCESS == res || EEXIST == errno) { - res = mkdir(DRM_PLUGINS_NATIVE_DATABASES, DRM_DIRECTORY_PERMISSION); - if (SUCCESS == res || EEXIST == errno) { - defaultServiceManager() - ->addService(String16("drm.drmManager"), new DrmManagerService()); - } - } - } + defaultServiceManager()->addService(String16("drm.drmManager"), new DrmManagerService()); } DrmManagerService::DrmManagerService() { -- cgit v1.1 From e943f84129326ab885cc7a69dcfa17f766b72b89 Mon Sep 17 00:00:00 2001 From: Takeshi Aimi Date: Fri, 8 Oct 2010 23:05:49 +0900 Subject: Update of DRM framework - Overload openDecryptSession() with uri parameter in order to accept URI of DRM content, Following API is added, DecryptHandle*openDecryptSession(const char* uri);. - Unify texisting three event types of processDrmInfo() so that caller of DRM framework does not have to handle many event types. - Let DrmManagerService call load/unload plugins API so that client of DRM framework does not have to manage plug-in load/unload. - Trivial fix in DrmManagerClient.java is also incorporated. Changes are made by Sony Corporation. Change-Id: If62b47fa0360718fdc943e6e6143671d7db26adc --- drm/drmserver/DrmManager.cpp | 108 +++++++++++++++++++++--------------- drm/drmserver/DrmManagerService.cpp | 46 +++++---------- 2 files changed, 77 insertions(+), 77 deletions(-) (limited to 'drm/drmserver') diff --git a/drm/drmserver/DrmManager.cpp b/drm/drmserver/DrmManager.cpp index 52527dc..b7a035f 100644 --- a/drm/drmserver/DrmManager.cpp +++ b/drm/drmserver/DrmManager.cpp @@ -85,22 +85,31 @@ void DrmManager::removeUniqueId(int uniqueId) { } } -status_t DrmManager::loadPlugIns(int uniqueId) { +status_t DrmManager::loadPlugIns() { String8 pluginDirPath("/system/lib/drm/plugins/native"); - return loadPlugIns(uniqueId, pluginDirPath); + return loadPlugIns(pluginDirPath); } -status_t DrmManager::loadPlugIns(int uniqueId, const String8& plugInDirPath) { +status_t DrmManager::loadPlugIns(const String8& plugInDirPath) { if (mSupportInfoToPlugInIdMap.isEmpty()) { mPlugInManager.loadPlugIns(plugInDirPath); - - initializePlugIns(uniqueId); - - populate(uniqueId); - } else { - initializePlugIns(uniqueId); + Vector 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) { + mSupportInfoToPlugInIdMap.add(*info, plugInPath); + } + } } + return DRM_NO_ERROR; +} +status_t DrmManager::unloadPlugIns() { + mConvertSessionMap.clear(); + mDecryptSessionMap.clear(); + mPlugInManager.unloadPlugIns(); + mSupportInfoToPlugInIdMap.clear(); return DRM_NO_ERROR; } @@ -111,21 +120,23 @@ status_t DrmManager::setDrmServiceListener( return DRM_NO_ERROR; } -status_t DrmManager::unloadPlugIns(int uniqueId) { - Vector plugInIdList = mPlugInManager.getPlugInIdList(); +void DrmManager::addClient(int uniqueId) { + if (!mSupportInfoToPlugInIdMap.isEmpty()) { + Vector 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); + } + } +} +void DrmManager::removeClient(int uniqueId) { + Vector plugInIdList = mPlugInManager.getPlugInIdList(); for (unsigned int index = 0; index < plugInIdList.size(); index++) { IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInIdList.itemAt(index)); rDrmEngine.terminate(uniqueId); } - - if (0 >= mUniqueIdVector.size()) { - mConvertSessionMap.clear(); - mDecryptSessionMap.clear(); - mSupportInfoToPlugInIdMap.clear(); - mPlugInManager.unloadPlugIns(); - } - return DRM_NO_ERROR; } DrmConstraints* DrmManager::getConstraints(int uniqueId, const String8* path, const int action) { @@ -144,7 +155,7 @@ status_t DrmManager::installDrmEngine(int uniqueId, const String8& absolutePath) rDrmEngine.initialize(uniqueId); rDrmEngine.setOnInfoListener(uniqueId, this); - DrmSupportInfo* info = rDrmEngine.getSupportInfo(uniqueId); + DrmSupportInfo* info = rDrmEngine.getSupportInfo(0); mSupportInfoToPlugInIdMap.add(*info, absolutePath); return DRM_NO_ERROR; @@ -154,7 +165,7 @@ bool DrmManager::canHandle(int uniqueId, const String8& path, const String8& mim const String8 plugInId = getSupportedPlugInId(mimeType); bool result = (EMPTY_STRING != plugInId) ? true : false; - if (NULL != path) { + if (0 < path.length()) { if (result) { IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); result = rDrmEngine.canHandle(uniqueId, path); @@ -340,7 +351,7 @@ status_t DrmManager::getAllSupportInfo( for (int i = 0; i < size; ++i) { String8 plugInPath = plugInPathList[i]; DrmSupportInfo* drmSupportInfo - = mPlugInManager.getPlugIn(plugInPath).getSupportInfo(uniqueId); + = mPlugInManager.getPlugIn(plugInPath).getSupportInfo(0); if (NULL != drmSupportInfo) { drmSupportInfoList.add(*drmSupportInfo); delete drmSupportInfo; drmSupportInfo = NULL; @@ -360,12 +371,12 @@ status_t DrmManager::getAllSupportInfo( } DecryptHandle* DrmManager::openDecryptSession(int uniqueId, int fd, int offset, int length) { + Mutex::Autolock _l(mDecryptLock); status_t result = DRM_ERROR_CANNOT_HANDLE; Vector plugInIdList = mPlugInManager.getPlugInIdList(); DecryptHandle* handle = new DecryptHandle(); if (NULL != handle) { - Mutex::Autolock _l(mDecryptLock); handle->decryptId = mDecryptSessionId + 1; for (unsigned int index = 0; index < plugInIdList.size(); index++) { @@ -380,16 +391,43 @@ DecryptHandle* DrmManager::openDecryptSession(int uniqueId, int fd, int offset, } } } - if (DRM_NO_ERROR != result) { delete handle; handle = NULL; LOGE("DrmManager::openDecryptSession: no capable plug-in found"); } + return handle; +} + +DecryptHandle* DrmManager::openDecryptSession(int uniqueId, const char* uri) { + Mutex::Autolock _l(mDecryptLock); + status_t result = DRM_ERROR_CANNOT_HANDLE; + Vector 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); + result = rDrmEngine.openDecryptSession(uniqueId, handle, uri); + if (DRM_NO_ERROR == result) { + ++mDecryptSessionId; + mDecryptSessionMap.add(mDecryptSessionId, &rDrmEngine); + break; + } + } + } + if (DRM_NO_ERROR != result) { + delete handle; handle = NULL; + LOGE("DrmManager::openDecryptSession: no capable plug-in found"); + } return handle; } status_t DrmManager::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) { + Mutex::Autolock _l(mDecryptLock); status_t result = DRM_ERROR_UNKNOWN; if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) { IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId); @@ -443,28 +481,6 @@ ssize_t DrmManager::pread(int uniqueId, DecryptHandle* decryptHandle, return result; } -void DrmManager::initializePlugIns(int uniqueId) { - Vector 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); - } -} - -void DrmManager::populate(int uniqueId) { - Vector plugInPathList = mPlugInManager.getPlugInIdList(); - - for (unsigned int i = 0; i < plugInPathList.size(); ++i) { - String8 plugInPath = plugInPathList[i]; - DrmSupportInfo* info = mPlugInManager.getPlugIn(plugInPath).getSupportInfo(uniqueId); - if (NULL != info) { - mSupportInfoToPlugInIdMap.add(*info, plugInPath); - } - } -} - String8 DrmManager::getSupportedPlugInId( int uniqueId, const String8& path, const String8& mimeType) { String8 plugInId(""); diff --git a/drm/drmserver/DrmManagerService.cpp b/drm/drmserver/DrmManagerService.cpp index 843dddb..8cf510d 100644 --- a/drm/drmserver/DrmManagerService.cpp +++ b/drm/drmserver/DrmManagerService.cpp @@ -27,36 +27,21 @@ using namespace android; -#define SUCCESS 0 -#define DRM_DIRECTORY_PERMISSION 0700 -#define DRM_PLUGINS_ROOT "/data/drm/plugins" -#define DRM_PLUGINS_NATIVE "/data/drm/plugins/native" -#define DRM_PLUGINS_NATIVE_DATABASES "/data/drm/plugins/native/databases" - void DrmManagerService::instantiate() { LOGV("instantiate"); - - int res = mkdir(DRM_PLUGINS_ROOT, DRM_DIRECTORY_PERMISSION); - if (SUCCESS == res || EEXIST == errno) { - res = mkdir(DRM_PLUGINS_NATIVE, DRM_DIRECTORY_PERMISSION); - if (SUCCESS == res || EEXIST == errno) { - res = mkdir(DRM_PLUGINS_NATIVE_DATABASES, DRM_DIRECTORY_PERMISSION); - if (SUCCESS == res || EEXIST == errno) { - defaultServiceManager() - ->addService(String16("drm.drmManager"), new DrmManagerService()); - } - } - } + defaultServiceManager()->addService(String16("drm.drmManager"), new DrmManagerService()); } -DrmManagerService::DrmManagerService() { +DrmManagerService::DrmManagerService() : + mDrmManager(NULL) { LOGV("created"); - mDrmManager = NULL; mDrmManager = new DrmManager(); + mDrmManager->loadPlugIns(); } DrmManagerService::~DrmManagerService() { LOGV("Destroyed"); + mDrmManager->unloadPlugIns(); delete mDrmManager; mDrmManager = NULL; } @@ -68,14 +53,12 @@ void DrmManagerService::removeUniqueId(int uniqueId) { mDrmManager->removeUniqueId(uniqueId); } -status_t DrmManagerService::loadPlugIns(int uniqueId) { - LOGV("Entering load plugins"); - return mDrmManager->loadPlugIns(uniqueId); +void DrmManagerService::addClient(int uniqueId) { + mDrmManager->addClient(uniqueId); } -status_t DrmManagerService::loadPlugIns(int uniqueId, const String8& plugInDirPath) { - LOGV("Entering load plugins from path"); - return mDrmManager->loadPlugIns(uniqueId, plugInDirPath); +void DrmManagerService::removeClient(int uniqueId) { + mDrmManager->removeClient(uniqueId); } status_t DrmManagerService::setDrmServiceListener( @@ -85,11 +68,6 @@ status_t DrmManagerService::setDrmServiceListener( return DRM_NO_ERROR; } -status_t DrmManagerService::unloadPlugIns(int uniqueId) { - LOGV("Entering unload plugins"); - return mDrmManager->unloadPlugIns(uniqueId); -} - status_t DrmManagerService::installDrmEngine(int uniqueId, const String8& drmEngineFile) { LOGV("Entering installDrmEngine"); return mDrmManager->installDrmEngine(uniqueId, drmEngineFile); @@ -197,6 +175,12 @@ DecryptHandle* DrmManagerService::openDecryptSession( return mDrmManager->openDecryptSession(uniqueId, fd, offset, length); } +DecryptHandle* DrmManagerService::openDecryptSession( + int uniqueId, const char* uri) { + LOGV("Entering DrmManagerService::openDecryptSession with uri"); + return mDrmManager->openDecryptSession(uniqueId, uri); +} + status_t DrmManagerService::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) { LOGV("Entering closeDecryptSession"); return mDrmManager->closeDecryptSession(uniqueId, decryptHandle); -- cgit v1.1 From 5a6d1487905df5ea28168bd907aae93c0688dadf Mon Sep 17 00:00:00 2001 From: Gloria Wang Date: Tue, 2 Nov 2010 15:02:48 -0700 Subject: Disable some logs Change-Id: I05fcf6869916504367814fd2abd2b1af88619f5b --- drm/drmserver/DrmManager.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'drm/drmserver') diff --git a/drm/drmserver/DrmManager.cpp b/drm/drmserver/DrmManager.cpp index 52527dc..645d2c6 100644 --- a/drm/drmserver/DrmManager.cpp +++ b/drm/drmserver/DrmManager.cpp @@ -383,7 +383,6 @@ DecryptHandle* DrmManager::openDecryptSession(int uniqueId, int fd, int offset, if (DRM_NO_ERROR != result) { delete handle; handle = NULL; - LOGE("DrmManager::openDecryptSession: no capable plug-in found"); } return handle; -- cgit v1.1 From 3473846f64f5b28e1cbeb70ef5867073fc93159e Mon Sep 17 00:00:00 2001 From: Takeshi Aimi Date: Tue, 16 Nov 2010 13:56:11 +0900 Subject: Update of DRM Framework. -Access permission handling Introduce an internal function which allows the desired process to access decryption flow. This new function is just for reference and each OEM manufacturer should implement/replace with their solutions. -New API, getMetadata() This API is for retrieving media metadata from container-based DRM, such as OMA forward-lock content. This API asks DRM agent to retrieve media metadata hiddein inside of DRM special container. -New API, acquireRights() This API wraps acquireDrmInfo() and processDrmInfo(). If DRM agent has valid implementation of both APIs, Application can acquire DrmRights only by calling this API. -Bug fix in event loop of OnInfoListener. Separate OnInfo event loop from mail thread loop so as to avoid the issue that message is not dispatched when mail thread is busy. Changes are made by SEMC and Sony. Change-Id: I04ee3e0988152a71e221f2256d83253749a29da0 --- drm/drmserver/DrmManager.cpp | 10 ++++++++ drm/drmserver/DrmManagerService.cpp | 49 +++++++++++++++++++++++++++++++++++-- 2 files changed, 57 insertions(+), 2 deletions(-) (limited to 'drm/drmserver') diff --git a/drm/drmserver/DrmManager.cpp b/drm/drmserver/DrmManager.cpp index b7a035f..537791c 100644 --- a/drm/drmserver/DrmManager.cpp +++ b/drm/drmserver/DrmManager.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -148,6 +149,15 @@ DrmConstraints* DrmManager::getConstraints(int uniqueId, const String8* path, co return NULL; } +DrmMetadata* DrmManager::getMetadata(int uniqueId, const String8* path) { + const String8 plugInId = getSupportedPlugInIdFromPath(uniqueId, *path); + if (EMPTY_STRING != plugInId) { + IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); + return rDrmEngine.getMetadata(uniqueId, path); + } + return NULL; +} + status_t DrmManager::installDrmEngine(int uniqueId, const String8& absolutePath) { mPlugInManager.loadPlugIn(absolutePath); diff --git a/drm/drmserver/DrmManagerService.cpp b/drm/drmserver/DrmManagerService.cpp index 8cf510d..4dcfa72 100644 --- a/drm/drmserver/DrmManagerService.cpp +++ b/drm/drmserver/DrmManagerService.cpp @@ -18,18 +18,50 @@ #define LOG_TAG "DrmManagerService(Native)" #include +#include + #include #include #include +#include #include #include "DrmManagerService.h" #include "DrmManager.h" using namespace android; +static Vector trustedUids; + +static bool isProtectedCallAllowed() { + // TODO + // Following implementation is just for reference. + // Each OEM manufacturer should implement/replace with their own solutions. + bool result = false; + + IPCThreadState* ipcState = IPCThreadState::self(); + uid_t uid = ipcState->getCallingUid(); + + for (unsigned int i = 0; i < trustedUids.size(); ++i) { + if (trustedUids[i] == uid) { + result = true; + break; + } + } + return result; +} + void DrmManagerService::instantiate() { LOGV("instantiate"); defaultServiceManager()->addService(String16("drm.drmManager"), new DrmManagerService()); + + if (0 >= trustedUids.size()) { + // TODO + // Following implementation is just for reference. + // Each OEM manufacturer should implement/replace with their own solutions. + + // Add trusted uids here + trustedUids.push(AID_MEDIA); + } } DrmManagerService::DrmManagerService() : @@ -79,6 +111,11 @@ DrmConstraints* DrmManagerService::getConstraints( return mDrmManager->getConstraints(uniqueId, path, action); } +DrmMetadata* DrmManagerService::getMetadata(int uniqueId, const String8* path) { + LOGV("Entering getMetadata from content"); + return mDrmManager->getMetadata(uniqueId, path); +} + bool DrmManagerService::canHandle(int uniqueId, const String8& path, const String8& mimeType) { LOGV("Entering canHandle"); return mDrmManager->canHandle(uniqueId, path, mimeType); @@ -172,13 +209,21 @@ status_t DrmManagerService::getAllSupportInfo( DecryptHandle* DrmManagerService::openDecryptSession( int uniqueId, int fd, int offset, int length) { LOGV("Entering DrmManagerService::openDecryptSession"); - return mDrmManager->openDecryptSession(uniqueId, fd, offset, length); + if (isProtectedCallAllowed()) { + return mDrmManager->openDecryptSession(uniqueId, fd, offset, length); + } + + return NULL; } DecryptHandle* DrmManagerService::openDecryptSession( int uniqueId, const char* uri) { LOGV("Entering DrmManagerService::openDecryptSession with uri"); - return mDrmManager->openDecryptSession(uniqueId, uri); + if (isProtectedCallAllowed()) { + return mDrmManager->openDecryptSession(uniqueId, uri); + } + + return NULL; } status_t DrmManagerService::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) { -- cgit v1.1 From a2cd44cb5067b4fe98794860690394254d3ac73c Mon Sep 17 00:00:00 2001 From: Gloria Wang Date: Fri, 19 Nov 2010 15:19:36 -0800 Subject: 64-bit file size/offset support for DRM framework Change-Id: I0ba7147607825234df9fa28732e1bba344e82e79 --- drm/drmserver/DrmManager.cpp | 6 +++--- drm/drmserver/DrmManagerService.cpp | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'drm/drmserver') diff --git a/drm/drmserver/DrmManager.cpp b/drm/drmserver/DrmManager.cpp index 35e62f3..8da8176 100644 --- a/drm/drmserver/DrmManager.cpp +++ b/drm/drmserver/DrmManager.cpp @@ -258,7 +258,7 @@ status_t DrmManager::consumeRights( } status_t DrmManager::setPlaybackStatus( - int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position) { + int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int64_t position) { status_t result = DRM_ERROR_UNKNOWN; if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) { IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId); @@ -370,7 +370,7 @@ status_t DrmManager::getAllSupportInfo( return DRM_NO_ERROR; } -DecryptHandle* DrmManager::openDecryptSession(int uniqueId, int fd, int offset, int length) { +DecryptHandle* DrmManager::openDecryptSession(int uniqueId, int fd, off64_t offset, off64_t length) { Mutex::Autolock _l(mDecryptLock); status_t result = DRM_ERROR_CANNOT_HANDLE; Vector plugInIdList = mPlugInManager.getPlugInIdList(); @@ -470,7 +470,7 @@ status_t DrmManager::finalizeDecryptUnit( } ssize_t DrmManager::pread(int uniqueId, DecryptHandle* decryptHandle, - void* buffer, ssize_t numBytes, off_t offset) { + void* buffer, ssize_t numBytes, off64_t offset) { ssize_t result = DECRYPT_FILE_ERROR; if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) { diff --git a/drm/drmserver/DrmManagerService.cpp b/drm/drmserver/DrmManagerService.cpp index 8cf510d..efd7bae 100644 --- a/drm/drmserver/DrmManagerService.cpp +++ b/drm/drmserver/DrmManagerService.cpp @@ -125,7 +125,7 @@ status_t DrmManagerService::consumeRights( } status_t DrmManagerService::setPlaybackStatus( - int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position) { + int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int64_t position) { LOGV("Entering setPlaybackStatus"); return mDrmManager->setPlaybackStatus(uniqueId, decryptHandle, playbackStatus, position); } @@ -170,7 +170,7 @@ status_t DrmManagerService::getAllSupportInfo( } DecryptHandle* DrmManagerService::openDecryptSession( - int uniqueId, int fd, int offset, int length) { + int uniqueId, int fd, off64_t offset, off64_t length) { LOGV("Entering DrmManagerService::openDecryptSession"); return mDrmManager->openDecryptSession(uniqueId, fd, offset, length); } @@ -206,7 +206,7 @@ status_t DrmManagerService::finalizeDecryptUnit( } ssize_t DrmManagerService::pread(int uniqueId, DecryptHandle* decryptHandle, - void* buffer, ssize_t numBytes, off_t offset) { + void* buffer, ssize_t numBytes, off64_t offset) { LOGV("Entering pread"); return mDrmManager->pread(uniqueId, decryptHandle, buffer, numBytes, offset); } -- cgit v1.1 From c618b5af98dec06d49374a61a5a94016f9fec2d3 Mon Sep 17 00:00:00 2001 From: Takeshi Aimi Date: Tue, 30 Nov 2010 16:27:42 +0900 Subject: DRM Framework bug fixes. - Make sure to clean-up obsolete listeners. - Close cursor after using it. - Add virtual destructor to the base class of OnInfoListener. Changes are made by SEMC and Sony. Change-Id: Ibb6dd625ef48e3597188f0d7c90f9d4c780b6139 --- drm/drmserver/DrmManager.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'drm/drmserver') diff --git a/drm/drmserver/DrmManager.cpp b/drm/drmserver/DrmManager.cpp index 537791c..49df1c8 100644 --- a/drm/drmserver/DrmManager.cpp +++ b/drm/drmserver/DrmManager.cpp @@ -117,7 +117,11 @@ status_t DrmManager::unloadPlugIns() { status_t DrmManager::setDrmServiceListener( int uniqueId, const sp& drmServiceListener) { Mutex::Autolock _l(mLock); - mServiceListeners.add(uniqueId, drmServiceListener); + if (NULL != drmServiceListener.get()) { + mServiceListeners.add(uniqueId, drmServiceListener); + } else { + mServiceListeners.removeItem(uniqueId); + } return DRM_NO_ERROR; } -- cgit v1.1 From fc4f5aad4af1e2d8eea5e7d7f69d1cad4704cbb7 Mon Sep 17 00:00:00 2001 From: Glenn Kasten Date: Tue, 11 Jan 2011 17:15:49 -0800 Subject: Bug 3229711 Change-Id: I3a4d41597cb92a1526417a622390dbb93dc71e99 --- drm/drmserver/DrmManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drm/drmserver') diff --git a/drm/drmserver/DrmManager.cpp b/drm/drmserver/DrmManager.cpp index 9a6f787..13c7454 100644 --- a/drm/drmserver/DrmManager.cpp +++ b/drm/drmserver/DrmManager.cpp @@ -87,7 +87,7 @@ void DrmManager::removeUniqueId(int uniqueId) { } status_t DrmManager::loadPlugIns() { - String8 pluginDirPath("/system/lib/drm/plugins/native"); + String8 pluginDirPath("/system/lib/drm"); return loadPlugIns(pluginDirPath); } -- cgit v1.1 From 7f89d09c0f4a47119834ba15789260b933123ea5 Mon Sep 17 00:00:00 2001 From: Gloria Wang Date: Wed, 2 Mar 2011 12:33:00 -0800 Subject: To support DRM files without file extension Change-Id: Ie7701048d0dbd51bf358364014a1b41c894b664c --- drm/drmserver/DrmManager.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'drm/drmserver') diff --git a/drm/drmserver/DrmManager.cpp b/drm/drmserver/DrmManager.cpp index ef7d274..ec400b7 100644 --- a/drm/drmserver/DrmManager.cpp +++ b/drm/drmserver/DrmManager.cpp @@ -184,7 +184,10 @@ bool DrmManager::canHandle(int uniqueId, const String8& path, const String8& mim IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); result = rDrmEngine.canHandle(uniqueId, path); } else { - result = canHandle(uniqueId, path); + String8 extension = path.getPathExtension(); + if (String8("") != extension) { + result = canHandle(uniqueId, path); + } } } return result; -- cgit v1.1 From 6b610a3d31a225adfc5867223df25dba16637bd9 Mon Sep 17 00:00:00 2001 From: Gloria Wang Date: Fri, 4 Mar 2011 14:45:03 -0800 Subject: - Change level of some LOGs from LOGE to LOGV because those logs are not error logs from non-DRMed content's point of view. - Add more mutex lock to avoid crash by multi-thread calls. - Fix for bug 4050039 Change-Id: I52fed22069f0cda6c4ac6a5363469168c797a33b --- drm/drmserver/DrmManager.cpp | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'drm/drmserver') diff --git a/drm/drmserver/DrmManager.cpp b/drm/drmserver/DrmManager.cpp index ec400b7..305bafc 100644 --- a/drm/drmserver/DrmManager.cpp +++ b/drm/drmserver/DrmManager.cpp @@ -51,6 +51,7 @@ DrmManager::~DrmManager() { } int DrmManager::addUniqueId(int uniqueId) { + Mutex::Autolock _l(mLock); if (0 == uniqueId) { int temp = 0; bool foundUniqueId = false; @@ -78,6 +79,7 @@ int DrmManager::addUniqueId(int 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); @@ -107,6 +109,7 @@ status_t DrmManager::loadPlugIns(const String8& plugInDirPath) { } status_t DrmManager::unloadPlugIns() { + Mutex::Autolock _l(mLock); mConvertSessionMap.clear(); mDecryptSessionMap.clear(); mPlugInManager.unloadPlugIns(); @@ -126,6 +129,7 @@ status_t DrmManager::setDrmServiceListener( } void DrmManager::addClient(int uniqueId) { + Mutex::Autolock _l(mLock); if (!mSupportInfoToPlugInIdMap.isEmpty()) { Vector plugInIdList = mPlugInManager.getPlugInIdList(); for (unsigned int index = 0; index < plugInIdList.size(); index++) { @@ -137,6 +141,7 @@ void DrmManager::addClient(int uniqueId) { } void DrmManager::removeClient(int uniqueId) { + Mutex::Autolock _l(mLock); Vector plugInIdList = mPlugInManager.getPlugInIdList(); for (unsigned int index = 0; index < plugInIdList.size(); index++) { IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInIdList.itemAt(index)); @@ -145,6 +150,7 @@ void DrmManager::removeClient(int uniqueId) { } DrmConstraints* DrmManager::getConstraints(int uniqueId, const String8* path, const int action) { + Mutex::Autolock _l(mLock); const String8 plugInId = getSupportedPlugInIdFromPath(uniqueId, *path); if (EMPTY_STRING != plugInId) { IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); @@ -154,6 +160,7 @@ DrmConstraints* DrmManager::getConstraints(int uniqueId, const String8* path, co } DrmMetadata* DrmManager::getMetadata(int uniqueId, const String8* path) { + Mutex::Autolock _l(mLock); const String8 plugInId = getSupportedPlugInIdFromPath(uniqueId, *path); if (EMPTY_STRING != plugInId) { IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); @@ -163,6 +170,7 @@ DrmMetadata* DrmManager::getMetadata(int uniqueId, const String8* path) { } status_t DrmManager::installDrmEngine(int uniqueId, const String8& absolutePath) { + Mutex::Autolock _l(mLock); mPlugInManager.loadPlugIn(absolutePath); IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(absolutePath); @@ -176,6 +184,7 @@ status_t DrmManager::installDrmEngine(int uniqueId, const String8& absolutePath) } bool DrmManager::canHandle(int uniqueId, const String8& path, const String8& mimeType) { + Mutex::Autolock _l(mLock); const String8 plugInId = getSupportedPlugInId(mimeType); bool result = (EMPTY_STRING != plugInId) ? true : false; @@ -194,6 +203,7 @@ bool DrmManager::canHandle(int uniqueId, const String8& path, const String8& mim } DrmInfoStatus* DrmManager::processDrmInfo(int uniqueId, const DrmInfo* drmInfo) { + Mutex::Autolock _l(mLock); const String8 plugInId = getSupportedPlugInId(drmInfo->getMimeType()); if (EMPTY_STRING != plugInId) { IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); @@ -218,6 +228,7 @@ bool DrmManager::canHandle(int uniqueId, const String8& path) { } DrmInfo* DrmManager::acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest) { + Mutex::Autolock _l(mLock); const String8 plugInId = getSupportedPlugInId(drmInfoRequest->getMimeType()); if (EMPTY_STRING != plugInId) { IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); @@ -228,6 +239,7 @@ DrmInfo* DrmManager::acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoR status_t DrmManager::saveRights(int uniqueId, const DrmRights& drmRights, const String8& rightsPath, const String8& contentPath) { + Mutex::Autolock _l(mLock); const String8 plugInId = getSupportedPlugInId(drmRights.getMimeType()); status_t result = DRM_ERROR_UNKNOWN; if (EMPTY_STRING != plugInId) { @@ -238,6 +250,7 @@ status_t DrmManager::saveRights(int uniqueId, const DrmRights& drmRights, } String8 DrmManager::getOriginalMimeType(int uniqueId, const String8& path) { + Mutex::Autolock _l(mLock); const String8 plugInId = getSupportedPlugInIdFromPath(uniqueId, path); if (EMPTY_STRING != plugInId) { IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); @@ -247,6 +260,7 @@ String8 DrmManager::getOriginalMimeType(int uniqueId, const String8& path) { } int DrmManager::getDrmObjectType(int uniqueId, const String8& path, const String8& mimeType) { + Mutex::Autolock _l(mLock); const String8 plugInId = getSupportedPlugInId(uniqueId, path, mimeType); if (EMPTY_STRING != plugInId) { IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); @@ -256,6 +270,7 @@ int DrmManager::getDrmObjectType(int uniqueId, const String8& path, const String } int DrmManager::checkRightsStatus(int uniqueId, const String8& path, int action) { + Mutex::Autolock _l(mLock); const String8 plugInId = getSupportedPlugInIdFromPath(uniqueId, path); if (EMPTY_STRING != plugInId) { IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); @@ -267,6 +282,7 @@ int DrmManager::checkRightsStatus(int uniqueId, const String8& path, int action) status_t DrmManager::consumeRights( int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) { status_t result = DRM_ERROR_UNKNOWN; + Mutex::Autolock _l(mDecryptLock); if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) { IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId); result = drmEngine->consumeRights(uniqueId, decryptHandle, action, reserve); @@ -277,6 +293,7 @@ status_t DrmManager::consumeRights( status_t DrmManager::setPlaybackStatus( int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int64_t position) { status_t result = DRM_ERROR_UNKNOWN; + Mutex::Autolock _l(mDecryptLock); if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) { IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId); result = drmEngine->setPlaybackStatus(uniqueId, decryptHandle, playbackStatus, position); @@ -286,6 +303,7 @@ status_t DrmManager::setPlaybackStatus( bool DrmManager::validateAction( int uniqueId, const String8& path, int action, const ActionDescription& description) { + Mutex::Autolock _l(mLock); const String8 plugInId = getSupportedPlugInIdFromPath(uniqueId, path); if (EMPTY_STRING != plugInId) { IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); @@ -295,6 +313,7 @@ bool DrmManager::validateAction( } status_t DrmManager::removeRights(int uniqueId, const String8& path) { + Mutex::Autolock _l(mLock); const String8 plugInId = getSupportedPlugInIdFromPath(uniqueId, path); status_t result = DRM_ERROR_UNKNOWN; if (EMPTY_STRING != plugInId) { @@ -318,6 +337,7 @@ status_t DrmManager::removeAllRights(int uniqueId) { } int DrmManager::openConvertSession(int uniqueId, const String8& mimeType) { + Mutex::Autolock _l(mConvertLock); int convertId = -1; const String8 plugInId = getSupportedPlugInId(mimeType); @@ -325,7 +345,6 @@ int DrmManager::openConvertSession(int uniqueId, const String8& mimeType) { IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); if (DRM_NO_ERROR == rDrmEngine.openConvertSession(uniqueId, mConvertId + 1)) { - Mutex::Autolock _l(mConvertLock); ++mConvertId; convertId = mConvertId; mConvertSessionMap.add(convertId, &rDrmEngine); @@ -338,6 +357,7 @@ DrmConvertedStatus* DrmManager::convertData( int uniqueId, int convertId, const DrmBuffer* inputData) { DrmConvertedStatus *drmConvertedStatus = NULL; + Mutex::Autolock _l(mConvertLock); if (mConvertSessionMap.indexOfKey(convertId) != NAME_NOT_FOUND) { IDrmEngine* drmEngine = mConvertSessionMap.valueFor(convertId); drmConvertedStatus = drmEngine->convertData(uniqueId, convertId, inputData); @@ -346,6 +366,7 @@ DrmConvertedStatus* DrmManager::convertData( } DrmConvertedStatus* DrmManager::closeConvertSession(int uniqueId, int convertId) { + Mutex::Autolock _l(mConvertLock); DrmConvertedStatus *drmConvertedStatus = NULL; if (mConvertSessionMap.indexOfKey(convertId) != NAME_NOT_FOUND) { @@ -358,6 +379,7 @@ DrmConvertedStatus* DrmManager::closeConvertSession(int uniqueId, int convertId) status_t DrmManager::getAllSupportInfo( int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray) { + Mutex::Autolock _l(mLock); Vector plugInPathList = mPlugInManager.getPlugInIdList(); int size = plugInPathList.size(); int validPlugins = 0; @@ -437,7 +459,7 @@ DecryptHandle* DrmManager::openDecryptSession(int uniqueId, const char* uri) { } if (DRM_NO_ERROR != result) { delete handle; handle = NULL; - LOGE("DrmManager::openDecryptSession: no capable plug-in found"); + LOGV("DrmManager::openDecryptSession: no capable plug-in found"); } return handle; } @@ -458,6 +480,7 @@ status_t DrmManager::closeDecryptSession(int uniqueId, DecryptHandle* decryptHan status_t DrmManager::initializeDecryptUnit( int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo) { status_t result = DRM_ERROR_UNKNOWN; + Mutex::Autolock _l(mDecryptLock); if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) { IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId); result = drmEngine->initializeDecryptUnit(uniqueId, decryptHandle, decryptUnitId, headerInfo); @@ -468,6 +491,8 @@ status_t DrmManager::initializeDecryptUnit( status_t DrmManager::decrypt(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) { status_t result = DRM_ERROR_UNKNOWN; + + Mutex::Autolock _l(mDecryptLock); if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) { IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId); result = drmEngine->decrypt( @@ -479,6 +504,7 @@ status_t DrmManager::decrypt(int uniqueId, DecryptHandle* decryptHandle, int dec status_t DrmManager::finalizeDecryptUnit( int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) { status_t result = DRM_ERROR_UNKNOWN; + Mutex::Autolock _l(mDecryptLock); if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) { IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId); result = drmEngine->finalizeDecryptUnit(uniqueId, decryptHandle, decryptUnitId); @@ -490,6 +516,7 @@ ssize_t DrmManager::pread(int uniqueId, DecryptHandle* decryptHandle, void* buffer, ssize_t numBytes, off64_t offset) { ssize_t result = DECRYPT_FILE_ERROR; + Mutex::Autolock _l(mDecryptLock); if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) { IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId); result = drmEngine->pread(uniqueId, decryptHandle, buffer, numBytes, offset); -- cgit v1.1 From 0e0a5f9e0b7a7ca618e8a1f7ccecc57a17e0d1e2 Mon Sep 17 00:00:00 2001 From: Gloria Wang Date: Fri, 11 Mar 2011 14:07:21 -0800 Subject: - Some change on the DrmManager in order to support feature request 4082089. In DrmManager, we currently lock both processDrmInfo() and onInfo() which is ok for now since processDrmInfo() is async call, and it will return without waiting for onInfo() call. However, if we send an event in processDrmInfo(), we will got deadlock here because we need to invoke onInf() which will wait for processDrmInfo() to release the lock. Use different lock for onInfo(). - Remove some redundent mutex lock. Change-Id: I59c794f95ba1693425723224114fa975cf9b235f --- drm/drmserver/DrmManager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drm/drmserver') diff --git a/drm/drmserver/DrmManager.cpp b/drm/drmserver/DrmManager.cpp index 305bafc..1eee5f2 100644 --- a/drm/drmserver/DrmManager.cpp +++ b/drm/drmserver/DrmManager.cpp @@ -119,7 +119,7 @@ status_t DrmManager::unloadPlugIns() { status_t DrmManager::setDrmServiceListener( int uniqueId, const sp& drmServiceListener) { - Mutex::Autolock _l(mLock); + Mutex::Autolock _l(mListenerLock); if (NULL != drmServiceListener.get()) { mServiceListeners.add(uniqueId, drmServiceListener); } else { @@ -573,7 +573,7 @@ String8 DrmManager::getSupportedPlugInIdFromPath(int uniqueId, const String8& pa } void DrmManager::onInfo(const DrmInfoEvent& event) { - Mutex::Autolock _l(mLock); + Mutex::Autolock _l(mListenerLock); for (unsigned int index = 0; index < mServiceListeners.size(); index++) { int uniqueId = mServiceListeners.keyAt(index); -- cgit v1.1 From 41b3d3be18b54e72a44813cbdd180aae7e77b444 Mon Sep 17 00:00:00 2001 From: Glenn Kasten Date: Mon, 14 Mar 2011 11:32:29 -0700 Subject: Bug 4016329 do full string comparisons Use full string comparisons instead of partial for file extension and MIME type. Do case-insensitive comparison of MIME type and file extensions. Fix error in comment for String8::getPathExtension. Remove dead code -- StringTokenizer is unused. Change-Id: I322be6235abbdaab5f7eafa48926dbb2cf46dc29 --- drm/drmserver/Android.mk | 3 +- drm/drmserver/StringTokenizer.cpp | 66 --------------------------------------- 2 files changed, 1 insertion(+), 68 deletions(-) delete mode 100644 drm/drmserver/StringTokenizer.cpp (limited to 'drm/drmserver') diff --git a/drm/drmserver/Android.mk b/drm/drmserver/Android.mk index 5df2ff8..f94f9a3 100644 --- a/drm/drmserver/Android.mk +++ b/drm/drmserver/Android.mk @@ -19,8 +19,7 @@ include $(CLEAR_VARS) LOCAL_SRC_FILES:= \ main_drmserver.cpp \ DrmManager.cpp \ - DrmManagerService.cpp \ - StringTokenizer.cpp + DrmManagerService.cpp LOCAL_SHARED_LIBRARIES := \ libutils \ diff --git a/drm/drmserver/StringTokenizer.cpp b/drm/drmserver/StringTokenizer.cpp deleted file mode 100644 index 2130a00..0000000 --- a/drm/drmserver/StringTokenizer.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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. - */ - -#include "StringTokenizer.h" - -using namespace android; - -StringTokenizer::StringTokenizer(const String8& string, const String8& delimiter) { - splitString(string, delimiter); -} - -void StringTokenizer::splitString(const String8& string, const String8& delimiter) { - for (unsigned int i = 0; i < string.length(); i++) { - unsigned int position = string.find(delimiter.string(), i); - if (string.length() != position) { - String8 token(string.string()+i, position-i); - if (token.length()) { - mStringTokenizerVector.push(token); - i = position + delimiter.length() - 1; - } - } else { - mStringTokenizerVector.push(String8(string.string()+i, string.length()-i)); - break; - } - } -} - -StringTokenizer::Iterator StringTokenizer::iterator() { - return Iterator(this); -} - -StringTokenizer::Iterator::Iterator(const StringTokenizer::Iterator& iterator) : - mStringTokenizer(iterator.mStringTokenizer), - mIndex(iterator.mIndex) { -} - -StringTokenizer::Iterator& StringTokenizer::Iterator::operator=( - const StringTokenizer::Iterator& iterator) { - mStringTokenizer = iterator.mStringTokenizer; - mIndex = iterator.mIndex; - return *this; -} - -bool StringTokenizer::Iterator::hasNext() { - return mIndex < mStringTokenizer->mStringTokenizerVector.size(); -} - -String8& StringTokenizer::Iterator::next() { - String8& value = mStringTokenizer->mStringTokenizerVector.editItemAt(mIndex); - mIndex++; - return value; -} - -- cgit v1.1 From 8635b7b095fbf7ffc63d3ce791891a9116ace1f6 Mon Sep 17 00:00:00 2001 From: James Dong Date: Mon, 14 Mar 2011 17:01:38 -0700 Subject: Add memory leak tracking/debugging code to drm server bug - 4099038 Change-Id: I6c048eaf3d7f34bc144b8daaa5fdef1ed474af66 --- drm/drmserver/Android.mk | 1 + drm/drmserver/DrmManagerService.cpp | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) (limited to 'drm/drmserver') diff --git a/drm/drmserver/Android.mk b/drm/drmserver/Android.mk index 5df2ff8..b5ad147 100644 --- a/drm/drmserver/Android.mk +++ b/drm/drmserver/Android.mk @@ -23,6 +23,7 @@ LOCAL_SRC_FILES:= \ StringTokenizer.cpp LOCAL_SHARED_LIBRARIES := \ + libmedia \ libutils \ libbinder diff --git a/drm/drmserver/DrmManagerService.cpp b/drm/drmserver/DrmManagerService.cpp index 0901a44..583669e 100644 --- a/drm/drmserver/DrmManagerService.cpp +++ b/drm/drmserver/DrmManagerService.cpp @@ -19,6 +19,7 @@ #include #include +#include #include #include @@ -256,3 +257,31 @@ ssize_t DrmManagerService::pread(int uniqueId, DecryptHandle* decryptHandle, return mDrmManager->pread(uniqueId, decryptHandle, buffer, numBytes, offset); } +status_t DrmManagerService::dump(int fd, const Vector& args) +{ + const size_t SIZE = 256; + char buffer[SIZE]; + String8 result; + if (checkCallingPermission(String16("android.permission.DUMP")) == false) { + snprintf(buffer, SIZE, "Permission Denial: " + "can't dump DrmManagerService from pid=%d, uid=%d\n", + IPCThreadState::self()->getCallingPid(), + IPCThreadState::self()->getCallingUid()); + result.append(buffer); + } else { +#if DRM_MEMORY_LEAK_TRACK + bool dumpMem = false; + for (size_t i = 0; i < args.size(); i++) { + if (args[i] == String16("-m")) { + dumpMem = true; + } + } + if (dumpMem) { + dumpMemoryAddresses(fd); + } +#endif + } + write(fd, result.string(), result.size()); + return NO_ERROR; +} + -- cgit v1.1 From 8d2577b9ac2f95f218db59a78447efd3c6a742dd Mon Sep 17 00:00:00 2001 From: Gloria Wang Date: Tue, 15 Mar 2011 10:52:28 -0700 Subject: Bug fixes of DRM framework. - Add death listener to clean-up drmserver appropriately when drmserver died. - Remove "static" declaration of mUniqueIdVector because it was not needed to be static variable. - Remove "class DrmContentIds;" because the class does not exist. - contentPath in saveRights() could be empty because it is not required by some DRM schemes. - Fix naming convention to use sXXX for static variables. - Fix typo Change-Id: I7d440488fc074c200f1009d1bafafeffebd690b2 --- drm/drmserver/DrmManager.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'drm/drmserver') diff --git a/drm/drmserver/DrmManager.cpp b/drm/drmserver/DrmManager.cpp index 305bafc..f44c06d 100644 --- a/drm/drmserver/DrmManager.cpp +++ b/drm/drmserver/DrmManager.cpp @@ -37,7 +37,6 @@ using namespace android; -Vector DrmManager::mUniqueIdVector; const String8 DrmManager::EMPTY_STRING(""); DrmManager::DrmManager() : -- cgit v1.1 From adfb5592622305090ad39dcc2b7df477736da2c6 Mon Sep 17 00:00:00 2001 From: James Dong Date: Sun, 24 Apr 2011 12:38:35 -0700 Subject: Fix memory leak from retrieval of getSupportedDrmInfo. Change-Id: Ic2192a9791c0a3c5e5357b4367a2d8bfb15af20c --- drm/drmserver/DrmManager.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'drm/drmserver') diff --git a/drm/drmserver/DrmManager.cpp b/drm/drmserver/DrmManager.cpp index 2fee59c..1809619 100644 --- a/drm/drmserver/DrmManager.cpp +++ b/drm/drmserver/DrmManager.cpp @@ -101,6 +101,7 @@ status_t DrmManager::loadPlugIns(const String8& plugInDirPath) { DrmSupportInfo* info = mPlugInManager.getPlugIn(plugInPath).getSupportInfo(0); if (NULL != info) { mSupportInfoToPlugInIdMap.add(*info, plugInPath); + delete info; } } } @@ -178,6 +179,7 @@ status_t DrmManager::installDrmEngine(int uniqueId, const String8& absolutePath) DrmSupportInfo* info = rDrmEngine.getSupportInfo(0); mSupportInfoToPlugInIdMap.add(*info, absolutePath); + delete info; return DRM_NO_ERROR; } -- cgit v1.1 From 5e0067b486c3862316aa1f293cf9690c0cf54bda Mon Sep 17 00:00:00 2001 From: Jeff Brown Date: Mon, 11 Jul 2011 22:12:16 -0700 Subject: Remove the simulator target from all makefiles. Bug: 5010576 Change-Id: I04d722f258951a3078fe07899f5bbe8aac02a8e8 --- drm/drmserver/Android.mk | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'drm/drmserver') diff --git a/drm/drmserver/Android.mk b/drm/drmserver/Android.mk index e3cd44f..fd417cb 100644 --- a/drm/drmserver/Android.mk +++ b/drm/drmserver/Android.mk @@ -24,13 +24,8 @@ LOCAL_SRC_FILES:= \ LOCAL_SHARED_LIBRARIES := \ libmedia \ libutils \ - libbinder - -ifeq ($(TARGET_SIMULATOR),true) - LOCAL_LDLIBS += -ldl -else - LOCAL_SHARED_LIBRARIES += libdl -endif + libbinder \ + libdl LOCAL_STATIC_LIBRARIES := libdrmframeworkcommon -- cgit v1.1 From 8f00151cbe693d52f3e233757c57fab3b6396d21 Mon Sep 17 00:00:00 2001 From: Gloria Wang Date: Thu, 21 Jul 2011 15:10:22 -0700 Subject: 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 --- drm/drmserver/DrmManager.cpp | 54 ++++++++++++++++++++++--------------- drm/drmserver/DrmManagerService.cpp | 4 +-- 2 files changed, 34 insertions(+), 24 deletions(-) (limited to 'drm/drmserver') 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) { -- cgit v1.1 From 5f6f4e4e89bc9b234d89276aea3eae7f677e2ff7 Mon Sep 17 00:00:00 2001 From: Edwin Wong Date: Wed, 21 Sep 2011 19:18:30 -0700 Subject: Modified loadPlugIns to load from /vendor and /system; skip libraries that are already loaded. BUG: 5284436 Change-Id: I99267c81a488860c3c7edb747100d44f3083bfc2 --- drm/drmserver/DrmManager.cpp | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'drm/drmserver') diff --git a/drm/drmserver/DrmManager.cpp b/drm/drmserver/DrmManager.cpp index 3e4fe8c..b2fa053 100644 --- a/drm/drmserver/DrmManager.cpp +++ b/drm/drmserver/DrmManager.cpp @@ -98,21 +98,27 @@ void DrmManager::removeUniqueId(int uniqueId) { } status_t DrmManager::loadPlugIns() { + + String8 vendorPluginDirPath("/vendor/lib/drm"); + loadPlugIns(vendorPluginDirPath); + String8 pluginDirPath("/system/lib/drm"); - return loadPlugIns(pluginDirPath); + loadPlugIns(pluginDirPath); + return DRM_NO_ERROR; + } status_t DrmManager::loadPlugIns(const String8& plugInDirPath) { - if (mSupportInfoToPlugInIdMap.isEmpty()) { - mPlugInManager.loadPlugIns(plugInDirPath); - Vector 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) { + mPlugInManager.loadPlugIns(plugInDirPath); + Vector 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) { mSupportInfoToPlugInIdMap.add(*info, plugInPath); - delete info; } + delete info; } } return DRM_NO_ERROR; -- cgit v1.1 From 3856b090cd04ba5dd4a59a12430ed724d5995909 Mon Sep 17 00:00:00 2001 From: Steve Block Date: Thu, 20 Oct 2011 11:56:00 +0100 Subject: Rename (IF_)LOGV(_IF) to (IF_)ALOGV(_IF) DO NOT MERGE See https://android-git.corp.google.com/g/#/c/143865 Bug: 5449033 Change-Id: I0122812ed6ff6f5b59fe4a43ab8bff0577adde0a --- drm/drmserver/DrmManager.cpp | 2 +- drm/drmserver/DrmManagerService.cpp | 60 ++++++++++++++++++------------------- 2 files changed, 31 insertions(+), 31 deletions(-) (limited to 'drm/drmserver') diff --git a/drm/drmserver/DrmManager.cpp b/drm/drmserver/DrmManager.cpp index b2fa053..3abf3d3 100644 --- a/drm/drmserver/DrmManager.cpp +++ b/drm/drmserver/DrmManager.cpp @@ -476,7 +476,7 @@ DecryptHandle* DrmManager::openDecryptSession(int uniqueId, const char* uri) { } if (DRM_NO_ERROR != result) { delete handle; handle = NULL; - LOGV("DrmManager::openDecryptSession: no capable plug-in found"); + ALOGV("DrmManager::openDecryptSession: no capable plug-in found"); } return handle; } diff --git a/drm/drmserver/DrmManagerService.cpp b/drm/drmserver/DrmManagerService.cpp index 7ebcac3..df17ac5 100644 --- a/drm/drmserver/DrmManagerService.cpp +++ b/drm/drmserver/DrmManagerService.cpp @@ -52,7 +52,7 @@ static bool isProtectedCallAllowed() { } void DrmManagerService::instantiate() { - LOGV("instantiate"); + ALOGV("instantiate"); defaultServiceManager()->addService(String16("drm.drmManager"), new DrmManagerService()); if (0 >= trustedUids.size()) { @@ -67,13 +67,13 @@ void DrmManagerService::instantiate() { DrmManagerService::DrmManagerService() : mDrmManager(NULL) { - LOGV("created"); + ALOGV("created"); mDrmManager = new DrmManager(); mDrmManager->loadPlugIns(); } DrmManagerService::~DrmManagerService() { - LOGV("Destroyed"); + ALOGV("Destroyed"); mDrmManager->unloadPlugIns(); delete mDrmManager; mDrmManager = NULL; } @@ -96,120 +96,120 @@ void DrmManagerService::removeClient(int uniqueId) { status_t DrmManagerService::setDrmServiceListener( int uniqueId, const sp& drmServiceListener) { - LOGV("Entering setDrmServiceListener"); + ALOGV("Entering setDrmServiceListener"); mDrmManager->setDrmServiceListener(uniqueId, drmServiceListener); return DRM_NO_ERROR; } status_t DrmManagerService::installDrmEngine(int uniqueId, const String8& drmEngineFile) { - LOGV("Entering installDrmEngine"); + ALOGV("Entering installDrmEngine"); return mDrmManager->installDrmEngine(uniqueId, drmEngineFile); } DrmConstraints* DrmManagerService::getConstraints( int uniqueId, const String8* path, const int action) { - LOGV("Entering getConstraints from content"); + ALOGV("Entering getConstraints from content"); return mDrmManager->getConstraints(uniqueId, path, action); } DrmMetadata* DrmManagerService::getMetadata(int uniqueId, const String8* path) { - LOGV("Entering getMetadata from content"); + ALOGV("Entering getMetadata from content"); return mDrmManager->getMetadata(uniqueId, path); } bool DrmManagerService::canHandle(int uniqueId, const String8& path, const String8& mimeType) { - LOGV("Entering canHandle"); + ALOGV("Entering canHandle"); return mDrmManager->canHandle(uniqueId, path, mimeType); } DrmInfoStatus* DrmManagerService::processDrmInfo(int uniqueId, const DrmInfo* drmInfo) { - LOGV("Entering processDrmInfo"); + ALOGV("Entering processDrmInfo"); return mDrmManager->processDrmInfo(uniqueId, drmInfo); } DrmInfo* DrmManagerService::acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest) { - LOGV("Entering acquireDrmInfo"); + ALOGV("Entering acquireDrmInfo"); return mDrmManager->acquireDrmInfo(uniqueId, drmInfoRequest); } status_t DrmManagerService::saveRights( int uniqueId, const DrmRights& drmRights, const String8& rightsPath, const String8& contentPath) { - LOGV("Entering saveRights"); + ALOGV("Entering saveRights"); return mDrmManager->saveRights(uniqueId, drmRights, rightsPath, contentPath); } String8 DrmManagerService::getOriginalMimeType(int uniqueId, const String8& path) { - LOGV("Entering getOriginalMimeType"); + ALOGV("Entering getOriginalMimeType"); return mDrmManager->getOriginalMimeType(uniqueId, path); } int DrmManagerService::getDrmObjectType( int uniqueId, const String8& path, const String8& mimeType) { - LOGV("Entering getDrmObjectType"); + ALOGV("Entering getDrmObjectType"); return mDrmManager->getDrmObjectType(uniqueId, path, mimeType); } int DrmManagerService::checkRightsStatus( int uniqueId, const String8& path, int action) { - LOGV("Entering checkRightsStatus"); + ALOGV("Entering checkRightsStatus"); return mDrmManager->checkRightsStatus(uniqueId, path, action); } status_t DrmManagerService::consumeRights( int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) { - LOGV("Entering consumeRights"); + ALOGV("Entering consumeRights"); return mDrmManager->consumeRights(uniqueId, decryptHandle, action, reserve); } status_t DrmManagerService::setPlaybackStatus( int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int64_t position) { - LOGV("Entering setPlaybackStatus"); + ALOGV("Entering setPlaybackStatus"); return mDrmManager->setPlaybackStatus(uniqueId, decryptHandle, playbackStatus, position); } bool DrmManagerService::validateAction( int uniqueId, const String8& path, int action, const ActionDescription& description) { - LOGV("Entering validateAction"); + ALOGV("Entering validateAction"); return mDrmManager->validateAction(uniqueId, path, action, description); } status_t DrmManagerService::removeRights(int uniqueId, const String8& path) { - LOGV("Entering removeRights"); + ALOGV("Entering removeRights"); return mDrmManager->removeRights(uniqueId, path); } status_t DrmManagerService::removeAllRights(int uniqueId) { - LOGV("Entering removeAllRights"); + ALOGV("Entering removeAllRights"); return mDrmManager->removeAllRights(uniqueId); } int DrmManagerService::openConvertSession(int uniqueId, const String8& mimeType) { - LOGV("Entering openConvertSession"); + ALOGV("Entering openConvertSession"); return mDrmManager->openConvertSession(uniqueId, mimeType); } DrmConvertedStatus* DrmManagerService::convertData( int uniqueId, int convertId, const DrmBuffer* inputData) { - LOGV("Entering convertData"); + ALOGV("Entering convertData"); return mDrmManager->convertData(uniqueId, convertId, inputData); } DrmConvertedStatus* DrmManagerService::closeConvertSession(int uniqueId, int convertId) { - LOGV("Entering closeConvertSession"); + ALOGV("Entering closeConvertSession"); return mDrmManager->closeConvertSession(uniqueId, convertId); } status_t DrmManagerService::getAllSupportInfo( int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray) { - LOGV("Entering getAllSupportInfo"); + ALOGV("Entering getAllSupportInfo"); return mDrmManager->getAllSupportInfo(uniqueId, length, drmSupportInfoArray); } DecryptHandle* DrmManagerService::openDecryptSession( int uniqueId, int fd, off64_t offset, off64_t length) { - LOGV("Entering DrmManagerService::openDecryptSession"); + ALOGV("Entering DrmManagerService::openDecryptSession"); if (isProtectedCallAllowed()) { return mDrmManager->openDecryptSession(uniqueId, fd, offset, length); } @@ -219,7 +219,7 @@ DecryptHandle* DrmManagerService::openDecryptSession( DecryptHandle* DrmManagerService::openDecryptSession( int uniqueId, const char* uri) { - LOGV("Entering DrmManagerService::openDecryptSession with uri"); + ALOGV("Entering DrmManagerService::openDecryptSession with uri"); if (isProtectedCallAllowed()) { return mDrmManager->openDecryptSession(uniqueId, uri); } @@ -228,32 +228,32 @@ DecryptHandle* DrmManagerService::openDecryptSession( } status_t DrmManagerService::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) { - LOGV("Entering closeDecryptSession"); + ALOGV("Entering closeDecryptSession"); return mDrmManager->closeDecryptSession(uniqueId, decryptHandle); } status_t DrmManagerService::initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo) { - LOGV("Entering initializeDecryptUnit"); + ALOGV("Entering initializeDecryptUnit"); return mDrmManager->initializeDecryptUnit(uniqueId,decryptHandle, decryptUnitId, headerInfo); } status_t DrmManagerService::decrypt( int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) { - LOGV("Entering decrypt"); + ALOGV("Entering decrypt"); return mDrmManager->decrypt(uniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer, IV); } status_t DrmManagerService::finalizeDecryptUnit( int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) { - LOGV("Entering finalizeDecryptUnit"); + ALOGV("Entering finalizeDecryptUnit"); return mDrmManager->finalizeDecryptUnit(uniqueId, decryptHandle, decryptUnitId); } ssize_t DrmManagerService::pread(int uniqueId, DecryptHandle* decryptHandle, void* buffer, ssize_t numBytes, off64_t offset) { - LOGV("Entering pread"); + ALOGV("Entering pread"); return mDrmManager->pread(uniqueId, decryptHandle, buffer, numBytes, offset); } -- cgit v1.1 From 40ddcb7150a31052ba20878454426dc3572b7acb Mon Sep 17 00:00:00 2001 From: Glenn Kasten Date: Thu, 10 Nov 2011 14:58:44 -0800 Subject: Fix log message Log did not have a tag, and was wrong level Change-Id: I8d12895c80483e1e39f117a393b8be2f4bdd3e1d --- drm/drmserver/main_drmserver.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'drm/drmserver') diff --git a/drm/drmserver/main_drmserver.cpp b/drm/drmserver/main_drmserver.cpp index 6d10646..e61b269 100644 --- a/drm/drmserver/main_drmserver.cpp +++ b/drm/drmserver/main_drmserver.cpp @@ -14,6 +14,9 @@ * limitations under the License. */ +#define LOG_TAG "drmserver" +//#define LOG_NDEBUG 0 + #include #include #include @@ -32,7 +35,7 @@ int main(int argc, char** argv) { sp proc(ProcessState::self()); sp sm = defaultServiceManager(); - LOGI("ServiceManager: %p", sm.get()); + ALOGV("ServiceManager: %p", sm.get()); DrmManagerService::instantiate(); ProcessState::self()->startThreadPool(); IPCThreadState::self()->joinThreadPool(); -- cgit v1.1 From a9d421d3c05b98ee5481428ca3dcb3e3245140ff Mon Sep 17 00:00:00 2001 From: Jeff Tinker Date: Fri, 9 Dec 2011 20:04:17 -0800 Subject: Fix drm enumeration order, resolves failure to play forward lock ringtones Change-Id: I58e8a26849409bc3bf98b066c5e07c2a0c91e0c9 related-to-bug: 5735466 --- drm/drmserver/DrmManager.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'drm/drmserver') diff --git a/drm/drmserver/DrmManager.cpp b/drm/drmserver/DrmManager.cpp index b2fa053..eaf884d 100644 --- a/drm/drmserver/DrmManager.cpp +++ b/drm/drmserver/DrmManager.cpp @@ -99,11 +99,12 @@ void DrmManager::removeUniqueId(int uniqueId) { status_t DrmManager::loadPlugIns() { + String8 pluginDirPath("/system/lib/drm"); + loadPlugIns(pluginDirPath); + String8 vendorPluginDirPath("/vendor/lib/drm"); loadPlugIns(vendorPluginDirPath); - String8 pluginDirPath("/system/lib/drm"); - loadPlugIns(pluginDirPath); return DRM_NO_ERROR; } -- cgit v1.1 From 785ee06d106cd7958e0c151ebc6b7174d9ba861e Mon Sep 17 00:00:00 2001 From: James Dong Date: Wed, 14 Dec 2011 10:57:05 -0800 Subject: Revert the following patches because they may lead to power regression because SHA/MD5 module is stuck 1. Revert "Fix drm flag setting missed in false drm recognition fix." This reverts commit 9f704f6c46a171357e49c411c83458b9d4565f3b. 2. Revert "Fixed the false drm recognition." This reverts commit aadbd80b307c817698ce5110ff8e002804d1b230. 3. Revert "Fix drm enumeration order, resolves failure to play forward lock ringtones" This reverts commit a5cbf023e349f2394ba6fc58d73b4375cfec4369. 4. Revert "Fix ANRs due to Widevine DRM plugin sniff taking too long." This reverts commit d0d19db1ca1c289b069db33f4665bcb9386064e9. As a result of the reverting, many ANRs from WV sniffing are back. related-to-bug: 5739618 --- drm/drmserver/DrmManager.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'drm/drmserver') diff --git a/drm/drmserver/DrmManager.cpp b/drm/drmserver/DrmManager.cpp index eaf884d..b2fa053 100644 --- a/drm/drmserver/DrmManager.cpp +++ b/drm/drmserver/DrmManager.cpp @@ -99,12 +99,11 @@ void DrmManager::removeUniqueId(int uniqueId) { status_t DrmManager::loadPlugIns() { - String8 pluginDirPath("/system/lib/drm"); - loadPlugIns(pluginDirPath); - String8 vendorPluginDirPath("/vendor/lib/drm"); loadPlugIns(vendorPluginDirPath); + String8 pluginDirPath("/system/lib/drm"); + loadPlugIns(pluginDirPath); return DRM_NO_ERROR; } -- cgit v1.1 From 9d2f386dd2885eaffa11fd494ae258bb09fe6397 Mon Sep 17 00:00:00 2001 From: James Dong Date: Tue, 10 Jan 2012 08:24:37 -0800 Subject: Separate sniffing from session initialization This avoid lengthy/duplicate sniffing for drm plugins when a decrypt session is opened o The change is backward compatibile in that no update is required for existing drm plug-ins if they do not plan to provide separate sniffer/extractor related-to-bug: 5725548 Change-Id: I7fc4caf82d77472da4e2bc7b5d31060fb54fd84c --- drm/drmserver/DrmManager.cpp | 11 +++++++---- drm/drmserver/DrmManagerService.cpp | 8 ++++---- 2 files changed, 11 insertions(+), 8 deletions(-) (limited to 'drm/drmserver') diff --git a/drm/drmserver/DrmManager.cpp b/drm/drmserver/DrmManager.cpp index 3abf3d3..999295a 100644 --- a/drm/drmserver/DrmManager.cpp +++ b/drm/drmserver/DrmManager.cpp @@ -426,7 +426,9 @@ status_t DrmManager::getAllSupportInfo( return DRM_NO_ERROR; } -DecryptHandle* DrmManager::openDecryptSession(int uniqueId, int fd, off64_t offset, off64_t length) { +DecryptHandle* DrmManager::openDecryptSession( + int uniqueId, int fd, off64_t offset, off64_t length, const char* mime) { + Mutex::Autolock _l(mDecryptLock); status_t result = DRM_ERROR_CANNOT_HANDLE; Vector plugInIdList = mPlugInManager.getPlugInIdList(); @@ -438,7 +440,7 @@ DecryptHandle* DrmManager::openDecryptSession(int uniqueId, int fd, off64_t offs for (unsigned int index = 0; index < plugInIdList.size(); index++) { String8 plugInId = plugInIdList.itemAt(index); IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); - result = rDrmEngine.openDecryptSession(uniqueId, handle, fd, offset, length); + result = rDrmEngine.openDecryptSession(uniqueId, handle, fd, offset, length, mime); if (DRM_NO_ERROR == result) { ++mDecryptSessionId; @@ -453,7 +455,8 @@ DecryptHandle* DrmManager::openDecryptSession(int uniqueId, int fd, off64_t offs return handle; } -DecryptHandle* DrmManager::openDecryptSession(int uniqueId, const char* uri) { +DecryptHandle* DrmManager::openDecryptSession( + int uniqueId, const char* uri, const char* mime) { Mutex::Autolock _l(mDecryptLock); status_t result = DRM_ERROR_CANNOT_HANDLE; Vector plugInIdList = mPlugInManager.getPlugInIdList(); @@ -465,7 +468,7 @@ DecryptHandle* DrmManager::openDecryptSession(int uniqueId, const char* uri) { for (unsigned int index = 0; index < plugInIdList.size(); index++) { String8 plugInId = plugInIdList.itemAt(index); IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); - result = rDrmEngine.openDecryptSession(uniqueId, handle, uri); + result = rDrmEngine.openDecryptSession(uniqueId, handle, uri, mime); if (DRM_NO_ERROR == result) { ++mDecryptSessionId; diff --git a/drm/drmserver/DrmManagerService.cpp b/drm/drmserver/DrmManagerService.cpp index df17ac5..caeb026 100644 --- a/drm/drmserver/DrmManagerService.cpp +++ b/drm/drmserver/DrmManagerService.cpp @@ -208,20 +208,20 @@ status_t DrmManagerService::getAllSupportInfo( } DecryptHandle* DrmManagerService::openDecryptSession( - int uniqueId, int fd, off64_t offset, off64_t length) { + int uniqueId, int fd, off64_t offset, off64_t length, const char* mime) { ALOGV("Entering DrmManagerService::openDecryptSession"); if (isProtectedCallAllowed()) { - return mDrmManager->openDecryptSession(uniqueId, fd, offset, length); + return mDrmManager->openDecryptSession(uniqueId, fd, offset, length, mime); } return NULL; } DecryptHandle* DrmManagerService::openDecryptSession( - int uniqueId, const char* uri) { + int uniqueId, const char* uri, const char* mime) { ALOGV("Entering DrmManagerService::openDecryptSession with uri"); if (isProtectedCallAllowed()) { - return mDrmManager->openDecryptSession(uniqueId, uri); + return mDrmManager->openDecryptSession(uniqueId, uri, mime); } return NULL; -- cgit v1.1 From d907e9451ec3c7b2244dd5605f1a26ab23466a7a Mon Sep 17 00:00:00 2001 From: James Dong Date: Mon, 27 Feb 2012 22:20:28 -0800 Subject: Remove unnecessary header file includes for drmserver Change-Id: I14033861e74d20f9d4897b651c4eeee126d4d610 --- drm/drmserver/main_drmserver.cpp | 5 ----- 1 file changed, 5 deletions(-) (limited to 'drm/drmserver') diff --git a/drm/drmserver/main_drmserver.cpp b/drm/drmserver/main_drmserver.cpp index e61b269..434d561 100644 --- a/drm/drmserver/main_drmserver.cpp +++ b/drm/drmserver/main_drmserver.cpp @@ -17,15 +17,10 @@ #define LOG_TAG "drmserver" //#define LOG_NDEBUG 0 -#include -#include -#include - #include #include #include #include -#include #include -- cgit v1.1 From 328745b130c1c59e53d68a9a3c71675d3932d34b Mon Sep 17 00:00:00 2001 From: James Dong Date: Tue, 28 Feb 2012 13:55:55 -0800 Subject: Added permission check for all sensitive drm API calls o all drm calls using a DecryptHandle now check the permission before proceeding Change-Id: Ic992a991357876c6e4bfbfab4f5eec1fa0634a13 --- drm/drmserver/DrmManagerService.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'drm/drmserver') diff --git a/drm/drmserver/DrmManagerService.cpp b/drm/drmserver/DrmManagerService.cpp index caeb026..8ba0203 100644 --- a/drm/drmserver/DrmManagerService.cpp +++ b/drm/drmserver/DrmManagerService.cpp @@ -159,12 +159,18 @@ int DrmManagerService::checkRightsStatus( status_t DrmManagerService::consumeRights( int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) { ALOGV("Entering consumeRights"); + if (!isProtectedCallAllowed()) { + return DRM_ERROR_NO_PERMISSION; + } return mDrmManager->consumeRights(uniqueId, decryptHandle, action, reserve); } status_t DrmManagerService::setPlaybackStatus( int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int64_t position) { ALOGV("Entering setPlaybackStatus"); + if (!isProtectedCallAllowed()) { + return DRM_ERROR_NO_PERMISSION; + } return mDrmManager->setPlaybackStatus(uniqueId, decryptHandle, playbackStatus, position); } @@ -229,12 +235,18 @@ DecryptHandle* DrmManagerService::openDecryptSession( status_t DrmManagerService::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) { ALOGV("Entering closeDecryptSession"); + if (!isProtectedCallAllowed()) { + return DRM_ERROR_NO_PERMISSION; + } return mDrmManager->closeDecryptSession(uniqueId, decryptHandle); } status_t DrmManagerService::initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo) { ALOGV("Entering initializeDecryptUnit"); + if (!isProtectedCallAllowed()) { + return DRM_ERROR_NO_PERMISSION; + } return mDrmManager->initializeDecryptUnit(uniqueId,decryptHandle, decryptUnitId, headerInfo); } @@ -242,18 +254,27 @@ status_t DrmManagerService::decrypt( int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) { ALOGV("Entering decrypt"); + if (!isProtectedCallAllowed()) { + return DRM_ERROR_NO_PERMISSION; + } return mDrmManager->decrypt(uniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer, IV); } status_t DrmManagerService::finalizeDecryptUnit( int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) { ALOGV("Entering finalizeDecryptUnit"); + if (!isProtectedCallAllowed()) { + return DRM_ERROR_NO_PERMISSION; + } return mDrmManager->finalizeDecryptUnit(uniqueId, decryptHandle, decryptUnitId); } ssize_t DrmManagerService::pread(int uniqueId, DecryptHandle* decryptHandle, void* buffer, ssize_t numBytes, off64_t offset) { ALOGV("Entering pread"); + if (!isProtectedCallAllowed()) { + return DRM_ERROR_NO_PERMISSION; + } return mDrmManager->pread(uniqueId, decryptHandle, buffer, numBytes, offset); } -- cgit v1.1