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