DrmManagerService.cpp revision 3473846f64f5b28e1cbeb70ef5867073fc93159e
1/* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17//#define LOG_NDEBUG 0 18#define LOG_TAG "DrmManagerService(Native)" 19#include <utils/Log.h> 20 21#include <private/android_filesystem_config.h> 22 23#include <errno.h> 24#include <utils/threads.h> 25#include <binder/IServiceManager.h> 26#include <binder/IPCThreadState.h> 27#include <sys/stat.h> 28#include "DrmManagerService.h" 29#include "DrmManager.h" 30 31using namespace android; 32 33static Vector<uid_t> trustedUids; 34 35static bool isProtectedCallAllowed() { 36 // TODO 37 // Following implementation is just for reference. 38 // Each OEM manufacturer should implement/replace with their own solutions. 39 bool result = false; 40 41 IPCThreadState* ipcState = IPCThreadState::self(); 42 uid_t uid = ipcState->getCallingUid(); 43 44 for (unsigned int i = 0; i < trustedUids.size(); ++i) { 45 if (trustedUids[i] == uid) { 46 result = true; 47 break; 48 } 49 } 50 return result; 51} 52 53void DrmManagerService::instantiate() { 54 LOGV("instantiate"); 55 defaultServiceManager()->addService(String16("drm.drmManager"), new DrmManagerService()); 56 57 if (0 >= trustedUids.size()) { 58 // TODO 59 // Following implementation is just for reference. 60 // Each OEM manufacturer should implement/replace with their own solutions. 61 62 // Add trusted uids here 63 trustedUids.push(AID_MEDIA); 64 } 65} 66 67DrmManagerService::DrmManagerService() : 68 mDrmManager(NULL) { 69 LOGV("created"); 70 mDrmManager = new DrmManager(); 71 mDrmManager->loadPlugIns(); 72} 73 74DrmManagerService::~DrmManagerService() { 75 LOGV("Destroyed"); 76 mDrmManager->unloadPlugIns(); 77 delete mDrmManager; mDrmManager = NULL; 78} 79 80int DrmManagerService::addUniqueId(int uniqueId) { 81 return mDrmManager->addUniqueId(uniqueId); 82} 83 84void DrmManagerService::removeUniqueId(int uniqueId) { 85 mDrmManager->removeUniqueId(uniqueId); 86} 87 88void DrmManagerService::addClient(int uniqueId) { 89 mDrmManager->addClient(uniqueId); 90} 91 92void DrmManagerService::removeClient(int uniqueId) { 93 mDrmManager->removeClient(uniqueId); 94} 95 96status_t DrmManagerService::setDrmServiceListener( 97 int uniqueId, const sp<IDrmServiceListener>& drmServiceListener) { 98 LOGV("Entering setDrmServiceListener"); 99 mDrmManager->setDrmServiceListener(uniqueId, drmServiceListener); 100 return DRM_NO_ERROR; 101} 102 103status_t DrmManagerService::installDrmEngine(int uniqueId, const String8& drmEngineFile) { 104 LOGV("Entering installDrmEngine"); 105 return mDrmManager->installDrmEngine(uniqueId, drmEngineFile); 106} 107 108DrmConstraints* DrmManagerService::getConstraints( 109 int uniqueId, const String8* path, const int action) { 110 LOGV("Entering getConstraints from content"); 111 return mDrmManager->getConstraints(uniqueId, path, action); 112} 113 114DrmMetadata* DrmManagerService::getMetadata(int uniqueId, const String8* path) { 115 LOGV("Entering getMetadata from content"); 116 return mDrmManager->getMetadata(uniqueId, path); 117} 118 119bool DrmManagerService::canHandle(int uniqueId, const String8& path, const String8& mimeType) { 120 LOGV("Entering canHandle"); 121 return mDrmManager->canHandle(uniqueId, path, mimeType); 122} 123 124DrmInfoStatus* DrmManagerService::processDrmInfo(int uniqueId, const DrmInfo* drmInfo) { 125 LOGV("Entering processDrmInfo"); 126 return mDrmManager->processDrmInfo(uniqueId, drmInfo); 127} 128 129DrmInfo* DrmManagerService::acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest) { 130 LOGV("Entering acquireDrmInfo"); 131 return mDrmManager->acquireDrmInfo(uniqueId, drmInfoRequest); 132} 133 134status_t DrmManagerService::saveRights( 135 int uniqueId, const DrmRights& drmRights, 136 const String8& rightsPath, const String8& contentPath) { 137 LOGV("Entering saveRights"); 138 return mDrmManager->saveRights(uniqueId, drmRights, rightsPath, contentPath); 139} 140 141String8 DrmManagerService::getOriginalMimeType(int uniqueId, const String8& path) { 142 LOGV("Entering getOriginalMimeType"); 143 return mDrmManager->getOriginalMimeType(uniqueId, path); 144} 145 146int DrmManagerService::getDrmObjectType( 147 int uniqueId, const String8& path, const String8& mimeType) { 148 LOGV("Entering getDrmObjectType"); 149 return mDrmManager->getDrmObjectType(uniqueId, path, mimeType); 150} 151 152int DrmManagerService::checkRightsStatus( 153 int uniqueId, const String8& path, int action) { 154 LOGV("Entering checkRightsStatus"); 155 return mDrmManager->checkRightsStatus(uniqueId, path, action); 156} 157 158status_t DrmManagerService::consumeRights( 159 int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) { 160 LOGV("Entering consumeRights"); 161 return mDrmManager->consumeRights(uniqueId, decryptHandle, action, reserve); 162} 163 164status_t DrmManagerService::setPlaybackStatus( 165 int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position) { 166 LOGV("Entering setPlaybackStatus"); 167 return mDrmManager->setPlaybackStatus(uniqueId, decryptHandle, playbackStatus, position); 168} 169 170bool DrmManagerService::validateAction( 171 int uniqueId, const String8& path, 172 int action, const ActionDescription& description) { 173 LOGV("Entering validateAction"); 174 return mDrmManager->validateAction(uniqueId, path, action, description); 175} 176 177status_t DrmManagerService::removeRights(int uniqueId, const String8& path) { 178 LOGV("Entering removeRights"); 179 return mDrmManager->removeRights(uniqueId, path); 180} 181 182status_t DrmManagerService::removeAllRights(int uniqueId) { 183 LOGV("Entering removeAllRights"); 184 return mDrmManager->removeAllRights(uniqueId); 185} 186 187int DrmManagerService::openConvertSession(int uniqueId, const String8& mimeType) { 188 LOGV("Entering openConvertSession"); 189 return mDrmManager->openConvertSession(uniqueId, mimeType); 190} 191 192DrmConvertedStatus* DrmManagerService::convertData( 193 int uniqueId, int convertId, const DrmBuffer* inputData) { 194 LOGV("Entering convertData"); 195 return mDrmManager->convertData(uniqueId, convertId, inputData); 196} 197 198DrmConvertedStatus* DrmManagerService::closeConvertSession(int uniqueId, int convertId) { 199 LOGV("Entering closeConvertSession"); 200 return mDrmManager->closeConvertSession(uniqueId, convertId); 201} 202 203status_t DrmManagerService::getAllSupportInfo( 204 int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray) { 205 LOGV("Entering getAllSupportInfo"); 206 return mDrmManager->getAllSupportInfo(uniqueId, length, drmSupportInfoArray); 207} 208 209DecryptHandle* DrmManagerService::openDecryptSession( 210 int uniqueId, int fd, int offset, int length) { 211 LOGV("Entering DrmManagerService::openDecryptSession"); 212 if (isProtectedCallAllowed()) { 213 return mDrmManager->openDecryptSession(uniqueId, fd, offset, length); 214 } 215 216 return NULL; 217} 218 219DecryptHandle* DrmManagerService::openDecryptSession( 220 int uniqueId, const char* uri) { 221 LOGV("Entering DrmManagerService::openDecryptSession with uri"); 222 if (isProtectedCallAllowed()) { 223 return mDrmManager->openDecryptSession(uniqueId, uri); 224 } 225 226 return NULL; 227} 228 229status_t DrmManagerService::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) { 230 LOGV("Entering closeDecryptSession"); 231 return mDrmManager->closeDecryptSession(uniqueId, decryptHandle); 232} 233 234status_t DrmManagerService::initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, 235 int decryptUnitId, const DrmBuffer* headerInfo) { 236 LOGV("Entering initializeDecryptUnit"); 237 return mDrmManager->initializeDecryptUnit(uniqueId,decryptHandle, decryptUnitId, headerInfo); 238} 239 240status_t DrmManagerService::decrypt( 241 int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, 242 const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) { 243 LOGV("Entering decrypt"); 244 return mDrmManager->decrypt(uniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer, IV); 245} 246 247status_t DrmManagerService::finalizeDecryptUnit( 248 int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) { 249 LOGV("Entering finalizeDecryptUnit"); 250 return mDrmManager->finalizeDecryptUnit(uniqueId, decryptHandle, decryptUnitId); 251} 252 253ssize_t DrmManagerService::pread(int uniqueId, DecryptHandle* decryptHandle, 254 void* buffer, ssize_t numBytes, off_t offset) { 255 LOGV("Entering pread"); 256 return mDrmManager->pread(uniqueId, decryptHandle, buffer, numBytes, offset); 257} 258 259