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