aimitakeshi | 27ed8ad | 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 | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 17 | //#define LOG_NDEBUG 0 |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 18 | #define LOG_TAG "DrmManager(Native)" |
| 19 | #include "utils/Log.h" |
| 20 | |
| 21 | #include <utils/String8.h> |
| 22 | #include <drm/DrmInfo.h> |
| 23 | #include <drm/DrmInfoEvent.h> |
| 24 | #include <drm/DrmRights.h> |
| 25 | #include <drm/DrmConstraints.h> |
Takeshi Aimi | 3473846 | 2010-11-16 13:56:11 +0900 | [diff] [blame] | 26 | #include <drm/DrmMetadata.h> |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 27 | #include <drm/DrmInfoStatus.h> |
| 28 | #include <drm/DrmInfoRequest.h> |
| 29 | #include <drm/DrmSupportInfo.h> |
| 30 | #include <drm/DrmConvertedStatus.h> |
| 31 | #include <IDrmEngine.h> |
| 32 | |
| 33 | #include "DrmManager.h" |
| 34 | #include "ReadWriteUtils.h" |
| 35 | |
| 36 | #define DECRYPT_FILE_ERROR -1 |
| 37 | |
| 38 | using namespace android; |
| 39 | |
| 40 | const String8 DrmManager::EMPTY_STRING(""); |
| 41 | |
| 42 | DrmManager::DrmManager() : |
| 43 | mDecryptSessionId(0), |
| 44 | mConvertId(0) { |
| 45 | |
| 46 | } |
| 47 | |
| 48 | DrmManager::~DrmManager() { |
| 49 | |
| 50 | } |
| 51 | |
Gloria Wang | 8f00151 | 2011-07-21 15:10:22 -0700 | [diff] [blame] | 52 | int DrmManager::addUniqueId(bool isNative) { |
Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 53 | Mutex::Autolock _l(mLock); |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 54 | |
Gloria Wang | 8f00151 | 2011-07-21 15:10:22 -0700 | [diff] [blame] | 55 | int temp = 0; |
| 56 | bool foundUniqueId = false; |
| 57 | const int size = mUniqueIdVector.size(); |
| 58 | const int uniqueIdRange = 0xfff; |
| 59 | int maxLoopTimes = (uniqueIdRange - 1) / 2; |
| 60 | srand(time(NULL)); |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 61 | |
Gloria Wang | 8f00151 | 2011-07-21 15:10:22 -0700 | [diff] [blame] | 62 | while (!foundUniqueId) { |
| 63 | temp = rand() & uniqueIdRange; |
| 64 | |
| 65 | if (isNative) { |
| 66 | // set a flag to differentiate DrmManagerClient |
| 67 | // created from native side and java side |
| 68 | temp |= 0x1000; |
| 69 | } |
| 70 | |
| 71 | int index = 0; |
| 72 | for (; index < size; ++index) { |
| 73 | if (mUniqueIdVector.itemAt(index) == temp) { |
| 74 | foundUniqueId = false; |
| 75 | break; |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 76 | } |
| 77 | } |
Gloria Wang | 8f00151 | 2011-07-21 15:10:22 -0700 | [diff] [blame] | 78 | if (index == size) { |
| 79 | foundUniqueId = true; |
| 80 | } |
| 81 | |
| 82 | maxLoopTimes --; |
| 83 | LOG_FATAL_IF(maxLoopTimes <= 0, "cannot find an unique ID for this session"); |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 84 | } |
Gloria Wang | 8f00151 | 2011-07-21 15:10:22 -0700 | [diff] [blame] | 85 | |
| 86 | mUniqueIdVector.push(temp); |
| 87 | return temp; |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | void DrmManager::removeUniqueId(int uniqueId) { |
Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 91 | Mutex::Autolock _l(mLock); |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 92 | for (unsigned int i = 0; i < mUniqueIdVector.size(); i++) { |
| 93 | if (uniqueId == mUniqueIdVector.itemAt(i)) { |
| 94 | mUniqueIdVector.removeAt(i); |
| 95 | break; |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | |
Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 100 | status_t DrmManager::loadPlugIns() { |
Edwin Wong | 5f6f4e4 | 2011-09-21 19:18:30 -0700 | [diff] [blame] | 101 | |
| 102 | String8 vendorPluginDirPath("/vendor/lib/drm"); |
| 103 | loadPlugIns(vendorPluginDirPath); |
| 104 | |
James Dong | 785ee06 | 2011-12-14 10:57:05 -0800 | [diff] [blame] | 105 | String8 pluginDirPath("/system/lib/drm"); |
| 106 | loadPlugIns(pluginDirPath); |
Edwin Wong | 5f6f4e4 | 2011-09-21 19:18:30 -0700 | [diff] [blame] | 107 | return DRM_NO_ERROR; |
| 108 | |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 109 | } |
| 110 | |
Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 111 | status_t DrmManager::loadPlugIns(const String8& plugInDirPath) { |
Edwin Wong | 5f6f4e4 | 2011-09-21 19:18:30 -0700 | [diff] [blame] | 112 | mPlugInManager.loadPlugIns(plugInDirPath); |
| 113 | Vector<String8> plugInPathList = mPlugInManager.getPlugInIdList(); |
| 114 | for (unsigned int i = 0; i < plugInPathList.size(); ++i) { |
| 115 | String8 plugInPath = plugInPathList[i]; |
| 116 | DrmSupportInfo* info = mPlugInManager.getPlugIn(plugInPath).getSupportInfo(0); |
| 117 | if (NULL != info) { |
| 118 | if (mSupportInfoToPlugInIdMap.indexOfKey(*info) < 0) { |
Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 119 | mSupportInfoToPlugInIdMap.add(*info, plugInPath); |
| 120 | } |
Edwin Wong | 5f6f4e4 | 2011-09-21 19:18:30 -0700 | [diff] [blame] | 121 | delete info; |
Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 122 | } |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 123 | } |
Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 124 | return DRM_NO_ERROR; |
| 125 | } |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 126 | |
Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 127 | status_t DrmManager::unloadPlugIns() { |
Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 128 | Mutex::Autolock _l(mLock); |
Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 129 | mConvertSessionMap.clear(); |
| 130 | mDecryptSessionMap.clear(); |
| 131 | mPlugInManager.unloadPlugIns(); |
| 132 | mSupportInfoToPlugInIdMap.clear(); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 133 | return DRM_NO_ERROR; |
| 134 | } |
| 135 | |
| 136 | status_t DrmManager::setDrmServiceListener( |
| 137 | int uniqueId, const sp<IDrmServiceListener>& drmServiceListener) { |
Gloria Wang | 0e0a5f9 | 2011-03-11 14:07:21 -0800 | [diff] [blame] | 138 | Mutex::Autolock _l(mListenerLock); |
Takeshi Aimi | c618b5a | 2010-11-30 16:27:42 +0900 | [diff] [blame] | 139 | if (NULL != drmServiceListener.get()) { |
| 140 | mServiceListeners.add(uniqueId, drmServiceListener); |
| 141 | } else { |
| 142 | mServiceListeners.removeItem(uniqueId); |
| 143 | } |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 144 | return DRM_NO_ERROR; |
| 145 | } |
| 146 | |
Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 147 | void DrmManager::addClient(int uniqueId) { |
Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 148 | Mutex::Autolock _l(mLock); |
Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 149 | if (!mSupportInfoToPlugInIdMap.isEmpty()) { |
| 150 | Vector<String8> plugInIdList = mPlugInManager.getPlugInIdList(); |
| 151 | for (unsigned int index = 0; index < plugInIdList.size(); index++) { |
| 152 | IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInIdList.itemAt(index)); |
| 153 | rDrmEngine.initialize(uniqueId); |
| 154 | rDrmEngine.setOnInfoListener(uniqueId, this); |
| 155 | } |
| 156 | } |
| 157 | } |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 158 | |
Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 159 | void DrmManager::removeClient(int uniqueId) { |
Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 160 | Mutex::Autolock _l(mLock); |
Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 161 | Vector<String8> plugInIdList = mPlugInManager.getPlugInIdList(); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 162 | for (unsigned int index = 0; index < plugInIdList.size(); index++) { |
| 163 | IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInIdList.itemAt(index)); |
| 164 | rDrmEngine.terminate(uniqueId); |
| 165 | } |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | DrmConstraints* DrmManager::getConstraints(int uniqueId, const String8* path, const int action) { |
Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 169 | Mutex::Autolock _l(mLock); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 170 | const String8 plugInId = getSupportedPlugInIdFromPath(uniqueId, *path); |
| 171 | if (EMPTY_STRING != plugInId) { |
| 172 | IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); |
| 173 | return rDrmEngine.getConstraints(uniqueId, path, action); |
| 174 | } |
| 175 | return NULL; |
| 176 | } |
| 177 | |
Takeshi Aimi | 3473846 | 2010-11-16 13:56:11 +0900 | [diff] [blame] | 178 | DrmMetadata* DrmManager::getMetadata(int uniqueId, const String8* path) { |
Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 179 | Mutex::Autolock _l(mLock); |
Takeshi Aimi | 3473846 | 2010-11-16 13:56:11 +0900 | [diff] [blame] | 180 | const String8 plugInId = getSupportedPlugInIdFromPath(uniqueId, *path); |
| 181 | if (EMPTY_STRING != plugInId) { |
| 182 | IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); |
| 183 | return rDrmEngine.getMetadata(uniqueId, path); |
| 184 | } |
| 185 | return NULL; |
| 186 | } |
| 187 | |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 188 | status_t DrmManager::installDrmEngine(int uniqueId, const String8& absolutePath) { |
Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 189 | Mutex::Autolock _l(mLock); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 190 | mPlugInManager.loadPlugIn(absolutePath); |
| 191 | |
| 192 | IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(absolutePath); |
| 193 | rDrmEngine.initialize(uniqueId); |
| 194 | rDrmEngine.setOnInfoListener(uniqueId, this); |
| 195 | |
Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 196 | DrmSupportInfo* info = rDrmEngine.getSupportInfo(0); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 197 | mSupportInfoToPlugInIdMap.add(*info, absolutePath); |
James Dong | adfb559 | 2011-04-24 12:38:35 -0700 | [diff] [blame] | 198 | delete info; |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 199 | |
| 200 | return DRM_NO_ERROR; |
| 201 | } |
| 202 | |
| 203 | bool DrmManager::canHandle(int uniqueId, const String8& path, const String8& mimeType) { |
Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 204 | Mutex::Autolock _l(mLock); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 205 | const String8 plugInId = getSupportedPlugInId(mimeType); |
| 206 | bool result = (EMPTY_STRING != plugInId) ? true : false; |
| 207 | |
Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 208 | if (0 < path.length()) { |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 209 | if (result) { |
| 210 | IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); |
| 211 | result = rDrmEngine.canHandle(uniqueId, path); |
| 212 | } else { |
Gloria Wang | 7f89d09 | 2011-03-02 12:33:00 -0800 | [diff] [blame] | 213 | String8 extension = path.getPathExtension(); |
| 214 | if (String8("") != extension) { |
| 215 | result = canHandle(uniqueId, path); |
| 216 | } |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 217 | } |
| 218 | } |
| 219 | return result; |
| 220 | } |
| 221 | |
| 222 | DrmInfoStatus* DrmManager::processDrmInfo(int uniqueId, const DrmInfo* drmInfo) { |
Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 223 | Mutex::Autolock _l(mLock); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 224 | const String8 plugInId = getSupportedPlugInId(drmInfo->getMimeType()); |
| 225 | if (EMPTY_STRING != plugInId) { |
| 226 | IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); |
| 227 | return rDrmEngine.processDrmInfo(uniqueId, drmInfo); |
| 228 | } |
| 229 | return NULL; |
| 230 | } |
| 231 | |
| 232 | bool DrmManager::canHandle(int uniqueId, const String8& path) { |
| 233 | bool result = false; |
| 234 | Vector<String8> plugInPathList = mPlugInManager.getPlugInIdList(); |
| 235 | |
| 236 | for (unsigned int i = 0; i < plugInPathList.size(); ++i) { |
| 237 | IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInPathList[i]); |
| 238 | result = rDrmEngine.canHandle(uniqueId, path); |
| 239 | |
| 240 | if (result) { |
| 241 | break; |
| 242 | } |
| 243 | } |
| 244 | return result; |
| 245 | } |
| 246 | |
| 247 | DrmInfo* DrmManager::acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest) { |
Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 248 | Mutex::Autolock _l(mLock); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 249 | const String8 plugInId = getSupportedPlugInId(drmInfoRequest->getMimeType()); |
| 250 | if (EMPTY_STRING != plugInId) { |
| 251 | IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); |
| 252 | return rDrmEngine.acquireDrmInfo(uniqueId, drmInfoRequest); |
| 253 | } |
| 254 | return NULL; |
| 255 | } |
| 256 | |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 257 | status_t DrmManager::saveRights(int uniqueId, const DrmRights& drmRights, |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 258 | const String8& rightsPath, const String8& contentPath) { |
Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 259 | Mutex::Autolock _l(mLock); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 260 | const String8 plugInId = getSupportedPlugInId(drmRights.getMimeType()); |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 261 | status_t result = DRM_ERROR_UNKNOWN; |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 262 | if (EMPTY_STRING != plugInId) { |
| 263 | IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 264 | result = rDrmEngine.saveRights(uniqueId, drmRights, rightsPath, contentPath); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 265 | } |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 266 | return result; |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | String8 DrmManager::getOriginalMimeType(int uniqueId, const String8& path) { |
Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 270 | Mutex::Autolock _l(mLock); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 271 | const String8 plugInId = getSupportedPlugInIdFromPath(uniqueId, path); |
| 272 | if (EMPTY_STRING != plugInId) { |
| 273 | IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); |
| 274 | return rDrmEngine.getOriginalMimeType(uniqueId, path); |
| 275 | } |
| 276 | return EMPTY_STRING; |
| 277 | } |
| 278 | |
| 279 | int DrmManager::getDrmObjectType(int uniqueId, const String8& path, const String8& mimeType) { |
Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 280 | Mutex::Autolock _l(mLock); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 281 | const String8 plugInId = getSupportedPlugInId(uniqueId, path, mimeType); |
| 282 | if (EMPTY_STRING != plugInId) { |
| 283 | IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); |
| 284 | return rDrmEngine.getDrmObjectType(uniqueId, path, mimeType); |
| 285 | } |
| 286 | return DrmObjectType::UNKNOWN; |
| 287 | } |
| 288 | |
| 289 | int DrmManager::checkRightsStatus(int uniqueId, const String8& path, int action) { |
Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 290 | Mutex::Autolock _l(mLock); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 291 | const String8 plugInId = getSupportedPlugInIdFromPath(uniqueId, path); |
| 292 | if (EMPTY_STRING != plugInId) { |
| 293 | IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); |
| 294 | return rDrmEngine.checkRightsStatus(uniqueId, path, action); |
| 295 | } |
| 296 | return RightsStatus::RIGHTS_INVALID; |
| 297 | } |
| 298 | |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 299 | status_t DrmManager::consumeRights( |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 300 | int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) { |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 301 | status_t result = DRM_ERROR_UNKNOWN; |
Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 302 | Mutex::Autolock _l(mDecryptLock); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 303 | if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) { |
| 304 | IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId); |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 305 | result = drmEngine->consumeRights(uniqueId, decryptHandle, action, reserve); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 306 | } |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 307 | return result; |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 308 | } |
| 309 | |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 310 | status_t DrmManager::setPlaybackStatus( |
Gloria Wang | a2cd44c | 2010-11-19 15:19:36 -0800 | [diff] [blame] | 311 | int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int64_t position) { |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 312 | status_t result = DRM_ERROR_UNKNOWN; |
Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 313 | Mutex::Autolock _l(mDecryptLock); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 314 | if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) { |
| 315 | IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId); |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 316 | result = drmEngine->setPlaybackStatus(uniqueId, decryptHandle, playbackStatus, position); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 317 | } |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 318 | return result; |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | bool DrmManager::validateAction( |
| 322 | int uniqueId, const String8& path, int action, const ActionDescription& description) { |
Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 323 | Mutex::Autolock _l(mLock); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 324 | const String8 plugInId = getSupportedPlugInIdFromPath(uniqueId, path); |
| 325 | if (EMPTY_STRING != plugInId) { |
| 326 | IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); |
| 327 | return rDrmEngine.validateAction(uniqueId, path, action, description); |
| 328 | } |
| 329 | return false; |
| 330 | } |
| 331 | |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 332 | status_t DrmManager::removeRights(int uniqueId, const String8& path) { |
Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 333 | Mutex::Autolock _l(mLock); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 334 | const String8 plugInId = getSupportedPlugInIdFromPath(uniqueId, path); |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 335 | status_t result = DRM_ERROR_UNKNOWN; |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 336 | if (EMPTY_STRING != plugInId) { |
| 337 | IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 338 | result = rDrmEngine.removeRights(uniqueId, path); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 339 | } |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 340 | return result; |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 341 | } |
| 342 | |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 343 | status_t DrmManager::removeAllRights(int uniqueId) { |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 344 | Vector<String8> plugInIdList = mPlugInManager.getPlugInIdList(); |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 345 | status_t result = DRM_ERROR_UNKNOWN; |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 346 | for (unsigned int index = 0; index < plugInIdList.size(); index++) { |
| 347 | IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInIdList.itemAt(index)); |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 348 | result = rDrmEngine.removeAllRights(uniqueId); |
| 349 | if (DRM_NO_ERROR != result) { |
| 350 | break; |
| 351 | } |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 352 | } |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 353 | return result; |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | int DrmManager::openConvertSession(int uniqueId, const String8& mimeType) { |
Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 357 | Mutex::Autolock _l(mConvertLock); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 358 | int convertId = -1; |
| 359 | |
| 360 | const String8 plugInId = getSupportedPlugInId(mimeType); |
| 361 | if (EMPTY_STRING != plugInId) { |
| 362 | IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); |
| 363 | |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 364 | if (DRM_NO_ERROR == rDrmEngine.openConvertSession(uniqueId, mConvertId + 1)) { |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 365 | ++mConvertId; |
| 366 | convertId = mConvertId; |
| 367 | mConvertSessionMap.add(convertId, &rDrmEngine); |
| 368 | } |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 369 | } |
| 370 | return convertId; |
| 371 | } |
| 372 | |
| 373 | DrmConvertedStatus* DrmManager::convertData( |
| 374 | int uniqueId, int convertId, const DrmBuffer* inputData) { |
| 375 | DrmConvertedStatus *drmConvertedStatus = NULL; |
| 376 | |
Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 377 | Mutex::Autolock _l(mConvertLock); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 378 | if (mConvertSessionMap.indexOfKey(convertId) != NAME_NOT_FOUND) { |
| 379 | IDrmEngine* drmEngine = mConvertSessionMap.valueFor(convertId); |
| 380 | drmConvertedStatus = drmEngine->convertData(uniqueId, convertId, inputData); |
| 381 | } |
| 382 | return drmConvertedStatus; |
| 383 | } |
| 384 | |
| 385 | DrmConvertedStatus* DrmManager::closeConvertSession(int uniqueId, int convertId) { |
Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 386 | Mutex::Autolock _l(mConvertLock); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 387 | DrmConvertedStatus *drmConvertedStatus = NULL; |
| 388 | |
| 389 | if (mConvertSessionMap.indexOfKey(convertId) != NAME_NOT_FOUND) { |
| 390 | IDrmEngine* drmEngine = mConvertSessionMap.valueFor(convertId); |
| 391 | drmConvertedStatus = drmEngine->closeConvertSession(uniqueId, convertId); |
| 392 | mConvertSessionMap.removeItem(convertId); |
| 393 | } |
| 394 | return drmConvertedStatus; |
| 395 | } |
| 396 | |
| 397 | status_t DrmManager::getAllSupportInfo( |
| 398 | int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray) { |
Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 399 | Mutex::Autolock _l(mLock); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 400 | Vector<String8> plugInPathList = mPlugInManager.getPlugInIdList(); |
| 401 | int size = plugInPathList.size(); |
| 402 | int validPlugins = 0; |
| 403 | |
| 404 | if (0 < size) { |
| 405 | Vector<DrmSupportInfo> drmSupportInfoList; |
| 406 | |
| 407 | for (int i = 0; i < size; ++i) { |
| 408 | String8 plugInPath = plugInPathList[i]; |
| 409 | DrmSupportInfo* drmSupportInfo |
Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 410 | = mPlugInManager.getPlugIn(plugInPath).getSupportInfo(0); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 411 | if (NULL != drmSupportInfo) { |
| 412 | drmSupportInfoList.add(*drmSupportInfo); |
| 413 | delete drmSupportInfo; drmSupportInfo = NULL; |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | validPlugins = drmSupportInfoList.size(); |
| 418 | if (0 < validPlugins) { |
| 419 | *drmSupportInfoArray = new DrmSupportInfo[validPlugins]; |
| 420 | for (int i = 0; i < validPlugins; ++i) { |
| 421 | (*drmSupportInfoArray)[i] = drmSupportInfoList[i]; |
| 422 | } |
| 423 | } |
| 424 | } |
| 425 | *length = validPlugins; |
| 426 | return DRM_NO_ERROR; |
| 427 | } |
| 428 | |
James Dong | 9d2f386 | 2012-01-10 08:24:37 -0800 | [diff] [blame] | 429 | DecryptHandle* DrmManager::openDecryptSession( |
| 430 | int uniqueId, int fd, off64_t offset, off64_t length, const char* mime) { |
| 431 | |
Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 432 | Mutex::Autolock _l(mDecryptLock); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 433 | status_t result = DRM_ERROR_CANNOT_HANDLE; |
| 434 | Vector<String8> plugInIdList = mPlugInManager.getPlugInIdList(); |
| 435 | |
| 436 | DecryptHandle* handle = new DecryptHandle(); |
| 437 | if (NULL != handle) { |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 438 | handle->decryptId = mDecryptSessionId + 1; |
| 439 | |
| 440 | for (unsigned int index = 0; index < plugInIdList.size(); index++) { |
| 441 | String8 plugInId = plugInIdList.itemAt(index); |
| 442 | IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); |
James Dong | 9d2f386 | 2012-01-10 08:24:37 -0800 | [diff] [blame] | 443 | result = rDrmEngine.openDecryptSession(uniqueId, handle, fd, offset, length, mime); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 444 | |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 445 | if (DRM_NO_ERROR == result) { |
| 446 | ++mDecryptSessionId; |
| 447 | mDecryptSessionMap.add(mDecryptSessionId, &rDrmEngine); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 448 | break; |
| 449 | } |
| 450 | } |
| 451 | } |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 452 | if (DRM_NO_ERROR != result) { |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 453 | delete handle; handle = NULL; |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 454 | } |
Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 455 | return handle; |
| 456 | } |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 457 | |
James Dong | 9d2f386 | 2012-01-10 08:24:37 -0800 | [diff] [blame] | 458 | DecryptHandle* DrmManager::openDecryptSession( |
| 459 | int uniqueId, const char* uri, const char* mime) { |
Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 460 | Mutex::Autolock _l(mDecryptLock); |
| 461 | status_t result = DRM_ERROR_CANNOT_HANDLE; |
| 462 | Vector<String8> plugInIdList = mPlugInManager.getPlugInIdList(); |
| 463 | |
| 464 | DecryptHandle* handle = new DecryptHandle(); |
| 465 | if (NULL != handle) { |
| 466 | handle->decryptId = mDecryptSessionId + 1; |
| 467 | |
| 468 | for (unsigned int index = 0; index < plugInIdList.size(); index++) { |
| 469 | String8 plugInId = plugInIdList.itemAt(index); |
| 470 | IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); |
James Dong | 9d2f386 | 2012-01-10 08:24:37 -0800 | [diff] [blame] | 471 | result = rDrmEngine.openDecryptSession(uniqueId, handle, uri, mime); |
Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 472 | |
| 473 | if (DRM_NO_ERROR == result) { |
| 474 | ++mDecryptSessionId; |
| 475 | mDecryptSessionMap.add(mDecryptSessionId, &rDrmEngine); |
| 476 | break; |
| 477 | } |
| 478 | } |
| 479 | } |
| 480 | if (DRM_NO_ERROR != result) { |
| 481 | delete handle; handle = NULL; |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 482 | ALOGV("DrmManager::openDecryptSession: no capable plug-in found"); |
Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 483 | } |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 484 | return handle; |
| 485 | } |
| 486 | |
Kei Takahashi | cba7b32 | 2012-01-18 17:10:19 +0900 | [diff] [blame] | 487 | DecryptHandle* DrmManager::openDecryptSession( |
| 488 | int uniqueId, const DrmBuffer& buf, const String8& mimeType) { |
| 489 | Mutex::Autolock _l(mDecryptLock); |
| 490 | status_t result = DRM_ERROR_CANNOT_HANDLE; |
| 491 | Vector<String8> plugInIdList = mPlugInManager.getPlugInIdList(); |
| 492 | |
| 493 | DecryptHandle* handle = new DecryptHandle(); |
| 494 | if (NULL != handle) { |
| 495 | handle->decryptId = mDecryptSessionId + 1; |
| 496 | |
| 497 | for (size_t index = 0; index < plugInIdList.size(); index++) { |
| 498 | String8 plugInId = plugInIdList.itemAt(index); |
| 499 | IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); |
| 500 | result = rDrmEngine.openDecryptSession(uniqueId, handle, buf, mimeType); |
| 501 | |
| 502 | if (DRM_NO_ERROR == result) { |
| 503 | ++mDecryptSessionId; |
| 504 | mDecryptSessionMap.add(mDecryptSessionId, &rDrmEngine); |
| 505 | break; |
| 506 | } |
| 507 | } |
| 508 | } |
| 509 | if (DRM_NO_ERROR != result) { |
| 510 | delete handle; |
| 511 | handle = NULL; |
| 512 | ALOGV("DrmManager::openDecryptSession: no capable plug-in found"); |
| 513 | } |
| 514 | return handle; |
| 515 | } |
| 516 | |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 517 | status_t DrmManager::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) { |
Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 518 | Mutex::Autolock _l(mDecryptLock); |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 519 | status_t result = DRM_ERROR_UNKNOWN; |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 520 | if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) { |
| 521 | IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId); |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 522 | result = drmEngine->closeDecryptSession(uniqueId, decryptHandle); |
| 523 | if (DRM_NO_ERROR == result) { |
| 524 | mDecryptSessionMap.removeItem(decryptHandle->decryptId); |
| 525 | } |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 526 | } |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 527 | return result; |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 528 | } |
| 529 | |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 530 | status_t DrmManager::initializeDecryptUnit( |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 531 | int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo) { |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 532 | status_t result = DRM_ERROR_UNKNOWN; |
Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 533 | Mutex::Autolock _l(mDecryptLock); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 534 | if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) { |
| 535 | IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId); |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 536 | result = drmEngine->initializeDecryptUnit(uniqueId, decryptHandle, decryptUnitId, headerInfo); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 537 | } |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 538 | return result; |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 539 | } |
| 540 | |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 541 | status_t DrmManager::decrypt(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, |
| 542 | const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) { |
| 543 | status_t result = DRM_ERROR_UNKNOWN; |
Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 544 | |
| 545 | Mutex::Autolock _l(mDecryptLock); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 546 | if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) { |
| 547 | IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId); |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 548 | result = drmEngine->decrypt( |
| 549 | uniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer, IV); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 550 | } |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 551 | return result; |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 552 | } |
| 553 | |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 554 | status_t DrmManager::finalizeDecryptUnit( |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 555 | int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) { |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 556 | status_t result = DRM_ERROR_UNKNOWN; |
Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 557 | Mutex::Autolock _l(mDecryptLock); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 558 | if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) { |
| 559 | IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId); |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 560 | result = drmEngine->finalizeDecryptUnit(uniqueId, decryptHandle, decryptUnitId); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 561 | } |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 562 | return result; |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | ssize_t DrmManager::pread(int uniqueId, DecryptHandle* decryptHandle, |
Gloria Wang | a2cd44c | 2010-11-19 15:19:36 -0800 | [diff] [blame] | 566 | void* buffer, ssize_t numBytes, off64_t offset) { |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 567 | ssize_t result = DECRYPT_FILE_ERROR; |
| 568 | |
Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 569 | Mutex::Autolock _l(mDecryptLock); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 570 | if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) { |
| 571 | IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId); |
| 572 | result = drmEngine->pread(uniqueId, decryptHandle, buffer, numBytes, offset); |
| 573 | } |
| 574 | return result; |
| 575 | } |
| 576 | |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 577 | String8 DrmManager::getSupportedPlugInId( |
| 578 | int uniqueId, const String8& path, const String8& mimeType) { |
| 579 | String8 plugInId(""); |
| 580 | |
| 581 | if (EMPTY_STRING != mimeType) { |
| 582 | plugInId = getSupportedPlugInId(mimeType); |
| 583 | } else { |
| 584 | plugInId = getSupportedPlugInIdFromPath(uniqueId, path); |
| 585 | } |
| 586 | return plugInId; |
| 587 | } |
| 588 | |
| 589 | String8 DrmManager::getSupportedPlugInId(const String8& mimeType) { |
| 590 | String8 plugInId(""); |
| 591 | |
| 592 | if (EMPTY_STRING != mimeType) { |
| 593 | for (unsigned int index = 0; index < mSupportInfoToPlugInIdMap.size(); index++) { |
| 594 | const DrmSupportInfo& drmSupportInfo = mSupportInfoToPlugInIdMap.keyAt(index); |
| 595 | |
| 596 | if (drmSupportInfo.isSupportedMimeType(mimeType)) { |
| 597 | plugInId = mSupportInfoToPlugInIdMap.valueFor(drmSupportInfo); |
| 598 | break; |
| 599 | } |
| 600 | } |
| 601 | } |
| 602 | return plugInId; |
| 603 | } |
| 604 | |
| 605 | String8 DrmManager::getSupportedPlugInIdFromPath(int uniqueId, const String8& path) { |
| 606 | String8 plugInId(""); |
| 607 | const String8 fileSuffix = path.getPathExtension(); |
| 608 | |
| 609 | for (unsigned int index = 0; index < mSupportInfoToPlugInIdMap.size(); index++) { |
| 610 | const DrmSupportInfo& drmSupportInfo = mSupportInfoToPlugInIdMap.keyAt(index); |
| 611 | |
| 612 | if (drmSupportInfo.isSupportedFileSuffix(fileSuffix)) { |
| 613 | String8 key = mSupportInfoToPlugInIdMap.valueFor(drmSupportInfo); |
| 614 | IDrmEngine& drmEngine = mPlugInManager.getPlugIn(key); |
| 615 | |
| 616 | if (drmEngine.canHandle(uniqueId, path)) { |
| 617 | plugInId = key; |
| 618 | break; |
| 619 | } |
| 620 | } |
| 621 | } |
| 622 | return plugInId; |
| 623 | } |
| 624 | |
| 625 | void DrmManager::onInfo(const DrmInfoEvent& event) { |
Gloria Wang | 0e0a5f9 | 2011-03-11 14:07:21 -0800 | [diff] [blame] | 626 | Mutex::Autolock _l(mListenerLock); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 627 | for (unsigned int index = 0; index < mServiceListeners.size(); index++) { |
| 628 | int uniqueId = mServiceListeners.keyAt(index); |
| 629 | |
| 630 | if (uniqueId == event.getUniqueId()) { |
| 631 | sp<IDrmServiceListener> serviceListener = mServiceListeners.valueFor(uniqueId); |
| 632 | serviceListener->notify(event); |
| 633 | } |
| 634 | } |
| 635 | } |
| 636 | |