blob: 7da52ea875d3b21650fe95e95341ebd5bf4d74b5 [file] [log] [blame]
Jeff Tinker441a78d2013-02-08 10:18:35 -08001/*
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
27namespace android {
28
29enum {
30 INIT_CHECK = IBinder::FIRST_CALL_TRANSACTION,
31 IS_CRYPTO_SUPPORTED,
32 CREATE_PLUGIN,
33 DESTROY_PLUGIN,
34 OPEN_SESSION,
35 CLOSE_SESSION,
Jeff Tinker4c63a232013-03-30 16:19:44 -070036 GET_KEY_REQUEST,
37 PROVIDE_KEY_RESPONSE,
38 REMOVE_KEYS,
39 RESTORE_KEYS,
40 QUERY_KEY_STATUS,
Jeff Tinker441a78d2013-02-08 10:18:35 -080041 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 Tinker4c63a232013-03-30 16:19:44 -070048 SET_PROPERTY_BYTE_ARRAY,
Adam Stoneab394d12017-12-22 12:34:20 -080049 GET_METRICS,
Jeff Tinker4c63a232013-03-30 16:19:44 -070050 SET_CIPHER_ALGORITHM,
51 SET_MAC_ALGORITHM,
52 ENCRYPT,
53 DECRYPT,
54 SIGN,
Jeff Tinker68d9d712014-03-04 13:21:31 -080055 SIGN_RSA,
Jeff Tinkerc0d5f1f2013-04-02 13:08:05 -070056 VERIFY,
Jeff Tinker68b15552014-04-30 10:19:03 -070057 SET_LISTENER,
Jeff Tinker3c1285e2014-10-31 00:55:16 -070058 GET_SECURE_STOP,
Jeff Tinker15177d72018-01-25 12:57:55 -080059 REMOVE_ALL_SECURE_STOPS,
Jeff Tinker6d998b62017-12-18 14:37:43 -080060 GET_HDCP_LEVELS,
61 GET_NUMBER_OF_SESSIONS,
62 GET_SECURITY_LEVEL,
63 SET_SECURITY_LEVEL,
Jeff Tinker15177d72018-01-25 12:57:55 -080064 REMOVE_SECURE_STOP,
65 GET_SECURE_STOP_IDS
Jeff Tinker441a78d2013-02-08 10:18:35 -080066};
67
68struct BpDrm : public BpInterface<IDrm> {
Chih-Hung Hsieh090ef602016-04-27 10:39:54 -070069 explicit BpDrm(const sp<IBinder> &impl)
Jeff Tinker441a78d2013-02-08 10:18:35 -080070 : BpInterface<IDrm>(impl) {
71 }
72
73 virtual status_t initCheck() const {
74 Parcel data, reply;
75 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
Jeff Tinker3b5401a2015-06-15 17:42:10 -070076 status_t status = remote()->transact(INIT_CHECK, data, &reply);
77 if (status != OK) {
78 return status;
79 }
Jeff Tinker441a78d2013-02-08 10:18:35 -080080
81 return reply.readInt32();
82 }
83
Jeff Tinker9cf69e02013-08-21 11:59:23 -070084 virtual bool isCryptoSchemeSupported(const uint8_t uuid[16], const String8 &mimeType) {
Jeff Tinker441a78d2013-02-08 10:18:35 -080085 Parcel data, reply;
86 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
87 data.write(uuid, 16);
Jeff Tinker9cf69e02013-08-21 11:59:23 -070088 data.writeString8(mimeType);
Jeff Tinker3b5401a2015-06-15 17:42:10 -070089 status_t status = remote()->transact(IS_CRYPTO_SUPPORTED, data, &reply);
90 if (status != OK) {
91 ALOGE("isCryptoSchemeSupported: binder call failed: %d", status);
92 return false;
93 }
Jeff Tinker441a78d2013-02-08 10:18:35 -080094
95 return reply.readInt32() != 0;
96 }
97
Edwin Wong68b3d9f2017-01-06 19:07:54 -080098 virtual status_t createPlugin(const uint8_t uuid[16],
99 const String8& appPackageName) {
Jeff Tinker441a78d2013-02-08 10:18:35 -0800100 Parcel data, reply;
101 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
102 data.write(uuid, 16);
Edwin Wong68b3d9f2017-01-06 19:07:54 -0800103 data.writeString8(appPackageName);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700104 status_t status = remote()->transact(CREATE_PLUGIN, data, &reply);
105 if (status != OK) {
Edwin Wong68b3d9f2017-01-06 19:07:54 -0800106 ALOGE("createPlugin: binder call failed: %d", status);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700107 return status;
108 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800109
110 return reply.readInt32();
111 }
112
113 virtual status_t destroyPlugin() {
114 Parcel data, reply;
115 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700116 status_t status = remote()->transact(DESTROY_PLUGIN, data, &reply);
117 if (status != OK) {
118 return status;
119 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800120
121 return reply.readInt32();
122 }
123
124 virtual status_t openSession(Vector<uint8_t> &sessionId) {
125 Parcel data, reply;
126 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
127
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700128 status_t status = remote()->transact(OPEN_SESSION, data, &reply);
129 if (status != OK) {
130 return status;
131 }
Jeff Tinker4c63a232013-03-30 16:19:44 -0700132 readVector(reply, sessionId);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800133
134 return reply.readInt32();
135 }
136
137 virtual status_t closeSession(Vector<uint8_t> const &sessionId) {
138 Parcel data, reply;
139 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
140
Jeff Tinker4c63a232013-03-30 16:19:44 -0700141 writeVector(data, sessionId);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700142 status_t status = remote()->transact(CLOSE_SESSION, data, &reply);
143 if (status != OK) {
144 return status;
145 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800146
147 return reply.readInt32();
148 }
149
150 virtual status_t
Jeff Tinker4c63a232013-03-30 16:19:44 -0700151 getKeyRequest(Vector<uint8_t> const &sessionId,
152 Vector<uint8_t> const &initData,
153 String8 const &mimeType, DrmPlugin::KeyType keyType,
154 KeyedVector<String8, String8> const &optionalParameters,
Jeff Tinkerd072c902015-03-16 13:39:29 -0700155 Vector<uint8_t> &request, String8 &defaultUrl,
156 DrmPlugin::KeyRequestType *keyRequestType) {
Jeff Tinker441a78d2013-02-08 10:18:35 -0800157 Parcel data, reply;
158 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
159
Jeff Tinker4c63a232013-03-30 16:19:44 -0700160 writeVector(data, sessionId);
161 writeVector(data, initData);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800162 data.writeString8(mimeType);
Jeff Tinker4c63a232013-03-30 16:19:44 -0700163 data.writeInt32((uint32_t)keyType);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800164
165 data.writeInt32(optionalParameters.size());
166 for (size_t i = 0; i < optionalParameters.size(); ++i) {
167 data.writeString8(optionalParameters.keyAt(i));
168 data.writeString8(optionalParameters.valueAt(i));
169 }
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700170
171 status_t status = remote()->transact(GET_KEY_REQUEST, data, &reply);
172 if (status != OK) {
173 return status;
174 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800175
Jeff Tinker4c63a232013-03-30 16:19:44 -0700176 readVector(reply, request);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800177 defaultUrl = reply.readString8();
Jeff Tinkerd072c902015-03-16 13:39:29 -0700178 *keyRequestType = static_cast<DrmPlugin::KeyRequestType>(reply.readInt32());
Jeff Tinker441a78d2013-02-08 10:18:35 -0800179
180 return reply.readInt32();
181 }
182
Jeff Tinker4c63a232013-03-30 16:19:44 -0700183 virtual status_t provideKeyResponse(Vector<uint8_t> const &sessionId,
184 Vector<uint8_t> const &response,
185 Vector<uint8_t> &keySetId) {
Jeff Tinker441a78d2013-02-08 10:18:35 -0800186 Parcel data, reply;
187 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
Jeff Tinker4c63a232013-03-30 16:19:44 -0700188 writeVector(data, sessionId);
189 writeVector(data, response);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700190
191 status_t status = remote()->transact(PROVIDE_KEY_RESPONSE, data, &reply);
192 if (status != OK) {
193 return status;
194 }
195
Jeff Tinker4c63a232013-03-30 16:19:44 -0700196 readVector(reply, keySetId);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800197
198 return reply.readInt32();
199 }
200
Jeff Tinker4c63a232013-03-30 16:19:44 -0700201 virtual status_t removeKeys(Vector<uint8_t> const &keySetId) {
Jeff Tinker441a78d2013-02-08 10:18:35 -0800202 Parcel data, reply;
203 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
204
Jeff Tinker4c63a232013-03-30 16:19:44 -0700205 writeVector(data, keySetId);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700206 status_t status = remote()->transact(REMOVE_KEYS, data, &reply);
207 if (status != OK) {
208 return status;
209 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800210
211 return reply.readInt32();
212 }
213
Jeff Tinker4c63a232013-03-30 16:19:44 -0700214 virtual status_t restoreKeys(Vector<uint8_t> const &sessionId,
215 Vector<uint8_t> const &keySetId) {
216 Parcel data, reply;
217 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
218
219 writeVector(data, sessionId);
220 writeVector(data, keySetId);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700221 status_t status = remote()->transact(RESTORE_KEYS, data, &reply);
222 if (status != OK) {
223 return status;
224 }
Jeff Tinker4c63a232013-03-30 16:19:44 -0700225
226 return reply.readInt32();
227 }
228
229 virtual status_t queryKeyStatus(Vector<uint8_t> const &sessionId,
Jeff Tinker441a78d2013-02-08 10:18:35 -0800230 KeyedVector<String8, String8> &infoMap) const {
231 Parcel data, reply;
232 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
233
Jeff Tinker4c63a232013-03-30 16:19:44 -0700234 writeVector(data, sessionId);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700235 status_t status = remote()->transact(QUERY_KEY_STATUS, data, &reply);
236 if (status != OK) {
237 return status;
238 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800239
240 infoMap.clear();
241 size_t count = reply.readInt32();
242 for (size_t i = 0; i < count; i++) {
243 String8 key = reply.readString8();
244 String8 value = reply.readString8();
245 infoMap.add(key, value);
246 }
247 return reply.readInt32();
248 }
249
Jeff Tinker68d9d712014-03-04 13:21:31 -0800250 virtual status_t getProvisionRequest(String8 const &certType,
251 String8 const &certAuthority,
252 Vector<uint8_t> &request,
Jeff Tinker441a78d2013-02-08 10:18:35 -0800253 String8 &defaultUrl) {
254 Parcel data, reply;
255 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
256
Jeff Tinker68d9d712014-03-04 13:21:31 -0800257 data.writeString8(certType);
258 data.writeString8(certAuthority);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700259 status_t status = remote()->transact(GET_PROVISION_REQUEST, data, &reply);
260 if (status != OK) {
261 return status;
262 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800263
Jeff Tinker4c63a232013-03-30 16:19:44 -0700264 readVector(reply, request);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800265 defaultUrl = reply.readString8();
266
267 return reply.readInt32();
268 }
269
Jeff Tinker68d9d712014-03-04 13:21:31 -0800270 virtual status_t provideProvisionResponse(Vector<uint8_t> const &response,
271 Vector<uint8_t> &certificate,
272 Vector<uint8_t> &wrappedKey) {
Jeff Tinker441a78d2013-02-08 10:18:35 -0800273 Parcel data, reply;
274 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
275
Jeff Tinker4c63a232013-03-30 16:19:44 -0700276 writeVector(data, response);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700277 status_t status = remote()->transact(PROVIDE_PROVISION_RESPONSE, data, &reply);
278 if (status != OK) {
279 return status;
280 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800281
Jeff Tinker68d9d712014-03-04 13:21:31 -0800282 readVector(reply, certificate);
283 readVector(reply, wrappedKey);
284
Jeff Tinker441a78d2013-02-08 10:18:35 -0800285 return reply.readInt32();
286 }
287
288 virtual status_t getSecureStops(List<Vector<uint8_t> > &secureStops) {
289 Parcel data, reply;
290 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
291
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700292 status_t status = remote()->transact(GET_SECURE_STOPS, data, &reply);
293 if (status != OK) {
294 return status;
295 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800296
297 secureStops.clear();
298 uint32_t count = reply.readInt32();
299 for (size_t i = 0; i < count; i++) {
300 Vector<uint8_t> secureStop;
Jeff Tinker4c63a232013-03-30 16:19:44 -0700301 readVector(reply, secureStop);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800302 secureStops.push_back(secureStop);
303 }
304 return reply.readInt32();
305 }
306
Jeff Tinker15177d72018-01-25 12:57:55 -0800307 virtual status_t getSecureStopIds(List<Vector<uint8_t> > &secureStopIds) {
308 Parcel data, reply;
309 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
310
311 status_t status = remote()->transact(GET_SECURE_STOP_IDS, data, &reply);
312 if (status != OK) {
313 return status;
314 }
315
316 secureStopIds.clear();
317 uint32_t count = reply.readInt32();
318 for (size_t i = 0; i < count; i++) {
319 Vector<uint8_t> secureStopId;
320 readVector(reply, secureStopId);
321 secureStopIds.push_back(secureStopId);
322 }
323 return reply.readInt32();
324 }
325
Jeff Tinker3c1285e2014-10-31 00:55:16 -0700326 virtual status_t getSecureStop(Vector<uint8_t> const &ssid, Vector<uint8_t> &secureStop) {
327 Parcel data, reply;
328 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
329
330 writeVector(data, ssid);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700331 status_t status = remote()->transact(GET_SECURE_STOP, data, &reply);
332 if (status != OK) {
333 return status;
334 }
Jeff Tinker3c1285e2014-10-31 00:55:16 -0700335
336 readVector(reply, secureStop);
337 return reply.readInt32();
338 }
339
Jeff Tinker441a78d2013-02-08 10:18:35 -0800340 virtual status_t releaseSecureStops(Vector<uint8_t> const &ssRelease) {
341 Parcel data, reply;
342 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
343
Jeff Tinker4c63a232013-03-30 16:19:44 -0700344 writeVector(data, ssRelease);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700345 status_t status = remote()->transact(RELEASE_SECURE_STOPS, data, &reply);
346 if (status != OK) {
347 return status;
348 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800349
350 return reply.readInt32();
351 }
352
Jeff Tinker15177d72018-01-25 12:57:55 -0800353 virtual status_t removeSecureStop(Vector<uint8_t> const &ssid) {
Jeff Tinker3c1285e2014-10-31 00:55:16 -0700354 Parcel data, reply;
355 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
356
Jeff Tinker15177d72018-01-25 12:57:55 -0800357 writeVector(data, ssid);
358 status_t status = remote()->transact(REMOVE_SECURE_STOP, data, &reply);
359 if (status != OK) {
360 return status;
361 }
362
363 return reply.readInt32();
364 }
365
366 virtual status_t removeAllSecureStops() {
367 Parcel data, reply;
368 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
369
370 status_t status = remote()->transact(REMOVE_ALL_SECURE_STOPS, data, &reply);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700371 if (status != OK) {
372 return status;
373 }
Jeff Tinker3c1285e2014-10-31 00:55:16 -0700374
375 return reply.readInt32();
376 }
377
Jeff Tinker441a78d2013-02-08 10:18:35 -0800378 virtual status_t getPropertyString(String8 const &name, String8 &value) const {
379 Parcel data, reply;
380 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
381
382 data.writeString8(name);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700383 status_t status = remote()->transact(GET_PROPERTY_STRING, data, &reply);
384 if (status != OK) {
385 return status;
386 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800387
388 value = reply.readString8();
389 return reply.readInt32();
390 }
391
Jeff Tinker6d998b62017-12-18 14:37:43 -0800392 virtual status_t getHdcpLevels(DrmPlugin::HdcpLevel *connected,
393 DrmPlugin::HdcpLevel *max) const {
394 Parcel data, reply;
395
396 if (connected == NULL || max == NULL) {
397 return BAD_VALUE;
398 }
399
400 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
401
402 status_t status = remote()->transact(GET_HDCP_LEVELS, data, &reply);
403 if (status != OK) {
404 return status;
405 }
406
407 *connected = static_cast<DrmPlugin::HdcpLevel>(reply.readInt32());
408 *max = static_cast<DrmPlugin::HdcpLevel>(reply.readInt32());
409 return reply.readInt32();
410 }
411
412 virtual status_t getNumberOfSessions(uint32_t *open, uint32_t *max) const {
413 Parcel data, reply;
414
415 if (open == NULL || max == NULL) {
416 return BAD_VALUE;
417 }
418
419 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
420
421 status_t status = remote()->transact(GET_NUMBER_OF_SESSIONS, data, &reply);
422 if (status != OK) {
423 return status;
424 }
425
426 *open = reply.readInt32();
427 *max = reply.readInt32();
428 return reply.readInt32();
429 }
430
431 virtual status_t getSecurityLevel(Vector<uint8_t> const &sessionId,
432 DrmPlugin::SecurityLevel *level) const {
433 Parcel data, reply;
434
435 if (level == NULL) {
436 return BAD_VALUE;
437 }
438
439 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
440
441 writeVector(data, sessionId);
442 status_t status = remote()->transact(GET_SECURITY_LEVEL, data, &reply);
443 if (status != OK) {
444 return status;
445 }
446
447 *level = static_cast<DrmPlugin::SecurityLevel>(reply.readInt32());
448 return reply.readInt32();
449 }
450
451 virtual status_t setSecurityLevel(Vector<uint8_t> const &sessionId,
452 const DrmPlugin::SecurityLevel& level) {
453 Parcel data, reply;
454
455 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
456
457 writeVector(data, sessionId);
458 data.writeInt32(static_cast<uint32_t>(level));
459
460 status_t status = remote()->transact(SET_SECURITY_LEVEL, data, &reply);
461 if (status != OK) {
462 return status;
463 }
464
465 return reply.readInt32();
466 }
467
Jeff Tinker441a78d2013-02-08 10:18:35 -0800468 virtual status_t getPropertyByteArray(String8 const &name, Vector<uint8_t> &value) const {
469 Parcel data, reply;
470 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
471
472 data.writeString8(name);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700473 status_t status = remote()->transact(GET_PROPERTY_BYTE_ARRAY, data, &reply);
474 if (status != OK) {
475 return status;
476 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800477
Jeff Tinker4c63a232013-03-30 16:19:44 -0700478 readVector(reply, value);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800479 return reply.readInt32();
480 }
481
482 virtual status_t setPropertyString(String8 const &name, String8 const &value) const {
483 Parcel data, reply;
484 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
485
486 data.writeString8(name);
487 data.writeString8(value);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700488 status_t status = remote()->transact(SET_PROPERTY_STRING, data, &reply);
489 if (status != OK) {
490 return status;
491 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800492
493 return reply.readInt32();
494 }
495
496 virtual status_t setPropertyByteArray(String8 const &name,
497 Vector<uint8_t> const &value) const {
498 Parcel data, reply;
499 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
500
501 data.writeString8(name);
Jeff Tinker4c63a232013-03-30 16:19:44 -0700502 writeVector(data, value);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700503 status_t status = remote()->transact(SET_PROPERTY_BYTE_ARRAY, data, &reply);
504 if (status != OK) {
505 return status;
506 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800507
508 return reply.readInt32();
509 }
510
Adam Stone637b7852018-01-30 12:09:36 -0800511 virtual status_t getMetrics(os::PersistableBundle *metrics) {
Adam Stone568b3c42018-01-31 12:57:16 -0800512 if (metrics == NULL) {
513 return BAD_VALUE;
514 }
Adam Stoneab394d12017-12-22 12:34:20 -0800515 Parcel data, reply;
516 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
517
518 status_t status = remote()->transact(GET_METRICS, data, &reply);
519 if (status != OK) {
520 return status;
521 }
Adam Stone568b3c42018-01-31 12:57:16 -0800522 // The reply data is ordered as
523 // 1) 32 bit integer reply followed by
524 // 2) Serialized PersistableBundle containing metrics.
525 status_t reply_status;
526 if (reply.readInt32(&reply_status) != OK
527 || reply_status != OK) {
528 ALOGE("Failed to read getMetrics response code from parcel. %d",
529 reply_status);
530 return reply_status;
531 }
Adam Stoneab394d12017-12-22 12:34:20 -0800532
Adam Stone568b3c42018-01-31 12:57:16 -0800533 status = metrics->readFromParcel(&reply);
534 if (status != OK) {
535 ALOGE("Failed to read metrics from parcel. %d", status);
536 return status;
537 }
538 return reply_status;
Adam Stoneab394d12017-12-22 12:34:20 -0800539 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800540
Jeff Tinker4c63a232013-03-30 16:19:44 -0700541 virtual status_t setCipherAlgorithm(Vector<uint8_t> const &sessionId,
542 String8 const &algorithm) {
543 Parcel data, reply;
544 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
545
546 writeVector(data, sessionId);
547 data.writeString8(algorithm);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700548 status_t status = remote()->transact(SET_CIPHER_ALGORITHM, data, &reply);
549 if (status != OK) {
550 return status;
551 }
Jeff Tinker4c63a232013-03-30 16:19:44 -0700552 return reply.readInt32();
553 }
554
555 virtual status_t setMacAlgorithm(Vector<uint8_t> const &sessionId,
556 String8 const &algorithm) {
557 Parcel data, reply;
558 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
559
560 writeVector(data, sessionId);
561 data.writeString8(algorithm);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700562 status_t status = remote()->transact(SET_MAC_ALGORITHM, data, &reply);
563 if (status != OK) {
564 return status;
565 }
Jeff Tinker4c63a232013-03-30 16:19:44 -0700566 return reply.readInt32();
567 }
568
569 virtual status_t encrypt(Vector<uint8_t> const &sessionId,
570 Vector<uint8_t> const &keyId,
571 Vector<uint8_t> const &input,
572 Vector<uint8_t> const &iv,
573 Vector<uint8_t> &output) {
574 Parcel data, reply;
575 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
576
577 writeVector(data, sessionId);
578 writeVector(data, keyId);
579 writeVector(data, input);
580 writeVector(data, iv);
581
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700582 status_t status = remote()->transact(ENCRYPT, data, &reply);
583 if (status != OK) {
584 return status;
585 }
Jeff Tinker4c63a232013-03-30 16:19:44 -0700586 readVector(reply, output);
587
588 return reply.readInt32();
589 }
590
591 virtual status_t decrypt(Vector<uint8_t> const &sessionId,
592 Vector<uint8_t> const &keyId,
593 Vector<uint8_t> const &input,
594 Vector<uint8_t> const &iv,
595 Vector<uint8_t> &output) {
596 Parcel data, reply;
597 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
598
599 writeVector(data, sessionId);
600 writeVector(data, keyId);
601 writeVector(data, input);
602 writeVector(data, iv);
603
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700604 status_t status = remote()->transact(DECRYPT, data, &reply);
605 if (status != OK) {
606 return status;
607 }
Jeff Tinker4c63a232013-03-30 16:19:44 -0700608 readVector(reply, output);
609
610 return reply.readInt32();
611 }
612
613 virtual status_t sign(Vector<uint8_t> const &sessionId,
614 Vector<uint8_t> const &keyId,
615 Vector<uint8_t> const &message,
616 Vector<uint8_t> &signature) {
617 Parcel data, reply;
618 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
619
620 writeVector(data, sessionId);
621 writeVector(data, keyId);
622 writeVector(data, message);
623
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700624 status_t status = remote()->transact(SIGN, data, &reply);
625 if (status != OK) {
626 return status;
627 }
Jeff Tinker4c63a232013-03-30 16:19:44 -0700628 readVector(reply, signature);
629
630 return reply.readInt32();
631 }
632
633 virtual status_t verify(Vector<uint8_t> const &sessionId,
634 Vector<uint8_t> const &keyId,
635 Vector<uint8_t> const &message,
636 Vector<uint8_t> const &signature,
637 bool &match) {
638 Parcel data, reply;
639 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
640
641 writeVector(data, sessionId);
642 writeVector(data, keyId);
643 writeVector(data, message);
644 writeVector(data, signature);
645
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700646 status_t status = remote()->transact(VERIFY, data, &reply);
647 if (status != OK) {
648 return status;
649 }
Jeff Tinker4c63a232013-03-30 16:19:44 -0700650 match = (bool)reply.readInt32();
651 return reply.readInt32();
652 }
653
Jeff Tinker68d9d712014-03-04 13:21:31 -0800654 virtual status_t signRSA(Vector<uint8_t> const &sessionId,
655 String8 const &algorithm,
656 Vector<uint8_t> const &message,
657 Vector<uint8_t> const &wrappedKey,
658 Vector<uint8_t> &signature) {
659 Parcel data, reply;
660 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
661
662 writeVector(data, sessionId);
663 data.writeString8(algorithm);
664 writeVector(data, message);
665 writeVector(data, wrappedKey);
666
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700667 status_t status = remote()->transact(SIGN_RSA, data, &reply);
668 if (status != OK) {
669 return status;
670 }
Jeff Tinker68d9d712014-03-04 13:21:31 -0800671 readVector(reply, signature);
672
673 return reply.readInt32();
674 }
675
Jeff Tinkerc0d5f1f2013-04-02 13:08:05 -0700676 virtual status_t setListener(const sp<IDrmClient>& listener) {
677 Parcel data, reply;
678 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
Marco Nelissen06b46062014-11-14 07:58:25 -0800679 data.writeStrongBinder(IInterface::asBinder(listener));
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700680 status_t status = remote()->transact(SET_LISTENER, data, &reply);
681 if (status != OK) {
682 return status;
683 }
Jeff Tinkerc0d5f1f2013-04-02 13:08:05 -0700684 return reply.readInt32();
685 }
686
Jeff Tinker441a78d2013-02-08 10:18:35 -0800687private:
Jeff Tinker4c63a232013-03-30 16:19:44 -0700688 void readVector(Parcel &reply, Vector<uint8_t> &vector) const {
689 uint32_t size = reply.readInt32();
690 vector.insertAt((size_t)0, size);
691 reply.read(vector.editArray(), size);
692 }
693
694 void writeVector(Parcel &data, Vector<uint8_t> const &vector) const {
695 data.writeInt32(vector.size());
696 data.write(vector.array(), vector.size());
697 }
698
Jeff Tinker441a78d2013-02-08 10:18:35 -0800699 DISALLOW_EVIL_CONSTRUCTORS(BpDrm);
700};
701
702IMPLEMENT_META_INTERFACE(Drm, "android.drm.IDrm");
703
704////////////////////////////////////////////////////////////////////////////////
705
Jeff Tinker4c63a232013-03-30 16:19:44 -0700706void BnDrm::readVector(const Parcel &data, Vector<uint8_t> &vector) const {
707 uint32_t size = data.readInt32();
Jeff Tinker3cf728e2017-10-18 20:54:26 +0000708 if (vector.insertAt((size_t)0, size) < 0) {
709 vector.clear();
710 }
711 if (data.read(vector.editArray(), size) != NO_ERROR) {
712 vector.clear();
713 android_errorWriteWithInfoLog(0x534e4554, "62872384", -1, NULL, 0);
714 }
Jeff Tinker4c63a232013-03-30 16:19:44 -0700715}
716
717void BnDrm::writeVector(Parcel *reply, Vector<uint8_t> const &vector) const {
718 reply->writeInt32(vector.size());
719 reply->write(vector.array(), vector.size());
720}
721
Jeff Tinker441a78d2013-02-08 10:18:35 -0800722status_t BnDrm::onTransact(
723 uint32_t code, const Parcel &data, Parcel *reply, uint32_t flags) {
724 switch (code) {
725 case INIT_CHECK:
726 {
727 CHECK_INTERFACE(IDrm, data, reply);
728 reply->writeInt32(initCheck());
729 return OK;
730 }
731
732 case IS_CRYPTO_SUPPORTED:
733 {
734 CHECK_INTERFACE(IDrm, data, reply);
735 uint8_t uuid[16];
736 data.read(uuid, sizeof(uuid));
Jeff Tinker9cf69e02013-08-21 11:59:23 -0700737 String8 mimeType = data.readString8();
738 reply->writeInt32(isCryptoSchemeSupported(uuid, mimeType));
Jeff Tinker441a78d2013-02-08 10:18:35 -0800739 return OK;
740 }
741
742 case CREATE_PLUGIN:
743 {
744 CHECK_INTERFACE(IDrm, data, reply);
745 uint8_t uuid[16];
746 data.read(uuid, sizeof(uuid));
Edwin Wong68b3d9f2017-01-06 19:07:54 -0800747 String8 appPackageName = data.readString8();
748 reply->writeInt32(createPlugin(uuid, appPackageName));
Jeff Tinker441a78d2013-02-08 10:18:35 -0800749 return OK;
750 }
751
752 case DESTROY_PLUGIN:
753 {
754 CHECK_INTERFACE(IDrm, data, reply);
755 reply->writeInt32(destroyPlugin());
756 return OK;
757 }
758
759 case OPEN_SESSION:
760 {
761 CHECK_INTERFACE(IDrm, data, reply);
762 Vector<uint8_t> sessionId;
763 status_t result = openSession(sessionId);
Jeff Tinker4c63a232013-03-30 16:19:44 -0700764 writeVector(reply, sessionId);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800765 reply->writeInt32(result);
766 return OK;
767 }
768
769 case CLOSE_SESSION:
770 {
771 CHECK_INTERFACE(IDrm, data, reply);
772 Vector<uint8_t> sessionId;
Jeff Tinker4c63a232013-03-30 16:19:44 -0700773 readVector(data, sessionId);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800774 reply->writeInt32(closeSession(sessionId));
775 return OK;
776 }
777
Jeff Tinker4c63a232013-03-30 16:19:44 -0700778 case GET_KEY_REQUEST:
Jeff Tinker441a78d2013-02-08 10:18:35 -0800779 {
780 CHECK_INTERFACE(IDrm, data, reply);
Jeff Tinker4c63a232013-03-30 16:19:44 -0700781 Vector<uint8_t> sessionId, initData;
Jeff Tinker441a78d2013-02-08 10:18:35 -0800782
Jeff Tinker4c63a232013-03-30 16:19:44 -0700783 readVector(data, sessionId);
784 readVector(data, initData);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800785 String8 mimeType = data.readString8();
Jeff Tinker4c63a232013-03-30 16:19:44 -0700786 DrmPlugin::KeyType keyType = (DrmPlugin::KeyType)data.readInt32();
Jeff Tinker441a78d2013-02-08 10:18:35 -0800787
788 KeyedVector<String8, String8> optionalParameters;
789 uint32_t count = data.readInt32();
790 for (size_t i = 0; i < count; ++i) {
791 String8 key, value;
792 key = data.readString8();
793 value = data.readString8();
794 optionalParameters.add(key, value);
795 }
796
797 Vector<uint8_t> request;
798 String8 defaultUrl;
Jeff Tinker8aff7772016-02-08 17:52:25 -0800799 DrmPlugin::KeyRequestType keyRequestType = DrmPlugin::kKeyRequestType_Unknown;
Jeff Tinker441a78d2013-02-08 10:18:35 -0800800
Jeff Tinkerd072c902015-03-16 13:39:29 -0700801 status_t result = getKeyRequest(sessionId, initData, mimeType,
802 keyType, optionalParameters, request, defaultUrl,
803 &keyRequestType);
804
Jeff Tinker4c63a232013-03-30 16:19:44 -0700805 writeVector(reply, request);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800806 reply->writeString8(defaultUrl);
Jeff Tinkerd072c902015-03-16 13:39:29 -0700807 reply->writeInt32(static_cast<int32_t>(keyRequestType));
Jeff Tinker441a78d2013-02-08 10:18:35 -0800808 reply->writeInt32(result);
809 return OK;
810 }
811
Jeff Tinker4c63a232013-03-30 16:19:44 -0700812 case PROVIDE_KEY_RESPONSE:
Jeff Tinker441a78d2013-02-08 10:18:35 -0800813 {
814 CHECK_INTERFACE(IDrm, data, reply);
Jeff Tinker4c63a232013-03-30 16:19:44 -0700815 Vector<uint8_t> sessionId, response, keySetId;
816 readVector(data, sessionId);
817 readVector(data, response);
818 uint32_t result = provideKeyResponse(sessionId, response, keySetId);
819 writeVector(reply, keySetId);
820 reply->writeInt32(result);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800821 return OK;
822 }
823
Jeff Tinker4c63a232013-03-30 16:19:44 -0700824 case REMOVE_KEYS:
Jeff Tinker441a78d2013-02-08 10:18:35 -0800825 {
826 CHECK_INTERFACE(IDrm, data, reply);
Jeff Tinker4c63a232013-03-30 16:19:44 -0700827 Vector<uint8_t> keySetId;
828 readVector(data, keySetId);
829 reply->writeInt32(removeKeys(keySetId));
Jeff Tinker441a78d2013-02-08 10:18:35 -0800830 return OK;
831 }
832
Jeff Tinker4c63a232013-03-30 16:19:44 -0700833 case RESTORE_KEYS:
834 {
835 CHECK_INTERFACE(IDrm, data, reply);
836 Vector<uint8_t> sessionId, keySetId;
837 readVector(data, sessionId);
838 readVector(data, keySetId);
839 reply->writeInt32(restoreKeys(sessionId, keySetId));
840 return OK;
841 }
842
843 case QUERY_KEY_STATUS:
Jeff Tinker441a78d2013-02-08 10:18:35 -0800844 {
845 CHECK_INTERFACE(IDrm, data, reply);
846 Vector<uint8_t> sessionId;
Jeff Tinker4c63a232013-03-30 16:19:44 -0700847 readVector(data, sessionId);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800848 KeyedVector<String8, String8> infoMap;
Jeff Tinker4c63a232013-03-30 16:19:44 -0700849 status_t result = queryKeyStatus(sessionId, infoMap);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800850 size_t count = infoMap.size();
851 reply->writeInt32(count);
852 for (size_t i = 0; i < count; ++i) {
853 reply->writeString8(infoMap.keyAt(i));
854 reply->writeString8(infoMap.valueAt(i));
855 }
856 reply->writeInt32(result);
857 return OK;
858 }
859
860 case GET_PROVISION_REQUEST:
861 {
862 CHECK_INTERFACE(IDrm, data, reply);
Jeff Tinker68d9d712014-03-04 13:21:31 -0800863 String8 certType = data.readString8();
864 String8 certAuthority = data.readString8();
865
Jeff Tinker441a78d2013-02-08 10:18:35 -0800866 Vector<uint8_t> request;
867 String8 defaultUrl;
Jeff Tinker68d9d712014-03-04 13:21:31 -0800868 status_t result = getProvisionRequest(certType, certAuthority,
869 request, defaultUrl);
Jeff Tinker4c63a232013-03-30 16:19:44 -0700870 writeVector(reply, request);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800871 reply->writeString8(defaultUrl);
872 reply->writeInt32(result);
873 return OK;
874 }
875
876 case PROVIDE_PROVISION_RESPONSE:
877 {
878 CHECK_INTERFACE(IDrm, data, reply);
879 Vector<uint8_t> response;
Jeff Tinker68d9d712014-03-04 13:21:31 -0800880 Vector<uint8_t> certificate;
881 Vector<uint8_t> wrappedKey;
Jeff Tinker4c63a232013-03-30 16:19:44 -0700882 readVector(data, response);
Jeff Tinker68d9d712014-03-04 13:21:31 -0800883 status_t result = provideProvisionResponse(response, certificate, wrappedKey);
884 writeVector(reply, certificate);
885 writeVector(reply, wrappedKey);
886 reply->writeInt32(result);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800887 return OK;
888 }
889
890 case GET_SECURE_STOPS:
891 {
892 CHECK_INTERFACE(IDrm, data, reply);
893 List<Vector<uint8_t> > secureStops;
894 status_t result = getSecureStops(secureStops);
895 size_t count = secureStops.size();
896 reply->writeInt32(count);
897 List<Vector<uint8_t> >::iterator iter = secureStops.begin();
898 while(iter != secureStops.end()) {
899 size_t size = iter->size();
900 reply->writeInt32(size);
901 reply->write(iter->array(), iter->size());
Jeff Tinker423e33c2013-04-08 15:23:17 -0700902 iter++;
Jeff Tinker441a78d2013-02-08 10:18:35 -0800903 }
904 reply->writeInt32(result);
905 return OK;
906 }
907
Jeff Tinker15177d72018-01-25 12:57:55 -0800908 case GET_SECURE_STOP_IDS:
909 {
910 CHECK_INTERFACE(IDrm, data, reply);
911 List<Vector<uint8_t> > secureStopIds;
912 status_t result = getSecureStopIds(secureStopIds);
913 size_t count = secureStopIds.size();
914 reply->writeInt32(count);
915 List<Vector<uint8_t> >::iterator iter = secureStopIds.begin();
916 while(iter != secureStopIds.end()) {
917 size_t size = iter->size();
918 reply->writeInt32(size);
919 reply->write(iter->array(), iter->size());
920 iter++;
921 }
922 reply->writeInt32(result);
923 return OK;
924 }
925
Jeff Tinker3c1285e2014-10-31 00:55:16 -0700926 case GET_SECURE_STOP:
927 {
928 CHECK_INTERFACE(IDrm, data, reply);
929 Vector<uint8_t> ssid, secureStop;
930 readVector(data, ssid);
931 status_t result = getSecureStop(ssid, secureStop);
932 writeVector(reply, secureStop);
933 reply->writeInt32(result);
934 return OK;
935 }
936
Jeff Tinker441a78d2013-02-08 10:18:35 -0800937 case RELEASE_SECURE_STOPS:
938 {
939 CHECK_INTERFACE(IDrm, data, reply);
940 Vector<uint8_t> ssRelease;
Jeff Tinker4c63a232013-03-30 16:19:44 -0700941 readVector(data, ssRelease);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800942 reply->writeInt32(releaseSecureStops(ssRelease));
943 return OK;
944 }
945
Jeff Tinker15177d72018-01-25 12:57:55 -0800946 case REMOVE_SECURE_STOP:
Jeff Tinker3c1285e2014-10-31 00:55:16 -0700947 {
948 CHECK_INTERFACE(IDrm, data, reply);
Jeff Tinker15177d72018-01-25 12:57:55 -0800949 Vector<uint8_t> ssid;
950 readVector(data, ssid);
951 reply->writeInt32(removeSecureStop(ssid));
952 return OK;
953 }
954
955 case REMOVE_ALL_SECURE_STOPS:
956 {
957 CHECK_INTERFACE(IDrm, data, reply);
958 reply->writeInt32(removeAllSecureStops());
Jeff Tinker3c1285e2014-10-31 00:55:16 -0700959 return OK;
960 }
961
Jeff Tinker6d998b62017-12-18 14:37:43 -0800962 case GET_HDCP_LEVELS:
963 {
964 CHECK_INTERFACE(IDrm, data, reply);
965 DrmPlugin::HdcpLevel connected = DrmPlugin::kHdcpLevelUnknown;
966 DrmPlugin::HdcpLevel max = DrmPlugin::kHdcpLevelUnknown;
967 status_t result = getHdcpLevels(&connected, &max);
968 reply->writeInt32(connected);
969 reply->writeInt32(max);
970 reply->writeInt32(result);
971 return OK;
972 }
973
974 case GET_NUMBER_OF_SESSIONS:
975 {
976 CHECK_INTERFACE(IDrm, data, reply);
977 uint32_t open = 0, max = 0;
978 status_t result = getNumberOfSessions(&open, &max);
979 reply->writeInt32(open);
980 reply->writeInt32(max);
981 reply->writeInt32(result);
982 return OK;
983 }
984
985 case GET_SECURITY_LEVEL:
986 {
987 CHECK_INTERFACE(IDrm, data, reply);
988 Vector<uint8_t> sessionId;
989 readVector(data, sessionId);
990 DrmPlugin::SecurityLevel level = DrmPlugin::kSecurityLevelUnknown;
991 status_t result = getSecurityLevel(sessionId, &level);
992 reply->writeInt32(level);
993 reply->writeInt32(result);
994 return OK;
995 }
996
997 case SET_SECURITY_LEVEL:
998 {
999 CHECK_INTERFACE(IDrm, data, reply);
1000 Vector<uint8_t> sessionId;
1001 readVector(data, sessionId);
1002 DrmPlugin::SecurityLevel level =
1003 static_cast<DrmPlugin::SecurityLevel>(data.readInt32());
1004 status_t result = setSecurityLevel(sessionId, level);
1005 reply->writeInt32(result);
1006 return OK;
1007 }
1008
Jeff Tinker441a78d2013-02-08 10:18:35 -08001009 case GET_PROPERTY_STRING:
1010 {
1011 CHECK_INTERFACE(IDrm, data, reply);
1012 String8 name = data.readString8();
1013 String8 value;
1014 status_t result = getPropertyString(name, value);
1015 reply->writeString8(value);
1016 reply->writeInt32(result);
1017 return OK;
1018 }
1019
1020 case GET_PROPERTY_BYTE_ARRAY:
1021 {
1022 CHECK_INTERFACE(IDrm, data, reply);
1023 String8 name = data.readString8();
1024 Vector<uint8_t> value;
1025 status_t result = getPropertyByteArray(name, value);
Jeff Tinker4c63a232013-03-30 16:19:44 -07001026 writeVector(reply, value);
Jeff Tinker441a78d2013-02-08 10:18:35 -08001027 reply->writeInt32(result);
1028 return OK;
1029 }
1030
1031 case SET_PROPERTY_STRING:
1032 {
1033 CHECK_INTERFACE(IDrm, data, reply);
1034 String8 name = data.readString8();
1035 String8 value = data.readString8();
1036 reply->writeInt32(setPropertyString(name, value));
1037 return OK;
1038 }
1039
1040 case SET_PROPERTY_BYTE_ARRAY:
1041 {
1042 CHECK_INTERFACE(IDrm, data, reply);
1043 String8 name = data.readString8();
1044 Vector<uint8_t> value;
Jeff Tinker4c63a232013-03-30 16:19:44 -07001045 readVector(data, value);
Jeff Tinker441a78d2013-02-08 10:18:35 -08001046 reply->writeInt32(setPropertyByteArray(name, value));
1047 return OK;
1048 }
1049
Adam Stoneab394d12017-12-22 12:34:20 -08001050 case GET_METRICS:
1051 {
1052 CHECK_INTERFACE(IDrm, data, reply);
1053
Adam Stone637b7852018-01-30 12:09:36 -08001054 os::PersistableBundle metrics;
1055 status_t result = getMetrics(&metrics);
Adam Stone568b3c42018-01-31 12:57:16 -08001056 // The reply data is ordered as
1057 // 1) 32 bit integer reply followed by
1058 // 2) Serialized PersistableBundle containing metrics.
1059 // Only write the metrics if the getMetrics result was
1060 // OK and we successfully added the status to reply.
1061 status_t parcel_result = reply->writeInt32(result);
1062 if (result == OK && parcel_result == OK) {
1063 parcel_result = metrics.writeToParcel(reply);
1064 }
1065 return parcel_result;
Adam Stoneab394d12017-12-22 12:34:20 -08001066 }
1067
Jeff Tinker4c63a232013-03-30 16:19:44 -07001068 case SET_CIPHER_ALGORITHM:
1069 {
1070 CHECK_INTERFACE(IDrm, data, reply);
1071 Vector<uint8_t> sessionId;
1072 readVector(data, sessionId);
1073 String8 algorithm = data.readString8();
1074 reply->writeInt32(setCipherAlgorithm(sessionId, algorithm));
1075 return OK;
1076 }
1077
1078 case SET_MAC_ALGORITHM:
1079 {
1080 CHECK_INTERFACE(IDrm, data, reply);
1081 Vector<uint8_t> sessionId;
1082 readVector(data, sessionId);
1083 String8 algorithm = data.readString8();
1084 reply->writeInt32(setMacAlgorithm(sessionId, algorithm));
1085 return OK;
1086 }
1087
1088 case ENCRYPT:
1089 {
1090 CHECK_INTERFACE(IDrm, data, reply);
1091 Vector<uint8_t> sessionId, keyId, input, iv, output;
1092 readVector(data, sessionId);
1093 readVector(data, keyId);
1094 readVector(data, input);
1095 readVector(data, iv);
1096 uint32_t result = encrypt(sessionId, keyId, input, iv, output);
1097 writeVector(reply, output);
1098 reply->writeInt32(result);
1099 return OK;
1100 }
1101
1102 case DECRYPT:
1103 {
1104 CHECK_INTERFACE(IDrm, data, reply);
1105 Vector<uint8_t> sessionId, keyId, input, iv, output;
1106 readVector(data, sessionId);
1107 readVector(data, keyId);
1108 readVector(data, input);
1109 readVector(data, iv);
1110 uint32_t result = decrypt(sessionId, keyId, input, iv, output);
1111 writeVector(reply, output);
1112 reply->writeInt32(result);
1113 return OK;
1114 }
1115
1116 case SIGN:
1117 {
1118 CHECK_INTERFACE(IDrm, data, reply);
1119 Vector<uint8_t> sessionId, keyId, message, signature;
1120 readVector(data, sessionId);
1121 readVector(data, keyId);
1122 readVector(data, message);
1123 uint32_t result = sign(sessionId, keyId, message, signature);
1124 writeVector(reply, signature);
1125 reply->writeInt32(result);
1126 return OK;
1127 }
1128
1129 case VERIFY:
1130 {
1131 CHECK_INTERFACE(IDrm, data, reply);
1132 Vector<uint8_t> sessionId, keyId, message, signature;
1133 readVector(data, sessionId);
1134 readVector(data, keyId);
1135 readVector(data, message);
1136 readVector(data, signature);
Jeff Tinker9a6861c2016-09-02 11:36:46 -07001137 bool match = false;
Jeff Tinker4c63a232013-03-30 16:19:44 -07001138 uint32_t result = verify(sessionId, keyId, message, signature, match);
1139 reply->writeInt32(match);
1140 reply->writeInt32(result);
1141 return OK;
1142 }
1143
Jeff Tinker68d9d712014-03-04 13:21:31 -08001144 case SIGN_RSA:
1145 {
1146 CHECK_INTERFACE(IDrm, data, reply);
1147 Vector<uint8_t> sessionId, message, wrappedKey, signature;
1148 readVector(data, sessionId);
1149 String8 algorithm = data.readString8();
1150 readVector(data, message);
1151 readVector(data, wrappedKey);
1152 uint32_t result = signRSA(sessionId, algorithm, message, wrappedKey, signature);
1153 writeVector(reply, signature);
1154 reply->writeInt32(result);
1155 return OK;
1156 }
1157
Jeff Tinkerc0d5f1f2013-04-02 13:08:05 -07001158 case SET_LISTENER: {
1159 CHECK_INTERFACE(IDrm, data, reply);
1160 sp<IDrmClient> listener =
1161 interface_cast<IDrmClient>(data.readStrongBinder());
1162 reply->writeInt32(setListener(listener));
1163 return NO_ERROR;
1164 } break;
1165
Jeff Tinker4c63a232013-03-30 16:19:44 -07001166 default:
1167 return BBinder::onTransact(code, data, reply, flags);
Jeff Tinker441a78d2013-02-08 10:18:35 -08001168 }
1169}
1170
1171} // namespace android