| 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 |         { | 
 | 102 |             ALOGW("Unrecognized message type: %zd", msg->what()); | 
 | 103 |         } | 
 | 104 |     } | 
 | 105 | } | 
 | 106 |  | 
 | 107 | int64_t DrmManager::getMetricsFlushPeriodUs() { | 
 | 108 |     return 1000 * 1000 * std::max(1ll, property_get_int64("drmmanager.metrics.period", 86400)); | 
 | 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 |  | 
 | 130 |     if (!mimeType.isEmpty()) { | 
| 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() { | 
| James Dong | 785ee06 | 2011-12-14 10:57:05 -0800 | [diff] [blame] | 211 |     String8 pluginDirPath("/system/lib/drm"); | 
 | 212 |     loadPlugIns(pluginDirPath); | 
| Edwin Wong | 5f6f4e4 | 2011-09-21 19:18:30 -0700 | [diff] [blame] | 213 |     return DRM_NO_ERROR; | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 214 | } | 
 | 215 |  | 
| Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 216 | status_t DrmManager::loadPlugIns(const String8& plugInDirPath) { | 
| Edwin Wong | 5f6f4e4 | 2011-09-21 19:18:30 -0700 | [diff] [blame] | 217 |     mPlugInManager.loadPlugIns(plugInDirPath); | 
 | 218 |     Vector<String8> plugInPathList = mPlugInManager.getPlugInIdList(); | 
| Mark Salyzyn | 3ab368e | 2014-04-15 14:55:53 -0700 | [diff] [blame] | 219 |     for (size_t i = 0; i < plugInPathList.size(); ++i) { | 
| Edwin Wong | 5f6f4e4 | 2011-09-21 19:18:30 -0700 | [diff] [blame] | 220 |         String8 plugInPath = plugInPathList[i]; | 
 | 221 |         DrmSupportInfo* info = mPlugInManager.getPlugIn(plugInPath).getSupportInfo(0); | 
 | 222 |         if (NULL != info) { | 
 | 223 |             if (mSupportInfoToPlugInIdMap.indexOfKey(*info) < 0) { | 
| Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 224 |                 mSupportInfoToPlugInIdMap.add(*info, plugInPath); | 
 | 225 |             } | 
| Edwin Wong | 5f6f4e4 | 2011-09-21 19:18:30 -0700 | [diff] [blame] | 226 |             delete info; | 
| Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 227 |         } | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 228 |     } | 
| Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 229 |     return DRM_NO_ERROR; | 
 | 230 | } | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 231 |  | 
| Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 232 | status_t DrmManager::unloadPlugIns() { | 
| Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 233 |     Mutex::Autolock _l(mLock); | 
| Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 234 |     mConvertSessionMap.clear(); | 
 | 235 |     mDecryptSessionMap.clear(); | 
 | 236 |     mPlugInManager.unloadPlugIns(); | 
 | 237 |     mSupportInfoToPlugInIdMap.clear(); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 238 |     return DRM_NO_ERROR; | 
 | 239 | } | 
 | 240 |  | 
 | 241 | status_t DrmManager::setDrmServiceListener( | 
 | 242 |             int uniqueId, const sp<IDrmServiceListener>& drmServiceListener) { | 
| Gloria Wang | 0e0a5f9 | 2011-03-11 14:07:21 -0800 | [diff] [blame] | 243 |     Mutex::Autolock _l(mListenerLock); | 
| Takeshi Aimi | c618b5a | 2010-11-30 16:27:42 +0900 | [diff] [blame] | 244 |     if (NULL != drmServiceListener.get()) { | 
 | 245 |         mServiceListeners.add(uniqueId, drmServiceListener); | 
 | 246 |     } else { | 
 | 247 |         mServiceListeners.removeItem(uniqueId); | 
 | 248 |     } | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 249 |     return DRM_NO_ERROR; | 
 | 250 | } | 
 | 251 |  | 
| Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 252 | void DrmManager::addClient(int uniqueId) { | 
| Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 253 |     Mutex::Autolock _l(mLock); | 
| Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 254 |     if (!mSupportInfoToPlugInIdMap.isEmpty()) { | 
 | 255 |         Vector<String8> plugInIdList = mPlugInManager.getPlugInIdList(); | 
| Mark Salyzyn | 3ab368e | 2014-04-15 14:55:53 -0700 | [diff] [blame] | 256 |         for (size_t index = 0; index < plugInIdList.size(); index++) { | 
| Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 257 |             IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInIdList.itemAt(index)); | 
 | 258 |             rDrmEngine.initialize(uniqueId); | 
 | 259 |             rDrmEngine.setOnInfoListener(uniqueId, this); | 
 | 260 |         } | 
 | 261 |     } | 
 | 262 | } | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 263 |  | 
| Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 264 | void DrmManager::removeClient(int uniqueId) { | 
| Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 265 |     Mutex::Autolock _l(mLock); | 
| Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 266 |     Vector<String8> plugInIdList = mPlugInManager.getPlugInIdList(); | 
| Mark Salyzyn | 3ab368e | 2014-04-15 14:55:53 -0700 | [diff] [blame] | 267 |     for (size_t index = 0; index < plugInIdList.size(); index++) { | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 268 |         IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInIdList.itemAt(index)); | 
 | 269 |         rDrmEngine.terminate(uniqueId); | 
 | 270 |     } | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 271 | } | 
 | 272 |  | 
 | 273 | DrmConstraints* DrmManager::getConstraints(int uniqueId, const String8* path, const int action) { | 
| Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 274 |     Mutex::Autolock _l(mLock); | 
| Robert Shih | ec056ae | 2019-08-17 01:54:04 -0700 | [diff] [blame] | 275 |     DrmConstraints *constraints = NULL; | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 276 |     const String8 plugInId = getSupportedPlugInIdFromPath(uniqueId, *path); | 
 | 277 |     if (EMPTY_STRING != plugInId) { | 
 | 278 |         IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); | 
| Robert Shih | ec056ae | 2019-08-17 01:54:04 -0700 | [diff] [blame] | 279 |         constraints = rDrmEngine.getConstraints(uniqueId, path, action); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 280 |     } | 
| Robert Shih | ec056ae | 2019-08-17 01:54:04 -0700 | [diff] [blame] | 281 |     if (NULL != constraints) { | 
| Robert Shih | 7bcf792 | 2020-02-07 15:01:57 -0800 | [diff] [blame] | 282 |         recordEngineMetrics(__func__, plugInId); | 
| Robert Shih | ec056ae | 2019-08-17 01:54:04 -0700 | [diff] [blame] | 283 |     } | 
 | 284 |     return constraints; | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 285 | } | 
 | 286 |  | 
