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