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 | |
| 21 | #include <errno.h> |
| 22 | #include <utils/threads.h> |
| 23 | #include <binder/IServiceManager.h> |
| 24 | #include <sys/stat.h> |
| 25 | #include "DrmManagerService.h" |
| 26 | #include "DrmManager.h" |
| 27 | |
| 28 | using namespace android; |
| 29 | |
| 30 | #define SUCCESS 0 |
| 31 | #define DRM_DIRECTORY_PERMISSION 0700 |
Takeshi Aimi | dc549d6 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 32 | #define DRM_PLUGINS_ROOT "/data/drm/plugins" |
| 33 | #define DRM_PLUGINS_NATIVE "/data/drm/plugins/native" |
| 34 | #define DRM_PLUGINS_NATIVE_DATABASES "/data/drm/plugins/native/databases" |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 35 | |
| 36 | void DrmManagerService::instantiate() { |
| 37 | LOGV("instantiate"); |
| 38 | |
Takeshi Aimi | dc549d6 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 39 | int res = mkdir(DRM_PLUGINS_ROOT, DRM_DIRECTORY_PERMISSION); |
| 40 | if (SUCCESS == res || EEXIST == errno) { |
| 41 | res = mkdir(DRM_PLUGINS_NATIVE, DRM_DIRECTORY_PERMISSION); |
| 42 | if (SUCCESS == res || EEXIST == errno) { |
| 43 | res = mkdir(DRM_PLUGINS_NATIVE_DATABASES, DRM_DIRECTORY_PERMISSION); |
| 44 | if (SUCCESS == res || EEXIST == errno) { |
| 45 | defaultServiceManager() |
| 46 | ->addService(String16("drm.drmManager"), new DrmManagerService()); |
| 47 | } |
| 48 | } |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 49 | } |
| 50 | } |
| 51 | |
| 52 | DrmManagerService::DrmManagerService() { |
| 53 | LOGV("created"); |
| 54 | mDrmManager = NULL; |
| 55 | mDrmManager = new DrmManager(); |
| 56 | } |
| 57 | |
| 58 | DrmManagerService::~DrmManagerService() { |
| 59 | LOGV("Destroyed"); |
| 60 | delete mDrmManager; mDrmManager = NULL; |
| 61 | } |
| 62 | |
Takeshi Aimi | dc549d6 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 63 | int DrmManagerService::addUniqueId(int uniqueId) { |
| 64 | return mDrmManager->addUniqueId(uniqueId); |
| 65 | } |
| 66 | |
| 67 | void DrmManagerService::removeUniqueId(int uniqueId) { |
| 68 | mDrmManager->removeUniqueId(uniqueId); |
| 69 | } |
| 70 | |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 71 | status_t DrmManagerService::loadPlugIns(int uniqueId) { |
| 72 | LOGV("Entering load plugins"); |
| 73 | return mDrmManager->loadPlugIns(uniqueId); |
| 74 | } |
| 75 | |
| 76 | status_t DrmManagerService::loadPlugIns(int uniqueId, const String8& plugInDirPath) { |
| 77 | LOGV("Entering load plugins from path"); |
| 78 | return mDrmManager->loadPlugIns(uniqueId, plugInDirPath); |
| 79 | } |
| 80 | |
| 81 | status_t DrmManagerService::setDrmServiceListener( |
| 82 | int uniqueId, const sp<IDrmServiceListener>& drmServiceListener) { |
| 83 | LOGV("Entering setDrmServiceListener"); |
| 84 | mDrmManager->setDrmServiceListener(uniqueId, drmServiceListener); |
| 85 | return DRM_NO_ERROR; |
| 86 | } |
| 87 | |
| 88 | status_t DrmManagerService::unloadPlugIns(int uniqueId) { |
| 89 | LOGV("Entering unload plugins"); |
| 90 | return mDrmManager->unloadPlugIns(uniqueId); |
| 91 | } |
| 92 | |
| 93 | status_t DrmManagerService::installDrmEngine(int uniqueId, const String8& drmEngineFile) { |
| 94 | LOGV("Entering installDrmEngine"); |
| 95 | return mDrmManager->installDrmEngine(uniqueId, drmEngineFile); |
| 96 | } |
| 97 | |
| 98 | DrmConstraints* DrmManagerService::getConstraints( |
| 99 | int uniqueId, const String8* path, const int action) { |
| 100 | LOGV("Entering getConstraints from content"); |
| 101 | return mDrmManager->getConstraints(uniqueId, path, action); |
| 102 | } |
| 103 | |
| 104 | bool DrmManagerService::canHandle(int uniqueId, const String8& path, const String8& mimeType) { |
| 105 | LOGV("Entering canHandle"); |
| 106 | return mDrmManager->canHandle(uniqueId, path, mimeType); |
| 107 | } |
| 108 | |
| 109 | DrmInfoStatus* DrmManagerService::processDrmInfo(int uniqueId, const DrmInfo* drmInfo) { |
| 110 | LOGV("Entering processDrmInfo"); |
| 111 | return mDrmManager->processDrmInfo(uniqueId, drmInfo); |
| 112 | } |
| 113 | |
| 114 | DrmInfo* DrmManagerService::acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest) { |
| 115 | LOGV("Entering acquireDrmInfo"); |
| 116 | return mDrmManager->acquireDrmInfo(uniqueId, drmInfoRequest); |
| 117 | } |
| 118 | |
Takeshi Aimi | dc549d6 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 119 | status_t DrmManagerService::saveRights( |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 120 | int uniqueId, const DrmRights& drmRights, |
| 121 | const String8& rightsPath, const String8& contentPath) { |
| 122 | LOGV("Entering saveRights"); |
| 123 | return mDrmManager->saveRights(uniqueId, drmRights, rightsPath, contentPath); |
| 124 | } |
| 125 | |
| 126 | String8 DrmManagerService::getOriginalMimeType(int uniqueId, const String8& path) { |
| 127 | LOGV("Entering getOriginalMimeType"); |
| 128 | return mDrmManager->getOriginalMimeType(uniqueId, path); |
| 129 | } |
| 130 | |
| 131 | int DrmManagerService::getDrmObjectType( |
| 132 | int uniqueId, const String8& path, const String8& mimeType) { |
| 133 | LOGV("Entering getDrmObjectType"); |
| 134 | return mDrmManager->getDrmObjectType(uniqueId, path, mimeType); |
| 135 | } |
| 136 | |
| 137 | int DrmManagerService::checkRightsStatus( |
| 138 | int uniqueId, const String8& path, int action) { |
| 139 | LOGV("Entering checkRightsStatus"); |
| 140 | return mDrmManager->checkRightsStatus(uniqueId, path, action); |
| 141 | } |
| 142 | |
Takeshi Aimi | dc549d6 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 143 | status_t DrmManagerService::consumeRights( |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 144 | int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) { |
| 145 | LOGV("Entering consumeRights"); |
Takeshi Aimi | dc549d6 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 146 | return mDrmManager->consumeRights(uniqueId, decryptHandle, action, reserve); |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 147 | } |
| 148 | |
Takeshi Aimi | dc549d6 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 149 | status_t DrmManagerService::setPlaybackStatus( |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 150 | int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position) { |
| 151 | LOGV("Entering setPlaybackStatus"); |
Takeshi Aimi | dc549d6 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 152 | return mDrmManager->setPlaybackStatus(uniqueId, decryptHandle, playbackStatus, position); |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | bool DrmManagerService::validateAction( |
| 156 | int uniqueId, const String8& path, |
| 157 | int action, const ActionDescription& description) { |
| 158 | LOGV("Entering validateAction"); |
| 159 | return mDrmManager->validateAction(uniqueId, path, action, description); |
| 160 | } |
| 161 | |
Takeshi Aimi | dc549d6 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 162 | status_t DrmManagerService::removeRights(int uniqueId, const String8& path) { |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 163 | LOGV("Entering removeRights"); |
Takeshi Aimi | dc549d6 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 164 | return mDrmManager->removeRights(uniqueId, path); |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 165 | } |
| 166 | |
Takeshi Aimi | dc549d6 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 167 | status_t DrmManagerService::removeAllRights(int uniqueId) { |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 168 | LOGV("Entering removeAllRights"); |
Takeshi Aimi | dc549d6 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 169 | return mDrmManager->removeAllRights(uniqueId); |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | int DrmManagerService::openConvertSession(int uniqueId, const String8& mimeType) { |
| 173 | LOGV("Entering openConvertSession"); |
| 174 | return mDrmManager->openConvertSession(uniqueId, mimeType); |
| 175 | } |
| 176 | |
| 177 | DrmConvertedStatus* DrmManagerService::convertData( |
| 178 | int uniqueId, int convertId, const DrmBuffer* inputData) { |
| 179 | LOGV("Entering convertData"); |
| 180 | return mDrmManager->convertData(uniqueId, convertId, inputData); |
| 181 | } |
| 182 | |
| 183 | DrmConvertedStatus* DrmManagerService::closeConvertSession(int uniqueId, int convertId) { |
| 184 | LOGV("Entering closeConvertSession"); |
| 185 | return mDrmManager->closeConvertSession(uniqueId, convertId); |
| 186 | } |
| 187 | |
| 188 | status_t DrmManagerService::getAllSupportInfo( |
| 189 | int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray) { |
| 190 | LOGV("Entering getAllSupportInfo"); |
| 191 | return mDrmManager->getAllSupportInfo(uniqueId, length, drmSupportInfoArray); |
| 192 | } |
| 193 | |
| 194 | DecryptHandle* DrmManagerService::openDecryptSession( |
| 195 | int uniqueId, int fd, int offset, int length) { |
| 196 | LOGV("Entering DrmManagerService::openDecryptSession"); |
| 197 | return mDrmManager->openDecryptSession(uniqueId, fd, offset, length); |
| 198 | } |
| 199 | |
Takeshi Aimi | dc549d6 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 200 | status_t DrmManagerService::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) { |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 201 | LOGV("Entering closeDecryptSession"); |
Takeshi Aimi | dc549d6 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 202 | return mDrmManager->closeDecryptSession(uniqueId, decryptHandle); |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 203 | } |
| 204 | |
Takeshi Aimi | dc549d6 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 205 | status_t DrmManagerService::initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 206 | int decryptUnitId, const DrmBuffer* headerInfo) { |
| 207 | LOGV("Entering initializeDecryptUnit"); |
Takeshi Aimi | dc549d6 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 208 | return mDrmManager->initializeDecryptUnit(uniqueId,decryptHandle, decryptUnitId, headerInfo); |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | status_t DrmManagerService::decrypt( |
Takeshi Aimi | dc549d6 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 212 | int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, |
| 213 | const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) { |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 214 | LOGV("Entering decrypt"); |
Takeshi Aimi | dc549d6 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 215 | return mDrmManager->decrypt(uniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer, IV); |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 216 | } |
| 217 | |
Takeshi Aimi | dc549d6 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 218 | status_t DrmManagerService::finalizeDecryptUnit( |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 219 | int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) { |
| 220 | LOGV("Entering finalizeDecryptUnit"); |
Takeshi Aimi | dc549d6 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 221 | return mDrmManager->finalizeDecryptUnit(uniqueId, decryptHandle, decryptUnitId); |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | ssize_t DrmManagerService::pread(int uniqueId, DecryptHandle* decryptHandle, |
| 225 | void* buffer, ssize_t numBytes, off_t offset) { |
| 226 | LOGV("Entering pread"); |
| 227 | return mDrmManager->pread(uniqueId, decryptHandle, buffer, numBytes, offset); |
| 228 | } |
| 229 | |