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