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