| Takeshi Aimi | 3473846 | 2010-11-16 13:56:11 +0900 | [diff] [blame] | 287 | DrmMetadata* DrmManager::getMetadata(int uniqueId, const String8* path) { | 
| Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 288 |     Mutex::Autolock _l(mLock); | 
| Robert Shih | ec056ae | 2019-08-17 01:54:04 -0700 | [diff] [blame] | 289 |     DrmMetadata *meta = NULL; | 
| Takeshi Aimi | 3473846 | 2010-11-16 13:56:11 +0900 | [diff] [blame] | 290 |     const String8 plugInId = getSupportedPlugInIdFromPath(uniqueId, *path); | 
 | 291 |     if (EMPTY_STRING != plugInId) { | 
 | 292 |         IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); | 
| Robert Shih | ec056ae | 2019-08-17 01:54:04 -0700 | [diff] [blame] | 293 |         meta = rDrmEngine.getMetadata(uniqueId, path); | 
| Takeshi Aimi | 3473846 | 2010-11-16 13:56:11 +0900 | [diff] [blame] | 294 |     } | 
| Robert Shih | ec056ae | 2019-08-17 01:54:04 -0700 | [diff] [blame] | 295 |     if (NULL != meta) { | 
| Robert Shih | 7bcf792 | 2020-02-07 15:01:57 -0800 | [diff] [blame] | 296 |         recordEngineMetrics(__func__, plugInId); | 
| Robert Shih | ec056ae | 2019-08-17 01:54:04 -0700 | [diff] [blame] | 297 |     } | 
 | 298 |     return meta; | 
