Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 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 "IDrm" |
| 19 | #include <utils/Log.h> |
| 20 | |
| 21 | #include <binder/Parcel.h> |
| 22 | #include <media/IDrm.h> |
| 23 | #include <media/stagefright/MediaErrors.h> |
| 24 | #include <media/stagefright/foundation/ADebug.h> |
| 25 | #include <media/stagefright/foundation/AString.h> |
| 26 | |
| 27 | namespace android { |
| 28 | |
| 29 | enum { |
| 30 | INIT_CHECK = IBinder::FIRST_CALL_TRANSACTION, |
| 31 | IS_CRYPTO_SUPPORTED, |
| 32 | CREATE_PLUGIN, |
| 33 | DESTROY_PLUGIN, |
| 34 | OPEN_SESSION, |
| 35 | CLOSE_SESSION, |
Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 36 | GET_KEY_REQUEST, |
| 37 | PROVIDE_KEY_RESPONSE, |
| 38 | REMOVE_KEYS, |
| 39 | RESTORE_KEYS, |
| 40 | QUERY_KEY_STATUS, |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 41 | GET_PROVISION_REQUEST, |
| 42 | PROVIDE_PROVISION_RESPONSE, |
| 43 | GET_SECURE_STOPS, |
| 44 | RELEASE_SECURE_STOPS, |
| 45 | GET_PROPERTY_STRING, |
| 46 | GET_PROPERTY_BYTE_ARRAY, |
| 47 | SET_PROPERTY_STRING, |
Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 48 | SET_PROPERTY_BYTE_ARRAY, |
Adam Stone | ab394d1 | 2017-12-22 12:34:20 -0800 | [diff] [blame] | 49 | GET_METRICS, |
Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 50 | SET_CIPHER_ALGORITHM, |
| 51 | SET_MAC_ALGORITHM, |
| 52 | ENCRYPT, |
| 53 | DECRYPT, |
| 54 | SIGN, |
Jeff Tinker | 68d9d71 | 2014-03-04 13:21:31 -0800 | [diff] [blame] | 55 | SIGN_RSA, |
Jeff Tinker | c0d5f1f | 2013-04-02 13:08:05 -0700 | [diff] [blame] | 56 | VERIFY, |
Jeff Tinker | 68b1555 | 2014-04-30 10:19:03 -0700 | [diff] [blame] | 57 | SET_LISTENER, |
Jeff Tinker | 3c1285e | 2014-10-31 00:55:16 -0700 | [diff] [blame] | 58 | GET_SECURE_STOP, |
Jeff Tinker | 15177d7 | 2018-01-25 12:57:55 -0800 | [diff] [blame] | 59 | REMOVE_ALL_SECURE_STOPS, |
Jeff Tinker | 6d998b6 | 2017-12-18 14:37:43 -0800 | [diff] [blame] | 60 | GET_HDCP_LEVELS, |
| 61 | GET_NUMBER_OF_SESSIONS, |
| 62 | GET_SECURITY_LEVEL, |
Jeff Tinker | 15177d7 | 2018-01-25 12:57:55 -0800 | [diff] [blame] | 63 | REMOVE_SECURE_STOP, |
| 64 | GET_SECURE_STOP_IDS |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | struct BpDrm : public BpInterface<IDrm> { |
Chih-Hung Hsieh | 090ef60 | 2016-04-27 10:39:54 -0700 | [diff] [blame] | 68 | explicit BpDrm(const sp<IBinder> &impl) |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 69 | : BpInterface<IDrm>(impl) { |
| 70 | } |
| 71 | |
| 72 | virtual status_t initCheck() const { |
| 73 | Parcel data, reply; |
| 74 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 75 | status_t status = remote()->transact(INIT_CHECK, data, &reply); |
| 76 | if (status != OK) { |
| 77 | return status; |
| 78 | } |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 79 | |
| 80 | return reply.readInt32(); |
| 81 | } |
| 82 | |
Jeff Tinker | 9cf69e0 | 2013-08-21 11:59:23 -0700 | [diff] [blame] | 83 | virtual bool isCryptoSchemeSupported(const uint8_t uuid[16], const String8 &mimeType) { |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 84 | Parcel data, reply; |
| 85 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| 86 | data.write(uuid, 16); |
Jeff Tinker | 9cf69e0 | 2013-08-21 11:59:23 -0700 | [diff] [blame] | 87 | data.writeString8(mimeType); |
Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 88 | status_t status = remote()->transact(IS_CRYPTO_SUPPORTED, data, &reply); |
| 89 | if (status != OK) { |
| 90 | ALOGE("isCryptoSchemeSupported: binder call failed: %d", status); |
| 91 | return false; |
| 92 | } |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 93 | |
| 94 | return reply.readInt32() != 0; |
| 95 | } |
| 96 | |
Edwin Wong | 68b3d9f | 2017-01-06 19:07:54 -0800 | [diff] [blame] | 97 | virtual status_t createPlugin(const uint8_t uuid[16], |
| 98 | const String8& appPackageName) { |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 99 | Parcel data, reply; |
| 100 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| 101 | data.write(uuid, 16); |
Edwin Wong | 68b3d9f | 2017-01-06 19:07:54 -0800 | [diff] [blame] | 102 | data.writeString8(appPackageName); |
Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 103 | status_t status = remote()->transact(CREATE_PLUGIN, data, &reply); |
| 104 | if (status != OK) { |
Edwin Wong | 68b3d9f | 2017-01-06 19:07:54 -0800 | [diff] [blame] | 105 | ALOGE("createPlugin: binder call failed: %d", status); |
Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 106 | return status; |
| 107 | } |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 108 | |
| 109 | return reply.readInt32(); |
| 110 | } |
| 111 | |
| 112 | virtual status_t destroyPlugin() { |
| 113 | Parcel data, reply; |
| 114 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 115 | status_t status = remote()->transact(DESTROY_PLUGIN, data, &reply); |
| 116 | if (status != OK) { |
| 117 | return status; |
| 118 | } |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 119 | |
| 120 | return reply.readInt32(); |
| 121 | } |
| 122 | |
Jeff Tinker | 41d279a | 2018-02-11 19:52:08 +0000 | [diff] [blame^] | 123 | virtual status_t openSession(DrmPlugin::SecurityLevel securityLevel, |
| 124 | Vector<uint8_t> &sessionId) { |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 125 | Parcel data, reply; |
| 126 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
Jeff Tinker | 41d279a | 2018-02-11 19:52:08 +0000 | [diff] [blame^] | 127 | data.writeInt32(securityLevel); |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 128 | |
Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 129 | status_t status = remote()->transact(OPEN_SESSION, data, &reply); |
| 130 | if (status != OK) { |
| 131 | return status; |
| 132 | } |
Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 133 | readVector(reply, sessionId); |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 134 | |
| 135 | return reply.readInt32(); |
| 136 | } |
| 137 | |
| 138 | virtual status_t closeSession(Vector<uint8_t> const &sessionId) { |
| 139 | Parcel data, reply; |
| 140 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| 141 | |
Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 142 | writeVector(data, sessionId); |
Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 143 | status_t status = remote()->transact(CLOSE_SESSION, data, &reply); |
| 144 | if (status != OK) { |
| 145 | return status; |
| 146 | } |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 147 | |
| 148 | return reply.readInt32(); |
| 149 | } |
| 150 | |
| 151 | virtual status_t |
Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 152 | getKeyRequest(Vector<uint8_t> const &sessionId, |
| 153 | Vector<uint8_t> const &initData, |
| 154 | String8 const &mimeType, DrmPlugin::KeyType keyType, |
| 155 | KeyedVector<String8, String8> const &optionalParameters, |
Jeff Tinker | d072c90 | 2015-03-16 13:39:29 -0700 | [diff] [blame] | 156 | Vector<uint8_t> &request, String8 &defaultUrl, |
| 157 | DrmPlugin::KeyRequestType *keyRequestType) { |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 158 | Parcel data, reply; |
| 159 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| 160 | |
Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 161 | writeVector(data, sessionId); |
| 162 | writeVector(data, initData); |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 163 | data.writeString8(mimeType); |
Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 164 | data.writeInt32((uint32_t)keyType); |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 165 | |
| 166 | data.writeInt32(optionalParameters.size()); |
| 167 | for (size_t i = 0; i < optionalParameters.size(); ++i) { |
| 168 | data.writeString8(optionalParameters.keyAt(i)); |
| 169 | data.writeString8(optionalParameters.valueAt(i)); |
| 170 | } |
Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 171 | |
| 172 | status_t status = remote()->transact(GET_KEY_REQUEST, data, &reply); |
| 173 | if (status != OK) { |
| 174 | return status; |
| 175 | } |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 176 | |
Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 177 | readVector(reply, request); |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 178 | defaultUrl = reply.readString8(); |
Jeff Tinker | d072c90 | 2015-03-16 13:39:29 -0700 | [diff] [blame] | 179 | *keyRequestType = static_cast<DrmPlugin::KeyRequestType>(reply.readInt32()); |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 180 | |
| 181 | return reply.readInt32(); |
| 182 | } |
| 183 | |
Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 184 | virtual status_t provideKeyResponse(Vector<uint8_t> const &sessionId, |
| 185 | Vector<uint8_t> const &response, |
| 186 | Vector<uint8_t> &keySetId) { |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 187 | Parcel data, reply; |
| 188 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 189 | writeVector(data, sessionId); |
| 190 | writeVector(data, response); |
Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 191 | |
| 192 | status_t status = remote()->transact(PROVIDE_KEY_RESPONSE, data, &reply); |
| 193 | if (status != OK) { |
| 194 | return status; |
| 195 | } |
| 196 | |
Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 197 | readVector(reply, keySetId); |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 198 | |
| 199 | return reply.readInt32(); |
| 200 | } |
| 201 | |
Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 202 | virtual status_t removeKeys(Vector<uint8_t> const &keySetId) { |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 203 | Parcel data, reply; |
| 204 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| 205 | |
Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 206 | writeVector(data, keySetId); |
Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 207 | status_t status = remote()->transact(REMOVE_KEYS, data, &reply); |
| 208 | if (status != OK) { |
| 209 | return status; |
| 210 | } |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 211 | |
| 212 | return reply.readInt32(); |
| 213 | } |
| 214 | |
Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 215 | virtual status_t restoreKeys(Vector<uint8_t> const &sessionId, |
| 216 | Vector<uint8_t> const &keySetId) { |
| 217 | Parcel data, reply; |
| 218 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| 219 | |
| 220 | writeVector(data, sessionId); |
| 221 | writeVector(data, keySetId); |
Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 222 | status_t status = remote()->transact(RESTORE_KEYS, data, &reply); |
| 223 | if (status != OK) { |
| 224 | return status; |
| 225 | } |
Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 226 | |
| 227 | return reply.readInt32(); |
| 228 | } |
| 229 | |
| 230 | virtual status_t queryKeyStatus(Vector<uint8_t> const &sessionId, |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 231 | KeyedVector<String8, String8> &infoMap) const { |
| 232 | Parcel data, reply; |
| 233 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| 234 | |
Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 235 | writeVector(data, sessionId); |
Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 236 | status_t status = remote()->transact(QUERY_KEY_STATUS, data, &reply); |
| 237 | if (status != OK) { |
| 238 | return status; |
| 239 | } |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 240 | |
| 241 | infoMap.clear(); |
| 242 | size_t count = reply.readInt32(); |
| 243 | for (size_t i = 0; i < count; i++) { |
| 244 | String8 key = reply.readString8(); |
| 245 | String8 value = reply.readString8(); |
| 246 | infoMap.add(key, value); |
| 247 | } |
| 248 | return reply.readInt32(); |
| 249 | } |
| 250 | |
Jeff Tinker | 68d9d71 | 2014-03-04 13:21:31 -0800 | [diff] [blame] | 251 | virtual status_t getProvisionRequest(String8 const &certType, |
| 252 | String8 const &certAuthority, |
| 253 | Vector<uint8_t> &request, |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 254 | String8 &defaultUrl) { |
| 255 | Parcel data, reply; |
| 256 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| 257 | |
Jeff Tinker | 68d9d71 | 2014-03-04 13:21:31 -0800 | [diff] [blame] | 258 | data.writeString8(certType); |
| 259 | data.writeString8(certAuthority); |
Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 260 | status_t status = remote()->transact(GET_PROVISION_REQUEST, data, &reply); |
| 261 | if (status != OK) { |
| 262 | return status; |
| 263 | } |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 264 | |
Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 265 | readVector(reply, request); |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 266 | defaultUrl = reply.readString8(); |
| 267 | |
| 268 | return reply.readInt32(); |
| 269 | } |
| 270 | |
Jeff Tinker | 68d9d71 | 2014-03-04 13:21:31 -0800 | [diff] [blame] | 271 | virtual status_t provideProvisionResponse(Vector<uint8_t> const &response, |
| 272 | Vector<uint8_t> &certificate, |
| 273 | Vector<uint8_t> &wrappedKey) { |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 274 | Parcel data, reply; |
| 275 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| 276 | |
Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 277 | writeVector(data, response); |
Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 278 | status_t status = remote()->transact(PROVIDE_PROVISION_RESPONSE, data, &reply); |
| 279 | if (status != OK) { |
| 280 | return status; |
| 281 | } |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 282 | |
Jeff Tinker | 68d9d71 | 2014-03-04 13:21:31 -0800 | [diff] [blame] | 283 | readVector(reply, certificate); |
| 284 | readVector(reply, wrappedKey); |
| 285 | |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 286 | return reply.readInt32(); |
| 287 | } |
| 288 | |
| 289 | virtual status_t getSecureStops(List<Vector<uint8_t> > &secureStops) { |
| 290 | Parcel data, reply; |
| 291 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| 292 | |
Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 293 | status_t status = remote()->transact(GET_SECURE_STOPS, data, &reply); |
| 294 | if (status != OK) { |
| 295 | return status; |
| 296 | } |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 297 | |
| 298 | secureStops.clear(); |
| 299 | uint32_t count = reply.readInt32(); |
| 300 | for (size_t i = 0; i < count; i++) { |
| 301 | Vector<uint8_t> secureStop; |
Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 302 | readVector(reply, secureStop); |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 303 | secureStops.push_back(secureStop); |
| 304 | } |
| 305 | return reply.readInt32(); |
| 306 | } |
| 307 | |
Jeff Tinker | 15177d7 | 2018-01-25 12:57:55 -0800 | [diff] [blame] | 308 | virtual status_t getSecureStopIds(List<Vector<uint8_t> > &secureStopIds) { |
| 309 | Parcel data, reply; |
| 310 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| 311 | |
| 312 | status_t status = remote()->transact(GET_SECURE_STOP_IDS, data, &reply); |
| 313 | if (status != OK) { |
| 314 | return status; |
| 315 | } |
| 316 | |
| 317 | secureStopIds.clear(); |
| 318 | uint32_t count = reply.readInt32(); |
| 319 | for (size_t i = 0; i < count; i++) { |
| 320 | Vector<uint8_t> secureStopId; |
| 321 | readVector(reply, secureStopId); |
| 322 | secureStopIds.push_back(secureStopId); |
| 323 | } |
| 324 | return reply.readInt32(); |
| 325 | } |
| 326 | |
Jeff Tinker | 3c1285e | 2014-10-31 00:55:16 -0700 | [diff] [blame] | 327 | virtual status_t getSecureStop(Vector<uint8_t> const &ssid, Vector<uint8_t> &secureStop) { |
| 328 | Parcel data, reply; |
| 329 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| 330 | |
| 331 | writeVector(data, ssid); |
Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 332 | status_t status = remote()->transact(GET_SECURE_STOP, data, &reply); |
| 333 | if (status != OK) { |
| 334 | return status; |
| 335 | } |
Jeff Tinker | 3c1285e | 2014-10-31 00:55:16 -0700 | [diff] [blame] | 336 | |
| 337 | readVector(reply, secureStop); |
| 338 | return reply.readInt32(); |
| 339 | } |
| 340 | |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 341 | virtual status_t releaseSecureStops(Vector<uint8_t> const &ssRelease) { |
| 342 | Parcel data, reply; |
| 343 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| 344 | |
Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 345 | writeVector(data, ssRelease); |
Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 346 | status_t status = remote()->transact(RELEASE_SECURE_STOPS, data, &reply); |
| 347 | if (status != OK) { |
| 348 | return status; |
| 349 | } |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 350 | |
| 351 | return reply.readInt32(); |
| 352 | } |
| 353 | |
Jeff Tinker | 15177d7 | 2018-01-25 12:57:55 -0800 | [diff] [blame] | 354 | virtual status_t removeSecureStop(Vector<uint8_t> const &ssid) { |
Jeff Tinker | 3c1285e | 2014-10-31 00:55:16 -0700 | [diff] [blame] | 355 | Parcel data, reply; |
| 356 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| 357 | |
Jeff Tinker | 15177d7 | 2018-01-25 12:57:55 -0800 | [diff] [blame] | 358 | writeVector(data, ssid); |
| 359 | status_t status = remote()->transact(REMOVE_SECURE_STOP, data, &reply); |
| 360 | if (status != OK) { |
| 361 | return status; |
| 362 | } |
| 363 | |
| 364 | return reply.readInt32(); |
| 365 | } |
| 366 | |
| 367 | virtual status_t removeAllSecureStops() { |
| 368 | Parcel data, reply; |
| 369 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| 370 | |
| 371 | status_t status = remote()->transact(REMOVE_ALL_SECURE_STOPS, data, &reply); |
Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 372 | if (status != OK) { |
| 373 | return status; |
| 374 | } |
Jeff Tinker | 3c1285e | 2014-10-31 00:55:16 -0700 | [diff] [blame] | 375 | |
| 376 | return reply.readInt32(); |
| 377 | } |
| 378 | |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 379 | virtual status_t getPropertyString(String8 const &name, String8 &value) const { |
| 380 | Parcel data, reply; |
| 381 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| 382 | |
| 383 | data.writeString8(name); |
Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 384 | status_t status = remote()->transact(GET_PROPERTY_STRING, data, &reply); |
| 385 | if (status != OK) { |
| 386 | return status; |
| 387 | } |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 388 | |
| 389 | value = reply.readString8(); |
| 390 | return reply.readInt32(); |
| 391 | } |
| 392 | |
Jeff Tinker | 6d998b6 | 2017-12-18 14:37:43 -0800 | [diff] [blame] | 393 | virtual status_t getHdcpLevels(DrmPlugin::HdcpLevel *connected, |
| 394 | DrmPlugin::HdcpLevel *max) const { |
| 395 | Parcel data, reply; |
| 396 | |
| 397 | if (connected == NULL || max == NULL) { |
| 398 | return BAD_VALUE; |
| 399 | } |
| 400 | |
| 401 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| 402 | |
| 403 | status_t status = remote()->transact(GET_HDCP_LEVELS, data, &reply); |
| 404 | if (status != OK) { |
| 405 | return status; |
| 406 | } |
| 407 | |
| 408 | *connected = static_cast<DrmPlugin::HdcpLevel>(reply.readInt32()); |
| 409 | *max = static_cast<DrmPlugin::HdcpLevel>(reply.readInt32()); |
| 410 | return reply.readInt32(); |
| 411 | } |
| 412 | |
| 413 | virtual status_t getNumberOfSessions(uint32_t *open, uint32_t *max) const { |
| 414 | Parcel data, reply; |
| 415 | |
| 416 | if (open == NULL || max == NULL) { |
| 417 | return BAD_VALUE; |
| 418 | } |
| 419 | |
| 420 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| 421 | |
| 422 | status_t status = remote()->transact(GET_NUMBER_OF_SESSIONS, data, &reply); |
| 423 | if (status != OK) { |
| 424 | return status; |
| 425 | } |
| 426 | |
| 427 | *open = reply.readInt32(); |
| 428 | *max = reply.readInt32(); |
| 429 | return reply.readInt32(); |
| 430 | } |
| 431 | |
| 432 | virtual status_t getSecurityLevel(Vector<uint8_t> const &sessionId, |
| 433 | DrmPlugin::SecurityLevel *level) const { |
| 434 | Parcel data, reply; |
| 435 | |
| 436 | if (level == NULL) { |
| 437 | return BAD_VALUE; |
| 438 | } |
| 439 | |
| 440 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| 441 | |
| 442 | writeVector(data, sessionId); |
| 443 | status_t status = remote()->transact(GET_SECURITY_LEVEL, data, &reply); |
| 444 | if (status != OK) { |
| 445 | return status; |
| 446 | } |
| 447 | |
| 448 | *level = static_cast<DrmPlugin::SecurityLevel>(reply.readInt32()); |
| 449 | return reply.readInt32(); |
| 450 | } |
| 451 | |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 452 | virtual status_t getPropertyByteArray(String8 const &name, Vector<uint8_t> &value) const { |
| 453 | Parcel data, reply; |
| 454 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| 455 | |
| 456 | data.writeString8(name); |
Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 457 | status_t status = remote()->transact(GET_PROPERTY_BYTE_ARRAY, data, &reply); |
| 458 | if (status != OK) { |
| 459 | return status; |
| 460 | } |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 461 | |
Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 462 | readVector(reply, value); |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 463 | return reply.readInt32(); |
| 464 | } |
| 465 | |
| 466 | virtual status_t setPropertyString(String8 const &name, String8 const &value) const { |
| 467 | Parcel data, reply; |
| 468 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| 469 | |
| 470 | data.writeString8(name); |
| 471 | data.writeString8(value); |
Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 472 | status_t status = remote()->transact(SET_PROPERTY_STRING, data, &reply); |
| 473 | if (status != OK) { |
| 474 | return status; |
| 475 | } |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 476 | |
| 477 | return reply.readInt32(); |
| 478 | } |
| 479 | |
| 480 | virtual status_t setPropertyByteArray(String8 const &name, |
| 481 | Vector<uint8_t> const &value) const { |
| 482 | Parcel data, reply; |
| 483 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| 484 | |
| 485 | data.writeString8(name); |
Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 486 | writeVector(data, value); |
Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 487 | status_t status = remote()->transact(SET_PROPERTY_BYTE_ARRAY, data, &reply); |
| 488 | if (status != OK) { |
| 489 | return status; |
| 490 | } |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 491 | |
| 492 | return reply.readInt32(); |
| 493 | } |
| 494 | |
Adam Stone | ab394d1 | 2017-12-22 12:34:20 -0800 | [diff] [blame] | 495 | virtual status_t getMetrics(MediaAnalyticsItem *item) { |
| 496 | Parcel data, reply; |
| 497 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| 498 | |
| 499 | status_t status = remote()->transact(GET_METRICS, data, &reply); |
| 500 | if (status != OK) { |
| 501 | return status; |
| 502 | } |
| 503 | |
| 504 | item->readFromParcel(reply); |
| 505 | return reply.readInt32(); |
| 506 | } |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 507 | |
Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 508 | virtual status_t setCipherAlgorithm(Vector<uint8_t> const &sessionId, |
| 509 | String8 const &algorithm) { |
| 510 | Parcel data, reply; |
| 511 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| 512 | |
| 513 | writeVector(data, sessionId); |
| 514 | data.writeString8(algorithm); |
Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 515 | status_t status = remote()->transact(SET_CIPHER_ALGORITHM, data, &reply); |
| 516 | if (status != OK) { |
| 517 | return status; |
| 518 | } |
Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 519 | return reply.readInt32(); |
| 520 | } |
| 521 | |
| 522 | virtual status_t setMacAlgorithm(Vector<uint8_t> const &sessionId, |
| 523 | String8 const &algorithm) { |
| 524 | Parcel data, reply; |
| 525 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| 526 | |
| 527 | writeVector(data, sessionId); |
| 528 | data.writeString8(algorithm); |
Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 529 | status_t status = remote()->transact(SET_MAC_ALGORITHM, data, &reply); |
| 530 | if (status != OK) { |
| 531 | return status; |
| 532 | } |
Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 533 | return reply.readInt32(); |
| 534 | } |
| 535 | |
| 536 | virtual status_t encrypt(Vector<uint8_t> const &sessionId, |
| 537 | Vector<uint8_t> const &keyId, |
| 538 | Vector<uint8_t> const &input, |
| 539 | Vector<uint8_t> const &iv, |
| 540 | Vector<uint8_t> &output) { |
| 541 | Parcel data, reply; |
| 542 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| 543 | |
| 544 | writeVector(data, sessionId); |
| 545 | writeVector(data, keyId); |
| 546 | writeVector(data, input); |
| 547 | writeVector(data, iv); |
| 548 | |
Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 549 | status_t status = remote()->transact(ENCRYPT, data, &reply); |
| 550 | if (status != OK) { |
| 551 | return status; |
| 552 | } |
Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 553 | readVector(reply, output); |
| 554 | |
| 555 | return reply.readInt32(); |
| 556 | } |
| 557 | |
| 558 | virtual status_t decrypt(Vector<uint8_t> const &sessionId, |
| 559 | Vector<uint8_t> const &keyId, |
| 560 | Vector<uint8_t> const &input, |
| 561 | Vector<uint8_t> const &iv, |
| 562 | Vector<uint8_t> &output) { |
| 563 | Parcel data, reply; |
| 564 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| 565 | |
| 566 | writeVector(data, sessionId); |
| 567 | writeVector(data, keyId); |
| 568 | writeVector(data, input); |
| 569 | writeVector(data, iv); |
| 570 | |
Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 571 | status_t status = remote()->transact(DECRYPT, data, &reply); |
| 572 | if (status != OK) { |
| 573 | return status; |
| 574 | } |
Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 575 | readVector(reply, output); |
| 576 | |
| 577 | return reply.readInt32(); |
| 578 | } |
| 579 | |
| 580 | virtual status_t sign(Vector<uint8_t> const &sessionId, |
| 581 | Vector<uint8_t> const &keyId, |
| 582 | Vector<uint8_t> const &message, |
| 583 | Vector<uint8_t> &signature) { |
| 584 | Parcel data, reply; |
| 585 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| 586 | |
| 587 | writeVector(data, sessionId); |
| 588 | writeVector(data, keyId); |
| 589 | writeVector(data, message); |
| 590 | |
Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 591 | status_t status = remote()->transact(SIGN, data, &reply); |
| 592 | if (status != OK) { |
| 593 | return status; |
| 594 | } |
Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 595 | readVector(reply, signature); |
| 596 | |
| 597 | return reply.readInt32(); |
| 598 | } |
| 599 | |
| 600 | virtual status_t verify(Vector<uint8_t> const &sessionId, |
| 601 | Vector<uint8_t> const &keyId, |
| 602 | Vector<uint8_t> const &message, |
| 603 | Vector<uint8_t> const &signature, |
| 604 | bool &match) { |
| 605 | Parcel data, reply; |
| 606 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| 607 | |
| 608 | writeVector(data, sessionId); |
| 609 | writeVector(data, keyId); |
| 610 | writeVector(data, message); |
| 611 | writeVector(data, signature); |
| 612 | |
Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 613 | status_t status = remote()->transact(VERIFY, data, &reply); |
| 614 | if (status != OK) { |
| 615 | return status; |
| 616 | } |
Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 617 | match = (bool)reply.readInt32(); |
| 618 | return reply.readInt32(); |
| 619 | } |
| 620 | |
Jeff Tinker | 68d9d71 | 2014-03-04 13:21:31 -0800 | [diff] [blame] | 621 | virtual status_t signRSA(Vector<uint8_t> const &sessionId, |
| 622 | String8 const &algorithm, |
| 623 | Vector<uint8_t> const &message, |
| 624 | Vector<uint8_t> const &wrappedKey, |
| 625 | Vector<uint8_t> &signature) { |
| 626 | Parcel data, reply; |
| 627 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
| 628 | |
| 629 | writeVector(data, sessionId); |
| 630 | data.writeString8(algorithm); |
| 631 | writeVector(data, message); |
| 632 | writeVector(data, wrappedKey); |
| 633 | |
Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 634 | status_t status = remote()->transact(SIGN_RSA, data, &reply); |
| 635 | if (status != OK) { |
| 636 | return status; |
| 637 | } |
Jeff Tinker | 68d9d71 | 2014-03-04 13:21:31 -0800 | [diff] [blame] | 638 | readVector(reply, signature); |
| 639 | |
| 640 | return reply.readInt32(); |
| 641 | } |
| 642 | |
Jeff Tinker | c0d5f1f | 2013-04-02 13:08:05 -0700 | [diff] [blame] | 643 | virtual status_t setListener(const sp<IDrmClient>& listener) { |
| 644 | Parcel data, reply; |
| 645 | data.writeInterfaceToken(IDrm::getInterfaceDescriptor()); |
Marco Nelissen | 06b4606 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 646 | data.writeStrongBinder(IInterface::asBinder(listener)); |
Jeff Tinker | 3b5401a | 2015-06-15 17:42:10 -0700 | [diff] [blame] | 647 | status_t status = remote()->transact(SET_LISTENER, data, &reply); |
| 648 | if (status != OK) { |
| 649 | return status; |
| 650 | } |
Jeff Tinker | c0d5f1f | 2013-04-02 13:08:05 -0700 | [diff] [blame] | 651 | return reply.readInt32(); |
| 652 | } |
| 653 | |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 654 | private: |
Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 655 | void readVector(Parcel &reply, Vector<uint8_t> &vector) const { |
| 656 | uint32_t size = reply.readInt32(); |
| 657 | vector.insertAt((size_t)0, size); |
| 658 | reply.read(vector.editArray(), size); |
| 659 | } |
| 660 | |
| 661 | void writeVector(Parcel &data, Vector<uint8_t> const &vector) const { |
| 662 | data.writeInt32(vector.size()); |
| 663 | data.write(vector.array(), vector.size()); |
| 664 | } |
| 665 | |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 666 | DISALLOW_EVIL_CONSTRUCTORS(BpDrm); |
| 667 | }; |
| 668 | |
| 669 | IMPLEMENT_META_INTERFACE(Drm, "android.drm.IDrm"); |
| 670 | |
| 671 | //////////////////////////////////////////////////////////////////////////////// |
| 672 | |
Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 673 | void BnDrm::readVector(const Parcel &data, Vector<uint8_t> &vector) const { |
| 674 | uint32_t size = data.readInt32(); |
Jeff Tinker | 3cf728e | 2017-10-18 20:54:26 +0000 | [diff] [blame] | 675 | if (vector.insertAt((size_t)0, size) < 0) { |
| 676 | vector.clear(); |
| 677 | } |
| 678 | if (data.read(vector.editArray(), size) != NO_ERROR) { |
| 679 | vector.clear(); |
| 680 | android_errorWriteWithInfoLog(0x534e4554, "62872384", -1, NULL, 0); |
| 681 | } |
Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 682 | } |
| 683 | |
| 684 | void BnDrm::writeVector(Parcel *reply, Vector<uint8_t> const &vector) const { |
| 685 | reply->writeInt32(vector.size()); |
| 686 | reply->write(vector.array(), vector.size()); |
| 687 | } |
| 688 | |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 689 | status_t BnDrm::onTransact( |
| 690 | uint32_t code, const Parcel &data, Parcel *reply, uint32_t flags) { |
| 691 | switch (code) { |
| 692 | case INIT_CHECK: |
| 693 | { |
| 694 | CHECK_INTERFACE(IDrm, data, reply); |
| 695 | reply->writeInt32(initCheck()); |
| 696 | return OK; |
| 697 | } |
| 698 | |
| 699 | case IS_CRYPTO_SUPPORTED: |
| 700 | { |
| 701 | CHECK_INTERFACE(IDrm, data, reply); |
| 702 | uint8_t uuid[16]; |
| 703 | data.read(uuid, sizeof(uuid)); |
Jeff Tinker | 9cf69e0 | 2013-08-21 11:59:23 -0700 | [diff] [blame] | 704 | String8 mimeType = data.readString8(); |
| 705 | reply->writeInt32(isCryptoSchemeSupported(uuid, mimeType)); |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 706 | return OK; |
| 707 | } |
| 708 | |
| 709 | case CREATE_PLUGIN: |
| 710 | { |
| 711 | CHECK_INTERFACE(IDrm, data, reply); |
| 712 | uint8_t uuid[16]; |
| 713 | data.read(uuid, sizeof(uuid)); |
Edwin Wong | 68b3d9f | 2017-01-06 19:07:54 -0800 | [diff] [blame] | 714 | String8 appPackageName = data.readString8(); |
| 715 | reply->writeInt32(createPlugin(uuid, appPackageName)); |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 716 | return OK; |
| 717 | } |
| 718 | |
| 719 | case DESTROY_PLUGIN: |
| 720 | { |
| 721 | CHECK_INTERFACE(IDrm, data, reply); |
| 722 | reply->writeInt32(destroyPlugin()); |
| 723 | return OK; |
| 724 | } |
| 725 | |
| 726 | case OPEN_SESSION: |
| 727 | { |
| 728 | CHECK_INTERFACE(IDrm, data, reply); |
Jeff Tinker | 41d279a | 2018-02-11 19:52:08 +0000 | [diff] [blame^] | 729 | DrmPlugin::SecurityLevel level = |
| 730 | static_cast<DrmPlugin::SecurityLevel>(data.readInt32()); |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 731 | Vector<uint8_t> sessionId; |
Jeff Tinker | 41d279a | 2018-02-11 19:52:08 +0000 | [diff] [blame^] | 732 | status_t result = openSession(level, sessionId); |
Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 733 | writeVector(reply, sessionId); |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 734 | reply->writeInt32(result); |
| 735 | return OK; |
| 736 | } |
| 737 | |
| 738 | case CLOSE_SESSION: |
| 739 | { |
| 740 | CHECK_INTERFACE(IDrm, data, reply); |
| 741 | Vector<uint8_t> sessionId; |
Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 742 | readVector(data, sessionId); |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 743 | reply->writeInt32(closeSession(sessionId)); |
| 744 | return OK; |
| 745 | } |
| 746 | |
Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 747 | case GET_KEY_REQUEST: |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 748 | { |
| 749 | CHECK_INTERFACE(IDrm, data, reply); |
Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 750 | Vector<uint8_t> sessionId, initData; |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 751 | |
Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 752 | readVector(data, sessionId); |
| 753 | readVector(data, initData); |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 754 | String8 mimeType = data.readString8(); |
Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 755 | DrmPlugin::KeyType keyType = (DrmPlugin::KeyType)data.readInt32(); |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 756 | |
| 757 | KeyedVector<String8, String8> optionalParameters; |
| 758 | uint32_t count = data.readInt32(); |
| 759 | for (size_t i = 0; i < count; ++i) { |
| 760 | String8 key, value; |
| 761 | key = data.readString8(); |
| 762 | value = data.readString8(); |
| 763 | optionalParameters.add(key, value); |
| 764 | } |
| 765 | |
| 766 | Vector<uint8_t> request; |
| 767 | String8 defaultUrl; |
Jeff Tinker | 8aff777 | 2016-02-08 17:52:25 -0800 | [diff] [blame] | 768 | DrmPlugin::KeyRequestType keyRequestType = DrmPlugin::kKeyRequestType_Unknown; |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 769 | |
Jeff Tinker | d072c90 | 2015-03-16 13:39:29 -0700 | [diff] [blame] | 770 | status_t result = getKeyRequest(sessionId, initData, mimeType, |
| 771 | keyType, optionalParameters, request, defaultUrl, |
| 772 | &keyRequestType); |
| 773 | |
Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 774 | writeVector(reply, request); |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 775 | reply->writeString8(defaultUrl); |
Jeff Tinker | d072c90 | 2015-03-16 13:39:29 -0700 | [diff] [blame] | 776 | reply->writeInt32(static_cast<int32_t>(keyRequestType)); |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 777 | reply->writeInt32(result); |
| 778 | return OK; |
| 779 | } |
| 780 | |
Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 781 | case PROVIDE_KEY_RESPONSE: |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 782 | { |
| 783 | CHECK_INTERFACE(IDrm, data, reply); |
Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 784 | Vector<uint8_t> sessionId, response, keySetId; |
| 785 | readVector(data, sessionId); |
| 786 | readVector(data, response); |
| 787 | uint32_t result = provideKeyResponse(sessionId, response, keySetId); |
| 788 | writeVector(reply, keySetId); |
| 789 | reply->writeInt32(result); |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 790 | return OK; |
| 791 | } |
| 792 | |
Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 793 | case REMOVE_KEYS: |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 794 | { |
| 795 | CHECK_INTERFACE(IDrm, data, reply); |
Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 796 | Vector<uint8_t> keySetId; |
| 797 | readVector(data, keySetId); |
| 798 | reply->writeInt32(removeKeys(keySetId)); |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 799 | return OK; |
| 800 | } |
| 801 | |
Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 802 | case RESTORE_KEYS: |
| 803 | { |
| 804 | CHECK_INTERFACE(IDrm, data, reply); |
| 805 | Vector<uint8_t> sessionId, keySetId; |
| 806 | readVector(data, sessionId); |
| 807 | readVector(data, keySetId); |
| 808 | reply->writeInt32(restoreKeys(sessionId, keySetId)); |
| 809 | return OK; |
| 810 | } |
| 811 | |
| 812 | case QUERY_KEY_STATUS: |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 813 | { |
| 814 | CHECK_INTERFACE(IDrm, data, reply); |
| 815 | Vector<uint8_t> sessionId; |
Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 816 | readVector(data, sessionId); |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 817 | KeyedVector<String8, String8> infoMap; |
Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 818 | status_t result = queryKeyStatus(sessionId, infoMap); |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 819 | size_t count = infoMap.size(); |
| 820 | reply->writeInt32(count); |
| 821 | for (size_t i = 0; i < count; ++i) { |
| 822 | reply->writeString8(infoMap.keyAt(i)); |
| 823 | reply->writeString8(infoMap.valueAt(i)); |
| 824 | } |
| 825 | reply->writeInt32(result); |
| 826 | return OK; |
| 827 | } |
| 828 | |
| 829 | case GET_PROVISION_REQUEST: |
| 830 | { |
| 831 | CHECK_INTERFACE(IDrm, data, reply); |
Jeff Tinker | 68d9d71 | 2014-03-04 13:21:31 -0800 | [diff] [blame] | 832 | String8 certType = data.readString8(); |
| 833 | String8 certAuthority = data.readString8(); |
| 834 | |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 835 | Vector<uint8_t> request; |
| 836 | String8 defaultUrl; |
Jeff Tinker | 68d9d71 | 2014-03-04 13:21:31 -0800 | [diff] [blame] | 837 | status_t result = getProvisionRequest(certType, certAuthority, |
| 838 | request, defaultUrl); |
Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 839 | writeVector(reply, request); |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 840 | reply->writeString8(defaultUrl); |
| 841 | reply->writeInt32(result); |
| 842 | return OK; |
| 843 | } |
| 844 | |
| 845 | case PROVIDE_PROVISION_RESPONSE: |
| 846 | { |
| 847 | CHECK_INTERFACE(IDrm, data, reply); |
| 848 | Vector<uint8_t> response; |
Jeff Tinker | 68d9d71 | 2014-03-04 13:21:31 -0800 | [diff] [blame] | 849 | Vector<uint8_t> certificate; |
| 850 | Vector<uint8_t> wrappedKey; |
Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 851 | readVector(data, response); |
Jeff Tinker | 68d9d71 | 2014-03-04 13:21:31 -0800 | [diff] [blame] | 852 | status_t result = provideProvisionResponse(response, certificate, wrappedKey); |
| 853 | writeVector(reply, certificate); |
| 854 | writeVector(reply, wrappedKey); |
| 855 | reply->writeInt32(result); |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 856 | return OK; |
| 857 | } |
| 858 | |
| 859 | case GET_SECURE_STOPS: |
| 860 | { |
| 861 | CHECK_INTERFACE(IDrm, data, reply); |
| 862 | List<Vector<uint8_t> > secureStops; |
| 863 | status_t result = getSecureStops(secureStops); |
| 864 | size_t count = secureStops.size(); |
| 865 | reply->writeInt32(count); |
| 866 | List<Vector<uint8_t> >::iterator iter = secureStops.begin(); |
| 867 | while(iter != secureStops.end()) { |
| 868 | size_t size = iter->size(); |
| 869 | reply->writeInt32(size); |
| 870 | reply->write(iter->array(), iter->size()); |
Jeff Tinker | 423e33c | 2013-04-08 15:23:17 -0700 | [diff] [blame] | 871 | iter++; |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 872 | } |
| 873 | reply->writeInt32(result); |
| 874 | return OK; |
| 875 | } |
| 876 | |
Jeff Tinker | 15177d7 | 2018-01-25 12:57:55 -0800 | [diff] [blame] | 877 | case GET_SECURE_STOP_IDS: |
| 878 | { |
| 879 | CHECK_INTERFACE(IDrm, data, reply); |
| 880 | List<Vector<uint8_t> > secureStopIds; |
| 881 | status_t result = getSecureStopIds(secureStopIds); |
| 882 | size_t count = secureStopIds.size(); |
| 883 | reply->writeInt32(count); |
| 884 | List<Vector<uint8_t> >::iterator iter = secureStopIds.begin(); |
| 885 | while(iter != secureStopIds.end()) { |
| 886 | size_t size = iter->size(); |
| 887 | reply->writeInt32(size); |
| 888 | reply->write(iter->array(), iter->size()); |
| 889 | iter++; |
| 890 | } |
| 891 | reply->writeInt32(result); |
| 892 | return OK; |
| 893 | } |
| 894 | |
Jeff Tinker | 3c1285e | 2014-10-31 00:55:16 -0700 | [diff] [blame] | 895 | case GET_SECURE_STOP: |
| 896 | { |
| 897 | CHECK_INTERFACE(IDrm, data, reply); |
| 898 | Vector<uint8_t> ssid, secureStop; |
| 899 | readVector(data, ssid); |
| 900 | status_t result = getSecureStop(ssid, secureStop); |
| 901 | writeVector(reply, secureStop); |
| 902 | reply->writeInt32(result); |
| 903 | return OK; |
| 904 | } |
| 905 | |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 906 | case RELEASE_SECURE_STOPS: |
| 907 | { |
| 908 | CHECK_INTERFACE(IDrm, data, reply); |
| 909 | Vector<uint8_t> ssRelease; |
Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 910 | readVector(data, ssRelease); |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 911 | reply->writeInt32(releaseSecureStops(ssRelease)); |
| 912 | return OK; |
| 913 | } |
| 914 | |
Jeff Tinker | 15177d7 | 2018-01-25 12:57:55 -0800 | [diff] [blame] | 915 | case REMOVE_SECURE_STOP: |
Jeff Tinker | 3c1285e | 2014-10-31 00:55:16 -0700 | [diff] [blame] | 916 | { |
| 917 | CHECK_INTERFACE(IDrm, data, reply); |
Jeff Tinker | 15177d7 | 2018-01-25 12:57:55 -0800 | [diff] [blame] | 918 | Vector<uint8_t> ssid; |
| 919 | readVector(data, ssid); |
| 920 | reply->writeInt32(removeSecureStop(ssid)); |
| 921 | return OK; |
| 922 | } |
| 923 | |
| 924 | case REMOVE_ALL_SECURE_STOPS: |
| 925 | { |
| 926 | CHECK_INTERFACE(IDrm, data, reply); |
| 927 | reply->writeInt32(removeAllSecureStops()); |
Jeff Tinker | 3c1285e | 2014-10-31 00:55:16 -0700 | [diff] [blame] | 928 | return OK; |
| 929 | } |
| 930 | |
Jeff Tinker | 6d998b6 | 2017-12-18 14:37:43 -0800 | [diff] [blame] | 931 | case GET_HDCP_LEVELS: |
| 932 | { |
| 933 | CHECK_INTERFACE(IDrm, data, reply); |
| 934 | DrmPlugin::HdcpLevel connected = DrmPlugin::kHdcpLevelUnknown; |
| 935 | DrmPlugin::HdcpLevel max = DrmPlugin::kHdcpLevelUnknown; |
| 936 | status_t result = getHdcpLevels(&connected, &max); |
| 937 | reply->writeInt32(connected); |
| 938 | reply->writeInt32(max); |
| 939 | reply->writeInt32(result); |
| 940 | return OK; |
| 941 | } |
| 942 | |
| 943 | case GET_NUMBER_OF_SESSIONS: |
| 944 | { |
| 945 | CHECK_INTERFACE(IDrm, data, reply); |
| 946 | uint32_t open = 0, max = 0; |
| 947 | status_t result = getNumberOfSessions(&open, &max); |
| 948 | reply->writeInt32(open); |
| 949 | reply->writeInt32(max); |
| 950 | reply->writeInt32(result); |
| 951 | return OK; |
| 952 | } |
| 953 | |
| 954 | case GET_SECURITY_LEVEL: |
| 955 | { |
| 956 | CHECK_INTERFACE(IDrm, data, reply); |
| 957 | Vector<uint8_t> sessionId; |
| 958 | readVector(data, sessionId); |
| 959 | DrmPlugin::SecurityLevel level = DrmPlugin::kSecurityLevelUnknown; |
| 960 | status_t result = getSecurityLevel(sessionId, &level); |
| 961 | reply->writeInt32(level); |
| 962 | reply->writeInt32(result); |
| 963 | return OK; |
| 964 | } |
| 965 | |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 966 | case GET_PROPERTY_STRING: |
| 967 | { |
| 968 | CHECK_INTERFACE(IDrm, data, reply); |
| 969 | String8 name = data.readString8(); |
| 970 | String8 value; |
| 971 | status_t result = getPropertyString(name, value); |
| 972 | reply->writeString8(value); |
| 973 | reply->writeInt32(result); |
| 974 | return OK; |
| 975 | } |
| 976 | |
| 977 | case GET_PROPERTY_BYTE_ARRAY: |
| 978 | { |
| 979 | CHECK_INTERFACE(IDrm, data, reply); |
| 980 | String8 name = data.readString8(); |
| 981 | Vector<uint8_t> value; |
| 982 | status_t result = getPropertyByteArray(name, value); |
Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 983 | writeVector(reply, value); |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 984 | reply->writeInt32(result); |
| 985 | return OK; |
| 986 | } |
| 987 | |
| 988 | case SET_PROPERTY_STRING: |
| 989 | { |
| 990 | CHECK_INTERFACE(IDrm, data, reply); |
| 991 | String8 name = data.readString8(); |
| 992 | String8 value = data.readString8(); |
| 993 | reply->writeInt32(setPropertyString(name, value)); |
| 994 | return OK; |
| 995 | } |
| 996 | |
| 997 | case SET_PROPERTY_BYTE_ARRAY: |
| 998 | { |
| 999 | CHECK_INTERFACE(IDrm, data, reply); |
| 1000 | String8 name = data.readString8(); |
| 1001 | Vector<uint8_t> value; |
Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 1002 | readVector(data, value); |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 1003 | reply->writeInt32(setPropertyByteArray(name, value)); |
| 1004 | return OK; |
| 1005 | } |
| 1006 | |
Adam Stone | ab394d1 | 2017-12-22 12:34:20 -0800 | [diff] [blame] | 1007 | case GET_METRICS: |
| 1008 | { |
| 1009 | CHECK_INTERFACE(IDrm, data, reply); |
| 1010 | |
| 1011 | MediaAnalyticsItem item; |
| 1012 | status_t result = getMetrics(&item); |
| 1013 | item.writeToParcel(reply); |
| 1014 | reply->writeInt32(result); |
| 1015 | return OK; |
| 1016 | } |
| 1017 | |
Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 1018 | case SET_CIPHER_ALGORITHM: |
| 1019 | { |
| 1020 | CHECK_INTERFACE(IDrm, data, reply); |
| 1021 | Vector<uint8_t> sessionId; |
| 1022 | readVector(data, sessionId); |
| 1023 | String8 algorithm = data.readString8(); |
| 1024 | reply->writeInt32(setCipherAlgorithm(sessionId, algorithm)); |
| 1025 | return OK; |
| 1026 | } |
| 1027 | |
| 1028 | case SET_MAC_ALGORITHM: |
| 1029 | { |
| 1030 | CHECK_INTERFACE(IDrm, data, reply); |
| 1031 | Vector<uint8_t> sessionId; |
| 1032 | readVector(data, sessionId); |
| 1033 | String8 algorithm = data.readString8(); |
| 1034 | reply->writeInt32(setMacAlgorithm(sessionId, algorithm)); |
| 1035 | return OK; |
| 1036 | } |
| 1037 | |
| 1038 | case ENCRYPT: |
| 1039 | { |
| 1040 | CHECK_INTERFACE(IDrm, data, reply); |
| 1041 | Vector<uint8_t> sessionId, keyId, input, iv, output; |
| 1042 | readVector(data, sessionId); |
| 1043 | readVector(data, keyId); |
| 1044 | readVector(data, input); |
| 1045 | readVector(data, iv); |
| 1046 | uint32_t result = encrypt(sessionId, keyId, input, iv, output); |
| 1047 | writeVector(reply, output); |
| 1048 | reply->writeInt32(result); |
| 1049 | return OK; |
| 1050 | } |
| 1051 | |
| 1052 | case DECRYPT: |
| 1053 | { |
| 1054 | CHECK_INTERFACE(IDrm, data, reply); |
| 1055 | Vector<uint8_t> sessionId, keyId, input, iv, output; |
| 1056 | readVector(data, sessionId); |
| 1057 | readVector(data, keyId); |
| 1058 | readVector(data, input); |
| 1059 | readVector(data, iv); |
| 1060 | uint32_t result = decrypt(sessionId, keyId, input, iv, output); |
| 1061 | writeVector(reply, output); |
| 1062 | reply->writeInt32(result); |
| 1063 | return OK; |
| 1064 | } |
| 1065 | |
| 1066 | case SIGN: |
| 1067 | { |
| 1068 | CHECK_INTERFACE(IDrm, data, reply); |
| 1069 | Vector<uint8_t> sessionId, keyId, message, signature; |
| 1070 | readVector(data, sessionId); |
| 1071 | readVector(data, keyId); |
| 1072 | readVector(data, message); |
| 1073 | uint32_t result = sign(sessionId, keyId, message, signature); |
| 1074 | writeVector(reply, signature); |
| 1075 | reply->writeInt32(result); |
| 1076 | return OK; |
| 1077 | } |
| 1078 | |
| 1079 | case VERIFY: |
| 1080 | { |
| 1081 | CHECK_INTERFACE(IDrm, data, reply); |
| 1082 | Vector<uint8_t> sessionId, keyId, message, signature; |
| 1083 | readVector(data, sessionId); |
| 1084 | readVector(data, keyId); |
| 1085 | readVector(data, message); |
| 1086 | readVector(data, signature); |
Jeff Tinker | 9a6861c | 2016-09-02 11:36:46 -0700 | [diff] [blame] | 1087 | bool match = false; |
Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 1088 | uint32_t result = verify(sessionId, keyId, message, signature, match); |
| 1089 | reply->writeInt32(match); |
| 1090 | reply->writeInt32(result); |
| 1091 | return OK; |
| 1092 | } |
| 1093 | |
Jeff Tinker | 68d9d71 | 2014-03-04 13:21:31 -0800 | [diff] [blame] | 1094 | case SIGN_RSA: |
| 1095 | { |
| 1096 | CHECK_INTERFACE(IDrm, data, reply); |
| 1097 | Vector<uint8_t> sessionId, message, wrappedKey, signature; |
| 1098 | readVector(data, sessionId); |
| 1099 | String8 algorithm = data.readString8(); |
| 1100 | readVector(data, message); |
| 1101 | readVector(data, wrappedKey); |
| 1102 | uint32_t result = signRSA(sessionId, algorithm, message, wrappedKey, signature); |
| 1103 | writeVector(reply, signature); |
| 1104 | reply->writeInt32(result); |
| 1105 | return OK; |
| 1106 | } |
| 1107 | |
Jeff Tinker | c0d5f1f | 2013-04-02 13:08:05 -0700 | [diff] [blame] | 1108 | case SET_LISTENER: { |
| 1109 | CHECK_INTERFACE(IDrm, data, reply); |
| 1110 | sp<IDrmClient> listener = |
| 1111 | interface_cast<IDrmClient>(data.readStrongBinder()); |
| 1112 | reply->writeInt32(setListener(listener)); |
| 1113 | return NO_ERROR; |
| 1114 | } break; |
| 1115 | |
Jeff Tinker | 4c63a23 | 2013-03-30 16:19:44 -0700 | [diff] [blame] | 1116 | default: |
| 1117 | return BBinder::onTransact(code, data, reply, flags); |
Jeff Tinker | 441a78d | 2013-02-08 10:18:35 -0800 | [diff] [blame] | 1118 | } |
| 1119 | } |
| 1120 | |
| 1121 | } // namespace android |