am 24a90c26: am d9334934: Merge "Update of DRM Framework."

* commit '24a90c2674270fee0783bafa54fd5d845bdf0c18':
  Update of DRM Framework.
This commit is contained in:
Gloria Wang
2010-11-22 21:29:08 -08:00
committed by Android Git Automerger
18 changed files with 433 additions and 2 deletions

View File

@@ -18,6 +18,7 @@ include $(CLEAR_VARS)
LOCAL_SRC_FILES:= \
DrmConstraints.cpp \
DrmMetadata.cpp \
DrmConvertedStatus.cpp \
DrmEngineBase.cpp \
DrmInfo.cpp \

View File

@@ -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);
}

117
drm/common/DrmMetadata.cpp Normal file
View File

@@ -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 <drm/DrmMetadata.h>
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;
}

View File

@@ -24,6 +24,7 @@
#include <drm/DrmInfo.h>
#include <drm/DrmConstraints.h>
#include <drm/DrmMetadata.h>
#include <drm/DrmRights.h>
#include <drm/DrmInfoStatus.h>
#include <drm/DrmConvertedStatus.h>
@@ -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;
@@ -825,6 +855,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");

View File

@@ -23,6 +23,7 @@
#include <drm/DrmInfoEvent.h>
#include <drm/DrmRights.h>
#include <drm/DrmConstraints.h>
#include <drm/DrmMetadata.h>
#include <drm/DrmInfoStatus.h>
#include <drm/DrmInfoRequest.h>
#include <drm/DrmSupportInfo.h>
@@ -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);

View File

@@ -18,18 +18,50 @@
#define LOG_TAG "DrmManagerService(Native)"
#include <utils/Log.h>
#include <private/android_filesystem_config.h>
#include <errno.h>
#include <utils/threads.h>
#include <binder/IServiceManager.h>
#include <binder/IPCThreadState.h>
#include <sys/stat.h>
#include "DrmManagerService.h"
#include "DrmManager.h"
using namespace android;
static Vector<uid_t> 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, off64_t offset, off64_t length) {
LOGV("Entering DrmManagerService::openDecryptSession");
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");
if (isProtectedCallAllowed()) {
return mDrmManager->openDecryptSession(uniqueId, uri);
}
return NULL;
}
status_t DrmManagerService::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) {

View File

@@ -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);
}

View File

@@ -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)) {

View File

@@ -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);

View File

@@ -85,6 +85,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
*

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);
@@ -116,6 +118,18 @@ protected:
virtual DrmConstraints* onGetConstraints(
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
*

View File

@@ -23,6 +23,7 @@ namespace android {
class DrmContentIds;
class DrmConstraints;
class DrmMetadata;
class DrmRights;
class DrmInfo;
class DrmInfoStatus;
@@ -104,6 +105,18 @@ public:
virtual DrmConstraints* getConstraints(
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
*

View File

@@ -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);

View File

@@ -20,6 +20,7 @@
#include <drm/DrmRights.h>
#include <drm/DrmConstraints.h>
#include <drm/DrmMetadata.h>
#include <drm/DrmInfo.h>
#include <drm/DrmInfoEvent.h>
#include <drm/DrmInfoStatus.h>
@@ -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);

View File

@@ -25,6 +25,7 @@ namespace android {
class DrmInfo;
class DrmRights;
class DrmMetadata;
class DrmInfoEvent;
class DrmInfoStatus;
class DrmInfoRequest;
@@ -203,6 +204,17 @@ public:
*/
DrmConstraints* getConstraints(const String8* path, const int action);
/**
* Get metadata information associated with input content
*
* @param[in] path Path of the protected content
* @return DrmMetadata
* key-value pairs of metadata
* @note
* In case of error, return NULL
*/
DrmMetadata* getMetadata(const String8* path);
/**
* Check whether the given mimetype or path can be handled
*

111
include/drm/DrmMetadata.h Normal file
View File

@@ -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.
*/
#ifndef __DRM_METADATA_H__
#define __DRM_METADATA_H__
#include "drm_framework_common.h"
namespace android {
/**
* This is an utility class which contains the constraints information.
*
* As a result of DrmManagerClient::getMetadata(const String8*)
* an instance of DrmMetadata would be returned.
*/
class DrmMetadata {
public:
/**
* Iterator for key
*/
class KeyIterator {
friend class DrmMetadata;
private:
KeyIterator(DrmMetadata* drmMetadata) : mDrmMetadata(drmMetadata), mIndex(0) {}
public:
KeyIterator(const KeyIterator& keyIterator);
KeyIterator& operator=(const KeyIterator& keyIterator);
virtual ~KeyIterator() {}
public:
bool hasNext();
const String8& next();
private:
DrmMetadata* mDrmMetadata;
unsigned int mIndex;
};
/**
* Iterator for constraints
*/
class Iterator {
friend class DrmMetadata;
private:
Iterator(DrmMetadata* drmMetadata) : mDrmMetadata(drmMetadata), mIndex(0) {}
public:
Iterator(const Iterator& iterator);
Iterator& operator=(const Iterator& iterator);
virtual ~Iterator() {}
public:
bool hasNext();
String8 next();
private:
DrmMetadata* mDrmMetadata;
unsigned int mIndex;
};
public:
DrmMetadata() {}
virtual ~DrmMetadata() {
DrmMetadata::KeyIterator keyIt = this->keyIterator();
while (keyIt.hasNext()) {
String8 key = keyIt.next();
const char* value = this->getAsByteArray(&key);
if (NULL != value) {
delete[] value;
value = NULL;
}
}
mMetadataMap.clear();
}
public:
int getCount(void) const;
status_t put(const String8* key, const char* value);
String8 get(const String8& key) const;
const char* getAsByteArray(const String8* key) const;
KeyIterator keyIterator();
Iterator iterator();
private:
const char* getValue(const String8* key) const;
private:
typedef KeyedVector<String8, const char*> DrmMetadataMap;
DrmMetadataMap mMetadataMap;
};
};
#endif /* __DRM_METADATA_H__ */