| Takeshi Aimi | 3473846 | 2010-11-16 13:56:11 +0900 | [diff] [blame] | 299 | } | 
 | 300 |  | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 301 | bool DrmManager::canHandle(int uniqueId, const String8& path, const String8& mimeType) { | 
| Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 302 |     Mutex::Autolock _l(mLock); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 303 |     const String8 plugInId = getSupportedPlugInId(mimeType); | 
 | 304 |     bool result = (EMPTY_STRING != plugInId) ? true : false; | 
 | 305 |  | 
| Robert Shih | ec056ae | 2019-08-17 01:54:04 -0700 | [diff] [blame] | 306 |     if (result) { | 
| Robert Shih | 7bcf792 | 2020-02-07 15:01:57 -0800 | [diff] [blame] | 307 |         recordEngineMetrics(__func__, plugInId, mimeType); | 
| Robert Shih | ec056ae | 2019-08-17 01:54:04 -0700 | [diff] [blame] | 308 |     } | 
 | 309 |  | 
| Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 310 |     if (0 < path.length()) { | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 311 |         if (result) { | 
 | 312 |             IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); | 
 | 313 |             result = rDrmEngine.canHandle(uniqueId, path); | 
 | 314 |         } else { | 
| Gloria Wang | 7f89d09 | 2011-03-02 12:33:00 -0800 | [diff] [blame] | 315 |             String8 extension = path.getPathExtension(); | 
 | 316 |             if (String8("") != extension) { | 
 | 317 |                 result = canHandle(uniqueId, path); | 
 | 318 |             } | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 319 |         } | 
 | 320 |     } | 
 | 321 |     return result; | 
 | 322 | } | 
 | 323 |  | 
 | 324 | DrmInfoStatus* DrmManager::processDrmInfo(int uniqueId, const DrmInfo* drmInfo) { | 
| Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 325 |     Mutex::Autolock _l(mLock); | 
| Robert Shih | ec056ae | 2019-08-17 01:54:04 -0700 | [diff] [blame] | 326 |     DrmInfoStatus *infoStatus = NULL; | 
 | 327 |     const String8 mimeType = drmInfo->getMimeType(); | 
 | 328 |     const String8 plugInId = getSupportedPlugInId(mimeType); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 329 |     if (EMPTY_STRING != plugInId) { | 
 | 330 |         IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); | 
| Robert Shih | ec056ae | 2019-08-17 01:54:04 -0700 | [diff] [blame] | 331 |         infoStatus = rDrmEngine.processDrmInfo(uniqueId, drmInfo); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 332 |     } | 
| Robert Shih | ec056ae | 2019-08-17 01:54:04 -0700 | [diff] [blame] | 333 |     if (NULL != infoStatus) { | 
| Robert Shih | 7bcf792 | 2020-02-07 15:01:57 -0800 | [diff] [blame] | 334 |         recordEngineMetrics(__func__, plugInId, mimeType); | 
| Robert Shih | ec056ae | 2019-08-17 01:54:04 -0700 | [diff] [blame] | 335 |     } | 
 | 336 |     return infoStatus; | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 337 | } | 
 | 338 |  | 
 | 339 | bool DrmManager::canHandle(int uniqueId, const String8& path) { | 
 | 340 |     bool result = false; | 
 | 341 |     Vector<String8> plugInPathList = mPlugInManager.getPlugInIdList(); | 
 | 342 |  | 
| Mark Salyzyn | 3ab368e | 2014-04-15 14:55:53 -0700 | [diff] [blame] | 343 |     for (size_t i = 0; i < plugInPathList.size(); ++i) { | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 344 |         IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInPathList[i]); | 
 | 345 |         result = rDrmEngine.canHandle(uniqueId, path); | 
 | 346 |  | 
 | 347 |         if (result) { | 
| Robert Shih | 7bcf792 | 2020-02-07 15:01:57 -0800 | [diff] [blame] | 348 |             recordEngineMetrics(__func__, plugInPathList[i]); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 349 |             break; | 
 | 350 |         } | 
 | 351 |     } | 
 | 352 |     return result; | 
 | 353 | } | 
 | 354 |  | 
 | 355 | DrmInfo* DrmManager::acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest) { | 
| Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 356 |     Mutex::Autolock _l(mLock); | 
| Robert Shih | ec056ae | 2019-08-17 01:54:04 -0700 | [diff] [blame] | 357 |     DrmInfo *info = NULL; | 
 | 358 |     const String8 mimeType = drmInfoRequest->getMimeType(); | 
 | 359 |     const String8 plugInId = getSupportedPlugInId(mimeType); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 360 |     if (EMPTY_STRING != plugInId) { | 
 | 361 |         IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); | 
| Robert Shih | ec056ae | 2019-08-17 01:54:04 -0700 | [diff] [blame] | 362 |         info = rDrmEngine.acquireDrmInfo(uniqueId, drmInfoRequest); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 363 |     } | 
| Robert Shih | ec056ae | 2019-08-17 01:54:04 -0700 | [diff] [blame] | 364 |     if (NULL != info) { | 
| Robert Shih | 7bcf792 | 2020-02-07 15:01:57 -0800 | [diff] [blame] | 365 |         recordEngineMetrics(__func__, plugInId, mimeType); | 
| Robert Shih | ec056ae | 2019-08-17 01:54:04 -0700 | [diff] [blame] | 366 |     } | 
 | 367 |     return info; | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 368 | } | 
 | 369 |  | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 370 | status_t DrmManager::saveRights(int uniqueId, const DrmRights& drmRights, | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 371 |             const String8& rightsPath, const String8& contentPath) { | 
| Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 372 |     Mutex::Autolock _l(mLock); | 
| Robert Shih | ec056ae | 2019-08-17 01:54:04 -0700 | [diff] [blame] | 373 |     const String8 mimeType = drmRights.getMimeType(); | 
 | 374 |     const String8 plugInId = getSupportedPlugInId(mimeType); | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 375 |     status_t result = DRM_ERROR_UNKNOWN; | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 376 |     if (EMPTY_STRING != plugInId) { | 
 | 377 |         IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 378 |         result = rDrmEngine.saveRights(uniqueId, drmRights, rightsPath, contentPath); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 379 |     } | 
| Robert Shih | ec056ae | 2019-08-17 01:54:04 -0700 | [diff] [blame] | 380 |     if (DRM_NO_ERROR == result) { | 
| Robert Shih | 7bcf792 | 2020-02-07 15:01:57 -0800 | [diff] [blame] | 381 |         recordEngineMetrics(__func__, plugInId, mimeType); | 
| Robert Shih | ec056ae | 2019-08-17 01:54:04 -0700 | [diff] [blame] | 382 |     } | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 383 |     return result; | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 384 | } | 
 | 385 |  | 
