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