blob: 51274d16c17fc04e6117183b87591c8f9a7b7547 [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 Tinkerdb3fa5f2019-01-25 22:56:56 -080086 virtual status_t isCryptoSchemeSupported(const uint8_t uuid[16], const String8 &mimeType,
87 DrmPlugin::SecurityLevel level, bool *isSupported) {
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);
Jeff Tinkerdb3fa5f2019-01-25 22:56:56 -080097 return status;
Jeff Tinker3b5401a2015-06-15 17:42:10 -070098 }
Jeff Tinkerdb3fa5f2019-01-25 22:56:56 -080099 *isSupported = static_cast<bool>(reply.readInt32());
Jeff Tinker441a78d2013-02-08 10:18:35 -0800100
Jeff Tinkerdb3fa5f2019-01-25 22:56:56 -0800101 return reply.readInt32();
Jeff Tinker441a78d2013-02-08 10:18:35 -0800102 }
103
Edwin Wong68b3d9f2017-01-06 19:07:54 -0800104 virtual status_t createPlugin(const uint8_t uuid[16],
105 const String8& appPackageName) {
Jeff Tinker441a78d2013-02-08 10:18:35 -0800106 Parcel data, reply;
107 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
108 data.write(uuid, 16);
Edwin Wong68b3d9f2017-01-06 19:07:54 -0800109 data.writeString8(appPackageName);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700110 status_t status = remote()->transact(CREATE_PLUGIN, data, &reply);
111 if (status != OK) {
Edwin Wong68b3d9f2017-01-06 19:07:54 -0800112 ALOGE("createPlugin: binder call failed: %d", status);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700113 return status;
114 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800115
116 return reply.readInt32();
117 }
118
119 virtual status_t destroyPlugin() {
120 Parcel data, reply;
121 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700122 status_t status = remote()->transact(DESTROY_PLUGIN, data, &reply);
123 if (status != OK) {
124 return status;
125 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800126
127 return reply.readInt32();
128 }
129
Jeff Tinker99dbfa82019-01-17 17:27:06 -0800130 virtual status_t openSession(DrmPlugin::SecurityLevel level,
Jeff Tinker41d279a2018-02-11 19:52:08 +0000131 Vector<uint8_t> &sessionId) {
Jeff Tinker441a78d2013-02-08 10:18:35 -0800132 Parcel data, reply;
133 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
Jeff Tinker99dbfa82019-01-17 17:27:06 -0800134 data.writeInt32(level);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800135
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700136 status_t status = remote()->transact(OPEN_SESSION, data, &reply);
137 if (status != OK) {
138 return status;
139 }
Jeff Tinker4c63a232013-03-30 16:19:44 -0700140 readVector(reply, sessionId);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800141
142 return reply.readInt32();
143 }
144
145 virtual status_t closeSession(Vector<uint8_t> const &sessionId) {
146 Parcel data, reply;
147 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
148
Jeff Tinker4c63a232013-03-30 16:19:44 -0700149 writeVector(data, sessionId);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700150 status_t status = remote()->transact(CLOSE_SESSION, data, &reply);
151 if (status != OK) {
152 return status;
153 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800154
155 return reply.readInt32();
156 }
157
158 virtual status_t
Jeff Tinker4c63a232013-03-30 16:19:44 -0700159 getKeyRequest(Vector<uint8_t> const &sessionId,
160 Vector<uint8_t> const &initData,
161 String8 const &mimeType, DrmPlugin::KeyType keyType,
162 KeyedVector<String8, String8> const &optionalParameters,
Jeff Tinkerd072c902015-03-16 13:39:29 -0700163 Vector<uint8_t> &request, String8 &defaultUrl,
164 DrmPlugin::KeyRequestType *keyRequestType) {
Jeff Tinker441a78d2013-02-08 10:18:35 -0800165 Parcel data, reply;
166 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
167
Jeff Tinker4c63a232013-03-30 16:19:44 -0700168 writeVector(data, sessionId);
169 writeVector(data, initData);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800170 data.writeString8(mimeType);
Jeff Tinker4c63a232013-03-30 16:19:44 -0700171 data.writeInt32((uint32_t)keyType);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800172
173 data.writeInt32(optionalParameters.size());
174 for (size_t i = 0; i < optionalParameters.size(); ++i) {
175 data.writeString8(optionalParameters.keyAt(i));
176 data.writeString8(optionalParameters.valueAt(i));
177 }
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700178
179 status_t status = remote()->transact(GET_KEY_REQUEST, data, &reply);
180 if (status != OK) {
181 return status;
182 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800183
Jeff Tinker4c63a232013-03-30 16:19:44 -0700184 readVector(reply, request);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800185 defaultUrl = reply.readString8();
Jeff Tinkerd072c902015-03-16 13:39:29 -0700186 *keyRequestType = static_cast<DrmPlugin::KeyRequestType>(reply.readInt32());
Jeff Tinker441a78d2013-02-08 10:18:35 -0800187
188 return reply.readInt32();
189 }
190
Jeff Tinker4c63a232013-03-30 16:19:44 -0700191 virtual status_t provideKeyResponse(Vector<uint8_t> const &sessionId,
192 Vector<uint8_t> const &response,
193 Vector<uint8_t> &keySetId) {
Jeff Tinker441a78d2013-02-08 10:18:35 -0800194 Parcel data, reply;
195 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
Jeff Tinker4c63a232013-03-30 16:19:44 -0700196 writeVector(data, sessionId);
197 writeVector(data, response);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700198
199 status_t status = remote()->transact(PROVIDE_KEY_RESPONSE, data, &reply);
200 if (status != OK) {
201 return status;
202 }
203
Jeff Tinker4c63a232013-03-30 16:19:44 -0700204 readVector(reply, keySetId);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800205
206 return reply.readInt32();
207 }
208
Jeff Tinker4c63a232013-03-30 16:19:44 -0700209 virtual status_t removeKeys(Vector<uint8_t> const &keySetId) {
Jeff Tinker441a78d2013-02-08 10:18:35 -0800210 Parcel data, reply;
211 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
212
Jeff Tinker4c63a232013-03-30 16:19:44 -0700213 writeVector(data, keySetId);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700214 status_t status = remote()->transact(REMOVE_KEYS, data, &reply);
215 if (status != OK) {
216 return status;
217 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800218
219 return reply.readInt32();
220 }
221
Jeff Tinker4c63a232013-03-30 16:19:44 -0700222 virtual status_t restoreKeys(Vector<uint8_t> const &sessionId,
223 Vector<uint8_t> const &keySetId) {
224 Parcel data, reply;
225 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
226
227 writeVector(data, sessionId);
228 writeVector(data, keySetId);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700229 status_t status = remote()->transact(RESTORE_KEYS, data, &reply);
230 if (status != OK) {
231 return status;
232 }
Jeff Tinker4c63a232013-03-30 16:19:44 -0700233
234 return reply.readInt32();
235 }
236
237 virtual status_t queryKeyStatus(Vector<uint8_t> const &sessionId,
Jeff Tinker441a78d2013-02-08 10:18:35 -0800238 KeyedVector<String8, String8> &infoMap) const {
239 Parcel data, reply;
240 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
241
Jeff Tinker4c63a232013-03-30 16:19:44 -0700242 writeVector(data, sessionId);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700243 status_t status = remote()->transact(QUERY_KEY_STATUS, data, &reply);
244 if (status != OK) {
245 return status;
246 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800247
248 infoMap.clear();
249 size_t count = reply.readInt32();
250 for (size_t i = 0; i < count; i++) {
251 String8 key = reply.readString8();
252 String8 value = reply.readString8();
253 infoMap.add(key, value);
254 }
255 return reply.readInt32();
256 }
257
Jeff Tinker68d9d712014-03-04 13:21:31 -0800258 virtual status_t getProvisionRequest(String8 const &certType,
259 String8 const &certAuthority,
260 Vector<uint8_t> &request,
Jeff Tinker441a78d2013-02-08 10:18:35 -0800261 String8 &defaultUrl) {
262 Parcel data, reply;
263 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
264
Jeff Tinker68d9d712014-03-04 13:21:31 -0800265 data.writeString8(certType);
266 data.writeString8(certAuthority);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700267 status_t status = remote()->transact(GET_PROVISION_REQUEST, data, &reply);
268 if (status != OK) {
269 return status;
270 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800271
Jeff Tinker4c63a232013-03-30 16:19:44 -0700272 readVector(reply, request);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800273 defaultUrl = reply.readString8();
274
275 return reply.readInt32();
276 }
277
Jeff Tinker68d9d712014-03-04 13:21:31 -0800278 virtual status_t provideProvisionResponse(Vector<uint8_t> const &response,
279 Vector<uint8_t> &certificate,
280 Vector<uint8_t> &wrappedKey) {
Jeff Tinker441a78d2013-02-08 10:18:35 -0800281 Parcel data, reply;
282 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
283
Jeff Tinker4c63a232013-03-30 16:19:44 -0700284 writeVector(data, response);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700285 status_t status = remote()->transact(PROVIDE_PROVISION_RESPONSE, data, &reply);
286 if (status != OK) {
287 return status;
288 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800289
Jeff Tinker68d9d712014-03-04 13:21:31 -0800290 readVector(reply, certificate);
291 readVector(reply, wrappedKey);
292
Jeff Tinker441a78d2013-02-08 10:18:35 -0800293 return reply.readInt32();
294 }
295
296 virtual status_t getSecureStops(List<Vector<uint8_t> > &secureStops) {
297 Parcel data, reply;
298 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
299
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700300 status_t status = remote()->transact(GET_SECURE_STOPS, data, &reply);
301 if (status != OK) {
302 return status;
303 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800304
305 secureStops.clear();
306 uint32_t count = reply.readInt32();
307 for (size_t i = 0; i < count; i++) {
308 Vector<uint8_t> secureStop;
Jeff Tinker4c63a232013-03-30 16:19:44 -0700309 readVector(reply, secureStop);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800310 secureStops.push_back(secureStop);
311 }
312 return reply.readInt32();
313 }
314
Jeff Tinker15177d72018-01-25 12:57:55 -0800315 virtual status_t getSecureStopIds(List<Vector<uint8_t> > &secureStopIds) {
316 Parcel data, reply;
317 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
318
319 status_t status = remote()->transact(GET_SECURE_STOP_IDS, data, &reply);
320 if (status != OK) {
321 return status;
322 }
323
324 secureStopIds.clear();
325 uint32_t count = reply.readInt32();
326 for (size_t i = 0; i < count; i++) {
327 Vector<uint8_t> secureStopId;
328 readVector(reply, secureStopId);
329 secureStopIds.push_back(secureStopId);
330 }
331 return reply.readInt32();
332 }
333
Jeff Tinker3c1285e2014-10-31 00:55:16 -0700334 virtual status_t getSecureStop(Vector<uint8_t> const &ssid, Vector<uint8_t> &secureStop) {
335 Parcel data, reply;
336 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
337
338 writeVector(data, ssid);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700339 status_t status = remote()->transact(GET_SECURE_STOP, data, &reply);
340 if (status != OK) {
341 return status;
342 }
Jeff Tinker3c1285e2014-10-31 00:55:16 -0700343
344 readVector(reply, secureStop);
345 return reply.readInt32();
346 }
347
Jeff Tinker441a78d2013-02-08 10:18:35 -0800348 virtual status_t releaseSecureStops(Vector<uint8_t> const &ssRelease) {
349 Parcel data, reply;
350 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
351
Jeff Tinker4c63a232013-03-30 16:19:44 -0700352 writeVector(data, ssRelease);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700353 status_t status = remote()->transact(RELEASE_SECURE_STOPS, data, &reply);
354 if (status != OK) {
355 return status;
356 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800357
358 return reply.readInt32();
359 }
360
Jeff Tinker15177d72018-01-25 12:57:55 -0800361 virtual status_t removeSecureStop(Vector<uint8_t> const &ssid) {
Jeff Tinker3c1285e2014-10-31 00:55:16 -0700362 Parcel data, reply;
363 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
364
Jeff Tinker15177d72018-01-25 12:57:55 -0800365 writeVector(data, ssid);
366 status_t status = remote()->transact(REMOVE_SECURE_STOP, data, &reply);
367 if (status != OK) {
368 return status;
369 }
370
371 return reply.readInt32();
372 }
373
374 virtual status_t removeAllSecureStops() {
375 Parcel data, reply;
376 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
377
378 status_t status = remote()->transact(REMOVE_ALL_SECURE_STOPS, data, &reply);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700379 if (status != OK) {
380 return status;
381 }
Jeff Tinker3c1285e2014-10-31 00:55:16 -0700382
383 return reply.readInt32();
384 }
385
Jeff Tinkerc8baaba2018-10-23 11:32:36 -0700386 virtual status_t getOfflineLicenseKeySetIds(List<Vector<uint8_t> > &keySetIds) const {
387 Parcel data, reply;
388 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
389
390 status_t status = remote()->transact(GET_OFFLINE_LICENSE_KEYSET_IDS, data, &reply);
391 if (status != OK) {
392 return status;
393 }
394
395 keySetIds.clear();
396 uint32_t count = reply.readInt32();
397 for (size_t i = 0; i < count; i++) {
398 Vector<uint8_t> keySetId;
399 readVector(reply, keySetId);
400 keySetIds.push_back(keySetId);
401 }
402 return reply.readInt32();
403 }
404
405 virtual status_t removeOfflineLicense(Vector<uint8_t> const &keySetId) {
406 Parcel data, reply;
407 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
408
409 writeVector(data, keySetId);
410 status_t status = remote()->transact(REMOVE_OFFLINE_LICENSE, data, &reply);
411 if (status != OK) {
412 return status;
413 }
414 return reply.readInt32();
415 }
416
417 virtual status_t getOfflineLicenseState(Vector<uint8_t> const &keySetId,
418 DrmPlugin::OfflineLicenseState *licenseState) const {
419 Parcel data, reply;
420 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
421
422 writeVector(data, keySetId);
423 status_t status = remote()->transact(GET_OFFLINE_LICENSE_STATE, data, &reply);
424 if (status != OK) {
425 *licenseState = DrmPlugin::OfflineLicenseState::kOfflineLicenseStateUnknown;
426 return status;
427 }
428 *licenseState = static_cast<DrmPlugin::OfflineLicenseState>(reply.readInt32());
429 return reply.readInt32();
430 }
431
Jeff Tinker441a78d2013-02-08 10:18:35 -0800432 virtual status_t getPropertyString(String8 const &name, String8 &value) const {
433 Parcel data, reply;
434 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
435
436 data.writeString8(name);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700437 status_t status = remote()->transact(GET_PROPERTY_STRING, data, &reply);
438 if (status != OK) {
439 return status;
440 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800441
442 value = reply.readString8();
443 return reply.readInt32();
444 }
445
Jeff Tinker6d998b62017-12-18 14:37:43 -0800446 virtual status_t getHdcpLevels(DrmPlugin::HdcpLevel *connected,
447 DrmPlugin::HdcpLevel *max) const {
448 Parcel data, reply;
449
450 if (connected == NULL || max == NULL) {
451 return BAD_VALUE;
452 }
453
454 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
455
456 status_t status = remote()->transact(GET_HDCP_LEVELS, data, &reply);
457 if (status != OK) {
458 return status;
459 }
460
461 *connected = static_cast<DrmPlugin::HdcpLevel>(reply.readInt32());
462 *max = static_cast<DrmPlugin::HdcpLevel>(reply.readInt32());
463 return reply.readInt32();
464 }
465
466 virtual status_t getNumberOfSessions(uint32_t *open, uint32_t *max) const {
467 Parcel data, reply;
468
469 if (open == NULL || max == NULL) {
470 return BAD_VALUE;
471 }
472
473 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
474
475 status_t status = remote()->transact(GET_NUMBER_OF_SESSIONS, data, &reply);
476 if (status != OK) {
477 return status;
478 }
479
480 *open = reply.readInt32();
481 *max = reply.readInt32();
482 return reply.readInt32();
483 }
484
485 virtual status_t getSecurityLevel(Vector<uint8_t> const &sessionId,
486 DrmPlugin::SecurityLevel *level) const {
487 Parcel data, reply;
488
489 if (level == NULL) {
490 return BAD_VALUE;
491 }
492
493 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
494
495 writeVector(data, sessionId);
496 status_t status = remote()->transact(GET_SECURITY_LEVEL, data, &reply);
497 if (status != OK) {
498 return status;
499 }
500
501 *level = static_cast<DrmPlugin::SecurityLevel>(reply.readInt32());
502 return reply.readInt32();
503 }
504
Jeff Tinker441a78d2013-02-08 10:18:35 -0800505 virtual status_t getPropertyByteArray(String8 const &name, Vector<uint8_t> &value) const {
506 Parcel data, reply;
507 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
508
509 data.writeString8(name);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700510 status_t status = remote()->transact(GET_PROPERTY_BYTE_ARRAY, data, &reply);
511 if (status != OK) {
512 return status;
513 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800514
Jeff Tinker4c63a232013-03-30 16:19:44 -0700515 readVector(reply, value);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800516 return reply.readInt32();
517 }
518
519 virtual status_t setPropertyString(String8 const &name, String8 const &value) const {
520 Parcel data, reply;
521 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
522
523 data.writeString8(name);
524 data.writeString8(value);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700525 status_t status = remote()->transact(SET_PROPERTY_STRING, data, &reply);
526 if (status != OK) {
527 return status;
528 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800529
530 return reply.readInt32();
531 }
532
533 virtual status_t setPropertyByteArray(String8 const &name,
534 Vector<uint8_t> const &value) const {
535 Parcel data, reply;
536 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
537
538 data.writeString8(name);
Jeff Tinker4c63a232013-03-30 16:19:44 -0700539 writeVector(data, value);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700540 status_t status = remote()->transact(SET_PROPERTY_BYTE_ARRAY, data, &reply);
541 if (status != OK) {
542 return status;
543 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800544
545 return reply.readInt32();
546 }
547
Adam Stone637b7852018-01-30 12:09:36 -0800548 virtual status_t getMetrics(os::PersistableBundle *metrics) {
Adam Stone568b3c42018-01-31 12:57:16 -0800549 if (metrics == NULL) {
550 return BAD_VALUE;
551 }
Adam Stoneab394d12017-12-22 12:34:20 -0800552 Parcel data, reply;
553 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
554
555 status_t status = remote()->transact(GET_METRICS, data, &reply);
556 if (status != OK) {
557 return status;
558 }
Adam Stone568b3c42018-01-31 12:57:16 -0800559 // The reply data is ordered as
560 // 1) 32 bit integer reply followed by
561 // 2) Serialized PersistableBundle containing metrics.
562 status_t reply_status;
563 if (reply.readInt32(&reply_status) != OK
564 || reply_status != OK) {
565 ALOGE("Failed to read getMetrics response code from parcel. %d",
566 reply_status);
567 return reply_status;
568 }
Adam Stoneab394d12017-12-22 12:34:20 -0800569
Adam Stone568b3c42018-01-31 12:57:16 -0800570 status = metrics->readFromParcel(&reply);
571 if (status != OK) {
572 ALOGE("Failed to read metrics from parcel. %d", status);
573 return status;
574 }
575 return reply_status;
Adam Stoneab394d12017-12-22 12:34:20 -0800576 }
Jeff Tinker441a78d2013-02-08 10:18:35 -0800577
Jeff Tinker4c63a232013-03-30 16:19:44 -0700578 virtual status_t setCipherAlgorithm(Vector<uint8_t> const &sessionId,
579 String8 const &algorithm) {
580 Parcel data, reply;
581 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
582
583 writeVector(data, sessionId);
584 data.writeString8(algorithm);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700585 status_t status = remote()->transact(SET_CIPHER_ALGORITHM, data, &reply);
586 if (status != OK) {
587 return status;
588 }
Jeff Tinker4c63a232013-03-30 16:19:44 -0700589 return reply.readInt32();
590 }
591
592 virtual status_t setMacAlgorithm(Vector<uint8_t> const &sessionId,
593 String8 const &algorithm) {
594 Parcel data, reply;
595 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
596
597 writeVector(data, sessionId);
598 data.writeString8(algorithm);
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700599 status_t status = remote()->transact(SET_MAC_ALGORITHM, data, &reply);
600 if (status != OK) {
601 return status;
602 }
Jeff Tinker4c63a232013-03-30 16:19:44 -0700603 return reply.readInt32();
604 }
605
606 virtual status_t encrypt(Vector<uint8_t> const &sessionId,
607 Vector<uint8_t> const &keyId,
608 Vector<uint8_t> const &input,
609 Vector<uint8_t> const &iv,
610 Vector<uint8_t> &output) {
611 Parcel data, reply;
612 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
613
614 writeVector(data, sessionId);
615 writeVector(data, keyId);
616 writeVector(data, input);
617 writeVector(data, iv);
618
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700619 status_t status = remote()->transact(ENCRYPT, data, &reply);
620 if (status != OK) {
621 return status;
622 }
Jeff Tinker4c63a232013-03-30 16:19:44 -0700623 readVector(reply, output);
624
625 return reply.readInt32();
626 }
627
628 virtual status_t decrypt(Vector<uint8_t> const &sessionId,
629 Vector<uint8_t> const &keyId,
630 Vector<uint8_t> const &input,
631 Vector<uint8_t> const &iv,
632 Vector<uint8_t> &output) {
633 Parcel data, reply;
634 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
635
636 writeVector(data, sessionId);
637 writeVector(data, keyId);
638 writeVector(data, input);
639 writeVector(data, iv);
640
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700641 status_t status = remote()->transact(DECRYPT, data, &reply);
642 if (status != OK) {
643 return status;
644 }
Jeff Tinker4c63a232013-03-30 16:19:44 -0700645 readVector(reply, output);
646
647 return reply.readInt32();
648 }
649
650 virtual status_t sign(Vector<uint8_t> const &sessionId,
651 Vector<uint8_t> const &keyId,
652 Vector<uint8_t> const &message,
653 Vector<uint8_t> &signature) {
654 Parcel data, reply;
655 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
656
657 writeVector(data, sessionId);
658 writeVector(data, keyId);
659 writeVector(data, message);
660
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700661 status_t status = remote()->transact(SIGN, data, &reply);
662 if (status != OK) {
663 return status;
664 }
Jeff Tinker4c63a232013-03-30 16:19:44 -0700665 readVector(reply, signature);
666
667 return reply.readInt32();
668 }
669
670 virtual status_t verify(Vector<uint8_t> const &sessionId,
671 Vector<uint8_t> const &keyId,
672 Vector<uint8_t> const &message,
673 Vector<uint8_t> const &signature,
674 bool &match) {
675 Parcel data, reply;
676 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
677
678 writeVector(data, sessionId);
679 writeVector(data, keyId);
680 writeVector(data, message);
681 writeVector(data, signature);
682
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700683 status_t status = remote()->transact(VERIFY, data, &reply);
684 if (status != OK) {
685 return status;
686 }
Jeff Tinker4c63a232013-03-30 16:19:44 -0700687 match = (bool)reply.readInt32();
688 return reply.readInt32();
689 }
690
Jeff Tinker68d9d712014-03-04 13:21:31 -0800691 virtual status_t signRSA(Vector<uint8_t> const &sessionId,
692 String8 const &algorithm,
693 Vector<uint8_t> const &message,
694 Vector<uint8_t> const &wrappedKey,
695 Vector<uint8_t> &signature) {
696 Parcel data, reply;
697 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
698
699 writeVector(data, sessionId);
700 data.writeString8(algorithm);
701 writeVector(data, message);
702 writeVector(data, wrappedKey);
703
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700704 status_t status = remote()->transact(SIGN_RSA, data, &reply);
705 if (status != OK) {
706 return status;
707 }
Jeff Tinker68d9d712014-03-04 13:21:31 -0800708 readVector(reply, signature);
709
710 return reply.readInt32();
711 }
712
Jeff Tinkerc0d5f1f2013-04-02 13:08:05 -0700713 virtual status_t setListener(const sp<IDrmClient>& listener) {
714 Parcel data, reply;
715 data.writeInterfaceToken(IDrm::getInterfaceDescriptor());
Marco Nelissen06b46062014-11-14 07:58:25 -0800716 data.writeStrongBinder(IInterface::asBinder(listener));
Jeff Tinker3b5401a2015-06-15 17:42:10 -0700717 status_t status = remote()->transact(SET_LISTENER, data, &reply);
718 if (status != OK) {
719 return status;
720 }
Jeff Tinkerc0d5f1f2013-04-02 13:08:05 -0700721 return reply.readInt32();
722 }
723
Jeff Tinker441a78d2013-02-08 10:18:35 -0800724private:
Jeff Tinker4c63a232013-03-30 16:19:44 -0700725 void readVector(Parcel &reply, Vector<uint8_t> &vector) const {
726 uint32_t size = reply.readInt32();
727 vector.insertAt((size_t)0, size);
728 reply.read(vector.editArray(), size);
729 }
730
731 void writeVector(Parcel &data, Vector<uint8_t> const &vector) const {
732 data.writeInt32(vector.size());
733 data.write(vector.array(), vector.size());
734 }
735
Jeff Tinker441a78d2013-02-08 10:18:35 -0800736 DISALLOW_EVIL_CONSTRUCTORS(BpDrm);
737};
738
739IMPLEMENT_META_INTERFACE(Drm, "android.drm.IDrm");
740
741////////////////////////////////////////////////////////////////////////////////
742
Jeff Tinker4c63a232013-03-30 16:19:44 -0700743void BnDrm::readVector(const Parcel &data, Vector<uint8_t> &vector) const {
744 uint32_t size = data.readInt32();
Jeff Tinkerb41a5272017-10-09 11:52:18 -0700745 if (vector.insertAt((size_t)0, size) < 0) {
746 vector.clear();
747 }
748 if (data.read(vector.editArray(), size) != NO_ERROR) {
749 vector.clear();
750 android_errorWriteWithInfoLog(0x534e4554, "62872384", -1, NULL, 0);
751 }
Jeff Tinker4c63a232013-03-30 16:19:44 -0700752}
753
754void BnDrm::writeVector(Parcel *reply, Vector<uint8_t> const &vector) const {
755 reply->writeInt32(vector.size());
756 reply->write(vector.array(), vector.size());
757}
758
Jeff Tinker441a78d2013-02-08 10:18:35 -0800759status_t BnDrm::onTransact(
760 uint32_t code, const Parcel &data, Parcel *reply, uint32_t flags) {
761 switch (code) {
762 case INIT_CHECK:
763 {
764 CHECK_INTERFACE(IDrm, data, reply);
765 reply->writeInt32(initCheck());
766 return OK;
767 }
768
769 case IS_CRYPTO_SUPPORTED:
770 {
771 CHECK_INTERFACE(IDrm, data, reply);
772 uint8_t uuid[16];
773 data.read(uuid, sizeof(uuid));
Jeff Tinker9cf69e02013-08-21 11:59:23 -0700774 String8 mimeType = data.readString8();
Jeff Tinker99dbfa82019-01-17 17:27:06 -0800775 DrmPlugin::SecurityLevel level =
776 static_cast<DrmPlugin::SecurityLevel>(data.readInt32());
Jeff Tinkerdb3fa5f2019-01-25 22:56:56 -0800777 bool isSupported = false;
778 status_t result = isCryptoSchemeSupported(uuid, mimeType, level, &isSupported);
779 reply->writeInt32(isSupported);
780 reply->writeInt32(result);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800781 return OK;
782 }
783
784 case CREATE_PLUGIN:
785 {
786 CHECK_INTERFACE(IDrm, data, reply);
787 uint8_t uuid[16];
788 data.read(uuid, sizeof(uuid));
Edwin Wong68b3d9f2017-01-06 19:07:54 -0800789 String8 appPackageName = data.readString8();
790 reply->writeInt32(createPlugin(uuid, appPackageName));
Jeff Tinker441a78d2013-02-08 10:18:35 -0800791 return OK;
792 }
793
794 case DESTROY_PLUGIN:
795 {
796 CHECK_INTERFACE(IDrm, data, reply);
797 reply->writeInt32(destroyPlugin());
798 return OK;
799 }
800
801 case OPEN_SESSION:
802 {
803 CHECK_INTERFACE(IDrm, data, reply);
Jeff Tinker41d279a2018-02-11 19:52:08 +0000804 DrmPlugin::SecurityLevel level =
805 static_cast<DrmPlugin::SecurityLevel>(data.readInt32());
Jeff Tinker441a78d2013-02-08 10:18:35 -0800806 Vector<uint8_t> sessionId;
Jeff Tinker41d279a2018-02-11 19:52:08 +0000807 status_t result = openSession(level, sessionId);
Jeff Tinker4c63a232013-03-30 16:19:44 -0700808 writeVector(reply, sessionId);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800809 reply->writeInt32(result);
810 return OK;
811 }
812
813 case CLOSE_SESSION:
814 {
815 CHECK_INTERFACE(IDrm, data, reply);
816 Vector<uint8_t> sessionId;
Jeff Tinker4c63a232013-03-30 16:19:44 -0700817 readVector(data, sessionId);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800818 reply->writeInt32(closeSession(sessionId));
819 return OK;
820 }
821
Jeff Tinker4c63a232013-03-30 16:19:44 -0700822 case GET_KEY_REQUEST:
Jeff Tinker441a78d2013-02-08 10:18:35 -0800823 {
824 CHECK_INTERFACE(IDrm, data, reply);
Jeff Tinker4c63a232013-03-30 16:19:44 -0700825 Vector<uint8_t> sessionId, initData;
Jeff Tinker441a78d2013-02-08 10:18:35 -0800826
Jeff Tinker4c63a232013-03-30 16:19:44 -0700827 readVector(data, sessionId);
828 readVector(data, initData);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800829 String8 mimeType = data.readString8();
Jeff Tinker4c63a232013-03-30 16:19:44 -0700830 DrmPlugin::KeyType keyType = (DrmPlugin::KeyType)data.readInt32();
Jeff Tinker441a78d2013-02-08 10:18:35 -0800831
832 KeyedVector<String8, String8> optionalParameters;
833 uint32_t count = data.readInt32();
834 for (size_t i = 0; i < count; ++i) {
835 String8 key, value;
836 key = data.readString8();
837 value = data.readString8();
838 optionalParameters.add(key, value);
839 }
840
841 Vector<uint8_t> request;
842 String8 defaultUrl;
Jeff Tinker8aff7772016-02-08 17:52:25 -0800843 DrmPlugin::KeyRequestType keyRequestType = DrmPlugin::kKeyRequestType_Unknown;
Jeff Tinker441a78d2013-02-08 10:18:35 -0800844
Jeff Tinkerd072c902015-03-16 13:39:29 -0700845 status_t result = getKeyRequest(sessionId, initData, mimeType,
846 keyType, optionalParameters, request, defaultUrl,
847 &keyRequestType);
848
Jeff Tinker4c63a232013-03-30 16:19:44 -0700849 writeVector(reply, request);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800850 reply->writeString8(defaultUrl);
Jeff Tinkerd072c902015-03-16 13:39:29 -0700851 reply->writeInt32(static_cast<int32_t>(keyRequestType));
Jeff Tinker441a78d2013-02-08 10:18:35 -0800852 reply->writeInt32(result);
853 return OK;
854 }
855
Jeff Tinker4c63a232013-03-30 16:19:44 -0700856 case PROVIDE_KEY_RESPONSE:
Jeff Tinker441a78d2013-02-08 10:18:35 -0800857 {
858 CHECK_INTERFACE(IDrm, data, reply);
Jeff Tinker4c63a232013-03-30 16:19:44 -0700859 Vector<uint8_t> sessionId, response, keySetId;
860 readVector(data, sessionId);
861 readVector(data, response);
862 uint32_t result = provideKeyResponse(sessionId, response, keySetId);
863 writeVector(reply, keySetId);
864 reply->writeInt32(result);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800865 return OK;
866 }
867
Jeff Tinker4c63a232013-03-30 16:19:44 -0700868 case REMOVE_KEYS:
Jeff Tinker441a78d2013-02-08 10:18:35 -0800869 {
870 CHECK_INTERFACE(IDrm, data, reply);
Jeff Tinker4c63a232013-03-30 16:19:44 -0700871 Vector<uint8_t> keySetId;
872 readVector(data, keySetId);
873 reply->writeInt32(removeKeys(keySetId));
Jeff Tinker441a78d2013-02-08 10:18:35 -0800874 return OK;
875 }
876
Jeff Tinker4c63a232013-03-30 16:19:44 -0700877 case RESTORE_KEYS:
878 {
879 CHECK_INTERFACE(IDrm, data, reply);
880 Vector<uint8_t> sessionId, keySetId;
881 readVector(data, sessionId);
882 readVector(data, keySetId);
883 reply->writeInt32(restoreKeys(sessionId, keySetId));
884 return OK;
885 }
886
887 case QUERY_KEY_STATUS:
Jeff Tinker441a78d2013-02-08 10:18:35 -0800888 {
889 CHECK_INTERFACE(IDrm, data, reply);
890 Vector<uint8_t> sessionId;
Jeff Tinker4c63a232013-03-30 16:19:44 -0700891 readVector(data, sessionId);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800892 KeyedVector<String8, String8> infoMap;
Jeff Tinker4c63a232013-03-30 16:19:44 -0700893 status_t result = queryKeyStatus(sessionId, infoMap);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800894 size_t count = infoMap.size();
895 reply->writeInt32(count);
896 for (size_t i = 0; i < count; ++i) {
897 reply->writeString8(infoMap.keyAt(i));
898 reply->writeString8(infoMap.valueAt(i));
899 }
900 reply->writeInt32(result);
901 return OK;
902 }
903
904 case GET_PROVISION_REQUEST:
905 {
906 CHECK_INTERFACE(IDrm, data, reply);
Jeff Tinker68d9d712014-03-04 13:21:31 -0800907 String8 certType = data.readString8();
908 String8 certAuthority = data.readString8();
909
Jeff Tinker441a78d2013-02-08 10:18:35 -0800910 Vector<uint8_t> request;
911 String8 defaultUrl;
Jeff Tinker68d9d712014-03-04 13:21:31 -0800912 status_t result = getProvisionRequest(certType, certAuthority,
913 request, defaultUrl);
Jeff Tinker4c63a232013-03-30 16:19:44 -0700914 writeVector(reply, request);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800915 reply->writeString8(defaultUrl);
916 reply->writeInt32(result);
917 return OK;
918 }
919
920 case PROVIDE_PROVISION_RESPONSE:
921 {
922 CHECK_INTERFACE(IDrm, data, reply);
923 Vector<uint8_t> response;
Jeff Tinker68d9d712014-03-04 13:21:31 -0800924 Vector<uint8_t> certificate;
925 Vector<uint8_t> wrappedKey;
Jeff Tinker4c63a232013-03-30 16:19:44 -0700926 readVector(data, response);
Jeff Tinker68d9d712014-03-04 13:21:31 -0800927 status_t result = provideProvisionResponse(response, certificate, wrappedKey);
928 writeVector(reply, certificate);
929 writeVector(reply, wrappedKey);
930 reply->writeInt32(result);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800931 return OK;
932 }
933
934 case GET_SECURE_STOPS:
935 {
936 CHECK_INTERFACE(IDrm, data, reply);
937 List<Vector<uint8_t> > secureStops;
938 status_t result = getSecureStops(secureStops);
939 size_t count = secureStops.size();
940 reply->writeInt32(count);
941 List<Vector<uint8_t> >::iterator iter = secureStops.begin();
942 while(iter != secureStops.end()) {
943 size_t size = iter->size();
944 reply->writeInt32(size);
945 reply->write(iter->array(), iter->size());
Jeff Tinker423e33c2013-04-08 15:23:17 -0700946 iter++;
Jeff Tinker441a78d2013-02-08 10:18:35 -0800947 }
948 reply->writeInt32(result);
949 return OK;
950 }
951
Jeff Tinker15177d72018-01-25 12:57:55 -0800952 case GET_SECURE_STOP_IDS:
953 {
954 CHECK_INTERFACE(IDrm, data, reply);
955 List<Vector<uint8_t> > secureStopIds;
956 status_t result = getSecureStopIds(secureStopIds);
957 size_t count = secureStopIds.size();
958 reply->writeInt32(count);
959 List<Vector<uint8_t> >::iterator iter = secureStopIds.begin();
960 while(iter != secureStopIds.end()) {
961 size_t size = iter->size();
962 reply->writeInt32(size);
963 reply->write(iter->array(), iter->size());
964 iter++;
965 }
966 reply->writeInt32(result);
967 return OK;
968 }
969
Jeff Tinker3c1285e2014-10-31 00:55:16 -0700970 case GET_SECURE_STOP:
971 {
972 CHECK_INTERFACE(IDrm, data, reply);
973 Vector<uint8_t> ssid, secureStop;
974 readVector(data, ssid);
975 status_t result = getSecureStop(ssid, secureStop);
976 writeVector(reply, secureStop);
977 reply->writeInt32(result);
978 return OK;
979 }
980
Jeff Tinker441a78d2013-02-08 10:18:35 -0800981 case RELEASE_SECURE_STOPS:
982 {
983 CHECK_INTERFACE(IDrm, data, reply);
984 Vector<uint8_t> ssRelease;
Jeff Tinker4c63a232013-03-30 16:19:44 -0700985 readVector(data, ssRelease);
Jeff Tinker441a78d2013-02-08 10:18:35 -0800986 reply->writeInt32(releaseSecureStops(ssRelease));
987 return OK;
988 }
989
Jeff Tinker15177d72018-01-25 12:57:55 -0800990 case REMOVE_SECURE_STOP:
Jeff Tinker3c1285e2014-10-31 00:55:16 -0700991 {
992 CHECK_INTERFACE(IDrm, data, reply);
Jeff Tinker15177d72018-01-25 12:57:55 -0800993 Vector<uint8_t> ssid;
994 readVector(data, ssid);
995 reply->writeInt32(removeSecureStop(ssid));
996 return OK;
997 }
998
999 case REMOVE_ALL_SECURE_STOPS:
1000 {
1001 CHECK_INTERFACE(IDrm, data, reply);
1002 reply->writeInt32(removeAllSecureStops());
Jeff Tinker3c1285e2014-10-31 00:55:16 -07001003 return OK;
1004 }
1005
Jeff Tinker6d998b62017-12-18 14:37:43 -08001006 case GET_HDCP_LEVELS:
1007 {
1008 CHECK_INTERFACE(IDrm, data, reply);
1009 DrmPlugin::HdcpLevel connected = DrmPlugin::kHdcpLevelUnknown;
1010 DrmPlugin::HdcpLevel max = DrmPlugin::kHdcpLevelUnknown;
1011 status_t result = getHdcpLevels(&connected, &max);
1012 reply->writeInt32(connected);
1013 reply->writeInt32(max);
1014 reply->writeInt32(result);
1015 return OK;
1016 }
1017
1018 case GET_NUMBER_OF_SESSIONS:
1019 {
1020 CHECK_INTERFACE(IDrm, data, reply);
1021 uint32_t open = 0, max = 0;
1022 status_t result = getNumberOfSessions(&open, &max);
1023 reply->writeInt32(open);
1024 reply->writeInt32(max);
1025 reply->writeInt32(result);
1026 return OK;
1027 }
1028
1029 case GET_SECURITY_LEVEL:
1030 {
1031 CHECK_INTERFACE(IDrm, data, reply);
1032 Vector<uint8_t> sessionId;
1033 readVector(data, sessionId);
1034 DrmPlugin::SecurityLevel level = DrmPlugin::kSecurityLevelUnknown;
1035 status_t result = getSecurityLevel(sessionId, &level);
1036 reply->writeInt32(level);
1037 reply->writeInt32(result);
1038 return OK;
1039 }
1040
Jeff Tinkerc8baaba2018-10-23 11:32:36 -07001041 case GET_OFFLINE_LICENSE_KEYSET_IDS:
1042 {
1043 CHECK_INTERFACE(IDrm, data, reply);
1044 List<Vector<uint8_t> > keySetIds;
1045 status_t result = getOfflineLicenseKeySetIds(keySetIds);
1046 size_t count = keySetIds.size();
1047 reply->writeInt32(count);
1048 List<Vector<uint8_t> >::iterator iter = keySetIds.begin();
1049 while(iter != keySetIds.end()) {
1050 size_t size = iter->size();
1051 reply->writeInt32(size);
1052 reply->write(iter->array(), iter->size());
1053 iter++;
1054 }
1055 reply->writeInt32(result);
1056 return OK;
1057 }
1058
1059 case REMOVE_OFFLINE_LICENSE:
1060 {
1061 CHECK_INTERFACE(IDrm, data, reply);
1062 Vector<uint8_t> keySetId;
1063 readVector(data, keySetId);
1064 reply->writeInt32(removeOfflineLicense(keySetId));
1065 return OK;
1066 }
1067
1068 case GET_OFFLINE_LICENSE_STATE:
1069 {
1070 CHECK_INTERFACE(IDrm, data, reply);
1071 Vector<uint8_t> keySetId;
1072 readVector(data, keySetId);
1073 DrmPlugin::OfflineLicenseState state;
1074 status_t result = getOfflineLicenseState(keySetId, &state);
1075 reply->writeInt32(static_cast<DrmPlugin::OfflineLicenseState>(state));
1076 reply->writeInt32(result);
1077 return OK;
1078 }
1079
Jeff Tinker441a78d2013-02-08 10:18:35 -08001080 case GET_PROPERTY_STRING:
1081 {
1082 CHECK_INTERFACE(IDrm, data, reply);
1083 String8 name = data.readString8();
1084 String8 value;
1085 status_t result = getPropertyString(name, value);
1086 reply->writeString8(value);
1087 reply->writeInt32(result);
1088 return OK;
1089 }
1090
1091 case GET_PROPERTY_BYTE_ARRAY:
1092 {
1093 CHECK_INTERFACE(IDrm, data, reply);
1094 String8 name = data.readString8();
1095 Vector<uint8_t> value;
1096 status_t result = getPropertyByteArray(name, value);
Jeff Tinker4c63a232013-03-30 16:19:44 -07001097 writeVector(reply, value);
Jeff Tinker441a78d2013-02-08 10:18:35 -08001098 reply->writeInt32(result);
1099 return OK;
1100 }
1101
1102 case SET_PROPERTY_STRING:
1103 {
1104 CHECK_INTERFACE(IDrm, data, reply);
1105 String8 name = data.readString8();
1106 String8 value = data.readString8();
1107 reply->writeInt32(setPropertyString(name, value));
1108 return OK;
1109 }
1110
1111 case SET_PROPERTY_BYTE_ARRAY:
1112 {
1113 CHECK_INTERFACE(IDrm, data, reply);
1114 String8 name = data.readString8();
1115 Vector<uint8_t> value;
Jeff Tinker4c63a232013-03-30 16:19:44 -07001116 readVector(data, value);
Jeff Tinker441a78d2013-02-08 10:18:35 -08001117 reply->writeInt32(setPropertyByteArray(name, value));
1118 return OK;
1119 }
1120
Adam Stoneab394d12017-12-22 12:34:20 -08001121 case GET_METRICS:
1122 {
1123 CHECK_INTERFACE(IDrm, data, reply);
1124
Adam Stone637b7852018-01-30 12:09:36 -08001125 os::PersistableBundle metrics;
1126 status_t result = getMetrics(&metrics);
Adam Stone568b3c42018-01-31 12:57:16 -08001127 // The reply data is ordered as
1128 // 1) 32 bit integer reply followed by
1129 // 2) Serialized PersistableBundle containing metrics.
1130 // Only write the metrics if the getMetrics result was
1131 // OK and we successfully added the status to reply.
1132 status_t parcel_result = reply->writeInt32(result);
1133 if (result == OK && parcel_result == OK) {
1134 parcel_result = metrics.writeToParcel(reply);
1135 }
1136 return parcel_result;
Adam Stoneab394d12017-12-22 12:34:20 -08001137 }
1138
Jeff Tinker4c63a232013-03-30 16:19:44 -07001139 case SET_CIPHER_ALGORITHM:
1140 {
1141 CHECK_INTERFACE(IDrm, data, reply);
1142 Vector<uint8_t> sessionId;
1143 readVector(data, sessionId);
1144 String8 algorithm = data.readString8();
1145 reply->writeInt32(setCipherAlgorithm(sessionId, algorithm));
1146 return OK;
1147 }
1148
1149 case SET_MAC_ALGORITHM:
1150 {
1151 CHECK_INTERFACE(IDrm, data, reply);
1152 Vector<uint8_t> sessionId;
1153 readVector(data, sessionId);
1154 String8 algorithm = data.readString8();
1155 reply->writeInt32(setMacAlgorithm(sessionId, algorithm));
1156 return OK;
1157 }
1158
1159 case ENCRYPT:
1160 {
1161 CHECK_INTERFACE(IDrm, data, reply);
1162 Vector<uint8_t> sessionId, keyId, input, iv, output;
1163 readVector(data, sessionId);
1164 readVector(data, keyId);
1165 readVector(data, input);
1166 readVector(data, iv);
1167 uint32_t result = encrypt(sessionId, keyId, input, iv, output);
1168 writeVector(reply, output);
1169 reply->writeInt32(result);
1170 return OK;
1171 }
1172
1173 case DECRYPT:
1174 {
1175 CHECK_INTERFACE(IDrm, data, reply);
1176 Vector<uint8_t> sessionId, keyId, input, iv, output;
1177 readVector(data, sessionId);
1178 readVector(data, keyId);
1179 readVector(data, input);
1180 readVector(data, iv);
1181 uint32_t result = decrypt(sessionId, keyId, input, iv, output);
1182 writeVector(reply, output);
1183 reply->writeInt32(result);
1184 return OK;
1185 }
1186
1187 case SIGN:
1188 {
1189 CHECK_INTERFACE(IDrm, data, reply);
1190 Vector<uint8_t> sessionId, keyId, message, signature;
1191 readVector(data, sessionId);
1192 readVector(data, keyId);
1193 readVector(data, message);
1194 uint32_t result = sign(sessionId, keyId, message, signature);
1195 writeVector(reply, signature);
1196 reply->writeInt32(result);
1197 return OK;
1198 }
1199
1200 case VERIFY:
1201 {
1202 CHECK_INTERFACE(IDrm, data, reply);
1203 Vector<uint8_t> sessionId, keyId, message, signature;
1204 readVector(data, sessionId);
1205 readVector(data, keyId);
1206 readVector(data, message);
1207 readVector(data, signature);
Jeff Tinker9a6861c2016-09-02 11:36:46 -07001208 bool match = false;
Jeff Tinker4c63a232013-03-30 16:19:44 -07001209 uint32_t result = verify(sessionId, keyId, message, signature, match);
1210 reply->writeInt32(match);
1211 reply->writeInt32(result);
1212 return OK;
1213 }
1214
Jeff Tinker68d9d712014-03-04 13:21:31 -08001215 case SIGN_RSA:
1216 {
1217 CHECK_INTERFACE(IDrm, data, reply);
1218 Vector<uint8_t> sessionId, message, wrappedKey, signature;
1219 readVector(data, sessionId);
1220 String8 algorithm = data.readString8();
1221 readVector(data, message);
1222 readVector(data, wrappedKey);
1223 uint32_t result = signRSA(sessionId, algorithm, message, wrappedKey, signature);
1224 writeVector(reply, signature);
1225 reply->writeInt32(result);
1226 return OK;
1227 }
1228
Jeff Tinkerc0d5f1f2013-04-02 13:08:05 -07001229 case SET_LISTENER: {
1230 CHECK_INTERFACE(IDrm, data, reply);
1231 sp<IDrmClient> listener =
1232 interface_cast<IDrmClient>(data.readStrongBinder());
1233 reply->writeInt32(setListener(listener));
1234 return NO_ERROR;
1235 } break;
1236
Jeff Tinker4c63a232013-03-30 16:19:44 -07001237 default:
1238 return BBinder::onTransact(code, data, reply, flags);
Jeff Tinker441a78d2013-02-08 10:18:35 -08001239 }
1240}
1241
1242} // namespace android