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