| James Dong | bf5b3b2 | 2012-07-30 17:57:39 -0700 | [diff] [blame] | 386 | String8 DrmManager::getOriginalMimeType(int uniqueId, const String8& path, int fd) { | 
| Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 387 |     Mutex::Autolock _l(mLock); | 
| Robert Shih | ec056ae | 2019-08-17 01:54:04 -0700 | [diff] [blame] | 388 |     String8 mimeType(EMPTY_STRING); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 389 |     const String8 plugInId = getSupportedPlugInIdFromPath(uniqueId, path); | 
 | 390 |     if (EMPTY_STRING != plugInId) { | 
 | 391 |         IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); | 
| Robert Shih | ec056ae | 2019-08-17 01:54:04 -0700 | [diff] [blame] | 392 |         mimeType = rDrmEngine.getOriginalMimeType(uniqueId, path, fd); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 393 |     } | 
| Robert Shih | ec056ae | 2019-08-17 01:54:04 -0700 | [diff] [blame] | 394 |     if (!mimeType.isEmpty()) { | 
| Robert Shih | 7bcf792 | 2020-02-07 15:01:57 -0800 | [diff] [blame] | 395 |         recordEngineMetrics(__func__, plugInId, mimeType); | 
| Robert Shih | ec056ae | 2019-08-17 01:54:04 -0700 | [diff] [blame] | 396 |     } | 
 | 397 |     return mimeType; | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 398 | } | 
 | 399 |  | 
 | 400 | int DrmManager::getDrmObjectType(int uniqueId, const String8& path, const String8& mimeType) { | 
| Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 401 |     Mutex::Autolock _l(mLock); | 
| Robert Shih | ec056ae | 2019-08-17 01:54:04 -0700 | [diff] [blame] | 402 |     int type = DrmObjectType::UNKNOWN; | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 403 |     const String8 plugInId = getSupportedPlugInId(uniqueId, path, mimeType); | 
 | 404 |     if (EMPTY_STRING != plugInId) { | 
 | 405 |         IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); | 
| Robert Shih | ec056ae | 2019-08-17 01:54:04 -0700 | [diff] [blame] | 406 |         type = rDrmEngine.getDrmObjectType(uniqueId, path, mimeType); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 407 |     } | 
| Robert Shih | ec056ae | 2019-08-17 01:54:04 -0700 | [diff] [blame] | 408 |     if (DrmObjectType::UNKNOWN != type) { | 
| Robert Shih | 7bcf792 | 2020-02-07 15:01:57 -0800 | [diff] [blame] | 409 |         recordEngineMetrics(__func__, plugInId, mimeType); | 
| Robert Shih | ec056ae | 2019-08-17 01:54:04 -0700 | [diff] [blame] | 410 |     } | 
 | 411 |     return type; | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 412 | } | 
 | 413 |  | 
 | 414 | int DrmManager::checkRightsStatus(int uniqueId, const String8& path, int action) { | 
| Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 415 |     Mutex::Autolock _l(mLock); | 
| Robert Shih | ec056ae | 2019-08-17 01:54:04 -0700 | [diff] [blame] | 416 |     int rightsStatus = RightsStatus::RIGHTS_INVALID; | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 417 |     const String8 plugInId = getSupportedPlugInIdFromPath(uniqueId, path); | 
 | 418 |     if (EMPTY_STRING != plugInId) { | 
 | 419 |         IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); | 
| Robert Shih | ec056ae | 2019-08-17 01:54:04 -0700 | [diff] [blame] | 420 |         rightsStatus = rDrmEngine.checkRightsStatus(uniqueId, path, action); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 421 |     } | 
| Robert Shih | ec056ae | 2019-08-17 01:54:04 -0700 | [diff] [blame] | 422 |     if (RightsStatus::RIGHTS_INVALID != rightsStatus) { | 
| Robert Shih | 7bcf792 | 2020-02-07 15:01:57 -0800 | [diff] [blame] | 423 |         recordEngineMetrics(__func__, plugInId); | 
| Robert Shih | ec056ae | 2019-08-17 01:54:04 -0700 | [diff] [blame] | 424 |     } | 
 | 425 |     return rightsStatus; | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 426 | } | 
 | 427 |  | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 428 | status_t DrmManager::consumeRights( | 
| Jeff Tinker | 5d49bef | 2018-10-03 23:01:09 -0700 | [diff] [blame] | 429 |     int uniqueId, sp<DecryptHandle>& decryptHandle, int action, bool reserve) { | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 430 |     status_t result = DRM_ERROR_UNKNOWN; | 
| Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 431 |     Mutex::Autolock _l(mDecryptLock); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 432 |     if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) { | 
 | 433 |         IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId); | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 434 |         result = drmEngine->consumeRights(uniqueId, decryptHandle, action, reserve); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 435 |     } | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 436 |     return result; | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 437 | } | 
 | 438 |  | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 439 | status_t DrmManager::setPlaybackStatus( | 
| Jeff Tinker | 5d49bef | 2018-10-03 23:01:09 -0700 | [diff] [blame] | 440 |     int uniqueId, sp<DecryptHandle>& decryptHandle, int playbackStatus, int64_t position) { | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 441 |     status_t result = DRM_ERROR_UNKNOWN; | 
| Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 442 |     Mutex::Autolock _l(mDecryptLock); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 443 |     if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) { | 
 | 444 |         IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId); | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 445 |         result = drmEngine->setPlaybackStatus(uniqueId, decryptHandle, playbackStatus, position); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 446 |     } | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 447 |     return result; | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 448 | } | 
 | 449 |  | 
 | 450 | bool DrmManager::validateAction( | 
 | 451 |     int uniqueId, const String8& path, int action, const ActionDescription& description) { | 
| Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 452 |     Mutex::Autolock _l(mLock); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 453 |     const String8 plugInId = getSupportedPlugInIdFromPath(uniqueId, path); | 
 | 454 |     if (EMPTY_STRING != plugInId) { | 
 | 455 |         IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); | 
 | 456 |         return rDrmEngine.validateAction(uniqueId, path, action, description); | 
 | 457 |     } | 
 | 458 |     return false; | 
 | 459 | } | 
 | 460 |  | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 461 | status_t DrmManager::removeRights(int uniqueId, const String8& path) { | 
| Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 462 |     Mutex::Autolock _l(mLock); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 463 |     const String8 plugInId = getSupportedPlugInIdFromPath(uniqueId, path); | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 464 |     status_t result = DRM_ERROR_UNKNOWN; | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 465 |     if (EMPTY_STRING != plugInId) { | 
 | 466 |         IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 467 |         result = rDrmEngine.removeRights(uniqueId, path); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 468 |     } | 
| Robert Shih | ec056ae | 2019-08-17 01:54:04 -0700 | [diff] [blame] | 469 |     if (DRM_NO_ERROR == result) { | 
| Robert Shih | 7bcf792 | 2020-02-07 15:01:57 -0800 | [diff] [blame] | 470 |         recordEngineMetrics(__func__, plugInId); | 
| Robert Shih | ec056ae | 2019-08-17 01:54:04 -0700 | [diff] [blame] | 471 |     } | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 472 |     return result; | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 473 | } | 
 | 474 |  | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 475 | status_t DrmManager::removeAllRights(int uniqueId) { | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 476 |     Vector<String8> plugInIdList = mPlugInManager.getPlugInIdList(); | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 477 |     status_t result = DRM_ERROR_UNKNOWN; | 
| Mark Salyzyn | 3ab368e | 2014-04-15 14:55:53 -0700 | [diff] [blame] | 478 |     for (size_t index = 0; index < plugInIdList.size(); index++) { | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 479 |         IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInIdList.itemAt(index)); | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 480 |         result = rDrmEngine.removeAllRights(uniqueId); | 
 | 481 |         if (DRM_NO_ERROR != result) { | 
 | 482 |             break; | 
 | 483 |         } | 
| Robert Shih | 7bcf792 | 2020-02-07 15:01:57 -0800 | [diff] [blame] | 484 |         recordEngineMetrics(__func__, plugInIdList[index]); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 485 |     } | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 486 |     return result; | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 487 | } | 
 | 488 |  | 
 | 489 | int DrmManager::openConvertSession(int uniqueId, const String8& mimeType) { | 
| Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 490 |     Mutex::Autolock _l(mConvertLock); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 491 |     int convertId = -1; | 
 | 492 |  | 
 | 493 |     const String8 plugInId = getSupportedPlugInId(mimeType); | 
 | 494 |     if (EMPTY_STRING != plugInId) { | 
 | 495 |         IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); | 
 | 496 |  | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 497 |         if (DRM_NO_ERROR == rDrmEngine.openConvertSession(uniqueId, mConvertId + 1)) { | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 498 |             ++mConvertId; | 
 | 499 |             convertId = mConvertId; | 
 | 500 |             mConvertSessionMap.add(convertId, &rDrmEngine); | 
| Robert Shih | 7bcf792 | 2020-02-07 15:01:57 -0800 | [diff] [blame] | 501 |             recordEngineMetrics(__func__, plugInId, mimeType); | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 502 |         } | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 503 |     } | 
 | 504 |     return convertId; | 
 | 505 | } | 
 | 506 |  | 
 | 507 | DrmConvertedStatus* DrmManager::convertData( | 
 | 508 |             int uniqueId, int convertId, const DrmBuffer* inputData) { | 
 | 509 |     DrmConvertedStatus *drmConvertedStatus = NULL; | 
 | 510 |  | 
| Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 511 |     Mutex::Autolock _l(mConvertLock); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 512 |     if (mConvertSessionMap.indexOfKey(convertId) != NAME_NOT_FOUND) { | 
 | 513 |         IDrmEngine* drmEngine = mConvertSessionMap.valueFor(convertId); | 
 | 514 |         drmConvertedStatus = drmEngine->convertData(uniqueId, convertId, inputData); | 
 | 515 |     } | 
 | 516 |     return drmConvertedStatus; | 
 | 517 | } | 
 | 518 |  | 
 | 519 | DrmConvertedStatus* DrmManager::closeConvertSession(int uniqueId, int convertId) { | 
| Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 520 |     Mutex::Autolock _l(mConvertLock); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 521 |     DrmConvertedStatus *drmConvertedStatus = NULL; | 
 | 522 |  | 
 | 523 |     if (mConvertSessionMap.indexOfKey(convertId) != NAME_NOT_FOUND) { | 
 | 524 |         IDrmEngine* drmEngine = mConvertSessionMap.valueFor(convertId); | 
 | 525 |         drmConvertedStatus = drmEngine->closeConvertSession(uniqueId, convertId); | 
 | 526 |         mConvertSessionMap.removeItem(convertId); | 
 | 527 |     } | 
 | 528 |     return drmConvertedStatus; | 
 | 529 | } | 
 | 530 |  | 
 | 531 | status_t DrmManager::getAllSupportInfo( | 
| Aurimas Liutikas | b223117 | 2016-02-12 16:57:08 -0800 | [diff] [blame] | 532 |                     int /* uniqueId */, int* length, DrmSupportInfo** drmSupportInfoArray) { | 
| Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 533 |     Mutex::Autolock _l(mLock); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 534 |     Vector<String8> plugInPathList = mPlugInManager.getPlugInIdList(); | 
 | 535 |     int size = plugInPathList.size(); | 
 | 536 |     int validPlugins = 0; | 
 | 537 |  | 
 | 538 |     if (0 < size) { | 
 | 539 |         Vector<DrmSupportInfo> drmSupportInfoList; | 
 | 540 |  | 
 | 541 |         for (int i = 0; i < size; ++i) { | 
 | 542 |             String8 plugInPath = plugInPathList[i]; | 
 | 543 |             DrmSupportInfo* drmSupportInfo | 
| Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 544 |                 = mPlugInManager.getPlugIn(plugInPath).getSupportInfo(0); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 545 |             if (NULL != drmSupportInfo) { | 
 | 546 |                 drmSupportInfoList.add(*drmSupportInfo); | 
 | 547 |                 delete drmSupportInfo; drmSupportInfo = NULL; | 
 | 548 |             } | 
 | 549 |         } | 
 | 550 |  | 
 | 551 |         validPlugins = drmSupportInfoList.size(); | 
 | 552 |         if (0 < validPlugins) { | 
 | 553 |             *drmSupportInfoArray = new DrmSupportInfo[validPlugins]; | 
 | 554 |             for (int i = 0; i < validPlugins; ++i) { | 
 | 555 |                 (*drmSupportInfoArray)[i] = drmSupportInfoList[i]; | 
 | 556 |             } | 
 | 557 |         } | 
 | 558 |     } | 
 | 559 |     *length = validPlugins; | 
 | 560 |     return DRM_NO_ERROR; | 
 | 561 | } | 
 | 562 |  | 
