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