blob: 63a95626a2d0c16960cf0f525dbe44075792024d [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 Stoneab394d12017-12-22 12:34:20 -0800511 virtual status_t getMetrics(MediaAnalyticsItem *item) {
512 Parcel data, reply;
513 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
514
515 status_t status = remote()->transact(GET_METRICS, data, &reply);
516 if (status != OK) {
517 return status;
518 }
519
520 item->readFromParcel(reply);
521 return reply.readInt32();
522 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800523
Jeff Tinker4c63a232013-03-30 16:19:44 -0700524 virtual status_t setCipherAlgorithm(Vector<uint8_t> const &sessionId,
525 String8 const &algorithm) {
526 Parcel data, reply;
527 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
528
529 writeVector(data, sessionId);
530 data.writeString8(algorithm);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700531 status_t status = remote()->transact(SET_CIPHER_ALGORITHM, data, &reply);
532 if (status != OK) {
533 return status;
534 }
Jeff Tinker4c63a232013-03-30 16:19:44 -0700535 return reply.readInt32();
536 }
537
538 virtual status_t setMacAlgorithm(Vector<uint8_t> const &sessionId,
539 String8 const &algorithm) {
540 Parcel data, reply;
541 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
542
543 writeVector(data, sessionId);
544 data.writeString8(algorithm);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700545 status_t status = remote()->transact(SET_MAC_ALGORITHM, data, &reply);
546 if (status != OK) {
547 return status;
548 }
Jeff Tinker4c63a232013-03-30 16:19:44 -0700549 return reply.readInt32();
550 }
551
552 virtual status_t encrypt(Vector<uint8_t> const &sessionId,
553 Vector<uint8_t> const &keyId,
554 Vector<uint8_t> const &input,
555 Vector<uint8_t> const &iv,
556 Vector<uint8_t> &output) {
557 Parcel data, reply;
558 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
559
560 writeVector(data, sessionId);
561 writeVector(data, keyId);
562 writeVector(data, input);
563 writeVector(data, iv);
564
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700565 status_t status = remote()->transact(ENCRYPT, data, &reply);
566 if (status != OK) {
567 return status;
568 }
Jeff Tinker4c63a232013-03-30 16:19:44 -0700569 readVector(reply, output);
570
571 return reply.readInt32();
572 }
573
574 virtual status_t decrypt(Vector<uint8_t> const &sessionId,
575 Vector<uint8_t> const &keyId,
576 Vector<uint8_t> const &input,
577 Vector<uint8_t> const &iv,
578 Vector<uint8_t> &output) {
579 Parcel data, reply;
580 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
581
582 writeVector(data, sessionId);
583 writeVector(data, keyId);
584 writeVector(data, input);
585 writeVector(data, iv);
586
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700587 status_t status = remote()->transact(DECRYPT, data, &reply);
588 if (status != OK) {
589 return status;
590 }
Jeff Tinker4c63a232013-03-30 16:19:44 -0700591 readVector(reply, output);
592
593 return reply.readInt32();
594 }
595
596 virtual status_t sign(Vector<uint8_t> const &sessionId,
597 Vector<uint8_t> const &keyId,
598 Vector<uint8_t> const &message,
599 Vector<uint8_t> &signature) {
600 Parcel data, reply;
601 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
602
603 writeVector(data, sessionId);
604 writeVector(data, keyId);
605 writeVector(data, message);
606
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700607 status_t status = remote()->transact(SIGN, data, &reply);
608 if (status != OK) {
609 return status;
610 }
Jeff Tinker4c63a232013-03-30 16:19:44 -0700611 readVector(reply, signature);
612
613 return reply.readInt32();
614 }
615
616 virtual status_t verify(Vector<uint8_t> const &sessionId,
617 Vector<uint8_t> const &keyId,
618 Vector<uint8_t> const &message,
619 Vector<uint8_t> const &signature,
620 bool &match) {
621 Parcel data, reply;
622 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
623
624 writeVector(data, sessionId);
625 writeVector(data, keyId);
626 writeVector(data, message);
627 writeVector(data, signature);
628
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700629 status_t status = remote()->transact(VERIFY, data, &reply);
630 if (status != OK) {
631 return status;
632 }
Jeff Tinker4c63a232013-03-30 16:19:44 -0700633 match = (bool)reply.readInt32();
634 return reply.readInt32();
635 }
636
Jeff Tinker68d9d712014-03-04 13:21:31 -0800637 virtual status_t signRSA(Vector<uint8_t> const &sessionId,
638 String8 const &algorithm,
639 Vector<uint8_t> const &message,
640 Vector<uint8_t> const &wrappedKey,
641 Vector<uint8_t> &signature) {
642 Parcel data, reply;
643 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
644
645 writeVector(data, sessionId);
646 data.writeString8(algorithm);
647 writeVector(data, message);
648 writeVector(data, wrappedKey);
649
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700650 status_t status = remote()->transact(SIGN_RSA, data, &reply);
651 if (status != OK) {
652 return status;
653 }
Jeff Tinker68d9d712014-03-04 13:21:31 -0800654 readVector(reply, signature);
655
656 return reply.readInt32();
657 }
658
Jeff Tinkerc0d5f1f2013-04-02 13:08:05 -0700659 virtual status_t setListener(const sp<IDrmClient>& listener) {
660 Parcel data, reply;
661 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
Marco Nelissen06b46062014-11-14 07:58:25 -0800662 data.writeStrongBinder(IInterface::asBinder(listener));
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700663 status_t status = remote()->transact(SET_LISTENER, data, &reply);
664 if (status != OK) {
665 return status;
666 }
Jeff Tinkerc0d5f1f2013-04-02 13:08:05 -0700667 return reply.readInt32();
668 }
669
Jeff Tinker441a78d2013-02-08 10:18:35 -0800670private:
Jeff Tinker4c63a232013-03-30 16:19:44 -0700671 void readVector(Parcel &reply, Vector<uint8_t> &vector) const {
672 uint32_t size = reply.readInt32();
673 vector.insertAt((size_t)0, size);
674 reply.read(vector.editArray(), size);
675 }
676
677 void writeVector(Parcel &data, Vector<uint8_t> const &vector) const {
678 data.writeInt32(vector.size());
679 data.write(vector.array(), vector.size());
680 }
681
Jeff Tinker441a78d2013-02-08 10:18:35 -0800682 DISALLOW_EVIL_CONSTRUCTORS(BpDrm);
683};
684
685IMPLEMENT_META_INTERFACE(Drm, "android.drm.IDrm");
686
687////////////////////////////////////////////////////////////////////////////////
688
Jeff Tinker4c63a232013-03-30 16:19:44 -0700689void BnDrm::readVector(const Parcel &data, Vector<uint8_t> &vector) const {
690 uint32_t size = data.readInt32();
Jeff Tinker3cf728e2017-10-18 20:54:26 +0000691 if (vector.insertAt((size_t)0, size) < 0) {
692 vector.clear();
693 }
694 if (data.read(vector.editArray(), size) != NO_ERROR) {
695 vector.clear();
696 android_errorWriteWithInfoLog(0x534e4554, "62872384", -1, NULL, 0);
697 }
Jeff Tinker4c63a232013-03-30 16:19:44 -0700698}
699
700void BnDrm::writeVector(Parcel *reply, Vector<uint8_t> const &vector) const {
701 reply->writeInt32(vector.size());
702 reply->write(vector.array(), vector.size());
703}
704
Jeff Tinker441a78d2013-02-08 10:18:35 -0800705status_t BnDrm::onTransact(
706 uint32_t code, const Parcel &data, Parcel *reply, uint32_t flags) {
707 switch (code) {
708 case INIT_CHECK:
709 {
710 CHECK_INTERFACE(IDrm, data, reply);
711 reply->writeInt32(initCheck());
712 return OK;
713 }
714
715 case IS_CRYPTO_SUPPORTED:
716 {
717 CHECK_INTERFACE(IDrm, data, reply);
718 uint8_t uuid[16];
719 data.read(uuid, sizeof(uuid));
Jeff Tinker9cf69e02013-08-21 11:59:23 -0700720 String8 mimeType = data.readString8();
721 reply->writeInt32(isCryptoSchemeSupported(uuid, mimeType));
Jeff Tinker441a78d2013-02-08 10:18:35 -0800722 return OK;
723 }
724
725 case CREATE_PLUGIN:
726 {
727 CHECK_INTERFACE(IDrm, data, reply);
728 uint8_t uuid[16];
729 data.read(uuid, sizeof(uuid));
Edwin Wong68b3d9f2017-01-06 19:07:54 -0800730 String8 appPackageName = data.readString8();
731 reply->writeInt32(createPlugin(uuid, appPackageName));
Jeff Tinker441a78d2013-02-08 10:18:35 -0800732 return OK;
733 }
734
735 case DESTROY_PLUGIN:
736 {
737 CHECK_INTERFACE(IDrm, data, reply);
738 reply->writeInt32(destroyPlugin());
739 return OK;
740 }
741
742 case OPEN_SESSION:
743 {
744 CHECK_INTERFACE(IDrm, data, reply);
745 Vector<uint8_t> sessionId;
746 status_t result = openSession(sessionId);
Jeff Tinker4c63a232013-03-30 16:19:44 -0700747 writeVector(reply, sessionId);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800748 reply->writeInt32(result);
749 return OK;
750 }
751
752 case CLOSE_SESSION:
753 {
754 CHECK_INTERFACE(IDrm, data, reply);
755 Vector<uint8_t> sessionId;
Jeff Tinker4c63a232013-03-30 16:19:44 -0700756 readVector(data, sessionId);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800757 reply->writeInt32(closeSession(sessionId));
758 return OK;
759 }
760
Jeff Tinker4c63a232013-03-30 16:19:44 -0700761 case GET_KEY_REQUEST:
Jeff Tinker441a78d2013-02-08 10:18:35 -0800762 {
763 CHECK_INTERFACE(IDrm, data, reply);
Jeff Tinker4c63a232013-03-30 16:19:44 -0700764 Vector<uint8_t> sessionId, initData;
Jeff Tinker441a78d2013-02-08 10:18:35 -0800765
Jeff Tinker4c63a232013-03-30 16:19:44 -0700766 readVector(data, sessionId);
767 readVector(data, initData);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800768 String8 mimeType = data.readString8();
Jeff Tinker4c63a232013-03-30 16:19:44 -0700769 DrmPlugin::KeyType keyType = (DrmPlugin::KeyType)data.readInt32();
Jeff Tinker441a78d2013-02-08 10:18:35 -0800770
771 KeyedVector<String8, String8> optionalParameters;
772 uint32_t count = data.readInt32();
773 for (size_t i = 0; i < count; ++i) {
774 String8 key, value;
775 key = data.readString8();
776 value = data.readString8();
777 optionalParameters.add(key, value);
778 }
779
780 Vector<uint8_t> request;
781 String8 defaultUrl;
Jeff Tinker8aff7772016-02-08 17:52:25 -0800782 DrmPlugin::KeyRequestType keyRequestType = DrmPlugin::kKeyRequestType_Unknown;
Jeff Tinker441a78d2013-02-08 10:18:35 -0800783
Jeff Tinkerd072c902015-03-16 13:39:29 -0700784 status_t result = getKeyRequest(sessionId, initData, mimeType,
785 keyType, optionalParameters, request, defaultUrl,
786 &keyRequestType);
787
Jeff Tinker4c63a232013-03-30 16:19:44 -0700788 writeVector(reply, request);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800789 reply->writeString8(defaultUrl);
Jeff Tinkerd072c902015-03-16 13:39:29 -0700790 reply->writeInt32(static_cast<int32_t>(keyRequestType));
Jeff Tinker441a78d2013-02-08 10:18:35 -0800791 reply->writeInt32(result);
792 return OK;
793 }
794
Jeff Tinker4c63a232013-03-30 16:19:44 -0700795 case PROVIDE_KEY_RESPONSE:
Jeff Tinker441a78d2013-02-08 10:18:35 -0800796 {
797 CHECK_INTERFACE(IDrm, data, reply);
Jeff Tinker4c63a232013-03-30 16:19:44 -0700798 Vector<uint8_t> sessionId, response, keySetId;
799 readVector(data, sessionId);
800 readVector(data, response);
801 uint32_t result = provideKeyResponse(sessionId, response, keySetId);
802 writeVector(reply, keySetId);
803 reply->writeInt32(result);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800804 return OK;
805 }
806
Jeff Tinker4c63a232013-03-30 16:19:44 -0700807 case REMOVE_KEYS:
Jeff Tinker441a78d2013-02-08 10:18:35 -0800808 {
809 CHECK_INTERFACE(IDrm, data, reply);
Jeff Tinker4c63a232013-03-30 16:19:44 -0700810 Vector<uint8_t> keySetId;
811 readVector(data, keySetId);
812 reply->writeInt32(removeKeys(keySetId));
Jeff Tinker441a78d2013-02-08 10:18:35 -0800813 return OK;
814 }
815
Jeff Tinker4c63a232013-03-30 16:19:44 -0700816 case RESTORE_KEYS:
817 {
818 CHECK_INTERFACE(IDrm, data, reply);
819 Vector<uint8_t> sessionId, keySetId;
820 readVector(data, sessionId);
821 readVector(data, keySetId);
822 reply->writeInt32(restoreKeys(sessionId, keySetId));
823 return OK;
824 }
825
826 case QUERY_KEY_STATUS:
Jeff Tinker441a78d2013-02-08 10:18:35 -0800827 {
828 CHECK_INTERFACE(IDrm, data, reply);
829 Vector<uint8_t> sessionId;
Jeff Tinker4c63a232013-03-30 16:19:44 -0700830 readVector(data, sessionId);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800831 KeyedVector<String8, String8> infoMap;
Jeff Tinker4c63a232013-03-30 16:19:44 -0700832 status_t result = queryKeyStatus(sessionId, infoMap);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800833 size_t count = infoMap.size();
834 reply->writeInt32(count);
835 for (size_t i = 0; i < count; ++i) {
836 reply->writeString8(infoMap.keyAt(i));
837 reply->writeString8(infoMap.valueAt(i));
838 }
839 reply->writeInt32(result);
840 return OK;
841 }
842
843 case GET_PROVISION_REQUEST:
844 {
845 CHECK_INTERFACE(IDrm, data, reply);
Jeff Tinker68d9d712014-03-04 13:21:31 -0800846 String8 certType = data.readString8();
847 String8 certAuthority = data.readString8();
848
Jeff Tinker441a78d2013-02-08 10:18:35 -0800849 Vector<uint8_t> request;
850 String8 defaultUrl;
Jeff Tinker68d9d712014-03-04 13:21:31 -0800851 status_t result = getProvisionRequest(certType, certAuthority,
852 request, defaultUrl);
Jeff Tinker4c63a232013-03-30 16:19:44 -0700853 writeVector(reply, request);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800854 reply->writeString8(defaultUrl);
855 reply->writeInt32(result);
856 return OK;
857 }
858
859 case PROVIDE_PROVISION_RESPONSE:
860 {
861 CHECK_INTERFACE(IDrm, data, reply);
862 Vector<uint8_t> response;
Jeff Tinker68d9d712014-03-04 13:21:31 -0800863 Vector<uint8_t> certificate;
864 Vector<uint8_t> wrappedKey;
Jeff Tinker4c63a232013-03-30 16:19:44 -0700865 readVector(data, response);
Jeff Tinker68d9d712014-03-04 13:21:31 -0800866 status_t result = provideProvisionResponse(response, certificate, wrappedKey);
867 writeVector(reply, certificate);
868 writeVector(reply, wrappedKey);
869 reply->writeInt32(result);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800870 return OK;
871 }
872
873 case GET_SECURE_STOPS:
874 {
875 CHECK_INTERFACE(IDrm, data, reply);
876 List<Vector<uint8_t> > secureStops;
877 status_t result = getSecureStops(secureStops);
878 size_t count = secureStops.size();
879 reply->writeInt32(count);
880 List<Vector<uint8_t> >::iterator iter = secureStops.begin();
881 while(iter != secureStops.end()) {
882 size_t size = iter->size();
883 reply->writeInt32(size);
884 reply->write(iter->array(), iter->size());
Jeff Tinker423e33c2013-04-08 15:23:17 -0700885 iter++;
Jeff Tinker441a78d2013-02-08 10:18:35 -0800886 }
887 reply->writeInt32(result);
888 return OK;
889 }
890
Jeff Tinker15177d72018-01-25 12:57:55 -0800891 case GET_SECURE_STOP_IDS:
892 {
893 CHECK_INTERFACE(IDrm, data, reply);
894 List<Vector<uint8_t> > secureStopIds;
895 status_t result = getSecureStopIds(secureStopIds);
896 size_t count = secureStopIds.size();
897 reply->writeInt32(count);
898 List<Vector<uint8_t> >::iterator iter = secureStopIds.begin();
899 while(iter != secureStopIds.end()) {
900 size_t size = iter->size();
901 reply->writeInt32(size);
902 reply->write(iter->array(), iter->size());
903 iter++;
904 }
905 reply->writeInt32(result);
906 return OK;
907 }
908
Jeff Tinker3c1285e2014-10-31 00:55:16 -0700909 case GET_SECURE_STOP:
910 {
911 CHECK_INTERFACE(IDrm, data, reply);
912 Vector<uint8_t> ssid, secureStop;
913 readVector(data, ssid);
914 status_t result = getSecureStop(ssid, secureStop);
915 writeVector(reply, secureStop);
916 reply->writeInt32(result);
917 return OK;
918 }
919
Jeff Tinker441a78d2013-02-08 10:18:35 -0800920 case RELEASE_SECURE_STOPS:
921 {
922 CHECK_INTERFACE(IDrm, data, reply);
923 Vector<uint8_t> ssRelease;
Jeff Tinker4c63a232013-03-30 16:19:44 -0700924 readVector(data, ssRelease);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800925 reply->writeInt32(releaseSecureStops(ssRelease));
926 return OK;
927 }
928
Jeff Tinker15177d72018-01-25 12:57:55 -0800929 case REMOVE_SECURE_STOP:
Jeff Tinker3c1285e2014-10-31 00:55:16 -0700930 {
931 CHECK_INTERFACE(IDrm, data, reply);
Jeff Tinker15177d72018-01-25 12:57:55 -0800932 Vector<uint8_t> ssid;
933 readVector(data, ssid);
934 reply->writeInt32(removeSecureStop(ssid));
935 return OK;
936 }
937
938 case REMOVE_ALL_SECURE_STOPS:
939 {
940 CHECK_INTERFACE(IDrm, data, reply);
941 reply->writeInt32(removeAllSecureStops());
Jeff Tinker3c1285e2014-10-31 00:55:16 -0700942 return OK;
943 }
944
Jeff Tinker6d998b62017-12-18 14:37:43 -0800945 case GET_HDCP_LEVELS:
946 {
947 CHECK_INTERFACE(IDrm, data, reply);
948 DrmPlugin::HdcpLevel connected = DrmPlugin::kHdcpLevelUnknown;
949 DrmPlugin::HdcpLevel max = DrmPlugin::kHdcpLevelUnknown;
950 status_t result = getHdcpLevels(&connected, &max);
951 reply->writeInt32(connected);
952 reply->writeInt32(max);
953 reply->writeInt32(result);
954 return OK;
955 }
956
957 case GET_NUMBER_OF_SESSIONS:
958 {
959 CHECK_INTERFACE(IDrm, data, reply);
960 uint32_t open = 0, max = 0;
961 status_t result = getNumberOfSessions(&open, &max);
962 reply->writeInt32(open);
963 reply->writeInt32(max);
964 reply->writeInt32(result);
965 return OK;
966 }
967
968 case GET_SECURITY_LEVEL:
969 {
970 CHECK_INTERFACE(IDrm, data, reply);
971 Vector<uint8_t> sessionId;
972 readVector(data, sessionId);
973 DrmPlugin::SecurityLevel level = DrmPlugin::kSecurityLevelUnknown;
974 status_t result = getSecurityLevel(sessionId, &level);
975 reply->writeInt32(level);
976 reply->writeInt32(result);
977 return OK;
978 }
979
980 case SET_SECURITY_LEVEL:
981 {
982 CHECK_INTERFACE(IDrm, data, reply);
983 Vector<uint8_t> sessionId;
984 readVector(data, sessionId);
985 DrmPlugin::SecurityLevel level =
986 static_cast<DrmPlugin::SecurityLevel>(data.readInt32());
987 status_t result = setSecurityLevel(sessionId, level);
988 reply->writeInt32(result);
989 return OK;
990 }
991
Jeff Tinker441a78d2013-02-08 10:18:35 -0800992 case GET_PROPERTY_STRING:
993 {
994 CHECK_INTERFACE(IDrm, data, reply);
995 String8 name = data.readString8();
996 String8 value;
997 status_t result = getPropertyString(name, value);
998 reply->writeString8(value);
999 reply->writeInt32(result);
1000 return OK;
1001 }
1002
1003 case GET_PROPERTY_BYTE_ARRAY:
1004 {
1005 CHECK_INTERFACE(IDrm, data, reply);
1006 String8 name = data.readString8();
1007 Vector<uint8_t> value;
1008 status_t result = getPropertyByteArray(name, value);
Jeff Tinker4c63a232013-03-30 16:19:44 -07001009 writeVector(reply, value);
Jeff Tinker441a78d2013-02-08 10:18:35 -08001010 reply->writeInt32(result);
1011 return OK;
1012 }
1013
1014 case SET_PROPERTY_STRING:
1015 {
1016 CHECK_INTERFACE(IDrm, data, reply);
1017 String8 name = data.readString8();
1018 String8 value = data.readString8();
1019 reply->writeInt32(setPropertyString(name, value));
1020 return OK;
1021 }
1022
1023 case SET_PROPERTY_BYTE_ARRAY:
1024 {
1025 CHECK_INTERFACE(IDrm, data, reply);
1026 String8 name = data.readString8();
1027 Vector<uint8_t> value;
Jeff Tinker4c63a232013-03-30 16:19:44 -07001028 readVector(data, value);
Jeff Tinker441a78d2013-02-08 10:18:35 -08001029 reply->writeInt32(setPropertyByteArray(name, value));
1030 return OK;
1031 }
1032
Adam Stoneab394d12017-12-22 12:34:20 -08001033 case GET_METRICS:
1034 {
1035 CHECK_INTERFACE(IDrm, data, reply);
1036
1037 MediaAnalyticsItem item;
1038 status_t result = getMetrics(&item);
1039 item.writeToParcel(reply);
1040 reply->writeInt32(result);
1041 return OK;
1042 }
1043
Jeff Tinker4c63a232013-03-30 16:19:44 -07001044 case SET_CIPHER_ALGORITHM:
1045 {
1046 CHECK_INTERFACE(IDrm, data, reply);
1047 Vector<uint8_t> sessionId;
1048 readVector(data, sessionId);
1049 String8 algorithm = data.readString8();
1050 reply->writeInt32(setCipherAlgorithm(sessionId, algorithm));
1051 return OK;
1052 }
1053
1054 case SET_MAC_ALGORITHM:
1055 {
1056 CHECK_INTERFACE(IDrm, data, reply);
1057 Vector<uint8_t> sessionId;
1058 readVector(data, sessionId);
1059 String8 algorithm = data.readString8();
1060 reply->writeInt32(setMacAlgorithm(sessionId, algorithm));
1061 return OK;
1062 }
1063
1064 case ENCRYPT:
1065 {
1066 CHECK_INTERFACE(IDrm, data, reply);
1067 Vector<uint8_t> sessionId, keyId, input, iv, output;
1068 readVector(data, sessionId);
1069 readVector(data, keyId);
1070 readVector(data, input);
1071 readVector(data, iv);
1072 uint32_t result = encrypt(sessionId, keyId, input, iv, output);
1073 writeVector(reply, output);
1074 reply->writeInt32(result);
1075 return OK;
1076 }
1077
1078 case DECRYPT:
1079 {
1080 CHECK_INTERFACE(IDrm, data, reply);
1081 Vector<uint8_t> sessionId, keyId, input, iv, output;
1082 readVector(data, sessionId);
1083 readVector(data, keyId);
1084 readVector(data, input);
1085 readVector(data, iv);
1086 uint32_t result = decrypt(sessionId, keyId, input, iv, output);
1087 writeVector(reply, output);
1088 reply->writeInt32(result);
1089 return OK;
1090 }
1091
1092 case SIGN:
1093 {
1094 CHECK_INTERFACE(IDrm, data, reply);
1095 Vector<uint8_t> sessionId, keyId, message, signature;
1096 readVector(data, sessionId);
1097 readVector(data, keyId);
1098 readVector(data, message);
1099 uint32_t result = sign(sessionId, keyId, message, signature);
1100 writeVector(reply, signature);
1101 reply->writeInt32(result);
1102 return OK;
1103 }
1104
1105 case VERIFY:
1106 {
1107 CHECK_INTERFACE(IDrm, data, reply);
1108 Vector<uint8_t> sessionId, keyId, message, signature;
1109 readVector(data, sessionId);
1110 readVector(data, keyId);
1111 readVector(data, message);
1112 readVector(data, signature);
Jeff Tinker9a6861c2016-09-02 11:36:46 -07001113 bool match = false;
Jeff Tinker4c63a232013-03-30 16:19:44 -07001114 uint32_t result = verify(sessionId, keyId, message, signature, match);
1115 reply->writeInt32(match);
1116 reply->writeInt32(result);
1117 return OK;
1118 }
1119
Jeff Tinker68d9d712014-03-04 13:21:31 -08001120 case SIGN_RSA:
1121 {
1122 CHECK_INTERFACE(IDrm, data, reply);
1123 Vector<uint8_t> sessionId, message, wrappedKey, signature;
1124 readVector(data, sessionId);
1125 String8 algorithm = data.readString8();
1126 readVector(data, message);
1127 readVector(data, wrappedKey);
1128 uint32_t result = signRSA(sessionId, algorithm, message, wrappedKey, signature);
1129 writeVector(reply, signature);
1130 reply->writeInt32(result);
1131 return OK;
1132 }
1133
Jeff Tinkerc0d5f1f2013-04-02 13:08:05 -07001134 case SET_LISTENER: {
1135 CHECK_INTERFACE(IDrm, data, reply);
1136 sp<IDrmClient> listener =
1137 interface_cast<IDrmClient>(data.readStrongBinder());
1138 reply->writeInt32(setListener(listener));
1139 return NO_ERROR;
1140 } break;
1141
Jeff Tinker4c63a232013-03-30 16:19:44 -07001142 default:
1143 return BBinder::onTransact(code, data, reply, flags);
Jeff Tinker441a78d2013-02-08 10:18:35 -08001144 }
1145}
1146
1147} // namespace android