| Jeff Tinker | 5d49bef | 2018-10-03 23:01:09 -0700 | [diff] [blame] | 563 | sp<DecryptHandle> DrmManager::openDecryptSession( | 
| James Dong | 9d2f386 | 2012-01-10 08:24:37 -0800 | [diff] [blame] | 564 |         int uniqueId, int fd, off64_t offset, off64_t length, const char* mime) { | 
 | 565 |  | 
| Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 566 |     Mutex::Autolock _l(mDecryptLock); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 567 |     status_t result = DRM_ERROR_CANNOT_HANDLE; | 
 | 568 |     Vector<String8> plugInIdList = mPlugInManager.getPlugInIdList(); | 
 | 569 |  | 
| Jeff Tinker | 5d49bef | 2018-10-03 23:01:09 -0700 | [diff] [blame] | 570 |     sp<DecryptHandle> handle = new DecryptHandle(); | 
 | 571 |     if (NULL != handle.get()) { | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 572 |         handle->decryptId = mDecryptSessionId + 1; | 
 | 573 |  | 
| Mark Salyzyn | 3ab368e | 2014-04-15 14:55:53 -0700 | [diff] [blame] | 574 |         for (size_t index = 0; index < plugInIdList.size(); index++) { | 
| Chih-Hung Hsieh | 8c0164c | 2016-08-09 14:20:59 -0700 | [diff] [blame] | 575 |             const String8& plugInId = plugInIdList.itemAt(index); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 576 |             IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); | 
| James Dong | 9d2f386 | 2012-01-10 08:24:37 -0800 | [diff] [blame] | 577 |             result = rDrmEngine.openDecryptSession(uniqueId, handle, fd, offset, length, mime); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 578 |  | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 579 |             if (DRM_NO_ERROR == result) { | 
 | 580 |                 ++mDecryptSessionId; | 
 | 581 |                 mDecryptSessionMap.add(mDecryptSessionId, &rDrmEngine); | 
| Robert Shih | 7bcf792 | 2020-02-07 15:01:57 -0800 | [diff] [blame] | 582 |                 recordEngineMetrics(__func__, plugInId, String8(mime)); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 583 |                 break; | 
 | 584 |             } | 
 | 585 |         } | 
 | 586 |     } | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 587 |     if (DRM_NO_ERROR != result) { | 
| Jeff Tinker | 5d49bef | 2018-10-03 23:01:09 -0700 | [diff] [blame] | 588 |         handle.clear(); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 589 |     } | 
| Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 590 |     return handle; | 
 | 591 | } | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 592 |  | 
