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