aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 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 | |
Takeshi Aimi | dc549d6 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 17 | //#define LOG_NDEBUG 0 |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 18 | #define LOG_TAG "DrmManagerService(Native)" |
| 19 | #include <utils/Log.h> |
| 20 | |
Takeshi Aimi | dc918656 | 2010-11-16 13:56:11 +0900 | [diff] [blame] | 21 | #include <private/android_filesystem_config.h> |
| 22 | |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 23 | #include <errno.h> |
| 24 | #include <utils/threads.h> |
| 25 | #include <binder/IServiceManager.h> |
Takeshi Aimi | dc918656 | 2010-11-16 13:56:11 +0900 | [diff] [blame] | 26 | #include <binder/IPCThreadState.h> |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 27 | #include <sys/stat.h> |
| 28 | #include "DrmManagerService.h" |
| 29 | #include "DrmManager.h" |
| 30 | |
| 31 | using namespace android; |
| 32 | |
Takeshi Aimi | dc918656 | 2010-11-16 13:56:11 +0900 | [diff] [blame] | 33 | static Vector<uid_t> trustedUids; |
| 34 | |
| 35 | static 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 | |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 53 | void DrmManagerService::instantiate() { |
| 54 | LOGV("instantiate"); |
Takeshi Aimi | c7b3ccc | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 55 | defaultServiceManager()->addService(String16("drm.drmManager"), new DrmManagerService()); |
Takeshi Aimi | dc918656 | 2010-11-16 13:56:11 +0900 | [diff] [blame] | 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 | } |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 65 | } |
| 66 | |
Takeshi Aimi | c7b3ccc | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 67 | DrmManagerService::DrmManagerService() : |
| 68 | mDrmManager(NULL) { |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 69 | LOGV("created"); |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 70 | mDrmManager = new DrmManager(); |
Takeshi Aimi | c7b3ccc | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 71 | mDrmManager->loadPlugIns(); |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | DrmManagerService::~DrmManagerService() { |
| 75 | LOGV("Destroyed"); |
Takeshi Aimi | c7b3ccc | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 76 | mDrmManager->unloadPlugIns(); |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 77 | delete mDrmManager; mDrmManager = NULL; |
| 78 | } |
| 79 | |
Takeshi Aimi | dc549d6 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 80 | int DrmManagerService::addUniqueId(int uniqueId) { |
| 81 | return mDrmManager->addUniqueId(uniqueId); |
| 82 | } |
| 83 | |
| 84 | void DrmManagerService::removeUniqueId(int uniqueId) { |
| 85 | mDrmManager->removeUniqueId(uniqueId); |
| 86 | } |
| 87 | |
Takeshi Aimi | c7b3ccc | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 88 | void DrmManagerService::addClient(int uniqueId) { |
| 89 | mDrmManager->addClient(uniqueId); |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 90 | } |
| 91 | |
Takeshi Aimi | c7b3ccc | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 92 | void DrmManagerService::removeClient(int uniqueId) { |
| 93 | mDrmManager->removeClient(uniqueId); |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | status_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 | |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 103 | status_t DrmManagerService::installDrmEngine(int uniqueId, const String8& drmEngineFile) { |
| 104 | LOGV("Entering installDrmEngine"); |
| 105 | return mDrmManager->installDrmEngine(uniqueId, drmEngineFile); |
| 106 | } |
| 107 | |
| 108 | DrmConstraints* 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 | |
Takeshi Aimi | dc918656 | 2010-11-16 13:56:11 +0900 | [diff] [blame] | 114 | DrmMetadata* DrmManagerService::getMetadata(int uniqueId, const String8* path) { |
| 115 | LOGV("Entering getMetadata from content"); |
| 116 | return mDrmManager->getMetadata(uniqueId, path); |
| 117 | } |
| 118 | |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 119 | bool DrmManagerService::canHandle(int uniqueId, const String8& path, const String8& mimeType) { |
| 120 | LOGV("Entering canHandle"); |
| 121 | return mDrmManager->canHandle(uniqueId, path, mimeType); |
| 122 | } |
| 123 | |
| 124 | DrmInfoStatus* DrmManagerService::processDrmInfo(int uniqueId, const DrmInfo* drmInfo) { |
| 125 | LOGV("Entering processDrmInfo"); |
| 126 | return mDrmManager->processDrmInfo(uniqueId, drmInfo); |
| 127 | } |
| 128 | |
| 129 | DrmInfo* DrmManagerService::acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest) { |
| 130 | LOGV("Entering acquireDrmInfo"); |
| 131 | return mDrmManager->acquireDrmInfo(uniqueId, drmInfoRequest); |
| 132 | } |
| 133 | |
Takeshi Aimi | dc549d6 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 134 | status_t DrmManagerService::saveRights( |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 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 | |
| 141 | String8 DrmManagerService::getOriginalMimeType(int uniqueId, const String8& path) { |
| 142 | LOGV("Entering getOriginalMimeType"); |
| 143 | return mDrmManager->getOriginalMimeType(uniqueId, path); |
| 144 | } |
| 145 | |
| 146 | int DrmManagerService::getDrmObjectType( |
| 147 | int uniqueId, const String8& path, const String8& mimeType) { |
| 148 | LOGV("Entering getDrmObjectType"); |
| 149 | return mDrmManager->getDrmObjectType(uniqueId, path, mimeType); |
| 150 | } |
| 151 | |
| 152 | int DrmManagerService::checkRightsStatus( |
| 153 | int uniqueId, const String8& path, int action) { |
| 154 | LOGV("Entering checkRightsStatus"); |
| 155 | return mDrmManager->checkRightsStatus(uniqueId, path, action); |
| 156 | } |
| 157 | |
Takeshi Aimi | dc549d6 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 158 | status_t DrmManagerService::consumeRights( |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 159 | int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) { |
| 160 | LOGV("Entering consumeRights"); |
Takeshi Aimi | dc549d6 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 161 | return mDrmManager->consumeRights(uniqueId, decryptHandle, action, reserve); |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 162 | } |
| 163 | |
Takeshi Aimi | dc549d6 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 164 | status_t DrmManagerService::setPlaybackStatus( |
Gloria Wang | 5fc3edb | 2010-11-19 15:19:36 -0800 | [diff] [blame] | 165 | int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int64_t position) { |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 166 | LOGV("Entering setPlaybackStatus"); |
Takeshi Aimi | dc549d6 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 167 | return mDrmManager->setPlaybackStatus(uniqueId, decryptHandle, playbackStatus, position); |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | bool 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 | |
Takeshi Aimi | dc549d6 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 177 | status_t DrmManagerService::removeRights(int uniqueId, const String8& path) { |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 178 | LOGV("Entering removeRights"); |
Takeshi Aimi | dc549d6 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 179 | return mDrmManager->removeRights(uniqueId, path); |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 180 | } |
| 181 | |
Takeshi Aimi | dc549d6 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 182 | status_t DrmManagerService::removeAllRights(int uniqueId) { |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 183 | LOGV("Entering removeAllRights"); |
Takeshi Aimi | dc549d6 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 184 | return mDrmManager->removeAllRights(uniqueId); |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | int DrmManagerService::openConvertSession(int uniqueId, const String8& mimeType) { |
| 188 | LOGV("Entering openConvertSession"); |
| 189 | return mDrmManager->openConvertSession(uniqueId, mimeType); |
| 190 | } |
| 191 | |
| 192 | DrmConvertedStatus* DrmManagerService::convertData( |
| 193 | int uniqueId, int convertId, const DrmBuffer* inputData) { |
| 194 | LOGV("Entering convertData"); |
| 195 | return mDrmManager->convertData(uniqueId, convertId, inputData); |
| 196 | } |
| 197 | |
| 198 | DrmConvertedStatus* DrmManagerService::closeConvertSession(int uniqueId, int convertId) { |
| 199 | LOGV("Entering closeConvertSession"); |
| 200 | return mDrmManager->closeConvertSession(uniqueId, convertId); |
| 201 | } |
| 202 | |
| 203 | status_t DrmManagerService::getAllSupportInfo( |
| 204 | int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray) { |
| 205 | LOGV("Entering getAllSupportInfo"); |
| 206 | return mDrmManager->getAllSupportInfo(uniqueId, length, drmSupportInfoArray); |
| 207 | } |
| 208 | |
| 209 | DecryptHandle* DrmManagerService::openDecryptSession( |
Gloria Wang | 5fc3edb | 2010-11-19 15:19:36 -0800 | [diff] [blame] | 210 | int uniqueId, int fd, off64_t offset, off64_t length) { |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 211 | LOGV("Entering DrmManagerService::openDecryptSession"); |
Takeshi Aimi | dc918656 | 2010-11-16 13:56:11 +0900 | [diff] [blame] | 212 | if (isProtectedCallAllowed()) { |
| 213 | return mDrmManager->openDecryptSession(uniqueId, fd, offset, length); |
| 214 | } |
| 215 | |
| 216 | return NULL; |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 217 | } |
| 218 | |
Takeshi Aimi | c7b3ccc | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 219 | DecryptHandle* DrmManagerService::openDecryptSession( |
| 220 | int uniqueId, const char* uri) { |
| 221 | LOGV("Entering DrmManagerService::openDecryptSession with uri"); |
Takeshi Aimi | dc918656 | 2010-11-16 13:56:11 +0900 | [diff] [blame] | 222 | if (isProtectedCallAllowed()) { |
| 223 | return mDrmManager->openDecryptSession(uniqueId, uri); |
| 224 | } |
| 225 | |
| 226 | return NULL; |
Takeshi Aimi | c7b3ccc | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 227 | } |
| 228 | |
Takeshi Aimi | dc549d6 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 229 | status_t DrmManagerService::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) { |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 230 | LOGV("Entering closeDecryptSession"); |
Takeshi Aimi | dc549d6 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 231 | return mDrmManager->closeDecryptSession(uniqueId, decryptHandle); |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 232 | } |
| 233 | |
Takeshi Aimi | dc549d6 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 234 | status_t DrmManagerService::initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 235 | int decryptUnitId, const DrmBuffer* headerInfo) { |
| 236 | LOGV("Entering initializeDecryptUnit"); |
Takeshi Aimi | dc549d6 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 237 | return mDrmManager->initializeDecryptUnit(uniqueId,decryptHandle, decryptUnitId, headerInfo); |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | status_t DrmManagerService::decrypt( |
Takeshi Aimi | dc549d6 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 241 | int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, |
| 242 | const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) { |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 243 | LOGV("Entering decrypt"); |
Takeshi Aimi | dc549d6 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 244 | return mDrmManager->decrypt(uniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer, IV); |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 245 | } |
| 246 | |
Takeshi Aimi | dc549d6 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 247 | status_t DrmManagerService::finalizeDecryptUnit( |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 248 | int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) { |
| 249 | LOGV("Entering finalizeDecryptUnit"); |
Takeshi Aimi | dc549d6 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 250 | return mDrmManager->finalizeDecryptUnit(uniqueId, decryptHandle, decryptUnitId); |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | ssize_t DrmManagerService::pread(int uniqueId, DecryptHandle* decryptHandle, |
Gloria Wang | 5fc3edb | 2010-11-19 15:19:36 -0800 | [diff] [blame] | 254 | void* buffer, ssize_t numBytes, off64_t offset) { |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 255 | LOGV("Entering pread"); |
| 256 | return mDrmManager->pread(uniqueId, decryptHandle, buffer, numBytes, offset); |
| 257 | } |
| 258 | |