| 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 | bool DrmManager::canHandle(int uniqueId, const String8& path, const String8& mimeType) { |
| 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 | const String8 plugInId = getSupportedPlugInId(mimeType); |
| 191 | bool result = (EMPTY_STRING != plugInId) ? true : false; |
| 192 | |
| Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 193 | if (0 < path.length()) { |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 194 | if (result) { |
| 195 | IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); |
| 196 | result = rDrmEngine.canHandle(uniqueId, path); |
| 197 | } else { |
| Gloria Wang | 7f89d09 | 2011-03-02 12:33:00 -0800 | [diff] [blame] | 198 | String8 extension = path.getPathExtension(); |
| 199 | if (String8("") != extension) { |
| 200 | result = canHandle(uniqueId, path); |
| 201 | } |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 202 | } |
| 203 | } |
| 204 | return result; |
| 205 | } |
| 206 | |
| 207 | DrmInfoStatus* DrmManager::processDrmInfo(int uniqueId, const DrmInfo* drmInfo) { |
| Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 208 | Mutex::Autolock _l(mLock); |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 209 | const String8 plugInId = getSupportedPlugInId(drmInfo->getMimeType()); |
| 210 | if (EMPTY_STRING != plugInId) { |
| 211 | IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); |
| 212 | return rDrmEngine.processDrmInfo(uniqueId, drmInfo); |
| 213 | } |
| 214 | return NULL; |
| 215 | } |
| 216 | |
| 217 | bool DrmManager::canHandle(int uniqueId, const String8& path) { |
| 218 | bool result = false; |
| 219 | Vector<String8> plugInPathList = mPlugInManager.getPlugInIdList(); |
| 220 | |
| 221 | for (unsigned int i = 0; i < plugInPathList.size(); ++i) { |
| 222 | IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInPathList[i]); |
| 223 | result = rDrmEngine.canHandle(uniqueId, path); |
| 224 | |
| 225 | if (result) { |
| 226 | break; |
| 227 | } |
| 228 | } |
| 229 | return result; |
| 230 | } |
| 231 | |
| 232 | DrmInfo* DrmManager::acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest) { |
| Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 233 | Mutex::Autolock _l(mLock); |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 234 | const String8 plugInId = getSupportedPlugInId(drmInfoRequest->getMimeType()); |
| 235 | if (EMPTY_STRING != plugInId) { |
| 236 | IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); |
| 237 | return rDrmEngine.acquireDrmInfo(uniqueId, drmInfoRequest); |
| 238 | } |
| 239 | return NULL; |
| 240 | } |
| 241 | |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 242 | status_t DrmManager::saveRights(int uniqueId, const DrmRights& drmRights, |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 243 | const String8& rightsPath, const String8& contentPath) { |
| Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 244 | Mutex::Autolock _l(mLock); |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 245 | const String8 plugInId = getSupportedPlugInId(drmRights.getMimeType()); |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 246 | status_t result = DRM_ERROR_UNKNOWN; |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 247 | if (EMPTY_STRING != plugInId) { |
| 248 | IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 249 | result = rDrmEngine.saveRights(uniqueId, drmRights, rightsPath, contentPath); |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 250 | } |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 251 | return result; |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | String8 DrmManager::getOriginalMimeType(int uniqueId, const String8& path) { |
| Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 255 | Mutex::Autolock _l(mLock); |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 256 | const String8 plugInId = getSupportedPlugInIdFromPath(uniqueId, path); |
| 257 | if (EMPTY_STRING != plugInId) { |
| 258 | IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); |
| 259 | return rDrmEngine.getOriginalMimeType(uniqueId, path); |
| 260 | } |
| 261 | return EMPTY_STRING; |
| 262 | } |
| 263 | |
| 264 | int DrmManager::getDrmObjectType(int uniqueId, const String8& path, const String8& mimeType) { |
| Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 265 | Mutex::Autolock _l(mLock); |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 266 | const String8 plugInId = getSupportedPlugInId(uniqueId, path, mimeType); |
| 267 | if (EMPTY_STRING != plugInId) { |
| 268 | IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); |
| 269 | return rDrmEngine.getDrmObjectType(uniqueId, path, mimeType); |
| 270 | } |
| 271 | return DrmObjectType::UNKNOWN; |
| 272 | } |
| 273 | |
| 274 | int DrmManager::checkRightsStatus(int uniqueId, const String8& path, int action) { |
| Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 275 | Mutex::Autolock _l(mLock); |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 276 | const String8 plugInId = getSupportedPlugInIdFromPath(uniqueId, path); |
| 277 | if (EMPTY_STRING != plugInId) { |
| 278 | IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); |
| 279 | return rDrmEngine.checkRightsStatus(uniqueId, path, action); |
| 280 | } |
| 281 | return RightsStatus::RIGHTS_INVALID; |
| 282 | } |
| 283 | |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 284 | status_t DrmManager::consumeRights( |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 285 | int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) { |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 286 | status_t result = DRM_ERROR_UNKNOWN; |
| Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 287 | Mutex::Autolock _l(mDecryptLock); |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 288 | if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) { |
| 289 | IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId); |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 290 | result = drmEngine->consumeRights(uniqueId, decryptHandle, action, reserve); |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 291 | } |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 292 | return result; |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 293 | } |
| 294 | |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 295 | status_t DrmManager::setPlaybackStatus( |
| Gloria Wang | a2cd44c | 2010-11-19 15:19:36 -0800 | [diff] [blame] | 296 | int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int64_t position) { |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 297 | status_t result = DRM_ERROR_UNKNOWN; |
| Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 298 | Mutex::Autolock _l(mDecryptLock); |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 299 | if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) { |
| 300 | IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId); |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 301 | result = drmEngine->setPlaybackStatus(uniqueId, decryptHandle, playbackStatus, position); |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 302 | } |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 303 | return result; |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | bool DrmManager::validateAction( |
| 307 | int uniqueId, const String8& path, int action, const ActionDescription& description) { |
| Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 308 | Mutex::Autolock _l(mLock); |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 309 | const String8 plugInId = getSupportedPlugInIdFromPath(uniqueId, path); |
| 310 | if (EMPTY_STRING != plugInId) { |
| 311 | IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); |
| 312 | return rDrmEngine.validateAction(uniqueId, path, action, description); |
| 313 | } |
| 314 | return false; |
| 315 | } |
| 316 | |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 317 | status_t DrmManager::removeRights(int uniqueId, const String8& path) { |
| Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 318 | Mutex::Autolock _l(mLock); |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 319 | const String8 plugInId = getSupportedPlugInIdFromPath(uniqueId, path); |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 320 | status_t result = DRM_ERROR_UNKNOWN; |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 321 | if (EMPTY_STRING != plugInId) { |
| 322 | IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 323 | result = rDrmEngine.removeRights(uniqueId, path); |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 324 | } |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 325 | return result; |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 326 | } |
| 327 | |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 328 | status_t DrmManager::removeAllRights(int uniqueId) { |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 329 | Vector<String8> plugInIdList = mPlugInManager.getPlugInIdList(); |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 330 | status_t result = DRM_ERROR_UNKNOWN; |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 331 | for (unsigned int index = 0; index < plugInIdList.size(); index++) { |
| 332 | IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInIdList.itemAt(index)); |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 333 | result = rDrmEngine.removeAllRights(uniqueId); |
| 334 | if (DRM_NO_ERROR != result) { |
| 335 | break; |
| 336 | } |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 337 | } |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 338 | return result; |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | int DrmManager::openConvertSession(int uniqueId, const String8& mimeType) { |
| Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 342 | Mutex::Autolock _l(mConvertLock); |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 343 | int convertId = -1; |
| 344 | |
| 345 | const String8 plugInId = getSupportedPlugInId(mimeType); |
| 346 | if (EMPTY_STRING != plugInId) { |
| 347 | IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); |
| 348 | |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 349 | if (DRM_NO_ERROR == rDrmEngine.openConvertSession(uniqueId, mConvertId + 1)) { |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 350 | ++mConvertId; |
| 351 | convertId = mConvertId; |
| 352 | mConvertSessionMap.add(convertId, &rDrmEngine); |
| 353 | } |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 354 | } |
| 355 | return convertId; |
| 356 | } |
| 357 | |
| 358 | DrmConvertedStatus* DrmManager::convertData( |
| 359 | int uniqueId, int convertId, const DrmBuffer* inputData) { |
| 360 | DrmConvertedStatus *drmConvertedStatus = NULL; |
| 361 | |
| Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 362 | Mutex::Autolock _l(mConvertLock); |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 363 | if (mConvertSessionMap.indexOfKey(convertId) != NAME_NOT_FOUND) { |
| 364 | IDrmEngine* drmEngine = mConvertSessionMap.valueFor(convertId); |
| 365 | drmConvertedStatus = drmEngine->convertData(uniqueId, convertId, inputData); |
| 366 | } |
| 367 | return drmConvertedStatus; |
| 368 | } |
| 369 | |
| 370 | DrmConvertedStatus* DrmManager::closeConvertSession(int uniqueId, int convertId) { |
| Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 371 | Mutex::Autolock _l(mConvertLock); |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 372 | DrmConvertedStatus *drmConvertedStatus = NULL; |
| 373 | |
| 374 | if (mConvertSessionMap.indexOfKey(convertId) != NAME_NOT_FOUND) { |
| 375 | IDrmEngine* drmEngine = mConvertSessionMap.valueFor(convertId); |
| 376 | drmConvertedStatus = drmEngine->closeConvertSession(uniqueId, convertId); |
| 377 | mConvertSessionMap.removeItem(convertId); |
| 378 | } |
| 379 | return drmConvertedStatus; |
| 380 | } |
| 381 | |
| 382 | status_t DrmManager::getAllSupportInfo( |
| 383 | int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray) { |
| Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 384 | Mutex::Autolock _l(mLock); |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 385 | Vector<String8> plugInPathList = mPlugInManager.getPlugInIdList(); |
| 386 | int size = plugInPathList.size(); |
| 387 | int validPlugins = 0; |
| 388 | |
| 389 | if (0 < size) { |
| 390 | Vector<DrmSupportInfo> drmSupportInfoList; |
| 391 | |
| 392 | for (int i = 0; i < size; ++i) { |
| 393 | String8 plugInPath = plugInPathList[i]; |
| 394 | DrmSupportInfo* drmSupportInfo |
| Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 395 | = mPlugInManager.getPlugIn(plugInPath).getSupportInfo(0); |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 396 | if (NULL != drmSupportInfo) { |
| 397 | drmSupportInfoList.add(*drmSupportInfo); |
| 398 | delete drmSupportInfo; drmSupportInfo = NULL; |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | validPlugins = drmSupportInfoList.size(); |
| 403 | if (0 < validPlugins) { |
| 404 | *drmSupportInfoArray = new DrmSupportInfo[validPlugins]; |
| 405 | for (int i = 0; i < validPlugins; ++i) { |
| 406 | (*drmSupportInfoArray)[i] = drmSupportInfoList[i]; |
| 407 | } |
| 408 | } |
| 409 | } |
| 410 | *length = validPlugins; |
| 411 | return DRM_NO_ERROR; |
| 412 | } |
| 413 | |
| James Dong | 9d2f386 | 2012-01-10 08:24:37 -0800 | [diff] [blame] | 414 | DecryptHandle* DrmManager::openDecryptSession( |
| 415 | int uniqueId, int fd, off64_t offset, off64_t length, const char* mime) { |
| 416 | |
| Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 417 | Mutex::Autolock _l(mDecryptLock); |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 418 | status_t result = DRM_ERROR_CANNOT_HANDLE; |
| 419 | Vector<String8> plugInIdList = mPlugInManager.getPlugInIdList(); |
| 420 | |
| 421 | DecryptHandle* handle = new DecryptHandle(); |
| 422 | if (NULL != handle) { |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 423 | handle->decryptId = mDecryptSessionId + 1; |
| 424 | |
| 425 | for (unsigned int index = 0; index < plugInIdList.size(); index++) { |
| 426 | String8 plugInId = plugInIdList.itemAt(index); |
| 427 | IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); |
| James Dong | 9d2f386 | 2012-01-10 08:24:37 -0800 | [diff] [blame] | 428 | result = rDrmEngine.openDecryptSession(uniqueId, handle, fd, offset, length, mime); |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 429 | |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 430 | if (DRM_NO_ERROR == result) { |
| 431 | ++mDecryptSessionId; |
| 432 | mDecryptSessionMap.add(mDecryptSessionId, &rDrmEngine); |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 433 | break; |
| 434 | } |
| 435 | } |
| 436 | } |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 437 | if (DRM_NO_ERROR != result) { |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 438 | delete handle; handle = NULL; |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 439 | } |
| Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 440 | return handle; |
| 441 | } |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 442 | |
| James Dong | 9d2f386 | 2012-01-10 08:24:37 -0800 | [diff] [blame] | 443 | DecryptHandle* DrmManager::openDecryptSession( |
| 444 | int uniqueId, const char* uri, const char* mime) { |
| Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 445 | Mutex::Autolock _l(mDecryptLock); |
| 446 | status_t result = DRM_ERROR_CANNOT_HANDLE; |
| 447 | Vector<String8> plugInIdList = mPlugInManager.getPlugInIdList(); |
| 448 | |
| 449 | DecryptHandle* handle = new DecryptHandle(); |
| 450 | if (NULL != handle) { |
| 451 | handle->decryptId = mDecryptSessionId + 1; |
| 452 | |
| 453 | for (unsigned int index = 0; index < plugInIdList.size(); index++) { |
| 454 | String8 plugInId = plugInIdList.itemAt(index); |
| 455 | IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); |
| James Dong | 9d2f386 | 2012-01-10 08:24:37 -0800 | [diff] [blame] | 456 | result = rDrmEngine.openDecryptSession(uniqueId, handle, uri, mime); |
| Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 457 | |
| 458 | if (DRM_NO_ERROR == result) { |
| 459 | ++mDecryptSessionId; |
| 460 | mDecryptSessionMap.add(mDecryptSessionId, &rDrmEngine); |
| 461 | break; |
| 462 | } |
| 463 | } |
| 464 | } |
| 465 | if (DRM_NO_ERROR != result) { |
| 466 | delete handle; handle = NULL; |
| Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 467 | ALOGV("DrmManager::openDecryptSession: no capable plug-in found"); |
| Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 468 | } |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 469 | return handle; |
| 470 | } |
| 471 | |
| Kei Takahashi | cba7b32 | 2012-01-18 17:10:19 +0900 | [diff] [blame] | 472 | DecryptHandle* DrmManager::openDecryptSession( |
| 473 | int uniqueId, const DrmBuffer& buf, const String8& mimeType) { |
| 474 | Mutex::Autolock _l(mDecryptLock); |
| 475 | status_t result = DRM_ERROR_CANNOT_HANDLE; |
| 476 | Vector<String8> plugInIdList = mPlugInManager.getPlugInIdList(); |
| 477 | |
| 478 | DecryptHandle* handle = new DecryptHandle(); |
| 479 | if (NULL != handle) { |
| 480 | handle->decryptId = mDecryptSessionId + 1; |
| 481 | |
| 482 | for (size_t index = 0; index < plugInIdList.size(); index++) { |
| 483 | String8 plugInId = plugInIdList.itemAt(index); |
| 484 | IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); |
| 485 | result = rDrmEngine.openDecryptSession(uniqueId, handle, buf, mimeType); |
| 486 | |
| 487 | if (DRM_NO_ERROR == result) { |
| 488 | ++mDecryptSessionId; |
| 489 | mDecryptSessionMap.add(mDecryptSessionId, &rDrmEngine); |
| 490 | break; |
| 491 | } |
| 492 | } |
| 493 | } |
| 494 | if (DRM_NO_ERROR != result) { |
| 495 | delete handle; |
| 496 | handle = NULL; |
| 497 | ALOGV("DrmManager::openDecryptSession: no capable plug-in found"); |
| 498 | } |
| 499 | return handle; |
| 500 | } |
| 501 | |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 502 | status_t DrmManager::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) { |
| Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 503 | Mutex::Autolock _l(mDecryptLock); |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 504 | status_t result = DRM_ERROR_UNKNOWN; |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 505 | if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) { |
| 506 | IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId); |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 507 | result = drmEngine->closeDecryptSession(uniqueId, decryptHandle); |
| 508 | if (DRM_NO_ERROR == result) { |
| 509 | mDecryptSessionMap.removeItem(decryptHandle->decryptId); |
| 510 | } |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 511 | } |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 512 | return result; |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 513 | } |
| 514 | |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 515 | status_t DrmManager::initializeDecryptUnit( |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 516 | int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo) { |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 517 | status_t result = DRM_ERROR_UNKNOWN; |
| Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 518 | Mutex::Autolock _l(mDecryptLock); |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 519 | if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) { |
| 520 | IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId); |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 521 | result = drmEngine->initializeDecryptUnit(uniqueId, decryptHandle, decryptUnitId, headerInfo); |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 522 | } |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 523 | return result; |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 524 | } |
| 525 | |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 526 | status_t DrmManager::decrypt(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, |
| 527 | const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) { |
| 528 | status_t result = DRM_ERROR_UNKNOWN; |
| Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 529 | |
| 530 | Mutex::Autolock _l(mDecryptLock); |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 531 | if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) { |
| 532 | IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId); |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 533 | result = drmEngine->decrypt( |
| 534 | uniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer, IV); |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 535 | } |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 536 | return result; |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 537 | } |
| 538 | |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 539 | status_t DrmManager::finalizeDecryptUnit( |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 540 | int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) { |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 541 | status_t result = DRM_ERROR_UNKNOWN; |
| Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 542 | Mutex::Autolock _l(mDecryptLock); |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 543 | if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) { |
| 544 | IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId); |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 545 | result = drmEngine->finalizeDecryptUnit(uniqueId, decryptHandle, decryptUnitId); |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 546 | } |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 547 | return result; |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | ssize_t DrmManager::pread(int uniqueId, DecryptHandle* decryptHandle, |
| Gloria Wang | a2cd44c | 2010-11-19 15:19:36 -0800 | [diff] [blame] | 551 | void* buffer, ssize_t numBytes, off64_t offset) { |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 552 | ssize_t result = DECRYPT_FILE_ERROR; |
| 553 | |
| Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 554 | Mutex::Autolock _l(mDecryptLock); |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 555 | if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) { |
| 556 | IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId); |
| 557 | result = drmEngine->pread(uniqueId, decryptHandle, buffer, numBytes, offset); |
| 558 | } |
| 559 | return result; |
| 560 | } |
| 561 | |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 562 | String8 DrmManager::getSupportedPlugInId( |
| 563 | int uniqueId, const String8& path, const String8& mimeType) { |
| 564 | String8 plugInId(""); |
| 565 | |
| 566 | if (EMPTY_STRING != mimeType) { |
| 567 | plugInId = getSupportedPlugInId(mimeType); |
| 568 | } else { |
| 569 | plugInId = getSupportedPlugInIdFromPath(uniqueId, path); |
| 570 | } |
| 571 | return plugInId; |
| 572 | } |
| 573 | |
| 574 | String8 DrmManager::getSupportedPlugInId(const String8& mimeType) { |
| 575 | String8 plugInId(""); |
| 576 | |
| 577 | if (EMPTY_STRING != mimeType) { |
| 578 | for (unsigned int index = 0; index < mSupportInfoToPlugInIdMap.size(); index++) { |
| 579 | const DrmSupportInfo& drmSupportInfo = mSupportInfoToPlugInIdMap.keyAt(index); |
| 580 | |
| 581 | if (drmSupportInfo.isSupportedMimeType(mimeType)) { |
| 582 | plugInId = mSupportInfoToPlugInIdMap.valueFor(drmSupportInfo); |
| 583 | break; |
| 584 | } |
| 585 | } |
| 586 | } |
| 587 | return plugInId; |
| 588 | } |
| 589 | |
| 590 | String8 DrmManager::getSupportedPlugInIdFromPath(int uniqueId, const String8& path) { |
| 591 | String8 plugInId(""); |
| 592 | const String8 fileSuffix = path.getPathExtension(); |
| 593 | |
| 594 | for (unsigned int index = 0; index < mSupportInfoToPlugInIdMap.size(); index++) { |
| 595 | const DrmSupportInfo& drmSupportInfo = mSupportInfoToPlugInIdMap.keyAt(index); |
| 596 | |
| 597 | if (drmSupportInfo.isSupportedFileSuffix(fileSuffix)) { |
| 598 | String8 key = mSupportInfoToPlugInIdMap.valueFor(drmSupportInfo); |
| 599 | IDrmEngine& drmEngine = mPlugInManager.getPlugIn(key); |
| 600 | |
| 601 | if (drmEngine.canHandle(uniqueId, path)) { |
| 602 | plugInId = key; |
| 603 | break; |
| 604 | } |
| 605 | } |
| 606 | } |
| 607 | return plugInId; |
| 608 | } |
| 609 | |
| 610 | void DrmManager::onInfo(const DrmInfoEvent& event) { |
| Gloria Wang | 0e0a5f9 | 2011-03-11 14:07:21 -0800 | [diff] [blame] | 611 | Mutex::Autolock _l(mListenerLock); |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 612 | for (unsigned int index = 0; index < mServiceListeners.size(); index++) { |
| 613 | int uniqueId = mServiceListeners.keyAt(index); |
| 614 | |
| 615 | if (uniqueId == event.getUniqueId()) { |
| 616 | sp<IDrmServiceListener> serviceListener = mServiceListeners.valueFor(uniqueId); |
| 617 | serviceListener->notify(event); |
| 618 | } |
| 619 | } |
| 620 | } |
| 621 | |