Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2021 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 | |
| 17 | //#define LOG_NDEBUG 0 |
| 18 | #define LOG_TAG "DrmHalAidl" |
| 19 | |
Kyle Zhang | 994023a | 2022-02-09 05:32:12 +0000 | [diff] [blame] | 20 | #include <array> |
| 21 | #include <algorithm> |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 22 | #include <android/binder_auto_utils.h> |
| 23 | #include <android/binder_manager.h> |
| 24 | #include <media/PluginMetricsReporting.h> |
| 25 | #include <media/stagefright/foundation/ADebug.h> |
| 26 | #include <media/stagefright/foundation/AString.h> |
| 27 | #include <media/stagefright/foundation/base64.h> |
| 28 | #include <media/stagefright/foundation/hexdump.h> |
| 29 | #include <mediadrm/DrmHalAidl.h> |
| 30 | #include <mediadrm/DrmSessionManager.h> |
| 31 | #include <mediadrm/DrmUtils.h> |
| 32 | |
Kyle Zhang | 96af957 | 2022-02-05 06:38:53 +0000 | [diff] [blame] | 33 | using ::android::DrmUtils::statusAidlToStatusT; |
Kyle Zhang | 994023a | 2022-02-09 05:32:12 +0000 | [diff] [blame] | 34 | using ::aidl::android::hardware::drm::CryptoSchemes; |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 35 | using ::aidl::android::hardware::drm::DrmMetricNamedValue; |
| 36 | using ::aidl::android::hardware::drm::DrmMetricValue; |
| 37 | using ::aidl::android::hardware::drm::HdcpLevel; |
| 38 | using ::aidl::android::hardware::drm::HdcpLevels; |
| 39 | using ::aidl::android::hardware::drm::KeyRequest; |
| 40 | using ::aidl::android::hardware::drm::KeyRequestType; |
| 41 | using ::aidl::android::hardware::drm::KeySetId; |
| 42 | using ::aidl::android::hardware::drm::KeyStatus; |
| 43 | using ::aidl::android::hardware::drm::KeyStatusType; |
| 44 | using ::aidl::android::hardware::drm::KeyType; |
| 45 | using ::aidl::android::hardware::drm::KeyValue; |
| 46 | using ::aidl::android::hardware::drm::NumberOfSessions; |
| 47 | using ::aidl::android::hardware::drm::OfflineLicenseState; |
| 48 | using ::aidl::android::hardware::drm::OpaqueData; |
| 49 | using ::aidl::android::hardware::drm::ProvideProvisionResponseResult; |
| 50 | using ::aidl::android::hardware::drm::ProvisionRequest; |
| 51 | using ::aidl::android::hardware::drm::SecureStop; |
| 52 | using ::aidl::android::hardware::drm::SecureStopId; |
| 53 | using ::aidl::android::hardware::drm::SecurityLevel; |
| 54 | using ::aidl::android::hardware::drm::Status; |
| 55 | using ::aidl::android::hardware::drm::Uuid; |
| 56 | using DrmMetricGroupAidl = ::aidl::android::hardware::drm::DrmMetricGroup; |
| 57 | using DrmMetricGroupHidl = ::android::hardware::drm::V1_1::DrmMetricGroup; |
| 58 | using DrmMetricAidl = ::aidl::android::hardware::drm::DrmMetric; |
| 59 | using DrmMetricHidl = ::android::hardware::drm::V1_1::DrmMetricGroup::Metric; |
| 60 | using ValueHidl = ::android::hardware::drm::V1_1::DrmMetricGroup::Value; |
| 61 | using AttributeHidl = ::android::hardware::drm::V1_1::DrmMetricGroup::Attribute; |
| 62 | using IDrmPluginAidl = ::aidl::android::hardware::drm::IDrmPlugin; |
| 63 | using EventTypeAidl = ::aidl::android::hardware::drm::EventType; |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 64 | using ::android::hardware::hidl_vec; |
| 65 | |
| 66 | namespace { |
| 67 | |
| 68 | constexpr char kPropertyDeviceUniqueId[] = "deviceUniqueId"; |
| 69 | constexpr char kEqualsSign[] = "="; |
| 70 | |
| 71 | template <typename T> |
| 72 | std::string toBase64StringNoPad(const T* data, size_t size) { |
| 73 | // Note that the base 64 conversion only works with arrays of single-byte |
| 74 | // values. If the source is empty or is not an array of single-byte values, |
| 75 | // return empty string. |
| 76 | if (size == 0 || sizeof(data[0]) != 1) { |
| 77 | return ""; |
| 78 | } |
| 79 | |
| 80 | android::AString outputString; |
| 81 | encodeBase64(data, size, &outputString); |
| 82 | // Remove trailing equals padding if it exists. |
| 83 | while (outputString.size() > 0 && outputString.endsWith(kEqualsSign)) { |
| 84 | outputString.erase(outputString.size() - 1, 1); |
| 85 | } |
| 86 | |
| 87 | return std::string(outputString.c_str(), outputString.size()); |
| 88 | } |
| 89 | |
| 90 | } // anonymous namespace |
| 91 | |
| 92 | namespace android { |
| 93 | |
| 94 | #define INIT_CHECK() \ |
| 95 | { \ |
| 96 | if (mInitCheck != OK) return mInitCheck; \ |
| 97 | } |
| 98 | |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 99 | template <typename Byte = uint8_t> |
| 100 | static std::vector<Byte> toStdVec(const Vector<uint8_t>& vector) { |
| 101 | auto v = reinterpret_cast<const Byte*>(vector.array()); |
| 102 | std::vector<Byte> vec(v, v + vector.size()); |
| 103 | return vec; |
| 104 | } |
| 105 | |
| 106 | static const Vector<uint8_t> toVector(const std::vector<uint8_t>& vec) { |
| 107 | Vector<uint8_t> vector; |
| 108 | vector.appendArray(vec.data(), vec.size()); |
| 109 | return *const_cast<const Vector<uint8_t>*>(&vector); |
| 110 | } |
| 111 | |
| 112 | static String8 toString8(const std::string& string) { |
| 113 | return String8(string.c_str()); |
| 114 | } |
| 115 | |
| 116 | static std::string toStdString(const String8& string8) { |
| 117 | return std::string(string8.string()); |
| 118 | } |
| 119 | |
| 120 | static std::vector<KeyValue> toKeyValueVector(const KeyedVector<String8, String8>& keyedVector) { |
| 121 | std::vector<KeyValue> stdKeyedVector; |
| 122 | for (size_t i = 0; i < keyedVector.size(); i++) { |
| 123 | KeyValue keyValue; |
| 124 | keyValue.key = toStdString(keyedVector.keyAt(i)); |
| 125 | keyValue.value = toStdString(keyedVector.valueAt(i)); |
| 126 | stdKeyedVector.push_back(keyValue); |
| 127 | } |
| 128 | return stdKeyedVector; |
| 129 | } |
| 130 | |
| 131 | static KeyedVector<String8, String8> toKeyedVector(const std::vector<KeyValue>& keyValueVec) { |
| 132 | KeyedVector<String8, String8> keyedVector; |
| 133 | for (size_t i = 0; i < keyValueVec.size(); i++) { |
| 134 | keyedVector.add(toString8(keyValueVec[i].key), toString8(keyValueVec[i].value)); |
| 135 | } |
| 136 | return keyedVector; |
| 137 | } |
| 138 | |
| 139 | static DrmPlugin::KeyRequestType toKeyRequestType(KeyRequestType keyRequestType) { |
| 140 | switch (keyRequestType) { |
| 141 | case KeyRequestType::INITIAL: |
| 142 | return DrmPlugin::kKeyRequestType_Initial; |
| 143 | break; |
| 144 | case KeyRequestType::RENEWAL: |
| 145 | return DrmPlugin::kKeyRequestType_Renewal; |
| 146 | break; |
| 147 | case KeyRequestType::RELEASE: |
| 148 | return DrmPlugin::kKeyRequestType_Release; |
| 149 | break; |
| 150 | case KeyRequestType::NONE: |
| 151 | return DrmPlugin::kKeyRequestType_None; |
| 152 | break; |
| 153 | case KeyRequestType::UPDATE: |
| 154 | return DrmPlugin::kKeyRequestType_Update; |
| 155 | break; |
| 156 | default: |
| 157 | return DrmPlugin::kKeyRequestType_Unknown; |
| 158 | break; |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | static List<Vector<uint8_t>> toSecureStops(const std::vector<SecureStop>& aSecureStops) { |
| 163 | List<Vector<uint8_t>> secureStops; |
| 164 | for (size_t i = 0; i < aSecureStops.size(); i++) { |
| 165 | secureStops.push_back(toVector(aSecureStops[i].opaqueData)); |
| 166 | } |
| 167 | return secureStops; |
| 168 | } |
| 169 | |
| 170 | static List<Vector<uint8_t>> toSecureStopIds(const std::vector<SecureStopId>& aSecureStopIds) { |
| 171 | List<Vector<uint8_t>> secureStopIds; |
| 172 | for (size_t i = 0; i < aSecureStopIds.size(); i++) { |
| 173 | secureStopIds.push_back(toVector(aSecureStopIds[i].secureStopId)); |
| 174 | } |
| 175 | return secureStopIds; |
| 176 | } |
| 177 | |
| 178 | static DrmPlugin::HdcpLevel toHdcpLevel(HdcpLevel level) { |
| 179 | switch (level) { |
| 180 | case HdcpLevel::HDCP_NONE: |
| 181 | return DrmPlugin::kHdcpNone; |
| 182 | case HdcpLevel::HDCP_V1: |
| 183 | return DrmPlugin::kHdcpV1; |
| 184 | case HdcpLevel::HDCP_V2: |
| 185 | return DrmPlugin::kHdcpV2; |
| 186 | case HdcpLevel::HDCP_V2_1: |
| 187 | return DrmPlugin::kHdcpV2_1; |
| 188 | case HdcpLevel::HDCP_V2_2: |
| 189 | return DrmPlugin::kHdcpV2_2; |
| 190 | case HdcpLevel::HDCP_V2_3: |
| 191 | return DrmPlugin::kHdcpV2_3; |
| 192 | case HdcpLevel::HDCP_NO_OUTPUT: |
| 193 | return DrmPlugin::kHdcpNoOutput; |
| 194 | default: |
| 195 | return DrmPlugin::kHdcpLevelUnknown; |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | static DrmPlugin::SecurityLevel toSecurityLevel(SecurityLevel level) { |
| 200 | switch (level) { |
| 201 | case SecurityLevel::SW_SECURE_CRYPTO: |
| 202 | return DrmPlugin::kSecurityLevelSwSecureCrypto; |
| 203 | case SecurityLevel::SW_SECURE_DECODE: |
| 204 | return DrmPlugin::kSecurityLevelSwSecureDecode; |
| 205 | case SecurityLevel::HW_SECURE_CRYPTO: |
| 206 | return DrmPlugin::kSecurityLevelHwSecureCrypto; |
| 207 | case SecurityLevel::HW_SECURE_DECODE: |
| 208 | return DrmPlugin::kSecurityLevelHwSecureDecode; |
| 209 | case SecurityLevel::HW_SECURE_ALL: |
| 210 | return DrmPlugin::kSecurityLevelHwSecureAll; |
| 211 | case SecurityLevel::DEFAULT: |
| 212 | return DrmPlugin::kSecurityLevelMax; |
| 213 | default: |
| 214 | return DrmPlugin::kSecurityLevelUnknown; |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | static SecurityLevel toAidlSecurityLevel(DrmPlugin::SecurityLevel level) { |
| 219 | switch (level) { |
| 220 | case DrmPlugin::kSecurityLevelSwSecureCrypto: |
| 221 | return SecurityLevel::SW_SECURE_CRYPTO; |
| 222 | case DrmPlugin::kSecurityLevelSwSecureDecode: |
| 223 | return SecurityLevel::SW_SECURE_DECODE; |
| 224 | case DrmPlugin::kSecurityLevelHwSecureCrypto: |
| 225 | return SecurityLevel::HW_SECURE_CRYPTO; |
| 226 | case DrmPlugin::kSecurityLevelHwSecureDecode: |
| 227 | return SecurityLevel::HW_SECURE_DECODE; |
| 228 | case DrmPlugin::kSecurityLevelHwSecureAll: |
| 229 | return SecurityLevel::HW_SECURE_ALL; |
| 230 | case DrmPlugin::kSecurityLevelMax: |
| 231 | return SecurityLevel::DEFAULT; |
| 232 | default: |
| 233 | return SecurityLevel::UNKNOWN; |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | static List<Vector<uint8_t>> toKeySetIds(const std::vector<KeySetId>& hKeySetIds) { |
| 238 | List<Vector<uint8_t>> keySetIds; |
| 239 | for (size_t i = 0; i < hKeySetIds.size(); i++) { |
| 240 | keySetIds.push_back(toVector(hKeySetIds[i].keySetId)); |
| 241 | } |
| 242 | return keySetIds; |
| 243 | } |
| 244 | |
Kyle Zhang | fa72c48 | 2022-02-04 03:55:43 +0000 | [diff] [blame] | 245 | static hidl_vec<uint8_t> toHidlVec(const Vector<uint8_t>& vector) { |
| 246 | hidl_vec<uint8_t> vec; |
| 247 | vec.setToExternal(const_cast<uint8_t*>(vector.array()), vector.size()); |
| 248 | return vec; |
| 249 | } |
| 250 | |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 251 | static DrmPlugin::OfflineLicenseState toOfflineLicenseState(OfflineLicenseState licenseState) { |
| 252 | switch (licenseState) { |
| 253 | case OfflineLicenseState::USABLE: |
| 254 | return DrmPlugin::kOfflineLicenseStateUsable; |
| 255 | case OfflineLicenseState::INACTIVE: |
| 256 | return DrmPlugin::kOfflineLicenseStateReleased; |
| 257 | default: |
| 258 | return DrmPlugin::kOfflineLicenseStateUnknown; |
| 259 | } |
| 260 | } |
| 261 | |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 262 | Mutex DrmHalAidl::mLock; |
| 263 | |
| 264 | static hidl_vec<DrmMetricGroupHidl> toDrmMetricGroupHidl(std::vector<DrmMetricGroupAidl> result) { |
Kyle Zhang | fa72c48 | 2022-02-04 03:55:43 +0000 | [diff] [blame] | 265 | std::vector<DrmMetricGroupHidl> resultHidl; |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 266 | for (auto r : result) { |
| 267 | DrmMetricGroupHidl re; |
Kyle Zhang | fa72c48 | 2022-02-04 03:55:43 +0000 | [diff] [blame] | 268 | std::vector<DrmMetricHidl> tmpMetric; |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 269 | for (auto m : r.metrics) { |
| 270 | DrmMetricHidl me; |
| 271 | me.name = m.name; |
Kyle Zhang | fa72c48 | 2022-02-04 03:55:43 +0000 | [diff] [blame] | 272 | std::vector<AttributeHidl> aTmp; |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 273 | for (auto attr : m.attributes) { |
| 274 | AttributeHidl attrHidl; |
| 275 | attrHidl.name = attr.name; |
| 276 | |
| 277 | switch (attr.value.getTag()) { |
| 278 | case DrmMetricValue::Tag::int64Value: |
| 279 | attrHidl.type = DrmMetricGroupHidl::ValueType::INT64_TYPE; |
| 280 | attrHidl.int64Value = attr.value.get<DrmMetricValue::Tag::int64Value>(); |
| 281 | break; |
| 282 | case DrmMetricValue::Tag::doubleValue: |
| 283 | attrHidl.type = DrmMetricGroupHidl::ValueType::DOUBLE_TYPE; |
| 284 | attrHidl.doubleValue = attr.value.get<DrmMetricValue::Tag::doubleValue>(); |
| 285 | break; |
| 286 | case DrmMetricValue::Tag::stringValue: |
| 287 | attrHidl.type = DrmMetricGroupHidl::ValueType::STRING_TYPE; |
| 288 | attrHidl.stringValue = attr.value.get<DrmMetricValue::Tag::stringValue>(); |
| 289 | break; |
| 290 | default: |
| 291 | break; |
| 292 | } |
| 293 | |
| 294 | aTmp.push_back(attrHidl); |
| 295 | } |
| 296 | |
Kyle Zhang | fa72c48 | 2022-02-04 03:55:43 +0000 | [diff] [blame] | 297 | me.attributes = aTmp; |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 298 | |
Kyle Zhang | fa72c48 | 2022-02-04 03:55:43 +0000 | [diff] [blame] | 299 | std::vector<ValueHidl> vTmp; |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 300 | for (auto value : m.values) { |
| 301 | ValueHidl valueHidl; |
| 302 | valueHidl.componentName = value.name; |
| 303 | switch (value.value.getTag()) { |
| 304 | case DrmMetricValue::Tag::int64Value: |
| 305 | valueHidl.type = DrmMetricGroupHidl::ValueType::INT64_TYPE; |
| 306 | valueHidl.int64Value = value.value.get<DrmMetricValue::Tag::int64Value>(); |
| 307 | break; |
| 308 | case DrmMetricValue::Tag::doubleValue: |
| 309 | valueHidl.type = DrmMetricGroupHidl::ValueType::DOUBLE_TYPE; |
| 310 | valueHidl.doubleValue = value.value.get<DrmMetricValue::Tag::doubleValue>(); |
| 311 | break; |
| 312 | case DrmMetricValue::Tag::stringValue: |
| 313 | valueHidl.type = DrmMetricGroupHidl::ValueType::STRING_TYPE; |
| 314 | valueHidl.stringValue = value.value.get<DrmMetricValue::Tag::stringValue>(); |
| 315 | break; |
| 316 | default: |
| 317 | break; |
| 318 | } |
| 319 | |
| 320 | vTmp.push_back(valueHidl); |
| 321 | } |
| 322 | |
Kyle Zhang | fa72c48 | 2022-02-04 03:55:43 +0000 | [diff] [blame] | 323 | me.values = vTmp; |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 324 | tmpMetric.push_back(me); |
| 325 | } |
| 326 | |
Kyle Zhang | fa72c48 | 2022-02-04 03:55:43 +0000 | [diff] [blame] | 327 | re.metrics = tmpMetric; |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 328 | resultHidl.push_back(re); |
| 329 | } |
| 330 | |
Kyle Zhang | fa72c48 | 2022-02-04 03:55:43 +0000 | [diff] [blame] | 331 | return resultHidl; |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | // DrmSessionClient Definition |
| 335 | |
| 336 | struct DrmHalAidl::DrmSessionClient : public aidl::android::media::BnResourceManagerClient { |
| 337 | explicit DrmSessionClient(DrmHalAidl* drm, const Vector<uint8_t>& sessionId) |
| 338 | : mSessionId(sessionId), mDrm(drm) {} |
| 339 | |
| 340 | ::ndk::ScopedAStatus reclaimResource(bool* _aidl_return) override; |
| 341 | ::ndk::ScopedAStatus getName(::std::string* _aidl_return) override; |
| 342 | |
| 343 | const Vector<uint8_t> mSessionId; |
| 344 | |
| 345 | virtual ~DrmSessionClient(); |
| 346 | |
| 347 | private: |
| 348 | wp<DrmHalAidl> mDrm; |
| 349 | |
| 350 | DISALLOW_EVIL_CONSTRUCTORS(DrmSessionClient); |
| 351 | }; |
| 352 | |
| 353 | ::ndk::ScopedAStatus DrmHalAidl::DrmSessionClient::reclaimResource(bool* _aidl_return) { |
| 354 | auto sessionId = mSessionId; |
| 355 | sp<DrmHalAidl> drm = mDrm.promote(); |
| 356 | if (drm == NULL) { |
| 357 | *_aidl_return = true; |
| 358 | return ::ndk::ScopedAStatus::ok(); |
| 359 | } |
| 360 | status_t err = drm->closeSession(sessionId); |
| 361 | if (err != OK) { |
| 362 | *_aidl_return = false; |
| 363 | return ::ndk::ScopedAStatus::ok(); |
| 364 | } |
| 365 | drm->onEvent(EventTypeAidl::SESSION_RECLAIMED, toHidlVec(sessionId), hidl_vec<uint8_t>()); |
| 366 | *_aidl_return = true; |
| 367 | return ::ndk::ScopedAStatus::ok(); |
| 368 | } |
| 369 | |
| 370 | ::ndk::ScopedAStatus DrmHalAidl::DrmSessionClient::getName(::std::string* _aidl_return) { |
| 371 | String8 name; |
| 372 | sp<DrmHalAidl> drm = mDrm.promote(); |
| 373 | if (drm == NULL) { |
| 374 | name.append("<deleted>"); |
| 375 | } else if (drm->getPropertyStringInternal(String8("vendor"), name) != OK || name.isEmpty()) { |
| 376 | name.append("<Get vendor failed or is empty>"); |
| 377 | } |
| 378 | name.append("["); |
| 379 | for (size_t i = 0; i < mSessionId.size(); ++i) { |
| 380 | name.appendFormat("%02x", mSessionId[i]); |
| 381 | } |
| 382 | name.append("]"); |
| 383 | *_aidl_return = name; |
| 384 | return ::ndk::ScopedAStatus::ok(); |
| 385 | } |
| 386 | |
| 387 | DrmHalAidl::DrmSessionClient::~DrmSessionClient() { |
| 388 | DrmSessionManager::Instance()->removeSession(mSessionId); |
| 389 | } |
| 390 | |
| 391 | // DrmHalAidl methods |
| 392 | DrmHalAidl::DrmHalAidl() |
Kyle Zhang | a55209d | 2022-02-03 01:52:46 +0000 | [diff] [blame] | 393 | : mListener(::ndk::SharedRefBase::make<DrmHalListener>(&mMetrics)), |
Kyle Zhang | 994023a | 2022-02-09 05:32:12 +0000 | [diff] [blame] | 394 | mFactories(DrmUtils::makeDrmFactoriesAidl()), |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 395 | mInitCheck((mFactories.size() == 0) ? ERROR_UNSUPPORTED : NO_INIT) {} |
| 396 | |
| 397 | status_t DrmHalAidl::initCheck() const { |
| 398 | return mInitCheck; |
| 399 | } |
| 400 | |
| 401 | DrmHalAidl::~DrmHalAidl() {} |
| 402 | |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 403 | status_t DrmHalAidl::setListener(const sp<IDrmClient>& listener) { |
Kyle Zhang | a55209d | 2022-02-03 01:52:46 +0000 | [diff] [blame] | 404 | mListener->setListener(listener); |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 405 | return NO_ERROR; |
| 406 | } |
| 407 | |
| 408 | status_t DrmHalAidl::isCryptoSchemeSupported(const uint8_t uuid[16], const String8& mimeType, |
| 409 | DrmPlugin::SecurityLevel level, bool* isSupported) { |
| 410 | Mutex::Autolock autoLock(mLock); |
| 411 | *isSupported = false; |
Kyle Zhang | 994023a | 2022-02-09 05:32:12 +0000 | [diff] [blame] | 412 | Uuid uuidAidl = DrmUtils::toAidlUuid(uuid); |
Kyle Zhang | a55209d | 2022-02-03 01:52:46 +0000 | [diff] [blame] | 413 | SecurityLevel levelAidl = toAidlSecurityLevel(level); |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 414 | std::string mimeTypeStr = mimeType.string(); |
Kyle Zhang | a55209d | 2022-02-03 01:52:46 +0000 | [diff] [blame] | 415 | |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 416 | for (ssize_t i = mFactories.size() - 1; i >= 0; i--) { |
Kyle Zhang | 994023a | 2022-02-09 05:32:12 +0000 | [diff] [blame] | 417 | CryptoSchemes schemes{}; |
| 418 | auto err = mFactories[i]->getSupportedCryptoSchemes(&schemes); |
| 419 | if (!err.isOk() || !std::count(schemes.uuids.begin(), schemes.uuids.end(), uuidAidl)) { |
| 420 | continue; |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 421 | } |
Kyle Zhang | 994023a | 2022-02-09 05:32:12 +0000 | [diff] [blame] | 422 | |
| 423 | if (levelAidl != SecurityLevel::DEFAULT && levelAidl != SecurityLevel::UNKNOWN) { |
| 424 | if (levelAidl > schemes.maxLevel || levelAidl < schemes.minLevel) { |
| 425 | continue; |
| 426 | } |
| 427 | } |
| 428 | |
| 429 | if (!mimeTypeStr.empty()) { |
| 430 | if (!std::count(schemes.mimeTypes.begin(), schemes.mimeTypes.end(), mimeTypeStr)) { |
| 431 | continue; |
| 432 | } |
| 433 | } |
| 434 | |
| 435 | *isSupported = true; |
| 436 | break; |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | return OK; |
| 440 | } |
| 441 | |
| 442 | status_t DrmHalAidl::createPlugin(const uint8_t uuid[16], const String8& appPackageName) { |
| 443 | Mutex::Autolock autoLock(mLock); |
| 444 | |
Kyle Zhang | 994023a | 2022-02-09 05:32:12 +0000 | [diff] [blame] | 445 | Uuid uuidAidl = DrmUtils::toAidlUuid(uuid); |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 446 | std::string appPackageNameAidl = toStdString(appPackageName); |
| 447 | std::shared_ptr<IDrmPluginAidl> pluginAidl; |
| 448 | mMetrics.SetAppPackageName(appPackageName); |
| 449 | mMetrics.SetAppUid(AIBinder_getCallingUid()); |
| 450 | for (ssize_t i = mFactories.size() - 1; i >= 0; i--) { |
| 451 | ::ndk::ScopedAStatus status = |
Kyle Zhang | 994023a | 2022-02-09 05:32:12 +0000 | [diff] [blame] | 452 | mFactories[i]->createDrmPlugin(uuidAidl, appPackageNameAidl, &pluginAidl); |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 453 | if (status.isOk()) { |
| 454 | if (pluginAidl != NULL) { |
| 455 | mPlugin = pluginAidl; |
| 456 | break; |
| 457 | } |
| 458 | } else { |
| 459 | DrmUtils::LOG2BE(uuid, "Failed to make drm plugin: %d", |
| 460 | status.getServiceSpecificError()); |
| 461 | } |
| 462 | } |
| 463 | |
| 464 | if (mPlugin == NULL) { |
| 465 | DrmUtils::LOG2BE(uuid, "No supported hal instance found"); |
| 466 | mInitCheck = ERROR_UNSUPPORTED; |
| 467 | } else { |
| 468 | mInitCheck = OK; |
Kyle Zhang | a55209d | 2022-02-03 01:52:46 +0000 | [diff] [blame] | 469 | // Stored pointer mListener upcast to base BnDrmPluginListener |
| 470 | ::ndk::ScopedAStatus status = mPlugin |
| 471 | ->setListener(std::static_pointer_cast<BnDrmPluginListener>(mListener)); |
| 472 | if (!status.isOk()) { |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 473 | mInitCheck = DEAD_OBJECT; |
Kyle Zhang | a55209d | 2022-02-03 01:52:46 +0000 | [diff] [blame] | 474 | ALOGE("setListener failed: ex %d svc err %d", |
| 475 | status.getExceptionCode(), |
| 476 | status.getServiceSpecificError()); |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | if (mInitCheck != OK) { |
| 480 | mPlugin.reset(); |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | return mInitCheck; |
| 485 | } |
| 486 | |
| 487 | status_t DrmHalAidl::openSession(DrmPlugin::SecurityLevel level, Vector<uint8_t>& sessionId) { |
| 488 | Mutex::Autolock autoLock(mLock); |
| 489 | INIT_CHECK(); |
| 490 | |
| 491 | SecurityLevel aSecurityLevel = toAidlSecurityLevel(level); |
| 492 | |
| 493 | if (aSecurityLevel == SecurityLevel::UNKNOWN) { |
| 494 | return ERROR_DRM_CANNOT_HANDLE; |
| 495 | } |
| 496 | |
| 497 | status_t err = UNKNOWN_ERROR; |
| 498 | bool retry = true; |
| 499 | do { |
| 500 | std::vector<uint8_t> aSessionId; |
| 501 | |
| 502 | ::ndk::ScopedAStatus status = mPlugin->openSession(aSecurityLevel, &aSessionId); |
| 503 | if (status.isOk()) sessionId = toVector(aSessionId); |
Kyle Zhang | 96af957 | 2022-02-05 06:38:53 +0000 | [diff] [blame] | 504 | err = statusAidlToStatusT(status); |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 505 | |
| 506 | if (err == ERROR_DRM_RESOURCE_BUSY && retry) { |
| 507 | mLock.unlock(); |
| 508 | // reclaimSession may call back to closeSession, since mLock is |
| 509 | // shared between Drm instances, we should unlock here to avoid |
| 510 | // deadlock. |
| 511 | retry = DrmSessionManager::Instance()->reclaimSession(AIBinder_getCallingPid()); |
| 512 | mLock.lock(); |
| 513 | } else { |
| 514 | retry = false; |
| 515 | } |
| 516 | } while (retry); |
| 517 | |
| 518 | if (err == OK) { |
| 519 | std::shared_ptr<DrmSessionClient> client = |
| 520 | ndk::SharedRefBase::make<DrmSessionClient>(this, sessionId); |
| 521 | DrmSessionManager::Instance()->addSession( |
| 522 | AIBinder_getCallingPid(), std::static_pointer_cast<IResourceManagerClient>(client), |
| 523 | sessionId); |
| 524 | mOpenSessions.push_back(client); |
| 525 | mMetrics.SetSessionStart(sessionId); |
| 526 | } |
| 527 | |
| 528 | mMetrics.mOpenSessionCounter.Increment(err); |
| 529 | return err; |
| 530 | } |
| 531 | |
| 532 | status_t DrmHalAidl::closeSession(Vector<uint8_t> const& sessionId) { |
| 533 | Mutex::Autolock autoLock(mLock); |
| 534 | INIT_CHECK(); |
| 535 | |
| 536 | std::vector<uint8_t> sessionIdAidl = toStdVec(sessionId); |
| 537 | ::ndk::ScopedAStatus status = mPlugin->closeSession(sessionIdAidl); |
Kyle Zhang | 96af957 | 2022-02-05 06:38:53 +0000 | [diff] [blame] | 538 | status_t response = statusAidlToStatusT(status); |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 539 | if (status.isOk()) { |
| 540 | DrmSessionManager::Instance()->removeSession(sessionId); |
| 541 | for (auto i = mOpenSessions.begin(); i != mOpenSessions.end(); i++) { |
| 542 | if (isEqualSessionId((*i)->mSessionId, sessionId)) { |
| 543 | mOpenSessions.erase(i); |
| 544 | break; |
| 545 | } |
| 546 | } |
| 547 | |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 548 | mMetrics.SetSessionEnd(sessionId); |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 549 | } |
Kyle Zhang | fa72c48 | 2022-02-04 03:55:43 +0000 | [diff] [blame] | 550 | |
Kyle Zhang | 96af957 | 2022-02-05 06:38:53 +0000 | [diff] [blame] | 551 | mMetrics.mCloseSessionCounter.Increment(response); |
| 552 | return response; |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 553 | } |
| 554 | |
| 555 | status_t DrmHalAidl::getKeyRequest(Vector<uint8_t> const& sessionId, |
| 556 | Vector<uint8_t> const& initData, String8 const& mimeType, |
| 557 | DrmPlugin::KeyType keyType, |
| 558 | KeyedVector<String8, String8> const& optionalParameters, |
| 559 | Vector<uint8_t>& request, String8& defaultUrl, |
| 560 | DrmPlugin::KeyRequestType* keyRequestType) { |
| 561 | Mutex::Autolock autoLock(mLock); |
| 562 | INIT_CHECK(); |
| 563 | EventTimer<status_t> keyRequestTimer(&mMetrics.mGetKeyRequestTimeUs); |
| 564 | |
| 565 | DrmSessionManager::Instance()->useSession(sessionId); |
| 566 | |
| 567 | KeyType aKeyType; |
| 568 | if (keyType == DrmPlugin::kKeyType_Streaming) { |
| 569 | aKeyType = KeyType::STREAMING; |
| 570 | } else if (keyType == DrmPlugin::kKeyType_Offline) { |
| 571 | aKeyType = KeyType::OFFLINE; |
| 572 | } else if (keyType == DrmPlugin::kKeyType_Release) { |
| 573 | aKeyType = KeyType::RELEASE; |
| 574 | } else { |
| 575 | keyRequestTimer.SetAttribute(BAD_VALUE); |
| 576 | return BAD_VALUE; |
| 577 | } |
| 578 | |
| 579 | status_t err = UNKNOWN_ERROR; |
| 580 | |
| 581 | std::vector<uint8_t> sessionIdAidl = toStdVec(sessionId); |
| 582 | std::vector<uint8_t> initDataAidl = toStdVec(initData); |
| 583 | KeyRequest keyRequest; |
| 584 | |
| 585 | ::ndk::ScopedAStatus status = |
| 586 | mPlugin->getKeyRequest(sessionIdAidl, initDataAidl, toStdString(mimeType), aKeyType, |
| 587 | toKeyValueVector(optionalParameters), &keyRequest); |
| 588 | if (status.isOk()) { |
| 589 | request = toVector(keyRequest.request); |
| 590 | defaultUrl = toString8(keyRequest.defaultUrl); |
| 591 | *keyRequestType = toKeyRequestType(keyRequest.requestType); |
| 592 | } |
| 593 | |
Kyle Zhang | 96af957 | 2022-02-05 06:38:53 +0000 | [diff] [blame] | 594 | err = statusAidlToStatusT(status); |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 595 | keyRequestTimer.SetAttribute(err); |
| 596 | return err; |
| 597 | } |
| 598 | |
| 599 | status_t DrmHalAidl::provideKeyResponse(Vector<uint8_t> const& sessionId, |
| 600 | Vector<uint8_t> const& response, |
| 601 | Vector<uint8_t>& keySetId) { |
| 602 | Mutex::Autolock autoLock(mLock); |
| 603 | INIT_CHECK(); |
| 604 | EventTimer<status_t> keyResponseTimer(&mMetrics.mProvideKeyResponseTimeUs); |
| 605 | |
| 606 | DrmSessionManager::Instance()->useSession(sessionId); |
| 607 | |
| 608 | status_t err = UNKNOWN_ERROR; |
| 609 | |
| 610 | std::vector<uint8_t> sessionIdAidl = toStdVec(sessionId); |
| 611 | std::vector<uint8_t> responseAidl = toStdVec(response); |
| 612 | KeySetId keySetIdsAidl; |
| 613 | ::ndk::ScopedAStatus status = |
| 614 | mPlugin->provideKeyResponse(sessionIdAidl, responseAidl, &keySetIdsAidl); |
| 615 | |
| 616 | if (status.isOk()) keySetId = toVector(keySetIdsAidl.keySetId); |
Kyle Zhang | 96af957 | 2022-02-05 06:38:53 +0000 | [diff] [blame] | 617 | err = statusAidlToStatusT(status); |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 618 | keyResponseTimer.SetAttribute(err); |
| 619 | return err; |
| 620 | } |
| 621 | |
| 622 | status_t DrmHalAidl::removeKeys(Vector<uint8_t> const& keySetId) { |
| 623 | Mutex::Autolock autoLock(mLock); |
| 624 | INIT_CHECK(); |
| 625 | |
| 626 | ::ndk::ScopedAStatus status = mPlugin->removeKeys(toStdVec(keySetId)); |
Kyle Zhang | 96af957 | 2022-02-05 06:38:53 +0000 | [diff] [blame] | 627 | return statusAidlToStatusT(status); |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | status_t DrmHalAidl::restoreKeys(Vector<uint8_t> const& sessionId, |
| 631 | Vector<uint8_t> const& keySetId) { |
| 632 | Mutex::Autolock autoLock(mLock); |
| 633 | INIT_CHECK(); |
| 634 | |
| 635 | DrmSessionManager::Instance()->useSession(sessionId); |
| 636 | |
| 637 | KeySetId keySetIdsAidl; |
| 638 | keySetIdsAidl.keySetId = toStdVec(keySetId); |
| 639 | ::ndk::ScopedAStatus status = mPlugin->restoreKeys(toStdVec(sessionId), keySetIdsAidl); |
Kyle Zhang | 96af957 | 2022-02-05 06:38:53 +0000 | [diff] [blame] | 640 | return statusAidlToStatusT(status); |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | status_t DrmHalAidl::queryKeyStatus(Vector<uint8_t> const& sessionId, |
| 644 | KeyedVector<String8, String8>& infoMap) const { |
| 645 | Mutex::Autolock autoLock(mLock); |
| 646 | INIT_CHECK(); |
| 647 | |
| 648 | DrmSessionManager::Instance()->useSession(sessionId); |
| 649 | |
| 650 | std::vector<KeyValue> infoMapAidl; |
| 651 | ::ndk::ScopedAStatus status = mPlugin->queryKeyStatus(toStdVec(sessionId), &infoMapAidl); |
| 652 | |
| 653 | infoMap = toKeyedVector(infoMapAidl); |
| 654 | |
Kyle Zhang | 96af957 | 2022-02-05 06:38:53 +0000 | [diff] [blame] | 655 | return statusAidlToStatusT(status); |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | status_t DrmHalAidl::getProvisionRequest(String8 const& certType, String8 const& certAuthority, |
| 659 | Vector<uint8_t>& request, String8& defaultUrl) { |
| 660 | Mutex::Autolock autoLock(mLock); |
| 661 | INIT_CHECK(); |
| 662 | |
| 663 | status_t err = UNKNOWN_ERROR; |
| 664 | |
| 665 | ProvisionRequest requestAidl; |
| 666 | ::ndk::ScopedAStatus status = mPlugin->getProvisionRequest( |
| 667 | toStdString(certType), toStdString(certAuthority), &requestAidl); |
| 668 | |
| 669 | request = toVector(requestAidl.request); |
| 670 | defaultUrl = toString8(requestAidl.defaultUrl); |
| 671 | |
Kyle Zhang | 96af957 | 2022-02-05 06:38:53 +0000 | [diff] [blame] | 672 | err = statusAidlToStatusT(status); |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 673 | mMetrics.mGetProvisionRequestCounter.Increment(err); |
| 674 | return err; |
| 675 | } |
| 676 | |
| 677 | status_t DrmHalAidl::provideProvisionResponse(Vector<uint8_t> const& response, |
| 678 | Vector<uint8_t>& certificate, |
| 679 | Vector<uint8_t>& wrappedKey) { |
| 680 | Mutex::Autolock autoLock(mLock); |
| 681 | INIT_CHECK(); |
| 682 | |
| 683 | status_t err = UNKNOWN_ERROR; |
| 684 | ProvideProvisionResponseResult result; |
| 685 | ::ndk::ScopedAStatus status = mPlugin->provideProvisionResponse(toStdVec(response), &result); |
| 686 | |
| 687 | certificate = toVector(result.certificate); |
| 688 | wrappedKey = toVector(result.wrappedKey); |
Kyle Zhang | 96af957 | 2022-02-05 06:38:53 +0000 | [diff] [blame] | 689 | err = statusAidlToStatusT(status); |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 690 | mMetrics.mProvideProvisionResponseCounter.Increment(err); |
| 691 | return err; |
| 692 | } |
| 693 | |
| 694 | status_t DrmHalAidl::getSecureStops(List<Vector<uint8_t>>& secureStops) { |
| 695 | Mutex::Autolock autoLock(mLock); |
| 696 | INIT_CHECK(); |
| 697 | |
| 698 | std::vector<SecureStop> result; |
| 699 | ::ndk::ScopedAStatus status = mPlugin->getSecureStops(&result); |
| 700 | |
| 701 | secureStops = toSecureStops(result); |
| 702 | |
Kyle Zhang | 96af957 | 2022-02-05 06:38:53 +0000 | [diff] [blame] | 703 | return statusAidlToStatusT(status); |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | status_t DrmHalAidl::getSecureStopIds(List<Vector<uint8_t>>& secureStopIds) { |
| 707 | Mutex::Autolock autoLock(mLock); |
| 708 | INIT_CHECK(); |
| 709 | |
| 710 | std::vector<SecureStopId> result; |
| 711 | ::ndk::ScopedAStatus status = mPlugin->getSecureStopIds(&result); |
| 712 | |
| 713 | secureStopIds = toSecureStopIds(result); |
| 714 | |
Kyle Zhang | 96af957 | 2022-02-05 06:38:53 +0000 | [diff] [blame] | 715 | return statusAidlToStatusT(status); |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | status_t DrmHalAidl::getSecureStop(Vector<uint8_t> const& ssid, Vector<uint8_t>& secureStop) { |
| 719 | Mutex::Autolock autoLock(mLock); |
| 720 | INIT_CHECK(); |
| 721 | |
| 722 | SecureStopId ssidAidl; |
| 723 | ssidAidl.secureStopId = toStdVec(ssid); |
| 724 | |
| 725 | SecureStop result; |
| 726 | ::ndk::ScopedAStatus status = mPlugin->getSecureStop(ssidAidl, &result); |
| 727 | |
| 728 | secureStop = toVector(result.opaqueData); |
| 729 | |
Kyle Zhang | 96af957 | 2022-02-05 06:38:53 +0000 | [diff] [blame] | 730 | return statusAidlToStatusT(status); |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 731 | } |
| 732 | |
| 733 | status_t DrmHalAidl::releaseSecureStops(Vector<uint8_t> const& ssRelease) { |
| 734 | Mutex::Autolock autoLock(mLock); |
| 735 | INIT_CHECK(); |
| 736 | |
| 737 | OpaqueData ssId; |
| 738 | ssId.opaqueData = toStdVec(ssRelease); |
| 739 | ::ndk::ScopedAStatus status = mPlugin->releaseSecureStops(ssId); |
| 740 | |
Kyle Zhang | 96af957 | 2022-02-05 06:38:53 +0000 | [diff] [blame] | 741 | return statusAidlToStatusT(status); |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | status_t DrmHalAidl::removeSecureStop(Vector<uint8_t> const& ssid) { |
| 745 | Mutex::Autolock autoLock(mLock); |
| 746 | |
| 747 | INIT_CHECK(); |
| 748 | |
| 749 | SecureStopId ssidAidl; |
| 750 | ssidAidl.secureStopId = toStdVec(ssid); |
| 751 | ::ndk::ScopedAStatus status = mPlugin->removeSecureStop(ssidAidl); |
Kyle Zhang | 96af957 | 2022-02-05 06:38:53 +0000 | [diff] [blame] | 752 | return statusAidlToStatusT(status); |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 753 | } |
| 754 | |
| 755 | status_t DrmHalAidl::removeAllSecureStops() { |
| 756 | Mutex::Autolock autoLock(mLock); |
| 757 | INIT_CHECK(); |
| 758 | |
| 759 | ::ndk::ScopedAStatus status = mPlugin->releaseAllSecureStops(); |
Kyle Zhang | 96af957 | 2022-02-05 06:38:53 +0000 | [diff] [blame] | 760 | return statusAidlToStatusT(status); |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | status_t DrmHalAidl::getHdcpLevels(DrmPlugin::HdcpLevel* connected, |
| 764 | DrmPlugin::HdcpLevel* max) const { |
| 765 | Mutex::Autolock autoLock(mLock); |
| 766 | INIT_CHECK(); |
| 767 | |
| 768 | if (connected == NULL || max == NULL) { |
| 769 | return BAD_VALUE; |
| 770 | } |
| 771 | |
| 772 | *connected = DrmPlugin::kHdcpLevelUnknown; |
| 773 | *max = DrmPlugin::kHdcpLevelUnknown; |
| 774 | |
| 775 | HdcpLevels lvlsAidl; |
| 776 | ::ndk::ScopedAStatus status = mPlugin->getHdcpLevels(&lvlsAidl); |
| 777 | |
| 778 | *connected = toHdcpLevel(lvlsAidl.connectedLevel); |
| 779 | *max = toHdcpLevel(lvlsAidl.maxLevel); |
| 780 | |
Kyle Zhang | 96af957 | 2022-02-05 06:38:53 +0000 | [diff] [blame] | 781 | return statusAidlToStatusT(status); |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | status_t DrmHalAidl::getNumberOfSessions(uint32_t* open, uint32_t* max) const { |
| 785 | Mutex::Autolock autoLock(mLock); |
| 786 | INIT_CHECK(); |
| 787 | |
| 788 | if (open == NULL || max == NULL) { |
| 789 | return BAD_VALUE; |
| 790 | } |
| 791 | |
| 792 | *open = 0; |
| 793 | *max = 0; |
| 794 | |
| 795 | NumberOfSessions result; |
| 796 | ::ndk::ScopedAStatus status = mPlugin->getNumberOfSessions(&result); |
| 797 | |
| 798 | *open = result.currentSessions; |
| 799 | *max = result.maxSessions; |
| 800 | |
Kyle Zhang | 96af957 | 2022-02-05 06:38:53 +0000 | [diff] [blame] | 801 | return statusAidlToStatusT(status); |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 802 | } |
| 803 | |
| 804 | status_t DrmHalAidl::getSecurityLevel(Vector<uint8_t> const& sessionId, |
| 805 | DrmPlugin::SecurityLevel* level) const { |
| 806 | Mutex::Autolock autoLock(mLock); |
| 807 | INIT_CHECK(); |
| 808 | |
| 809 | if (level == NULL) { |
| 810 | return BAD_VALUE; |
| 811 | } |
| 812 | |
| 813 | *level = DrmPlugin::kSecurityLevelUnknown; |
| 814 | |
| 815 | SecurityLevel result; |
| 816 | ::ndk::ScopedAStatus status = mPlugin->getSecurityLevel(toStdVec(sessionId), &result); |
| 817 | |
| 818 | *level = toSecurityLevel(result); |
| 819 | |
Kyle Zhang | 96af957 | 2022-02-05 06:38:53 +0000 | [diff] [blame] | 820 | return statusAidlToStatusT(status); |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 821 | } |
| 822 | |
| 823 | status_t DrmHalAidl::getOfflineLicenseKeySetIds(List<Vector<uint8_t>>& keySetIds) const { |
| 824 | Mutex::Autolock autoLock(mLock); |
| 825 | INIT_CHECK(); |
| 826 | |
| 827 | std::vector<KeySetId> result; |
| 828 | ::ndk::ScopedAStatus status = mPlugin->getOfflineLicenseKeySetIds(&result); |
| 829 | |
| 830 | keySetIds = toKeySetIds(result); |
| 831 | |
Kyle Zhang | 96af957 | 2022-02-05 06:38:53 +0000 | [diff] [blame] | 832 | return statusAidlToStatusT(status); |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 833 | } |
| 834 | |
| 835 | status_t DrmHalAidl::removeOfflineLicense(Vector<uint8_t> const& keySetId) { |
| 836 | Mutex::Autolock autoLock(mLock); |
| 837 | INIT_CHECK(); |
| 838 | |
| 839 | KeySetId keySetIdAidl; |
| 840 | keySetIdAidl.keySetId = toStdVec(keySetId); |
| 841 | ::ndk::ScopedAStatus status = mPlugin->removeOfflineLicense(keySetIdAidl); |
Kyle Zhang | 96af957 | 2022-02-05 06:38:53 +0000 | [diff] [blame] | 842 | return statusAidlToStatusT(status); |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 843 | } |
| 844 | |
| 845 | status_t DrmHalAidl::getOfflineLicenseState(Vector<uint8_t> const& keySetId, |
| 846 | DrmPlugin::OfflineLicenseState* licenseState) const { |
| 847 | Mutex::Autolock autoLock(mLock); |
| 848 | |
| 849 | INIT_CHECK(); |
| 850 | *licenseState = DrmPlugin::kOfflineLicenseStateUnknown; |
| 851 | |
| 852 | KeySetId keySetIdAidl; |
| 853 | keySetIdAidl.keySetId = toStdVec(keySetId); |
| 854 | |
| 855 | OfflineLicenseState result; |
| 856 | ::ndk::ScopedAStatus status = mPlugin->getOfflineLicenseState(keySetIdAidl, &result); |
| 857 | |
| 858 | *licenseState = toOfflineLicenseState(result); |
| 859 | |
Kyle Zhang | 96af957 | 2022-02-05 06:38:53 +0000 | [diff] [blame] | 860 | return statusAidlToStatusT(status); |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 861 | } |
| 862 | |
| 863 | status_t DrmHalAidl::getPropertyString(String8 const& name, String8& value) const { |
| 864 | Mutex::Autolock autoLock(mLock); |
| 865 | return getPropertyStringInternal(name, value); |
| 866 | } |
| 867 | |
| 868 | status_t DrmHalAidl::getPropertyStringInternal(String8 const& name, String8& value) const { |
| 869 | // This function is internal to the class and should only be called while |
| 870 | // mLock is already held. |
| 871 | INIT_CHECK(); |
| 872 | |
| 873 | std::string result; |
| 874 | ::ndk::ScopedAStatus status = mPlugin->getPropertyString(toStdString(name), &result); |
| 875 | |
| 876 | value = toString8(result); |
| 877 | |
Kyle Zhang | 96af957 | 2022-02-05 06:38:53 +0000 | [diff] [blame] | 878 | return statusAidlToStatusT(status); |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 879 | } |
| 880 | |
| 881 | status_t DrmHalAidl::getPropertyByteArray(String8 const& name, Vector<uint8_t>& value) const { |
| 882 | Mutex::Autolock autoLock(mLock); |
| 883 | return getPropertyByteArrayInternal(name, value); |
| 884 | } |
| 885 | |
| 886 | status_t DrmHalAidl::getPropertyByteArrayInternal(String8 const& name, |
| 887 | Vector<uint8_t>& value) const { |
| 888 | // This function is internal to the class and should only be called while |
| 889 | // mLock is already held. |
| 890 | INIT_CHECK(); |
| 891 | |
| 892 | status_t err = UNKNOWN_ERROR; |
| 893 | |
| 894 | std::vector<uint8_t> result; |
| 895 | ::ndk::ScopedAStatus status = mPlugin->getPropertyByteArray(toStdString(name), &result); |
| 896 | |
| 897 | value = toVector(result); |
Kyle Zhang | 96af957 | 2022-02-05 06:38:53 +0000 | [diff] [blame] | 898 | err = statusAidlToStatusT(status); |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 899 | if (name == kPropertyDeviceUniqueId) { |
| 900 | mMetrics.mGetDeviceUniqueIdCounter.Increment(err); |
| 901 | } |
| 902 | return err; |
| 903 | } |
| 904 | |
| 905 | status_t DrmHalAidl::setPropertyString(String8 const& name, String8 const& value) const { |
| 906 | Mutex::Autolock autoLock(mLock); |
| 907 | INIT_CHECK(); |
| 908 | |
| 909 | ::ndk::ScopedAStatus status = mPlugin->setPropertyString(toStdString(name), toStdString(value)); |
Kyle Zhang | 96af957 | 2022-02-05 06:38:53 +0000 | [diff] [blame] | 910 | return statusAidlToStatusT(status); |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 911 | } |
| 912 | |
| 913 | status_t DrmHalAidl::setPropertyByteArray(String8 const& name, Vector<uint8_t> const& value) const { |
| 914 | Mutex::Autolock autoLock(mLock); |
| 915 | INIT_CHECK(); |
| 916 | |
| 917 | ::ndk::ScopedAStatus status = mPlugin->setPropertyByteArray(toStdString(name), toStdVec(value)); |
Kyle Zhang | 96af957 | 2022-02-05 06:38:53 +0000 | [diff] [blame] | 918 | return statusAidlToStatusT(status); |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 919 | } |
| 920 | |
| 921 | status_t DrmHalAidl::getMetrics(const sp<IDrmMetricsConsumer>& consumer) { |
| 922 | if (consumer == nullptr) { |
| 923 | return UNEXPECTED_NULL; |
| 924 | } |
| 925 | consumer->consumeFrameworkMetrics(mMetrics); |
| 926 | |
| 927 | // Append vendor metrics if they are supported. |
| 928 | |
| 929 | String8 vendor; |
| 930 | String8 description; |
| 931 | if (getPropertyStringInternal(String8("vendor"), vendor) != OK || vendor.isEmpty()) { |
| 932 | ALOGE("Get vendor failed or is empty"); |
| 933 | vendor = "NONE"; |
| 934 | } |
| 935 | if (getPropertyStringInternal(String8("description"), description) != OK || |
| 936 | description.isEmpty()) { |
| 937 | ALOGE("Get description failed or is empty."); |
| 938 | description = "NONE"; |
| 939 | } |
| 940 | vendor += "."; |
| 941 | vendor += description; |
| 942 | |
| 943 | hidl_vec<DrmMetricGroupHidl> pluginMetrics; |
| 944 | status_t err = UNKNOWN_ERROR; |
| 945 | |
| 946 | std::vector<DrmMetricGroupAidl> result; |
| 947 | ::ndk::ScopedAStatus status = mPlugin->getMetrics(&result); |
| 948 | |
| 949 | if (status.isOk()) { |
| 950 | pluginMetrics = toDrmMetricGroupHidl(result); |
| 951 | consumer->consumeHidlMetrics(vendor, pluginMetrics); |
| 952 | } |
| 953 | |
Kyle Zhang | 96af957 | 2022-02-05 06:38:53 +0000 | [diff] [blame] | 954 | err = statusAidlToStatusT(status); |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 955 | |
| 956 | return err; |
| 957 | } |
| 958 | |
| 959 | status_t DrmHalAidl::setCipherAlgorithm(Vector<uint8_t> const& sessionId, |
| 960 | String8 const& algorithm) { |
| 961 | Mutex::Autolock autoLock(mLock); |
| 962 | INIT_CHECK(); |
| 963 | |
| 964 | DrmSessionManager::Instance()->useSession(sessionId); |
| 965 | |
| 966 | ::ndk::ScopedAStatus status = |
| 967 | mPlugin->setCipherAlgorithm(toStdVec(sessionId), toStdString(algorithm)); |
Kyle Zhang | 96af957 | 2022-02-05 06:38:53 +0000 | [diff] [blame] | 968 | return statusAidlToStatusT(status); |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 969 | } |
| 970 | |
| 971 | status_t DrmHalAidl::setMacAlgorithm(Vector<uint8_t> const& sessionId, String8 const& algorithm) { |
| 972 | Mutex::Autolock autoLock(mLock); |
| 973 | INIT_CHECK(); |
| 974 | |
| 975 | DrmSessionManager::Instance()->useSession(sessionId); |
| 976 | |
| 977 | ::ndk::ScopedAStatus status = |
| 978 | mPlugin->setMacAlgorithm(toStdVec(sessionId), toStdString(algorithm)); |
Kyle Zhang | 96af957 | 2022-02-05 06:38:53 +0000 | [diff] [blame] | 979 | return statusAidlToStatusT(status); |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 980 | } |
| 981 | |
| 982 | status_t DrmHalAidl::encrypt(Vector<uint8_t> const& sessionId, Vector<uint8_t> const& keyId, |
| 983 | Vector<uint8_t> const& input, Vector<uint8_t> const& iv, |
| 984 | Vector<uint8_t>& output) { |
| 985 | Mutex::Autolock autoLock(mLock); |
| 986 | INIT_CHECK(); |
| 987 | |
| 988 | DrmSessionManager::Instance()->useSession(sessionId); |
| 989 | |
| 990 | std::vector<uint8_t> result; |
| 991 | ::ndk::ScopedAStatus status = mPlugin->encrypt(toStdVec(sessionId), toStdVec(keyId), |
| 992 | toStdVec(input), toStdVec(iv), &result); |
| 993 | |
| 994 | output = toVector(result); |
| 995 | |
Kyle Zhang | 96af957 | 2022-02-05 06:38:53 +0000 | [diff] [blame] | 996 | return statusAidlToStatusT(status); |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 997 | } |
| 998 | |
| 999 | status_t DrmHalAidl::decrypt(Vector<uint8_t> const& sessionId, Vector<uint8_t> const& keyId, |
| 1000 | Vector<uint8_t> const& input, Vector<uint8_t> const& iv, |
| 1001 | Vector<uint8_t>& output) { |
| 1002 | Mutex::Autolock autoLock(mLock); |
| 1003 | INIT_CHECK(); |
| 1004 | |
| 1005 | DrmSessionManager::Instance()->useSession(sessionId); |
| 1006 | |
| 1007 | std::vector<uint8_t> result; |
| 1008 | ::ndk::ScopedAStatus status = mPlugin->decrypt(toStdVec(sessionId), toStdVec(keyId), |
| 1009 | toStdVec(input), toStdVec(iv), &result); |
| 1010 | |
| 1011 | output = toVector(result); |
| 1012 | |
Kyle Zhang | 96af957 | 2022-02-05 06:38:53 +0000 | [diff] [blame] | 1013 | return statusAidlToStatusT(status); |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 1014 | } |
| 1015 | |
| 1016 | status_t DrmHalAidl::sign(Vector<uint8_t> const& sessionId, Vector<uint8_t> const& keyId, |
| 1017 | Vector<uint8_t> const& message, Vector<uint8_t>& signature) { |
| 1018 | Mutex::Autolock autoLock(mLock); |
| 1019 | INIT_CHECK(); |
| 1020 | |
| 1021 | DrmSessionManager::Instance()->useSession(sessionId); |
| 1022 | |
| 1023 | std::vector<uint8_t> result; |
| 1024 | ::ndk::ScopedAStatus status = |
| 1025 | mPlugin->sign(toStdVec(sessionId), toStdVec(keyId), toStdVec(message), &result); |
| 1026 | |
| 1027 | signature = toVector(result); |
| 1028 | |
Kyle Zhang | 96af957 | 2022-02-05 06:38:53 +0000 | [diff] [blame] | 1029 | return statusAidlToStatusT(status); |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 1030 | } |
| 1031 | |
| 1032 | status_t DrmHalAidl::verify(Vector<uint8_t> const& sessionId, Vector<uint8_t> const& keyId, |
| 1033 | Vector<uint8_t> const& message, Vector<uint8_t> const& signature, |
| 1034 | bool& match) { |
| 1035 | Mutex::Autolock autoLock(mLock); |
| 1036 | INIT_CHECK(); |
| 1037 | |
| 1038 | DrmSessionManager::Instance()->useSession(sessionId); |
| 1039 | |
| 1040 | ::ndk::ScopedAStatus status = mPlugin->verify(toStdVec(sessionId), toStdVec(keyId), |
| 1041 | toStdVec(message), toStdVec(signature), &match); |
| 1042 | |
Kyle Zhang | 96af957 | 2022-02-05 06:38:53 +0000 | [diff] [blame] | 1043 | return statusAidlToStatusT(status); |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 1044 | } |
| 1045 | |
| 1046 | status_t DrmHalAidl::signRSA(Vector<uint8_t> const& sessionId, String8 const& algorithm, |
| 1047 | Vector<uint8_t> const& message, Vector<uint8_t> const& wrappedKey, |
| 1048 | Vector<uint8_t>& signature) { |
| 1049 | Mutex::Autolock autoLock(mLock); |
| 1050 | INIT_CHECK(); |
| 1051 | |
| 1052 | DrmSessionManager::Instance()->useSession(sessionId); |
| 1053 | |
| 1054 | std::vector<uint8_t> result; |
| 1055 | ::ndk::ScopedAStatus status = |
| 1056 | mPlugin->signRSA(toStdVec(sessionId), toStdString(algorithm), toStdVec(message), |
| 1057 | toStdVec(wrappedKey), &result); |
| 1058 | |
| 1059 | signature = toVector(result); |
| 1060 | |
Kyle Zhang | 96af957 | 2022-02-05 06:38:53 +0000 | [diff] [blame] | 1061 | return statusAidlToStatusT(status); |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 1062 | } |
| 1063 | |
| 1064 | status_t DrmHalAidl::requiresSecureDecoder(const char* mime, bool* required) const { |
| 1065 | Mutex::Autolock autoLock(mLock); |
| 1066 | INIT_CHECK(); |
| 1067 | |
| 1068 | std::string mimeAidl(mime); |
Kyle Zhang | 994023a | 2022-02-09 05:32:12 +0000 | [diff] [blame] | 1069 | ::ndk::ScopedAStatus status = |
| 1070 | mPlugin->requiresSecureDecoder(mimeAidl, SecurityLevel::DEFAULT, required); |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 1071 | if (!status.isOk()) { |
| 1072 | DrmUtils::LOG2BE("requiresSecureDecoder txn failed: %d", status.getServiceSpecificError()); |
| 1073 | return DEAD_OBJECT; |
| 1074 | } |
| 1075 | |
| 1076 | return OK; |
| 1077 | } |
| 1078 | |
| 1079 | status_t DrmHalAidl::requiresSecureDecoder(const char* mime, DrmPlugin::SecurityLevel securityLevel, |
| 1080 | bool* required) const { |
| 1081 | Mutex::Autolock autoLock(mLock); |
| 1082 | INIT_CHECK(); |
| 1083 | |
| 1084 | auto aLevel = toAidlSecurityLevel(securityLevel); |
| 1085 | std::string mimeAidl(mime); |
| 1086 | ::ndk::ScopedAStatus status = mPlugin->requiresSecureDecoder(mimeAidl, aLevel, required); |
Kyle Zhang | 96af957 | 2022-02-05 06:38:53 +0000 | [diff] [blame] | 1087 | |
| 1088 | status_t err = statusAidlToStatusT(status); |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 1089 | if (!status.isOk()) { |
| 1090 | DrmUtils::LOG2BE("requiresSecureDecoder txn failed: %d", status.getServiceSpecificError()); |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 1091 | } |
| 1092 | |
Kyle Zhang | 96af957 | 2022-02-05 06:38:53 +0000 | [diff] [blame] | 1093 | return err; |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 1094 | } |
| 1095 | |
| 1096 | status_t DrmHalAidl::setPlaybackId(Vector<uint8_t> const& sessionId, const char* playbackId) { |
| 1097 | Mutex::Autolock autoLock(mLock); |
| 1098 | INIT_CHECK(); |
| 1099 | std::string playbackIdAidl(playbackId); |
| 1100 | ::ndk::ScopedAStatus status = mPlugin->setPlaybackId(toStdVec(sessionId), playbackIdAidl); |
Kyle Zhang | 96af957 | 2022-02-05 06:38:53 +0000 | [diff] [blame] | 1101 | return statusAidlToStatusT(status); |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 1102 | } |
| 1103 | |
| 1104 | status_t DrmHalAidl::getLogMessages(Vector<drm::V1_4::LogMessage>& logs) const { |
| 1105 | Mutex::Autolock autoLock(mLock); |
| 1106 | return DrmUtils::GetLogMessagesAidl<IDrmPluginAidl>(mPlugin, logs); |
| 1107 | } |
| 1108 | |
| 1109 | void DrmHalAidl::closeOpenSessions() { |
| 1110 | Mutex::Autolock autoLock(mLock); |
| 1111 | auto openSessions = mOpenSessions; |
| 1112 | for (size_t i = 0; i < openSessions.size(); i++) { |
| 1113 | mLock.unlock(); |
| 1114 | closeSession(openSessions[i]->mSessionId); |
| 1115 | mLock.lock(); |
| 1116 | } |
| 1117 | mOpenSessions.clear(); |
| 1118 | } |
| 1119 | |
| 1120 | std::string DrmHalAidl::reportPluginMetrics() const { |
| 1121 | Vector<uint8_t> metricsVector; |
| 1122 | String8 vendor; |
| 1123 | String8 description; |
| 1124 | std::string metricsString; |
| 1125 | if (getPropertyStringInternal(String8("vendor"), vendor) == OK && |
| 1126 | getPropertyStringInternal(String8("description"), description) == OK && |
| 1127 | getPropertyByteArrayInternal(String8("metrics"), metricsVector) == OK) { |
| 1128 | metricsString = toBase64StringNoPad(metricsVector.array(), metricsVector.size()); |
| 1129 | status_t res = android::reportDrmPluginMetrics(metricsString, vendor, description, |
| 1130 | mMetrics.GetAppUid()); |
| 1131 | if (res != OK) { |
| 1132 | ALOGE("Metrics were retrieved but could not be reported: %d", res); |
| 1133 | } |
| 1134 | } |
| 1135 | return metricsString; |
| 1136 | } |
| 1137 | |
| 1138 | std::string DrmHalAidl::reportFrameworkMetrics(const std::string& pluginMetrics) const { |
| 1139 | mediametrics_handle_t item(mediametrics_create("mediadrm")); |
| 1140 | mediametrics_setUid(item, mMetrics.GetAppUid()); |
| 1141 | String8 vendor; |
| 1142 | String8 description; |
| 1143 | status_t result = getPropertyStringInternal(String8("vendor"), vendor); |
| 1144 | if (result != OK) { |
| 1145 | ALOGE("Failed to get vendor from drm plugin: %d", result); |
| 1146 | } else { |
| 1147 | mediametrics_setCString(item, "vendor", vendor.c_str()); |
| 1148 | } |
| 1149 | result = getPropertyStringInternal(String8("description"), description); |
| 1150 | if (result != OK) { |
| 1151 | ALOGE("Failed to get description from drm plugin: %d", result); |
| 1152 | } else { |
| 1153 | mediametrics_setCString(item, "description", description.c_str()); |
| 1154 | } |
| 1155 | |
| 1156 | std::string serializedMetrics; |
| 1157 | result = mMetrics.GetSerializedMetrics(&serializedMetrics); |
| 1158 | if (result != OK) { |
| 1159 | ALOGE("Failed to serialize framework metrics: %d", result); |
| 1160 | } |
| 1161 | std::string b64EncodedMetrics = |
| 1162 | toBase64StringNoPad(serializedMetrics.data(), serializedMetrics.size()); |
| 1163 | if (!b64EncodedMetrics.empty()) { |
| 1164 | mediametrics_setCString(item, "serialized_metrics", b64EncodedMetrics.c_str()); |
| 1165 | } |
| 1166 | if (!pluginMetrics.empty()) { |
| 1167 | mediametrics_setCString(item, "plugin_metrics", pluginMetrics.c_str()); |
| 1168 | } |
| 1169 | if (!mediametrics_selfRecord(item)) { |
| 1170 | ALOGE("Failed to self record framework metrics"); |
| 1171 | } |
| 1172 | mediametrics_delete(item); |
| 1173 | return serializedMetrics; |
| 1174 | } |
| 1175 | |
| 1176 | void DrmHalAidl::cleanup() { |
| 1177 | closeOpenSessions(); |
| 1178 | |
| 1179 | Mutex::Autolock autoLock(mLock); |
| 1180 | reportFrameworkMetrics(reportPluginMetrics()); |
| 1181 | |
| 1182 | setListener(NULL); |
| 1183 | mInitCheck = NO_INIT; |
| 1184 | if (mPlugin != NULL) { |
| 1185 | if (!mPlugin->setListener(NULL).isOk()) { |
| 1186 | mInitCheck = DEAD_OBJECT; |
| 1187 | } |
| 1188 | } |
| 1189 | |
| 1190 | mPlugin.reset(); |
| 1191 | } |
| 1192 | |
| 1193 | status_t DrmHalAidl::destroyPlugin() { |
| 1194 | cleanup(); |
| 1195 | return OK; |
| 1196 | } |
| 1197 | |
| 1198 | ::ndk::ScopedAStatus DrmHalAidl::onEvent(EventTypeAidl eventTypeAidl, |
| 1199 | const std::vector<uint8_t>& sessionId, |
| 1200 | const std::vector<uint8_t>& data) { |
Kyle Zhang | a55209d | 2022-02-03 01:52:46 +0000 | [diff] [blame] | 1201 | return mListener->onEvent(eventTypeAidl, sessionId, data); |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 1202 | } |
| 1203 | |
| 1204 | ::ndk::ScopedAStatus DrmHalAidl::onExpirationUpdate(const std::vector<uint8_t>& sessionId, |
| 1205 | int64_t expiryTimeInMS) { |
Kyle Zhang | a55209d | 2022-02-03 01:52:46 +0000 | [diff] [blame] | 1206 | return mListener->onExpirationUpdate(sessionId, expiryTimeInMS); |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 1207 | } |
| 1208 | |
| 1209 | ::ndk::ScopedAStatus DrmHalAidl::onKeysChange(const std::vector<uint8_t>& sessionId, |
| 1210 | const std::vector<KeyStatus>& keyStatusListAidl, |
| 1211 | bool hasNewUsableKey) { |
Kyle Zhang | a55209d | 2022-02-03 01:52:46 +0000 | [diff] [blame] | 1212 | return mListener->onKeysChange(sessionId, keyStatusListAidl, hasNewUsableKey); |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 1213 | } |
| 1214 | |
| 1215 | ::ndk::ScopedAStatus DrmHalAidl::onSessionLostState(const std::vector<uint8_t>& sessionId) { |
Kyle Zhang | a55209d | 2022-02-03 01:52:46 +0000 | [diff] [blame] | 1216 | return mListener->onSessionLostState(sessionId); |
Kyle Zhang | 6605add | 2022-01-13 17:51:23 +0000 | [diff] [blame] | 1217 | } |
| 1218 | |
| 1219 | } // namespace android |