| Jeff Tinker | 5d49bef | 2018-10-03 23:01:09 -0700 | [diff] [blame] | 593 | sp<DecryptHandle> DrmManager::openDecryptSession( | 
| James Dong | 9d2f386 | 2012-01-10 08:24:37 -0800 | [diff] [blame] | 594 |         int uniqueId, const char* uri, const char* mime) { | 
| Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 595 |     Mutex::Autolock _l(mDecryptLock); | 
 | 596 |     status_t result = DRM_ERROR_CANNOT_HANDLE; | 
 | 597 |     Vector<String8> plugInIdList = mPlugInManager.getPlugInIdList(); | 
 | 598 |  | 
| Jeff Tinker | 5d49bef | 2018-10-03 23:01:09 -0700 | [diff] [blame] | 599 |     sp<DecryptHandle> handle = new DecryptHandle(); | 
 | 600 |     if (NULL != handle.get()) { | 
| Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 601 |         handle->decryptId = mDecryptSessionId + 1; | 
 | 602 |  | 
| Mark Salyzyn | 3ab368e | 2014-04-15 14:55:53 -0700 | [diff] [blame] | 603 |         for (size_t index = 0; index < plugInIdList.size(); index++) { | 
| Chih-Hung Hsieh | 8c0164c | 2016-08-09 14:20:59 -0700 | [diff] [blame] | 604 |             const String8& plugInId = plugInIdList.itemAt(index); | 
| Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 605 |             IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); | 
| James Dong | 9d2f386 | 2012-01-10 08:24:37 -0800 | [diff] [blame] | 606 |             result = rDrmEngine.openDecryptSession(uniqueId, handle, uri, mime); | 
| Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 607 |  | 
 | 608 |             if (DRM_NO_ERROR == result) { | 
 | 609 |                 ++mDecryptSessionId; | 
 | 610 |                 mDecryptSessionMap.add(mDecryptSessionId, &rDrmEngine); | 
| Robert Shih | 7bcf792 | 2020-02-07 15:01:57 -0800 | [diff] [blame] | 611 |                 recordEngineMetrics(__func__, plugInId, String8(mime)); | 
| Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 612 |                 break; | 
 | 613 |             } | 
 | 614 |         } | 
 | 615 |     } | 
 | 616 |     if (DRM_NO_ERROR != result) { | 
| Jeff Tinker | 5d49bef | 2018-10-03 23:01:09 -0700 | [diff] [blame] | 617 |         handle.clear(); | 
| Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 618 |         ALOGV("DrmManager::openDecryptSession: no capable plug-in found"); | 
| Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 619 |     } | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 620 |     return handle; | 
 | 621 | } | 
 | 622 |  | 
