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