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/common/Android.mk | 41 + drm/common/DrmConstraints.cpp | 117 ++ drm/common/DrmConvertedStatus.cpp | 28 + drm/common/DrmEngineBase.cpp | 147 +++ drm/common/DrmInfo.cpp | 111 ++ drm/common/DrmInfoEvent.cpp | 44 + drm/common/DrmInfoRequest.cpp | 106 ++ drm/common/DrmInfoStatus.cpp | 28 + drm/common/DrmRights.cpp | 51 + drm/common/DrmSupportInfo.cpp | 155 +++ drm/common/IDrmIOService.cpp | 78 ++ drm/common/IDrmManagerService.cpp | 1358 ++++++++++++++++++++ drm/common/IDrmServiceListener.cpp | 65 + drm/common/ReadWriteUtils.cpp | 100 ++ 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 + drm/libdrmframework/Android.mk | 42 + drm/libdrmframework/DrmManagerClient.cpp | 159 +++ drm/libdrmframework/DrmManagerClientImpl.cpp | 319 +++++ drm/libdrmframework/include/DrmIOService.h | 46 + drm/libdrmframework/include/DrmManager.h | 153 +++ drm/libdrmframework/include/DrmManagerClientImpl.h | 400 ++++++ drm/libdrmframework/include/DrmManagerService.h | 119 ++ drm/libdrmframework/include/IDrmIOService.h | 86 ++ drm/libdrmframework/include/IDrmManagerService.h | 242 ++++ drm/libdrmframework/include/IDrmServiceListener.h | 71 + drm/libdrmframework/include/PlugInManager.h | 273 ++++ drm/libdrmframework/include/ReadWriteUtils.h | 71 + drm/libdrmframework/include/StringTokenizer.h | 87 ++ drm/libdrmframework/plugins/Android.mk | 16 + .../plugins/common/include/DrmEngineBase.h | 411 ++++++ .../plugins/common/include/IDrmEngine.h | 371 ++++++ drm/libdrmframework/plugins/passthru/Android.mk | 44 + .../plugins/passthru/include/DrmPassthruPlugIn.h | 97 ++ .../plugins/passthru/src/DrmPassthruPlugIn.cpp | 280 ++++ 38 files changed, 6554 insertions(+) create mode 100644 drm/common/Android.mk create mode 100644 drm/common/DrmConstraints.cpp create mode 100644 drm/common/DrmConvertedStatus.cpp create mode 100644 drm/common/DrmEngineBase.cpp create mode 100644 drm/common/DrmInfo.cpp create mode 100644 drm/common/DrmInfoEvent.cpp create mode 100644 drm/common/DrmInfoRequest.cpp create mode 100644 drm/common/DrmInfoStatus.cpp create mode 100644 drm/common/DrmRights.cpp create mode 100644 drm/common/DrmSupportInfo.cpp create mode 100644 drm/common/IDrmIOService.cpp create mode 100644 drm/common/IDrmManagerService.cpp create mode 100644 drm/common/IDrmServiceListener.cpp create mode 100644 drm/common/ReadWriteUtils.cpp 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 create mode 100644 drm/libdrmframework/Android.mk create mode 100644 drm/libdrmframework/DrmManagerClient.cpp create mode 100644 drm/libdrmframework/DrmManagerClientImpl.cpp create mode 100644 drm/libdrmframework/include/DrmIOService.h create mode 100644 drm/libdrmframework/include/DrmManager.h create mode 100644 drm/libdrmframework/include/DrmManagerClientImpl.h create mode 100644 drm/libdrmframework/include/DrmManagerService.h create mode 100644 drm/libdrmframework/include/IDrmIOService.h create mode 100644 drm/libdrmframework/include/IDrmManagerService.h create mode 100644 drm/libdrmframework/include/IDrmServiceListener.h create mode 100644 drm/libdrmframework/include/PlugInManager.h create mode 100644 drm/libdrmframework/include/ReadWriteUtils.h create mode 100644 drm/libdrmframework/include/StringTokenizer.h create mode 100644 drm/libdrmframework/plugins/Android.mk create mode 100644 drm/libdrmframework/plugins/common/include/DrmEngineBase.h create mode 100644 drm/libdrmframework/plugins/common/include/IDrmEngine.h create mode 100644 drm/libdrmframework/plugins/passthru/Android.mk create mode 100644 drm/libdrmframework/plugins/passthru/include/DrmPassthruPlugIn.h create mode 100644 drm/libdrmframework/plugins/passthru/src/DrmPassthruPlugIn.cpp (limited to 'drm') diff --git a/drm/common/Android.mk b/drm/common/Android.mk new file mode 100644 index 0000000..249fe8e --- /dev/null +++ b/drm/common/Android.mk @@ -0,0 +1,41 @@ +# +# 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:= \ + DrmConstraints.cpp \ + DrmConvertedStatus.cpp \ + DrmEngineBase.cpp \ + DrmInfo.cpp \ + DrmInfoRequest.cpp \ + DrmInfoStatus.cpp \ + DrmRights.cpp \ + DrmSupportInfo.cpp \ + IDrmIOService.cpp \ + IDrmManagerService.cpp \ + IDrmServiceListener.cpp \ + DrmInfoEvent.cpp \ + ReadWriteUtils.cpp + +LOCAL_C_INCLUDES := \ + $(TOP)/frameworks/base/include \ + $(TOP)/frameworks/base/drm/libdrmframework/include \ + $(TOP)/frameworks/base/drm/libdrmframework/plugins/common/include + +LOCAL_MODULE:= libdrmframeworkcommon + +include $(BUILD_STATIC_LIBRARY) diff --git a/drm/common/DrmConstraints.cpp b/drm/common/DrmConstraints.cpp new file mode 100644 index 0000000..11ce410 --- /dev/null +++ b/drm/common/DrmConstraints.cpp @@ -0,0 +1,117 @@ +/* + * 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 + +using namespace android; + +const String8 DrmConstraints::MAX_REPEAT_COUNT("max_repeat_count"); +const String8 DrmConstraints::REMAINING_REPEAT_COUNT("remaining_repeat_count"); +const String8 DrmConstraints::LICENSE_START_TIME("license_start_time"); +const String8 DrmConstraints::LICENSE_EXPIRY_TIME("license_expiry_time"); +const String8 DrmConstraints::LICENSE_AVAILABLE_TIME("license_available_time"); +const String8 DrmConstraints::EXTENDED_METADATA("extended_metadata"); + +int DrmConstraints::getCount(void) const { + return mConstraintMap.size(); +} + +status_t DrmConstraints::put(const String8* key, const char* value) { + int length = strlen(value); + char* charValue = new char[length + 1]; + if (NULL != charValue) { + strncpy(charValue, value, length); + charValue[length] = '\0'; + mConstraintMap.add(*key, charValue); + } + return DRM_NO_ERROR; +} + +String8 DrmConstraints::get(const String8& key) const { + if (NULL != getValue(&key)) { + return String8(getValue(&key)); + } + return String8(""); +} + +const char* DrmConstraints::getValue(const String8* key) const { + if (NAME_NOT_FOUND != mConstraintMap.indexOfKey(*key)) { + return mConstraintMap.valueFor(*key); + } + return NULL; +} + +const char* DrmConstraints::getAsByteArray(const String8* key) const { + return getValue(key); +} + +bool DrmConstraints::KeyIterator::hasNext() { + return mIndex < mDrmConstraints->mConstraintMap.size(); +} + +const String8& DrmConstraints::KeyIterator::next() { + const String8& key = mDrmConstraints->mConstraintMap.keyAt(mIndex); + mIndex++; + return key; +} + +DrmConstraints::KeyIterator DrmConstraints::keyIterator() { + return KeyIterator(this); +} + +DrmConstraints::KeyIterator::KeyIterator(const DrmConstraints::KeyIterator& keyIterator) + : mDrmConstraints(keyIterator.mDrmConstraints), + mIndex(keyIterator.mIndex) { + LOGV("DrmConstraints::KeyIterator::KeyIterator"); +} + +DrmConstraints::KeyIterator& DrmConstraints::KeyIterator::operator=( + const DrmConstraints::KeyIterator& keyIterator) { + LOGV("DrmConstraints::KeyIterator::operator="); + mDrmConstraints = keyIterator.mDrmConstraints; + mIndex = keyIterator.mIndex; + return *this; +} + + +DrmConstraints::Iterator DrmConstraints::iterator() { + return Iterator(this); +} + +DrmConstraints::Iterator::Iterator(const DrmConstraints::Iterator& iterator) : + mDrmConstraints(iterator.mDrmConstraints), + mIndex(iterator.mIndex) { + LOGV("DrmConstraints::Iterator::Iterator"); +} + +DrmConstraints::Iterator& DrmConstraints::Iterator::operator=( + const DrmConstraints::Iterator& iterator) { + LOGV("DrmConstraints::Iterator::operator="); + mDrmConstraints = iterator.mDrmConstraints; + mIndex = iterator.mIndex; + return *this; +} + +bool DrmConstraints::Iterator::hasNext() { + return mIndex < mDrmConstraints->mConstraintMap.size(); +} + +String8 DrmConstraints::Iterator::next() { + String8 value = String8(mDrmConstraints->mConstraintMap.editValueAt(mIndex)); + mIndex++; + return value; +} + diff --git a/drm/common/DrmConvertedStatus.cpp b/drm/common/DrmConvertedStatus.cpp new file mode 100644 index 0000000..5d035f5 --- /dev/null +++ b/drm/common/DrmConvertedStatus.cpp @@ -0,0 +1,28 @@ +/* + * 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 + +using namespace android; + +DrmConvertedStatus::DrmConvertedStatus( + int _statusCode, const DrmBuffer* _convertedData, int _offset) : + statusCode(_statusCode), + convertedData(_convertedData), + offset(_offset) { + +} + diff --git a/drm/common/DrmEngineBase.cpp b/drm/common/DrmEngineBase.cpp new file mode 100644 index 0000000..70398e8 --- /dev/null +++ b/drm/common/DrmEngineBase.cpp @@ -0,0 +1,147 @@ +/* + * 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 "DrmEngineBase.h" + +using namespace android; + +DrmEngineBase::DrmEngineBase() { + +} + +DrmEngineBase::~DrmEngineBase() { + +} + +DrmConstraints* DrmEngineBase::getConstraints( + int uniqueId, const String8* path, int action) { + return onGetConstraints(uniqueId, path, action); +} + +status_t DrmEngineBase::initialize(int uniqueId) { + return onInitialize(uniqueId); +} + +status_t DrmEngineBase::setOnInfoListener( + int uniqueId, const IDrmEngine::OnInfoListener* infoListener) { + return onSetOnInfoListener(uniqueId, infoListener); +} + +status_t DrmEngineBase::terminate(int uniqueId) { + return onTerminate(uniqueId); +} + +bool DrmEngineBase::canHandle(int uniqueId, const String8& path) { + return onCanHandle(uniqueId, path); +} + +DrmInfoStatus* DrmEngineBase::processDrmInfo(int uniqueId, const DrmInfo* drmInfo) { + return onProcessDrmInfo(uniqueId, drmInfo); +} + +void DrmEngineBase::saveRights( + int uniqueId, const DrmRights& drmRights, + const String8& rightsPath, const String8& contentPath) { + return onSaveRights(uniqueId, drmRights, rightsPath, contentPath); +} + +DrmInfo* DrmEngineBase::acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest) { + return onAcquireDrmInfo(uniqueId, drmInfoRequest); +} + +String8 DrmEngineBase::getOriginalMimeType(int uniqueId, const String8& path) { + return onGetOriginalMimeType(uniqueId, path); +} + +int DrmEngineBase::getDrmObjectType(int uniqueId, const String8& path, const String8& mimeType) { + return onGetDrmObjectType(uniqueId, path, mimeType); +} + +int DrmEngineBase::checkRightsStatus(int uniqueId, const String8& path, int action) { + return onCheckRightsStatus(uniqueId, path, action); +} + +void DrmEngineBase::consumeRights( + int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) { + onConsumeRights(uniqueId, decryptHandle, action, reserve); +} + +void DrmEngineBase::setPlaybackStatus( + int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position) { + onSetPlaybackStatus(uniqueId, decryptHandle, playbackStatus, position); +} + +bool DrmEngineBase::validateAction( + int uniqueId, const String8& path, + int action, const ActionDescription& description) { + return onValidateAction(uniqueId, path, action, description); +} + +void DrmEngineBase::removeRights(int uniqueId, const String8& path) { + onRemoveRights(uniqueId, path); +} + +void DrmEngineBase::removeAllRights(int uniqueId) { + onRemoveAllRights(uniqueId); +} + +void DrmEngineBase::openConvertSession(int uniqueId, int convertId) { + onOpenConvertSession(uniqueId, convertId); +} + +DrmConvertedStatus* DrmEngineBase::convertData( + int uniqueId, int convertId, const DrmBuffer* inputData) { + return onConvertData(uniqueId, convertId, inputData); +} + +DrmConvertedStatus* DrmEngineBase::closeConvertSession(int uniqueId, int convertId) { + return onCloseConvertSession(uniqueId, convertId); +} + +DrmSupportInfo* DrmEngineBase::getSupportInfo(int uniqueId) { + return onGetSupportInfo(uniqueId); +} + +status_t DrmEngineBase::openDecryptSession( + int uniqueId, DecryptHandle* decryptHandle, int fd, int offset, int length) { + return onOpenDecryptSession(uniqueId, decryptHandle, fd, offset, length); +} + +void DrmEngineBase::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) { + onCloseDecryptSession(uniqueId, decryptHandle); +} + +void DrmEngineBase::initializeDecryptUnit( + int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo) { + onInitializeDecryptUnit(uniqueId, decryptHandle, decryptUnitId, headerInfo); +} + +status_t DrmEngineBase::decrypt( + int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, + const DrmBuffer* encBuffer, DrmBuffer** decBuffer) { + return onDecrypt(uniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer); +} + +void DrmEngineBase::finalizeDecryptUnit( + int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) { + onFinalizeDecryptUnit(uniqueId, decryptHandle, decryptUnitId); +} + +ssize_t DrmEngineBase::pread( + int uniqueId, DecryptHandle* decryptHandle, void* buffer, ssize_t numBytes, off_t offset) { + return onPread(uniqueId, decryptHandle, buffer, numBytes, offset); +} + diff --git a/drm/common/DrmInfo.cpp b/drm/common/DrmInfo.cpp new file mode 100644 index 0000000..ddcab33 --- /dev/null +++ b/drm/common/DrmInfo.cpp @@ -0,0 +1,111 @@ +/* + * 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 + +using namespace android; + +DrmInfo::DrmInfo(int infoType, const DrmBuffer& drmBuffer, const String8& mimeType) : + mInfoType(infoType), + mData(drmBuffer), + mMimeType(mimeType) { + +} + +int DrmInfo::getInfoType(void) const { + return mInfoType; +} + +String8 DrmInfo::getMimeType(void) const { + return mMimeType; +} + +const DrmBuffer& DrmInfo::getData(void) const { + return mData; +} + +int DrmInfo::getCount(void) const { + return mAttributes.size(); +} + +status_t DrmInfo::put(const String8& key, const String8& value) { + mAttributes.add(key, value); + return DRM_NO_ERROR; +} + +String8 DrmInfo::get(const String8& key) const { + if (NAME_NOT_FOUND != mAttributes.indexOfKey(key)) { + return mAttributes.valueFor(key); + } + return String8(""); +} + +int DrmInfo::indexOfKey(const String8& key) const { + return mAttributes.indexOfKey(key); +} + +DrmInfo::KeyIterator DrmInfo::keyIterator() const { + return KeyIterator(this); +} + +DrmInfo::Iterator DrmInfo::iterator() const { + return Iterator(this); +} + +// KeyIterator implementation +DrmInfo::KeyIterator::KeyIterator(const DrmInfo::KeyIterator& keyIterator) : + mDrmInfo(keyIterator.mDrmInfo), mIndex(keyIterator.mIndex) { + +} + +bool DrmInfo::KeyIterator::hasNext() { + return (mIndex < mDrmInfo->mAttributes.size()); +} + +const String8& DrmInfo::KeyIterator::next() { + const String8& key = mDrmInfo->mAttributes.keyAt(mIndex); + mIndex++; + return key; +} + +DrmInfo::KeyIterator& DrmInfo::KeyIterator::operator=(const DrmInfo::KeyIterator& keyIterator) { + mDrmInfo = keyIterator.mDrmInfo; + mIndex = keyIterator.mIndex; + return *this; +} + +// Iterator implementation +DrmInfo::Iterator::Iterator(const DrmInfo::Iterator& iterator) + : mDrmInfo(iterator.mDrmInfo), mIndex(iterator.mIndex) { + +} + +DrmInfo::Iterator& DrmInfo::Iterator::operator=(const DrmInfo::Iterator& iterator) { + mDrmInfo = iterator.mDrmInfo; + mIndex = iterator.mIndex; + return *this; +} + +bool DrmInfo::Iterator::hasNext() { + return mIndex < mDrmInfo->mAttributes.size(); +} + +String8& DrmInfo::Iterator::next() { + String8& value = mDrmInfo->mAttributes.editValueAt(mIndex); + mIndex++; + return value; +} + diff --git a/drm/common/DrmInfoEvent.cpp b/drm/common/DrmInfoEvent.cpp new file mode 100644 index 0000000..eb58129 --- /dev/null +++ b/drm/common/DrmInfoEvent.cpp @@ -0,0 +1,44 @@ +/* + * 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 "DrmInfoEvent" +#include "utils/Log.h" + +#include +#include + +using namespace android; + +DrmInfoEvent::DrmInfoEvent(int uniqueId, int infoType, const String8& message) + : mUniqueId(uniqueId), + mInfoType(infoType), + mMessage(message) { + +} + +int DrmInfoEvent::getUniqueId() const { + return mUniqueId; +} + +int DrmInfoEvent::getType() const { + return mInfoType; +} + +const String8& DrmInfoEvent::getMessage() const { + return mMessage; +} + diff --git a/drm/common/DrmInfoRequest.cpp b/drm/common/DrmInfoRequest.cpp new file mode 100644 index 0000000..a646859 --- /dev/null +++ b/drm/common/DrmInfoRequest.cpp @@ -0,0 +1,106 @@ +/* + * 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 + +using namespace android; + +const String8 DrmInfoRequest::ACCOUNT_ID("account_id"); +const String8 DrmInfoRequest::SUBSCRIPTION_ID("subscription_id"); + +DrmInfoRequest::DrmInfoRequest(int infoType, const String8& mimeType) : + mInfoType(infoType), mMimeType(mimeType) { + +} + +String8 DrmInfoRequest::getMimeType(void) const { + return mMimeType; +} + +int DrmInfoRequest::getInfoType(void) const { + return mInfoType; +} + +int DrmInfoRequest::getCount(void) const { + return mRequestInformationMap.size(); +} + +status_t DrmInfoRequest::put(const String8& key, const String8& value) { + mRequestInformationMap.add(key, value); + return DRM_NO_ERROR; +} + +String8 DrmInfoRequest::get(const String8& key) const { + if (NAME_NOT_FOUND != mRequestInformationMap.indexOfKey(key)) { + return mRequestInformationMap.valueFor(key); + } + return String8(""); +} + +DrmInfoRequest::KeyIterator DrmInfoRequest::keyIterator() const { + return KeyIterator(this); +} + +DrmInfoRequest::Iterator DrmInfoRequest::iterator() const { + return Iterator(this); +} + +// KeyIterator implementation +DrmInfoRequest::KeyIterator::KeyIterator(const DrmInfoRequest::KeyIterator& keyIterator) + : mDrmInfoRequest(keyIterator.mDrmInfoRequest), + mIndex(keyIterator.mIndex) { + +} + +bool DrmInfoRequest::KeyIterator::hasNext() { + return (mIndex < mDrmInfoRequest->mRequestInformationMap.size()); +} + +const String8& DrmInfoRequest::KeyIterator::next() { + const String8& key = mDrmInfoRequest->mRequestInformationMap.keyAt(mIndex); + mIndex++; + return key; +} + +DrmInfoRequest::KeyIterator& DrmInfoRequest::KeyIterator::operator=( + const DrmInfoRequest::KeyIterator& keyIterator) { + mDrmInfoRequest = keyIterator.mDrmInfoRequest; + mIndex = keyIterator.mIndex; + return *this; +} + +// Iterator implementation +DrmInfoRequest::Iterator::Iterator(const DrmInfoRequest::Iterator& iterator) : + mDrmInfoRequest(iterator.mDrmInfoRequest), mIndex(iterator.mIndex) { +} + +DrmInfoRequest::Iterator& DrmInfoRequest::Iterator::operator=( + const DrmInfoRequest::Iterator& iterator) { + mDrmInfoRequest = iterator.mDrmInfoRequest; + mIndex = iterator.mIndex; + return *this; +} + +bool DrmInfoRequest::Iterator::hasNext() { + return mIndex < mDrmInfoRequest->mRequestInformationMap.size(); +} + +String8& DrmInfoRequest::Iterator::next() { + String8& value = mDrmInfoRequest->mRequestInformationMap.editValueAt(mIndex); + mIndex++; + return value; +} + diff --git a/drm/common/DrmInfoStatus.cpp b/drm/common/DrmInfoStatus.cpp new file mode 100644 index 0000000..f3a1516 --- /dev/null +++ b/drm/common/DrmInfoStatus.cpp @@ -0,0 +1,28 @@ +/* + * 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 + +using namespace android; + +DrmInfoStatus::DrmInfoStatus( + int _statusCode, const DrmBuffer* _drmBuffer, const String8& _mimeType) : + statusCode(_statusCode), + drmBuffer(_drmBuffer), + mimeType(_mimeType) { + +} + diff --git a/drm/common/DrmRights.cpp b/drm/common/DrmRights.cpp new file mode 100644 index 0000000..dc1e6c5 --- /dev/null +++ b/drm/common/DrmRights.cpp @@ -0,0 +1,51 @@ +/* + * 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 + +using namespace android; + +DrmRights::DrmRights(const String8& rightsFilePath, const String8& mimeType, + const String8& accountId, const String8& subscriptionId) { + /** + * TODO Read DrmRights from rights file + */ +} + +DrmRights::DrmRights(const DrmBuffer& rightsData, const String8& mimeType, + const String8& accountId, const String8& subscriptionId) : + mData(rightsData), + mMimeType(mimeType), + mAccountId(accountId), + mSubscriptionId(subscriptionId) { +} + +const DrmBuffer& DrmRights::getData(void) const { + return mData; +} + +String8 DrmRights::getMimeType(void) const { + return mMimeType; +} + +String8 DrmRights::getAccountId(void) const { + return mAccountId; +} + +String8 DrmRights::getSubscriptionId(void) const { + return mSubscriptionId; +} + diff --git a/drm/common/DrmSupportInfo.cpp b/drm/common/DrmSupportInfo.cpp new file mode 100644 index 0000000..35e83fc --- /dev/null +++ b/drm/common/DrmSupportInfo.cpp @@ -0,0 +1,155 @@ +/* + * 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 + +using namespace android; + +DrmSupportInfo::DrmSupportInfo() { + +} + +DrmSupportInfo::DrmSupportInfo(const DrmSupportInfo& drmSupportInfo): + mMimeTypeVector(drmSupportInfo.mMimeTypeVector), + mFileSuffixVector(drmSupportInfo.mFileSuffixVector), + mDescription(drmSupportInfo.mDescription) { + +} + +bool DrmSupportInfo::operator<(const DrmSupportInfo& drmSupportInfo) const { + // Do we need to check mMimeTypeVector & mFileSuffixVector ? + // Note Vector doesn't overrides "<" operator + return mDescription < drmSupportInfo.mDescription; +} + +bool DrmSupportInfo::operator==(const DrmSupportInfo& drmSupportInfo) const { + // Do we need to check mMimeTypeVector & mFileSuffixVector ? + // Note Vector doesn't overrides "==" operator + return (mDescription == drmSupportInfo.mDescription); +} + +bool DrmSupportInfo::isSupportedMimeType(const String8& mimeType) const { + for (int i = 0; i < mMimeTypeVector.size(); i++) { + const String8 item = mMimeTypeVector.itemAt(i); + + if (String8("") != mimeType && item.find(mimeType) != -1) { + return true; + } + } + return false; +} + +bool DrmSupportInfo::isSupportedFileSuffix(const String8& fileType) const { + for (int i = 0; i < mFileSuffixVector.size(); i++) { + const String8 item = mFileSuffixVector.itemAt(i); + + if (String8("") != fileType && item.find(fileType) != -1) { + return true; + } + } + return false; +} + +DrmSupportInfo& DrmSupportInfo::operator=(const DrmSupportInfo& drmSupportInfo) { + mMimeTypeVector = drmSupportInfo.mMimeTypeVector; + mFileSuffixVector = drmSupportInfo.mFileSuffixVector; + mDescription = drmSupportInfo.mDescription; + return *this; +} + +int DrmSupportInfo::getMimeTypeCount(void) const { + return mMimeTypeVector.size(); +} + +int DrmSupportInfo::getFileSuffixCount(void) const { + return mFileSuffixVector.size(); +} + +status_t DrmSupportInfo::addMimeType(const String8& mimeType) { + mMimeTypeVector.push(mimeType); + return DRM_NO_ERROR; +} + +status_t DrmSupportInfo::addFileSuffix(const String8& fileSuffix) { + mFileSuffixVector.push(fileSuffix); + return DRM_NO_ERROR; +} + +status_t DrmSupportInfo::setDescription(const String8& description) { + mDescription = description; + return DRM_NO_ERROR; +} + +String8 DrmSupportInfo::getDescription() const { + return mDescription; +} + +DrmSupportInfo::FileSuffixIterator DrmSupportInfo::getFileSuffixIterator() { + return FileSuffixIterator(this); +} + +DrmSupportInfo::MimeTypeIterator DrmSupportInfo::getMimeTypeIterator() { + return MimeTypeIterator(this); +} + +DrmSupportInfo::FileSuffixIterator::FileSuffixIterator( + const DrmSupportInfo::FileSuffixIterator& iterator) : + mDrmSupportInfo(iterator.mDrmSupportInfo), + mIndex(iterator.mIndex) { + +} + +DrmSupportInfo::FileSuffixIterator& DrmSupportInfo::FileSuffixIterator::operator=( + const DrmSupportInfo::FileSuffixIterator& iterator) { + mDrmSupportInfo = iterator.mDrmSupportInfo; + mIndex = iterator.mIndex; + return *this; +} + +bool DrmSupportInfo::FileSuffixIterator::hasNext() { + return mIndex < mDrmSupportInfo->mFileSuffixVector.size(); +} + +String8& DrmSupportInfo::FileSuffixIterator::next() { + String8& value = mDrmSupportInfo->mFileSuffixVector.editItemAt(mIndex); + mIndex++; + return value; +} + +DrmSupportInfo::MimeTypeIterator::MimeTypeIterator( + const DrmSupportInfo::MimeTypeIterator& iterator) : + mDrmSupportInfo(iterator.mDrmSupportInfo), + mIndex(iterator.mIndex) { + +} + +DrmSupportInfo::MimeTypeIterator& DrmSupportInfo::MimeTypeIterator::operator=( + const DrmSupportInfo::MimeTypeIterator& iterator) { + mDrmSupportInfo = iterator.mDrmSupportInfo; + mIndex = iterator.mIndex; + return *this; +} + +bool DrmSupportInfo::MimeTypeIterator::hasNext() { + return mIndex < mDrmSupportInfo->mMimeTypeVector.size(); +} + +String8& DrmSupportInfo::MimeTypeIterator::next() { + String8& value = mDrmSupportInfo->mMimeTypeVector.editItemAt(mIndex); + mIndex++; + return value; +} + diff --git a/drm/common/IDrmIOService.cpp b/drm/common/IDrmIOService.cpp new file mode 100644 index 0000000..7ce45e7 --- /dev/null +++ b/drm/common/IDrmIOService.cpp @@ -0,0 +1,78 @@ +/* + * 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 "IDrmIOService" +#include + +#include +#include +#include +#include +#include +#include "IDrmIOService.h" + +using namespace android; + +void BpDrmIOService::writeToFile(const String8& filePath, const String8& dataBuffer) { + Parcel data, reply; + + data.writeInterfaceToken(IDrmIOService::getInterfaceDescriptor()); + data.writeString8(filePath); + data.writeString8(dataBuffer); + + remote()->transact(WRITE_TO_FILE, data, &reply); +} + +String8 BpDrmIOService::readFromFile(const String8& filePath) { + + Parcel data, reply; + + data.writeInterfaceToken(IDrmIOService::getInterfaceDescriptor()); + data.writeString8(filePath); + + remote()->transact(READ_FROM_FILE, data, &reply); + return reply.readString8(); +} + +IMPLEMENT_META_INTERFACE(DrmIOService, "drm.IDrmIOService"); + +status_t BnDrmIOService::onTransact( + uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) { + + switch (code) { + case WRITE_TO_FILE: + { + CHECK_INTERFACE(IDrmIOService, data, reply); + + writeToFile(data.readString8(), data.readString8()); + return DRM_NO_ERROR; + } + + case READ_FROM_FILE: + { + CHECK_INTERFACE(IDrmIOService, data, reply); + + String8 dataBuffer = readFromFile(data.readString8()); + reply->writeString8(dataBuffer); + return DRM_NO_ERROR; + } + + default: + return BBinder::onTransact(code, data, reply, flags); + } +} + diff --git a/drm/common/IDrmManagerService.cpp b/drm/common/IDrmManagerService.cpp new file mode 100644 index 0000000..4fc828a --- /dev/null +++ b/drm/common/IDrmManagerService.cpp @@ -0,0 +1,1358 @@ +/* + * 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 "IDrmManagerService(Native)" +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "IDrmManagerService.h" + +#define INVALID_BUFFER_LENGTH -1 + +using namespace android; + +status_t BpDrmManagerService::loadPlugIns(int uniqueId) { + LOGV("load plugins"); + Parcel data, reply; + + data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); + data.writeInt32(uniqueId); + + remote()->transact(LOAD_PLUGINS, data, &reply); + return reply.readInt32(); +} + +status_t BpDrmManagerService::loadPlugIns(int uniqueId, const String8& plugInDirPath) { + LOGV("load plugins from path"); + Parcel data, reply; + + data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); + data.writeInt32(uniqueId); + data.writeString8(plugInDirPath); + + remote()->transact(LOAD_PLUGINS_FROM_PATH, data, &reply); + return reply.readInt32(); +} + +status_t BpDrmManagerService::setDrmServiceListener( + int uniqueId, const sp& drmServiceListener) { + LOGV("setDrmServiceListener"); + Parcel data, reply; + + data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); + data.writeInt32(uniqueId); + data.writeStrongBinder(drmServiceListener->asBinder()); + remote()->transact(SET_DRM_SERVICE_LISTENER, data, &reply); + return reply.readInt32(); +} + +status_t BpDrmManagerService::unloadPlugIns(int uniqueId) { + LOGV("unload plugins"); + Parcel data, reply; + + data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); + data.writeInt32(uniqueId); + + remote()->transact(UNLOAD_PLUGINS, data, &reply); + return reply.readInt32(); +} + +status_t BpDrmManagerService::installDrmEngine(int uniqueId, const String8& drmEngineFile) { + LOGV("Install DRM Engine"); + Parcel data, reply; + + data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); + data.writeInt32(uniqueId); + data.writeString8(drmEngineFile); + + remote()->transact(INSTALL_DRM_ENGINE, data, &reply); + return reply.readInt32(); +} + +DrmConstraints* BpDrmManagerService::getConstraints( + int uniqueId, const String8* path, const int action) { + LOGV("Get Constraints"); + Parcel data, reply; + + data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); + data.writeInt32(uniqueId); + data.writeString8(*path); + data.writeInt32(action); + + remote()->transact(GET_CONSTRAINTS_FROM_CONTENT, data, &reply); + + DrmConstraints* drmConstraints = NULL; + if (0 != reply.dataAvail()) { + //Filling Drm Constraints + drmConstraints = new DrmConstraints(); + + const int size = reply.readInt32(); + for (int index = 0; index < size; ++index) { + const String8 key(reply.readString8()); + const int bufferSize = reply.readInt32(); + char* data = NULL; + if (0 < bufferSize) { + data = new char[bufferSize]; + reply.read(data, bufferSize); + } + drmConstraints->put(&key, data); + } + } + return drmConstraints; +} + +bool BpDrmManagerService::canHandle(int uniqueId, const String8& path, const String8& mimeType) { + LOGV("Can Handle"); + Parcel data, reply; + + data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); + data.writeInt32(uniqueId); + + data.writeString8(path); + data.writeString8(mimeType); + + remote()->transact(CAN_HANDLE, data, &reply); + + return static_cast(reply.readInt32()); +} + +DrmInfoStatus* BpDrmManagerService::processDrmInfo(int uniqueId, const DrmInfo* drmInfo) { + LOGV("Process DRM Info"); + Parcel data, reply; + + data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); + data.writeInt32(uniqueId); + + //Filling DRM info + data.writeInt32(drmInfo->getInfoType()); + const DrmBuffer dataBuffer = drmInfo->getData(); + const int dataBufferSize = dataBuffer.length; + data.writeInt32(dataBufferSize); + if (0 < dataBufferSize) { + data.write(dataBuffer.data, dataBufferSize); + } + data.writeString8(drmInfo->getMimeType()); + + data.writeInt32(drmInfo->getCount()); + DrmInfo::KeyIterator keyIt = drmInfo->keyIterator(); + + while (keyIt.hasNext()) { + const String8 key = keyIt.next(); + data.writeString8(key); + const String8 value = drmInfo->get(key); + data.writeString8((value == String8("")) ? String8("NULL") : value); + } + + remote()->transact(PROCESS_DRM_INFO, data, &reply); + + DrmInfoStatus* drmInfoStatus = NULL; + if (0 != reply.dataAvail()) { + //Filling DRM Info Status + const int statusCode = reply.readInt32(); + const String8 mimeType = reply.readString8(); + + DrmBuffer* drmBuffer = NULL; + if (0 != reply.dataAvail()) { + const int bufferSize = reply.readInt32(); + char* data = NULL; + if (0 < bufferSize) { + data = new char[bufferSize]; + reply.read(data, bufferSize); + } + drmBuffer = new DrmBuffer(data, bufferSize); + } + drmInfoStatus = new DrmInfoStatus(statusCode, drmBuffer, mimeType); + } + return drmInfoStatus; +} + +DrmInfo* BpDrmManagerService::acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInforequest) { + LOGV("Acquire DRM Info"); + Parcel data, reply; + + data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); + data.writeInt32(uniqueId); + + //Filling DRM Info Request + data.writeInt32(drmInforequest->getInfoType()); + data.writeString8(drmInforequest->getMimeType()); + + data.writeInt32(drmInforequest->getCount()); + DrmInfoRequest::KeyIterator keyIt = drmInforequest->keyIterator(); + + while (keyIt.hasNext()) { + const String8 key = keyIt.next(); + data.writeString8(key); + const String8 value = drmInforequest->get(key); + data.writeString8((value == String8("")) ? String8("NULL") : value); + } + + remote()->transact(ACQUIRE_DRM_INFO, data, &reply); + + DrmInfo* drmInfo = NULL; + if (0 != reply.dataAvail()) { + //Filling DRM Info + const int infoType = reply.readInt32(); + const int bufferSize = reply.readInt32(); + char* data = NULL; + + if (0 < bufferSize) { + data = new char[bufferSize]; + reply.read(data, bufferSize); + } + drmInfo = new DrmInfo(infoType, DrmBuffer(data, bufferSize), reply.readString8()); + + const int size = reply.readInt32(); + for (int index = 0; index < size; ++index) { + const String8 key(reply.readString8()); + const String8 value(reply.readString8()); + drmInfo->put(key, (value == String8("NULL")) ? String8("") : value); + } + } + return drmInfo; +} + +void BpDrmManagerService::saveRights( + int uniqueId, const DrmRights& drmRights, + const String8& rightsPath, const String8& contentPath) { + LOGV("Save Rights"); + Parcel data, reply; + + data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); + data.writeInt32(uniqueId); + + //Filling Drm Rights + const DrmBuffer dataBuffer = drmRights.getData(); + data.writeInt32(dataBuffer.length); + data.write(dataBuffer.data, dataBuffer.length); + + const String8 mimeType = drmRights.getMimeType(); + data.writeString8((mimeType == String8("")) ? String8("NULL") : mimeType); + + const String8 accountId = drmRights.getAccountId(); + data.writeString8((accountId == String8("")) ? String8("NULL") : accountId); + + const String8 subscriptionId = drmRights.getSubscriptionId(); + data.writeString8((subscriptionId == String8("")) ? String8("NULL") : subscriptionId); + + data.writeString8((rightsPath == String8("")) ? String8("NULL") : rightsPath); + data.writeString8((contentPath == String8("")) ? String8("NULL") : contentPath); + + remote()->transact(SAVE_RIGHTS, data, &reply); +} + +String8 BpDrmManagerService::getOriginalMimeType(int uniqueId, const String8& path) { + LOGV("Get Original MimeType"); + Parcel data, reply; + + data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); + data.writeInt32(uniqueId); + data.writeString8(path); + + remote()->transact(GET_ORIGINAL_MIMETYPE, data, &reply); + return reply.readString8(); +} + +int BpDrmManagerService::getDrmObjectType( + int uniqueId, const String8& path, const String8& mimeType) { + LOGV("Get Drm object type"); + Parcel data, reply; + + data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); + data.writeInt32(uniqueId); + data.writeString8(path); + data.writeString8(mimeType); + + remote()->transact(GET_DRM_OBJECT_TYPE, data, &reply); + + return reply.readInt32(); +} + +int BpDrmManagerService::checkRightsStatus(int uniqueId, const String8& path, int action) { + LOGV("checkRightsStatus"); + Parcel data, reply; + + data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); + data.writeInt32(uniqueId); + data.writeString8(path); + data.writeInt32(action); + + remote()->transact(CHECK_RIGHTS_STATUS, data, &reply); + + return reply.readInt32(); +} + +void BpDrmManagerService::consumeRights( + int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) { + LOGV("consumeRights"); + Parcel data, reply; + + data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); + data.writeInt32(uniqueId); + + data.writeInt32(decryptHandle->decryptId); + data.writeString8(decryptHandle->mimeType); + data.writeInt32(decryptHandle->decryptApiType); + data.writeInt32(decryptHandle->status); + + if (NULL != decryptHandle->decryptInfo) { + data.writeInt32(decryptHandle->decryptInfo->decryptBufferLength); + } else { + data.writeInt32(INVALID_BUFFER_LENGTH); + } + + data.writeInt32(action); + data.writeInt32(static_cast< int>(reserve)); + + remote()->transact(CONSUME_RIGHTS, data, &reply); +} + +void BpDrmManagerService::setPlaybackStatus( + int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position) { + LOGV("setPlaybackStatus"); + Parcel data, reply; + + data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); + data.writeInt32(uniqueId); + + data.writeInt32(decryptHandle->decryptId); + data.writeString8(decryptHandle->mimeType); + data.writeInt32(decryptHandle->decryptApiType); + data.writeInt32(decryptHandle->status); + + if (NULL != decryptHandle->decryptInfo) { + data.writeInt32(decryptHandle->decryptInfo->decryptBufferLength); + } else { + data.writeInt32(INVALID_BUFFER_LENGTH); + } + + data.writeInt32(playbackStatus); + data.writeInt32(position); + + remote()->transact(SET_PLAYBACK_STATUS, data, &reply); +} + +bool BpDrmManagerService::validateAction( + int uniqueId, const String8& path, + int action, const ActionDescription& description) { + LOGV("validateAction"); + Parcel data, reply; + + data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); + data.writeInt32(uniqueId); + data.writeString8(path); + data.writeInt32(action); + data.writeInt32(description.outputType); + data.writeInt32(description.configuration); + + remote()->transact(VALIDATE_ACTION, data, &reply); + + return static_cast(reply.readInt32()); +} + +void BpDrmManagerService::removeRights(int uniqueId, const String8& path) { + LOGV("removeRights"); + Parcel data, reply; + + data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); + data.writeInt32(uniqueId); + data.writeString8(path); + + remote()->transact(REMOVE_RIGHTS, data, &reply); +} + +void BpDrmManagerService::removeAllRights(int uniqueId) { + LOGV("removeAllRights"); + Parcel data, reply; + + data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); + data.writeInt32(uniqueId); + + remote()->transact(REMOVE_ALL_RIGHTS, data, &reply); +} + +int BpDrmManagerService::openConvertSession(int uniqueId, const String8& mimeType) { + LOGV("openConvertSession"); + Parcel data, reply; + + data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); + data.writeInt32(uniqueId); + data.writeString8(mimeType); + + remote()->transact(OPEN_CONVERT_SESSION, data, &reply); + return reply.readInt32(); +} + +DrmConvertedStatus* BpDrmManagerService::convertData( + int uniqueId, int convertId, const DrmBuffer* inputData) { + LOGV("convertData"); + Parcel data, reply; + + data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); + data.writeInt32(uniqueId); + data.writeInt32(convertId); + data.writeInt32(inputData->length); + data.write(inputData->data, inputData->length); + + remote()->transact(CONVERT_DATA, data, &reply); + + DrmConvertedStatus* drmConvertedStatus = NULL; + + if (0 != reply.dataAvail()) { + //Filling DRM Converted Status + const int statusCode = reply.readInt32(); + const int offset = reply.readInt32(); + + DrmBuffer* convertedData = NULL; + if (0 != reply.dataAvail()) { + const int bufferSize = reply.readInt32(); + char* data = NULL; + if (0 < bufferSize) { + data = new char[bufferSize]; + reply.read(data, bufferSize); + } + convertedData = new DrmBuffer(data, bufferSize); + } + drmConvertedStatus = new DrmConvertedStatus(statusCode, convertedData, offset); + } + return drmConvertedStatus; +} + +DrmConvertedStatus* BpDrmManagerService::closeConvertSession(int uniqueId, int convertId) { + LOGV("closeConvertSession"); + Parcel data, reply; + + data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); + data.writeInt32(uniqueId); + data.writeInt32(convertId); + + remote()->transact(CLOSE_CONVERT_SESSION, data, &reply); + + DrmConvertedStatus* drmConvertedStatus = NULL; + + if (0 != reply.dataAvail()) { + //Filling DRM Converted Status + const int statusCode = reply.readInt32(); + const int offset = reply.readInt32(); + + DrmBuffer* convertedData = NULL; + if (0 != reply.dataAvail()) { + const int bufferSize = reply.readInt32(); + char* data = NULL; + if (0 < bufferSize) { + data = new char[bufferSize]; + reply.read(data, bufferSize); + } + convertedData = new DrmBuffer(data, bufferSize); + } + drmConvertedStatus = new DrmConvertedStatus(statusCode, convertedData, offset); + } + return drmConvertedStatus; +} + +status_t BpDrmManagerService::getAllSupportInfo( + int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray) { + LOGV("Get All Support Info"); + Parcel data, reply; + + data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); + data.writeInt32(uniqueId); + + remote()->transact(GET_ALL_SUPPORT_INFO, data, &reply); + + //Filling DRM Support Info + const int arraySize = reply.readInt32(); + if (0 < arraySize) { + *drmSupportInfoArray = new DrmSupportInfo[arraySize]; + + for (int index = 0; index < arraySize; ++index) { + DrmSupportInfo drmSupportInfo; + + const int fileSuffixVectorSize = reply.readInt32(); + for (int i = 0; i < fileSuffixVectorSize; ++i) { + drmSupportInfo.addFileSuffix(reply.readString8()); + } + + const int mimeTypeVectorSize = reply.readInt32(); + for (int i = 0; i < mimeTypeVectorSize; ++i) { + drmSupportInfo.addMimeType(reply.readString8()); + } + + drmSupportInfo.setDescription(reply.readString8()); + (*drmSupportInfoArray)[index] = drmSupportInfo; + } + } + *length = arraySize; + return reply.readInt32(); +} + +DecryptHandle* BpDrmManagerService::openDecryptSession( + int uniqueId, int fd, int offset, int length) { + LOGV("Entering BpDrmManagerService::openDecryptSession"); + Parcel data, reply; + + const String16 interfaceDescriptor = IDrmManagerService::getInterfaceDescriptor(); + LOGV("BpDrmManagerService::openDecryptSession: InterfaceDescriptor name is %s", + interfaceDescriptor.string()); + data.writeInterfaceToken(interfaceDescriptor); + data.writeInt32(uniqueId); + data.writeFileDescriptor(fd); + data.writeInt32(offset); + data.writeInt32(length); + + LOGV("try to invoke remote onTransact() with code OPEN_DECRYPT_SESSION"); + remote()->transact(OPEN_DECRYPT_SESSION, data, &reply); + + DecryptHandle* handle = NULL; + if (0 != reply.dataAvail()) { + handle = new DecryptHandle(); + handle->decryptId = reply.readInt32(); + handle->mimeType = reply.readString8(); + handle->decryptApiType = reply.readInt32(); + handle->status = reply.readInt32(); + handle->decryptInfo = NULL; + if (0 != reply.dataAvail()) { + handle->decryptInfo = new DecryptInfo(); + handle->decryptInfo->decryptBufferLength = reply.readInt32(); + } + } else { + LOGE("no decryptHandle is generated in service side"); + } + return handle; +} + +void BpDrmManagerService::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) { + LOGV("closeDecryptSession"); + Parcel data, reply; + + data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); + data.writeInt32(uniqueId); + + data.writeInt32(decryptHandle->decryptId); + data.writeString8(decryptHandle->mimeType); + data.writeInt32(decryptHandle->decryptApiType); + data.writeInt32(decryptHandle->status); + + if (NULL != decryptHandle->decryptInfo) { + data.writeInt32(decryptHandle->decryptInfo->decryptBufferLength); + } else { + data.writeInt32(INVALID_BUFFER_LENGTH); + } + + remote()->transact(CLOSE_DECRYPT_SESSION, data, &reply); + + if (NULL != decryptHandle->decryptInfo) { + LOGV("deleting decryptInfo"); + delete decryptHandle->decryptInfo; decryptHandle->decryptInfo = NULL; + } + delete decryptHandle; decryptHandle = NULL; +} + +void BpDrmManagerService::initializeDecryptUnit( + int uniqueId, DecryptHandle* decryptHandle, + int decryptUnitId, const DrmBuffer* headerInfo) { + LOGV("initializeDecryptUnit"); + Parcel data, reply; + + data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); + data.writeInt32(uniqueId); + + data.writeInt32(decryptHandle->decryptId); + data.writeString8(decryptHandle->mimeType); + data.writeInt32(decryptHandle->decryptApiType); + data.writeInt32(decryptHandle->status); + + if (NULL != decryptHandle->decryptInfo) { + data.writeInt32(decryptHandle->decryptInfo->decryptBufferLength); + } else { + data.writeInt32(INVALID_BUFFER_LENGTH); + } + data.writeInt32(decryptUnitId); + + data.writeInt32(headerInfo->length); + data.write(headerInfo->data, headerInfo->length); + + remote()->transact(INITIALIZE_DECRYPT_UNIT, data, &reply); +} + +status_t BpDrmManagerService::decrypt( + int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, + const DrmBuffer* encBuffer, DrmBuffer** decBuffer) { + LOGV("decrypt"); + Parcel data, reply; + + data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); + data.writeInt32(uniqueId); + + data.writeInt32(decryptHandle->decryptId); + data.writeString8(decryptHandle->mimeType); + data.writeInt32(decryptHandle->decryptApiType); + data.writeInt32(decryptHandle->status); + + if (NULL != decryptHandle->decryptInfo) { + data.writeInt32(decryptHandle->decryptInfo->decryptBufferLength); + } else { + data.writeInt32(INVALID_BUFFER_LENGTH); + } + + data.writeInt32(decryptUnitId); + data.writeInt32((*decBuffer)->length); + + data.writeInt32(encBuffer->length); + data.write(encBuffer->data, encBuffer->length); + + remote()->transact(DECRYPT, data, &reply); + + const status_t status = reply.readInt32(); + LOGV("Return value of decrypt() is %d", status); + + const int size = reply.readInt32(); + (*decBuffer)->length = size; + reply.read((void *)(*decBuffer)->data, size); + + return status; +} + +void BpDrmManagerService::finalizeDecryptUnit( + int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) { + LOGV("finalizeDecryptUnit"); + Parcel data, reply; + + data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); + data.writeInt32(uniqueId); + + data.writeInt32(decryptHandle->decryptId); + data.writeString8(decryptHandle->mimeType); + data.writeInt32(decryptHandle->decryptApiType); + data.writeInt32(decryptHandle->status); + + if (NULL != decryptHandle->decryptInfo) { + data.writeInt32(decryptHandle->decryptInfo->decryptBufferLength); + } else { + data.writeInt32(INVALID_BUFFER_LENGTH); + } + + data.writeInt32(decryptUnitId); + + remote()->transact(FINALIZE_DECRYPT_UNIT, data, &reply); +} + +ssize_t BpDrmManagerService::pread( + int uniqueId, DecryptHandle* decryptHandle, void* buffer, + ssize_t numBytes, off_t offset) { + LOGV("read"); + Parcel data, reply; + int result; + + data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); + data.writeInt32(uniqueId); + + data.writeInt32(decryptHandle->decryptId); + data.writeString8(decryptHandle->mimeType); + data.writeInt32(decryptHandle->decryptApiType); + data.writeInt32(decryptHandle->status); + + if (NULL != decryptHandle->decryptInfo) { + data.writeInt32(decryptHandle->decryptInfo->decryptBufferLength); + } else { + data.writeInt32(INVALID_BUFFER_LENGTH); + } + + data.writeInt32(numBytes); + data.writeInt32(offset); + + remote()->transact(PREAD, data, &reply); + result = reply.readInt32(); + if (0 < result) { + reply.read(buffer, result); + } + return result; +} + +IMPLEMENT_META_INTERFACE(DrmManagerService, "drm.IDrmManagerService"); + +status_t BnDrmManagerService::onTransact( + uint32_t code, const Parcel& data, + Parcel* reply, uint32_t flags) { + LOGV("Entering BnDrmManagerService::onTransact with code %d", code); + + switch (code) { + case LOAD_PLUGINS: + { + LOGV("BnDrmManagerService::onTransact :LOAD_PLUGINS"); + CHECK_INTERFACE(IDrmManagerService, data, reply); + + status_t status = loadPlugIns(data.readInt32()); + + reply->writeInt32(status); + return DRM_NO_ERROR; + + } + + case LOAD_PLUGINS_FROM_PATH: + { + LOGV("BnDrmManagerService::onTransact :LOAD_PLUGINS_FROM_PATH"); + CHECK_INTERFACE(IDrmManagerService, data, reply); + + status_t status = loadPlugIns(data.readInt32(), data.readString8()); + + reply->writeInt32(status); + return DRM_NO_ERROR; + } + + case SET_DRM_SERVICE_LISTENER: + { + LOGV("BnDrmManagerService::onTransact :SET_DRM_SERVICE_LISTENER"); + CHECK_INTERFACE(IDrmManagerService, data, reply); + + const int uniqueId = data.readInt32(); + const sp drmServiceListener + = interface_cast (data.readStrongBinder()); + + status_t status = setDrmServiceListener(uniqueId, drmServiceListener); + + reply->writeInt32(status); + return DRM_NO_ERROR; + } + + case UNLOAD_PLUGINS: + { + LOGV("BnDrmManagerService::onTransact :UNLOAD_PLUGINS"); + CHECK_INTERFACE(IDrmManagerService, data, reply); + + status_t status = unloadPlugIns(data.readInt32()); + + reply->writeInt32(status); + return DRM_NO_ERROR; + } + + case INSTALL_DRM_ENGINE: + { + LOGV("BnDrmManagerService::onTransact :INSTALL_DRM_ENGINE"); + CHECK_INTERFACE(IDrmManagerService, data, reply); + + status_t status = installDrmEngine(data.readInt32(), data.readString8()); + + reply->writeInt32(status); + return DRM_NO_ERROR; + } + + case GET_CONSTRAINTS_FROM_CONTENT: + { + LOGV("BnDrmManagerService::onTransact :GET_CONSTRAINTS_FROM_CONTENT"); + CHECK_INTERFACE(IDrmManagerService, data, reply); + + const int uniqueId = data.readInt32(); + const String8 path = data.readString8(); + + DrmConstraints* drmConstraints = getConstraints(uniqueId, &path, data.readInt32()); + + if (NULL != drmConstraints) { + //Filling DRM Constraints contents + reply->writeInt32(drmConstraints->getCount()); + + DrmConstraints::KeyIterator keyIt = drmConstraints->keyIterator(); + while (keyIt.hasNext()) { + const String8 key = keyIt.next(); + reply->writeString8(key); + const char* value = drmConstraints->getAsByteArray(&key); + int bufferSize = 0; + if (NULL != value) { + bufferSize = strlen(value); + } + reply->writeInt32(bufferSize + 1); + reply->write(value, bufferSize + 1); + } + } + delete drmConstraints; drmConstraints = NULL; + return DRM_NO_ERROR; + } + + case CAN_HANDLE: + { + LOGV("BnDrmManagerService::onTransact :CAN_HANDLE"); + CHECK_INTERFACE(IDrmManagerService, data, reply); + + const int uniqueId = data.readInt32(); + const String8 path = data.readString8(); + const String8 mimeType = data.readString8(); + + bool result = canHandle(uniqueId, path, mimeType); + + reply->writeInt32(result); + return DRM_NO_ERROR; + } + + case PROCESS_DRM_INFO: + { + LOGV("BnDrmManagerService::onTransact :PROCESS_DRM_INFO"); + CHECK_INTERFACE(IDrmManagerService, data, reply); + + const int uniqueId = data.readInt32(); + + //Filling DRM info + const int infoType = data.readInt32(); + const int bufferSize = data.readInt32(); + char* buffer = NULL; + if (0 < bufferSize) { + buffer = (char *)data.readInplace(bufferSize); + } + const DrmBuffer drmBuffer(buffer, bufferSize); + DrmInfo* drmInfo = new DrmInfo(infoType, drmBuffer, data.readString8()); + + const int size = data.readInt32(); + for (int index = 0; index < size; ++index) { + const String8 key(data.readString8()); + const String8 value(data.readString8()); + drmInfo->put(key, (value == String8("NULL")) ? String8("") : value); + } + + DrmInfoStatus* drmInfoStatus = processDrmInfo(uniqueId, drmInfo); + + if (NULL != drmInfoStatus) { + //Filling DRM Info Status contents + reply->writeInt32(drmInfoStatus->statusCode); + reply->writeString8(drmInfoStatus->mimeType); + + if (NULL != drmInfoStatus->drmBuffer) { + const DrmBuffer* drmBuffer = drmInfoStatus->drmBuffer; + const int bufferSize = drmBuffer->length; + reply->writeInt32(bufferSize); + if (0 < bufferSize) { + reply->write(drmBuffer->data, bufferSize); + } + delete [] drmBuffer->data; + delete drmBuffer; drmBuffer = NULL; + } + } + delete drmInfo; drmInfo = NULL; + delete drmInfoStatus; drmInfoStatus = NULL; + return DRM_NO_ERROR; + } + + case ACQUIRE_DRM_INFO: + { + LOGV("BnDrmManagerService::onTransact :ACQUIRE_DRM_INFO"); + CHECK_INTERFACE(IDrmManagerService, data, reply); + + const int uniqueId = data.readInt32(); + + //Filling DRM info Request + DrmInfoRequest* drmInfoRequest = new DrmInfoRequest(data.readInt32(), data.readString8()); + + const int size = data.readInt32(); + for (int index = 0; index < size; ++index) { + const String8 key(data.readString8()); + const String8 value(data.readString8()); + drmInfoRequest->put(key, (value == String8("NULL")) ? String8("") : value); + } + + DrmInfo* drmInfo = acquireDrmInfo(uniqueId, drmInfoRequest); + + if (NULL != drmInfo) { + //Filling DRM Info + const DrmBuffer drmBuffer = drmInfo->getData(); + reply->writeInt32(drmInfo->getInfoType()); + + const int bufferSize = drmBuffer.length; + reply->writeInt32(bufferSize); + if (0 < bufferSize) { + reply->write(drmBuffer.data, bufferSize); + } + reply->writeString8(drmInfo->getMimeType()); + reply->writeInt32(drmInfo->getCount()); + + DrmInfo::KeyIterator keyIt = drmInfo->keyIterator(); + while (keyIt.hasNext()) { + const String8 key = keyIt.next(); + reply->writeString8(key); + const String8 value = drmInfo->get(key); + reply->writeString8((value == String8("")) ? String8("NULL") : value); + } + delete [] drmBuffer.data; + } + delete drmInfoRequest; drmInfoRequest = NULL; + delete drmInfo; drmInfo = NULL; + return DRM_NO_ERROR; + } + + case SAVE_RIGHTS: + { + LOGV("BnDrmManagerService::onTransact :SAVE_RIGHTS"); + CHECK_INTERFACE(IDrmManagerService, data, reply); + + const int uniqueId = data.readInt32(); + + //Filling DRM Rights + const int bufferSize = data.readInt32(); + const DrmBuffer drmBuffer((char *)data.readInplace(bufferSize), bufferSize); + + const String8 mimeType(data.readString8()); + const String8 accountId(data.readString8()); + const String8 subscriptionId(data.readString8()); + const String8 rightsPath(data.readString8()); + const String8 contentPath(data.readString8()); + + DrmRights drmRights(drmBuffer, + ((mimeType == String8("NULL")) ? String8("") : mimeType), + ((accountId == String8("NULL")) ? String8("") : accountId), + ((subscriptionId == String8("NULL")) ? String8("") : subscriptionId)); + + saveRights(uniqueId, drmRights, + ((rightsPath == String8("NULL")) ? String8("") : rightsPath), + ((contentPath == String8("NULL")) ? String8("") : contentPath)); + + return DRM_NO_ERROR; + } + + case GET_ORIGINAL_MIMETYPE: + { + LOGV("BnDrmManagerService::onTransact :GET_ORIGINAL_MIMETYPE"); + CHECK_INTERFACE(IDrmManagerService, data, reply); + + const String8 originalMimeType = getOriginalMimeType(data.readInt32(), data.readString8()); + + reply->writeString8(originalMimeType); + return DRM_NO_ERROR; + } + + case GET_DRM_OBJECT_TYPE: + { + LOGV("BnDrmManagerService::onTransact :GET_DRM_OBJECT_TYPE"); + CHECK_INTERFACE(IDrmManagerService, data, reply); + + const int drmObjectType + = getDrmObjectType(data.readInt32(), data.readString8(), data.readString8()); + + reply->writeInt32(drmObjectType); + return DRM_NO_ERROR; + } + + case CHECK_RIGHTS_STATUS: + { + LOGV("BnDrmManagerService::onTransact :CHECK_RIGHTS_STATUS"); + CHECK_INTERFACE(IDrmManagerService, data, reply); + + const int result + = checkRightsStatus(data.readInt32(), data.readString8(), data.readInt32()); + + reply->writeInt32(result); + return DRM_NO_ERROR; + } + + case CONSUME_RIGHTS: + { + LOGV("BnDrmManagerService::onTransact :CONSUME_RIGHTS"); + CHECK_INTERFACE(IDrmManagerService, data, reply); + + const int uniqueId = data.readInt32(); + + DecryptHandle handle; + handle.decryptId = data.readInt32(); + handle.mimeType = data.readString8(); + handle.decryptApiType = data.readInt32(); + handle.status = data.readInt32(); + handle.decryptInfo = NULL; + + const int bufferLength = data.readInt32(); + if (INVALID_BUFFER_LENGTH != bufferLength) { + handle.decryptInfo = new DecryptInfo(); + handle.decryptInfo->decryptBufferLength = bufferLength; + } + + consumeRights(uniqueId, &handle, data.readInt32(), static_cast(data.readInt32())); + + delete handle.decryptInfo; handle.decryptInfo = NULL; + return DRM_NO_ERROR; + } + + case SET_PLAYBACK_STATUS: + { + LOGV("BnDrmManagerService::onTransact :SET_PLAYBACK_STATUS"); + CHECK_INTERFACE(IDrmManagerService, data, reply); + + const int uniqueId = data.readInt32(); + + DecryptHandle handle; + handle.decryptId = data.readInt32(); + handle.mimeType = data.readString8(); + handle.decryptApiType = data.readInt32(); + handle.status = data.readInt32(); + handle.decryptInfo = NULL; + + const int bufferLength = data.readInt32(); + if (INVALID_BUFFER_LENGTH != bufferLength) { + handle.decryptInfo = new DecryptInfo(); + handle.decryptInfo->decryptBufferLength = bufferLength; + } + + setPlaybackStatus(uniqueId, &handle, data.readInt32(), data.readInt32()); + + delete handle.decryptInfo; handle.decryptInfo = NULL; + return DRM_NO_ERROR; + } + + case VALIDATE_ACTION: + { + LOGV("BnDrmManagerService::onTransact :VALIDATE_ACTION"); + CHECK_INTERFACE(IDrmManagerService, data, reply); + + bool result = validateAction( + data.readInt32(), + data.readString8(), + data.readInt32(), + ActionDescription(data.readInt32(), data.readInt32())); + + reply->writeInt32(result); + return DRM_NO_ERROR; + } + + case REMOVE_RIGHTS: + { + LOGV("BnDrmManagerService::onTransact :REMOVE_RIGHTS"); + CHECK_INTERFACE(IDrmManagerService, data, reply); + + removeRights(data.readInt32(), data.readString8()); + + return DRM_NO_ERROR; + } + + case REMOVE_ALL_RIGHTS: + { + LOGV("BnDrmManagerService::onTransact :REMOVE_ALL_RIGHTS"); + CHECK_INTERFACE(IDrmManagerService, data, reply); + + removeAllRights(data.readInt32()); + + return DRM_NO_ERROR; + } + + case OPEN_CONVERT_SESSION: + { + LOGV("BnDrmManagerService::onTransact :OPEN_CONVERT_SESSION"); + CHECK_INTERFACE(IDrmManagerService, data, reply); + + const int convertId = openConvertSession(data.readInt32(), data.readString8()); + + reply->writeInt32(convertId); + return DRM_NO_ERROR; + } + + case CONVERT_DATA: + { + LOGV("BnDrmManagerService::onTransact :CONVERT_DATA"); + CHECK_INTERFACE(IDrmManagerService, data, reply); + + const int uniqueId = data.readInt32(); + const int convertId = data.readInt32(); + + //Filling input data + const int bufferSize = data.readInt32(); + DrmBuffer* inputData = new DrmBuffer((char *)data.readInplace(bufferSize), bufferSize); + + DrmConvertedStatus* drmConvertedStatus = convertData(uniqueId, convertId, inputData); + + if (NULL != drmConvertedStatus) { + //Filling Drm Converted Ststus + reply->writeInt32(drmConvertedStatus->statusCode); + reply->writeInt32(drmConvertedStatus->offset); + + if (NULL != drmConvertedStatus->convertedData) { + const DrmBuffer* convertedData = drmConvertedStatus->convertedData; + const int bufferSize = convertedData->length; + reply->writeInt32(bufferSize); + if (0 < bufferSize) { + reply->write(convertedData->data, bufferSize); + } + delete [] convertedData->data; + delete convertedData; convertedData = NULL; + } + } + delete inputData; inputData = NULL; + delete drmConvertedStatus; drmConvertedStatus = NULL; + return DRM_NO_ERROR; + } + + case CLOSE_CONVERT_SESSION: + { + LOGV("BnDrmManagerService::onTransact :CLOSE_CONVERT_SESSION"); + CHECK_INTERFACE(IDrmManagerService, data, reply); + + DrmConvertedStatus* drmConvertedStatus + = closeConvertSession(data.readInt32(), data.readInt32()); + + if (NULL != drmConvertedStatus) { + //Filling Drm Converted Ststus + reply->writeInt32(drmConvertedStatus->statusCode); + reply->writeInt32(drmConvertedStatus->offset); + + if (NULL != drmConvertedStatus->convertedData) { + const DrmBuffer* convertedData = drmConvertedStatus->convertedData; + const int bufferSize = convertedData->length; + reply->writeInt32(bufferSize); + if (0 < bufferSize) { + reply->write(convertedData->data, bufferSize); + } + delete [] convertedData->data; + delete convertedData; convertedData = NULL; + } + } + delete drmConvertedStatus; drmConvertedStatus = NULL; + return DRM_NO_ERROR; + } + + case GET_ALL_SUPPORT_INFO: + { + LOGV("BnDrmManagerService::onTransact :GET_ALL_SUPPORT_INFO"); + CHECK_INTERFACE(IDrmManagerService, data, reply); + + const int uniqueId = data.readInt32(); + int length = 0; + DrmSupportInfo* drmSupportInfoArray = NULL; + + status_t status = getAllSupportInfo(uniqueId, &length, &drmSupportInfoArray); + + reply->writeInt32(length); + for (int i = 0; i < length; ++i) { + DrmSupportInfo drmSupportInfo = drmSupportInfoArray[i]; + + reply->writeInt32(drmSupportInfo.getFileSuffixCount()); + DrmSupportInfo::FileSuffixIterator fileSuffixIt + = drmSupportInfo.getFileSuffixIterator(); + while (fileSuffixIt.hasNext()) { + reply->writeString8(fileSuffixIt.next()); + } + + reply->writeInt32(drmSupportInfo.getMimeTypeCount()); + DrmSupportInfo::MimeTypeIterator mimeTypeIt = drmSupportInfo.getMimeTypeIterator(); + while (mimeTypeIt.hasNext()) { + reply->writeString8(mimeTypeIt.next()); + } + reply->writeString8(drmSupportInfo.getDescription()); + } + delete [] drmSupportInfoArray; drmSupportInfoArray = NULL; + reply->writeInt32(status); + return DRM_NO_ERROR; + } + + case OPEN_DECRYPT_SESSION: + { + LOGV("BnDrmManagerService::onTransact :OPEN_DECRYPT_SESSION"); + CHECK_INTERFACE(IDrmManagerService, data, reply); + + const int uniqueId = data.readInt32(); + const int fd = data.readFileDescriptor(); + + DecryptHandle* handle + = openDecryptSession(uniqueId, fd, data.readInt32(), data.readInt32()); + + if (NULL != handle) { + reply->writeInt32(handle->decryptId); + reply->writeString8(handle->mimeType); + reply->writeInt32(handle->decryptApiType); + reply->writeInt32(handle->status); + if (NULL != handle->decryptInfo) { + reply->writeInt32(handle->decryptInfo->decryptBufferLength); + delete handle->decryptInfo; handle->decryptInfo = NULL; + } + } else { + LOGE("NULL decryptHandle is returned"); + } + delete handle; handle = NULL; + return DRM_NO_ERROR; + } + + case CLOSE_DECRYPT_SESSION: + { + LOGV("BnDrmManagerService::onTransact :CLOSE_DECRYPT_SESSION"); + CHECK_INTERFACE(IDrmManagerService, data, reply); + + const int uniqueId = data.readInt32(); + + DecryptHandle* handle = new DecryptHandle(); + handle->decryptId = data.readInt32(); + handle->mimeType = data.readString8(); + handle->decryptApiType = data.readInt32(); + handle->status = data.readInt32(); + handle->decryptInfo = NULL; + + const int bufferLength = data.readInt32(); + if (INVALID_BUFFER_LENGTH != bufferLength) { + handle->decryptInfo = new DecryptInfo(); + handle->decryptInfo->decryptBufferLength = bufferLength; + } + + closeDecryptSession(uniqueId, handle); + return DRM_NO_ERROR; + } + + case INITIALIZE_DECRYPT_UNIT: + { + LOGV("BnDrmManagerService::onTransact :INITIALIZE_DECRYPT_UNIT"); + CHECK_INTERFACE(IDrmManagerService, data, reply); + + const int uniqueId = data.readInt32(); + + DecryptHandle handle; + handle.decryptId = data.readInt32(); + handle.mimeType = data.readString8(); + handle.decryptApiType = data.readInt32(); + handle.status = data.readInt32(); + handle.decryptInfo = NULL; + + const int bufferLength = data.readInt32(); + if (INVALID_BUFFER_LENGTH != bufferLength) { + handle.decryptInfo = new DecryptInfo(); + handle.decryptInfo->decryptBufferLength = bufferLength; + } + const int decryptUnitId = data.readInt32(); + + //Filling Header info + const int bufferSize = data.readInt32(); + DrmBuffer* headerInfo = NULL; + headerInfo = new DrmBuffer((char *)data.readInplace(bufferSize), bufferSize); + + initializeDecryptUnit(uniqueId, &handle, decryptUnitId, headerInfo); + + delete handle.decryptInfo; handle.decryptInfo = NULL; + delete headerInfo; headerInfo = NULL; + return DRM_NO_ERROR; + } + + case DECRYPT: + { + LOGV("BnDrmManagerService::onTransact :DECRYPT"); + CHECK_INTERFACE(IDrmManagerService, data, reply); + + const int uniqueId = data.readInt32(); + + DecryptHandle handle; + handle.decryptId = data.readInt32(); + handle.mimeType = data.readString8(); + handle.decryptApiType = data.readInt32(); + handle.status = data.readInt32(); + handle.decryptInfo = NULL; + + const int bufferLength = data.readInt32(); + if (INVALID_BUFFER_LENGTH != bufferLength) { + handle.decryptInfo = new DecryptInfo(); + handle.decryptInfo->decryptBufferLength = bufferLength; + } + const int decryptUnitId = data.readInt32(); + const int decBufferSize = data.readInt32(); + + const int encBufferSize = data.readInt32(); + DrmBuffer* encBuffer + = new DrmBuffer((char *)data.readInplace(encBufferSize), encBufferSize); + + char* buffer = NULL; + buffer = new char[decBufferSize]; + DrmBuffer* decBuffer = new DrmBuffer(buffer, decBufferSize); + + const status_t status = decrypt(uniqueId, &handle, decryptUnitId, encBuffer, &decBuffer); + + reply->writeInt32(status); + + const int size = decBuffer->length; + reply->writeInt32(size); + reply->write(decBuffer->data, size); + + delete handle.decryptInfo; handle.decryptInfo = NULL; + delete encBuffer; encBuffer = NULL; + delete decBuffer; decBuffer = NULL; + delete [] buffer; buffer = NULL; + return DRM_NO_ERROR; + } + + case FINALIZE_DECRYPT_UNIT: + { + LOGV("BnDrmManagerService::onTransact :FINALIZE_DECRYPT_UNIT"); + CHECK_INTERFACE(IDrmManagerService, data, reply); + + const int uniqueId = data.readInt32(); + + DecryptHandle handle; + handle.decryptId = data.readInt32(); + handle.mimeType = data.readString8(); + handle.decryptApiType = data.readInt32(); + handle.status = data.readInt32(); + handle.decryptInfo = NULL; + + const int bufferLength = data.readInt32(); + if (INVALID_BUFFER_LENGTH != bufferLength) { + handle.decryptInfo = new DecryptInfo(); + handle.decryptInfo->decryptBufferLength = bufferLength; + } + + finalizeDecryptUnit(uniqueId, &handle, data.readInt32()); + + delete handle.decryptInfo; handle.decryptInfo = NULL; + return DRM_NO_ERROR; + } + + case PREAD: + { + LOGV("BnDrmManagerService::onTransact :READ"); + CHECK_INTERFACE(IDrmManagerService, data, reply); + + const int uniqueId = data.readInt32(); + + DecryptHandle handle; + handle.decryptId = data.readInt32(); + handle.mimeType = data.readString8(); + handle.decryptApiType = data.readInt32(); + handle.status = data.readInt32(); + handle.decryptInfo = NULL; + + const int bufferLength = data.readInt32(); + if (INVALID_BUFFER_LENGTH != bufferLength) { + handle.decryptInfo = new DecryptInfo(); + handle.decryptInfo->decryptBufferLength = bufferLength; + } + + const int numBytes = data.readInt32(); + char* buffer = new char[numBytes]; + + const off_t offset = data.readInt32(); + + ssize_t result = pread(uniqueId, &handle, buffer, numBytes, offset); + reply->writeInt32(result); + if (0 < result) { + reply->write(buffer, result); + } + + delete handle.decryptInfo; handle.decryptInfo = NULL; + delete [] buffer, buffer = NULL; + return DRM_NO_ERROR; + } + + default: + return BBinder::onTransact(code, data, reply, flags); + } +} + diff --git a/drm/common/IDrmServiceListener.cpp b/drm/common/IDrmServiceListener.cpp new file mode 100644 index 0000000..0a69115 --- /dev/null +++ b/drm/common/IDrmServiceListener.cpp @@ -0,0 +1,65 @@ +/* + * 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 "IDrmServiceListener" +#include + +#include +#include +#include +#include +#include +#include +#include "IDrmServiceListener.h" + +using namespace android; + +status_t BpDrmServiceListener::notify(const DrmInfoEvent& event) { + Parcel data, reply; + + data.writeInterfaceToken(IDrmServiceListener::getInterfaceDescriptor()); + data.writeInt32(event.getUniqueId()); + data.writeInt32(event.getType()); + data.writeString8(event.getMessage()); + + remote()->transact(NOTIFY, data, &reply); + return reply.readInt32(); +} + +IMPLEMENT_META_INTERFACE(DrmServiceListener, "drm.IDrmServiceListener"); + +status_t BnDrmServiceListener::onTransact( + uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) { + + switch (code) { + case NOTIFY: + { + CHECK_INTERFACE(IDrmServiceListener, data, reply); + int uniqueId = data.readInt32(); + int type = data.readInt32(); + const String8& message = data.readString8(); + + status_t status = notify(DrmInfoEvent(uniqueId, type, message)); + reply->writeInt32(status); + + return DRM_NO_ERROR; + } + default: + return BBinder::onTransact(code, data, reply, flags); + } +} + diff --git a/drm/common/ReadWriteUtils.cpp b/drm/common/ReadWriteUtils.cpp new file mode 100644 index 0000000..4319c1c --- /dev/null +++ b/drm/common/ReadWriteUtils.cpp @@ -0,0 +1,100 @@ +/* + * 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 +#include + +using namespace android; + +#define FAILURE -1 + +String8 ReadWriteUtils::readBytes(const String8& filePath) { + FILE* file = NULL; + file = fopen(filePath.string(), "r"); + + String8 string(""); + if (NULL != file) { + int fd = fileno(file); + struct stat sb; + + if (fstat(fd, &sb) == 0 && sb.st_size > 0) { + FileMap* fileMap = new FileMap(); + if (fileMap->create(filePath.string(), fd, 0, sb.st_size, true)) { + char* addr = (char*)fileMap->getDataPtr(); + string.append(addr, sb.st_size); + fileMap->release(); + } + } + fclose(file); + } + return string; +} + +void ReadWriteUtils::writeToFile(const String8& filePath, const String8& data) { + FILE* file = NULL; + file = fopen(filePath.string(), "w+"); + + if (NULL != file) { + int fd = fileno(file); + + int size = data.size(); + if (FAILURE != ftruncate(fd, size)) { + FileMap* fileMap = NULL; + fileMap = new FileMap(); + if (fileMap->create(filePath.string(), fd, 0, size, false)) { + char* addr = (char*)fileMap->getDataPtr(); + memcpy(addr, data.string(), size); + fileMap->release(); + } + } + fclose(file); + } +} + +void ReadWriteUtils::appendToFile(const String8& filePath, const String8& data) { + FILE* file = NULL; + file = fopen(filePath.string(), "a+"); + + if (NULL != file) { + int fd = fileno(file); + + int offset = lseek(fd, 0, SEEK_END); + if (FAILURE != offset) { + int newEntrySize = data.size(); + int fileSize = offset + newEntrySize; + + if (FAILURE != ftruncate(fd, fileSize)) { + FileMap* fileMap = NULL; + fileMap = new FileMap(); + if (fileMap->create(filePath.string(), fd, offset, fileSize, false)) { + char* addr = (char*)fileMap->getDataPtr(); + memcpy(addr, data.string(), data.size()); + fileMap->release(); + } + } + } + fclose(file); + } +} + 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(); +} + diff --git a/drm/libdrmframework/Android.mk b/drm/libdrmframework/Android.mk new file mode 100644 index 0000000..c25d79b --- /dev/null +++ b/drm/libdrmframework/Android.mk @@ -0,0 +1,42 @@ +# +# 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:= \ + DrmManagerClientImpl.cpp \ + DrmManagerClient.cpp + +LOCAL_MODULE:= libdrmframework + +LOCAL_SHARED_LIBRARIES := \ + libutils \ + libbinder \ + libdl + +LOCAL_STATIC_LIBRARIES := \ + libdrmframeworkcommon + +LOCAL_C_INCLUDES += \ + $(TOP)/frameworks/base/drm/libdrmframework/include \ + $(TOP)/frameworks/base/include + +LOCAL_PRELINK_MODULE := false + +include $(BUILD_SHARED_LIBRARY) + +include $(call all-makefiles-under,$(LOCAL_PATH)) diff --git a/drm/libdrmframework/DrmManagerClient.cpp b/drm/libdrmframework/DrmManagerClient.cpp new file mode 100644 index 0000000..06c7c50 --- /dev/null +++ b/drm/libdrmframework/DrmManagerClient.cpp @@ -0,0 +1,159 @@ +/* + * 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 "DrmManagerClient(Native)" +#include + +#include +#include +#include + +#include "DrmManagerClientImpl.h" + +using namespace android; + +DrmManagerClient::DrmManagerClient() { + int uniqueId = 0; + mDrmManagerClientImpl = NULL; + + mDrmManagerClientImpl = DrmManagerClientImpl::create(&uniqueId); + mUniqueId = uniqueId; + + loadPlugIns(); +} + +DrmManagerClient::~DrmManagerClient() { + unloadPlugIns(); + DrmManagerClientImpl::remove(mUniqueId); + + delete mDrmManagerClientImpl; mDrmManagerClientImpl = NULL; +} + +status_t DrmManagerClient::loadPlugIns() { + return mDrmManagerClientImpl->loadPlugIns(mUniqueId); +} + +status_t DrmManagerClient::setOnInfoListener( + const sp& infoListener) { + return mDrmManagerClientImpl->setOnInfoListener(mUniqueId, infoListener); +} + +status_t DrmManagerClient::unloadPlugIns() { + return mDrmManagerClientImpl->unloadPlugIns(mUniqueId); +} + +DrmConstraints* DrmManagerClient::getConstraints(const String8* path, const int action) { + return mDrmManagerClientImpl->getConstraints(mUniqueId, path, action); +} + +bool DrmManagerClient::canHandle(const String8& path, const String8& mimeType) { + return mDrmManagerClientImpl->canHandle(mUniqueId, path, mimeType); +} + +DrmInfoStatus* DrmManagerClient::processDrmInfo(const DrmInfo* drmInfo) { + return mDrmManagerClientImpl->processDrmInfo(mUniqueId, drmInfo); +} + +DrmInfo* DrmManagerClient::acquireDrmInfo(const DrmInfoRequest* drmInfoRequest) { + return mDrmManagerClientImpl->acquireDrmInfo(mUniqueId, drmInfoRequest); +} + +void DrmManagerClient::saveRights( + const DrmRights& drmRights, const String8& rightsPath, const String8& contentPath) { + return mDrmManagerClientImpl->saveRights(mUniqueId, drmRights, rightsPath, contentPath); +} + +String8 DrmManagerClient::getOriginalMimeType(const String8& path) { + return mDrmManagerClientImpl->getOriginalMimeType(mUniqueId, path); +} + +int DrmManagerClient::getDrmObjectType(const String8& path, const String8& mimeType) { + return mDrmManagerClientImpl->getDrmObjectType( mUniqueId, path, mimeType); +} + +int DrmManagerClient::checkRightsStatus(const String8& path, int action) { + return mDrmManagerClientImpl->checkRightsStatus(mUniqueId, path, action); +} + +void DrmManagerClient::consumeRights(DecryptHandle* decryptHandle, int action, bool reserve) { + mDrmManagerClientImpl->consumeRights(mUniqueId, decryptHandle, action, reserve); +} + +void DrmManagerClient::setPlaybackStatus( + DecryptHandle* decryptHandle, int playbackStatus, int position) { + mDrmManagerClientImpl->setPlaybackStatus(mUniqueId, decryptHandle, playbackStatus, position); +} + +bool DrmManagerClient::validateAction( + const String8& path, int action, const ActionDescription& description) { + return mDrmManagerClientImpl->validateAction(mUniqueId, path, action, description); +} + +void DrmManagerClient::removeRights(const String8& path) { + mDrmManagerClientImpl->removeRights(mUniqueId, path); +} + +void DrmManagerClient::removeAllRights() { + mDrmManagerClientImpl->removeAllRights(mUniqueId); +} + +int DrmManagerClient::openConvertSession(const String8& mimeType) { + return mDrmManagerClientImpl->openConvertSession(mUniqueId, mimeType); +} + +DrmConvertedStatus* DrmManagerClient::convertData(int convertId, const DrmBuffer* inputData) { + return mDrmManagerClientImpl->convertData(mUniqueId, convertId, inputData); +} + +DrmConvertedStatus* DrmManagerClient::closeConvertSession(int convertId) { + return mDrmManagerClientImpl->closeConvertSession(mUniqueId, convertId); +} + +status_t DrmManagerClient::getAllSupportInfo(int* length, DrmSupportInfo** drmSupportInfoArray) { + return mDrmManagerClientImpl->getAllSupportInfo(mUniqueId, length, drmSupportInfoArray); +} + +DecryptHandle* DrmManagerClient::openDecryptSession(int fd, int offset, int length) { + return mDrmManagerClientImpl->openDecryptSession(mUniqueId, fd, offset, length); +} + +void DrmManagerClient::closeDecryptSession(DecryptHandle* decryptHandle) { + mDrmManagerClientImpl->closeDecryptSession(mUniqueId, decryptHandle); +} + +void DrmManagerClient::initializeDecryptUnit( + DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo) { + mDrmManagerClientImpl->initializeDecryptUnit( + mUniqueId, decryptHandle, decryptUnitId, headerInfo); +} + +status_t DrmManagerClient::decrypt( + DecryptHandle* decryptHandle, int decryptUnitId, + const DrmBuffer* encBuffer, DrmBuffer** decBuffer) { + return mDrmManagerClientImpl->decrypt( + mUniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer); +} + +void DrmManagerClient::finalizeDecryptUnit(DecryptHandle* decryptHandle, int decryptUnitId) { + mDrmManagerClientImpl->finalizeDecryptUnit(mUniqueId, decryptHandle, decryptUnitId); +} + +ssize_t DrmManagerClient::pread( + DecryptHandle* decryptHandle, void* buffer, ssize_t numBytes, off_t offset) { + return mDrmManagerClientImpl->pread(mUniqueId, decryptHandle, buffer, numBytes, offset); +} + diff --git a/drm/libdrmframework/DrmManagerClientImpl.cpp b/drm/libdrmframework/DrmManagerClientImpl.cpp new file mode 100644 index 0000000..7274b49 --- /dev/null +++ b/drm/libdrmframework/DrmManagerClientImpl.cpp @@ -0,0 +1,319 @@ +/* + * 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 "DrmManagerClientImpl(Native)" +#include + +#include +#include +#include + +#include "DrmManagerClientImpl.h" + +using namespace android; + +#define INVALID_VALUE -1 + +Mutex DrmManagerClientImpl::mMutex; +Vector DrmManagerClientImpl::mUniqueIdVector; +sp DrmManagerClientImpl::mDrmManagerService; +const String8 DrmManagerClientImpl::EMPTY_STRING(""); + +DrmManagerClientImpl* DrmManagerClientImpl::create(int* pUniqueId) { + if (0 == *pUniqueId) { + int uniqueId = 0; + bool foundUniqueId = false; + srand(time(NULL)); + + while (!foundUniqueId) { + const int size = mUniqueIdVector.size(); + uniqueId = rand() % 100; + + int index = 0; + for (; index < size; ++index) { + if (mUniqueIdVector.itemAt(index) == uniqueId) { + foundUniqueId = false; + break; + } + } + if (index == size) { + foundUniqueId = true; + } + } + *pUniqueId = uniqueId; + } + mUniqueIdVector.push(*pUniqueId); + return new DrmManagerClientImpl(); +} + +void DrmManagerClientImpl::remove(int uniqueId) { + for (int i = 0; i < mUniqueIdVector.size(); i++) { + if (uniqueId == mUniqueIdVector.itemAt(i)) { + mUniqueIdVector.removeAt(i); + break; + } + } +} + +DrmManagerClientImpl::DrmManagerClientImpl() { + +} + +DrmManagerClientImpl::~DrmManagerClientImpl() { + +} + +const sp& DrmManagerClientImpl::getDrmManagerService() { + mMutex.lock(); + if (NULL == mDrmManagerService.get()) { + sp sm = defaultServiceManager(); + sp binder; + do { + binder = sm->getService(String16("drm.drmManager")); + if (binder != 0) { + break; + } + LOGW("DrmManagerService not published, waiting..."); + struct timespec reqt; + reqt.tv_sec = 0; + reqt.tv_nsec = 500000000; //0.5 sec + nanosleep(&reqt, NULL); + } while (true); + + mDrmManagerService = interface_cast(binder); + } + mMutex.unlock(); + return mDrmManagerService; +} + +status_t DrmManagerClientImpl::loadPlugIns(int uniqueId) { + return getDrmManagerService()->loadPlugIns(uniqueId); +} + +status_t DrmManagerClientImpl::loadPlugIns(int uniqueId, const String8& plugInDirPath) { + status_t status = DRM_ERROR_UNKNOWN; + if (EMPTY_STRING != plugInDirPath) { + status = getDrmManagerService()->loadPlugIns(uniqueId, plugInDirPath); + } + return status; +} + +status_t DrmManagerClientImpl::setOnInfoListener( + int uniqueId, const sp& infoListener) { + Mutex::Autolock _l(mLock); + mOnInfoListener = infoListener; + return getDrmManagerService()->setDrmServiceListener(uniqueId, this); +} + +status_t DrmManagerClientImpl::unloadPlugIns(int uniqueId) { + return getDrmManagerService()->unloadPlugIns(uniqueId); +} + +status_t DrmManagerClientImpl::installDrmEngine(int uniqueId, const String8& drmEngineFile) { + status_t status = DRM_ERROR_UNKNOWN; + if (EMPTY_STRING != drmEngineFile) { + status = getDrmManagerService()->installDrmEngine(uniqueId, drmEngineFile); + } + return status; +} + +DrmConstraints* DrmManagerClientImpl::getConstraints( + int uniqueId, const String8* path, const int action) { + DrmConstraints *drmConstraints = NULL; + if ((NULL != path) && (EMPTY_STRING != *path)) { + drmConstraints = getDrmManagerService()->getConstraints(uniqueId, path, action); + } + return drmConstraints; +} + +bool DrmManagerClientImpl::canHandle(int uniqueId, const String8& path, const String8& mimeType) { + bool retCode = false; + if ((EMPTY_STRING != path) || (EMPTY_STRING != mimeType)) { + retCode = getDrmManagerService()->canHandle(uniqueId, path, mimeType); + } + return retCode; +} + +DrmInfoStatus* DrmManagerClientImpl::processDrmInfo(int uniqueId, const DrmInfo* drmInfo) { + DrmInfoStatus *drmInfoStatus = NULL; + if (NULL != drmInfo) { + drmInfoStatus = getDrmManagerService()->processDrmInfo(uniqueId, drmInfo); + } + return drmInfoStatus; +} + +DrmInfo* DrmManagerClientImpl::acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest) { + DrmInfo* drmInfo = NULL; + if (NULL != drmInfoRequest) { + drmInfo = getDrmManagerService()->acquireDrmInfo(uniqueId, drmInfoRequest); + } + return drmInfo; +} + +void DrmManagerClientImpl::saveRights(int uniqueId, const DrmRights& drmRights, + const String8& rightsPath, const String8& contentPath) { + if (EMPTY_STRING != contentPath) { + getDrmManagerService()->saveRights(uniqueId, drmRights, rightsPath, contentPath); + } +} + +String8 DrmManagerClientImpl::getOriginalMimeType(int uniqueId, const String8& path) { + String8 mimeType = EMPTY_STRING; + if (EMPTY_STRING != path) { + mimeType = getDrmManagerService()->getOriginalMimeType(uniqueId, path); + } + return mimeType; +} + +int DrmManagerClientImpl::getDrmObjectType( + int uniqueId, const String8& path, const String8& mimeType) { + int drmOjectType = DrmObjectType::UNKNOWN; + if ((EMPTY_STRING != path) || (EMPTY_STRING != mimeType)) { + drmOjectType = getDrmManagerService()->getDrmObjectType(uniqueId, path, mimeType); + } + return drmOjectType; +} + +int DrmManagerClientImpl::checkRightsStatus( + int uniqueId, const String8& path, int action) { + int rightsStatus = RightsStatus::RIGHTS_INVALID; + if (EMPTY_STRING != path) { + rightsStatus = getDrmManagerService()->checkRightsStatus(uniqueId, path, action); + } + return rightsStatus; +} + +void DrmManagerClientImpl::consumeRights( + int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) { + if (NULL != decryptHandle) { + getDrmManagerService()->consumeRights(uniqueId, decryptHandle, action, reserve); + } +} + +void DrmManagerClientImpl::setPlaybackStatus( + int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position) { + if (NULL != decryptHandle) { + getDrmManagerService()->setPlaybackStatus( + uniqueId, decryptHandle, playbackStatus, position); + } +} + +bool DrmManagerClientImpl::validateAction( + int uniqueId, const String8& path, int action, const ActionDescription& description) { + bool retCode = false; + if (EMPTY_STRING != path) { + retCode = getDrmManagerService()->validateAction(uniqueId, path, action, description); + } + return retCode; +} + +void DrmManagerClientImpl::removeRights(int uniqueId, const String8& path) { + if (EMPTY_STRING != path) { + getDrmManagerService()->removeRights(uniqueId, path); + } +} + +void DrmManagerClientImpl::removeAllRights(int uniqueId) { + getDrmManagerService()->removeAllRights(uniqueId); +} + +int DrmManagerClientImpl::openConvertSession(int uniqueId, const String8& mimeType) { + int retCode = INVALID_VALUE; + if (EMPTY_STRING != mimeType) { + retCode = getDrmManagerService()->openConvertSession(uniqueId, mimeType); + } + return retCode; +} + +DrmConvertedStatus* DrmManagerClientImpl::convertData( + int uniqueId, int convertId, const DrmBuffer* inputData) { + DrmConvertedStatus* drmConvertedStatus = NULL; + if (NULL != inputData) { + drmConvertedStatus = getDrmManagerService()->convertData(uniqueId, convertId, inputData); + } + return drmConvertedStatus; +} + +DrmConvertedStatus* DrmManagerClientImpl::closeConvertSession(int uniqueId, int convertId) { + return getDrmManagerService()->closeConvertSession(uniqueId, convertId); +} + +status_t DrmManagerClientImpl::getAllSupportInfo( + int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray) { + status_t status = DRM_ERROR_UNKNOWN; + if ((NULL != drmSupportInfoArray) && (NULL != length)) { + status = getDrmManagerService()->getAllSupportInfo(uniqueId, length, drmSupportInfoArray); + } + return status; +} + +DecryptHandle* DrmManagerClientImpl::openDecryptSession( + int uniqueId, int fd, int offset, int length) { + LOGV("Entering DrmManagerClientImpl::openDecryptSession"); + return getDrmManagerService()->openDecryptSession(uniqueId, fd, offset, length); +} + +void DrmManagerClientImpl::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) { + if (NULL != decryptHandle) { + getDrmManagerService()->closeDecryptSession( uniqueId, decryptHandle); + } +} + +void DrmManagerClientImpl::initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, + int decryptUnitId, const DrmBuffer* headerInfo) { + if ((NULL != decryptHandle) && (NULL != headerInfo)) { + getDrmManagerService()->initializeDecryptUnit( + uniqueId, decryptHandle, decryptUnitId, headerInfo); + } +} + +status_t DrmManagerClientImpl::decrypt(int uniqueId, DecryptHandle* decryptHandle, + int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer) { + status_t status = DRM_ERROR_UNKNOWN; + if ((NULL != decryptHandle) && (NULL != encBuffer) + && (NULL != decBuffer) && (NULL != *decBuffer)) { + status = getDrmManagerService()->decrypt( + uniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer); + } + return status; +} + +void DrmManagerClientImpl::finalizeDecryptUnit( + int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) { + if (NULL != decryptHandle) { + getDrmManagerService()->finalizeDecryptUnit(uniqueId, decryptHandle, decryptUnitId); + } +} + +ssize_t DrmManagerClientImpl::pread(int uniqueId, DecryptHandle* decryptHandle, + void* buffer, ssize_t numBytes, off_t offset) { + ssize_t retCode = INVALID_VALUE; + if ((NULL != decryptHandle) && (NULL != buffer) && (0 < numBytes)) { + retCode = getDrmManagerService()->pread(uniqueId, decryptHandle, buffer, numBytes, offset); + } + return retCode; +} + +status_t DrmManagerClientImpl::notify(const DrmInfoEvent& event) { + if (NULL != mOnInfoListener.get()) { + Mutex::Autolock _l(mLock); + sp listener = mOnInfoListener; + listener->onInfo(event); + } + return DRM_NO_ERROR; +} + diff --git a/drm/libdrmframework/include/DrmIOService.h b/drm/libdrmframework/include/DrmIOService.h new file mode 100644 index 0000000..244124e --- /dev/null +++ b/drm/libdrmframework/include/DrmIOService.h @@ -0,0 +1,46 @@ +/* + * 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. + */ + +#ifndef __DRM_IO_SERVICE_H__ +#define __DRM_IO_SERVICE_H__ + +#include "IDrmIOService.h" + +namespace android { + +/** + * This is the implementation class for DRM IO service. + * + * The instance of this class is created while starting the DRM IO service. + * + */ +class DrmIOService : public BnDrmIOService { +public: + static void instantiate(); + +private: + DrmIOService(); + virtual ~DrmIOService(); + +public: + void writeToFile(const String8& filePath, const String8& dataBuffer); + String8 readFromFile(const String8& filePath); +}; + +}; + +#endif /* __DRM_IO_SERVICE_H__ */ + diff --git a/drm/libdrmframework/include/DrmManager.h b/drm/libdrmframework/include/DrmManager.h new file mode 100644 index 0000000..2ba9e99 --- /dev/null +++ b/drm/libdrmframework/include/DrmManager.h @@ -0,0 +1,153 @@ +/* + * 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. + */ + +#ifndef __DRM_MANAGER_H__ +#define __DRM_MANAGER_H__ + +#include +#include +#include +#include "IDrmEngine.h" +#include "PlugInManager.h" +#include "IDrmServiceListener.h" + +namespace android { + +class IDrmManager; +class DrmRegistrationInfo; +class DrmUnregistrationInfo; +class DrmRightsAcquisitionInfo; +class DrmContentIds; +class DrmConstraints; +class DrmRights; +class DrmInfo; +class DrmInfoStatus; +class DrmConvertedStatus; +class DrmInfoRequest; +class DrmSupportInfo; +class ActionDescription; + +/** + * This is implementation class for DRM Manager. This class delegates the + * functionality to corresponding DRM Engine. + * + * The DrmManagerService class creates an instance of this class. + * + */ +class DrmManager : public IDrmEngine::OnInfoListener { +public: + DrmManager(); + virtual ~DrmManager(); + +public: + + status_t loadPlugIns(int uniqueId); + + status_t loadPlugIns(int uniqueId, const String8& plugInDirPath); + + status_t setDrmServiceListener( + int uniqueId, const sp& drmServiceListener); + + status_t unloadPlugIns(int uniqueId); + + status_t installDrmEngine(int uniqueId, const String8& drmEngineFile); + + DrmConstraints* getConstraints(int uniqueId, const String8* path, const int action); + + bool canHandle(int uniqueId, const String8& path, const String8& mimeType); + + DrmInfoStatus* processDrmInfo(int uniqueId, const DrmInfo* drmInfo); + + DrmInfo* acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest); + + void saveRights(int uniqueId, const DrmRights& drmRights, + const String8& rightsPath, const String8& contentPath); + + String8 getOriginalMimeType(int uniqueId, const String8& path); + + int getDrmObjectType(int uniqueId, const String8& path, const String8& mimeType); + + int checkRightsStatus(int uniqueId, const String8& path, int action); + + void consumeRights(int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve); + + void setPlaybackStatus( + int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position); + + bool validateAction( + int uniqueId, const String8& path, int action, const ActionDescription& description); + + void removeRights(int uniqueId, const String8& path); + + void removeAllRights(int uniqueId); + + int openConvertSession(int uniqueId, const String8& mimeType); + + DrmConvertedStatus* convertData(int uniqueId, int convertId, const DrmBuffer* inputData); + + DrmConvertedStatus* closeConvertSession(int uniqueId, int convertId); + + status_t getAllSupportInfo(int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray); + + DecryptHandle* openDecryptSession(int uniqueId, int fd, int offset, int length); + + void closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle); + + void initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, + int decryptUnitId, const DrmBuffer* headerInfo); + + status_t decrypt(int uniqueId, DecryptHandle* decryptHandle, + int decryptUnitId, const DrmBuffer* encBuffer,DrmBuffer** decBuffer); + + void finalizeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId); + + ssize_t pread(int uniqueId, DecryptHandle* decryptHandle, + void* buffer, ssize_t numBytes, off_t offset); + + void onInfo(const DrmInfoEvent& event); + +private: + String8 getSupportedPlugInId(int uniqueId, const String8& path, const String8& mimeType); + + String8 getSupportedPlugInId(const String8& mimeType); + + String8 getSupportedPlugInIdFromPath(int uniqueId, const String8& path); + + void populate(int uniqueId); + + bool canHandle(int uniqueId, const String8& path); + + void initializePlugIns(int uniqueId); + +private: + static const String8 EMPTY_STRING; + + int mDecryptSessionId; + int mConvertId; + Mutex mLock; + Mutex mDecryptLock; + Mutex mConvertLock; + TPlugInManager mPlugInManager; + KeyedVector< DrmSupportInfo, String8 > mSupportInfoToPlugInIdMap; + KeyedVector< int, IDrmEngine*> mConvertSessionMap; + KeyedVector< int, sp > mServiceListeners; + KeyedVector< int, IDrmEngine*> mDecryptSessionMap; +}; + +}; + +#endif /* __DRM_MANAGER_H__ */ + diff --git a/drm/libdrmframework/include/DrmManagerClientImpl.h b/drm/libdrmframework/include/DrmManagerClientImpl.h new file mode 100644 index 0000000..e70e6e1 --- /dev/null +++ b/drm/libdrmframework/include/DrmManagerClientImpl.h @@ -0,0 +1,400 @@ +/* + * 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. + */ + +#ifndef __DRM_MANAGER_CLIENT_IMPL_H__ +#define __DRM_MANAGER_CLIENT_IMPL_H__ + +#include +#include +#include + +#include "IDrmManagerService.h" + +namespace android { + +class DrmInfoEvent; +/** + * This is implementation class for DrmManagerClient class. + * + * Only the JNI layer creates an instance of this class to delegate + * functionality to Native later. + * + */ +class DrmManagerClientImpl : public BnDrmServiceListener { +private: + DrmManagerClientImpl(); + +public: + static DrmManagerClientImpl* create(int* pUniqueId); + + static void remove(int uniqueId); + + virtual ~DrmManagerClientImpl(); + +public: + /** + * Initialize DRM Manager + * load available plug-ins from default plugInDirPath + * + * @param[in] uniqueId Unique identifier for a session + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure + */ + status_t loadPlugIns(int uniqueId); + + /** + * Finalize DRM Manager + * release resources associated with each plug-in + * unload all plug-ins and etc. + * + * @param[in] uniqueId Unique identifier for a session + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure + */ + status_t unloadPlugIns(int uniqueId); + + /** + * Register a callback to be invoked when the caller required to + * receive necessary information + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] infoListener Listener + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure + */ + status_t setOnInfoListener( + int uniqueId, const sp& infoListener); + + /** + * Get constraint information associated with input content + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] path Path of the protected content + * @param[in] action Actions defined such as, + * Action::DEFAULT, Action::PLAY, etc + * @return DrmConstraints + * key-value pairs of constraint are embedded in it + * @note + * In case of error, return NULL + */ + DrmConstraints* getConstraints(int uniqueId, const String8* path, const int action); + + /** + * Check whether the given mimetype or path can be handled + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] path Path of the content needs to be handled + * @param[in] mimetype Mimetype of the content needs to be handled + * @return + * True if DrmManager can handle given path or mime type. + */ + bool canHandle(int uniqueId, const String8& path, const String8& mimeType); + + /** + * Executes given drm information based on its type + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] drmInfo Information needs to be processed + * @return DrmInfoStatus + * instance as a result of processing given input + */ + DrmInfoStatus* processDrmInfo(int uniqueId, const DrmInfo* drmInfo); + + /** + * Retrieves necessary information for registration, unregistration or rights + * acquisition information. + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] drmInfoRequest Request information to retrieve drmInfo + * @return DrmInfo + * instance as a result of processing given input + */ + DrmInfo* acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest); + + /** + * Save DRM rights to specified rights path + * and make association with content path + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] drmRights DrmRights to be saved + * @param[in] rightsPath File path where rights to be saved + * @param[in] contentPath File path where content was saved + */ + void saveRights(int uniqueId, const DrmRights& drmRights, + const String8& rightsPath, const String8& contentPath); + + /** + * Retrieves the mime type embedded inside the original content + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] path the path of the protected content + * @return String8 + * Returns mime-type of the original content, such as "video/mpeg" + */ + String8 getOriginalMimeType(int uniqueId, const String8& path); + + /** + * Retrieves the type of the protected object (content, rights, etc..) + * using specified path or mimetype. At least one parameter should be non null + * to retrieve DRM object type + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] path Path of the content or null. + * @param[in] mimeType Mime type of the content or null. + * @return type of the DRM content, + * such as DrmObjectType::CONTENT, DrmObjectType::RIGHTS_OBJECT + */ + int getDrmObjectType(int uniqueId, const String8& path, const String8& mimeType); + + /** + * Check whether the given content has valid rights or not + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] path Path of the protected content + * @param[in] action Action to perform (Action::DEFAULT, Action::PLAY, etc) + * @return the status of the rights for the protected content, + * such as RightsStatus::RIGHTS_VALID, RightsStatus::RIGHTS_EXPIRED, etc. + */ + int checkRightsStatus(int uniqueId, const String8& path, int action); + + /** + * Consumes the rights for a content. + * If the reserve parameter is true the rights is reserved until the same + * application calls this api again with the reserve parameter set to false. + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] decryptHandle Handle for the decryption session + * @param[in] action Action to perform. (Action::DEFAULT, Action::PLAY, etc) + * @param[in] reserve True if the rights should be reserved. + */ + void consumeRights(int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve); + + /** + * Informs the DRM engine about the playback actions performed on the DRM files. + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] decryptHandle Handle for the decryption session + * @param[in] playbackStatus Playback action (Playback::START, Playback::STOP, Playback::PAUSE) + * @param[in] position Position in the file (in milliseconds) where the start occurs. + * Only valid together with Playback::START. + */ + void setPlaybackStatus( + int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position); + + /** + * Validates whether an action on the DRM content is allowed or not. + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] path Path of the protected content + * @param[in] action Action to validate (Action::PLAY, Action::TRANSFER, etc) + * @param[in] description Detailed description of the action + * @return true if the action is allowed. + */ + bool validateAction( + int uniqueId, const String8& path, int action, const ActionDescription& description); + + /** + * Removes the rights associated with the given protected content + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] path Path of the protected content + */ + void removeRights(int uniqueId, const String8& path); + + /** + * Removes all the rights information of each plug-in associated with + * DRM framework. Will be used in master reset + * + * @param[in] uniqueId Unique identifier for a session + */ + void removeAllRights(int uniqueId); + + /** + * This API is for Forward Lock based DRM scheme. + * Each time the application tries to download a new DRM file + * which needs to be converted, then the application has to + * begin with calling this API. + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] mimeType Description/MIME type of the input data packet + * @return Return handle for the convert session + */ + int openConvertSession(int uniqueId, const String8& mimeType); + + /** + * Accepts and converts the input data which is part of DRM file. + * The resultant converted data and the status is returned in the DrmConvertedInfo + * object. This method will be called each time there are new block + * of data received by the application. + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] convertId Handle for the convert session + * @param[in] inputData Input Data which need to be converted + * @return Return object contains the status of the data conversion, + * the output converted data and offset. In this case the + * application will ignore the offset information. + */ + DrmConvertedStatus* convertData(int uniqueId, int convertId, const DrmBuffer* inputData); + + /** + * Informs the Drm Agent when there is no more data which need to be converted + * or when an error occurs. Upon successful conversion of the complete data, + * the agent will inform that where the header and body signature + * should be added. This signature appending is needed to integrity + * protect the converted file. + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] convertId Handle for the convert session + * @return Return object contains the status of the data conversion, + * the header and body signature data. It also informs + * the application on which offset these signature data + * should be appended. + */ + DrmConvertedStatus* closeConvertSession(int uniqueId, int convertId); + + /** + * Retrieves all DrmSupportInfo instance that native DRM framework can handle. + * This interface is meant to be used by JNI layer + * + * @param[in] uniqueId Unique identifier for a session + * @param[out] length Number of elements in drmSupportInfoArray + * @param[out] drmSupportInfoArray Array contains all DrmSupportInfo + * that native DRM framework can handle + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure + */ + status_t getAllSupportInfo(int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray); + + /** + * Open the decrypt session to decrypt the given protected content + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] fd File descriptor of the protected content to be decrypted + * @param[in] offset Start position of the content + * @param[in] length The length of the protected content + * @return + * Handle for the decryption session + */ + DecryptHandle* openDecryptSession(int uniqueId, int fd, int offset, int length); + + /** + * Close the decrypt session for the given handle + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] decryptHandle Handle for the decryption session + */ + void closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle); + + /** + * Initialize decryption for the given unit of the protected content + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] decryptHandle Handle for the decryption session + * @param[in] decryptUnitId ID which specifies decryption unit, such as track ID + * @param[in] headerInfo Information for initializing decryption of this decrypUnit + */ + void initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, + int decryptUnitId, const DrmBuffer* headerInfo); + + /** + * Decrypt the protected content buffers for the given unit + * This method will be called any number of times, based on number of + * encrypted streams received from application. + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] decryptHandle Handle for the decryption session + * @param[in] decryptUnitId ID which specifies decryption unit, such as track ID + * @param[in] encBuffer Encrypted data block + * @param[out] decBuffer Decrypted data block + * @return status_t + * Returns the error code for this API + * DRM_NO_ERROR for success, and one of DRM_ERROR_UNKNOWN, DRM_ERROR_LICENSE_EXPIRED + * DRM_ERROR_SESSION_NOT_OPENED, DRM_ERROR_DECRYPT_UNIT_NOT_INITIALIZED, + * DRM_ERROR_DECRYPT for failure. + */ + status_t decrypt(int uniqueId, DecryptHandle* decryptHandle, + int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer); + + /** + * Finalize decryption for the given unit of the protected content + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] decryptHandle Handle for the decryption session + * @param[in] decryptUnitId ID which specifies decryption unit, such as track ID + */ + void finalizeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId); + + /** + * Reads the specified number of bytes from an open DRM file. + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] decryptHandle Handle for the decryption session + * @param[out] buffer Reference to the buffer that should receive the read data. + * @param[in] numBytes Number of bytes to read. + * @param[in] offset Offset with which to update the file position. + * + * @return Number of bytes read. Returns -1 for Failure. + */ + ssize_t pread(int uniqueId, DecryptHandle* decryptHandle, + void* buffer, ssize_t numBytes, off_t offset); + + /** + * Notify the event to the registered listener + * + * @param[in] event The event to be notified + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure + */ + status_t notify(const DrmInfoEvent& event); + +private: + /** + * Initialize DRM Manager + * load available plug-ins from plugInDirPath + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] plugInDirPath Directory from where to load plug-ins + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure + */ + status_t loadPlugIns(int uniqueId, const String8& plugInDirPath); + + /** + * Install new DRM Engine Plug-in at the runtime + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] drmEngine Shared Object(so) File in which DRM Engine defined + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure + */ + status_t installDrmEngine(int uniqueId, const String8& drmEngineFile); + +private: + Mutex mLock; + sp mOnInfoListener; + +private: + static Mutex mMutex; + static Vector mUniqueIdVector; + static sp mDrmManagerService; + static const sp& getDrmManagerService(); + static const String8 EMPTY_STRING; +}; + +}; + +#endif /* __DRM_MANAGER_CLIENT_IMPL_H__ */ + diff --git a/drm/libdrmframework/include/DrmManagerService.h b/drm/libdrmframework/include/DrmManagerService.h new file mode 100644 index 0000000..fef121c --- /dev/null +++ b/drm/libdrmframework/include/DrmManagerService.h @@ -0,0 +1,119 @@ +/* + * 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. + */ + +#ifndef __DRM_MANAGER_SERVICE_H__ +#define __DRM_MANAGER_SERVICE_H__ + +#include +#include +#include +#include +#include "IDrmManagerService.h" +#include "IDrmServiceListener.h" + +namespace android { + +class DrmManager; +class String8; +class Mutex; + +/** + * This is the implementation class for DRM manager service. This delegates + * the responsibility to DrmManager. + * + * The instance of this class is created while starting the DRM manager service. + * + */ +class DrmManagerService : public BnDrmManagerService { +public: + static void instantiate(); + +private: + DrmManagerService(); + virtual ~DrmManagerService(); + +public: + status_t loadPlugIns(int uniqueId); + + status_t loadPlugIns(int uniqueId, const String8& plugInDirPath); + + status_t setDrmServiceListener( + int uniqueId, const sp& drmServiceListener); + + status_t unloadPlugIns(int uniqueId); + + status_t installDrmEngine(int uniqueId, const String8& drmEngineFile); + + DrmConstraints* getConstraints(int uniqueId, const String8* path, const int action); + + bool canHandle(int uniqueId, const String8& path, const String8& mimeType); + + DrmInfoStatus* processDrmInfo(int uniqueId, const DrmInfo* drmInfo); + + DrmInfo* acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInforequest); + + void saveRights(int uniqueId, const DrmRights& drmRights, + const String8& rightsPath, const String8& contentPath); + + String8 getOriginalMimeType(int uniqueId, const String8& path); + + int getDrmObjectType(int uniqueId, const String8& path, const String8& mimeType); + + int checkRightsStatus(int uniqueId, const String8& path,int action); + + void consumeRights(int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve); + + void setPlaybackStatus( + int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position); + + bool validateAction(int uniqueId, const String8& path, + int action, const ActionDescription& description); + + void removeRights(int uniqueId, const String8& path); + + void removeAllRights(int uniqueId); + + int openConvertSession(int uniqueId, const String8& mimeType); + + DrmConvertedStatus* convertData(int uniqueId, int convertId, const DrmBuffer* inputData); + + DrmConvertedStatus* closeConvertSession(int uniqueId, int convertId); + + status_t getAllSupportInfo(int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray); + + DecryptHandle* openDecryptSession(int uniqueId, int fd, int offset, int length); + + void closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle); + + void initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, + int decryptUnitId, const DrmBuffer* headerInfo); + + status_t decrypt(int uniqueId, DecryptHandle* decryptHandle, + int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer); + + void finalizeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId); + + ssize_t pread(int uniqueId, DecryptHandle* decryptHandle, + void* buffer, ssize_t numBytes, off_t offset); + +private: + DrmManager* mDrmManager; +}; + +}; + +#endif /* __DRM_MANAGER_SERVICE_H__ */ + diff --git a/drm/libdrmframework/include/IDrmIOService.h b/drm/libdrmframework/include/IDrmIOService.h new file mode 100644 index 0000000..5e0d907 --- /dev/null +++ b/drm/libdrmframework/include/IDrmIOService.h @@ -0,0 +1,86 @@ +/* + * 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. + */ + +#ifndef __IDRM_IO_SERVICE_H__ +#define __IDRM_IO_SERVICE_H__ + +#include +#include +#include + +namespace android { + +/** + * This is the interface class for DRM IO service. + * + */ +class IDrmIOService : public IInterface +{ +public: + enum { + WRITE_TO_FILE = IBinder::FIRST_CALL_TRANSACTION, + READ_FROM_FILE + }; + +public: + DECLARE_META_INTERFACE(DrmIOService); + +public: + /** + * Writes the data into the file path provided + * + * @param[in] filePath Path of the file + * @param[in] dataBuffer Data to write + */ + virtual void writeToFile(const String8& filePath, const String8& dataBuffer) = 0; + + /** + * Reads the data from the file path provided + * + * @param[in] filePath Path of the file + * @return Data read from the file + */ + virtual String8 readFromFile(const String8& filePath) = 0; +}; + +/** + * This is the Binder implementation class for DRM IO service. + */ +class BpDrmIOService: public BpInterface +{ +public: + BpDrmIOService(const sp& impl) + : BpInterface(impl) {} + + virtual void writeToFile(const String8& filePath, const String8& dataBuffer); + + virtual String8 readFromFile(const String8& filePath); +}; + +/** + * This is the Binder implementation class for DRM IO service. + */ +class BnDrmIOService: public BnInterface +{ +public: + virtual status_t onTransact( + uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags = 0); +}; + +}; + +#endif /* __IDRM_IO_SERVICE_H__ */ + diff --git a/drm/libdrmframework/include/IDrmManagerService.h b/drm/libdrmframework/include/IDrmManagerService.h new file mode 100644 index 0000000..a4d128a --- /dev/null +++ b/drm/libdrmframework/include/IDrmManagerService.h @@ -0,0 +1,242 @@ +/* + * 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. + */ + +#ifndef __IDRM_MANAGER_SERVICE_H__ +#define __IDRM_MANAGER_SERVICE_H__ + +#include +#include +#include +#include +#include "IDrmServiceListener.h" + +namespace android { + +class DrmContentIds; +class DrmConstraints; +class DrmRights; +class DrmInfo; +class DrmInfoStatus; +class DrmInfoRequest; +class DrmSupportInfo; +class DrmConvertedStatus; +class String8; +class ActionDescription; + +/** + * This is the interface class for DRM Manager service. + * + */ +class IDrmManagerService : public IInterface +{ +public: + enum { + LOAD_PLUGINS = IBinder::FIRST_CALL_TRANSACTION, + LOAD_PLUGINS_FROM_PATH, + SET_DRM_SERVICE_LISTENER, + UNLOAD_PLUGINS, + INSTALL_DRM_ENGINE, + GET_CONSTRAINTS_FROM_CONTENT, + CAN_HANDLE, + PROCESS_DRM_INFO, + ACQUIRE_DRM_INFO, + SAVE_RIGHTS, + GET_ORIGINAL_MIMETYPE, + GET_DRM_OBJECT_TYPE, + CHECK_RIGHTS_STATUS, + CONSUME_RIGHTS, + SET_PLAYBACK_STATUS, + VALIDATE_ACTION, + REMOVE_RIGHTS, + REMOVE_ALL_RIGHTS, + OPEN_CONVERT_SESSION, + CONVERT_DATA, + CLOSE_CONVERT_SESSION, + GET_ALL_SUPPORT_INFO, + OPEN_DECRYPT_SESSION, + CLOSE_DECRYPT_SESSION, + INITIALIZE_DECRYPT_UNIT, + DECRYPT, + FINALIZE_DECRYPT_UNIT, + PREAD + }; + +public: + DECLARE_META_INTERFACE(DrmManagerService); + +public: + virtual status_t loadPlugIns(int uniqueId) = 0; + + virtual status_t loadPlugIns(int uniqueId, const String8& plugInDirPath) = 0; + + virtual status_t setDrmServiceListener( + int uniqueId, const sp& infoListener) = 0; + + virtual status_t unloadPlugIns(int uniqueId) = 0; + + virtual status_t installDrmEngine(int uniqueId, const String8& drmEngineFile) = 0; + + virtual DrmConstraints* getConstraints( + int uniqueId, const String8* path, const int action) = 0; + + virtual bool canHandle(int uniqueId, const String8& path, const String8& mimeType) = 0; + + virtual DrmInfoStatus* processDrmInfo(int uniqueId, const DrmInfo* drmInfo) = 0; + + virtual DrmInfo* acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInforequest) = 0; + + virtual void saveRights(int uniqueId, const DrmRights& drmRights, + const String8& rightsPath, const String8& contentPath) = 0; + + virtual String8 getOriginalMimeType(int uniqueId, const String8& path) = 0; + + virtual int getDrmObjectType( + int uniqueId, const String8& path, const String8& mimeType) = 0; + + virtual int checkRightsStatus(int uniqueId, const String8& path, int action) = 0; + + virtual void consumeRights( + int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) = 0; + + virtual void setPlaybackStatus( + int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position) = 0; + + virtual bool validateAction( + int uniqueId, const String8& path, + int action, const ActionDescription& description) = 0; + + virtual void removeRights(int uniqueId, const String8& path) = 0; + + virtual void removeAllRights(int uniqueId) = 0; + + virtual int openConvertSession(int uniqueId, const String8& mimeType) = 0; + + virtual DrmConvertedStatus* convertData( + int uniqueId, int convertId, const DrmBuffer* inputData) = 0; + + virtual DrmConvertedStatus* closeConvertSession(int uniqueId, int convertId) = 0; + + virtual status_t getAllSupportInfo( + int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray) = 0; + + virtual DecryptHandle* openDecryptSession(int uniqueId, int fd, int offset, int length) = 0; + + virtual void closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) = 0; + + virtual void initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, + int decryptUnitId, const DrmBuffer* headerInfo) = 0; + + virtual status_t decrypt(int uniqueId, DecryptHandle* decryptHandle, + int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer) = 0; + + virtual void finalizeDecryptUnit( + int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) = 0; + + virtual ssize_t pread(int uniqueId, DecryptHandle* decryptHandle, + void* buffer, ssize_t numBytes,off_t offset) = 0; +}; + +/** + * This is the Binder implementation class for DRM Manager service. + */ +class BpDrmManagerService: public BpInterface +{ +public: + BpDrmManagerService(const sp& impl) + : BpInterface(impl) {} + + virtual status_t loadPlugIns(int uniqueId); + + virtual status_t loadPlugIns(int uniqueId, const String8& plugInDirPath); + + virtual status_t setDrmServiceListener( + int uniqueId, const sp& infoListener); + + virtual status_t unloadPlugIns(int uniqueId); + + virtual status_t installDrmEngine(int uniqueId, const String8& drmEngineFile); + + virtual DrmConstraints* getConstraints(int uniqueId, const String8* path, const int action); + + virtual bool canHandle(int uniqueId, const String8& path, const String8& mimeType); + + virtual DrmInfoStatus* processDrmInfo(int uniqueId, const DrmInfo* drmInfo); + + virtual DrmInfo* acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInforequest); + + virtual void saveRights(int uniqueId, const DrmRights& drmRights, + const String8& rightsPath, const String8& contentPath); + + virtual String8 getOriginalMimeType(int uniqueId, const String8& path); + + virtual int getDrmObjectType(int uniqueId, const String8& path, const String8& mimeType); + + virtual int checkRightsStatus(int uniqueId, const String8& path, int action); + + virtual void consumeRights( + int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve); + + virtual void setPlaybackStatus( + int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position); + + virtual bool validateAction( + int uniqueId, const String8& path, int action, const ActionDescription& description); + + virtual void removeRights(int uniqueId, const String8& path); + + virtual void removeAllRights(int uniqueId); + + virtual int openConvertSession(int uniqueId, const String8& mimeType); + + virtual DrmConvertedStatus* convertData( + int uniqueId, int convertId, const DrmBuffer* inputData); + + virtual DrmConvertedStatus* closeConvertSession(int uniqueId, int convertId); + + virtual status_t getAllSupportInfo( + int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray); + + virtual DecryptHandle* openDecryptSession(int uniqueId, int fd, int offset, int length); + + virtual void closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle); + + virtual void initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, + int decryptUnitId, const DrmBuffer* headerInfo); + + virtual status_t decrypt(int uniqueId, DecryptHandle* decryptHandle, + int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer); + + virtual void finalizeDecryptUnit( + int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId); + + virtual ssize_t pread(int uniqueId, DecryptHandle* decryptHandle, + void* buffer, ssize_t numBytes, off_t offset); +}; + +/** + * This is the Binder implementation class for DRM Manager service. + */ +class BnDrmManagerService: public BnInterface +{ +public: + virtual status_t onTransact( + uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags = 0); +}; + +}; + +#endif /* __IDRM_MANAGER_SERVICE_H__ */ + diff --git a/drm/libdrmframework/include/IDrmServiceListener.h b/drm/libdrmframework/include/IDrmServiceListener.h new file mode 100644 index 0000000..7f7109f --- /dev/null +++ b/drm/libdrmframework/include/IDrmServiceListener.h @@ -0,0 +1,71 @@ +/* + * 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. + */ + +#ifndef __IDRM_SERVICE_LISTENER_H__ +#define __IDRM_SERVICE_LISTENER_H__ + +#include +#include +#include + +namespace android { + +class DrmInfoEvent; + +/** + * This is the interface class for DRM service listener. + * + */ +class IDrmServiceListener : public IInterface +{ +public: + enum { + NOTIFY = IBinder::FIRST_CALL_TRANSACTION, + }; + +public: + DECLARE_META_INTERFACE(DrmServiceListener); + +public: + virtual status_t notify(const DrmInfoEvent& event) = 0; +}; + +/** + * This is the Binder implementation class for DRM service listener. + */ +class BpDrmServiceListener: public BpInterface +{ +public: + BpDrmServiceListener(const sp& impl) + : BpInterface(impl) {} + + virtual status_t notify(const DrmInfoEvent& event); +}; + +/** + * This is the Binder implementation class for DRM service listener. + */ +class BnDrmServiceListener: public BnInterface +{ +public: + virtual status_t onTransact( + uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags = 0); +}; + +}; + +#endif /* __IDRM_SERVICE_LISTENER_H__ */ + diff --git a/drm/libdrmframework/include/PlugInManager.h b/drm/libdrmframework/include/PlugInManager.h new file mode 100644 index 0000000..9ad195f --- /dev/null +++ b/drm/libdrmframework/include/PlugInManager.h @@ -0,0 +1,273 @@ +/* + * 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. + */ + +#ifndef __PLUGIN_MANAGER_H__ +#define __PLUGIN_MANAGER_H__ + +#include +#include +#include + +#include +#include +#include + +namespace android { + +const char* const PLUGIN_MANAGER_CREATE = "create"; +const char* const PLUGIN_MANAGER_DESTROY = "destroy"; +const char* const PLUGIN_EXTENSION = ".so"; + +/** + * This is the template class for Plugin manager. + * + * The DrmManager uses this class to handle the plugins. + * + */ +template +class TPlugInManager { +private: + typedef void* HANDLE; + typedef Type* create_t(void); + typedef void destroy_t(Type*); + typedef create_t* FPCREATE; + typedef destroy_t* FPDESTORY; + + typedef struct _PlugInContainer { + String8 sPath; + HANDLE hHandle; + FPCREATE fpCreate; + FPDESTORY fpDestory; + Type* pInstance; + + _PlugInContainer(): + sPath("") + ,hHandle(NULL) + ,fpCreate(NULL) + ,fpDestory(NULL) + ,pInstance(NULL) + {} + } PlugInContainer; + + typedef KeyedVector PlugInMap; + PlugInMap m_plugInMap; + + typedef Vector PlugInIdList; + PlugInIdList m_plugInIdList; + +public: + /** + * Load all the plug-ins in the specified directory + * + * @param[in] rsPlugInDirPath + * Directory path which plug-ins (dynamic library) are stored + * @note Plug-ins should be implemented according to the specification + */ + void loadPlugIns(const String8& rsPlugInDirPath) { + Vector plugInFileList = getPlugInPathList(rsPlugInDirPath); + + if (!plugInFileList.isEmpty()) { + for (unsigned int i = 0; i < plugInFileList.size(); ++i) { + loadPlugIn(plugInFileList[i]); + } + } + } + + /** + * Unload all the plug-ins + * + */ + void unloadPlugIns() { + for (unsigned int i = 0; i < m_plugInIdList.size(); ++i) { + unloadPlugIn(m_plugInIdList[i]); + } + m_plugInIdList.clear(); + } + + /** + * Get all the IDs of available plug-ins + * + * @return[in] plugInIdList + * String type Vector in which all plug-in IDs are stored + */ + Vector getPlugInIdList() const { + return m_plugInIdList; + } + + /** + * Get a plug-in reference of specified ID + * + * @param[in] rsPlugInId + * Plug-in ID to be used + * @return plugIn + * Reference of specified plug-in instance + */ + Type& getPlugIn(const String8& rsPlugInId) { + if (!contains(rsPlugInId)) { + // This error case never happens + } + return *(m_plugInMap.valueFor(rsPlugInId)->pInstance); + } + +public: + /** + * Load a plug-in stored in the specified path + * + * @param[in] rsPlugInPath + * Plug-in (dynamic library) file path + * @note Plug-in should be implemented according to the specification + */ + void loadPlugIn(const String8& rsPlugInPath) { + if (contains(rsPlugInPath)) { + return; + } + + PlugInContainer* pPlugInContainer = new PlugInContainer(); + + pPlugInContainer->hHandle = dlopen(rsPlugInPath.string(), RTLD_LAZY); + + if (NULL == pPlugInContainer->hHandle) { + delete pPlugInContainer; + pPlugInContainer = NULL; + return; + } + + pPlugInContainer->sPath = rsPlugInPath; + pPlugInContainer->fpCreate + = (FPCREATE)dlsym(pPlugInContainer->hHandle, PLUGIN_MANAGER_CREATE); + pPlugInContainer->fpDestory + = (FPDESTORY)dlsym(pPlugInContainer->hHandle, PLUGIN_MANAGER_DESTROY); + + if (NULL != pPlugInContainer->fpCreate && NULL != pPlugInContainer->fpDestory) { + pPlugInContainer->pInstance = (Type*)pPlugInContainer->fpCreate(); + m_plugInIdList.add(rsPlugInPath); + m_plugInMap.add(rsPlugInPath, pPlugInContainer); + } else { + dlclose(pPlugInContainer->hHandle); + delete pPlugInContainer; + pPlugInContainer = NULL; + return; + } + } + + /** + * Unload a plug-in stored in the specified path + * + * @param[in] rsPlugInPath + * Plug-in (dynamic library) file path + */ + void unloadPlugIn(const String8& rsPlugInPath) { + if (!contains(rsPlugInPath)) { + return; + } + + PlugInContainer* pPlugInContainer = m_plugInMap.valueFor(rsPlugInPath); + pPlugInContainer->fpDestory(pPlugInContainer->pInstance); + dlclose(pPlugInContainer->hHandle); + + m_plugInMap.removeItem(rsPlugInPath); + delete pPlugInContainer; + pPlugInContainer = NULL; + } + +private: + /** + * True if TPlugInManager contains rsPlugInId + */ + bool contains(const String8& rsPlugInId) { + return m_plugInMap.indexOfKey(rsPlugInId) != NAME_NOT_FOUND; + } + + /** + * Return file path list of plug-ins stored in the specified directory + * + * @param[in] rsDirPath + * Directory path in which plug-ins are stored + * @return plugInFileList + * String type Vector in which file path of plug-ins are stored + */ + Vector getPlugInPathList(const String8& rsDirPath) { + Vector fileList; + DIR* pDir = opendir(rsDirPath.string()); + struct dirent* pEntry = new dirent(); + + while (NULL != pDir && NULL != (pEntry = readdir(pDir))) { + if (!isPlugIn(pEntry)) { + continue; + } + String8 plugInPath; + plugInPath += rsDirPath; + plugInPath += "/"; + plugInPath += pEntry->d_name; + + fileList.add(plugInPath); + } + + if (NULL != pDir) { + closedir(pDir); + } + delete pEntry; + pEntry = NULL; + + return fileList; + } + + /** + * True if the input name denotes plug-in + */ + bool isPlugIn(const struct dirent* pEntry) const { + String8 sName(pEntry->d_name); + int extentionPos = sName.size() - String8(PLUGIN_EXTENSION).size(); + if (extentionPos < 0) { + return false; + } + return extentionPos == (int)sName.find(PLUGIN_EXTENSION); + } + + /** + * True if the input entry is "." or ".." + */ + bool isDotOrDDot(const struct dirent* pEntry) const { + String8 sName(pEntry->d_name); + return "." == sName || ".." == sName; + } + + /** + * True if input entry is directory + */ + bool isDirectory(const struct dirent* pEntry) const { + return DT_DIR == pEntry->d_type; + } + + /** + * True if input entry is regular file + */ + bool isRegularFile(const struct dirent* pEntry) const { + return DT_REG == pEntry->d_type; + } + + /** + * True if input entry is link + */ + bool isLink(const struct dirent* pEntry) const { + return DT_LNK == pEntry->d_type; + } +}; + +}; + +#endif /* __PLUGIN_MANAGER_H__ */ + diff --git a/drm/libdrmframework/include/ReadWriteUtils.h b/drm/libdrmframework/include/ReadWriteUtils.h new file mode 100644 index 0000000..022149e --- /dev/null +++ b/drm/libdrmframework/include/ReadWriteUtils.h @@ -0,0 +1,71 @@ +/* + * 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. + */ + +#ifndef __READ_WRITE_UTILS_H__ +#define __READ_WRITE_UTILS_H__ + +#include +#include + +namespace android { + +/** + * This is an utility class which performs IO operations. + * + */ +class ReadWriteUtils { +public: + /** + * Constructor for ReadWriteUtils + */ + ReadWriteUtils() {} + + /** + * Destructor for ReadWriteUtils + */ + virtual ~ReadWriteUtils(); + +public: + /** + * Reads the data from the file path provided + * + * @param[in] filePath Path of the file + * @return Data read from the file + */ + static String8 readBytes(const String8& filePath); + /** + * Writes the data into the file path provided + * + * @param[in] filePath Path of the file + * @param[in] dataBuffer Data to write + */ + static void writeToFile(const String8& filePath, const String8& data); + /** + * Appends the data into the file path provided + * + * @param[in] filePath Path of the file + * @param[in] dataBuffer Data to append + */ + static void appendToFile(const String8& filePath, const String8& data); + +private: + FileMap* mFileMap; +}; + +}; + +#endif /* __READ_WRITE_UTILS_H__ */ + diff --git a/drm/libdrmframework/include/StringTokenizer.h b/drm/libdrmframework/include/StringTokenizer.h new file mode 100644 index 0000000..70e7558 --- /dev/null +++ b/drm/libdrmframework/include/StringTokenizer.h @@ -0,0 +1,87 @@ +/* + * 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. + */ + +#ifndef __STRING_TOKENIZER_H__ +#define __STRING_TOKENIZER_H__ + +#include + +namespace android { + +/** + * This is an utility class for String manipulation. + * + */ +class StringTokenizer { +public: + /** + * Iterator for string tokens + */ + class Iterator { + friend class StringTokenizer; + private: + Iterator(StringTokenizer* StringTokenizer) + : mStringTokenizer(StringTokenizer), mIndex(0) {} + + public: + Iterator(const Iterator& iterator); + Iterator& operator=(const Iterator& iterator); + virtual ~Iterator() {} + + public: + bool hasNext(); + String8& next(); + + private: + StringTokenizer* mStringTokenizer; + unsigned int mIndex; + }; + +public: + /** + * Constructor for StringTokenizer + * + * @param[in] string Complete string data + * @param[in] delimeter Delimeter used to split the string + */ + StringTokenizer(const String8& string, const String8& delimeter); + + /** + * Destructor for StringTokenizer + */ + ~StringTokenizer() {} + +private: + /** + * Splits the string according to the delimeter + */ + void splitString(const String8& string, const String8& delimeter); + +public: + /** + * Returns Iterator object to walk through the split string values + * + * @return Iterator object + */ + Iterator iterator(); + +private: + Vector mStringTokenizerVector; +}; + +}; +#endif /* __STRING_TOKENIZER_H__ */ + diff --git a/drm/libdrmframework/plugins/Android.mk b/drm/libdrmframework/plugins/Android.mk new file mode 100644 index 0000000..9ee7961 --- /dev/null +++ b/drm/libdrmframework/plugins/Android.mk @@ -0,0 +1,16 @@ +# +# 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 $(call all-subdir-makefiles) diff --git a/drm/libdrmframework/plugins/common/include/DrmEngineBase.h b/drm/libdrmframework/plugins/common/include/DrmEngineBase.h new file mode 100644 index 0000000..667958a --- /dev/null +++ b/drm/libdrmframework/plugins/common/include/DrmEngineBase.h @@ -0,0 +1,411 @@ +/* + * 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. + */ + +#ifndef __DRM_ENGINE_BASE_H__ +#define __DRM_ENGINE_BASE_H__ + +#include +#include "IDrmEngine.h" + +namespace android { + +/** + * This class is an interface for plug-in developers + * + * Responsibility of this class is control the sequence of actual plug-in. + * All each plug-in developer has to do is implement onXXX() type virtual interfaces. + */ +class DrmEngineBase : public IDrmEngine { +public: + DrmEngineBase(); + virtual ~DrmEngineBase(); + +public: + DrmConstraints* getConstraints(int uniqueId, const String8* path, int action); + + status_t initialize(int uniqueId); + + status_t setOnInfoListener(int uniqueId, const IDrmEngine::OnInfoListener* infoListener); + + status_t terminate(int uniqueId); + + bool canHandle(int uniqueId, const String8& path); + + DrmInfoStatus* processDrmInfo(int uniqueId, const DrmInfo* drmInfo); + + void saveRights(int uniqueId, const DrmRights& drmRights, + const String8& rightsPath, const String8& contentPath); + + DrmInfo* acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest); + + String8 getOriginalMimeType(int uniqueId, const String8& path); + + int getDrmObjectType(int uniqueId, const String8& path, const String8& mimeType); + + int checkRightsStatus(int uniqueId, const String8& path, int action); + + void consumeRights(int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve); + + void setPlaybackStatus( + int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position); + + bool validateAction( + int uniqueId, const String8& path, int action, const ActionDescription& description); + + void removeRights(int uniqueId, const String8& path); + + void removeAllRights(int uniqueId); + + void openConvertSession(int uniqueId, int convertId); + + DrmConvertedStatus* convertData(int uniqueId, int convertId, const DrmBuffer* inputData); + + DrmConvertedStatus* closeConvertSession(int uniqueId, int convertId); + + DrmSupportInfo* getSupportInfo(int uniqueId); + + status_t openDecryptSession( + int uniqueId, DecryptHandle* decryptHandle, int fd, int offset, int length); + + void closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle); + + void initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, + int decryptUnitId, const DrmBuffer* headerInfo); + + status_t decrypt(int uniqueId, DecryptHandle* decryptHandle, + int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer); + + void finalizeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId); + + ssize_t pread(int uniqueId, DecryptHandle* decryptHandle, + void* buffer, ssize_t numBytes, off_t offset); + +protected: + ///////////////////////////////////////////////////// + // Interface for plug-in developers // + // each plug-in has to implement following method // + ///////////////////////////////////////////////////// + /** + * Get constraint information associated with input content + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] path Path of the protected content + * @param[in] action Actions defined such as, + * Action::DEFAULT, Action::PLAY, etc + * @return DrmConstraints + * key-value pairs of constraint are embedded in it + * @note + * In case of error, return NULL + */ + virtual DrmConstraints* onGetConstraints( + int uniqueId, const String8* path, int action) = 0; + + /** + * Initialize plug-in + * + * @param[in] uniqueId Unique identifier for a session + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure + */ + virtual status_t onInitialize(int uniqueId) = 0; + + /** + * Register a callback to be invoked when the caller required to + * receive necessary information + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] infoListener Listener + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure + */ + virtual status_t onSetOnInfoListener( + int uniqueId, const IDrmEngine::OnInfoListener* infoListener) = 0; + + /** + * Terminate the plug-in + * and release resource bound to plug-in + * + * @param[in] uniqueId Unique identifier for a session + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure + */ + virtual status_t onTerminate(int uniqueId) = 0; + + /** + * Get whether the given content can be handled by this plugin or not + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] path Path the protected object + * @return bool + * Returns true if this plugin can handle , false in case of not able to handle + */ + virtual bool onCanHandle(int uniqueId, const String8& path) = 0; + + /** + * Executes given drm information based on its type + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] drmInfo Information needs to be processed + * @return DrmInfoStatus + * instance as a result of processing given input + */ + virtual DrmInfoStatus* onProcessDrmInfo(int uniqueId, const DrmInfo* drmInfo) = 0; + + /** + * Save DRM rights to specified rights path + * and make association with content path + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] drmRights DrmRights to be saved + * @param[in] rightsPath File path where rights to be saved + * @param[in] contentPath File path where content was saved + */ + virtual void onSaveRights(int uniqueId, const DrmRights& drmRights, + const String8& rightspath, const String8& contentPath) = 0; + + /** + * Retrieves necessary information for registration, unregistration or rights + * acquisition information. + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] drmInfoRequest Request information to retrieve drmInfo + * @return DrmInfo + * instance as a result of processing given input + */ + virtual DrmInfo* onAcquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInforequest) = 0; + + /** + * Retrieves the mime type embedded inside the original content + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] path Path of the protected content + * @return String8 + * Returns mime-type of the original content, such as "video/mpeg" + */ + virtual String8 onGetOriginalMimeType(int uniqueId, const String8& path) = 0; + + /** + * Retrieves the type of the protected object (content, rights, etc..) + * using specified path or mimetype. At least one parameter should be non null + * to retrieve DRM object type + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] path Path of the content or null. + * @param[in] mimeType Mime type of the content or null. + * @return type of the DRM content, + * such as DrmObjectType::CONTENT, DrmObjectType::RIGHTS_OBJECT + */ + virtual int onGetDrmObjectType( + int uniqueId, const String8& path, const String8& mimeType) = 0; + + /** + * Check whether the given content has valid rights or not + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] path Path of the protected content + * @param[in] action Action to perform (Action::DEFAULT, Action::PLAY, etc) + * @return the status of the rights for the protected content, + * such as RightsStatus::RIGHTS_VALID, RightsStatus::RIGHTS_EXPIRED, etc. + */ + virtual int onCheckRightsStatus(int uniqueId, const String8& path, int action) = 0; + + /** + * Consumes the rights for a content. + * If the reserve parameter is true the rights is reserved until the same + * application calls this api again with the reserve parameter set to false. + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] decryptHandle Handle for the decryption session + * @param[in] action Action to perform. (Action::DEFAULT, Action::PLAY, etc) + * @param[in] reserve True if the rights should be reserved. + */ + virtual void onConsumeRights(int uniqueId, DecryptHandle* decryptHandle, + int action, bool reserve) = 0; + + /** + * Informs the DRM Engine about the playback actions performed on the DRM files. + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] decryptHandle Handle for the decryption session + * @param[in] playbackStatus Playback action (Playback::START, Playback::STOP, Playback::PAUSE) + * @param[in] position Position in the file (in milliseconds) where the start occurs. + * Only valid together with Playback::START. + */ + virtual void onSetPlaybackStatus( + int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position) = 0; + + /** + * Validates whether an action on the DRM content is allowed or not. + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] path Path of the protected content + * @param[in] action Action to validate (Action::PLAY, Action::TRANSFER, etc) + * @param[in] description Detailed description of the action + * @return true if the action is allowed. + */ + virtual bool onValidateAction(int uniqueId, const String8& path, + int action, const ActionDescription& description) = 0; + + /** + * Removes the rights associated with the given protected content + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] path Path of the protected content + */ + virtual void onRemoveRights(int uniqueId, const String8& path) = 0; + + /** + * Removes all the rights information of each plug-in associated with + * DRM framework. Will be used in master reset + * + * @param[in] uniqueId Unique identifier for a session + */ + virtual void onRemoveAllRights(int uniqueId) = 0; + + /** + * This API is for Forward Lock based DRM scheme. + * Each time the application tries to download a new DRM file + * which needs to be converted, then the application has to + * begin with calling this API. + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] convertId Handle for the convert session + */ + virtual void onOpenConvertSession(int uniqueId, int convertId) = 0; + + /** + * Accepts and converts the input data which is part of DRM file. + * The resultant converted data and the status is returned in the DrmConvertedInfo + * object. This method will be called each time there are new block + * of data received by the application. + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] convertId Handle for the convert session + * @param[in] inputData Input Data which need to be converted + * @return Return object contains the status of the data conversion, + * the output converted data and offset. In this case the + * application will ignore the offset information. + */ + virtual DrmConvertedStatus* onConvertData( + int uniqueId, int convertId, const DrmBuffer* inputData) = 0; + + /** + * Informs the Drm Agent when there is no more data which need to be converted + * or when an error occurs. Upon successful conversion of the complete data, + * the agent will inform that where the header and body signature + * should be added. This signature appending is needed to integrity + * protect the converted file. + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] convertId Handle for the convert session + * @return Return object contains the status of the data conversion, + * the header and body signature data. It also informs + * the application on which offset these signature data + * should be appended. + */ + virtual DrmConvertedStatus* onCloseConvertSession(int uniqueId, int convertId) = 0; + + /** + * Returns the information about the Drm Engine capabilities which includes + * supported MimeTypes and file suffixes. + * + * @param[in] uniqueId Unique identifier for a session + * @return DrmSupportInfo + * instance which holds the capabilities of a plug-in + */ + virtual DrmSupportInfo* onGetSupportInfo(int uniqueId) = 0; + + /** + * Open the decrypt session to decrypt the given protected content + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] decryptHandle Handle for the current decryption session + * @param[in] fd File descriptor of the protected content to be decrypted + * @param[in] offset Start position of the content + * @param[in] length The length of the protected content + * @return + * DRM_ERROR_CANNOT_HANDLE for failure and DRM_NO_ERROR for success + */ + virtual status_t onOpenDecryptSession( + int uniqueId, DecryptHandle* decryptHandle, int fd, int offset, int length) = 0; + + /** + * Close the decrypt session for the given handle + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] decryptHandle Handle for the decryption session + */ + virtual void onCloseDecryptSession(int uniqueId, DecryptHandle* decryptHandle) = 0; + + /** + * Initialize decryption for the given unit of the protected content + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] decryptId Handle for the decryption session + * @param[in] decryptUnitId ID Specifies decryption unit, such as track ID + * @param[in] headerInfo Information for initializing decryption of this decrypUnit + */ + virtual void onInitializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, + int decryptUnitId, const DrmBuffer* headerInfo) = 0; + + /** + * Decrypt the protected content buffers for the given unit + * This method will be called any number of times, based on number of + * encrypted streams received from application. + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] decryptId Handle for the decryption session + * @param[in] decryptUnitId ID Specifies decryption unit, such as track ID + * @param[in] encBuffer Encrypted data block + * @param[out] decBuffer Decrypted data block + * @return status_t + * Returns the error code for this API + * DRM_NO_ERROR for success, and one of DRM_ERROR_UNKNOWN, DRM_ERROR_LICENSE_EXPIRED + * DRM_ERROR_SESSION_NOT_OPENED, DRM_ERROR_DECRYPT_UNIT_NOT_INITIALIZED, + * DRM_ERROR_DECRYPT for failure. + */ + virtual status_t onDecrypt(int uniqueId, DecryptHandle* decryptHandle, + int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer) = 0; + + /** + * Finalize decryption for the given unit of the protected content + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] decryptHandle Handle for the decryption session + * @param[in] decryptUnitId ID Specifies decryption unit, such as track ID + */ + virtual void onFinalizeDecryptUnit( + int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) = 0; + + /** + * Reads the specified number of bytes from an open DRM file. + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] decryptHandle Handle for the decryption session + * @param[out] buffer Reference to the buffer that should receive the read data. + * @param[in] numBytes Number of bytes to read. + * @param[in] offset Offset with which to update the file position. + * + * @return Number of bytes read. Returns -1 for Failure. + */ + virtual ssize_t onPread(int uniqueId, DecryptHandle* decryptHandle, + void* buffer, ssize_t numBytes, off_t offset) = 0; +}; + +}; + +#endif /* __DRM_ENGINE_BASE_H__ */ + diff --git a/drm/libdrmframework/plugins/common/include/IDrmEngine.h b/drm/libdrmframework/plugins/common/include/IDrmEngine.h new file mode 100644 index 0000000..0d52f66 --- /dev/null +++ b/drm/libdrmframework/plugins/common/include/IDrmEngine.h @@ -0,0 +1,371 @@ +/* + * 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. + */ + +#ifndef __IDRM_ENGINE_H__ +#define __IDRM_ENGINE_H__ + +#include + +namespace android { + +class DrmContentIds; +class DrmConstraints; +class DrmRights; +class DrmInfo; +class DrmInfoStatus; +class DrmConvertedStatus; +class DrmInfoRequest; +class DrmSupportInfo; +class DrmInfoEvent; + +/** + * This class is an interface for plug-in user + * + * Responsibility of this class is provide generic interface to DRM Engine Manager. + * Each interface need to be as abstract as possible. + */ +class IDrmEngine { +public: + virtual ~IDrmEngine() { + } + +public: + class OnInfoListener { + + public: + virtual void onInfo(const DrmInfoEvent& event) = 0; + + virtual ~OnInfoListener() { } + }; + +public: + + ////////////////////////////////// + // Implementation of IDrmEngine // + ////////////////////////////////// + + /** + * Initialize plug-in + * + * @param[in] uniqueId Unique identifier for a session + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure + */ + virtual status_t initialize(int uniqueId) = 0; + + /** + * Register a callback to be invoked when the caller required to + * receive necessary information + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] infoListener Listener + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure + */ + virtual status_t setOnInfoListener( + int uniqueId, const IDrmEngine::OnInfoListener* infoListener) = 0; + + /** + * Terminate the plug-in + * and release resource bound to plug-in + * e.g.) release native resource + * + * @param[in] uniqueId Unique identifier for a session + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure + */ + virtual status_t terminate(int uniqueId) = 0; + + /** + * Get constraint information associated with input content + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] path Path of the protected content + * @param[in] action Actions defined such as, + * Action::DEFAULT, Action::PLAY, etc + * @return DrmConstraints + * key-value pairs of constraint are embedded in it + * @note + * In case of error, return NULL + */ + virtual DrmConstraints* getConstraints( + int uniqueId, const String8* path, int action) = 0; + + /** + * Get whether the given content can be handled by this plugin or not + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] path Path the protected object + * @return bool + * true if this plugin can handle , false in case of not able to handle + */ + virtual bool canHandle(int uniqueId, const String8& path) = 0; + + /** + * Executes given drm information based on its type + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] drmInfo Information needs to be processed + * @return DrmInfoStatus + * instance as a result of processing given input + */ + virtual DrmInfoStatus* processDrmInfo(int uniqueId, const DrmInfo* drmInfo) = 0; + + /** + * Retrieves necessary information for registration, unregistration or rights + * acquisition information. + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] drmInfoRequest Request information to retrieve drmInfo + * @return DrmInfo + * instance as a result of processing given input + */ + virtual DrmInfo* acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest) = 0; + + /** + * Save DRM rights to specified rights path + * and make association with content path + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] drmRights DrmRights to be saved + * @param[in] rightsPath File path where rights to be saved + * @param[in] contentPath File path where content was saved + */ + virtual void saveRights(int uniqueId, const DrmRights& drmRights, + const String8& rightsPath, const String8& contentPath) = 0; + + /** + * Retrieves the mime type embedded inside the original content + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] path Path of the protected content + * @return String8 + * Returns mime-type of the original content, such as "video/mpeg" + */ + virtual String8 getOriginalMimeType(int uniqueId, const String8& path) = 0; + + /** + * Retrieves the type of the protected object (content, rights, etc..) + * using specified path or mimetype. At least one parameter should be non null + * to retrieve DRM object type + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] path Path of the content or null. + * @param[in] mimeType Mime type of the content or null. + * @return type of the DRM content, + * such as DrmObjectType::CONTENT, DrmObjectType::RIGHTS_OBJECT + */ + virtual int getDrmObjectType( + int uniqueId, const String8& path, const String8& mimeType) = 0; + + /** + * Check whether the given content has valid rights or not + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] path Path of the protected content + * @param[in] action Action to perform (Action::DEFAULT, Action::PLAY, etc) + * @return the status of the rights for the protected content, + * such as RightsStatus::RIGHTS_VALID, RightsStatus::RIGHTS_EXPIRED, etc. + */ + virtual int checkRightsStatus(int uniqueId, const String8& path, int action) = 0; + + /** + * Consumes the rights for a content. + * If the reserve parameter is true the rights is reserved until the same + * application calls this api again with the reserve parameter set to false. + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] decryptHandle Handle for the decryption session + * @param[in] action Action to perform. (Action::DEFAULT, Action::PLAY, etc) + * @param[in] reserve True if the rights should be reserved. + */ + virtual void consumeRights( + int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) = 0; + + /** + * Informs the DRM Engine about the playback actions performed on the DRM files. + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] decryptHandle Handle for the decryption session + * @param[in] playbackStatus Playback action (Playback::START, Playback::STOP, Playback::PAUSE) + * @param[in] position Position in the file (in milliseconds) where the start occurs. + * Only valid together with Playback::START. + */ + virtual void setPlaybackStatus(int uniqueId, DecryptHandle* decryptHandle, + int playbackStatus, int position) = 0; + + /** + * Validates whether an action on the DRM content is allowed or not. + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] path Path of the protected content + * @param[in] action Action to validate (Action::PLAY, Action::TRANSFER, etc) + * @param[in] description Detailed description of the action + * @return true if the action is allowed. + */ + virtual bool validateAction(int uniqueId, const String8& path, + int action, const ActionDescription& description) = 0; + + /** + * Removes the rights associated with the given protected content + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] path Path of the protected content + */ + virtual void removeRights(int uniqueId, const String8& path) = 0; + + /** + * Removes all the rights information of each plug-in associated with + * DRM framework. Will be used in master reset + * + * @param[in] uniqueId Unique identifier for a session + */ + virtual void removeAllRights(int uniqueId) = 0; + + /** + * This API is for Forward Lock based DRM scheme. + * Each time the application tries to download a new DRM file + * which needs to be converted, then the application has to + * begin with calling this API. + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] convertId Handle for the convert session + */ + virtual void openConvertSession(int uniqueId, int convertId) = 0; + + /** + * Accepts and converts the input data which is part of DRM file. + * The resultant converted data and the status is returned in the DrmConvertedInfo + * object. This method will be called each time there are new block + * of data received by the application. + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] convertId Handle for the convert session + * @param[in] inputData Input Data which need to be converted + * @return Return object contains the status of the data conversion, + * the output converted data and offset. In this case the + * application will ignore the offset information. + */ + virtual DrmConvertedStatus* convertData( + int uniqueId, int convertId, const DrmBuffer* inputData) = 0; + + /** + * Informs the Drm Agent when there is no more data which need to be converted + * or when an error occurs. Upon successful conversion of the complete data, + * the agent will inform that where the header and body signature + * should be added. This signature appending is needed to integrity + * protect the converted file. + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] convertId Handle for the convert session + * @return Return object contains the status of the data conversion, + * the header and body signature data. It also informs + * the application on which offset these signature data + * should be appended. + */ + virtual DrmConvertedStatus* closeConvertSession( int uniqueId, int convertId) = 0; + + /** + * Returns the information about the Drm Engine capabilities which includes + * supported MimeTypes and file suffixes. + * + * @param[in] uniqueId Unique identifier for a session + * @return DrmSupportInfo + * instance which holds the capabilities of a plug-in + */ + virtual DrmSupportInfo* getSupportInfo(int uniqueId) = 0; + + /** + * Open the decrypt session to decrypt the given protected content + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] decryptHandle Handle for the current decryption session + * @param[in] fd File descriptor of the protected content to be decrypted + * @param[in] offset Start position of the content + * @param[in] length The length of the protected content + * @return + * DRM_ERROR_CANNOT_HANDLE for failure and DRM_NO_ERROR for success + */ + virtual status_t openDecryptSession( + int uniqueId, DecryptHandle* decryptHandle, int fd, int offset, int length) = 0; + + /** + * Close the decrypt session for the given handle + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] decryptHandle Handle for the decryption session + */ + virtual void closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) = 0; + + /** + * Initialize decryption for the given unit of the protected content + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] decryptHandle Handle for the decryption session + * @param[in] decryptUnitId ID which specifies decryption unit, such as track ID + * @param[in] headerInfo Information for initializing decryption of this decrypUnit + */ + virtual void initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, + int decryptUnitId, const DrmBuffer* headerInfo) = 0; + + /** + * Decrypt the protected content buffers for the given unit + * This method will be called any number of times, based on number of + * encrypted streams received from application. + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] decryptHandle Handle for the decryption session + * @param[in] decryptUnitId ID which specifies decryption unit, such as track ID + * @param[in] encBuffer Encrypted data block + * @param[out] decBuffer Decrypted data block + * @return status_t + * Returns the error code for this API + * DRM_NO_ERROR for success, and one of DRM_ERROR_UNKNOWN, DRM_ERROR_LICENSE_EXPIRED + * DRM_ERROR_SESSION_NOT_OPENED, DRM_ERROR_DECRYPT_UNIT_NOT_INITIALIZED, + * DRM_ERROR_DECRYPT for failure. + */ + virtual status_t decrypt(int uniqueId, DecryptHandle* decryptHandle, + int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer) = 0; + + /** + * Finalize decryption for the given unit of the protected content + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] decryptHandle Handle for the decryption session + * @param[in] decryptUnitId ID which specifies decryption unit, such as track ID + */ + virtual void finalizeDecryptUnit( + int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) = 0; + + /** + * Reads the specified number of bytes from an open DRM file. + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] decryptHandle Handle for the decryption session + * @param[out] buffer Reference to the buffer that should receive the read data. + * @param[in] numBytes Number of bytes to read. + * @param[in] offset Offset with which to update the file position. + * + * @return Number of bytes read. Returns -1 for Failure. + */ + virtual ssize_t pread(int uniqueId, DecryptHandle* decryptHandle, + void* buffer, ssize_t numBytes, off_t offset) = 0; +}; + +}; + +#endif /* __IDRM_ENGINE_H__ */ + diff --git a/drm/libdrmframework/plugins/passthru/Android.mk b/drm/libdrmframework/plugins/passthru/Android.mk new file mode 100644 index 0000000..a7bbf23 --- /dev/null +++ b/drm/libdrmframework/plugins/passthru/Android.mk @@ -0,0 +1,44 @@ +# +# 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:= \ + src/DrmPassthruPlugIn.cpp + +LOCAL_MODULE := libdrmpassthruplugin + +LOCAL_STATIC_LIBRARIES := libdrmframeworkcommon + +LOCAL_SHARED_LIBRARIES := \ + libutils \ + libdl + +LOCAL_PRELINK_MODULE := false + +LOCAL_C_INCLUDES += \ + $(TOP)/frameworks/base/drm/libdrmframework/include \ + $(TOP)/frameworks/base/drm/libdrmframework/plugins/passthru/include \ + $(TOP)/frameworks/base/drm/libdrmframework/plugins/common/include \ + $(TOP)/frameworks/base/include + +# Set the following flag to enable the decryption passthru flow +#LOCAL_CFLAGS += -DENABLE_PASSTHRU_DECRYPTION + +PRODUCT_COPY_FILES += \ + $(TARGET_OUT_SHARED_LIBRARIES)/libdrmpassthruplugin.so:system/lib/drm/plugins/native/libdrmpassthruplugin.so + +include $(BUILD_SHARED_LIBRARY) diff --git a/drm/libdrmframework/plugins/passthru/include/DrmPassthruPlugIn.h b/drm/libdrmframework/plugins/passthru/include/DrmPassthruPlugIn.h new file mode 100644 index 0000000..d2c7852 --- /dev/null +++ b/drm/libdrmframework/plugins/passthru/include/DrmPassthruPlugIn.h @@ -0,0 +1,97 @@ +/* + * 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. + */ + +#ifndef __DRM_PASSTHRU_PLUGIN_H__ +#define __DRM_PASSTHRU_PLUGIN_H__ + +#include + +namespace android { + +class DrmPassthruPlugIn : public DrmEngineBase { + +public: + DrmPassthruPlugIn(); + virtual ~DrmPassthruPlugIn(); + +protected: + DrmConstraints* onGetConstraints(int uniqueId, const String8* path, int action); + + status_t onInitialize(int uniqueId); + + status_t onSetOnInfoListener(int uniqueId, const IDrmEngine::OnInfoListener* infoListener); + + status_t onTerminate(int uniqueId); + + bool onCanHandle(int uniqueId, const String8& path); + + DrmInfoStatus* onProcessDrmInfo(int uniqueId, const DrmInfo* drmInfo); + + void onSaveRights(int uniqueId, const DrmRights& drmRights, + const String8& rightsPath, const String8& contentPath); + + DrmInfo* onAcquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest); + + String8 onGetOriginalMimeType(int uniqueId, const String8& path); + + int onGetDrmObjectType(int uniqueId, const String8& path, const String8& mimeType); + + int onCheckRightsStatus(int uniqueId, const String8& path, int action); + + void onConsumeRights(int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve); + + void onSetPlaybackStatus( + int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position); + + bool onValidateAction( + int uniqueId, const String8& path, int action, const ActionDescription& description); + + void onRemoveRights(int uniqueId, const String8& path); + + void onRemoveAllRights(int uniqueId); + + void onOpenConvertSession(int uniqueId, int convertId); + + DrmConvertedStatus* onConvertData(int uniqueId, int convertId, const DrmBuffer* inputData); + + DrmConvertedStatus* onCloseConvertSession(int uniqueId, int convertId); + + DrmSupportInfo* onGetSupportInfo(int uniqueId); + + status_t onOpenDecryptSession( + int uniqueId, DecryptHandle* decryptHandle, int fd, int offset, int length); + + void onCloseDecryptSession(int uniqueId, DecryptHandle* decryptHandle); + + void onInitializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, + int decryptUnitId, const DrmBuffer* headerInfo); + + status_t onDecrypt(int uniqueId, DecryptHandle* decryptHandle, + int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer); + + void onFinalizeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId); + + ssize_t onPread(int uniqueId, DecryptHandle* decryptHandle, + void* buffer, ssize_t numBytes, off_t offset); + +private: + DecryptHandle* openDecryptSessionImpl(); +}; + +}; + +#endif /* __DRM_PASSTHRU_PLUGIN_H__ */ + diff --git a/drm/libdrmframework/plugins/passthru/src/DrmPassthruPlugIn.cpp b/drm/libdrmframework/plugins/passthru/src/DrmPassthruPlugIn.cpp new file mode 100644 index 0000000..2655d0b --- /dev/null +++ b/drm/libdrmframework/plugins/passthru/src/DrmPassthruPlugIn.cpp @@ -0,0 +1,280 @@ +/* + * 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 "DrmPassthruPlugIn" +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace android; + + +// This extern "C" is mandatory to be managed by TPlugInManager +extern "C" IDrmEngine* create() { + return new DrmPassthruPlugIn(); +} + +// This extern "C" is mandatory to be managed by TPlugInManager +extern "C" void destroy(IDrmEngine* pPlugIn) { + delete pPlugIn; + pPlugIn = NULL; +} + +DrmPassthruPlugIn::DrmPassthruPlugIn() + : DrmEngineBase() { + +} + +DrmPassthruPlugIn::~DrmPassthruPlugIn() { + +} + +DrmConstraints* DrmPassthruPlugIn::onGetConstraints( + int uniqueId, const String8* path, int action) { + LOGD("DrmPassthruPlugIn::onGetConstraints From Path: %d", uniqueId); + DrmConstraints* drmConstraints = new DrmConstraints(); + + String8 value("dummy_available_time"); + char* charValue = NULL; + charValue = new char[value.length() + 1]; + strncpy(charValue, value.string(), value.length()); + + //Just add dummy available time for verification + drmConstraints->put(&(DrmConstraints::LICENSE_AVAILABLE_TIME), charValue); + + return drmConstraints; +} + +DrmInfoStatus* DrmPassthruPlugIn::onProcessDrmInfo(int uniqueId, const DrmInfo* drmInfo) { + LOGD("DrmPassthruPlugIn::onProcessDrmInfo - Enter : %d", uniqueId); + DrmInfoStatus* drmInfoStatus = NULL; + if (NULL != drmInfo) { + switch (drmInfo->getInfoType()) { + case DrmInfoRequest::TYPE_REGISTRATION_INFO: { + const DrmBuffer* emptyBuffer = new DrmBuffer(); + drmInfoStatus + = new DrmInfoStatus(DrmInfoStatus::STATUS_OK, emptyBuffer, drmInfo->getMimeType()); + break; + } + case DrmInfoRequest::TYPE_UNREGISTRATION_INFO: { + const DrmBuffer* emptyBuffer = new DrmBuffer(); + drmInfoStatus + = new DrmInfoStatus(DrmInfoStatus::STATUS_OK, emptyBuffer, drmInfo->getMimeType()); + break; + } + case DrmInfoRequest::TYPE_RIGHTS_ACQUISITION_INFO: { + String8 licenseString("dummy_license_string"); + const int bufferSize = licenseString.size(); + char* data = NULL; + data = new char[bufferSize]; + memcpy(data, licenseString.string(), bufferSize); + const DrmBuffer* buffer = new DrmBuffer(data, bufferSize); + drmInfoStatus + = new DrmInfoStatus(DrmInfoStatus::STATUS_OK, buffer, drmInfo->getMimeType()); + break; + } + } + } + LOGD("DrmPassthruPlugIn::onProcessDrmInfo - Exit"); + return drmInfoStatus; +} + +status_t DrmPassthruPlugIn::onSetOnInfoListener( + int uniqueId, const IDrmEngine::OnInfoListener* infoListener) { + LOGD("DrmPassthruPlugIn::onSetOnInfoListener : %d", uniqueId); + return DRM_NO_ERROR; +} + +status_t DrmPassthruPlugIn::onInitialize(int uniqueId) { + LOGD("DrmPassthruPlugIn::onInitialize : %d", uniqueId); + return DRM_NO_ERROR; +} + +status_t DrmPassthruPlugIn::onTerminate(int uniqueId) { + LOGD("DrmPassthruPlugIn::onTerminate : %d", uniqueId); + return DRM_NO_ERROR; +} + +DrmSupportInfo* DrmPassthruPlugIn::onGetSupportInfo(int uniqueId) { + LOGD("DrmPassthruPlugIn::onGetSupportInfo : %d", uniqueId); + DrmSupportInfo* drmSupportInfo = new DrmSupportInfo(); + // Add mimetype's + drmSupportInfo->addMimeType(String8("application/vnd.passthru.drm")); + // Add File Suffixes + drmSupportInfo->addFileSuffix(String8(".passthru")); + // Add plug-in description + drmSupportInfo->setDescription(String8("Passthru plug-in")); + return drmSupportInfo; +} + +void DrmPassthruPlugIn::onSaveRights(int uniqueId, const DrmRights& drmRights, + const String8& rightsPath, const String8& contentPath) { + LOGD("DrmPassthruPlugIn::onSaveRights : %d", uniqueId); +} + +DrmInfo* DrmPassthruPlugIn::onAcquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest) { + LOGD("DrmPassthruPlugIn::onAcquireDrmInfo : %d", uniqueId); + DrmInfo* drmInfo = NULL; + + if (NULL != drmInfoRequest) { + String8 dataString("dummy_acquistion_string"); + int length = dataString.length(); + char* data = NULL; + data = new char[length]; + memcpy(data, dataString.string(), length); + drmInfo = new DrmInfo(drmInfoRequest->getInfoType(), + DrmBuffer(data, length), drmInfoRequest->getMimeType()); + } + return drmInfo; +} + +bool DrmPassthruPlugIn::onCanHandle(int uniqueId, const String8& path) { + LOGD("DrmPassthruPlugIn::canHandle: %s ", path.string()); + String8 extension = path.getPathExtension(); + extension.toLower(); + return (String8(".passthru") == extension); +} + +String8 DrmPassthruPlugIn::onGetOriginalMimeType(int uniqueId, const String8& path) { + LOGD("DrmPassthruPlugIn::onGetOriginalMimeType() : %d", uniqueId); + return String8("video/passthru"); +} + +int DrmPassthruPlugIn::onGetDrmObjectType( + int uniqueId, const String8& path, const String8& mimeType) { + LOGD("DrmPassthruPlugIn::onGetDrmObjectType() : %d", uniqueId); + return DrmObjectType::UNKNOWN; +} + +int DrmPassthruPlugIn::onCheckRightsStatus(int uniqueId, const String8& path, int action) { + LOGD("DrmPassthruPlugIn::onCheckRightsStatus() : %d", uniqueId); + int rightsStatus = RightsStatus::RIGHTS_VALID; + return rightsStatus; +} + +void DrmPassthruPlugIn::onConsumeRights(int uniqueId, DecryptHandle* decryptHandle, + int action, bool reserve) { + LOGD("DrmPassthruPlugIn::onConsumeRights() : %d", uniqueId); +} + +void DrmPassthruPlugIn::onSetPlaybackStatus(int uniqueId, DecryptHandle* decryptHandle, + int playbackStatus, int position) { + LOGD("DrmPassthruPlugIn::onSetPlaybackStatus() : %d", uniqueId); +} + +bool DrmPassthruPlugIn::onValidateAction(int uniqueId, const String8& path, + int action, const ActionDescription& description) { + LOGD("DrmPassthruPlugIn::onValidateAction() : %d", uniqueId); + return true; +} + +void DrmPassthruPlugIn::onRemoveRights(int uniqueId, const String8& path) { + LOGD("DrmPassthruPlugIn::onRemoveRights() : %d", uniqueId); +} + +void DrmPassthruPlugIn::onRemoveAllRights(int uniqueId) { + LOGD("DrmPassthruPlugIn::onRemoveAllRights() : %d", uniqueId); +} + +void DrmPassthruPlugIn::onOpenConvertSession(int uniqueId, int convertId) { + LOGD("DrmPassthruPlugIn::onOpenConvertSession() : %d", uniqueId); +} + +DrmConvertedStatus* DrmPassthruPlugIn::onConvertData( + int uniqueId, int convertId, const DrmBuffer* inputData) { + LOGD("DrmPassthruPlugIn::onConvertData() : %d", uniqueId); + DrmBuffer* convertedData = NULL; + + if (NULL != inputData && 0 < inputData->length) { + int length = inputData->length; + char* data = NULL; + data = new char[length]; + convertedData = new DrmBuffer(data, length); + memcpy(convertedData->data, inputData->data, length); + } + return new DrmConvertedStatus(DrmConvertedStatus::STATUS_OK, convertedData, 0 /*offset*/); +} + +DrmConvertedStatus* DrmPassthruPlugIn::onCloseConvertSession(int uniqueId, int convertId) { + LOGD("DrmPassthruPlugIn::onCloseConvertSession() : %d", uniqueId); + return new DrmConvertedStatus(DrmConvertedStatus::STATUS_OK, NULL, 0 /*offset*/); +} + +status_t DrmPassthruPlugIn::onOpenDecryptSession( + int uniqueId, DecryptHandle* decryptHandle, int fd, int offset, int length) { + LOGD("DrmPassthruPlugIn::onOpenDecryptSession() : %d", uniqueId); + +#ifdef ENABLE_PASSTHRU_DECRYPTION + decryptHandle->mimeType = String8("video/passthru"); + decryptHandle->decryptApiType = DecryptApiType::ELEMENTARY_STREAM_BASED; + decryptHandle->status = DRM_NO_ERROR; + decryptHandle->decryptInfo = NULL; + return DRM_NO_ERROR; +#endif + + return DRM_ERROR_CANNOT_HANDLE; +} + +void DrmPassthruPlugIn::onCloseDecryptSession(int uniqueId, DecryptHandle* decryptHandle) { + LOGD("DrmPassthruPlugIn::onCloseDecryptSession() : %d", uniqueId); + if (NULL != decryptHandle) { + if (NULL != decryptHandle->decryptInfo) { + delete decryptHandle->decryptInfo; decryptHandle->decryptInfo = NULL; + } + delete decryptHandle; decryptHandle = NULL; + } +} + +void DrmPassthruPlugIn::onInitializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, + int decryptUnitId, const DrmBuffer* headerInfo) { + LOGD("DrmPassthruPlugIn::onInitializeDecryptUnit() : %d", uniqueId); +} + +status_t DrmPassthruPlugIn::onDecrypt(int uniqueId, DecryptHandle* decryptHandle, + int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer) { + LOGD("DrmPassthruPlugIn::onDecrypt() : %d", uniqueId); + /** + * As a workaround implementation passthru would copy the given + * encrypted buffer as it is to decrypted buffer. Note, decBuffer + * memory has to be allocated by the caller. + */ + if (NULL != (*decBuffer) && 0 < (*decBuffer)->length) { + memcpy((*decBuffer)->data, encBuffer->data, encBuffer->length); + (*decBuffer)->length = encBuffer->length; + } + return DRM_NO_ERROR; +} + +void DrmPassthruPlugIn::onFinalizeDecryptUnit( + int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) { + LOGD("DrmPassthruPlugIn::onFinalizeDecryptUnit() : %d", uniqueId); +} + +ssize_t DrmPassthruPlugIn::onPread(int uniqueId, DecryptHandle* decryptHandle, + void* buffer, ssize_t numBytes, off_t offset) { + LOGD("DrmPassthruPlugIn::onPread() : %d", uniqueId); + return 0; +} + -- 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') 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 ea916b1e27da465c5989a443040ca5e65e4592fe Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Queru Date: Thu, 9 Sep 2010 16:10:32 -0700 Subject: fix build Change-Id: Idccb3f2499bbaac61099d8232cadd633b93ad846 --- drm/libdrmframework/plugins/passthru/Android.mk | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'drm') diff --git a/drm/libdrmframework/plugins/passthru/Android.mk b/drm/libdrmframework/plugins/passthru/Android.mk index a7bbf23..169b89b 100644 --- a/drm/libdrmframework/plugins/passthru/Android.mk +++ b/drm/libdrmframework/plugins/passthru/Android.mk @@ -24,8 +24,13 @@ LOCAL_MODULE := libdrmpassthruplugin LOCAL_STATIC_LIBRARIES := libdrmframeworkcommon LOCAL_SHARED_LIBRARIES := \ - libutils \ - libdl + libutils + +ifeq ($(TARGET_SIMULATOR),true) + LOCAL_LDLIBS += -ldl +else + LOCAL_SHARED_LIBRARIES += libdl +endif LOCAL_PRELINK_MODULE := false -- cgit v1.1 From 3df6c0fc75b3278a93eff176471bd9c6365ab24b Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Queru Date: Thu, 9 Sep 2010 16:16:14 -0700 Subject: fix build Change-Id: Iccb40c8c5df879288f35e0940c721d306fb75c12 --- drm/libdrmframework/Android.mk | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'drm') diff --git a/drm/libdrmframework/Android.mk b/drm/libdrmframework/Android.mk index c25d79b..765adba 100644 --- a/drm/libdrmframework/Android.mk +++ b/drm/libdrmframework/Android.mk @@ -25,8 +25,13 @@ LOCAL_MODULE:= libdrmframework 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/common/Android.mk | 2 ++ drm/drmserver/Android.mk | 2 ++ drm/libdrmframework/Android.mk | 2 ++ drm/libdrmframework/plugins/passthru/Android.mk | 3 +-- 4 files changed, 7 insertions(+), 2 deletions(-) (limited to 'drm') diff --git a/drm/common/Android.mk b/drm/common/Android.mk index 249fe8e..808b2c2 100644 --- a/drm/common/Android.mk +++ b/drm/common/Android.mk @@ -38,4 +38,6 @@ LOCAL_C_INCLUDES := \ LOCAL_MODULE:= libdrmframeworkcommon +LOCAL_MODULE_TAGS := optional + include $(BUILD_STATIC_LIBRARY) 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) diff --git a/drm/libdrmframework/Android.mk b/drm/libdrmframework/Android.mk index 765adba..99133ba 100644 --- a/drm/libdrmframework/Android.mk +++ b/drm/libdrmframework/Android.mk @@ -42,6 +42,8 @@ LOCAL_C_INCLUDES += \ LOCAL_PRELINK_MODULE := false +LOCAL_MODULE_TAGS := optional + include $(BUILD_SHARED_LIBRARY) include $(call all-makefiles-under,$(LOCAL_PATH)) diff --git a/drm/libdrmframework/plugins/passthru/Android.mk b/drm/libdrmframework/plugins/passthru/Android.mk index 169b89b..7856d37 100644 --- a/drm/libdrmframework/plugins/passthru/Android.mk +++ b/drm/libdrmframework/plugins/passthru/Android.mk @@ -43,7 +43,6 @@ LOCAL_C_INCLUDES += \ # Set the following flag to enable the decryption passthru flow #LOCAL_CFLAGS += -DENABLE_PASSTHRU_DECRYPTION -PRODUCT_COPY_FILES += \ - $(TARGET_OUT_SHARED_LIBRARIES)/libdrmpassthruplugin.so:system/lib/drm/plugins/native/libdrmpassthruplugin.so +LOCAL_MODULE_TAGS := optional include $(BUILD_SHARED_LIBRARY) -- 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/common/DrmConstraints.cpp | 4 - drm/common/DrmEngineBase.cpp | 38 +++--- drm/common/DrmInfoEvent.cpp | 4 - drm/common/DrmRights.cpp | 22 +++- drm/common/DrmSupportInfo.cpp | 4 +- drm/common/IDrmIOService.cpp | 4 - drm/common/IDrmManagerService.cpp | 114 +++++++++++++---- drm/common/IDrmServiceListener.cpp | 4 - drm/common/ReadWriteUtils.cpp | 61 +++++---- drm/drmserver/DrmManager.cpp | 136 ++++++++++++++------- drm/drmserver/DrmManagerService.cpp | 69 ++++++----- drm/drmserver/StringTokenizer.cpp | 2 - drm/libdrmframework/DrmManagerClient.cpp | 43 +++---- drm/libdrmframework/DrmManagerClientImpl.cpp | 85 ++++++------- drm/libdrmframework/include/DrmManager.h | 24 ++-- drm/libdrmframework/include/DrmManagerClientImpl.h | 38 ++++-- drm/libdrmframework/include/DrmManagerService.h | 24 ++-- drm/libdrmframework/include/IDrmManagerService.h | 52 ++++---- drm/libdrmframework/include/ReadWriteUtils.h | 8 ++ .../plugins/common/include/DrmEngineBase.h | 63 ++++++---- .../plugins/common/include/IDrmEngine.h | 41 +++++-- .../plugins/passthru/include/DrmPassthruPlugIn.h | 22 ++-- .../plugins/passthru/src/DrmPassthruPlugIn.cpp | 29 +++-- 23 files changed, 550 insertions(+), 341 deletions(-) (limited to 'drm') diff --git a/drm/common/DrmConstraints.cpp b/drm/common/DrmConstraints.cpp index 11ce410..4a4d798 100644 --- a/drm/common/DrmConstraints.cpp +++ b/drm/common/DrmConstraints.cpp @@ -75,12 +75,10 @@ DrmConstraints::KeyIterator DrmConstraints::keyIterator() { DrmConstraints::KeyIterator::KeyIterator(const DrmConstraints::KeyIterator& keyIterator) : mDrmConstraints(keyIterator.mDrmConstraints), mIndex(keyIterator.mIndex) { - LOGV("DrmConstraints::KeyIterator::KeyIterator"); } DrmConstraints::KeyIterator& DrmConstraints::KeyIterator::operator=( const DrmConstraints::KeyIterator& keyIterator) { - LOGV("DrmConstraints::KeyIterator::operator="); mDrmConstraints = keyIterator.mDrmConstraints; mIndex = keyIterator.mIndex; return *this; @@ -94,12 +92,10 @@ DrmConstraints::Iterator DrmConstraints::iterator() { DrmConstraints::Iterator::Iterator(const DrmConstraints::Iterator& iterator) : mDrmConstraints(iterator.mDrmConstraints), mIndex(iterator.mIndex) { - LOGV("DrmConstraints::Iterator::Iterator"); } DrmConstraints::Iterator& DrmConstraints::Iterator::operator=( const DrmConstraints::Iterator& iterator) { - LOGV("DrmConstraints::Iterator::operator="); mDrmConstraints = iterator.mDrmConstraints; mIndex = iterator.mIndex; return *this; diff --git a/drm/common/DrmEngineBase.cpp b/drm/common/DrmEngineBase.cpp index 70398e8..17cdf54 100644 --- a/drm/common/DrmEngineBase.cpp +++ b/drm/common/DrmEngineBase.cpp @@ -52,7 +52,7 @@ DrmInfoStatus* DrmEngineBase::processDrmInfo(int uniqueId, const DrmInfo* drmInf return onProcessDrmInfo(uniqueId, drmInfo); } -void DrmEngineBase::saveRights( +status_t DrmEngineBase::saveRights( int uniqueId, const DrmRights& drmRights, const String8& rightsPath, const String8& contentPath) { return onSaveRights(uniqueId, drmRights, rightsPath, contentPath); @@ -74,14 +74,14 @@ int DrmEngineBase::checkRightsStatus(int uniqueId, const String8& path, int acti return onCheckRightsStatus(uniqueId, path, action); } -void DrmEngineBase::consumeRights( +status_t DrmEngineBase::consumeRights( int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) { - onConsumeRights(uniqueId, decryptHandle, action, reserve); + return onConsumeRights(uniqueId, decryptHandle, action, reserve); } -void DrmEngineBase::setPlaybackStatus( +status_t DrmEngineBase::setPlaybackStatus( int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position) { - onSetPlaybackStatus(uniqueId, decryptHandle, playbackStatus, position); + return onSetPlaybackStatus(uniqueId, decryptHandle, playbackStatus, position); } bool DrmEngineBase::validateAction( @@ -90,16 +90,16 @@ bool DrmEngineBase::validateAction( return onValidateAction(uniqueId, path, action, description); } -void DrmEngineBase::removeRights(int uniqueId, const String8& path) { - onRemoveRights(uniqueId, path); +status_t DrmEngineBase::removeRights(int uniqueId, const String8& path) { + return onRemoveRights(uniqueId, path); } -void DrmEngineBase::removeAllRights(int uniqueId) { - onRemoveAllRights(uniqueId); +status_t DrmEngineBase::removeAllRights(int uniqueId) { + return onRemoveAllRights(uniqueId); } -void DrmEngineBase::openConvertSession(int uniqueId, int convertId) { - onOpenConvertSession(uniqueId, convertId); +status_t DrmEngineBase::openConvertSession(int uniqueId, int convertId) { + return onOpenConvertSession(uniqueId, convertId); } DrmConvertedStatus* DrmEngineBase::convertData( @@ -120,24 +120,24 @@ status_t DrmEngineBase::openDecryptSession( return onOpenDecryptSession(uniqueId, decryptHandle, fd, offset, length); } -void DrmEngineBase::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) { - onCloseDecryptSession(uniqueId, decryptHandle); +status_t DrmEngineBase::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) { + return onCloseDecryptSession(uniqueId, decryptHandle); } -void DrmEngineBase::initializeDecryptUnit( +status_t DrmEngineBase::initializeDecryptUnit( int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo) { - onInitializeDecryptUnit(uniqueId, decryptHandle, decryptUnitId, headerInfo); + return onInitializeDecryptUnit(uniqueId, decryptHandle, decryptUnitId, headerInfo); } status_t DrmEngineBase::decrypt( int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, - const DrmBuffer* encBuffer, DrmBuffer** decBuffer) { - return onDecrypt(uniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer); + const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) { + return onDecrypt(uniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer, IV); } -void DrmEngineBase::finalizeDecryptUnit( +status_t DrmEngineBase::finalizeDecryptUnit( int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) { - onFinalizeDecryptUnit(uniqueId, decryptHandle, decryptUnitId); + return onFinalizeDecryptUnit(uniqueId, decryptHandle, decryptUnitId); } ssize_t DrmEngineBase::pread( diff --git a/drm/common/DrmInfoEvent.cpp b/drm/common/DrmInfoEvent.cpp index eb58129..8d115a8 100644 --- a/drm/common/DrmInfoEvent.cpp +++ b/drm/common/DrmInfoEvent.cpp @@ -14,10 +14,6 @@ * limitations under the License. */ -#define LOG_NDEBUG 0 -#define LOG_TAG "DrmInfoEvent" -#include "utils/Log.h" - #include #include diff --git a/drm/common/DrmRights.cpp b/drm/common/DrmRights.cpp index dc1e6c5..3aecb3d 100644 --- a/drm/common/DrmRights.cpp +++ b/drm/common/DrmRights.cpp @@ -15,14 +15,21 @@ */ #include +#include using namespace android; DrmRights::DrmRights(const String8& rightsFilePath, const String8& mimeType, - const String8& accountId, const String8& subscriptionId) { - /** - * TODO Read DrmRights from rights file - */ + const String8& accountId, const String8& subscriptionId) : + mMimeType(mimeType), + mAccountId(accountId), + mSubscriptionId(subscriptionId), + mRightsFromFile(NULL) { + int rightsLength = 0; + if (String8("") != rightsFilePath) { + rightsLength = ReadWriteUtils::readBytes(rightsFilePath, &mRightsFromFile); + } + mData = DrmBuffer(mRightsFromFile, rightsLength); } DrmRights::DrmRights(const DrmBuffer& rightsData, const String8& mimeType, @@ -30,7 +37,12 @@ DrmRights::DrmRights(const DrmBuffer& rightsData, const String8& mimeType, mData(rightsData), mMimeType(mimeType), mAccountId(accountId), - mSubscriptionId(subscriptionId) { + mSubscriptionId(subscriptionId), + mRightsFromFile(NULL) { +} + +DrmRights::~DrmRights() { + delete[] mRightsFromFile; mRightsFromFile = NULL; } const DrmBuffer& DrmRights::getData(void) const { diff --git a/drm/common/DrmSupportInfo.cpp b/drm/common/DrmSupportInfo.cpp index 35e83fc..ffc8953 100644 --- a/drm/common/DrmSupportInfo.cpp +++ b/drm/common/DrmSupportInfo.cpp @@ -42,7 +42,7 @@ bool DrmSupportInfo::operator==(const DrmSupportInfo& drmSupportInfo) const { } bool DrmSupportInfo::isSupportedMimeType(const String8& mimeType) const { - for (int i = 0; i < mMimeTypeVector.size(); i++) { + for (unsigned int i = 0; i < mMimeTypeVector.size(); i++) { const String8 item = mMimeTypeVector.itemAt(i); if (String8("") != mimeType && item.find(mimeType) != -1) { @@ -53,7 +53,7 @@ bool DrmSupportInfo::isSupportedMimeType(const String8& mimeType) const { } bool DrmSupportInfo::isSupportedFileSuffix(const String8& fileType) const { - for (int i = 0; i < mFileSuffixVector.size(); i++) { + for (unsigned int i = 0; i < mFileSuffixVector.size(); i++) { const String8 item = mFileSuffixVector.itemAt(i); if (String8("") != fileType && item.find(fileType) != -1) { diff --git a/drm/common/IDrmIOService.cpp b/drm/common/IDrmIOService.cpp index 7ce45e7..e44ca55 100644 --- a/drm/common/IDrmIOService.cpp +++ b/drm/common/IDrmIOService.cpp @@ -14,10 +14,6 @@ * limitations under the License. */ -#define LOG_NDEBUG 0 -#define LOG_TAG "IDrmIOService" -#include - #include #include #include diff --git a/drm/common/IDrmManagerService.cpp b/drm/common/IDrmManagerService.cpp index 4fc828a..c28527c 100644 --- a/drm/common/IDrmManagerService.cpp +++ b/drm/common/IDrmManagerService.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#define LOG_NDEBUG 0 +//#define LOG_NDEBUG 0 #define LOG_TAG "IDrmManagerService(Native)" #include @@ -36,6 +36,23 @@ using namespace android; +int BpDrmManagerService::addUniqueId(int uniqueId) { + LOGV("add uniqueid"); + Parcel data, reply; + data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); + data.writeInt32(uniqueId); + remote()->transact(ADD_UNIQUEID, data, &reply); + return reply.readInt32(); +} + +void BpDrmManagerService::removeUniqueId(int uniqueId) { + LOGV("remove uniqueid"); + Parcel data, reply; + data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); + data.writeInt32(uniqueId); + remote()->transact(REMOVE_UNIQUEID, data, &reply); +} + status_t BpDrmManagerService::loadPlugIns(int uniqueId) { LOGV("load plugins"); Parcel data, reply; @@ -237,7 +254,7 @@ DrmInfo* BpDrmManagerService::acquireDrmInfo(int uniqueId, const DrmInfoRequest* return drmInfo; } -void BpDrmManagerService::saveRights( +status_t BpDrmManagerService::saveRights( int uniqueId, const DrmRights& drmRights, const String8& rightsPath, const String8& contentPath) { LOGV("Save Rights"); @@ -264,6 +281,7 @@ void BpDrmManagerService::saveRights( data.writeString8((contentPath == String8("")) ? String8("NULL") : contentPath); remote()->transact(SAVE_RIGHTS, data, &reply); + return reply.readInt32(); } String8 BpDrmManagerService::getOriginalMimeType(int uniqueId, const String8& path) { @@ -307,10 +325,10 @@ int BpDrmManagerService::checkRightsStatus(int uniqueId, const String8& path, in return reply.readInt32(); } -void BpDrmManagerService::consumeRights( +status_t BpDrmManagerService::consumeRights( int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) { LOGV("consumeRights"); - Parcel data, reply; + Parcel data, reply; data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); data.writeInt32(uniqueId); @@ -330,9 +348,10 @@ void BpDrmManagerService::consumeRights( data.writeInt32(static_cast< int>(reserve)); remote()->transact(CONSUME_RIGHTS, data, &reply); + return reply.readInt32(); } -void BpDrmManagerService::setPlaybackStatus( +status_t BpDrmManagerService::setPlaybackStatus( int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position) { LOGV("setPlaybackStatus"); Parcel data, reply; @@ -355,6 +374,7 @@ void BpDrmManagerService::setPlaybackStatus( data.writeInt32(position); remote()->transact(SET_PLAYBACK_STATUS, data, &reply); + return reply.readInt32(); } bool BpDrmManagerService::validateAction( @@ -375,7 +395,7 @@ bool BpDrmManagerService::validateAction( return static_cast(reply.readInt32()); } -void BpDrmManagerService::removeRights(int uniqueId, const String8& path) { +status_t BpDrmManagerService::removeRights(int uniqueId, const String8& path) { LOGV("removeRights"); Parcel data, reply; @@ -384,9 +404,10 @@ void BpDrmManagerService::removeRights(int uniqueId, const String8& path) { data.writeString8(path); remote()->transact(REMOVE_RIGHTS, data, &reply); + return reply.readInt32(); } -void BpDrmManagerService::removeAllRights(int uniqueId) { +status_t BpDrmManagerService::removeAllRights(int uniqueId) { LOGV("removeAllRights"); Parcel data, reply; @@ -394,6 +415,7 @@ void BpDrmManagerService::removeAllRights(int uniqueId) { data.writeInt32(uniqueId); remote()->transact(REMOVE_ALL_RIGHTS, data, &reply); + return reply.readInt32(); } int BpDrmManagerService::openConvertSession(int uniqueId, const String8& mimeType) { @@ -517,15 +539,12 @@ DecryptHandle* BpDrmManagerService::openDecryptSession( Parcel data, reply; const String16 interfaceDescriptor = IDrmManagerService::getInterfaceDescriptor(); - LOGV("BpDrmManagerService::openDecryptSession: InterfaceDescriptor name is %s", - interfaceDescriptor.string()); data.writeInterfaceToken(interfaceDescriptor); data.writeInt32(uniqueId); data.writeFileDescriptor(fd); data.writeInt32(offset); data.writeInt32(length); - LOGV("try to invoke remote onTransact() with code OPEN_DECRYPT_SESSION"); remote()->transact(OPEN_DECRYPT_SESSION, data, &reply); DecryptHandle* handle = NULL; @@ -546,7 +565,7 @@ DecryptHandle* BpDrmManagerService::openDecryptSession( return handle; } -void BpDrmManagerService::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) { +status_t BpDrmManagerService::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) { LOGV("closeDecryptSession"); Parcel data, reply; @@ -571,9 +590,10 @@ void BpDrmManagerService::closeDecryptSession(int uniqueId, DecryptHandle* decry delete decryptHandle->decryptInfo; decryptHandle->decryptInfo = NULL; } delete decryptHandle; decryptHandle = NULL; + return reply.readInt32(); } -void BpDrmManagerService::initializeDecryptUnit( +status_t BpDrmManagerService::initializeDecryptUnit( int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo) { LOGV("initializeDecryptUnit"); @@ -598,11 +618,12 @@ void BpDrmManagerService::initializeDecryptUnit( data.write(headerInfo->data, headerInfo->length); remote()->transact(INITIALIZE_DECRYPT_UNIT, data, &reply); + return reply.readInt32(); } status_t BpDrmManagerService::decrypt( int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, - const DrmBuffer* encBuffer, DrmBuffer** decBuffer) { + const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) { LOGV("decrypt"); Parcel data, reply; @@ -626,6 +647,11 @@ status_t BpDrmManagerService::decrypt( data.writeInt32(encBuffer->length); data.write(encBuffer->data, encBuffer->length); + if (NULL != IV) { + data.writeInt32(IV->length); + data.write(IV->data, IV->length); + } + remote()->transact(DECRYPT, data, &reply); const status_t status = reply.readInt32(); @@ -638,7 +664,7 @@ status_t BpDrmManagerService::decrypt( return status; } -void BpDrmManagerService::finalizeDecryptUnit( +status_t BpDrmManagerService::finalizeDecryptUnit( int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) { LOGV("finalizeDecryptUnit"); Parcel data, reply; @@ -660,6 +686,7 @@ void BpDrmManagerService::finalizeDecryptUnit( data.writeInt32(decryptUnitId); remote()->transact(FINALIZE_DECRYPT_UNIT, data, &reply); + return reply.readInt32(); } ssize_t BpDrmManagerService::pread( @@ -702,6 +729,23 @@ status_t BnDrmManagerService::onTransact( LOGV("Entering BnDrmManagerService::onTransact with code %d", code); switch (code) { + case ADD_UNIQUEID: + { + LOGV("BnDrmManagerService::onTransact :ADD_UNIQUEID"); + CHECK_INTERFACE(IDrmManagerService, data, reply); + int uniqueId = addUniqueId(data.readInt32()); + reply->writeInt32(uniqueId); + return DRM_NO_ERROR; + } + + case REMOVE_UNIQUEID: + { + LOGV("BnDrmManagerService::onTransact :REMOVE_UNIQUEID"); + CHECK_INTERFACE(IDrmManagerService, data, reply); + removeUniqueId(data.readInt32()); + return DRM_NO_ERROR; + } + case LOAD_PLUGINS: { LOGV("BnDrmManagerService::onTransact :LOAD_PLUGINS"); @@ -711,7 +755,6 @@ status_t BnDrmManagerService::onTransact( reply->writeInt32(status); return DRM_NO_ERROR; - } case LOAD_PLUGINS_FROM_PATH: @@ -745,7 +788,8 @@ status_t BnDrmManagerService::onTransact( LOGV("BnDrmManagerService::onTransact :UNLOAD_PLUGINS"); CHECK_INTERFACE(IDrmManagerService, data, reply); - status_t status = unloadPlugIns(data.readInt32()); + const int uniqueId = data.readInt32(); + status_t status = unloadPlugIns(uniqueId); reply->writeInt32(status); return DRM_NO_ERROR; @@ -923,10 +967,11 @@ status_t BnDrmManagerService::onTransact( ((accountId == String8("NULL")) ? String8("") : accountId), ((subscriptionId == String8("NULL")) ? String8("") : subscriptionId)); - saveRights(uniqueId, drmRights, + const status_t status = saveRights(uniqueId, drmRights, ((rightsPath == String8("NULL")) ? String8("") : rightsPath), ((contentPath == String8("NULL")) ? String8("") : contentPath)); + reply->writeInt32(status); return DRM_NO_ERROR; } @@ -985,7 +1030,10 @@ status_t BnDrmManagerService::onTransact( handle.decryptInfo->decryptBufferLength = bufferLength; } - consumeRights(uniqueId, &handle, data.readInt32(), static_cast(data.readInt32())); + const status_t status + = consumeRights(uniqueId, &handle, data.readInt32(), + static_cast(data.readInt32())); + reply->writeInt32(status); delete handle.decryptInfo; handle.decryptInfo = NULL; return DRM_NO_ERROR; @@ -1011,7 +1059,9 @@ status_t BnDrmManagerService::onTransact( handle.decryptInfo->decryptBufferLength = bufferLength; } - setPlaybackStatus(uniqueId, &handle, data.readInt32(), data.readInt32()); + const status_t status + = setPlaybackStatus(uniqueId, &handle, data.readInt32(), data.readInt32()); + reply->writeInt32(status); delete handle.decryptInfo; handle.decryptInfo = NULL; return DRM_NO_ERROR; @@ -1037,7 +1087,8 @@ status_t BnDrmManagerService::onTransact( LOGV("BnDrmManagerService::onTransact :REMOVE_RIGHTS"); CHECK_INTERFACE(IDrmManagerService, data, reply); - removeRights(data.readInt32(), data.readString8()); + const status_t status = removeRights(data.readInt32(), data.readString8()); + reply->writeInt32(status); return DRM_NO_ERROR; } @@ -1047,7 +1098,8 @@ status_t BnDrmManagerService::onTransact( LOGV("BnDrmManagerService::onTransact :REMOVE_ALL_RIGHTS"); CHECK_INTERFACE(IDrmManagerService, data, reply); - removeAllRights(data.readInt32()); + const status_t status = removeAllRights(data.readInt32()); + reply->writeInt32(status); return DRM_NO_ERROR; } @@ -1207,7 +1259,8 @@ status_t BnDrmManagerService::onTransact( handle->decryptInfo->decryptBufferLength = bufferLength; } - closeDecryptSession(uniqueId, handle); + const status_t status = closeDecryptSession(uniqueId, handle); + reply->writeInt32(status); return DRM_NO_ERROR; } @@ -1237,7 +1290,9 @@ status_t BnDrmManagerService::onTransact( DrmBuffer* headerInfo = NULL; headerInfo = new DrmBuffer((char *)data.readInplace(bufferSize), bufferSize); - initializeDecryptUnit(uniqueId, &handle, decryptUnitId, headerInfo); + const status_t status + = initializeDecryptUnit(uniqueId, &handle, decryptUnitId, headerInfo); + reply->writeInt32(status); delete handle.decryptInfo; handle.decryptInfo = NULL; delete headerInfo; headerInfo = NULL; @@ -1274,7 +1329,14 @@ status_t BnDrmManagerService::onTransact( buffer = new char[decBufferSize]; DrmBuffer* decBuffer = new DrmBuffer(buffer, decBufferSize); - const status_t status = decrypt(uniqueId, &handle, decryptUnitId, encBuffer, &decBuffer); + DrmBuffer* IV = NULL; + if (0 != data.dataAvail()) { + const int ivBufferlength = data.readInt32(); + IV = new DrmBuffer((char *)data.readInplace(ivBufferlength), ivBufferlength); + } + + const status_t status + = decrypt(uniqueId, &handle, decryptUnitId, encBuffer, &decBuffer, IV); reply->writeInt32(status); @@ -1286,6 +1348,7 @@ status_t BnDrmManagerService::onTransact( delete encBuffer; encBuffer = NULL; delete decBuffer; decBuffer = NULL; delete [] buffer; buffer = NULL; + delete IV; IV = NULL; return DRM_NO_ERROR; } @@ -1309,7 +1372,8 @@ status_t BnDrmManagerService::onTransact( handle.decryptInfo->decryptBufferLength = bufferLength; } - finalizeDecryptUnit(uniqueId, &handle, data.readInt32()); + const status_t status = finalizeDecryptUnit(uniqueId, &handle, data.readInt32()); + reply->writeInt32(status); delete handle.decryptInfo; handle.decryptInfo = NULL; return DRM_NO_ERROR; diff --git a/drm/common/IDrmServiceListener.cpp b/drm/common/IDrmServiceListener.cpp index 0a69115..6eeea40 100644 --- a/drm/common/IDrmServiceListener.cpp +++ b/drm/common/IDrmServiceListener.cpp @@ -14,10 +14,6 @@ * limitations under the License. */ -#define LOG_NDEBUG 0 -#define LOG_TAG "IDrmServiceListener" -#include - #include #include #include diff --git a/drm/common/ReadWriteUtils.cpp b/drm/common/ReadWriteUtils.cpp index 4319c1c..7ec4fa2 100644 --- a/drm/common/ReadWriteUtils.cpp +++ b/drm/common/ReadWriteUtils.cpp @@ -14,6 +14,10 @@ * limitations under the License. */ +//#define LOG_NDEBUG 0 +#define LOG_TAG "ReadWriteUtils" +#include + #include #include #include @@ -22,7 +26,6 @@ #include #include #include -#include #include using namespace android; @@ -39,18 +42,39 @@ String8 ReadWriteUtils::readBytes(const String8& filePath) { struct stat sb; if (fstat(fd, &sb) == 0 && sb.st_size > 0) { - FileMap* fileMap = new FileMap(); - if (fileMap->create(filePath.string(), fd, 0, sb.st_size, true)) { - char* addr = (char*)fileMap->getDataPtr(); - string.append(addr, sb.st_size); - fileMap->release(); + int length = sb.st_size; + char* bytes = new char[length]; + if (length == read(fd, (void*) bytes, length)) { + string.append(bytes, length); } + delete bytes; } fclose(file); } return string; } +int ReadWriteUtils::readBytes(const String8& filePath, char** buffer) { + FILE* file = NULL; + file = fopen(filePath.string(), "r"); + int length = 0; + + if (NULL != file) { + int fd = fileno(file); + struct stat sb; + + if (fstat(fd, &sb) == 0 && sb.st_size > 0) { + length = sb.st_size; + *buffer = new char[length]; + if (length != read(fd, (void*) *buffer, length)) { + length = FAILURE; + } + } + fclose(file); + } + return length; +} + void ReadWriteUtils::writeToFile(const String8& filePath, const String8& data) { FILE* file = NULL; file = fopen(filePath.string(), "w+"); @@ -60,12 +84,8 @@ void ReadWriteUtils::writeToFile(const String8& filePath, const String8& data) { int size = data.size(); if (FAILURE != ftruncate(fd, size)) { - FileMap* fileMap = NULL; - fileMap = new FileMap(); - if (fileMap->create(filePath.string(), fd, 0, size, false)) { - char* addr = (char*)fileMap->getDataPtr(); - memcpy(addr, data.string(), size); - fileMap->release(); + if (size != write(fd, data.string(), size)) { + LOGE("Failed to write the data to: %s", filePath.string()); } } fclose(file); @@ -79,20 +99,9 @@ void ReadWriteUtils::appendToFile(const String8& filePath, const String8& data) if (NULL != file) { int fd = fileno(file); - int offset = lseek(fd, 0, SEEK_END); - if (FAILURE != offset) { - int newEntrySize = data.size(); - int fileSize = offset + newEntrySize; - - if (FAILURE != ftruncate(fd, fileSize)) { - FileMap* fileMap = NULL; - fileMap = new FileMap(); - if (fileMap->create(filePath.string(), fd, offset, fileSize, false)) { - char* addr = (char*)fileMap->getDataPtr(); - memcpy(addr, data.string(), data.size()); - fileMap->release(); - } - } + int size = data.size(); + if (size != write(fd, data.string(), size)) { + LOGE("Failed to write the data to: %s", filePath.string()); } fclose(file); } 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; diff --git a/drm/libdrmframework/DrmManagerClient.cpp b/drm/libdrmframework/DrmManagerClient.cpp index 06c7c50..c996994 100644 --- a/drm/libdrmframework/DrmManagerClient.cpp +++ b/drm/libdrmframework/DrmManagerClient.cpp @@ -14,10 +14,6 @@ * limitations under the License. */ -#define LOG_NDEBUG 0 -#define LOG_TAG "DrmManagerClient(Native)" -#include - #include #include #include @@ -37,8 +33,8 @@ DrmManagerClient::DrmManagerClient() { } DrmManagerClient::~DrmManagerClient() { - unloadPlugIns(); DrmManagerClientImpl::remove(mUniqueId); + unloadPlugIns(); delete mDrmManagerClientImpl; mDrmManagerClientImpl = NULL; } @@ -72,7 +68,7 @@ DrmInfo* DrmManagerClient::acquireDrmInfo(const DrmInfoRequest* drmInfoRequest) return mDrmManagerClientImpl->acquireDrmInfo(mUniqueId, drmInfoRequest); } -void DrmManagerClient::saveRights( +status_t DrmManagerClient::saveRights( const DrmRights& drmRights, const String8& rightsPath, const String8& contentPath) { return mDrmManagerClientImpl->saveRights(mUniqueId, drmRights, rightsPath, contentPath); } @@ -89,13 +85,14 @@ int DrmManagerClient::checkRightsStatus(const String8& path, int action) { return mDrmManagerClientImpl->checkRightsStatus(mUniqueId, path, action); } -void DrmManagerClient::consumeRights(DecryptHandle* decryptHandle, int action, bool reserve) { - mDrmManagerClientImpl->consumeRights(mUniqueId, decryptHandle, action, reserve); +status_t DrmManagerClient::consumeRights(DecryptHandle* decryptHandle, int action, bool reserve) { + return mDrmManagerClientImpl->consumeRights(mUniqueId, decryptHandle, action, reserve); } -void DrmManagerClient::setPlaybackStatus( +status_t DrmManagerClient::setPlaybackStatus( DecryptHandle* decryptHandle, int playbackStatus, int position) { - mDrmManagerClientImpl->setPlaybackStatus(mUniqueId, decryptHandle, playbackStatus, position); + return mDrmManagerClientImpl + ->setPlaybackStatus(mUniqueId, decryptHandle, playbackStatus, position); } bool DrmManagerClient::validateAction( @@ -103,12 +100,12 @@ bool DrmManagerClient::validateAction( return mDrmManagerClientImpl->validateAction(mUniqueId, path, action, description); } -void DrmManagerClient::removeRights(const String8& path) { - mDrmManagerClientImpl->removeRights(mUniqueId, path); +status_t DrmManagerClient::removeRights(const String8& path) { + return mDrmManagerClientImpl->removeRights(mUniqueId, path); } -void DrmManagerClient::removeAllRights() { - mDrmManagerClientImpl->removeAllRights(mUniqueId); +status_t DrmManagerClient::removeAllRights() { + return mDrmManagerClientImpl->removeAllRights(mUniqueId); } int DrmManagerClient::openConvertSession(const String8& mimeType) { @@ -131,25 +128,25 @@ DecryptHandle* DrmManagerClient::openDecryptSession(int fd, int offset, int leng return mDrmManagerClientImpl->openDecryptSession(mUniqueId, fd, offset, length); } -void DrmManagerClient::closeDecryptSession(DecryptHandle* decryptHandle) { - mDrmManagerClientImpl->closeDecryptSession(mUniqueId, decryptHandle); +status_t DrmManagerClient::closeDecryptSession(DecryptHandle* decryptHandle) { + return mDrmManagerClientImpl->closeDecryptSession(mUniqueId, decryptHandle); } -void DrmManagerClient::initializeDecryptUnit( +status_t DrmManagerClient::initializeDecryptUnit( DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo) { - mDrmManagerClientImpl->initializeDecryptUnit( - mUniqueId, decryptHandle, decryptUnitId, headerInfo); + return mDrmManagerClientImpl->initializeDecryptUnit( + mUniqueId, decryptHandle, decryptUnitId, headerInfo); } status_t DrmManagerClient::decrypt( DecryptHandle* decryptHandle, int decryptUnitId, - const DrmBuffer* encBuffer, DrmBuffer** decBuffer) { + const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) { return mDrmManagerClientImpl->decrypt( - mUniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer); + mUniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer, IV); } -void DrmManagerClient::finalizeDecryptUnit(DecryptHandle* decryptHandle, int decryptUnitId) { - mDrmManagerClientImpl->finalizeDecryptUnit(mUniqueId, decryptHandle, decryptUnitId); +status_t DrmManagerClient::finalizeDecryptUnit(DecryptHandle* decryptHandle, int decryptUnitId) { + return mDrmManagerClientImpl->finalizeDecryptUnit(mUniqueId, decryptHandle, decryptUnitId); } ssize_t DrmManagerClient::pread( diff --git a/drm/libdrmframework/DrmManagerClientImpl.cpp b/drm/libdrmframework/DrmManagerClientImpl.cpp index 7274b49..272adcd 100644 --- a/drm/libdrmframework/DrmManagerClientImpl.cpp +++ b/drm/libdrmframework/DrmManagerClientImpl.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#define LOG_NDEBUG 0 +//#define LOG_NDEBUG 0 #define LOG_TAG "DrmManagerClientImpl(Native)" #include @@ -29,44 +29,21 @@ using namespace android; #define INVALID_VALUE -1 Mutex DrmManagerClientImpl::mMutex; -Vector DrmManagerClientImpl::mUniqueIdVector; sp DrmManagerClientImpl::mDrmManagerService; const String8 DrmManagerClientImpl::EMPTY_STRING(""); DrmManagerClientImpl* DrmManagerClientImpl::create(int* pUniqueId) { if (0 == *pUniqueId) { - int uniqueId = 0; - bool foundUniqueId = false; - srand(time(NULL)); - - while (!foundUniqueId) { - const int size = mUniqueIdVector.size(); - uniqueId = rand() % 100; - - int index = 0; - for (; index < size; ++index) { - if (mUniqueIdVector.itemAt(index) == uniqueId) { - foundUniqueId = false; - break; - } - } - if (index == size) { - foundUniqueId = true; - } - } + int uniqueId = getDrmManagerService()->addUniqueId(*pUniqueId); *pUniqueId = uniqueId; + } else { + getDrmManagerService()->addUniqueId(*pUniqueId); } - mUniqueIdVector.push(*pUniqueId); return new DrmManagerClientImpl(); } void DrmManagerClientImpl::remove(int uniqueId) { - for (int i = 0; i < mUniqueIdVector.size(); i++) { - if (uniqueId == mUniqueIdVector.itemAt(i)) { - mUniqueIdVector.removeAt(i); - break; - } - } + getDrmManagerService()->removeUniqueId(uniqueId); } DrmManagerClientImpl::DrmManagerClientImpl() { @@ -164,11 +141,13 @@ DrmInfo* DrmManagerClientImpl::acquireDrmInfo(int uniqueId, const DrmInfoRequest return drmInfo; } -void DrmManagerClientImpl::saveRights(int uniqueId, const DrmRights& drmRights, +status_t DrmManagerClientImpl::saveRights(int uniqueId, const DrmRights& drmRights, const String8& rightsPath, const String8& contentPath) { + status_t status = DRM_ERROR_UNKNOWN; if (EMPTY_STRING != contentPath) { - getDrmManagerService()->saveRights(uniqueId, drmRights, rightsPath, contentPath); + status = getDrmManagerService()->saveRights(uniqueId, drmRights, rightsPath, contentPath); } + return status; } String8 DrmManagerClientImpl::getOriginalMimeType(int uniqueId, const String8& path) { @@ -197,19 +176,23 @@ int DrmManagerClientImpl::checkRightsStatus( return rightsStatus; } -void DrmManagerClientImpl::consumeRights( +status_t DrmManagerClientImpl::consumeRights( int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) { + status_t status = DRM_ERROR_UNKNOWN; if (NULL != decryptHandle) { - getDrmManagerService()->consumeRights(uniqueId, decryptHandle, action, reserve); + status = getDrmManagerService()->consumeRights(uniqueId, decryptHandle, action, reserve); } + return status; } -void DrmManagerClientImpl::setPlaybackStatus( +status_t DrmManagerClientImpl::setPlaybackStatus( int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position) { + status_t status = DRM_ERROR_UNKNOWN; if (NULL != decryptHandle) { - getDrmManagerService()->setPlaybackStatus( + status = getDrmManagerService()->setPlaybackStatus( uniqueId, decryptHandle, playbackStatus, position); } + return status; } bool DrmManagerClientImpl::validateAction( @@ -221,14 +204,16 @@ bool DrmManagerClientImpl::validateAction( return retCode; } -void DrmManagerClientImpl::removeRights(int uniqueId, const String8& path) { +status_t DrmManagerClientImpl::removeRights(int uniqueId, const String8& path) { + status_t status = DRM_ERROR_UNKNOWN; if (EMPTY_STRING != path) { - getDrmManagerService()->removeRights(uniqueId, path); + status = getDrmManagerService()->removeRights(uniqueId, path); } + return status; } -void DrmManagerClientImpl::removeAllRights(int uniqueId) { - getDrmManagerService()->removeAllRights(uniqueId); +status_t DrmManagerClientImpl::removeAllRights(int uniqueId) { + return getDrmManagerService()->removeAllRights(uniqueId); } int DrmManagerClientImpl::openConvertSession(int uniqueId, const String8& mimeType) { @@ -263,40 +248,46 @@ status_t DrmManagerClientImpl::getAllSupportInfo( DecryptHandle* DrmManagerClientImpl::openDecryptSession( int uniqueId, int fd, int offset, int length) { - LOGV("Entering DrmManagerClientImpl::openDecryptSession"); return getDrmManagerService()->openDecryptSession(uniqueId, fd, offset, length); } -void DrmManagerClientImpl::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) { +status_t DrmManagerClientImpl::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) { + status_t status = DRM_ERROR_UNKNOWN; if (NULL != decryptHandle) { - getDrmManagerService()->closeDecryptSession( uniqueId, decryptHandle); + status = getDrmManagerService()->closeDecryptSession( uniqueId, decryptHandle); } + return status; } -void DrmManagerClientImpl::initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, +status_t DrmManagerClientImpl::initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo) { + status_t status = DRM_ERROR_UNKNOWN; if ((NULL != decryptHandle) && (NULL != headerInfo)) { - getDrmManagerService()->initializeDecryptUnit( + status = getDrmManagerService()->initializeDecryptUnit( uniqueId, decryptHandle, decryptUnitId, headerInfo); } + return status; } status_t DrmManagerClientImpl::decrypt(int uniqueId, DecryptHandle* decryptHandle, - int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer) { + int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) { status_t status = DRM_ERROR_UNKNOWN; if ((NULL != decryptHandle) && (NULL != encBuffer) && (NULL != decBuffer) && (NULL != *decBuffer)) { status = getDrmManagerService()->decrypt( - uniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer); + uniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer, IV); } return status; } -void DrmManagerClientImpl::finalizeDecryptUnit( +status_t DrmManagerClientImpl::finalizeDecryptUnit( int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) { + status_t status = DRM_ERROR_UNKNOWN; if (NULL != decryptHandle) { - getDrmManagerService()->finalizeDecryptUnit(uniqueId, decryptHandle, decryptUnitId); + status + = getDrmManagerService()->finalizeDecryptUnit(uniqueId, decryptHandle, decryptUnitId); } + return status; } ssize_t DrmManagerClientImpl::pread(int uniqueId, DecryptHandle* decryptHandle, diff --git a/drm/libdrmframework/include/DrmManager.h b/drm/libdrmframework/include/DrmManager.h index 2ba9e99..dc3e460 100644 --- a/drm/libdrmframework/include/DrmManager.h +++ b/drm/libdrmframework/include/DrmManager.h @@ -53,6 +53,9 @@ public: virtual ~DrmManager(); public: + int addUniqueId(int uniqueId); + + void removeUniqueId(int uniqueId); status_t loadPlugIns(int uniqueId); @@ -73,7 +76,7 @@ public: DrmInfo* acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest); - void saveRights(int uniqueId, const DrmRights& drmRights, + status_t saveRights(int uniqueId, const DrmRights& drmRights, const String8& rightsPath, const String8& contentPath); String8 getOriginalMimeType(int uniqueId, const String8& path); @@ -82,17 +85,17 @@ public: int checkRightsStatus(int uniqueId, const String8& path, int action); - void consumeRights(int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve); + status_t consumeRights(int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve); - void setPlaybackStatus( + status_t setPlaybackStatus( int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position); bool validateAction( int uniqueId, const String8& path, int action, const ActionDescription& description); - void removeRights(int uniqueId, const String8& path); + status_t removeRights(int uniqueId, const String8& path); - void removeAllRights(int uniqueId); + status_t removeAllRights(int uniqueId); int openConvertSession(int uniqueId, const String8& mimeType); @@ -104,15 +107,15 @@ public: DecryptHandle* openDecryptSession(int uniqueId, int fd, int offset, int length); - void closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle); + status_t closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle); - void initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, + status_t initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo); - status_t decrypt(int uniqueId, DecryptHandle* decryptHandle, - int decryptUnitId, const DrmBuffer* encBuffer,DrmBuffer** decBuffer); + status_t decrypt(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, + const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV); - void finalizeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId); + status_t finalizeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId); ssize_t pread(int uniqueId, DecryptHandle* decryptHandle, void* buffer, ssize_t numBytes, off_t offset); @@ -133,6 +136,7 @@ private: void initializePlugIns(int uniqueId); private: + static Vector mUniqueIdVector; static const String8 EMPTY_STRING; int mDecryptSessionId; diff --git a/drm/libdrmframework/include/DrmManagerClientImpl.h b/drm/libdrmframework/include/DrmManagerClientImpl.h index e70e6e1..492c7f5 100644 --- a/drm/libdrmframework/include/DrmManagerClientImpl.h +++ b/drm/libdrmframework/include/DrmManagerClientImpl.h @@ -132,8 +132,10 @@ public: * @param[in] drmRights DrmRights to be saved * @param[in] rightsPath File path where rights to be saved * @param[in] contentPath File path where content was saved + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure */ - void saveRights(int uniqueId, const DrmRights& drmRights, + status_t saveRights(int uniqueId, const DrmRights& drmRights, const String8& rightsPath, const String8& contentPath); /** @@ -179,8 +181,10 @@ public: * @param[in] decryptHandle Handle for the decryption session * @param[in] action Action to perform. (Action::DEFAULT, Action::PLAY, etc) * @param[in] reserve True if the rights should be reserved. + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure */ - void consumeRights(int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve); + status_t consumeRights(int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve); /** * Informs the DRM engine about the playback actions performed on the DRM files. @@ -190,8 +194,10 @@ public: * @param[in] playbackStatus Playback action (Playback::START, Playback::STOP, Playback::PAUSE) * @param[in] position Position in the file (in milliseconds) where the start occurs. * Only valid together with Playback::START. + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure */ - void setPlaybackStatus( + status_t setPlaybackStatus( int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position); /** @@ -211,16 +217,20 @@ public: * * @param[in] uniqueId Unique identifier for a session * @param[in] path Path of the protected content + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure */ - void removeRights(int uniqueId, const String8& path); + status_t removeRights(int uniqueId, const String8& path); /** * Removes all the rights information of each plug-in associated with * DRM framework. Will be used in master reset * * @param[in] uniqueId Unique identifier for a session + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure */ - void removeAllRights(int uniqueId); + status_t removeAllRights(int uniqueId); /** * This API is for Forward Lock based DRM scheme. @@ -295,8 +305,10 @@ public: * * @param[in] uniqueId Unique identifier for a session * @param[in] decryptHandle Handle for the decryption session + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure */ - void closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle); + status_t closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle); /** * Initialize decryption for the given unit of the protected content @@ -305,8 +317,10 @@ public: * @param[in] decryptHandle Handle for the decryption session * @param[in] decryptUnitId ID which specifies decryption unit, such as track ID * @param[in] headerInfo Information for initializing decryption of this decrypUnit + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure */ - void initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, + status_t initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo); /** @@ -319,14 +333,15 @@ public: * @param[in] decryptUnitId ID which specifies decryption unit, such as track ID * @param[in] encBuffer Encrypted data block * @param[out] decBuffer Decrypted data block + * @param[in] IV Optional buffer * @return status_t * Returns the error code for this API * DRM_NO_ERROR for success, and one of DRM_ERROR_UNKNOWN, DRM_ERROR_LICENSE_EXPIRED * DRM_ERROR_SESSION_NOT_OPENED, DRM_ERROR_DECRYPT_UNIT_NOT_INITIALIZED, * DRM_ERROR_DECRYPT for failure. */ - status_t decrypt(int uniqueId, DecryptHandle* decryptHandle, - int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer); + status_t decrypt(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, + const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV); /** * Finalize decryption for the given unit of the protected content @@ -334,8 +349,10 @@ public: * @param[in] uniqueId Unique identifier for a session * @param[in] decryptHandle Handle for the decryption session * @param[in] decryptUnitId ID which specifies decryption unit, such as track ID + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure */ - void finalizeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId); + status_t finalizeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId); /** * Reads the specified number of bytes from an open DRM file. @@ -388,7 +405,6 @@ private: private: static Mutex mMutex; - static Vector mUniqueIdVector; static sp mDrmManagerService; static const sp& getDrmManagerService(); static const String8 EMPTY_STRING; diff --git a/drm/libdrmframework/include/DrmManagerService.h b/drm/libdrmframework/include/DrmManagerService.h index fef121c..f455e15 100644 --- a/drm/libdrmframework/include/DrmManagerService.h +++ b/drm/libdrmframework/include/DrmManagerService.h @@ -46,6 +46,10 @@ private: virtual ~DrmManagerService(); public: + int addUniqueId(int uniqueId); + + void removeUniqueId(int uniqueId); + status_t loadPlugIns(int uniqueId); status_t loadPlugIns(int uniqueId, const String8& plugInDirPath); @@ -65,7 +69,7 @@ public: DrmInfo* acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInforequest); - void saveRights(int uniqueId, const DrmRights& drmRights, + status_t saveRights(int uniqueId, const DrmRights& drmRights, const String8& rightsPath, const String8& contentPath); String8 getOriginalMimeType(int uniqueId, const String8& path); @@ -74,17 +78,17 @@ public: int checkRightsStatus(int uniqueId, const String8& path,int action); - void consumeRights(int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve); + status_t consumeRights(int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve); - void setPlaybackStatus( + status_t setPlaybackStatus( int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position); bool validateAction(int uniqueId, const String8& path, int action, const ActionDescription& description); - void removeRights(int uniqueId, const String8& path); + status_t removeRights(int uniqueId, const String8& path); - void removeAllRights(int uniqueId); + status_t removeAllRights(int uniqueId); int openConvertSession(int uniqueId, const String8& mimeType); @@ -96,15 +100,15 @@ public: DecryptHandle* openDecryptSession(int uniqueId, int fd, int offset, int length); - void closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle); + status_t closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle); - void initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, + status_t initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo); - status_t decrypt(int uniqueId, DecryptHandle* decryptHandle, - int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer); + status_t decrypt(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, + const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV); - void finalizeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId); + status_t finalizeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId); ssize_t pread(int uniqueId, DecryptHandle* decryptHandle, void* buffer, ssize_t numBytes, off_t offset); diff --git a/drm/libdrmframework/include/IDrmManagerService.h b/drm/libdrmframework/include/IDrmManagerService.h index a4d128a..5c668ed 100644 --- a/drm/libdrmframework/include/IDrmManagerService.h +++ b/drm/libdrmframework/include/IDrmManagerService.h @@ -44,7 +44,9 @@ class IDrmManagerService : public IInterface { public: enum { - LOAD_PLUGINS = IBinder::FIRST_CALL_TRANSACTION, + ADD_UNIQUEID = IBinder::FIRST_CALL_TRANSACTION, + REMOVE_UNIQUEID, + LOAD_PLUGINS, LOAD_PLUGINS_FROM_PATH, SET_DRM_SERVICE_LISTENER, UNLOAD_PLUGINS, @@ -78,6 +80,10 @@ public: DECLARE_META_INTERFACE(DrmManagerService); public: + virtual int addUniqueId(int uniqueId) = 0; + + virtual void removeUniqueId(int uniqueId) = 0; + virtual status_t loadPlugIns(int uniqueId) = 0; virtual status_t loadPlugIns(int uniqueId, const String8& plugInDirPath) = 0; @@ -98,7 +104,7 @@ public: virtual DrmInfo* acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInforequest) = 0; - virtual void saveRights(int uniqueId, const DrmRights& drmRights, + virtual status_t saveRights(int uniqueId, const DrmRights& drmRights, const String8& rightsPath, const String8& contentPath) = 0; virtual String8 getOriginalMimeType(int uniqueId, const String8& path) = 0; @@ -108,19 +114,19 @@ public: virtual int checkRightsStatus(int uniqueId, const String8& path, int action) = 0; - virtual void consumeRights( + virtual status_t consumeRights( int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) = 0; - virtual void setPlaybackStatus( + virtual status_t setPlaybackStatus( int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position) = 0; virtual bool validateAction( int uniqueId, const String8& path, int action, const ActionDescription& description) = 0; - virtual void removeRights(int uniqueId, const String8& path) = 0; + virtual status_t removeRights(int uniqueId, const String8& path) = 0; - virtual void removeAllRights(int uniqueId) = 0; + virtual status_t removeAllRights(int uniqueId) = 0; virtual int openConvertSession(int uniqueId, const String8& mimeType) = 0; @@ -134,15 +140,15 @@ public: virtual DecryptHandle* openDecryptSession(int uniqueId, int fd, int offset, int length) = 0; - virtual void closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) = 0; + virtual status_t closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) = 0; - virtual void initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, + virtual status_t initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo) = 0; - virtual status_t decrypt(int uniqueId, DecryptHandle* decryptHandle, - int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer) = 0; + virtual status_t decrypt(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, + const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) = 0; - virtual void finalizeDecryptUnit( + virtual status_t finalizeDecryptUnit( int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) = 0; virtual ssize_t pread(int uniqueId, DecryptHandle* decryptHandle, @@ -158,6 +164,10 @@ public: BpDrmManagerService(const sp& impl) : BpInterface(impl) {} + virtual int addUniqueId(int uniqueId); + + virtual void removeUniqueId(int uniqueId); + virtual status_t loadPlugIns(int uniqueId); virtual status_t loadPlugIns(int uniqueId, const String8& plugInDirPath); @@ -177,7 +187,7 @@ public: virtual DrmInfo* acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInforequest); - virtual void saveRights(int uniqueId, const DrmRights& drmRights, + virtual status_t saveRights(int uniqueId, const DrmRights& drmRights, const String8& rightsPath, const String8& contentPath); virtual String8 getOriginalMimeType(int uniqueId, const String8& path); @@ -186,18 +196,18 @@ public: virtual int checkRightsStatus(int uniqueId, const String8& path, int action); - virtual void consumeRights( + virtual status_t consumeRights( int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve); - virtual void setPlaybackStatus( + virtual status_t setPlaybackStatus( int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position); virtual bool validateAction( int uniqueId, const String8& path, int action, const ActionDescription& description); - virtual void removeRights(int uniqueId, const String8& path); + virtual status_t removeRights(int uniqueId, const String8& path); - virtual void removeAllRights(int uniqueId); + virtual status_t removeAllRights(int uniqueId); virtual int openConvertSession(int uniqueId, const String8& mimeType); @@ -211,15 +221,15 @@ public: virtual DecryptHandle* openDecryptSession(int uniqueId, int fd, int offset, int length); - virtual void closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle); + virtual status_t closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle); - virtual void initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, + virtual status_t initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo); - virtual status_t decrypt(int uniqueId, DecryptHandle* decryptHandle, - int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer); + virtual status_t decrypt(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, + const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV); - virtual void finalizeDecryptUnit( + virtual status_t finalizeDecryptUnit( int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId); virtual ssize_t pread(int uniqueId, DecryptHandle* decryptHandle, diff --git a/drm/libdrmframework/include/ReadWriteUtils.h b/drm/libdrmframework/include/ReadWriteUtils.h index 022149e..529b342 100644 --- a/drm/libdrmframework/include/ReadWriteUtils.h +++ b/drm/libdrmframework/include/ReadWriteUtils.h @@ -47,6 +47,14 @@ public: */ static String8 readBytes(const String8& filePath); /** + * Reads the data into the given buffer from the file path provided + * + * @param[in] filePath Path of the file + * @param[out] buffer Data read from the file + * @return Length of the data read from the file + */ + static int readBytes(const String8& filePath, char** buffer); + /** * Writes the data into the file path provided * * @param[in] filePath Path of the file diff --git a/drm/libdrmframework/plugins/common/include/DrmEngineBase.h b/drm/libdrmframework/plugins/common/include/DrmEngineBase.h index 667958a..b355534 100644 --- a/drm/libdrmframework/plugins/common/include/DrmEngineBase.h +++ b/drm/libdrmframework/plugins/common/include/DrmEngineBase.h @@ -46,7 +46,7 @@ public: DrmInfoStatus* processDrmInfo(int uniqueId, const DrmInfo* drmInfo); - void saveRights(int uniqueId, const DrmRights& drmRights, + status_t saveRights(int uniqueId, const DrmRights& drmRights, const String8& rightsPath, const String8& contentPath); DrmInfo* acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest); @@ -57,19 +57,19 @@ public: int checkRightsStatus(int uniqueId, const String8& path, int action); - void consumeRights(int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve); + status_t consumeRights(int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve); - void setPlaybackStatus( + status_t setPlaybackStatus( int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position); bool validateAction( int uniqueId, const String8& path, int action, const ActionDescription& description); - void removeRights(int uniqueId, const String8& path); + status_t removeRights(int uniqueId, const String8& path); - void removeAllRights(int uniqueId); + status_t removeAllRights(int uniqueId); - void openConvertSession(int uniqueId, int convertId); + status_t openConvertSession(int uniqueId, int convertId); DrmConvertedStatus* convertData(int uniqueId, int convertId, const DrmBuffer* inputData); @@ -80,15 +80,15 @@ public: status_t openDecryptSession( int uniqueId, DecryptHandle* decryptHandle, int fd, int offset, int length); - void closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle); + status_t closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle); - void initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, + status_t initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo); - status_t decrypt(int uniqueId, DecryptHandle* decryptHandle, - int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer); + status_t decrypt(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, + const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV); - void finalizeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId); + status_t finalizeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId); ssize_t pread(int uniqueId, DecryptHandle* decryptHandle, void* buffer, ssize_t numBytes, off_t offset); @@ -172,8 +172,10 @@ protected: * @param[in] drmRights DrmRights to be saved * @param[in] rightsPath File path where rights to be saved * @param[in] contentPath File path where content was saved + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure */ - virtual void onSaveRights(int uniqueId, const DrmRights& drmRights, + virtual status_t onSaveRights(int uniqueId, const DrmRights& drmRights, const String8& rightspath, const String8& contentPath) = 0; /** @@ -231,8 +233,10 @@ protected: * @param[in] decryptHandle Handle for the decryption session * @param[in] action Action to perform. (Action::DEFAULT, Action::PLAY, etc) * @param[in] reserve True if the rights should be reserved. + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure */ - virtual void onConsumeRights(int uniqueId, DecryptHandle* decryptHandle, + virtual status_t onConsumeRights(int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) = 0; /** @@ -243,8 +247,10 @@ protected: * @param[in] playbackStatus Playback action (Playback::START, Playback::STOP, Playback::PAUSE) * @param[in] position Position in the file (in milliseconds) where the start occurs. * Only valid together with Playback::START. + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure */ - virtual void onSetPlaybackStatus( + virtual status_t onSetPlaybackStatus( int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position) = 0; /** @@ -264,16 +270,20 @@ protected: * * @param[in] uniqueId Unique identifier for a session * @param[in] path Path of the protected content + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure */ - virtual void onRemoveRights(int uniqueId, const String8& path) = 0; + virtual status_t onRemoveRights(int uniqueId, const String8& path) = 0; /** * Removes all the rights information of each plug-in associated with * DRM framework. Will be used in master reset * * @param[in] uniqueId Unique identifier for a session + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure */ - virtual void onRemoveAllRights(int uniqueId) = 0; + virtual status_t onRemoveAllRights(int uniqueId) = 0; /** * This API is for Forward Lock based DRM scheme. @@ -283,8 +293,10 @@ protected: * * @param[in] uniqueId Unique identifier for a session * @param[in] convertId Handle for the convert session + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure */ - virtual void onOpenConvertSession(int uniqueId, int convertId) = 0; + virtual status_t onOpenConvertSession(int uniqueId, int convertId) = 0; /** * Accepts and converts the input data which is part of DRM file. @@ -347,8 +359,10 @@ protected: * * @param[in] uniqueId Unique identifier for a session * @param[in] decryptHandle Handle for the decryption session + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure */ - virtual void onCloseDecryptSession(int uniqueId, DecryptHandle* decryptHandle) = 0; + virtual status_t onCloseDecryptSession(int uniqueId, DecryptHandle* decryptHandle) = 0; /** * Initialize decryption for the given unit of the protected content @@ -357,8 +371,10 @@ protected: * @param[in] decryptId Handle for the decryption session * @param[in] decryptUnitId ID Specifies decryption unit, such as track ID * @param[in] headerInfo Information for initializing decryption of this decrypUnit + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure */ - virtual void onInitializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, + virtual status_t onInitializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo) = 0; /** @@ -371,14 +387,15 @@ protected: * @param[in] decryptUnitId ID Specifies decryption unit, such as track ID * @param[in] encBuffer Encrypted data block * @param[out] decBuffer Decrypted data block + * @param[in] IV Optional buffer * @return status_t * Returns the error code for this API * DRM_NO_ERROR for success, and one of DRM_ERROR_UNKNOWN, DRM_ERROR_LICENSE_EXPIRED * DRM_ERROR_SESSION_NOT_OPENED, DRM_ERROR_DECRYPT_UNIT_NOT_INITIALIZED, * DRM_ERROR_DECRYPT for failure. */ - virtual status_t onDecrypt(int uniqueId, DecryptHandle* decryptHandle, - int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer) = 0; + virtual status_t onDecrypt(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, + const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) = 0; /** * Finalize decryption for the given unit of the protected content @@ -386,8 +403,10 @@ protected: * @param[in] uniqueId Unique identifier for a session * @param[in] decryptHandle Handle for the decryption session * @param[in] decryptUnitId ID Specifies decryption unit, such as track ID + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure */ - virtual void onFinalizeDecryptUnit( + virtual status_t onFinalizeDecryptUnit( int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) = 0; /** diff --git a/drm/libdrmframework/plugins/common/include/IDrmEngine.h b/drm/libdrmframework/plugins/common/include/IDrmEngine.h index 0d52f66..b711500 100644 --- a/drm/libdrmframework/plugins/common/include/IDrmEngine.h +++ b/drm/libdrmframework/plugins/common/include/IDrmEngine.h @@ -143,8 +143,10 @@ public: * @param[in] drmRights DrmRights to be saved * @param[in] rightsPath File path where rights to be saved * @param[in] contentPath File path where content was saved + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure */ - virtual void saveRights(int uniqueId, const DrmRights& drmRights, + virtual status_t saveRights(int uniqueId, const DrmRights& drmRights, const String8& rightsPath, const String8& contentPath) = 0; /** @@ -191,8 +193,10 @@ public: * @param[in] decryptHandle Handle for the decryption session * @param[in] action Action to perform. (Action::DEFAULT, Action::PLAY, etc) * @param[in] reserve True if the rights should be reserved. + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure */ - virtual void consumeRights( + virtual status_t consumeRights( int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) = 0; /** @@ -203,8 +207,10 @@ public: * @param[in] playbackStatus Playback action (Playback::START, Playback::STOP, Playback::PAUSE) * @param[in] position Position in the file (in milliseconds) where the start occurs. * Only valid together with Playback::START. + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure */ - virtual void setPlaybackStatus(int uniqueId, DecryptHandle* decryptHandle, + virtual status_t setPlaybackStatus(int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position) = 0; /** @@ -224,16 +230,20 @@ public: * * @param[in] uniqueId Unique identifier for a session * @param[in] path Path of the protected content + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure */ - virtual void removeRights(int uniqueId, const String8& path) = 0; + virtual status_t removeRights(int uniqueId, const String8& path) = 0; /** * Removes all the rights information of each plug-in associated with * DRM framework. Will be used in master reset * * @param[in] uniqueId Unique identifier for a session + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure */ - virtual void removeAllRights(int uniqueId) = 0; + virtual status_t removeAllRights(int uniqueId) = 0; /** * This API is for Forward Lock based DRM scheme. @@ -243,8 +253,10 @@ public: * * @param[in] uniqueId Unique identifier for a session * @param[in] convertId Handle for the convert session + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure */ - virtual void openConvertSession(int uniqueId, int convertId) = 0; + virtual status_t openConvertSession(int uniqueId, int convertId) = 0; /** * Accepts and converts the input data which is part of DRM file. @@ -307,8 +319,10 @@ public: * * @param[in] uniqueId Unique identifier for a session * @param[in] decryptHandle Handle for the decryption session + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure */ - virtual void closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) = 0; + virtual status_t closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) = 0; /** * Initialize decryption for the given unit of the protected content @@ -317,8 +331,10 @@ public: * @param[in] decryptHandle Handle for the decryption session * @param[in] decryptUnitId ID which specifies decryption unit, such as track ID * @param[in] headerInfo Information for initializing decryption of this decrypUnit + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure */ - virtual void initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, + virtual status_t initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo) = 0; /** @@ -331,14 +347,15 @@ public: * @param[in] decryptUnitId ID which specifies decryption unit, such as track ID * @param[in] encBuffer Encrypted data block * @param[out] decBuffer Decrypted data block + * @param[in] IV Optional buffer * @return status_t * Returns the error code for this API * DRM_NO_ERROR for success, and one of DRM_ERROR_UNKNOWN, DRM_ERROR_LICENSE_EXPIRED * DRM_ERROR_SESSION_NOT_OPENED, DRM_ERROR_DECRYPT_UNIT_NOT_INITIALIZED, * DRM_ERROR_DECRYPT for failure. */ - virtual status_t decrypt(int uniqueId, DecryptHandle* decryptHandle, - int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer) = 0; + virtual status_t decrypt(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, + const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) = 0; /** * Finalize decryption for the given unit of the protected content @@ -346,8 +363,10 @@ public: * @param[in] uniqueId Unique identifier for a session * @param[in] decryptHandle Handle for the decryption session * @param[in] decryptUnitId ID which specifies decryption unit, such as track ID + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure */ - virtual void finalizeDecryptUnit( + virtual status_t finalizeDecryptUnit( int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) = 0; /** diff --git a/drm/libdrmframework/plugins/passthru/include/DrmPassthruPlugIn.h b/drm/libdrmframework/plugins/passthru/include/DrmPassthruPlugIn.h index d2c7852..eed1628 100644 --- a/drm/libdrmframework/plugins/passthru/include/DrmPassthruPlugIn.h +++ b/drm/libdrmframework/plugins/passthru/include/DrmPassthruPlugIn.h @@ -40,7 +40,7 @@ protected: DrmInfoStatus* onProcessDrmInfo(int uniqueId, const DrmInfo* drmInfo); - void onSaveRights(int uniqueId, const DrmRights& drmRights, + status_t onSaveRights(int uniqueId, const DrmRights& drmRights, const String8& rightsPath, const String8& contentPath); DrmInfo* onAcquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest); @@ -51,19 +51,19 @@ protected: int onCheckRightsStatus(int uniqueId, const String8& path, int action); - void onConsumeRights(int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve); + status_t onConsumeRights(int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve); - void onSetPlaybackStatus( + status_t onSetPlaybackStatus( int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position); bool onValidateAction( int uniqueId, const String8& path, int action, const ActionDescription& description); - void onRemoveRights(int uniqueId, const String8& path); + status_t onRemoveRights(int uniqueId, const String8& path); - void onRemoveAllRights(int uniqueId); + status_t onRemoveAllRights(int uniqueId); - void onOpenConvertSession(int uniqueId, int convertId); + status_t onOpenConvertSession(int uniqueId, int convertId); DrmConvertedStatus* onConvertData(int uniqueId, int convertId, const DrmBuffer* inputData); @@ -74,15 +74,15 @@ protected: status_t onOpenDecryptSession( int uniqueId, DecryptHandle* decryptHandle, int fd, int offset, int length); - void onCloseDecryptSession(int uniqueId, DecryptHandle* decryptHandle); + status_t onCloseDecryptSession(int uniqueId, DecryptHandle* decryptHandle); - void onInitializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, + status_t onInitializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo); - status_t onDecrypt(int uniqueId, DecryptHandle* decryptHandle, - int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer); + status_t onDecrypt(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, + const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV); - void onFinalizeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId); + status_t onFinalizeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId); ssize_t onPread(int uniqueId, DecryptHandle* decryptHandle, void* buffer, ssize_t numBytes, off_t offset); diff --git a/drm/libdrmframework/plugins/passthru/src/DrmPassthruPlugIn.cpp b/drm/libdrmframework/plugins/passthru/src/DrmPassthruPlugIn.cpp index 2655d0b..4c7714d 100644 --- a/drm/libdrmframework/plugins/passthru/src/DrmPassthruPlugIn.cpp +++ b/drm/libdrmframework/plugins/passthru/src/DrmPassthruPlugIn.cpp @@ -129,9 +129,10 @@ DrmSupportInfo* DrmPassthruPlugIn::onGetSupportInfo(int uniqueId) { return drmSupportInfo; } -void DrmPassthruPlugIn::onSaveRights(int uniqueId, const DrmRights& drmRights, +status_t DrmPassthruPlugIn::onSaveRights(int uniqueId, const DrmRights& drmRights, const String8& rightsPath, const String8& contentPath) { LOGD("DrmPassthruPlugIn::onSaveRights : %d", uniqueId); + return DRM_NO_ERROR; } DrmInfo* DrmPassthruPlugIn::onAcquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest) { @@ -174,14 +175,16 @@ int DrmPassthruPlugIn::onCheckRightsStatus(int uniqueId, const String8& path, in return rightsStatus; } -void DrmPassthruPlugIn::onConsumeRights(int uniqueId, DecryptHandle* decryptHandle, +status_t DrmPassthruPlugIn::onConsumeRights(int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) { LOGD("DrmPassthruPlugIn::onConsumeRights() : %d", uniqueId); + return DRM_NO_ERROR; } -void DrmPassthruPlugIn::onSetPlaybackStatus(int uniqueId, DecryptHandle* decryptHandle, +status_t DrmPassthruPlugIn::onSetPlaybackStatus(int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position) { LOGD("DrmPassthruPlugIn::onSetPlaybackStatus() : %d", uniqueId); + return DRM_NO_ERROR; } bool DrmPassthruPlugIn::onValidateAction(int uniqueId, const String8& path, @@ -190,16 +193,19 @@ bool DrmPassthruPlugIn::onValidateAction(int uniqueId, const String8& path, return true; } -void DrmPassthruPlugIn::onRemoveRights(int uniqueId, const String8& path) { +status_t DrmPassthruPlugIn::onRemoveRights(int uniqueId, const String8& path) { LOGD("DrmPassthruPlugIn::onRemoveRights() : %d", uniqueId); + return DRM_NO_ERROR; } -void DrmPassthruPlugIn::onRemoveAllRights(int uniqueId) { +status_t DrmPassthruPlugIn::onRemoveAllRights(int uniqueId) { LOGD("DrmPassthruPlugIn::onRemoveAllRights() : %d", uniqueId); + return DRM_NO_ERROR; } -void DrmPassthruPlugIn::onOpenConvertSession(int uniqueId, int convertId) { +status_t DrmPassthruPlugIn::onOpenConvertSession(int uniqueId, int convertId) { LOGD("DrmPassthruPlugIn::onOpenConvertSession() : %d", uniqueId); + return DRM_NO_ERROR; } DrmConvertedStatus* DrmPassthruPlugIn::onConvertData( @@ -237,7 +243,7 @@ status_t DrmPassthruPlugIn::onOpenDecryptSession( return DRM_ERROR_CANNOT_HANDLE; } -void DrmPassthruPlugIn::onCloseDecryptSession(int uniqueId, DecryptHandle* decryptHandle) { +status_t DrmPassthruPlugIn::onCloseDecryptSession(int uniqueId, DecryptHandle* decryptHandle) { LOGD("DrmPassthruPlugIn::onCloseDecryptSession() : %d", uniqueId); if (NULL != decryptHandle) { if (NULL != decryptHandle->decryptInfo) { @@ -245,15 +251,17 @@ void DrmPassthruPlugIn::onCloseDecryptSession(int uniqueId, DecryptHandle* decry } delete decryptHandle; decryptHandle = NULL; } + return DRM_NO_ERROR; } -void DrmPassthruPlugIn::onInitializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, +status_t DrmPassthruPlugIn::onInitializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo) { LOGD("DrmPassthruPlugIn::onInitializeDecryptUnit() : %d", uniqueId); + return DRM_NO_ERROR; } status_t DrmPassthruPlugIn::onDecrypt(int uniqueId, DecryptHandle* decryptHandle, - int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer) { + int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) { LOGD("DrmPassthruPlugIn::onDecrypt() : %d", uniqueId); /** * As a workaround implementation passthru would copy the given @@ -267,9 +275,10 @@ status_t DrmPassthruPlugIn::onDecrypt(int uniqueId, DecryptHandle* decryptHandle return DRM_NO_ERROR; } -void DrmPassthruPlugIn::onFinalizeDecryptUnit( +status_t DrmPassthruPlugIn::onFinalizeDecryptUnit( int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) { LOGD("DrmPassthruPlugIn::onFinalizeDecryptUnit() : %d", uniqueId); + return DRM_NO_ERROR; } ssize_t DrmPassthruPlugIn::onPread(int uniqueId, DecryptHandle* decryptHandle, -- 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') 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 6dc55e7067d2baaf92970bd03412df98bf7f88c8 Mon Sep 17 00:00:00 2001 From: Gloria Wang Date: Fri, 29 Oct 2010 16:44:37 -0700 Subject: Add support for WV plugin Change-Id: I0b9d0488f123c05ad2d94315236458f479e00b78 --- drm/libdrmframework/plugins/widevine/Android.mk | 27 +++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 drm/libdrmframework/plugins/widevine/Android.mk (limited to 'drm') diff --git a/drm/libdrmframework/plugins/widevine/Android.mk b/drm/libdrmframework/plugins/widevine/Android.mk new file mode 100644 index 0000000..2c388da --- /dev/null +++ b/drm/libdrmframework/plugins/widevine/Android.mk @@ -0,0 +1,27 @@ +# +# 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_MODULE := libdrmwvmplugin + +LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/drm/plugins/native + +LOCAL_PRELINK_MODULE := false + +LOCAL_MODULE_TAGS := optional + +include $(BUILD_SHARED_LIBRARY) -- 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/common/DrmEngineBase.cpp | 5 + drm/common/DrmInfoStatus.cpp | 3 +- drm/common/IDrmManagerService.cpp | 119 ++++++++++++--------- drm/drmserver/DrmManager.cpp | 108 +++++++++++-------- drm/drmserver/DrmManagerService.cpp | 46 +++----- drm/libdrmframework/DrmManagerClient.cpp | 32 +++--- drm/libdrmframework/DrmManagerClientImpl.cpp | 32 +++--- drm/libdrmframework/include/DrmManager.h | 18 ++-- drm/libdrmframework/include/DrmManagerClientImpl.h | 40 +++---- drm/libdrmframework/include/DrmManagerService.h | 8 +- drm/libdrmframework/include/IDrmManagerService.h | 22 ++-- .../plugins/common/include/DrmEngineBase.h | 15 +++ .../plugins/common/include/IDrmEngine.h | 12 +++ .../plugins/passthru/include/DrmPassthruPlugIn.h | 3 + .../plugins/passthru/src/DrmPassthruPlugIn.cpp | 17 +-- 15 files changed, 260 insertions(+), 220 deletions(-) (limited to 'drm') diff --git a/drm/common/DrmEngineBase.cpp b/drm/common/DrmEngineBase.cpp index 17cdf54..10c64ee 100644 --- a/drm/common/DrmEngineBase.cpp +++ b/drm/common/DrmEngineBase.cpp @@ -120,6 +120,11 @@ status_t DrmEngineBase::openDecryptSession( return onOpenDecryptSession(uniqueId, decryptHandle, fd, offset, length); } +status_t DrmEngineBase::openDecryptSession( + int uniqueId, DecryptHandle* decryptHandle, const char* uri) { + return onOpenDecryptSession(uniqueId, decryptHandle, uri); +} + status_t DrmEngineBase::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) { return onCloseDecryptSession(uniqueId, decryptHandle); } diff --git a/drm/common/DrmInfoStatus.cpp b/drm/common/DrmInfoStatus.cpp index f3a1516..8ec7311 100644 --- a/drm/common/DrmInfoStatus.cpp +++ b/drm/common/DrmInfoStatus.cpp @@ -19,8 +19,9 @@ using namespace android; DrmInfoStatus::DrmInfoStatus( - int _statusCode, const DrmBuffer* _drmBuffer, const String8& _mimeType) : + int _statusCode, int _infoType, const DrmBuffer* _drmBuffer, const String8& _mimeType) : statusCode(_statusCode), + infoType(_infoType), drmBuffer(_drmBuffer), mimeType(_mimeType) { diff --git a/drm/common/IDrmManagerService.cpp b/drm/common/IDrmManagerService.cpp index c28527c..b8ae852 100644 --- a/drm/common/IDrmManagerService.cpp +++ b/drm/common/IDrmManagerService.cpp @@ -53,27 +53,18 @@ void BpDrmManagerService::removeUniqueId(int uniqueId) { remote()->transact(REMOVE_UNIQUEID, data, &reply); } -status_t BpDrmManagerService::loadPlugIns(int uniqueId) { - LOGV("load plugins"); +void BpDrmManagerService::addClient(int uniqueId) { Parcel data, reply; - data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); data.writeInt32(uniqueId); - - remote()->transact(LOAD_PLUGINS, data, &reply); - return reply.readInt32(); + remote()->transact(ADD_CLIENT, data, &reply); } -status_t BpDrmManagerService::loadPlugIns(int uniqueId, const String8& plugInDirPath) { - LOGV("load plugins from path"); +void BpDrmManagerService::removeClient(int uniqueId) { Parcel data, reply; - data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); data.writeInt32(uniqueId); - data.writeString8(plugInDirPath); - - remote()->transact(LOAD_PLUGINS_FROM_PATH, data, &reply); - return reply.readInt32(); + remote()->transact(REMOVE_CLIENT, data, &reply); } status_t BpDrmManagerService::setDrmServiceListener( @@ -88,17 +79,6 @@ status_t BpDrmManagerService::setDrmServiceListener( return reply.readInt32(); } -status_t BpDrmManagerService::unloadPlugIns(int uniqueId) { - LOGV("unload plugins"); - Parcel data, reply; - - data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); - data.writeInt32(uniqueId); - - remote()->transact(UNLOAD_PLUGINS, data, &reply); - return reply.readInt32(); -} - status_t BpDrmManagerService::installDrmEngine(int uniqueId, const String8& drmEngineFile) { LOGV("Install DRM Engine"); Parcel data, reply; @@ -191,6 +171,7 @@ DrmInfoStatus* BpDrmManagerService::processDrmInfo(int uniqueId, const DrmInfo* if (0 != reply.dataAvail()) { //Filling DRM Info Status const int statusCode = reply.readInt32(); + const int infoType = reply.readInt32(); const String8 mimeType = reply.readString8(); DrmBuffer* drmBuffer = NULL; @@ -203,7 +184,7 @@ DrmInfoStatus* BpDrmManagerService::processDrmInfo(int uniqueId, const DrmInfo* } drmBuffer = new DrmBuffer(data, bufferSize); } - drmInfoStatus = new DrmInfoStatus(statusCode, drmBuffer, mimeType); + drmInfoStatus = new DrmInfoStatus(statusCode, infoType, drmBuffer, mimeType); } return drmInfoStatus; } @@ -538,8 +519,7 @@ DecryptHandle* BpDrmManagerService::openDecryptSession( LOGV("Entering BpDrmManagerService::openDecryptSession"); Parcel data, reply; - const String16 interfaceDescriptor = IDrmManagerService::getInterfaceDescriptor(); - data.writeInterfaceToken(interfaceDescriptor); + data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); data.writeInt32(uniqueId); data.writeFileDescriptor(fd); data.writeInt32(offset); @@ -565,6 +545,34 @@ DecryptHandle* BpDrmManagerService::openDecryptSession( return handle; } +DecryptHandle* BpDrmManagerService::openDecryptSession(int uniqueId, const char* uri) { + LOGV("Entering BpDrmManagerService::openDecryptSession"); + Parcel data, reply; + + data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); + data.writeInt32(uniqueId); + data.writeString8(String8(uri)); + + remote()->transact(OPEN_DECRYPT_SESSION_FROM_URI, data, &reply); + + DecryptHandle* handle = NULL; + if (0 != reply.dataAvail()) { + handle = new DecryptHandle(); + handle->decryptId = reply.readInt32(); + handle->mimeType = reply.readString8(); + handle->decryptApiType = reply.readInt32(); + handle->status = reply.readInt32(); + handle->decryptInfo = NULL; + if (0 != reply.dataAvail()) { + handle->decryptInfo = new DecryptInfo(); + handle->decryptInfo->decryptBufferLength = reply.readInt32(); + } + } else { + LOGE("no decryptHandle is generated in service side"); + } + return handle; +} + status_t BpDrmManagerService::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) { LOGV("closeDecryptSession"); Parcel data, reply; @@ -746,25 +754,19 @@ status_t BnDrmManagerService::onTransact( return DRM_NO_ERROR; } - case LOAD_PLUGINS: + case ADD_CLIENT: { - LOGV("BnDrmManagerService::onTransact :LOAD_PLUGINS"); + LOGV("BnDrmManagerService::onTransact :ADD_CLIENT"); CHECK_INTERFACE(IDrmManagerService, data, reply); - - status_t status = loadPlugIns(data.readInt32()); - - reply->writeInt32(status); + addClient(data.readInt32()); return DRM_NO_ERROR; } - case LOAD_PLUGINS_FROM_PATH: + case REMOVE_CLIENT: { - LOGV("BnDrmManagerService::onTransact :LOAD_PLUGINS_FROM_PATH"); + LOGV("BnDrmManagerService::onTransact :REMOVE_CLIENT"); CHECK_INTERFACE(IDrmManagerService, data, reply); - - status_t status = loadPlugIns(data.readInt32(), data.readString8()); - - reply->writeInt32(status); + removeClient(data.readInt32()); return DRM_NO_ERROR; } @@ -783,18 +785,6 @@ status_t BnDrmManagerService::onTransact( return DRM_NO_ERROR; } - case UNLOAD_PLUGINS: - { - LOGV("BnDrmManagerService::onTransact :UNLOAD_PLUGINS"); - CHECK_INTERFACE(IDrmManagerService, data, reply); - - const int uniqueId = data.readInt32(); - status_t status = unloadPlugIns(uniqueId); - - reply->writeInt32(status); - return DRM_NO_ERROR; - } - case INSTALL_DRM_ENGINE: { LOGV("BnDrmManagerService::onTransact :INSTALL_DRM_ENGINE"); @@ -881,6 +871,7 @@ status_t BnDrmManagerService::onTransact( if (NULL != drmInfoStatus) { //Filling DRM Info Status contents reply->writeInt32(drmInfoStatus->statusCode); + reply->writeInt32(drmInfoStatus->infoType); reply->writeString8(drmInfoStatus->mimeType); if (NULL != drmInfoStatus->drmBuffer) { @@ -1239,6 +1230,32 @@ status_t BnDrmManagerService::onTransact( return DRM_NO_ERROR; } + case OPEN_DECRYPT_SESSION_FROM_URI: + { + LOGV("BnDrmManagerService::onTransact :OPEN_DECRYPT_SESSION_FROM_URI"); + CHECK_INTERFACE(IDrmManagerService, data, reply); + + const int uniqueId = data.readInt32(); + const String8 uri = data.readString8(); + + DecryptHandle* handle = openDecryptSession(uniqueId, uri.string()); + + if (NULL != handle) { + reply->writeInt32(handle->decryptId); + reply->writeString8(handle->mimeType); + reply->writeInt32(handle->decryptApiType); + reply->writeInt32(handle->status); + if (NULL != handle->decryptInfo) { + reply->writeInt32(handle->decryptInfo->decryptBufferLength); + delete handle->decryptInfo; handle->decryptInfo = NULL; + } + } else { + LOGE("NULL decryptHandle is returned"); + } + delete handle; handle = NULL; + return DRM_NO_ERROR; + } + case CLOSE_DECRYPT_SESSION: { LOGV("BnDrmManagerService::onTransact :CLOSE_DECRYPT_SESSION"); 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); diff --git a/drm/libdrmframework/DrmManagerClient.cpp b/drm/libdrmframework/DrmManagerClient.cpp index c996994..f0439eb 100644 --- a/drm/libdrmframework/DrmManagerClient.cpp +++ b/drm/libdrmframework/DrmManagerClient.cpp @@ -22,36 +22,23 @@ using namespace android; -DrmManagerClient::DrmManagerClient() { - int uniqueId = 0; - mDrmManagerClientImpl = NULL; - - mDrmManagerClientImpl = DrmManagerClientImpl::create(&uniqueId); - mUniqueId = uniqueId; - - loadPlugIns(); +DrmManagerClient::DrmManagerClient(): + mUniqueId(0), mDrmManagerClientImpl(NULL) { + mDrmManagerClientImpl = DrmManagerClientImpl::create(&mUniqueId); + mDrmManagerClientImpl->addClient(mUniqueId); } DrmManagerClient::~DrmManagerClient() { DrmManagerClientImpl::remove(mUniqueId); - unloadPlugIns(); - + mDrmManagerClientImpl->removeClient(mUniqueId); delete mDrmManagerClientImpl; mDrmManagerClientImpl = NULL; } -status_t DrmManagerClient::loadPlugIns() { - return mDrmManagerClientImpl->loadPlugIns(mUniqueId); -} - status_t DrmManagerClient::setOnInfoListener( const sp& infoListener) { return mDrmManagerClientImpl->setOnInfoListener(mUniqueId, infoListener); } -status_t DrmManagerClient::unloadPlugIns() { - return mDrmManagerClientImpl->unloadPlugIns(mUniqueId); -} - DrmConstraints* DrmManagerClient::getConstraints(const String8* path, const int action) { return mDrmManagerClientImpl->getConstraints(mUniqueId, path, action); } @@ -86,6 +73,7 @@ int DrmManagerClient::checkRightsStatus(const String8& path, int action) { } status_t DrmManagerClient::consumeRights(DecryptHandle* decryptHandle, int action, bool reserve) { + Mutex::Autolock _l(mDecryptLock); return mDrmManagerClientImpl->consumeRights(mUniqueId, decryptHandle, action, reserve); } @@ -128,12 +116,17 @@ DecryptHandle* DrmManagerClient::openDecryptSession(int fd, int offset, int leng return mDrmManagerClientImpl->openDecryptSession(mUniqueId, fd, offset, length); } +DecryptHandle* DrmManagerClient::openDecryptSession(const char* uri) { + return mDrmManagerClientImpl->openDecryptSession(mUniqueId, uri); +} + status_t DrmManagerClient::closeDecryptSession(DecryptHandle* decryptHandle) { return mDrmManagerClientImpl->closeDecryptSession(mUniqueId, decryptHandle); } status_t DrmManagerClient::initializeDecryptUnit( DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo) { + Mutex::Autolock _l(mDecryptLock); return mDrmManagerClientImpl->initializeDecryptUnit( mUniqueId, decryptHandle, decryptUnitId, headerInfo); } @@ -141,16 +134,19 @@ status_t DrmManagerClient::initializeDecryptUnit( status_t DrmManagerClient::decrypt( DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) { + Mutex::Autolock _l(mDecryptLock); return mDrmManagerClientImpl->decrypt( mUniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer, IV); } status_t DrmManagerClient::finalizeDecryptUnit(DecryptHandle* decryptHandle, int decryptUnitId) { + Mutex::Autolock _l(mDecryptLock); return mDrmManagerClientImpl->finalizeDecryptUnit(mUniqueId, decryptHandle, decryptUnitId); } ssize_t DrmManagerClient::pread( DecryptHandle* decryptHandle, void* buffer, ssize_t numBytes, off_t offset) { + Mutex::Autolock _l(mDecryptLock); return mDrmManagerClientImpl->pread(mUniqueId, decryptHandle, buffer, numBytes, offset); } diff --git a/drm/libdrmframework/DrmManagerClientImpl.cpp b/drm/libdrmframework/DrmManagerClientImpl.cpp index 272adcd..b3ae9a7 100644 --- a/drm/libdrmframework/DrmManagerClientImpl.cpp +++ b/drm/libdrmframework/DrmManagerClientImpl.cpp @@ -46,14 +46,6 @@ void DrmManagerClientImpl::remove(int uniqueId) { getDrmManagerService()->removeUniqueId(uniqueId); } -DrmManagerClientImpl::DrmManagerClientImpl() { - -} - -DrmManagerClientImpl::~DrmManagerClientImpl() { - -} - const sp& DrmManagerClientImpl::getDrmManagerService() { mMutex.lock(); if (NULL == mDrmManagerService.get()) { @@ -77,16 +69,12 @@ const sp& DrmManagerClientImpl::getDrmManagerService() { return mDrmManagerService; } -status_t DrmManagerClientImpl::loadPlugIns(int uniqueId) { - return getDrmManagerService()->loadPlugIns(uniqueId); +void DrmManagerClientImpl::addClient(int uniqueId) { + getDrmManagerService()->addClient(uniqueId); } -status_t DrmManagerClientImpl::loadPlugIns(int uniqueId, const String8& plugInDirPath) { - status_t status = DRM_ERROR_UNKNOWN; - if (EMPTY_STRING != plugInDirPath) { - status = getDrmManagerService()->loadPlugIns(uniqueId, plugInDirPath); - } - return status; +void DrmManagerClientImpl::removeClient(int uniqueId) { + getDrmManagerService()->removeClient(uniqueId); } status_t DrmManagerClientImpl::setOnInfoListener( @@ -96,10 +84,6 @@ status_t DrmManagerClientImpl::setOnInfoListener( return getDrmManagerService()->setDrmServiceListener(uniqueId, this); } -status_t DrmManagerClientImpl::unloadPlugIns(int uniqueId) { - return getDrmManagerService()->unloadPlugIns(uniqueId); -} - status_t DrmManagerClientImpl::installDrmEngine(int uniqueId, const String8& drmEngineFile) { status_t status = DRM_ERROR_UNKNOWN; if (EMPTY_STRING != drmEngineFile) { @@ -251,6 +235,14 @@ DecryptHandle* DrmManagerClientImpl::openDecryptSession( return getDrmManagerService()->openDecryptSession(uniqueId, fd, offset, length); } +DecryptHandle* DrmManagerClientImpl::openDecryptSession(int uniqueId, const char* uri) { + DecryptHandle* handle = NULL; + if (NULL != uri) { + handle = getDrmManagerService()->openDecryptSession(uniqueId, uri); + } + return handle; +} + status_t DrmManagerClientImpl::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) { status_t status = DRM_ERROR_UNKNOWN; if (NULL != decryptHandle) { diff --git a/drm/libdrmframework/include/DrmManager.h b/drm/libdrmframework/include/DrmManager.h index dc3e460..d782f5b 100644 --- a/drm/libdrmframework/include/DrmManager.h +++ b/drm/libdrmframework/include/DrmManager.h @@ -57,15 +57,19 @@ public: void removeUniqueId(int uniqueId); - status_t loadPlugIns(int uniqueId); + void addClient(int uniqueId); - status_t loadPlugIns(int uniqueId, const String8& plugInDirPath); + void removeClient(int uniqueId); + + status_t loadPlugIns(); + + status_t loadPlugIns(const String8& plugInDirPath); + + status_t unloadPlugIns(); status_t setDrmServiceListener( int uniqueId, const sp& drmServiceListener); - status_t unloadPlugIns(int uniqueId); - status_t installDrmEngine(int uniqueId, const String8& drmEngineFile); DrmConstraints* getConstraints(int uniqueId, const String8* path, const int action); @@ -107,6 +111,8 @@ public: DecryptHandle* openDecryptSession(int uniqueId, int fd, int offset, int length); + DecryptHandle* openDecryptSession(int uniqueId, const char* uri); + status_t closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle); status_t initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, @@ -129,12 +135,8 @@ private: String8 getSupportedPlugInIdFromPath(int uniqueId, const String8& path); - void populate(int uniqueId); - bool canHandle(int uniqueId, const String8& path); - void initializePlugIns(int uniqueId); - private: static Vector mUniqueIdVector; static const String8 EMPTY_STRING; diff --git a/drm/libdrmframework/include/DrmManagerClientImpl.h b/drm/libdrmframework/include/DrmManagerClientImpl.h index 492c7f5..1c6be46 100644 --- a/drm/libdrmframework/include/DrmManagerClientImpl.h +++ b/drm/libdrmframework/include/DrmManagerClientImpl.h @@ -35,36 +35,29 @@ class DrmInfoEvent; */ class DrmManagerClientImpl : public BnDrmServiceListener { private: - DrmManagerClientImpl(); + DrmManagerClientImpl() { } public: static DrmManagerClientImpl* create(int* pUniqueId); static void remove(int uniqueId); - virtual ~DrmManagerClientImpl(); + virtual ~DrmManagerClientImpl() { } public: /** - * Initialize DRM Manager - * load available plug-ins from default plugInDirPath + * Adds the client respective to given unique id. * * @param[in] uniqueId Unique identifier for a session - * @return status_t - * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure */ - status_t loadPlugIns(int uniqueId); + void addClient(int uniqueId); /** - * Finalize DRM Manager - * release resources associated with each plug-in - * unload all plug-ins and etc. + * Removes the client respective to given unique id. * * @param[in] uniqueId Unique identifier for a session - * @return status_t - * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure */ - status_t unloadPlugIns(int uniqueId); + void removeClient(int uniqueId); /** * Register a callback to be invoked when the caller required to @@ -301,6 +294,16 @@ public: DecryptHandle* openDecryptSession(int uniqueId, int fd, int offset, int length); /** + * Open the decrypt session to decrypt the given protected content + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] uri Path of the protected content to be decrypted + * @return + * Handle for the decryption session + */ + DecryptHandle* openDecryptSession(int uniqueId, const char* uri); + + /** * Close the decrypt session for the given handle * * @param[in] uniqueId Unique identifier for a session @@ -379,17 +382,6 @@ public: private: /** - * Initialize DRM Manager - * load available plug-ins from plugInDirPath - * - * @param[in] uniqueId Unique identifier for a session - * @param[in] plugInDirPath Directory from where to load plug-ins - * @return status_t - * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure - */ - status_t loadPlugIns(int uniqueId, const String8& plugInDirPath); - - /** * Install new DRM Engine Plug-in at the runtime * * @param[in] uniqueId Unique identifier for a session diff --git a/drm/libdrmframework/include/DrmManagerService.h b/drm/libdrmframework/include/DrmManagerService.h index f455e15..4a3aeae 100644 --- a/drm/libdrmframework/include/DrmManagerService.h +++ b/drm/libdrmframework/include/DrmManagerService.h @@ -50,15 +50,13 @@ public: void removeUniqueId(int uniqueId); - status_t loadPlugIns(int uniqueId); + void addClient(int uniqueId); - status_t loadPlugIns(int uniqueId, const String8& plugInDirPath); + void removeClient(int uniqueId); status_t setDrmServiceListener( int uniqueId, const sp& drmServiceListener); - status_t unloadPlugIns(int uniqueId); - status_t installDrmEngine(int uniqueId, const String8& drmEngineFile); DrmConstraints* getConstraints(int uniqueId, const String8* path, const int action); @@ -100,6 +98,8 @@ public: DecryptHandle* openDecryptSession(int uniqueId, int fd, int offset, int length); + DecryptHandle* openDecryptSession(int uniqueId, const char* uri); + status_t closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle); status_t initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, diff --git a/drm/libdrmframework/include/IDrmManagerService.h b/drm/libdrmframework/include/IDrmManagerService.h index 5c668ed..1275488 100644 --- a/drm/libdrmframework/include/IDrmManagerService.h +++ b/drm/libdrmframework/include/IDrmManagerService.h @@ -46,10 +46,9 @@ public: enum { ADD_UNIQUEID = IBinder::FIRST_CALL_TRANSACTION, REMOVE_UNIQUEID, - LOAD_PLUGINS, - LOAD_PLUGINS_FROM_PATH, + ADD_CLIENT, + REMOVE_CLIENT, SET_DRM_SERVICE_LISTENER, - UNLOAD_PLUGINS, INSTALL_DRM_ENGINE, GET_CONSTRAINTS_FROM_CONTENT, CAN_HANDLE, @@ -69,6 +68,7 @@ public: CLOSE_CONVERT_SESSION, GET_ALL_SUPPORT_INFO, OPEN_DECRYPT_SESSION, + OPEN_DECRYPT_SESSION_FROM_URI, CLOSE_DECRYPT_SESSION, INITIALIZE_DECRYPT_UNIT, DECRYPT, @@ -84,15 +84,13 @@ public: virtual void removeUniqueId(int uniqueId) = 0; - virtual status_t loadPlugIns(int uniqueId) = 0; + virtual void addClient(int uniqueId) = 0; - virtual status_t loadPlugIns(int uniqueId, const String8& plugInDirPath) = 0; + virtual void removeClient(int uniqueId) = 0; virtual status_t setDrmServiceListener( int uniqueId, const sp& infoListener) = 0; - virtual status_t unloadPlugIns(int uniqueId) = 0; - virtual status_t installDrmEngine(int uniqueId, const String8& drmEngineFile) = 0; virtual DrmConstraints* getConstraints( @@ -140,6 +138,8 @@ public: virtual DecryptHandle* openDecryptSession(int uniqueId, int fd, int offset, int length) = 0; + virtual DecryptHandle* openDecryptSession(int uniqueId, const char* uri) = 0; + virtual status_t closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) = 0; virtual status_t initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, @@ -168,15 +168,13 @@ public: virtual void removeUniqueId(int uniqueId); - virtual status_t loadPlugIns(int uniqueId); + virtual void addClient(int uniqueId); - virtual status_t loadPlugIns(int uniqueId, const String8& plugInDirPath); + virtual void removeClient(int uniqueId); virtual status_t setDrmServiceListener( int uniqueId, const sp& infoListener); - virtual status_t unloadPlugIns(int uniqueId); - virtual status_t installDrmEngine(int uniqueId, const String8& drmEngineFile); virtual DrmConstraints* getConstraints(int uniqueId, const String8* path, const int action); @@ -221,6 +219,8 @@ public: virtual DecryptHandle* openDecryptSession(int uniqueId, int fd, int offset, int length); + virtual DecryptHandle* openDecryptSession(int uniqueId, const char* uri); + virtual status_t closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle); virtual status_t initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, diff --git a/drm/libdrmframework/plugins/common/include/DrmEngineBase.h b/drm/libdrmframework/plugins/common/include/DrmEngineBase.h index b355534..5851af5 100644 --- a/drm/libdrmframework/plugins/common/include/DrmEngineBase.h +++ b/drm/libdrmframework/plugins/common/include/DrmEngineBase.h @@ -80,6 +80,9 @@ public: status_t openDecryptSession( int uniqueId, DecryptHandle* decryptHandle, int fd, int offset, int length); + status_t openDecryptSession( + int uniqueId, DecryptHandle* decryptHandle, const char* uri); + status_t closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle); status_t initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, @@ -355,6 +358,18 @@ protected: int uniqueId, DecryptHandle* decryptHandle, int fd, int offset, int length) = 0; /** + * Open the decrypt session to decrypt the given protected content + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] decryptHandle Handle for the current decryption session + * @param[in] uri Path of the protected content to be decrypted + * @return + * DRM_ERROR_CANNOT_HANDLE for failure and DRM_NO_ERROR for success + */ + virtual status_t onOpenDecryptSession( + int uniqueId, DecryptHandle* decryptHandle, const char* uri) = 0; + + /** * Close the decrypt session for the given handle * * @param[in] uniqueId Unique identifier for a session diff --git a/drm/libdrmframework/plugins/common/include/IDrmEngine.h b/drm/libdrmframework/plugins/common/include/IDrmEngine.h index b711500..cc03ef2 100644 --- a/drm/libdrmframework/plugins/common/include/IDrmEngine.h +++ b/drm/libdrmframework/plugins/common/include/IDrmEngine.h @@ -315,6 +315,18 @@ public: int uniqueId, DecryptHandle* decryptHandle, int fd, int offset, int length) = 0; /** + * Open the decrypt session to decrypt the given protected content + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] decryptHandle Handle for the current decryption session + * @param[in] uri Path of the protected content to be decrypted + * @return + * DRM_ERROR_CANNOT_HANDLE for failure and DRM_NO_ERROR for success + */ + virtual status_t openDecryptSession( + int uniqueId, DecryptHandle* decryptHandle, const char* uri) = 0; + + /** * Close the decrypt session for the given handle * * @param[in] uniqueId Unique identifier for a session diff --git a/drm/libdrmframework/plugins/passthru/include/DrmPassthruPlugIn.h b/drm/libdrmframework/plugins/passthru/include/DrmPassthruPlugIn.h index eed1628..ddb7fd3 100644 --- a/drm/libdrmframework/plugins/passthru/include/DrmPassthruPlugIn.h +++ b/drm/libdrmframework/plugins/passthru/include/DrmPassthruPlugIn.h @@ -74,6 +74,9 @@ protected: status_t onOpenDecryptSession( int uniqueId, DecryptHandle* decryptHandle, int fd, int offset, int length); + status_t onOpenDecryptSession( + int uniqueId, DecryptHandle* decryptHandle, const char* uri); + status_t onCloseDecryptSession(int uniqueId, DecryptHandle* decryptHandle); status_t onInitializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, diff --git a/drm/libdrmframework/plugins/passthru/src/DrmPassthruPlugIn.cpp b/drm/libdrmframework/plugins/passthru/src/DrmPassthruPlugIn.cpp index 4c7714d..41f8e91 100644 --- a/drm/libdrmframework/plugins/passthru/src/DrmPassthruPlugIn.cpp +++ b/drm/libdrmframework/plugins/passthru/src/DrmPassthruPlugIn.cpp @@ -74,14 +74,14 @@ DrmInfoStatus* DrmPassthruPlugIn::onProcessDrmInfo(int uniqueId, const DrmInfo* switch (drmInfo->getInfoType()) { case DrmInfoRequest::TYPE_REGISTRATION_INFO: { const DrmBuffer* emptyBuffer = new DrmBuffer(); - drmInfoStatus - = new DrmInfoStatus(DrmInfoStatus::STATUS_OK, emptyBuffer, drmInfo->getMimeType()); + drmInfoStatus = new DrmInfoStatus(DrmInfoStatus::STATUS_OK, + DrmInfoRequest::TYPE_REGISTRATION_INFO, emptyBuffer, drmInfo->getMimeType()); break; } case DrmInfoRequest::TYPE_UNREGISTRATION_INFO: { const DrmBuffer* emptyBuffer = new DrmBuffer(); - drmInfoStatus - = new DrmInfoStatus(DrmInfoStatus::STATUS_OK, emptyBuffer, drmInfo->getMimeType()); + drmInfoStatus = new DrmInfoStatus(DrmInfoStatus::STATUS_OK, + DrmInfoRequest::TYPE_UNREGISTRATION_INFO, emptyBuffer, drmInfo->getMimeType()); break; } case DrmInfoRequest::TYPE_RIGHTS_ACQUISITION_INFO: { @@ -91,8 +91,8 @@ DrmInfoStatus* DrmPassthruPlugIn::onProcessDrmInfo(int uniqueId, const DrmInfo* data = new char[bufferSize]; memcpy(data, licenseString.string(), bufferSize); const DrmBuffer* buffer = new DrmBuffer(data, bufferSize); - drmInfoStatus - = new DrmInfoStatus(DrmInfoStatus::STATUS_OK, buffer, drmInfo->getMimeType()); + drmInfoStatus = new DrmInfoStatus(DrmInfoStatus::STATUS_OK, + DrmInfoRequest::TYPE_RIGHTS_ACQUISITION_INFO, buffer, drmInfo->getMimeType()); break; } } @@ -243,6 +243,11 @@ status_t DrmPassthruPlugIn::onOpenDecryptSession( return DRM_ERROR_CANNOT_HANDLE; } +status_t DrmPassthruPlugIn::onOpenDecryptSession( + int uniqueId, DecryptHandle* decryptHandle, const char* uri) { + return DRM_ERROR_CANNOT_HANDLE; +} + status_t DrmPassthruPlugIn::onCloseDecryptSession(int uniqueId, DecryptHandle* decryptHandle) { LOGD("DrmPassthruPlugIn::onCloseDecryptSession() : %d", uniqueId); if (NULL != 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/common/IDrmManagerService.cpp | 4 ---- drm/drmserver/DrmManager.cpp | 1 - 2 files changed, 5 deletions(-) (limited to 'drm') diff --git a/drm/common/IDrmManagerService.cpp b/drm/common/IDrmManagerService.cpp index c28527c..e46451d 100644 --- a/drm/common/IDrmManagerService.cpp +++ b/drm/common/IDrmManagerService.cpp @@ -559,8 +559,6 @@ DecryptHandle* BpDrmManagerService::openDecryptSession( handle->decryptInfo = new DecryptInfo(); handle->decryptInfo->decryptBufferLength = reply.readInt32(); } - } else { - LOGE("no decryptHandle is generated in service side"); } return handle; } @@ -1232,8 +1230,6 @@ status_t BnDrmManagerService::onTransact( reply->writeInt32(handle->decryptInfo->decryptBufferLength); delete handle->decryptInfo; handle->decryptInfo = NULL; } - } else { - LOGE("NULL decryptHandle is returned"); } delete handle; handle = NULL; return DRM_NO_ERROR; 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/common/Android.mk | 1 + drm/common/DrmEngineBase.cpp | 4 + drm/common/DrmMetadata.cpp | 117 +++++++++++++++++++++ drm/common/IDrmManagerService.cpp | 62 +++++++++++ drm/drmserver/DrmManager.cpp | 10 ++ drm/drmserver/DrmManagerService.cpp | 49 ++++++++- drm/libdrmframework/DrmManagerClient.cpp | 4 + drm/libdrmframework/DrmManagerClientImpl.cpp | 8 ++ drm/libdrmframework/include/DrmManager.h | 3 + drm/libdrmframework/include/DrmManagerClientImpl.h | 12 +++ drm/libdrmframework/include/DrmManagerService.h | 2 + drm/libdrmframework/include/IDrmManagerService.h | 6 ++ .../plugins/common/include/DrmEngineBase.h | 14 +++ .../plugins/common/include/IDrmEngine.h | 13 +++ .../plugins/passthru/include/DrmPassthruPlugIn.h | 2 + .../plugins/passthru/src/DrmPassthruPlugIn.cpp | 5 + 16 files changed, 310 insertions(+), 2 deletions(-) create mode 100644 drm/common/DrmMetadata.cpp (limited to 'drm') diff --git a/drm/common/Android.mk b/drm/common/Android.mk index 808b2c2..c79a91a 100644 --- a/drm/common/Android.mk +++ b/drm/common/Android.mk @@ -18,6 +18,7 @@ include $(CLEAR_VARS) LOCAL_SRC_FILES:= \ DrmConstraints.cpp \ + DrmMetadata.cpp \ DrmConvertedStatus.cpp \ DrmEngineBase.cpp \ DrmInfo.cpp \ diff --git a/drm/common/DrmEngineBase.cpp b/drm/common/DrmEngineBase.cpp index 10c64ee..ac360eb 100644 --- a/drm/common/DrmEngineBase.cpp +++ b/drm/common/DrmEngineBase.cpp @@ -31,6 +31,10 @@ DrmConstraints* DrmEngineBase::getConstraints( return onGetConstraints(uniqueId, path, action); } +DrmMetadata* DrmEngineBase::getMetadata(int uniqueId, const String8* path) { + return onGetMetadata(uniqueId, path); +} + status_t DrmEngineBase::initialize(int uniqueId) { return onInitialize(uniqueId); } diff --git a/drm/common/DrmMetadata.cpp b/drm/common/DrmMetadata.cpp new file mode 100644 index 0000000..6cc5ec1 --- /dev/null +++ b/drm/common/DrmMetadata.cpp @@ -0,0 +1,117 @@ +/* + * 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 + +using namespace android; + +int DrmMetadata::getCount(void) const { + return mMetadataMap.size(); +} + +status_t DrmMetadata::put(const String8* key, + const char* value) { + if((value != NULL) && (key != NULL)) { + int length = strlen(value); + char* charValue = new char[length + 1]; + + memcpy(charValue, value, length); + charValue[length] = '\0'; + mMetadataMap.add(*key, charValue); + } + return NO_ERROR; +} + +String8 DrmMetadata::get(const String8& key) const { + if (NULL != getValue(&key)) { + return String8(getValue(&key)); + } + else { + return String8(""); + } +} + +const char* DrmMetadata::getValue(const String8* key) const { + if(key != NULL) { + if (NAME_NOT_FOUND != mMetadataMap.indexOfKey(*key)) { + return mMetadataMap.valueFor(*key); + } + else { + return NULL; + } + } else { + return NULL; + } +} + +const char* DrmMetadata::getAsByteArray(const String8* key) const { + return getValue(key); +} + +bool DrmMetadata::KeyIterator::hasNext() { + return mIndex < mDrmMetadata->mMetadataMap.size(); +} + +const String8& DrmMetadata::KeyIterator::next() { + const String8& key = mDrmMetadata->mMetadataMap.keyAt(mIndex); + mIndex++; + return key; +} + +DrmMetadata::KeyIterator DrmMetadata::keyIterator() { + return KeyIterator(this); +} + +DrmMetadata::KeyIterator::KeyIterator(const DrmMetadata::KeyIterator& keyIterator) : + mDrmMetadata(keyIterator.mDrmMetadata), + mIndex(keyIterator.mIndex) { + LOGV("DrmMetadata::KeyIterator::KeyIterator"); +} + +DrmMetadata::KeyIterator& DrmMetadata::KeyIterator::operator=(const DrmMetadata::KeyIterator& keyIterator) { + LOGV("DrmMetadata::KeyIterator::operator="); + mDrmMetadata = keyIterator.mDrmMetadata; + mIndex = keyIterator.mIndex; + return *this; +} + + +DrmMetadata::Iterator DrmMetadata::iterator() { + return Iterator(this); +} + +DrmMetadata::Iterator::Iterator(const DrmMetadata::Iterator& iterator) : + mDrmMetadata(iterator.mDrmMetadata), + mIndex(iterator.mIndex) { + LOGV("DrmMetadata::Iterator::Iterator"); +} + +DrmMetadata::Iterator& DrmMetadata::Iterator::operator=(const DrmMetadata::Iterator& iterator) { + LOGV("DrmMetadata::Iterator::operator="); + mDrmMetadata = iterator.mDrmMetadata; + mIndex = iterator.mIndex; + return *this; +} + +bool DrmMetadata::Iterator::hasNext() { + return mIndex < mDrmMetadata->mMetadataMap.size(); +} + +String8 DrmMetadata::Iterator::next() { + String8 value = String8(mDrmMetadata->mMetadataMap.editValueAt(mIndex)); + mIndex++; + return value; +} diff --git a/drm/common/IDrmManagerService.cpp b/drm/common/IDrmManagerService.cpp index b8ae852..723b50e 100644 --- a/drm/common/IDrmManagerService.cpp +++ b/drm/common/IDrmManagerService.cpp @@ -24,6 +24,7 @@ #include #include +#include #include #include #include @@ -123,6 +124,35 @@ DrmConstraints* BpDrmManagerService::getConstraints( return drmConstraints; } +DrmMetadata* BpDrmManagerService::getMetadata(int uniqueId, const String8* path) { + LOGV("Get Metadata"); + Parcel data, reply; + data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); + data.writeInt32(uniqueId); + + DrmMetadata* drmMetadata = NULL; + data.writeString8(*path); + remote()->transact(GET_METADATA_FROM_CONTENT, data, &reply); + + if (0 != reply.dataAvail()) { + //Filling Drm Metadata + drmMetadata = new DrmMetadata(); + + const int size = reply.readInt32(); + for (int index = 0; index < size; ++index) { + const String8 key(reply.readString8()); + const int bufferSize = reply.readInt32(); + char* data = NULL; + if (0 < bufferSize) { + data = new char[bufferSize]; + reply.read(data, bufferSize); + } + drmMetadata->put(&key, data); + } + } + return drmMetadata; +} + bool BpDrmManagerService::canHandle(int uniqueId, const String8& path, const String8& mimeType) { LOGV("Can Handle"); Parcel data, reply; @@ -827,6 +857,38 @@ status_t BnDrmManagerService::onTransact( return DRM_NO_ERROR; } + case GET_METADATA_FROM_CONTENT: + { + LOGV("BnDrmManagerService::onTransact :GET_METADATA_FROM_CONTENT"); + CHECK_INTERFACE(IDrmManagerService, data, reply); + + const int uniqueId = data.readInt32(); + const String8 path = data.readString8(); + + DrmMetadata* drmMetadata = getMetadata(uniqueId, &path); + if (NULL != drmMetadata) { + //Filling DRM Metadata contents + reply->writeInt32(drmMetadata->getCount()); + + DrmMetadata::KeyIterator keyIt = drmMetadata->keyIterator(); + while (keyIt.hasNext()) { + const String8 key = keyIt.next(); + reply->writeString8(key); + const char* value = drmMetadata->getAsByteArray(&key); + int bufferSize = 0; + if (NULL != value) { + bufferSize = strlen(value); + reply->writeInt32(bufferSize + 1); + reply->write(value, bufferSize + 1); + } else { + reply->writeInt32(0); + } + } + } + delete drmMetadata; drmMetadata = NULL; + return NO_ERROR; + } + case CAN_HANDLE: { LOGV("BnDrmManagerService::onTransact :CAN_HANDLE"); 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) { diff --git a/drm/libdrmframework/DrmManagerClient.cpp b/drm/libdrmframework/DrmManagerClient.cpp index f0439eb..fa3d52a 100644 --- a/drm/libdrmframework/DrmManagerClient.cpp +++ b/drm/libdrmframework/DrmManagerClient.cpp @@ -43,6 +43,10 @@ DrmConstraints* DrmManagerClient::getConstraints(const String8* path, const int return mDrmManagerClientImpl->getConstraints(mUniqueId, path, action); } +DrmMetadata* DrmManagerClient::getMetadata(const String8* path) { + return mDrmManagerClientImpl->getMetadata(mUniqueId, path); +} + bool DrmManagerClient::canHandle(const String8& path, const String8& mimeType) { return mDrmManagerClientImpl->canHandle(mUniqueId, path, mimeType); } diff --git a/drm/libdrmframework/DrmManagerClientImpl.cpp b/drm/libdrmframework/DrmManagerClientImpl.cpp index b3ae9a7..32fa491 100644 --- a/drm/libdrmframework/DrmManagerClientImpl.cpp +++ b/drm/libdrmframework/DrmManagerClientImpl.cpp @@ -101,6 +101,14 @@ DrmConstraints* DrmManagerClientImpl::getConstraints( return drmConstraints; } +DrmMetadata* DrmManagerClientImpl::getMetadata(int uniqueId, const String8* path) { + DrmMetadata *drmMetadata = NULL; + if ((NULL != path) && (EMPTY_STRING != *path)) { + drmMetadata = getDrmManagerService()->getMetadata(uniqueId, path); + } + return drmMetadata; +} + bool DrmManagerClientImpl::canHandle(int uniqueId, const String8& path, const String8& mimeType) { bool retCode = false; if ((EMPTY_STRING != path) || (EMPTY_STRING != mimeType)) { diff --git a/drm/libdrmframework/include/DrmManager.h b/drm/libdrmframework/include/DrmManager.h index d782f5b..bc462c2 100644 --- a/drm/libdrmframework/include/DrmManager.h +++ b/drm/libdrmframework/include/DrmManager.h @@ -32,6 +32,7 @@ class DrmUnregistrationInfo; class DrmRightsAcquisitionInfo; class DrmContentIds; class DrmConstraints; +class DrmMetadata; class DrmRights; class DrmInfo; class DrmInfoStatus; @@ -74,6 +75,8 @@ public: DrmConstraints* getConstraints(int uniqueId, const String8* path, const int action); + DrmMetadata* getMetadata(int uniqueId, const String8* path); + bool canHandle(int uniqueId, const String8& path, const String8& mimeType); DrmInfoStatus* processDrmInfo(int uniqueId, const DrmInfo* drmInfo); diff --git a/drm/libdrmframework/include/DrmManagerClientImpl.h b/drm/libdrmframework/include/DrmManagerClientImpl.h index 1c6be46..ff84fc7 100644 --- a/drm/libdrmframework/include/DrmManagerClientImpl.h +++ b/drm/libdrmframework/include/DrmManagerClientImpl.h @@ -86,6 +86,18 @@ public: DrmConstraints* getConstraints(int uniqueId, const String8* path, const int action); /** + * Get metadata information associated with input content. + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] path Path of the protected content + * @return DrmMetadata + * key-value pairs of metadata are embedded in it + * @note + * In case of error, return NULL + */ + DrmMetadata* getMetadata(int uniqueId, const String8* path); + + /** * Check whether the given mimetype or path can be handled * * @param[in] uniqueId Unique identifier for a session diff --git a/drm/libdrmframework/include/DrmManagerService.h b/drm/libdrmframework/include/DrmManagerService.h index 4a3aeae..f346356 100644 --- a/drm/libdrmframework/include/DrmManagerService.h +++ b/drm/libdrmframework/include/DrmManagerService.h @@ -61,6 +61,8 @@ public: DrmConstraints* getConstraints(int uniqueId, const String8* path, const int action); + DrmMetadata* getMetadata(int uniqueId, const String8* path); + bool canHandle(int uniqueId, const String8& path, const String8& mimeType); DrmInfoStatus* processDrmInfo(int uniqueId, const DrmInfo* drmInfo); diff --git a/drm/libdrmframework/include/IDrmManagerService.h b/drm/libdrmframework/include/IDrmManagerService.h index 1275488..f1dabd3 100644 --- a/drm/libdrmframework/include/IDrmManagerService.h +++ b/drm/libdrmframework/include/IDrmManagerService.h @@ -27,6 +27,7 @@ namespace android { class DrmContentIds; class DrmConstraints; +class DrmMetadata; class DrmRights; class DrmInfo; class DrmInfoStatus; @@ -51,6 +52,7 @@ public: SET_DRM_SERVICE_LISTENER, INSTALL_DRM_ENGINE, GET_CONSTRAINTS_FROM_CONTENT, + GET_METADATA_FROM_CONTENT, CAN_HANDLE, PROCESS_DRM_INFO, ACQUIRE_DRM_INFO, @@ -96,6 +98,8 @@ public: virtual DrmConstraints* getConstraints( int uniqueId, const String8* path, const int action) = 0; + virtual DrmMetadata* getMetadata(int uniqueId, const String8* path) = 0; + virtual bool canHandle(int uniqueId, const String8& path, const String8& mimeType) = 0; virtual DrmInfoStatus* processDrmInfo(int uniqueId, const DrmInfo* drmInfo) = 0; @@ -179,6 +183,8 @@ public: virtual DrmConstraints* getConstraints(int uniqueId, const String8* path, const int action); + virtual DrmMetadata* getMetadata(int uniqueId, const String8* path); + virtual bool canHandle(int uniqueId, const String8& path, const String8& mimeType); virtual DrmInfoStatus* processDrmInfo(int uniqueId, const DrmInfo* drmInfo); diff --git a/drm/libdrmframework/plugins/common/include/DrmEngineBase.h b/drm/libdrmframework/plugins/common/include/DrmEngineBase.h index 5851af5..67b6355 100644 --- a/drm/libdrmframework/plugins/common/include/DrmEngineBase.h +++ b/drm/libdrmframework/plugins/common/include/DrmEngineBase.h @@ -36,6 +36,8 @@ public: public: DrmConstraints* getConstraints(int uniqueId, const String8* path, int action); + DrmMetadata* getMetadata(int uniqueId, const String8* path); + status_t initialize(int uniqueId); status_t setOnInfoListener(int uniqueId, const IDrmEngine::OnInfoListener* infoListener); @@ -117,6 +119,18 @@ protected: int uniqueId, const String8* path, int action) = 0; /** + * Get metadata information associated with input content + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] path Path of the protected content + * @return DrmMetadata + * key-value pairs of metadata + * @note + * In case of error, return NULL + */ + virtual DrmMetadata* onGetMetadata(int uniqueId, const String8* path) = 0; + + /** * Initialize plug-in * * @param[in] uniqueId Unique identifier for a session diff --git a/drm/libdrmframework/plugins/common/include/IDrmEngine.h b/drm/libdrmframework/plugins/common/include/IDrmEngine.h index cc03ef2..f839070 100644 --- a/drm/libdrmframework/plugins/common/include/IDrmEngine.h +++ b/drm/libdrmframework/plugins/common/include/IDrmEngine.h @@ -23,6 +23,7 @@ namespace android { class DrmContentIds; class DrmConstraints; +class DrmMetadata; class DrmRights; class DrmInfo; class DrmInfoStatus; @@ -105,6 +106,18 @@ public: int uniqueId, const String8* path, int action) = 0; /** + * Get metadata information associated with input content + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] path Path of the protected content + * @return DrmMetadata + * key-value pairs of metadata + * @note + * In case of error, return NULL + */ + virtual DrmMetadata* getMetadata(int uniqueId, const String8* path) = 0; + + /** * Get whether the given content can be handled by this plugin or not * * @param[in] uniqueId Unique identifier for a session diff --git a/drm/libdrmframework/plugins/passthru/include/DrmPassthruPlugIn.h b/drm/libdrmframework/plugins/passthru/include/DrmPassthruPlugIn.h index ddb7fd3..bbcd9ed 100644 --- a/drm/libdrmframework/plugins/passthru/include/DrmPassthruPlugIn.h +++ b/drm/libdrmframework/plugins/passthru/include/DrmPassthruPlugIn.h @@ -30,6 +30,8 @@ public: protected: DrmConstraints* onGetConstraints(int uniqueId, const String8* path, int action); + DrmMetadata* onGetMetadata(int uniqueId, const String8* path); + status_t onInitialize(int uniqueId); status_t onSetOnInfoListener(int uniqueId, const IDrmEngine::OnInfoListener* infoListener); diff --git a/drm/libdrmframework/plugins/passthru/src/DrmPassthruPlugIn.cpp b/drm/libdrmframework/plugins/passthru/src/DrmPassthruPlugIn.cpp index 41f8e91..dee1fdb 100644 --- a/drm/libdrmframework/plugins/passthru/src/DrmPassthruPlugIn.cpp +++ b/drm/libdrmframework/plugins/passthru/src/DrmPassthruPlugIn.cpp @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -51,6 +52,10 @@ DrmPassthruPlugIn::~DrmPassthruPlugIn() { } +DrmMetadata* DrmPassthruPlugIn::onGetMetadata(int uniqueId, const String8* path) { + return NULL; +} + DrmConstraints* DrmPassthruPlugIn::onGetConstraints( int uniqueId, const String8* path, int action) { LOGD("DrmPassthruPlugIn::onGetConstraints From Path: %d", uniqueId); -- 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/common/DrmEngineBase.cpp | 6 +++--- drm/common/IDrmManagerService.cpp | 24 +++++++++++----------- drm/common/ReadWriteUtils.cpp | 4 ++-- drm/drmserver/DrmManager.cpp | 6 +++--- drm/drmserver/DrmManagerService.cpp | 6 +++--- drm/libdrmframework/DrmManagerClient.cpp | 6 +++--- drm/libdrmframework/DrmManagerClientImpl.cpp | 6 +++--- drm/libdrmframework/include/DrmManager.h | 6 +++--- drm/libdrmframework/include/DrmManagerClientImpl.h | 6 +++--- drm/libdrmframework/include/DrmManagerService.h | 6 +++--- drm/libdrmframework/include/IDrmManagerService.h | 12 +++++------ .../plugins/common/include/DrmEngineBase.h | 12 +++++------ .../plugins/common/include/IDrmEngine.h | 6 +++--- .../plugins/passthru/include/DrmPassthruPlugIn.h | 6 +++--- .../plugins/passthru/src/DrmPassthruPlugIn.cpp | 6 +++--- 15 files changed, 59 insertions(+), 59 deletions(-) (limited to 'drm') diff --git a/drm/common/DrmEngineBase.cpp b/drm/common/DrmEngineBase.cpp index 10c64ee..98a9ece 100644 --- a/drm/common/DrmEngineBase.cpp +++ b/drm/common/DrmEngineBase.cpp @@ -80,7 +80,7 @@ status_t DrmEngineBase::consumeRights( } status_t DrmEngineBase::setPlaybackStatus( - int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position) { + int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int64_t position) { return onSetPlaybackStatus(uniqueId, decryptHandle, playbackStatus, position); } @@ -116,7 +116,7 @@ DrmSupportInfo* DrmEngineBase::getSupportInfo(int uniqueId) { } status_t DrmEngineBase::openDecryptSession( - int uniqueId, DecryptHandle* decryptHandle, int fd, int offset, int length) { + int uniqueId, DecryptHandle* decryptHandle, int fd, off64_t offset, off64_t length) { return onOpenDecryptSession(uniqueId, decryptHandle, fd, offset, length); } @@ -146,7 +146,7 @@ status_t DrmEngineBase::finalizeDecryptUnit( } ssize_t DrmEngineBase::pread( - int uniqueId, DecryptHandle* decryptHandle, void* buffer, ssize_t numBytes, off_t offset) { + int uniqueId, DecryptHandle* decryptHandle, void* buffer, ssize_t numBytes, off64_t offset) { return onPread(uniqueId, decryptHandle, buffer, numBytes, offset); } diff --git a/drm/common/IDrmManagerService.cpp b/drm/common/IDrmManagerService.cpp index c3d12f0..fca4261 100644 --- a/drm/common/IDrmManagerService.cpp +++ b/drm/common/IDrmManagerService.cpp @@ -333,7 +333,7 @@ status_t BpDrmManagerService::consumeRights( } status_t BpDrmManagerService::setPlaybackStatus( - int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position) { + int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int64_t position) { LOGV("setPlaybackStatus"); Parcel data, reply; @@ -429,7 +429,7 @@ DrmConvertedStatus* BpDrmManagerService::convertData( if (0 != reply.dataAvail()) { //Filling DRM Converted Status const int statusCode = reply.readInt32(); - const int offset = reply.readInt32(); + const off64_t offset = reply.readInt64(); DrmBuffer* convertedData = NULL; if (0 != reply.dataAvail()) { @@ -461,7 +461,7 @@ DrmConvertedStatus* BpDrmManagerService::closeConvertSession(int uniqueId, int c if (0 != reply.dataAvail()) { //Filling DRM Converted Status const int statusCode = reply.readInt32(); - const int offset = reply.readInt32(); + const off64_t offset = reply.readInt64(); DrmBuffer* convertedData = NULL; if (0 != reply.dataAvail()) { @@ -515,15 +515,15 @@ status_t BpDrmManagerService::getAllSupportInfo( } DecryptHandle* BpDrmManagerService::openDecryptSession( - int uniqueId, int fd, int offset, int length) { + int uniqueId, int fd, off64_t offset, off64_t length) { LOGV("Entering BpDrmManagerService::openDecryptSession"); Parcel data, reply; data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); data.writeInt32(uniqueId); data.writeFileDescriptor(fd); - data.writeInt32(offset); - data.writeInt32(length); + data.writeInt64(offset); + data.writeInt64(length); remote()->transact(OPEN_DECRYPT_SESSION, data, &reply); @@ -697,7 +697,7 @@ status_t BpDrmManagerService::finalizeDecryptUnit( ssize_t BpDrmManagerService::pread( int uniqueId, DecryptHandle* decryptHandle, void* buffer, - ssize_t numBytes, off_t offset) { + ssize_t numBytes, off64_t offset) { LOGV("read"); Parcel data, reply; int result; @@ -717,7 +717,7 @@ ssize_t BpDrmManagerService::pread( } data.writeInt32(numBytes); - data.writeInt32(offset); + data.writeInt64(offset); remote()->transact(PREAD, data, &reply); result = reply.readInt32(); @@ -1121,7 +1121,7 @@ status_t BnDrmManagerService::onTransact( if (NULL != drmConvertedStatus) { //Filling Drm Converted Ststus reply->writeInt32(drmConvertedStatus->statusCode); - reply->writeInt32(drmConvertedStatus->offset); + reply->writeInt64(drmConvertedStatus->offset); if (NULL != drmConvertedStatus->convertedData) { const DrmBuffer* convertedData = drmConvertedStatus->convertedData; @@ -1150,7 +1150,7 @@ status_t BnDrmManagerService::onTransact( if (NULL != drmConvertedStatus) { //Filling Drm Converted Ststus reply->writeInt32(drmConvertedStatus->statusCode); - reply->writeInt32(drmConvertedStatus->offset); + reply->writeInt64(drmConvertedStatus->offset); if (NULL != drmConvertedStatus->convertedData) { const DrmBuffer* convertedData = drmConvertedStatus->convertedData; @@ -1210,7 +1210,7 @@ status_t BnDrmManagerService::onTransact( const int fd = data.readFileDescriptor(); DecryptHandle* handle - = openDecryptSession(uniqueId, fd, data.readInt32(), data.readInt32()); + = openDecryptSession(uniqueId, fd, data.readInt64(), data.readInt64()); if (NULL != handle) { reply->writeInt32(handle->decryptId); @@ -1415,7 +1415,7 @@ status_t BnDrmManagerService::onTransact( const int numBytes = data.readInt32(); char* buffer = new char[numBytes]; - const off_t offset = data.readInt32(); + const off64_t offset = data.readInt64(); ssize_t result = pread(uniqueId, &handle, buffer, numBytes, offset); reply->writeInt32(result); diff --git a/drm/common/ReadWriteUtils.cpp b/drm/common/ReadWriteUtils.cpp index 7ec4fa2..c16214e 100644 --- a/drm/common/ReadWriteUtils.cpp +++ b/drm/common/ReadWriteUtils.cpp @@ -42,7 +42,7 @@ String8 ReadWriteUtils::readBytes(const String8& filePath) { struct stat sb; if (fstat(fd, &sb) == 0 && sb.st_size > 0) { - int length = sb.st_size; + off64_t length = sb.st_size; char* bytes = new char[length]; if (length == read(fd, (void*) bytes, length)) { string.append(bytes, length); @@ -57,7 +57,7 @@ String8 ReadWriteUtils::readBytes(const String8& filePath) { int ReadWriteUtils::readBytes(const String8& filePath, char** buffer) { FILE* file = NULL; file = fopen(filePath.string(), "r"); - int length = 0; + off64_t length = 0; if (NULL != file) { int fd = fileno(file); 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); } diff --git a/drm/libdrmframework/DrmManagerClient.cpp b/drm/libdrmframework/DrmManagerClient.cpp index f0439eb..0cbbbd4 100644 --- a/drm/libdrmframework/DrmManagerClient.cpp +++ b/drm/libdrmframework/DrmManagerClient.cpp @@ -78,7 +78,7 @@ status_t DrmManagerClient::consumeRights(DecryptHandle* decryptHandle, int actio } status_t DrmManagerClient::setPlaybackStatus( - DecryptHandle* decryptHandle, int playbackStatus, int position) { + DecryptHandle* decryptHandle, int playbackStatus, int64_t position) { return mDrmManagerClientImpl ->setPlaybackStatus(mUniqueId, decryptHandle, playbackStatus, position); } @@ -112,7 +112,7 @@ status_t DrmManagerClient::getAllSupportInfo(int* length, DrmSupportInfo** drmSu return mDrmManagerClientImpl->getAllSupportInfo(mUniqueId, length, drmSupportInfoArray); } -DecryptHandle* DrmManagerClient::openDecryptSession(int fd, int offset, int length) { +DecryptHandle* DrmManagerClient::openDecryptSession(int fd, off64_t offset, off64_t length) { return mDrmManagerClientImpl->openDecryptSession(mUniqueId, fd, offset, length); } @@ -145,7 +145,7 @@ status_t DrmManagerClient::finalizeDecryptUnit(DecryptHandle* decryptHandle, int } ssize_t DrmManagerClient::pread( - DecryptHandle* decryptHandle, void* buffer, ssize_t numBytes, off_t offset) { + DecryptHandle* decryptHandle, void* buffer, ssize_t numBytes, off64_t offset) { Mutex::Autolock _l(mDecryptLock); return mDrmManagerClientImpl->pread(mUniqueId, decryptHandle, buffer, numBytes, offset); } diff --git a/drm/libdrmframework/DrmManagerClientImpl.cpp b/drm/libdrmframework/DrmManagerClientImpl.cpp index b3ae9a7..519ed67 100644 --- a/drm/libdrmframework/DrmManagerClientImpl.cpp +++ b/drm/libdrmframework/DrmManagerClientImpl.cpp @@ -170,7 +170,7 @@ status_t DrmManagerClientImpl::consumeRights( } status_t DrmManagerClientImpl::setPlaybackStatus( - int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position) { + int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int64_t position) { status_t status = DRM_ERROR_UNKNOWN; if (NULL != decryptHandle) { status = getDrmManagerService()->setPlaybackStatus( @@ -231,7 +231,7 @@ status_t DrmManagerClientImpl::getAllSupportInfo( } DecryptHandle* DrmManagerClientImpl::openDecryptSession( - int uniqueId, int fd, int offset, int length) { + int uniqueId, int fd, off64_t offset, off64_t length) { return getDrmManagerService()->openDecryptSession(uniqueId, fd, offset, length); } @@ -283,7 +283,7 @@ status_t DrmManagerClientImpl::finalizeDecryptUnit( } ssize_t DrmManagerClientImpl::pread(int uniqueId, DecryptHandle* decryptHandle, - void* buffer, ssize_t numBytes, off_t offset) { + void* buffer, ssize_t numBytes, off64_t offset) { ssize_t retCode = INVALID_VALUE; if ((NULL != decryptHandle) && (NULL != buffer) && (0 < numBytes)) { retCode = getDrmManagerService()->pread(uniqueId, decryptHandle, buffer, numBytes, offset); diff --git a/drm/libdrmframework/include/DrmManager.h b/drm/libdrmframework/include/DrmManager.h index d782f5b..a0250b7 100644 --- a/drm/libdrmframework/include/DrmManager.h +++ b/drm/libdrmframework/include/DrmManager.h @@ -92,7 +92,7 @@ public: status_t consumeRights(int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve); status_t setPlaybackStatus( - int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position); + int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int64_t position); bool validateAction( int uniqueId, const String8& path, int action, const ActionDescription& description); @@ -109,7 +109,7 @@ public: status_t getAllSupportInfo(int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray); - DecryptHandle* openDecryptSession(int uniqueId, int fd, int offset, int length); + DecryptHandle* openDecryptSession(int uniqueId, int fd, off64_t offset, off64_t length); DecryptHandle* openDecryptSession(int uniqueId, const char* uri); @@ -124,7 +124,7 @@ public: status_t finalizeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId); ssize_t pread(int uniqueId, DecryptHandle* decryptHandle, - void* buffer, ssize_t numBytes, off_t offset); + void* buffer, ssize_t numBytes, off64_t offset); void onInfo(const DrmInfoEvent& event); diff --git a/drm/libdrmframework/include/DrmManagerClientImpl.h b/drm/libdrmframework/include/DrmManagerClientImpl.h index 1c6be46..769f4d0 100644 --- a/drm/libdrmframework/include/DrmManagerClientImpl.h +++ b/drm/libdrmframework/include/DrmManagerClientImpl.h @@ -191,7 +191,7 @@ public: * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure */ status_t setPlaybackStatus( - int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position); + int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int64_t position); /** * Validates whether an action on the DRM content is allowed or not. @@ -291,7 +291,7 @@ public: * @return * Handle for the decryption session */ - DecryptHandle* openDecryptSession(int uniqueId, int fd, int offset, int length); + DecryptHandle* openDecryptSession(int uniqueId, int fd, off64_t offset, off64_t length); /** * Open the decrypt session to decrypt the given protected content @@ -369,7 +369,7 @@ public: * @return Number of bytes read. Returns -1 for Failure. */ ssize_t pread(int uniqueId, DecryptHandle* decryptHandle, - void* buffer, ssize_t numBytes, off_t offset); + void* buffer, ssize_t numBytes, off64_t offset); /** * Notify the event to the registered listener diff --git a/drm/libdrmframework/include/DrmManagerService.h b/drm/libdrmframework/include/DrmManagerService.h index 4a3aeae..4b3ba71 100644 --- a/drm/libdrmframework/include/DrmManagerService.h +++ b/drm/libdrmframework/include/DrmManagerService.h @@ -79,7 +79,7 @@ public: status_t consumeRights(int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve); status_t setPlaybackStatus( - int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position); + int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int64_t position); bool validateAction(int uniqueId, const String8& path, int action, const ActionDescription& description); @@ -96,7 +96,7 @@ public: status_t getAllSupportInfo(int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray); - DecryptHandle* openDecryptSession(int uniqueId, int fd, int offset, int length); + DecryptHandle* openDecryptSession(int uniqueId, int fd, off64_t offset, off64_t length); DecryptHandle* openDecryptSession(int uniqueId, const char* uri); @@ -111,7 +111,7 @@ public: status_t finalizeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId); ssize_t pread(int uniqueId, DecryptHandle* decryptHandle, - void* buffer, ssize_t numBytes, off_t offset); + void* buffer, ssize_t numBytes, off64_t offset); private: DrmManager* mDrmManager; diff --git a/drm/libdrmframework/include/IDrmManagerService.h b/drm/libdrmframework/include/IDrmManagerService.h index 1275488..20fb2ab 100644 --- a/drm/libdrmframework/include/IDrmManagerService.h +++ b/drm/libdrmframework/include/IDrmManagerService.h @@ -116,7 +116,7 @@ public: int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) = 0; virtual status_t setPlaybackStatus( - int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position) = 0; + int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int64_t position) = 0; virtual bool validateAction( int uniqueId, const String8& path, @@ -136,7 +136,7 @@ public: virtual status_t getAllSupportInfo( int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray) = 0; - virtual DecryptHandle* openDecryptSession(int uniqueId, int fd, int offset, int length) = 0; + virtual DecryptHandle* openDecryptSession(int uniqueId, int fd, off64_t offset, off64_t length) = 0; virtual DecryptHandle* openDecryptSession(int uniqueId, const char* uri) = 0; @@ -152,7 +152,7 @@ public: int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) = 0; virtual ssize_t pread(int uniqueId, DecryptHandle* decryptHandle, - void* buffer, ssize_t numBytes,off_t offset) = 0; + void* buffer, ssize_t numBytes,off64_t offset) = 0; }; /** @@ -198,7 +198,7 @@ public: int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve); virtual status_t setPlaybackStatus( - int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position); + int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int64_t position); virtual bool validateAction( int uniqueId, const String8& path, int action, const ActionDescription& description); @@ -217,7 +217,7 @@ public: virtual status_t getAllSupportInfo( int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray); - virtual DecryptHandle* openDecryptSession(int uniqueId, int fd, int offset, int length); + virtual DecryptHandle* openDecryptSession(int uniqueId, int fd, off64_t offset, off64_t length); virtual DecryptHandle* openDecryptSession(int uniqueId, const char* uri); @@ -233,7 +233,7 @@ public: int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId); virtual ssize_t pread(int uniqueId, DecryptHandle* decryptHandle, - void* buffer, ssize_t numBytes, off_t offset); + void* buffer, ssize_t numBytes, off64_t offset); }; /** diff --git a/drm/libdrmframework/plugins/common/include/DrmEngineBase.h b/drm/libdrmframework/plugins/common/include/DrmEngineBase.h index 5851af5..779f7ac 100644 --- a/drm/libdrmframework/plugins/common/include/DrmEngineBase.h +++ b/drm/libdrmframework/plugins/common/include/DrmEngineBase.h @@ -60,7 +60,7 @@ public: status_t consumeRights(int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve); status_t setPlaybackStatus( - int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position); + int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int64_t position); bool validateAction( int uniqueId, const String8& path, int action, const ActionDescription& description); @@ -78,7 +78,7 @@ public: DrmSupportInfo* getSupportInfo(int uniqueId); status_t openDecryptSession( - int uniqueId, DecryptHandle* decryptHandle, int fd, int offset, int length); + int uniqueId, DecryptHandle* decryptHandle, int fd, off64_t offset, off64_t length); status_t openDecryptSession( int uniqueId, DecryptHandle* decryptHandle, const char* uri); @@ -94,7 +94,7 @@ public: status_t finalizeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId); ssize_t pread(int uniqueId, DecryptHandle* decryptHandle, - void* buffer, ssize_t numBytes, off_t offset); + void* buffer, ssize_t numBytes, off64_t offset); protected: ///////////////////////////////////////////////////// @@ -254,7 +254,7 @@ protected: * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure */ virtual status_t onSetPlaybackStatus( - int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position) = 0; + int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int64_t position) = 0; /** * Validates whether an action on the DRM content is allowed or not. @@ -355,7 +355,7 @@ protected: * DRM_ERROR_CANNOT_HANDLE for failure and DRM_NO_ERROR for success */ virtual status_t onOpenDecryptSession( - int uniqueId, DecryptHandle* decryptHandle, int fd, int offset, int length) = 0; + int uniqueId, DecryptHandle* decryptHandle, int fd, off64_t offset, off64_t length) = 0; /** * Open the decrypt session to decrypt the given protected content @@ -436,7 +436,7 @@ protected: * @return Number of bytes read. Returns -1 for Failure. */ virtual ssize_t onPread(int uniqueId, DecryptHandle* decryptHandle, - void* buffer, ssize_t numBytes, off_t offset) = 0; + void* buffer, ssize_t numBytes, off64_t offset) = 0; }; }; diff --git a/drm/libdrmframework/plugins/common/include/IDrmEngine.h b/drm/libdrmframework/plugins/common/include/IDrmEngine.h index cc03ef2..28e6d8e 100644 --- a/drm/libdrmframework/plugins/common/include/IDrmEngine.h +++ b/drm/libdrmframework/plugins/common/include/IDrmEngine.h @@ -211,7 +211,7 @@ public: * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure */ virtual status_t setPlaybackStatus(int uniqueId, DecryptHandle* decryptHandle, - int playbackStatus, int position) = 0; + int playbackStatus, int64_t position) = 0; /** * Validates whether an action on the DRM content is allowed or not. @@ -312,7 +312,7 @@ public: * DRM_ERROR_CANNOT_HANDLE for failure and DRM_NO_ERROR for success */ virtual status_t openDecryptSession( - int uniqueId, DecryptHandle* decryptHandle, int fd, int offset, int length) = 0; + int uniqueId, DecryptHandle* decryptHandle, int fd, off64_t offset, off64_t length) = 0; /** * Open the decrypt session to decrypt the given protected content @@ -393,7 +393,7 @@ public: * @return Number of bytes read. Returns -1 for Failure. */ virtual ssize_t pread(int uniqueId, DecryptHandle* decryptHandle, - void* buffer, ssize_t numBytes, off_t offset) = 0; + void* buffer, ssize_t numBytes, off64_t offset) = 0; }; }; diff --git a/drm/libdrmframework/plugins/passthru/include/DrmPassthruPlugIn.h b/drm/libdrmframework/plugins/passthru/include/DrmPassthruPlugIn.h index ddb7fd3..9c94e73 100644 --- a/drm/libdrmframework/plugins/passthru/include/DrmPassthruPlugIn.h +++ b/drm/libdrmframework/plugins/passthru/include/DrmPassthruPlugIn.h @@ -54,7 +54,7 @@ protected: status_t onConsumeRights(int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve); status_t onSetPlaybackStatus( - int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position); + int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int64_t position); bool onValidateAction( int uniqueId, const String8& path, int action, const ActionDescription& description); @@ -72,7 +72,7 @@ protected: DrmSupportInfo* onGetSupportInfo(int uniqueId); status_t onOpenDecryptSession( - int uniqueId, DecryptHandle* decryptHandle, int fd, int offset, int length); + int uniqueId, DecryptHandle* decryptHandle, int fd, off64_t offset, off64_t length); status_t onOpenDecryptSession( int uniqueId, DecryptHandle* decryptHandle, const char* uri); @@ -88,7 +88,7 @@ protected: status_t onFinalizeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId); ssize_t onPread(int uniqueId, DecryptHandle* decryptHandle, - void* buffer, ssize_t numBytes, off_t offset); + void* buffer, ssize_t numBytes, off64_t offset); private: DecryptHandle* openDecryptSessionImpl(); diff --git a/drm/libdrmframework/plugins/passthru/src/DrmPassthruPlugIn.cpp b/drm/libdrmframework/plugins/passthru/src/DrmPassthruPlugIn.cpp index 41f8e91..73c9708 100644 --- a/drm/libdrmframework/plugins/passthru/src/DrmPassthruPlugIn.cpp +++ b/drm/libdrmframework/plugins/passthru/src/DrmPassthruPlugIn.cpp @@ -182,7 +182,7 @@ status_t DrmPassthruPlugIn::onConsumeRights(int uniqueId, DecryptHandle* decrypt } status_t DrmPassthruPlugIn::onSetPlaybackStatus(int uniqueId, DecryptHandle* decryptHandle, - int playbackStatus, int position) { + int playbackStatus, int64_t position) { LOGD("DrmPassthruPlugIn::onSetPlaybackStatus() : %d", uniqueId); return DRM_NO_ERROR; } @@ -229,7 +229,7 @@ DrmConvertedStatus* DrmPassthruPlugIn::onCloseConvertSession(int uniqueId, int c } status_t DrmPassthruPlugIn::onOpenDecryptSession( - int uniqueId, DecryptHandle* decryptHandle, int fd, int offset, int length) { + int uniqueId, DecryptHandle* decryptHandle, int fd, off64_t offset, off64_t length) { LOGD("DrmPassthruPlugIn::onOpenDecryptSession() : %d", uniqueId); #ifdef ENABLE_PASSTHRU_DECRYPTION @@ -287,7 +287,7 @@ status_t DrmPassthruPlugIn::onFinalizeDecryptUnit( } ssize_t DrmPassthruPlugIn::onPread(int uniqueId, DecryptHandle* decryptHandle, - void* buffer, ssize_t numBytes, off_t offset) { + void* buffer, ssize_t numBytes, off64_t offset) { LOGD("DrmPassthruPlugIn::onPread() : %d", uniqueId); return 0; } -- cgit v1.1 From e558276ea14c1a165aa3b319885e9512b8322613 Mon Sep 17 00:00:00 2001 From: Gloria Wang Date: Wed, 24 Nov 2010 15:39:20 -0800 Subject: Remove empty Widevine make files Change-Id: I0e58070231d00a13da4c46e7c8c4b824c5c12263 --- drm/libdrmframework/plugins/widevine/Android.mk | 27 ------------------------- 1 file changed, 27 deletions(-) delete mode 100644 drm/libdrmframework/plugins/widevine/Android.mk (limited to 'drm') diff --git a/drm/libdrmframework/plugins/widevine/Android.mk b/drm/libdrmframework/plugins/widevine/Android.mk deleted file mode 100644 index 2c388da..0000000 --- a/drm/libdrmframework/plugins/widevine/Android.mk +++ /dev/null @@ -1,27 +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. -# -LOCAL_PATH:= $(call my-dir) -include $(CLEAR_VARS) - -LOCAL_MODULE := libdrmwvmplugin - -LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/drm/plugins/native - -LOCAL_PRELINK_MODULE := false - -LOCAL_MODULE_TAGS := optional - -include $(BUILD_SHARED_LIBRARY) -- 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 +++++- drm/libdrmframework/DrmManagerClient.cpp | 1 + drm/libdrmframework/DrmManagerClientImpl.cpp | 3 ++- 3 files changed, 8 insertions(+), 2 deletions(-) (limited to 'drm') 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; } diff --git a/drm/libdrmframework/DrmManagerClient.cpp b/drm/libdrmframework/DrmManagerClient.cpp index fa3d52a..8bb00c3 100644 --- a/drm/libdrmframework/DrmManagerClient.cpp +++ b/drm/libdrmframework/DrmManagerClient.cpp @@ -31,6 +31,7 @@ DrmManagerClient::DrmManagerClient(): DrmManagerClient::~DrmManagerClient() { DrmManagerClientImpl::remove(mUniqueId); mDrmManagerClientImpl->removeClient(mUniqueId); + mDrmManagerClientImpl->setOnInfoListener(mUniqueId, NULL); delete mDrmManagerClientImpl; mDrmManagerClientImpl = NULL; } diff --git a/drm/libdrmframework/DrmManagerClientImpl.cpp b/drm/libdrmframework/DrmManagerClientImpl.cpp index 32fa491..eea312b 100644 --- a/drm/libdrmframework/DrmManagerClientImpl.cpp +++ b/drm/libdrmframework/DrmManagerClientImpl.cpp @@ -81,7 +81,8 @@ status_t DrmManagerClientImpl::setOnInfoListener( int uniqueId, const sp& infoListener) { Mutex::Autolock _l(mLock); mOnInfoListener = infoListener; - return getDrmManagerService()->setDrmServiceListener(uniqueId, this); + return getDrmManagerService()->setDrmServiceListener(uniqueId, + (NULL != infoListener.get()) ? this : NULL); } status_t DrmManagerClientImpl::installDrmEngine(int uniqueId, const String8& drmEngineFile) { -- cgit v1.1 From fdd65a0fc7df2c878cc601e4c0f4021cb264f051 Mon Sep 17 00:00:00 2001 From: Pravat Dalbehera Date: Wed, 5 Jan 2011 09:02:51 +0100 Subject: Initial OMA DRM forward lock contribution OMA DRM forward lock agent is plugged into the Open DRM framework. Forward lock agent implementation contains: - Forward lock engine to communicate with framework - Converter to encrypt the original file into a special format - Decoder to feed the decrypted data for rendering - Lightweight unique key-encryption mechanism - Documentation Change-Id: Id828ebc30b8147b58b14960a73571648bc01ae94 --- drm/libdrmframework/plugins/common/Android.mk | 16 + drm/libdrmframework/plugins/common/util/Android.mk | 52 + .../plugins/common/util/include/MimeTypeUtil.h | 46 + .../plugins/common/util/include/SessionMap.h | 155 +++ .../plugins/common/util/src/MimeTypeUtil.cpp | 154 +++ .../plugins/forward-lock/Android.mk | 16 + .../plugins/forward-lock/FwdLockEngine/Android.mk | 67 + .../FwdLockEngine/include/FwdLockEngine.h | 559 ++++++++ .../FwdLockEngine/include/FwdLockEngineConst.h | 37 + .../FwdLockEngine/src/FwdLockEngine.cpp | 628 +++++++++ .../forward-lock/internal-format/Android.mk | 16 + .../forward-lock/internal-format/common/Android.mk | 32 + .../internal-format/common/FwdLockGlue.c | 191 +++ .../internal-format/common/FwdLockGlue.h | 85 ++ .../internal-format/converter/Android.mk | 37 + .../internal-format/converter/FwdLockConv.c | 1339 ++++++++++++++++++++ .../internal-format/converter/FwdLockConv.h | 282 +++++ .../internal-format/decoder/Android.mk | 37 + .../internal-format/decoder/FwdLockFile.c | 447 +++++++ .../internal-format/decoder/FwdLockFile.h | 135 ++ .../forward-lock/internal-format/doc/FwdLock.html | 1039 +++++++++++++++ .../internal-format/doc/images/image001.gif | Bin 0 -> 5571 bytes .../internal-format/doc/images/image002.gif | Bin 0 -> 11149 bytes .../internal-format/doc/images/image003.gif | Bin 0 -> 13873 bytes .../internal-format/doc/images/image004.gif | Bin 0 -> 10779 bytes .../internal-format/doc/images/image005.gif | Bin 0 -> 9351 bytes .../internal-format/doc/images/image006.gif | Bin 0 -> 9048 bytes 27 files changed, 5370 insertions(+) create mode 100644 drm/libdrmframework/plugins/common/Android.mk create mode 100644 drm/libdrmframework/plugins/common/util/Android.mk create mode 100644 drm/libdrmframework/plugins/common/util/include/MimeTypeUtil.h create mode 100644 drm/libdrmframework/plugins/common/util/include/SessionMap.h create mode 100644 drm/libdrmframework/plugins/common/util/src/MimeTypeUtil.cpp create mode 100644 drm/libdrmframework/plugins/forward-lock/Android.mk create mode 100644 drm/libdrmframework/plugins/forward-lock/FwdLockEngine/Android.mk create mode 100644 drm/libdrmframework/plugins/forward-lock/FwdLockEngine/include/FwdLockEngine.h create mode 100644 drm/libdrmframework/plugins/forward-lock/FwdLockEngine/include/FwdLockEngineConst.h create mode 100644 drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp create mode 100644 drm/libdrmframework/plugins/forward-lock/internal-format/Android.mk create mode 100644 drm/libdrmframework/plugins/forward-lock/internal-format/common/Android.mk create mode 100644 drm/libdrmframework/plugins/forward-lock/internal-format/common/FwdLockGlue.c create mode 100644 drm/libdrmframework/plugins/forward-lock/internal-format/common/FwdLockGlue.h create mode 100644 drm/libdrmframework/plugins/forward-lock/internal-format/converter/Android.mk create mode 100644 drm/libdrmframework/plugins/forward-lock/internal-format/converter/FwdLockConv.c create mode 100644 drm/libdrmframework/plugins/forward-lock/internal-format/converter/FwdLockConv.h create mode 100644 drm/libdrmframework/plugins/forward-lock/internal-format/decoder/Android.mk create mode 100644 drm/libdrmframework/plugins/forward-lock/internal-format/decoder/FwdLockFile.c create mode 100644 drm/libdrmframework/plugins/forward-lock/internal-format/decoder/FwdLockFile.h create mode 100755 drm/libdrmframework/plugins/forward-lock/internal-format/doc/FwdLock.html create mode 100644 drm/libdrmframework/plugins/forward-lock/internal-format/doc/images/image001.gif create mode 100644 drm/libdrmframework/plugins/forward-lock/internal-format/doc/images/image002.gif create mode 100644 drm/libdrmframework/plugins/forward-lock/internal-format/doc/images/image003.gif create mode 100644 drm/libdrmframework/plugins/forward-lock/internal-format/doc/images/image004.gif create mode 100644 drm/libdrmframework/plugins/forward-lock/internal-format/doc/images/image005.gif create mode 100644 drm/libdrmframework/plugins/forward-lock/internal-format/doc/images/image006.gif (limited to 'drm') diff --git a/drm/libdrmframework/plugins/common/Android.mk b/drm/libdrmframework/plugins/common/Android.mk new file mode 100644 index 0000000..9ee7961 --- /dev/null +++ b/drm/libdrmframework/plugins/common/Android.mk @@ -0,0 +1,16 @@ +# +# 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 $(call all-subdir-makefiles) diff --git a/drm/libdrmframework/plugins/common/util/Android.mk b/drm/libdrmframework/plugins/common/util/Android.mk new file mode 100644 index 0000000..15dda80 --- /dev/null +++ b/drm/libdrmframework/plugins/common/util/Android.mk @@ -0,0 +1,52 @@ +# +# 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 := \ + src/MimeTypeUtil.cpp + +LOCAL_MODULE := libdrmutility + +LOCAL_SHARED_LIBRARIES := \ + libutils \ + libdl \ + libdvm \ + libandroid_runtime \ + libnativehelper \ + liblog + + +base := frameworks/base + +LOCAL_C_INCLUDES += \ + $(JNI_H_INCLUDE) \ + $(base)/include \ + $(base)/include/drm \ + $(base)/include/drm/plugins \ + $(LOCAL_PATH)/include + + +ifneq ($(TARGET_BUILD_VARIANT),user) +LOCAL_C_INCLUDES += \ + $(LOCAL_PATH)/tools + +endif + +LOCAL_MODULE_TAGS := optional + +include $(BUILD_STATIC_LIBRARY) diff --git a/drm/libdrmframework/plugins/common/util/include/MimeTypeUtil.h b/drm/libdrmframework/plugins/common/util/include/MimeTypeUtil.h new file mode 100644 index 0000000..4d12a61 --- /dev/null +++ b/drm/libdrmframework/plugins/common/util/include/MimeTypeUtil.h @@ -0,0 +1,46 @@ +/* + * 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. + */ + +#ifndef __MIMETYPEUTIL_H__ +#define __MIMETYPEUTIL_H__ + +#include + +namespace android { + +class MimeTypeUtil { + +public: + + MimeTypeUtil() {} + + virtual ~MimeTypeUtil() {} + +/** + * May convert the mimetype if there is a well known + * replacement mimetype otherwise the original mimetype + * is returned. + * + * @param mimeType - mimetype in lower case to convert. + * + * @return mimetype or null. + */ +static String8 convertMimeType(String8& mimeType); + +}; +}; + +#endif /* __MIMETYPEUTIL_H__ */ diff --git a/drm/libdrmframework/plugins/common/util/include/SessionMap.h b/drm/libdrmframework/plugins/common/util/include/SessionMap.h new file mode 100644 index 0000000..3dff58c --- /dev/null +++ b/drm/libdrmframework/plugins/common/util/include/SessionMap.h @@ -0,0 +1,155 @@ +/* + * 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. + */ + +#ifndef __SESSIONMAP_H__ +#define __SESSIONMAP_H__ + +#include + +namespace android { + +/** + * A wrapper template class for handling DRM Engine sessions. + */ +template +class SessionMap { + +public: + KeyedVector map; + + SessionMap() {} + + virtual ~SessionMap() { + destroyMap(); + } + +/** + * Adds a new value in the session map table. It expects memory to be allocated already + * for the session object + * + * @param key - key or Session ID + * @param value - session object to add + * + * @return boolean result of adding value. returns false if key is already exist. + */ +bool addValue(int key, NODE value) { + bool result = false; + + if (!isCreated(key)) { + map.add(key, value); + result = true; + } + + return result; +} + + +/** + * returns the session object by the key + * + * @param key - key or Session ID + * + * @return session object as per the key + */ +NODE getValue(int key) { + NODE value = NULL; + + if (isCreated(key)) { + value = (NODE) map.valueFor(key); + } + + return value; +} + +/** + * returns the number of objects in the session map table + * + * @return count of number of session objects. + */ +int getSize() { + return map.size(); +} + +/** + * returns the session object by the index in the session map table + * + * @param index - index of the value required + * + * @return session object as per the index + */ +NODE getValueAt(unsigned int index) { + NODE value = NULL; + + if (map.size() > index) { + value = map.valueAt(index); + } + + return value; +} + +/** + * deletes the object from session map. It also frees up memory for the session object. + * + * @param key - key of the value to be deleted + * + */ +void removeValue(int key) { + deleteValue(getValue(key)); + map.removeItem(key); +} + +/** + * decides if session is already created. + * + * @param key - key of the value for the session + * + * @return boolean result of whether session is created + */ +bool isCreated(int key) { + return (0 <= map.indexOfKey(key)); +} + +/** + * empty the entire session table. It releases all the memory for session objects. + */ +void destroyMap() { + int size = map.size(); + int i = 0; + + for (i = 0; i < size; i++) { + deleteValue(map.valueAt(i)); + } + + map.clear(); +} + +/** + * free up the memory for the session object. + * Make sure if any reference to the session object anywhere, otherwise it will be a + * dangle pointer after this call. + * + * @param value - session object to free + * + */ +void deleteValue(NODE value) { + delete value; +} + +}; + +}; + +#endif /* __SESSIONMAP_H__ */ diff --git a/drm/libdrmframework/plugins/common/util/src/MimeTypeUtil.cpp b/drm/libdrmframework/plugins/common/util/src/MimeTypeUtil.cpp new file mode 100644 index 0000000..4ee903e --- /dev/null +++ b/drm/libdrmframework/plugins/common/util/src/MimeTypeUtil.cpp @@ -0,0 +1,154 @@ +/* + * 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 + +namespace android { + +#undef LOG_TAG +#define LOG_TAG "MimeTypeUtil" + +enum { + MIMETYPE_AUDIO = 0, + MIMETYPE_APPLICATION = 1, + MIMETYPE_IMAGE = 2, + MIMETYPE_VIDEO = 3, + MIMETYPE_LAST = -1, +}; + +struct MimeGroup{ + int type; // Audio, video,.. use the enum values + const char* pGroup; // "audio/", "video/",.. should contain the last "/" + int size; // Number of bytes. e.g. "audio/" = 6 bytes +}; + +struct MimeTypeList{ + int type; + const char* pMimeExt; // Everything after the '/' e.g. audio/x-mpeg -> "x-mpeg" + int size; // Number of bytes. e.g. "x-mpeg" = 6 bytes + const char* pMimeType; // Mimetype that should be returned +}; + + +// Known mimetypes by android +static const char mime_type_audio_mpeg[] = "audio/mpeg"; +static const char mime_type_audio_3gpp[] = "audio/3gpp"; +static const char mime_type_audio_amr[] = "audio/amr-wb"; +static const char mime_type_audio_aac[] = "audio/mp4a-latm"; +static const char mime_type_audio_wav[] = "audio/wav"; + +static const char mime_type_video_mpeg4[] = "video/mpeg4"; +static const char mime_type_video_3gpp[] = "video/3gpp"; + +// Known mimetype groups +static const char mime_group_audio[] = "audio/"; +static const char mime_group_application[] = "application/"; +static const char mime_group_image[] = "image/"; +static const char mime_group_video[] = "video/"; + +static struct MimeGroup mimeGroup[] = { + {MIMETYPE_AUDIO, mime_group_audio, sizeof(mime_group_audio)-1}, + {MIMETYPE_APPLICATION, mime_group_application, sizeof(mime_group_application)-1}, + {MIMETYPE_IMAGE, mime_group_image, sizeof(mime_group_image)-1}, + {MIMETYPE_VIDEO, mime_group_video, sizeof(mime_group_video)-1}, + {MIMETYPE_LAST, NULL, 0} // Must be last entry +}; + +// List of all mimetypes that should be converted. +static struct MimeTypeList mimeTypeList[] = { + // Mp3 mime types + {MIMETYPE_AUDIO, "mp3", sizeof("mp3")-1, mime_type_audio_mpeg}, + {MIMETYPE_AUDIO, "x-mpeg", sizeof("x-mpeg")-1, mime_type_audio_mpeg}, + {MIMETYPE_AUDIO, "x-mp3", sizeof("x-mp3")-1, mime_type_audio_mpeg}, + {MIMETYPE_AUDIO, "mpg", sizeof("mpg")-1, mime_type_audio_mpeg}, + {MIMETYPE_AUDIO, "mpg3", sizeof("mpg")-1, mime_type_audio_mpeg}, + {MIMETYPE_AUDIO, "x-mpg", sizeof("x-mpg")-1, mime_type_audio_mpeg}, + {MIMETYPE_AUDIO, "x-mpegaudio", sizeof("x-mpegaudio")-1, mime_type_audio_mpeg}, + + // 3gpp audio mime types + {MIMETYPE_AUDIO, "3gp", sizeof("3gp")-1, mime_type_audio_3gpp}, + + // Amr audio mime types + {MIMETYPE_AUDIO, "amr", sizeof("amr")-1, mime_type_audio_amr}, + + // Aac audio mime types + {MIMETYPE_AUDIO, "aac", sizeof("aac")-1, mime_type_audio_aac}, + + // Wav audio mime types + {MIMETYPE_AUDIO, "x-wav", sizeof("x-wav")-1, mime_type_audio_wav}, + + // Mpeg4 video mime types + {MIMETYPE_VIDEO, "mpg4", sizeof("mpg4")-1, mime_type_video_mpeg4}, + {MIMETYPE_VIDEO, "mp4v-es", sizeof("mp4v-es")-1, mime_type_video_mpeg4}, + + // 3gpp video mime types + {MIMETYPE_VIDEO, "3gp", sizeof("3gp")-1, mime_type_video_3gpp}, + + // Must be last entry + {MIMETYPE_LAST, NULL, 0, NULL} +}; + +/** + * May convert the mimetype if there is a well known + * replacement mimetype otherwise the original mimetype + * is returned. + * + * @param mimeType - mimetype in lower case to convert. + * + * @return mimetype or null. + */ +String8 MimeTypeUtil::convertMimeType(String8& mimeType) { + String8 result = mimeType; + const char* pTmp; + const char* pMimeType; + struct MimeGroup* pGroup; + struct MimeTypeList* pMimeItem; + int len; + + pMimeType = mimeType.string(); + if (NULL != pMimeType) { + /* Check which group the mimetype is */ + pGroup = mimeGroup; + + while (MIMETYPE_LAST != pGroup->type) { + if (0 == strncmp(pMimeType, pGroup->pGroup, pGroup->size)) { + break; + } + pGroup++; + } + + /* Go through the mimetype list. Only check items of the correct group */ + if (MIMETYPE_LAST != pGroup->type) { + pMimeItem = mimeTypeList; + len = strlen (pMimeType+pGroup->size); + + while (MIMETYPE_LAST != pMimeItem->type) { + if ((len == pMimeItem->size) && + (0 == strcmp(pMimeType+pGroup->size, pMimeItem->pMimeExt))) { + result = String8(pMimeItem->pMimeType); + break; + } + pMimeItem++; + } + } + LOGI("convertMimeType got mimetype %s, converted into mimetype %s", + pMimeType, result.string()); + } + + return result; +} +}; diff --git a/drm/libdrmframework/plugins/forward-lock/Android.mk b/drm/libdrmframework/plugins/forward-lock/Android.mk new file mode 100644 index 0000000..9ee7961 --- /dev/null +++ b/drm/libdrmframework/plugins/forward-lock/Android.mk @@ -0,0 +1,16 @@ +# +# 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 $(call all-subdir-makefiles) diff --git a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/Android.mk b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/Android.mk new file mode 100644 index 0000000..d4a6f18 --- /dev/null +++ b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/Android.mk @@ -0,0 +1,67 @@ +# +# 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) + +base := frameworks/base + +# Determine whether the DRM framework uses 64-bit data types for file offsets and do the same. +ifneq ($(shell grep -c 'off64_t offset' $(base)/drm/libdrmframework/plugins/common/include/IDrmEngine.h), 0) +LOCAL_CFLAGS += -DUSE_64BIT_DRM_API +endif + +LOCAL_SRC_FILES:= \ + src/FwdLockEngine.cpp + +LOCAL_MODULE := libfwdlockengine + +LOCAL_SHARED_LIBRARIES := \ + libicui18n \ + libicuuc \ + libutils \ + libdl \ + libandroid_runtime \ + libnativehelper \ + libcrypto \ + libssl \ + libdrmframework + +LOCAL_STATIC_LIBRARIES := \ + libdrmutility \ + libdrmframeworkcommon \ + libfwdlock-common \ + libfwdlock-converter \ + libfwdlock-decoder + +LOCAL_PRELINK_MODULE := false + +LOCAL_C_INCLUDES += \ + $(JNI_H_INCLUDE) \ + $(base)/include/drm \ + $(base)/drm/libdrmframework/plugins/common/include \ + $(base)/drm/libdrmframework/plugins/common/util/include \ + $(base)/drm/libdrmframework/plugins/forward-lock/internal-format/common \ + $(base)/drm/libdrmframework/plugins/forward-lock/internal-format/converter \ + $(base)/drm/libdrmframework/plugins/forward-lock/internal-format/decoder \ + $(LOCAL_PATH)/include \ + external/openssl/include + +LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/drm/plugins/native + +LOCAL_MODULE_TAGS := optional + +include $(BUILD_SHARED_LIBRARY) diff --git a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/include/FwdLockEngine.h b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/include/FwdLockEngine.h new file mode 100644 index 0000000..34804cf --- /dev/null +++ b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/include/FwdLockEngine.h @@ -0,0 +1,559 @@ +/* + * 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. + */ + +#ifndef __FWDLOCKENGINE_H__ +#define __FWDLOCKENGINE_H__ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "SessionMap.h" +#include "FwdLockConv.h" + +namespace android { + +/** + * Forward Lock Engine class. + */ +class FwdLockEngine : public android::DrmEngineBase { + +public: + FwdLockEngine(); + virtual ~FwdLockEngine(); + +protected: +/** + * Get constraint information associated with input content. + * + * @param uniqueId Unique identifier for a session + * @param path Path of the protected content + * @param action Actions defined such as, + * Action::DEFAULT, Action::PLAY, etc + * @return DrmConstraints + * key-value pairs of constraint are embedded in it + * @note + * In case of error, return NULL + */ +DrmConstraints* onGetConstraints(int uniqueId, const String8* path, int action); + +/** + * Get metadata information associated with input content. + * + * @param uniqueId Unique identifier for a session + * @param path Path of the protected content + * @return DrmMetadata + * For Forward Lock engine, it returns an empty object + * @note + * In case of error, returns NULL + */ +DrmMetadata* onGetMetadata(int uniqueId, const String8* path); + +/** + * Initialize plug-in. + * + * @param uniqueId Unique identifier for a session + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure + */ +status_t onInitialize(int uniqueId); + +/** + * Register a callback to be invoked when the caller required to + * receive necessary information. + * + * @param uniqueId Unique identifier for a session + * @param infoListener Listener + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure + */ +status_t onSetOnInfoListener(int uniqueId, const IDrmEngine::OnInfoListener* infoListener); + +/** + * Terminate the plug-in and release resources bound to it. + * + * @param uniqueId Unique identifier for a session + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure + */ +status_t onTerminate(int uniqueId); + +/** + * Get whether the given content can be handled by this plugin or not. + * + * @param uniqueId Unique identifier for a session + * @param path Path to the protected object + * @return bool + * Returns true if this plugin can handle , false in case of not able to handle + */ +bool onCanHandle(int uniqueId, const String8& path); + +/** + * Processes the given DRM information as appropriate for its type. + * Not used for Forward Lock Engine. + * + * @param uniqueId Unique identifier for a session + * @param drmInfo Information that needs to be processed + * @return DrmInfoStatus + * instance as a result of processing given input + */ +DrmInfoStatus* onProcessDrmInfo(int uniqueId, const DrmInfo* drmInfo); + +/** + * Save DRM rights to specified rights path + * and make association with content path. + * + * @param uniqueId Unique identifier for a session + * @param drmRights DrmRights to be saved + * @param rightsPath File path where rights to be saved + * @param contentPath File path where content was saved + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure + */ +status_t onSaveRights(int uniqueId, + const DrmRights& drmRights, + const String8& rightsPath, + const String8& contentPath); + +/** + * Retrieves necessary information for registration, unregistration or rights + * acquisition information. + * + * @param uniqueId Unique identifier for a session + * @param drmInfoRequest Request information to retrieve drmInfo + * @return DrmInfo + * instance as a result of processing given input + */ +DrmInfo* onAcquireDrmInfo(int uniqueId, + const DrmInfoRequest* drmInfoRequest); + +/** + * Retrieves the mime type embedded inside the original content. + * + * @param uniqueId Unique identifier for a session + * @param path Path of the protected content + * @return String8 + * Returns mime-type of the original content, such as "video/mpeg" + */ +String8 onGetOriginalMimeType(int uniqueId, const String8& path); + +/** + * Retrieves the type of the protected object (content, rights, etc..) + * using specified path or mimetype. At least one parameter should be non null + * to retrieve DRM object type. + * + * @param uniqueId Unique identifier for a session + * @param path Path of the content or null. + * @param mimeType Mime type of the content or null. + * @return type of the DRM content, + * such as DrmObjectType::CONTENT, DrmObjectType::RIGHTS_OBJECT + */ +int onGetDrmObjectType(int uniqueId, + const String8& path, + const String8& mimeType); + +/** + * Check whether the given content has valid rights or not. + * + * @param uniqueId Unique identifier for a session + * @param path Path of the protected content + * @param action Action to perform (Action::DEFAULT, Action::PLAY, etc) + * @return the status of the rights for the protected content, + * such as RightsStatus::RIGHTS_VALID, RightsStatus::RIGHTS_EXPIRED, etc. + */ +int onCheckRightsStatus(int uniqueId, + const String8& path, + int action); + +/** + * Consumes the rights for a content. + * If the reserve parameter is true the rights are reserved until the same + * application calls this api again with the reserve parameter set to false. + * + * @param uniqueId Unique identifier for a session + * @param decryptHandle Handle for the decryption session + * @param action Action to perform. (Action::DEFAULT, Action::PLAY, etc) + * @param reserve True if the rights should be reserved. + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure + */ +status_t onConsumeRights(int uniqueId, + DecryptHandle* decryptHandle, + int action, + bool reserve); + +/** + * Informs the DRM Engine about the playback actions performed on the DRM files. + * + * @param uniqueId Unique identifier for a session + * @param decryptHandle Handle for the decryption session + * @param playbackStatus Playback action (Playback::START, Playback::STOP, Playback::PAUSE) + * @param position Position in the file (in milliseconds) where the start occurs. + * Only valid together with Playback::START. + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure + */ +#ifdef USE_64BIT_DRM_API +status_t onSetPlaybackStatus(int uniqueId, + DecryptHandle* decryptHandle, + int playbackStatus, + int64_t position); +#else +status_t onSetPlaybackStatus(int uniqueId, + DecryptHandle* decryptHandle, + int playbackStatus, + int position); +#endif + +/** + * Validates whether an action on the DRM content is allowed or not. + * + * @param uniqueId Unique identifier for a session + * @param path Path of the protected content + * @param action Action to validate (Action::PLAY, Action::TRANSFER, etc) + * @param description Detailed description of the action + * @return true if the action is allowed. + */ +bool onValidateAction(int uniqueId, + const String8& path, + int action, + const ActionDescription& description); + +/** + * Removes the rights associated with the given protected content. + * Not used for Forward Lock Engine. + * + * @param uniqueId Unique identifier for a session + * @param path Path of the protected content + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure + */ +status_t onRemoveRights(int uniqueId, const String8& path); + +/** + * Removes all the rights information of each plug-in associated with + * DRM framework. Will be used in master reset but does nothing for + * Forward Lock Engine. + * + * @param uniqueId Unique identifier for a session + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure + */ +status_t onRemoveAllRights(int uniqueId); + +/** + * Starts the Forward Lock file conversion session. + * Each time the application tries to download a new DRM file + * which needs to be converted, then the application has to + * begin with calling this API. The convertId is used as the conversion session key + * and must not be the same for different convert sessions. + * + * @param uniqueId Unique identifier for a session + * @param convertId Handle for the convert session + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure + */ +status_t onOpenConvertSession(int uniqueId, int convertId); + +/** + * Accepts and converts the input data which is part of DRM file. + * The resultant converted data and the status is returned in the DrmConvertedInfo + * object. This method will be called each time there is a new block + * of data received by the application. + * + * @param uniqueId Unique identifier for a session + * @param convertId Handle for the convert session + * @param inputData Input Data which need to be converted + * @return Return object contains the status of the data conversion, + * the output converted data and offset. In this case the + * application will ignore the offset information. + */ +DrmConvertedStatus* onConvertData(int uniqueId, + int convertId, + const DrmBuffer* inputData); + +/** + * Closes the convert session in case of data supply completed or error occurred. + * Upon successful conversion of the complete data, it returns signature calculated over + * the entire data used over a conversion session. This signature must be copied to the offset + * mentioned in the DrmConvertedStatus. Signature is used for data integrity protection. + * + * @param uniqueId Unique identifier for a session + * @param convertId Handle for the convert session + * @return Return object contains the status of the data conversion, + * the header and body signature data. It also informs + * the application about the file offset at which this + * signature data should be written. + */ +DrmConvertedStatus* onCloseConvertSession(int uniqueId, int convertId); + +/** + * Returns the information about the Drm Engine capabilities which includes + * supported MimeTypes and file suffixes. + * + * @param uniqueId Unique identifier for a session + * @return DrmSupportInfo + * instance which holds the capabilities of a plug-in + */ +DrmSupportInfo* onGetSupportInfo(int uniqueId); + +/** + * Open the decrypt session to decrypt the given protected content. + * + * @param uniqueId Unique identifier for a session + * @param decryptHandle Handle for the current decryption session + * @param fd File descriptor of the protected content to be decrypted + * @param offset Start position of the content + * @param length The length of the protected content + * @return + * DRM_ERROR_CANNOT_HANDLE for failure and DRM_NO_ERROR for success + */ +#ifdef USE_64BIT_DRM_API +status_t onOpenDecryptSession(int uniqueId, + DecryptHandle* decryptHandle, + int fd, off64_t offset, off64_t length); +#else +status_t onOpenDecryptSession(int uniqueId, + DecryptHandle* decryptHandle, + int fd, int offset, int length); +#endif + +/** + * Open the decrypt session to decrypt the given protected content. + * + * @param uniqueId Unique identifier for a session + * @param decryptHandle Handle for the current decryption session + * @param uri Path of the protected content to be decrypted + * @return + * DRM_ERROR_CANNOT_HANDLE for failure and DRM_NO_ERROR for success + */ +status_t onOpenDecryptSession(int uniqueId, + DecryptHandle* decryptHandle, + const char* uri); + +/** + * Close the decrypt session for the given handle. + * + * @param uniqueId Unique identifier for a session + * @param decryptHandle Handle for the decryption session + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure + */ +status_t onCloseDecryptSession(int uniqueId, + DecryptHandle* decryptHandle); + +/** + * Initialize decryption for the given unit of the protected content. + * + * @param uniqueId Unique identifier for a session + * @param decryptHandle Handle for the decryption session + * @param decryptUnitId ID which specifies decryption unit, such as track ID + * @param headerInfo Information for initializing decryption of this decrypUnit + * @return + * DRM_ERROR_CANNOT_HANDLE for failure and DRM_NO_ERROR for success + */ +status_t onInitializeDecryptUnit(int uniqueId, + DecryptHandle* decryptHandle, + int decryptUnitId, + const DrmBuffer* headerInfo); + +/** + * Decrypt the protected content buffers for the given unit. + * This method will be called any number of times, based on number of + * encrypted streams received from application. + * + * @param uniqueId Unique identifier for a session + * @param decryptHandle Handle for the decryption session + * @param decryptUnitId ID which specifies decryption unit, such as track ID + * @param encBuffer Encrypted data block + * @param decBuffer Decrypted data block + * @return status_t + * Returns the error code for this API + * DRM_NO_ERROR for success, and one of DRM_ERROR_UNKNOWN, DRM_ERROR_LICENSE_EXPIRED + * DRM_ERROR_SESSION_NOT_OPENED, DRM_ERROR_DECRYPT_UNIT_NOT_INITIALIZED, + * DRM_ERROR_DECRYPT for failure. + */ +status_t onDecrypt(int uniqueId, + DecryptHandle* decryptHandle, + int decryptUnitId, + const DrmBuffer* encBuffer, + DrmBuffer** decBuffer); + +/** + * Decrypt the protected content buffers for the given unit. + * This method will be called any number of times, based on number of + * encrypted streams received from application. + * + * @param uniqueId Unique identifier for a session + * @param decryptId Handle for the decryption session + * @param decryptUnitId ID Specifies decryption unit, such as track ID + * @param encBuffer Encrypted data block + * @param decBuffer Decrypted data block + * @param IV Optional buffer + * @return status_t + * Returns the error code for this API + * DRM_NO_ERROR for success, and one of DRM_ERROR_UNKNOWN, DRM_ERROR_LICENSE_EXPIRED + * DRM_ERROR_SESSION_NOT_OPENED, DRM_ERROR_DECRYPT_UNIT_NOT_INITIALIZED, + * DRM_ERROR_DECRYPT for failure. + */ +status_t onDecrypt(int uniqueId, DecryptHandle* decryptHandle, + int decryptUnitId, const DrmBuffer* encBuffer, + DrmBuffer** decBuffer, DrmBuffer* IV); + +/** + * Finalize decryption for the given unit of the protected content. + * + * @param uniqueId Unique identifier for a session + * @param decryptHandle Handle for the decryption session + * @param decryptUnitId ID Specifies decryption unit, such as track ID + * @return + * DRM_ERROR_CANNOT_HANDLE for failure and DRM_NO_ERROR for success + */ +status_t onFinalizeDecryptUnit(int uniqueId, + DecryptHandle* decryptHandle, + int decryptUnitId); + +/** + * Reads the specified number of bytes from an open DRM file. + * + * @param uniqueId Unique identifier for a session + * @param decryptHandle Handle for the decryption session + * @param buffer Reference to the buffer that should receive the read data. + * @param numBytes Number of bytes to read. + * + * @return Number of bytes read. + * @retval -1 Failure. + */ +ssize_t onRead(int uniqueId, + DecryptHandle* decryptHandle, + void* pBuffer, + int numBytes); + +/** + * Updates the file position within an open DRM file. + * + * @param uniqueId Unique identifier for a session + * @param decryptHandle Handle for the decryption session + * @param offset Offset with which to update the file position. + * @param whence One of SEEK_SET, SEEK_CUR, and SEEK_END. + * These constants are defined in unistd.h. + * + * @return New file position. + * @retval ((off_t)-1) Failure. + */ +#ifdef USE_64BIT_DRM_API +off64_t onLseek(int uniqueId, + DecryptHandle* decryptHandle, + off64_t offset, + int whence); +#else +off_t onLseek(int uniqueId, + DecryptHandle* decryptHandle, + off_t offset, + int whence); +#endif + +/** + * Reads the specified number of bytes from an open DRM file. + * + * @param uniqueId Unique identifier for a session + * @param decryptHandle Handle for the decryption session + * @param buffer Reference to the buffer that should receive the read data. + * @param numBytes Number of bytes to read. + * @param offset Offset with which to update the file position. + * + * @return Number of bytes read. Returns -1 for Failure. + */ +#ifdef USE_64BIT_DRM_API +ssize_t onPread(int uniqueId, + DecryptHandle* decryptHandle, + void* buffer, + ssize_t numBytes, + off64_t offset); +#else +ssize_t onPread(int uniqueId, + DecryptHandle* decryptHandle, + void* buffer, + ssize_t numBytes, + off_t offset); +#endif + +private: + +/** + * Session Class for Forward Lock Conversion. An object of this class is created + * for every conversion. + */ +class ConvertSession { + public : + int uniqueId; + FwdLockConv_Output_t output; + + ConvertSession() { + uniqueId = 0; + memset(&output, 0, sizeof(FwdLockConv_Output_t)); + } + + virtual ~ConvertSession() {} +}; + +/** + * Session Class for Forward Lock decoder. An object of this class is created + * for every decoding session. + */ +class DecodeSession { + public : + int fileDesc; + off_t offset; + + DecodeSession() { + fileDesc = -1; + offset = 0; + } + + DecodeSession(int fd) { + fileDesc = fd; + offset = 0; + } + + virtual ~DecodeSession() {} +}; + +/** + * Session Map Tables for Conversion and Decoding of forward lock files. + */ +SessionMap convertSessionMap; +SessionMap decodeSessionMap; + +/** + * Converts the error code from Forward Lock Converter to DrmConvertStatus error code. + * + * @param Forward Lock Converter error code + * + * @return Status code from DrmConvertStatus. + */ +static int getConvertedStatus(FwdLockConv_Status_t status); +}; + +}; + +#endif /* __FWDLOCKENGINE_H__ */ diff --git a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/include/FwdLockEngineConst.h b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/include/FwdLockEngineConst.h new file mode 100644 index 0000000..da95d60 --- /dev/null +++ b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/include/FwdLockEngineConst.h @@ -0,0 +1,37 @@ +/* + * 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. + */ + +#ifndef __FWDLOCKENGINECONST_H__ +#define __FWDLOCKENGINECONST_H__ + +namespace android { + +/** + * Constants for forward Lock Engine used for exposing engine's capabilities. + */ +#define FWDLOCK_EXTENSION_FL ("FL") +#define FWDLOCK_DOTEXTENSION_FL (".fl") +#define FWDLOCK_MIMETYPE_FL ("application/x-android-drm-fl") + +#define FWDLOCK_EXTENSION_DM ("DM") +#define FWDLOCK_DOTEXTENSION_DM (".dm") +#define FWDLOCK_MIMETYPE_DM ("application/vnd.oma.drm.message") + +#define FWDLOCK_DESCRIPTION ("OMA V1 Forward Lock") + +}; + +#endif /* __FWDLOCKENGINECONST_H__ */ diff --git a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp new file mode 100644 index 0000000..d430f72 --- /dev/null +++ b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp @@ -0,0 +1,628 @@ +/* + * 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 "SessionMap.h" +#include "FwdLockEngine.h" +#include +#include +#include +#include +#include "drm_framework_common.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "FwdLockConv.h" +#include "FwdLockFile.h" +#include "FwdLockGlue.h" +#include "FwdLockEngineConst.h" +#include "MimeTypeUtil.h" + +#undef LOG_TAG +#define LOG_TAG "FwdLockEngine" + +using namespace android; +// This extern "C" is mandatory to be managed by TPlugInManager +extern "C" IDrmEngine* create() { + return new FwdLockEngine(); +} + +// This extern "C" is mandatory to be managed by TPlugInManager +extern "C" void destroy(IDrmEngine* plugIn) { + delete plugIn; +} + +FwdLockEngine::FwdLockEngine() { + LOGD("FwdLockEngine Construction"); +} + +FwdLockEngine::~FwdLockEngine() { + LOGD("FwdLockEngine Destruction"); + + convertSessionMap.destroyMap(); + decodeSessionMap.destroyMap(); +} + +int FwdLockEngine::getConvertedStatus(FwdLockConv_Status_t status) { + int retStatus = DrmConvertedStatus::STATUS_ERROR; + + switch(status) { + case FwdLockConv_Status_OK: + retStatus = DrmConvertedStatus::STATUS_OK; + break; + case FwdLockConv_Status_SyntaxError: + case FwdLockConv_Status_InvalidArgument: + case FwdLockConv_Status_UnsupportedFileFormat: + case FwdLockConv_Status_UnsupportedContentTransferEncoding: + LOGD("FwdLockEngine getConvertedStatus: file conversion Error %d. " \ + "Returning STATUS_INPUTDATA_ERROR", status); + retStatus = DrmConvertedStatus::STATUS_INPUTDATA_ERROR; + break; + default: + LOGD("FwdLockEngine getConvertedStatus: file conversion Error %d. " \ + "Returning STATUS_ERROR", status); + retStatus = DrmConvertedStatus::STATUS_ERROR; + break; + } + + return retStatus; +} + +DrmConstraints* FwdLockEngine::onGetConstraints(int uniqueId, const String8* path, int action) { + DrmConstraints* drmConstraints = NULL; + + LOGD("FwdLockEngine::onGetConstraints"); + + if (NULL != path && + (RightsStatus::RIGHTS_VALID == onCheckRightsStatus(uniqueId, *path, action))) { + // Return the empty constraints to show no error condition. + drmConstraints = new DrmConstraints(); + } + + return drmConstraints; +} + +DrmMetadata* FwdLockEngine::onGetMetadata(int uniqueId, const String8* path) { + DrmMetadata* drmMetadata = NULL; + + LOGD("FwdLockEngine::onGetMetadata"); + + if (NULL != path) { + // Returns empty metadata to show no error condition. + drmMetadata = new DrmMetadata(); + } + + return drmMetadata; +} + +android::status_t FwdLockEngine::onInitialize(int uniqueId) { + LOGD("FwdLockEngine::onInitialize"); + + + if (FwdLockGlue_InitializeKeyEncryption()) { + LOGD("FwdLockEngine::onInitialize -- FwdLockGlue_InitializeKeyEncryption succeeded"); + } else { + LOGD("FwdLockEngine::onInitialize -- FwdLockGlue_InitializeKeyEncryption failed:" + "errno = %d", errno); + } + + return DRM_NO_ERROR; +} + +android::status_t +FwdLockEngine::onSetOnInfoListener(int uniqueId, const IDrmEngine::OnInfoListener* infoListener) { + // Not used + LOGD("FwdLockEngine::onSetOnInfoListener"); + + return DRM_NO_ERROR; +} + +android::status_t FwdLockEngine::onTerminate(int uniqueId) { + LOGD("FwdLockEngine::onTerminate"); + + return DRM_NO_ERROR; +} + +DrmSupportInfo* FwdLockEngine::onGetSupportInfo(int uniqueId) { + DrmSupportInfo* pSupportInfo = new DrmSupportInfo(); + + LOGD("FwdLockEngine::onGetSupportInfo"); + + // fill all Forward Lock mimetypes and extensions + if (NULL != pSupportInfo) { + pSupportInfo->addMimeType(String8(FWDLOCK_MIMETYPE_FL)); + pSupportInfo->addFileSuffix(String8(FWDLOCK_DOTEXTENSION_FL)); + pSupportInfo->addMimeType(String8(FWDLOCK_MIMETYPE_DM)); + pSupportInfo->addFileSuffix(String8(FWDLOCK_DOTEXTENSION_DM)); + + pSupportInfo->setDescription(String8(FWDLOCK_DESCRIPTION)); + } + + return pSupportInfo; +} + +bool FwdLockEngine::onCanHandle(int uniqueId, const String8& path) { + bool result = false; + + String8 extString = path.getPathExtension(); + + extString.toLower(); + + if ((extString == String8(FWDLOCK_DOTEXTENSION_FL)) || + (extString == String8(FWDLOCK_DOTEXTENSION_DM))) { + result = true; + } + return result; +} + +DrmInfoStatus* FwdLockEngine::onProcessDrmInfo(int uniqueId, const DrmInfo* drmInfo) { + DrmInfoStatus *drmInfoStatus = NULL; + + // Nothing to process + + drmInfoStatus = new DrmInfoStatus((int)DrmInfoStatus::STATUS_OK, 0, NULL, String8("")); + + LOGD("FwdLockEngine::onProcessDrmInfo"); + + return drmInfoStatus; +} + +status_t FwdLockEngine::onSaveRights( + int uniqueId, + const DrmRights& drmRights, + const String8& rightsPath, + const String8& contentPath) { + // No rights to save. Return + LOGD("FwdLockEngine::onSaveRights"); + return DRM_ERROR_UNKNOWN; +} + +DrmInfo* FwdLockEngine::onAcquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest) { + DrmInfo* drmInfo = NULL; + + // Nothing to be done for Forward Lock file + LOGD("FwdLockEngine::onAcquireDrmInfo"); + + return drmInfo; +} + +int FwdLockEngine::onCheckRightsStatus(int uniqueId, + const String8& path, + int action) { + int result = RightsStatus::RIGHTS_INVALID; + + LOGD("FwdLockEngine::onCheckRightsStatus"); + + // Only Transfer action is not allowed for forward Lock files. + if (onCanHandle(uniqueId, path)) { + switch(action) { + case Action::DEFAULT: + case Action::PLAY: + case Action::RINGTONE: + case Action::OUTPUT: + case Action::PREVIEW: + case Action::EXECUTE: + case Action::DISPLAY: + result = RightsStatus::RIGHTS_VALID; + break; + + case Action::TRANSFER: + default: + result = RightsStatus::RIGHTS_INVALID; + break; + } + } + + return result; +} + +status_t FwdLockEngine::onConsumeRights(int uniqueId, + DecryptHandle* decryptHandle, + int action, + bool reserve) { + // No rights consumption + LOGD("FwdLockEngine::onConsumeRights"); + return DRM_NO_ERROR; +} + +bool FwdLockEngine::onValidateAction(int uniqueId, + const String8& path, + int action, + const ActionDescription& description) { + LOGD("FwdLockEngine::onValidateAction"); + + // For the forwardlock engine checkRights and ValidateAction are the same. + return (onCheckRightsStatus(uniqueId, path, action) == RightsStatus::RIGHTS_VALID); +} + +String8 FwdLockEngine::onGetOriginalMimeType(int uniqueId, const String8& path) { + LOGD("FwdLockEngine::onGetOriginalMimeType"); + String8 mimeString = String8(""); + int fileDesc = FwdLockFile_open(path.string()); + + if (-1 < fileDesc) { + const char* pMimeType = FwdLockFile_GetContentType(fileDesc); + + if (NULL != pMimeType) { + String8 contentType = String8(pMimeType); + contentType.toLower(); + mimeString = MimeTypeUtil::convertMimeType(contentType); + } + + FwdLockFile_close(fileDesc); + } + + return mimeString; +} + +int FwdLockEngine::onGetDrmObjectType(int uniqueId, + const String8& path, + const String8& mimeType) { + String8 mimeStr = String8(mimeType); + + LOGD("FwdLockEngine::onGetDrmObjectType"); + + mimeStr.toLower(); + + /* Checks whether + * 1. path and mime type both are not empty strings (meaning unavailable) else content is unknown + * 2. if one of them is empty string and if other is known then its a DRM Content Object. + * 3. if both of them are available, then both may be of known type + * (regardless of the relation between them to make it compatible with other DRM Engines) + */ + if (((0 == path.length()) || onCanHandle(uniqueId, path)) && + ((0 == mimeType.length()) || ((mimeStr == String8(FWDLOCK_MIMETYPE_FL)) || + (mimeStr == String8(FWDLOCK_MIMETYPE_DM)))) && (mimeType != path) ) { + return DrmObjectType::CONTENT; + } + + return DrmObjectType::UNKNOWN; +} + +status_t FwdLockEngine::onRemoveRights(int uniqueId, const String8& path) { + // No Rights to remove + LOGD("FwdLockEngine::onRemoveRights"); + return DRM_NO_ERROR; +} + +status_t FwdLockEngine::onRemoveAllRights(int uniqueId) { + // No rights to remove + LOGD("FwdLockEngine::onRemoveAllRights"); + return DRM_NO_ERROR; +} + +#ifdef USE_64BIT_DRM_API +status_t FwdLockEngine::onSetPlaybackStatus(int uniqueId, DecryptHandle* decryptHandle, + int playbackStatus, int64_t position) { +#else +status_t FwdLockEngine::onSetPlaybackStatus(int uniqueId, DecryptHandle* decryptHandle, + int playbackStatus, int position) { +#endif + // Not used + LOGD("FwdLockEngine::onSetPlaybackStatus"); + return DRM_NO_ERROR; +} + +status_t FwdLockEngine::onOpenConvertSession(int uniqueId, + int convertId) { + status_t result = DRM_ERROR_UNKNOWN; + LOGD("FwdLockEngine::onOpenConvertSession"); + if (!convertSessionMap.isCreated(convertId)) { + ConvertSession *newSession = new ConvertSession(); + if (FwdLockConv_Status_OK == + FwdLockConv_OpenSession(&(newSession->uniqueId), &(newSession->output))) { + convertSessionMap.addValue(convertId, newSession); + result = DRM_NO_ERROR; + } else { + LOGD("FwdLockEngine::onOpenConvertSession -- FwdLockConv_OpenSession failed."); + delete newSession; + } + } + return result; +} + +DrmConvertedStatus* FwdLockEngine::onConvertData(int uniqueId, + int convertId, + const DrmBuffer* inputData) { + FwdLockConv_Status_t retStatus = FwdLockConv_Status_InvalidArgument; + DrmBuffer *convResult = new DrmBuffer(NULL, 0); + int offset = -1; + + if (NULL != inputData && convertSessionMap.isCreated(convertId)) { + ConvertSession *convSession = convertSessionMap.getValue(convertId); + + if (NULL != convSession) { + retStatus = FwdLockConv_ConvertData(convSession->uniqueId, + inputData->data, + inputData->length, + &(convSession->output)); + + if (FwdLockConv_Status_OK == retStatus) { + // return bytes from conversion if available + if (convSession->output.fromConvertData.numBytes > 0) { + convResult->data = new char[convSession->output.fromConvertData.numBytes]; + + if (NULL != convResult->data) { + convResult->length = convSession->output.fromConvertData.numBytes; + memcpy(convResult->data, + (char *)convSession->output.fromConvertData.pBuffer, + convResult->length); + } + } + } else { + offset = convSession->output.fromConvertData.errorPos; + } + } + } + return new DrmConvertedStatus(getConvertedStatus(retStatus), convResult, offset); +} + +DrmConvertedStatus* FwdLockEngine::onCloseConvertSession(int uniqueId, + int convertId) { + FwdLockConv_Status_t retStatus = FwdLockConv_Status_InvalidArgument; + DrmBuffer *convResult = new DrmBuffer(NULL, 0); + int offset = -1; + + LOGD("FwdLockEngine::onCloseConvertSession"); + + if (convertSessionMap.isCreated(convertId)) { + ConvertSession *convSession = convertSessionMap.getValue(convertId); + + if (NULL != convSession) { + retStatus = FwdLockConv_CloseSession(convSession->uniqueId, &(convSession->output)); + + if (FwdLockConv_Status_OK == retStatus) { + offset = convSession->output.fromCloseSession.fileOffset; + convResult->data = new char[FWD_LOCK_SIGNATURES_SIZE]; + + if (NULL != convResult->data) { + convResult->length = FWD_LOCK_SIGNATURES_SIZE; + memcpy(convResult->data, + (char *)convSession->output.fromCloseSession.signatures, + convResult->length); + } + } + } + convertSessionMap.removeValue(convertId); + } + return new DrmConvertedStatus(getConvertedStatus(retStatus), convResult, offset); +} + +#ifdef USE_64BIT_DRM_API +status_t FwdLockEngine::onOpenDecryptSession(int uniqueId, + DecryptHandle* decryptHandle, + int fd, + off64_t offset, + off64_t length) { +#else +status_t FwdLockEngine::onOpenDecryptSession(int uniqueId, + DecryptHandle* decryptHandle, + int fd, + int offset, + int length) { +#endif + status_t result = DRM_ERROR_CANNOT_HANDLE; + int fileDesc = -1; + + LOGD("FwdLockEngine::onOpenDecryptSession"); + + if ((-1 < fd) && + (NULL != decryptHandle) && + (!decodeSessionMap.isCreated(decryptHandle->decryptId))) { + fileDesc = dup(fd); + } else { + LOGD("FwdLockEngine::onOpenDecryptSession parameter error"); + return result; + } + + if (-1 < fileDesc && + -1 < ::lseek(fileDesc, offset, SEEK_SET) && + -1 < FwdLockFile_attach(fileDesc)) { + // check for file integrity. This must be done to protect the content mangling. + int retVal = FwdLockFile_CheckHeaderIntegrity(fileDesc); + DecodeSession* decodeSession = new DecodeSession(fileDesc); + + if (retVal && NULL != decodeSession) { + decodeSessionMap.addValue(decryptHandle->decryptId, decodeSession); + const char *pmime= FwdLockFile_GetContentType(fileDesc); + String8 contentType = String8(pmime == NULL ? "" : pmime); + contentType.toLower(); + decryptHandle->mimeType = MimeTypeUtil::convertMimeType(contentType); + decryptHandle->decryptApiType = DecryptApiType::CONTAINER_BASED; + decryptHandle->status = RightsStatus::RIGHTS_VALID; + decryptHandle->decryptInfo = NULL; + result = DRM_NO_ERROR; + } else { + LOGD("FwdLockEngine::onOpenDecryptSession Integrity Check failed for the fd"); + FwdLockFile_detach(fileDesc); + ::close(fileDesc); + delete decodeSession; + } + } + + LOGD("FwdLockEngine::onOpenDecryptSession Exit. result = %d", result); + + return result; +} + +status_t FwdLockEngine::onOpenDecryptSession(int uniqueId, + DecryptHandle* decryptHandle, + const char* uri) { + status_t result = DRM_ERROR_CANNOT_HANDLE; + const char fileTag [] = "file://"; + + if (NULL != decryptHandle && NULL != uri && strlen(uri) > sizeof(fileTag)) { + String8 uriTag = String8(uri); + uriTag.toLower(); + + if (0 == strncmp(uriTag.string(), fileTag, sizeof(fileTag) - 1)) { + const char *filePath = strchr(uri + sizeof(fileTag) - 1, '/'); + if (NULL != filePath && onCanHandle(uniqueId, String8(filePath))) { + int fd = open(filePath, O_RDONLY); + + if (-1 < fd) { + // offset is always 0 and length is not used. so any positive size. + result = onOpenDecryptSession(uniqueId, decryptHandle, fd, 0, 1); + + // fd is duplicated already if success. closing the file + close(fd); + } + } + } + } + + return result; +} + +status_t FwdLockEngine::onCloseDecryptSession(int uniqueId, + DecryptHandle* decryptHandle) { + status_t result = DRM_ERROR_UNKNOWN; + LOGD("FwdLockEngine::onCloseDecryptSession"); + + if (NULL != decryptHandle && decodeSessionMap.isCreated(decryptHandle->decryptId)) { + DecodeSession* session = decodeSessionMap.getValue(decryptHandle->decryptId); + if (NULL != session && session->fileDesc > -1) { + FwdLockFile_detach(session->fileDesc); + ::close(session->fileDesc); + decodeSessionMap.removeValue(decryptHandle->decryptId); + result = DRM_NO_ERROR; + } + } + + LOGD("FwdLockEngine::onCloseDecryptSession Exit"); + return result; +} + +status_t FwdLockEngine::onInitializeDecryptUnit(int uniqueId, + DecryptHandle* decryptHandle, + int decryptUnitId, + const DrmBuffer* headerInfo) { + LOGD("FwdLockEngine::onInitializeDecryptUnit"); + return DRM_ERROR_UNKNOWN; +} + +status_t FwdLockEngine::onDecrypt(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, + const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) { + LOGD("FwdLockEngine::onDecrypt"); + return DRM_ERROR_UNKNOWN; +} + +status_t FwdLockEngine::onDecrypt(int uniqueId, + DecryptHandle* decryptHandle, + int decryptUnitId, + const DrmBuffer* encBuffer, + DrmBuffer** decBuffer) { + LOGD("FwdLockEngine::onDecrypt"); + return DRM_ERROR_UNKNOWN; +} + +status_t FwdLockEngine::onFinalizeDecryptUnit(int uniqueId, + DecryptHandle* decryptHandle, + int decryptUnitId) { + LOGD("FwdLockEngine::onFinalizeDecryptUnit"); + return DRM_ERROR_UNKNOWN; +} + +ssize_t FwdLockEngine::onRead(int uniqueId, + DecryptHandle* decryptHandle, + void* buffer, + int numBytes) { + ssize_t size = -1; + + if (NULL != decryptHandle && + decodeSessionMap.isCreated(decryptHandle->decryptId) && + NULL != buffer && + numBytes > -1) { + DecodeSession* session = decodeSessionMap.getValue(decryptHandle->decryptId); + if (NULL != session && session->fileDesc > -1) { + size = FwdLockFile_read(session->fileDesc, buffer, numBytes); + + if (0 > size) { + session->offset = ((off_t)-1); + } else { + session->offset += size; + } + } + } + + return size; +} + +#ifdef USE_64BIT_DRM_API +off64_t FwdLockEngine::onLseek(int uniqueId, DecryptHandle* decryptHandle, + off64_t offset, int whence) { +#else +off_t FwdLockEngine::onLseek(int uniqueId, DecryptHandle* decryptHandle, + off_t offset, int whence) { +#endif + off_t offval = -1; + + if (NULL != decryptHandle && decodeSessionMap.isCreated(decryptHandle->decryptId)) { + DecodeSession* session = decodeSessionMap.getValue(decryptHandle->decryptId); + if (NULL != session && session->fileDesc > -1) { + offval = FwdLockFile_lseek(session->fileDesc, offset, whence); + session->offset = offval; + } + } + + return offval; +} + +#ifdef USE_64BIT_DRM_API +ssize_t FwdLockEngine::onPread(int uniqueId, + DecryptHandle* decryptHandle, + void* buffer, + ssize_t numBytes, + off64_t offset) { +#else +ssize_t FwdLockEngine::onPread(int uniqueId, + DecryptHandle* decryptHandle, + void* buffer, + ssize_t numBytes, + off_t offset) { +#endif + ssize_t bytesRead = -1; + + DecodeSession* decoderSession = NULL; + + if ((NULL != decryptHandle) && + (NULL != (decoderSession = decodeSessionMap.getValue(decryptHandle->decryptId))) && + (NULL != buffer) && + (numBytes > -1) && + (offset > -1)) { + if (offset != decoderSession->offset) { + decoderSession->offset = onLseek(uniqueId, decryptHandle, offset, SEEK_SET); + } + + if (((off_t)-1) != decoderSession->offset) { + bytesRead = onRead(uniqueId, decryptHandle, buffer, numBytes); + if (bytesRead < 0) { + LOGD("FwdLockEngine::onPread error reading"); + } + } + } else { + LOGD("FwdLockEngine::onPread decryptId not found"); + } + + return bytesRead; +} diff --git a/drm/libdrmframework/plugins/forward-lock/internal-format/Android.mk b/drm/libdrmframework/plugins/forward-lock/internal-format/Android.mk new file mode 100644 index 0000000..9ee7961 --- /dev/null +++ b/drm/libdrmframework/plugins/forward-lock/internal-format/Android.mk @@ -0,0 +1,16 @@ +# +# 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 $(call all-subdir-makefiles) diff --git a/drm/libdrmframework/plugins/forward-lock/internal-format/common/Android.mk b/drm/libdrmframework/plugins/forward-lock/internal-format/common/Android.mk new file mode 100644 index 0000000..6c5d3cf --- /dev/null +++ b/drm/libdrmframework/plugins/forward-lock/internal-format/common/Android.mk @@ -0,0 +1,32 @@ +# +# 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 := \ + FwdLockGlue.c + +LOCAL_C_INCLUDES := \ + external/openssl/include + +LOCAL_SHARED_LIBRARIES := libcrypto + +LOCAL_MODULE := libfwdlock-common + +LOCAL_MODULE_TAGS := optional + +include $(BUILD_STATIC_LIBRARY) diff --git a/drm/libdrmframework/plugins/forward-lock/internal-format/common/FwdLockGlue.c b/drm/libdrmframework/plugins/forward-lock/internal-format/common/FwdLockGlue.c new file mode 100644 index 0000000..92bda8f --- /dev/null +++ b/drm/libdrmframework/plugins/forward-lock/internal-format/common/FwdLockGlue.c @@ -0,0 +1,191 @@ +/* + * 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 + +#include "FwdLockGlue.h" + +#define TRUE 1 +#define FALSE 0 + +#define KEY_SIZE 16 +#define KEY_SIZE_IN_BITS (KEY_SIZE * 8) + +static int isInitialized = FALSE; + +static const char strKeyFilename[] = "/data/drm/fwdlock/kek.dat"; + +static AES_KEY encryptionRoundKeys; +static AES_KEY decryptionRoundKeys; + +/** + * Creates all directories along the fully qualified path of the given file. + * + * @param[in] path A reference to the fully qualified path of a file. + * @param[in] mode The access mode to use for the directories being created. + * + * @return A Boolean value indicating whether the operation was successful. + */ +static int FwdLockGlue_CreateDirectories(const char *path, mode_t mode) { + int result = TRUE; + size_t partialPathLength = strlen(path); + char *partialPath = malloc(partialPathLength + 1); + if (partialPath == NULL) { + result = FALSE; + } else { + size_t i; + for (i = 0; i < partialPathLength; ++i) { + if (path[i] == '/' && i > 0) { + partialPath[i] = '\0'; + if (mkdir(partialPath, mode) != 0 && errno != EEXIST) { + result = FALSE; + break; + } + } + partialPath[i] = path[i]; + } + free(partialPath); + } + return result; +} + +/** + * Initializes the round keys used for encryption and decryption of session keys. First creates a + * device-unique key-encryption key if none exists yet. + */ +static void FwdLockGlue_InitializeRoundKeys() { + unsigned char keyEncryptionKey[KEY_SIZE]; + int fileDesc = open(strKeyFilename, O_RDONLY); + if (fileDesc >= 0) { + if (read(fileDesc, keyEncryptionKey, KEY_SIZE) == KEY_SIZE) { + isInitialized = TRUE; + } + (void)close(fileDesc); + } else if (errno == ENOENT && + FwdLockGlue_GetRandomNumber(keyEncryptionKey, KEY_SIZE) && + FwdLockGlue_CreateDirectories(strKeyFilename, S_IRWXU)) { + fileDesc = open(strKeyFilename, O_CREAT | O_TRUNC | O_WRONLY, S_IRUSR); + if (fileDesc >= 0) { + if (write(fileDesc, keyEncryptionKey, KEY_SIZE) == KEY_SIZE) { + isInitialized = TRUE; + } + (void)close(fileDesc); + } + } + if (isInitialized) { + if (AES_set_encrypt_key(keyEncryptionKey, KEY_SIZE_IN_BITS, &encryptionRoundKeys) != 0 || + AES_set_decrypt_key(keyEncryptionKey, KEY_SIZE_IN_BITS, &decryptionRoundKeys) != 0) { + isInitialized = FALSE; + } + } + memset(keyEncryptionKey, 0, KEY_SIZE); // Zero out key data. +} + +/** + * Validates the padding of a decrypted key. + * + * @param[in] pData A reference to the buffer containing the decrypted key and padding. + * @param[in] decryptedKeyLength The length in bytes of the decrypted key. + * + * @return A Boolean value indicating whether the padding was valid. + */ +static int FwdLockGlue_ValidatePadding(const unsigned char *pData, size_t decryptedKeyLength) { + size_t i; + size_t padding = AES_BLOCK_SIZE - (decryptedKeyLength % AES_BLOCK_SIZE); + pData += decryptedKeyLength; + for (i = 0; i < padding; ++i) { + if ((size_t)*pData != padding) { + return FALSE; + } + ++pData; + } + return TRUE; +} + +int FwdLockGlue_GetRandomNumber(void *pBuffer, size_t numBytes) { + // Generate 'cryptographically secure' random bytes by reading them from "/dev/urandom" (the + // non-blocking version of "/dev/random"). + ssize_t numBytesRead = 0; + int fileDesc = open("/dev/urandom", O_RDONLY); + if (fileDesc >= 0) { + numBytesRead = read(fileDesc, pBuffer, numBytes); + (void)close(fileDesc); + } + return numBytesRead >= 0 && (size_t)numBytesRead == numBytes; +} + +int FwdLockGlue_InitializeKeyEncryption() { + static pthread_once_t once = PTHREAD_ONCE_INIT; + pthread_once(&once, FwdLockGlue_InitializeRoundKeys); + return isInitialized; +} + +size_t FwdLockGlue_GetEncryptedKeyLength(size_t plaintextKeyLength) { + return ((plaintextKeyLength / AES_BLOCK_SIZE) + 2) * AES_BLOCK_SIZE; +} + +int FwdLockGlue_EncryptKey(const void *pPlaintextKey, + size_t plaintextKeyLength, + void *pEncryptedKey, + size_t encryptedKeyLength) { + int result = FALSE; + assert(encryptedKeyLength == FwdLockGlue_GetEncryptedKeyLength(plaintextKeyLength)); + if (FwdLockGlue_InitializeKeyEncryption()) { + unsigned char initVector[AES_BLOCK_SIZE]; + if (FwdLockGlue_GetRandomNumber(initVector, AES_BLOCK_SIZE)) { + size_t padding = AES_BLOCK_SIZE - (plaintextKeyLength % AES_BLOCK_SIZE); + size_t dataLength = encryptedKeyLength - AES_BLOCK_SIZE; + memcpy(pEncryptedKey, pPlaintextKey, plaintextKeyLength); + memset((unsigned char *)pEncryptedKey + plaintextKeyLength, (int)padding, padding); + memcpy((unsigned char *)pEncryptedKey + dataLength, initVector, AES_BLOCK_SIZE); + AES_cbc_encrypt(pEncryptedKey, pEncryptedKey, dataLength, &encryptionRoundKeys, + initVector, AES_ENCRYPT); + result = TRUE; + } + } + return result; +} + +int FwdLockGlue_DecryptKey(const void *pEncryptedKey, + size_t encryptedKeyLength, + void *pDecryptedKey, + size_t decryptedKeyLength) { + int result = FALSE; + assert(encryptedKeyLength == FwdLockGlue_GetEncryptedKeyLength(decryptedKeyLength)); + if (FwdLockGlue_InitializeKeyEncryption()) { + size_t dataLength = encryptedKeyLength - AES_BLOCK_SIZE; + unsigned char *pData = malloc(dataLength); + if (pData != NULL) { + unsigned char initVector[AES_BLOCK_SIZE]; + memcpy(pData, pEncryptedKey, dataLength); + memcpy(initVector, (const unsigned char *)pEncryptedKey + dataLength, AES_BLOCK_SIZE); + AES_cbc_encrypt(pData, pData, dataLength, &decryptionRoundKeys, initVector, + AES_DECRYPT); + memcpy(pDecryptedKey, pData, decryptedKeyLength); + result = FwdLockGlue_ValidatePadding(pData, decryptedKeyLength); + free(pData); + } + } + return result; +} diff --git a/drm/libdrmframework/plugins/forward-lock/internal-format/common/FwdLockGlue.h b/drm/libdrmframework/plugins/forward-lock/internal-format/common/FwdLockGlue.h new file mode 100644 index 0000000..f36f6ea --- /dev/null +++ b/drm/libdrmframework/plugins/forward-lock/internal-format/common/FwdLockGlue.h @@ -0,0 +1,85 @@ +/* + * 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. + */ + +#ifndef __FWDLOCKGLUE_H__ +#define __FWDLOCKGLUE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Generates the specified number of cryptographically secure random bytes. + * + * @param[out] pBuffer A reference to the buffer that should receive the random data. + * @param[in] numBytes The number of random bytes to generate. + * + * @return A Boolean value indicating whether the operation was successful. + */ +int FwdLockGlue_GetRandomNumber(void *pBuffer, size_t numBytes); + +/** + * Performs initialization of the key-encryption key. Should be called once during startup to + * facilitate encryption and decryption of session keys. + * + * @return A Boolean value indicating whether the operation was successful. + */ +int FwdLockGlue_InitializeKeyEncryption(); + +/** + * Returns the length of the encrypted key, given the length of the plaintext key. + * + * @param[in] plaintextKeyLength The length in bytes of the plaintext key. + * + * @return The length in bytes of the encrypted key. + */ +size_t FwdLockGlue_GetEncryptedKeyLength(size_t plaintextKeyLength); + +/** + * Encrypts the given session key using a key-encryption key unique to this device. + * + * @param[in] pPlaintextKey A reference to the buffer containing the plaintext key. + * @param[in] plaintextKeyLength The length in bytes of the plaintext key. + * @param[out] pEncryptedKey A reference to the buffer containing the encrypted key. + * @param[in] encryptedKeyLength The length in bytes of the encrypted key. + * + * @return A Boolean value indicating whether the operation was successful. + */ +int FwdLockGlue_EncryptKey(const void *pPlaintextKey, + size_t plaintextKeyLength, + void *pEncryptedKey, + size_t encryptedKeyLength); + +/** + * Decrypts the given session key using a key-encryption key unique to this device. + * + * @param[in] pEncryptedKey A reference to the buffer containing the encrypted key. + * @param[in] encryptedKeyLength The length in bytes of the encrypted key. + * @param[out] pDecryptedKey A reference to the buffer containing the decrypted key. + * @param[in] decryptedKeyLength The length in bytes of the decrypted key. + * + * @return A Boolean value indicating whether the operation was successful. + */ +int FwdLockGlue_DecryptKey(const void *pEncryptedKey, + size_t encryptedKeyLength, + void *pDecryptedKey, + size_t decryptedKeyLength); + +#ifdef __cplusplus +} +#endif + +#endif // __FWDLOCKGLUE_H__ diff --git a/drm/libdrmframework/plugins/forward-lock/internal-format/converter/Android.mk b/drm/libdrmframework/plugins/forward-lock/internal-format/converter/Android.mk new file mode 100644 index 0000000..00bb788 --- /dev/null +++ b/drm/libdrmframework/plugins/forward-lock/internal-format/converter/Android.mk @@ -0,0 +1,37 @@ +# +# 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 := \ + FwdLockConv.c + +LOCAL_C_INCLUDES := \ + frameworks/base/drm/libdrmframework/plugins/forward-lock/internal-format/common \ + external/openssl/include + +LOCAL_SHARED_LIBRARIES := libcrypto + +LOCAL_WHOLE_STATIC_LIBRARIES := libfwdlock-common + +LOCAL_STATIC_LIBRARIES := libfwdlock-common + +LOCAL_MODULE := libfwdlock-converter + +LOCAL_MODULE_TAGS := optional + +include $(BUILD_STATIC_LIBRARY) diff --git a/drm/libdrmframework/plugins/forward-lock/internal-format/converter/FwdLockConv.c b/drm/libdrmframework/plugins/forward-lock/internal-format/converter/FwdLockConv.c new file mode 100644 index 0000000..14ea9e9 --- /dev/null +++ b/drm/libdrmframework/plugins/forward-lock/internal-format/converter/FwdLockConv.c @@ -0,0 +1,1339 @@ +/* + * 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 +#include + +#include "FwdLockConv.h" +#include "FwdLockGlue.h" + +#define TRUE 1 +#define FALSE 0 + +#define INVALID_OFFSET ((off64_t)-1) + +#define MAX_NUM_SESSIONS 32 + +#define OUTPUT_BUFFER_SIZE_INCREMENT 1024 +#define READ_BUFFER_SIZE 1024 + +#define MAX_BOUNDARY_LENGTH 70 +#define MAX_DELIMITER_LENGTH (MAX_BOUNDARY_LENGTH + 4) + +#define STRING_LENGTH_INCREMENT 25 + +#define KEY_SIZE AES_BLOCK_SIZE +#define KEY_SIZE_IN_BITS (KEY_SIZE * 8) + +#define SHA1_HASH_SIZE 20 + +#define FWD_LOCK_VERSION 0 +#define FWD_LOCK_SUBFORMAT 0 +#define USAGE_RESTRICTION_FLAGS 0 +#define CONTENT_TYPE_LENGTH_POS 7 +#define TOP_HEADER_SIZE 8 + +/** + * Data type for the parser states of the converter. + */ +typedef enum FwdLockConv_ParserState { + FwdLockConv_ParserState_WantsOpenDelimiter, + FwdLockConv_ParserState_WantsMimeHeaders, + FwdLockConv_ParserState_WantsBinaryEncodedData, + FwdLockConv_ParserState_WantsBase64EncodedData, + FwdLockConv_ParserState_Done +} FwdLockConv_ParserState_t; + +/** + * Data type for the scanner states of the converter. + */ +typedef enum FwdLockConv_ScannerState { + FwdLockConv_ScannerState_WantsFirstDash, + FwdLockConv_ScannerState_WantsSecondDash, + FwdLockConv_ScannerState_WantsCR, + FwdLockConv_ScannerState_WantsLF, + FwdLockConv_ScannerState_WantsBoundary, + FwdLockConv_ScannerState_WantsBoundaryEnd, + FwdLockConv_ScannerState_WantsMimeHeaderNameStart, + FwdLockConv_ScannerState_WantsMimeHeaderName, + FwdLockConv_ScannerState_WantsMimeHeaderNameEnd, + FwdLockConv_ScannerState_WantsContentTypeStart, + FwdLockConv_ScannerState_WantsContentType, + FwdLockConv_ScannerState_WantsContentTransferEncodingStart, + FwdLockConv_ScannerState_Wants_A_OR_I, + FwdLockConv_ScannerState_Wants_N, + FwdLockConv_ScannerState_Wants_A, + FwdLockConv_ScannerState_Wants_R, + FwdLockConv_ScannerState_Wants_Y, + FwdLockConv_ScannerState_Wants_S, + FwdLockConv_ScannerState_Wants_E, + FwdLockConv_ScannerState_Wants_6, + FwdLockConv_ScannerState_Wants_4, + FwdLockConv_ScannerState_Wants_B, + FwdLockConv_ScannerState_Wants_I, + FwdLockConv_ScannerState_Wants_T, + FwdLockConv_ScannerState_WantsContentTransferEncodingEnd, + FwdLockConv_ScannerState_WantsMimeHeaderValueEnd, + FwdLockConv_ScannerState_WantsMimeHeadersEnd, + FwdLockConv_ScannerState_WantsByte1, + FwdLockConv_ScannerState_WantsByte1_AfterCRLF, + FwdLockConv_ScannerState_WantsByte2, + FwdLockConv_ScannerState_WantsByte3, + FwdLockConv_ScannerState_WantsByte4, + FwdLockConv_ScannerState_WantsPadding, + FwdLockConv_ScannerState_WantsWhitespace, + FwdLockConv_ScannerState_WantsWhitespace_AfterCRLF, + FwdLockConv_ScannerState_WantsDelimiter +} FwdLockConv_ScannerState_t; + +/** + * Data type for the content transfer encoding. + */ +typedef enum FwdLockConv_ContentTransferEncoding { + FwdLockConv_ContentTransferEncoding_Undefined, + FwdLockConv_ContentTransferEncoding_Binary, + FwdLockConv_ContentTransferEncoding_Base64 +} FwdLockConv_ContentTransferEncoding_t; + +/** + * Data type for a dynamically growing string. + */ +typedef struct FwdLockConv_String { + char *ptr; + size_t length; + size_t maxLength; + size_t lengthIncrement; +} FwdLockConv_String_t; + +/** + * Data type for the per-file state information needed by the converter. + */ +typedef struct FwdLockConv_Session { + FwdLockConv_ParserState_t parserState; + FwdLockConv_ScannerState_t scannerState; + FwdLockConv_ScannerState_t savedScannerState; + off64_t numCharsConsumed; + char delimiter[MAX_DELIMITER_LENGTH]; + size_t delimiterLength; + size_t delimiterMatchPos; + FwdLockConv_String_t mimeHeaderName; + FwdLockConv_String_t contentType; + FwdLockConv_ContentTransferEncoding_t contentTransferEncoding; + unsigned char sessionKey[KEY_SIZE]; + void *pEncryptedSessionKey; + size_t encryptedSessionKeyLength; + AES_KEY encryptionRoundKeys; + HMAC_CTX signingContext; + unsigned char topHeader[TOP_HEADER_SIZE]; + unsigned char counter[AES_BLOCK_SIZE]; + unsigned char keyStream[AES_BLOCK_SIZE]; + int keyStreamIndex; + unsigned char ch; + size_t outputBufferSize; + size_t dataOffset; + size_t numDataBytes; +} FwdLockConv_Session_t; + +static FwdLockConv_Session_t *sessionPtrs[MAX_NUM_SESSIONS] = { NULL }; + +static pthread_mutex_t sessionAcquisitionMutex = PTHREAD_MUTEX_INITIALIZER; + +static const FwdLockConv_String_t nullString = { NULL, 0, 0, STRING_LENGTH_INCREMENT }; + +static const unsigned char topHeaderTemplate[] = + { 'F', 'W', 'L', 'K', FWD_LOCK_VERSION, FWD_LOCK_SUBFORMAT, USAGE_RESTRICTION_FLAGS }; + +static const char strContent[] = "content-"; +static const char strType[] = "type"; +static const char strTransferEncoding[] = "transfer-encoding"; +static const char strTextPlain[] = "text/plain"; +static const char strApplicationVndOmaDrmRightsXml[] = "application/vnd.oma.drm.rights+xml"; +static const char strApplicationVndOmaDrmContent[] = "application/vnd.oma.drm.content"; + +static const size_t strlenContent = sizeof strContent - 1; +static const size_t strlenTextPlain = sizeof strTextPlain - 1; + +static const signed char base64Values[] = { + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, + 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -2, -1, -1, + -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, + -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, + 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51 +}; + +/** + * Acquires an unused converter session. + * + * @return A session ID. + */ +static int FwdLockConv_AcquireSession() { + int sessionId = -1; + int i; + pthread_mutex_lock(&sessionAcquisitionMutex); + for (i = 0; i < MAX_NUM_SESSIONS; ++i) { + if (sessionPtrs[i] == NULL) { + sessionPtrs[i] = malloc(sizeof *sessionPtrs[i]); + if (sessionPtrs[i] != NULL) { + sessionId = i; + } + break; + } + } + pthread_mutex_unlock(&sessionAcquisitionMutex); + return sessionId; +} + +/** + * Checks whether a session ID is in range and currently in use. + * + * @param[in] sessionID A session ID. + * + * @return A Boolean value indicating whether the session ID is in range and currently in use. + */ +static int FwdLockConv_IsValidSession(int sessionId) { + return 0 <= sessionId && sessionId < MAX_NUM_SESSIONS && sessionPtrs[sessionId] != NULL; +} + +/** + * Releases a converter session. + * + * @param[in] sessionID A session ID. + */ +static void FwdLockConv_ReleaseSession(int sessionId) { + pthread_mutex_lock(&sessionAcquisitionMutex); + assert(FwdLockConv_IsValidSession(sessionId)); + memset(sessionPtrs[sessionId], 0, sizeof *sessionPtrs[sessionId]); // Zero out key data. + free(sessionPtrs[sessionId]); + sessionPtrs[sessionId] = NULL; + pthread_mutex_unlock(&sessionAcquisitionMutex); +} + +/** + * Derives cryptographically independent keys for encryption and signing from the session key. + * + * @param[in,out] pSession A reference to a converter session. + * + * @return A status code. + */ +static int FwdLockConv_DeriveKeys(FwdLockConv_Session_t *pSession) { + FwdLockConv_Status_t status; + struct FwdLockConv_DeriveKeys_Data { + AES_KEY sessionRoundKeys; + unsigned char value[KEY_SIZE]; + unsigned char key[KEY_SIZE]; + } *pData = malloc(sizeof *pData); + if (pData == NULL) { + status = FwdLockConv_Status_OutOfMemory; + } else { + if (AES_set_encrypt_key(pSession->sessionKey, KEY_SIZE_IN_BITS, + &pData->sessionRoundKeys) != 0) { + status = FwdLockConv_Status_ProgramError; + } else { + // Encrypt the 16-byte value {0, 0, ..., 0} to produce the encryption key. + memset(pData->value, 0, KEY_SIZE); + AES_encrypt(pData->value, pData->key, &pData->sessionRoundKeys); + if (AES_set_encrypt_key(pData->key, KEY_SIZE_IN_BITS, + &pSession->encryptionRoundKeys) != 0) { + status = FwdLockConv_Status_ProgramError; + } else { + // Encrypt the 16-byte value {1, 0, ..., 0} to produce the signing key. + ++pData->value[0]; + AES_encrypt(pData->value, pData->key, &pData->sessionRoundKeys); + HMAC_CTX_init(&pSession->signingContext); + HMAC_Init_ex(&pSession->signingContext, pData->key, KEY_SIZE, EVP_sha1(), NULL); + status = FwdLockConv_Status_OK; + } + } + memset(pData, 0, sizeof pData); // Zero out key data. + free(pData); + } + return status; +} + +/** + * Checks whether a given character is valid in a boundary. Note that the boundary may contain + * leading and internal spaces. + * + * @param[in] ch The character to check. + * + * @return A Boolean value indicating whether the given character is valid in a boundary. + */ +static int FwdLockConv_IsBoundaryChar(int ch) { + return isalnum(ch) || ch == '\'' || + ch == '(' || ch == ')' || ch == '+' || ch == '_' || ch == ',' || ch == '-' || + ch == '.' || ch == '/' || ch == ':' || ch == '=' || ch == '?' || ch == ' '; +} + +/** + * Checks whether a given character should be considered whitespace, using a narrower definition + * than the standard-library isspace() function. + * + * @param[in] ch The character to check. + * + * @return A Boolean value indicating whether the given character should be considered whitespace. + */ +static int FwdLockConv_IsWhitespace(int ch) { + return ch == ' ' || ch == '\t'; +} + +/** + * Removes trailing spaces from the delimiter. + * + * @param[in,out] pSession A reference to a converter session. + * + * @return A status code. + */ +static FwdLockConv_Status_t FwdLockConv_RightTrimDelimiter(FwdLockConv_Session_t *pSession) { + while (pSession->delimiterLength > 4 && + pSession->delimiter[pSession->delimiterLength - 1] == ' ') { + --pSession->delimiterLength; + } + if (pSession->delimiterLength > 4) { + return FwdLockConv_Status_OK; + } + return FwdLockConv_Status_SyntaxError; +} + +/** + * Matches the open delimiter. + * + * @param[in,out] pSession A reference to a converter session. + * @param[in] ch A character. + * + * @return A status code. + */ +static FwdLockConv_Status_t FwdLockConv_MatchOpenDelimiter(FwdLockConv_Session_t *pSession, + int ch) { + FwdLockConv_Status_t status = FwdLockConv_Status_OK; + switch (pSession->scannerState) { + case FwdLockConv_ScannerState_WantsFirstDash: + if (ch == '-') { + pSession->scannerState = FwdLockConv_ScannerState_WantsSecondDash; + } else if (ch == '\r') { + pSession->scannerState = FwdLockConv_ScannerState_WantsLF; + } else { + pSession->scannerState = FwdLockConv_ScannerState_WantsCR; + } + break; + case FwdLockConv_ScannerState_WantsSecondDash: + if (ch == '-') { + // The delimiter starts with "\r\n--" (the open delimiter may omit the initial "\r\n"). + // The rest is the user-defined boundary that should come next. + pSession->delimiter[0] = '\r'; + pSession->delimiter[1] = '\n'; + pSession->delimiter[2] = '-'; + pSession->delimiter[3] = '-'; + pSession->delimiterLength = 4; + pSession->scannerState = FwdLockConv_ScannerState_WantsBoundary; + } else if (ch == '\r') { + pSession->scannerState = FwdLockConv_ScannerState_WantsLF; + } else { + pSession->scannerState = FwdLockConv_ScannerState_WantsCR; + } + break; + case FwdLockConv_ScannerState_WantsCR: + if (ch == '\r') { + pSession->scannerState = FwdLockConv_ScannerState_WantsLF; + } + break; + case FwdLockConv_ScannerState_WantsLF: + if (ch == '\n') { + pSession->scannerState = FwdLockConv_ScannerState_WantsFirstDash; + } else if (ch != '\r') { + pSession->scannerState = FwdLockConv_ScannerState_WantsCR; + } + break; + case FwdLockConv_ScannerState_WantsBoundary: + if (FwdLockConv_IsBoundaryChar(ch)) { + // The boundary may contain leading and internal spaces, so trailing spaces will also be + // matched here. These will be removed later. + if (pSession->delimiterLength < MAX_DELIMITER_LENGTH) { + pSession->delimiter[pSession->delimiterLength++] = ch; + } else if (ch != ' ') { + status = FwdLockConv_Status_SyntaxError; + } + } else if (ch == '\r') { + status = FwdLockConv_RightTrimDelimiter(pSession); + if (status == FwdLockConv_Status_OK) { + pSession->scannerState = FwdLockConv_ScannerState_WantsBoundaryEnd; + } + } else if (ch == '\t') { + status = FwdLockConv_RightTrimDelimiter(pSession); + if (status == FwdLockConv_Status_OK) { + pSession->scannerState = FwdLockConv_ScannerState_WantsWhitespace; + } + } else { + status = FwdLockConv_Status_SyntaxError; + } + break; + case FwdLockConv_ScannerState_WantsWhitespace: + if (ch == '\r') { + pSession->scannerState = FwdLockConv_ScannerState_WantsBoundaryEnd; + } else if (!FwdLockConv_IsWhitespace(ch)) { + status = FwdLockConv_Status_SyntaxError; + } + break; + case FwdLockConv_ScannerState_WantsBoundaryEnd: + if (ch == '\n') { + pSession->parserState = FwdLockConv_ParserState_WantsMimeHeaders; + pSession->scannerState = FwdLockConv_ScannerState_WantsMimeHeaderNameStart; + } else { + status = FwdLockConv_Status_SyntaxError; + } + break; + default: + status = FwdLockConv_Status_ProgramError; + break; + } + return status; +} + +/** + * Checks whether a given character is valid in a MIME header name. + * + * @param[in] ch The character to check. + * + * @return A Boolean value indicating whether the given character is valid in a MIME header name. + */ +static int FwdLockConv_IsMimeHeaderNameChar(int ch) { + return isgraph(ch) && ch != ':'; +} + +/** + * Checks whether a given character is valid in a MIME header value. + * + * @param[in] ch The character to check. + * + * @return A Boolean value indicating whether the given character is valid in a MIME header value. + */ +static int FwdLockConv_IsMimeHeaderValueChar(int ch) { + return isgraph(ch) && ch != ';'; +} + +/** + * Appends a character to the specified dynamically growing string. + * + * @param[in,out] pString A reference to a dynamically growing string. + * @param[in] ch The character to append. + * + * @return A status code. + */ +static FwdLockConv_Status_t FwdLockConv_StringAppend(FwdLockConv_String_t *pString, int ch) { + if (pString->length == pString->maxLength) { + size_t newMaxLength = pString->maxLength + pString->lengthIncrement; + char *newPtr = realloc(pString->ptr, newMaxLength + 1); + if (newPtr == NULL) { + return FwdLockConv_Status_OutOfMemory; + } + pString->ptr = newPtr; + pString->maxLength = newMaxLength; + } + pString->ptr[pString->length++] = ch; + pString->ptr[pString->length] = '\0'; + return FwdLockConv_Status_OK; +} + +/** + * Attempts to recognize the MIME header name and changes the scanner state accordingly. + * + * @param[in,out] pSession A reference to a converter session. + * + * @return A status code. + */ +static FwdLockConv_Status_t FwdLockConv_RecognizeMimeHeaderName(FwdLockConv_Session_t *pSession) { + FwdLockConv_Status_t status = FwdLockConv_Status_OK; + if (strncmp(pSession->mimeHeaderName.ptr, strContent, strlenContent) == 0) { + if (strcmp(pSession->mimeHeaderName.ptr + strlenContent, strType) == 0) { + if (pSession->contentType.ptr == NULL) { + pSession->scannerState = FwdLockConv_ScannerState_WantsContentTypeStart; + } else { + status = FwdLockConv_Status_SyntaxError; + } + } else if (strcmp(pSession->mimeHeaderName.ptr + strlenContent, strTransferEncoding) == 0) { + if (pSession->contentTransferEncoding == + FwdLockConv_ContentTransferEncoding_Undefined) { + pSession->scannerState = FwdLockConv_ScannerState_WantsContentTransferEncodingStart; + } else { + status = FwdLockConv_Status_SyntaxError; + } + } else { + pSession->scannerState = FwdLockConv_ScannerState_WantsCR; + } + } else { + pSession->scannerState = FwdLockConv_ScannerState_WantsCR; + } + return status; +} + +/** + * Applies defaults to missing MIME header values. + * + * @param[in,out] pSession A reference to a converter session. + * + * @return A status code. + */ +static FwdLockConv_Status_t FwdLockConv_ApplyDefaults(FwdLockConv_Session_t *pSession) { + if (pSession->contentType.ptr == NULL) { + // Content type is missing: default to "text/plain". + pSession->contentType.ptr = malloc(sizeof strTextPlain); + if (pSession->contentType.ptr == NULL) { + return FwdLockConv_Status_OutOfMemory; + } + memcpy(pSession->contentType.ptr, strTextPlain, sizeof strTextPlain); + pSession->contentType.length = strlenTextPlain; + pSession->contentType.maxLength = strlenTextPlain; + } + if (pSession->contentTransferEncoding == FwdLockConv_ContentTransferEncoding_Undefined) { + // Content transfer encoding is missing: default to binary. + pSession->contentTransferEncoding = FwdLockConv_ContentTransferEncoding_Binary; + } + return FwdLockConv_Status_OK; +} + +/** + * Verifies that the content type is supported. + * + * @param[in,out] pSession A reference to a converter session. + * + * @return A status code. + */ +static FwdLockConv_Status_t FwdLockConv_VerifyContentType(FwdLockConv_Session_t *pSession) { + FwdLockConv_Status_t status; + if (pSession->contentType.ptr == NULL) { + status = FwdLockConv_Status_ProgramError; + } else if (strcmp(pSession->contentType.ptr, strApplicationVndOmaDrmRightsXml) == 0 || + strcmp(pSession->contentType.ptr, strApplicationVndOmaDrmContent) == 0) { + status = FwdLockConv_Status_UnsupportedFileFormat; + } else { + status = FwdLockConv_Status_OK; + } + return status; +} + +/** + * Writes the header of the output file. + * + * @param[in,out] pSession A reference to a converter session. + * @param[out] pOutput The output from the conversion process. + * + * @return A status code. + */ +static FwdLockConv_Status_t FwdLockConv_WriteHeader(FwdLockConv_Session_t *pSession, + FwdLockConv_Output_t *pOutput) { + FwdLockConv_Status_t status; + if (pSession->contentType.length > UCHAR_MAX) { + status = FwdLockConv_Status_SyntaxError; + } else { + pSession->outputBufferSize = OUTPUT_BUFFER_SIZE_INCREMENT; + pOutput->fromConvertData.pBuffer = malloc(pSession->outputBufferSize); + if (pOutput->fromConvertData.pBuffer == NULL) { + status = FwdLockConv_Status_OutOfMemory; + } else { + size_t encryptedSessionKeyPos = TOP_HEADER_SIZE + pSession->contentType.length; + size_t dataSignaturePos = encryptedSessionKeyPos + pSession->encryptedSessionKeyLength; + size_t headerSignaturePos = dataSignaturePos + SHA1_HASH_SIZE; + pSession->dataOffset = headerSignaturePos + SHA1_HASH_SIZE; + memcpy(pSession->topHeader, topHeaderTemplate, sizeof topHeaderTemplate); + pSession->topHeader[CONTENT_TYPE_LENGTH_POS] = + (unsigned char)pSession->contentType.length; + memcpy(pOutput->fromConvertData.pBuffer, pSession->topHeader, TOP_HEADER_SIZE); + memcpy((char *)pOutput->fromConvertData.pBuffer + TOP_HEADER_SIZE, + pSession->contentType.ptr, pSession->contentType.length); + memcpy((char *)pOutput->fromConvertData.pBuffer + encryptedSessionKeyPos, + pSession->pEncryptedSessionKey, pSession->encryptedSessionKeyLength); + + // Set the signatures to all zeros for now; they will have to be updated later. + memset((char *)pOutput->fromConvertData.pBuffer + dataSignaturePos, 0, + SHA1_HASH_SIZE); + memset((char *)pOutput->fromConvertData.pBuffer + headerSignaturePos, 0, + SHA1_HASH_SIZE); + + pOutput->fromConvertData.numBytes = pSession->dataOffset; + status = FwdLockConv_Status_OK; + } + } + return status; +} + +/** + * Matches the MIME headers. + * + * @param[in,out] pSession A reference to a converter session. + * @param[in] ch A character. + * @param[out] pOutput The output from the conversion process. + * + * @return A status code. + */ +static FwdLockConv_Status_t FwdLockConv_MatchMimeHeaders(FwdLockConv_Session_t *pSession, + int ch, + FwdLockConv_Output_t *pOutput) { + FwdLockConv_Status_t status = FwdLockConv_Status_OK; + switch (pSession->scannerState) { + case FwdLockConv_ScannerState_WantsMimeHeaderNameStart: + if (FwdLockConv_IsMimeHeaderNameChar(ch)) { + pSession->mimeHeaderName.length = 0; + status = FwdLockConv_StringAppend(&pSession->mimeHeaderName, tolower(ch)); + if (status == FwdLockConv_Status_OK) { + pSession->scannerState = FwdLockConv_ScannerState_WantsMimeHeaderName; + } + } else if (ch == '\r') { + pSession->scannerState = FwdLockConv_ScannerState_WantsMimeHeadersEnd; + } else if (!FwdLockConv_IsWhitespace(ch)) { + status = FwdLockConv_Status_SyntaxError; + } + break; + case FwdLockConv_ScannerState_WantsMimeHeaderName: + if (FwdLockConv_IsMimeHeaderNameChar(ch)) { + status = FwdLockConv_StringAppend(&pSession->mimeHeaderName, tolower(ch)); + } else if (ch == ':') { + status = FwdLockConv_RecognizeMimeHeaderName(pSession); + } else if (FwdLockConv_IsWhitespace(ch)) { + pSession->scannerState = FwdLockConv_ScannerState_WantsMimeHeaderNameEnd; + } else { + status = FwdLockConv_Status_SyntaxError; + } + break; + case FwdLockConv_ScannerState_WantsMimeHeaderNameEnd: + if (ch == ':') { + status = FwdLockConv_RecognizeMimeHeaderName(pSession); + } else if (!FwdLockConv_IsWhitespace(ch)) { + status = FwdLockConv_Status_SyntaxError; + } + break; + case FwdLockConv_ScannerState_WantsContentTypeStart: + if (FwdLockConv_IsMimeHeaderValueChar(ch)) { + status = FwdLockConv_StringAppend(&pSession->contentType, tolower(ch)); + if (status == FwdLockConv_Status_OK) { + pSession->scannerState = FwdLockConv_ScannerState_WantsContentType; + } + } else if (!FwdLockConv_IsWhitespace(ch)) { + status = FwdLockConv_Status_SyntaxError; + } + break; + case FwdLockConv_ScannerState_WantsContentType: + if (FwdLockConv_IsMimeHeaderValueChar(ch)) { + status = FwdLockConv_StringAppend(&pSession->contentType, tolower(ch)); + } else if (ch == ';') { + pSession->scannerState = FwdLockConv_ScannerState_WantsCR; + } else if (ch == '\r') { + pSession->scannerState = FwdLockConv_ScannerState_WantsLF; + } else if (FwdLockConv_IsWhitespace(ch)) { + pSession->scannerState = FwdLockConv_ScannerState_WantsMimeHeaderValueEnd; + } else { + status = FwdLockConv_Status_SyntaxError; + } + break; + case FwdLockConv_ScannerState_WantsContentTransferEncodingStart: + if (ch == 'b' || ch == 'B') { + pSession->scannerState = FwdLockConv_ScannerState_Wants_A_OR_I; + } else if (ch == '7' || ch == '8') { + pSession->scannerState = FwdLockConv_ScannerState_Wants_B; + } else if (!FwdLockConv_IsWhitespace(ch)) { + status = FwdLockConv_Status_UnsupportedContentTransferEncoding; + } + break; + case FwdLockConv_ScannerState_Wants_A_OR_I: + if (ch == 'i' || ch == 'I') { + pSession->scannerState = FwdLockConv_ScannerState_Wants_N; + } else if (ch == 'a' || ch == 'A') { + pSession->scannerState = FwdLockConv_ScannerState_Wants_S; + } else { + status = FwdLockConv_Status_UnsupportedContentTransferEncoding; + } + break; + case FwdLockConv_ScannerState_Wants_N: + if (ch == 'n' || ch == 'N') { + pSession->scannerState = FwdLockConv_ScannerState_Wants_A; + } else { + status = FwdLockConv_Status_UnsupportedContentTransferEncoding; + } + break; + case FwdLockConv_ScannerState_Wants_A: + if (ch == 'a' || ch == 'A') { + pSession->scannerState = FwdLockConv_ScannerState_Wants_R; + } else { + status = FwdLockConv_Status_UnsupportedContentTransferEncoding; + } + break; + case FwdLockConv_ScannerState_Wants_R: + if (ch == 'r' || ch == 'R') { + pSession->scannerState = FwdLockConv_ScannerState_Wants_Y; + } else { + status = FwdLockConv_Status_UnsupportedContentTransferEncoding; + } + break; + case FwdLockConv_ScannerState_Wants_Y: + if (ch == 'y' || ch == 'Y') { + pSession->contentTransferEncoding = FwdLockConv_ContentTransferEncoding_Binary; + pSession->scannerState = FwdLockConv_ScannerState_WantsContentTransferEncodingEnd; + } else { + status = FwdLockConv_Status_UnsupportedContentTransferEncoding; + } + break; + case FwdLockConv_ScannerState_Wants_S: + if (ch == 's' || ch == 'S') { + pSession->scannerState = FwdLockConv_ScannerState_Wants_E; + } else { + status = FwdLockConv_Status_UnsupportedContentTransferEncoding; + } + break; + case FwdLockConv_ScannerState_Wants_E: + if (ch == 'e' || ch == 'E') { + pSession->scannerState = FwdLockConv_ScannerState_Wants_6; + } else { + status = FwdLockConv_Status_UnsupportedContentTransferEncoding; + } + break; + case FwdLockConv_ScannerState_Wants_6: + if (ch == '6') { + pSession->scannerState = FwdLockConv_ScannerState_Wants_4; + } else { + status = FwdLockConv_Status_UnsupportedContentTransferEncoding; + } + break; + case FwdLockConv_ScannerState_Wants_4: + if (ch == '4') { + pSession->contentTransferEncoding = FwdLockConv_ContentTransferEncoding_Base64; + pSession->scannerState = FwdLockConv_ScannerState_WantsContentTransferEncodingEnd; + } else { + status = FwdLockConv_Status_UnsupportedContentTransferEncoding; + } + break; + case FwdLockConv_ScannerState_Wants_B: + if (ch == 'b' || ch == 'B') { + pSession->scannerState = FwdLockConv_ScannerState_Wants_I; + } else { + status = FwdLockConv_Status_UnsupportedContentTransferEncoding; + } + break; + case FwdLockConv_ScannerState_Wants_I: + if (ch == 'i' || ch == 'I') { + pSession->scannerState = FwdLockConv_ScannerState_Wants_T; + } else { + status = FwdLockConv_Status_UnsupportedContentTransferEncoding; + } + break; + case FwdLockConv_ScannerState_Wants_T: + if (ch == 't' || ch == 'T') { + pSession->contentTransferEncoding = FwdLockConv_ContentTransferEncoding_Binary; + pSession->scannerState = FwdLockConv_ScannerState_WantsContentTransferEncodingEnd; + } else { + status = FwdLockConv_Status_UnsupportedContentTransferEncoding; + } + break; + case FwdLockConv_ScannerState_WantsContentTransferEncodingEnd: + if (ch == ';') { + pSession->scannerState = FwdLockConv_ScannerState_WantsCR; + } else if (ch == '\r') { + pSession->scannerState = FwdLockConv_ScannerState_WantsLF; + } else if (FwdLockConv_IsWhitespace(ch)) { + pSession->scannerState = FwdLockConv_ScannerState_WantsMimeHeaderValueEnd; + } else { + status = FwdLockConv_Status_UnsupportedContentTransferEncoding; + } + break; + case FwdLockConv_ScannerState_WantsMimeHeaderValueEnd: + if (ch == ';') { + pSession->scannerState = FwdLockConv_ScannerState_WantsCR; + } else if (ch == '\r') { + pSession->scannerState = FwdLockConv_ScannerState_WantsLF; + } else if (!FwdLockConv_IsWhitespace(ch)) { + status = FwdLockConv_Status_SyntaxError; + } + break; + case FwdLockConv_ScannerState_WantsCR: + if (ch == '\r') { + pSession->scannerState = FwdLockConv_ScannerState_WantsLF; + } + break; + case FwdLockConv_ScannerState_WantsLF: + if (ch == '\n') { + pSession->scannerState = FwdLockConv_ScannerState_WantsMimeHeaderNameStart; + } else { + status = FwdLockConv_Status_SyntaxError; + } + break; + case FwdLockConv_ScannerState_WantsMimeHeadersEnd: + if (ch == '\n') { + status = FwdLockConv_ApplyDefaults(pSession); + if (status == FwdLockConv_Status_OK) { + status = FwdLockConv_VerifyContentType(pSession); + } + if (status == FwdLockConv_Status_OK) { + status = FwdLockConv_WriteHeader(pSession, pOutput); + } + if (status == FwdLockConv_Status_OK) { + if (pSession->contentTransferEncoding == + FwdLockConv_ContentTransferEncoding_Binary) { + pSession->parserState = FwdLockConv_ParserState_WantsBinaryEncodedData; + } else { + pSession->parserState = FwdLockConv_ParserState_WantsBase64EncodedData; + } + pSession->scannerState = FwdLockConv_ScannerState_WantsByte1; + } + } else { + status = FwdLockConv_Status_SyntaxError; + } + break; + default: + status = FwdLockConv_Status_ProgramError; + break; + } + return status; +} + +/** + * Increments the counter, treated as a 16-byte little-endian number, by one. + * + * @param[in,out] pSession A reference to a converter session. + */ +static void FwdLockConv_IncrementCounter(FwdLockConv_Session_t *pSession) { + size_t i = 0; + while ((++pSession->counter[i] == 0) && (++i < AES_BLOCK_SIZE)) + ; +} + +/** + * Encrypts the given character and writes it to the output buffer. + * + * @param[in,out] pSession A reference to a converter session. + * @param[in] ch The character to encrypt and write. + * @param[in,out] pOutput The output from the conversion process. + * + * @return A status code. + */ +static FwdLockConv_Status_t FwdLockConv_WriteEncryptedChar(FwdLockConv_Session_t *pSession, + unsigned char ch, + FwdLockConv_Output_t *pOutput) { + if (pOutput->fromConvertData.numBytes == pSession->outputBufferSize) { + void *pBuffer; + pSession->outputBufferSize += OUTPUT_BUFFER_SIZE_INCREMENT; + pBuffer = realloc(pOutput->fromConvertData.pBuffer, pSession->outputBufferSize); + if (pBuffer == NULL) { + return FwdLockConv_Status_OutOfMemory; + } + pOutput->fromConvertData.pBuffer = pBuffer; + } + if (++pSession->keyStreamIndex == AES_BLOCK_SIZE) { + FwdLockConv_IncrementCounter(pSession); + pSession->keyStreamIndex = 0; + } + if (pSession->keyStreamIndex == 0) { + AES_encrypt(pSession->counter, pSession->keyStream, &pSession->encryptionRoundKeys); + } + ch ^= pSession->keyStream[pSession->keyStreamIndex]; + ((unsigned char *)pOutput->fromConvertData.pBuffer)[pOutput->fromConvertData.numBytes++] = ch; + ++pSession->numDataBytes; + return FwdLockConv_Status_OK; +} + +/** + * Matches binary-encoded content data and encrypts it, while looking out for the close delimiter. + * + * @param[in,out] pSession A reference to a converter session. + * @param[in] ch A character. + * @param[in,out] pOutput The output from the conversion process. + * + * @return A status code. + */ +static FwdLockConv_Status_t FwdLockConv_MatchBinaryEncodedData(FwdLockConv_Session_t *pSession, + int ch, + FwdLockConv_Output_t *pOutput) { + FwdLockConv_Status_t status = FwdLockConv_Status_OK; + switch (pSession->scannerState) { + case FwdLockConv_ScannerState_WantsByte1: + if (ch != pSession->delimiter[pSession->delimiterMatchPos]) { + // The partial match of the delimiter turned out to be spurious. Flush the matched bytes + // to the output buffer and start over. + size_t i; + for (i = 0; i < pSession->delimiterMatchPos; ++i) { + status = FwdLockConv_WriteEncryptedChar(pSession, pSession->delimiter[i], pOutput); + if (status != FwdLockConv_Status_OK) { + return status; + } + } + pSession->delimiterMatchPos = 0; + } + if (ch != pSession->delimiter[pSession->delimiterMatchPos]) { + // The current character isn't part of the delimiter. Write it to the output buffer. + status = FwdLockConv_WriteEncryptedChar(pSession, ch, pOutput); + } else if (++pSession->delimiterMatchPos == pSession->delimiterLength) { + // The entire delimiter has been matched. The only valid characters now are the "--" + // that complete the close delimiter (no more message parts are expected). + pSession->scannerState = FwdLockConv_ScannerState_WantsFirstDash; + } + break; + case FwdLockConv_ScannerState_WantsFirstDash: + if (ch == '-') { + pSession->scannerState = FwdLockConv_ScannerState_WantsSecondDash; + } else { + status = FwdLockConv_Status_SyntaxError; + } + break; + case FwdLockConv_ScannerState_WantsSecondDash: + if (ch == '-') { + pSession->parserState = FwdLockConv_ParserState_Done; + } else { + status = FwdLockConv_Status_SyntaxError; + } + break; + default: + status = FwdLockConv_Status_ProgramError; + break; + } + return status; +} + +/** + * Checks whether a given character is valid in base64-encoded data. + * + * @param[in] ch The character to check. + * + * @return A Boolean value indicating whether the given character is valid in base64-encoded data. + */ +static int FwdLockConv_IsBase64Char(int ch) { + return 0 <= ch && ch <= 'z' && base64Values[ch] >= 0; +} + +/** + * Matches base64-encoded content data and encrypts it, while looking out for the close delimiter. + * + * @param[in,out] pSession A reference to a converter session. + * @param[in] ch A character. + * @param[in,out] pOutput The output from the conversion process. + * + * @return A status code. + */ +static FwdLockConv_Status_t FwdLockConv_MatchBase64EncodedData(FwdLockConv_Session_t *pSession, + int ch, + FwdLockConv_Output_t *pOutput) { + FwdLockConv_Status_t status = FwdLockConv_Status_OK; + switch (pSession->scannerState) { + case FwdLockConv_ScannerState_WantsByte1: + case FwdLockConv_ScannerState_WantsByte1_AfterCRLF: + if (FwdLockConv_IsBase64Char(ch)) { + pSession->ch = base64Values[ch] << 2; + pSession->scannerState = FwdLockConv_ScannerState_WantsByte2; + } else if (ch == '\r') { + pSession->savedScannerState = FwdLockConv_ScannerState_WantsByte1_AfterCRLF; + pSession->scannerState = FwdLockConv_ScannerState_WantsLF; + } else if (ch == '-') { + if (pSession->scannerState == FwdLockConv_ScannerState_WantsByte1_AfterCRLF) { + pSession->delimiterMatchPos = 3; + pSession->scannerState = FwdLockConv_ScannerState_WantsDelimiter; + } else { + status = FwdLockConv_Status_SyntaxError; + } + } else if (!FwdLockConv_IsWhitespace(ch)) { + status = FwdLockConv_Status_SyntaxError; + } + break; + case FwdLockConv_ScannerState_WantsByte2: + if (FwdLockConv_IsBase64Char(ch)) { + pSession->ch |= base64Values[ch] >> 4; + status = FwdLockConv_WriteEncryptedChar(pSession, pSession->ch, pOutput); + if (status == FwdLockConv_Status_OK) { + pSession->ch = base64Values[ch] << 4; + pSession->scannerState = FwdLockConv_ScannerState_WantsByte3; + } + } else if (ch == '\r') { + pSession->savedScannerState = pSession->scannerState; + pSession->scannerState = FwdLockConv_ScannerState_WantsLF; + } else if (!FwdLockConv_IsWhitespace(ch)) { + status = FwdLockConv_Status_SyntaxError; + } + break; + case FwdLockConv_ScannerState_WantsByte3: + if (FwdLockConv_IsBase64Char(ch)) { + pSession->ch |= base64Values[ch] >> 2; + status = FwdLockConv_WriteEncryptedChar(pSession, pSession->ch, pOutput); + if (status == FwdLockConv_Status_OK) { + pSession->ch = base64Values[ch] << 6; + pSession->scannerState = FwdLockConv_ScannerState_WantsByte4; + } + } else if (ch == '\r') { + pSession->savedScannerState = pSession->scannerState; + pSession->scannerState = FwdLockConv_ScannerState_WantsLF; + } else if (ch == '=') { + pSession->scannerState = FwdLockConv_ScannerState_WantsPadding; + } else if (!FwdLockConv_IsWhitespace(ch)) { + status = FwdLockConv_Status_SyntaxError; + } + break; + case FwdLockConv_ScannerState_WantsByte4: + if (FwdLockConv_IsBase64Char(ch)) { + pSession->ch |= base64Values[ch]; + status = FwdLockConv_WriteEncryptedChar(pSession, pSession->ch, pOutput); + if (status == FwdLockConv_Status_OK) { + pSession->scannerState = FwdLockConv_ScannerState_WantsByte1; + } + } else if (ch == '\r') { + pSession->savedScannerState = pSession->scannerState; + pSession->scannerState = FwdLockConv_ScannerState_WantsLF; + } else if (ch == '=') { + pSession->scannerState = FwdLockConv_ScannerState_WantsWhitespace; + } else if (!FwdLockConv_IsWhitespace(ch)) { + status = FwdLockConv_Status_SyntaxError; + } + break; + case FwdLockConv_ScannerState_WantsLF: + if (ch == '\n') { + pSession->scannerState = pSession->savedScannerState; + } else { + status = FwdLockConv_Status_SyntaxError; + } + break; + case FwdLockConv_ScannerState_WantsPadding: + if (ch == '=') { + pSession->scannerState = FwdLockConv_ScannerState_WantsWhitespace; + } else { + status = FwdLockConv_Status_SyntaxError; + } + break; + case FwdLockConv_ScannerState_WantsWhitespace: + case FwdLockConv_ScannerState_WantsWhitespace_AfterCRLF: + if (ch == '\r') { + pSession->savedScannerState = FwdLockConv_ScannerState_WantsWhitespace_AfterCRLF; + pSession->scannerState = FwdLockConv_ScannerState_WantsLF; + } else if (ch == '-') { + if (pSession->scannerState == FwdLockConv_ScannerState_WantsWhitespace_AfterCRLF) { + pSession->delimiterMatchPos = 3; + pSession->scannerState = FwdLockConv_ScannerState_WantsDelimiter; + } else { + status = FwdLockConv_Status_SyntaxError; + } + } else if (FwdLockConv_IsWhitespace(ch)) { + pSession->scannerState = FwdLockConv_ScannerState_WantsWhitespace; + } else { + status = FwdLockConv_Status_SyntaxError; + } + break; + case FwdLockConv_ScannerState_WantsDelimiter: + if (ch != pSession->delimiter[pSession->delimiterMatchPos]) { + status = FwdLockConv_Status_SyntaxError; + } else if (++pSession->delimiterMatchPos == pSession->delimiterLength) { + pSession->scannerState = FwdLockConv_ScannerState_WantsFirstDash; + } + break; + case FwdLockConv_ScannerState_WantsFirstDash: + if (ch == '-') { + pSession->scannerState = FwdLockConv_ScannerState_WantsSecondDash; + } else { + status = FwdLockConv_Status_SyntaxError; + } + break; + case FwdLockConv_ScannerState_WantsSecondDash: + if (ch == '-') { + pSession->parserState = FwdLockConv_ParserState_Done; + } else { + status = FwdLockConv_Status_SyntaxError; + } + break; + default: + status = FwdLockConv_Status_ProgramError; + break; + } + return status; +} + +/** + * Pushes a single character into the converter's state machine. + * + * @param[in,out] pSession A reference to a converter session. + * @param[in] ch A character. + * @param[in,out] pOutput The output from the conversion process. + * + * @return A status code. + */ +static FwdLockConv_Status_t FwdLockConv_PushChar(FwdLockConv_Session_t *pSession, + int ch, + FwdLockConv_Output_t *pOutput) { + FwdLockConv_Status_t status; + ++pSession->numCharsConsumed; + switch (pSession->parserState) { + case FwdLockConv_ParserState_WantsOpenDelimiter: + status = FwdLockConv_MatchOpenDelimiter(pSession, ch); + break; + case FwdLockConv_ParserState_WantsMimeHeaders: + status = FwdLockConv_MatchMimeHeaders(pSession, ch, pOutput); + break; + case FwdLockConv_ParserState_WantsBinaryEncodedData: + status = FwdLockConv_MatchBinaryEncodedData(pSession, ch, pOutput); + break; + case FwdLockConv_ParserState_WantsBase64EncodedData: + status = FwdLockConv_MatchBase64EncodedData(pSession, ch, pOutput); + break; + case FwdLockConv_ParserState_Done: + status = FwdLockConv_Status_OK; + break; + default: + status = FwdLockConv_Status_ProgramError; + break; + } + return status; +} + +FwdLockConv_Status_t FwdLockConv_OpenSession(int *pSessionId, FwdLockConv_Output_t *pOutput) { + FwdLockConv_Status_t status; + if (pSessionId == NULL || pOutput == NULL) { + status = FwdLockConv_Status_InvalidArgument; + } else { + *pSessionId = FwdLockConv_AcquireSession(); + if (*pSessionId < 0) { + status = FwdLockConv_Status_TooManySessions; + } else { + FwdLockConv_Session_t *pSession = sessionPtrs[*pSessionId]; + pSession->encryptedSessionKeyLength = FwdLockGlue_GetEncryptedKeyLength(KEY_SIZE); + if (pSession->encryptedSessionKeyLength < AES_BLOCK_SIZE) { + // The encrypted session key is used as the CTR-mode nonce, so it must be at least + // the size of a single AES block. + status = FwdLockConv_Status_ProgramError; + } else { + pSession->pEncryptedSessionKey = malloc(pSession->encryptedSessionKeyLength); + if (pSession->pEncryptedSessionKey == NULL) { + status = FwdLockConv_Status_OutOfMemory; + } else { + if (!FwdLockGlue_GetRandomNumber(pSession->sessionKey, KEY_SIZE)) { + status = FwdLockConv_Status_RandomNumberGenerationFailed; + } else if (!FwdLockGlue_EncryptKey(pSession->sessionKey, KEY_SIZE, + pSession->pEncryptedSessionKey, + pSession->encryptedSessionKeyLength)) { + status = FwdLockConv_Status_KeyEncryptionFailed; + } else { + status = FwdLockConv_DeriveKeys(pSession); + } + if (status == FwdLockConv_Status_OK) { + memset(pSession->sessionKey, 0, KEY_SIZE); // Zero out key data. + memcpy(pSession->counter, pSession->pEncryptedSessionKey, AES_BLOCK_SIZE); + pSession->parserState = FwdLockConv_ParserState_WantsOpenDelimiter; + pSession->scannerState = FwdLockConv_ScannerState_WantsFirstDash; + pSession->numCharsConsumed = 0; + pSession->delimiterMatchPos = 0; + pSession->mimeHeaderName = nullString; + pSession->contentType = nullString; + pSession->contentTransferEncoding = + FwdLockConv_ContentTransferEncoding_Undefined; + pSession->keyStreamIndex = -1; + pOutput->fromConvertData.pBuffer = NULL; + pOutput->fromConvertData.errorPos = INVALID_OFFSET; + } else { + free(pSession->pEncryptedSessionKey); + } + } + } + if (status != FwdLockConv_Status_OK) { + FwdLockConv_ReleaseSession(*pSessionId); + *pSessionId = -1; + } + } + } + return status; +} + +FwdLockConv_Status_t FwdLockConv_ConvertData(int sessionId, + const void *pBuffer, + size_t numBytes, + FwdLockConv_Output_t *pOutput) { + FwdLockConv_Status_t status; + if (!FwdLockConv_IsValidSession(sessionId) || pBuffer == NULL || pOutput == NULL) { + status = FwdLockConv_Status_InvalidArgument; + } else { + size_t i; + FwdLockConv_Session_t *pSession = sessionPtrs[sessionId]; + pSession->dataOffset = 0; + pSession->numDataBytes = 0; + pOutput->fromConvertData.numBytes = 0; + status = FwdLockConv_Status_OK; + + for (i = 0; i < numBytes; ++i) { + status = FwdLockConv_PushChar(pSession, ((char *)pBuffer)[i], pOutput); + if (status != FwdLockConv_Status_OK) { + break; + } + } + if (status == FwdLockConv_Status_OK) { + // Update the data signature. + HMAC_Update(&pSession->signingContext, + &((unsigned char *)pOutput->fromConvertData.pBuffer)[pSession->dataOffset], + pSession->numDataBytes); + } else if (status == FwdLockConv_Status_SyntaxError) { + pOutput->fromConvertData.errorPos = pSession->numCharsConsumed; + } + } + return status; +} + +FwdLockConv_Status_t FwdLockConv_CloseSession(int sessionId, FwdLockConv_Output_t *pOutput) { + FwdLockConv_Status_t status; + if (!FwdLockConv_IsValidSession(sessionId) || pOutput == NULL) { + status = FwdLockConv_Status_InvalidArgument; + } else { + FwdLockConv_Session_t *pSession = sessionPtrs[sessionId]; + free(pOutput->fromConvertData.pBuffer); + if (pSession->parserState != FwdLockConv_ParserState_Done) { + pOutput->fromCloseSession.errorPos = pSession->numCharsConsumed; + status = FwdLockConv_Status_SyntaxError; + } else { + // Finalize the data signature. + size_t signatureSize; + HMAC_Final(&pSession->signingContext, pOutput->fromCloseSession.signatures, + &signatureSize); + if (signatureSize != SHA1_HASH_SIZE) { + status = FwdLockConv_Status_ProgramError; + } else { + // Calculate the header signature, which is a signature of the rest of the header + // including the data signature. + HMAC_Init_ex(&pSession->signingContext, NULL, KEY_SIZE, NULL, NULL); + HMAC_Update(&pSession->signingContext, pSession->topHeader, TOP_HEADER_SIZE); + HMAC_Update(&pSession->signingContext, (unsigned char *)pSession->contentType.ptr, + pSession->contentType.length); + HMAC_Update(&pSession->signingContext, pSession->pEncryptedSessionKey, + pSession->encryptedSessionKeyLength); + HMAC_Update(&pSession->signingContext, pOutput->fromCloseSession.signatures, + signatureSize); + HMAC_Final(&pSession->signingContext, &pOutput->fromCloseSession. + signatures[signatureSize], &signatureSize); + if (signatureSize != SHA1_HASH_SIZE) { + status = FwdLockConv_Status_ProgramError; + } else { + pOutput->fromCloseSession.fileOffset = TOP_HEADER_SIZE + + pSession->contentType.length + pSession->encryptedSessionKeyLength; + status = FwdLockConv_Status_OK; + } + } + pOutput->fromCloseSession.errorPos = INVALID_OFFSET; + } + free(pSession->mimeHeaderName.ptr); + free(pSession->contentType.ptr); + free(pSession->pEncryptedSessionKey); + HMAC_CTX_cleanup(&pSession->signingContext); + FwdLockConv_ReleaseSession(sessionId); + } + return status; +} + +FwdLockConv_Status_t FwdLockConv_ConvertOpenFile(int inputFileDesc, + FwdLockConv_ReadFunc_t *fpReadFunc, + int outputFileDesc, + FwdLockConv_WriteFunc_t *fpWriteFunc, + FwdLockConv_LSeekFunc_t *fpLSeekFunc, + off64_t *pErrorPos) { + FwdLockConv_Status_t status; + if (pErrorPos != NULL) { + *pErrorPos = INVALID_OFFSET; + } + if (fpReadFunc == NULL || fpWriteFunc == NULL || fpLSeekFunc == NULL || inputFileDesc < 0 || + outputFileDesc < 0) { + status = FwdLockConv_Status_InvalidArgument; + } else { + char *pReadBuffer = malloc(READ_BUFFER_SIZE); + if (pReadBuffer == NULL) { + status = FwdLockConv_Status_OutOfMemory; + } else { + int sessionId; + FwdLockConv_Output_t output; + status = FwdLockConv_OpenSession(&sessionId, &output); + if (status == FwdLockConv_Status_OK) { + ssize_t numBytesRead; + FwdLockConv_Status_t closeStatus; + while ((numBytesRead = + fpReadFunc(inputFileDesc, pReadBuffer, READ_BUFFER_SIZE)) > 0) { + status = FwdLockConv_ConvertData(sessionId, pReadBuffer, (size_t)numBytesRead, + &output); + if (status == FwdLockConv_Status_OK) { + if (output.fromConvertData.pBuffer != NULL && + output.fromConvertData.numBytes > 0) { + ssize_t numBytesWritten = fpWriteFunc(outputFileDesc, + output.fromConvertData.pBuffer, + output.fromConvertData.numBytes); + if (numBytesWritten != (ssize_t)output.fromConvertData.numBytes) { + status = FwdLockConv_Status_FileWriteError; + break; + } + } + } else { + if (status == FwdLockConv_Status_SyntaxError && pErrorPos != NULL) { + *pErrorPos = output.fromConvertData.errorPos; + } + break; + } + } // end while + if (numBytesRead < 0) { + status = FwdLockConv_Status_FileReadError; + } + closeStatus = FwdLockConv_CloseSession(sessionId, &output); + if (status == FwdLockConv_Status_OK) { + if (closeStatus != FwdLockConv_Status_OK) { + if (closeStatus == FwdLockConv_Status_SyntaxError && pErrorPos != NULL) { + *pErrorPos = output.fromCloseSession.errorPos; + } + status = closeStatus; + } else if (fpLSeekFunc(outputFileDesc, output.fromCloseSession.fileOffset, + SEEK_SET) < 0) { + status = FwdLockConv_Status_FileSeekError; + } else if (fpWriteFunc(outputFileDesc, output.fromCloseSession.signatures, + FWD_LOCK_SIGNATURES_SIZE) != FWD_LOCK_SIGNATURES_SIZE) { + status = FwdLockConv_Status_FileWriteError; + } + } + } + free(pReadBuffer); + } + } + return status; +} + +FwdLockConv_Status_t FwdLockConv_ConvertFile(const char *pInputFilename, + const char *pOutputFilename, + off64_t *pErrorPos) { + FwdLockConv_Status_t status; + if (pErrorPos != NULL) { + *pErrorPos = INVALID_OFFSET; + } + if (pInputFilename == NULL || pOutputFilename == NULL) { + status = FwdLockConv_Status_InvalidArgument; + } else { + int inputFileDesc = open(pInputFilename, O_RDONLY); + if (inputFileDesc < 0) { + status = FwdLockConv_Status_FileNotFound; + } else { + int outputFileDesc = open(pOutputFilename, O_CREAT | O_TRUNC | O_WRONLY, + S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + if (outputFileDesc < 0) { + status = FwdLockConv_Status_FileCreationFailed; + } else { + status = FwdLockConv_ConvertOpenFile(inputFileDesc, read, outputFileDesc, write, + lseek64, pErrorPos); + if (close(outputFileDesc) == 0 && status != FwdLockConv_Status_OK) { + remove(pOutputFilename); + } + } + (void)close(inputFileDesc); + } + } + return status; +} diff --git a/drm/libdrmframework/plugins/forward-lock/internal-format/converter/FwdLockConv.h b/drm/libdrmframework/plugins/forward-lock/internal-format/converter/FwdLockConv.h new file mode 100644 index 0000000..e20c0c3 --- /dev/null +++ b/drm/libdrmframework/plugins/forward-lock/internal-format/converter/FwdLockConv.h @@ -0,0 +1,282 @@ +/* + * 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. + */ + +#ifndef __FWDLOCKCONV_H__ +#define __FWDLOCKCONV_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +/** + * The size of the data and header signatures combined. The signatures are adjacent to each other in + * the produced output file. + */ +#define FWD_LOCK_SIGNATURES_SIZE (2 * 20) + +/** + * Data type for the output from FwdLockConv_ConvertData. + */ +typedef struct FwdLockConv_ConvertData_Output { + /// The converted data. + void *pBuffer; + + /// The size of the converted data. + size_t numBytes; + + /// The file position where the error occurred, in the case of a syntax error. + off64_t errorPos; +} FwdLockConv_ConvertData_Output_t; + +/** + * Data type for the output from FwdLockConv_CloseSession. + */ +typedef struct FwdLockConv_CloseSession_Output { + /// The final set of signatures. + unsigned char signatures[FWD_LOCK_SIGNATURES_SIZE]; + + /// The offset in the produced output file where the signatures are located. + off64_t fileOffset; + + /// The file position where the error occurred, in the case of a syntax error. + off64_t errorPos; +} FwdLockConv_CloseSession_Output_t; + +/** + * Data type for the output from the conversion process. + */ +typedef union FwdLockConv_Output { + FwdLockConv_ConvertData_Output_t fromConvertData; + FwdLockConv_CloseSession_Output_t fromCloseSession; +} FwdLockConv_Output_t; + +/** + * Data type for the Posix-style read function used by the converter in pull mode. + * + * @param[in] fileDesc The file descriptor of a file opened for reading. + * @param[out] pBuffer A reference to the buffer that should receive the read data. + * @param[in] numBytes The number of bytes to read. + * + * @return The number of bytes read. + * @retval -1 Failure. + */ +typedef ssize_t FwdLockConv_ReadFunc_t(int fileDesc, void *pBuffer, size_t numBytes); + +/** + * Data type for the Posix-style write function used by the converter in pull mode. + * + * @param[in] fileDesc The file descriptor of a file opened for writing. + * @param[in] pBuffer A reference to the buffer containing the data to be written. + * @param[in] numBytes The number of bytes to write. + * + * @return The number of bytes written. + * @retval -1 Failure. + */ +typedef ssize_t FwdLockConv_WriteFunc_t(int fileDesc, const void *pBuffer, size_t numBytes); + +/** + * Data type for the Posix-style lseek function used by the converter in pull mode. + * + * @param[in] fileDesc The file descriptor of a file opened for writing. + * @param[in] offset The offset with which to update the file position. + * @param[in] whence One of SEEK_SET, SEEK_CUR, and SEEK_END. + * + * @return The new file position. + * @retval ((off64_t)-1) Failure. + */ +typedef off64_t FwdLockConv_LSeekFunc_t(int fileDesc, off64_t offset, int whence); + +/** + * The status codes returned by the converter functions. + */ +typedef enum FwdLockConv_Status { + /// The operation was successful. + FwdLockConv_Status_OK = 0, + + /// An actual argument to the function is invalid (a program error on the caller's part). + FwdLockConv_Status_InvalidArgument = 1, + + /// There is not enough free dynamic memory to complete the operation. + FwdLockConv_Status_OutOfMemory = 2, + + /// An error occurred while opening the input file. + FwdLockConv_Status_FileNotFound = 3, + + /// An error occurred while creating the output file. + FwdLockConv_Status_FileCreationFailed = 4, + + /// An error occurred while reading from the input file. + FwdLockConv_Status_FileReadError = 5, + + /// An error occurred while writing to the output file. + FwdLockConv_Status_FileWriteError = 6, + + /// An error occurred while seeking to a new file position within the output file. + FwdLockConv_Status_FileSeekError = 7, + + /// The input file is not a syntactically correct OMA DRM v1 Forward Lock file. + FwdLockConv_Status_SyntaxError = 8, + + /// Support for this DRM file format has been disabled in the current product configuration. + FwdLockConv_Status_UnsupportedFileFormat = 9, + + /// The content transfer encoding is not one of "binary", "base64", "7bit", or "8bit" + /// (case-insensitive). + FwdLockConv_Status_UnsupportedContentTransferEncoding = 10, + + /// The generation of a random number failed. + FwdLockConv_Status_RandomNumberGenerationFailed = 11, + + /// Key encryption failed. + FwdLockConv_Status_KeyEncryptionFailed = 12, + + /// The calculation of a keyed hash for integrity protection failed. + FwdLockConv_Status_IntegrityProtectionFailed = 13, + + /// There are too many ongoing sessions for another one to be opened. + FwdLockConv_Status_TooManySessions = 14, + + /// An unexpected error occurred. + FwdLockConv_Status_ProgramError = 15 +} FwdLockConv_Status_t; + +/** + * Opens a session for converting an OMA DRM v1 Forward Lock file to the internal Forward Lock file + * format. + * + * @param[out] pSessionId The session ID. + * @param[out] pOutput The output from the conversion process (initialized). + * + * @return A status code. + * @retval FwdLockConv_Status_OK + * @retval FwdLockConv_Status_InvalidArgument + * @retval FwdLockConv_Status_TooManySessions + */ +FwdLockConv_Status_t FwdLockConv_OpenSession(int *pSessionId, FwdLockConv_Output_t *pOutput); + +/** + * Supplies the converter with data to convert. The caller is expected to write the converted data + * to file. Can be called an arbitrary number of times. + * + * @param[in] sessionId The session ID. + * @param[in] pBuffer A reference to a buffer containing the data to convert. + * @param[in] numBytes The number of bytes to convert. + * @param[in,out] pOutput The output from the conversion process (allocated/reallocated). + * + * @return A status code. + * @retval FwdLockConv_Status_OK + * @retval FwdLockConv_Status_InvalidArgument + * @retval FwdLockConv_Status_OutOfMemory + * @retval FwdLockConv_Status_SyntaxError + * @retval FwdLockConv_Status_UnsupportedFileFormat + * @retval FwdLockConv_Status_UnsupportedContentTransferEncoding + * @retval FwdLockConv_Status_RandomNumberGenerationFailed + * @retval FwdLockConv_Status_KeyEncryptionFailed + * @retval FwdLockConv_Status_DataEncryptionFailed + */ +FwdLockConv_Status_t FwdLockConv_ConvertData(int sessionId, + const void *pBuffer, + size_t numBytes, + FwdLockConv_Output_t *pOutput); + +/** + * Closes a session for converting an OMA DRM v1 Forward Lock file to the internal Forward Lock + * file format. The caller must update the produced output file at the indicated file offset with + * the final set of signatures. + * + * @param[in] sessionId The session ID. + * @param[in,out] pOutput The output from the conversion process (deallocated and overwritten). + * + * @return A status code. + * @retval FwdLockConv_Status_OK + * @retval FwdLockConv_Status_InvalidArgument + * @retval FwdLockConv_Status_OutOfMemory + * @retval FwdLockConv_Status_IntegrityProtectionFailed + */ +FwdLockConv_Status_t FwdLockConv_CloseSession(int sessionId, FwdLockConv_Output_t *pOutput); + +/** + * Converts an open OMA DRM v1 Forward Lock file to the internal Forward Lock file format in pull + * mode. + * + * @param[in] inputFileDesc The file descriptor of the open input file. + * @param[in] fpReadFunc A reference to a read function that can operate on the open input file. + * @param[in] outputFileDesc The file descriptor of the open output file. + * @param[in] fpWriteFunc A reference to a write function that can operate on the open output file. + * @param[in] fpLSeekFunc A reference to an lseek function that can operate on the open output file. + * @param[out] pErrorPos + * The file position where the error occurred, in the case of a syntax error. May be NULL. + * + * @return A status code. + * @retval FwdLockConv_Status_OK + * @retval FwdLockConv_Status_InvalidArgument + * @retval FwdLockConv_Status_OutOfMemory + * @retval FwdLockConv_Status_FileReadError + * @retval FwdLockConv_Status_FileWriteError + * @retval FwdLockConv_Status_FileSeekError + * @retval FwdLockConv_Status_SyntaxError + * @retval FwdLockConv_Status_UnsupportedFileFormat + * @retval FwdLockConv_Status_UnsupportedContentTransferEncoding + * @retval FwdLockConv_Status_RandomNumberGenerationFailed + * @retval FwdLockConv_Status_KeyEncryptionFailed + * @retval FwdLockConv_Status_DataEncryptionFailed + * @retval FwdLockConv_Status_IntegrityProtectionFailed + * @retval FwdLockConv_Status_TooManySessions + */ +FwdLockConv_Status_t FwdLockConv_ConvertOpenFile(int inputFileDesc, + FwdLockConv_ReadFunc_t *fpReadFunc, + int outputFileDesc, + FwdLockConv_WriteFunc_t *fpWriteFunc, + FwdLockConv_LSeekFunc_t *fpLSeekFunc, + off64_t *pErrorPos); + +/** + * Converts an OMA DRM v1 Forward Lock file to the internal Forward Lock file format in pull mode. + * + * @param[in] pInputFilename A reference to the input filename. + * @param[in] pOutputFilename A reference to the output filename. + * @param[out] pErrorPos + * The file position where the error occurred, in the case of a syntax error. May be NULL. + * + * @return A status code. + * @retval FwdLockConv_Status_OK + * @retval FwdLockConv_Status_InvalidArgument + * @retval FwdLockConv_Status_OutOfMemory + * @retval FwdLockConv_Status_FileNotFound + * @retval FwdLockConv_Status_FileCreationFailed + * @retval FwdLockConv_Status_FileReadError + * @retval FwdLockConv_Status_FileWriteError + * @retval FwdLockConv_Status_FileSeekError + * @retval FwdLockConv_Status_SyntaxError + * @retval FwdLockConv_Status_UnsupportedFileFormat + * @retval FwdLockConv_Status_UnsupportedContentTransferEncoding + * @retval FwdLockConv_Status_RandomNumberGenerationFailed + * @retval FwdLockConv_Status_KeyEncryptionFailed + * @retval FwdLockConv_Status_DataEncryptionFailed + * @retval FwdLockConv_Status_IntegrityProtectionFailed + * @retval FwdLockConv_Status_TooManySessions + */ +FwdLockConv_Status_t FwdLockConv_ConvertFile(const char *pInputFilename, + const char *pOutputFilename, + off64_t *pErrorPos); + +#ifdef __cplusplus +} +#endif + +#endif // __FWDLOCKCONV_H__ diff --git a/drm/libdrmframework/plugins/forward-lock/internal-format/decoder/Android.mk b/drm/libdrmframework/plugins/forward-lock/internal-format/decoder/Android.mk new file mode 100644 index 0000000..b625edf --- /dev/null +++ b/drm/libdrmframework/plugins/forward-lock/internal-format/decoder/Android.mk @@ -0,0 +1,37 @@ +# +# 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 := \ + FwdLockFile.c + +LOCAL_C_INCLUDES := \ + frameworks/base/drm/libdrmframework/plugins/forward-lock/internal-format/common \ + external/openssl/include + +LOCAL_SHARED_LIBRARIES := libcrypto + +LOCAL_WHOLE_STATIC_LIBRARIES := libfwdlock-common + +LOCAL_STATIC_LIBRARIES := libfwdlock-common + +LOCAL_MODULE := libfwdlock-decoder + +LOCAL_MODULE_TAGS := optional + +include $(BUILD_STATIC_LIBRARY) diff --git a/drm/libdrmframework/plugins/forward-lock/internal-format/decoder/FwdLockFile.c b/drm/libdrmframework/plugins/forward-lock/internal-format/decoder/FwdLockFile.c new file mode 100644 index 0000000..98284e7 --- /dev/null +++ b/drm/libdrmframework/plugins/forward-lock/internal-format/decoder/FwdLockFile.c @@ -0,0 +1,447 @@ +/* + * 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 +#include + +#include "FwdLockFile.h" +#include "FwdLockGlue.h" + +#define TRUE 1 +#define FALSE 0 + +#define INVALID_OFFSET ((off64_t)-1) + +#define INVALID_BLOCK_INDEX ((uint64_t)-1) + +#define MAX_NUM_SESSIONS 128 + +#define KEY_SIZE AES_BLOCK_SIZE +#define KEY_SIZE_IN_BITS (KEY_SIZE * 8) + +#define SHA1_HASH_SIZE 20 +#define SHA1_BLOCK_SIZE 64 + +#define FWD_LOCK_VERSION 0 +#define FWD_LOCK_SUBFORMAT 0 +#define USAGE_RESTRICTION_FLAGS 0 +#define CONTENT_TYPE_LENGTH_POS 7 +#define TOP_HEADER_SIZE 8 + +#define SIG_CALC_BUFFER_SIZE (16 * SHA1_BLOCK_SIZE) + +/** + * Data type for the per-file state information needed by the decoder. + */ +typedef struct FwdLockFile_Session { + int fileDesc; + unsigned char topHeader[TOP_HEADER_SIZE]; + char *pContentType; + size_t contentTypeLength; + void *pEncryptedSessionKey; + size_t encryptedSessionKeyLength; + unsigned char dataSignature[SHA1_HASH_SIZE]; + unsigned char headerSignature[SHA1_HASH_SIZE]; + off64_t dataOffset; + off64_t filePos; + AES_KEY encryptionRoundKeys; + HMAC_CTX signingContext; + unsigned char keyStream[AES_BLOCK_SIZE]; + uint64_t blockIndex; +} FwdLockFile_Session_t; + +static FwdLockFile_Session_t *sessionPtrs[MAX_NUM_SESSIONS] = { NULL }; + +static pthread_mutex_t sessionAcquisitionMutex = PTHREAD_MUTEX_INITIALIZER; + +static const unsigned char topHeaderTemplate[] = + { 'F', 'W', 'L', 'K', FWD_LOCK_VERSION, FWD_LOCK_SUBFORMAT, USAGE_RESTRICTION_FLAGS }; + +/** + * Acquires an unused file session for the given file descriptor. + * + * @param[in] fileDesc A file descriptor. + * + * @return A session ID. + */ +static int FwdLockFile_AcquireSession(int fileDesc) { + int sessionId = -1; + if (fileDesc < 0) { + errno = EBADF; + } else { + int i; + pthread_mutex_lock(&sessionAcquisitionMutex); + for (i = 0; i < MAX_NUM_SESSIONS; ++i) { + int candidateSessionId = (fileDesc + i) % MAX_NUM_SESSIONS; + if (sessionPtrs[candidateSessionId] == NULL) { + sessionPtrs[candidateSessionId] = malloc(sizeof **sessionPtrs); + if (sessionPtrs[candidateSessionId] != NULL) { + sessionPtrs[candidateSessionId]->fileDesc = fileDesc; + sessionPtrs[candidateSessionId]->pContentType = NULL; + sessionPtrs[candidateSessionId]->pEncryptedSessionKey = NULL; + sessionId = candidateSessionId; + } + break; + } + } + pthread_mutex_unlock(&sessionAcquisitionMutex); + if (i == MAX_NUM_SESSIONS) { + errno = ENFILE; + } + } + return sessionId; +} + +/** + * Finds the file session associated to the given file descriptor. + * + * @param[in] fileDesc A file descriptor. + * + * @return A session ID. + */ +static int FwdLockFile_FindSession(int fileDesc) { + int sessionId = -1; + if (fileDesc < 0) { + errno = EBADF; + } else { + int i; + pthread_mutex_lock(&sessionAcquisitionMutex); + for (i = 0; i < MAX_NUM_SESSIONS; ++i) { + int candidateSessionId = (fileDesc + i) % MAX_NUM_SESSIONS; + if (sessionPtrs[candidateSessionId] != NULL && + sessionPtrs[candidateSessionId]->fileDesc == fileDesc) { + sessionId = candidateSessionId; + break; + } + } + pthread_mutex_unlock(&sessionAcquisitionMutex); + if (i == MAX_NUM_SESSIONS) { + errno = EBADF; + } + } + return sessionId; +} + +/** + * Releases a file session. + * + * @param[in] sessionID A session ID. + */ +static void FwdLockFile_ReleaseSession(int sessionId) { + pthread_mutex_lock(&sessionAcquisitionMutex); + assert(0 <= sessionId && sessionId < MAX_NUM_SESSIONS && sessionPtrs[sessionId] != NULL); + free(sessionPtrs[sessionId]->pContentType); + free(sessionPtrs[sessionId]->pEncryptedSessionKey); + memset(sessionPtrs[sessionId], 0, sizeof *sessionPtrs[sessionId]); // Zero out key data. + free(sessionPtrs[sessionId]); + sessionPtrs[sessionId] = NULL; + pthread_mutex_unlock(&sessionAcquisitionMutex); +} + +/** + * Derives keys for encryption and signing from the encrypted session key. + * + * @param[in,out] pSession A reference to a file session. + * + * @return A Boolean value indicating whether key derivation was successful. + */ +static int FwdLockFile_DeriveKeys(FwdLockFile_Session_t * pSession) { + int result; + struct FwdLockFile_DeriveKeys_Data { + AES_KEY sessionRoundKeys; + unsigned char value[KEY_SIZE]; + unsigned char key[KEY_SIZE]; + } *pData = malloc(sizeof *pData); + if (pData == NULL) { + result = FALSE; + } else { + result = FwdLockGlue_DecryptKey(pSession->pEncryptedSessionKey, + pSession->encryptedSessionKeyLength, pData->key, KEY_SIZE); + if (result) { + if (AES_set_encrypt_key(pData->key, KEY_SIZE_IN_BITS, &pData->sessionRoundKeys) != 0) { + result = FALSE; + } else { + // Encrypt the 16-byte value {0, 0, ..., 0} to produce the encryption key. + memset(pData->value, 0, KEY_SIZE); + AES_encrypt(pData->value, pData->key, &pData->sessionRoundKeys); + if (AES_set_encrypt_key(pData->key, KEY_SIZE_IN_BITS, + &pSession->encryptionRoundKeys) != 0) { + result = FALSE; + } else { + // Encrypt the 16-byte value {1, 0, ..., 0} to produce the signing key. + ++pData->value[0]; + AES_encrypt(pData->value, pData->key, &pData->sessionRoundKeys); + HMAC_CTX_init(&pSession->signingContext); + HMAC_Init_ex(&pSession->signingContext, pData->key, KEY_SIZE, EVP_sha1(), NULL); + } + } + } + if (!result) { + errno = ENOSYS; + } + memset(pData, 0, sizeof pData); // Zero out key data. + free(pData); + } + return result; +} + +/** + * Calculates the counter, treated as a 16-byte little-endian number, used to generate the keystream + * for the given block. + * + * @param[in] pNonce A reference to the nonce. + * @param[in] blockIndex The index number of the block. + * @param[out] pCounter A reference to the counter. + */ +static void FwdLockFile_CalculateCounter(const unsigned char *pNonce, + uint64_t blockIndex, + unsigned char *pCounter) { + unsigned char carry = 0; + size_t i = 0; + for (; i < sizeof blockIndex; ++i) { + unsigned char part = pNonce[i] + (unsigned char)(blockIndex >> (i * CHAR_BIT)); + pCounter[i] = part + carry; + carry = (part < pNonce[i] || pCounter[i] < part) ? 1 : 0; + } + for (; i < AES_BLOCK_SIZE; ++i) { + pCounter[i] = pNonce[i] + carry; + carry = (pCounter[i] < pNonce[i]) ? 1 : 0; + } +} + +/** + * Decrypts the byte at the current file position using AES-128-CTR. In CTR (or "counter") mode, + * encryption and decryption are performed using the same algorithm. + * + * @param[in,out] pSession A reference to a file session. + * @param[in] pByte The byte to decrypt. + */ +void FwdLockFile_DecryptByte(FwdLockFile_Session_t * pSession, unsigned char *pByte) { + uint64_t blockIndex = pSession->filePos / AES_BLOCK_SIZE; + uint64_t blockOffset = pSession->filePos % AES_BLOCK_SIZE; + if (blockIndex != pSession->blockIndex) { + // The first 16 bytes of the encrypted session key is used as the nonce. + unsigned char counter[AES_BLOCK_SIZE]; + FwdLockFile_CalculateCounter(pSession->pEncryptedSessionKey, blockIndex, counter); + AES_encrypt(counter, pSession->keyStream, &pSession->encryptionRoundKeys); + pSession->blockIndex = blockIndex; + } + *pByte ^= pSession->keyStream[blockOffset]; +} + +int FwdLockFile_attach(int fileDesc) { + int sessionId = FwdLockFile_AcquireSession(fileDesc); + if (sessionId >= 0) { + FwdLockFile_Session_t *pSession = sessionPtrs[sessionId]; + int isSuccess = FALSE; + if (read(fileDesc, pSession->topHeader, TOP_HEADER_SIZE) == TOP_HEADER_SIZE && + memcmp(pSession->topHeader, topHeaderTemplate, sizeof topHeaderTemplate) == 0) { + pSession->contentTypeLength = pSession->topHeader[CONTENT_TYPE_LENGTH_POS]; + assert(pSession->contentTypeLength <= UCHAR_MAX); // Untaint scalar for code checkers. + pSession->pContentType = malloc(pSession->contentTypeLength + 1); + if (pSession->pContentType != NULL && + read(fileDesc, pSession->pContentType, pSession->contentTypeLength) == + (ssize_t)pSession->contentTypeLength) { + pSession->pContentType[pSession->contentTypeLength] = '\0'; + pSession->encryptedSessionKeyLength = FwdLockGlue_GetEncryptedKeyLength(KEY_SIZE); + pSession->pEncryptedSessionKey = malloc(pSession->encryptedSessionKeyLength); + if (pSession->pEncryptedSessionKey != NULL && + read(fileDesc, pSession->pEncryptedSessionKey, + pSession->encryptedSessionKeyLength) == + (ssize_t)pSession->encryptedSessionKeyLength && + read(fileDesc, pSession->dataSignature, SHA1_HASH_SIZE) == + SHA1_HASH_SIZE && + read(fileDesc, pSession->headerSignature, SHA1_HASH_SIZE) == + SHA1_HASH_SIZE) { + isSuccess = FwdLockFile_DeriveKeys(pSession); + } + } + } + if (isSuccess) { + pSession->dataOffset = pSession->contentTypeLength + + pSession->encryptedSessionKeyLength + TOP_HEADER_SIZE + 2 * SHA1_HASH_SIZE; + pSession->filePos = 0; + pSession->blockIndex = INVALID_BLOCK_INDEX; + } else { + FwdLockFile_ReleaseSession(sessionId); + sessionId = -1; + } + } + return (sessionId >= 0) ? 0 : -1; +} + +int FwdLockFile_open(const char *pFilename) { + int fileDesc = open(pFilename, O_RDONLY); + if (fileDesc >= 0 && FwdLockFile_attach(fileDesc) < 0) { + (void)close(fileDesc); + fileDesc = -1; + } + return fileDesc; +} + +ssize_t FwdLockFile_read(int fileDesc, void *pBuffer, size_t numBytes) { + ssize_t numBytesRead; + int sessionId = FwdLockFile_FindSession(fileDesc); + if (sessionId < 0) { + numBytesRead = -1; + } else { + FwdLockFile_Session_t *pSession = sessionPtrs[sessionId]; + ssize_t i; + numBytesRead = read(pSession->fileDesc, pBuffer, numBytes); + for (i = 0; i < numBytesRead; ++i) { + FwdLockFile_DecryptByte(pSession, &((unsigned char *)pBuffer)[i]); + ++pSession->filePos; + } + } + return numBytesRead; +} + +off64_t FwdLockFile_lseek(int fileDesc, off64_t offset, int whence) { + off64_t newFilePos; + int sessionId = FwdLockFile_FindSession(fileDesc); + if (sessionId < 0) { + newFilePos = INVALID_OFFSET; + } else { + FwdLockFile_Session_t *pSession = sessionPtrs[sessionId]; + switch (whence) { + case SEEK_SET: + newFilePos = lseek64(pSession->fileDesc, pSession->dataOffset + offset, whence); + break; + case SEEK_CUR: + case SEEK_END: + newFilePos = lseek64(pSession->fileDesc, offset, whence); + break; + default: + errno = EINVAL; + newFilePos = INVALID_OFFSET; + break; + } + if (newFilePos != INVALID_OFFSET) { + if (newFilePos < pSession->dataOffset) { + // The new file position is illegal for an internal Forward Lock file. Restore the + // original file position. + (void)lseek64(pSession->fileDesc, pSession->dataOffset + pSession->filePos, + SEEK_SET); + errno = EINVAL; + newFilePos = INVALID_OFFSET; + } else { + // The return value should be the file position that lseek64() would have returned + // for the embedded content file. + pSession->filePos = newFilePos - pSession->dataOffset; + newFilePos = pSession->filePos; + } + } + } + return newFilePos; +} + +int FwdLockFile_detach(int fileDesc) { + int sessionId = FwdLockFile_FindSession(fileDesc); + if (sessionId < 0) { + return -1; + } + HMAC_CTX_cleanup(&sessionPtrs[sessionId]->signingContext); + FwdLockFile_ReleaseSession(sessionId); + return 0; +} + +int FwdLockFile_close(int fileDesc) { + return (FwdLockFile_detach(fileDesc) == 0) ? close(fileDesc) : -1; +} + +int FwdLockFile_CheckDataIntegrity(int fileDesc) { + int result; + int sessionId = FwdLockFile_FindSession(fileDesc); + if (sessionId < 0) { + result = FALSE; + } else { + struct FwdLockFile_CheckDataIntegrity_Data { + unsigned char signature[SHA1_HASH_SIZE]; + unsigned char buffer[SIG_CALC_BUFFER_SIZE]; + } *pData = malloc(sizeof *pData); + if (pData == NULL) { + result = FALSE; + } else { + FwdLockFile_Session_t *pSession = sessionPtrs[sessionId]; + if (lseek64(pSession->fileDesc, pSession->dataOffset, SEEK_SET) != + pSession->dataOffset) { + result = FALSE; + } else { + ssize_t numBytesRead; + size_t signatureSize = SHA1_HASH_SIZE; + while ((numBytesRead = + read(pSession->fileDesc, pData->buffer, SIG_CALC_BUFFER_SIZE)) > 0) { + HMAC_Update(&pSession->signingContext, pData->buffer, (size_t)numBytesRead); + } + if (numBytesRead < 0) { + result = FALSE; + } else { + HMAC_Final(&pSession->signingContext, pData->signature, &signatureSize); + assert(signatureSize == SHA1_HASH_SIZE); + result = memcmp(pData->signature, pSession->dataSignature, signatureSize) == 0; + } + HMAC_Init_ex(&pSession->signingContext, NULL, KEY_SIZE, NULL, NULL); + (void)lseek64(pSession->fileDesc, pSession->dataOffset + pSession->filePos, + SEEK_SET); + } + free(pData); + } + } + return result; +} + +int FwdLockFile_CheckHeaderIntegrity(int fileDesc) { + int result; + int sessionId = FwdLockFile_FindSession(fileDesc); + if (sessionId < 0) { + result = FALSE; + } else { + FwdLockFile_Session_t *pSession = sessionPtrs[sessionId]; + unsigned char signature[SHA1_HASH_SIZE]; + size_t signatureSize = SHA1_HASH_SIZE; + HMAC_Update(&pSession->signingContext, pSession->topHeader, TOP_HEADER_SIZE); + HMAC_Update(&pSession->signingContext, (unsigned char *)pSession->pContentType, + pSession->contentTypeLength); + HMAC_Update(&pSession->signingContext, pSession->pEncryptedSessionKey, + pSession->encryptedSessionKeyLength); + HMAC_Update(&pSession->signingContext, pSession->dataSignature, signatureSize); + HMAC_Final(&pSession->signingContext, signature, &signatureSize); + assert(signatureSize == SHA1_HASH_SIZE); + result = memcmp(signature, pSession->headerSignature, signatureSize) == 0; + HMAC_Init_ex(&pSession->signingContext, NULL, KEY_SIZE, NULL, NULL); + } + return result; +} + +int FwdLockFile_CheckIntegrity(int fileDesc) { + return FwdLockFile_CheckHeaderIntegrity(fileDesc) && FwdLockFile_CheckDataIntegrity(fileDesc); +} + +const char *FwdLockFile_GetContentType(int fileDesc) { + int sessionId = FwdLockFile_FindSession(fileDesc); + if (sessionId < 0) { + return NULL; + } + return sessionPtrs[sessionId]->pContentType; +} diff --git a/drm/libdrmframework/plugins/forward-lock/internal-format/decoder/FwdLockFile.h b/drm/libdrmframework/plugins/forward-lock/internal-format/decoder/FwdLockFile.h new file mode 100644 index 0000000..fc64050 --- /dev/null +++ b/drm/libdrmframework/plugins/forward-lock/internal-format/decoder/FwdLockFile.h @@ -0,0 +1,135 @@ +/* + * 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. + */ + +#ifndef __FWDLOCKFILE_H__ +#define __FWDLOCKFILE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +/** + * Attaches to an open Forward Lock file. The file position is assumed to be at the beginning of the + * file. + * + * @param[in] fileDesc The file descriptor of an open Forward Lock file. + * + * @return A status code. + * @retval 0 Success. + * @retval -1 Failure. + */ +int FwdLockFile_attach(int fileDesc); + +/** + * Opens a Forward Lock file for reading. + * + * @param[in] pFilename A reference to a filename. + * + * @return A file descriptor. + * @retval -1 Failure. + */ +int FwdLockFile_open(const char *pFilename); + +/** + * Reads the specified number of bytes from an open Forward Lock file. + * + * @param[in] fileDesc The file descriptor of an open Forward Lock file. + * @param[out] pBuffer A reference to the buffer that should receive the read data. + * @param[in] numBytes The number of bytes to read. + * + * @return The number of bytes read. + * @retval -1 Failure. + */ +ssize_t FwdLockFile_read(int fileDesc, void *pBuffer, size_t numBytes); + +/** + * Updates the file position within an open Forward Lock file. + * + * @param[in] fileDesc The file descriptor of an open Forward Lock file. + * @param[in] offset The offset with which to update the file position. + * @param[in] whence One of SEEK_SET, SEEK_CUR, and SEEK_END. + * + * @return The new file position. + * @retval ((off64_t)-1) Failure. + */ +off64_t FwdLockFile_lseek(int fileDesc, off64_t offset, int whence); + +/** + * Detaches from an open Forward Lock file. + * + * @param[in] fileDesc The file descriptor of an open Forward Lock file. + * + * @return A status code. + * @retval 0 Success. + * @retval -1 Failure. + */ +int FwdLockFile_detach(int fileDesc); + +/** + * Closes an open Forward Lock file. + * + * @param[in] fileDesc The file descriptor of an open Forward Lock file. + * + * @return A status code. + * @retval 0 Success. + * @retval -1 Failure. + */ +int FwdLockFile_close(int fileDesc); + +/** + * Checks the data integrity of an open Forward Lock file. + * + * @param[in] fileDesc The file descriptor of an open Forward Lock file. + * + * @return A Boolean value indicating whether the integrity check was successful. + */ +int FwdLockFile_CheckDataIntegrity(int fileDesc); + +/** + * Checks the header integrity of an open Forward Lock file. + * + * @param[in] fileDesc The file descriptor of an open Forward Lock file. + * + * @return A Boolean value indicating whether the integrity check was successful. + */ +int FwdLockFile_CheckHeaderIntegrity(int fileDesc); + +/** + * Checks both the data and header integrity of an open Forward Lock file. + * + * @param[in] fileDesc The file descriptor of an open Forward Lock file. + * + * @return A Boolean value indicating whether the integrity check was successful. + */ +int FwdLockFile_CheckIntegrity(int fileDesc); + +/** + * Returns the content type of an open Forward Lock file. + * + * @param[in] fileDesc The file descriptor of an open Forward Lock file. + * + * @return + * A reference to the content type. The reference remains valid as long as the file is kept open. + */ +const char *FwdLockFile_GetContentType(int fileDesc); + +#ifdef __cplusplus +} +#endif + +#endif // __FWDLOCKFILE_H__ diff --git a/drm/libdrmframework/plugins/forward-lock/internal-format/doc/FwdLock.html b/drm/libdrmframework/plugins/forward-lock/internal-format/doc/FwdLock.html new file mode 100755 index 0000000..8f95cd2 --- /dev/null +++ b/drm/libdrmframework/plugins/forward-lock/internal-format/doc/FwdLock.html @@ -0,0 +1,1039 @@ + + + + + +Forward Lock Converter and Decoder + + + + + + + + +
+
+ +
+ +

1      Introduction

+ +

The internal Forward Lock file format is used for encrypting +inherently unencrypted OMA DRM version 1 Forward Lock and Combined Delivery +files so they can be securely stored on externally accessible file system partitions +such as memory stick.

+ +

Our general strategy is to convert such OMA DRM Message +(‘.dm’) files to internal Forward Lock (‘.fl’) files as soon as they are +downloaded or otherwise transferred to the phone, and not actually provide any +decoders for ‘.dm’ files.

+ +

2      +Overview

+ +

The Forward Lock Converter converts OMA DRM Message +files to the internal file format. The Forward Lock Decoder provides a +POSIX-level API for transparent reading and seeking through such a converted +file as if it were unencrypted. The API also includes functions for checking a +file’s integrity and getting the MIME type of its embedded content.

+ +

The converter and decoder are +built into two separate libraries, which share common code for random number +generation and key encryption in a third library. For test purposes there is +also a unit test application. See Figure 1.

+ +

+ +

Figure 1. Block diagram illustrating the dependencies between the executable modules.

+ +
+
+ +

3      +Use Cases

+ +

This section describes all the use cases for the converter +and decoder. It shows the sequence of API calls that should be used to solve +these use cases.

+ +

3.1    +Converter

+ +

Through the converter API, conversion can be performed in one +of two ways:

+ +

1.      Push-mode +conversion is when the client progressively feeds data to the converter as +it arrives. This is appropriate when data arrives gradually in chunks, with +idle time in between. Consequently, push mode is used for converting files +being downloaded through HTTP. See section 3.1.1.

+ +

2.      Pull-mode +conversion is when the converter drives the process and consumes data from +the client as it needs it. This is appropriate when the entire file to be +converted is readily available. Hence, pull mode is used by the unit test application. +See section 3.1.2.

+ +

Internally, pull-mode conversion is implemented in terms +of the API for push-mode conversion.

+ +

3.1.1    Convert Data +(Push-Mode Conversion)

+ +

Push-mode conversion is performed as follows (see also Figure 2):

+ +

1.      FwdLockConv_OpenSession +initializes the output parameter and returns a session ID to be used in +subsequent calls to the API. The output parameter is a union of return values +whose correct use at any given moment is determined by the API function last +called.

+ +

2.      FwdLockConv_ConvertData +is called repeatedly until no more input data remains. Each call converts the +maximum amount of data possible and writes it to the output buffer. The client then +writes this data to file.

+ +

3.      FwdLockConv_CloseSession +cleans up the session and deallocates the output buffer. If all has gone well, a +two-part cryptographic signature of the output file is calculated. The client +must go back and rewrite part of the file header with this updated signature +information.

+ +

Every time a file is being converted, the converter calls FwdLockGlue_GetRandomNumber +to generate a new, unique session key. No two converted files look alike, even +if the original files are the same.

+ +

Note: The random bytes cannot come from any bare-minimum +implementation of the C-library rand +function—they must be cryptographically secure. Otherwise, security will be +compromised.

+ +

The session key is encrypted and stored within the +converted file. Key encryption is performed using FwdLockGlue_GetEncryptedKeyLength and FwdLockGlue_EncryptKey. +These two functions, together with the corresponding decryption function (FwdLockGlue_DecryptKey), +are the integration points where an OEM manufacturer may implement their own +key-encryption scheme.

+ +

Note: The key-encryption key must be unique to each +device; this is what makes the files forward lock–protected. Ideally, it should +be derived from secret hardware parameters, but at the very least it should be +persistent from one master reset to the next.

+ +
+ +

Note: In the open-source implementation of the libfwdlock-common +library, a random key-encryption key is generated and stored in plaintext in +the file system, without being obfuscated in any way (doing so would be futile +since the source code is openly available). This key must be kept secret from +the user, and shouldn’t be possible to extract through backup-and-restore +functionality or the like. OEM manufacturers will probably want to implement a +truly hardware-based device-unique key.

+ +
+ +

+ +

Figure 2. Converter UC: Convert Data.

+ +
+
+ +

3.1.2    Convert File +(Pull-Mode Conversion)

+ +

Pull-mode conversion is performed by calling FwdLockFile_ConvertFile +with the filename, unless there is need for a specialized read function, in +which case FwdLockFile_ConvertOpenFile +should be used directly instead. See Figure 3.

+ +

Internally, FwdLockFile_ConvertFile +calls FwdLockFile_ConvertOpenFile. +The latter then proceeds with the conversion using the push-mode API, acting as +the client in the previous use case; see section 3.1.1.

+ +

+ +

Figure 3. Converter UC: Convert File.

+ +
+
+ +

3.2    +Decoder

+ +

The decoder API allows the client to do the following:

+ +

1.      Check +the integrity of an internal Forward Lock file, i.e., detect whether it has +been manipulated in any way; see section 3.2.1.

+ +

2.      Get +the MIME type of the embedded content (the “original” MIME type before DRM protection +was applied); see section 3.2.2.

+ +

3.      Decode +the file by random access, i.e., read and seek through it in an arbitrary +manner; see section 3.2.3.

+ +

All subsequent operations on a file first require it to be +opened. Opening a file returns a file descriptor—a handle to be used in +these subsequent operations.

+ +

If the filename is known, an internal Forward Lock file +can be opened using FwdLockFile_open. +If only the file descriptor of an already open file is available, a decoding +session can instead be initialized using FwdLockFile_attach.

+ +

Internally, FwdLockFile_open calls FwdLockFile_attach. For efficiency +reasons, FwdLockFile_attach +therefore assumes that the file position is at the beginning of the file when +the function gets called. A client who calls it directly must make sure that +this assumption holds.

+ +

When a file is being attached, the session key stored in +the file during conversion is decrypted using FwdLockGlue_GetEncryptedKeyLength and FwdLockGlue_DecryptKey, +in order to set up for decoding and integrity checking.

+ +

For just getting the content type, however, retrieving the +session key would strictly speaking not be necessary, so there is an +opportunity here to optimize for that if it proves necessary later.

+ +

Symmetrical to FwdLockFile_open and FwdLockFile_attach, there are also functions +for closing a file or detaching from it:

+ +

1.      If +it was opened with FwdLockFile_open +it should be closed with FwdLockFile_close.

+ +

2.      If +it was attached with FwdLockFile_attach +it should be detached with FwdLockFile_detach.

+ +
+
+ +

3.2.1    Check Integrity

+ +

There are three methods for checking the integrity of an +internal Forward Lock file, in whole or in part (see also Figure 4):

+ +

1.      FwdLockFile_CheckDataIntegrity, +which checks the integrity of the encrypted content data.

+ +

2.      FwdLockFile_CheckHeaderIntegrity, +which checks the integrity of the file header, including the content type and +other fields not currently supported but reserved for future use.

+ +

3.      FwdLockFile_CheckIntegrity, +which internally calls first FwdLockFile_CheckHeaderIntegrity +and then FwdLockFile_CheckDataIntegrity.

+ +

FwdLockFile_CheckHeaderIntegrity is +generally much faster than FwdLockFile_CheckDataIntegrity, +whose running time is directly proportional to the size of the file.

+ +

+ +

Figure 4. Decoder UC: Check Integrity.

+ +
+
+ +

3.2.2    Get Content Type

+ +

FwdLockFile_GetContentType returns a +read-only reference to an ASCII string containing the MIME type of the +embedded content. This reference is valid as long as the file is kept open. +Clients who need access to the content type after closing the file should make +a copy of the string. See Figure 5 below.

+ +

+ +

Figure 5. Decoder UC: Get Content Type.

+ +
+
+ +

3.2.3    Decode File

+ +

After opening an internal Forward Lock file (or attaching +to an already open one), it can be transparently read from as if it were +unencrypted. Any number of calls to read data from the current file position or +set it to a new one (which is what lseek does) can be made in any order; this is what we +call random access. See Figure 6.

+ +

The Forward Lock Decoder versions of the read, lseek, and close functions +have the exact same signatures as their POSIX counterparts. So, for example, +the call FwdLockFile_lseek(fd, +0, SEEK_END) returns the size of the embedded content data, i.e., the +size of the original file before DRM protection.

+ +

Moreover, FwdLockFile_open +is like regular POSIX open +except it takes only the filename as a parameter—access is always read-only.

+ +

+ +

Figure 6. Decoder UC: Decode File.

+ +
+
+ +

4      +Definition of the Internal Forward Lock File Format

+ +

The inner structure of an internal +Forward Lock file is defined in Table 1 below.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

Offset [bytes]

+
+

Size [bytes]

+
+

Description

+
+

0

+
+

4

+
+

The file signature (so-called + magic number): a four-character code consisting of the letters + F-W-L-K.

+
+

4

+
+

1

+
+

Version number (0 for the + first version).

+
+

5

+
+

1

+
+

Indicates the subformat:

+

0x00 Forward Lock

+

0x01 Combined Delivery

+
+

6

+
+

1

+
+

Usage restriction flags (prohibitions + against usage as ringtone or as wallpaper and screen saver). Also indicates + if the file is bound to a specific SIM card.

+

0x00 No usage + restrictions

+

0x01 Ringtone usage + prohibited

+

0x02 Screen usage + prohibited

+

0x80 Bound to SIM

+

(Any number of these may be + OR-ed together.)

+
+

7

+
+

1

+
+

Length of the MIME content + type (k).

+
+

8

+
+

k

+
+

The MIME content type + (ASCII-encoded without null-character termination).

+
+

8+k

+
+

l = 0 or 16

+
+

If the subformat is + Combined Delivery, this field contains the auto-generated content ID (16 bytes). + If not, this field is zero-size.

+
+

8+k+l

+
+

m = 0 or 9

+
+

If the file is bound to a + specific SIM card, this field contains the 9-byte packed IMSI number. If not, + this field is zero-size.

+
+

8+k+l+m

+
+

n ≥ 16

+
+

The encrypted session key, the + first sixteen bytes of which are also used as the CTR-mode nonce (similar + to the CBC-mode initialization vector).

+
+

8+k+l+m+n

+
+

20

+
+

Data signature—the SHA-1 + HMAC of the encrypted content data.

+
+

28+k+l+m+n

+
+

20

+
+

Header signature—the SHA-1 + HMAC of all the fields above, including the encrypted session key and data + signature.

+
+

48+k+l+m+n

+
+

<to the end of the + file>

+
+

The content data encrypted + using 128-bit AES in CTR mode.

+
+ +

Table 1. Definition of the fields of an internal Forward Lock file.

+ +

As of now, neither Combined Delivery nor usage +restrictions (including SIM binding) are supported. These fields are reserved +for future use.

+ +

4.1    +Key Derivation

+ +

The session key consists of sixteen bytes fetched from a +cryptographically secure random number generator. From the session key, two +separate keys are derived: one used for encryption, the other for signing.

+ +

The encryption key is the output from encrypting the +16-byte all-zero input block {0, 0, …, 0} using 128-bit AES with the random session +key as the key. The signing key is the output from encrypting the 16-byte input +block {1, 0, …, 0} the same way. The keys so derived will be cryptographically +independent from each other.

+ +

The session key is encrypted using a hardware-dependent +key-encryption key unique to each device. The encrypted session key is stored +inside the file, and its first sixteen bytes are also used as the nonce +for the CTR-mode encryption of the content data.

+ +

4.2    +Calculation of the Counters

+ +

Using CTR (“counter”) mode, a block cipher such as AES can +be turned into a stream cipher. The process of encryption and decryption is +well defined in [1], except for the specifics of the calculation of the +counters. For the internal Forward Lock file format, the counters are +calculated as follows:

+ +

1.      The +nonce is interpreted as a 128-bit unsigned integer in little-endian format.

+ +

2.      The +zero-based block sequence number (also a little-endian unsigned integer) is +added modulo 2128 to the nonce to produce the counter for a given +block.

+ +

5      +Unit Test Cases

+ +

Unit test cases for the converter and decoder come in two +varieties:

+ +

1.      Black-box +test cases aim to verify that you get sensible results from malformed or +“tricky” input data.

+ +

2.      White-box +test cases aim to maximize code coverage using knowledge of code internals.

+ +

The black-box test cases are dependent on a specifically +designed set of input files found in the forward-lock/internal-format/test/res +directory in the repository. For ‘tests’ variants of the software, these input +files will be automatically installed in the file system image during build.

+ +

Run the test cases from the ADB shell command line as +follows:

+ +

# +gtest_fwdlock

+ +

If all black-box but no white-box test cases fail, the +input files probably can’t be found in the working directory.

+ +

6      +References

+ +

[1]           +Dworkin, +Morris: “Recommendation for Block Cipher Modes of Operation—Methods and +Techniques,” NIST Special Publication 800-38A, December 2001.

+ +
+ + + + diff --git a/drm/libdrmframework/plugins/forward-lock/internal-format/doc/images/image001.gif b/drm/libdrmframework/plugins/forward-lock/internal-format/doc/images/image001.gif new file mode 100644 index 0000000..ee94513 Binary files /dev/null and b/drm/libdrmframework/plugins/forward-lock/internal-format/doc/images/image001.gif differ diff --git a/drm/libdrmframework/plugins/forward-lock/internal-format/doc/images/image002.gif b/drm/libdrmframework/plugins/forward-lock/internal-format/doc/images/image002.gif new file mode 100644 index 0000000..8c12f46 Binary files /dev/null and b/drm/libdrmframework/plugins/forward-lock/internal-format/doc/images/image002.gif differ diff --git a/drm/libdrmframework/plugins/forward-lock/internal-format/doc/images/image003.gif b/drm/libdrmframework/plugins/forward-lock/internal-format/doc/images/image003.gif new file mode 100644 index 0000000..9e019ca Binary files /dev/null and b/drm/libdrmframework/plugins/forward-lock/internal-format/doc/images/image003.gif differ diff --git a/drm/libdrmframework/plugins/forward-lock/internal-format/doc/images/image004.gif b/drm/libdrmframework/plugins/forward-lock/internal-format/doc/images/image004.gif new file mode 100644 index 0000000..cae1d01 Binary files /dev/null and b/drm/libdrmframework/plugins/forward-lock/internal-format/doc/images/image004.gif differ diff --git a/drm/libdrmframework/plugins/forward-lock/internal-format/doc/images/image005.gif b/drm/libdrmframework/plugins/forward-lock/internal-format/doc/images/image005.gif new file mode 100644 index 0000000..0d87be9 Binary files /dev/null and b/drm/libdrmframework/plugins/forward-lock/internal-format/doc/images/image005.gif differ diff --git a/drm/libdrmframework/plugins/forward-lock/internal-format/doc/images/image006.gif b/drm/libdrmframework/plugins/forward-lock/internal-format/doc/images/image006.gif new file mode 100644 index 0000000..9445b6b Binary files /dev/null and b/drm/libdrmframework/plugins/forward-lock/internal-format/doc/images/image006.gif differ -- 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') 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 0a32d7981b98fdfca48a1e35ca746f1cc11849d3 Mon Sep 17 00:00:00 2001 From: Gloria Wang Date: Tue, 18 Jan 2011 15:23:51 -0800 Subject: rename /system/lib/drm/plugins/native/ to /system/lib/drm-plugin/ Change-Id: I043489cb81e53ed7cd5abd9769004da5ecd4d91d --- drm/libdrmframework/plugins/forward-lock/FwdLockEngine/Android.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drm') diff --git a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/Android.mk b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/Android.mk index d4a6f18..af67aa3 100644 --- a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/Android.mk +++ b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/Android.mk @@ -60,7 +60,7 @@ LOCAL_C_INCLUDES += \ $(LOCAL_PATH)/include \ external/openssl/include -LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/drm/plugins/native +LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/drm LOCAL_MODULE_TAGS := optional -- cgit v1.1 From 2ed8a921ef55aa2f3dd4b7ac33b7ded6ec33d92d Mon Sep 17 00:00:00 2001 From: Gloria Wang Date: Wed, 19 Jan 2011 15:38:16 -0800 Subject: More fix for 64 bit offset. Change-Id: Ia05060113ca0f43a4362914dc99c89c89e30eb4a --- drm/common/IDrmManagerService.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drm') diff --git a/drm/common/IDrmManagerService.cpp b/drm/common/IDrmManagerService.cpp index 75edac6..ddbd220 100644 --- a/drm/common/IDrmManagerService.cpp +++ b/drm/common/IDrmManagerService.cpp @@ -382,7 +382,7 @@ status_t BpDrmManagerService::setPlaybackStatus( } data.writeInt32(playbackStatus); - data.writeInt32(position); + data.writeInt64(position); remote()->transact(SET_PLAYBACK_STATUS, data, &reply); return reply.readInt32(); @@ -1111,7 +1111,7 @@ status_t BnDrmManagerService::onTransact( } const status_t status - = setPlaybackStatus(uniqueId, &handle, data.readInt32(), data.readInt32()); + = setPlaybackStatus(uniqueId, &handle, data.readInt32(), data.readInt64()); reply->writeInt32(status); delete handle.decryptInfo; handle.decryptInfo = NULL; -- cgit v1.1 From 44482001e106cfb7389110f869ddae381f8a2da7 Mon Sep 17 00:00:00 2001 From: Glenn Kasten Date: Fri, 21 Jan 2011 09:06:19 -0800 Subject: Bug 3361124 Remove drmioserver, continued Change-Id: I525b7a3ac1a79d3aaa1d3c7853df1c903b38b7c0 --- drm/common/Android.mk | 1 - drm/common/IDrmIOService.cpp | 74 ------------------------- drm/libdrmframework/include/DrmIOService.h | 46 --------------- drm/libdrmframework/include/IDrmIOService.h | 86 ----------------------------- 4 files changed, 207 deletions(-) delete mode 100644 drm/common/IDrmIOService.cpp delete mode 100644 drm/libdrmframework/include/DrmIOService.h delete mode 100644 drm/libdrmframework/include/IDrmIOService.h (limited to 'drm') diff --git a/drm/common/Android.mk b/drm/common/Android.mk index c79a91a..f1136c9 100644 --- a/drm/common/Android.mk +++ b/drm/common/Android.mk @@ -26,7 +26,6 @@ LOCAL_SRC_FILES:= \ DrmInfoStatus.cpp \ DrmRights.cpp \ DrmSupportInfo.cpp \ - IDrmIOService.cpp \ IDrmManagerService.cpp \ IDrmServiceListener.cpp \ DrmInfoEvent.cpp \ diff --git a/drm/common/IDrmIOService.cpp b/drm/common/IDrmIOService.cpp deleted file mode 100644 index e44ca55..0000000 --- a/drm/common/IDrmIOService.cpp +++ /dev/null @@ -1,74 +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 -#include -#include -#include -#include -#include "IDrmIOService.h" - -using namespace android; - -void BpDrmIOService::writeToFile(const String8& filePath, const String8& dataBuffer) { - Parcel data, reply; - - data.writeInterfaceToken(IDrmIOService::getInterfaceDescriptor()); - data.writeString8(filePath); - data.writeString8(dataBuffer); - - remote()->transact(WRITE_TO_FILE, data, &reply); -} - -String8 BpDrmIOService::readFromFile(const String8& filePath) { - - Parcel data, reply; - - data.writeInterfaceToken(IDrmIOService::getInterfaceDescriptor()); - data.writeString8(filePath); - - remote()->transact(READ_FROM_FILE, data, &reply); - return reply.readString8(); -} - -IMPLEMENT_META_INTERFACE(DrmIOService, "drm.IDrmIOService"); - -status_t BnDrmIOService::onTransact( - uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) { - - switch (code) { - case WRITE_TO_FILE: - { - CHECK_INTERFACE(IDrmIOService, data, reply); - - writeToFile(data.readString8(), data.readString8()); - return DRM_NO_ERROR; - } - - case READ_FROM_FILE: - { - CHECK_INTERFACE(IDrmIOService, data, reply); - - String8 dataBuffer = readFromFile(data.readString8()); - reply->writeString8(dataBuffer); - return DRM_NO_ERROR; - } - - default: - return BBinder::onTransact(code, data, reply, flags); - } -} - diff --git a/drm/libdrmframework/include/DrmIOService.h b/drm/libdrmframework/include/DrmIOService.h deleted file mode 100644 index 244124e..0000000 --- a/drm/libdrmframework/include/DrmIOService.h +++ /dev/null @@ -1,46 +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. - */ - -#ifndef __DRM_IO_SERVICE_H__ -#define __DRM_IO_SERVICE_H__ - -#include "IDrmIOService.h" - -namespace android { - -/** - * This is the implementation class for DRM IO service. - * - * The instance of this class is created while starting the DRM IO service. - * - */ -class DrmIOService : public BnDrmIOService { -public: - static void instantiate(); - -private: - DrmIOService(); - virtual ~DrmIOService(); - -public: - void writeToFile(const String8& filePath, const String8& dataBuffer); - String8 readFromFile(const String8& filePath); -}; - -}; - -#endif /* __DRM_IO_SERVICE_H__ */ - diff --git a/drm/libdrmframework/include/IDrmIOService.h b/drm/libdrmframework/include/IDrmIOService.h deleted file mode 100644 index 5e0d907..0000000 --- a/drm/libdrmframework/include/IDrmIOService.h +++ /dev/null @@ -1,86 +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. - */ - -#ifndef __IDRM_IO_SERVICE_H__ -#define __IDRM_IO_SERVICE_H__ - -#include -#include -#include - -namespace android { - -/** - * This is the interface class for DRM IO service. - * - */ -class IDrmIOService : public IInterface -{ -public: - enum { - WRITE_TO_FILE = IBinder::FIRST_CALL_TRANSACTION, - READ_FROM_FILE - }; - -public: - DECLARE_META_INTERFACE(DrmIOService); - -public: - /** - * Writes the data into the file path provided - * - * @param[in] filePath Path of the file - * @param[in] dataBuffer Data to write - */ - virtual void writeToFile(const String8& filePath, const String8& dataBuffer) = 0; - - /** - * Reads the data from the file path provided - * - * @param[in] filePath Path of the file - * @return Data read from the file - */ - virtual String8 readFromFile(const String8& filePath) = 0; -}; - -/** - * This is the Binder implementation class for DRM IO service. - */ -class BpDrmIOService: public BpInterface -{ -public: - BpDrmIOService(const sp& impl) - : BpInterface(impl) {} - - virtual void writeToFile(const String8& filePath, const String8& dataBuffer); - - virtual String8 readFromFile(const String8& filePath); -}; - -/** - * This is the Binder implementation class for DRM IO service. - */ -class BnDrmIOService: public BnInterface -{ -public: - virtual status_t onTransact( - uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags = 0); -}; - -}; - -#endif /* __IDRM_IO_SERVICE_H__ */ - -- cgit v1.1 From d4366e89e46317673a97516ee2d25768038dc444 Mon Sep 17 00:00:00 2001 From: Gloria Wang Date: Tue, 15 Feb 2011 10:34:26 -0800 Subject: - Update from Widevine - Bug fixes Change-Id: I494cfe145e7aad36f3d8c68841cab847487dd85b --- drm/libdrmframework/plugins/widevine/Android.mk | 48 ++ .../plugins/widevine/include/WVMDrmPlugin.h | 111 ++++ .../plugins/widevine/include/WVMLogging.h | 22 + .../plugins/widevine/src/WVMDrmPlugin.cpp | 726 +++++++++++++++++++++ .../plugins/widevine/src/WVMLogging.cpp | 25 + .../plugins/widevine/test/Android.mk | 32 + .../plugins/widevine/test/TestPlugin.cpp | 237 +++++++ drm/libdrmframework/plugins/widevine/test/kill.sh | 3 + 8 files changed, 1204 insertions(+) create mode 100644 drm/libdrmframework/plugins/widevine/Android.mk create mode 100644 drm/libdrmframework/plugins/widevine/include/WVMDrmPlugin.h create mode 100644 drm/libdrmframework/plugins/widevine/include/WVMLogging.h create mode 100644 drm/libdrmframework/plugins/widevine/src/WVMDrmPlugin.cpp create mode 100644 drm/libdrmframework/plugins/widevine/src/WVMLogging.cpp create mode 100644 drm/libdrmframework/plugins/widevine/test/Android.mk create mode 100644 drm/libdrmframework/plugins/widevine/test/TestPlugin.cpp create mode 100755 drm/libdrmframework/plugins/widevine/test/kill.sh (limited to 'drm') diff --git a/drm/libdrmframework/plugins/widevine/Android.mk b/drm/libdrmframework/plugins/widevine/Android.mk new file mode 100644 index 0000000..60c8fad --- /dev/null +++ b/drm/libdrmframework/plugins/widevine/Android.mk @@ -0,0 +1,48 @@ +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +ifeq ($(TARGET_ARCH),arm) + +LOCAL_SRC_FILES:= \ + src/WVMDrmPlugin.cpp \ + src/WVMLogging.cpp + +LOCAL_C_INCLUDES:= \ + bionic \ + bionic/libstdc++/include \ + external/stlport/stlport \ + vendor/widevine/proprietary/include \ + frameworks/base/drm/libdrmframework/plugins/widevine/include + +LOCAL_MODULE := libdrmwvmplugin +LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/drm + +LOCAL_STATIC_LIBRARIES := \ + libdrmframeworkcommon + +LOCAL_SHARED_LIBRARIES := \ + libutils \ + libcutils \ + libstlport \ + libz \ + libwvdrm \ + libWVStreamControlAPI + +ifeq ($(TARGET_SIMULATOR),true) + LOCAL_LDLIBS += -ldl +else + LOCAL_SHARED_LIBRARIES += libdl +endif + +LOCAL_PRELINK_MODULE := false + +LOCAL_C_INCLUDES += \ + $(TOP)/frameworks/base/drm/libdrmframework/include \ + $(TOP)/frameworks/base/drm/libdrmframework/plugins/common/include \ + $(TOP)/frameworks/base/include + +LOCAL_MODULE_TAGS := optional + +include $(BUILD_SHARED_LIBRARY) + +endif diff --git a/drm/libdrmframework/plugins/widevine/include/WVMDrmPlugin.h b/drm/libdrmframework/plugins/widevine/include/WVMDrmPlugin.h new file mode 100644 index 0000000..efce025 --- /dev/null +++ b/drm/libdrmframework/plugins/widevine/include/WVMDrmPlugin.h @@ -0,0 +1,111 @@ +/* + * Copyright (C) 2011 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. + */ + +#ifndef __WVMDRMPLUGIN_H__ +#define __WVMDRMPLUGIN_H__ + + +#include +#include + +#include "WVDRMPluginAPI.h" + + +namespace android { + + class WVMDrmPlugin : public DrmEngineBase + { + +public: + WVMDrmPlugin(); + virtual ~WVMDrmPlugin(); + +protected: + DrmConstraints* onGetConstraints(int uniqueId, const String8* path, int action); + + DrmMetadata* onGetMetadata(int uniqueId, const String8* path); + + status_t onInitialize(int uniqueId); + + status_t onSetOnInfoListener(int uniqueId, const IDrmEngine::OnInfoListener* infoListener); + + status_t onTerminate(int uniqueId); + + bool onCanHandle(int uniqueId, const String8& path); + + DrmInfoStatus* onProcessDrmInfo(int uniqueId, const DrmInfo* drmInfo); + + status_t onSaveRights(int uniqueId, const DrmRights& drmRights, + const String8& rightsPath, const String8& contentPath); + + DrmInfo* onAcquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest); + + String8 onGetOriginalMimeType(int uniqueId, const String8& path); + + int onGetDrmObjectType(int uniqueId, const String8& path, const String8& mimeType); + + int onCheckRightsStatus(int uniqueId, const String8& path, int action); + + status_t onConsumeRights(int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve); + + status_t onSetPlaybackStatus( + int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, off64_t position); + + bool onValidateAction( + int uniqueId, const String8& path, int action, const ActionDescription& description); + + status_t onRemoveRights(int uniqueId, const String8& path); + + status_t onRemoveAllRights(int uniqueId); + + status_t onOpenConvertSession(int uniqueId, int convertId); + + DrmConvertedStatus* onConvertData(int uniqueId, int convertId, const DrmBuffer* inputData); + + DrmConvertedStatus* onCloseConvertSession(int uniqueId, int convertId); + + DrmSupportInfo* onGetSupportInfo(int uniqueId); + + status_t onOpenDecryptSession(int uniqueId, DecryptHandle *decryptHandle, + int fd, off64_t offset, off64_t length); + + status_t onOpenDecryptSession(int uniqueId, DecryptHandle *decryptHandle, + const char *uri); + + status_t onCloseDecryptSession(int uniqueId, DecryptHandle* decryptHandle); + + status_t onInitializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, + int decryptUnitId, const DrmBuffer* headerInfo); + + status_t onDecrypt(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, + const DrmBuffer* encBuffer, DrmBuffer** decBuffer, + DrmBuffer *ivBuffer); + + + status_t onFinalizeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId); + + ssize_t onPread(int uniqueId, DecryptHandle* decryptHandle, + void* buffer, ssize_t numBytes, off64_t offset); + +private: + const IDrmEngine::OnInfoListener *mOnInfoListener; + WVDRMPluginAPI *mDrmPluginImpl; +}; + +}; + +#endif /* __WVMDRMPLUGIN__ */ + diff --git a/drm/libdrmframework/plugins/widevine/include/WVMLogging.h b/drm/libdrmframework/plugins/widevine/include/WVMLogging.h new file mode 100644 index 0000000..1e46c7a --- /dev/null +++ b/drm/libdrmframework/plugins/widevine/include/WVMLogging.h @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2011 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. + */ + +#ifndef __WVMLOGGING_H__ +#define __WVMLOGGING_H__ + +void android_printbuf(const char *buf); + +#endif diff --git a/drm/libdrmframework/plugins/widevine/src/WVMDrmPlugin.cpp b/drm/libdrmframework/plugins/widevine/src/WVMDrmPlugin.cpp new file mode 100644 index 0000000..b39599c --- /dev/null +++ b/drm/libdrmframework/plugins/widevine/src/WVMDrmPlugin.cpp @@ -0,0 +1,726 @@ +/* + * Copyright (C) 2011 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 "WVMDrmPlugIn" +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "WVMDrmPlugin.h" +#include "WVMLogging.h" +#include "AndroidHooks.h" + +using namespace std; +using namespace android; + + +// This extern "C" is mandatory to be managed by TPlugInManager +extern "C" IDrmEngine* create() { + return new WVMDrmPlugin(); +} + +// This extern "C" is mandatory to be managed by TPlugInManager +extern "C" void destroy(IDrmEngine* pPlugIn) { + delete pPlugIn; +} + +WVMDrmPlugin::WVMDrmPlugin() + : DrmEngineBase(), + mOnInfoListener(NULL), + mDrmPluginImpl(WVDRMPluginAPI::create()) +{ +} + +WVMDrmPlugin::~WVMDrmPlugin() { + WVDRMPluginAPI::destroy(mDrmPluginImpl); +} + + +/** + * Initialize plug-in + * + * @param[in] uniqueId Unique identifier for a session + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure + */ +status_t WVMDrmPlugin::onInitialize(int uniqueId) { + //LOGD("WVMDrmPlugin::onInitialize : %d", uniqueId); + AndroidSetLogCallout(android_printbuf); + return DRM_NO_ERROR; +} + +/** + * Terminate the plug-in + * and release resource bound to plug-in + * + * @param[in] uniqueId Unique identifier for a session + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure + */ +status_t WVMDrmPlugin::onTerminate(int uniqueId) { + //LOGD("WVMDrmPlugin::onTerminate : %d", uniqueId); + return DRM_NO_ERROR; +} + +/** + * Register a callback to be invoked when the caller required to + * receive necessary information + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] infoListener Listener + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure + */ +status_t WVMDrmPlugin::onSetOnInfoListener( + int uniqueId, const IDrmEngine::OnInfoListener* infoListener) { + //LOGD("WVMDrmPlugin::onSetOnInfoListener : %d", uniqueId); + mOnInfoListener = infoListener; + return DRM_NO_ERROR; +} + +/** + * Retrieves necessary information for registration, unregistration or rights + * acquisition information. + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] drmInfoRequest Request information to retrieve drmInfo + * @return DrmInfo + * instance as a result of processing given input + */ +DrmInfo* WVMDrmPlugin::onAcquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest) { + //LOGD("WVMDrmPlugin::onAcquireDrmInfo : %d", uniqueId); + DrmInfo* drmInfo = NULL; + + std::string assetPath; + + if (NULL != drmInfoRequest) { + switch(drmInfoRequest->getInfoType()) { + case DrmInfoRequest::TYPE_RIGHTS_ACQUISITION_INFO: { + + assetPath = drmInfoRequest->get(String8("WVAssetURIKey")).string(); + + WVCredentials credentials; + + // creates a data store object per each portal + credentials.portal = drmInfoRequest->get(String8("WVPortalKey")).string(); + if ( (assetPath.size() == 0) || (credentials.portal.size() == 0) ) { + LOGE("onAcquireDrmInfo: Empty asset path or portal string, must specify both"); + return NULL; + } + + std::string assetDbPath = drmInfoRequest->get(String8("WVAssetDBPathKey")).string(); + //LOGV("onAcquireDrmInfo: portal=%s, dsPath=%s", credentials.portal.c_str(), assetDbPath.c_str()); + + credentials.drmServerURL = drmInfoRequest->get(String8("WVDRMServerKey")).string(); + credentials.userData = drmInfoRequest->get(String8("WVCAUserDataKey")).string(); + credentials.deviceID = drmInfoRequest->get(String8("WVDeviceIDKey")).string(); + credentials.streamID = drmInfoRequest->get(String8("WVStreamIDKey")).string(); + + string systemIdStr = drmInfoRequest->get(String8("WVSystemIDKey")).string(); + string assetIdStr = drmInfoRequest->get(String8("WVAssetIDKey")).string(); + string keyIdStr = drmInfoRequest->get(String8("WVKeyIDKey")).string(); + + uint32_t systemId, assetId, keyId; + + if (!mDrmPluginImpl->AcquireDrmInfo(assetPath, credentials, assetDbPath, + systemIdStr, assetIdStr, keyIdStr, + &systemId, &assetId, &keyId)) + return NULL; + + + String8 dataString("dummy_acquistion_string"); + int length = dataString.length(); + char* data = NULL; + data = new char[length]; + memcpy(data, dataString.string(), length); + drmInfo = new DrmInfo(drmInfoRequest->getInfoType(), + DrmBuffer(data, length), drmInfoRequest->getMimeType()); + + // Sets additional drmInfo attributes + drmInfo->put(String8("WVAssetURIKey"), String8(assetPath.c_str())); + drmInfo->put(String8("WVDRMServerKey"), String8(credentials.drmServerURL.c_str())); + drmInfo->put(String8("WVAssetDbPathKey"), String8(assetDbPath.c_str())); + drmInfo->put(String8("WVPortalKey"), String8(credentials.portal.c_str())); + drmInfo->put(String8("WVCAUserDataKey"), String8(credentials.userData.c_str())); + drmInfo->put(String8("WVDeviceIDKey"), String8(credentials.deviceID.c_str())); + drmInfo->put(String8("WVStreamIDKey"), String8(credentials.streamID.c_str())); + + char buffer[16]; + sprintf(buffer, "%lu", (unsigned long)systemId); + drmInfo->put(String8("WVSystemIDKey"), String8(buffer)); + sprintf(buffer, "%lu", (unsigned long)assetId); + drmInfo->put(String8("WVAssetIDKey"), String8(buffer)); + sprintf(buffer, "%lu", (unsigned long)keyId); + drmInfo->put(String8("WVKeyIDKey"), String8(buffer)); + break; + } + case DrmInfoRequest::TYPE_REGISTRATION_INFO: + case DrmInfoRequest::TYPE_UNREGISTRATION_INFO: + case DrmInfoRequest::TYPE_RIGHTS_ACQUISITION_PROGRESS_INFO: { + LOGE("onAcquireDrmInfo: Unsupported DrmInfoRequest type %d", + drmInfoRequest->getInfoType()); + break; + } + default: { + LOGE("onAcquireDrmInfo: Unknown info type %d", drmInfoRequest->getInfoType()); + break; + } + } + } + return drmInfo; +} + +/** + * Executes given drm information based on its type + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] drmInfo Information needs to be processed + * @return DrmInfoStatus + * instance as a result of processing given input + */ +DrmInfoStatus* WVMDrmPlugin::onProcessDrmInfo(int uniqueId, const DrmInfo* drmInfo) { + //LOGD("WVMDrmPlugin::onProcessDrmInfo: %d", uniqueId); + + int status = DrmInfoStatus::STATUS_ERROR; + + if (NULL != drmInfo) { + if (drmInfo->getInfoType() == DrmInfoRequest::TYPE_RIGHTS_ACQUISITION_INFO) { + std::string assetPath = drmInfo->get(String8("WVAssetURIKey")).string(); + + if (mDrmPluginImpl->ProcessDrmInfo(assetPath)) + status = DrmInfoStatus::STATUS_OK; + } else { + LOGE("onProcessDrmInfo : drmInfo type %d not supported", drmInfo->getInfoType()); + } + } else { + LOGE("onProcessDrmInfo : drmInfo cannot be NULL"); + } + + String8 licenseString("dummy_license_string"); + const int bufferSize = licenseString.size(); + char* data = NULL; + data = new char[bufferSize]; + memcpy(data, licenseString.string(), bufferSize); + const DrmBuffer* buffer = new DrmBuffer(data, bufferSize); + DrmInfoStatus* drmInfoStatus = + new DrmInfoStatus(status, drmInfo->getInfoType(), buffer, drmInfo->getMimeType()); + + return drmInfoStatus; +} + +/** + * Get constraint information associated with input content + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] path Path of the protected content + * @param[in] action Actions defined such as, + * Action::DEFAULT, Action::PLAY, etc + * @return DrmConstraints + * key-value pairs of constraint are embedded in it + * @note + * In case of error, return NULL + */ +DrmConstraints* WVMDrmPlugin::onGetConstraints(int uniqueId, const String8* path, int action) +{ + //LOGD("WVMDrmPlugin::onGetConstraints : %d", uniqueId); + + if ( (Action::DEFAULT != action) && (Action::PLAY != action) ) { + LOGE("onGetConstraints : action %d not supported", action); + return NULL; + } + + uint32_t licenseDuration = 0; + uint32_t timeSincePlayback = 0; + uint32_t timeRemaining = 0; + + std::string assetPath(path->string()); + if (!mDrmPluginImpl->GetConstraints(assetPath, &timeSincePlayback, &timeRemaining, &licenseDuration)) + return NULL; + + DrmConstraints* drmConstraints = new DrmConstraints(); + char charValue[16]; // max uint32 = 0xffffffff + terminating char + + memset(charValue, 0, 16); + sprintf(charValue, "%lu", (unsigned long)timeSincePlayback); + drmConstraints->put(&(DrmConstraints::LICENSE_START_TIME), charValue); + + memset(charValue, 0, 16); + sprintf(charValue, "%lu", (unsigned long)timeRemaining); + drmConstraints->put(&(DrmConstraints::LICENSE_EXPIRY_TIME), charValue); + + memset(charValue, 0, 16); + sprintf(charValue, "%lu", (unsigned long)licenseDuration); + drmConstraints->put(&(DrmConstraints::LICENSE_AVAILABLE_TIME), charValue); + + return drmConstraints; +} + + +/** + * Returns the information about the Drm Engine capabilities which includes + * supported MimeTypes and file suffixes. + * + * @param[in] uniqueId Unique identifier for a session + * @return DrmSupportInfo + * instance which holds the capabilities of a plug-in + */ +DrmSupportInfo* WVMDrmPlugin::onGetSupportInfo(int uniqueId) { + //LOGD("WVMDrmPlugin::onGetSupportInfo : %d", uniqueId); + DrmSupportInfo* drmSupportInfo = new DrmSupportInfo(); + // Add mimetype's + drmSupportInfo->addMimeType(String8("video/wvm")); + // Add File Suffixes + drmSupportInfo->addFileSuffix(String8(".wvm")); + // Add plug-in description + drmSupportInfo->setDescription(String8("Widevine DRM plug-in")); + return drmSupportInfo; +} + +/** + * Get meta data from protected content + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] path Path of the protected content + * + * @return DrmMetadata + * key-value pairs of meta data; NULL if failed + */ +DrmMetadata* WVMDrmPlugin::onGetMetadata(int uniqueId, const String8* path) { + //LOGD("WVDrmPlugin::onGetMetadata returns NULL\n"); + return NULL; +} + +/** + * Save DRM rights to specified rights path + * and make association with content path + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] drmRights DrmRights to be saved + * @param[in] rightsPath File path where rights to be saved + * @param[in] contentPath File path where content was saved + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure + */ +status_t WVMDrmPlugin::onSaveRights(int uniqueId, const DrmRights& drmRights, + const String8& rightsPath, const String8& contentPath) { + //LOGD("WVMDrmPlugin::onSaveRights : %d", uniqueId); + return DRM_NO_ERROR; +} + +/** + * Get whether the given content can be handled by this plugin or not + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] path Path the protected object + * @return bool + * Returns true if this plugin can handle , false in case of not able to handle + */ +bool WVMDrmPlugin::onCanHandle(int uniqueId, const String8& path) { + //LOGD("WVMDrmPlugin::canHandle('%s') ", path.string()); + String8 extension = path.getPathExtension(); + extension.toLower(); + return (String8(".wvm") == extension); +} + +/** + * Retrieves the mime type embedded inside the original content + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] path Path of the protected content + * @return String8 + * Returns mime-type of the original content, such as "video/mpeg" + */ +String8 WVMDrmPlugin::onGetOriginalMimeType(int uniqueId, const String8& path) { + //LOGD("WVMDrmPlugin::onGetOriginalMimeType() : %d", uniqueId); + return String8("video/wvm"); +} + +/** + * Retrieves the type of the protected object (content, rights, etc..) + * using specified path or mimetype. At least one parameter should be non null + * to retrieve DRM object type + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] path Path of the content or null. + * @param[in] mimeType Mime type of the content or null. + * @return type of the DRM content, + * such as DrmObjectType::CONTENT, DrmObjectType::RIGHTS_OBJECT + */ +int WVMDrmPlugin::onGetDrmObjectType( + int uniqueId, const String8& path, const String8& mimeType) { + //LOGD("WVMDrmPlugin::onGetDrmObjectType() : %d", uniqueId); + return DrmObjectType::UNKNOWN; +} + +/** + * Check whether the given content has valid rights or not + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] path Path of the protected content + * @param[in] action Action to perform (Action::DEFAULT, Action::PLAY, etc) + * @return the status of the rights for the protected content, + * such as RightsStatus::RIGHTS_VALID, RightsStatus::RIGHTS_EXPIRED, etc. + */ +int WVMDrmPlugin::onCheckRightsStatus(int uniqueId, const String8& path, int action) { + //LOGD("WVMDrmPlugin::onCheckRightsStatus() : %d", uniqueId); + + if ( (Action::DEFAULT != action) && (Action::PLAY != action) ) { + LOGE("onCheckRightsStatus : action %d not supported", action); + return RightsStatus::RIGHTS_INVALID; + } + + std::string assetPath(path.string()); + int rightsStatus = mDrmPluginImpl->CheckRightsStatus(assetPath); + + switch(rightsStatus) { + case WVDRMPluginAPI::RIGHTS_INVALID: + return RightsStatus::RIGHTS_INVALID; + break; + case WVDRMPluginAPI::RIGHTS_EXPIRED: + return RightsStatus::RIGHTS_EXPIRED; + break; + case WVDRMPluginAPI::RIGHTS_VALID: + return RightsStatus::RIGHTS_VALID; + break; + case WVDRMPluginAPI::RIGHTS_NOT_ACQUIRED: + return RightsStatus::RIGHTS_NOT_ACQUIRED; + break; + } + return RightsStatus::RIGHTS_INVALID; +} + +/** + * Consumes the rights for a content. + * If the reserve parameter is true the rights is reserved until the same + * application calls this api again with the reserve parameter set to false. + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] decryptHandle Handle for the decryption session + * @param[in] action Action to perform. (Action::DEFAULT, Action::PLAY, etc) + * @param[in] reserve True if the rights should be reserved. + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure + */ +status_t WVMDrmPlugin::onConsumeRights(int uniqueId, DecryptHandle* decryptHandle, + int action, bool reserve) { + //LOGD("WVMDrmPlugin::onConsumeRights() : %d", uniqueId); + return DRM_NO_ERROR; +} + +/** + * Informs the DRM Engine about the playback actions performed on the DRM files. + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] decryptHandle Handle for the decryption session + * @param[in] playbackStatus Playback action (Playback::START, Playback::STOP, Playback::PAUSE) + * @param[in] position Position in the file (in milliseconds) where the start occurs. + * Only valid together with Playback::START. + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure + */ +status_t WVMDrmPlugin::onSetPlaybackStatus(int uniqueId, DecryptHandle* decryptHandle, + int playbackStatus, off64_t position) { + //LOGD("WVMDrmPlugin::onSetPlaybackStatus"); + + int op; + + switch(playbackStatus) { + case Playback::START: + op = WVDRMPluginAPI::PLAYBACK_START; + break; + case Playback::STOP: + op = WVDRMPluginAPI::PLAYBACK_STOP; + break; + case Playback::PAUSE: + op = WVDRMPluginAPI::PLAYBACK_PAUSE; + break; + default: + op = WVDRMPluginAPI::PLAYBACK_INVALID; + break; + } + + if (mDrmPluginImpl->SetPlaybackStatus(op, position)) + return DRM_NO_ERROR; + + return DRM_ERROR_UNKNOWN; +} + +/** + * Validates whether an action on the DRM content is allowed or not. + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] path Path of the protected content + * @param[in] action Action to validate (Action::PLAY, Action::TRANSFER, etc) + * @param[in] description Detailed description of the action + * @return true if the action is allowed. + */ +bool WVMDrmPlugin::onValidateAction(int uniqueId, const String8& path, + int action, const ActionDescription& description) { + //LOGD("WVMDrmPlugin::onValidateAction() : %d", uniqueId); + return true; +} + +/** + * Removes the rights associated with the given protected content + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] path Path of the protected content + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure + */ +status_t WVMDrmPlugin::onRemoveRights(int uniqueId, const String8& path) { + //LOGD("WVMDrmPlugin::onRemoveRights() : %d", uniqueId); + + std::string assetPath(path.string()); + if (mDrmPluginImpl->RemoveRights(assetPath)) + return DRM_NO_ERROR; + + return DRM_ERROR_UNKNOWN; +} + +/** + * Removes all the rights information of each plug-in associated with + * DRM framework. Will be used in master reset + * + * @param[in] uniqueId Unique identifier for a session + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure + */ +status_t WVMDrmPlugin::onRemoveAllRights(int uniqueId) { + //LOGD("WVMDrmPlugin::onRemoveAllRights() : %d", uniqueId); + + if (mDrmPluginImpl->RemoveAllRights()) + return DRM_NO_ERROR; + + return DRM_ERROR_UNKNOWN; +} + +/** + * Open the decrypt session to decrypt the given protected content + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] decryptHandle Handle for the current decryption session + * @param[in] fd File descriptor of the protected content to be decrypted + * @param[in] offset Start position of the content + * @param[in] length The length of the protected content + * @return + * DRM_ERROR_CANNOT_HANDLE for failure and DRM_NO_ERROR for success + */ +status_t WVMDrmPlugin::onOpenDecryptSession( + int uniqueId, DecryptHandle *decryptHandle, int fd, off64_t offset, off64_t length) +{ + status_t result = DRM_ERROR_CANNOT_HANDLE; + + //LOGD("onOpenDecryptSession: fd=%d, offset=%lld, length=%lld", fd, offset, length); + + char buffer[64 * 1024]; + int dupfd = dup(fd); + if (dupfd == -1) + return result; + + FILE *f = fdopen(dupfd, "rb"); + if (f) { + fseek(f, 0, SEEK_SET); + if (fread(buffer, 1, sizeof(buffer), f) != sizeof(buffer)) { + fclose(f); + return DRM_ERROR_CANNOT_HANDLE; + } + fclose(f); + } else { + close(dupfd); + return result; + } + + if (WV_IsWidevineMedia(buffer, sizeof(buffer))) { + //LOGD("WVMDrmPlugin::onOpenDecryptSession - WV_IsWidevineMedia: true"); + decryptHandle->mimeType = String8("video/wvm"); + decryptHandle->decryptApiType = DecryptApiType::WV_BASED; + decryptHandle->status = DRM_NO_ERROR; + decryptHandle->decryptInfo = NULL; + result = DRM_NO_ERROR; + } else { + //LOGD("WVMDrmPlugin::onOpenDecryptSession - not Widevine media"); + } + + return result; +} + +/** + * Open the decrypt session to decrypt the given protected content + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] decryptHandle Handle for the current decryption session + * @param[in] uri Path of the protected content to be decrypted + * @return + * DRM_ERROR_CANNOT_HANDLE for failure and DRM_NO_ERROR for success + */ +status_t WVMDrmPlugin::onOpenDecryptSession( + int uniqueId, DecryptHandle* decryptHandle, const char* uri) +{ + status_t result = DRM_ERROR_CANNOT_HANDLE; + + if (!uri) + return result; + + size_t len = strlen(uri); + + if ((len >= 4 && !strncmp(&uri[len - 4], ".wvm", 4)) || + (strstr(uri, ".wvm?") != NULL) || + (len >= 5 && !strncmp(&uri[len - 5], ".m3u8", 5)) || + (strstr(uri, ".m3u8?") != NULL)) + { + //LOGD("WVMDrmPlugin::onOpenDecryptSession(uri) : %d - match", uniqueId); + decryptHandle->mimeType = String8("video/wvm"); + decryptHandle->decryptApiType = DecryptApiType::WV_BASED; + decryptHandle->status = DRM_NO_ERROR; + decryptHandle->decryptInfo = NULL; + + mDrmPluginImpl->OpenSession(); + result = DRM_NO_ERROR; + } else { + //LOGD("WVMDrmPlugin::onOpenDecryptSession(uri) - not Widevine media"); + } + + + return result; +} + + +/** + * Close the decrypt session for the given handle + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] decryptHandle Handle for the decryption session + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure + */ +status_t WVMDrmPlugin::onCloseDecryptSession(int uniqueId, DecryptHandle* decryptHandle) { + //LOGD("WVMDrmPlugin::onCloseDecryptSession() : %d", uniqueId); + if (NULL != decryptHandle) { + if (NULL != decryptHandle->decryptInfo) { + delete decryptHandle->decryptInfo; decryptHandle->decryptInfo = NULL; + } + delete decryptHandle; decryptHandle = NULL; + } + mDrmPluginImpl->CloseSession(); + return DRM_NO_ERROR; +} + +/** + * Initialize decryption for the given unit of the protected content + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] decryptId Handle for the decryption session + * @param[in] decryptUnitId ID Specifies decryption unit, such as track ID + * @param[in] headerInfo Information for initializing decryption of this decrypUnit + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure + */ +status_t WVMDrmPlugin::onInitializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, + int decryptUnitId, const DrmBuffer* headerInfo) { + //LOGD("WVMDrmPlugin::onInitializeDecryptUnit(): %d", uniqueId); + if (!mDrmPluginImpl->Prepare(headerInfo->data, headerInfo->length)) + return DRM_ERROR_CANNOT_HANDLE; + + return DRM_NO_ERROR; +} + +/** + * Decrypt the protected content buffers for the given unit + * This method will be called any number of times, based on number of + * encrypted streams received from application. + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] decryptId Handle for the decryption session + * @param[in] decryptUnitId ID Specifies decryption unit, such as track ID + * @param[in] encBuffer Encrypted data block + * @param[out] decBuffer Decrypted data block + * @param[in] IV Optional buffer + * @return status_t + * Returns the error code for this API + * DRM_NO_ERROR for success, and one of DRM_ERROR_UNKNOWN, DRM_ERROR_LICENSE_EXPIRED + * DRM_ERROR_SESSION_NOT_OPENED, DRM_ERROR_DECRYPT_UNIT_NOT_INITIALIZED, + * DRM_ERROR_DECRYPT for failure. + */ +status_t WVMDrmPlugin::onDecrypt(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, + const DrmBuffer* encBuffer, DrmBuffer** decBuffer, + DrmBuffer *ivBuffer) +{ + //LOGD("WVMDrmPlugin::onDecrypt\n"); +#define AES_BLOCK_SIZE 16 + char iv[AES_BLOCK_SIZE]; + memcpy(iv, ivBuffer->data, sizeof(iv)); + + if (*decBuffer == NULL) + return DRM_ERROR_DECRYPT; + + (*decBuffer)->length = encBuffer->length; + + if (!mDrmPluginImpl->Operate(encBuffer->data, (*decBuffer)->data, encBuffer->length, iv)) { + (*decBuffer)->length = 0; + usleep(1000000); // prevent spinning + return DRM_ERROR_LICENSE_EXPIRED; + } + + return DRM_NO_ERROR; +} + +/** + * Finalize decryption for the given unit of the protected content + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] decryptHandle Handle for the decryption session + * @param[in] decryptUnitId ID Specifies decryption unit, such as track ID + * @return status_t + * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure + */ +status_t WVMDrmPlugin::onFinalizeDecryptUnit( + int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) { + //LOGD("WVMDrmPlugin::onFinalizeDecryptUnit() : %d", uniqueId); + return DRM_NO_ERROR; +} + +/** + * The following methods are not required for the Widevine DRM plugin + */ +ssize_t WVMDrmPlugin::onPread(int uniqueId, DecryptHandle* decryptHandle, + void* buffer, ssize_t numBytes, off64_t offset) { + return DRM_ERROR_UNKNOWN; +} + + +status_t WVMDrmPlugin::onOpenConvertSession(int uniqueId, int convertId) { + return DRM_ERROR_UNKNOWN; +} + +DrmConvertedStatus* WVMDrmPlugin::onConvertData( + int uniqueId, int convertId, const DrmBuffer* inputData) { + return NULL; +} + +DrmConvertedStatus* WVMDrmPlugin::onCloseConvertSession(int uniqueId, int convertId) { + return NULL; +} + + diff --git a/drm/libdrmframework/plugins/widevine/src/WVMLogging.cpp b/drm/libdrmframework/plugins/widevine/src/WVMLogging.cpp new file mode 100644 index 0000000..a3b9bd7 --- /dev/null +++ b/drm/libdrmframework/plugins/widevine/src/WVMLogging.cpp @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2011 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_TAG "WVMLogging" +#include +#include "WVMLogging.h" + +// Connect Widevine debug logging into Android logging + +void android_printbuf(const char *buf) +{ + LOGD("%s", buf); +} diff --git a/drm/libdrmframework/plugins/widevine/test/Android.mk b/drm/libdrmframework/plugins/widevine/test/Android.mk new file mode 100644 index 0000000..d3fa57c --- /dev/null +++ b/drm/libdrmframework/plugins/widevine/test/Android.mk @@ -0,0 +1,32 @@ +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_SRC_FILES:= \ + TestPlugin.cpp \ + ../src/WVMLogging.cpp + +LOCAL_C_INCLUDES+= \ + bionic \ + vendor/widevine/proprietary/include \ + external/stlport/stlport \ + frameworks/base/drm/libdrmframework/include \ + frameworks/base/drm/libdrmframework/plugins/common/include \ + frameworks/base/drm/libdrmframework/plugins/widevine/include + +LOCAL_SHARED_LIBRARIES := \ + libstlport \ + libwvdrm \ + liblog \ + libutils \ + libz \ + libdl + +LOCAL_STATIC_LIBRARIES := \ + libdrmframeworkcommon + +LOCAL_MODULE:=test-wvdrmplugin + +LOCAL_MODULE_TAGS := tests + +include $(BUILD_EXECUTABLE) + diff --git a/drm/libdrmframework/plugins/widevine/test/TestPlugin.cpp b/drm/libdrmframework/plugins/widevine/test/TestPlugin.cpp new file mode 100644 index 0000000..1942257 --- /dev/null +++ b/drm/libdrmframework/plugins/widevine/test/TestPlugin.cpp @@ -0,0 +1,237 @@ +/* + * Copyright (C) 2011 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 "WVMDrmPlugin.h" +#include "drm/DrmInfoRequest.h" +#include "drm/DrmInfoStatus.h" +#include "drm/DrmConstraints.h" +#include "drm/DrmInfo.h" + +using namespace android; +using namespace std; + +class WVMDrmPluginTest +{ +public: + WVMDrmPluginTest() {} + ~WVMDrmPluginTest() {} + + void TestAsset(IDrmEngine *plugin, String8 &url); + + void TestRemoveAllRights(IDrmEngine *plugin); + void TestAcquireRights(IDrmEngine *plugin, String8 &url); + void TestCheckRightsNotAcquired(IDrmEngine *plugin, String8 &url); + void TestCheckValidRights(IDrmEngine *plugin, String8 &url); + void TestGetConstraints(IDrmEngine *plugin, String8 &url); + void TestRemoveRights(IDrmEngine *plugin, String8 &url); + + // Tests + void Run(); +}; + +void WVMDrmPluginTest::Run() +{ + cout << "WVDrmPluginTest::Run" << endl; + const char *path = "/system/lib/drm/libdrmwvmplugin.so"; + void *handle = dlopen(path, RTLD_NOW); + if (handle == NULL) { + fprintf(stderr, "Can't open plugin: %s\n", path); + exit(-1); + } + + typedef IDrmEngine *(*create_t)(); + create_t creator = (create_t)dlsym(handle, "create"); + if (!creator) { + fprintf(stderr, "Can't find create method\n"); + exit(-1); + } + + typedef void (*destroy_t)(IDrmEngine *); + destroy_t destroyer = (destroy_t)dlsym(handle, "destroy"); + if (!destroyer) { + fprintf(stderr, "Can't find destroy method\n"); + exit(-1); + } + + // Basic test - see if we can instantiate the object and call a method + IDrmEngine *plugin = (*creator)(); + if (plugin->initialize(0) != DRM_NO_ERROR) { + fprintf(stderr, "onInitialize failed!\n"); + exit(-1); + } + + // Remote asset + String8 url; + url = String8("http://seawwws001.cdn.shibboleth.tv/videos/qa/adventures_d_ch_444169.wvm"); + TestAsset(plugin, url); + + // Local asset + url = String8("file:///sdcard/Widevine/trailers_d_ch_444169.wvm"); + TestAsset(plugin, url); + + // Remote asset with query parameters + url = String8("http://seawwws001.cdn.shibboleth.tv/videos/qa/adventures_d_ch_444169.wvm?a=b"); + TestAsset(plugin, url); + + // Shut down and clean up + if (plugin->terminate(0) != DRM_NO_ERROR) { + fprintf(stderr, "onTerminate failed!\n"); + exit(-1); + } + destroyer(plugin); + dlclose(handle); + printf("Test successful!\n"); + exit(0); +} + +void WVMDrmPluginTest::TestAcquireRights(IDrmEngine *plugin, String8 &url) +{ + cout << "WVDrmPluginTest::TestAcquireRights url=" << url << endl; + + String8 mimeType("video/wvm"); + DrmInfoRequest rightsAcquisitionInfo(DrmInfoRequest::TYPE_RIGHTS_ACQUISITION_INFO, mimeType); + rightsAcquisitionInfo.put(String8("WVDRMServerKey"), String8("http://wstfcps005.shibboleth.tv/widevine/cypherpc/cgi-bin/GetEMMs.cgi")); + rightsAcquisitionInfo.put(String8("WVAssetURIKey"), url); + rightsAcquisitionInfo.put(String8("WVDeviceIDKey"), String8("device1234")); + rightsAcquisitionInfo.put(String8("WVPortalKey"), String8("YouTube")); + + DrmInfo *info = plugin->acquireDrmInfo(0, &rightsAcquisitionInfo); + if (info == NULL) { + fprintf(stderr, "acquireDrmInfo failed!\n"); + exit(-1); + } + + DrmInfoStatus *status = plugin->processDrmInfo(0, info); + if (status == NULL || status->statusCode != DrmInfoStatus::STATUS_OK) { + fprintf(stderr, "processDrmInfo failed!\n"); + exit(-1); + } + + delete status; + delete info; +} + +void WVMDrmPluginTest::TestCheckRightsNotAcquired(IDrmEngine *plugin, String8 &url) +{ + cout << "WVDrmPluginTest::TestCheckRightsNotAcquired url=" << url << endl; + + if (plugin->checkRightsStatus(0, url, Action::DEFAULT) != RightsStatus::RIGHTS_NOT_ACQUIRED) { + fprintf(stderr, "checkRightsNotAcquired default action failed!\n"); + exit(-1); + } + + if (plugin->checkRightsStatus(0, url, Action::PLAY) != RightsStatus::RIGHTS_NOT_ACQUIRED) { + fprintf(stderr, "checkRightsNotAcquired failed!\n"); + exit(-1); + } +} + +void WVMDrmPluginTest::TestCheckValidRights(IDrmEngine *plugin, String8 &url) +{ + cout << "WVDrmPluginTest::TestCheckValidRights url=" << url << endl; + + if (plugin->checkRightsStatus(0, url, Action::DEFAULT) != RightsStatus::RIGHTS_VALID) { + fprintf(stderr, "checkValidRights default action failed!\n"); + exit(-1); + } + + if (plugin->checkRightsStatus(0, url, Action::PLAY) != RightsStatus::RIGHTS_VALID) { + fprintf(stderr, "checkValidRights play action failed!\n"); + exit(-1); + } +} + +void WVMDrmPluginTest::TestGetConstraints(IDrmEngine *plugin, String8 &url) +{ + cout << "WVDrmPluginTest::TestGetConstraints url=" << url << endl; + + DrmConstraints *constraints; + constraints = plugin->getConstraints(0, &url, Action::PLAY); + if (constraints == NULL) { + fprintf(stderr, "getConstraints returned NULL constraints!\n"); + exit(-1); + } + + if (constraints->getCount() != 3) { + fprintf(stderr, "getConstraints returned unexpected count!\n"); + exit(-1); + } + + if (constraints->get(DrmConstraints::LICENSE_START_TIME) == "") { + fprintf(stderr, "getConstraints returned unexpected count!\n"); + exit(-1); + } + + if (constraints->get(DrmConstraints::LICENSE_AVAILABLE_TIME) == "") { + fprintf(stderr, "getConstraints returned unexpected count!\n"); + exit(-1); + } + + if (constraints->get(DrmConstraints::LICENSE_EXPIRY_TIME) == "") { + fprintf(stderr, "getConstraints returned unexpected count!\n"); + exit(-1); + } + + delete constraints; +} + +void WVMDrmPluginTest::TestRemoveRights(IDrmEngine *plugin, String8 &url) +{ + cout << "WVDrmPluginTest::TestRemoveRights url=" << url << endl; + + status_t status = plugin->removeRights(0, url); + if (status != DRM_NO_ERROR) { + fprintf(stderr, "removeRights returned error: %d!\n", (int)status); + exit(-1); + } +} + +void WVMDrmPluginTest::TestRemoveAllRights(IDrmEngine *plugin) +{ + cout << "WVDrmPluginTest::TestRemoveAllRights" << endl; + + status_t status = plugin->removeAllRights(0); + if (status != DRM_NO_ERROR) { + fprintf(stderr, "removeAllRights returned error: %d!\n", (int)status); + exit(-1); + } +} + +void WVMDrmPluginTest::TestAsset(IDrmEngine *plugin, String8 &url) +{ + cout << "WVDrmPluginTest::TestAsset url=" << url << endl; + + TestAcquireRights(plugin, url); + TestCheckValidRights(plugin, url); + TestGetConstraints(plugin, url); + TestRemoveRights(plugin, url); + TestCheckRightsNotAcquired(plugin, url); + TestAcquireRights(plugin, url); + TestRemoveAllRights(plugin); + TestCheckRightsNotAcquired(plugin, url); +} + +int main(int argc, char **argv) +{ + // turn off some noisy printing in WVStreamControl + setenv("WV_SILENT", "true", 1); + WVMDrmPluginTest test; + test.Run(); +} diff --git a/drm/libdrmframework/plugins/widevine/test/kill.sh b/drm/libdrmframework/plugins/widevine/test/kill.sh new file mode 100755 index 0000000..acc7151 --- /dev/null +++ b/drm/libdrmframework/plugins/widevine/test/kill.sh @@ -0,0 +1,3 @@ +#!/bin/sh +PID=`adb shell ps | grep test-wvdrmplugin | awk '{print $2}'` +adb shell kill -9 $PID -- cgit v1.1 From 1de41a66e3e7b548ee44e6654580e5f6f7265b11 Mon Sep 17 00:00:00 2001 From: Gloria Wang Date: Fri, 18 Feb 2011 22:42:26 -0800 Subject: Move all Widevine code which have dependency on vendor modules to vendor/widevine Change-Id: If75bce539bae02117fb4f628be64e3a7363375e9 --- drm/libdrmframework/plugins/widevine/Android.mk | 48 -- .../plugins/widevine/include/WVMDrmPlugin.h | 111 ---- .../plugins/widevine/include/WVMLogging.h | 22 - .../plugins/widevine/src/WVMDrmPlugin.cpp | 726 --------------------- .../plugins/widevine/src/WVMLogging.cpp | 25 - .../plugins/widevine/test/Android.mk | 32 - .../plugins/widevine/test/TestPlugin.cpp | 237 ------- drm/libdrmframework/plugins/widevine/test/kill.sh | 3 - 8 files changed, 1204 deletions(-) delete mode 100644 drm/libdrmframework/plugins/widevine/Android.mk delete mode 100644 drm/libdrmframework/plugins/widevine/include/WVMDrmPlugin.h delete mode 100644 drm/libdrmframework/plugins/widevine/include/WVMLogging.h delete mode 100644 drm/libdrmframework/plugins/widevine/src/WVMDrmPlugin.cpp delete mode 100644 drm/libdrmframework/plugins/widevine/src/WVMLogging.cpp delete mode 100644 drm/libdrmframework/plugins/widevine/test/Android.mk delete mode 100644 drm/libdrmframework/plugins/widevine/test/TestPlugin.cpp delete mode 100755 drm/libdrmframework/plugins/widevine/test/kill.sh (limited to 'drm') diff --git a/drm/libdrmframework/plugins/widevine/Android.mk b/drm/libdrmframework/plugins/widevine/Android.mk deleted file mode 100644 index 60c8fad..0000000 --- a/drm/libdrmframework/plugins/widevine/Android.mk +++ /dev/null @@ -1,48 +0,0 @@ -LOCAL_PATH:= $(call my-dir) -include $(CLEAR_VARS) - -ifeq ($(TARGET_ARCH),arm) - -LOCAL_SRC_FILES:= \ - src/WVMDrmPlugin.cpp \ - src/WVMLogging.cpp - -LOCAL_C_INCLUDES:= \ - bionic \ - bionic/libstdc++/include \ - external/stlport/stlport \ - vendor/widevine/proprietary/include \ - frameworks/base/drm/libdrmframework/plugins/widevine/include - -LOCAL_MODULE := libdrmwvmplugin -LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/drm - -LOCAL_STATIC_LIBRARIES := \ - libdrmframeworkcommon - -LOCAL_SHARED_LIBRARIES := \ - libutils \ - libcutils \ - libstlport \ - libz \ - libwvdrm \ - libWVStreamControlAPI - -ifeq ($(TARGET_SIMULATOR),true) - LOCAL_LDLIBS += -ldl -else - LOCAL_SHARED_LIBRARIES += libdl -endif - -LOCAL_PRELINK_MODULE := false - -LOCAL_C_INCLUDES += \ - $(TOP)/frameworks/base/drm/libdrmframework/include \ - $(TOP)/frameworks/base/drm/libdrmframework/plugins/common/include \ - $(TOP)/frameworks/base/include - -LOCAL_MODULE_TAGS := optional - -include $(BUILD_SHARED_LIBRARY) - -endif diff --git a/drm/libdrmframework/plugins/widevine/include/WVMDrmPlugin.h b/drm/libdrmframework/plugins/widevine/include/WVMDrmPlugin.h deleted file mode 100644 index efce025..0000000 --- a/drm/libdrmframework/plugins/widevine/include/WVMDrmPlugin.h +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (C) 2011 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. - */ - -#ifndef __WVMDRMPLUGIN_H__ -#define __WVMDRMPLUGIN_H__ - - -#include -#include - -#include "WVDRMPluginAPI.h" - - -namespace android { - - class WVMDrmPlugin : public DrmEngineBase - { - -public: - WVMDrmPlugin(); - virtual ~WVMDrmPlugin(); - -protected: - DrmConstraints* onGetConstraints(int uniqueId, const String8* path, int action); - - DrmMetadata* onGetMetadata(int uniqueId, const String8* path); - - status_t onInitialize(int uniqueId); - - status_t onSetOnInfoListener(int uniqueId, const IDrmEngine::OnInfoListener* infoListener); - - status_t onTerminate(int uniqueId); - - bool onCanHandle(int uniqueId, const String8& path); - - DrmInfoStatus* onProcessDrmInfo(int uniqueId, const DrmInfo* drmInfo); - - status_t onSaveRights(int uniqueId, const DrmRights& drmRights, - const String8& rightsPath, const String8& contentPath); - - DrmInfo* onAcquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest); - - String8 onGetOriginalMimeType(int uniqueId, const String8& path); - - int onGetDrmObjectType(int uniqueId, const String8& path, const String8& mimeType); - - int onCheckRightsStatus(int uniqueId, const String8& path, int action); - - status_t onConsumeRights(int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve); - - status_t onSetPlaybackStatus( - int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, off64_t position); - - bool onValidateAction( - int uniqueId, const String8& path, int action, const ActionDescription& description); - - status_t onRemoveRights(int uniqueId, const String8& path); - - status_t onRemoveAllRights(int uniqueId); - - status_t onOpenConvertSession(int uniqueId, int convertId); - - DrmConvertedStatus* onConvertData(int uniqueId, int convertId, const DrmBuffer* inputData); - - DrmConvertedStatus* onCloseConvertSession(int uniqueId, int convertId); - - DrmSupportInfo* onGetSupportInfo(int uniqueId); - - status_t onOpenDecryptSession(int uniqueId, DecryptHandle *decryptHandle, - int fd, off64_t offset, off64_t length); - - status_t onOpenDecryptSession(int uniqueId, DecryptHandle *decryptHandle, - const char *uri); - - status_t onCloseDecryptSession(int uniqueId, DecryptHandle* decryptHandle); - - status_t onInitializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, - int decryptUnitId, const DrmBuffer* headerInfo); - - status_t onDecrypt(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, - const DrmBuffer* encBuffer, DrmBuffer** decBuffer, - DrmBuffer *ivBuffer); - - - status_t onFinalizeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId); - - ssize_t onPread(int uniqueId, DecryptHandle* decryptHandle, - void* buffer, ssize_t numBytes, off64_t offset); - -private: - const IDrmEngine::OnInfoListener *mOnInfoListener; - WVDRMPluginAPI *mDrmPluginImpl; -}; - -}; - -#endif /* __WVMDRMPLUGIN__ */ - diff --git a/drm/libdrmframework/plugins/widevine/include/WVMLogging.h b/drm/libdrmframework/plugins/widevine/include/WVMLogging.h deleted file mode 100644 index 1e46c7a..0000000 --- a/drm/libdrmframework/plugins/widevine/include/WVMLogging.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (C) 2011 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. - */ - -#ifndef __WVMLOGGING_H__ -#define __WVMLOGGING_H__ - -void android_printbuf(const char *buf); - -#endif diff --git a/drm/libdrmframework/plugins/widevine/src/WVMDrmPlugin.cpp b/drm/libdrmframework/plugins/widevine/src/WVMDrmPlugin.cpp deleted file mode 100644 index b39599c..0000000 --- a/drm/libdrmframework/plugins/widevine/src/WVMDrmPlugin.cpp +++ /dev/null @@ -1,726 +0,0 @@ -/* - * Copyright (C) 2011 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 "WVMDrmPlugIn" -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "WVMDrmPlugin.h" -#include "WVMLogging.h" -#include "AndroidHooks.h" - -using namespace std; -using namespace android; - - -// This extern "C" is mandatory to be managed by TPlugInManager -extern "C" IDrmEngine* create() { - return new WVMDrmPlugin(); -} - -// This extern "C" is mandatory to be managed by TPlugInManager -extern "C" void destroy(IDrmEngine* pPlugIn) { - delete pPlugIn; -} - -WVMDrmPlugin::WVMDrmPlugin() - : DrmEngineBase(), - mOnInfoListener(NULL), - mDrmPluginImpl(WVDRMPluginAPI::create()) -{ -} - -WVMDrmPlugin::~WVMDrmPlugin() { - WVDRMPluginAPI::destroy(mDrmPluginImpl); -} - - -/** - * Initialize plug-in - * - * @param[in] uniqueId Unique identifier for a session - * @return status_t - * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure - */ -status_t WVMDrmPlugin::onInitialize(int uniqueId) { - //LOGD("WVMDrmPlugin::onInitialize : %d", uniqueId); - AndroidSetLogCallout(android_printbuf); - return DRM_NO_ERROR; -} - -/** - * Terminate the plug-in - * and release resource bound to plug-in - * - * @param[in] uniqueId Unique identifier for a session - * @return status_t - * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure - */ -status_t WVMDrmPlugin::onTerminate(int uniqueId) { - //LOGD("WVMDrmPlugin::onTerminate : %d", uniqueId); - return DRM_NO_ERROR; -} - -/** - * Register a callback to be invoked when the caller required to - * receive necessary information - * - * @param[in] uniqueId Unique identifier for a session - * @param[in] infoListener Listener - * @return status_t - * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure - */ -status_t WVMDrmPlugin::onSetOnInfoListener( - int uniqueId, const IDrmEngine::OnInfoListener* infoListener) { - //LOGD("WVMDrmPlugin::onSetOnInfoListener : %d", uniqueId); - mOnInfoListener = infoListener; - return DRM_NO_ERROR; -} - -/** - * Retrieves necessary information for registration, unregistration or rights - * acquisition information. - * - * @param[in] uniqueId Unique identifier for a session - * @param[in] drmInfoRequest Request information to retrieve drmInfo - * @return DrmInfo - * instance as a result of processing given input - */ -DrmInfo* WVMDrmPlugin::onAcquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest) { - //LOGD("WVMDrmPlugin::onAcquireDrmInfo : %d", uniqueId); - DrmInfo* drmInfo = NULL; - - std::string assetPath; - - if (NULL != drmInfoRequest) { - switch(drmInfoRequest->getInfoType()) { - case DrmInfoRequest::TYPE_RIGHTS_ACQUISITION_INFO: { - - assetPath = drmInfoRequest->get(String8("WVAssetURIKey")).string(); - - WVCredentials credentials; - - // creates a data store object per each portal - credentials.portal = drmInfoRequest->get(String8("WVPortalKey")).string(); - if ( (assetPath.size() == 0) || (credentials.portal.size() == 0) ) { - LOGE("onAcquireDrmInfo: Empty asset path or portal string, must specify both"); - return NULL; - } - - std::string assetDbPath = drmInfoRequest->get(String8("WVAssetDBPathKey")).string(); - //LOGV("onAcquireDrmInfo: portal=%s, dsPath=%s", credentials.portal.c_str(), assetDbPath.c_str()); - - credentials.drmServerURL = drmInfoRequest->get(String8("WVDRMServerKey")).string(); - credentials.userData = drmInfoRequest->get(String8("WVCAUserDataKey")).string(); - credentials.deviceID = drmInfoRequest->get(String8("WVDeviceIDKey")).string(); - credentials.streamID = drmInfoRequest->get(String8("WVStreamIDKey")).string(); - - string systemIdStr = drmInfoRequest->get(String8("WVSystemIDKey")).string(); - string assetIdStr = drmInfoRequest->get(String8("WVAssetIDKey")).string(); - string keyIdStr = drmInfoRequest->get(String8("WVKeyIDKey")).string(); - - uint32_t systemId, assetId, keyId; - - if (!mDrmPluginImpl->AcquireDrmInfo(assetPath, credentials, assetDbPath, - systemIdStr, assetIdStr, keyIdStr, - &systemId, &assetId, &keyId)) - return NULL; - - - String8 dataString("dummy_acquistion_string"); - int length = dataString.length(); - char* data = NULL; - data = new char[length]; - memcpy(data, dataString.string(), length); - drmInfo = new DrmInfo(drmInfoRequest->getInfoType(), - DrmBuffer(data, length), drmInfoRequest->getMimeType()); - - // Sets additional drmInfo attributes - drmInfo->put(String8("WVAssetURIKey"), String8(assetPath.c_str())); - drmInfo->put(String8("WVDRMServerKey"), String8(credentials.drmServerURL.c_str())); - drmInfo->put(String8("WVAssetDbPathKey"), String8(assetDbPath.c_str())); - drmInfo->put(String8("WVPortalKey"), String8(credentials.portal.c_str())); - drmInfo->put(String8("WVCAUserDataKey"), String8(credentials.userData.c_str())); - drmInfo->put(String8("WVDeviceIDKey"), String8(credentials.deviceID.c_str())); - drmInfo->put(String8("WVStreamIDKey"), String8(credentials.streamID.c_str())); - - char buffer[16]; - sprintf(buffer, "%lu", (unsigned long)systemId); - drmInfo->put(String8("WVSystemIDKey"), String8(buffer)); - sprintf(buffer, "%lu", (unsigned long)assetId); - drmInfo->put(String8("WVAssetIDKey"), String8(buffer)); - sprintf(buffer, "%lu", (unsigned long)keyId); - drmInfo->put(String8("WVKeyIDKey"), String8(buffer)); - break; - } - case DrmInfoRequest::TYPE_REGISTRATION_INFO: - case DrmInfoRequest::TYPE_UNREGISTRATION_INFO: - case DrmInfoRequest::TYPE_RIGHTS_ACQUISITION_PROGRESS_INFO: { - LOGE("onAcquireDrmInfo: Unsupported DrmInfoRequest type %d", - drmInfoRequest->getInfoType()); - break; - } - default: { - LOGE("onAcquireDrmInfo: Unknown info type %d", drmInfoRequest->getInfoType()); - break; - } - } - } - return drmInfo; -} - -/** - * Executes given drm information based on its type - * - * @param[in] uniqueId Unique identifier for a session - * @param[in] drmInfo Information needs to be processed - * @return DrmInfoStatus - * instance as a result of processing given input - */ -DrmInfoStatus* WVMDrmPlugin::onProcessDrmInfo(int uniqueId, const DrmInfo* drmInfo) { - //LOGD("WVMDrmPlugin::onProcessDrmInfo: %d", uniqueId); - - int status = DrmInfoStatus::STATUS_ERROR; - - if (NULL != drmInfo) { - if (drmInfo->getInfoType() == DrmInfoRequest::TYPE_RIGHTS_ACQUISITION_INFO) { - std::string assetPath = drmInfo->get(String8("WVAssetURIKey")).string(); - - if (mDrmPluginImpl->ProcessDrmInfo(assetPath)) - status = DrmInfoStatus::STATUS_OK; - } else { - LOGE("onProcessDrmInfo : drmInfo type %d not supported", drmInfo->getInfoType()); - } - } else { - LOGE("onProcessDrmInfo : drmInfo cannot be NULL"); - } - - String8 licenseString("dummy_license_string"); - const int bufferSize = licenseString.size(); - char* data = NULL; - data = new char[bufferSize]; - memcpy(data, licenseString.string(), bufferSize); - const DrmBuffer* buffer = new DrmBuffer(data, bufferSize); - DrmInfoStatus* drmInfoStatus = - new DrmInfoStatus(status, drmInfo->getInfoType(), buffer, drmInfo->getMimeType()); - - return drmInfoStatus; -} - -/** - * Get constraint information associated with input content - * - * @param[in] uniqueId Unique identifier for a session - * @param[in] path Path of the protected content - * @param[in] action Actions defined such as, - * Action::DEFAULT, Action::PLAY, etc - * @return DrmConstraints - * key-value pairs of constraint are embedded in it - * @note - * In case of error, return NULL - */ -DrmConstraints* WVMDrmPlugin::onGetConstraints(int uniqueId, const String8* path, int action) -{ - //LOGD("WVMDrmPlugin::onGetConstraints : %d", uniqueId); - - if ( (Action::DEFAULT != action) && (Action::PLAY != action) ) { - LOGE("onGetConstraints : action %d not supported", action); - return NULL; - } - - uint32_t licenseDuration = 0; - uint32_t timeSincePlayback = 0; - uint32_t timeRemaining = 0; - - std::string assetPath(path->string()); - if (!mDrmPluginImpl->GetConstraints(assetPath, &timeSincePlayback, &timeRemaining, &licenseDuration)) - return NULL; - - DrmConstraints* drmConstraints = new DrmConstraints(); - char charValue[16]; // max uint32 = 0xffffffff + terminating char - - memset(charValue, 0, 16); - sprintf(charValue, "%lu", (unsigned long)timeSincePlayback); - drmConstraints->put(&(DrmConstraints::LICENSE_START_TIME), charValue); - - memset(charValue, 0, 16); - sprintf(charValue, "%lu", (unsigned long)timeRemaining); - drmConstraints->put(&(DrmConstraints::LICENSE_EXPIRY_TIME), charValue); - - memset(charValue, 0, 16); - sprintf(charValue, "%lu", (unsigned long)licenseDuration); - drmConstraints->put(&(DrmConstraints::LICENSE_AVAILABLE_TIME), charValue); - - return drmConstraints; -} - - -/** - * Returns the information about the Drm Engine capabilities which includes - * supported MimeTypes and file suffixes. - * - * @param[in] uniqueId Unique identifier for a session - * @return DrmSupportInfo - * instance which holds the capabilities of a plug-in - */ -DrmSupportInfo* WVMDrmPlugin::onGetSupportInfo(int uniqueId) { - //LOGD("WVMDrmPlugin::onGetSupportInfo : %d", uniqueId); - DrmSupportInfo* drmSupportInfo = new DrmSupportInfo(); - // Add mimetype's - drmSupportInfo->addMimeType(String8("video/wvm")); - // Add File Suffixes - drmSupportInfo->addFileSuffix(String8(".wvm")); - // Add plug-in description - drmSupportInfo->setDescription(String8("Widevine DRM plug-in")); - return drmSupportInfo; -} - -/** - * Get meta data from protected content - * - * @param[in] uniqueId Unique identifier for a session - * @param[in] path Path of the protected content - * - * @return DrmMetadata - * key-value pairs of meta data; NULL if failed - */ -DrmMetadata* WVMDrmPlugin::onGetMetadata(int uniqueId, const String8* path) { - //LOGD("WVDrmPlugin::onGetMetadata returns NULL\n"); - return NULL; -} - -/** - * Save DRM rights to specified rights path - * and make association with content path - * - * @param[in] uniqueId Unique identifier for a session - * @param[in] drmRights DrmRights to be saved - * @param[in] rightsPath File path where rights to be saved - * @param[in] contentPath File path where content was saved - * @return status_t - * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure - */ -status_t WVMDrmPlugin::onSaveRights(int uniqueId, const DrmRights& drmRights, - const String8& rightsPath, const String8& contentPath) { - //LOGD("WVMDrmPlugin::onSaveRights : %d", uniqueId); - return DRM_NO_ERROR; -} - -/** - * Get whether the given content can be handled by this plugin or not - * - * @param[in] uniqueId Unique identifier for a session - * @param[in] path Path the protected object - * @return bool - * Returns true if this plugin can handle , false in case of not able to handle - */ -bool WVMDrmPlugin::onCanHandle(int uniqueId, const String8& path) { - //LOGD("WVMDrmPlugin::canHandle('%s') ", path.string()); - String8 extension = path.getPathExtension(); - extension.toLower(); - return (String8(".wvm") == extension); -} - -/** - * Retrieves the mime type embedded inside the original content - * - * @param[in] uniqueId Unique identifier for a session - * @param[in] path Path of the protected content - * @return String8 - * Returns mime-type of the original content, such as "video/mpeg" - */ -String8 WVMDrmPlugin::onGetOriginalMimeType(int uniqueId, const String8& path) { - //LOGD("WVMDrmPlugin::onGetOriginalMimeType() : %d", uniqueId); - return String8("video/wvm"); -} - -/** - * Retrieves the type of the protected object (content, rights, etc..) - * using specified path or mimetype. At least one parameter should be non null - * to retrieve DRM object type - * - * @param[in] uniqueId Unique identifier for a session - * @param[in] path Path of the content or null. - * @param[in] mimeType Mime type of the content or null. - * @return type of the DRM content, - * such as DrmObjectType::CONTENT, DrmObjectType::RIGHTS_OBJECT - */ -int WVMDrmPlugin::onGetDrmObjectType( - int uniqueId, const String8& path, const String8& mimeType) { - //LOGD("WVMDrmPlugin::onGetDrmObjectType() : %d", uniqueId); - return DrmObjectType::UNKNOWN; -} - -/** - * Check whether the given content has valid rights or not - * - * @param[in] uniqueId Unique identifier for a session - * @param[in] path Path of the protected content - * @param[in] action Action to perform (Action::DEFAULT, Action::PLAY, etc) - * @return the status of the rights for the protected content, - * such as RightsStatus::RIGHTS_VALID, RightsStatus::RIGHTS_EXPIRED, etc. - */ -int WVMDrmPlugin::onCheckRightsStatus(int uniqueId, const String8& path, int action) { - //LOGD("WVMDrmPlugin::onCheckRightsStatus() : %d", uniqueId); - - if ( (Action::DEFAULT != action) && (Action::PLAY != action) ) { - LOGE("onCheckRightsStatus : action %d not supported", action); - return RightsStatus::RIGHTS_INVALID; - } - - std::string assetPath(path.string()); - int rightsStatus = mDrmPluginImpl->CheckRightsStatus(assetPath); - - switch(rightsStatus) { - case WVDRMPluginAPI::RIGHTS_INVALID: - return RightsStatus::RIGHTS_INVALID; - break; - case WVDRMPluginAPI::RIGHTS_EXPIRED: - return RightsStatus::RIGHTS_EXPIRED; - break; - case WVDRMPluginAPI::RIGHTS_VALID: - return RightsStatus::RIGHTS_VALID; - break; - case WVDRMPluginAPI::RIGHTS_NOT_ACQUIRED: - return RightsStatus::RIGHTS_NOT_ACQUIRED; - break; - } - return RightsStatus::RIGHTS_INVALID; -} - -/** - * Consumes the rights for a content. - * If the reserve parameter is true the rights is reserved until the same - * application calls this api again with the reserve parameter set to false. - * - * @param[in] uniqueId Unique identifier for a session - * @param[in] decryptHandle Handle for the decryption session - * @param[in] action Action to perform. (Action::DEFAULT, Action::PLAY, etc) - * @param[in] reserve True if the rights should be reserved. - * @return status_t - * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure - */ -status_t WVMDrmPlugin::onConsumeRights(int uniqueId, DecryptHandle* decryptHandle, - int action, bool reserve) { - //LOGD("WVMDrmPlugin::onConsumeRights() : %d", uniqueId); - return DRM_NO_ERROR; -} - -/** - * Informs the DRM Engine about the playback actions performed on the DRM files. - * - * @param[in] uniqueId Unique identifier for a session - * @param[in] decryptHandle Handle for the decryption session - * @param[in] playbackStatus Playback action (Playback::START, Playback::STOP, Playback::PAUSE) - * @param[in] position Position in the file (in milliseconds) where the start occurs. - * Only valid together with Playback::START. - * @return status_t - * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure - */ -status_t WVMDrmPlugin::onSetPlaybackStatus(int uniqueId, DecryptHandle* decryptHandle, - int playbackStatus, off64_t position) { - //LOGD("WVMDrmPlugin::onSetPlaybackStatus"); - - int op; - - switch(playbackStatus) { - case Playback::START: - op = WVDRMPluginAPI::PLAYBACK_START; - break; - case Playback::STOP: - op = WVDRMPluginAPI::PLAYBACK_STOP; - break; - case Playback::PAUSE: - op = WVDRMPluginAPI::PLAYBACK_PAUSE; - break; - default: - op = WVDRMPluginAPI::PLAYBACK_INVALID; - break; - } - - if (mDrmPluginImpl->SetPlaybackStatus(op, position)) - return DRM_NO_ERROR; - - return DRM_ERROR_UNKNOWN; -} - -/** - * Validates whether an action on the DRM content is allowed or not. - * - * @param[in] uniqueId Unique identifier for a session - * @param[in] path Path of the protected content - * @param[in] action Action to validate (Action::PLAY, Action::TRANSFER, etc) - * @param[in] description Detailed description of the action - * @return true if the action is allowed. - */ -bool WVMDrmPlugin::onValidateAction(int uniqueId, const String8& path, - int action, const ActionDescription& description) { - //LOGD("WVMDrmPlugin::onValidateAction() : %d", uniqueId); - return true; -} - -/** - * Removes the rights associated with the given protected content - * - * @param[in] uniqueId Unique identifier for a session - * @param[in] path Path of the protected content - * @return status_t - * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure - */ -status_t WVMDrmPlugin::onRemoveRights(int uniqueId, const String8& path) { - //LOGD("WVMDrmPlugin::onRemoveRights() : %d", uniqueId); - - std::string assetPath(path.string()); - if (mDrmPluginImpl->RemoveRights(assetPath)) - return DRM_NO_ERROR; - - return DRM_ERROR_UNKNOWN; -} - -/** - * Removes all the rights information of each plug-in associated with - * DRM framework. Will be used in master reset - * - * @param[in] uniqueId Unique identifier for a session - * @return status_t - * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure - */ -status_t WVMDrmPlugin::onRemoveAllRights(int uniqueId) { - //LOGD("WVMDrmPlugin::onRemoveAllRights() : %d", uniqueId); - - if (mDrmPluginImpl->RemoveAllRights()) - return DRM_NO_ERROR; - - return DRM_ERROR_UNKNOWN; -} - -/** - * Open the decrypt session to decrypt the given protected content - * - * @param[in] uniqueId Unique identifier for a session - * @param[in] decryptHandle Handle for the current decryption session - * @param[in] fd File descriptor of the protected content to be decrypted - * @param[in] offset Start position of the content - * @param[in] length The length of the protected content - * @return - * DRM_ERROR_CANNOT_HANDLE for failure and DRM_NO_ERROR for success - */ -status_t WVMDrmPlugin::onOpenDecryptSession( - int uniqueId, DecryptHandle *decryptHandle, int fd, off64_t offset, off64_t length) -{ - status_t result = DRM_ERROR_CANNOT_HANDLE; - - //LOGD("onOpenDecryptSession: fd=%d, offset=%lld, length=%lld", fd, offset, length); - - char buffer[64 * 1024]; - int dupfd = dup(fd); - if (dupfd == -1) - return result; - - FILE *f = fdopen(dupfd, "rb"); - if (f) { - fseek(f, 0, SEEK_SET); - if (fread(buffer, 1, sizeof(buffer), f) != sizeof(buffer)) { - fclose(f); - return DRM_ERROR_CANNOT_HANDLE; - } - fclose(f); - } else { - close(dupfd); - return result; - } - - if (WV_IsWidevineMedia(buffer, sizeof(buffer))) { - //LOGD("WVMDrmPlugin::onOpenDecryptSession - WV_IsWidevineMedia: true"); - decryptHandle->mimeType = String8("video/wvm"); - decryptHandle->decryptApiType = DecryptApiType::WV_BASED; - decryptHandle->status = DRM_NO_ERROR; - decryptHandle->decryptInfo = NULL; - result = DRM_NO_ERROR; - } else { - //LOGD("WVMDrmPlugin::onOpenDecryptSession - not Widevine media"); - } - - return result; -} - -/** - * Open the decrypt session to decrypt the given protected content - * - * @param[in] uniqueId Unique identifier for a session - * @param[in] decryptHandle Handle for the current decryption session - * @param[in] uri Path of the protected content to be decrypted - * @return - * DRM_ERROR_CANNOT_HANDLE for failure and DRM_NO_ERROR for success - */ -status_t WVMDrmPlugin::onOpenDecryptSession( - int uniqueId, DecryptHandle* decryptHandle, const char* uri) -{ - status_t result = DRM_ERROR_CANNOT_HANDLE; - - if (!uri) - return result; - - size_t len = strlen(uri); - - if ((len >= 4 && !strncmp(&uri[len - 4], ".wvm", 4)) || - (strstr(uri, ".wvm?") != NULL) || - (len >= 5 && !strncmp(&uri[len - 5], ".m3u8", 5)) || - (strstr(uri, ".m3u8?") != NULL)) - { - //LOGD("WVMDrmPlugin::onOpenDecryptSession(uri) : %d - match", uniqueId); - decryptHandle->mimeType = String8("video/wvm"); - decryptHandle->decryptApiType = DecryptApiType::WV_BASED; - decryptHandle->status = DRM_NO_ERROR; - decryptHandle->decryptInfo = NULL; - - mDrmPluginImpl->OpenSession(); - result = DRM_NO_ERROR; - } else { - //LOGD("WVMDrmPlugin::onOpenDecryptSession(uri) - not Widevine media"); - } - - - return result; -} - - -/** - * Close the decrypt session for the given handle - * - * @param[in] uniqueId Unique identifier for a session - * @param[in] decryptHandle Handle for the decryption session - * @return status_t - * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure - */ -status_t WVMDrmPlugin::onCloseDecryptSession(int uniqueId, DecryptHandle* decryptHandle) { - //LOGD("WVMDrmPlugin::onCloseDecryptSession() : %d", uniqueId); - if (NULL != decryptHandle) { - if (NULL != decryptHandle->decryptInfo) { - delete decryptHandle->decryptInfo; decryptHandle->decryptInfo = NULL; - } - delete decryptHandle; decryptHandle = NULL; - } - mDrmPluginImpl->CloseSession(); - return DRM_NO_ERROR; -} - -/** - * Initialize decryption for the given unit of the protected content - * - * @param[in] uniqueId Unique identifier for a session - * @param[in] decryptId Handle for the decryption session - * @param[in] decryptUnitId ID Specifies decryption unit, such as track ID - * @param[in] headerInfo Information for initializing decryption of this decrypUnit - * @return status_t - * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure - */ -status_t WVMDrmPlugin::onInitializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, - int decryptUnitId, const DrmBuffer* headerInfo) { - //LOGD("WVMDrmPlugin::onInitializeDecryptUnit(): %d", uniqueId); - if (!mDrmPluginImpl->Prepare(headerInfo->data, headerInfo->length)) - return DRM_ERROR_CANNOT_HANDLE; - - return DRM_NO_ERROR; -} - -/** - * Decrypt the protected content buffers for the given unit - * This method will be called any number of times, based on number of - * encrypted streams received from application. - * - * @param[in] uniqueId Unique identifier for a session - * @param[in] decryptId Handle for the decryption session - * @param[in] decryptUnitId ID Specifies decryption unit, such as track ID - * @param[in] encBuffer Encrypted data block - * @param[out] decBuffer Decrypted data block - * @param[in] IV Optional buffer - * @return status_t - * Returns the error code for this API - * DRM_NO_ERROR for success, and one of DRM_ERROR_UNKNOWN, DRM_ERROR_LICENSE_EXPIRED - * DRM_ERROR_SESSION_NOT_OPENED, DRM_ERROR_DECRYPT_UNIT_NOT_INITIALIZED, - * DRM_ERROR_DECRYPT for failure. - */ -status_t WVMDrmPlugin::onDecrypt(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, - const DrmBuffer* encBuffer, DrmBuffer** decBuffer, - DrmBuffer *ivBuffer) -{ - //LOGD("WVMDrmPlugin::onDecrypt\n"); -#define AES_BLOCK_SIZE 16 - char iv[AES_BLOCK_SIZE]; - memcpy(iv, ivBuffer->data, sizeof(iv)); - - if (*decBuffer == NULL) - return DRM_ERROR_DECRYPT; - - (*decBuffer)->length = encBuffer->length; - - if (!mDrmPluginImpl->Operate(encBuffer->data, (*decBuffer)->data, encBuffer->length, iv)) { - (*decBuffer)->length = 0; - usleep(1000000); // prevent spinning - return DRM_ERROR_LICENSE_EXPIRED; - } - - return DRM_NO_ERROR; -} - -/** - * Finalize decryption for the given unit of the protected content - * - * @param[in] uniqueId Unique identifier for a session - * @param[in] decryptHandle Handle for the decryption session - * @param[in] decryptUnitId ID Specifies decryption unit, such as track ID - * @return status_t - * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure - */ -status_t WVMDrmPlugin::onFinalizeDecryptUnit( - int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) { - //LOGD("WVMDrmPlugin::onFinalizeDecryptUnit() : %d", uniqueId); - return DRM_NO_ERROR; -} - -/** - * The following methods are not required for the Widevine DRM plugin - */ -ssize_t WVMDrmPlugin::onPread(int uniqueId, DecryptHandle* decryptHandle, - void* buffer, ssize_t numBytes, off64_t offset) { - return DRM_ERROR_UNKNOWN; -} - - -status_t WVMDrmPlugin::onOpenConvertSession(int uniqueId, int convertId) { - return DRM_ERROR_UNKNOWN; -} - -DrmConvertedStatus* WVMDrmPlugin::onConvertData( - int uniqueId, int convertId, const DrmBuffer* inputData) { - return NULL; -} - -DrmConvertedStatus* WVMDrmPlugin::onCloseConvertSession(int uniqueId, int convertId) { - return NULL; -} - - diff --git a/drm/libdrmframework/plugins/widevine/src/WVMLogging.cpp b/drm/libdrmframework/plugins/widevine/src/WVMLogging.cpp deleted file mode 100644 index a3b9bd7..0000000 --- a/drm/libdrmframework/plugins/widevine/src/WVMLogging.cpp +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (C) 2011 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_TAG "WVMLogging" -#include -#include "WVMLogging.h" - -// Connect Widevine debug logging into Android logging - -void android_printbuf(const char *buf) -{ - LOGD("%s", buf); -} diff --git a/drm/libdrmframework/plugins/widevine/test/Android.mk b/drm/libdrmframework/plugins/widevine/test/Android.mk deleted file mode 100644 index d3fa57c..0000000 --- a/drm/libdrmframework/plugins/widevine/test/Android.mk +++ /dev/null @@ -1,32 +0,0 @@ -LOCAL_PATH:= $(call my-dir) -include $(CLEAR_VARS) - -LOCAL_SRC_FILES:= \ - TestPlugin.cpp \ - ../src/WVMLogging.cpp - -LOCAL_C_INCLUDES+= \ - bionic \ - vendor/widevine/proprietary/include \ - external/stlport/stlport \ - frameworks/base/drm/libdrmframework/include \ - frameworks/base/drm/libdrmframework/plugins/common/include \ - frameworks/base/drm/libdrmframework/plugins/widevine/include - -LOCAL_SHARED_LIBRARIES := \ - libstlport \ - libwvdrm \ - liblog \ - libutils \ - libz \ - libdl - -LOCAL_STATIC_LIBRARIES := \ - libdrmframeworkcommon - -LOCAL_MODULE:=test-wvdrmplugin - -LOCAL_MODULE_TAGS := tests - -include $(BUILD_EXECUTABLE) - diff --git a/drm/libdrmframework/plugins/widevine/test/TestPlugin.cpp b/drm/libdrmframework/plugins/widevine/test/TestPlugin.cpp deleted file mode 100644 index 1942257..0000000 --- a/drm/libdrmframework/plugins/widevine/test/TestPlugin.cpp +++ /dev/null @@ -1,237 +0,0 @@ -/* - * Copyright (C) 2011 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 "WVMDrmPlugin.h" -#include "drm/DrmInfoRequest.h" -#include "drm/DrmInfoStatus.h" -#include "drm/DrmConstraints.h" -#include "drm/DrmInfo.h" - -using namespace android; -using namespace std; - -class WVMDrmPluginTest -{ -public: - WVMDrmPluginTest() {} - ~WVMDrmPluginTest() {} - - void TestAsset(IDrmEngine *plugin, String8 &url); - - void TestRemoveAllRights(IDrmEngine *plugin); - void TestAcquireRights(IDrmEngine *plugin, String8 &url); - void TestCheckRightsNotAcquired(IDrmEngine *plugin, String8 &url); - void TestCheckValidRights(IDrmEngine *plugin, String8 &url); - void TestGetConstraints(IDrmEngine *plugin, String8 &url); - void TestRemoveRights(IDrmEngine *plugin, String8 &url); - - // Tests - void Run(); -}; - -void WVMDrmPluginTest::Run() -{ - cout << "WVDrmPluginTest::Run" << endl; - const char *path = "/system/lib/drm/libdrmwvmplugin.so"; - void *handle = dlopen(path, RTLD_NOW); - if (handle == NULL) { - fprintf(stderr, "Can't open plugin: %s\n", path); - exit(-1); - } - - typedef IDrmEngine *(*create_t)(); - create_t creator = (create_t)dlsym(handle, "create"); - if (!creator) { - fprintf(stderr, "Can't find create method\n"); - exit(-1); - } - - typedef void (*destroy_t)(IDrmEngine *); - destroy_t destroyer = (destroy_t)dlsym(handle, "destroy"); - if (!destroyer) { - fprintf(stderr, "Can't find destroy method\n"); - exit(-1); - } - - // Basic test - see if we can instantiate the object and call a method - IDrmEngine *plugin = (*creator)(); - if (plugin->initialize(0) != DRM_NO_ERROR) { - fprintf(stderr, "onInitialize failed!\n"); - exit(-1); - } - - // Remote asset - String8 url; - url = String8("http://seawwws001.cdn.shibboleth.tv/videos/qa/adventures_d_ch_444169.wvm"); - TestAsset(plugin, url); - - // Local asset - url = String8("file:///sdcard/Widevine/trailers_d_ch_444169.wvm"); - TestAsset(plugin, url); - - // Remote asset with query parameters - url = String8("http://seawwws001.cdn.shibboleth.tv/videos/qa/adventures_d_ch_444169.wvm?a=b"); - TestAsset(plugin, url); - - // Shut down and clean up - if (plugin->terminate(0) != DRM_NO_ERROR) { - fprintf(stderr, "onTerminate failed!\n"); - exit(-1); - } - destroyer(plugin); - dlclose(handle); - printf("Test successful!\n"); - exit(0); -} - -void WVMDrmPluginTest::TestAcquireRights(IDrmEngine *plugin, String8 &url) -{ - cout << "WVDrmPluginTest::TestAcquireRights url=" << url << endl; - - String8 mimeType("video/wvm"); - DrmInfoRequest rightsAcquisitionInfo(DrmInfoRequest::TYPE_RIGHTS_ACQUISITION_INFO, mimeType); - rightsAcquisitionInfo.put(String8("WVDRMServerKey"), String8("http://wstfcps005.shibboleth.tv/widevine/cypherpc/cgi-bin/GetEMMs.cgi")); - rightsAcquisitionInfo.put(String8("WVAssetURIKey"), url); - rightsAcquisitionInfo.put(String8("WVDeviceIDKey"), String8("device1234")); - rightsAcquisitionInfo.put(String8("WVPortalKey"), String8("YouTube")); - - DrmInfo *info = plugin->acquireDrmInfo(0, &rightsAcquisitionInfo); - if (info == NULL) { - fprintf(stderr, "acquireDrmInfo failed!\n"); - exit(-1); - } - - DrmInfoStatus *status = plugin->processDrmInfo(0, info); - if (status == NULL || status->statusCode != DrmInfoStatus::STATUS_OK) { - fprintf(stderr, "processDrmInfo failed!\n"); - exit(-1); - } - - delete status; - delete info; -} - -void WVMDrmPluginTest::TestCheckRightsNotAcquired(IDrmEngine *plugin, String8 &url) -{ - cout << "WVDrmPluginTest::TestCheckRightsNotAcquired url=" << url << endl; - - if (plugin->checkRightsStatus(0, url, Action::DEFAULT) != RightsStatus::RIGHTS_NOT_ACQUIRED) { - fprintf(stderr, "checkRightsNotAcquired default action failed!\n"); - exit(-1); - } - - if (plugin->checkRightsStatus(0, url, Action::PLAY) != RightsStatus::RIGHTS_NOT_ACQUIRED) { - fprintf(stderr, "checkRightsNotAcquired failed!\n"); - exit(-1); - } -} - -void WVMDrmPluginTest::TestCheckValidRights(IDrmEngine *plugin, String8 &url) -{ - cout << "WVDrmPluginTest::TestCheckValidRights url=" << url << endl; - - if (plugin->checkRightsStatus(0, url, Action::DEFAULT) != RightsStatus::RIGHTS_VALID) { - fprintf(stderr, "checkValidRights default action failed!\n"); - exit(-1); - } - - if (plugin->checkRightsStatus(0, url, Action::PLAY) != RightsStatus::RIGHTS_VALID) { - fprintf(stderr, "checkValidRights play action failed!\n"); - exit(-1); - } -} - -void WVMDrmPluginTest::TestGetConstraints(IDrmEngine *plugin, String8 &url) -{ - cout << "WVDrmPluginTest::TestGetConstraints url=" << url << endl; - - DrmConstraints *constraints; - constraints = plugin->getConstraints(0, &url, Action::PLAY); - if (constraints == NULL) { - fprintf(stderr, "getConstraints returned NULL constraints!\n"); - exit(-1); - } - - if (constraints->getCount() != 3) { - fprintf(stderr, "getConstraints returned unexpected count!\n"); - exit(-1); - } - - if (constraints->get(DrmConstraints::LICENSE_START_TIME) == "") { - fprintf(stderr, "getConstraints returned unexpected count!\n"); - exit(-1); - } - - if (constraints->get(DrmConstraints::LICENSE_AVAILABLE_TIME) == "") { - fprintf(stderr, "getConstraints returned unexpected count!\n"); - exit(-1); - } - - if (constraints->get(DrmConstraints::LICENSE_EXPIRY_TIME) == "") { - fprintf(stderr, "getConstraints returned unexpected count!\n"); - exit(-1); - } - - delete constraints; -} - -void WVMDrmPluginTest::TestRemoveRights(IDrmEngine *plugin, String8 &url) -{ - cout << "WVDrmPluginTest::TestRemoveRights url=" << url << endl; - - status_t status = plugin->removeRights(0, url); - if (status != DRM_NO_ERROR) { - fprintf(stderr, "removeRights returned error: %d!\n", (int)status); - exit(-1); - } -} - -void WVMDrmPluginTest::TestRemoveAllRights(IDrmEngine *plugin) -{ - cout << "WVDrmPluginTest::TestRemoveAllRights" << endl; - - status_t status = plugin->removeAllRights(0); - if (status != DRM_NO_ERROR) { - fprintf(stderr, "removeAllRights returned error: %d!\n", (int)status); - exit(-1); - } -} - -void WVMDrmPluginTest::TestAsset(IDrmEngine *plugin, String8 &url) -{ - cout << "WVDrmPluginTest::TestAsset url=" << url << endl; - - TestAcquireRights(plugin, url); - TestCheckValidRights(plugin, url); - TestGetConstraints(plugin, url); - TestRemoveRights(plugin, url); - TestCheckRightsNotAcquired(plugin, url); - TestAcquireRights(plugin, url); - TestRemoveAllRights(plugin); - TestCheckRightsNotAcquired(plugin, url); -} - -int main(int argc, char **argv) -{ - // turn off some noisy printing in WVStreamControl - setenv("WV_SILENT", "true", 1); - WVMDrmPluginTest test; - test.Run(); -} diff --git a/drm/libdrmframework/plugins/widevine/test/kill.sh b/drm/libdrmframework/plugins/widevine/test/kill.sh deleted file mode 100755 index acc7151..0000000 --- a/drm/libdrmframework/plugins/widevine/test/kill.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -PID=`adb shell ps | grep test-wvdrmplugin | awk '{print $2}'` -adb shell kill -9 $PID -- 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/common/DrmSupportInfo.cpp | 2 +- drm/drmserver/DrmManager.cpp | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'drm') diff --git a/drm/common/DrmSupportInfo.cpp b/drm/common/DrmSupportInfo.cpp index ffc8953..3e02093 100644 --- a/drm/common/DrmSupportInfo.cpp +++ b/drm/common/DrmSupportInfo.cpp @@ -56,7 +56,7 @@ bool DrmSupportInfo::isSupportedFileSuffix(const String8& fileType) const { for (unsigned int i = 0; i < mFileSuffixVector.size(); i++) { const String8 item = mFileSuffixVector.itemAt(i); - if (String8("") != fileType && item.find(fileType) != -1) { + if (item.find(fileType) != -1) { return true; } } 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/common/IDrmManagerService.cpp | 4 ++-- drm/drmserver/DrmManager.cpp | 31 +++++++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 4 deletions(-) (limited to 'drm') diff --git a/drm/common/IDrmManagerService.cpp b/drm/common/IDrmManagerService.cpp index ddbd220..696e305 100644 --- a/drm/common/IDrmManagerService.cpp +++ b/drm/common/IDrmManagerService.cpp @@ -596,7 +596,7 @@ DecryptHandle* BpDrmManagerService::openDecryptSession(int uniqueId, const char* handle->decryptInfo->decryptBufferLength = reply.readInt32(); } } else { - LOGE("no decryptHandle is generated in service side"); + LOGV("no decryptHandle is generated in service side"); } return handle; } @@ -1308,7 +1308,7 @@ status_t BnDrmManagerService::onTransact( delete handle->decryptInfo; handle->decryptInfo = NULL; } } else { - LOGE("NULL decryptHandle is returned"); + LOGV("NULL decryptHandle is returned"); } delete handle; handle = NULL; return DRM_NO_ERROR; 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 b5ce361d19e69fe156f7188c9ee0f4734b259874 Mon Sep 17 00:00:00 2001 From: Gloria Wang Date: Thu, 24 Feb 2011 16:40:57 -0800 Subject: Fix for bug 3477330 This patch fixs a crash bug caused by using a NULL DecryptHandle pointer. Fix by using sp instead. Change-Id: Icbd59858385e8256125a615a3c82656b25319d44 --- drm/common/IDrmManagerService.cpp | 5 - drm/libdrmframework/DrmManagerClient.cpp | 25 +++-- drm/libdrmframework/DrmManagerClientImpl.cpp | 111 +++++++++++++-------- drm/libdrmframework/include/DrmManagerClientImpl.h | 18 ++-- 4 files changed, 92 insertions(+), 67 deletions(-) (limited to 'drm') diff --git a/drm/common/IDrmManagerService.cpp b/drm/common/IDrmManagerService.cpp index 696e305..e2bfb16 100644 --- a/drm/common/IDrmManagerService.cpp +++ b/drm/common/IDrmManagerService.cpp @@ -621,11 +621,6 @@ status_t BpDrmManagerService::closeDecryptSession(int uniqueId, DecryptHandle* d remote()->transact(CLOSE_DECRYPT_SESSION, data, &reply); - if (NULL != decryptHandle->decryptInfo) { - LOGV("deleting decryptInfo"); - delete decryptHandle->decryptInfo; decryptHandle->decryptInfo = NULL; - } - delete decryptHandle; decryptHandle = NULL; return reply.readInt32(); } diff --git a/drm/libdrmframework/DrmManagerClient.cpp b/drm/libdrmframework/DrmManagerClient.cpp index 7b51822..3143d45 100644 --- a/drm/libdrmframework/DrmManagerClient.cpp +++ b/drm/libdrmframework/DrmManagerClient.cpp @@ -77,13 +77,14 @@ int DrmManagerClient::checkRightsStatus(const String8& path, int action) { return mDrmManagerClientImpl->checkRightsStatus(mUniqueId, path, action); } -status_t DrmManagerClient::consumeRights(DecryptHandle* decryptHandle, int action, bool reserve) { +status_t DrmManagerClient::consumeRights( + sp &decryptHandle, int action, bool reserve) { Mutex::Autolock _l(mDecryptLock); return mDrmManagerClientImpl->consumeRights(mUniqueId, decryptHandle, action, reserve); } status_t DrmManagerClient::setPlaybackStatus( - DecryptHandle* decryptHandle, int playbackStatus, int64_t position) { + sp &decryptHandle, int playbackStatus, int64_t position) { return mDrmManagerClientImpl ->setPlaybackStatus(mUniqueId, decryptHandle, playbackStatus, position); } @@ -117,40 +118,42 @@ status_t DrmManagerClient::getAllSupportInfo(int* length, DrmSupportInfo** drmSu return mDrmManagerClientImpl->getAllSupportInfo(mUniqueId, length, drmSupportInfoArray); } -DecryptHandle* DrmManagerClient::openDecryptSession(int fd, off64_t offset, off64_t length) { +sp DrmManagerClient::openDecryptSession(int fd, off64_t offset, off64_t length) { return mDrmManagerClientImpl->openDecryptSession(mUniqueId, fd, offset, length); } -DecryptHandle* DrmManagerClient::openDecryptSession(const char* uri) { +sp DrmManagerClient::openDecryptSession(const char* uri) { return mDrmManagerClientImpl->openDecryptSession(mUniqueId, uri); } -status_t DrmManagerClient::closeDecryptSession(DecryptHandle* decryptHandle) { +status_t DrmManagerClient::closeDecryptSession(sp &decryptHandle) { return mDrmManagerClientImpl->closeDecryptSession(mUniqueId, decryptHandle); } status_t DrmManagerClient::initializeDecryptUnit( - DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo) { + sp &decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo) { Mutex::Autolock _l(mDecryptLock); return mDrmManagerClientImpl->initializeDecryptUnit( mUniqueId, decryptHandle, decryptUnitId, headerInfo); } status_t DrmManagerClient::decrypt( - DecryptHandle* decryptHandle, int decryptUnitId, - const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) { + sp &decryptHandle, int decryptUnitId, + const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) { Mutex::Autolock _l(mDecryptLock); return mDrmManagerClientImpl->decrypt( mUniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer, IV); } -status_t DrmManagerClient::finalizeDecryptUnit(DecryptHandle* decryptHandle, int decryptUnitId) { +status_t DrmManagerClient::finalizeDecryptUnit( + sp &decryptHandle, int decryptUnitId) { Mutex::Autolock _l(mDecryptLock); - return mDrmManagerClientImpl->finalizeDecryptUnit(mUniqueId, decryptHandle, decryptUnitId); + return mDrmManagerClientImpl->finalizeDecryptUnit(mUniqueId, + decryptHandle, decryptUnitId); } ssize_t DrmManagerClient::pread( - DecryptHandle* decryptHandle, void* buffer, ssize_t numBytes, off64_t offset) { + sp &decryptHandle, void* buffer, ssize_t numBytes, off64_t offset) { Mutex::Autolock _l(mDecryptLock); return mDrmManagerClientImpl->pread(mUniqueId, decryptHandle, buffer, numBytes, offset); } diff --git a/drm/libdrmframework/DrmManagerClientImpl.cpp b/drm/libdrmframework/DrmManagerClientImpl.cpp index d20de92..e6ae220 100644 --- a/drm/libdrmframework/DrmManagerClientImpl.cpp +++ b/drm/libdrmframework/DrmManagerClientImpl.cpp @@ -78,14 +78,16 @@ void DrmManagerClientImpl::removeClient(int uniqueId) { } status_t DrmManagerClientImpl::setOnInfoListener( - int uniqueId, const sp& infoListener) { + int uniqueId, + const sp& infoListener) { Mutex::Autolock _l(mLock); mOnInfoListener = infoListener; return getDrmManagerService()->setDrmServiceListener(uniqueId, (NULL != infoListener.get()) ? this : NULL); } -status_t DrmManagerClientImpl::installDrmEngine(int uniqueId, const String8& drmEngineFile) { +status_t DrmManagerClientImpl::installDrmEngine( + int uniqueId, const String8& drmEngineFile) { status_t status = DRM_ERROR_UNKNOWN; if (EMPTY_STRING != drmEngineFile) { status = getDrmManagerService()->installDrmEngine(uniqueId, drmEngineFile); @@ -97,7 +99,8 @@ DrmConstraints* DrmManagerClientImpl::getConstraints( int uniqueId, const String8* path, const int action) { DrmConstraints *drmConstraints = NULL; if ((NULL != path) && (EMPTY_STRING != *path)) { - drmConstraints = getDrmManagerService()->getConstraints(uniqueId, path, action); + drmConstraints = + getDrmManagerService()->getConstraints(uniqueId, path, action); } return drmConstraints; } @@ -110,7 +113,8 @@ DrmMetadata* DrmManagerClientImpl::getMetadata(int uniqueId, const String8* path return drmMetadata; } -bool DrmManagerClientImpl::canHandle(int uniqueId, const String8& path, const String8& mimeType) { +bool DrmManagerClientImpl::canHandle( + int uniqueId, const String8& path, const String8& mimeType) { bool retCode = false; if ((EMPTY_STRING != path) || (EMPTY_STRING != mimeType)) { retCode = getDrmManagerService()->canHandle(uniqueId, path, mimeType); @@ -118,7 +122,8 @@ bool DrmManagerClientImpl::canHandle(int uniqueId, const String8& path, const St return retCode; } -DrmInfoStatus* DrmManagerClientImpl::processDrmInfo(int uniqueId, const DrmInfo* drmInfo) { +DrmInfoStatus* DrmManagerClientImpl::processDrmInfo( + int uniqueId, const DrmInfo* drmInfo) { DrmInfoStatus *drmInfoStatus = NULL; if (NULL != drmInfo) { drmInfoStatus = getDrmManagerService()->processDrmInfo(uniqueId, drmInfo); @@ -126,7 +131,8 @@ DrmInfoStatus* DrmManagerClientImpl::processDrmInfo(int uniqueId, const DrmInfo* return drmInfoStatus; } -DrmInfo* DrmManagerClientImpl::acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest) { +DrmInfo* DrmManagerClientImpl::acquireDrmInfo( + int uniqueId, const DrmInfoRequest* drmInfoRequest) { DrmInfo* drmInfo = NULL; if (NULL != drmInfoRequest) { drmInfo = getDrmManagerService()->acquireDrmInfo(uniqueId, drmInfoRequest); @@ -138,12 +144,14 @@ status_t DrmManagerClientImpl::saveRights(int uniqueId, const DrmRights& drmRigh const String8& rightsPath, const String8& contentPath) { status_t status = DRM_ERROR_UNKNOWN; if (EMPTY_STRING != contentPath) { - status = getDrmManagerService()->saveRights(uniqueId, drmRights, rightsPath, contentPath); + status = getDrmManagerService()->saveRights( + uniqueId, drmRights, rightsPath, contentPath); } return status; } -String8 DrmManagerClientImpl::getOriginalMimeType(int uniqueId, const String8& path) { +String8 DrmManagerClientImpl::getOriginalMimeType( + int uniqueId, const String8& path) { String8 mimeType = EMPTY_STRING; if (EMPTY_STRING != path) { mimeType = getDrmManagerService()->getOriginalMimeType(uniqueId, path); @@ -155,7 +163,8 @@ int DrmManagerClientImpl::getDrmObjectType( int uniqueId, const String8& path, const String8& mimeType) { int drmOjectType = DrmObjectType::UNKNOWN; if ((EMPTY_STRING != path) || (EMPTY_STRING != mimeType)) { - drmOjectType = getDrmManagerService()->getDrmObjectType(uniqueId, path, mimeType); + drmOjectType = + getDrmManagerService()->getDrmObjectType(uniqueId, path, mimeType); } return drmOjectType; } @@ -164,35 +173,41 @@ int DrmManagerClientImpl::checkRightsStatus( int uniqueId, const String8& path, int action) { int rightsStatus = RightsStatus::RIGHTS_INVALID; if (EMPTY_STRING != path) { - rightsStatus = getDrmManagerService()->checkRightsStatus(uniqueId, path, action); + rightsStatus = + getDrmManagerService()->checkRightsStatus(uniqueId, path, action); } return rightsStatus; } status_t DrmManagerClientImpl::consumeRights( - int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) { + int uniqueId, sp &decryptHandle, + int action, bool reserve) { status_t status = DRM_ERROR_UNKNOWN; - if (NULL != decryptHandle) { - status = getDrmManagerService()->consumeRights(uniqueId, decryptHandle, action, reserve); + if (NULL != decryptHandle.get()) { + status = getDrmManagerService()->consumeRights( + uniqueId, decryptHandle.get(), action, reserve); } return status; } status_t DrmManagerClientImpl::setPlaybackStatus( - int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int64_t position) { + int uniqueId, sp &decryptHandle, + int playbackStatus, int64_t position) { status_t status = DRM_ERROR_UNKNOWN; - if (NULL != decryptHandle) { + if (NULL != decryptHandle.get()) { status = getDrmManagerService()->setPlaybackStatus( - uniqueId, decryptHandle, playbackStatus, position); + uniqueId, decryptHandle.get(), playbackStatus, position); } return status; } bool DrmManagerClientImpl::validateAction( - int uniqueId, const String8& path, int action, const ActionDescription& description) { + int uniqueId, const String8& path, + int action, const ActionDescription& description) { bool retCode = false; if (EMPTY_STRING != path) { - retCode = getDrmManagerService()->validateAction(uniqueId, path, action, description); + retCode = getDrmManagerService()->validateAction( + uniqueId, path, action, description); } return retCode; } @@ -209,7 +224,8 @@ status_t DrmManagerClientImpl::removeAllRights(int uniqueId) { return getDrmManagerService()->removeAllRights(uniqueId); } -int DrmManagerClientImpl::openConvertSession(int uniqueId, const String8& mimeType) { +int DrmManagerClientImpl::openConvertSession( + int uniqueId, const String8& mimeType) { int retCode = INVALID_VALUE; if (EMPTY_STRING != mimeType) { retCode = getDrmManagerService()->openConvertSession(uniqueId, mimeType); @@ -221,12 +237,14 @@ DrmConvertedStatus* DrmManagerClientImpl::convertData( int uniqueId, int convertId, const DrmBuffer* inputData) { DrmConvertedStatus* drmConvertedStatus = NULL; if (NULL != inputData) { - drmConvertedStatus = getDrmManagerService()->convertData(uniqueId, convertId, inputData); + drmConvertedStatus = + getDrmManagerService()->convertData(uniqueId, convertId, inputData); } return drmConvertedStatus; } -DrmConvertedStatus* DrmManagerClientImpl::closeConvertSession(int uniqueId, int convertId) { +DrmConvertedStatus* DrmManagerClientImpl::closeConvertSession( + int uniqueId, int convertId) { return getDrmManagerService()->closeConvertSession(uniqueId, convertId); } @@ -234,17 +252,19 @@ status_t DrmManagerClientImpl::getAllSupportInfo( int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray) { status_t status = DRM_ERROR_UNKNOWN; if ((NULL != drmSupportInfoArray) && (NULL != length)) { - status = getDrmManagerService()->getAllSupportInfo(uniqueId, length, drmSupportInfoArray); + status = getDrmManagerService()->getAllSupportInfo( + uniqueId, length, drmSupportInfoArray); } return status; } -DecryptHandle* DrmManagerClientImpl::openDecryptSession( +sp DrmManagerClientImpl::openDecryptSession( int uniqueId, int fd, off64_t offset, off64_t length) { return getDrmManagerService()->openDecryptSession(uniqueId, fd, offset, length); } -DecryptHandle* DrmManagerClientImpl::openDecryptSession(int uniqueId, const char* uri) { +sp DrmManagerClientImpl::openDecryptSession( + int uniqueId, const char* uri) { DecryptHandle* handle = NULL; if (NULL != uri) { handle = getDrmManagerService()->openDecryptSession(uniqueId, uri); @@ -252,50 +272,57 @@ DecryptHandle* DrmManagerClientImpl::openDecryptSession(int uniqueId, const char return handle; } -status_t DrmManagerClientImpl::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) { +status_t DrmManagerClientImpl::closeDecryptSession( + int uniqueId, sp &decryptHandle) { status_t status = DRM_ERROR_UNKNOWN; - if (NULL != decryptHandle) { - status = getDrmManagerService()->closeDecryptSession( uniqueId, decryptHandle); + if (NULL != decryptHandle.get()) { + status = getDrmManagerService()->closeDecryptSession( + uniqueId, decryptHandle.get()); } return status; } -status_t DrmManagerClientImpl::initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, - int decryptUnitId, const DrmBuffer* headerInfo) { +status_t DrmManagerClientImpl::initializeDecryptUnit( + int uniqueId, sp &decryptHandle, + int decryptUnitId, const DrmBuffer* headerInfo) { status_t status = DRM_ERROR_UNKNOWN; - if ((NULL != decryptHandle) && (NULL != headerInfo)) { + if ((NULL != decryptHandle.get()) && (NULL != headerInfo)) { status = getDrmManagerService()->initializeDecryptUnit( - uniqueId, decryptHandle, decryptUnitId, headerInfo); + uniqueId, decryptHandle.get(), decryptUnitId, headerInfo); } return status; } -status_t DrmManagerClientImpl::decrypt(int uniqueId, DecryptHandle* decryptHandle, - int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) { +status_t DrmManagerClientImpl::decrypt( + int uniqueId, sp &decryptHandle, + int decryptUnitId, const DrmBuffer* encBuffer, + DrmBuffer** decBuffer, DrmBuffer* IV) { status_t status = DRM_ERROR_UNKNOWN; - if ((NULL != decryptHandle) && (NULL != encBuffer) + if ((NULL != decryptHandle.get()) && (NULL != encBuffer) && (NULL != decBuffer) && (NULL != *decBuffer)) { status = getDrmManagerService()->decrypt( - uniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer, IV); + uniqueId, decryptHandle.get(), decryptUnitId, + encBuffer, decBuffer, IV); } return status; } status_t DrmManagerClientImpl::finalizeDecryptUnit( - int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) { + int uniqueId, sp &decryptHandle, int decryptUnitId) { status_t status = DRM_ERROR_UNKNOWN; - if (NULL != decryptHandle) { - status - = getDrmManagerService()->finalizeDecryptUnit(uniqueId, decryptHandle, decryptUnitId); + if (NULL != decryptHandle.get()) { + status = getDrmManagerService()->finalizeDecryptUnit( + uniqueId, decryptHandle.get(), decryptUnitId); } return status; } -ssize_t DrmManagerClientImpl::pread(int uniqueId, DecryptHandle* decryptHandle, +ssize_t DrmManagerClientImpl::pread(int uniqueId, sp &decryptHandle, void* buffer, ssize_t numBytes, off64_t offset) { ssize_t retCode = INVALID_VALUE; - if ((NULL != decryptHandle) && (NULL != buffer) && (0 < numBytes)) { - retCode = getDrmManagerService()->pread(uniqueId, decryptHandle, buffer, numBytes, offset); + if ((NULL != decryptHandle.get()) && (NULL != buffer) && (0 < numBytes)) { + retCode = getDrmManagerService()->pread( + uniqueId, decryptHandle.get(), buffer, numBytes, offset); } return retCode; } diff --git a/drm/libdrmframework/include/DrmManagerClientImpl.h b/drm/libdrmframework/include/DrmManagerClientImpl.h index 0a7fcd1..0cba8d4 100644 --- a/drm/libdrmframework/include/DrmManagerClientImpl.h +++ b/drm/libdrmframework/include/DrmManagerClientImpl.h @@ -189,7 +189,7 @@ public: * @return status_t * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure */ - status_t consumeRights(int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve); + status_t consumeRights(int uniqueId, sp &decryptHandle, int action, bool reserve); /** * Informs the DRM engine about the playback actions performed on the DRM files. @@ -203,7 +203,7 @@ public: * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure */ status_t setPlaybackStatus( - int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int64_t position); + int uniqueId, sp &decryptHandle, int playbackStatus, int64_t position); /** * Validates whether an action on the DRM content is allowed or not. @@ -303,7 +303,7 @@ public: * @return * Handle for the decryption session */ - DecryptHandle* openDecryptSession(int uniqueId, int fd, off64_t offset, off64_t length); + sp openDecryptSession(int uniqueId, int fd, off64_t offset, off64_t length); /** * Open the decrypt session to decrypt the given protected content @@ -313,7 +313,7 @@ public: * @return * Handle for the decryption session */ - DecryptHandle* openDecryptSession(int uniqueId, const char* uri); + sp openDecryptSession(int uniqueId, const char* uri); /** * Close the decrypt session for the given handle @@ -323,7 +323,7 @@ public: * @return status_t * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure */ - status_t closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle); + status_t closeDecryptSession(int uniqueId, sp &decryptHandle); /** * Initialize decryption for the given unit of the protected content @@ -335,7 +335,7 @@ public: * @return status_t * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure */ - status_t initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, + status_t initializeDecryptUnit(int uniqueId, sp &decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo); /** @@ -355,7 +355,7 @@ public: * DRM_ERROR_SESSION_NOT_OPENED, DRM_ERROR_DECRYPT_UNIT_NOT_INITIALIZED, * DRM_ERROR_DECRYPT for failure. */ - status_t decrypt(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, + status_t decrypt(int uniqueId, sp &decryptHandle, int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV); /** @@ -367,7 +367,7 @@ public: * @return status_t * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure */ - status_t finalizeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId); + status_t finalizeDecryptUnit(int uniqueId, sp &decryptHandle, int decryptUnitId); /** * Reads the specified number of bytes from an open DRM file. @@ -380,7 +380,7 @@ public: * * @return Number of bytes read. Returns -1 for Failure. */ - ssize_t pread(int uniqueId, DecryptHandle* decryptHandle, + ssize_t pread(int uniqueId, sp &decryptHandle, void* buffer, ssize_t numBytes, off64_t 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 ++-- drm/libdrmframework/DrmManagerClient.cpp | 5 ----- drm/libdrmframework/include/DrmManager.h | 1 + 3 files changed, 3 insertions(+), 7 deletions(-) (limited to 'drm') 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); diff --git a/drm/libdrmframework/DrmManagerClient.cpp b/drm/libdrmframework/DrmManagerClient.cpp index 7b51822..1d1e258 100644 --- a/drm/libdrmframework/DrmManagerClient.cpp +++ b/drm/libdrmframework/DrmManagerClient.cpp @@ -78,7 +78,6 @@ int DrmManagerClient::checkRightsStatus(const String8& path, int action) { } status_t DrmManagerClient::consumeRights(DecryptHandle* decryptHandle, int action, bool reserve) { - Mutex::Autolock _l(mDecryptLock); return mDrmManagerClientImpl->consumeRights(mUniqueId, decryptHandle, action, reserve); } @@ -131,7 +130,6 @@ status_t DrmManagerClient::closeDecryptSession(DecryptHandle* decryptHandle) { status_t DrmManagerClient::initializeDecryptUnit( DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo) { - Mutex::Autolock _l(mDecryptLock); return mDrmManagerClientImpl->initializeDecryptUnit( mUniqueId, decryptHandle, decryptUnitId, headerInfo); } @@ -139,19 +137,16 @@ status_t DrmManagerClient::initializeDecryptUnit( status_t DrmManagerClient::decrypt( DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) { - Mutex::Autolock _l(mDecryptLock); return mDrmManagerClientImpl->decrypt( mUniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer, IV); } status_t DrmManagerClient::finalizeDecryptUnit(DecryptHandle* decryptHandle, int decryptUnitId) { - Mutex::Autolock _l(mDecryptLock); return mDrmManagerClientImpl->finalizeDecryptUnit(mUniqueId, decryptHandle, decryptUnitId); } ssize_t DrmManagerClient::pread( DecryptHandle* decryptHandle, void* buffer, ssize_t numBytes, off64_t offset) { - Mutex::Autolock _l(mDecryptLock); return mDrmManagerClientImpl->pread(mUniqueId, decryptHandle, buffer, numBytes, offset); } diff --git a/drm/libdrmframework/include/DrmManager.h b/drm/libdrmframework/include/DrmManager.h index e05366d..c7276f9 100644 --- a/drm/libdrmframework/include/DrmManager.h +++ b/drm/libdrmframework/include/DrmManager.h @@ -147,6 +147,7 @@ private: int mDecryptSessionId; int mConvertId; Mutex mLock; + Mutex mListenerLock; Mutex mDecryptLock; Mutex mConvertLock; TPlugInManager mPlugInManager; -- cgit v1.1 From 9691a73139bb36c5bf294ed13eedcb04d7f05320 Mon Sep 17 00:00:00 2001 From: Iliyan Malchev Date: Mon, 14 Mar 2011 14:02:13 -0700 Subject: frameworks/base: remove LOCAL_PRELINK_MODULE Change-Id: I54dd62ebef47e7690afa5a858f3cad941b135481 Signed-off-by: Iliyan Malchev --- drm/libdrmframework/Android.mk | 2 +- drm/libdrmframework/plugins/forward-lock/FwdLockEngine/Android.mk | 2 +- drm/libdrmframework/plugins/passthru/Android.mk | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'drm') diff --git a/drm/libdrmframework/Android.mk b/drm/libdrmframework/Android.mk index 99133ba..f1526a4 100644 --- a/drm/libdrmframework/Android.mk +++ b/drm/libdrmframework/Android.mk @@ -40,7 +40,7 @@ LOCAL_C_INCLUDES += \ $(TOP)/frameworks/base/drm/libdrmframework/include \ $(TOP)/frameworks/base/include -LOCAL_PRELINK_MODULE := false + LOCAL_MODULE_TAGS := optional diff --git a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/Android.mk b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/Android.mk index af67aa3..9805a40 100644 --- a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/Android.mk +++ b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/Android.mk @@ -47,7 +47,7 @@ LOCAL_STATIC_LIBRARIES := \ libfwdlock-converter \ libfwdlock-decoder -LOCAL_PRELINK_MODULE := false + LOCAL_C_INCLUDES += \ $(JNI_H_INCLUDE) \ diff --git a/drm/libdrmframework/plugins/passthru/Android.mk b/drm/libdrmframework/plugins/passthru/Android.mk index 7856d37..be18b64 100644 --- a/drm/libdrmframework/plugins/passthru/Android.mk +++ b/drm/libdrmframework/plugins/passthru/Android.mk @@ -32,7 +32,7 @@ else LOCAL_SHARED_LIBRARIES += libdl endif -LOCAL_PRELINK_MODULE := false + LOCAL_C_INCLUDES += \ $(TOP)/frameworks/base/drm/libdrmframework/include \ -- 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/common/DrmSupportInfo.cpp | 4 +- drm/drmserver/Android.mk | 3 +- drm/drmserver/StringTokenizer.cpp | 66 -------------------- drm/libdrmframework/include/PlugInManager.h | 8 +-- drm/libdrmframework/include/StringTokenizer.h | 87 --------------------------- 5 files changed, 6 insertions(+), 162 deletions(-) delete mode 100644 drm/drmserver/StringTokenizer.cpp delete mode 100644 drm/libdrmframework/include/StringTokenizer.h (limited to 'drm') diff --git a/drm/common/DrmSupportInfo.cpp b/drm/common/DrmSupportInfo.cpp index 3e02093..c0bff0e 100644 --- a/drm/common/DrmSupportInfo.cpp +++ b/drm/common/DrmSupportInfo.cpp @@ -45,7 +45,7 @@ bool DrmSupportInfo::isSupportedMimeType(const String8& mimeType) const { for (unsigned int i = 0; i < mMimeTypeVector.size(); i++) { const String8 item = mMimeTypeVector.itemAt(i); - if (String8("") != mimeType && item.find(mimeType) != -1) { + if (!strcasecmp(item.string(), mimeType.string())) { return true; } } @@ -56,7 +56,7 @@ bool DrmSupportInfo::isSupportedFileSuffix(const String8& fileType) const { for (unsigned int i = 0; i < mFileSuffixVector.size(); i++) { const String8 item = mFileSuffixVector.itemAt(i); - if (item.find(fileType) != -1) { + if (!strcasecmp(item.string(), fileType.string())) { return true; } } 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; -} - diff --git a/drm/libdrmframework/include/PlugInManager.h b/drm/libdrmframework/include/PlugInManager.h index 9ad195f..8029138 100644 --- a/drm/libdrmframework/include/PlugInManager.h +++ b/drm/libdrmframework/include/PlugInManager.h @@ -230,11 +230,9 @@ private: */ bool isPlugIn(const struct dirent* pEntry) const { String8 sName(pEntry->d_name); - int extentionPos = sName.size() - String8(PLUGIN_EXTENSION).size(); - if (extentionPos < 0) { - return false; - } - return extentionPos == (int)sName.find(PLUGIN_EXTENSION); + String8 extension(sName.getPathExtension()); + // Note that the plug-in extension must exactly match case + return extension == String8(PLUGIN_EXTENSION); } /** diff --git a/drm/libdrmframework/include/StringTokenizer.h b/drm/libdrmframework/include/StringTokenizer.h deleted file mode 100644 index 70e7558..0000000 --- a/drm/libdrmframework/include/StringTokenizer.h +++ /dev/null @@ -1,87 +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. - */ - -#ifndef __STRING_TOKENIZER_H__ -#define __STRING_TOKENIZER_H__ - -#include - -namespace android { - -/** - * This is an utility class for String manipulation. - * - */ -class StringTokenizer { -public: - /** - * Iterator for string tokens - */ - class Iterator { - friend class StringTokenizer; - private: - Iterator(StringTokenizer* StringTokenizer) - : mStringTokenizer(StringTokenizer), mIndex(0) {} - - public: - Iterator(const Iterator& iterator); - Iterator& operator=(const Iterator& iterator); - virtual ~Iterator() {} - - public: - bool hasNext(); - String8& next(); - - private: - StringTokenizer* mStringTokenizer; - unsigned int mIndex; - }; - -public: - /** - * Constructor for StringTokenizer - * - * @param[in] string Complete string data - * @param[in] delimeter Delimeter used to split the string - */ - StringTokenizer(const String8& string, const String8& delimeter); - - /** - * Destructor for StringTokenizer - */ - ~StringTokenizer() {} - -private: - /** - * Splits the string according to the delimeter - */ - void splitString(const String8& string, const String8& delimeter); - -public: - /** - * Returns Iterator object to walk through the split string values - * - * @return Iterator object - */ - Iterator iterator(); - -private: - Vector mStringTokenizerVector; -}; - -}; -#endif /* __STRING_TOKENIZER_H__ */ - -- 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 +++++++++++++++++++++++++ drm/libdrmframework/include/DrmManagerService.h | 2 ++ 3 files changed, 32 insertions(+) (limited to 'drm') 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; +} + diff --git a/drm/libdrmframework/include/DrmManagerService.h b/drm/libdrmframework/include/DrmManagerService.h index d0a0db7..227496a 100644 --- a/drm/libdrmframework/include/DrmManagerService.h +++ b/drm/libdrmframework/include/DrmManagerService.h @@ -115,6 +115,8 @@ public: ssize_t pread(int uniqueId, DecryptHandle* decryptHandle, void* buffer, ssize_t numBytes, off64_t offset); + virtual status_t dump(int fd, const Vector& args); + private: DrmManager* mDrmManager; }; -- 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 - drm/libdrmframework/DrmManagerClientImpl.cpp | 37 +++++++++++++++------- drm/libdrmframework/include/DrmManager.h | 3 +- drm/libdrmframework/include/DrmManagerClientImpl.h | 12 +++++-- drm/libdrmframework/include/IDrmManagerService.h | 1 - .../plugins/common/include/IDrmEngine.h | 1 - 6 files changed, 36 insertions(+), 19 deletions(-) (limited to 'drm') 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() : diff --git a/drm/libdrmframework/DrmManagerClientImpl.cpp b/drm/libdrmframework/DrmManagerClientImpl.cpp index e6ae220..a57dd98 100644 --- a/drm/libdrmframework/DrmManagerClientImpl.cpp +++ b/drm/libdrmframework/DrmManagerClientImpl.cpp @@ -28,8 +28,9 @@ using namespace android; #define INVALID_VALUE -1 -Mutex DrmManagerClientImpl::mMutex; -sp DrmManagerClientImpl::mDrmManagerService; +Mutex DrmManagerClientImpl::sMutex; +sp DrmManagerClientImpl::sDrmManagerService; +sp DrmManagerClientImpl::sDeathNotifier; const String8 DrmManagerClientImpl::EMPTY_STRING(""); DrmManagerClientImpl* DrmManagerClientImpl::create(int* pUniqueId) { @@ -47,8 +48,8 @@ void DrmManagerClientImpl::remove(int uniqueId) { } const sp& DrmManagerClientImpl::getDrmManagerService() { - mMutex.lock(); - if (NULL == mDrmManagerService.get()) { + Mutex::Autolock lock(sMutex); + if (NULL == sDrmManagerService.get()) { sp sm = defaultServiceManager(); sp binder; do { @@ -62,11 +63,13 @@ const sp& DrmManagerClientImpl::getDrmManagerService() { reqt.tv_nsec = 500000000; //0.5 sec nanosleep(&reqt, NULL); } while (true); - - mDrmManagerService = interface_cast(binder); + if (NULL == sDeathNotifier.get()) { + sDeathNotifier = new DeathNotifier(); + } + binder->linkToDeath(sDeathNotifier); + sDrmManagerService = interface_cast(binder); } - mMutex.unlock(); - return mDrmManagerService; + return sDrmManagerService; } void DrmManagerClientImpl::addClient(int uniqueId) { @@ -143,11 +146,8 @@ DrmInfo* DrmManagerClientImpl::acquireDrmInfo( status_t DrmManagerClientImpl::saveRights(int uniqueId, const DrmRights& drmRights, const String8& rightsPath, const String8& contentPath) { status_t status = DRM_ERROR_UNKNOWN; - if (EMPTY_STRING != contentPath) { - status = getDrmManagerService()->saveRights( + return getDrmManagerService()->saveRights( uniqueId, drmRights, rightsPath, contentPath); - } - return status; } String8 DrmManagerClientImpl::getOriginalMimeType( @@ -336,3 +336,16 @@ status_t DrmManagerClientImpl::notify(const DrmInfoEvent& event) { return DRM_NO_ERROR; } +DrmManagerClientImpl::DeathNotifier::~DeathNotifier() { + Mutex::Autolock lock(sMutex); + if (NULL != sDrmManagerService.get()) { + sDrmManagerService->asBinder()->unlinkToDeath(this); + } +} + +void DrmManagerClientImpl::DeathNotifier::binderDied(const wp& who) { + Mutex::Autolock lock(sMutex); + DrmManagerClientImpl::sDrmManagerService.clear(); + LOGW("DrmManager server died!"); +} + diff --git a/drm/libdrmframework/include/DrmManager.h b/drm/libdrmframework/include/DrmManager.h index e05366d..86a5ff4 100644 --- a/drm/libdrmframework/include/DrmManager.h +++ b/drm/libdrmframework/include/DrmManager.h @@ -30,7 +30,6 @@ class IDrmManager; class DrmRegistrationInfo; class DrmUnregistrationInfo; class DrmRightsAcquisitionInfo; -class DrmContentIds; class DrmConstraints; class DrmMetadata; class DrmRights; @@ -141,7 +140,7 @@ private: bool canHandle(int uniqueId, const String8& path); private: - static Vector mUniqueIdVector; + Vector mUniqueIdVector; static const String8 EMPTY_STRING; int mDecryptSessionId; diff --git a/drm/libdrmframework/include/DrmManagerClientImpl.h b/drm/libdrmframework/include/DrmManagerClientImpl.h index 0cba8d4..564896b 100644 --- a/drm/libdrmframework/include/DrmManagerClientImpl.h +++ b/drm/libdrmframework/include/DrmManagerClientImpl.h @@ -407,9 +407,17 @@ private: Mutex mLock; sp mOnInfoListener; + class DeathNotifier: public IBinder::DeathRecipient { + public: + DeathNotifier() {} + virtual ~DeathNotifier(); + virtual void binderDied(const wp& who); + }; + private: - static Mutex mMutex; - static sp mDrmManagerService; + static Mutex sMutex; + static sp sDeathNotifier; + static sp sDrmManagerService; static const sp& getDrmManagerService(); static const String8 EMPTY_STRING; }; diff --git a/drm/libdrmframework/include/IDrmManagerService.h b/drm/libdrmframework/include/IDrmManagerService.h index 2424ea5..7727e55 100644 --- a/drm/libdrmframework/include/IDrmManagerService.h +++ b/drm/libdrmframework/include/IDrmManagerService.h @@ -25,7 +25,6 @@ namespace android { -class DrmContentIds; class DrmConstraints; class DrmMetadata; class DrmRights; diff --git a/drm/libdrmframework/plugins/common/include/IDrmEngine.h b/drm/libdrmframework/plugins/common/include/IDrmEngine.h index d05c24f..77460f6 100644 --- a/drm/libdrmframework/plugins/common/include/IDrmEngine.h +++ b/drm/libdrmframework/plugins/common/include/IDrmEngine.h @@ -21,7 +21,6 @@ namespace android { -class DrmContentIds; class DrmConstraints; class DrmMetadata; class DrmRights; -- cgit v1.1 From 79cbc13ede26d08ab6633a042843a9d154c3c166 Mon Sep 17 00:00:00 2001 From: Gloria Wang Date: Thu, 17 Mar 2011 15:02:34 -0700 Subject: Fix for bug 4126103. mMessage in DrmInfoEvent is a reference to the message string, so the temporary message created in the plugin was going out of scope and being destructed while the message was being sent. Changed DrmInfoEvent's mMessage to be const String8 instead of const String8& Change-Id: I174197ad24f3df997d3bc1f897658cfc53862636 --- drm/common/DrmInfoEvent.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drm') diff --git a/drm/common/DrmInfoEvent.cpp b/drm/common/DrmInfoEvent.cpp index 8d115a8..27a5a2d 100644 --- a/drm/common/DrmInfoEvent.cpp +++ b/drm/common/DrmInfoEvent.cpp @@ -19,7 +19,7 @@ using namespace android; -DrmInfoEvent::DrmInfoEvent(int uniqueId, int infoType, const String8& message) +DrmInfoEvent::DrmInfoEvent(int uniqueId, int infoType, const String8 message) : mUniqueId(uniqueId), mInfoType(infoType), mMessage(message) { @@ -34,7 +34,7 @@ int DrmInfoEvent::getType() const { return mInfoType; } -const String8& DrmInfoEvent::getMessage() const { +const String8 DrmInfoEvent::getMessage() const { return mMessage; } -- cgit v1.1 From 1da9aa606096e14985924e8433a087d04f68ea22 Mon Sep 17 00:00:00 2001 From: Gloria Wang Date: Sun, 20 Mar 2011 10:25:16 -0700 Subject: Fix for 4084554. DRM framework support for enabling/disabling copy control settings from a DRM plugin Change-Id: I6529695cc4adbab2b9a63708bb459e3b77e07564 --- drm/common/IDrmManagerService.cpp | 276 ++++++++++++-------------------------- 1 file changed, 88 insertions(+), 188 deletions(-) (limited to 'drm') diff --git a/drm/common/IDrmManagerService.cpp b/drm/common/IDrmManagerService.cpp index e2bfb16..1f117c6 100644 --- a/drm/common/IDrmManagerService.cpp +++ b/drm/common/IDrmManagerService.cpp @@ -37,6 +37,63 @@ using namespace android; +static void writeDecrptHandleToParcelData( + const DecryptHandle* handle, Parcel* data) { + data->writeInt32(handle->decryptId); + data->writeString8(handle->mimeType); + data->writeInt32(handle->decryptApiType); + data->writeInt32(handle->status); + + int size = handle->copyControlVector.size(); + data->writeInt32(size); + for(int i = 0; i < size; i++) { + data->writeInt32(handle->copyControlVector.keyAt(i)); + data->writeInt32(handle->copyControlVector.valueAt(i)); + } + + if (NULL != handle->decryptInfo) { + data->writeInt32(handle->decryptInfo->decryptBufferLength); + } else { + data->writeInt32(INVALID_BUFFER_LENGTH); + } +} + +static void readDecryptHandleFromParcelData( + DecryptHandle* handle, const Parcel& data) { + if (0 == data.dataAvail()) { + return; + } + + handle->decryptId = data.readInt32(); + handle->mimeType = data.readString8(); + handle->decryptApiType = data.readInt32(); + handle->status = data.readInt32(); + + int size = data.readInt32(); + for (int i = 0; i < size; i ++) { + handle->copyControlVector.add( + (DrmCopyControl)data.readInt32(), data.readInt32()); + } + + handle->decryptInfo = NULL; + const int bufferLen = data.readInt32(); + if (INVALID_BUFFER_LENGTH != bufferLen) { + handle->decryptInfo = new DecryptInfo(); + handle->decryptInfo->decryptBufferLength = bufferLen; + } +} + +static void clearDecryptHandle(DecryptHandle* handle) { + if (handle == NULL) { + return; + } + if (handle->decryptInfo) { + delete handle->decryptInfo; + handle->decryptInfo = NULL; + } + handle->copyControlVector.clear(); +} + int BpDrmManagerService::addUniqueId(int uniqueId) { LOGV("add uniqueid"); Parcel data, reply; @@ -344,16 +401,7 @@ status_t BpDrmManagerService::consumeRights( data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); data.writeInt32(uniqueId); - data.writeInt32(decryptHandle->decryptId); - data.writeString8(decryptHandle->mimeType); - data.writeInt32(decryptHandle->decryptApiType); - data.writeInt32(decryptHandle->status); - - if (NULL != decryptHandle->decryptInfo) { - data.writeInt32(decryptHandle->decryptInfo->decryptBufferLength); - } else { - data.writeInt32(INVALID_BUFFER_LENGTH); - } + writeDecrptHandleToParcelData(decryptHandle, &data); data.writeInt32(action); data.writeInt32(static_cast< int>(reserve)); @@ -370,16 +418,7 @@ status_t BpDrmManagerService::setPlaybackStatus( data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); data.writeInt32(uniqueId); - data.writeInt32(decryptHandle->decryptId); - data.writeString8(decryptHandle->mimeType); - data.writeInt32(decryptHandle->decryptApiType); - data.writeInt32(decryptHandle->status); - - if (NULL != decryptHandle->decryptInfo) { - data.writeInt32(decryptHandle->decryptInfo->decryptBufferLength); - } else { - data.writeInt32(INVALID_BUFFER_LENGTH); - } + writeDecrptHandleToParcelData(decryptHandle, &data); data.writeInt32(playbackStatus); data.writeInt64(position); @@ -560,15 +599,7 @@ DecryptHandle* BpDrmManagerService::openDecryptSession( DecryptHandle* handle = NULL; if (0 != reply.dataAvail()) { handle = new DecryptHandle(); - handle->decryptId = reply.readInt32(); - handle->mimeType = reply.readString8(); - handle->decryptApiType = reply.readInt32(); - handle->status = reply.readInt32(); - handle->decryptInfo = NULL; - if (0 != reply.dataAvail()) { - handle->decryptInfo = new DecryptInfo(); - handle->decryptInfo->decryptBufferLength = reply.readInt32(); - } + readDecryptHandleFromParcelData(handle, reply); } return handle; } @@ -586,15 +617,7 @@ DecryptHandle* BpDrmManagerService::openDecryptSession(int uniqueId, const char* DecryptHandle* handle = NULL; if (0 != reply.dataAvail()) { handle = new DecryptHandle(); - handle->decryptId = reply.readInt32(); - handle->mimeType = reply.readString8(); - handle->decryptApiType = reply.readInt32(); - handle->status = reply.readInt32(); - handle->decryptInfo = NULL; - if (0 != reply.dataAvail()) { - handle->decryptInfo = new DecryptInfo(); - handle->decryptInfo->decryptBufferLength = reply.readInt32(); - } + readDecryptHandleFromParcelData(handle, reply); } else { LOGV("no decryptHandle is generated in service side"); } @@ -608,16 +631,7 @@ status_t BpDrmManagerService::closeDecryptSession(int uniqueId, DecryptHandle* d data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); data.writeInt32(uniqueId); - data.writeInt32(decryptHandle->decryptId); - data.writeString8(decryptHandle->mimeType); - data.writeInt32(decryptHandle->decryptApiType); - data.writeInt32(decryptHandle->status); - - if (NULL != decryptHandle->decryptInfo) { - data.writeInt32(decryptHandle->decryptInfo->decryptBufferLength); - } else { - data.writeInt32(INVALID_BUFFER_LENGTH); - } + writeDecrptHandleToParcelData(decryptHandle, &data); remote()->transact(CLOSE_DECRYPT_SESSION, data, &reply); @@ -633,16 +647,8 @@ status_t BpDrmManagerService::initializeDecryptUnit( data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); data.writeInt32(uniqueId); - data.writeInt32(decryptHandle->decryptId); - data.writeString8(decryptHandle->mimeType); - data.writeInt32(decryptHandle->decryptApiType); - data.writeInt32(decryptHandle->status); + writeDecrptHandleToParcelData(decryptHandle, &data); - if (NULL != decryptHandle->decryptInfo) { - data.writeInt32(decryptHandle->decryptInfo->decryptBufferLength); - } else { - data.writeInt32(INVALID_BUFFER_LENGTH); - } data.writeInt32(decryptUnitId); data.writeInt32(headerInfo->length); @@ -661,16 +667,7 @@ status_t BpDrmManagerService::decrypt( data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); data.writeInt32(uniqueId); - data.writeInt32(decryptHandle->decryptId); - data.writeString8(decryptHandle->mimeType); - data.writeInt32(decryptHandle->decryptApiType); - data.writeInt32(decryptHandle->status); - - if (NULL != decryptHandle->decryptInfo) { - data.writeInt32(decryptHandle->decryptInfo->decryptBufferLength); - } else { - data.writeInt32(INVALID_BUFFER_LENGTH); - } + writeDecrptHandleToParcelData(decryptHandle, &data); data.writeInt32(decryptUnitId); data.writeInt32((*decBuffer)->length); @@ -703,16 +700,7 @@ status_t BpDrmManagerService::finalizeDecryptUnit( data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); data.writeInt32(uniqueId); - data.writeInt32(decryptHandle->decryptId); - data.writeString8(decryptHandle->mimeType); - data.writeInt32(decryptHandle->decryptApiType); - data.writeInt32(decryptHandle->status); - - if (NULL != decryptHandle->decryptInfo) { - data.writeInt32(decryptHandle->decryptInfo->decryptBufferLength); - } else { - data.writeInt32(INVALID_BUFFER_LENGTH); - } + writeDecrptHandleToParcelData(decryptHandle, &data); data.writeInt32(decryptUnitId); @@ -730,16 +718,7 @@ ssize_t BpDrmManagerService::pread( data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); data.writeInt32(uniqueId); - data.writeInt32(decryptHandle->decryptId); - data.writeString8(decryptHandle->mimeType); - data.writeInt32(decryptHandle->decryptApiType); - data.writeInt32(decryptHandle->status); - - if (NULL != decryptHandle->decryptInfo) { - data.writeInt32(decryptHandle->decryptInfo->decryptBufferLength); - } else { - data.writeInt32(INVALID_BUFFER_LENGTH); - } + writeDecrptHandleToParcelData(decryptHandle, &data); data.writeInt32(numBytes); data.writeInt64(offset); @@ -1064,24 +1043,14 @@ status_t BnDrmManagerService::onTransact( const int uniqueId = data.readInt32(); DecryptHandle handle; - handle.decryptId = data.readInt32(); - handle.mimeType = data.readString8(); - handle.decryptApiType = data.readInt32(); - handle.status = data.readInt32(); - handle.decryptInfo = NULL; - - const int bufferLength = data.readInt32(); - if (INVALID_BUFFER_LENGTH != bufferLength) { - handle.decryptInfo = new DecryptInfo(); - handle.decryptInfo->decryptBufferLength = bufferLength; - } + readDecryptHandleFromParcelData(&handle, data); const status_t status = consumeRights(uniqueId, &handle, data.readInt32(), static_cast(data.readInt32())); reply->writeInt32(status); - delete handle.decryptInfo; handle.decryptInfo = NULL; + clearDecryptHandle(&handle); return DRM_NO_ERROR; } @@ -1093,23 +1062,13 @@ status_t BnDrmManagerService::onTransact( const int uniqueId = data.readInt32(); DecryptHandle handle; - handle.decryptId = data.readInt32(); - handle.mimeType = data.readString8(); - handle.decryptApiType = data.readInt32(); - handle.status = data.readInt32(); - handle.decryptInfo = NULL; - - const int bufferLength = data.readInt32(); - if (INVALID_BUFFER_LENGTH != bufferLength) { - handle.decryptInfo = new DecryptInfo(); - handle.decryptInfo->decryptBufferLength = bufferLength; - } + readDecryptHandleFromParcelData(&handle, data); const status_t status = setPlaybackStatus(uniqueId, &handle, data.readInt32(), data.readInt64()); reply->writeInt32(status); - delete handle.decryptInfo; handle.decryptInfo = NULL; + clearDecryptHandle(&handle); return DRM_NO_ERROR; } @@ -1270,16 +1229,10 @@ status_t BnDrmManagerService::onTransact( = openDecryptSession(uniqueId, fd, data.readInt64(), data.readInt64()); if (NULL != handle) { - reply->writeInt32(handle->decryptId); - reply->writeString8(handle->mimeType); - reply->writeInt32(handle->decryptApiType); - reply->writeInt32(handle->status); - if (NULL != handle->decryptInfo) { - reply->writeInt32(handle->decryptInfo->decryptBufferLength); - delete handle->decryptInfo; handle->decryptInfo = NULL; - } + writeDecrptHandleToParcelData(handle, reply); + clearDecryptHandle(handle); + delete handle; handle = NULL; } - delete handle; handle = NULL; return DRM_NO_ERROR; } @@ -1294,18 +1247,13 @@ status_t BnDrmManagerService::onTransact( DecryptHandle* handle = openDecryptSession(uniqueId, uri.string()); if (NULL != handle) { - reply->writeInt32(handle->decryptId); - reply->writeString8(handle->mimeType); - reply->writeInt32(handle->decryptApiType); - reply->writeInt32(handle->status); - if (NULL != handle->decryptInfo) { - reply->writeInt32(handle->decryptInfo->decryptBufferLength); - delete handle->decryptInfo; handle->decryptInfo = NULL; - } + writeDecrptHandleToParcelData(handle, reply); + + clearDecryptHandle(handle); + delete handle; handle = NULL; } else { LOGV("NULL decryptHandle is returned"); } - delete handle; handle = NULL; return DRM_NO_ERROR; } @@ -1317,17 +1265,7 @@ status_t BnDrmManagerService::onTransact( const int uniqueId = data.readInt32(); DecryptHandle* handle = new DecryptHandle(); - handle->decryptId = data.readInt32(); - handle->mimeType = data.readString8(); - handle->decryptApiType = data.readInt32(); - handle->status = data.readInt32(); - handle->decryptInfo = NULL; - - const int bufferLength = data.readInt32(); - if (INVALID_BUFFER_LENGTH != bufferLength) { - handle->decryptInfo = new DecryptInfo(); - handle->decryptInfo->decryptBufferLength = bufferLength; - } + readDecryptHandleFromParcelData(handle, data); const status_t status = closeDecryptSession(uniqueId, handle); reply->writeInt32(status); @@ -1342,17 +1280,8 @@ status_t BnDrmManagerService::onTransact( const int uniqueId = data.readInt32(); DecryptHandle handle; - handle.decryptId = data.readInt32(); - handle.mimeType = data.readString8(); - handle.decryptApiType = data.readInt32(); - handle.status = data.readInt32(); - handle.decryptInfo = NULL; - - const int bufferLength = data.readInt32(); - if (INVALID_BUFFER_LENGTH != bufferLength) { - handle.decryptInfo = new DecryptInfo(); - handle.decryptInfo->decryptBufferLength = bufferLength; - } + readDecryptHandleFromParcelData(&handle, data); + const int decryptUnitId = data.readInt32(); //Filling Header info @@ -1364,7 +1293,7 @@ status_t BnDrmManagerService::onTransact( = initializeDecryptUnit(uniqueId, &handle, decryptUnitId, headerInfo); reply->writeInt32(status); - delete handle.decryptInfo; handle.decryptInfo = NULL; + clearDecryptHandle(&handle); delete headerInfo; headerInfo = NULL; return DRM_NO_ERROR; } @@ -1377,17 +1306,8 @@ status_t BnDrmManagerService::onTransact( const int uniqueId = data.readInt32(); DecryptHandle handle; - handle.decryptId = data.readInt32(); - handle.mimeType = data.readString8(); - handle.decryptApiType = data.readInt32(); - handle.status = data.readInt32(); - handle.decryptInfo = NULL; - - const int bufferLength = data.readInt32(); - if (INVALID_BUFFER_LENGTH != bufferLength) { - handle.decryptInfo = new DecryptInfo(); - handle.decryptInfo->decryptBufferLength = bufferLength; - } + readDecryptHandleFromParcelData(&handle, data); + const int decryptUnitId = data.readInt32(); const int decBufferSize = data.readInt32(); @@ -1414,7 +1334,7 @@ status_t BnDrmManagerService::onTransact( reply->writeInt32(size); reply->write(decBuffer->data, size); - delete handle.decryptInfo; handle.decryptInfo = NULL; + clearDecryptHandle(&handle); delete encBuffer; encBuffer = NULL; delete decBuffer; decBuffer = NULL; delete [] buffer; buffer = NULL; @@ -1430,22 +1350,12 @@ status_t BnDrmManagerService::onTransact( const int uniqueId = data.readInt32(); DecryptHandle handle; - handle.decryptId = data.readInt32(); - handle.mimeType = data.readString8(); - handle.decryptApiType = data.readInt32(); - handle.status = data.readInt32(); - handle.decryptInfo = NULL; - - const int bufferLength = data.readInt32(); - if (INVALID_BUFFER_LENGTH != bufferLength) { - handle.decryptInfo = new DecryptInfo(); - handle.decryptInfo->decryptBufferLength = bufferLength; - } + readDecryptHandleFromParcelData(&handle, data); const status_t status = finalizeDecryptUnit(uniqueId, &handle, data.readInt32()); reply->writeInt32(status); - delete handle.decryptInfo; handle.decryptInfo = NULL; + clearDecryptHandle(&handle); return DRM_NO_ERROR; } @@ -1457,17 +1367,7 @@ status_t BnDrmManagerService::onTransact( const int uniqueId = data.readInt32(); DecryptHandle handle; - handle.decryptId = data.readInt32(); - handle.mimeType = data.readString8(); - handle.decryptApiType = data.readInt32(); - handle.status = data.readInt32(); - handle.decryptInfo = NULL; - - const int bufferLength = data.readInt32(); - if (INVALID_BUFFER_LENGTH != bufferLength) { - handle.decryptInfo = new DecryptInfo(); - handle.decryptInfo->decryptBufferLength = bufferLength; - } + readDecryptHandleFromParcelData(&handle, data); const int numBytes = data.readInt32(); char* buffer = new char[numBytes]; @@ -1480,7 +1380,7 @@ status_t BnDrmManagerService::onTransact( reply->write(buffer, result); } - delete handle.decryptInfo; handle.decryptInfo = NULL; + clearDecryptHandle(&handle); delete [] buffer, buffer = NULL; return DRM_NO_ERROR; } -- cgit v1.1 From 4dabc20fa21f78a0bc2f91f772ad449ac8b17028 Mon Sep 17 00:00:00 2001 From: Gloria Wang Date: Mon, 21 Mar 2011 16:53:14 -0700 Subject: do not merge: Cherry pick change I6529695c from master to partially fix bug 4126624. Change-Id: If724de60bd6da1becdffc815d5358ffe78629469 --- drm/common/IDrmManagerService.cpp | 276 ++++++++++++-------------------------- 1 file changed, 88 insertions(+), 188 deletions(-) (limited to 'drm') diff --git a/drm/common/IDrmManagerService.cpp b/drm/common/IDrmManagerService.cpp index 696e305..16f1dd0 100644 --- a/drm/common/IDrmManagerService.cpp +++ b/drm/common/IDrmManagerService.cpp @@ -37,6 +37,63 @@ using namespace android; +static void writeDecrptHandleToParcelData( + const DecryptHandle* handle, Parcel* data) { + data->writeInt32(handle->decryptId); + data->writeString8(handle->mimeType); + data->writeInt32(handle->decryptApiType); + data->writeInt32(handle->status); + + int size = handle->copyControlVector.size(); + data->writeInt32(size); + for(int i = 0; i < size; i++) { + data->writeInt32(handle->copyControlVector.keyAt(i)); + data->writeInt32(handle->copyControlVector.valueAt(i)); + } + + if (NULL != handle->decryptInfo) { + data->writeInt32(handle->decryptInfo->decryptBufferLength); + } else { + data->writeInt32(INVALID_BUFFER_LENGTH); + } +} + +static void readDecryptHandleFromParcelData( + DecryptHandle* handle, const Parcel& data) { + if (0 == data.dataAvail()) { + return; + } + + handle->decryptId = data.readInt32(); + handle->mimeType = data.readString8(); + handle->decryptApiType = data.readInt32(); + handle->status = data.readInt32(); + + int size = data.readInt32(); + for (int i = 0; i < size; i ++) { + handle->copyControlVector.add( + (DrmCopyControl)data.readInt32(), data.readInt32()); + } + + handle->decryptInfo = NULL; + const int bufferLen = data.readInt32(); + if (INVALID_BUFFER_LENGTH != bufferLen) { + handle->decryptInfo = new DecryptInfo(); + handle->decryptInfo->decryptBufferLength = bufferLen; + } +} + +static void clearDecryptHandle(DecryptHandle* handle) { + if (handle == NULL) { + return; + } + if (handle->decryptInfo) { + delete handle->decryptInfo; + handle->decryptInfo = NULL; + } + handle->copyControlVector.clear(); +} + int BpDrmManagerService::addUniqueId(int uniqueId) { LOGV("add uniqueid"); Parcel data, reply; @@ -344,16 +401,7 @@ status_t BpDrmManagerService::consumeRights( data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); data.writeInt32(uniqueId); - data.writeInt32(decryptHandle->decryptId); - data.writeString8(decryptHandle->mimeType); - data.writeInt32(decryptHandle->decryptApiType); - data.writeInt32(decryptHandle->status); - - if (NULL != decryptHandle->decryptInfo) { - data.writeInt32(decryptHandle->decryptInfo->decryptBufferLength); - } else { - data.writeInt32(INVALID_BUFFER_LENGTH); - } + writeDecrptHandleToParcelData(decryptHandle, &data); data.writeInt32(action); data.writeInt32(static_cast< int>(reserve)); @@ -370,16 +418,7 @@ status_t BpDrmManagerService::setPlaybackStatus( data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); data.writeInt32(uniqueId); - data.writeInt32(decryptHandle->decryptId); - data.writeString8(decryptHandle->mimeType); - data.writeInt32(decryptHandle->decryptApiType); - data.writeInt32(decryptHandle->status); - - if (NULL != decryptHandle->decryptInfo) { - data.writeInt32(decryptHandle->decryptInfo->decryptBufferLength); - } else { - data.writeInt32(INVALID_BUFFER_LENGTH); - } + writeDecrptHandleToParcelData(decryptHandle, &data); data.writeInt32(playbackStatus); data.writeInt64(position); @@ -560,15 +599,7 @@ DecryptHandle* BpDrmManagerService::openDecryptSession( DecryptHandle* handle = NULL; if (0 != reply.dataAvail()) { handle = new DecryptHandle(); - handle->decryptId = reply.readInt32(); - handle->mimeType = reply.readString8(); - handle->decryptApiType = reply.readInt32(); - handle->status = reply.readInt32(); - handle->decryptInfo = NULL; - if (0 != reply.dataAvail()) { - handle->decryptInfo = new DecryptInfo(); - handle->decryptInfo->decryptBufferLength = reply.readInt32(); - } + readDecryptHandleFromParcelData(handle, reply); } return handle; } @@ -586,15 +617,7 @@ DecryptHandle* BpDrmManagerService::openDecryptSession(int uniqueId, const char* DecryptHandle* handle = NULL; if (0 != reply.dataAvail()) { handle = new DecryptHandle(); - handle->decryptId = reply.readInt32(); - handle->mimeType = reply.readString8(); - handle->decryptApiType = reply.readInt32(); - handle->status = reply.readInt32(); - handle->decryptInfo = NULL; - if (0 != reply.dataAvail()) { - handle->decryptInfo = new DecryptInfo(); - handle->decryptInfo->decryptBufferLength = reply.readInt32(); - } + readDecryptHandleFromParcelData(handle, reply); } else { LOGV("no decryptHandle is generated in service side"); } @@ -608,16 +631,7 @@ status_t BpDrmManagerService::closeDecryptSession(int uniqueId, DecryptHandle* d data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); data.writeInt32(uniqueId); - data.writeInt32(decryptHandle->decryptId); - data.writeString8(decryptHandle->mimeType); - data.writeInt32(decryptHandle->decryptApiType); - data.writeInt32(decryptHandle->status); - - if (NULL != decryptHandle->decryptInfo) { - data.writeInt32(decryptHandle->decryptInfo->decryptBufferLength); - } else { - data.writeInt32(INVALID_BUFFER_LENGTH); - } + writeDecrptHandleToParcelData(decryptHandle, &data); remote()->transact(CLOSE_DECRYPT_SESSION, data, &reply); @@ -638,16 +652,8 @@ status_t BpDrmManagerService::initializeDecryptUnit( data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); data.writeInt32(uniqueId); - data.writeInt32(decryptHandle->decryptId); - data.writeString8(decryptHandle->mimeType); - data.writeInt32(decryptHandle->decryptApiType); - data.writeInt32(decryptHandle->status); + writeDecrptHandleToParcelData(decryptHandle, &data); - if (NULL != decryptHandle->decryptInfo) { - data.writeInt32(decryptHandle->decryptInfo->decryptBufferLength); - } else { - data.writeInt32(INVALID_BUFFER_LENGTH); - } data.writeInt32(decryptUnitId); data.writeInt32(headerInfo->length); @@ -666,16 +672,7 @@ status_t BpDrmManagerService::decrypt( data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); data.writeInt32(uniqueId); - data.writeInt32(decryptHandle->decryptId); - data.writeString8(decryptHandle->mimeType); - data.writeInt32(decryptHandle->decryptApiType); - data.writeInt32(decryptHandle->status); - - if (NULL != decryptHandle->decryptInfo) { - data.writeInt32(decryptHandle->decryptInfo->decryptBufferLength); - } else { - data.writeInt32(INVALID_BUFFER_LENGTH); - } + writeDecrptHandleToParcelData(decryptHandle, &data); data.writeInt32(decryptUnitId); data.writeInt32((*decBuffer)->length); @@ -708,16 +705,7 @@ status_t BpDrmManagerService::finalizeDecryptUnit( data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); data.writeInt32(uniqueId); - data.writeInt32(decryptHandle->decryptId); - data.writeString8(decryptHandle->mimeType); - data.writeInt32(decryptHandle->decryptApiType); - data.writeInt32(decryptHandle->status); - - if (NULL != decryptHandle->decryptInfo) { - data.writeInt32(decryptHandle->decryptInfo->decryptBufferLength); - } else { - data.writeInt32(INVALID_BUFFER_LENGTH); - } + writeDecrptHandleToParcelData(decryptHandle, &data); data.writeInt32(decryptUnitId); @@ -735,16 +723,7 @@ ssize_t BpDrmManagerService::pread( data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); data.writeInt32(uniqueId); - data.writeInt32(decryptHandle->decryptId); - data.writeString8(decryptHandle->mimeType); - data.writeInt32(decryptHandle->decryptApiType); - data.writeInt32(decryptHandle->status); - - if (NULL != decryptHandle->decryptInfo) { - data.writeInt32(decryptHandle->decryptInfo->decryptBufferLength); - } else { - data.writeInt32(INVALID_BUFFER_LENGTH); - } + writeDecrptHandleToParcelData(decryptHandle, &data); data.writeInt32(numBytes); data.writeInt64(offset); @@ -1069,24 +1048,14 @@ status_t BnDrmManagerService::onTransact( const int uniqueId = data.readInt32(); DecryptHandle handle; - handle.decryptId = data.readInt32(); - handle.mimeType = data.readString8(); - handle.decryptApiType = data.readInt32(); - handle.status = data.readInt32(); - handle.decryptInfo = NULL; - - const int bufferLength = data.readInt32(); - if (INVALID_BUFFER_LENGTH != bufferLength) { - handle.decryptInfo = new DecryptInfo(); - handle.decryptInfo->decryptBufferLength = bufferLength; - } + readDecryptHandleFromParcelData(&handle, data); const status_t status = consumeRights(uniqueId, &handle, data.readInt32(), static_cast(data.readInt32())); reply->writeInt32(status); - delete handle.decryptInfo; handle.decryptInfo = NULL; + clearDecryptHandle(&handle); return DRM_NO_ERROR; } @@ -1098,23 +1067,13 @@ status_t BnDrmManagerService::onTransact( const int uniqueId = data.readInt32(); DecryptHandle handle; - handle.decryptId = data.readInt32(); - handle.mimeType = data.readString8(); - handle.decryptApiType = data.readInt32(); - handle.status = data.readInt32(); - handle.decryptInfo = NULL; - - const int bufferLength = data.readInt32(); - if (INVALID_BUFFER_LENGTH != bufferLength) { - handle.decryptInfo = new DecryptInfo(); - handle.decryptInfo->decryptBufferLength = bufferLength; - } + readDecryptHandleFromParcelData(&handle, data); const status_t status = setPlaybackStatus(uniqueId, &handle, data.readInt32(), data.readInt64()); reply->writeInt32(status); - delete handle.decryptInfo; handle.decryptInfo = NULL; + clearDecryptHandle(&handle); return DRM_NO_ERROR; } @@ -1275,16 +1234,10 @@ status_t BnDrmManagerService::onTransact( = openDecryptSession(uniqueId, fd, data.readInt64(), data.readInt64()); if (NULL != handle) { - reply->writeInt32(handle->decryptId); - reply->writeString8(handle->mimeType); - reply->writeInt32(handle->decryptApiType); - reply->writeInt32(handle->status); - if (NULL != handle->decryptInfo) { - reply->writeInt32(handle->decryptInfo->decryptBufferLength); - delete handle->decryptInfo; handle->decryptInfo = NULL; - } + writeDecrptHandleToParcelData(handle, reply); + clearDecryptHandle(handle); + delete handle; handle = NULL; } - delete handle; handle = NULL; return DRM_NO_ERROR; } @@ -1299,18 +1252,13 @@ status_t BnDrmManagerService::onTransact( DecryptHandle* handle = openDecryptSession(uniqueId, uri.string()); if (NULL != handle) { - reply->writeInt32(handle->decryptId); - reply->writeString8(handle->mimeType); - reply->writeInt32(handle->decryptApiType); - reply->writeInt32(handle->status); - if (NULL != handle->decryptInfo) { - reply->writeInt32(handle->decryptInfo->decryptBufferLength); - delete handle->decryptInfo; handle->decryptInfo = NULL; - } + writeDecrptHandleToParcelData(handle, reply); + + clearDecryptHandle(handle); + delete handle; handle = NULL; } else { LOGV("NULL decryptHandle is returned"); } - delete handle; handle = NULL; return DRM_NO_ERROR; } @@ -1322,17 +1270,7 @@ status_t BnDrmManagerService::onTransact( const int uniqueId = data.readInt32(); DecryptHandle* handle = new DecryptHandle(); - handle->decryptId = data.readInt32(); - handle->mimeType = data.readString8(); - handle->decryptApiType = data.readInt32(); - handle->status = data.readInt32(); - handle->decryptInfo = NULL; - - const int bufferLength = data.readInt32(); - if (INVALID_BUFFER_LENGTH != bufferLength) { - handle->decryptInfo = new DecryptInfo(); - handle->decryptInfo->decryptBufferLength = bufferLength; - } + readDecryptHandleFromParcelData(handle, data); const status_t status = closeDecryptSession(uniqueId, handle); reply->writeInt32(status); @@ -1347,17 +1285,8 @@ status_t BnDrmManagerService::onTransact( const int uniqueId = data.readInt32(); DecryptHandle handle; - handle.decryptId = data.readInt32(); - handle.mimeType = data.readString8(); - handle.decryptApiType = data.readInt32(); - handle.status = data.readInt32(); - handle.decryptInfo = NULL; - - const int bufferLength = data.readInt32(); - if (INVALID_BUFFER_LENGTH != bufferLength) { - handle.decryptInfo = new DecryptInfo(); - handle.decryptInfo->decryptBufferLength = bufferLength; - } + readDecryptHandleFromParcelData(&handle, data); + const int decryptUnitId = data.readInt32(); //Filling Header info @@ -1369,7 +1298,7 @@ status_t BnDrmManagerService::onTransact( = initializeDecryptUnit(uniqueId, &handle, decryptUnitId, headerInfo); reply->writeInt32(status); - delete handle.decryptInfo; handle.decryptInfo = NULL; + clearDecryptHandle(&handle); delete headerInfo; headerInfo = NULL; return DRM_NO_ERROR; } @@ -1382,17 +1311,8 @@ status_t BnDrmManagerService::onTransact( const int uniqueId = data.readInt32(); DecryptHandle handle; - handle.decryptId = data.readInt32(); - handle.mimeType = data.readString8(); - handle.decryptApiType = data.readInt32(); - handle.status = data.readInt32(); - handle.decryptInfo = NULL; - - const int bufferLength = data.readInt32(); - if (INVALID_BUFFER_LENGTH != bufferLength) { - handle.decryptInfo = new DecryptInfo(); - handle.decryptInfo->decryptBufferLength = bufferLength; - } + readDecryptHandleFromParcelData(&handle, data); + const int decryptUnitId = data.readInt32(); const int decBufferSize = data.readInt32(); @@ -1419,7 +1339,7 @@ status_t BnDrmManagerService::onTransact( reply->writeInt32(size); reply->write(decBuffer->data, size); - delete handle.decryptInfo; handle.decryptInfo = NULL; + clearDecryptHandle(&handle); delete encBuffer; encBuffer = NULL; delete decBuffer; decBuffer = NULL; delete [] buffer; buffer = NULL; @@ -1435,22 +1355,12 @@ status_t BnDrmManagerService::onTransact( const int uniqueId = data.readInt32(); DecryptHandle handle; - handle.decryptId = data.readInt32(); - handle.mimeType = data.readString8(); - handle.decryptApiType = data.readInt32(); - handle.status = data.readInt32(); - handle.decryptInfo = NULL; - - const int bufferLength = data.readInt32(); - if (INVALID_BUFFER_LENGTH != bufferLength) { - handle.decryptInfo = new DecryptInfo(); - handle.decryptInfo->decryptBufferLength = bufferLength; - } + readDecryptHandleFromParcelData(&handle, data); const status_t status = finalizeDecryptUnit(uniqueId, &handle, data.readInt32()); reply->writeInt32(status); - delete handle.decryptInfo; handle.decryptInfo = NULL; + clearDecryptHandle(&handle); return DRM_NO_ERROR; } @@ -1462,17 +1372,7 @@ status_t BnDrmManagerService::onTransact( const int uniqueId = data.readInt32(); DecryptHandle handle; - handle.decryptId = data.readInt32(); - handle.mimeType = data.readString8(); - handle.decryptApiType = data.readInt32(); - handle.status = data.readInt32(); - handle.decryptInfo = NULL; - - const int bufferLength = data.readInt32(); - if (INVALID_BUFFER_LENGTH != bufferLength) { - handle.decryptInfo = new DecryptInfo(); - handle.decryptInfo->decryptBufferLength = bufferLength; - } + readDecryptHandleFromParcelData(&handle, data); const int numBytes = data.readInt32(); char* buffer = new char[numBytes]; @@ -1485,7 +1385,7 @@ status_t BnDrmManagerService::onTransact( reply->write(buffer, result); } - delete handle.decryptInfo; handle.decryptInfo = NULL; + clearDecryptHandle(&handle); delete [] buffer, buffer = NULL; return DRM_NO_ERROR; } -- cgit v1.1 From 6b2a35bbec228ce012065260ba153ee894f17a4e Mon Sep 17 00:00:00 2001 From: Gloria Wang Date: Mon, 21 Mar 2011 17:22:13 -0700 Subject: Add one more field in DecryptHandle to support bug 4126624 Change-Id: Ic7ea5fd211c4f8283de8fdf722f89b6a94e5750b --- drm/common/IDrmManagerService.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'drm') diff --git a/drm/common/IDrmManagerService.cpp b/drm/common/IDrmManagerService.cpp index 16f1dd0..346934b 100644 --- a/drm/common/IDrmManagerService.cpp +++ b/drm/common/IDrmManagerService.cpp @@ -51,6 +51,13 @@ static void writeDecrptHandleToParcelData( data->writeInt32(handle->copyControlVector.valueAt(i)); } + size = handle->extendedData.size(); + data->writeInt32(size); + for(int i = 0; i < size; i++) { + data->writeString8(handle->extendedData.keyAt(i)); + data->writeString8(handle->extendedData.valueAt(i)); + } + if (NULL != handle->decryptInfo) { data->writeInt32(handle->decryptInfo->decryptBufferLength); } else { @@ -71,8 +78,16 @@ static void readDecryptHandleFromParcelData( int size = data.readInt32(); for (int i = 0; i < size; i ++) { - handle->copyControlVector.add( - (DrmCopyControl)data.readInt32(), data.readInt32()); + DrmCopyControl key = (DrmCopyControl)data.readInt32(); + int value = data.readInt32(); + handle->copyControlVector.add(key, value); + } + + size = data.readInt32(); + for (int i = 0; i < size; i ++) { + String8 key = data.readString8(); + String8 value = data.readString8(); + handle->extendedData.add(key, value); } handle->decryptInfo = NULL; -- cgit v1.1 From 21e7c33eaf8772819bf57fe9557885e4ebc43e1b Mon Sep 17 00:00:00 2001 From: Carl Shapiro Date: Tue, 22 Mar 2011 11:51:57 -0700 Subject: Include strings.h for the strcasecmp prototype. Change-Id: I83cd464d59d16f1c5f8afa7e50d474ca2bb41713 --- drm/common/DrmSupportInfo.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drm') diff --git a/drm/common/DrmSupportInfo.cpp b/drm/common/DrmSupportInfo.cpp index c0bff0e..3dee435 100644 --- a/drm/common/DrmSupportInfo.cpp +++ b/drm/common/DrmSupportInfo.cpp @@ -15,6 +15,7 @@ */ #include +#include using namespace android; @@ -152,4 +153,3 @@ String8& DrmSupportInfo::MimeTypeIterator::next() { mIndex++; return value; } - -- cgit v1.1 From 07d0220bcc9036bcbe36819912559267d9c1c538 Mon Sep 17 00:00:00 2001 From: Gloria Wang Date: Wed, 23 Mar 2011 22:35:13 -0700 Subject: Fix for bug 4165823. Add death listener to clean-up drmserver appropriately when drmserver died. Cherry-pick from master. Do not merge. Change-Id: I7782cc96ce173a87ebfd315950f3880fa90294d6 --- drm/libdrmframework/DrmManagerClientImpl.cpp | 32 ++++++++++++++++------ drm/libdrmframework/include/DrmManagerClientImpl.h | 12 ++++++-- 2 files changed, 34 insertions(+), 10 deletions(-) (limited to 'drm') diff --git a/drm/libdrmframework/DrmManagerClientImpl.cpp b/drm/libdrmframework/DrmManagerClientImpl.cpp index d20de92..9c7fed3 100644 --- a/drm/libdrmframework/DrmManagerClientImpl.cpp +++ b/drm/libdrmframework/DrmManagerClientImpl.cpp @@ -28,8 +28,9 @@ using namespace android; #define INVALID_VALUE -1 -Mutex DrmManagerClientImpl::mMutex; -sp DrmManagerClientImpl::mDrmManagerService; +Mutex DrmManagerClientImpl::sMutex; +sp DrmManagerClientImpl::sDrmManagerService; +sp DrmManagerClientImpl::sDeathNotifier; const String8 DrmManagerClientImpl::EMPTY_STRING(""); DrmManagerClientImpl* DrmManagerClientImpl::create(int* pUniqueId) { @@ -47,8 +48,8 @@ void DrmManagerClientImpl::remove(int uniqueId) { } const sp& DrmManagerClientImpl::getDrmManagerService() { - mMutex.lock(); - if (NULL == mDrmManagerService.get()) { + Mutex::Autolock lock(sMutex); + if (NULL == sDrmManagerService.get()) { sp sm = defaultServiceManager(); sp binder; do { @@ -62,11 +63,13 @@ const sp& DrmManagerClientImpl::getDrmManagerService() { reqt.tv_nsec = 500000000; //0.5 sec nanosleep(&reqt, NULL); } while (true); - - mDrmManagerService = interface_cast(binder); + if (NULL == sDeathNotifier.get()) { + sDeathNotifier = new DeathNotifier(); + } + binder->linkToDeath(sDeathNotifier); + sDrmManagerService = interface_cast(binder); } - mMutex.unlock(); - return mDrmManagerService; + return sDrmManagerService; } void DrmManagerClientImpl::addClient(int uniqueId) { @@ -309,3 +312,16 @@ status_t DrmManagerClientImpl::notify(const DrmInfoEvent& event) { return DRM_NO_ERROR; } +DrmManagerClientImpl::DeathNotifier::~DeathNotifier() { + Mutex::Autolock lock(sMutex); + if (NULL != sDrmManagerService.get()) { + sDrmManagerService->asBinder()->unlinkToDeath(this); + } +} + +void DrmManagerClientImpl::DeathNotifier::binderDied(const wp& who) { + Mutex::Autolock lock(sMutex); + DrmManagerClientImpl::sDrmManagerService.clear(); + LOGW("DrmManager server died!"); +} + diff --git a/drm/libdrmframework/include/DrmManagerClientImpl.h b/drm/libdrmframework/include/DrmManagerClientImpl.h index 0a7fcd1..429e4c3 100644 --- a/drm/libdrmframework/include/DrmManagerClientImpl.h +++ b/drm/libdrmframework/include/DrmManagerClientImpl.h @@ -407,9 +407,17 @@ private: Mutex mLock; sp mOnInfoListener; + class DeathNotifier: public IBinder::DeathRecipient { + public: + DeathNotifier() {} + virtual ~DeathNotifier(); + virtual void binderDied(const wp& who); + }; + private: - static Mutex mMutex; - static sp mDrmManagerService; + static Mutex sMutex; + static sp sDeathNotifier; + static sp sDrmManagerService; static const sp& getDrmManagerService(); static const String8 EMPTY_STRING; }; -- cgit v1.1 From 25cd5788a70f45c807ad22aa0ecdc7e1d4d5fd67 Mon Sep 17 00:00:00 2001 From: Gloria Wang Date: Thu, 24 Mar 2011 13:14:02 -0700 Subject: Fix for bug 4126624. Change the mDrmManagerClientImpl to sp to avoid double delete the pointer. Change-Id: I7aacea1bc58ab6425ef6f6f09472c6f2970ebb4d --- drm/libdrmframework/DrmManagerClient.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'drm') diff --git a/drm/libdrmframework/DrmManagerClient.cpp b/drm/libdrmframework/DrmManagerClient.cpp index 1d1e258..c1f382a 100644 --- a/drm/libdrmframework/DrmManagerClient.cpp +++ b/drm/libdrmframework/DrmManagerClient.cpp @@ -32,7 +32,6 @@ DrmManagerClient::~DrmManagerClient() { DrmManagerClientImpl::remove(mUniqueId); mDrmManagerClientImpl->removeClient(mUniqueId); mDrmManagerClientImpl->setOnInfoListener(mUniqueId, NULL); - delete mDrmManagerClientImpl; mDrmManagerClientImpl = NULL; } status_t DrmManagerClient::setOnInfoListener( -- 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') 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 50872c0b6563b75bb02e0de2fd578b40db8227db Mon Sep 17 00:00:00 2001 From: Gloria Wang Date: Mon, 13 Jun 2011 16:29:38 -0700 Subject: Duplicated fileDesc is not closed when input file is not forward-lock content. Fix for bug 4606053. Change-Id: I1b45457d8cdc75d268631911f46ce6ec931b1770 --- .../plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'drm') diff --git a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp index d430f72..3cbd8f1 100644 --- a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp +++ b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp @@ -455,11 +455,14 @@ status_t FwdLockEngine::onOpenDecryptSession(int uniqueId, } else { LOGD("FwdLockEngine::onOpenDecryptSession Integrity Check failed for the fd"); FwdLockFile_detach(fileDesc); - ::close(fileDesc); delete decodeSession; } } + if (DRM_NO_ERROR != result && -1 < fileDesc) { + ::close(fileDesc); + } + LOGD("FwdLockEngine::onOpenDecryptSession Exit. result = %d", result); return result; -- cgit v1.1 From b432603d711cd504d0de62f7fbb095b90c9a4283 Mon Sep 17 00:00:00 2001 From: Gloria Wang Date: Tue, 14 Jun 2011 14:44:15 -0700 Subject: To remove log spam in the Forward Lock DRM plugin. Fix for bug 4619159. Change-Id: Id4984aade4cceb59a1fdf904949f62535decd2a4 --- .../FwdLockEngine/src/FwdLockEngine.cpp | 60 +++++++++++----------- 1 file changed, 30 insertions(+), 30 deletions(-) (limited to 'drm') diff --git a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp index 3cbd8f1..07b3b47 100644 --- a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp +++ b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp @@ -53,11 +53,11 @@ extern "C" void destroy(IDrmEngine* plugIn) { } FwdLockEngine::FwdLockEngine() { - LOGD("FwdLockEngine Construction"); + LOGV("FwdLockEngine Construction"); } FwdLockEngine::~FwdLockEngine() { - LOGD("FwdLockEngine Destruction"); + LOGV("FwdLockEngine Destruction"); convertSessionMap.destroyMap(); decodeSessionMap.destroyMap(); @@ -91,7 +91,7 @@ int FwdLockEngine::getConvertedStatus(FwdLockConv_Status_t status) { DrmConstraints* FwdLockEngine::onGetConstraints(int uniqueId, const String8* path, int action) { DrmConstraints* drmConstraints = NULL; - LOGD("FwdLockEngine::onGetConstraints"); + LOGV("FwdLockEngine::onGetConstraints"); if (NULL != path && (RightsStatus::RIGHTS_VALID == onCheckRightsStatus(uniqueId, *path, action))) { @@ -105,7 +105,7 @@ DrmConstraints* FwdLockEngine::onGetConstraints(int uniqueId, const String8* pat DrmMetadata* FwdLockEngine::onGetMetadata(int uniqueId, const String8* path) { DrmMetadata* drmMetadata = NULL; - LOGD("FwdLockEngine::onGetMetadata"); + LOGV("FwdLockEngine::onGetMetadata"); if (NULL != path) { // Returns empty metadata to show no error condition. @@ -116,11 +116,11 @@ DrmMetadata* FwdLockEngine::onGetMetadata(int uniqueId, const String8* path) { } android::status_t FwdLockEngine::onInitialize(int uniqueId) { - LOGD("FwdLockEngine::onInitialize"); + LOGV("FwdLockEngine::onInitialize"); if (FwdLockGlue_InitializeKeyEncryption()) { - LOGD("FwdLockEngine::onInitialize -- FwdLockGlue_InitializeKeyEncryption succeeded"); + LOGV("FwdLockEngine::onInitialize -- FwdLockGlue_InitializeKeyEncryption succeeded"); } else { LOGD("FwdLockEngine::onInitialize -- FwdLockGlue_InitializeKeyEncryption failed:" "errno = %d", errno); @@ -132,13 +132,13 @@ android::status_t FwdLockEngine::onInitialize(int uniqueId) { android::status_t FwdLockEngine::onSetOnInfoListener(int uniqueId, const IDrmEngine::OnInfoListener* infoListener) { // Not used - LOGD("FwdLockEngine::onSetOnInfoListener"); + LOGV("FwdLockEngine::onSetOnInfoListener"); return DRM_NO_ERROR; } android::status_t FwdLockEngine::onTerminate(int uniqueId) { - LOGD("FwdLockEngine::onTerminate"); + LOGV("FwdLockEngine::onTerminate"); return DRM_NO_ERROR; } @@ -146,7 +146,7 @@ android::status_t FwdLockEngine::onTerminate(int uniqueId) { DrmSupportInfo* FwdLockEngine::onGetSupportInfo(int uniqueId) { DrmSupportInfo* pSupportInfo = new DrmSupportInfo(); - LOGD("FwdLockEngine::onGetSupportInfo"); + LOGV("FwdLockEngine::onGetSupportInfo"); // fill all Forward Lock mimetypes and extensions if (NULL != pSupportInfo) { @@ -182,7 +182,7 @@ DrmInfoStatus* FwdLockEngine::onProcessDrmInfo(int uniqueId, const DrmInfo* drmI drmInfoStatus = new DrmInfoStatus((int)DrmInfoStatus::STATUS_OK, 0, NULL, String8("")); - LOGD("FwdLockEngine::onProcessDrmInfo"); + LOGV("FwdLockEngine::onProcessDrmInfo"); return drmInfoStatus; } @@ -193,7 +193,7 @@ status_t FwdLockEngine::onSaveRights( const String8& rightsPath, const String8& contentPath) { // No rights to save. Return - LOGD("FwdLockEngine::onSaveRights"); + LOGV("FwdLockEngine::onSaveRights"); return DRM_ERROR_UNKNOWN; } @@ -201,7 +201,7 @@ DrmInfo* FwdLockEngine::onAcquireDrmInfo(int uniqueId, const DrmInfoRequest* drm DrmInfo* drmInfo = NULL; // Nothing to be done for Forward Lock file - LOGD("FwdLockEngine::onAcquireDrmInfo"); + LOGV("FwdLockEngine::onAcquireDrmInfo"); return drmInfo; } @@ -211,7 +211,7 @@ int FwdLockEngine::onCheckRightsStatus(int uniqueId, int action) { int result = RightsStatus::RIGHTS_INVALID; - LOGD("FwdLockEngine::onCheckRightsStatus"); + LOGV("FwdLockEngine::onCheckRightsStatus"); // Only Transfer action is not allowed for forward Lock files. if (onCanHandle(uniqueId, path)) { @@ -241,7 +241,7 @@ status_t FwdLockEngine::onConsumeRights(int uniqueId, int action, bool reserve) { // No rights consumption - LOGD("FwdLockEngine::onConsumeRights"); + LOGV("FwdLockEngine::onConsumeRights"); return DRM_NO_ERROR; } @@ -249,14 +249,14 @@ bool FwdLockEngine::onValidateAction(int uniqueId, const String8& path, int action, const ActionDescription& description) { - LOGD("FwdLockEngine::onValidateAction"); + LOGV("FwdLockEngine::onValidateAction"); // For the forwardlock engine checkRights and ValidateAction are the same. return (onCheckRightsStatus(uniqueId, path, action) == RightsStatus::RIGHTS_VALID); } String8 FwdLockEngine::onGetOriginalMimeType(int uniqueId, const String8& path) { - LOGD("FwdLockEngine::onGetOriginalMimeType"); + LOGV("FwdLockEngine::onGetOriginalMimeType"); String8 mimeString = String8(""); int fileDesc = FwdLockFile_open(path.string()); @@ -280,7 +280,7 @@ int FwdLockEngine::onGetDrmObjectType(int uniqueId, const String8& mimeType) { String8 mimeStr = String8(mimeType); - LOGD("FwdLockEngine::onGetDrmObjectType"); + LOGV("FwdLockEngine::onGetDrmObjectType"); mimeStr.toLower(); @@ -301,13 +301,13 @@ int FwdLockEngine::onGetDrmObjectType(int uniqueId, status_t FwdLockEngine::onRemoveRights(int uniqueId, const String8& path) { // No Rights to remove - LOGD("FwdLockEngine::onRemoveRights"); + LOGV("FwdLockEngine::onRemoveRights"); return DRM_NO_ERROR; } status_t FwdLockEngine::onRemoveAllRights(int uniqueId) { // No rights to remove - LOGD("FwdLockEngine::onRemoveAllRights"); + LOGV("FwdLockEngine::onRemoveAllRights"); return DRM_NO_ERROR; } @@ -319,14 +319,14 @@ status_t FwdLockEngine::onSetPlaybackStatus(int uniqueId, DecryptHandle* decrypt int playbackStatus, int position) { #endif // Not used - LOGD("FwdLockEngine::onSetPlaybackStatus"); + LOGV("FwdLockEngine::onSetPlaybackStatus"); return DRM_NO_ERROR; } status_t FwdLockEngine::onOpenConvertSession(int uniqueId, int convertId) { status_t result = DRM_ERROR_UNKNOWN; - LOGD("FwdLockEngine::onOpenConvertSession"); + LOGV("FwdLockEngine::onOpenConvertSession"); if (!convertSessionMap.isCreated(convertId)) { ConvertSession *newSession = new ConvertSession(); if (FwdLockConv_Status_OK == @@ -383,7 +383,7 @@ DrmConvertedStatus* FwdLockEngine::onCloseConvertSession(int uniqueId, DrmBuffer *convResult = new DrmBuffer(NULL, 0); int offset = -1; - LOGD("FwdLockEngine::onCloseConvertSession"); + LOGV("FwdLockEngine::onCloseConvertSession"); if (convertSessionMap.isCreated(convertId)) { ConvertSession *convSession = convertSessionMap.getValue(convertId); @@ -424,7 +424,7 @@ status_t FwdLockEngine::onOpenDecryptSession(int uniqueId, status_t result = DRM_ERROR_CANNOT_HANDLE; int fileDesc = -1; - LOGD("FwdLockEngine::onOpenDecryptSession"); + LOGV("FwdLockEngine::onOpenDecryptSession"); if ((-1 < fd) && (NULL != decryptHandle) && @@ -463,7 +463,7 @@ status_t FwdLockEngine::onOpenDecryptSession(int uniqueId, ::close(fileDesc); } - LOGD("FwdLockEngine::onOpenDecryptSession Exit. result = %d", result); + LOGV("FwdLockEngine::onOpenDecryptSession Exit. result = %d", result); return result; } @@ -500,7 +500,7 @@ status_t FwdLockEngine::onOpenDecryptSession(int uniqueId, status_t FwdLockEngine::onCloseDecryptSession(int uniqueId, DecryptHandle* decryptHandle) { status_t result = DRM_ERROR_UNKNOWN; - LOGD("FwdLockEngine::onCloseDecryptSession"); + LOGV("FwdLockEngine::onCloseDecryptSession"); if (NULL != decryptHandle && decodeSessionMap.isCreated(decryptHandle->decryptId)) { DecodeSession* session = decodeSessionMap.getValue(decryptHandle->decryptId); @@ -512,7 +512,7 @@ status_t FwdLockEngine::onCloseDecryptSession(int uniqueId, } } - LOGD("FwdLockEngine::onCloseDecryptSession Exit"); + LOGV("FwdLockEngine::onCloseDecryptSession Exit"); return result; } @@ -520,13 +520,13 @@ status_t FwdLockEngine::onInitializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo) { - LOGD("FwdLockEngine::onInitializeDecryptUnit"); + LOGV("FwdLockEngine::onInitializeDecryptUnit"); return DRM_ERROR_UNKNOWN; } status_t FwdLockEngine::onDecrypt(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) { - LOGD("FwdLockEngine::onDecrypt"); + LOGV("FwdLockEngine::onDecrypt"); return DRM_ERROR_UNKNOWN; } @@ -535,14 +535,14 @@ status_t FwdLockEngine::onDecrypt(int uniqueId, int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer) { - LOGD("FwdLockEngine::onDecrypt"); + LOGV("FwdLockEngine::onDecrypt"); return DRM_ERROR_UNKNOWN; } status_t FwdLockEngine::onFinalizeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) { - LOGD("FwdLockEngine::onFinalizeDecryptUnit"); + LOGV("FwdLockEngine::onFinalizeDecryptUnit"); return DRM_ERROR_UNKNOWN; } -- cgit v1.1 From c10ce33302f91896fc2a87c13b00518a4bc26e3a Mon Sep 17 00:00:00 2001 From: Gloria Wang Date: Wed, 15 Jun 2011 10:27:52 -0700 Subject: -Fix some typo -Remove one unnecessary memory allocation Change-Id: Icea21f33d2c7891333e06429d2f382389e5bd27f --- drm/common/IDrmManagerService.cpp | 28 ++++++++++++++-------------- drm/libdrmframework/include/PlugInManager.h | 4 +--- 2 files changed, 15 insertions(+), 17 deletions(-) (limited to 'drm') diff --git a/drm/common/IDrmManagerService.cpp b/drm/common/IDrmManagerService.cpp index c37b4f8..458f1b6 100644 --- a/drm/common/IDrmManagerService.cpp +++ b/drm/common/IDrmManagerService.cpp @@ -37,7 +37,7 @@ using namespace android; -static void writeDecrptHandleToParcelData( +static void writeDecryptHandleToParcelData( const DecryptHandle* handle, Parcel* data) { data->writeInt32(handle->decryptId); data->writeString8(handle->mimeType); @@ -46,14 +46,14 @@ static void writeDecrptHandleToParcelData( int size = handle->copyControlVector.size(); data->writeInt32(size); - for(int i = 0; i < size; i++) { + for (int i = 0; i < size; i++) { data->writeInt32(handle->copyControlVector.keyAt(i)); data->writeInt32(handle->copyControlVector.valueAt(i)); } size = handle->extendedData.size(); data->writeInt32(size); - for(int i = 0; i < size; i++) { + for (int i = 0; i < size; i++) { data->writeString8(handle->extendedData.keyAt(i)); data->writeString8(handle->extendedData.valueAt(i)); } @@ -77,14 +77,14 @@ static void readDecryptHandleFromParcelData( handle->status = data.readInt32(); int size = data.readInt32(); - for (int i = 0; i < size; i ++) { + for (int i = 0; i < size; i++) { DrmCopyControl key = (DrmCopyControl)data.readInt32(); int value = data.readInt32(); handle->copyControlVector.add(key, value); } size = data.readInt32(); - for (int i = 0; i < size; i ++) { + for (int i = 0; i < size; i++) { String8 key = data.readString8(); String8 value = data.readString8(); handle->extendedData.add(key, value); @@ -416,7 +416,7 @@ status_t BpDrmManagerService::consumeRights( data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); data.writeInt32(uniqueId); - writeDecrptHandleToParcelData(decryptHandle, &data); + writeDecryptHandleToParcelData(decryptHandle, &data); data.writeInt32(action); data.writeInt32(static_cast< int>(reserve)); @@ -433,7 +433,7 @@ status_t BpDrmManagerService::setPlaybackStatus( data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); data.writeInt32(uniqueId); - writeDecrptHandleToParcelData(decryptHandle, &data); + writeDecryptHandleToParcelData(decryptHandle, &data); data.writeInt32(playbackStatus); data.writeInt64(position); @@ -646,7 +646,7 @@ status_t BpDrmManagerService::closeDecryptSession(int uniqueId, DecryptHandle* d data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); data.writeInt32(uniqueId); - writeDecrptHandleToParcelData(decryptHandle, &data); + writeDecryptHandleToParcelData(decryptHandle, &data); remote()->transact(CLOSE_DECRYPT_SESSION, data, &reply); @@ -662,7 +662,7 @@ status_t BpDrmManagerService::initializeDecryptUnit( data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); data.writeInt32(uniqueId); - writeDecrptHandleToParcelData(decryptHandle, &data); + writeDecryptHandleToParcelData(decryptHandle, &data); data.writeInt32(decryptUnitId); @@ -682,7 +682,7 @@ status_t BpDrmManagerService::decrypt( data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); data.writeInt32(uniqueId); - writeDecrptHandleToParcelData(decryptHandle, &data); + writeDecryptHandleToParcelData(decryptHandle, &data); data.writeInt32(decryptUnitId); data.writeInt32((*decBuffer)->length); @@ -715,7 +715,7 @@ status_t BpDrmManagerService::finalizeDecryptUnit( data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); data.writeInt32(uniqueId); - writeDecrptHandleToParcelData(decryptHandle, &data); + writeDecryptHandleToParcelData(decryptHandle, &data); data.writeInt32(decryptUnitId); @@ -733,7 +733,7 @@ ssize_t BpDrmManagerService::pread( data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); data.writeInt32(uniqueId); - writeDecrptHandleToParcelData(decryptHandle, &data); + writeDecryptHandleToParcelData(decryptHandle, &data); data.writeInt32(numBytes); data.writeInt64(offset); @@ -1244,7 +1244,7 @@ status_t BnDrmManagerService::onTransact( = openDecryptSession(uniqueId, fd, data.readInt64(), data.readInt64()); if (NULL != handle) { - writeDecrptHandleToParcelData(handle, reply); + writeDecryptHandleToParcelData(handle, reply); clearDecryptHandle(handle); delete handle; handle = NULL; } @@ -1262,7 +1262,7 @@ status_t BnDrmManagerService::onTransact( DecryptHandle* handle = openDecryptSession(uniqueId, uri.string()); if (NULL != handle) { - writeDecrptHandleToParcelData(handle, reply); + writeDecryptHandleToParcelData(handle, reply); clearDecryptHandle(handle); delete handle; handle = NULL; diff --git a/drm/libdrmframework/include/PlugInManager.h b/drm/libdrmframework/include/PlugInManager.h index 8029138..7bb143f 100644 --- a/drm/libdrmframework/include/PlugInManager.h +++ b/drm/libdrmframework/include/PlugInManager.h @@ -202,7 +202,7 @@ private: Vector getPlugInPathList(const String8& rsDirPath) { Vector fileList; DIR* pDir = opendir(rsDirPath.string()); - struct dirent* pEntry = new dirent(); + struct dirent* pEntry; while (NULL != pDir && NULL != (pEntry = readdir(pDir))) { if (!isPlugIn(pEntry)) { @@ -219,8 +219,6 @@ private: if (NULL != pDir) { closedir(pDir); } - delete pEntry; - pEntry = NULL; return fileList; } -- cgit v1.1 From 409e5a07f044239aac2059c9ba3b3f6f48eeaba1 Mon Sep 17 00:00:00 2001 From: Gloria Wang Date: Tue, 21 Jun 2011 11:07:59 -0700 Subject: Fix a memory leak in the Forward Lock plugin. For bug 4770217. Change-Id: I14f4d4ead524c661e68a20738e7a50e4d8fd92ea --- .../forward-lock/FwdLockEngine/src/FwdLockEngine.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'drm') diff --git a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp index 07b3b47..31c3c14 100644 --- a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp +++ b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp @@ -512,6 +512,19 @@ status_t FwdLockEngine::onCloseDecryptSession(int uniqueId, } } + if (NULL != decryptHandle) { + if (NULL != decryptHandle->decryptInfo) { + delete decryptHandle->decryptInfo; + decryptHandle->decryptInfo = NULL; + } + + decryptHandle->copyControlVector.clear(); + decryptHandle->extendedData.clear(); + + delete decryptHandle; + decryptHandle = NULL; + } + LOGV("FwdLockEngine::onCloseDecryptSession Exit"); return result; } -- cgit v1.1 From ab00df4d8585b181e9058eb1b9c7996aa3bbaeab Mon Sep 17 00:00:00 2001 From: Gloria Wang Date: Wed, 22 Jun 2011 14:55:16 -0700 Subject: - Add two sanity checks. - Remove one unnecessary line. - Clear the extendedData vector in DecryptHandle. Change-Id: I2610c6d68f12d48cb69323a5eb2ae4b3b3e44dff --- drm/common/DrmSupportInfo.cpp | 4 ++++ drm/common/IDrmManagerService.cpp | 1 + drm/libdrmframework/DrmManagerClientImpl.cpp | 1 - 3 files changed, 5 insertions(+), 1 deletion(-) (limited to 'drm') diff --git a/drm/common/DrmSupportInfo.cpp b/drm/common/DrmSupportInfo.cpp index 3dee435..5400bdd 100644 --- a/drm/common/DrmSupportInfo.cpp +++ b/drm/common/DrmSupportInfo.cpp @@ -43,6 +43,10 @@ bool DrmSupportInfo::operator==(const DrmSupportInfo& drmSupportInfo) const { } bool DrmSupportInfo::isSupportedMimeType(const String8& mimeType) const { + if (String8("") == mimeType) { + return false; + } + for (unsigned int i = 0; i < mMimeTypeVector.size(); i++) { const String8 item = mMimeTypeVector.itemAt(i); diff --git a/drm/common/IDrmManagerService.cpp b/drm/common/IDrmManagerService.cpp index 458f1b6..2d8e877 100644 --- a/drm/common/IDrmManagerService.cpp +++ b/drm/common/IDrmManagerService.cpp @@ -107,6 +107,7 @@ static void clearDecryptHandle(DecryptHandle* handle) { handle->decryptInfo = NULL; } handle->copyControlVector.clear(); + handle->extendedData.clear(); } int BpDrmManagerService::addUniqueId(int uniqueId) { diff --git a/drm/libdrmframework/DrmManagerClientImpl.cpp b/drm/libdrmframework/DrmManagerClientImpl.cpp index a57dd98..a36bd4a 100644 --- a/drm/libdrmframework/DrmManagerClientImpl.cpp +++ b/drm/libdrmframework/DrmManagerClientImpl.cpp @@ -145,7 +145,6 @@ DrmInfo* DrmManagerClientImpl::acquireDrmInfo( status_t DrmManagerClientImpl::saveRights(int uniqueId, const DrmRights& drmRights, const String8& rightsPath, const String8& contentPath) { - status_t status = DRM_ERROR_UNKNOWN; return getDrmManagerService()->saveRights( uniqueId, drmRights, rightsPath, contentPath); } -- 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 ++------- drm/libdrmframework/Android.mk | 9 ++------- drm/libdrmframework/plugins/passthru/Android.mk | 10 ++-------- 3 files changed, 6 insertions(+), 22 deletions(-) (limited to 'drm') 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 diff --git a/drm/libdrmframework/Android.mk b/drm/libdrmframework/Android.mk index f1526a4..c534402 100644 --- a/drm/libdrmframework/Android.mk +++ b/drm/libdrmframework/Android.mk @@ -25,13 +25,8 @@ LOCAL_MODULE:= libdrmframework LOCAL_SHARED_LIBRARIES := \ libutils \ - libbinder - -ifeq ($(TARGET_SIMULATOR),true) - LOCAL_LDLIBS += -ldl -else - LOCAL_SHARED_LIBRARIES += libdl -endif + libbinder \ + libdl LOCAL_STATIC_LIBRARIES := \ libdrmframeworkcommon diff --git a/drm/libdrmframework/plugins/passthru/Android.mk b/drm/libdrmframework/plugins/passthru/Android.mk index be18b64..d0d1439 100644 --- a/drm/libdrmframework/plugins/passthru/Android.mk +++ b/drm/libdrmframework/plugins/passthru/Android.mk @@ -24,14 +24,8 @@ LOCAL_MODULE := libdrmpassthruplugin LOCAL_STATIC_LIBRARIES := libdrmframeworkcommon LOCAL_SHARED_LIBRARIES := \ - libutils - -ifeq ($(TARGET_SIMULATOR),true) - LOCAL_LDLIBS += -ldl -else - LOCAL_SHARED_LIBRARIES += libdl -endif - + libutils \ + libdl LOCAL_C_INCLUDES += \ -- 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/common/IDrmManagerService.cpp | 4 +- drm/drmserver/DrmManager.cpp | 54 +++++++++++++--------- drm/drmserver/DrmManagerService.cpp | 4 +- drm/libdrmframework/DrmManagerClient.cpp | 2 +- drm/libdrmframework/DrmManagerClientImpl.cpp | 11 ++--- drm/libdrmframework/include/DrmManager.h | 2 +- drm/libdrmframework/include/DrmManagerClientImpl.h | 2 +- drm/libdrmframework/include/DrmManagerService.h | 2 +- drm/libdrmframework/include/IDrmManagerService.h | 4 +- .../plugins/common/include/DrmEngineBase.h | 8 +++- 10 files changed, 53 insertions(+), 40 deletions(-) (limited to 'drm') diff --git a/drm/common/IDrmManagerService.cpp b/drm/common/IDrmManagerService.cpp index 2d8e877..986f32c 100644 --- a/drm/common/IDrmManagerService.cpp +++ b/drm/common/IDrmManagerService.cpp @@ -110,11 +110,11 @@ static void clearDecryptHandle(DecryptHandle* handle) { handle->extendedData.clear(); } -int BpDrmManagerService::addUniqueId(int uniqueId) { +int BpDrmManagerService::addUniqueId(bool isNative) { LOGV("add uniqueid"); Parcel data, reply; data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); - data.writeInt32(uniqueId); + data.writeInt32(isNative); remote()->transact(ADD_UNIQUEID, data, &reply); return reply.readInt32(); } diff --git a/drm/drmserver/DrmManager.cpp b/drm/drmserver/DrmManager.cpp index 1809619..3e4fe8c 100644 --- a/drm/drmserver/DrmManager.cpp +++ b/drm/drmserver/DrmManager.cpp @@ -49,32 +49,42 @@ DrmManager::~DrmManager() { } -int DrmManager::addUniqueId(int uniqueId) { +int DrmManager::addUniqueId(bool isNative) { Mutex::Autolock _l(mLock); - if (0 == uniqueId) { - int temp = 0; - bool foundUniqueId = false; - srand(time(NULL)); - - while (!foundUniqueId) { - const int size = mUniqueIdVector.size(); - temp = rand() % 100; - - int index = 0; - for (; index < size; ++index) { - if (mUniqueIdVector.itemAt(index) == temp) { - foundUniqueId = false; - break; - } - } - if (index == size) { - foundUniqueId = true; + + int temp = 0; + bool foundUniqueId = false; + const int size = mUniqueIdVector.size(); + const int uniqueIdRange = 0xfff; + int maxLoopTimes = (uniqueIdRange - 1) / 2; + srand(time(NULL)); + + while (!foundUniqueId) { + temp = rand() & uniqueIdRange; + + if (isNative) { + // set a flag to differentiate DrmManagerClient + // created from native side and java side + temp |= 0x1000; + } + + int index = 0; + for (; index < size; ++index) { + if (mUniqueIdVector.itemAt(index) == temp) { + foundUniqueId = false; + break; } } - uniqueId = temp; + if (index == size) { + foundUniqueId = true; + } + + maxLoopTimes --; + LOG_FATAL_IF(maxLoopTimes <= 0, "cannot find an unique ID for this session"); } - mUniqueIdVector.push(uniqueId); - return uniqueId; + + mUniqueIdVector.push(temp); + return temp; } void DrmManager::removeUniqueId(int uniqueId) { diff --git a/drm/drmserver/DrmManagerService.cpp b/drm/drmserver/DrmManagerService.cpp index 583669e..7ebcac3 100644 --- a/drm/drmserver/DrmManagerService.cpp +++ b/drm/drmserver/DrmManagerService.cpp @@ -78,8 +78,8 @@ DrmManagerService::~DrmManagerService() { delete mDrmManager; mDrmManager = NULL; } -int DrmManagerService::addUniqueId(int uniqueId) { - return mDrmManager->addUniqueId(uniqueId); +int DrmManagerService::addUniqueId(bool isNative) { + return mDrmManager->addUniqueId(isNative); } void DrmManagerService::removeUniqueId(int uniqueId) { diff --git a/drm/libdrmframework/DrmManagerClient.cpp b/drm/libdrmframework/DrmManagerClient.cpp index b50199f..c9c0d57 100644 --- a/drm/libdrmframework/DrmManagerClient.cpp +++ b/drm/libdrmframework/DrmManagerClient.cpp @@ -24,7 +24,7 @@ using namespace android; DrmManagerClient::DrmManagerClient(): mUniqueId(0), mDrmManagerClientImpl(NULL) { - mDrmManagerClientImpl = DrmManagerClientImpl::create(&mUniqueId); + mDrmManagerClientImpl = DrmManagerClientImpl::create(&mUniqueId, true); mDrmManagerClientImpl->addClient(mUniqueId); } diff --git a/drm/libdrmframework/DrmManagerClientImpl.cpp b/drm/libdrmframework/DrmManagerClientImpl.cpp index a36bd4a..67f58ca 100644 --- a/drm/libdrmframework/DrmManagerClientImpl.cpp +++ b/drm/libdrmframework/DrmManagerClientImpl.cpp @@ -33,13 +33,10 @@ sp DrmManagerClientImpl::sDrmManagerService; sp DrmManagerClientImpl::sDeathNotifier; const String8 DrmManagerClientImpl::EMPTY_STRING(""); -DrmManagerClientImpl* DrmManagerClientImpl::create(int* pUniqueId) { - if (0 == *pUniqueId) { - int uniqueId = getDrmManagerService()->addUniqueId(*pUniqueId); - *pUniqueId = uniqueId; - } else { - getDrmManagerService()->addUniqueId(*pUniqueId); - } +DrmManagerClientImpl* DrmManagerClientImpl::create( + int* pUniqueId, bool isNative) { + *pUniqueId = getDrmManagerService()->addUniqueId(isNative); + return new DrmManagerClientImpl(); } diff --git a/drm/libdrmframework/include/DrmManager.h b/drm/libdrmframework/include/DrmManager.h index af2c2a8..ac2b946 100644 --- a/drm/libdrmframework/include/DrmManager.h +++ b/drm/libdrmframework/include/DrmManager.h @@ -53,7 +53,7 @@ public: virtual ~DrmManager(); public: - int addUniqueId(int uniqueId); + int addUniqueId(bool isNative); void removeUniqueId(int uniqueId); diff --git a/drm/libdrmframework/include/DrmManagerClientImpl.h b/drm/libdrmframework/include/DrmManagerClientImpl.h index 564896b..e3338d9 100644 --- a/drm/libdrmframework/include/DrmManagerClientImpl.h +++ b/drm/libdrmframework/include/DrmManagerClientImpl.h @@ -38,7 +38,7 @@ private: DrmManagerClientImpl() { } public: - static DrmManagerClientImpl* create(int* pUniqueId); + static DrmManagerClientImpl* create(int* pUniqueId, bool isNative); static void remove(int uniqueId); diff --git a/drm/libdrmframework/include/DrmManagerService.h b/drm/libdrmframework/include/DrmManagerService.h index 227496a..9cb5804 100644 --- a/drm/libdrmframework/include/DrmManagerService.h +++ b/drm/libdrmframework/include/DrmManagerService.h @@ -46,7 +46,7 @@ private: virtual ~DrmManagerService(); public: - int addUniqueId(int uniqueId); + int addUniqueId(bool isNative); void removeUniqueId(int uniqueId); diff --git a/drm/libdrmframework/include/IDrmManagerService.h b/drm/libdrmframework/include/IDrmManagerService.h index 7727e55..b9618bb 100644 --- a/drm/libdrmframework/include/IDrmManagerService.h +++ b/drm/libdrmframework/include/IDrmManagerService.h @@ -81,7 +81,7 @@ public: DECLARE_META_INTERFACE(DrmManagerService); public: - virtual int addUniqueId(int uniqueId) = 0; + virtual int addUniqueId(bool isNative) = 0; virtual void removeUniqueId(int uniqueId) = 0; @@ -167,7 +167,7 @@ public: BpDrmManagerService(const sp& impl) : BpInterface(impl) {} - virtual int addUniqueId(int uniqueId); + virtual int addUniqueId(bool isNative); virtual void removeUniqueId(int uniqueId); diff --git a/drm/libdrmframework/plugins/common/include/DrmEngineBase.h b/drm/libdrmframework/plugins/common/include/DrmEngineBase.h index b61e3d3..4a5afcf 100644 --- a/drm/libdrmframework/plugins/common/include/DrmEngineBase.h +++ b/drm/libdrmframework/plugins/common/include/DrmEngineBase.h @@ -143,7 +143,13 @@ protected: * Register a callback to be invoked when the caller required to * receive necessary information * - * @param[in] uniqueId Unique identifier for a session + * @param[in] uniqueId Unique identifier for a session. uniqueId is a random + * number generated in the DRM service. If the DrmManagerClient + * is created in native code, uniqueId will be a number ranged + * from 0x1000 to 0x1fff. If it comes from Java code, the uniqueId + * will be a number ranged from 0x00 to 0xfff. So bit 0x1000 in + * uniqueId could be used in DRM plugins to differentiate native + * OnInfoListener and Java OnInfoListener. * @param[in] infoListener Listener * @return status_t * Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure -- cgit v1.1 From 197f047db2909c3d8cc84b95f69d18410a935fb8 Mon Sep 17 00:00:00 2001 From: Gloria Wang Date: Mon, 1 Aug 2011 10:31:24 -0700 Subject: Fix ordering assumption of argument evaluation. No specific order is specified in the C++ standard, but the order of the calls to Parcel read commands matters. Move any calls with multiple reads to local variables. Fix for bug 5103507. Change-Id: Ic23ad50ec5f443146f00324b66d5e2bd5b9ffd0d --- drm/common/IDrmManagerService.cpp | 66 ++++++++++++++++++++++++++------------- 1 file changed, 45 insertions(+), 21 deletions(-) (limited to 'drm') diff --git a/drm/common/IDrmManagerService.cpp b/drm/common/IDrmManagerService.cpp index 986f32c..0b76a36 100644 --- a/drm/common/IDrmManagerService.cpp +++ b/drm/common/IDrmManagerService.cpp @@ -808,7 +808,9 @@ status_t BnDrmManagerService::onTransact( LOGV("BnDrmManagerService::onTransact :INSTALL_DRM_ENGINE"); CHECK_INTERFACE(IDrmManagerService, data, reply); - status_t status = installDrmEngine(data.readInt32(), data.readString8()); + const int uniqueId = data.readInt32(); + const String8 engineFile = data.readString8(); + status_t status = installDrmEngine(uniqueId, engineFile); reply->writeInt32(status); return DRM_NO_ERROR; @@ -822,7 +824,8 @@ status_t BnDrmManagerService::onTransact( const int uniqueId = data.readInt32(); const String8 path = data.readString8(); - DrmConstraints* drmConstraints = getConstraints(uniqueId, &path, data.readInt32()); + DrmConstraints* drmConstraints + = getConstraints(uniqueId, &path, data.readInt32()); if (NULL != drmConstraints) { //Filling DRM Constraints contents @@ -948,7 +951,9 @@ status_t BnDrmManagerService::onTransact( const int uniqueId = data.readInt32(); //Filling DRM info Request - DrmInfoRequest* drmInfoRequest = new DrmInfoRequest(data.readInt32(), data.readString8()); + const int infoType = data.readInt32(); + const String8 mimeType = data.readString8(); + DrmInfoRequest* drmInfoRequest = new DrmInfoRequest(infoType, mimeType); const int size = data.readInt32(); for (int index = 0; index < size; ++index) { @@ -1021,7 +1026,9 @@ status_t BnDrmManagerService::onTransact( LOGV("BnDrmManagerService::onTransact :GET_ORIGINAL_MIMETYPE"); CHECK_INTERFACE(IDrmManagerService, data, reply); - const String8 originalMimeType = getOriginalMimeType(data.readInt32(), data.readString8()); + const int uniqueId = data.readInt32(); + const String8 path = data.readString8(); + const String8 originalMimeType = getOriginalMimeType(uniqueId, path); reply->writeString8(originalMimeType); return DRM_NO_ERROR; @@ -1032,8 +1039,10 @@ status_t BnDrmManagerService::onTransact( LOGV("BnDrmManagerService::onTransact :GET_DRM_OBJECT_TYPE"); CHECK_INTERFACE(IDrmManagerService, data, reply); - const int drmObjectType - = getDrmObjectType(data.readInt32(), data.readString8(), data.readString8()); + const int uniqueId = data.readInt32(); + const String8 path = data.readString8(); + const String8 mimeType = data.readString8(); + const int drmObjectType = getDrmObjectType(uniqueId, path, mimeType); reply->writeInt32(drmObjectType); return DRM_NO_ERROR; @@ -1044,8 +1053,10 @@ status_t BnDrmManagerService::onTransact( LOGV("BnDrmManagerService::onTransact :CHECK_RIGHTS_STATUS"); CHECK_INTERFACE(IDrmManagerService, data, reply); - const int result - = checkRightsStatus(data.readInt32(), data.readString8(), data.readInt32()); + const int uniqueId = data.readInt32(); + const String8 path = data.readString8(); + const int action = data.readInt32(); + const int result = checkRightsStatus(uniqueId, path, action); reply->writeInt32(result); return DRM_NO_ERROR; @@ -1061,9 +1072,10 @@ status_t BnDrmManagerService::onTransact( DecryptHandle handle; readDecryptHandleFromParcelData(&handle, data); + const int action = data.readInt32(); + const bool reserve = static_cast(data.readInt32()); const status_t status - = consumeRights(uniqueId, &handle, data.readInt32(), - static_cast(data.readInt32())); + = consumeRights(uniqueId, &handle, action, reserve); reply->writeInt32(status); clearDecryptHandle(&handle); @@ -1080,8 +1092,10 @@ status_t BnDrmManagerService::onTransact( DecryptHandle handle; readDecryptHandleFromParcelData(&handle, data); + const int playbackStatus = data.readInt32(); + const int64_t position = data.readInt64(); const status_t status - = setPlaybackStatus(uniqueId, &handle, data.readInt32(), data.readInt64()); + = setPlaybackStatus(uniqueId, &handle, playbackStatus, position); reply->writeInt32(status); clearDecryptHandle(&handle); @@ -1093,11 +1107,13 @@ status_t BnDrmManagerService::onTransact( LOGV("BnDrmManagerService::onTransact :VALIDATE_ACTION"); CHECK_INTERFACE(IDrmManagerService, data, reply); - bool result = validateAction( - data.readInt32(), - data.readString8(), - data.readInt32(), - ActionDescription(data.readInt32(), data.readInt32())); + const int uniqueId = data.readInt32(); + const String8 path = data.readString8(); + const int action = data.readInt32(); + const int outputType = data.readInt32(); + const int configuration = data.readInt32(); + bool result = validateAction(uniqueId, path, action, + ActionDescription(outputType, configuration)); reply->writeInt32(result); return DRM_NO_ERROR; @@ -1108,7 +1124,9 @@ status_t BnDrmManagerService::onTransact( LOGV("BnDrmManagerService::onTransact :REMOVE_RIGHTS"); CHECK_INTERFACE(IDrmManagerService, data, reply); - const status_t status = removeRights(data.readInt32(), data.readString8()); + int uniqueId = data.readInt32(); + String8 path = data.readString8(); + const status_t status = removeRights(uniqueId, path); reply->writeInt32(status); return DRM_NO_ERROR; @@ -1130,7 +1148,9 @@ status_t BnDrmManagerService::onTransact( LOGV("BnDrmManagerService::onTransact :OPEN_CONVERT_SESSION"); CHECK_INTERFACE(IDrmManagerService, data, reply); - const int convertId = openConvertSession(data.readInt32(), data.readString8()); + const int uniqueId = data.readInt32(); + const String8 mimeType = data.readString8(); + const int convertId = openConvertSession(uniqueId, mimeType); reply->writeInt32(convertId); return DRM_NO_ERROR; @@ -1176,8 +1196,10 @@ status_t BnDrmManagerService::onTransact( LOGV("BnDrmManagerService::onTransact :CLOSE_CONVERT_SESSION"); CHECK_INTERFACE(IDrmManagerService, data, reply); - DrmConvertedStatus* drmConvertedStatus - = closeConvertSession(data.readInt32(), data.readInt32()); + const int uniqueId = data.readInt32(); + const int convertId = data.readInt32(); + DrmConvertedStatus* drmConvertedStatus + = closeConvertSession(uniqueId, convertId); if (NULL != drmConvertedStatus) { //Filling Drm Converted Ststus @@ -1241,8 +1263,10 @@ status_t BnDrmManagerService::onTransact( const int uniqueId = data.readInt32(); const int fd = data.readFileDescriptor(); + const off64_t offset = data.readInt64(); + const off64_t length = data.readInt64(); DecryptHandle* handle - = openDecryptSession(uniqueId, fd, data.readInt64(), data.readInt64()); + = openDecryptSession(uniqueId, fd, offset, length); if (NULL != handle) { writeDecryptHandleToParcelData(handle, reply); -- cgit v1.1 From 90855078eb989944bca1824058d7231cd68e5021 Mon Sep 17 00:00:00 2001 From: Henrik B Andersson Date: Mon, 21 Feb 2011 14:22:08 +0100 Subject: Bug fixes in OMA DRM v1 Forward Lock Agent A couple of fixes in the Forward Lock Agent. The DRM Framework isn't thread safe so the Forward Lock Agent needs to protect the private structures. Base64-encoded content with LF-only instead of CRLF line breaks is now accepted. A fix for non-standard boundary characters. The debug prints are also turned off as default. Change-Id: I8ab417231380fbe1c371d18a147773ceabc6f69f --- .../plugins/common/util/include/SessionMap.h | 238 ++++++++++++--------- .../plugins/common/util/src/MimeTypeUtil.cpp | 62 +++--- .../plugins/forward-lock/FwdLockEngine/Android.mk | 3 + .../FwdLockEngine/src/FwdLockEngine.cpp | 99 +++++---- .../internal-format/converter/FwdLockConv.c | 26 ++- .../internal-format/decoder/FwdLockFile.c | 12 +- 6 files changed, 257 insertions(+), 183 deletions(-) (limited to 'drm') diff --git a/drm/libdrmframework/plugins/common/util/include/SessionMap.h b/drm/libdrmframework/plugins/common/util/include/SessionMap.h index 3dff58c..e563894 100644 --- a/drm/libdrmframework/plugins/common/util/include/SessionMap.h +++ b/drm/libdrmframework/plugins/common/util/include/SessionMap.h @@ -13,141 +13,175 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - #ifndef __SESSIONMAP_H__ #define __SESSIONMAP_H__ #include +#include namespace android { /** - * A wrapper template class for handling DRM Engine sessions. + * A thread safe wrapper template class for session handlings for Drm Engines. It wraps a + * pointer type over KeyedVector. It keeps pointer as data in the vector and free up memory + * allocated pointer can be of any type of structure/class meant for keeping session data. + * so session object here means pointer to the session data. */ -template +template class SessionMap { public: - KeyedVector map; - SessionMap() {} virtual ~SessionMap() { + Mutex::Autolock lock(mLock); destroyMap(); } -/** - * Adds a new value in the session map table. It expects memory to be allocated already - * for the session object - * - * @param key - key or Session ID - * @param value - session object to add - * - * @return boolean result of adding value. returns false if key is already exist. - */ -bool addValue(int key, NODE value) { - bool result = false; - - if (!isCreated(key)) { - map.add(key, value); - result = true; + /** + * Adds a new value in the session map table. It expects memory to be allocated already + * for the session object + * + * @param key - key or Session ID + * @param value - session object to add + * + * @return boolean result of adding value. returns false if key is already exist. + */ + bool addValue(int key, TValue value) { + Mutex::Autolock lock(mLock); + if (!isCreatedInternal(key)) { + map.add(key, value); + return true; + } + return false; } - return result; -} - - -/** - * returns the session object by the key - * - * @param key - key or Session ID - * - * @return session object as per the key - */ -NODE getValue(int key) { - NODE value = NULL; - - if (isCreated(key)) { - value = (NODE) map.valueFor(key); + /** + * returns the session object by the key + * + * @param key - key or Session ID + * + * @return session object as per the key + */ + TValue getValue(int key) { + Mutex::Autolock lock(mLock); + return getValueInternal(key); } - return value; -} - -/** - * returns the number of objects in the session map table - * - * @return count of number of session objects. - */ -int getSize() { - return map.size(); -} - -/** - * returns the session object by the index in the session map table - * - * @param index - index of the value required - * - * @return session object as per the index - */ -NODE getValueAt(unsigned int index) { - NODE value = NULL; + /** + * returns the number of objects in the session map table + * + * @return count of number of session objects. + */ + int getSize() { + Mutex::Autolock lock(mLock); + return map.size(); + } - if (map.size() > index) { - value = map.valueAt(index); + /** + * returns the session object by the index in the session map table + * + * @param index - index of the value required + * + * @return session object as per the index + */ + TValue getValueAt(unsigned int index) { + TValue value = NULL; + Mutex::Autolock lock(mLock); + + if (map.size() > index) { + value = map.valueAt(index); + } + return value; } - return value; -} + /** + * deletes the object from session map. It also frees up memory for the session object. + * + * @param key - key of the value to be deleted + * + */ + void removeValue(int key) { + Mutex::Autolock lock(mLock); + deleteValue(getValueInternal(key)); + map.removeItem(key); + } -/** - * deletes the object from session map. It also frees up memory for the session object. - * - * @param key - key of the value to be deleted - * - */ -void removeValue(int key) { - deleteValue(getValue(key)); - map.removeItem(key); -} + /** + * decides if session is already created. + * + * @param key - key of the value for the session + * + * @return boolean result of whether session is created + */ + bool isCreated(int key) { + Mutex::Autolock lock(mLock); + return isCreatedInternal(key); + } -/** - * decides if session is already created. - * - * @param key - key of the value for the session - * - * @return boolean result of whether session is created - */ -bool isCreated(int key) { - return (0 <= map.indexOfKey(key)); -} + SessionMap & operator=(const SessionMap & objectCopy) { + Mutex::Autolock lock(mLock); -/** - * empty the entire session table. It releases all the memory for session objects. - */ -void destroyMap() { - int size = map.size(); - int i = 0; + destroyMap(); + map = objectCopy.map; + return *this; + } - for (i = 0; i < size; i++) { - deleteValue(map.valueAt(i)); +private: + KeyedVector map; + Mutex mLock; + + /** + * free up the memory for the session object. + * Make sure if any reference to the session object anywhere, otherwise it will be a + * dangle pointer after this call. + * + * @param value - session object to free + * + */ + void deleteValue(TValue value) { + delete value; } - map.clear(); -} + /** + * free up the memory for the entire map. + * free up any resources in the sessions before calling this funtion. + * + */ + void destroyMap() { + int size = map.size(); + + for (int i = 0; i < size; i++) { + deleteValue(map.valueAt(i)); + } + map.clear(); + } -/** - * free up the memory for the session object. - * Make sure if any reference to the session object anywhere, otherwise it will be a - * dangle pointer after this call. - * - * @param value - session object to free - * - */ -void deleteValue(NODE value) { - delete value; -} + /** + * decides if session is already created. + * + * @param key - key of the value for the session + * + * @return boolean result of whether session is created + */ + bool isCreatedInternal(int key) { + return(0 <= map.indexOfKey(key)); + } + /** + * returns the session object by the key + * + * @param key - key or Session ID + * + * @return session object as per the key + */ + TValue getValueInternal(int key) { + TValue value = NULL; + if (isCreatedInternal(key)) { + value = (TValue) map.valueFor(key); + } + return value; + } }; }; diff --git a/drm/libdrmframework/plugins/common/util/src/MimeTypeUtil.cpp b/drm/libdrmframework/plugins/common/util/src/MimeTypeUtil.cpp index 4ee903e..57ef799 100644 --- a/drm/libdrmframework/plugins/common/util/src/MimeTypeUtil.cpp +++ b/drm/libdrmframework/plugins/common/util/src/MimeTypeUtil.cpp @@ -22,6 +22,13 @@ namespace android { #undef LOG_TAG #define LOG_TAG "MimeTypeUtil" +#ifdef DRM_OMA_FL_ENGINE_DEBUG +#define LOG_NDEBUG 0 +#define LOG_DEBUG(...) LOGD(__VA_ARGS__) +#else +#define LOG_DEBUG(...) +#endif + enum { MIMETYPE_AUDIO = 0, MIMETYPE_APPLICATION = 1, @@ -59,6 +66,7 @@ static const char mime_group_audio[] = "audio/"; static const char mime_group_application[] = "application/"; static const char mime_group_image[] = "image/"; static const char mime_group_video[] = "video/"; +static const char mime_type_unsupported[] = "unsupported/drm.mimetype"; static struct MimeGroup mimeGroup[] = { {MIMETYPE_AUDIO, mime_group_audio, sizeof(mime_group_audio)-1}, @@ -107,48 +115,52 @@ static struct MimeTypeList mimeTypeList[] = { * replacement mimetype otherwise the original mimetype * is returned. * + * If the mimetype is of unsupported group i.e. application/* + * then "unsupported/drm.mimetype" will be returned. + * * @param mimeType - mimetype in lower case to convert. * - * @return mimetype or null. + * @return mimetype or "unsupported/drm.mimetype". */ String8 MimeTypeUtil::convertMimeType(String8& mimeType) { String8 result = mimeType; - const char* pTmp; const char* pMimeType; struct MimeGroup* pGroup; struct MimeTypeList* pMimeItem; int len; - pMimeType = mimeType.string(); if (NULL != pMimeType) { - /* Check which group the mimetype is */ - pGroup = mimeGroup; - - while (MIMETYPE_LAST != pGroup->type) { - if (0 == strncmp(pMimeType, pGroup->pGroup, pGroup->size)) { - break; + if ((0 == strncmp(pMimeType, mime_group_audio, (sizeof mime_group_audio) - 1)) || + (0 == strncmp(pMimeType, mime_group_video, (sizeof mime_group_video) - 1))) { + /* Check which group the mimetype is */ + pGroup = mimeGroup; + while (MIMETYPE_LAST != pGroup->type) { + if (0 == strncmp(pMimeType, pGroup->pGroup, pGroup->size)) { + break; + } + pGroup++; } - pGroup++; - } - - /* Go through the mimetype list. Only check items of the correct group */ - if (MIMETYPE_LAST != pGroup->type) { - pMimeItem = mimeTypeList; - len = strlen (pMimeType+pGroup->size); - while (MIMETYPE_LAST != pMimeItem->type) { - if ((len == pMimeItem->size) && - (0 == strcmp(pMimeType+pGroup->size, pMimeItem->pMimeExt))) { - result = String8(pMimeItem->pMimeType); - break; + /* Go through the mimetype list. Only check items of the correct group */ + if (MIMETYPE_LAST != pGroup->type) { + pMimeItem = mimeTypeList; + len = strlen (pMimeType+pGroup->size); + while (MIMETYPE_LAST != pMimeItem->type) { + if ((pGroup->type == pMimeItem->type) && + (len == pMimeItem->size) && + (0 == strcmp(pMimeType+pGroup->size, pMimeItem->pMimeExt))) { + result = String8(pMimeItem->pMimeType); + break; + } + pMimeItem++; } - pMimeItem++; } + } else { + result = String8(mime_type_unsupported); } - LOGI("convertMimeType got mimetype %s, converted into mimetype %s", - pMimeType, result.string()); + LOG_DEBUG("convertMimeType got mimetype %s, converted into mimetype %s", + pMimeType, result.string()); } - return result; } }; diff --git a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/Android.mk b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/Android.mk index d4a6f18..21de4ea 100644 --- a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/Android.mk +++ b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/Android.mk @@ -17,6 +17,9 @@ LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) +# The flag below turns on local debug printouts +#LOCAL_CFLAGS += -DDRM_OMA_FL_ENGINE_DEBUG + base := frameworks/base # Determine whether the DRM framework uses 64-bit data types for file offsets and do the same. diff --git a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp index d430f72..9453a20 100644 --- a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp +++ b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp @@ -41,6 +41,13 @@ #undef LOG_TAG #define LOG_TAG "FwdLockEngine" +#ifdef DRM_OMA_FL_ENGINE_DEBUG +#define LOG_NDEBUG 0 +#define LOG_VERBOSE(...) LOGV(__VA_ARGS__) +#else +#define LOG_VERBOSE(...) +#endif + using namespace android; // This extern "C" is mandatory to be managed by TPlugInManager extern "C" IDrmEngine* create() { @@ -53,14 +60,25 @@ extern "C" void destroy(IDrmEngine* plugIn) { } FwdLockEngine::FwdLockEngine() { - LOGD("FwdLockEngine Construction"); + LOG_VERBOSE("FwdLockEngine Construction"); } FwdLockEngine::~FwdLockEngine() { - LOGD("FwdLockEngine Destruction"); + LOG_VERBOSE("FwdLockEngine Destruction"); + + int size = decodeSessionMap.getSize(); - convertSessionMap.destroyMap(); - decodeSessionMap.destroyMap(); + for (int i = 0; i < size; i++) { + DecodeSession *session = (DecodeSession*) decodeSessionMap.getValueAt(i); + FwdLockFile_detach(session->fileDesc); + ::close(session->fileDesc); + } + + size = convertSessionMap.getSize(); + for (int i = 0; i < size; i++) { + ConvertSession *convSession = (ConvertSession*) convertSessionMap.getValueAt(i); + FwdLockConv_CloseSession(convSession->uniqueId, &(convSession->output)); + } } int FwdLockEngine::getConvertedStatus(FwdLockConv_Status_t status) { @@ -74,12 +92,12 @@ int FwdLockEngine::getConvertedStatus(FwdLockConv_Status_t status) { case FwdLockConv_Status_InvalidArgument: case FwdLockConv_Status_UnsupportedFileFormat: case FwdLockConv_Status_UnsupportedContentTransferEncoding: - LOGD("FwdLockEngine getConvertedStatus: file conversion Error %d. " \ + LOGE("FwdLockEngine getConvertedStatus: file conversion Error %d. " "Returning STATUS_INPUTDATA_ERROR", status); retStatus = DrmConvertedStatus::STATUS_INPUTDATA_ERROR; break; default: - LOGD("FwdLockEngine getConvertedStatus: file conversion Error %d. " \ + LOGE("FwdLockEngine getConvertedStatus: file conversion Error %d. " "Returning STATUS_ERROR", status); retStatus = DrmConvertedStatus::STATUS_ERROR; break; @@ -91,7 +109,7 @@ int FwdLockEngine::getConvertedStatus(FwdLockConv_Status_t status) { DrmConstraints* FwdLockEngine::onGetConstraints(int uniqueId, const String8* path, int action) { DrmConstraints* drmConstraints = NULL; - LOGD("FwdLockEngine::onGetConstraints"); + LOG_VERBOSE("FwdLockEngine::onGetConstraints"); if (NULL != path && (RightsStatus::RIGHTS_VALID == onCheckRightsStatus(uniqueId, *path, action))) { @@ -105,7 +123,7 @@ DrmConstraints* FwdLockEngine::onGetConstraints(int uniqueId, const String8* pat DrmMetadata* FwdLockEngine::onGetMetadata(int uniqueId, const String8* path) { DrmMetadata* drmMetadata = NULL; - LOGD("FwdLockEngine::onGetMetadata"); + LOG_VERBOSE("FwdLockEngine::onGetMetadata"); if (NULL != path) { // Returns empty metadata to show no error condition. @@ -116,13 +134,12 @@ DrmMetadata* FwdLockEngine::onGetMetadata(int uniqueId, const String8* path) { } android::status_t FwdLockEngine::onInitialize(int uniqueId) { - LOGD("FwdLockEngine::onInitialize"); - + LOG_VERBOSE("FwdLockEngine::onInitialize"); if (FwdLockGlue_InitializeKeyEncryption()) { - LOGD("FwdLockEngine::onInitialize -- FwdLockGlue_InitializeKeyEncryption succeeded"); + LOG_VERBOSE("FwdLockEngine::onInitialize -- FwdLockGlue_InitializeKeyEncryption succeeded"); } else { - LOGD("FwdLockEngine::onInitialize -- FwdLockGlue_InitializeKeyEncryption failed:" + LOGE("FwdLockEngine::onInitialize -- FwdLockGlue_InitializeKeyEncryption failed:" "errno = %d", errno); } @@ -132,13 +149,13 @@ android::status_t FwdLockEngine::onInitialize(int uniqueId) { android::status_t FwdLockEngine::onSetOnInfoListener(int uniqueId, const IDrmEngine::OnInfoListener* infoListener) { // Not used - LOGD("FwdLockEngine::onSetOnInfoListener"); + LOG_VERBOSE("FwdLockEngine::onSetOnInfoListener"); return DRM_NO_ERROR; } android::status_t FwdLockEngine::onTerminate(int uniqueId) { - LOGD("FwdLockEngine::onTerminate"); + LOG_VERBOSE("FwdLockEngine::onTerminate"); return DRM_NO_ERROR; } @@ -146,7 +163,7 @@ android::status_t FwdLockEngine::onTerminate(int uniqueId) { DrmSupportInfo* FwdLockEngine::onGetSupportInfo(int uniqueId) { DrmSupportInfo* pSupportInfo = new DrmSupportInfo(); - LOGD("FwdLockEngine::onGetSupportInfo"); + LOG_VERBOSE("FwdLockEngine::onGetSupportInfo"); // fill all Forward Lock mimetypes and extensions if (NULL != pSupportInfo) { @@ -182,7 +199,7 @@ DrmInfoStatus* FwdLockEngine::onProcessDrmInfo(int uniqueId, const DrmInfo* drmI drmInfoStatus = new DrmInfoStatus((int)DrmInfoStatus::STATUS_OK, 0, NULL, String8("")); - LOGD("FwdLockEngine::onProcessDrmInfo"); + LOG_VERBOSE("FwdLockEngine::onProcessDrmInfo"); return drmInfoStatus; } @@ -193,7 +210,7 @@ status_t FwdLockEngine::onSaveRights( const String8& rightsPath, const String8& contentPath) { // No rights to save. Return - LOGD("FwdLockEngine::onSaveRights"); + LOG_VERBOSE("FwdLockEngine::onSaveRights"); return DRM_ERROR_UNKNOWN; } @@ -201,7 +218,7 @@ DrmInfo* FwdLockEngine::onAcquireDrmInfo(int uniqueId, const DrmInfoRequest* drm DrmInfo* drmInfo = NULL; // Nothing to be done for Forward Lock file - LOGD("FwdLockEngine::onAcquireDrmInfo"); + LOG_VERBOSE("FwdLockEngine::onAcquireDrmInfo"); return drmInfo; } @@ -211,7 +228,7 @@ int FwdLockEngine::onCheckRightsStatus(int uniqueId, int action) { int result = RightsStatus::RIGHTS_INVALID; - LOGD("FwdLockEngine::onCheckRightsStatus"); + LOG_VERBOSE("FwdLockEngine::onCheckRightsStatus"); // Only Transfer action is not allowed for forward Lock files. if (onCanHandle(uniqueId, path)) { @@ -241,7 +258,7 @@ status_t FwdLockEngine::onConsumeRights(int uniqueId, int action, bool reserve) { // No rights consumption - LOGD("FwdLockEngine::onConsumeRights"); + LOG_VERBOSE("FwdLockEngine::onConsumeRights"); return DRM_NO_ERROR; } @@ -249,14 +266,14 @@ bool FwdLockEngine::onValidateAction(int uniqueId, const String8& path, int action, const ActionDescription& description) { - LOGD("FwdLockEngine::onValidateAction"); + LOG_VERBOSE("FwdLockEngine::onValidateAction"); // For the forwardlock engine checkRights and ValidateAction are the same. return (onCheckRightsStatus(uniqueId, path, action) == RightsStatus::RIGHTS_VALID); } String8 FwdLockEngine::onGetOriginalMimeType(int uniqueId, const String8& path) { - LOGD("FwdLockEngine::onGetOriginalMimeType"); + LOG_VERBOSE("FwdLockEngine::onGetOriginalMimeType"); String8 mimeString = String8(""); int fileDesc = FwdLockFile_open(path.string()); @@ -280,7 +297,7 @@ int FwdLockEngine::onGetDrmObjectType(int uniqueId, const String8& mimeType) { String8 mimeStr = String8(mimeType); - LOGD("FwdLockEngine::onGetDrmObjectType"); + LOG_VERBOSE("FwdLockEngine::onGetDrmObjectType"); mimeStr.toLower(); @@ -301,13 +318,13 @@ int FwdLockEngine::onGetDrmObjectType(int uniqueId, status_t FwdLockEngine::onRemoveRights(int uniqueId, const String8& path) { // No Rights to remove - LOGD("FwdLockEngine::onRemoveRights"); + LOG_VERBOSE("FwdLockEngine::onRemoveRights"); return DRM_NO_ERROR; } status_t FwdLockEngine::onRemoveAllRights(int uniqueId) { // No rights to remove - LOGD("FwdLockEngine::onRemoveAllRights"); + LOG_VERBOSE("FwdLockEngine::onRemoveAllRights"); return DRM_NO_ERROR; } @@ -319,14 +336,14 @@ status_t FwdLockEngine::onSetPlaybackStatus(int uniqueId, DecryptHandle* decrypt int playbackStatus, int position) { #endif // Not used - LOGD("FwdLockEngine::onSetPlaybackStatus"); + LOG_VERBOSE("FwdLockEngine::onSetPlaybackStatus"); return DRM_NO_ERROR; } status_t FwdLockEngine::onOpenConvertSession(int uniqueId, int convertId) { status_t result = DRM_ERROR_UNKNOWN; - LOGD("FwdLockEngine::onOpenConvertSession"); + LOG_VERBOSE("FwdLockEngine::onOpenConvertSession"); if (!convertSessionMap.isCreated(convertId)) { ConvertSession *newSession = new ConvertSession(); if (FwdLockConv_Status_OK == @@ -334,7 +351,7 @@ status_t FwdLockEngine::onOpenConvertSession(int uniqueId, convertSessionMap.addValue(convertId, newSession); result = DRM_NO_ERROR; } else { - LOGD("FwdLockEngine::onOpenConvertSession -- FwdLockConv_OpenSession failed."); + LOGE("FwdLockEngine::onOpenConvertSession -- FwdLockConv_OpenSession failed."); delete newSession; } } @@ -383,7 +400,7 @@ DrmConvertedStatus* FwdLockEngine::onCloseConvertSession(int uniqueId, DrmBuffer *convResult = new DrmBuffer(NULL, 0); int offset = -1; - LOGD("FwdLockEngine::onCloseConvertSession"); + LOG_VERBOSE("FwdLockEngine::onCloseConvertSession"); if (convertSessionMap.isCreated(convertId)) { ConvertSession *convSession = convertSessionMap.getValue(convertId); @@ -424,14 +441,14 @@ status_t FwdLockEngine::onOpenDecryptSession(int uniqueId, status_t result = DRM_ERROR_CANNOT_HANDLE; int fileDesc = -1; - LOGD("FwdLockEngine::onOpenDecryptSession"); + LOG_VERBOSE("FwdLockEngine::onOpenDecryptSession"); if ((-1 < fd) && (NULL != decryptHandle) && (!decodeSessionMap.isCreated(decryptHandle->decryptId))) { fileDesc = dup(fd); } else { - LOGD("FwdLockEngine::onOpenDecryptSession parameter error"); + LOGE("FwdLockEngine::onOpenDecryptSession parameter error"); return result; } @@ -453,14 +470,14 @@ status_t FwdLockEngine::onOpenDecryptSession(int uniqueId, decryptHandle->decryptInfo = NULL; result = DRM_NO_ERROR; } else { - LOGD("FwdLockEngine::onOpenDecryptSession Integrity Check failed for the fd"); + LOG_VERBOSE("FwdLockEngine::onOpenDecryptSession Integrity Check failed for the fd"); FwdLockFile_detach(fileDesc); ::close(fileDesc); delete decodeSession; } } - LOGD("FwdLockEngine::onOpenDecryptSession Exit. result = %d", result); + LOG_VERBOSE("FwdLockEngine::onOpenDecryptSession Exit. result = %d", result); return result; } @@ -497,7 +514,7 @@ status_t FwdLockEngine::onOpenDecryptSession(int uniqueId, status_t FwdLockEngine::onCloseDecryptSession(int uniqueId, DecryptHandle* decryptHandle) { status_t result = DRM_ERROR_UNKNOWN; - LOGD("FwdLockEngine::onCloseDecryptSession"); + LOG_VERBOSE("FwdLockEngine::onCloseDecryptSession"); if (NULL != decryptHandle && decodeSessionMap.isCreated(decryptHandle->decryptId)) { DecodeSession* session = decodeSessionMap.getValue(decryptHandle->decryptId); @@ -509,7 +526,7 @@ status_t FwdLockEngine::onCloseDecryptSession(int uniqueId, } } - LOGD("FwdLockEngine::onCloseDecryptSession Exit"); + LOG_VERBOSE("FwdLockEngine::onCloseDecryptSession Exit"); return result; } @@ -517,13 +534,13 @@ status_t FwdLockEngine::onInitializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo) { - LOGD("FwdLockEngine::onInitializeDecryptUnit"); + LOGE("FwdLockEngine::onInitializeDecryptUnit is not supported for this DRM scheme"); return DRM_ERROR_UNKNOWN; } status_t FwdLockEngine::onDecrypt(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) { - LOGD("FwdLockEngine::onDecrypt"); + LOGE("FwdLockEngine::onDecrypt is not supported for this DRM scheme"); return DRM_ERROR_UNKNOWN; } @@ -532,14 +549,14 @@ status_t FwdLockEngine::onDecrypt(int uniqueId, int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer) { - LOGD("FwdLockEngine::onDecrypt"); + LOGE("FwdLockEngine::onDecrypt is not supported for this DRM scheme"); return DRM_ERROR_UNKNOWN; } status_t FwdLockEngine::onFinalizeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) { - LOGD("FwdLockEngine::onFinalizeDecryptUnit"); + LOGE("FwdLockEngine::onFinalizeDecryptUnit is not supported for this DRM scheme"); return DRM_ERROR_UNKNOWN; } @@ -617,11 +634,11 @@ ssize_t FwdLockEngine::onPread(int uniqueId, if (((off_t)-1) != decoderSession->offset) { bytesRead = onRead(uniqueId, decryptHandle, buffer, numBytes); if (bytesRead < 0) { - LOGD("FwdLockEngine::onPread error reading"); + LOGE("FwdLockEngine::onPread error reading"); } } } else { - LOGD("FwdLockEngine::onPread decryptId not found"); + LOGE("FwdLockEngine::onPread decryptId not found"); } return bytesRead; diff --git a/drm/libdrmframework/plugins/forward-lock/internal-format/converter/FwdLockConv.c b/drm/libdrmframework/plugins/forward-lock/internal-format/converter/FwdLockConv.c index 14ea9e9..299116d 100644 --- a/drm/libdrmframework/plugins/forward-lock/internal-format/converter/FwdLockConv.c +++ b/drm/libdrmframework/plugins/forward-lock/internal-format/converter/FwdLockConv.c @@ -275,17 +275,18 @@ static int FwdLockConv_DeriveKeys(FwdLockConv_Session_t *pSession) { } /** - * Checks whether a given character is valid in a boundary. Note that the boundary may contain - * leading and internal spaces. + * Checks whether a given character is valid in a boundary. Allows some non-standard characters that + * are invalid according to RFC 2046 but nevertheless used by one vendor's DRM packager. Note that + * the boundary may contain leading and internal spaces. * * @param[in] ch The character to check. * * @return A Boolean value indicating whether the given character is valid in a boundary. */ static int FwdLockConv_IsBoundaryChar(int ch) { - return isalnum(ch) || ch == '\'' || - ch == '(' || ch == ')' || ch == '+' || ch == '_' || ch == ',' || ch == '-' || - ch == '.' || ch == '/' || ch == ':' || ch == '=' || ch == '?' || ch == ' '; + return isalnum(ch) || ch == '\'' || ch == '(' || ch == ')' || ch == '+' || ch == '_' || + ch == ',' || ch == '-' || ch == '.' || ch == '/' || ch == ':' || ch == '=' || + ch == '?' || ch == ' ' || ch == '%' || ch == '[' || ch == '&' || ch == '*' || ch == '^'; } /** @@ -1085,6 +1086,13 @@ static FwdLockConv_Status_t FwdLockConv_PushChar(FwdLockConv_Session_t *pSession status = FwdLockConv_MatchBinaryEncodedData(pSession, ch, pOutput); break; case FwdLockConv_ParserState_WantsBase64EncodedData: + if (ch == '\n' && pSession->scannerState != FwdLockConv_ScannerState_WantsLF) { + // Repair base64-encoded data that doesn't have carriage returns in its line breaks. + status = FwdLockConv_MatchBase64EncodedData(pSession, '\r', pOutput); + if (status != FwdLockConv_Status_OK) { + break; + } + } status = FwdLockConv_MatchBase64EncodedData(pSession, ch, pOutput); break; case FwdLockConv_ParserState_Done: @@ -1199,7 +1207,7 @@ FwdLockConv_Status_t FwdLockConv_CloseSession(int sessionId, FwdLockConv_Output_ status = FwdLockConv_Status_SyntaxError; } else { // Finalize the data signature. - size_t signatureSize; + unsigned int signatureSize = SHA1_HASH_SIZE; HMAC_Final(&pSession->signingContext, pOutput->fromCloseSession.signatures, &signatureSize); if (signatureSize != SHA1_HASH_SIZE) { @@ -1214,9 +1222,9 @@ FwdLockConv_Status_t FwdLockConv_CloseSession(int sessionId, FwdLockConv_Output_ HMAC_Update(&pSession->signingContext, pSession->pEncryptedSessionKey, pSession->encryptedSessionKeyLength); HMAC_Update(&pSession->signingContext, pOutput->fromCloseSession.signatures, - signatureSize); - HMAC_Final(&pSession->signingContext, &pOutput->fromCloseSession. - signatures[signatureSize], &signatureSize); + SHA1_HASH_SIZE); + HMAC_Final(&pSession->signingContext, + &pOutput->fromCloseSession.signatures[SHA1_HASH_SIZE], &signatureSize); if (signatureSize != SHA1_HASH_SIZE) { status = FwdLockConv_Status_ProgramError; } else { diff --git a/drm/libdrmframework/plugins/forward-lock/internal-format/decoder/FwdLockFile.c b/drm/libdrmframework/plugins/forward-lock/internal-format/decoder/FwdLockFile.c index 98284e7..dacf00e 100644 --- a/drm/libdrmframework/plugins/forward-lock/internal-format/decoder/FwdLockFile.c +++ b/drm/libdrmframework/plugins/forward-lock/internal-format/decoder/FwdLockFile.c @@ -114,7 +114,7 @@ static int FwdLockFile_AcquireSession(int fileDesc) { } /** - * Finds the file session associated to the given file descriptor. + * Finds the file session associated with the given file descriptor. * * @param[in] fileDesc A file descriptor. * @@ -389,7 +389,7 @@ int FwdLockFile_CheckDataIntegrity(int fileDesc) { result = FALSE; } else { ssize_t numBytesRead; - size_t signatureSize = SHA1_HASH_SIZE; + unsigned int signatureSize = SHA1_HASH_SIZE; while ((numBytesRead = read(pSession->fileDesc, pData->buffer, SIG_CALC_BUFFER_SIZE)) > 0) { HMAC_Update(&pSession->signingContext, pData->buffer, (size_t)numBytesRead); @@ -399,7 +399,7 @@ int FwdLockFile_CheckDataIntegrity(int fileDesc) { } else { HMAC_Final(&pSession->signingContext, pData->signature, &signatureSize); assert(signatureSize == SHA1_HASH_SIZE); - result = memcmp(pData->signature, pSession->dataSignature, signatureSize) == 0; + result = memcmp(pData->signature, pSession->dataSignature, SHA1_HASH_SIZE) == 0; } HMAC_Init_ex(&pSession->signingContext, NULL, KEY_SIZE, NULL, NULL); (void)lseek64(pSession->fileDesc, pSession->dataOffset + pSession->filePos, @@ -419,16 +419,16 @@ int FwdLockFile_CheckHeaderIntegrity(int fileDesc) { } else { FwdLockFile_Session_t *pSession = sessionPtrs[sessionId]; unsigned char signature[SHA1_HASH_SIZE]; - size_t signatureSize = SHA1_HASH_SIZE; + unsigned int signatureSize = SHA1_HASH_SIZE; HMAC_Update(&pSession->signingContext, pSession->topHeader, TOP_HEADER_SIZE); HMAC_Update(&pSession->signingContext, (unsigned char *)pSession->pContentType, pSession->contentTypeLength); HMAC_Update(&pSession->signingContext, pSession->pEncryptedSessionKey, pSession->encryptedSessionKeyLength); - HMAC_Update(&pSession->signingContext, pSession->dataSignature, signatureSize); + HMAC_Update(&pSession->signingContext, pSession->dataSignature, SHA1_HASH_SIZE); HMAC_Final(&pSession->signingContext, signature, &signatureSize); assert(signatureSize == SHA1_HASH_SIZE); - result = memcmp(signature, pSession->headerSignature, signatureSize) == 0; + result = memcmp(signature, pSession->headerSignature, SHA1_HASH_SIZE) == 0; HMAC_Init_ex(&pSession->signingContext, NULL, KEY_SIZE, NULL, NULL); } return result; -- 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') 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/common/DrmMetadata.cpp | 8 +- drm/common/IDrmManagerService.cpp | 128 ++++++++++----------- drm/drmserver/DrmManager.cpp | 2 +- drm/drmserver/DrmManagerService.cpp | 60 +++++----- .../FwdLockEngine/src/FwdLockEngine.cpp | 2 +- 5 files changed, 100 insertions(+), 100 deletions(-) (limited to 'drm') diff --git a/drm/common/DrmMetadata.cpp b/drm/common/DrmMetadata.cpp index 6cc5ec1..2a4b8c8 100644 --- a/drm/common/DrmMetadata.cpp +++ b/drm/common/DrmMetadata.cpp @@ -78,11 +78,11 @@ DrmMetadata::KeyIterator DrmMetadata::keyIterator() { DrmMetadata::KeyIterator::KeyIterator(const DrmMetadata::KeyIterator& keyIterator) : mDrmMetadata(keyIterator.mDrmMetadata), mIndex(keyIterator.mIndex) { - LOGV("DrmMetadata::KeyIterator::KeyIterator"); + ALOGV("DrmMetadata::KeyIterator::KeyIterator"); } DrmMetadata::KeyIterator& DrmMetadata::KeyIterator::operator=(const DrmMetadata::KeyIterator& keyIterator) { - LOGV("DrmMetadata::KeyIterator::operator="); + ALOGV("DrmMetadata::KeyIterator::operator="); mDrmMetadata = keyIterator.mDrmMetadata; mIndex = keyIterator.mIndex; return *this; @@ -96,11 +96,11 @@ DrmMetadata::Iterator DrmMetadata::iterator() { DrmMetadata::Iterator::Iterator(const DrmMetadata::Iterator& iterator) : mDrmMetadata(iterator.mDrmMetadata), mIndex(iterator.mIndex) { - LOGV("DrmMetadata::Iterator::Iterator"); + ALOGV("DrmMetadata::Iterator::Iterator"); } DrmMetadata::Iterator& DrmMetadata::Iterator::operator=(const DrmMetadata::Iterator& iterator) { - LOGV("DrmMetadata::Iterator::operator="); + ALOGV("DrmMetadata::Iterator::operator="); mDrmMetadata = iterator.mDrmMetadata; mIndex = iterator.mIndex; return *this; diff --git a/drm/common/IDrmManagerService.cpp b/drm/common/IDrmManagerService.cpp index 0b76a36..3ed8ade 100644 --- a/drm/common/IDrmManagerService.cpp +++ b/drm/common/IDrmManagerService.cpp @@ -111,7 +111,7 @@ static void clearDecryptHandle(DecryptHandle* handle) { } int BpDrmManagerService::addUniqueId(bool isNative) { - LOGV("add uniqueid"); + ALOGV("add uniqueid"); Parcel data, reply; data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); data.writeInt32(isNative); @@ -120,7 +120,7 @@ int BpDrmManagerService::addUniqueId(bool isNative) { } void BpDrmManagerService::removeUniqueId(int uniqueId) { - LOGV("remove uniqueid"); + ALOGV("remove uniqueid"); Parcel data, reply; data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); data.writeInt32(uniqueId); @@ -143,7 +143,7 @@ void BpDrmManagerService::removeClient(int uniqueId) { status_t BpDrmManagerService::setDrmServiceListener( int uniqueId, const sp& drmServiceListener) { - LOGV("setDrmServiceListener"); + ALOGV("setDrmServiceListener"); Parcel data, reply; data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); @@ -154,7 +154,7 @@ status_t BpDrmManagerService::setDrmServiceListener( } status_t BpDrmManagerService::installDrmEngine(int uniqueId, const String8& drmEngineFile) { - LOGV("Install DRM Engine"); + ALOGV("Install DRM Engine"); Parcel data, reply; data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); @@ -167,7 +167,7 @@ status_t BpDrmManagerService::installDrmEngine(int uniqueId, const String8& drmE DrmConstraints* BpDrmManagerService::getConstraints( int uniqueId, const String8* path, const int action) { - LOGV("Get Constraints"); + ALOGV("Get Constraints"); Parcel data, reply; data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); @@ -198,7 +198,7 @@ DrmConstraints* BpDrmManagerService::getConstraints( } DrmMetadata* BpDrmManagerService::getMetadata(int uniqueId, const String8* path) { - LOGV("Get Metadata"); + ALOGV("Get Metadata"); Parcel data, reply; data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); data.writeInt32(uniqueId); @@ -227,7 +227,7 @@ DrmMetadata* BpDrmManagerService::getMetadata(int uniqueId, const String8* path) } bool BpDrmManagerService::canHandle(int uniqueId, const String8& path, const String8& mimeType) { - LOGV("Can Handle"); + ALOGV("Can Handle"); Parcel data, reply; data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); @@ -242,7 +242,7 @@ bool BpDrmManagerService::canHandle(int uniqueId, const String8& path, const Str } DrmInfoStatus* BpDrmManagerService::processDrmInfo(int uniqueId, const DrmInfo* drmInfo) { - LOGV("Process DRM Info"); + ALOGV("Process DRM Info"); Parcel data, reply; data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); @@ -293,7 +293,7 @@ DrmInfoStatus* BpDrmManagerService::processDrmInfo(int uniqueId, const DrmInfo* } DrmInfo* BpDrmManagerService::acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInforequest) { - LOGV("Acquire DRM Info"); + ALOGV("Acquire DRM Info"); Parcel data, reply; data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); @@ -341,7 +341,7 @@ DrmInfo* BpDrmManagerService::acquireDrmInfo(int uniqueId, const DrmInfoRequest* status_t BpDrmManagerService::saveRights( int uniqueId, const DrmRights& drmRights, const String8& rightsPath, const String8& contentPath) { - LOGV("Save Rights"); + ALOGV("Save Rights"); Parcel data, reply; data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); @@ -369,7 +369,7 @@ status_t BpDrmManagerService::saveRights( } String8 BpDrmManagerService::getOriginalMimeType(int uniqueId, const String8& path) { - LOGV("Get Original MimeType"); + ALOGV("Get Original MimeType"); Parcel data, reply; data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); @@ -382,7 +382,7 @@ String8 BpDrmManagerService::getOriginalMimeType(int uniqueId, const String8& pa int BpDrmManagerService::getDrmObjectType( int uniqueId, const String8& path, const String8& mimeType) { - LOGV("Get Drm object type"); + ALOGV("Get Drm object type"); Parcel data, reply; data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); @@ -396,7 +396,7 @@ int BpDrmManagerService::getDrmObjectType( } int BpDrmManagerService::checkRightsStatus(int uniqueId, const String8& path, int action) { - LOGV("checkRightsStatus"); + ALOGV("checkRightsStatus"); Parcel data, reply; data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); @@ -411,7 +411,7 @@ int BpDrmManagerService::checkRightsStatus(int uniqueId, const String8& path, in status_t BpDrmManagerService::consumeRights( int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) { - LOGV("consumeRights"); + ALOGV("consumeRights"); Parcel data, reply; data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); @@ -428,7 +428,7 @@ status_t BpDrmManagerService::consumeRights( status_t BpDrmManagerService::setPlaybackStatus( int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int64_t position) { - LOGV("setPlaybackStatus"); + ALOGV("setPlaybackStatus"); Parcel data, reply; data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); @@ -446,7 +446,7 @@ status_t BpDrmManagerService::setPlaybackStatus( bool BpDrmManagerService::validateAction( int uniqueId, const String8& path, int action, const ActionDescription& description) { - LOGV("validateAction"); + ALOGV("validateAction"); Parcel data, reply; data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); @@ -462,7 +462,7 @@ bool BpDrmManagerService::validateAction( } status_t BpDrmManagerService::removeRights(int uniqueId, const String8& path) { - LOGV("removeRights"); + ALOGV("removeRights"); Parcel data, reply; data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); @@ -474,7 +474,7 @@ status_t BpDrmManagerService::removeRights(int uniqueId, const String8& path) { } status_t BpDrmManagerService::removeAllRights(int uniqueId) { - LOGV("removeAllRights"); + ALOGV("removeAllRights"); Parcel data, reply; data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); @@ -485,7 +485,7 @@ status_t BpDrmManagerService::removeAllRights(int uniqueId) { } int BpDrmManagerService::openConvertSession(int uniqueId, const String8& mimeType) { - LOGV("openConvertSession"); + ALOGV("openConvertSession"); Parcel data, reply; data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); @@ -498,7 +498,7 @@ int BpDrmManagerService::openConvertSession(int uniqueId, const String8& mimeTyp DrmConvertedStatus* BpDrmManagerService::convertData( int uniqueId, int convertId, const DrmBuffer* inputData) { - LOGV("convertData"); + ALOGV("convertData"); Parcel data, reply; data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); @@ -532,7 +532,7 @@ DrmConvertedStatus* BpDrmManagerService::convertData( } DrmConvertedStatus* BpDrmManagerService::closeConvertSession(int uniqueId, int convertId) { - LOGV("closeConvertSession"); + ALOGV("closeConvertSession"); Parcel data, reply; data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); @@ -565,7 +565,7 @@ DrmConvertedStatus* BpDrmManagerService::closeConvertSession(int uniqueId, int c status_t BpDrmManagerService::getAllSupportInfo( int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray) { - LOGV("Get All Support Info"); + ALOGV("Get All Support Info"); Parcel data, reply; data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); @@ -601,7 +601,7 @@ status_t BpDrmManagerService::getAllSupportInfo( DecryptHandle* BpDrmManagerService::openDecryptSession( int uniqueId, int fd, off64_t offset, off64_t length) { - LOGV("Entering BpDrmManagerService::openDecryptSession"); + ALOGV("Entering BpDrmManagerService::openDecryptSession"); Parcel data, reply; data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); @@ -621,7 +621,7 @@ DecryptHandle* BpDrmManagerService::openDecryptSession( } DecryptHandle* BpDrmManagerService::openDecryptSession(int uniqueId, const char* uri) { - LOGV("Entering BpDrmManagerService::openDecryptSession"); + ALOGV("Entering BpDrmManagerService::openDecryptSession"); Parcel data, reply; data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); @@ -635,13 +635,13 @@ DecryptHandle* BpDrmManagerService::openDecryptSession(int uniqueId, const char* handle = new DecryptHandle(); readDecryptHandleFromParcelData(handle, reply); } else { - LOGV("no decryptHandle is generated in service side"); + ALOGV("no decryptHandle is generated in service side"); } return handle; } status_t BpDrmManagerService::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) { - LOGV("closeDecryptSession"); + ALOGV("closeDecryptSession"); Parcel data, reply; data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); @@ -657,7 +657,7 @@ status_t BpDrmManagerService::closeDecryptSession(int uniqueId, DecryptHandle* d status_t BpDrmManagerService::initializeDecryptUnit( int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo) { - LOGV("initializeDecryptUnit"); + ALOGV("initializeDecryptUnit"); Parcel data, reply; data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); @@ -677,7 +677,7 @@ status_t BpDrmManagerService::initializeDecryptUnit( status_t BpDrmManagerService::decrypt( int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) { - LOGV("decrypt"); + ALOGV("decrypt"); Parcel data, reply; data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); @@ -699,7 +699,7 @@ status_t BpDrmManagerService::decrypt( remote()->transact(DECRYPT, data, &reply); const status_t status = reply.readInt32(); - LOGV("Return value of decrypt() is %d", status); + ALOGV("Return value of decrypt() is %d", status); const int size = reply.readInt32(); (*decBuffer)->length = size; @@ -710,7 +710,7 @@ status_t BpDrmManagerService::decrypt( status_t BpDrmManagerService::finalizeDecryptUnit( int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) { - LOGV("finalizeDecryptUnit"); + ALOGV("finalizeDecryptUnit"); Parcel data, reply; data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); @@ -727,7 +727,7 @@ status_t BpDrmManagerService::finalizeDecryptUnit( ssize_t BpDrmManagerService::pread( int uniqueId, DecryptHandle* decryptHandle, void* buffer, ssize_t numBytes, off64_t offset) { - LOGV("read"); + ALOGV("read"); Parcel data, reply; int result; @@ -752,12 +752,12 @@ IMPLEMENT_META_INTERFACE(DrmManagerService, "drm.IDrmManagerService"); status_t BnDrmManagerService::onTransact( uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) { - LOGV("Entering BnDrmManagerService::onTransact with code %d", code); + ALOGV("Entering BnDrmManagerService::onTransact with code %d", code); switch (code) { case ADD_UNIQUEID: { - LOGV("BnDrmManagerService::onTransact :ADD_UNIQUEID"); + ALOGV("BnDrmManagerService::onTransact :ADD_UNIQUEID"); CHECK_INTERFACE(IDrmManagerService, data, reply); int uniqueId = addUniqueId(data.readInt32()); reply->writeInt32(uniqueId); @@ -766,7 +766,7 @@ status_t BnDrmManagerService::onTransact( case REMOVE_UNIQUEID: { - LOGV("BnDrmManagerService::onTransact :REMOVE_UNIQUEID"); + ALOGV("BnDrmManagerService::onTransact :REMOVE_UNIQUEID"); CHECK_INTERFACE(IDrmManagerService, data, reply); removeUniqueId(data.readInt32()); return DRM_NO_ERROR; @@ -774,7 +774,7 @@ status_t BnDrmManagerService::onTransact( case ADD_CLIENT: { - LOGV("BnDrmManagerService::onTransact :ADD_CLIENT"); + ALOGV("BnDrmManagerService::onTransact :ADD_CLIENT"); CHECK_INTERFACE(IDrmManagerService, data, reply); addClient(data.readInt32()); return DRM_NO_ERROR; @@ -782,7 +782,7 @@ status_t BnDrmManagerService::onTransact( case REMOVE_CLIENT: { - LOGV("BnDrmManagerService::onTransact :REMOVE_CLIENT"); + ALOGV("BnDrmManagerService::onTransact :REMOVE_CLIENT"); CHECK_INTERFACE(IDrmManagerService, data, reply); removeClient(data.readInt32()); return DRM_NO_ERROR; @@ -790,7 +790,7 @@ status_t BnDrmManagerService::onTransact( case SET_DRM_SERVICE_LISTENER: { - LOGV("BnDrmManagerService::onTransact :SET_DRM_SERVICE_LISTENER"); + ALOGV("BnDrmManagerService::onTransact :SET_DRM_SERVICE_LISTENER"); CHECK_INTERFACE(IDrmManagerService, data, reply); const int uniqueId = data.readInt32(); @@ -805,7 +805,7 @@ status_t BnDrmManagerService::onTransact( case INSTALL_DRM_ENGINE: { - LOGV("BnDrmManagerService::onTransact :INSTALL_DRM_ENGINE"); + ALOGV("BnDrmManagerService::onTransact :INSTALL_DRM_ENGINE"); CHECK_INTERFACE(IDrmManagerService, data, reply); const int uniqueId = data.readInt32(); @@ -818,7 +818,7 @@ status_t BnDrmManagerService::onTransact( case GET_CONSTRAINTS_FROM_CONTENT: { - LOGV("BnDrmManagerService::onTransact :GET_CONSTRAINTS_FROM_CONTENT"); + ALOGV("BnDrmManagerService::onTransact :GET_CONSTRAINTS_FROM_CONTENT"); CHECK_INTERFACE(IDrmManagerService, data, reply); const int uniqueId = data.readInt32(); @@ -850,7 +850,7 @@ status_t BnDrmManagerService::onTransact( case GET_METADATA_FROM_CONTENT: { - LOGV("BnDrmManagerService::onTransact :GET_METADATA_FROM_CONTENT"); + ALOGV("BnDrmManagerService::onTransact :GET_METADATA_FROM_CONTENT"); CHECK_INTERFACE(IDrmManagerService, data, reply); const int uniqueId = data.readInt32(); @@ -882,7 +882,7 @@ status_t BnDrmManagerService::onTransact( case CAN_HANDLE: { - LOGV("BnDrmManagerService::onTransact :CAN_HANDLE"); + ALOGV("BnDrmManagerService::onTransact :CAN_HANDLE"); CHECK_INTERFACE(IDrmManagerService, data, reply); const int uniqueId = data.readInt32(); @@ -897,7 +897,7 @@ status_t BnDrmManagerService::onTransact( case PROCESS_DRM_INFO: { - LOGV("BnDrmManagerService::onTransact :PROCESS_DRM_INFO"); + ALOGV("BnDrmManagerService::onTransact :PROCESS_DRM_INFO"); CHECK_INTERFACE(IDrmManagerService, data, reply); const int uniqueId = data.readInt32(); @@ -945,7 +945,7 @@ status_t BnDrmManagerService::onTransact( case ACQUIRE_DRM_INFO: { - LOGV("BnDrmManagerService::onTransact :ACQUIRE_DRM_INFO"); + ALOGV("BnDrmManagerService::onTransact :ACQUIRE_DRM_INFO"); CHECK_INTERFACE(IDrmManagerService, data, reply); const int uniqueId = data.readInt32(); @@ -993,7 +993,7 @@ status_t BnDrmManagerService::onTransact( case SAVE_RIGHTS: { - LOGV("BnDrmManagerService::onTransact :SAVE_RIGHTS"); + ALOGV("BnDrmManagerService::onTransact :SAVE_RIGHTS"); CHECK_INTERFACE(IDrmManagerService, data, reply); const int uniqueId = data.readInt32(); @@ -1023,7 +1023,7 @@ status_t BnDrmManagerService::onTransact( case GET_ORIGINAL_MIMETYPE: { - LOGV("BnDrmManagerService::onTransact :GET_ORIGINAL_MIMETYPE"); + ALOGV("BnDrmManagerService::onTransact :GET_ORIGINAL_MIMETYPE"); CHECK_INTERFACE(IDrmManagerService, data, reply); const int uniqueId = data.readInt32(); @@ -1036,7 +1036,7 @@ status_t BnDrmManagerService::onTransact( case GET_DRM_OBJECT_TYPE: { - LOGV("BnDrmManagerService::onTransact :GET_DRM_OBJECT_TYPE"); + ALOGV("BnDrmManagerService::onTransact :GET_DRM_OBJECT_TYPE"); CHECK_INTERFACE(IDrmManagerService, data, reply); const int uniqueId = data.readInt32(); @@ -1050,7 +1050,7 @@ status_t BnDrmManagerService::onTransact( case CHECK_RIGHTS_STATUS: { - LOGV("BnDrmManagerService::onTransact :CHECK_RIGHTS_STATUS"); + ALOGV("BnDrmManagerService::onTransact :CHECK_RIGHTS_STATUS"); CHECK_INTERFACE(IDrmManagerService, data, reply); const int uniqueId = data.readInt32(); @@ -1064,7 +1064,7 @@ status_t BnDrmManagerService::onTransact( case CONSUME_RIGHTS: { - LOGV("BnDrmManagerService::onTransact :CONSUME_RIGHTS"); + ALOGV("BnDrmManagerService::onTransact :CONSUME_RIGHTS"); CHECK_INTERFACE(IDrmManagerService, data, reply); const int uniqueId = data.readInt32(); @@ -1084,7 +1084,7 @@ status_t BnDrmManagerService::onTransact( case SET_PLAYBACK_STATUS: { - LOGV("BnDrmManagerService::onTransact :SET_PLAYBACK_STATUS"); + ALOGV("BnDrmManagerService::onTransact :SET_PLAYBACK_STATUS"); CHECK_INTERFACE(IDrmManagerService, data, reply); const int uniqueId = data.readInt32(); @@ -1104,7 +1104,7 @@ status_t BnDrmManagerService::onTransact( case VALIDATE_ACTION: { - LOGV("BnDrmManagerService::onTransact :VALIDATE_ACTION"); + ALOGV("BnDrmManagerService::onTransact :VALIDATE_ACTION"); CHECK_INTERFACE(IDrmManagerService, data, reply); const int uniqueId = data.readInt32(); @@ -1121,7 +1121,7 @@ status_t BnDrmManagerService::onTransact( case REMOVE_RIGHTS: { - LOGV("BnDrmManagerService::onTransact :REMOVE_RIGHTS"); + ALOGV("BnDrmManagerService::onTransact :REMOVE_RIGHTS"); CHECK_INTERFACE(IDrmManagerService, data, reply); int uniqueId = data.readInt32(); @@ -1134,7 +1134,7 @@ status_t BnDrmManagerService::onTransact( case REMOVE_ALL_RIGHTS: { - LOGV("BnDrmManagerService::onTransact :REMOVE_ALL_RIGHTS"); + ALOGV("BnDrmManagerService::onTransact :REMOVE_ALL_RIGHTS"); CHECK_INTERFACE(IDrmManagerService, data, reply); const status_t status = removeAllRights(data.readInt32()); @@ -1145,7 +1145,7 @@ status_t BnDrmManagerService::onTransact( case OPEN_CONVERT_SESSION: { - LOGV("BnDrmManagerService::onTransact :OPEN_CONVERT_SESSION"); + ALOGV("BnDrmManagerService::onTransact :OPEN_CONVERT_SESSION"); CHECK_INTERFACE(IDrmManagerService, data, reply); const int uniqueId = data.readInt32(); @@ -1158,7 +1158,7 @@ status_t BnDrmManagerService::onTransact( case CONVERT_DATA: { - LOGV("BnDrmManagerService::onTransact :CONVERT_DATA"); + ALOGV("BnDrmManagerService::onTransact :CONVERT_DATA"); CHECK_INTERFACE(IDrmManagerService, data, reply); const int uniqueId = data.readInt32(); @@ -1193,7 +1193,7 @@ status_t BnDrmManagerService::onTransact( case CLOSE_CONVERT_SESSION: { - LOGV("BnDrmManagerService::onTransact :CLOSE_CONVERT_SESSION"); + ALOGV("BnDrmManagerService::onTransact :CLOSE_CONVERT_SESSION"); CHECK_INTERFACE(IDrmManagerService, data, reply); const int uniqueId = data.readInt32(); @@ -1223,7 +1223,7 @@ status_t BnDrmManagerService::onTransact( case GET_ALL_SUPPORT_INFO: { - LOGV("BnDrmManagerService::onTransact :GET_ALL_SUPPORT_INFO"); + ALOGV("BnDrmManagerService::onTransact :GET_ALL_SUPPORT_INFO"); CHECK_INTERFACE(IDrmManagerService, data, reply); const int uniqueId = data.readInt32(); @@ -1257,7 +1257,7 @@ status_t BnDrmManagerService::onTransact( case OPEN_DECRYPT_SESSION: { - LOGV("BnDrmManagerService::onTransact :OPEN_DECRYPT_SESSION"); + ALOGV("BnDrmManagerService::onTransact :OPEN_DECRYPT_SESSION"); CHECK_INTERFACE(IDrmManagerService, data, reply); const int uniqueId = data.readInt32(); @@ -1278,7 +1278,7 @@ status_t BnDrmManagerService::onTransact( case OPEN_DECRYPT_SESSION_FROM_URI: { - LOGV("BnDrmManagerService::onTransact :OPEN_DECRYPT_SESSION_FROM_URI"); + ALOGV("BnDrmManagerService::onTransact :OPEN_DECRYPT_SESSION_FROM_URI"); CHECK_INTERFACE(IDrmManagerService, data, reply); const int uniqueId = data.readInt32(); @@ -1292,14 +1292,14 @@ status_t BnDrmManagerService::onTransact( clearDecryptHandle(handle); delete handle; handle = NULL; } else { - LOGV("NULL decryptHandle is returned"); + ALOGV("NULL decryptHandle is returned"); } return DRM_NO_ERROR; } case CLOSE_DECRYPT_SESSION: { - LOGV("BnDrmManagerService::onTransact :CLOSE_DECRYPT_SESSION"); + ALOGV("BnDrmManagerService::onTransact :CLOSE_DECRYPT_SESSION"); CHECK_INTERFACE(IDrmManagerService, data, reply); const int uniqueId = data.readInt32(); @@ -1314,7 +1314,7 @@ status_t BnDrmManagerService::onTransact( case INITIALIZE_DECRYPT_UNIT: { - LOGV("BnDrmManagerService::onTransact :INITIALIZE_DECRYPT_UNIT"); + ALOGV("BnDrmManagerService::onTransact :INITIALIZE_DECRYPT_UNIT"); CHECK_INTERFACE(IDrmManagerService, data, reply); const int uniqueId = data.readInt32(); @@ -1340,7 +1340,7 @@ status_t BnDrmManagerService::onTransact( case DECRYPT: { - LOGV("BnDrmManagerService::onTransact :DECRYPT"); + ALOGV("BnDrmManagerService::onTransact :DECRYPT"); CHECK_INTERFACE(IDrmManagerService, data, reply); const int uniqueId = data.readInt32(); @@ -1384,7 +1384,7 @@ status_t BnDrmManagerService::onTransact( case FINALIZE_DECRYPT_UNIT: { - LOGV("BnDrmManagerService::onTransact :FINALIZE_DECRYPT_UNIT"); + ALOGV("BnDrmManagerService::onTransact :FINALIZE_DECRYPT_UNIT"); CHECK_INTERFACE(IDrmManagerService, data, reply); const int uniqueId = data.readInt32(); @@ -1401,7 +1401,7 @@ status_t BnDrmManagerService::onTransact( case PREAD: { - LOGV("BnDrmManagerService::onTransact :READ"); + ALOGV("BnDrmManagerService::onTransact :READ"); CHECK_INTERFACE(IDrmManagerService, data, reply); const int uniqueId = data.readInt32(); 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); } diff --git a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp index e184545..7799040 100644 --- a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp +++ b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp @@ -43,7 +43,7 @@ #ifdef DRM_OMA_FL_ENGINE_DEBUG #define LOG_NDEBUG 0 -#define LOG_VERBOSE(...) LOGV(__VA_ARGS__) +#define LOG_VERBOSE(...) ALOGV(__VA_ARGS__) #else #define LOG_VERBOSE(...) #endif -- 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') 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') 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') 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 b8a805261bf0282e992d3608035e47d05a898710 Mon Sep 17 00:00:00 2001 From: Steve Block Date: Tue, 20 Dec 2011 16:23:08 +0000 Subject: Rename (IF_)LOGD(_IF) to (IF_)ALOGD(_IF) DO NOT MERGE See https://android-git.corp.google.com/g/156016 Bug: 5449033 Change-Id: I4c4e33bb9df3e39e11cd985e193e6fbab4635298 --- .../plugins/common/util/src/MimeTypeUtil.cpp | 2 +- .../plugins/passthru/src/DrmPassthruPlugIn.cpp | 54 +++++++++++----------- 2 files changed, 28 insertions(+), 28 deletions(-) (limited to 'drm') diff --git a/drm/libdrmframework/plugins/common/util/src/MimeTypeUtil.cpp b/drm/libdrmframework/plugins/common/util/src/MimeTypeUtil.cpp index 57ef799..576ed15 100644 --- a/drm/libdrmframework/plugins/common/util/src/MimeTypeUtil.cpp +++ b/drm/libdrmframework/plugins/common/util/src/MimeTypeUtil.cpp @@ -24,7 +24,7 @@ namespace android { #ifdef DRM_OMA_FL_ENGINE_DEBUG #define LOG_NDEBUG 0 -#define LOG_DEBUG(...) LOGD(__VA_ARGS__) +#define LOG_DEBUG(...) ALOGD(__VA_ARGS__) #else #define LOG_DEBUG(...) #endif diff --git a/drm/libdrmframework/plugins/passthru/src/DrmPassthruPlugIn.cpp b/drm/libdrmframework/plugins/passthru/src/DrmPassthruPlugIn.cpp index 976978f..0ffc0a7 100644 --- a/drm/libdrmframework/plugins/passthru/src/DrmPassthruPlugIn.cpp +++ b/drm/libdrmframework/plugins/passthru/src/DrmPassthruPlugIn.cpp @@ -58,7 +58,7 @@ DrmMetadata* DrmPassthruPlugIn::onGetMetadata(int uniqueId, const String8* path) DrmConstraints* DrmPassthruPlugIn::onGetConstraints( int uniqueId, const String8* path, int action) { - LOGD("DrmPassthruPlugIn::onGetConstraints From Path: %d", uniqueId); + ALOGD("DrmPassthruPlugIn::onGetConstraints From Path: %d", uniqueId); DrmConstraints* drmConstraints = new DrmConstraints(); String8 value("dummy_available_time"); @@ -73,7 +73,7 @@ DrmConstraints* DrmPassthruPlugIn::onGetConstraints( } DrmInfoStatus* DrmPassthruPlugIn::onProcessDrmInfo(int uniqueId, const DrmInfo* drmInfo) { - LOGD("DrmPassthruPlugIn::onProcessDrmInfo - Enter : %d", uniqueId); + ALOGD("DrmPassthruPlugIn::onProcessDrmInfo - Enter : %d", uniqueId); DrmInfoStatus* drmInfoStatus = NULL; if (NULL != drmInfo) { switch (drmInfo->getInfoType()) { @@ -102,28 +102,28 @@ DrmInfoStatus* DrmPassthruPlugIn::onProcessDrmInfo(int uniqueId, const DrmInfo* } } } - LOGD("DrmPassthruPlugIn::onProcessDrmInfo - Exit"); + ALOGD("DrmPassthruPlugIn::onProcessDrmInfo - Exit"); return drmInfoStatus; } status_t DrmPassthruPlugIn::onSetOnInfoListener( int uniqueId, const IDrmEngine::OnInfoListener* infoListener) { - LOGD("DrmPassthruPlugIn::onSetOnInfoListener : %d", uniqueId); + ALOGD("DrmPassthruPlugIn::onSetOnInfoListener : %d", uniqueId); return DRM_NO_ERROR; } status_t DrmPassthruPlugIn::onInitialize(int uniqueId) { - LOGD("DrmPassthruPlugIn::onInitialize : %d", uniqueId); + ALOGD("DrmPassthruPlugIn::onInitialize : %d", uniqueId); return DRM_NO_ERROR; } status_t DrmPassthruPlugIn::onTerminate(int uniqueId) { - LOGD("DrmPassthruPlugIn::onTerminate : %d", uniqueId); + ALOGD("DrmPassthruPlugIn::onTerminate : %d", uniqueId); return DRM_NO_ERROR; } DrmSupportInfo* DrmPassthruPlugIn::onGetSupportInfo(int uniqueId) { - LOGD("DrmPassthruPlugIn::onGetSupportInfo : %d", uniqueId); + ALOGD("DrmPassthruPlugIn::onGetSupportInfo : %d", uniqueId); DrmSupportInfo* drmSupportInfo = new DrmSupportInfo(); // Add mimetype's drmSupportInfo->addMimeType(String8("application/vnd.passthru.drm")); @@ -136,12 +136,12 @@ DrmSupportInfo* DrmPassthruPlugIn::onGetSupportInfo(int uniqueId) { status_t DrmPassthruPlugIn::onSaveRights(int uniqueId, const DrmRights& drmRights, const String8& rightsPath, const String8& contentPath) { - LOGD("DrmPassthruPlugIn::onSaveRights : %d", uniqueId); + ALOGD("DrmPassthruPlugIn::onSaveRights : %d", uniqueId); return DRM_NO_ERROR; } DrmInfo* DrmPassthruPlugIn::onAcquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest) { - LOGD("DrmPassthruPlugIn::onAcquireDrmInfo : %d", uniqueId); + ALOGD("DrmPassthruPlugIn::onAcquireDrmInfo : %d", uniqueId); DrmInfo* drmInfo = NULL; if (NULL != drmInfoRequest) { @@ -157,65 +157,65 @@ DrmInfo* DrmPassthruPlugIn::onAcquireDrmInfo(int uniqueId, const DrmInfoRequest* } bool DrmPassthruPlugIn::onCanHandle(int uniqueId, const String8& path) { - LOGD("DrmPassthruPlugIn::canHandle: %s ", path.string()); + ALOGD("DrmPassthruPlugIn::canHandle: %s ", path.string()); String8 extension = path.getPathExtension(); extension.toLower(); return (String8(".passthru") == extension); } String8 DrmPassthruPlugIn::onGetOriginalMimeType(int uniqueId, const String8& path) { - LOGD("DrmPassthruPlugIn::onGetOriginalMimeType() : %d", uniqueId); + ALOGD("DrmPassthruPlugIn::onGetOriginalMimeType() : %d", uniqueId); return String8("video/passthru"); } int DrmPassthruPlugIn::onGetDrmObjectType( int uniqueId, const String8& path, const String8& mimeType) { - LOGD("DrmPassthruPlugIn::onGetDrmObjectType() : %d", uniqueId); + ALOGD("DrmPassthruPlugIn::onGetDrmObjectType() : %d", uniqueId); return DrmObjectType::UNKNOWN; } int DrmPassthruPlugIn::onCheckRightsStatus(int uniqueId, const String8& path, int action) { - LOGD("DrmPassthruPlugIn::onCheckRightsStatus() : %d", uniqueId); + ALOGD("DrmPassthruPlugIn::onCheckRightsStatus() : %d", uniqueId); int rightsStatus = RightsStatus::RIGHTS_VALID; return rightsStatus; } status_t DrmPassthruPlugIn::onConsumeRights(int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) { - LOGD("DrmPassthruPlugIn::onConsumeRights() : %d", uniqueId); + ALOGD("DrmPassthruPlugIn::onConsumeRights() : %d", uniqueId); return DRM_NO_ERROR; } status_t DrmPassthruPlugIn::onSetPlaybackStatus(int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int64_t position) { - LOGD("DrmPassthruPlugIn::onSetPlaybackStatus() : %d", uniqueId); + ALOGD("DrmPassthruPlugIn::onSetPlaybackStatus() : %d", uniqueId); return DRM_NO_ERROR; } bool DrmPassthruPlugIn::onValidateAction(int uniqueId, const String8& path, int action, const ActionDescription& description) { - LOGD("DrmPassthruPlugIn::onValidateAction() : %d", uniqueId); + ALOGD("DrmPassthruPlugIn::onValidateAction() : %d", uniqueId); return true; } status_t DrmPassthruPlugIn::onRemoveRights(int uniqueId, const String8& path) { - LOGD("DrmPassthruPlugIn::onRemoveRights() : %d", uniqueId); + ALOGD("DrmPassthruPlugIn::onRemoveRights() : %d", uniqueId); return DRM_NO_ERROR; } status_t DrmPassthruPlugIn::onRemoveAllRights(int uniqueId) { - LOGD("DrmPassthruPlugIn::onRemoveAllRights() : %d", uniqueId); + ALOGD("DrmPassthruPlugIn::onRemoveAllRights() : %d", uniqueId); return DRM_NO_ERROR; } status_t DrmPassthruPlugIn::onOpenConvertSession(int uniqueId, int convertId) { - LOGD("DrmPassthruPlugIn::onOpenConvertSession() : %d", uniqueId); + ALOGD("DrmPassthruPlugIn::onOpenConvertSession() : %d", uniqueId); return DRM_NO_ERROR; } DrmConvertedStatus* DrmPassthruPlugIn::onConvertData( int uniqueId, int convertId, const DrmBuffer* inputData) { - LOGD("DrmPassthruPlugIn::onConvertData() : %d", uniqueId); + ALOGD("DrmPassthruPlugIn::onConvertData() : %d", uniqueId); DrmBuffer* convertedData = NULL; if (NULL != inputData && 0 < inputData->length) { @@ -229,13 +229,13 @@ DrmConvertedStatus* DrmPassthruPlugIn::onConvertData( } DrmConvertedStatus* DrmPassthruPlugIn::onCloseConvertSession(int uniqueId, int convertId) { - LOGD("DrmPassthruPlugIn::onCloseConvertSession() : %d", uniqueId); + ALOGD("DrmPassthruPlugIn::onCloseConvertSession() : %d", uniqueId); return new DrmConvertedStatus(DrmConvertedStatus::STATUS_OK, NULL, 0 /*offset*/); } status_t DrmPassthruPlugIn::onOpenDecryptSession( int uniqueId, DecryptHandle* decryptHandle, int fd, off64_t offset, off64_t length) { - LOGD("DrmPassthruPlugIn::onOpenDecryptSession() : %d", uniqueId); + ALOGD("DrmPassthruPlugIn::onOpenDecryptSession() : %d", uniqueId); #ifdef ENABLE_PASSTHRU_DECRYPTION decryptHandle->mimeType = String8("video/passthru"); @@ -254,7 +254,7 @@ status_t DrmPassthruPlugIn::onOpenDecryptSession( } status_t DrmPassthruPlugIn::onCloseDecryptSession(int uniqueId, DecryptHandle* decryptHandle) { - LOGD("DrmPassthruPlugIn::onCloseDecryptSession() : %d", uniqueId); + ALOGD("DrmPassthruPlugIn::onCloseDecryptSession() : %d", uniqueId); if (NULL != decryptHandle) { if (NULL != decryptHandle->decryptInfo) { delete decryptHandle->decryptInfo; decryptHandle->decryptInfo = NULL; @@ -266,13 +266,13 @@ status_t DrmPassthruPlugIn::onCloseDecryptSession(int uniqueId, DecryptHandle* d status_t DrmPassthruPlugIn::onInitializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo) { - LOGD("DrmPassthruPlugIn::onInitializeDecryptUnit() : %d", uniqueId); + ALOGD("DrmPassthruPlugIn::onInitializeDecryptUnit() : %d", uniqueId); return DRM_NO_ERROR; } status_t DrmPassthruPlugIn::onDecrypt(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) { - LOGD("DrmPassthruPlugIn::onDecrypt() : %d", uniqueId); + ALOGD("DrmPassthruPlugIn::onDecrypt() : %d", uniqueId); /** * As a workaround implementation passthru would copy the given * encrypted buffer as it is to decrypted buffer. Note, decBuffer @@ -287,13 +287,13 @@ status_t DrmPassthruPlugIn::onDecrypt(int uniqueId, DecryptHandle* decryptHandle status_t DrmPassthruPlugIn::onFinalizeDecryptUnit( int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) { - LOGD("DrmPassthruPlugIn::onFinalizeDecryptUnit() : %d", uniqueId); + ALOGD("DrmPassthruPlugIn::onFinalizeDecryptUnit() : %d", uniqueId); return DRM_NO_ERROR; } ssize_t DrmPassthruPlugIn::onPread(int uniqueId, DecryptHandle* decryptHandle, void* buffer, ssize_t numBytes, off64_t offset) { - LOGD("DrmPassthruPlugIn::onPread() : %d", uniqueId); + ALOGD("DrmPassthruPlugIn::onPread() : %d", uniqueId); return 0; } -- cgit v1.1 From 5ff1dd576bb93c45b44088a51544a18fc43ebf58 Mon Sep 17 00:00:00 2001 From: Steve Block Date: Thu, 5 Jan 2012 23:22:43 +0000 Subject: Rename (IF_)LOGW(_IF) to (IF_)ALOGW(_IF) DO NOT MERGE See https://android-git.corp.google.com/g/157065 Bug: 5449033 Change-Id: I00a4b904f9449e6f93b7fd35eac28640d7929e69 --- drm/libdrmframework/DrmManagerClientImpl.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drm') diff --git a/drm/libdrmframework/DrmManagerClientImpl.cpp b/drm/libdrmframework/DrmManagerClientImpl.cpp index 67f58ca..b222b8f 100644 --- a/drm/libdrmframework/DrmManagerClientImpl.cpp +++ b/drm/libdrmframework/DrmManagerClientImpl.cpp @@ -54,7 +54,7 @@ const sp& DrmManagerClientImpl::getDrmManagerService() { if (binder != 0) { break; } - LOGW("DrmManagerService not published, waiting..."); + ALOGW("DrmManagerService not published, waiting..."); struct timespec reqt; reqt.tv_sec = 0; reqt.tv_nsec = 500000000; //0.5 sec @@ -342,6 +342,6 @@ DrmManagerClientImpl::DeathNotifier::~DeathNotifier() { void DrmManagerClientImpl::DeathNotifier::binderDied(const wp& who) { Mutex::Autolock lock(sMutex); DrmManagerClientImpl::sDrmManagerService.clear(); - LOGW("DrmManager server died!"); + ALOGW("DrmManager server died!"); } -- cgit v1.1 From 29357bc2c0dd7c43ad3bd0c8e3efa4e6fd9bfd47 Mon Sep 17 00:00:00 2001 From: Steve Block Date: Fri, 6 Jan 2012 19:20:56 +0000 Subject: Rename (IF_)LOGE(_IF) to (IF_)ALOGE(_IF) DO NOT MERGE See https://android-git.corp.google.com/g/#/c/157220 Bug: 5449033 Change-Id: Ic9c19d30693bd56755f55906127cd6bd7126096c --- drm/common/ReadWriteUtils.cpp | 4 ++-- .../FwdLockEngine/src/FwdLockEngine.cpp | 22 +++++++++++----------- 2 files changed, 13 insertions(+), 13 deletions(-) (limited to 'drm') diff --git a/drm/common/ReadWriteUtils.cpp b/drm/common/ReadWriteUtils.cpp index c16214e..fd17e98 100644 --- a/drm/common/ReadWriteUtils.cpp +++ b/drm/common/ReadWriteUtils.cpp @@ -85,7 +85,7 @@ void ReadWriteUtils::writeToFile(const String8& filePath, const String8& data) { int size = data.size(); if (FAILURE != ftruncate(fd, size)) { if (size != write(fd, data.string(), size)) { - LOGE("Failed to write the data to: %s", filePath.string()); + ALOGE("Failed to write the data to: %s", filePath.string()); } } fclose(file); @@ -101,7 +101,7 @@ void ReadWriteUtils::appendToFile(const String8& filePath, const String8& data) int size = data.size(); if (size != write(fd, data.string(), size)) { - LOGE("Failed to write the data to: %s", filePath.string()); + ALOGE("Failed to write the data to: %s", filePath.string()); } fclose(file); } diff --git a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp index 7799040..0273a4b 100644 --- a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp +++ b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp @@ -92,12 +92,12 @@ int FwdLockEngine::getConvertedStatus(FwdLockConv_Status_t status) { case FwdLockConv_Status_InvalidArgument: case FwdLockConv_Status_UnsupportedFileFormat: case FwdLockConv_Status_UnsupportedContentTransferEncoding: - LOGE("FwdLockEngine getConvertedStatus: file conversion Error %d. " + ALOGE("FwdLockEngine getConvertedStatus: file conversion Error %d. " "Returning STATUS_INPUTDATA_ERROR", status); retStatus = DrmConvertedStatus::STATUS_INPUTDATA_ERROR; break; default: - LOGE("FwdLockEngine getConvertedStatus: file conversion Error %d. " + ALOGE("FwdLockEngine getConvertedStatus: file conversion Error %d. " "Returning STATUS_ERROR", status); retStatus = DrmConvertedStatus::STATUS_ERROR; break; @@ -139,7 +139,7 @@ android::status_t FwdLockEngine::onInitialize(int uniqueId) { if (FwdLockGlue_InitializeKeyEncryption()) { LOG_VERBOSE("FwdLockEngine::onInitialize -- FwdLockGlue_InitializeKeyEncryption succeeded"); } else { - LOGE("FwdLockEngine::onInitialize -- FwdLockGlue_InitializeKeyEncryption failed:" + ALOGE("FwdLockEngine::onInitialize -- FwdLockGlue_InitializeKeyEncryption failed:" "errno = %d", errno); } @@ -351,7 +351,7 @@ status_t FwdLockEngine::onOpenConvertSession(int uniqueId, convertSessionMap.addValue(convertId, newSession); result = DRM_NO_ERROR; } else { - LOGE("FwdLockEngine::onOpenConvertSession -- FwdLockConv_OpenSession failed."); + ALOGE("FwdLockEngine::onOpenConvertSession -- FwdLockConv_OpenSession failed."); delete newSession; } } @@ -448,7 +448,7 @@ status_t FwdLockEngine::onOpenDecryptSession(int uniqueId, (!decodeSessionMap.isCreated(decryptHandle->decryptId))) { fileDesc = dup(fd); } else { - LOGE("FwdLockEngine::onOpenDecryptSession parameter error"); + ALOGE("FwdLockEngine::onOpenDecryptSession parameter error"); return result; } @@ -550,13 +550,13 @@ status_t FwdLockEngine::onInitializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo) { - LOGE("FwdLockEngine::onInitializeDecryptUnit is not supported for this DRM scheme"); + ALOGE("FwdLockEngine::onInitializeDecryptUnit is not supported for this DRM scheme"); return DRM_ERROR_UNKNOWN; } status_t FwdLockEngine::onDecrypt(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) { - LOGE("FwdLockEngine::onDecrypt is not supported for this DRM scheme"); + ALOGE("FwdLockEngine::onDecrypt is not supported for this DRM scheme"); return DRM_ERROR_UNKNOWN; } @@ -565,14 +565,14 @@ status_t FwdLockEngine::onDecrypt(int uniqueId, int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer) { - LOGE("FwdLockEngine::onDecrypt is not supported for this DRM scheme"); + ALOGE("FwdLockEngine::onDecrypt is not supported for this DRM scheme"); return DRM_ERROR_UNKNOWN; } status_t FwdLockEngine::onFinalizeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) { - LOGE("FwdLockEngine::onFinalizeDecryptUnit is not supported for this DRM scheme"); + ALOGE("FwdLockEngine::onFinalizeDecryptUnit is not supported for this DRM scheme"); return DRM_ERROR_UNKNOWN; } @@ -650,11 +650,11 @@ ssize_t FwdLockEngine::onPread(int uniqueId, if (((off_t)-1) != decoderSession->offset) { bytesRead = onRead(uniqueId, decryptHandle, buffer, numBytes); if (bytesRead < 0) { - LOGE("FwdLockEngine::onPread error reading"); + ALOGE("FwdLockEngine::onPread error reading"); } } } else { - LOGE("FwdLockEngine::onPread decryptId not found"); + ALOGE("FwdLockEngine::onPread decryptId not found"); } return bytesRead; -- 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/common/DrmEngineBase.cpp | 18 ++++++-- drm/common/IDrmManagerService.cpp | 25 ++++++++--- drm/drmserver/DrmManager.cpp | 11 +++-- drm/drmserver/DrmManagerService.cpp | 8 ++-- drm/libdrmframework/DrmManagerClient.cpp | 14 ++++-- drm/libdrmframework/DrmManagerClientImpl.cpp | 12 +++-- drm/libdrmframework/include/DrmManager.h | 5 ++- drm/libdrmframework/include/DrmManagerClientImpl.h | 8 +++- drm/libdrmframework/include/DrmManagerService.h | 6 ++- drm/libdrmframework/include/IDrmManagerService.h | 14 ++++-- .../plugins/common/include/DrmEngineBase.h | 51 ++++++++++++++++++++-- .../plugins/common/include/IDrmEngine.h | 10 ++++- 12 files changed, 141 insertions(+), 41 deletions(-) (limited to 'drm') diff --git a/drm/common/DrmEngineBase.cpp b/drm/common/DrmEngineBase.cpp index 9b16c36..1c345a2 100644 --- a/drm/common/DrmEngineBase.cpp +++ b/drm/common/DrmEngineBase.cpp @@ -120,13 +120,23 @@ DrmSupportInfo* DrmEngineBase::getSupportInfo(int uniqueId) { } status_t DrmEngineBase::openDecryptSession( - int uniqueId, DecryptHandle* decryptHandle, int fd, off64_t offset, off64_t length) { - return onOpenDecryptSession(uniqueId, decryptHandle, fd, offset, length); + int uniqueId, DecryptHandle* decryptHandle, + int fd, off64_t offset, off64_t length, const char* mime) { + + if (!mime || mime[0] == '\0') { + return onOpenDecryptSession(uniqueId, decryptHandle, fd, offset, length); + } + + return onOpenDecryptSession(uniqueId, decryptHandle, fd, offset, length, mime); } status_t DrmEngineBase::openDecryptSession( - int uniqueId, DecryptHandle* decryptHandle, const char* uri) { - return onOpenDecryptSession(uniqueId, decryptHandle, uri); + int uniqueId, DecryptHandle* decryptHandle, + const char* uri, const char* mime) { + if (!mime || mime[0] == '\0') { + return onOpenDecryptSession(uniqueId, decryptHandle, uri); + } + return onOpenDecryptSession(uniqueId, decryptHandle, uri, mime); } status_t DrmEngineBase::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) { diff --git a/drm/common/IDrmManagerService.cpp b/drm/common/IDrmManagerService.cpp index 3ed8ade..43f64f2 100644 --- a/drm/common/IDrmManagerService.cpp +++ b/drm/common/IDrmManagerService.cpp @@ -600,7 +600,7 @@ status_t BpDrmManagerService::getAllSupportInfo( } DecryptHandle* BpDrmManagerService::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 BpDrmManagerService::openDecryptSession"); Parcel data, reply; @@ -609,6 +609,11 @@ DecryptHandle* BpDrmManagerService::openDecryptSession( data.writeFileDescriptor(fd); data.writeInt64(offset); data.writeInt64(length); + String8 mimeType; + if (mime) { + mimeType = mime; + } + data.writeString8(mimeType); remote()->transact(OPEN_DECRYPT_SESSION, data, &reply); @@ -620,13 +625,20 @@ DecryptHandle* BpDrmManagerService::openDecryptSession( return handle; } -DecryptHandle* BpDrmManagerService::openDecryptSession(int uniqueId, const char* uri) { - ALOGV("Entering BpDrmManagerService::openDecryptSession"); +DecryptHandle* BpDrmManagerService::openDecryptSession( + int uniqueId, const char* uri, const char* mime) { + + ALOGV("Entering BpDrmManagerService::openDecryptSession: mime=%s", mime? mime: "NULL"); Parcel data, reply; data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); data.writeInt32(uniqueId); data.writeString8(String8(uri)); + String8 mimeType; + if (mime) { + mimeType = mime; + } + data.writeString8(mimeType); remote()->transact(OPEN_DECRYPT_SESSION_FROM_URI, data, &reply); @@ -1265,8 +1277,10 @@ status_t BnDrmManagerService::onTransact( const off64_t offset = data.readInt64(); const off64_t length = data.readInt64(); + const String8 mime = data.readString8(); + DecryptHandle* handle - = openDecryptSession(uniqueId, fd, offset, length); + = openDecryptSession(uniqueId, fd, offset, length, mime.string()); if (NULL != handle) { writeDecryptHandleToParcelData(handle, reply); @@ -1283,8 +1297,9 @@ status_t BnDrmManagerService::onTransact( const int uniqueId = data.readInt32(); const String8 uri = data.readString8(); + const String8 mime = data.readString8(); - DecryptHandle* handle = openDecryptSession(uniqueId, uri.string()); + DecryptHandle* handle = openDecryptSession(uniqueId, uri.string(), mime.string()); if (NULL != handle) { writeDecryptHandleToParcelData(handle, reply); 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; diff --git a/drm/libdrmframework/DrmManagerClient.cpp b/drm/libdrmframework/DrmManagerClient.cpp index c9c0d57..8768c08 100644 --- a/drm/libdrmframework/DrmManagerClient.cpp +++ b/drm/libdrmframework/DrmManagerClient.cpp @@ -116,12 +116,18 @@ status_t DrmManagerClient::getAllSupportInfo(int* length, DrmSupportInfo** drmSu return mDrmManagerClientImpl->getAllSupportInfo(mUniqueId, length, drmSupportInfoArray); } -sp DrmManagerClient::openDecryptSession(int fd, off64_t offset, off64_t length) { - return mDrmManagerClientImpl->openDecryptSession(mUniqueId, fd, offset, length); +sp DrmManagerClient::openDecryptSession( + int fd, off64_t offset, off64_t length, const char* mime) { + + return mDrmManagerClientImpl->openDecryptSession( + mUniqueId, fd, offset, length, mime); } -sp DrmManagerClient::openDecryptSession(const char* uri) { - return mDrmManagerClientImpl->openDecryptSession(mUniqueId, uri); +sp DrmManagerClient::openDecryptSession( + const char* uri, const char* mime) { + + return mDrmManagerClientImpl->openDecryptSession( + mUniqueId, uri, mime); } status_t DrmManagerClient::closeDecryptSession(sp &decryptHandle) { diff --git a/drm/libdrmframework/DrmManagerClientImpl.cpp b/drm/libdrmframework/DrmManagerClientImpl.cpp index b222b8f..fb0439e 100644 --- a/drm/libdrmframework/DrmManagerClientImpl.cpp +++ b/drm/libdrmframework/DrmManagerClientImpl.cpp @@ -255,15 +255,19 @@ status_t DrmManagerClientImpl::getAllSupportInfo( } sp DrmManagerClientImpl::openDecryptSession( - int uniqueId, int fd, off64_t offset, off64_t length) { - return getDrmManagerService()->openDecryptSession(uniqueId, fd, offset, length); + int uniqueId, int fd, off64_t offset, + off64_t length, const char* mime) { + + return getDrmManagerService()->openDecryptSession( + uniqueId, fd, offset, length, mime); } sp DrmManagerClientImpl::openDecryptSession( - int uniqueId, const char* uri) { + int uniqueId, const char* uri, const char* mime) { + DecryptHandle* handle = NULL; if (NULL != uri) { - handle = getDrmManagerService()->openDecryptSession(uniqueId, uri); + handle = getDrmManagerService()->openDecryptSession(uniqueId, uri, mime); } return handle; } diff --git a/drm/libdrmframework/include/DrmManager.h b/drm/libdrmframework/include/DrmManager.h index ac2b946..c9167d4 100644 --- a/drm/libdrmframework/include/DrmManager.h +++ b/drm/libdrmframework/include/DrmManager.h @@ -111,9 +111,10 @@ public: status_t getAllSupportInfo(int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray); - DecryptHandle* openDecryptSession(int uniqueId, int fd, off64_t offset, off64_t length); + DecryptHandle* openDecryptSession( + int uniqueId, int fd, off64_t offset, off64_t length, const char* mime); - DecryptHandle* openDecryptSession(int uniqueId, const char* uri); + DecryptHandle* openDecryptSession(int uniqueId, const char* uri, const char* mime); status_t closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle); diff --git a/drm/libdrmframework/include/DrmManagerClientImpl.h b/drm/libdrmframework/include/DrmManagerClientImpl.h index e3338d9..2aa493f 100644 --- a/drm/libdrmframework/include/DrmManagerClientImpl.h +++ b/drm/libdrmframework/include/DrmManagerClientImpl.h @@ -300,20 +300,24 @@ public: * @param[in] fd File descriptor of the protected content to be decrypted * @param[in] offset Start position of the content * @param[in] length The length of the protected content + * @param[in] mime The mime type of the protected content if it is not NULL or empty * @return * Handle for the decryption session */ - sp openDecryptSession(int uniqueId, int fd, off64_t offset, off64_t length); + sp openDecryptSession( + int uniqueId, int fd, off64_t offset, off64_t length, const char* mime); /** * Open the decrypt session to decrypt the given protected content * * @param[in] uniqueId Unique identifier for a session * @param[in] uri Path of the protected content to be decrypted + * @param[in] mime The mime type of the protected content if it is not NULL or empty * @return * Handle for the decryption session */ - sp openDecryptSession(int uniqueId, const char* uri); + sp openDecryptSession( + int uniqueId, const char* uri, const char* mime); /** * Close the decrypt session for the given handle diff --git a/drm/libdrmframework/include/DrmManagerService.h b/drm/libdrmframework/include/DrmManagerService.h index 9cb5804..1a8c2ae 100644 --- a/drm/libdrmframework/include/DrmManagerService.h +++ b/drm/libdrmframework/include/DrmManagerService.h @@ -98,9 +98,11 @@ public: status_t getAllSupportInfo(int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray); - DecryptHandle* openDecryptSession(int uniqueId, int fd, off64_t offset, off64_t length); + DecryptHandle* openDecryptSession( + int uniqueId, int fd, off64_t offset, off64_t length, const char *mime); - DecryptHandle* openDecryptSession(int uniqueId, const char* uri); + DecryptHandle* openDecryptSession( + int uniqueId, const char* uri, const char* mime); status_t closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle); diff --git a/drm/libdrmframework/include/IDrmManagerService.h b/drm/libdrmframework/include/IDrmManagerService.h index b9618bb..a7d21c5 100644 --- a/drm/libdrmframework/include/IDrmManagerService.h +++ b/drm/libdrmframework/include/IDrmManagerService.h @@ -139,9 +139,12 @@ public: virtual status_t getAllSupportInfo( int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray) = 0; - virtual DecryptHandle* openDecryptSession(int uniqueId, int fd, off64_t offset, off64_t length) = 0; + virtual DecryptHandle* openDecryptSession( + int uniqueId, int fd, off64_t offset, + off64_t length, const char* mime) = 0; - virtual DecryptHandle* openDecryptSession(int uniqueId, const char* uri) = 0; + virtual DecryptHandle* openDecryptSession( + int uniqueId, const char* uri, const char* mime) = 0; virtual status_t closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) = 0; @@ -222,9 +225,12 @@ public: virtual status_t getAllSupportInfo( int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray); - virtual DecryptHandle* openDecryptSession(int uniqueId, int fd, off64_t offset, off64_t length); + virtual DecryptHandle* openDecryptSession( + int uniqueId, int fd, off64_t offset, off64_t length, + const char* mime); - virtual DecryptHandle* openDecryptSession(int uniqueId, const char* uri); + virtual DecryptHandle* openDecryptSession( + int uniqueId, const char* uri, const char* mime); virtual status_t closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle); diff --git a/drm/libdrmframework/plugins/common/include/DrmEngineBase.h b/drm/libdrmframework/plugins/common/include/DrmEngineBase.h index 4a5afcf..08f6e6d 100644 --- a/drm/libdrmframework/plugins/common/include/DrmEngineBase.h +++ b/drm/libdrmframework/plugins/common/include/DrmEngineBase.h @@ -80,10 +80,12 @@ public: DrmSupportInfo* getSupportInfo(int uniqueId); status_t openDecryptSession( - int uniqueId, DecryptHandle* decryptHandle, int fd, off64_t offset, off64_t length); + int uniqueId, DecryptHandle* decryptHandle, + int fd, off64_t offset, off64_t length, const char* mime); status_t openDecryptSession( - int uniqueId, DecryptHandle* decryptHandle, const char* uri); + int uniqueId, DecryptHandle* decryptHandle, + const char* uri, const char* mime); status_t closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle); @@ -375,7 +377,29 @@ protected: * DRM_ERROR_CANNOT_HANDLE for failure and DRM_NO_ERROR for success */ virtual status_t onOpenDecryptSession( - int uniqueId, DecryptHandle* decryptHandle, int fd, off64_t offset, off64_t length) = 0; + int uniqueId, DecryptHandle* decryptHandle, + int fd, off64_t offset, off64_t length) = 0; + + /** + * Open the decrypt session to decrypt the given protected content + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] decryptHandle Handle for the current decryption session + * @param[in] fd File descriptor of the protected content to be decrypted + * @param[in] offset Start position of the content + * @param[in] length The length of the protected content + * @param[in] mime Mime type of the protected content + * drm plugin may do some optimization since the mime type is known. + * @return + * DRM_ERROR_CANNOT_HANDLE for failure and DRM_NO_ERROR for success + */ + virtual status_t onOpenDecryptSession( + int uniqueId, DecryptHandle* decryptHandle, + int fd, off64_t offset, off64_t length, + const char* mime) { + + return DRM_ERROR_CANNOT_HANDLE; + } /** * Open the decrypt session to decrypt the given protected content @@ -387,7 +411,26 @@ protected: * DRM_ERROR_CANNOT_HANDLE for failure and DRM_NO_ERROR for success */ virtual status_t onOpenDecryptSession( - int uniqueId, DecryptHandle* decryptHandle, const char* uri) = 0; + int uniqueId, DecryptHandle* decryptHandle, + const char* uri) = 0; + + /** + * Open the decrypt session to decrypt the given protected content + * + * @param[in] uniqueId Unique identifier for a session + * @param[in] decryptHandle Handle for the current decryption session + * @param[in] uri Path of the protected content to be decrypted + * @param[in] mime Mime type of the protected content. The corresponding + * drm plugin may do some optimization since the mime type is known. + * @return + * DRM_ERROR_CANNOT_HANDLE for failure and DRM_NO_ERROR for success + */ + virtual status_t onOpenDecryptSession( + int uniqueId, DecryptHandle* decryptHandle, + const char* uri, const char* mime) { + + return DRM_ERROR_CANNOT_HANDLE; + } /** * Close the decrypt session for the given handle diff --git a/drm/libdrmframework/plugins/common/include/IDrmEngine.h b/drm/libdrmframework/plugins/common/include/IDrmEngine.h index 77460f6..dcf5977 100644 --- a/drm/libdrmframework/plugins/common/include/IDrmEngine.h +++ b/drm/libdrmframework/plugins/common/include/IDrmEngine.h @@ -320,11 +320,14 @@ public: * @param[in] fd File descriptor of the protected content to be decrypted * @param[in] offset Start position of the content * @param[in] length The length of the protected content + * @param[in] mime Mime type of the protected content if it is + * not NULL or empty * @return * DRM_ERROR_CANNOT_HANDLE for failure and DRM_NO_ERROR for success */ virtual status_t openDecryptSession( - int uniqueId, DecryptHandle* decryptHandle, int fd, off64_t offset, off64_t length) = 0; + int uniqueId, DecryptHandle* decryptHandle, + int fd, off64_t offset, off64_t length, const char* mime) = 0; /** * Open the decrypt session to decrypt the given protected content @@ -332,11 +335,14 @@ public: * @param[in] uniqueId Unique identifier for a session * @param[in] decryptHandle Handle for the current decryption session * @param[in] uri Path of the protected content to be decrypted + * @param[in] mime Mime type of the protected content if it is + * not NULL or empty * @return * DRM_ERROR_CANNOT_HANDLE for failure and DRM_NO_ERROR for success */ virtual status_t openDecryptSession( - int uniqueId, DecryptHandle* decryptHandle, const char* uri) = 0; + int uniqueId, DecryptHandle* decryptHandle, + const char* uri, const char* mime) = 0; /** * Close the decrypt session for the given handle -- 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') 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') 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 From 9c78e8681dafcdf265bc733875bad436ef9ec220 Mon Sep 17 00:00:00 2001 From: James Dong Date: Fri, 9 Mar 2012 13:05:17 -0800 Subject: Added an failure log message when the fwdlock engine fails to open a given file. Change-Id: I0e7f60b61f03fde046fc1ad668b28cdee635898b --- .../plugins/forward-lock/internal-format/decoder/FwdLockFile.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'drm') diff --git a/drm/libdrmframework/plugins/forward-lock/internal-format/decoder/FwdLockFile.c b/drm/libdrmframework/plugins/forward-lock/internal-format/decoder/FwdLockFile.c index dacf00e..365bdec 100644 --- a/drm/libdrmframework/plugins/forward-lock/internal-format/decoder/FwdLockFile.c +++ b/drm/libdrmframework/plugins/forward-lock/internal-format/decoder/FwdLockFile.c @@ -14,6 +14,7 @@ * limitations under the License. */ +#include #include #include #include @@ -107,6 +108,7 @@ static int FwdLockFile_AcquireSession(int fileDesc) { } pthread_mutex_unlock(&sessionAcquisitionMutex); if (i == MAX_NUM_SESSIONS) { + ALOGE("Too many sessions opened at the same time"); errno = ENFILE; } } @@ -293,7 +295,12 @@ int FwdLockFile_attach(int fileDesc) { int FwdLockFile_open(const char *pFilename) { int fileDesc = open(pFilename, O_RDONLY); - if (fileDesc >= 0 && FwdLockFile_attach(fileDesc) < 0) { + if (fileDesc < 0) { + ALOGE("failed to open file '%s': %s", pFilename, strerror(errno)); + return fileDesc; + } + + if (FwdLockFile_attach(fileDesc) < 0) { (void)close(fileDesc); fileDesc = -1; } -- cgit v1.1 From bd2f13ddbe7a9e7550205f6b53880329e09b9457 Mon Sep 17 00:00:00 2001 From: James Dong Date: Fri, 9 Mar 2012 17:33:42 -0800 Subject: Avoid checking supported mime types or file suffixes in multiple places Change-Id: I47d24070c7bda385cd1d7fa1f6a75dbb1f82b476 --- .../FwdLockEngine/include/FwdLockEngine.h | 8 +++ .../FwdLockEngine/include/FwdLockEngineConst.h | 37 ------------- .../FwdLockEngine/src/FwdLockEngine.cpp | 63 ++++++++++++++++------ 3 files changed, 55 insertions(+), 53 deletions(-) delete mode 100644 drm/libdrmframework/plugins/forward-lock/FwdLockEngine/include/FwdLockEngineConst.h (limited to 'drm') diff --git a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/include/FwdLockEngine.h b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/include/FwdLockEngine.h index 34804cf..c0e408e 100644 --- a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/include/FwdLockEngine.h +++ b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/include/FwdLockEngine.h @@ -499,6 +499,14 @@ ssize_t onPread(int uniqueId, private: + static const String8 Description; + static const String8 FileSuffixes[]; + static const String8 MimeTypes[]; + static bool IsFileSuffixSupported(const String8& suffix); + static bool IsMimeTypeSupported(const String8& mime); + static void AddSupportedMimeTypes(DrmSupportInfo *info); + static void AddSupportedFileSuffixes(DrmSupportInfo *info); + /** * Session Class for Forward Lock Conversion. An object of this class is created * for every conversion. diff --git a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/include/FwdLockEngineConst.h b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/include/FwdLockEngineConst.h deleted file mode 100644 index da95d60..0000000 --- a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/include/FwdLockEngineConst.h +++ /dev/null @@ -1,37 +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. - */ - -#ifndef __FWDLOCKENGINECONST_H__ -#define __FWDLOCKENGINECONST_H__ - -namespace android { - -/** - * Constants for forward Lock Engine used for exposing engine's capabilities. - */ -#define FWDLOCK_EXTENSION_FL ("FL") -#define FWDLOCK_DOTEXTENSION_FL (".fl") -#define FWDLOCK_MIMETYPE_FL ("application/x-android-drm-fl") - -#define FWDLOCK_EXTENSION_DM ("DM") -#define FWDLOCK_DOTEXTENSION_DM (".dm") -#define FWDLOCK_MIMETYPE_DM ("application/vnd.oma.drm.message") - -#define FWDLOCK_DESCRIPTION ("OMA V1 Forward Lock") - -}; - -#endif /* __FWDLOCKENGINECONST_H__ */ diff --git a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp index 0273a4b..5ee41e6 100644 --- a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp +++ b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp @@ -35,7 +35,6 @@ #include "FwdLockConv.h" #include "FwdLockFile.h" #include "FwdLockGlue.h" -#include "FwdLockEngineConst.h" #include "MimeTypeUtil.h" #undef LOG_TAG @@ -160,6 +159,48 @@ android::status_t FwdLockEngine::onTerminate(int uniqueId) { return DRM_NO_ERROR; } +const String8 FwdLockEngine::FileSuffixes[] = { + String8(".fl"), + String8(".dm"), +}; + +const String8 FwdLockEngine::MimeTypes[] = { + String8("application/x-android-drm-fl"), + String8("application/vnd.oma.drm.message"), +}; + +const String8 FwdLockEngine::Description("OMA V1 Forward Lock"); + +void FwdLockEngine::AddSupportedMimeTypes(DrmSupportInfo *info) { + for (size_t i = 0, n = sizeof(MimeTypes)/sizeof(MimeTypes[0]); i < n; ++i) { + info->addMimeType(MimeTypes[i]); + } +} + +void FwdLockEngine::AddSupportedFileSuffixes(DrmSupportInfo *info) { + for (size_t i = 0, n = sizeof(FileSuffixes)/sizeof(FileSuffixes[0]); i < n; ++i) { + info->addFileSuffix(FileSuffixes[i]); + } +} + +bool FwdLockEngine::IsMimeTypeSupported(const String8& mime) { + for (size_t i = 0, n = sizeof(MimeTypes)/sizeof(MimeTypes[0]); i < n; ++i) { + if (mime == MimeTypes[i]) { + return true; + } + } + return false; +} + +bool FwdLockEngine::IsFileSuffixSupported(const String8& suffix) { + for (size_t i = 0, n = sizeof(FileSuffixes)/sizeof(FileSuffixes[0]); i < n; ++i) { + if (suffix == FileSuffixes[i]) { + return true; + } + } + return false; +} + DrmSupportInfo* FwdLockEngine::onGetSupportInfo(int uniqueId) { DrmSupportInfo* pSupportInfo = new DrmSupportInfo(); @@ -167,12 +208,9 @@ DrmSupportInfo* FwdLockEngine::onGetSupportInfo(int uniqueId) { // fill all Forward Lock mimetypes and extensions if (NULL != pSupportInfo) { - pSupportInfo->addMimeType(String8(FWDLOCK_MIMETYPE_FL)); - pSupportInfo->addFileSuffix(String8(FWDLOCK_DOTEXTENSION_FL)); - pSupportInfo->addMimeType(String8(FWDLOCK_MIMETYPE_DM)); - pSupportInfo->addFileSuffix(String8(FWDLOCK_DOTEXTENSION_DM)); - - pSupportInfo->setDescription(String8(FWDLOCK_DESCRIPTION)); + AddSupportedMimeTypes(pSupportInfo); + AddSupportedFileSuffixes(pSupportInfo); + pSupportInfo->setDescription(Description); } return pSupportInfo; @@ -182,14 +220,8 @@ bool FwdLockEngine::onCanHandle(int uniqueId, const String8& path) { bool result = false; String8 extString = path.getPathExtension(); - extString.toLower(); - - if ((extString == String8(FWDLOCK_DOTEXTENSION_FL)) || - (extString == String8(FWDLOCK_DOTEXTENSION_DM))) { - result = true; - } - return result; + return IsFileSuffixSupported(extString); } DrmInfoStatus* FwdLockEngine::onProcessDrmInfo(int uniqueId, const DrmInfo* drmInfo) { @@ -308,8 +340,7 @@ int FwdLockEngine::onGetDrmObjectType(int uniqueId, * (regardless of the relation between them to make it compatible with other DRM Engines) */ if (((0 == path.length()) || onCanHandle(uniqueId, path)) && - ((0 == mimeType.length()) || ((mimeStr == String8(FWDLOCK_MIMETYPE_FL)) || - (mimeStr == String8(FWDLOCK_MIMETYPE_DM)))) && (mimeType != path) ) { + ((0 == mimeType.length()) || IsMimeTypeSupported(mimeType)) && (mimeType != path) ) { return DrmObjectType::CONTENT; } -- cgit v1.1 From ad6ec91c0bca37587e28bf72dfc38cde1b90544f Mon Sep 17 00:00:00 2001 From: James Dong Date: Mon, 12 Mar 2012 23:20:29 -0700 Subject: make sure that lower-case mime and file suffix is used to check against the supported ones Change-Id: I6a20832f6a2dfb8554dbddef0dee87cc21c05c80 --- .../forward-lock/FwdLockEngine/src/FwdLockEngine.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'drm') diff --git a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp index 5ee41e6..4b1b40e 100644 --- a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp +++ b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp @@ -159,11 +159,13 @@ android::status_t FwdLockEngine::onTerminate(int uniqueId) { return DRM_NO_ERROR; } +// make sure that lower-case letters are used. const String8 FwdLockEngine::FileSuffixes[] = { String8(".fl"), String8(".dm"), }; +// make sure that lower-case letters are used. const String8 FwdLockEngine::MimeTypes[] = { String8("application/x-android-drm-fl"), String8("application/vnd.oma.drm.message"), @@ -184,8 +186,10 @@ void FwdLockEngine::AddSupportedFileSuffixes(DrmSupportInfo *info) { } bool FwdLockEngine::IsMimeTypeSupported(const String8& mime) { + String8 tmp(mime); + tmp.toLower(); for (size_t i = 0, n = sizeof(MimeTypes)/sizeof(MimeTypes[0]); i < n; ++i) { - if (mime == MimeTypes[i]) { + if (tmp == MimeTypes[i]) { return true; } } @@ -193,8 +197,10 @@ bool FwdLockEngine::IsMimeTypeSupported(const String8& mime) { } bool FwdLockEngine::IsFileSuffixSupported(const String8& suffix) { + String8 tmp(suffix); + tmp.toLower(); for (size_t i = 0, n = sizeof(FileSuffixes)/sizeof(FileSuffixes[0]); i < n; ++i) { - if (suffix == FileSuffixes[i]) { + if (tmp == FileSuffixes[i]) { return true; } } @@ -220,7 +226,6 @@ bool FwdLockEngine::onCanHandle(int uniqueId, const String8& path) { bool result = false; String8 extString = path.getPathExtension(); - extString.toLower(); return IsFileSuffixSupported(extString); } @@ -331,8 +336,6 @@ int FwdLockEngine::onGetDrmObjectType(int uniqueId, LOG_VERBOSE("FwdLockEngine::onGetDrmObjectType"); - mimeStr.toLower(); - /* Checks whether * 1. path and mime type both are not empty strings (meaning unavailable) else content is unknown * 2. if one of them is empty string and if other is known then its a DRM Content Object. -- cgit v1.1 From 0a38af09ebbacdc9aa0d5ecb24e2f0484bf4f191 Mon Sep 17 00:00:00 2001 From: James Dong Date: Tue, 13 Mar 2012 18:54:16 -0700 Subject: Turned off log spamming from DrmPassthruPlugin Change-Id: I2cecdba49cf044d2aafd8aa404d27df311cad401 --- .../plugins/passthru/src/DrmPassthruPlugIn.cpp | 56 +++++++++++----------- 1 file changed, 28 insertions(+), 28 deletions(-) (limited to 'drm') diff --git a/drm/libdrmframework/plugins/passthru/src/DrmPassthruPlugIn.cpp b/drm/libdrmframework/plugins/passthru/src/DrmPassthruPlugIn.cpp index 0ffc0a7..33e723d 100644 --- a/drm/libdrmframework/plugins/passthru/src/DrmPassthruPlugIn.cpp +++ b/drm/libdrmframework/plugins/passthru/src/DrmPassthruPlugIn.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#define LOG_NDEBUG 0 +//#define LOG_NDEBUG 0 #define LOG_TAG "DrmPassthruPlugIn" #include @@ -58,7 +58,7 @@ DrmMetadata* DrmPassthruPlugIn::onGetMetadata(int uniqueId, const String8* path) DrmConstraints* DrmPassthruPlugIn::onGetConstraints( int uniqueId, const String8* path, int action) { - ALOGD("DrmPassthruPlugIn::onGetConstraints From Path: %d", uniqueId); + ALOGV("DrmPassthruPlugIn::onGetConstraints From Path: %d", uniqueId); DrmConstraints* drmConstraints = new DrmConstraints(); String8 value("dummy_available_time"); @@ -73,7 +73,7 @@ DrmConstraints* DrmPassthruPlugIn::onGetConstraints( } DrmInfoStatus* DrmPassthruPlugIn::onProcessDrmInfo(int uniqueId, const DrmInfo* drmInfo) { - ALOGD("DrmPassthruPlugIn::onProcessDrmInfo - Enter : %d", uniqueId); + ALOGV("DrmPassthruPlugIn::onProcessDrmInfo - Enter : %d", uniqueId); DrmInfoStatus* drmInfoStatus = NULL; if (NULL != drmInfo) { switch (drmInfo->getInfoType()) { @@ -102,28 +102,28 @@ DrmInfoStatus* DrmPassthruPlugIn::onProcessDrmInfo(int uniqueId, const DrmInfo* } } } - ALOGD("DrmPassthruPlugIn::onProcessDrmInfo - Exit"); + ALOGV("DrmPassthruPlugIn::onProcessDrmInfo - Exit"); return drmInfoStatus; } status_t DrmPassthruPlugIn::onSetOnInfoListener( int uniqueId, const IDrmEngine::OnInfoListener* infoListener) { - ALOGD("DrmPassthruPlugIn::onSetOnInfoListener : %d", uniqueId); + ALOGV("DrmPassthruPlugIn::onSetOnInfoListener : %d", uniqueId); return DRM_NO_ERROR; } status_t DrmPassthruPlugIn::onInitialize(int uniqueId) { - ALOGD("DrmPassthruPlugIn::onInitialize : %d", uniqueId); + ALOGV("DrmPassthruPlugIn::onInitialize : %d", uniqueId); return DRM_NO_ERROR; } status_t DrmPassthruPlugIn::onTerminate(int uniqueId) { - ALOGD("DrmPassthruPlugIn::onTerminate : %d", uniqueId); + ALOGV("DrmPassthruPlugIn::onTerminate : %d", uniqueId); return DRM_NO_ERROR; } DrmSupportInfo* DrmPassthruPlugIn::onGetSupportInfo(int uniqueId) { - ALOGD("DrmPassthruPlugIn::onGetSupportInfo : %d", uniqueId); + ALOGV("DrmPassthruPlugIn::onGetSupportInfo : %d", uniqueId); DrmSupportInfo* drmSupportInfo = new DrmSupportInfo(); // Add mimetype's drmSupportInfo->addMimeType(String8("application/vnd.passthru.drm")); @@ -136,12 +136,12 @@ DrmSupportInfo* DrmPassthruPlugIn::onGetSupportInfo(int uniqueId) { status_t DrmPassthruPlugIn::onSaveRights(int uniqueId, const DrmRights& drmRights, const String8& rightsPath, const String8& contentPath) { - ALOGD("DrmPassthruPlugIn::onSaveRights : %d", uniqueId); + ALOGV("DrmPassthruPlugIn::onSaveRights : %d", uniqueId); return DRM_NO_ERROR; } DrmInfo* DrmPassthruPlugIn::onAcquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest) { - ALOGD("DrmPassthruPlugIn::onAcquireDrmInfo : %d", uniqueId); + ALOGV("DrmPassthruPlugIn::onAcquireDrmInfo : %d", uniqueId); DrmInfo* drmInfo = NULL; if (NULL != drmInfoRequest) { @@ -157,65 +157,65 @@ DrmInfo* DrmPassthruPlugIn::onAcquireDrmInfo(int uniqueId, const DrmInfoRequest* } bool DrmPassthruPlugIn::onCanHandle(int uniqueId, const String8& path) { - ALOGD("DrmPassthruPlugIn::canHandle: %s ", path.string()); + ALOGV("DrmPassthruPlugIn::canHandle: %s ", path.string()); String8 extension = path.getPathExtension(); extension.toLower(); return (String8(".passthru") == extension); } String8 DrmPassthruPlugIn::onGetOriginalMimeType(int uniqueId, const String8& path) { - ALOGD("DrmPassthruPlugIn::onGetOriginalMimeType() : %d", uniqueId); + ALOGV("DrmPassthruPlugIn::onGetOriginalMimeType() : %d", uniqueId); return String8("video/passthru"); } int DrmPassthruPlugIn::onGetDrmObjectType( int uniqueId, const String8& path, const String8& mimeType) { - ALOGD("DrmPassthruPlugIn::onGetDrmObjectType() : %d", uniqueId); + ALOGV("DrmPassthruPlugIn::onGetDrmObjectType() : %d", uniqueId); return DrmObjectType::UNKNOWN; } int DrmPassthruPlugIn::onCheckRightsStatus(int uniqueId, const String8& path, int action) { - ALOGD("DrmPassthruPlugIn::onCheckRightsStatus() : %d", uniqueId); + ALOGV("DrmPassthruPlugIn::onCheckRightsStatus() : %d", uniqueId); int rightsStatus = RightsStatus::RIGHTS_VALID; return rightsStatus; } status_t DrmPassthruPlugIn::onConsumeRights(int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) { - ALOGD("DrmPassthruPlugIn::onConsumeRights() : %d", uniqueId); + ALOGV("DrmPassthruPlugIn::onConsumeRights() : %d", uniqueId); return DRM_NO_ERROR; } status_t DrmPassthruPlugIn::onSetPlaybackStatus(int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int64_t position) { - ALOGD("DrmPassthruPlugIn::onSetPlaybackStatus() : %d", uniqueId); + ALOGV("DrmPassthruPlugIn::onSetPlaybackStatus() : %d", uniqueId); return DRM_NO_ERROR; } bool DrmPassthruPlugIn::onValidateAction(int uniqueId, const String8& path, int action, const ActionDescription& description) { - ALOGD("DrmPassthruPlugIn::onValidateAction() : %d", uniqueId); + ALOGV("DrmPassthruPlugIn::onValidateAction() : %d", uniqueId); return true; } status_t DrmPassthruPlugIn::onRemoveRights(int uniqueId, const String8& path) { - ALOGD("DrmPassthruPlugIn::onRemoveRights() : %d", uniqueId); + ALOGV("DrmPassthruPlugIn::onRemoveRights() : %d", uniqueId); return DRM_NO_ERROR; } status_t DrmPassthruPlugIn::onRemoveAllRights(int uniqueId) { - ALOGD("DrmPassthruPlugIn::onRemoveAllRights() : %d", uniqueId); + ALOGV("DrmPassthruPlugIn::onRemoveAllRights() : %d", uniqueId); return DRM_NO_ERROR; } status_t DrmPassthruPlugIn::onOpenConvertSession(int uniqueId, int convertId) { - ALOGD("DrmPassthruPlugIn::onOpenConvertSession() : %d", uniqueId); + ALOGV("DrmPassthruPlugIn::onOpenConvertSession() : %d", uniqueId); return DRM_NO_ERROR; } DrmConvertedStatus* DrmPassthruPlugIn::onConvertData( int uniqueId, int convertId, const DrmBuffer* inputData) { - ALOGD("DrmPassthruPlugIn::onConvertData() : %d", uniqueId); + ALOGV("DrmPassthruPlugIn::onConvertData() : %d", uniqueId); DrmBuffer* convertedData = NULL; if (NULL != inputData && 0 < inputData->length) { @@ -229,13 +229,13 @@ DrmConvertedStatus* DrmPassthruPlugIn::onConvertData( } DrmConvertedStatus* DrmPassthruPlugIn::onCloseConvertSession(int uniqueId, int convertId) { - ALOGD("DrmPassthruPlugIn::onCloseConvertSession() : %d", uniqueId); + ALOGV("DrmPassthruPlugIn::onCloseConvertSession() : %d", uniqueId); return new DrmConvertedStatus(DrmConvertedStatus::STATUS_OK, NULL, 0 /*offset*/); } status_t DrmPassthruPlugIn::onOpenDecryptSession( int uniqueId, DecryptHandle* decryptHandle, int fd, off64_t offset, off64_t length) { - ALOGD("DrmPassthruPlugIn::onOpenDecryptSession() : %d", uniqueId); + ALOGV("DrmPassthruPlugIn::onOpenDecryptSession() : %d", uniqueId); #ifdef ENABLE_PASSTHRU_DECRYPTION decryptHandle->mimeType = String8("video/passthru"); @@ -254,7 +254,7 @@ status_t DrmPassthruPlugIn::onOpenDecryptSession( } status_t DrmPassthruPlugIn::onCloseDecryptSession(int uniqueId, DecryptHandle* decryptHandle) { - ALOGD("DrmPassthruPlugIn::onCloseDecryptSession() : %d", uniqueId); + ALOGV("DrmPassthruPlugIn::onCloseDecryptSession() : %d", uniqueId); if (NULL != decryptHandle) { if (NULL != decryptHandle->decryptInfo) { delete decryptHandle->decryptInfo; decryptHandle->decryptInfo = NULL; @@ -266,13 +266,13 @@ status_t DrmPassthruPlugIn::onCloseDecryptSession(int uniqueId, DecryptHandle* d status_t DrmPassthruPlugIn::onInitializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo) { - ALOGD("DrmPassthruPlugIn::onInitializeDecryptUnit() : %d", uniqueId); + ALOGV("DrmPassthruPlugIn::onInitializeDecryptUnit() : %d", uniqueId); return DRM_NO_ERROR; } status_t DrmPassthruPlugIn::onDecrypt(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) { - ALOGD("DrmPassthruPlugIn::onDecrypt() : %d", uniqueId); + ALOGV("DrmPassthruPlugIn::onDecrypt() : %d", uniqueId); /** * As a workaround implementation passthru would copy the given * encrypted buffer as it is to decrypted buffer. Note, decBuffer @@ -287,13 +287,13 @@ status_t DrmPassthruPlugIn::onDecrypt(int uniqueId, DecryptHandle* decryptHandle status_t DrmPassthruPlugIn::onFinalizeDecryptUnit( int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) { - ALOGD("DrmPassthruPlugIn::onFinalizeDecryptUnit() : %d", uniqueId); + ALOGV("DrmPassthruPlugIn::onFinalizeDecryptUnit() : %d", uniqueId); return DRM_NO_ERROR; } ssize_t DrmPassthruPlugIn::onPread(int uniqueId, DecryptHandle* decryptHandle, void* buffer, ssize_t numBytes, off64_t offset) { - ALOGD("DrmPassthruPlugIn::onPread() : %d", uniqueId); + ALOGV("DrmPassthruPlugIn::onPread() : %d", uniqueId); return 0; } -- cgit v1.1 From 35250664455c9642cc14d3831b663880637a7d70 Mon Sep 17 00:00:00 2001 From: James Dong Date: Tue, 13 Mar 2012 19:20:55 -0700 Subject: Fixed a buffer overflow bug in DrmPassthruPlugin Change-Id: I8df2a90409c9266a094a1a0904a5ff76ec483d16 --- drm/libdrmframework/plugins/passthru/src/DrmPassthruPlugIn.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'drm') diff --git a/drm/libdrmframework/plugins/passthru/src/DrmPassthruPlugIn.cpp b/drm/libdrmframework/plugins/passthru/src/DrmPassthruPlugIn.cpp index 0ffc0a7..77db32c 100644 --- a/drm/libdrmframework/plugins/passthru/src/DrmPassthruPlugIn.cpp +++ b/drm/libdrmframework/plugins/passthru/src/DrmPassthruPlugIn.cpp @@ -279,8 +279,14 @@ status_t DrmPassthruPlugIn::onDecrypt(int uniqueId, DecryptHandle* decryptHandle * memory has to be allocated by the caller. */ if (NULL != (*decBuffer) && 0 < (*decBuffer)->length) { - memcpy((*decBuffer)->data, encBuffer->data, encBuffer->length); - (*decBuffer)->length = encBuffer->length; + if ((*decBuffer)->length >= encBuffer->length) { + memcpy((*decBuffer)->data, encBuffer->data, encBuffer->length); + (*decBuffer)->length = encBuffer->length; + } else { + ALOGE("decBuffer size (%d) too small to hold %d bytes", + (*decBuffer)->length, encBuffer->length); + return DRM_ERROR_UNKNOWN; + } } return DRM_NO_ERROR; } -- cgit v1.1