| Jeff Tinker | 5d49bef | 2018-10-03 23:01:09 -0700 | [diff] [blame] | 623 | sp<DecryptHandle> DrmManager::openDecryptSession( | 
| Kei Takahashi | cba7b32 | 2012-01-18 17:10:19 +0900 | [diff] [blame] | 624 |         int uniqueId, const DrmBuffer& buf, const String8& mimeType) { | 
 | 625 |     Mutex::Autolock _l(mDecryptLock); | 
 | 626 |     status_t result = DRM_ERROR_CANNOT_HANDLE; | 
 | 627 |     Vector<String8> plugInIdList = mPlugInManager.getPlugInIdList(); | 
 | 628 |  | 
| Jeff Tinker | 5d49bef | 2018-10-03 23:01:09 -0700 | [diff] [blame] | 629 |     sp<DecryptHandle> handle = new DecryptHandle(); | 
 | 630 |     if (NULL != handle.get()) { | 
| Kei Takahashi | cba7b32 | 2012-01-18 17:10:19 +0900 | [diff] [blame] | 631 |         handle->decryptId = mDecryptSessionId + 1; | 
 | 632 |  | 
 | 633 |         for (size_t index = 0; index < plugInIdList.size(); index++) { | 
| Chih-Hung Hsieh | 8c0164c | 2016-08-09 14:20:59 -0700 | [diff] [blame] | 634 |             const String8& plugInId = plugInIdList.itemAt(index); | 
| Kei Takahashi | cba7b32 | 2012-01-18 17:10:19 +0900 | [diff] [blame] | 635 |             IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); | 
 | 636 |             result = rDrmEngine.openDecryptSession(uniqueId, handle, buf, mimeType); | 
 | 637 |  | 
 | 638 |             if (DRM_NO_ERROR == result) { | 
 | 639 |                 ++mDecryptSessionId; | 
 | 640 |                 mDecryptSessionMap.add(mDecryptSessionId, &rDrmEngine); | 
| Robert Shih | 7bcf792 | 2020-02-07 15:01:57 -0800 | [diff] [blame] | 641 |                 recordEngineMetrics(__func__, plugInId, mimeType); | 
| Kei Takahashi | cba7b32 | 2012-01-18 17:10:19 +0900 | [diff] [blame] | 642 |                 break; | 
 | 643 |             } | 
 | 644 |         } | 
 | 645 |     } | 
 | 646 |     if (DRM_NO_ERROR != result) { | 
| Jeff Tinker | 5d49bef | 2018-10-03 23:01:09 -0700 | [diff] [blame] | 647 |         handle.clear(); | 
| Kei Takahashi | cba7b32 | 2012-01-18 17:10:19 +0900 | [diff] [blame] | 648 |         ALOGV("DrmManager::openDecryptSession: no capable plug-in found"); | 
 | 649 |     } | 
 | 650 |     return handle; | 
 | 651 | } | 
 | 652 |  | 
| Jeff Tinker | 5d49bef | 2018-10-03 23:01:09 -0700 | [diff] [blame] | 653 | status_t DrmManager::closeDecryptSession(int uniqueId, sp<DecryptHandle>& decryptHandle) { | 
| Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 654 |     Mutex::Autolock _l(mDecryptLock); | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 655 |     status_t result = DRM_ERROR_UNKNOWN; | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 656 |     if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) { | 
 | 657 |         IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId); | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 658 |         result = drmEngine->closeDecryptSession(uniqueId, decryptHandle); | 
| Jeff Tinker | 5d49bef | 2018-10-03 23:01:09 -0700 | [diff] [blame] | 659 |         if (DRM_NO_ERROR == result && NULL != decryptHandle.get()) { | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 660 |             mDecryptSessionMap.removeItem(decryptHandle->decryptId); | 
 | 661 |         } | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 662 |     } | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 663 |     return result; | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 664 | } | 
 | 665 |  | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 666 | status_t DrmManager::initializeDecryptUnit( | 
| Jeff Tinker | 5d49bef | 2018-10-03 23:01:09 -0700 | [diff] [blame] | 667 |         int uniqueId, sp<DecryptHandle>& decryptHandle, int decryptUnitId, | 
 | 668 |         const DrmBuffer* headerInfo) { | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 669 |     status_t result = DRM_ERROR_UNKNOWN; | 
| Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 670 |     Mutex::Autolock _l(mDecryptLock); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 671 |     if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) { | 
 | 672 |         IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId); | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 673 |         result = drmEngine->initializeDecryptUnit(uniqueId, decryptHandle, decryptUnitId, headerInfo); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 674 |     } | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 675 |     return result; | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 676 | } | 
 | 677 |  | 
| Jeff Tinker | 5d49bef | 2018-10-03 23:01:09 -0700 | [diff] [blame] | 678 | status_t DrmManager::decrypt(int uniqueId, sp<DecryptHandle>& decryptHandle, int decryptUnitId, | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 679 |             const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) { | 
 | 680 |     status_t result = DRM_ERROR_UNKNOWN; | 
| Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 681 |  | 
 | 682 |     Mutex::Autolock _l(mDecryptLock); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 683 |     if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) { | 
 | 684 |         IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId); | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 685 |         result = drmEngine->decrypt( | 
 | 686 |                 uniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer, IV); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 687 |     } | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 688 |     return result; | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 689 | } | 
 | 690 |  | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 691 | status_t DrmManager::finalizeDecryptUnit( | 
| Jeff Tinker | 5d49bef | 2018-10-03 23:01:09 -0700 | [diff] [blame] | 692 |             int uniqueId, sp<DecryptHandle>& decryptHandle, int decryptUnitId) { | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 693 |     status_t result = DRM_ERROR_UNKNOWN; | 
| Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 694 |     Mutex::Autolock _l(mDecryptLock); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 695 |     if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) { | 
 | 696 |         IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId); | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 697 |         result = drmEngine->finalizeDecryptUnit(uniqueId, decryptHandle, decryptUnitId); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 698 |     } | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 699 |     return result; | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 700 | } | 
 | 701 |  | 
