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