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