| Jeff Tinker | 5d49bef | 2018-10-03 23:01:09 -0700 | [diff] [blame] | 702 | ssize_t DrmManager::pread(int uniqueId, sp<DecryptHandle>& decryptHandle, | 
| Gloria Wang | a2cd44c | 2010-11-19 15:19:36 -0800 | [diff] [blame] | 703 |             void* buffer, ssize_t numBytes, off64_t offset) { | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 704 |     ssize_t result = DECRYPT_FILE_ERROR; | 
 | 705 |  | 
| Gloria Wang | 6b610a3 | 2011-03-04 14:45:03 -0800 | [diff] [blame] | 706 |     Mutex::Autolock _l(mDecryptLock); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 707 |     if (mDecryptSessionMap.indexOfKey(decryptHandle->decryptId) != NAME_NOT_FOUND) { | 
 | 708 |         IDrmEngine* drmEngine = mDecryptSessionMap.valueFor(decryptHandle->decryptId); | 
 | 709 |         result = drmEngine->pread(uniqueId, decryptHandle, buffer, numBytes, offset); | 
 | 710 |     } | 
 | 711 |     return result; | 
 | 712 | } | 
 | 713 |  | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 714 | String8 DrmManager::getSupportedPlugInId( | 
 | 715 |             int uniqueId, const String8& path, const String8& mimeType) { | 
 | 716 |     String8 plugInId(""); | 
 | 717 |  | 
 | 718 |     if (EMPTY_STRING != mimeType) { | 
 | 719 |         plugInId = getSupportedPlugInId(mimeType); | 
 | 720 |     } else { | 
 | 721 |         plugInId = getSupportedPlugInIdFromPath(uniqueId, path); | 
 | 722 |     } | 
 | 723 |     return plugInId; | 
 | 724 | } | 
 | 725 |  | 
 | 726 | String8 DrmManager::getSupportedPlugInId(const String8& mimeType) { | 
 | 727 |     String8 plugInId(""); | 
 | 728 |  | 
 | 729 |     if (EMPTY_STRING != mimeType) { | 
| Mark Salyzyn | 3ab368e | 2014-04-15 14:55:53 -0700 | [diff] [blame] | 730 |         for (size_t index = 0; index < mSupportInfoToPlugInIdMap.size(); index++) { | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 731 |             const DrmSupportInfo& drmSupportInfo = mSupportInfoToPlugInIdMap.keyAt(index); | 
 | 732 |  | 
 | 733 |             if (drmSupportInfo.isSupportedMimeType(mimeType)) { | 
 | 734 |                 plugInId = mSupportInfoToPlugInIdMap.valueFor(drmSupportInfo); | 
 | 735 |                 break; | 
 | 736 |             } | 
 | 737 |         } | 
 | 738 |     } | 
 | 739 |     return plugInId; | 
 | 740 | } | 
 | 741 |  | 
 | 742 | String8 DrmManager::getSupportedPlugInIdFromPath(int uniqueId, const String8& path) { | 
 | 743 |     String8 plugInId(""); | 
 | 744 |     const String8 fileSuffix = path.getPathExtension(); | 
 | 745 |  | 
| Mark Salyzyn | 3ab368e | 2014-04-15 14:55:53 -0700 | [diff] [blame] | 746 |     for (size_t index = 0; index < mSupportInfoToPlugInIdMap.size(); index++) { | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 747 |         const DrmSupportInfo& drmSupportInfo = mSupportInfoToPlugInIdMap.keyAt(index); | 
 | 748 |  | 
 | 749 |         if (drmSupportInfo.isSupportedFileSuffix(fileSuffix)) { | 
 | 750 |             String8 key = mSupportInfoToPlugInIdMap.valueFor(drmSupportInfo); | 
 | 751 |             IDrmEngine& drmEngine = mPlugInManager.getPlugIn(key); | 
 | 752 |  | 
 | 753 |             if (drmEngine.canHandle(uniqueId, path)) { | 
 | 754 |                 plugInId = key; | 
 | 755 |                 break; | 
 | 756 |             } | 
 | 757 |         } | 
 | 758 |     } | 
 | 759 |     return plugInId; | 
 | 760 | } | 
 | 761 |  | 
 | 762 | void DrmManager::onInfo(const DrmInfoEvent& event) { | 
| Gloria Wang | 0e0a5f9 | 2011-03-11 14:07:21 -0800 | [diff] [blame] | 763 |     Mutex::Autolock _l(mListenerLock); | 
| Mark Salyzyn | 3ab368e | 2014-04-15 14:55:53 -0700 | [diff] [blame] | 764 |     for (size_t index = 0; index < mServiceListeners.size(); index++) { | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 765 |         int uniqueId = mServiceListeners.keyAt(index); | 
 | 766 |  | 
 | 767 |         if (uniqueId == event.getUniqueId()) { | 
 | 768 |             sp<IDrmServiceListener> serviceListener = mServiceListeners.valueFor(uniqueId); | 
 | 769 |             serviceListener->notify(event); | 
 | 770 |         } | 
 | 771 |     } | 
 | 772 | } | 
 | 773 |  |