blob: 8c26317128332928cc4b2ae699544b0434e5e102 [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 Tinker9cf69e02013-08-21 11:59:23 -070086 virtual bool isCryptoSchemeSupported(const uint8_t uuid[16], const String8 &mimeType) {
Jeff Tinker441a78d2013-02-08 10:18:35 -080087 Parcel data, reply;
88 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
89 data.write(uuid, 16);
Jeff Tinker9cf69e02013-08-21 11:59:23 -070090 data.writeString8(mimeType);
Jeff Tinker3b5401a2015-06-15 17:42:10 -070091 status_t status = remote()->transact(IS_CRYPTO_SUPPORTED, data, &reply);
92 if (status != OK) {
93 ALOGE("isCryptoSchemeSupported: binder call failed: %d", status);
94 return false;
95 }
Jeff Tinker441a78d2013-02-08 10:18:35 -080096
97 return reply.readInt32() != 0;
98 }
99
Edwin Wong68b3d9f2017-01-06 19:07:54 -0800100 virtual status_t createPlugin(const uint8_t uuid[16],
101 const String8& appPackageName) {
Jeff Tinker441a78d2013-02-08 10:18:35 -0800102 Parcel data, reply;
103 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
104 data.write(uuid, 16);
Edwin Wong68b3d9f2017-01-06 19:07:54 -0800105 data.writeString8(appPackageName);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700106 status_t status = remote()->transact(CREATE_PLUGIN, data, &reply);
107 if (status != OK) {
Edwin Wong68b3d9f2017-01-06 19:07:54 -0800108 ALOGE("createPlugin: binder call failed: %d", status);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700109 return status;
110 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800111
112 return reply.readInt32();
113 }
114
115 virtual status_t destroyPlugin() {
116 Parcel data, reply;
117 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700118 status_t status = remote()->transact(DESTROY_PLUGIN, data, &reply);
119 if (status != OK) {
120 return status;
121 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800122
123 return reply.readInt32();
124 }
125
Jeff Tinker41d279a2018-02-11 19:52:08 +0000126 virtual status_t openSession(DrmPlugin::SecurityLevel securityLevel,
127 Vector<uint8_t> &sessionId) {
Jeff Tinker441a78d2013-02-08 10:18:35 -0800128 Parcel data, reply;
129 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
Jeff Tinker41d279a2018-02-11 19:52:08 +0000130 data.writeInt32(securityLevel);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800131
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700132 status_t status = remote()->transact(OPEN_SESSION, data, &reply);
133 if (status != OK) {
134 return status;
135 }
Jeff Tinker4c63a232013-03-30 16:19:44 -0700136 readVector(reply, sessionId);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800137
138 return reply.readInt32();
139 }
140
141 virtual status_t closeSession(Vector<uint8_t> const &sessionId) {
142 Parcel data, reply;
143 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
144
Jeff Tinker4c63a232013-03-30 16:19:44 -0700145 writeVector(data, sessionId);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700146 status_t status = remote()->transact(CLOSE_SESSION, data, &reply);
147 if (status != OK) {
148 return status;
149 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800150
151 return reply.readInt32();
152 }
153
154 virtual status_t
Jeff Tinker4c63a232013-03-30 16:19:44 -0700155 getKeyRequest(Vector<uint8_t> const &sessionId,
156 Vector<uint8_t> const &initData,
157 String8 const &mimeType, DrmPlugin::KeyType keyType,
158 KeyedVector<String8, String8> const &optionalParameters,
Jeff Tinkerd072c902015-03-16 13:39:29 -0700159 Vector<uint8_t> &request, String8 &defaultUrl,
160 DrmPlugin::KeyRequestType *keyRequestType) {
Jeff Tinker441a78d2013-02-08 10:18:35 -0800161 Parcel data, reply;
162 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
163
Jeff Tinker4c63a232013-03-30 16:19:44 -0700164 writeVector(data, sessionId);
165 writeVector(data, initData);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800166 data.writeString8(mimeType);
Jeff Tinker4c63a232013-03-30 16:19:44 -0700167 data.writeInt32((uint32_t)keyType);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800168
169 data.writeInt32(optionalParameters.size());
170 for (size_t i = 0; i < optionalParameters.size(); ++i) {
171 data.writeString8(optionalParameters.keyAt(i));
172 data.writeString8(optionalParameters.valueAt(i));
173 }
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700174
175 status_t status = remote()->transact(GET_KEY_REQUEST, data, &reply);
176 if (status != OK) {
177 return status;
178 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800179
Jeff Tinker4c63a232013-03-30 16:19:44 -0700180 readVector(reply, request);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800181 defaultUrl = reply.readString8();
Jeff Tinkerd072c902015-03-16 13:39:29 -0700182 *keyRequestType = static_cast<DrmPlugin::KeyRequestType>(reply.readInt32());
Jeff Tinker441a78d2013-02-08 10:18:35 -0800183
184 return reply.readInt32();
185 }
186
Jeff Tinker4c63a232013-03-30 16:19:44 -0700187 virtual status_t provideKeyResponse(Vector<uint8_t> const &sessionId,
188 Vector<uint8_t> const &response,
189 Vector<uint8_t> &keySetId) {
Jeff Tinker441a78d2013-02-08 10:18:35 -0800190 Parcel data, reply;
191 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
Jeff Tinker4c63a232013-03-30 16:19:44 -0700192 writeVector(data, sessionId);
193 writeVector(data, response);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700194
195 status_t status = remote()->transact(PROVIDE_KEY_RESPONSE, data, &reply);
196 if (status != OK) {
197 return status;
198 }
199
Jeff Tinker4c63a232013-03-30 16:19:44 -0700200 readVector(reply, keySetId);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800201
202 return reply.readInt32();
203 }
204
Jeff Tinker4c63a232013-03-30 16:19:44 -0700205 virtual status_t removeKeys(Vector<uint8_t> const &keySetId) {
Jeff Tinker441a78d2013-02-08 10:18:35 -0800206 Parcel data, reply;
207 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
208
Jeff Tinker4c63a232013-03-30 16:19:44 -0700209 writeVector(data, keySetId);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700210 status_t status = remote()->transact(REMOVE_KEYS, data, &reply);
211 if (status != OK) {
212 return status;
213 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800214
215 return reply.readInt32();
216 }
217
Jeff Tinker4c63a232013-03-30 16:19:44 -0700218 virtual status_t restoreKeys(Vector<uint8_t> const &sessionId,
219 Vector<uint8_t> const &keySetId) {
220 Parcel data, reply;
221 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
222
223 writeVector(data, sessionId);
224 writeVector(data, keySetId);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700225 status_t status = remote()->transact(RESTORE_KEYS, data, &reply);
226 if (status != OK) {
227 return status;
228 }
Jeff Tinker4c63a232013-03-30 16:19:44 -0700229
230 return reply.readInt32();
231 }
232
233 virtual status_t queryKeyStatus(Vector<uint8_t> const &sessionId,
Jeff Tinker441a78d2013-02-08 10:18:35 -0800234 KeyedVector<String8, String8> &infoMap) const {
235 Parcel data, reply;
236 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
237
Jeff Tinker4c63a232013-03-30 16:19:44 -0700238 writeVector(data, sessionId);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700239 status_t status = remote()->transact(QUERY_KEY_STATUS, data, &reply);
240 if (status != OK) {
241 return status;
242 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800243
244 infoMap.clear();
245 size_t count = reply.readInt32();
246 for (size_t i = 0; i < count; i++) {
247 String8 key = reply.readString8();
248 String8 value = reply.readString8();
249 infoMap.add(key, value);
250 }
251 return reply.readInt32();
252 }
253
Jeff Tinker68d9d712014-03-04 13:21:31 -0800254 virtual status_t getProvisionRequest(String8 const &certType,
255 String8 const &certAuthority,
256 Vector<uint8_t> &request,
Jeff Tinker441a78d2013-02-08 10:18:35 -0800257 String8 &defaultUrl) {
258 Parcel data, reply;
259 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
260
Jeff Tinker68d9d712014-03-04 13:21:31 -0800261 data.writeString8(certType);
262 data.writeString8(certAuthority);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700263 status_t status = remote()->transact(GET_PROVISION_REQUEST, data, &reply);
264 if (status != OK) {
265 return status;
266 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800267
Jeff Tinker4c63a232013-03-30 16:19:44 -0700268 readVector(reply, request);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800269 defaultUrl = reply.readString8();
270
271 return reply.readInt32();
272 }
273
Jeff Tinker68d9d712014-03-04 13:21:31 -0800274 virtual status_t provideProvisionResponse(Vector<uint8_t> const &response,
275 Vector<uint8_t> &certificate,
276 Vector<uint8_t> &wrappedKey) {
Jeff Tinker441a78d2013-02-08 10:18:35 -0800277 Parcel data, reply;
278 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
279
Jeff Tinker4c63a232013-03-30 16:19:44 -0700280 writeVector(data, response);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700281 status_t status = remote()->transact(PROVIDE_PROVISION_RESPONSE, data, &reply);
282 if (status != OK) {
283 return status;
284 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800285
Jeff Tinker68d9d712014-03-04 13:21:31 -0800286 readVector(reply, certificate);
287 readVector(reply, wrappedKey);
288
Jeff Tinker441a78d2013-02-08 10:18:35 -0800289 return reply.readInt32();
290 }
291
292 virtual status_t getSecureStops(List<Vector<uint8_t> > &secureStops) {
293 Parcel data, reply;
294 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
295
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700296 status_t status = remote()->transact(GET_SECURE_STOPS, data, &reply);
297 if (status != OK) {
298 return status;
299 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800300
301 secureStops.clear();
302 uint32_t count = reply.readInt32();
303 for (size_t i = 0; i < count; i++) {
304 Vector<uint8_t> secureStop;
Jeff Tinker4c63a232013-03-30 16:19:44 -0700305 readVector(reply, secureStop);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800306 secureStops.push_back(secureStop);
307 }
308 return reply.readInt32();
309 }
310
Jeff Tinker15177d72018-01-25 12:57:55 -0800311 virtual status_t getSecureStopIds(List<Vector<uint8_t> > &secureStopIds) {
312 Parcel data, reply;
313 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
314
315 status_t status = remote()->transact(GET_SECURE_STOP_IDS, data, &reply);
316 if (status != OK) {
317 return status;
318 }
319
320 secureStopIds.clear();
321 uint32_t count = reply.readInt32();
322 for (size_t i = 0; i < count; i++) {
323 Vector<uint8_t> secureStopId;
324 readVector(reply, secureStopId);
325 secureStopIds.push_back(secureStopId);
326 }
327 return reply.readInt32();
328 }
329
Jeff Tinker3c1285e2014-10-31 00:55:16 -0700330 virtual status_t getSecureStop(Vector<uint8_t> const &ssid, Vector<uint8_t> &secureStop) {
331 Parcel data, reply;
332 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
333
334 writeVector(data, ssid);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700335 status_t status = remote()->transact(GET_SECURE_STOP, data, &reply);
336 if (status != OK) {
337 return status;
338 }
Jeff Tinker3c1285e2014-10-31 00:55:16 -0700339
340 readVector(reply, secureStop);
341 return reply.readInt32();
342 }
343
Jeff Tinker441a78d2013-02-08 10:18:35 -0800344 virtual status_t releaseSecureStops(Vector<uint8_t> const &ssRelease) {
345 Parcel data, reply;
346 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
347
Jeff Tinker4c63a232013-03-30 16:19:44 -0700348 writeVector(data, ssRelease);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700349 status_t status = remote()->transact(RELEASE_SECURE_STOPS, data, &reply);
350 if (status != OK) {
351 return status;
352 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800353
354 return reply.readInt32();
355 }
356
Jeff Tinker15177d72018-01-25 12:57:55 -0800357 virtual status_t removeSecureStop(Vector<uint8_t> const &ssid) {
Jeff Tinker3c1285e2014-10-31 00:55:16 -0700358 Parcel data, reply;
359 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
360
Jeff Tinker15177d72018-01-25 12:57:55 -0800361 writeVector(data, ssid);
362 status_t status = remote()->transact(REMOVE_SECURE_STOP, data, &reply);
363 if (status != OK) {
364 return status;
365 }
366
367 return reply.readInt32();
368 }
369
370 virtual status_t removeAllSecureStops() {
371 Parcel data, reply;
372 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
373
374 status_t status = remote()->transact(REMOVE_ALL_SECURE_STOPS, data, &reply);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700375 if (status != OK) {
376 return status;
377 }
Jeff Tinker3c1285e2014-10-31 00:55:16 -0700378
379 return reply.readInt32();
380 }
381
Jeff Tinkerc8baaba2018-10-23 11:32:36 -0700382 virtual status_t getOfflineLicenseKeySetIds(List<Vector<uint8_t> > &keySetIds) const {
383 Parcel data, reply;
384 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
385
386 status_t status = remote()->transact(GET_OFFLINE_LICENSE_KEYSET_IDS, data, &reply);
387 if (status != OK) {
388 return status;
389 }
390
391 keySetIds.clear();
392 uint32_t count = reply.readInt32();
393 for (size_t i = 0; i < count; i++) {
394 Vector<uint8_t> keySetId;
395 readVector(reply, keySetId);
396 keySetIds.push_back(keySetId);
397 }
398 return reply.readInt32();
399 }
400
401 virtual status_t removeOfflineLicense(Vector<uint8_t> const &keySetId) {
402 Parcel data, reply;
403 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
404
405 writeVector(data, keySetId);
406 status_t status = remote()->transact(REMOVE_OFFLINE_LICENSE, data, &reply);
407 if (status != OK) {
408 return status;
409 }
410 return reply.readInt32();
411 }
412
413 virtual status_t getOfflineLicenseState(Vector<uint8_t> const &keySetId,
414 DrmPlugin::OfflineLicenseState *licenseState) const {
415 Parcel data, reply;
416 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
417
418 writeVector(data, keySetId);
419 status_t status = remote()->transact(GET_OFFLINE_LICENSE_STATE, data, &reply);
420 if (status != OK) {
421 *licenseState = DrmPlugin::OfflineLicenseState::kOfflineLicenseStateUnknown;
422 return status;
423 }
424 *licenseState = static_cast<DrmPlugin::OfflineLicenseState>(reply.readInt32());
425 return reply.readInt32();
426 }
427
Jeff Tinker441a78d2013-02-08 10:18:35 -0800428 virtual status_t getPropertyString(String8 const &name, String8 &value) const {
429 Parcel data, reply;
430 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
431
432 data.writeString8(name);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700433 status_t status = remote()->transact(GET_PROPERTY_STRING, data, &reply);
434 if (status != OK) {
435 return status;
436 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800437
438 value = reply.readString8();
439 return reply.readInt32();
440 }
441
Jeff Tinker6d998b62017-12-18 14:37:43 -0800442 virtual status_t getHdcpLevels(DrmPlugin::HdcpLevel *connected,
443 DrmPlugin::HdcpLevel *max) const {
444 Parcel data, reply;
445
446 if (connected == NULL || max == NULL) {
447 return BAD_VALUE;
448 }
449
450 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
451
452 status_t status = remote()->transact(GET_HDCP_LEVELS, data, &reply);
453 if (status != OK) {
454 return status;
455 }
456
457 *connected = static_cast<DrmPlugin::HdcpLevel>(reply.readInt32());
458 *max = static_cast<DrmPlugin::HdcpLevel>(reply.readInt32());
459 return reply.readInt32();
460 }
461
462 virtual status_t getNumberOfSessions(uint32_t *open, uint32_t *max) const {
463 Parcel data, reply;
464
465 if (open == NULL || max == NULL) {
466 return BAD_VALUE;
467 }
468
469 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
470
471 status_t status = remote()->transact(GET_NUMBER_OF_SESSIONS, data, &reply);
472 if (status != OK) {
473 return status;
474 }
475
476 *open = reply.readInt32();
477 *max = reply.readInt32();
478 return reply.readInt32();
479 }
480
481 virtual status_t getSecurityLevel(Vector<uint8_t> const &sessionId,
482 DrmPlugin::SecurityLevel *level) const {
483 Parcel data, reply;
484
485 if (level == NULL) {
486 return BAD_VALUE;
487 }
488
489 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
490
491 writeVector(data, sessionId);
492 status_t status = remote()->transact(GET_SECURITY_LEVEL, data, &reply);
493 if (status != OK) {
494 return status;
495 }
496
497 *level = static_cast<DrmPlugin::SecurityLevel>(reply.readInt32());
498 return reply.readInt32();
499 }
500
Jeff Tinker441a78d2013-02-08 10:18:35 -0800501 virtual status_t getPropertyByteArray(String8 const &name, Vector<uint8_t> &value) const {
502 Parcel data, reply;
503 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
504
505 data.writeString8(name);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700506 status_t status = remote()->transact(GET_PROPERTY_BYTE_ARRAY, data, &reply);
507 if (status != OK) {
508 return status;
509 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800510
Jeff Tinker4c63a232013-03-30 16:19:44 -0700511 readVector(reply, value);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800512 return reply.readInt32();
513 }
514
515 virtual status_t setPropertyString(String8 const &name, String8 const &value) const {
516 Parcel data, reply;
517 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
518
519 data.writeString8(name);
520 data.writeString8(value);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700521 status_t status = remote()->transact(SET_PROPERTY_STRING, data, &reply);
522 if (status != OK) {
523 return status;
524 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800525
526 return reply.readInt32();
527 }
528
529 virtual status_t setPropertyByteArray(String8 const &name,
530 Vector<uint8_t> const &value) const {
531 Parcel data, reply;
532 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
533
534 data.writeString8(name);
Jeff Tinker4c63a232013-03-30 16:19:44 -0700535 writeVector(data, value);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700536 status_t status = remote()->transact(SET_PROPERTY_BYTE_ARRAY, data, &reply);
537 if (status != OK) {
538 return status;
539 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800540
541 return reply.readInt32();
542 }
543
Adam Stone637b7852018-01-30 12:09:36 -0800544 virtual status_t getMetrics(os::PersistableBundle *metrics) {
Adam Stone568b3c42018-01-31 12:57:16 -0800545 if (metrics == NULL) {
546 return BAD_VALUE;
547 }
Adam Stoneab394d12017-12-22 12:34:20 -0800548 Parcel data, reply;
549 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
550
551 status_t status = remote()->transact(GET_METRICS, data, &reply);
552 if (status != OK) {
553 return status;
554 }
Adam Stone568b3c42018-01-31 12:57:16 -0800555 // The reply data is ordered as
556 // 1) 32 bit integer reply followed by
557 // 2) Serialized PersistableBundle containing metrics.
558 status_t reply_status;
559 if (reply.readInt32(&reply_status) != OK
560 || reply_status != OK) {
561 ALOGE("Failed to read getMetrics response code from parcel. %d",
562 reply_status);
563 return reply_status;
564 }
Adam Stoneab394d12017-12-22 12:34:20 -0800565
Adam Stone568b3c42018-01-31 12:57:16 -0800566 status = metrics->readFromParcel(&reply);
567 if (status != OK) {
568 ALOGE("Failed to read metrics from parcel. %d", status);
569 return status;
570 }
571 return reply_status;
Adam Stoneab394d12017-12-22 12:34:20 -0800572 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800573
Jeff Tinker4c63a232013-03-30 16:19:44 -0700574 virtual status_t setCipherAlgorithm(Vector<uint8_t> const &sessionId,
575 String8 const &algorithm) {
576 Parcel data, reply;
577 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
578
579 writeVector(data, sessionId);
580 data.writeString8(algorithm);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700581 status_t status = remote()->transact(SET_CIPHER_ALGORITHM, data, &reply);
582 if (status != OK) {
583 return status;
584 }
Jeff Tinker4c63a232013-03-30 16:19:44 -0700585 return reply.readInt32();
586 }
587
588 virtual status_t setMacAlgorithm(Vector<uint8_t> const &sessionId,
589 String8 const &algorithm) {
590 Parcel data, reply;
591 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
592
593 writeVector(data, sessionId);
594 data.writeString8(algorithm);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700595 status_t status = remote()->transact(SET_MAC_ALGORITHM, data, &reply);
596 if (status != OK) {
597 return status;
598 }
Jeff Tinker4c63a232013-03-30 16:19:44 -0700599 return reply.readInt32();
600 }
601
602 virtual status_t encrypt(Vector<uint8_t> const &sessionId,
603 Vector<uint8_t> const &keyId,
604 Vector<uint8_t> const &input,
605 Vector<uint8_t> const &iv,
606 Vector<uint8_t> &output) {
607 Parcel data, reply;
608 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
609
610 writeVector(data, sessionId);
611 writeVector(data, keyId);
612 writeVector(data, input);
613 writeVector(data, iv);
614
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700615 status_t status = remote()->transact(ENCRYPT, data, &reply);
616 if (status != OK) {
617 return status;
618 }
Jeff Tinker4c63a232013-03-30 16:19:44 -0700619 readVector(reply, output);
620
621 return reply.readInt32();
622 }
623
624 virtual status_t decrypt(Vector<uint8_t> const &sessionId,
625 Vector<uint8_t> const &keyId,
626 Vector<uint8_t> const &input,
627 Vector<uint8_t> const &iv,
628 Vector<uint8_t> &output) {
629 Parcel data, reply;
630 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
631
632 writeVector(data, sessionId);
633 writeVector(data, keyId);
634 writeVector(data, input);
635 writeVector(data, iv);
636
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700637 status_t status = remote()->transact(DECRYPT, data, &reply);
638 if (status != OK) {
639 return status;
640 }
Jeff Tinker4c63a232013-03-30 16:19:44 -0700641 readVector(reply, output);
642
643 return reply.readInt32();
644 }
645
646 virtual status_t sign(Vector<uint8_t> const &sessionId,
647 Vector<uint8_t> const &keyId,
648 Vector<uint8_t> const &message,
649 Vector<uint8_t> &signature) {
650 Parcel data, reply;
651 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
652
653 writeVector(data, sessionId);
654 writeVector(data, keyId);
655 writeVector(data, message);
656
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700657 status_t status = remote()->transact(SIGN, data, &reply);
658 if (status != OK) {
659 return status;
660 }
Jeff Tinker4c63a232013-03-30 16:19:44 -0700661 readVector(reply, signature);
662
663 return reply.readInt32();
664 }
665
666 virtual status_t verify(Vector<uint8_t> const &sessionId,
667 Vector<uint8_t> const &keyId,
668 Vector<uint8_t> const &message,
669 Vector<uint8_t> const &signature,
670 bool &match) {
671 Parcel data, reply;
672 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
673
674 writeVector(data, sessionId);
675 writeVector(data, keyId);
676 writeVector(data, message);
677 writeVector(data, signature);
678
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700679 status_t status = remote()->transact(VERIFY, data, &reply);
680 if (status != OK) {
681 return status;
682 }
Jeff Tinker4c63a232013-03-30 16:19:44 -0700683 match = (bool)reply.readInt32();
684 return reply.readInt32();
685 }
686
Jeff Tinker68d9d712014-03-04 13:21:31 -0800687 virtual status_t signRSA(Vector<uint8_t> const &sessionId,
688 String8 const &algorithm,
689 Vector<uint8_t> const &message,
690 Vector<uint8_t> const &wrappedKey,
691 Vector<uint8_t> &signature) {
692 Parcel data, reply;
693 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
694
695 writeVector(data, sessionId);
696 data.writeString8(algorithm);
697 writeVector(data, message);
698 writeVector(data, wrappedKey);
699
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700700 status_t status = remote()->transact(SIGN_RSA, data, &reply);
701 if (status != OK) {
702 return status;
703 }
Jeff Tinker68d9d712014-03-04 13:21:31 -0800704 readVector(reply, signature);
705
706 return reply.readInt32();
707 }
708
Jeff Tinkerc0d5f1f2013-04-02 13:08:05 -0700709 virtual status_t setListener(const sp<IDrmClient>& listener) {
710 Parcel data, reply;
711 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
Marco Nelissen06b46062014-11-14 07:58:25 -0800712 data.writeStrongBinder(IInterface::asBinder(listener));
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700713 status_t status = remote()->transact(SET_LISTENER, data, &reply);
714 if (status != OK) {
715 return status;
716 }
Jeff Tinkerc0d5f1f2013-04-02 13:08:05 -0700717 return reply.readInt32();
718 }
719
Jeff Tinker441a78d2013-02-08 10:18:35 -0800720private:
Jeff Tinker4c63a232013-03-30 16:19:44 -0700721 void readVector(Parcel &reply, Vector<uint8_t> &vector) const {
722 uint32_t size = reply.readInt32();
723 vector.insertAt((size_t)0, size);
724 reply.read(vector.editArray(), size);
725 }
726
727 void writeVector(Parcel &data, Vector<uint8_t> const &vector) const {
728 data.writeInt32(vector.size());
729 data.write(vector.array(), vector.size());
730 }
731
Jeff Tinker441a78d2013-02-08 10:18:35 -0800732 DISALLOW_EVIL_CONSTRUCTORS(BpDrm);
733};
734
735IMPLEMENT_META_INTERFACE(Drm, "android.drm.IDrm");
736
737////////////////////////////////////////////////////////////////////////////////
738
Jeff Tinker4c63a232013-03-30 16:19:44 -0700739void BnDrm::readVector(const Parcel &data, Vector<uint8_t> &vector) const {
740 uint32_t size = data.readInt32();
Jeff Tinker3cf728e2017-10-18 20:54:26 +0000741 if (vector.insertAt((size_t)0, size) < 0) {
742 vector.clear();
743 }
744 if (data.read(vector.editArray(), size) != NO_ERROR) {
745 vector.clear();
746 android_errorWriteWithInfoLog(0x534e4554, "62872384", -1, NULL, 0);
747 }
Jeff Tinker4c63a232013-03-30 16:19:44 -0700748}
749
750void BnDrm::writeVector(Parcel *reply, Vector<uint8_t> const &vector) const {
751 reply->writeInt32(vector.size());
752 reply->write(vector.array(), vector.size());
753}
754
Jeff Tinker441a78d2013-02-08 10:18:35 -0800755status_t BnDrm::onTransact(
756 uint32_t code, const Parcel &data, Parcel *reply, uint32_t flags) {
757 switch (code) {
758 case INIT_CHECK:
759 {
760 CHECK_INTERFACE(IDrm, data, reply);
761 reply->writeInt32(initCheck());
762 return OK;
763 }
764
765 case IS_CRYPTO_SUPPORTED:
766 {
767 CHECK_INTERFACE(IDrm, data, reply);
768 uint8_t uuid[16];
769 data.read(uuid, sizeof(uuid));
Jeff Tinker9cf69e02013-08-21 11:59:23 -0700770 String8 mimeType = data.readString8();
771 reply->writeInt32(isCryptoSchemeSupported(uuid, mimeType));
Jeff Tinker441a78d2013-02-08 10:18:35 -0800772 return OK;
773 }
774
775 case CREATE_PLUGIN:
776 {
777 CHECK_INTERFACE(IDrm, data, reply);
778 uint8_t uuid[16];
779 data.read(uuid, sizeof(uuid));
Edwin Wong68b3d9f2017-01-06 19:07:54 -0800780 String8 appPackageName = data.readString8();
781 reply->writeInt32(createPlugin(uuid, appPackageName));
Jeff Tinker441a78d2013-02-08 10:18:35 -0800782 return OK;
783 }
784
785 case DESTROY_PLUGIN:
786 {
787 CHECK_INTERFACE(IDrm, data, reply);
788 reply->writeInt32(destroyPlugin());
789 return OK;
790 }
791
792 case OPEN_SESSION:
793 {
794 CHECK_INTERFACE(IDrm, data, reply);
Jeff Tinker41d279a2018-02-11 19:52:08 +0000795 DrmPlugin::SecurityLevel level =
796 static_cast<DrmPlugin::SecurityLevel>(data.readInt32());
Jeff Tinker441a78d2013-02-08 10:18:35 -0800797 Vector<uint8_t> sessionId;
Jeff Tinker41d279a2018-02-11 19:52:08 +0000798 status_t result = openSession(level, sessionId);
Jeff Tinker4c63a232013-03-30 16:19:44 -0700799 writeVector(reply, sessionId);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800800 reply->writeInt32(result);
801 return OK;
802 }
803
804 case CLOSE_SESSION:
805 {
806 CHECK_INTERFACE(IDrm, data, reply);
807 Vector<uint8_t> sessionId;
Jeff Tinker4c63a232013-03-30 16:19:44 -0700808 readVector(data, sessionId);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800809 reply->writeInt32(closeSession(sessionId));
810 return OK;
811 }
812
Jeff Tinker4c63a232013-03-30 16:19:44 -0700813 case GET_KEY_REQUEST:
Jeff Tinker441a78d2013-02-08 10:18:35 -0800814 {
815 CHECK_INTERFACE(IDrm, data, reply);
Jeff Tinker4c63a232013-03-30 16:19:44 -0700816 Vector<uint8_t> sessionId, initData;
Jeff Tinker441a78d2013-02-08 10:18:35 -0800817
Jeff Tinker4c63a232013-03-30 16:19:44 -0700818 readVector(data, sessionId);
819 readVector(data, initData);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800820 String8 mimeType = data.readString8();
Jeff Tinker4c63a232013-03-30 16:19:44 -0700821 DrmPlugin::KeyType keyType = (DrmPlugin::KeyType)data.readInt32();
Jeff Tinker441a78d2013-02-08 10:18:35 -0800822
823 KeyedVector<String8, String8> optionalParameters;
824 uint32_t count = data.readInt32();
825 for (size_t i = 0; i < count; ++i) {
826 String8 key, value;
827 key = data.readString8();
828 value = data.readString8();
829 optionalParameters.add(key, value);
830 }
831
832 Vector<uint8_t> request;
833 String8 defaultUrl;
Jeff Tinker8aff7772016-02-08 17:52:25 -0800834 DrmPlugin::KeyRequestType keyRequestType = DrmPlugin::kKeyRequestType_Unknown;
Jeff Tinker441a78d2013-02-08 10:18:35 -0800835
Jeff Tinkerd072c902015-03-16 13:39:29 -0700836 status_t result = getKeyRequest(sessionId, initData, mimeType,
837 keyType, optionalParameters, request, defaultUrl,
838 &keyRequestType);
839
Jeff Tinker4c63a232013-03-30 16:19:44 -0700840 writeVector(reply, request);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800841 reply->writeString8(defaultUrl);
Jeff Tinkerd072c902015-03-16 13:39:29 -0700842 reply->writeInt32(static_cast<int32_t>(keyRequestType));
Jeff Tinker441a78d2013-02-08 10:18:35 -0800843 reply->writeInt32(result);
844 return OK;
845 }
846
Jeff Tinker4c63a232013-03-30 16:19:44 -0700847 case PROVIDE_KEY_RESPONSE:
Jeff Tinker441a78d2013-02-08 10:18:35 -0800848 {
849 CHECK_INTERFACE(IDrm, data, reply);
Jeff Tinker4c63a232013-03-30 16:19:44 -0700850 Vector<uint8_t> sessionId, response, keySetId;
851 readVector(data, sessionId);
852 readVector(data, response);
853 uint32_t result = provideKeyResponse(sessionId, response, keySetId);
854 writeVector(reply, keySetId);
855 reply->writeInt32(result);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800856 return OK;
857 }
858
Jeff Tinker4c63a232013-03-30 16:19:44 -0700859 case REMOVE_KEYS:
Jeff Tinker441a78d2013-02-08 10:18:35 -0800860 {
861 CHECK_INTERFACE(IDrm, data, reply);
Jeff Tinker4c63a232013-03-30 16:19:44 -0700862 Vector<uint8_t> keySetId;
863 readVector(data, keySetId);
864 reply->writeInt32(removeKeys(keySetId));
Jeff Tinker441a78d2013-02-08 10:18:35 -0800865 return OK;
866 }
867
Jeff Tinker4c63a232013-03-30 16:19:44 -0700868 case RESTORE_KEYS:
869 {
870 CHECK_INTERFACE(IDrm, data, reply);
871 Vector<uint8_t> sessionId, keySetId;
872 readVector(data, sessionId);
873 readVector(data, keySetId);
874 reply->writeInt32(restoreKeys(sessionId, keySetId));
875 return OK;
876 }
877
878 case QUERY_KEY_STATUS:
Jeff Tinker441a78d2013-02-08 10:18:35 -0800879 {
880 CHECK_INTERFACE(IDrm, data, reply);
881 Vector<uint8_t> sessionId;
Jeff Tinker4c63a232013-03-30 16:19:44 -0700882 readVector(data, sessionId);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800883 KeyedVector<String8, String8> infoMap;
Jeff Tinker4c63a232013-03-30 16:19:44 -0700884 status_t result = queryKeyStatus(sessionId, infoMap);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800885 size_t count = infoMap.size();
886 reply->writeInt32(count);
887 for (size_t i = 0; i < count; ++i) {
888 reply->writeString8(infoMap.keyAt(i));
889 reply->writeString8(infoMap.valueAt(i));
890 }
891 reply->writeInt32(result);
892 return OK;
893 }
894
895 case GET_PROVISION_REQUEST:
896 {
897 CHECK_INTERFACE(IDrm, data, reply);
Jeff Tinker68d9d712014-03-04 13:21:31 -0800898 String8 certType = data.readString8();
899 String8 certAuthority = data.readString8();
900
Jeff Tinker441a78d2013-02-08 10:18:35 -0800901 Vector<uint8_t> request;
902 String8 defaultUrl;
Jeff Tinker68d9d712014-03-04 13:21:31 -0800903 status_t result = getProvisionRequest(certType, certAuthority,
904 request, defaultUrl);
Jeff Tinker4c63a232013-03-30 16:19:44 -0700905 writeVector(reply, request);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800906 reply->writeString8(defaultUrl);
907 reply->writeInt32(result);
908 return OK;
909 }
910
911 case PROVIDE_PROVISION_RESPONSE:
912 {
913 CHECK_INTERFACE(IDrm, data, reply);
914 Vector<uint8_t> response;
Jeff Tinker68d9d712014-03-04 13:21:31 -0800915 Vector<uint8_t> certificate;
916 Vector<uint8_t> wrappedKey;
Jeff Tinker4c63a232013-03-30 16:19:44 -0700917 readVector(data, response);
Jeff Tinker68d9d712014-03-04 13:21:31 -0800918 status_t result = provideProvisionResponse(response, certificate, wrappedKey);
919 writeVector(reply, certificate);
920 writeVector(reply, wrappedKey);
921 reply->writeInt32(result);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800922 return OK;
923 }
924
925 case GET_SECURE_STOPS:
926 {
927 CHECK_INTERFACE(IDrm, data, reply);
928 List<Vector<uint8_t> > secureStops;
929 status_t result = getSecureStops(secureStops);
930 size_t count = secureStops.size();
931 reply->writeInt32(count);
932 List<Vector<uint8_t> >::iterator iter = secureStops.begin();
933 while(iter != secureStops.end()) {
934 size_t size = iter->size();
935 reply->writeInt32(size);
936 reply->write(iter->array(), iter->size());
Jeff Tinker423e33c2013-04-08 15:23:17 -0700937 iter++;
Jeff Tinker441a78d2013-02-08 10:18:35 -0800938 }
939 reply->writeInt32(result);
940 return OK;
941 }
942
Jeff Tinker15177d72018-01-25 12:57:55 -0800943 case GET_SECURE_STOP_IDS:
944 {
945 CHECK_INTERFACE(IDrm, data, reply);
946 List<Vector<uint8_t> > secureStopIds;
947 status_t result = getSecureStopIds(secureStopIds);
948 size_t count = secureStopIds.size();
949 reply->writeInt32(count);
950 List<Vector<uint8_t> >::iterator iter = secureStopIds.begin();
951 while(iter != secureStopIds.end()) {
952 size_t size = iter->size();
953 reply->writeInt32(size);
954 reply->write(iter->array(), iter->size());
955 iter++;
956 }
957 reply->writeInt32(result);
958 return OK;
959 }
960
Jeff Tinker3c1285e2014-10-31 00:55:16 -0700961 case GET_SECURE_STOP:
962 {
963 CHECK_INTERFACE(IDrm, data, reply);
964 Vector<uint8_t> ssid, secureStop;
965 readVector(data, ssid);
966 status_t result = getSecureStop(ssid, secureStop);
967 writeVector(reply, secureStop);
968 reply->writeInt32(result);
969 return OK;
970 }
971
Jeff Tinker441a78d2013-02-08 10:18:35 -0800972 case RELEASE_SECURE_STOPS:
973 {
974 CHECK_INTERFACE(IDrm, data, reply);
975 Vector<uint8_t> ssRelease;
Jeff Tinker4c63a232013-03-30 16:19:44 -0700976 readVector(data, ssRelease);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800977 reply->writeInt32(releaseSecureStops(ssRelease));
978 return OK;
979 }
980
Jeff Tinker15177d72018-01-25 12:57:55 -0800981 case REMOVE_SECURE_STOP:
Jeff Tinker3c1285e2014-10-31 00:55:16 -0700982 {
983 CHECK_INTERFACE(IDrm, data, reply);
Jeff Tinker15177d72018-01-25 12:57:55 -0800984 Vector<uint8_t> ssid;
985 readVector(data, ssid);
986 reply->writeInt32(removeSecureStop(ssid));
987 return OK;
988 }
989
990 case REMOVE_ALL_SECURE_STOPS:
991 {
992 CHECK_INTERFACE(IDrm, data, reply);
993 reply->writeInt32(removeAllSecureStops());
Jeff Tinker3c1285e2014-10-31 00:55:16 -0700994 return OK;
995 }
996
Jeff Tinker6d998b62017-12-18 14:37:43 -0800997 case GET_HDCP_LEVELS:
998 {
999 CHECK_INTERFACE(IDrm, data, reply);
1000 DrmPlugin::HdcpLevel connected = DrmPlugin::kHdcpLevelUnknown;
1001 DrmPlugin::HdcpLevel max = DrmPlugin::kHdcpLevelUnknown;
1002 status_t result = getHdcpLevels(&connected, &max);
1003 reply->writeInt32(connected);
1004 reply->writeInt32(max);
1005 reply->writeInt32(result);
1006 return OK;
1007 }
1008
1009 case GET_NUMBER_OF_SESSIONS:
1010 {
1011 CHECK_INTERFACE(IDrm, data, reply);
1012 uint32_t open = 0, max = 0;
1013 status_t result = getNumberOfSessions(&open, &max);
1014 reply->writeInt32(open);
1015 reply->writeInt32(max);
1016 reply->writeInt32(result);
1017 return OK;
1018 }
1019
1020 case GET_SECURITY_LEVEL:
1021 {
1022 CHECK_INTERFACE(IDrm, data, reply);
1023 Vector<uint8_t> sessionId;
1024 readVector(data, sessionId);
1025 DrmPlugin::SecurityLevel level = DrmPlugin::kSecurityLevelUnknown;
1026 status_t result = getSecurityLevel(sessionId, &level);
1027 reply->writeInt32(level);
1028 reply->writeInt32(result);
1029 return OK;
1030 }
1031
Jeff Tinkerc8baaba2018-10-23 11:32:36 -07001032 case GET_OFFLINE_LICENSE_KEYSET_IDS:
1033 {
1034 CHECK_INTERFACE(IDrm, data, reply);
1035 List<Vector<uint8_t> > keySetIds;
1036 status_t result = getOfflineLicenseKeySetIds(keySetIds);
1037 size_t count = keySetIds.size();
1038 reply->writeInt32(count);
1039 List<Vector<uint8_t> >::iterator iter = keySetIds.begin();
1040 while(iter != keySetIds.end()) {
1041 size_t size = iter->size();
1042 reply->writeInt32(size);
1043 reply->write(iter->array(), iter->size());
1044 iter++;
1045 }
1046 reply->writeInt32(result);
1047 return OK;
1048 }
1049
1050 case REMOVE_OFFLINE_LICENSE:
1051 {
1052 CHECK_INTERFACE(IDrm, data, reply);
1053 Vector<uint8_t> keySetId;
1054 readVector(data, keySetId);
1055 reply->writeInt32(removeOfflineLicense(keySetId));
1056 return OK;
1057 }
1058
1059 case GET_OFFLINE_LICENSE_STATE:
1060 {
1061 CHECK_INTERFACE(IDrm, data, reply);
1062 Vector<uint8_t> keySetId;
1063 readVector(data, keySetId);
1064 DrmPlugin::OfflineLicenseState state;
1065 status_t result = getOfflineLicenseState(keySetId, &state);
1066 reply->writeInt32(static_cast<DrmPlugin::OfflineLicenseState>(state));
1067 reply->writeInt32(result);
1068 return OK;
1069 }
1070
Jeff Tinker441a78d2013-02-08 10:18:35 -08001071 case GET_PROPERTY_STRING:
1072 {
1073 CHECK_INTERFACE(IDrm, data, reply);
1074 String8 name = data.readString8();
1075 String8 value;
1076 status_t result = getPropertyString(name, value);
1077 reply->writeString8(value);
1078 reply->writeInt32(result);
1079 return OK;
1080 }
1081
1082 case GET_PROPERTY_BYTE_ARRAY:
1083 {
1084 CHECK_INTERFACE(IDrm, data, reply);
1085 String8 name = data.readString8();
1086 Vector<uint8_t> value;
1087 status_t result = getPropertyByteArray(name, value);
Jeff Tinker4c63a232013-03-30 16:19:44 -07001088 writeVector(reply, value);
Jeff Tinker441a78d2013-02-08 10:18:35 -08001089 reply->writeInt32(result);
1090 return OK;
1091 }
1092
1093 case SET_PROPERTY_STRING:
1094 {
1095 CHECK_INTERFACE(IDrm, data, reply);
1096 String8 name = data.readString8();
1097 String8 value = data.readString8();
1098 reply->writeInt32(setPropertyString(name, value));
1099 return OK;
1100 }
1101
1102 case SET_PROPERTY_BYTE_ARRAY:
1103 {
1104 CHECK_INTERFACE(IDrm, data, reply);
1105 String8 name = data.readString8();
1106 Vector<uint8_t> value;
Jeff Tinker4c63a232013-03-30 16:19:44 -07001107 readVector(data, value);
Jeff Tinker441a78d2013-02-08 10:18:35 -08001108 reply->writeInt32(setPropertyByteArray(name, value));
1109 return OK;
1110 }
1111
Adam Stoneab394d12017-12-22 12:34:20 -08001112 case GET_METRICS:
1113 {
1114 CHECK_INTERFACE(IDrm, data, reply);
1115
Adam Stone637b7852018-01-30 12:09:36 -08001116 os::PersistableBundle metrics;
1117 status_t result = getMetrics(&metrics);
Adam Stone568b3c42018-01-31 12:57:16 -08001118 // The reply data is ordered as
1119 // 1) 32 bit integer reply followed by
1120 // 2) Serialized PersistableBundle containing metrics.
1121 // Only write the metrics if the getMetrics result was
1122 // OK and we successfully added the status to reply.
1123 status_t parcel_result = reply->writeInt32(result);
1124 if (result == OK && parcel_result == OK) {
1125 parcel_result = metrics.writeToParcel(reply);
1126 }
1127 return parcel_result;
Adam Stoneab394d12017-12-22 12:34:20 -08001128 }
1129
Jeff Tinker4c63a232013-03-30 16:19:44 -07001130 case SET_CIPHER_ALGORITHM:
1131 {
1132 CHECK_INTERFACE(IDrm, data, reply);
1133 Vector<uint8_t> sessionId;
1134 readVector(data, sessionId);
1135 String8 algorithm = data.readString8();
1136 reply->writeInt32(setCipherAlgorithm(sessionId, algorithm));
1137 return OK;
1138 }
1139
1140 case SET_MAC_ALGORITHM:
1141 {
1142 CHECK_INTERFACE(IDrm, data, reply);
1143 Vector<uint8_t> sessionId;
1144 readVector(data, sessionId);
1145 String8 algorithm = data.readString8();
1146 reply->writeInt32(setMacAlgorithm(sessionId, algorithm));
1147 return OK;
1148 }
1149
1150 case ENCRYPT:
1151 {
1152 CHECK_INTERFACE(IDrm, data, reply);
1153 Vector<uint8_t> sessionId, keyId, input, iv, output;
1154 readVector(data, sessionId);
1155 readVector(data, keyId);
1156 readVector(data, input);
1157 readVector(data, iv);
1158 uint32_t result = encrypt(sessionId, keyId, input, iv, output);
1159 writeVector(reply, output);
1160 reply->writeInt32(result);
1161 return OK;
1162 }
1163
1164 case DECRYPT:
1165 {
1166 CHECK_INTERFACE(IDrm, data, reply);
1167 Vector<uint8_t> sessionId, keyId, input, iv, output;
1168 readVector(data, sessionId);
1169 readVector(data, keyId);
1170 readVector(data, input);
1171 readVector(data, iv);
1172 uint32_t result = decrypt(sessionId, keyId, input, iv, output);
1173 writeVector(reply, output);
1174 reply->writeInt32(result);
1175 return OK;
1176 }
1177
1178 case SIGN:
1179 {
1180 CHECK_INTERFACE(IDrm, data, reply);
1181 Vector<uint8_t> sessionId, keyId, message, signature;
1182 readVector(data, sessionId);
1183 readVector(data, keyId);
1184 readVector(data, message);
1185 uint32_t result = sign(sessionId, keyId, message, signature);
1186 writeVector(reply, signature);
1187 reply->writeInt32(result);
1188 return OK;
1189 }
1190
1191 case VERIFY:
1192 {
1193 CHECK_INTERFACE(IDrm, data, reply);
1194 Vector<uint8_t> sessionId, keyId, message, signature;
1195 readVector(data, sessionId);
1196 readVector(data, keyId);
1197 readVector(data, message);
1198 readVector(data, signature);
Jeff Tinker9a6861c2016-09-02 11:36:46 -07001199 bool match = false;
Jeff Tinker4c63a232013-03-30 16:19:44 -07001200 uint32_t result = verify(sessionId, keyId, message, signature, match);
1201 reply->writeInt32(match);
1202 reply->writeInt32(result);
1203 return OK;
1204 }
1205
Jeff Tinker68d9d712014-03-04 13:21:31 -08001206 case SIGN_RSA:
1207 {
1208 CHECK_INTERFACE(IDrm, data, reply);
1209 Vector<uint8_t> sessionId, message, wrappedKey, signature;
1210 readVector(data, sessionId);
1211 String8 algorithm = data.readString8();
1212 readVector(data, message);
1213 readVector(data, wrappedKey);
1214 uint32_t result = signRSA(sessionId, algorithm, message, wrappedKey, signature);
1215 writeVector(reply, signature);
1216 reply->writeInt32(result);
1217 return OK;
1218 }
1219
Jeff Tinkerc0d5f1f2013-04-02 13:08:05 -07001220 case SET_LISTENER: {
1221 CHECK_INTERFACE(IDrm, data, reply);
1222 sp<IDrmClient> listener =
1223 interface_cast<IDrmClient>(data.readStrongBinder());
1224 reply->writeInt32(setListener(listener));
1225 return NO_ERROR;
1226 } break;
1227
Jeff Tinker4c63a232013-03-30 16:19:44 -07001228 default:
1229 return BBinder::onTransact(code, data, reply, flags);
Jeff Tinker441a78d2013-02-08 10:18:35 -08001230 }
1231}
1232
1233} // namespace android