blob: 0f343151c8f02696719af52fbbb1ec59de79675c [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>
Jeff Tinker441a78d2013-02-08 10:18:35 -080022#include <media/stagefright/MediaErrors.h>
23#include <media/stagefright/foundation/ADebug.h>
24#include <media/stagefright/foundation/AString.h>
Jeff Tinker7d2c6e82018-02-16 16:14:59 -080025#include <mediadrm/IDrm.h>
Jeff Tinker441a78d2013-02-08 10:18:35 -080026
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,
Jeff Tinker15177d72018-01-25 12:57:55 -080063 REMOVE_SECURE_STOP,
Jeff Tinkerc8baaba2018-10-23 11:32:36 -070064 GET_SECURE_STOP_IDS,
65 GET_OFFLINE_LICENSE_KEYSET_IDS,
66 REMOVE_OFFLINE_LICENSE,
67 GET_OFFLINE_LICENSE_STATE
Jeff Tinker441a78d2013-02-08 10:18:35 -080068};
69
70struct BpDrm : public BpInterface<IDrm> {
Chih-Hung Hsieh090ef602016-04-27 10:39:54 -070071 explicit BpDrm(const sp<IBinder> &impl)
Jeff Tinker441a78d2013-02-08 10:18:35 -080072 : BpInterface<IDrm>(impl) {
73 }
74
75 virtual status_t initCheck() const {
76 Parcel data, reply;
77 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
Jeff Tinker3b5401a2015-06-15 17:42:10 -070078 status_t status = remote()->transact(INIT_CHECK, data, &reply);
79 if (status != OK) {
80 return status;
81 }
Jeff Tinker441a78d2013-02-08 10:18:35 -080082
83 return reply.readInt32();
84 }
85
Jeff Tinker99dbfa82019-01-17 17:27:06 -080086 virtual bool isCryptoSchemeSupported(const uint8_t uuid[16], const String8 &mimeType,
87 DrmPlugin::SecurityLevel level) {
Jeff Tinker441a78d2013-02-08 10:18:35 -080088 Parcel data, reply;
89 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
90 data.write(uuid, 16);
Jeff Tinker9cf69e02013-08-21 11:59:23 -070091 data.writeString8(mimeType);
Jeff Tinker99dbfa82019-01-17 17:27:06 -080092 data.writeInt32(level);
93
Jeff Tinker3b5401a2015-06-15 17:42:10 -070094 status_t status = remote()->transact(IS_CRYPTO_SUPPORTED, data, &reply);
95 if (status != OK) {
96 ALOGE("isCryptoSchemeSupported: binder call failed: %d", status);
97 return false;
98 }
Jeff Tinker441a78d2013-02-08 10:18:35 -080099
100 return reply.readInt32() != 0;
101 }
102
Edwin Wong68b3d9f2017-01-06 19:07:54 -0800103 virtual status_t createPlugin(const uint8_t uuid[16],
104 const String8& appPackageName) {
Jeff Tinker441a78d2013-02-08 10:18:35 -0800105 Parcel data, reply;
106 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
107 data.write(uuid, 16);
Edwin Wong68b3d9f2017-01-06 19:07:54 -0800108 data.writeString8(appPackageName);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700109 status_t status = remote()->transact(CREATE_PLUGIN, data, &reply);
110 if (status != OK) {
Edwin Wong68b3d9f2017-01-06 19:07:54 -0800111 ALOGE("createPlugin: binder call failed: %d", status);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700112 return status;
113 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800114
115 return reply.readInt32();
116 }
117
118 virtual status_t destroyPlugin() {
119 Parcel data, reply;
120 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700121 status_t status = remote()->transact(DESTROY_PLUGIN, data, &reply);
122 if (status != OK) {
123 return status;
124 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800125
126 return reply.readInt32();
127 }
128
Jeff Tinker99dbfa82019-01-17 17:27:06 -0800129 virtual status_t openSession(DrmPlugin::SecurityLevel level,
Jeff Tinker41d279a2018-02-11 19:52:08 +0000130 Vector<uint8_t> &sessionId) {
Jeff Tinker441a78d2013-02-08 10:18:35 -0800131 Parcel data, reply;
132 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
Jeff Tinker99dbfa82019-01-17 17:27:06 -0800133 data.writeInt32(level);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800134
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700135 status_t status = remote()->transact(OPEN_SESSION, data, &reply);
136 if (status != OK) {
137 return status;
138 }
Jeff Tinker4c63a232013-03-30 16:19:44 -0700139 readVector(reply, sessionId);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800140
141 return reply.readInt32();
142 }
143
144 virtual status_t closeSession(Vector<uint8_t> const &sessionId) {
145 Parcel data, reply;
146 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
147
Jeff Tinker4c63a232013-03-30 16:19:44 -0700148 writeVector(data, sessionId);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700149 status_t status = remote()->transact(CLOSE_SESSION, data, &reply);
150 if (status != OK) {
151 return status;
152 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800153
154 return reply.readInt32();
155 }
156
157 virtual status_t
Jeff Tinker4c63a232013-03-30 16:19:44 -0700158 getKeyRequest(Vector<uint8_t> const &sessionId,
159 Vector<uint8_t> const &initData,
160 String8 const &mimeType, DrmPlugin::KeyType keyType,
161 KeyedVector<String8, String8> const &optionalParameters,
Jeff Tinkerd072c902015-03-16 13:39:29 -0700162 Vector<uint8_t> &request, String8 &defaultUrl,
163 DrmPlugin::KeyRequestType *keyRequestType) {
Jeff Tinker441a78d2013-02-08 10:18:35 -0800164 Parcel data, reply;
165 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
166
Jeff Tinker4c63a232013-03-30 16:19:44 -0700167 writeVector(data, sessionId);
168 writeVector(data, initData);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800169 data.writeString8(mimeType);
Jeff Tinker4c63a232013-03-30 16:19:44 -0700170 data.writeInt32((uint32_t)keyType);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800171
172 data.writeInt32(optionalParameters.size());
173 for (size_t i = 0; i < optionalParameters.size(); ++i) {
174 data.writeString8(optionalParameters.keyAt(i));
175 data.writeString8(optionalParameters.valueAt(i));
176 }
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700177
178 status_t status = remote()->transact(GET_KEY_REQUEST, data, &reply);
179 if (status != OK) {
180 return status;
181 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800182
Jeff Tinker4c63a232013-03-30 16:19:44 -0700183 readVector(reply, request);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800184 defaultUrl = reply.readString8();
Jeff Tinkerd072c902015-03-16 13:39:29 -0700185 *keyRequestType = static_cast<DrmPlugin::KeyRequestType>(reply.readInt32());
Jeff Tinker441a78d2013-02-08 10:18:35 -0800186
187 return reply.readInt32();
188 }
189
Jeff Tinker4c63a232013-03-30 16:19:44 -0700190 virtual status_t provideKeyResponse(Vector<uint8_t> const &sessionId,
191 Vector<uint8_t> const &response,
192 Vector<uint8_t> &keySetId) {
Jeff Tinker441a78d2013-02-08 10:18:35 -0800193 Parcel data, reply;
194 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
Jeff Tinker4c63a232013-03-30 16:19:44 -0700195 writeVector(data, sessionId);
196 writeVector(data, response);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700197
198 status_t status = remote()->transact(PROVIDE_KEY_RESPONSE, data, &reply);
199 if (status != OK) {
200 return status;
201 }
202
Jeff Tinker4c63a232013-03-30 16:19:44 -0700203 readVector(reply, keySetId);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800204
205 return reply.readInt32();
206 }
207
Jeff Tinker4c63a232013-03-30 16:19:44 -0700208 virtual status_t removeKeys(Vector<uint8_t> const &keySetId) {
Jeff Tinker441a78d2013-02-08 10:18:35 -0800209 Parcel data, reply;
210 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
211
Jeff Tinker4c63a232013-03-30 16:19:44 -0700212 writeVector(data, keySetId);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700213 status_t status = remote()->transact(REMOVE_KEYS, data, &reply);
214 if (status != OK) {
215 return status;
216 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800217
218 return reply.readInt32();
219 }
220
Jeff Tinker4c63a232013-03-30 16:19:44 -0700221 virtual status_t restoreKeys(Vector<uint8_t> const &sessionId,
222 Vector<uint8_t> const &keySetId) {
223 Parcel data, reply;
224 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
225
226 writeVector(data, sessionId);
227 writeVector(data, keySetId);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700228 status_t status = remote()->transact(RESTORE_KEYS, data, &reply);
229 if (status != OK) {
230 return status;
231 }
Jeff Tinker4c63a232013-03-30 16:19:44 -0700232
233 return reply.readInt32();
234 }
235
236 virtual status_t queryKeyStatus(Vector<uint8_t> const &sessionId,
Jeff Tinker441a78d2013-02-08 10:18:35 -0800237 KeyedVector<String8, String8> &infoMap) const {
238 Parcel data, reply;
239 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
240
Jeff Tinker4c63a232013-03-30 16:19:44 -0700241 writeVector(data, sessionId);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700242 status_t status = remote()->transact(QUERY_KEY_STATUS, data, &reply);
243 if (status != OK) {
244 return status;
245 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800246
247 infoMap.clear();
248 size_t count = reply.readInt32();
249 for (size_t i = 0; i < count; i++) {
250 String8 key = reply.readString8();
251 String8 value = reply.readString8();
252 infoMap.add(key, value);
253 }
254 return reply.readInt32();
255 }
256
Jeff Tinker68d9d712014-03-04 13:21:31 -0800257 virtual status_t getProvisionRequest(String8 const &certType,
258 String8 const &certAuthority,
259 Vector<uint8_t> &request,
Jeff Tinker441a78d2013-02-08 10:18:35 -0800260 String8 &defaultUrl) {
261 Parcel data, reply;
262 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
263
Jeff Tinker68d9d712014-03-04 13:21:31 -0800264 data.writeString8(certType);
265 data.writeString8(certAuthority);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700266 status_t status = remote()->transact(GET_PROVISION_REQUEST, data, &reply);
267 if (status != OK) {
268 return status;
269 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800270
Jeff Tinker4c63a232013-03-30 16:19:44 -0700271 readVector(reply, request);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800272 defaultUrl = reply.readString8();
273
274 return reply.readInt32();
275 }
276
Jeff Tinker68d9d712014-03-04 13:21:31 -0800277 virtual status_t provideProvisionResponse(Vector<uint8_t> const &response,
278 Vector<uint8_t> &certificate,
279 Vector<uint8_t> &wrappedKey) {
Jeff Tinker441a78d2013-02-08 10:18:35 -0800280 Parcel data, reply;
281 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
282
Jeff Tinker4c63a232013-03-30 16:19:44 -0700283 writeVector(data, response);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700284 status_t status = remote()->transact(PROVIDE_PROVISION_RESPONSE, data, &reply);
285 if (status != OK) {
286 return status;
287 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800288
Jeff Tinker68d9d712014-03-04 13:21:31 -0800289 readVector(reply, certificate);
290 readVector(reply, wrappedKey);
291
Jeff Tinker441a78d2013-02-08 10:18:35 -0800292 return reply.readInt32();
293 }
294
295 virtual status_t getSecureStops(List<Vector<uint8_t> > &secureStops) {
296 Parcel data, reply;
297 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
298
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700299 status_t status = remote()->transact(GET_SECURE_STOPS, data, &reply);
300 if (status != OK) {
301 return status;
302 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800303
304 secureStops.clear();
305 uint32_t count = reply.readInt32();
306 for (size_t i = 0; i < count; i++) {
307 Vector<uint8_t> secureStop;
Jeff Tinker4c63a232013-03-30 16:19:44 -0700308 readVector(reply, secureStop);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800309 secureStops.push_back(secureStop);
310 }
311 return reply.readInt32();
312 }
313
Jeff Tinker15177d72018-01-25 12:57:55 -0800314 virtual status_t getSecureStopIds(List<Vector<uint8_t> > &secureStopIds) {
315 Parcel data, reply;
316 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
317
318 status_t status = remote()->transact(GET_SECURE_STOP_IDS, data, &reply);
319 if (status != OK) {
320 return status;
321 }
322
323 secureStopIds.clear();
324 uint32_t count = reply.readInt32();
325 for (size_t i = 0; i < count; i++) {
326 Vector<uint8_t> secureStopId;
327 readVector(reply, secureStopId);
328 secureStopIds.push_back(secureStopId);
329 }
330 return reply.readInt32();
331 }
332
Jeff Tinker3c1285e2014-10-31 00:55:16 -0700333 virtual status_t getSecureStop(Vector<uint8_t> const &ssid, Vector<uint8_t> &secureStop) {
334 Parcel data, reply;
335 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
336
337 writeVector(data, ssid);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700338 status_t status = remote()->transact(GET_SECURE_STOP, data, &reply);
339 if (status != OK) {
340 return status;
341 }
Jeff Tinker3c1285e2014-10-31 00:55:16 -0700342
343 readVector(reply, secureStop);
344 return reply.readInt32();
345 }
346
Jeff Tinker441a78d2013-02-08 10:18:35 -0800347 virtual status_t releaseSecureStops(Vector<uint8_t> const &ssRelease) {
348 Parcel data, reply;
349 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
350
Jeff Tinker4c63a232013-03-30 16:19:44 -0700351 writeVector(data, ssRelease);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700352 status_t status = remote()->transact(RELEASE_SECURE_STOPS, data, &reply);
353 if (status != OK) {
354 return status;
355 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800356
357 return reply.readInt32();
358 }
359
Jeff Tinker15177d72018-01-25 12:57:55 -0800360 virtual status_t removeSecureStop(Vector<uint8_t> const &ssid) {
Jeff Tinker3c1285e2014-10-31 00:55:16 -0700361 Parcel data, reply;
362 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
363
Jeff Tinker15177d72018-01-25 12:57:55 -0800364 writeVector(data, ssid);
365 status_t status = remote()->transact(REMOVE_SECURE_STOP, data, &reply);
366 if (status != OK) {
367 return status;
368 }
369
370 return reply.readInt32();
371 }
372
373 virtual status_t removeAllSecureStops() {
374 Parcel data, reply;
375 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
376
377 status_t status = remote()->transact(REMOVE_ALL_SECURE_STOPS, data, &reply);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700378 if (status != OK) {
379 return status;
380 }
Jeff Tinker3c1285e2014-10-31 00:55:16 -0700381
382 return reply.readInt32();
383 }
384
Jeff Tinkerc8baaba2018-10-23 11:32:36 -0700385 virtual status_t getOfflineLicenseKeySetIds(List<Vector<uint8_t> > &keySetIds) const {
386 Parcel data, reply;
387 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
388
389 status_t status = remote()->transact(GET_OFFLINE_LICENSE_KEYSET_IDS, data, &reply);
390 if (status != OK) {
391 return status;
392 }
393
394 keySetIds.clear();
395 uint32_t count = reply.readInt32();
396 for (size_t i = 0; i < count; i++) {
397 Vector<uint8_t> keySetId;
398 readVector(reply, keySetId);
399 keySetIds.push_back(keySetId);
400 }
401 return reply.readInt32();
402 }
403
404 virtual status_t removeOfflineLicense(Vector<uint8_t> const &keySetId) {
405 Parcel data, reply;
406 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
407
408 writeVector(data, keySetId);
409 status_t status = remote()->transact(REMOVE_OFFLINE_LICENSE, data, &reply);
410 if (status != OK) {
411 return status;
412 }
413 return reply.readInt32();
414 }
415
416 virtual status_t getOfflineLicenseState(Vector<uint8_t> const &keySetId,
417 DrmPlugin::OfflineLicenseState *licenseState) const {
418 Parcel data, reply;
419 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
420
421 writeVector(data, keySetId);
422 status_t status = remote()->transact(GET_OFFLINE_LICENSE_STATE, data, &reply);
423 if (status != OK) {
424 *licenseState = DrmPlugin::OfflineLicenseState::kOfflineLicenseStateUnknown;
425 return status;
426 }
427 *licenseState = static_cast<DrmPlugin::OfflineLicenseState>(reply.readInt32());
428 return reply.readInt32();
429 }
430
Jeff Tinker441a78d2013-02-08 10:18:35 -0800431 virtual status_t getPropertyString(String8 const &name, String8 &value) const {
432 Parcel data, reply;
433 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
434
435 data.writeString8(name);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700436 status_t status = remote()->transact(GET_PROPERTY_STRING, data, &reply);
437 if (status != OK) {
438 return status;
439 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800440
441 value = reply.readString8();
442 return reply.readInt32();
443 }
444
Jeff Tinker6d998b62017-12-18 14:37:43 -0800445 virtual status_t getHdcpLevels(DrmPlugin::HdcpLevel *connected,
446 DrmPlugin::HdcpLevel *max) const {
447 Parcel data, reply;
448
449 if (connected == NULL || max == NULL) {
450 return BAD_VALUE;
451 }
452
453 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
454
455 status_t status = remote()->transact(GET_HDCP_LEVELS, data, &reply);
456 if (status != OK) {
457 return status;
458 }
459
460 *connected = static_cast<DrmPlugin::HdcpLevel>(reply.readInt32());
461 *max = static_cast<DrmPlugin::HdcpLevel>(reply.readInt32());
462 return reply.readInt32();
463 }
464
465 virtual status_t getNumberOfSessions(uint32_t *open, uint32_t *max) const {
466 Parcel data, reply;
467
468 if (open == NULL || max == NULL) {
469 return BAD_VALUE;
470 }
471
472 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
473
474 status_t status = remote()->transact(GET_NUMBER_OF_SESSIONS, data, &reply);
475 if (status != OK) {
476 return status;
477 }
478
479 *open = reply.readInt32();
480 *max = reply.readInt32();
481 return reply.readInt32();
482 }
483
484 virtual status_t getSecurityLevel(Vector<uint8_t> const &sessionId,
485 DrmPlugin::SecurityLevel *level) const {
486 Parcel data, reply;
487
488 if (level == NULL) {
489 return BAD_VALUE;
490 }
491
492 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
493
494 writeVector(data, sessionId);
495 status_t status = remote()->transact(GET_SECURITY_LEVEL, data, &reply);
496 if (status != OK) {
497 return status;
498 }
499
500 *level = static_cast<DrmPlugin::SecurityLevel>(reply.readInt32());
501 return reply.readInt32();
502 }
503
Jeff Tinker441a78d2013-02-08 10:18:35 -0800504 virtual status_t getPropertyByteArray(String8 const &name, Vector<uint8_t> &value) const {
505 Parcel data, reply;
506 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
507
508 data.writeString8(name);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700509 status_t status = remote()->transact(GET_PROPERTY_BYTE_ARRAY, data, &reply);
510 if (status != OK) {
511 return status;
512 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800513
Jeff Tinker4c63a232013-03-30 16:19:44 -0700514 readVector(reply, value);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800515 return reply.readInt32();
516 }
517
518 virtual status_t setPropertyString(String8 const &name, String8 const &value) const {
519 Parcel data, reply;
520 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
521
522 data.writeString8(name);
523 data.writeString8(value);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700524 status_t status = remote()->transact(SET_PROPERTY_STRING, data, &reply);
525 if (status != OK) {
526 return status;
527 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800528
529 return reply.readInt32();
530 }
531
532 virtual status_t setPropertyByteArray(String8 const &name,
533 Vector<uint8_t> const &value) const {
534 Parcel data, reply;
535 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
536
537 data.writeString8(name);
Jeff Tinker4c63a232013-03-30 16:19:44 -0700538 writeVector(data, value);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700539 status_t status = remote()->transact(SET_PROPERTY_BYTE_ARRAY, data, &reply);
540 if (status != OK) {
541 return status;
542 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800543
544 return reply.readInt32();
545 }
546
Adam Stone637b7852018-01-30 12:09:36 -0800547 virtual status_t getMetrics(os::PersistableBundle *metrics) {
Adam Stone568b3c42018-01-31 12:57:16 -0800548 if (metrics == NULL) {
549 return BAD_VALUE;
550 }
Adam Stoneab394d12017-12-22 12:34:20 -0800551 Parcel data, reply;
552 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
553
554 status_t status = remote()->transact(GET_METRICS, data, &reply);
555 if (status != OK) {
556 return status;
557 }
Adam Stone568b3c42018-01-31 12:57:16 -0800558 // The reply data is ordered as
559 // 1) 32 bit integer reply followed by
560 // 2) Serialized PersistableBundle containing metrics.
561 status_t reply_status;
562 if (reply.readInt32(&reply_status) != OK
563 || reply_status != OK) {
564 ALOGE("Failed to read getMetrics response code from parcel. %d",
565 reply_status);
566 return reply_status;
567 }
Adam Stoneab394d12017-12-22 12:34:20 -0800568
Adam Stone568b3c42018-01-31 12:57:16 -0800569 status = metrics->readFromParcel(&reply);
570 if (status != OK) {
571 ALOGE("Failed to read metrics from parcel. %d", status);
572 return status;
573 }
574 return reply_status;
Adam Stoneab394d12017-12-22 12:34:20 -0800575 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800576
Jeff Tinker4c63a232013-03-30 16:19:44 -0700577 virtual status_t setCipherAlgorithm(Vector<uint8_t> const &sessionId,
578 String8 const &algorithm) {
579 Parcel data, reply;
580 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
581
582 writeVector(data, sessionId);
583 data.writeString8(algorithm);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700584 status_t status = remote()->transact(SET_CIPHER_ALGORITHM, data, &reply);
585 if (status != OK) {
586 return status;
587 }
Jeff Tinker4c63a232013-03-30 16:19:44 -0700588 return reply.readInt32();
589 }
590
591 virtual status_t setMacAlgorithm(Vector<uint8_t> const &sessionId,
592 String8 const &algorithm) {
593 Parcel data, reply;
594 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
595
596 writeVector(data, sessionId);
597 data.writeString8(algorithm);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700598 status_t status = remote()->transact(SET_MAC_ALGORITHM, data, &reply);
599 if (status != OK) {
600 return status;
601 }
Jeff Tinker4c63a232013-03-30 16:19:44 -0700602 return reply.readInt32();
603 }
604
605 virtual status_t encrypt(Vector<uint8_t> const &sessionId,
606 Vector<uint8_t> const &keyId,
607 Vector<uint8_t> const &input,
608 Vector<uint8_t> const &iv,
609 Vector<uint8_t> &output) {
610 Parcel data, reply;
611 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
612
613 writeVector(data, sessionId);
614 writeVector(data, keyId);
615 writeVector(data, input);
616 writeVector(data, iv);
617
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700618 status_t status = remote()->transact(ENCRYPT, data, &reply);
619 if (status != OK) {
620 return status;
621 }
Jeff Tinker4c63a232013-03-30 16:19:44 -0700622 readVector(reply, output);
623
624 return reply.readInt32();
625 }
626
627 virtual status_t decrypt(Vector<uint8_t> const &sessionId,
628 Vector<uint8_t> const &keyId,
629 Vector<uint8_t> const &input,
630 Vector<uint8_t> const &iv,
631 Vector<uint8_t> &output) {
632 Parcel data, reply;
633 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
634
635 writeVector(data, sessionId);
636 writeVector(data, keyId);
637 writeVector(data, input);
638 writeVector(data, iv);
639
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700640 status_t status = remote()->transact(DECRYPT, data, &reply);
641 if (status != OK) {
642 return status;
643 }
Jeff Tinker4c63a232013-03-30 16:19:44 -0700644 readVector(reply, output);
645
646 return reply.readInt32();
647 }
648
649 virtual status_t sign(Vector<uint8_t> const &sessionId,
650 Vector<uint8_t> const &keyId,
651 Vector<uint8_t> const &message,
652 Vector<uint8_t> &signature) {
653 Parcel data, reply;
654 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
655
656 writeVector(data, sessionId);
657 writeVector(data, keyId);
658 writeVector(data, message);
659
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700660 status_t status = remote()->transact(SIGN, data, &reply);
661 if (status != OK) {
662 return status;
663 }
Jeff Tinker4c63a232013-03-30 16:19:44 -0700664 readVector(reply, signature);
665
666 return reply.readInt32();
667 }
668
669 virtual status_t verify(Vector<uint8_t> const &sessionId,
670 Vector<uint8_t> const &keyId,
671 Vector<uint8_t> const &message,
672 Vector<uint8_t> const &signature,
673 bool &match) {
674 Parcel data, reply;
675 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
676
677 writeVector(data, sessionId);
678 writeVector(data, keyId);
679 writeVector(data, message);
680 writeVector(data, signature);
681
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700682 status_t status = remote()->transact(VERIFY, data, &reply);
683 if (status != OK) {
684 return status;
685 }
Jeff Tinker4c63a232013-03-30 16:19:44 -0700686 match = (bool)reply.readInt32();
687 return reply.readInt32();
688 }
689
Jeff Tinker68d9d712014-03-04 13:21:31 -0800690 virtual status_t signRSA(Vector<uint8_t> const &sessionId,
691 String8 const &algorithm,
692 Vector<uint8_t> const &message,
693 Vector<uint8_t> const &wrappedKey,
694 Vector<uint8_t> &signature) {
695 Parcel data, reply;
696 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
697
698 writeVector(data, sessionId);
699 data.writeString8(algorithm);
700 writeVector(data, message);
701 writeVector(data, wrappedKey);
702
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700703 status_t status = remote()->transact(SIGN_RSA, data, &reply);
704 if (status != OK) {
705 return status;
706 }
Jeff Tinker68d9d712014-03-04 13:21:31 -0800707 readVector(reply, signature);
708
709 return reply.readInt32();
710 }
711
Jeff Tinkerc0d5f1f2013-04-02 13:08:05 -0700712 virtual status_t setListener(const sp<IDrmClient>& listener) {
713 Parcel data, reply;
714 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
Marco Nelissen06b46062014-11-14 07:58:25 -0800715 data.writeStrongBinder(IInterface::asBinder(listener));
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700716 status_t status = remote()->transact(SET_LISTENER, data, &reply);
717 if (status != OK) {
718 return status;
719 }
Jeff Tinkerc0d5f1f2013-04-02 13:08:05 -0700720 return reply.readInt32();
721 }
722
Jeff Tinker441a78d2013-02-08 10:18:35 -0800723private:
Jeff Tinker4c63a232013-03-30 16:19:44 -0700724 void readVector(Parcel &reply, Vector<uint8_t> &vector) const {
725 uint32_t size = reply.readInt32();
726 vector.insertAt((size_t)0, size);
727 reply.read(vector.editArray(), size);
728 }
729
730 void writeVector(Parcel &data, Vector<uint8_t> const &vector) const {
731 data.writeInt32(vector.size());
732 data.write(vector.array(), vector.size());
733 }
734
Jeff Tinker441a78d2013-02-08 10:18:35 -0800735 DISALLOW_EVIL_CONSTRUCTORS(BpDrm);
736};
737
738IMPLEMENT_META_INTERFACE(Drm, "android.drm.IDrm");
739
740////////////////////////////////////////////////////////////////////////////////
741
Jeff Tinker4c63a232013-03-30 16:19:44 -0700742void BnDrm::readVector(const Parcel &data, Vector<uint8_t> &vector) const {
743 uint32_t size = data.readInt32();
Jeff Tinker3cf728e2017-10-18 20:54:26 +0000744 if (vector.insertAt((size_t)0, size) < 0) {
745 vector.clear();
746 }
747 if (data.read(vector.editArray(), size) != NO_ERROR) {
748 vector.clear();
749 android_errorWriteWithInfoLog(0x534e4554, "62872384", -1, NULL, 0);
750 }
Jeff Tinker4c63a232013-03-30 16:19:44 -0700751}
752
753void BnDrm::writeVector(Parcel *reply, Vector<uint8_t> const &vector) const {
754 reply->writeInt32(vector.size());
755 reply->write(vector.array(), vector.size());
756}
757
Jeff Tinker441a78d2013-02-08 10:18:35 -0800758status_t BnDrm::onTransact(
759 uint32_t code, const Parcel &data, Parcel *reply, uint32_t flags) {
760 switch (code) {
761 case INIT_CHECK:
762 {
763 CHECK_INTERFACE(IDrm, data, reply);
764 reply->writeInt32(initCheck());
765 return OK;
766 }
767
768 case IS_CRYPTO_SUPPORTED:
769 {
770 CHECK_INTERFACE(IDrm, data, reply);
771 uint8_t uuid[16];
772 data.read(uuid, sizeof(uuid));
Jeff Tinker9cf69e02013-08-21 11:59:23 -0700773 String8 mimeType = data.readString8();
Jeff Tinker99dbfa82019-01-17 17:27:06 -0800774 DrmPlugin::SecurityLevel level =
775 static_cast<DrmPlugin::SecurityLevel>(data.readInt32());
776 reply->writeInt32(isCryptoSchemeSupported(uuid, mimeType, level));
Jeff Tinker441a78d2013-02-08 10:18:35 -0800777 return OK;
778 }
779
780 case CREATE_PLUGIN:
781 {
782 CHECK_INTERFACE(IDrm, data, reply);
783 uint8_t uuid[16];
784 data.read(uuid, sizeof(uuid));
Edwin Wong68b3d9f2017-01-06 19:07:54 -0800785 String8 appPackageName = data.readString8();
786 reply->writeInt32(createPlugin(uuid, appPackageName));
Jeff Tinker441a78d2013-02-08 10:18:35 -0800787 return OK;
788 }
789
790 case DESTROY_PLUGIN:
791 {
792 CHECK_INTERFACE(IDrm, data, reply);
793 reply->writeInt32(destroyPlugin());
794 return OK;
795 }
796
797 case OPEN_SESSION:
798 {
799 CHECK_INTERFACE(IDrm, data, reply);
Jeff Tinker41d279a2018-02-11 19:52:08 +0000800 DrmPlugin::SecurityLevel level =
801 static_cast<DrmPlugin::SecurityLevel>(data.readInt32());
Jeff Tinker441a78d2013-02-08 10:18:35 -0800802 Vector<uint8_t> sessionId;
Jeff Tinker41d279a2018-02-11 19:52:08 +0000803 status_t result = openSession(level, sessionId);
Jeff Tinker4c63a232013-03-30 16:19:44 -0700804 writeVector(reply, sessionId);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800805 reply->writeInt32(result);
806 return OK;
807 }
808
809 case CLOSE_SESSION:
810 {
811 CHECK_INTERFACE(IDrm, data, reply);
812 Vector<uint8_t> sessionId;
Jeff Tinker4c63a232013-03-30 16:19:44 -0700813 readVector(data, sessionId);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800814 reply->writeInt32(closeSession(sessionId));
815 return OK;
816 }
817
Jeff Tinker4c63a232013-03-30 16:19:44 -0700818 case GET_KEY_REQUEST:
Jeff Tinker441a78d2013-02-08 10:18:35 -0800819 {
820 CHECK_INTERFACE(IDrm, data, reply);
Jeff Tinker4c63a232013-03-30 16:19:44 -0700821 Vector<uint8_t> sessionId, initData;
Jeff Tinker441a78d2013-02-08 10:18:35 -0800822
Jeff Tinker4c63a232013-03-30 16:19:44 -0700823 readVector(data, sessionId);
824 readVector(data, initData);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800825 String8 mimeType = data.readString8();
Jeff Tinker4c63a232013-03-30 16:19:44 -0700826 DrmPlugin::KeyType keyType = (DrmPlugin::KeyType)data.readInt32();
Jeff Tinker441a78d2013-02-08 10:18:35 -0800827
828 KeyedVector<String8, String8> optionalParameters;
829 uint32_t count = data.readInt32();
830 for (size_t i = 0; i < count; ++i) {
831 String8 key, value;
832 key = data.readString8();
833 value = data.readString8();
834 optionalParameters.add(key, value);
835 }
836
837 Vector<uint8_t> request;
838 String8 defaultUrl;
Jeff Tinker8aff7772016-02-08 17:52:25 -0800839 DrmPlugin::KeyRequestType keyRequestType = DrmPlugin::kKeyRequestType_Unknown;
Jeff Tinker441a78d2013-02-08 10:18:35 -0800840
Jeff Tinkerd072c902015-03-16 13:39:29 -0700841 status_t result = getKeyRequest(sessionId, initData, mimeType,
842 keyType, optionalParameters, request, defaultUrl,
843 &keyRequestType);
844
Jeff Tinker4c63a232013-03-30 16:19:44 -0700845 writeVector(reply, request);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800846 reply->writeString8(defaultUrl);
Jeff Tinkerd072c902015-03-16 13:39:29 -0700847 reply->writeInt32(static_cast<int32_t>(keyRequestType));
Jeff Tinker441a78d2013-02-08 10:18:35 -0800848 reply->writeInt32(result);
849 return OK;
850 }
851
Jeff Tinker4c63a232013-03-30 16:19:44 -0700852 case PROVIDE_KEY_RESPONSE:
Jeff Tinker441a78d2013-02-08 10:18:35 -0800853 {
854 CHECK_INTERFACE(IDrm, data, reply);
Jeff Tinker4c63a232013-03-30 16:19:44 -0700855 Vector<uint8_t> sessionId, response, keySetId;
856 readVector(data, sessionId);
857 readVector(data, response);
858 uint32_t result = provideKeyResponse(sessionId, response, keySetId);
859 writeVector(reply, keySetId);
860 reply->writeInt32(result);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800861 return OK;
862 }
863
Jeff Tinker4c63a232013-03-30 16:19:44 -0700864 case REMOVE_KEYS:
Jeff Tinker441a78d2013-02-08 10:18:35 -0800865 {
866 CHECK_INTERFACE(IDrm, data, reply);
Jeff Tinker4c63a232013-03-30 16:19:44 -0700867 Vector<uint8_t> keySetId;
868 readVector(data, keySetId);
869 reply->writeInt32(removeKeys(keySetId));
Jeff Tinker441a78d2013-02-08 10:18:35 -0800870 return OK;
871 }
872
Jeff Tinker4c63a232013-03-30 16:19:44 -0700873 case RESTORE_KEYS:
874 {
875 CHECK_INTERFACE(IDrm, data, reply);
876 Vector<uint8_t> sessionId, keySetId;
877 readVector(data, sessionId);
878 readVector(data, keySetId);
879 reply->writeInt32(restoreKeys(sessionId, keySetId));
880 return OK;
881 }
882
883 case QUERY_KEY_STATUS:
Jeff Tinker441a78d2013-02-08 10:18:35 -0800884 {
885 CHECK_INTERFACE(IDrm, data, reply);
886 Vector<uint8_t> sessionId;
Jeff Tinker4c63a232013-03-30 16:19:44 -0700887 readVector(data, sessionId);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800888 KeyedVector<String8, String8> infoMap;
Jeff Tinker4c63a232013-03-30 16:19:44 -0700889 status_t result = queryKeyStatus(sessionId, infoMap);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800890 size_t count = infoMap.size();
891 reply->writeInt32(count);
892 for (size_t i = 0; i < count; ++i) {
893 reply->writeString8(infoMap.keyAt(i));
894 reply->writeString8(infoMap.valueAt(i));
895 }
896 reply->writeInt32(result);
897 return OK;
898 }
899
900 case GET_PROVISION_REQUEST:
901 {
902 CHECK_INTERFACE(IDrm, data, reply);
Jeff Tinker68d9d712014-03-04 13:21:31 -0800903 String8 certType = data.readString8();
904 String8 certAuthority = data.readString8();
905
Jeff Tinker441a78d2013-02-08 10:18:35 -0800906 Vector<uint8_t> request;
907 String8 defaultUrl;
Jeff Tinker68d9d712014-03-04 13:21:31 -0800908 status_t result = getProvisionRequest(certType, certAuthority,
909 request, defaultUrl);
Jeff Tinker4c63a232013-03-30 16:19:44 -0700910 writeVector(reply, request);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800911 reply->writeString8(defaultUrl);
912 reply->writeInt32(result);
913 return OK;
914 }
915
916 case PROVIDE_PROVISION_RESPONSE:
917 {
918 CHECK_INTERFACE(IDrm, data, reply);
919 Vector<uint8_t> response;
Jeff Tinker68d9d712014-03-04 13:21:31 -0800920 Vector<uint8_t> certificate;
921 Vector<uint8_t> wrappedKey;
Jeff Tinker4c63a232013-03-30 16:19:44 -0700922 readVector(data, response);
Jeff Tinker68d9d712014-03-04 13:21:31 -0800923 status_t result = provideProvisionResponse(response, certificate, wrappedKey);
924 writeVector(reply, certificate);
925 writeVector(reply, wrappedKey);
926 reply->writeInt32(result);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800927 return OK;
928 }
929
930 case GET_SECURE_STOPS:
931 {
932 CHECK_INTERFACE(IDrm, data, reply);
933 List<Vector<uint8_t> > secureStops;
934 status_t result = getSecureStops(secureStops);
935 size_t count = secureStops.size();
936 reply->writeInt32(count);
937 List<Vector<uint8_t> >::iterator iter = secureStops.begin();
938 while(iter != secureStops.end()) {
939 size_t size = iter->size();
940 reply->writeInt32(size);
941 reply->write(iter->array(), iter->size());
Jeff Tinker423e33c2013-04-08 15:23:17 -0700942 iter++;
Jeff Tinker441a78d2013-02-08 10:18:35 -0800943 }
944 reply->writeInt32(result);
945 return OK;
946 }
947
Jeff Tinker15177d72018-01-25 12:57:55 -0800948 case GET_SECURE_STOP_IDS:
949 {
950 CHECK_INTERFACE(IDrm, data, reply);
951 List<Vector<uint8_t> > secureStopIds;
952 status_t result = getSecureStopIds(secureStopIds);
953 size_t count = secureStopIds.size();
954 reply->writeInt32(count);
955 List<Vector<uint8_t> >::iterator iter = secureStopIds.begin();
956 while(iter != secureStopIds.end()) {
957 size_t size = iter->size();
958 reply->writeInt32(size);
959 reply->write(iter->array(), iter->size());
960 iter++;
961 }
962 reply->writeInt32(result);
963 return OK;
964 }
965
Jeff Tinker3c1285e2014-10-31 00:55:16 -0700966 case GET_SECURE_STOP:
967 {
968 CHECK_INTERFACE(IDrm, data, reply);
969 Vector<uint8_t> ssid, secureStop;
970 readVector(data, ssid);
971 status_t result = getSecureStop(ssid, secureStop);
972 writeVector(reply, secureStop);
973 reply->writeInt32(result);
974 return OK;
975 }
976
Jeff Tinker441a78d2013-02-08 10:18:35 -0800977 case RELEASE_SECURE_STOPS:
978 {
979 CHECK_INTERFACE(IDrm, data, reply);
980 Vector<uint8_t> ssRelease;
Jeff Tinker4c63a232013-03-30 16:19:44 -0700981 readVector(data, ssRelease);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800982 reply->writeInt32(releaseSecureStops(ssRelease));
983 return OK;
984 }
985
Jeff Tinker15177d72018-01-25 12:57:55 -0800986 case REMOVE_SECURE_STOP:
Jeff Tinker3c1285e2014-10-31 00:55:16 -0700987 {
988 CHECK_INTERFACE(IDrm, data, reply);
Jeff Tinker15177d72018-01-25 12:57:55 -0800989 Vector<uint8_t> ssid;
990 readVector(data, ssid);
991 reply->writeInt32(removeSecureStop(ssid));
992 return OK;
993 }
994
995 case REMOVE_ALL_SECURE_STOPS:
996 {
997 CHECK_INTERFACE(IDrm, data, reply);
998 reply->writeInt32(removeAllSecureStops());
Jeff Tinker3c1285e2014-10-31 00:55:16 -0700999 return OK;
1000 }
1001
Jeff Tinker6d998b62017-12-18 14:37:43 -08001002 case GET_HDCP_LEVELS:
1003 {
1004 CHECK_INTERFACE(IDrm, data, reply);
1005 DrmPlugin::HdcpLevel connected = DrmPlugin::kHdcpLevelUnknown;
1006 DrmPlugin::HdcpLevel max = DrmPlugin::kHdcpLevelUnknown;
1007 status_t result = getHdcpLevels(&connected, &max);
1008 reply->writeInt32(connected);
1009 reply->writeInt32(max);
1010 reply->writeInt32(result);
1011 return OK;
1012 }
1013
1014 case GET_NUMBER_OF_SESSIONS:
1015 {
1016 CHECK_INTERFACE(IDrm, data, reply);
1017 uint32_t open = 0, max = 0;
1018 status_t result = getNumberOfSessions(&open, &max);
1019 reply->writeInt32(open);
1020 reply->writeInt32(max);
1021 reply->writeInt32(result);
1022 return OK;
1023 }
1024
1025 case GET_SECURITY_LEVEL:
1026 {
1027 CHECK_INTERFACE(IDrm, data, reply);
1028 Vector<uint8_t> sessionId;
1029 readVector(data, sessionId);
1030 DrmPlugin::SecurityLevel level = DrmPlugin::kSecurityLevelUnknown;
1031 status_t result = getSecurityLevel(sessionId, &level);
1032 reply->writeInt32(level);
1033 reply->writeInt32(result);
1034 return OK;
1035 }
1036
Jeff Tinkerc8baaba2018-10-23 11:32:36 -07001037 case GET_OFFLINE_LICENSE_KEYSET_IDS:
1038 {
1039 CHECK_INTERFACE(IDrm, data, reply);
1040 List<Vector<uint8_t> > keySetIds;
1041 status_t result = getOfflineLicenseKeySetIds(keySetIds);
1042 size_t count = keySetIds.size();
1043 reply->writeInt32(count);
1044 List<Vector<uint8_t> >::iterator iter = keySetIds.begin();
1045 while(iter != keySetIds.end()) {
1046 size_t size = iter->size();
1047 reply->writeInt32(size);
1048 reply->write(iter->array(), iter->size());
1049 iter++;
1050 }
1051 reply->writeInt32(result);
1052 return OK;
1053 }
1054
1055 case REMOVE_OFFLINE_LICENSE:
1056 {
1057 CHECK_INTERFACE(IDrm, data, reply);
1058 Vector<uint8_t> keySetId;
1059 readVector(data, keySetId);
1060 reply->writeInt32(removeOfflineLicense(keySetId));
1061 return OK;
1062 }
1063
1064 case GET_OFFLINE_LICENSE_STATE:
1065 {
1066 CHECK_INTERFACE(IDrm, data, reply);
1067 Vector<uint8_t> keySetId;
1068 readVector(data, keySetId);
1069 DrmPlugin::OfflineLicenseState state;
1070 status_t result = getOfflineLicenseState(keySetId, &state);
1071 reply->writeInt32(static_cast<DrmPlugin::OfflineLicenseState>(state));
1072 reply->writeInt32(result);
1073 return OK;
1074 }
1075
Jeff Tinker441a78d2013-02-08 10:18:35 -08001076 case GET_PROPERTY_STRING:
1077 {
1078 CHECK_INTERFACE(IDrm, data, reply);
1079 String8 name = data.readString8();
1080 String8 value;
1081 status_t result = getPropertyString(name, value);
1082 reply->writeString8(value);
1083 reply->writeInt32(result);
1084 return OK;
1085 }
1086
1087 case GET_PROPERTY_BYTE_ARRAY:
1088 {
1089 CHECK_INTERFACE(IDrm, data, reply);
1090 String8 name = data.readString8();
1091 Vector<uint8_t> value;
1092 status_t result = getPropertyByteArray(name, value);
Jeff Tinker4c63a232013-03-30 16:19:44 -07001093 writeVector(reply, value);
Jeff Tinker441a78d2013-02-08 10:18:35 -08001094 reply->writeInt32(result);
1095 return OK;
1096 }
1097
1098 case SET_PROPERTY_STRING:
1099 {
1100 CHECK_INTERFACE(IDrm, data, reply);
1101 String8 name = data.readString8();
1102 String8 value = data.readString8();
1103 reply->writeInt32(setPropertyString(name, value));
1104 return OK;
1105 }
1106
1107 case SET_PROPERTY_BYTE_ARRAY:
1108 {
1109 CHECK_INTERFACE(IDrm, data, reply);
1110 String8 name = data.readString8();
1111 Vector<uint8_t> value;
Jeff Tinker4c63a232013-03-30 16:19:44 -07001112 readVector(data, value);
Jeff Tinker441a78d2013-02-08 10:18:35 -08001113 reply->writeInt32(setPropertyByteArray(name, value));
1114 return OK;
1115 }
1116
Adam Stoneab394d12017-12-22 12:34:20 -08001117 case GET_METRICS:
1118 {
1119 CHECK_INTERFACE(IDrm, data, reply);
1120
Adam Stone637b7852018-01-30 12:09:36 -08001121 os::PersistableBundle metrics;
1122 status_t result = getMetrics(&metrics);
Adam Stone568b3c42018-01-31 12:57:16 -08001123 // The reply data is ordered as
1124 // 1) 32 bit integer reply followed by
1125 // 2) Serialized PersistableBundle containing metrics.
1126 // Only write the metrics if the getMetrics result was
1127 // OK and we successfully added the status to reply.
1128 status_t parcel_result = reply->writeInt32(result);
1129 if (result == OK && parcel_result == OK) {
1130 parcel_result = metrics.writeToParcel(reply);
1131 }
1132 return parcel_result;
Adam Stoneab394d12017-12-22 12:34:20 -08001133 }
1134
Jeff Tinker4c63a232013-03-30 16:19:44 -07001135 case SET_CIPHER_ALGORITHM:
1136 {
1137 CHECK_INTERFACE(IDrm, data, reply);
1138 Vector<uint8_t> sessionId;
1139 readVector(data, sessionId);
1140 String8 algorithm = data.readString8();
1141 reply->writeInt32(setCipherAlgorithm(sessionId, algorithm));
1142 return OK;
1143 }
1144
1145 case SET_MAC_ALGORITHM:
1146 {
1147 CHECK_INTERFACE(IDrm, data, reply);
1148 Vector<uint8_t> sessionId;
1149 readVector(data, sessionId);
1150 String8 algorithm = data.readString8();
1151 reply->writeInt32(setMacAlgorithm(sessionId, algorithm));
1152 return OK;
1153 }
1154
1155 case ENCRYPT:
1156 {
1157 CHECK_INTERFACE(IDrm, data, reply);
1158 Vector<uint8_t> sessionId, keyId, input, iv, output;
1159 readVector(data, sessionId);
1160 readVector(data, keyId);
1161 readVector(data, input);
1162 readVector(data, iv);
1163 uint32_t result = encrypt(sessionId, keyId, input, iv, output);
1164 writeVector(reply, output);
1165 reply->writeInt32(result);
1166 return OK;
1167 }
1168
1169 case DECRYPT:
1170 {
1171 CHECK_INTERFACE(IDrm, data, reply);
1172 Vector<uint8_t> sessionId, keyId, input, iv, output;
1173 readVector(data, sessionId);
1174 readVector(data, keyId);
1175 readVector(data, input);
1176 readVector(data, iv);
1177 uint32_t result = decrypt(sessionId, keyId, input, iv, output);
1178 writeVector(reply, output);
1179 reply->writeInt32(result);
1180 return OK;
1181 }
1182
1183 case SIGN:
1184 {
1185 CHECK_INTERFACE(IDrm, data, reply);
1186 Vector<uint8_t> sessionId, keyId, message, signature;
1187 readVector(data, sessionId);
1188 readVector(data, keyId);
1189 readVector(data, message);
1190 uint32_t result = sign(sessionId, keyId, message, signature);
1191 writeVector(reply, signature);
1192 reply->writeInt32(result);
1193 return OK;
1194 }
1195
1196 case VERIFY:
1197 {
1198 CHECK_INTERFACE(IDrm, data, reply);
1199 Vector<uint8_t> sessionId, keyId, message, signature;
1200 readVector(data, sessionId);
1201 readVector(data, keyId);
1202 readVector(data, message);
1203 readVector(data, signature);
Jeff Tinker9a6861c2016-09-02 11:36:46 -07001204 bool match = false;
Jeff Tinker4c63a232013-03-30 16:19:44 -07001205 uint32_t result = verify(sessionId, keyId, message, signature, match);
1206 reply->writeInt32(match);
1207 reply->writeInt32(result);
1208 return OK;
1209 }
1210
Jeff Tinker68d9d712014-03-04 13:21:31 -08001211 case SIGN_RSA:
1212 {
1213 CHECK_INTERFACE(IDrm, data, reply);
1214 Vector<uint8_t> sessionId, message, wrappedKey, signature;
1215 readVector(data, sessionId);
1216 String8 algorithm = data.readString8();
1217 readVector(data, message);
1218 readVector(data, wrappedKey);
1219 uint32_t result = signRSA(sessionId, algorithm, message, wrappedKey, signature);
1220 writeVector(reply, signature);
1221 reply->writeInt32(result);
1222 return OK;
1223 }
1224
Jeff Tinkerc0d5f1f2013-04-02 13:08:05 -07001225 case SET_LISTENER: {
1226 CHECK_INTERFACE(IDrm, data, reply);
1227 sp<IDrmClient> listener =
1228 interface_cast<IDrmClient>(data.readStrongBinder());
1229 reply->writeInt32(setListener(listener));
1230 return NO_ERROR;
1231 } break;
1232
Jeff Tinker4c63a232013-03-30 16:19:44 -07001233 default:
1234 return BBinder::onTransact(code, data, reply, flags);
Jeff Tinker441a78d2013-02-08 10:18:35 -08001235 }
1236}
1237
1238} // namespace android