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