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