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