Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 "DrmHal" |
Adam Stone | fb679e3 | 2018-02-07 10:25:48 -0800 | [diff] [blame] | 19 | #include <iomanip> |
| 20 | |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 21 | #include <utils/Log.h> |
| 22 | |
Robert Shih | 6152d7c | 2019-11-19 22:54:27 -0800 | [diff] [blame] | 23 | #include <android/binder_manager.h> |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 24 | |
Robert Shih | 0f3a8a0 | 2019-11-14 15:43:39 -0800 | [diff] [blame] | 25 | #include <aidl/android/media/BnResourceManagerClient.h> |
Jeff Tinker | c8baaba | 2018-10-23 11:32:36 -0700 | [diff] [blame] | 26 | #include <android/hardware/drm/1.2/types.h> |
Peter Kalauskas | ca5642c | 2018-11-12 12:34:42 -0800 | [diff] [blame] | 27 | #include <android/hidl/manager/1.2/IServiceManager.h> |
Jeff Tinker | 593111f | 2017-05-25 16:00:21 -0700 | [diff] [blame] | 28 | #include <hidl/ServiceManagement.h> |
Adam Stone | f0e618d | 2018-01-17 19:20:41 -0800 | [diff] [blame] | 29 | #include <media/EventMetric.h> |
Robert Shih | 82ea6be | 2019-11-07 17:47:23 -0800 | [diff] [blame] | 30 | #include <media/MediaMetrics.h> |
John W. Bruce | 33ecc4f | 2017-04-03 16:49:05 -0700 | [diff] [blame] | 31 | #include <media/PluginMetricsReporting.h> |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 32 | #include <media/drm/DrmAPI.h> |
| 33 | #include <media/stagefright/foundation/ADebug.h> |
| 34 | #include <media/stagefright/foundation/AString.h> |
Adam Stone | 32494f5 | 2018-02-26 22:53:27 -0800 | [diff] [blame] | 35 | #include <media/stagefright/foundation/base64.h> |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 36 | #include <media/stagefright/foundation/hexdump.h> |
| 37 | #include <media/stagefright/MediaErrors.h> |
Jeff Tinker | 7d2c6e8 | 2018-02-16 16:14:59 -0800 | [diff] [blame] | 38 | #include <mediadrm/DrmHal.h> |
| 39 | #include <mediadrm/DrmSessionClientInterface.h> |
| 40 | #include <mediadrm/DrmSessionManager.h> |
Robert Shih | 9353881 | 2019-11-12 12:21:35 -0800 | [diff] [blame] | 41 | #include <mediadrm/IDrmMetricsConsumer.h> |
Robert Shih | c0d1d0e | 2019-11-24 13:21:04 -0800 | [diff] [blame] | 42 | #include <mediadrm/DrmUtils.h> |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 43 | |
Robert Shih | 61e1c76 | 2019-10-31 21:26:58 -0700 | [diff] [blame] | 44 | #include <vector> |
| 45 | |
Jeff Tinker | 6d998b6 | 2017-12-18 14:37:43 -0800 | [diff] [blame] | 46 | using drm::V1_0::KeyedVector; |
Jeff Tinker | b8684f3 | 2018-12-12 08:41:31 -0800 | [diff] [blame] | 47 | using drm::V1_0::KeyRequestType; |
Jeff Tinker | 6d998b6 | 2017-12-18 14:37:43 -0800 | [diff] [blame] | 48 | using drm::V1_0::KeyType; |
| 49 | using drm::V1_0::KeyValue; |
Jeff Tinker | 6d998b6 | 2017-12-18 14:37:43 -0800 | [diff] [blame] | 50 | using drm::V1_0::SecureStop; |
Jeff Tinker | 15177d7 | 2018-01-25 12:57:55 -0800 | [diff] [blame] | 51 | using drm::V1_0::SecureStopId; |
Jeff Tinker | 6d998b6 | 2017-12-18 14:37:43 -0800 | [diff] [blame] | 52 | using drm::V1_0::Status; |
Jeff Tinker | c8baaba | 2018-10-23 11:32:36 -0700 | [diff] [blame] | 53 | using drm::V1_1::HdcpLevel; |
| 54 | using drm::V1_1::SecureStopRelease; |
| 55 | using drm::V1_1::SecurityLevel; |
| 56 | using drm::V1_2::KeySetId; |
Robert Shih | a503326 | 2019-05-06 14:15:12 -0700 | [diff] [blame] | 57 | using drm::V1_2::KeyStatusType; |
Robert Shih | 5944a0b | 2021-02-10 04:26:33 -0800 | [diff] [blame] | 58 | using ::android::DrmUtils::toStatusT; |
Adam Stone | 28f27c3 | 2018-02-05 15:07:48 -0800 | [diff] [blame] | 59 | using ::android::hardware::drm::V1_1::DrmMetricGroup; |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 60 | using ::android::hardware::hidl_array; |
| 61 | using ::android::hardware::hidl_string; |
| 62 | using ::android::hardware::hidl_vec; |
| 63 | using ::android::hardware::Return; |
| 64 | using ::android::hardware::Void; |
Adam Stone | 637b785 | 2018-01-30 12:09:36 -0800 | [diff] [blame] | 65 | using ::android::os::PersistableBundle; |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 66 | using ::android::sp; |
| 67 | |
Jeff Tinker | b8684f3 | 2018-12-12 08:41:31 -0800 | [diff] [blame] | 68 | typedef drm::V1_1::KeyRequestType KeyRequestType_V1_1; |
| 69 | typedef drm::V1_2::Status Status_V1_2; |
Jeff Tinker | 44c2cc4 | 2019-01-14 10:24:18 -0800 | [diff] [blame] | 70 | typedef drm::V1_2::HdcpLevel HdcpLevel_V1_2; |
Jeff Tinker | b8684f3 | 2018-12-12 08:41:31 -0800 | [diff] [blame] | 71 | |
Adam Stone | cea91ce | 2018-01-22 19:23:28 -0800 | [diff] [blame] | 72 | namespace { |
| 73 | |
| 74 | // This constant corresponds to the PROPERTY_DEVICE_UNIQUE_ID constant |
| 75 | // in the MediaDrm API. |
| 76 | constexpr char kPropertyDeviceUniqueId[] = "deviceUniqueId"; |
Adam Stone | 32494f5 | 2018-02-26 22:53:27 -0800 | [diff] [blame] | 77 | constexpr char kEqualsSign[] = "="; |
Adam Stone | cea91ce | 2018-01-22 19:23:28 -0800 | [diff] [blame] | 78 | |
Adam Stone | 32494f5 | 2018-02-26 22:53:27 -0800 | [diff] [blame] | 79 | template<typename T> |
| 80 | std::string toBase64StringNoPad(const T* data, size_t size) { |
Adam Stone | 630092e | 2018-05-02 13:06:34 -0700 | [diff] [blame] | 81 | // Note that the base 64 conversion only works with arrays of single-byte |
| 82 | // values. If the source is empty or is not an array of single-byte values, |
| 83 | // return empty string. |
| 84 | if (size == 0 || sizeof(data[0]) != 1) { |
Adam Stone | 32494f5 | 2018-02-26 22:53:27 -0800 | [diff] [blame] | 85 | return ""; |
| 86 | } |
Adam Stone | 32494f5 | 2018-02-26 22:53:27 -0800 | [diff] [blame] | 87 | |
| 88 | android::AString outputString; |
| 89 | encodeBase64(data, size, &outputString); |
| 90 | // Remove trailing equals padding if it exists. |
| 91 | while (outputString.size() > 0 && outputString.endsWith(kEqualsSign)) { |
| 92 | outputString.erase(outputString.size() - 1, 1); |
| 93 | } |
| 94 | |
| 95 | return std::string(outputString.c_str(), outputString.size()); |
Adam Stone | cea91ce | 2018-01-22 19:23:28 -0800 | [diff] [blame] | 96 | } |
| 97 | |
Adam Stone | 32494f5 | 2018-02-26 22:53:27 -0800 | [diff] [blame] | 98 | } // anonymous namespace |
| 99 | |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 100 | namespace android { |
| 101 | |
Jeff Tinker | 6d998b6 | 2017-12-18 14:37:43 -0800 | [diff] [blame] | 102 | #define INIT_CHECK() {if (mInitCheck != OK) return mInitCheck;} |
| 103 | |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 104 | static const Vector<uint8_t> toVector(const hidl_vec<uint8_t> &vec) { |
| 105 | Vector<uint8_t> vector; |
| 106 | vector.appendArray(vec.data(), vec.size()); |
| 107 | return *const_cast<const Vector<uint8_t> *>(&vector); |
| 108 | } |
| 109 | |
| 110 | static hidl_vec<uint8_t> toHidlVec(const Vector<uint8_t> &vector) { |
| 111 | hidl_vec<uint8_t> vec; |
| 112 | vec.setToExternal(const_cast<uint8_t *>(vector.array()), vector.size()); |
| 113 | return vec; |
| 114 | } |
| 115 | |
| 116 | static String8 toString8(const hidl_string &string) { |
| 117 | return String8(string.c_str()); |
| 118 | } |
| 119 | |
| 120 | static hidl_string toHidlString(const String8& string) { |
| 121 | return hidl_string(string.string()); |
| 122 | } |
| 123 | |
Jeff Tinker | 6d998b6 | 2017-12-18 14:37:43 -0800 | [diff] [blame] | 124 | static DrmPlugin::SecurityLevel toSecurityLevel(SecurityLevel level) { |
| 125 | switch(level) { |
| 126 | case SecurityLevel::SW_SECURE_CRYPTO: |
| 127 | return DrmPlugin::kSecurityLevelSwSecureCrypto; |
| 128 | case SecurityLevel::SW_SECURE_DECODE: |
| 129 | return DrmPlugin::kSecurityLevelSwSecureDecode; |
| 130 | case SecurityLevel::HW_SECURE_CRYPTO: |
| 131 | return DrmPlugin::kSecurityLevelHwSecureCrypto; |
| 132 | case SecurityLevel::HW_SECURE_DECODE: |
| 133 | return DrmPlugin::kSecurityLevelHwSecureDecode; |
| 134 | case SecurityLevel::HW_SECURE_ALL: |
| 135 | return DrmPlugin::kSecurityLevelHwSecureAll; |
| 136 | default: |
| 137 | return DrmPlugin::kSecurityLevelUnknown; |
| 138 | } |
| 139 | } |
| 140 | |
Jeff Tinker | 99dbfa8 | 2019-01-17 17:27:06 -0800 | [diff] [blame] | 141 | static SecurityLevel toHidlSecurityLevel(DrmPlugin::SecurityLevel level) { |
| 142 | switch(level) { |
| 143 | case DrmPlugin::kSecurityLevelSwSecureCrypto: |
| 144 | return SecurityLevel::SW_SECURE_CRYPTO; |
| 145 | case DrmPlugin::kSecurityLevelSwSecureDecode: |
| 146 | return SecurityLevel::SW_SECURE_DECODE; |
| 147 | case DrmPlugin::kSecurityLevelHwSecureCrypto: |
| 148 | return SecurityLevel::HW_SECURE_CRYPTO; |
| 149 | case DrmPlugin::kSecurityLevelHwSecureDecode: |
| 150 | return SecurityLevel::HW_SECURE_DECODE; |
| 151 | case DrmPlugin::kSecurityLevelHwSecureAll: |
| 152 | return SecurityLevel::HW_SECURE_ALL; |
| 153 | default: |
| 154 | return SecurityLevel::UNKNOWN; |
| 155 | } |
| 156 | } |
| 157 | |
Jeff Tinker | c8baaba | 2018-10-23 11:32:36 -0700 | [diff] [blame] | 158 | static DrmPlugin::OfflineLicenseState toOfflineLicenseState( |
| 159 | OfflineLicenseState licenseState) { |
| 160 | switch(licenseState) { |
| 161 | case OfflineLicenseState::USABLE: |
| 162 | return DrmPlugin::kOfflineLicenseStateUsable; |
| 163 | case OfflineLicenseState::INACTIVE: |
Jeff Tinker | 9a95b0f | 2019-01-30 17:39:20 -0800 | [diff] [blame] | 164 | return DrmPlugin::kOfflineLicenseStateReleased; |
Jeff Tinker | c8baaba | 2018-10-23 11:32:36 -0700 | [diff] [blame] | 165 | default: |
| 166 | return DrmPlugin::kOfflineLicenseStateUnknown; |
| 167 | } |
| 168 | } |
| 169 | |
Jeff Tinker | 44c2cc4 | 2019-01-14 10:24:18 -0800 | [diff] [blame] | 170 | static DrmPlugin::HdcpLevel toHdcpLevel(HdcpLevel_V1_2 level) { |
Jeff Tinker | 6d998b6 | 2017-12-18 14:37:43 -0800 | [diff] [blame] | 171 | switch(level) { |
Jeff Tinker | 44c2cc4 | 2019-01-14 10:24:18 -0800 | [diff] [blame] | 172 | case HdcpLevel_V1_2::HDCP_NONE: |
Jeff Tinker | 6d998b6 | 2017-12-18 14:37:43 -0800 | [diff] [blame] | 173 | return DrmPlugin::kHdcpNone; |
Jeff Tinker | 44c2cc4 | 2019-01-14 10:24:18 -0800 | [diff] [blame] | 174 | case HdcpLevel_V1_2::HDCP_V1: |
Jeff Tinker | 6d998b6 | 2017-12-18 14:37:43 -0800 | [diff] [blame] | 175 | return DrmPlugin::kHdcpV1; |
Jeff Tinker | 44c2cc4 | 2019-01-14 10:24:18 -0800 | [diff] [blame] | 176 | case HdcpLevel_V1_2::HDCP_V2: |
Jeff Tinker | 6d998b6 | 2017-12-18 14:37:43 -0800 | [diff] [blame] | 177 | return DrmPlugin::kHdcpV2; |
Jeff Tinker | 44c2cc4 | 2019-01-14 10:24:18 -0800 | [diff] [blame] | 178 | case HdcpLevel_V1_2::HDCP_V2_1: |
Jeff Tinker | 6d998b6 | 2017-12-18 14:37:43 -0800 | [diff] [blame] | 179 | return DrmPlugin::kHdcpV2_1; |
Jeff Tinker | 44c2cc4 | 2019-01-14 10:24:18 -0800 | [diff] [blame] | 180 | case HdcpLevel_V1_2::HDCP_V2_2: |
Jeff Tinker | 6d998b6 | 2017-12-18 14:37:43 -0800 | [diff] [blame] | 181 | return DrmPlugin::kHdcpV2_2; |
Jeff Tinker | 44c2cc4 | 2019-01-14 10:24:18 -0800 | [diff] [blame] | 182 | case HdcpLevel_V1_2::HDCP_V2_3: |
| 183 | return DrmPlugin::kHdcpV2_3; |
| 184 | case HdcpLevel_V1_2::HDCP_NO_OUTPUT: |
Jeff Tinker | 6d998b6 | 2017-12-18 14:37:43 -0800 | [diff] [blame] | 185 | return DrmPlugin::kHdcpNoOutput; |
| 186 | default: |
| 187 | return DrmPlugin::kHdcpLevelUnknown; |
| 188 | } |
| 189 | } |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 190 | static ::KeyedVector toHidlKeyedVector(const KeyedVector<String8, String8>& |
| 191 | keyedVector) { |
| 192 | std::vector<KeyValue> stdKeyedVector; |
| 193 | for (size_t i = 0; i < keyedVector.size(); i++) { |
| 194 | KeyValue keyValue; |
| 195 | keyValue.key = toHidlString(keyedVector.keyAt(i)); |
| 196 | keyValue.value = toHidlString(keyedVector.valueAt(i)); |
| 197 | stdKeyedVector.push_back(keyValue); |
| 198 | } |
| 199 | return ::KeyedVector(stdKeyedVector); |
| 200 | } |
| 201 | |
| 202 | static KeyedVector<String8, String8> toKeyedVector(const ::KeyedVector& |
| 203 | hKeyedVector) { |
| 204 | KeyedVector<String8, String8> keyedVector; |
| 205 | for (size_t i = 0; i < hKeyedVector.size(); i++) { |
| 206 | keyedVector.add(toString8(hKeyedVector[i].key), |
| 207 | toString8(hKeyedVector[i].value)); |
| 208 | } |
| 209 | return keyedVector; |
| 210 | } |
| 211 | |
Jeff Tinker | abeb36a | 2017-02-17 09:42:46 -0800 | [diff] [blame] | 212 | static List<Vector<uint8_t>> toSecureStops(const hidl_vec<SecureStop>& |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 213 | hSecureStops) { |
Jeff Tinker | abeb36a | 2017-02-17 09:42:46 -0800 | [diff] [blame] | 214 | List<Vector<uint8_t>> secureStops; |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 215 | for (size_t i = 0; i < hSecureStops.size(); i++) { |
| 216 | secureStops.push_back(toVector(hSecureStops[i].opaqueData)); |
| 217 | } |
| 218 | return secureStops; |
| 219 | } |
| 220 | |
Jeff Tinker | 15177d7 | 2018-01-25 12:57:55 -0800 | [diff] [blame] | 221 | static List<Vector<uint8_t>> toSecureStopIds(const hidl_vec<SecureStopId>& |
| 222 | hSecureStopIds) { |
| 223 | List<Vector<uint8_t>> secureStopIds; |
| 224 | for (size_t i = 0; i < hSecureStopIds.size(); i++) { |
| 225 | secureStopIds.push_back(toVector(hSecureStopIds[i])); |
| 226 | } |
| 227 | return secureStopIds; |
| 228 | } |
| 229 | |
Jeff Tinker | c8baaba | 2018-10-23 11:32:36 -0700 | [diff] [blame] | 230 | static List<Vector<uint8_t>> toKeySetIds(const hidl_vec<KeySetId>& |
| 231 | hKeySetIds) { |
| 232 | List<Vector<uint8_t>> keySetIds; |
| 233 | for (size_t i = 0; i < hKeySetIds.size(); i++) { |
| 234 | keySetIds.push_back(toVector(hKeySetIds[i])); |
| 235 | } |
| 236 | return keySetIds; |
| 237 | } |
| 238 | |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 239 | Mutex DrmHal::mLock; |
| 240 | |
Robert Shih | 0f3a8a0 | 2019-11-14 15:43:39 -0800 | [diff] [blame] | 241 | struct DrmHal::DrmSessionClient : public aidl::android::media::BnResourceManagerClient { |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 242 | explicit DrmSessionClient(DrmHal* drm, const Vector<uint8_t>& sessionId) |
| 243 | : mSessionId(sessionId), |
| 244 | mDrm(drm) {} |
| 245 | |
Robert Shih | 0f3a8a0 | 2019-11-14 15:43:39 -0800 | [diff] [blame] | 246 | ::ndk::ScopedAStatus reclaimResource(bool* _aidl_return) override; |
| 247 | ::ndk::ScopedAStatus getName(::std::string* _aidl_return) override; |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 248 | |
| 249 | const Vector<uint8_t> mSessionId; |
| 250 | |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 251 | virtual ~DrmSessionClient(); |
| 252 | |
| 253 | private: |
| 254 | wp<DrmHal> mDrm; |
| 255 | |
| 256 | DISALLOW_EVIL_CONSTRUCTORS(DrmSessionClient); |
| 257 | }; |
| 258 | |
Robert Shih | 0f3a8a0 | 2019-11-14 15:43:39 -0800 | [diff] [blame] | 259 | ::ndk::ScopedAStatus DrmHal::DrmSessionClient::reclaimResource(bool* _aidl_return) { |
| 260 | auto sessionId = mSessionId; |
Robert Shih | c3af31b | 2019-09-20 21:45:01 -0700 | [diff] [blame] | 261 | sp<DrmHal> drm = mDrm.promote(); |
| 262 | if (drm == NULL) { |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 263 | *_aidl_return = true; |
Robert Shih | 0f3a8a0 | 2019-11-14 15:43:39 -0800 | [diff] [blame] | 264 | return ::ndk::ScopedAStatus::ok(); |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 265 | } |
Robert Shih | 0f3a8a0 | 2019-11-14 15:43:39 -0800 | [diff] [blame] | 266 | status_t err = drm->closeSession(sessionId); |
Robert Shih | c3af31b | 2019-09-20 21:45:01 -0700 | [diff] [blame] | 267 | if (err != OK) { |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 268 | *_aidl_return = false; |
Robert Shih | 0f3a8a0 | 2019-11-14 15:43:39 -0800 | [diff] [blame] | 269 | return ::ndk::ScopedAStatus::ok(); |
Robert Shih | c3af31b | 2019-09-20 21:45:01 -0700 | [diff] [blame] | 270 | } |
| 271 | drm->sendEvent(EventType::SESSION_RECLAIMED, |
Robert Shih | 0f3a8a0 | 2019-11-14 15:43:39 -0800 | [diff] [blame] | 272 | toHidlVec(sessionId), hidl_vec<uint8_t>()); |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 273 | *_aidl_return = true; |
Robert Shih | 0f3a8a0 | 2019-11-14 15:43:39 -0800 | [diff] [blame] | 274 | return ::ndk::ScopedAStatus::ok(); |
Robert Shih | c3af31b | 2019-09-20 21:45:01 -0700 | [diff] [blame] | 275 | } |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 276 | |
Robert Shih | 0f3a8a0 | 2019-11-14 15:43:39 -0800 | [diff] [blame] | 277 | ::ndk::ScopedAStatus DrmHal::DrmSessionClient::getName(::std::string* _aidl_return) { |
Robert Shih | c3af31b | 2019-09-20 21:45:01 -0700 | [diff] [blame] | 278 | String8 name; |
| 279 | sp<DrmHal> drm = mDrm.promote(); |
| 280 | if (drm == NULL) { |
| 281 | name.append("<deleted>"); |
| 282 | } else if (drm->getPropertyStringInternal(String8("vendor"), name) != OK |
| 283 | || name.isEmpty()) { |
| 284 | name.append("<Get vendor failed or is empty>"); |
| 285 | } |
| 286 | name.append("["); |
| 287 | for (size_t i = 0; i < mSessionId.size(); ++i) { |
| 288 | name.appendFormat("%02x", mSessionId[i]); |
| 289 | } |
| 290 | name.append("]"); |
Chong Zhang | 181e695 | 2019-10-09 13:23:39 -0700 | [diff] [blame] | 291 | *_aidl_return = name; |
Robert Shih | 0f3a8a0 | 2019-11-14 15:43:39 -0800 | [diff] [blame] | 292 | return ::ndk::ScopedAStatus::ok(); |
Robert Shih | c3af31b | 2019-09-20 21:45:01 -0700 | [diff] [blame] | 293 | } |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 294 | |
Robert Shih | c3af31b | 2019-09-20 21:45:01 -0700 | [diff] [blame] | 295 | DrmHal::DrmSessionClient::~DrmSessionClient() { |
| 296 | DrmSessionManager::Instance()->removeSession(mSessionId); |
| 297 | } |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 298 | |
| 299 | DrmHal::DrmHal() |
Robert Shih | c3af31b | 2019-09-20 21:45:01 -0700 | [diff] [blame] | 300 | : mFactories(makeDrmFactories()), |
Jeff Tinker | abeb36a | 2017-02-17 09:42:46 -0800 | [diff] [blame] | 301 | mInitCheck((mFactories.size() == 0) ? ERROR_UNSUPPORTED : NO_INIT) { |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 302 | } |
| 303 | |
Jeff Tinker | 6133281 | 2017-05-15 16:53:10 -0700 | [diff] [blame] | 304 | void DrmHal::closeOpenSessions() { |
Jeff Tinker | 7dfe28f | 2018-02-15 12:17:40 -0800 | [diff] [blame] | 305 | Mutex::Autolock autoLock(mLock); |
| 306 | auto openSessions = mOpenSessions; |
| 307 | for (size_t i = 0; i < openSessions.size(); i++) { |
| 308 | mLock.unlock(); |
Robert Shih | c3af31b | 2019-09-20 21:45:01 -0700 | [diff] [blame] | 309 | closeSession(openSessions[i]->mSessionId); |
Jeff Tinker | 7dfe28f | 2018-02-15 12:17:40 -0800 | [diff] [blame] | 310 | mLock.lock(); |
Jeff Tinker | 6133281 | 2017-05-15 16:53:10 -0700 | [diff] [blame] | 311 | } |
| 312 | mOpenSessions.clear(); |
| 313 | } |
| 314 | |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 315 | DrmHal::~DrmHal() { |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 316 | } |
| 317 | |
Jeff Tinker | 7dfe28f | 2018-02-15 12:17:40 -0800 | [diff] [blame] | 318 | void DrmHal::cleanup() { |
| 319 | closeOpenSessions(); |
| 320 | |
| 321 | Mutex::Autolock autoLock(mLock); |
| 322 | reportPluginMetrics(); |
| 323 | reportFrameworkMetrics(); |
| 324 | |
| 325 | setListener(NULL); |
| 326 | mInitCheck = NO_INIT; |
Jeff Tinker | b8684f3 | 2018-12-12 08:41:31 -0800 | [diff] [blame] | 327 | if (mPluginV1_2 != NULL) { |
| 328 | if (!mPluginV1_2->setListener(NULL).isOk()) { |
| 329 | mInitCheck = DEAD_OBJECT; |
| 330 | } |
| 331 | } else if (mPlugin != NULL) { |
Jeff Tinker | 7dfe28f | 2018-02-15 12:17:40 -0800 | [diff] [blame] | 332 | if (!mPlugin->setListener(NULL).isOk()) { |
| 333 | mInitCheck = DEAD_OBJECT; |
| 334 | } |
| 335 | } |
| 336 | mPlugin.clear(); |
| 337 | mPluginV1_1.clear(); |
Jeff Tinker | c8baaba | 2018-10-23 11:32:36 -0700 | [diff] [blame] | 338 | mPluginV1_2.clear(); |
Robert Shih | fbe581e | 2021-01-14 05:12:04 -0800 | [diff] [blame] | 339 | mPluginV1_4.clear(); |
Jeff Tinker | 7dfe28f | 2018-02-15 12:17:40 -0800 | [diff] [blame] | 340 | } |
| 341 | |
Robert Shih | c0d1d0e | 2019-11-24 13:21:04 -0800 | [diff] [blame] | 342 | std::vector<sp<IDrmFactory>> DrmHal::makeDrmFactories() { |
| 343 | std::vector<sp<IDrmFactory>> factories(DrmUtils::MakeDrmFactories()); |
Jeff Tinker | abeb36a | 2017-02-17 09:42:46 -0800 | [diff] [blame] | 344 | if (factories.size() == 0) { |
| 345 | // must be in passthrough mode, load the default passthrough service |
Jeff Tinker | e309b22 | 2017-04-05 08:01:28 -0700 | [diff] [blame] | 346 | auto passthrough = IDrmFactory::getService(); |
Jeff Tinker | abeb36a | 2017-02-17 09:42:46 -0800 | [diff] [blame] | 347 | if (passthrough != NULL) { |
Jeff Tinker | e307dc4 | 2018-02-11 19:53:54 +0000 | [diff] [blame] | 348 | ALOGI("makeDrmFactories: using default passthrough drm instance"); |
Jeff Tinker | abeb36a | 2017-02-17 09:42:46 -0800 | [diff] [blame] | 349 | factories.push_back(passthrough); |
| 350 | } else { |
| 351 | ALOGE("Failed to find any drm factories"); |
| 352 | } |
| 353 | } |
| 354 | return factories; |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 355 | } |
| 356 | |
Jeff Tinker | abeb36a | 2017-02-17 09:42:46 -0800 | [diff] [blame] | 357 | sp<IDrmPlugin> DrmHal::makeDrmPlugin(const sp<IDrmFactory>& factory, |
| 358 | const uint8_t uuid[16], const String8& appPackageName) { |
Adam Stone | 32494f5 | 2018-02-26 22:53:27 -0800 | [diff] [blame] | 359 | mAppPackageName = appPackageName; |
Adam Stone | fb679e3 | 2018-02-07 10:25:48 -0800 | [diff] [blame] | 360 | mMetrics.SetAppPackageName(appPackageName); |
Robert Shih | 6152d7c | 2019-11-19 22:54:27 -0800 | [diff] [blame] | 361 | mMetrics.SetAppUid(AIBinder_getCallingUid()); |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 362 | |
| 363 | sp<IDrmPlugin> plugin; |
Jeff Tinker | abeb36a | 2017-02-17 09:42:46 -0800 | [diff] [blame] | 364 | Return<void> hResult = factory->createPlugin(uuid, appPackageName.string(), |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 365 | [&](Status status, const sp<IDrmPlugin>& hPlugin) { |
Jeff Tinker | abeb36a | 2017-02-17 09:42:46 -0800 | [diff] [blame] | 366 | if (status != Status::OK) { |
| 367 | ALOGE("Failed to make drm plugin"); |
| 368 | return; |
| 369 | } |
| 370 | plugin = hPlugin; |
| 371 | } |
| 372 | ); |
Jeff Tinker | f0e89b0 | 2017-08-07 15:58:41 -0700 | [diff] [blame] | 373 | |
| 374 | if (!hResult.isOk()) { |
| 375 | ALOGE("createPlugin remote call failed"); |
| 376 | } |
| 377 | |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 378 | return plugin; |
| 379 | } |
| 380 | |
| 381 | status_t DrmHal::initCheck() const { |
| 382 | return mInitCheck; |
| 383 | } |
| 384 | |
| 385 | status_t DrmHal::setListener(const sp<IDrmClient>& listener) |
| 386 | { |
| 387 | Mutex::Autolock lock(mEventLock); |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 388 | mListener = listener; |
| 389 | return NO_ERROR; |
| 390 | } |
| 391 | |
| 392 | Return<void> DrmHal::sendEvent(EventType hEventType, |
| 393 | const hidl_vec<uint8_t>& sessionId, const hidl_vec<uint8_t>& data) { |
Adam Stone | cea91ce | 2018-01-22 19:23:28 -0800 | [diff] [blame] | 394 | mMetrics.mEventCounter.Increment(hEventType); |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 395 | |
| 396 | mEventLock.lock(); |
| 397 | sp<IDrmClient> listener = mListener; |
| 398 | mEventLock.unlock(); |
| 399 | |
| 400 | if (listener != NULL) { |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 401 | Mutex::Autolock lock(mNotifyLock); |
| 402 | DrmPlugin::EventType eventType; |
| 403 | switch(hEventType) { |
| 404 | case EventType::PROVISION_REQUIRED: |
| 405 | eventType = DrmPlugin::kDrmPluginEventProvisionRequired; |
| 406 | break; |
| 407 | case EventType::KEY_NEEDED: |
| 408 | eventType = DrmPlugin::kDrmPluginEventKeyNeeded; |
| 409 | break; |
| 410 | case EventType::KEY_EXPIRED: |
| 411 | eventType = DrmPlugin::kDrmPluginEventKeyExpired; |
| 412 | break; |
| 413 | case EventType::VENDOR_DEFINED: |
| 414 | eventType = DrmPlugin::kDrmPluginEventVendorDefined; |
| 415 | break; |
Rahul Frias | b86f4b3 | 2017-03-27 15:13:30 -0700 | [diff] [blame] | 416 | case EventType::SESSION_RECLAIMED: |
| 417 | eventType = DrmPlugin::kDrmPluginEventSessionReclaimed; |
| 418 | break; |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 419 | default: |
| 420 | return Void(); |
| 421 | } |
Robert Shih | 61e1c76 | 2019-10-31 21:26:58 -0700 | [diff] [blame] | 422 | listener->sendEvent(eventType, sessionId, data); |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 423 | } |
| 424 | return Void(); |
| 425 | } |
| 426 | |
| 427 | Return<void> DrmHal::sendExpirationUpdate(const hidl_vec<uint8_t>& sessionId, |
| 428 | int64_t expiryTimeInMS) { |
| 429 | |
| 430 | mEventLock.lock(); |
| 431 | sp<IDrmClient> listener = mListener; |
| 432 | mEventLock.unlock(); |
| 433 | |
| 434 | if (listener != NULL) { |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 435 | Mutex::Autolock lock(mNotifyLock); |
Robert Shih | 61e1c76 | 2019-10-31 21:26:58 -0700 | [diff] [blame] | 436 | listener->sendExpirationUpdate(sessionId, expiryTimeInMS); |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 437 | } |
| 438 | return Void(); |
| 439 | } |
| 440 | |
| 441 | Return<void> DrmHal::sendKeysChange(const hidl_vec<uint8_t>& sessionId, |
Robert Shih | a503326 | 2019-05-06 14:15:12 -0700 | [diff] [blame] | 442 | const hidl_vec<KeyStatus_V1_0>& keyStatusList_V1_0, bool hasNewUsableKey) { |
| 443 | std::vector<KeyStatus> keyStatusVec; |
| 444 | for (const auto &keyStatus_V1_0 : keyStatusList_V1_0) { |
| 445 | keyStatusVec.push_back({keyStatus_V1_0.keyId, |
| 446 | static_cast<KeyStatusType>(keyStatus_V1_0.type)}); |
| 447 | } |
| 448 | hidl_vec<KeyStatus> keyStatusList_V1_2(keyStatusVec); |
| 449 | return sendKeysChange_1_2(sessionId, keyStatusList_V1_2, hasNewUsableKey); |
| 450 | } |
| 451 | |
| 452 | Return<void> DrmHal::sendKeysChange_1_2(const hidl_vec<uint8_t>& sessionId, |
Robert Shih | 61e1c76 | 2019-10-31 21:26:58 -0700 | [diff] [blame] | 453 | const hidl_vec<KeyStatus>& hKeyStatusList, bool hasNewUsableKey) { |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 454 | |
| 455 | mEventLock.lock(); |
| 456 | sp<IDrmClient> listener = mListener; |
| 457 | mEventLock.unlock(); |
| 458 | |
| 459 | if (listener != NULL) { |
Robert Shih | 61e1c76 | 2019-10-31 21:26:58 -0700 | [diff] [blame] | 460 | std::vector<DrmKeyStatus> keyStatusList; |
| 461 | size_t nKeys = hKeyStatusList.size(); |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 462 | for (size_t i = 0; i < nKeys; ++i) { |
Robert Shih | 61e1c76 | 2019-10-31 21:26:58 -0700 | [diff] [blame] | 463 | const KeyStatus &keyStatus = hKeyStatusList[i]; |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 464 | uint32_t type; |
| 465 | switch(keyStatus.type) { |
| 466 | case KeyStatusType::USABLE: |
| 467 | type = DrmPlugin::kKeyStatusType_Usable; |
| 468 | break; |
| 469 | case KeyStatusType::EXPIRED: |
| 470 | type = DrmPlugin::kKeyStatusType_Expired; |
| 471 | break; |
| 472 | case KeyStatusType::OUTPUTNOTALLOWED: |
| 473 | type = DrmPlugin::kKeyStatusType_OutputNotAllowed; |
| 474 | break; |
| 475 | case KeyStatusType::STATUSPENDING: |
| 476 | type = DrmPlugin::kKeyStatusType_StatusPending; |
| 477 | break; |
Robert Shih | a503326 | 2019-05-06 14:15:12 -0700 | [diff] [blame] | 478 | case KeyStatusType::USABLEINFUTURE: |
| 479 | type = DrmPlugin::kKeyStatusType_UsableInFuture; |
| 480 | break; |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 481 | case KeyStatusType::INTERNALERROR: |
| 482 | default: |
| 483 | type = DrmPlugin::kKeyStatusType_InternalError; |
| 484 | break; |
| 485 | } |
Robert Shih | 61e1c76 | 2019-10-31 21:26:58 -0700 | [diff] [blame] | 486 | keyStatusList.push_back({type, keyStatus.keyId}); |
Adam Stone | cea91ce | 2018-01-22 19:23:28 -0800 | [diff] [blame] | 487 | mMetrics.mKeyStatusChangeCounter.Increment(keyStatus.type); |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 488 | } |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 489 | |
| 490 | Mutex::Autolock lock(mNotifyLock); |
Robert Shih | 61e1c76 | 2019-10-31 21:26:58 -0700 | [diff] [blame] | 491 | listener->sendKeysChange(sessionId, keyStatusList, hasNewUsableKey); |
Adam Stone | cea91ce | 2018-01-22 19:23:28 -0800 | [diff] [blame] | 492 | } else { |
| 493 | // There's no listener. But we still want to count the key change |
| 494 | // events. |
Robert Shih | 61e1c76 | 2019-10-31 21:26:58 -0700 | [diff] [blame] | 495 | size_t nKeys = hKeyStatusList.size(); |
Adam Stone | cea91ce | 2018-01-22 19:23:28 -0800 | [diff] [blame] | 496 | for (size_t i = 0; i < nKeys; i++) { |
Robert Shih | 61e1c76 | 2019-10-31 21:26:58 -0700 | [diff] [blame] | 497 | mMetrics.mKeyStatusChangeCounter.Increment(hKeyStatusList[i].type); |
Adam Stone | cea91ce | 2018-01-22 19:23:28 -0800 | [diff] [blame] | 498 | } |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 499 | } |
Adam Stone | cea91ce | 2018-01-22 19:23:28 -0800 | [diff] [blame] | 500 | |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 501 | return Void(); |
| 502 | } |
| 503 | |
Jeff Tinker | b8684f3 | 2018-12-12 08:41:31 -0800 | [diff] [blame] | 504 | Return<void> DrmHal::sendSessionLostState( |
| 505 | const hidl_vec<uint8_t>& sessionId) { |
| 506 | |
| 507 | mEventLock.lock(); |
| 508 | sp<IDrmClient> listener = mListener; |
| 509 | mEventLock.unlock(); |
| 510 | |
| 511 | if (listener != NULL) { |
Jeff Tinker | b8684f3 | 2018-12-12 08:41:31 -0800 | [diff] [blame] | 512 | Mutex::Autolock lock(mNotifyLock); |
Robert Shih | 61e1c76 | 2019-10-31 21:26:58 -0700 | [diff] [blame] | 513 | listener->sendSessionLostState(sessionId); |
Jeff Tinker | b8684f3 | 2018-12-12 08:41:31 -0800 | [diff] [blame] | 514 | } |
| 515 | return Void(); |
| 516 | } |
| 517 | |
Jeff Tinker | db3fa5f | 2019-01-25 22:56:56 -0800 | [diff] [blame] | 518 | status_t DrmHal::matchMimeTypeAndSecurityLevel(const sp<IDrmFactory> &factory, |
| 519 | const uint8_t uuid[16], |
| 520 | const String8 &mimeType, |
| 521 | DrmPlugin::SecurityLevel level, |
| 522 | bool *isSupported) { |
| 523 | *isSupported = false; |
| 524 | |
| 525 | // handle default value cases |
| 526 | if (level == DrmPlugin::kSecurityLevelUnknown) { |
| 527 | if (mimeType == "") { |
| 528 | // isCryptoSchemeSupported(uuid) |
| 529 | *isSupported = true; |
| 530 | } else { |
| 531 | // isCryptoSchemeSupported(uuid, mimeType) |
| 532 | *isSupported = factory->isContentTypeSupported(mimeType.string()); |
| 533 | } |
| 534 | return OK; |
| 535 | } else if (mimeType == "") { |
| 536 | return BAD_VALUE; |
Jeff Tinker | 99dbfa8 | 2019-01-17 17:27:06 -0800 | [diff] [blame] | 537 | } |
| 538 | |
Jeff Tinker | db3fa5f | 2019-01-25 22:56:56 -0800 | [diff] [blame] | 539 | sp<drm::V1_2::IDrmFactory> factoryV1_2 = drm::V1_2::IDrmFactory::castFrom(factory); |
| 540 | if (factoryV1_2 == NULL) { |
| 541 | return ERROR_UNSUPPORTED; |
Jeff Tinker | 99dbfa8 | 2019-01-17 17:27:06 -0800 | [diff] [blame] | 542 | } else { |
Jeff Tinker | db3fa5f | 2019-01-25 22:56:56 -0800 | [diff] [blame] | 543 | *isSupported = factoryV1_2->isCryptoSchemeSupported_1_2(uuid, |
| 544 | mimeType.string(), toHidlSecurityLevel(level)); |
| 545 | return OK; |
Jeff Tinker | 99dbfa8 | 2019-01-17 17:27:06 -0800 | [diff] [blame] | 546 | } |
Jeff Tinker | 99dbfa8 | 2019-01-17 17:27:06 -0800 | [diff] [blame] | 547 | } |
| 548 | |
Jeff Tinker | db3fa5f | 2019-01-25 22:56:56 -0800 | [diff] [blame] | 549 | status_t DrmHal::isCryptoSchemeSupported(const uint8_t uuid[16], |
| 550 | const String8 &mimeType, |
| 551 | DrmPlugin::SecurityLevel level, |
| 552 | bool *isSupported) { |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 553 | Mutex::Autolock autoLock(mLock); |
Jeff Tinker | db3fa5f | 2019-01-25 22:56:56 -0800 | [diff] [blame] | 554 | *isSupported = false; |
| 555 | for (ssize_t i = mFactories.size() - 1; i >= 0; i--) { |
| 556 | if (mFactories[i]->isCryptoSchemeSupported(uuid)) { |
| 557 | return matchMimeTypeAndSecurityLevel(mFactories[i], |
| 558 | uuid, mimeType, level, isSupported); |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 559 | } |
| 560 | } |
Jeff Tinker | db3fa5f | 2019-01-25 22:56:56 -0800 | [diff] [blame] | 561 | return OK; |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 562 | } |
| 563 | |
Edwin Wong | 68b3d9f | 2017-01-06 19:07:54 -0800 | [diff] [blame] | 564 | status_t DrmHal::createPlugin(const uint8_t uuid[16], |
| 565 | const String8& appPackageName) { |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 566 | Mutex::Autolock autoLock(mLock); |
| 567 | |
Jeff Tinker | db3fa5f | 2019-01-25 22:56:56 -0800 | [diff] [blame] | 568 | for (ssize_t i = mFactories.size() - 1; i >= 0; i--) { |
Jeff Tinker | abeb36a | 2017-02-17 09:42:46 -0800 | [diff] [blame] | 569 | if (mFactories[i]->isCryptoSchemeSupported(uuid)) { |
Peter Kalauskas | 7676a40 | 2018-12-27 11:04:16 -0800 | [diff] [blame] | 570 | auto plugin = makeDrmPlugin(mFactories[i], uuid, appPackageName); |
| 571 | if (plugin != NULL) { |
| 572 | mPlugin = plugin; |
Edwin Wong | 5641aa2 | 2018-01-30 17:52:21 -0800 | [diff] [blame] | 573 | mPluginV1_1 = drm::V1_1::IDrmPlugin::castFrom(mPlugin); |
Jeff Tinker | c8baaba | 2018-10-23 11:32:36 -0700 | [diff] [blame] | 574 | mPluginV1_2 = drm::V1_2::IDrmPlugin::castFrom(mPlugin); |
Robert Shih | fbe581e | 2021-01-14 05:12:04 -0800 | [diff] [blame] | 575 | mPluginV1_4 = drm::V1_4::IDrmPlugin::castFrom(mPlugin); |
Peter Kalauskas | 7676a40 | 2018-12-27 11:04:16 -0800 | [diff] [blame] | 576 | break; |
Edwin Wong | 5641aa2 | 2018-01-30 17:52:21 -0800 | [diff] [blame] | 577 | } |
Jeff Tinker | abeb36a | 2017-02-17 09:42:46 -0800 | [diff] [blame] | 578 | } |
| 579 | } |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 580 | |
| 581 | if (mPlugin == NULL) { |
| 582 | mInitCheck = ERROR_UNSUPPORTED; |
| 583 | } else { |
Jeff Tinker | b8684f3 | 2018-12-12 08:41:31 -0800 | [diff] [blame] | 584 | mInitCheck = OK; |
| 585 | if (mPluginV1_2 != NULL) { |
| 586 | if (!mPluginV1_2->setListener(this).isOk()) { |
| 587 | mInitCheck = DEAD_OBJECT; |
| 588 | } |
| 589 | } else if (!mPlugin->setListener(this).isOk()) { |
Jeff Tinker | 319d5f4 | 2017-07-26 15:44:33 -0700 | [diff] [blame] | 590 | mInitCheck = DEAD_OBJECT; |
Jeff Tinker | b8684f3 | 2018-12-12 08:41:31 -0800 | [diff] [blame] | 591 | } |
| 592 | if (mInitCheck != OK) { |
| 593 | mPlugin.clear(); |
| 594 | mPluginV1_1.clear(); |
| 595 | mPluginV1_2.clear(); |
Robert Shih | fbe581e | 2021-01-14 05:12:04 -0800 | [diff] [blame] | 596 | mPluginV1_4.clear(); |
Jeff Tinker | 319d5f4 | 2017-07-26 15:44:33 -0700 | [diff] [blame] | 597 | } |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 598 | } |
| 599 | |
Jeff Tinker | b8684f3 | 2018-12-12 08:41:31 -0800 | [diff] [blame] | 600 | |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 601 | return mInitCheck; |
| 602 | } |
| 603 | |
| 604 | status_t DrmHal::destroyPlugin() { |
Jeff Tinker | 7dfe28f | 2018-02-15 12:17:40 -0800 | [diff] [blame] | 605 | cleanup(); |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 606 | return OK; |
| 607 | } |
| 608 | |
Jeff Tinker | 41d279a | 2018-02-11 19:52:08 +0000 | [diff] [blame] | 609 | status_t DrmHal::openSession(DrmPlugin::SecurityLevel level, |
| 610 | Vector<uint8_t> &sessionId) { |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 611 | Mutex::Autolock autoLock(mLock); |
Jeff Tinker | 6d998b6 | 2017-12-18 14:37:43 -0800 | [diff] [blame] | 612 | INIT_CHECK(); |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 613 | |
Jeff Tinker | 99dbfa8 | 2019-01-17 17:27:06 -0800 | [diff] [blame] | 614 | SecurityLevel hSecurityLevel = toHidlSecurityLevel(level); |
Jeff Tinker | 41d279a | 2018-02-11 19:52:08 +0000 | [diff] [blame] | 615 | bool setSecurityLevel = true; |
Tobias Thierer | 5f5e43f | 2018-02-11 15:00:57 +0000 | [diff] [blame] | 616 | |
Jeff Tinker | 99dbfa8 | 2019-01-17 17:27:06 -0800 | [diff] [blame] | 617 | if (level == DrmPlugin::kSecurityLevelMax) { |
Jeff Tinker | 41d279a | 2018-02-11 19:52:08 +0000 | [diff] [blame] | 618 | setSecurityLevel = false; |
Jeff Tinker | 99dbfa8 | 2019-01-17 17:27:06 -0800 | [diff] [blame] | 619 | } else { |
| 620 | if (hSecurityLevel == SecurityLevel::UNKNOWN) { |
| 621 | return ERROR_DRM_CANNOT_HANDLE; |
| 622 | } |
Jeff Tinker | 41d279a | 2018-02-11 19:52:08 +0000 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | status_t err = UNKNOWN_ERROR; |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 626 | bool retry = true; |
| 627 | do { |
| 628 | hidl_vec<uint8_t> hSessionId; |
| 629 | |
Jeff Tinker | 41d279a | 2018-02-11 19:52:08 +0000 | [diff] [blame] | 630 | Return<void> hResult; |
| 631 | if (mPluginV1_1 == NULL || !setSecurityLevel) { |
| 632 | hResult = mPlugin->openSession( |
| 633 | [&](Status status,const hidl_vec<uint8_t>& id) { |
| 634 | if (status == Status::OK) { |
| 635 | sessionId = toVector(id); |
| 636 | } |
| 637 | err = toStatusT(status); |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 638 | } |
Jeff Tinker | 41d279a | 2018-02-11 19:52:08 +0000 | [diff] [blame] | 639 | ); |
| 640 | } else { |
| 641 | hResult = mPluginV1_1->openSession_1_1(hSecurityLevel, |
| 642 | [&](Status status, const hidl_vec<uint8_t>& id) { |
| 643 | if (status == Status::OK) { |
| 644 | sessionId = toVector(id); |
| 645 | } |
| 646 | err = toStatusT(status); |
| 647 | } |
| 648 | ); |
| 649 | } |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 650 | |
| 651 | if (!hResult.isOk()) { |
| 652 | err = DEAD_OBJECT; |
| 653 | } |
| 654 | |
| 655 | if (err == ERROR_DRM_RESOURCE_BUSY && retry) { |
| 656 | mLock.unlock(); |
| 657 | // reclaimSession may call back to closeSession, since mLock is |
| 658 | // shared between Drm instances, we should unlock here to avoid |
| 659 | // deadlock. |
Robert Shih | 6152d7c | 2019-11-19 22:54:27 -0800 | [diff] [blame] | 660 | retry = DrmSessionManager::Instance()->reclaimSession(AIBinder_getCallingPid()); |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 661 | mLock.lock(); |
| 662 | } else { |
| 663 | retry = false; |
| 664 | } |
| 665 | } while (retry); |
| 666 | |
| 667 | if (err == OK) { |
Steven Moreland | e0496a2 | 2020-02-13 13:13:52 -0800 | [diff] [blame] | 668 | std::shared_ptr<DrmSessionClient> client = |
| 669 | ndk::SharedRefBase::make<DrmSessionClient>(this, sessionId); |
Robert Shih | 6152d7c | 2019-11-19 22:54:27 -0800 | [diff] [blame] | 670 | DrmSessionManager::Instance()->addSession(AIBinder_getCallingPid(), |
Robert Shih | 0f3a8a0 | 2019-11-14 15:43:39 -0800 | [diff] [blame] | 671 | std::static_pointer_cast<IResourceManagerClient>(client), sessionId); |
| 672 | mOpenSessions.push_back(client); |
Adam Stone | 568b3c4 | 2018-01-31 12:57:16 -0800 | [diff] [blame] | 673 | mMetrics.SetSessionStart(sessionId); |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 674 | } |
Adam Stone | aaf87dd | 2018-01-08 11:55:06 -0800 | [diff] [blame] | 675 | |
Adam Stone | f0e618d | 2018-01-17 19:20:41 -0800 | [diff] [blame] | 676 | mMetrics.mOpenSessionCounter.Increment(err); |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 677 | return err; |
| 678 | } |
| 679 | |
| 680 | status_t DrmHal::closeSession(Vector<uint8_t> const &sessionId) { |
| 681 | Mutex::Autolock autoLock(mLock); |
Jeff Tinker | 6d998b6 | 2017-12-18 14:37:43 -0800 | [diff] [blame] | 682 | INIT_CHECK(); |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 683 | |
Jeff Tinker | 319d5f4 | 2017-07-26 15:44:33 -0700 | [diff] [blame] | 684 | Return<Status> status = mPlugin->closeSession(toHidlVec(sessionId)); |
| 685 | if (status.isOk()) { |
| 686 | if (status == Status::OK) { |
| 687 | DrmSessionManager::Instance()->removeSession(sessionId); |
Robert Shih | 0f3a8a0 | 2019-11-14 15:43:39 -0800 | [diff] [blame] | 688 | for (auto i = mOpenSessions.begin(); i != mOpenSessions.end(); i++) { |
| 689 | if (isEqualSessionId((*i)->mSessionId, sessionId)) { |
| 690 | mOpenSessions.erase(i); |
Jeff Tinker | 319d5f4 | 2017-07-26 15:44:33 -0700 | [diff] [blame] | 691 | break; |
| 692 | } |
Jeff Tinker | 6133281 | 2017-05-15 16:53:10 -0700 | [diff] [blame] | 693 | } |
| 694 | } |
Adam Stone | cea91ce | 2018-01-22 19:23:28 -0800 | [diff] [blame] | 695 | status_t response = toStatusT(status); |
Adam Stone | 568b3c4 | 2018-01-31 12:57:16 -0800 | [diff] [blame] | 696 | mMetrics.SetSessionEnd(sessionId); |
Adam Stone | cea91ce | 2018-01-22 19:23:28 -0800 | [diff] [blame] | 697 | mMetrics.mCloseSessionCounter.Increment(response); |
| 698 | return response; |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 699 | } |
Adam Stone | cea91ce | 2018-01-22 19:23:28 -0800 | [diff] [blame] | 700 | mMetrics.mCloseSessionCounter.Increment(DEAD_OBJECT); |
Jeff Tinker | 319d5f4 | 2017-07-26 15:44:33 -0700 | [diff] [blame] | 701 | return DEAD_OBJECT; |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 702 | } |
| 703 | |
Jeff Tinker | b8684f3 | 2018-12-12 08:41:31 -0800 | [diff] [blame] | 704 | static DrmPlugin::KeyRequestType toKeyRequestType( |
| 705 | KeyRequestType keyRequestType) { |
| 706 | switch (keyRequestType) { |
| 707 | case KeyRequestType::INITIAL: |
| 708 | return DrmPlugin::kKeyRequestType_Initial; |
| 709 | break; |
| 710 | case KeyRequestType::RENEWAL: |
| 711 | return DrmPlugin::kKeyRequestType_Renewal; |
| 712 | break; |
| 713 | case KeyRequestType::RELEASE: |
| 714 | return DrmPlugin::kKeyRequestType_Release; |
| 715 | break; |
| 716 | default: |
| 717 | return DrmPlugin::kKeyRequestType_Unknown; |
| 718 | break; |
| 719 | } |
| 720 | } |
| 721 | |
| 722 | static DrmPlugin::KeyRequestType toKeyRequestType_1_1( |
| 723 | KeyRequestType_V1_1 keyRequestType) { |
| 724 | switch (keyRequestType) { |
| 725 | case KeyRequestType_V1_1::NONE: |
| 726 | return DrmPlugin::kKeyRequestType_None; |
| 727 | break; |
| 728 | case KeyRequestType_V1_1::UPDATE: |
| 729 | return DrmPlugin::kKeyRequestType_Update; |
| 730 | break; |
| 731 | default: |
| 732 | return toKeyRequestType(static_cast<KeyRequestType>(keyRequestType)); |
| 733 | break; |
| 734 | } |
| 735 | } |
| 736 | |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 737 | status_t DrmHal::getKeyRequest(Vector<uint8_t> const &sessionId, |
| 738 | Vector<uint8_t> const &initData, String8 const &mimeType, |
| 739 | DrmPlugin::KeyType keyType, KeyedVector<String8, |
| 740 | String8> const &optionalParameters, Vector<uint8_t> &request, |
| 741 | String8 &defaultUrl, DrmPlugin::KeyRequestType *keyRequestType) { |
| 742 | Mutex::Autolock autoLock(mLock); |
Jeff Tinker | 6d998b6 | 2017-12-18 14:37:43 -0800 | [diff] [blame] | 743 | INIT_CHECK(); |
Adam Stone | fb679e3 | 2018-02-07 10:25:48 -0800 | [diff] [blame] | 744 | EventTimer<status_t> keyRequestTimer(&mMetrics.mGetKeyRequestTimeUs); |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 745 | |
| 746 | DrmSessionManager::Instance()->useSession(sessionId); |
| 747 | |
| 748 | KeyType hKeyType; |
| 749 | if (keyType == DrmPlugin::kKeyType_Streaming) { |
| 750 | hKeyType = KeyType::STREAMING; |
| 751 | } else if (keyType == DrmPlugin::kKeyType_Offline) { |
| 752 | hKeyType = KeyType::OFFLINE; |
| 753 | } else if (keyType == DrmPlugin::kKeyType_Release) { |
| 754 | hKeyType = KeyType::RELEASE; |
| 755 | } else { |
Adam Stone | f0e618d | 2018-01-17 19:20:41 -0800 | [diff] [blame] | 756 | keyRequestTimer.SetAttribute(BAD_VALUE); |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 757 | return BAD_VALUE; |
| 758 | } |
| 759 | |
| 760 | ::KeyedVector hOptionalParameters = toHidlKeyedVector(optionalParameters); |
| 761 | |
| 762 | status_t err = UNKNOWN_ERROR; |
Jeff Tinker | b8684f3 | 2018-12-12 08:41:31 -0800 | [diff] [blame] | 763 | Return<void> hResult; |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 764 | |
Jeff Tinker | b8684f3 | 2018-12-12 08:41:31 -0800 | [diff] [blame] | 765 | if (mPluginV1_2 != NULL) { |
| 766 | hResult = mPluginV1_2->getKeyRequest_1_2( |
| 767 | toHidlVec(sessionId), toHidlVec(initData), |
| 768 | toHidlString(mimeType), hKeyType, hOptionalParameters, |
| 769 | [&](Status_V1_2 status, const hidl_vec<uint8_t>& hRequest, |
| 770 | KeyRequestType_V1_1 hKeyRequestType, |
| 771 | const hidl_string& hDefaultUrl) { |
| 772 | if (status == Status_V1_2::OK) { |
| 773 | request = toVector(hRequest); |
| 774 | defaultUrl = toString8(hDefaultUrl); |
| 775 | *keyRequestType = toKeyRequestType_1_1(hKeyRequestType); |
| 776 | } |
Robert Shih | 5944a0b | 2021-02-10 04:26:33 -0800 | [diff] [blame] | 777 | err = toStatusT(status); |
Jeff Tinker | b8684f3 | 2018-12-12 08:41:31 -0800 | [diff] [blame] | 778 | }); |
| 779 | } else if (mPluginV1_1 != NULL) { |
| 780 | hResult = mPluginV1_1->getKeyRequest_1_1( |
Rahul Frias | 59bc3fa | 2018-01-22 23:48:52 -0800 | [diff] [blame] | 781 | toHidlVec(sessionId), toHidlVec(initData), |
| 782 | toHidlString(mimeType), hKeyType, hOptionalParameters, |
| 783 | [&](Status status, const hidl_vec<uint8_t>& hRequest, |
Jeff Tinker | b8684f3 | 2018-12-12 08:41:31 -0800 | [diff] [blame] | 784 | KeyRequestType_V1_1 hKeyRequestType, |
| 785 | const hidl_string& hDefaultUrl) { |
| 786 | if (status == Status::OK) { |
| 787 | request = toVector(hRequest); |
| 788 | defaultUrl = toString8(hDefaultUrl); |
| 789 | *keyRequestType = toKeyRequestType_1_1(hKeyRequestType); |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 790 | } |
| 791 | err = toStatusT(status); |
Jeff Tinker | b8684f3 | 2018-12-12 08:41:31 -0800 | [diff] [blame] | 792 | }); |
| 793 | } else { |
| 794 | hResult = mPlugin->getKeyRequest( |
| 795 | toHidlVec(sessionId), toHidlVec(initData), |
| 796 | toHidlString(mimeType), hKeyType, hOptionalParameters, |
| 797 | [&](Status status, const hidl_vec<uint8_t>& hRequest, |
| 798 | KeyRequestType hKeyRequestType, |
| 799 | const hidl_string& hDefaultUrl) { |
| 800 | if (status == Status::OK) { |
| 801 | request = toVector(hRequest); |
| 802 | defaultUrl = toString8(hDefaultUrl); |
| 803 | *keyRequestType = toKeyRequestType(hKeyRequestType); |
| 804 | } |
| 805 | err = toStatusT(status); |
| 806 | }); |
| 807 | } |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 808 | |
Adam Stone | f0e618d | 2018-01-17 19:20:41 -0800 | [diff] [blame] | 809 | err = hResult.isOk() ? err : DEAD_OBJECT; |
| 810 | keyRequestTimer.SetAttribute(err); |
| 811 | return err; |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 812 | } |
| 813 | |
| 814 | status_t DrmHal::provideKeyResponse(Vector<uint8_t> const &sessionId, |
| 815 | Vector<uint8_t> const &response, Vector<uint8_t> &keySetId) { |
| 816 | Mutex::Autolock autoLock(mLock); |
Jeff Tinker | 6d998b6 | 2017-12-18 14:37:43 -0800 | [diff] [blame] | 817 | INIT_CHECK(); |
George Burgess IV | c42403d | 2019-10-18 09:54:32 -0700 | [diff] [blame] | 818 | EventTimer<status_t> keyResponseTimer(&mMetrics.mProvideKeyResponseTimeUs); |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 819 | |
| 820 | DrmSessionManager::Instance()->useSession(sessionId); |
| 821 | |
| 822 | status_t err = UNKNOWN_ERROR; |
| 823 | |
| 824 | Return<void> hResult = mPlugin->provideKeyResponse(toHidlVec(sessionId), |
| 825 | toHidlVec(response), |
| 826 | [&](Status status, const hidl_vec<uint8_t>& hKeySetId) { |
| 827 | if (status == Status::OK) { |
| 828 | keySetId = toVector(hKeySetId); |
| 829 | } |
| 830 | err = toStatusT(status); |
| 831 | } |
| 832 | ); |
Adam Stone | cea91ce | 2018-01-22 19:23:28 -0800 | [diff] [blame] | 833 | err = hResult.isOk() ? err : DEAD_OBJECT; |
| 834 | keyResponseTimer.SetAttribute(err); |
| 835 | return err; |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 836 | } |
| 837 | |
| 838 | status_t DrmHal::removeKeys(Vector<uint8_t> const &keySetId) { |
| 839 | Mutex::Autolock autoLock(mLock); |
Jeff Tinker | 6d998b6 | 2017-12-18 14:37:43 -0800 | [diff] [blame] | 840 | INIT_CHECK(); |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 841 | |
Jeff Tinker | 58ad475 | 2018-02-16 16:51:59 -0800 | [diff] [blame] | 842 | Return<Status> status = mPlugin->removeKeys(toHidlVec(keySetId)); |
| 843 | return status.isOk() ? toStatusT(status) : DEAD_OBJECT; |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 844 | } |
| 845 | |
| 846 | status_t DrmHal::restoreKeys(Vector<uint8_t> const &sessionId, |
| 847 | Vector<uint8_t> const &keySetId) { |
| 848 | Mutex::Autolock autoLock(mLock); |
Jeff Tinker | 6d998b6 | 2017-12-18 14:37:43 -0800 | [diff] [blame] | 849 | INIT_CHECK(); |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 850 | |
| 851 | DrmSessionManager::Instance()->useSession(sessionId); |
| 852 | |
Jeff Tinker | 58ad475 | 2018-02-16 16:51:59 -0800 | [diff] [blame] | 853 | Return<Status> status = mPlugin->restoreKeys(toHidlVec(sessionId), |
| 854 | toHidlVec(keySetId)); |
| 855 | return status.isOk() ? toStatusT(status) : DEAD_OBJECT; |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 856 | } |
| 857 | |
| 858 | status_t DrmHal::queryKeyStatus(Vector<uint8_t> const &sessionId, |
| 859 | KeyedVector<String8, String8> &infoMap) const { |
| 860 | Mutex::Autolock autoLock(mLock); |
Jeff Tinker | 6d998b6 | 2017-12-18 14:37:43 -0800 | [diff] [blame] | 861 | INIT_CHECK(); |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 862 | |
| 863 | DrmSessionManager::Instance()->useSession(sessionId); |
| 864 | |
| 865 | ::KeyedVector hInfoMap; |
| 866 | |
| 867 | status_t err = UNKNOWN_ERROR; |
| 868 | |
| 869 | Return<void> hResult = mPlugin->queryKeyStatus(toHidlVec(sessionId), |
| 870 | [&](Status status, const hidl_vec<KeyValue>& map) { |
| 871 | if (status == Status::OK) { |
| 872 | infoMap = toKeyedVector(map); |
| 873 | } |
| 874 | err = toStatusT(status); |
| 875 | } |
| 876 | ); |
| 877 | |
| 878 | return hResult.isOk() ? err : DEAD_OBJECT; |
| 879 | } |
| 880 | |
| 881 | status_t DrmHal::getProvisionRequest(String8 const &certType, |
| 882 | String8 const &certAuthority, Vector<uint8_t> &request, |
| 883 | String8 &defaultUrl) { |
| 884 | Mutex::Autolock autoLock(mLock); |
Jeff Tinker | 6d998b6 | 2017-12-18 14:37:43 -0800 | [diff] [blame] | 885 | INIT_CHECK(); |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 886 | |
| 887 | status_t err = UNKNOWN_ERROR; |
Jeff Tinker | b8684f3 | 2018-12-12 08:41:31 -0800 | [diff] [blame] | 888 | Return<void> hResult; |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 889 | |
Jeff Tinker | b8684f3 | 2018-12-12 08:41:31 -0800 | [diff] [blame] | 890 | if (mPluginV1_2 != NULL) { |
| 891 | Return<void> hResult = mPluginV1_2->getProvisionRequest_1_2( |
| 892 | toHidlString(certType), toHidlString(certAuthority), |
| 893 | [&](Status_V1_2 status, const hidl_vec<uint8_t>& hRequest, |
| 894 | const hidl_string& hDefaultUrl) { |
| 895 | if (status == Status_V1_2::OK) { |
| 896 | request = toVector(hRequest); |
| 897 | defaultUrl = toString8(hDefaultUrl); |
| 898 | } |
Robert Shih | 5944a0b | 2021-02-10 04:26:33 -0800 | [diff] [blame] | 899 | err = toStatusT(status); |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 900 | } |
Jeff Tinker | b8684f3 | 2018-12-12 08:41:31 -0800 | [diff] [blame] | 901 | ); |
| 902 | } else { |
| 903 | Return<void> hResult = mPlugin->getProvisionRequest( |
| 904 | toHidlString(certType), toHidlString(certAuthority), |
| 905 | [&](Status status, const hidl_vec<uint8_t>& hRequest, |
| 906 | const hidl_string& hDefaultUrl) { |
| 907 | if (status == Status::OK) { |
| 908 | request = toVector(hRequest); |
| 909 | defaultUrl = toString8(hDefaultUrl); |
| 910 | } |
| 911 | err = toStatusT(status); |
| 912 | } |
| 913 | ); |
| 914 | } |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 915 | |
Adam Stone | cea91ce | 2018-01-22 19:23:28 -0800 | [diff] [blame] | 916 | err = hResult.isOk() ? err : DEAD_OBJECT; |
| 917 | mMetrics.mGetProvisionRequestCounter.Increment(err); |
| 918 | return err; |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 919 | } |
| 920 | |
| 921 | status_t DrmHal::provideProvisionResponse(Vector<uint8_t> const &response, |
Edwin Wong | 68b3d9f | 2017-01-06 19:07:54 -0800 | [diff] [blame] | 922 | Vector<uint8_t> &certificate, Vector<uint8_t> &wrappedKey) { |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 923 | Mutex::Autolock autoLock(mLock); |
Jeff Tinker | 6d998b6 | 2017-12-18 14:37:43 -0800 | [diff] [blame] | 924 | INIT_CHECK(); |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 925 | |
| 926 | status_t err = UNKNOWN_ERROR; |
| 927 | |
| 928 | Return<void> hResult = mPlugin->provideProvisionResponse(toHidlVec(response), |
| 929 | [&](Status status, const hidl_vec<uint8_t>& hCertificate, |
| 930 | const hidl_vec<uint8_t>& hWrappedKey) { |
| 931 | if (status == Status::OK) { |
| 932 | certificate = toVector(hCertificate); |
| 933 | wrappedKey = toVector(hWrappedKey); |
| 934 | } |
| 935 | err = toStatusT(status); |
| 936 | } |
| 937 | ); |
| 938 | |
Adam Stone | cea91ce | 2018-01-22 19:23:28 -0800 | [diff] [blame] | 939 | err = hResult.isOk() ? err : DEAD_OBJECT; |
| 940 | mMetrics.mProvideProvisionResponseCounter.Increment(err); |
| 941 | return err; |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 942 | } |
| 943 | |
Jeff Tinker | abeb36a | 2017-02-17 09:42:46 -0800 | [diff] [blame] | 944 | status_t DrmHal::getSecureStops(List<Vector<uint8_t>> &secureStops) { |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 945 | Mutex::Autolock autoLock(mLock); |
Jeff Tinker | 6d998b6 | 2017-12-18 14:37:43 -0800 | [diff] [blame] | 946 | INIT_CHECK(); |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 947 | |
| 948 | status_t err = UNKNOWN_ERROR; |
| 949 | |
| 950 | Return<void> hResult = mPlugin->getSecureStops( |
| 951 | [&](Status status, const hidl_vec<SecureStop>& hSecureStops) { |
| 952 | if (status == Status::OK) { |
| 953 | secureStops = toSecureStops(hSecureStops); |
| 954 | } |
| 955 | err = toStatusT(status); |
| 956 | } |
| 957 | ); |
| 958 | |
| 959 | return hResult.isOk() ? err : DEAD_OBJECT; |
| 960 | } |
| 961 | |
| 962 | |
Jeff Tinker | 15177d7 | 2018-01-25 12:57:55 -0800 | [diff] [blame] | 963 | status_t DrmHal::getSecureStopIds(List<Vector<uint8_t>> &secureStopIds) { |
| 964 | Mutex::Autolock autoLock(mLock); |
| 965 | |
| 966 | if (mInitCheck != OK) { |
| 967 | return mInitCheck; |
| 968 | } |
| 969 | |
| 970 | if (mPluginV1_1 == NULL) { |
| 971 | return ERROR_DRM_CANNOT_HANDLE; |
| 972 | } |
| 973 | |
| 974 | status_t err = UNKNOWN_ERROR; |
| 975 | |
| 976 | Return<void> hResult = mPluginV1_1->getSecureStopIds( |
| 977 | [&](Status status, const hidl_vec<SecureStopId>& hSecureStopIds) { |
| 978 | if (status == Status::OK) { |
| 979 | secureStopIds = toSecureStopIds(hSecureStopIds); |
| 980 | } |
| 981 | err = toStatusT(status); |
| 982 | } |
| 983 | ); |
| 984 | |
| 985 | return hResult.isOk() ? err : DEAD_OBJECT; |
| 986 | } |
| 987 | |
| 988 | |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 989 | status_t DrmHal::getSecureStop(Vector<uint8_t> const &ssid, Vector<uint8_t> &secureStop) { |
| 990 | Mutex::Autolock autoLock(mLock); |
Jeff Tinker | 6d998b6 | 2017-12-18 14:37:43 -0800 | [diff] [blame] | 991 | INIT_CHECK(); |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 992 | |
| 993 | status_t err = UNKNOWN_ERROR; |
| 994 | |
| 995 | Return<void> hResult = mPlugin->getSecureStop(toHidlVec(ssid), |
| 996 | [&](Status status, const SecureStop& hSecureStop) { |
| 997 | if (status == Status::OK) { |
| 998 | secureStop = toVector(hSecureStop.opaqueData); |
| 999 | } |
| 1000 | err = toStatusT(status); |
| 1001 | } |
| 1002 | ); |
| 1003 | |
| 1004 | return hResult.isOk() ? err : DEAD_OBJECT; |
| 1005 | } |
| 1006 | |
| 1007 | status_t DrmHal::releaseSecureStops(Vector<uint8_t> const &ssRelease) { |
| 1008 | Mutex::Autolock autoLock(mLock); |
Jeff Tinker | 6d998b6 | 2017-12-18 14:37:43 -0800 | [diff] [blame] | 1009 | INIT_CHECK(); |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 1010 | |
Jeff Tinker | 58ad475 | 2018-02-16 16:51:59 -0800 | [diff] [blame] | 1011 | Return<Status> status(Status::ERROR_DRM_UNKNOWN); |
Jeff Tinker | 15177d7 | 2018-01-25 12:57:55 -0800 | [diff] [blame] | 1012 | if (mPluginV1_1 != NULL) { |
| 1013 | SecureStopRelease secureStopRelease; |
| 1014 | secureStopRelease.opaqueData = toHidlVec(ssRelease); |
Jeff Tinker | 58ad475 | 2018-02-16 16:51:59 -0800 | [diff] [blame] | 1015 | status = mPluginV1_1->releaseSecureStops(secureStopRelease); |
| 1016 | } else { |
| 1017 | status = mPlugin->releaseSecureStop(toHidlVec(ssRelease)); |
Jeff Tinker | 15177d7 | 2018-01-25 12:57:55 -0800 | [diff] [blame] | 1018 | } |
Jeff Tinker | 58ad475 | 2018-02-16 16:51:59 -0800 | [diff] [blame] | 1019 | return status.isOk() ? toStatusT(status) : DEAD_OBJECT; |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 1020 | } |
| 1021 | |
Jeff Tinker | 15177d7 | 2018-01-25 12:57:55 -0800 | [diff] [blame] | 1022 | status_t DrmHal::removeSecureStop(Vector<uint8_t> const &ssid) { |
| 1023 | Mutex::Autolock autoLock(mLock); |
| 1024 | |
| 1025 | if (mInitCheck != OK) { |
| 1026 | return mInitCheck; |
| 1027 | } |
| 1028 | |
| 1029 | if (mPluginV1_1 == NULL) { |
| 1030 | return ERROR_DRM_CANNOT_HANDLE; |
| 1031 | } |
| 1032 | |
Jeff Tinker | 58ad475 | 2018-02-16 16:51:59 -0800 | [diff] [blame] | 1033 | Return<Status> status = mPluginV1_1->removeSecureStop(toHidlVec(ssid)); |
| 1034 | return status.isOk() ? toStatusT(status) : DEAD_OBJECT; |
Jeff Tinker | 15177d7 | 2018-01-25 12:57:55 -0800 | [diff] [blame] | 1035 | } |
| 1036 | |
| 1037 | status_t DrmHal::removeAllSecureStops() { |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 1038 | Mutex::Autolock autoLock(mLock); |
Jeff Tinker | 6d998b6 | 2017-12-18 14:37:43 -0800 | [diff] [blame] | 1039 | INIT_CHECK(); |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 1040 | |
Jeff Tinker | 58ad475 | 2018-02-16 16:51:59 -0800 | [diff] [blame] | 1041 | Return<Status> status(Status::ERROR_DRM_UNKNOWN); |
Jeff Tinker | 15177d7 | 2018-01-25 12:57:55 -0800 | [diff] [blame] | 1042 | if (mPluginV1_1 != NULL) { |
Jeff Tinker | 58ad475 | 2018-02-16 16:51:59 -0800 | [diff] [blame] | 1043 | status = mPluginV1_1->removeAllSecureStops(); |
| 1044 | } else { |
| 1045 | status = mPlugin->releaseAllSecureStops(); |
Jeff Tinker | 15177d7 | 2018-01-25 12:57:55 -0800 | [diff] [blame] | 1046 | } |
Jeff Tinker | 58ad475 | 2018-02-16 16:51:59 -0800 | [diff] [blame] | 1047 | return status.isOk() ? toStatusT(status) : DEAD_OBJECT; |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 1048 | } |
| 1049 | |
Jeff Tinker | 6d998b6 | 2017-12-18 14:37:43 -0800 | [diff] [blame] | 1050 | status_t DrmHal::getHdcpLevels(DrmPlugin::HdcpLevel *connected, |
| 1051 | DrmPlugin::HdcpLevel *max) const { |
| 1052 | Mutex::Autolock autoLock(mLock); |
| 1053 | INIT_CHECK(); |
| 1054 | |
| 1055 | if (connected == NULL || max == NULL) { |
| 1056 | return BAD_VALUE; |
| 1057 | } |
| 1058 | status_t err = UNKNOWN_ERROR; |
| 1059 | |
Jeff Tinker | 6d998b6 | 2017-12-18 14:37:43 -0800 | [diff] [blame] | 1060 | *connected = DrmPlugin::kHdcpLevelUnknown; |
| 1061 | *max = DrmPlugin::kHdcpLevelUnknown; |
| 1062 | |
Jeff Tinker | 44c2cc4 | 2019-01-14 10:24:18 -0800 | [diff] [blame] | 1063 | Return<void> hResult; |
| 1064 | if (mPluginV1_2 != NULL) { |
| 1065 | hResult = mPluginV1_2->getHdcpLevels_1_2( |
| 1066 | [&](Status_V1_2 status, const HdcpLevel_V1_2& hConnected, const HdcpLevel_V1_2& hMax) { |
| 1067 | if (status == Status_V1_2::OK) { |
| 1068 | *connected = toHdcpLevel(hConnected); |
| 1069 | *max = toHdcpLevel(hMax); |
| 1070 | } |
Robert Shih | 5944a0b | 2021-02-10 04:26:33 -0800 | [diff] [blame] | 1071 | err = toStatusT(status); |
Jeff Tinker | 44c2cc4 | 2019-01-14 10:24:18 -0800 | [diff] [blame] | 1072 | }); |
| 1073 | } else if (mPluginV1_1 != NULL) { |
| 1074 | hResult = mPluginV1_1->getHdcpLevels( |
| 1075 | [&](Status status, const HdcpLevel& hConnected, const HdcpLevel& hMax) { |
| 1076 | if (status == Status::OK) { |
| 1077 | *connected = toHdcpLevel(static_cast<HdcpLevel_V1_2>(hConnected)); |
| 1078 | *max = toHdcpLevel(static_cast<HdcpLevel_V1_2>(hMax)); |
| 1079 | } |
| 1080 | err = toStatusT(status); |
| 1081 | }); |
| 1082 | } else { |
| 1083 | return ERROR_DRM_CANNOT_HANDLE; |
| 1084 | } |
Jeff Tinker | 6d998b6 | 2017-12-18 14:37:43 -0800 | [diff] [blame] | 1085 | |
| 1086 | return hResult.isOk() ? err : DEAD_OBJECT; |
| 1087 | } |
| 1088 | |
| 1089 | status_t DrmHal::getNumberOfSessions(uint32_t *open, uint32_t *max) const { |
| 1090 | Mutex::Autolock autoLock(mLock); |
| 1091 | INIT_CHECK(); |
| 1092 | |
| 1093 | if (open == NULL || max == NULL) { |
| 1094 | return BAD_VALUE; |
| 1095 | } |
| 1096 | status_t err = UNKNOWN_ERROR; |
| 1097 | |
| 1098 | *open = 0; |
| 1099 | *max = 0; |
| 1100 | |
| 1101 | if (mPluginV1_1 == NULL) { |
| 1102 | return ERROR_DRM_CANNOT_HANDLE; |
| 1103 | } |
| 1104 | |
| 1105 | Return<void> hResult = mPluginV1_1->getNumberOfSessions( |
| 1106 | [&](Status status, uint32_t hOpen, uint32_t hMax) { |
| 1107 | if (status == Status::OK) { |
| 1108 | *open = hOpen; |
| 1109 | *max = hMax; |
| 1110 | } |
| 1111 | err = toStatusT(status); |
| 1112 | } |
| 1113 | ); |
| 1114 | |
| 1115 | return hResult.isOk() ? err : DEAD_OBJECT; |
| 1116 | } |
| 1117 | |
| 1118 | status_t DrmHal::getSecurityLevel(Vector<uint8_t> const &sessionId, |
| 1119 | DrmPlugin::SecurityLevel *level) const { |
| 1120 | Mutex::Autolock autoLock(mLock); |
| 1121 | INIT_CHECK(); |
| 1122 | |
| 1123 | if (level == NULL) { |
| 1124 | return BAD_VALUE; |
| 1125 | } |
| 1126 | status_t err = UNKNOWN_ERROR; |
| 1127 | |
| 1128 | if (mPluginV1_1 == NULL) { |
| 1129 | return ERROR_DRM_CANNOT_HANDLE; |
| 1130 | } |
| 1131 | |
| 1132 | *level = DrmPlugin::kSecurityLevelUnknown; |
| 1133 | |
| 1134 | Return<void> hResult = mPluginV1_1->getSecurityLevel(toHidlVec(sessionId), |
| 1135 | [&](Status status, SecurityLevel hLevel) { |
| 1136 | if (status == Status::OK) { |
| 1137 | *level = toSecurityLevel(hLevel); |
| 1138 | } |
| 1139 | err = toStatusT(status); |
| 1140 | } |
| 1141 | ); |
| 1142 | |
| 1143 | return hResult.isOk() ? err : DEAD_OBJECT; |
| 1144 | } |
| 1145 | |
Jeff Tinker | c8baaba | 2018-10-23 11:32:36 -0700 | [diff] [blame] | 1146 | status_t DrmHal::getOfflineLicenseKeySetIds(List<Vector<uint8_t>> &keySetIds) const { |
| 1147 | Mutex::Autolock autoLock(mLock); |
| 1148 | |
| 1149 | if (mInitCheck != OK) { |
| 1150 | return mInitCheck; |
| 1151 | } |
| 1152 | |
| 1153 | if (mPluginV1_2 == NULL) { |
Jeff Tinker | db3fa5f | 2019-01-25 22:56:56 -0800 | [diff] [blame] | 1154 | return ERROR_UNSUPPORTED; |
Jeff Tinker | c8baaba | 2018-10-23 11:32:36 -0700 | [diff] [blame] | 1155 | } |
| 1156 | |
| 1157 | status_t err = UNKNOWN_ERROR; |
| 1158 | |
| 1159 | Return<void> hResult = mPluginV1_2->getOfflineLicenseKeySetIds( |
| 1160 | [&](Status status, const hidl_vec<KeySetId>& hKeySetIds) { |
| 1161 | if (status == Status::OK) { |
| 1162 | keySetIds = toKeySetIds(hKeySetIds); |
| 1163 | } |
| 1164 | err = toStatusT(status); |
| 1165 | } |
| 1166 | ); |
| 1167 | |
| 1168 | return hResult.isOk() ? err : DEAD_OBJECT; |
| 1169 | } |
| 1170 | |
| 1171 | status_t DrmHal::removeOfflineLicense(Vector<uint8_t> const &keySetId) { |
| 1172 | Mutex::Autolock autoLock(mLock); |
| 1173 | |
| 1174 | if (mInitCheck != OK) { |
| 1175 | return mInitCheck; |
| 1176 | } |
| 1177 | |
| 1178 | if (mPluginV1_2 == NULL) { |
Jeff Tinker | db3fa5f | 2019-01-25 22:56:56 -0800 | [diff] [blame] | 1179 | return ERROR_UNSUPPORTED; |
Jeff Tinker | c8baaba | 2018-10-23 11:32:36 -0700 | [diff] [blame] | 1180 | } |
| 1181 | |
| 1182 | Return<Status> status = mPluginV1_2->removeOfflineLicense(toHidlVec(keySetId)); |
| 1183 | return status.isOk() ? toStatusT(status) : DEAD_OBJECT; |
| 1184 | } |
| 1185 | |
| 1186 | status_t DrmHal::getOfflineLicenseState(Vector<uint8_t> const &keySetId, |
| 1187 | DrmPlugin::OfflineLicenseState *licenseState) const { |
| 1188 | Mutex::Autolock autoLock(mLock); |
| 1189 | |
| 1190 | if (mInitCheck != OK) { |
| 1191 | return mInitCheck; |
| 1192 | } |
| 1193 | |
| 1194 | if (mPluginV1_2 == NULL) { |
Jeff Tinker | db3fa5f | 2019-01-25 22:56:56 -0800 | [diff] [blame] | 1195 | return ERROR_UNSUPPORTED; |
Jeff Tinker | c8baaba | 2018-10-23 11:32:36 -0700 | [diff] [blame] | 1196 | } |
| 1197 | *licenseState = DrmPlugin::kOfflineLicenseStateUnknown; |
| 1198 | |
| 1199 | status_t err = UNKNOWN_ERROR; |
| 1200 | |
| 1201 | Return<void> hResult = mPluginV1_2->getOfflineLicenseState(toHidlVec(keySetId), |
| 1202 | [&](Status status, OfflineLicenseState hLicenseState) { |
| 1203 | if (status == Status::OK) { |
| 1204 | *licenseState = toOfflineLicenseState(hLicenseState); |
| 1205 | } |
| 1206 | err = toStatusT(status); |
| 1207 | } |
| 1208 | ); |
| 1209 | |
| 1210 | return hResult.isOk() ? err : DEAD_OBJECT; |
| 1211 | } |
| 1212 | |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 1213 | status_t DrmHal::getPropertyString(String8 const &name, String8 &value ) const { |
| 1214 | Mutex::Autolock autoLock(mLock); |
John W. Bruce | 33ecc4f | 2017-04-03 16:49:05 -0700 | [diff] [blame] | 1215 | return getPropertyStringInternal(name, value); |
| 1216 | } |
| 1217 | |
| 1218 | status_t DrmHal::getPropertyStringInternal(String8 const &name, String8 &value) const { |
| 1219 | // This function is internal to the class and should only be called while |
| 1220 | // mLock is already held. |
Jeff Tinker | 6d998b6 | 2017-12-18 14:37:43 -0800 | [diff] [blame] | 1221 | INIT_CHECK(); |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 1222 | |
| 1223 | status_t err = UNKNOWN_ERROR; |
| 1224 | |
| 1225 | Return<void> hResult = mPlugin->getPropertyString(toHidlString(name), |
| 1226 | [&](Status status, const hidl_string& hValue) { |
| 1227 | if (status == Status::OK) { |
| 1228 | value = toString8(hValue); |
| 1229 | } |
| 1230 | err = toStatusT(status); |
| 1231 | } |
| 1232 | ); |
| 1233 | |
| 1234 | return hResult.isOk() ? err : DEAD_OBJECT; |
| 1235 | } |
| 1236 | |
| 1237 | status_t DrmHal::getPropertyByteArray(String8 const &name, Vector<uint8_t> &value ) const { |
| 1238 | Mutex::Autolock autoLock(mLock); |
John W. Bruce | 33ecc4f | 2017-04-03 16:49:05 -0700 | [diff] [blame] | 1239 | return getPropertyByteArrayInternal(name, value); |
| 1240 | } |
| 1241 | |
| 1242 | status_t DrmHal::getPropertyByteArrayInternal(String8 const &name, Vector<uint8_t> &value ) const { |
| 1243 | // This function is internal to the class and should only be called while |
| 1244 | // mLock is already held. |
Jeff Tinker | 6d998b6 | 2017-12-18 14:37:43 -0800 | [diff] [blame] | 1245 | INIT_CHECK(); |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 1246 | |
| 1247 | status_t err = UNKNOWN_ERROR; |
| 1248 | |
| 1249 | Return<void> hResult = mPlugin->getPropertyByteArray(toHidlString(name), |
| 1250 | [&](Status status, const hidl_vec<uint8_t>& hValue) { |
| 1251 | if (status == Status::OK) { |
| 1252 | value = toVector(hValue); |
| 1253 | } |
| 1254 | err = toStatusT(status); |
| 1255 | } |
| 1256 | ); |
| 1257 | |
Adam Stone | cea91ce | 2018-01-22 19:23:28 -0800 | [diff] [blame] | 1258 | err = hResult.isOk() ? err : DEAD_OBJECT; |
| 1259 | if (name == kPropertyDeviceUniqueId) { |
| 1260 | mMetrics.mGetDeviceUniqueIdCounter.Increment(err); |
| 1261 | } |
| 1262 | return err; |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 1263 | } |
| 1264 | |
| 1265 | status_t DrmHal::setPropertyString(String8 const &name, String8 const &value ) const { |
| 1266 | Mutex::Autolock autoLock(mLock); |
Jeff Tinker | 6d998b6 | 2017-12-18 14:37:43 -0800 | [diff] [blame] | 1267 | INIT_CHECK(); |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 1268 | |
Jeff Tinker | 58ad475 | 2018-02-16 16:51:59 -0800 | [diff] [blame] | 1269 | Return<Status> status = mPlugin->setPropertyString(toHidlString(name), |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 1270 | toHidlString(value)); |
Jeff Tinker | 58ad475 | 2018-02-16 16:51:59 -0800 | [diff] [blame] | 1271 | return status.isOk() ? toStatusT(status) : DEAD_OBJECT; |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 1272 | } |
| 1273 | |
| 1274 | status_t DrmHal::setPropertyByteArray(String8 const &name, |
| 1275 | Vector<uint8_t> const &value ) const { |
| 1276 | Mutex::Autolock autoLock(mLock); |
Jeff Tinker | 6d998b6 | 2017-12-18 14:37:43 -0800 | [diff] [blame] | 1277 | INIT_CHECK(); |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 1278 | |
Jeff Tinker | 58ad475 | 2018-02-16 16:51:59 -0800 | [diff] [blame] | 1279 | Return<Status> status = mPlugin->setPropertyByteArray(toHidlString(name), |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 1280 | toHidlVec(value)); |
Jeff Tinker | 58ad475 | 2018-02-16 16:51:59 -0800 | [diff] [blame] | 1281 | return status.isOk() ? toStatusT(status) : DEAD_OBJECT; |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 1282 | } |
| 1283 | |
Robert Shih | 9353881 | 2019-11-12 12:21:35 -0800 | [diff] [blame] | 1284 | status_t DrmHal::getMetrics(const sp<IDrmMetricsConsumer> &consumer) { |
| 1285 | if (consumer == nullptr) { |
Adam Stone | 28f27c3 | 2018-02-05 15:07:48 -0800 | [diff] [blame] | 1286 | return UNEXPECTED_NULL; |
| 1287 | } |
Robert Shih | 9353881 | 2019-11-12 12:21:35 -0800 | [diff] [blame] | 1288 | consumer->consumeFrameworkMetrics(mMetrics); |
Adam Stone | 28f27c3 | 2018-02-05 15:07:48 -0800 | [diff] [blame] | 1289 | |
| 1290 | // Append vendor metrics if they are supported. |
| 1291 | if (mPluginV1_1 != NULL) { |
| 1292 | String8 vendor; |
| 1293 | String8 description; |
| 1294 | if (getPropertyStringInternal(String8("vendor"), vendor) != OK |
| 1295 | || vendor.isEmpty()) { |
| 1296 | ALOGE("Get vendor failed or is empty"); |
| 1297 | vendor = "NONE"; |
| 1298 | } |
| 1299 | if (getPropertyStringInternal(String8("description"), description) != OK |
| 1300 | || description.isEmpty()) { |
| 1301 | ALOGE("Get description failed or is empty."); |
| 1302 | description = "NONE"; |
| 1303 | } |
| 1304 | vendor += "."; |
| 1305 | vendor += description; |
| 1306 | |
| 1307 | hidl_vec<DrmMetricGroup> pluginMetrics; |
| 1308 | status_t err = UNKNOWN_ERROR; |
| 1309 | |
| 1310 | Return<void> status = mPluginV1_1->getMetrics( |
| 1311 | [&](Status status, hidl_vec<DrmMetricGroup> pluginMetrics) { |
| 1312 | if (status != Status::OK) { |
| 1313 | ALOGV("Error getting plugin metrics: %d", status); |
| 1314 | } else { |
Robert Shih | 9353881 | 2019-11-12 12:21:35 -0800 | [diff] [blame] | 1315 | consumer->consumeHidlMetrics(vendor, pluginMetrics); |
Adam Stone | 28f27c3 | 2018-02-05 15:07:48 -0800 | [diff] [blame] | 1316 | } |
| 1317 | err = toStatusT(status); |
| 1318 | }); |
| 1319 | return status.isOk() ? err : DEAD_OBJECT; |
Adam Stone | f0e618d | 2018-01-17 19:20:41 -0800 | [diff] [blame] | 1320 | } |
| 1321 | |
Adam Stone | ab394d1 | 2017-12-22 12:34:20 -0800 | [diff] [blame] | 1322 | return OK; |
| 1323 | } |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 1324 | |
| 1325 | status_t DrmHal::setCipherAlgorithm(Vector<uint8_t> const &sessionId, |
| 1326 | String8 const &algorithm) { |
| 1327 | Mutex::Autolock autoLock(mLock); |
Jeff Tinker | 6d998b6 | 2017-12-18 14:37:43 -0800 | [diff] [blame] | 1328 | INIT_CHECK(); |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 1329 | |
| 1330 | DrmSessionManager::Instance()->useSession(sessionId); |
| 1331 | |
Jeff Tinker | e641294 | 2018-04-30 17:35:16 -0700 | [diff] [blame] | 1332 | Return<Status> status = mPlugin->setCipherAlgorithm(toHidlVec(sessionId), |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 1333 | toHidlString(algorithm)); |
Jeff Tinker | e641294 | 2018-04-30 17:35:16 -0700 | [diff] [blame] | 1334 | return status.isOk() ? toStatusT(status) : DEAD_OBJECT; |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 1335 | } |
| 1336 | |
| 1337 | status_t DrmHal::setMacAlgorithm(Vector<uint8_t> const &sessionId, |
| 1338 | String8 const &algorithm) { |
| 1339 | Mutex::Autolock autoLock(mLock); |
Jeff Tinker | 6d998b6 | 2017-12-18 14:37:43 -0800 | [diff] [blame] | 1340 | INIT_CHECK(); |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 1341 | |
| 1342 | DrmSessionManager::Instance()->useSession(sessionId); |
| 1343 | |
Jeff Tinker | e641294 | 2018-04-30 17:35:16 -0700 | [diff] [blame] | 1344 | Return<Status> status = mPlugin->setMacAlgorithm(toHidlVec(sessionId), |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 1345 | toHidlString(algorithm)); |
Jeff Tinker | e641294 | 2018-04-30 17:35:16 -0700 | [diff] [blame] | 1346 | return status.isOk() ? toStatusT(status) : DEAD_OBJECT; |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 1347 | } |
| 1348 | |
| 1349 | status_t DrmHal::encrypt(Vector<uint8_t> const &sessionId, |
Edwin Wong | 68b3d9f | 2017-01-06 19:07:54 -0800 | [diff] [blame] | 1350 | Vector<uint8_t> const &keyId, Vector<uint8_t> const &input, |
| 1351 | Vector<uint8_t> const &iv, Vector<uint8_t> &output) { |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 1352 | Mutex::Autolock autoLock(mLock); |
Jeff Tinker | 6d998b6 | 2017-12-18 14:37:43 -0800 | [diff] [blame] | 1353 | INIT_CHECK(); |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 1354 | |
| 1355 | DrmSessionManager::Instance()->useSession(sessionId); |
| 1356 | |
| 1357 | status_t err = UNKNOWN_ERROR; |
| 1358 | |
| 1359 | Return<void> hResult = mPlugin->encrypt(toHidlVec(sessionId), |
| 1360 | toHidlVec(keyId), toHidlVec(input), toHidlVec(iv), |
| 1361 | [&](Status status, const hidl_vec<uint8_t>& hOutput) { |
| 1362 | if (status == Status::OK) { |
| 1363 | output = toVector(hOutput); |
| 1364 | } |
| 1365 | err = toStatusT(status); |
| 1366 | } |
| 1367 | ); |
| 1368 | |
| 1369 | return hResult.isOk() ? err : DEAD_OBJECT; |
| 1370 | } |
| 1371 | |
| 1372 | status_t DrmHal::decrypt(Vector<uint8_t> const &sessionId, |
Edwin Wong | 68b3d9f | 2017-01-06 19:07:54 -0800 | [diff] [blame] | 1373 | Vector<uint8_t> const &keyId, Vector<uint8_t> const &input, |
| 1374 | Vector<uint8_t> const &iv, Vector<uint8_t> &output) { |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 1375 | Mutex::Autolock autoLock(mLock); |
Jeff Tinker | 6d998b6 | 2017-12-18 14:37:43 -0800 | [diff] [blame] | 1376 | INIT_CHECK(); |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 1377 | |
| 1378 | DrmSessionManager::Instance()->useSession(sessionId); |
| 1379 | |
| 1380 | status_t err = UNKNOWN_ERROR; |
| 1381 | |
| 1382 | Return<void> hResult = mPlugin->decrypt(toHidlVec(sessionId), |
| 1383 | toHidlVec(keyId), toHidlVec(input), toHidlVec(iv), |
| 1384 | [&](Status status, const hidl_vec<uint8_t>& hOutput) { |
| 1385 | if (status == Status::OK) { |
| 1386 | output = toVector(hOutput); |
| 1387 | } |
| 1388 | err = toStatusT(status); |
| 1389 | } |
| 1390 | ); |
| 1391 | |
| 1392 | return hResult.isOk() ? err : DEAD_OBJECT; |
| 1393 | } |
| 1394 | |
| 1395 | status_t DrmHal::sign(Vector<uint8_t> const &sessionId, |
Edwin Wong | 68b3d9f | 2017-01-06 19:07:54 -0800 | [diff] [blame] | 1396 | Vector<uint8_t> const &keyId, Vector<uint8_t> const &message, |
| 1397 | Vector<uint8_t> &signature) { |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 1398 | Mutex::Autolock autoLock(mLock); |
Jeff Tinker | 6d998b6 | 2017-12-18 14:37:43 -0800 | [diff] [blame] | 1399 | INIT_CHECK(); |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 1400 | |
| 1401 | DrmSessionManager::Instance()->useSession(sessionId); |
| 1402 | |
| 1403 | status_t err = UNKNOWN_ERROR; |
| 1404 | |
| 1405 | Return<void> hResult = mPlugin->sign(toHidlVec(sessionId), |
| 1406 | toHidlVec(keyId), toHidlVec(message), |
| 1407 | [&](Status status, const hidl_vec<uint8_t>& hSignature) { |
| 1408 | if (status == Status::OK) { |
| 1409 | signature = toVector(hSignature); |
| 1410 | } |
| 1411 | err = toStatusT(status); |
| 1412 | } |
| 1413 | ); |
| 1414 | |
| 1415 | return hResult.isOk() ? err : DEAD_OBJECT; |
| 1416 | } |
| 1417 | |
| 1418 | status_t DrmHal::verify(Vector<uint8_t> const &sessionId, |
Edwin Wong | 68b3d9f | 2017-01-06 19:07:54 -0800 | [diff] [blame] | 1419 | Vector<uint8_t> const &keyId, Vector<uint8_t> const &message, |
| 1420 | Vector<uint8_t> const &signature, bool &match) { |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 1421 | Mutex::Autolock autoLock(mLock); |
Jeff Tinker | 6d998b6 | 2017-12-18 14:37:43 -0800 | [diff] [blame] | 1422 | INIT_CHECK(); |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 1423 | |
| 1424 | DrmSessionManager::Instance()->useSession(sessionId); |
| 1425 | |
| 1426 | status_t err = UNKNOWN_ERROR; |
| 1427 | |
| 1428 | Return<void> hResult = mPlugin->verify(toHidlVec(sessionId),toHidlVec(keyId), |
| 1429 | toHidlVec(message), toHidlVec(signature), |
| 1430 | [&](Status status, bool hMatch) { |
| 1431 | if (status == Status::OK) { |
| 1432 | match = hMatch; |
| 1433 | } else { |
| 1434 | match = false; |
| 1435 | } |
| 1436 | err = toStatusT(status); |
| 1437 | } |
| 1438 | ); |
| 1439 | |
| 1440 | return hResult.isOk() ? err : DEAD_OBJECT; |
| 1441 | } |
| 1442 | |
| 1443 | status_t DrmHal::signRSA(Vector<uint8_t> const &sessionId, |
Edwin Wong | 68b3d9f | 2017-01-06 19:07:54 -0800 | [diff] [blame] | 1444 | String8 const &algorithm, Vector<uint8_t> const &message, |
| 1445 | Vector<uint8_t> const &wrappedKey, Vector<uint8_t> &signature) { |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 1446 | Mutex::Autolock autoLock(mLock); |
Jeff Tinker | 6d998b6 | 2017-12-18 14:37:43 -0800 | [diff] [blame] | 1447 | INIT_CHECK(); |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 1448 | |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 1449 | DrmSessionManager::Instance()->useSession(sessionId); |
| 1450 | |
| 1451 | status_t err = UNKNOWN_ERROR; |
| 1452 | |
| 1453 | Return<void> hResult = mPlugin->signRSA(toHidlVec(sessionId), |
| 1454 | toHidlString(algorithm), toHidlVec(message), toHidlVec(wrappedKey), |
| 1455 | [&](Status status, const hidl_vec<uint8_t>& hSignature) { |
| 1456 | if (status == Status::OK) { |
| 1457 | signature = toVector(hSignature); |
| 1458 | } |
| 1459 | err = toStatusT(status); |
| 1460 | } |
| 1461 | ); |
| 1462 | |
| 1463 | return hResult.isOk() ? err : DEAD_OBJECT; |
| 1464 | } |
| 1465 | |
Adam Stone | fb679e3 | 2018-02-07 10:25:48 -0800 | [diff] [blame] | 1466 | void DrmHal::reportFrameworkMetrics() const |
| 1467 | { |
Robert Shih | 82ea6be | 2019-11-07 17:47:23 -0800 | [diff] [blame] | 1468 | mediametrics_handle_t item(mediametrics_create("mediadrm")); |
| 1469 | mediametrics_setUid(item, mMetrics.GetAppUid()); |
Adam Stone | fb679e3 | 2018-02-07 10:25:48 -0800 | [diff] [blame] | 1470 | String8 vendor; |
| 1471 | String8 description; |
| 1472 | status_t result = getPropertyStringInternal(String8("vendor"), vendor); |
| 1473 | if (result != OK) { |
Jeff Tinker | 987ac70 | 2018-02-15 17:02:22 -0800 | [diff] [blame] | 1474 | ALOGE("Failed to get vendor from drm plugin: %d", result); |
Adam Stone | fb679e3 | 2018-02-07 10:25:48 -0800 | [diff] [blame] | 1475 | } else { |
Robert Shih | 82ea6be | 2019-11-07 17:47:23 -0800 | [diff] [blame] | 1476 | mediametrics_setCString(item, "vendor", vendor.c_str()); |
Adam Stone | fb679e3 | 2018-02-07 10:25:48 -0800 | [diff] [blame] | 1477 | } |
| 1478 | result = getPropertyStringInternal(String8("description"), description); |
| 1479 | if (result != OK) { |
Jeff Tinker | 987ac70 | 2018-02-15 17:02:22 -0800 | [diff] [blame] | 1480 | ALOGE("Failed to get description from drm plugin: %d", result); |
Adam Stone | fb679e3 | 2018-02-07 10:25:48 -0800 | [diff] [blame] | 1481 | } else { |
Robert Shih | 82ea6be | 2019-11-07 17:47:23 -0800 | [diff] [blame] | 1482 | mediametrics_setCString(item, "description", description.c_str()); |
Adam Stone | fb679e3 | 2018-02-07 10:25:48 -0800 | [diff] [blame] | 1483 | } |
Adam Stone | ab394d1 | 2017-12-22 12:34:20 -0800 | [diff] [blame] | 1484 | |
Adam Stone | fb679e3 | 2018-02-07 10:25:48 -0800 | [diff] [blame] | 1485 | std::string serializedMetrics; |
| 1486 | result = mMetrics.GetSerializedMetrics(&serializedMetrics); |
| 1487 | if (result != OK) { |
Jeff Tinker | 987ac70 | 2018-02-15 17:02:22 -0800 | [diff] [blame] | 1488 | ALOGE("Failed to serialize framework metrics: %d", result); |
Adam Stone | fb679e3 | 2018-02-07 10:25:48 -0800 | [diff] [blame] | 1489 | } |
Adam Stone | 32494f5 | 2018-02-26 22:53:27 -0800 | [diff] [blame] | 1490 | std::string b64EncodedMetrics = toBase64StringNoPad(serializedMetrics.data(), |
| 1491 | serializedMetrics.size()); |
| 1492 | if (!b64EncodedMetrics.empty()) { |
Robert Shih | 82ea6be | 2019-11-07 17:47:23 -0800 | [diff] [blame] | 1493 | mediametrics_setCString(item, "serialized_metrics", b64EncodedMetrics.c_str()); |
Adam Stone | fb679e3 | 2018-02-07 10:25:48 -0800 | [diff] [blame] | 1494 | } |
Robert Shih | 82ea6be | 2019-11-07 17:47:23 -0800 | [diff] [blame] | 1495 | if (!mediametrics_selfRecord(item)) { |
Jeff Tinker | 987ac70 | 2018-02-15 17:02:22 -0800 | [diff] [blame] | 1496 | ALOGE("Failed to self record framework metrics"); |
Adam Stone | fb679e3 | 2018-02-07 10:25:48 -0800 | [diff] [blame] | 1497 | } |
Robert Shih | 82ea6be | 2019-11-07 17:47:23 -0800 | [diff] [blame] | 1498 | mediametrics_delete(item); |
Adam Stone | fb679e3 | 2018-02-07 10:25:48 -0800 | [diff] [blame] | 1499 | } |
| 1500 | |
| 1501 | void DrmHal::reportPluginMetrics() const |
John W. Bruce | 33ecc4f | 2017-04-03 16:49:05 -0700 | [diff] [blame] | 1502 | { |
Adam Stone | 32494f5 | 2018-02-26 22:53:27 -0800 | [diff] [blame] | 1503 | Vector<uint8_t> metricsVector; |
John W. Bruce | 33ecc4f | 2017-04-03 16:49:05 -0700 | [diff] [blame] | 1504 | String8 vendor; |
| 1505 | String8 description; |
| 1506 | if (getPropertyStringInternal(String8("vendor"), vendor) == OK && |
| 1507 | getPropertyStringInternal(String8("description"), description) == OK && |
Adam Stone | 32494f5 | 2018-02-26 22:53:27 -0800 | [diff] [blame] | 1508 | getPropertyByteArrayInternal(String8("metrics"), metricsVector) == OK) { |
| 1509 | std::string metricsString = toBase64StringNoPad(metricsVector.array(), |
| 1510 | metricsVector.size()); |
| 1511 | status_t res = android::reportDrmPluginMetrics(metricsString, vendor, |
Robert Shih | 82ea6be | 2019-11-07 17:47:23 -0800 | [diff] [blame] | 1512 | description, mMetrics.GetAppUid()); |
John W. Bruce | 33ecc4f | 2017-04-03 16:49:05 -0700 | [diff] [blame] | 1513 | if (res != OK) { |
Jeff Tinker | 987ac70 | 2018-02-15 17:02:22 -0800 | [diff] [blame] | 1514 | ALOGE("Metrics were retrieved but could not be reported: %d", res); |
John W. Bruce | 33ecc4f | 2017-04-03 16:49:05 -0700 | [diff] [blame] | 1515 | } |
| 1516 | } |
| 1517 | } |
| 1518 | |
Robert Shih | fbe581e | 2021-01-14 05:12:04 -0800 | [diff] [blame] | 1519 | bool DrmHal::requiresSecureDecoder(const char *mime) const { |
| 1520 | Mutex::Autolock autoLock(mLock); |
| 1521 | if (mPluginV1_4 == NULL) { |
| 1522 | return false; |
| 1523 | } |
| 1524 | return mPluginV1_4->requiresSecureDecoderDefault(hidl_string(mime)); |
| 1525 | } |
| 1526 | |
| 1527 | bool DrmHal::requiresSecureDecoder(const char *mime, |
| 1528 | DrmPlugin::SecurityLevel securityLevel) const { |
| 1529 | Mutex::Autolock autoLock(mLock); |
| 1530 | if (mPluginV1_4 == NULL) { |
| 1531 | return false; |
| 1532 | } |
| 1533 | auto hLevel = toHidlSecurityLevel(securityLevel); |
| 1534 | return mPluginV1_4->requiresSecureDecoder(hidl_string(mime), hLevel); |
| 1535 | } |
| 1536 | |
Robert Shih | 726afea | 2021-01-17 23:41:12 -0800 | [diff] [blame] | 1537 | status_t DrmHal::setPlaybackId(Vector<uint8_t> const &sessionId, const char *playbackId) { |
| 1538 | Mutex::Autolock autoLock(mLock); |
| 1539 | if (mPluginV1_4 == NULL) { |
| 1540 | return ERROR_UNSUPPORTED; |
| 1541 | } |
| 1542 | drm::V1_0::Status err = mPluginV1_4->setPlaybackId( |
| 1543 | toHidlVec(sessionId), |
| 1544 | hidl_string(playbackId)); |
| 1545 | return toStatusT(err); |
| 1546 | } |
| 1547 | |
Robert Shih | 9afca95 | 2021-02-12 01:36:06 -0800 | [diff] [blame^] | 1548 | status_t DrmHal::getLogMessages(Vector<drm::V1_4::LogMessage> &logs) const { |
| 1549 | Mutex::Autolock autoLock(mLock); |
| 1550 | return DrmUtils::GetLogMessages<drm::V1_4::IDrmPlugin>(mPlugin, logs); |
| 1551 | } |
| 1552 | |
Jeff Tinker | a53d655 | 2017-01-20 00:31:46 -0800 | [diff] [blame] | 1553 | } // namespace android |