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