blob: fca42619671d6e7d50d7547b9455ee822f83c6eb [file] [log] [blame]
aimitakeshi27ed8ad2010-07-29 10:12:27 +09001/*
2 * Copyright (C) 2010 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
Takeshi Aimi2272ee22010-09-20 23:40:41 +090017//#define LOG_NDEBUG 0
aimitakeshi27ed8ad2010-07-29 10:12:27 +090018#define LOG_TAG "IDrmManagerService(Native)"
19#include <utils/Log.h>
20
21#include <stdint.h>
22#include <sys/types.h>
23#include <binder/IPCThreadState.h>
24
25#include <drm/DrmInfo.h>
26#include <drm/DrmConstraints.h>
27#include <drm/DrmRights.h>
28#include <drm/DrmInfoStatus.h>
29#include <drm/DrmConvertedStatus.h>
30#include <drm/DrmInfoRequest.h>
31#include <drm/DrmSupportInfo.h>
32
33#include "IDrmManagerService.h"
34
35#define INVALID_BUFFER_LENGTH -1
36
37using namespace android;
38
Takeshi Aimi2272ee22010-09-20 23:40:41 +090039int BpDrmManagerService::addUniqueId(int uniqueId) {
40 LOGV("add uniqueid");
41 Parcel data, reply;
42 data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
43 data.writeInt32(uniqueId);
44 remote()->transact(ADD_UNIQUEID, data, &reply);
45 return reply.readInt32();
46}
47
48void BpDrmManagerService::removeUniqueId(int uniqueId) {
49 LOGV("remove uniqueid");
50 Parcel data, reply;
51 data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
52 data.writeInt32(uniqueId);
53 remote()->transact(REMOVE_UNIQUEID, data, &reply);
54}
55
Takeshi Aimie943f842010-10-08 23:05:49 +090056void BpDrmManagerService::addClient(int uniqueId) {
aimitakeshi27ed8ad2010-07-29 10:12:27 +090057 Parcel data, reply;
aimitakeshi27ed8ad2010-07-29 10:12:27 +090058 data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
59 data.writeInt32(uniqueId);
Takeshi Aimie943f842010-10-08 23:05:49 +090060 remote()->transact(ADD_CLIENT, data, &reply);
aimitakeshi27ed8ad2010-07-29 10:12:27 +090061}
62
Takeshi Aimie943f842010-10-08 23:05:49 +090063void BpDrmManagerService::removeClient(int uniqueId) {
aimitakeshi27ed8ad2010-07-29 10:12:27 +090064 Parcel data, reply;
aimitakeshi27ed8ad2010-07-29 10:12:27 +090065 data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
66 data.writeInt32(uniqueId);
Takeshi Aimie943f842010-10-08 23:05:49 +090067 remote()->transact(REMOVE_CLIENT, data, &reply);
aimitakeshi27ed8ad2010-07-29 10:12:27 +090068}
69
70status_t BpDrmManagerService::setDrmServiceListener(
71 int uniqueId, const sp<IDrmServiceListener>& drmServiceListener) {
72 LOGV("setDrmServiceListener");
73 Parcel data, reply;
74
75 data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
76 data.writeInt32(uniqueId);
77 data.writeStrongBinder(drmServiceListener->asBinder());
78 remote()->transact(SET_DRM_SERVICE_LISTENER, data, &reply);
79 return reply.readInt32();
80}
81
aimitakeshi27ed8ad2010-07-29 10:12:27 +090082status_t BpDrmManagerService::installDrmEngine(int uniqueId, const String8& drmEngineFile) {
83 LOGV("Install DRM Engine");
84 Parcel data, reply;
85
86 data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
87 data.writeInt32(uniqueId);
88 data.writeString8(drmEngineFile);
89
90 remote()->transact(INSTALL_DRM_ENGINE, data, &reply);
91 return reply.readInt32();
92}
93
94DrmConstraints* BpDrmManagerService::getConstraints(
95 int uniqueId, const String8* path, const int action) {
96 LOGV("Get Constraints");
97 Parcel data, reply;
98
99 data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
100 data.writeInt32(uniqueId);
101 data.writeString8(*path);
102 data.writeInt32(action);
103
104 remote()->transact(GET_CONSTRAINTS_FROM_CONTENT, data, &reply);
105
106 DrmConstraints* drmConstraints = NULL;
107 if (0 != reply.dataAvail()) {
108 //Filling Drm Constraints
109 drmConstraints = new DrmConstraints();
110
111 const int size = reply.readInt32();
112 for (int index = 0; index < size; ++index) {
113 const String8 key(reply.readString8());
114 const int bufferSize = reply.readInt32();
115 char* data = NULL;
116 if (0 < bufferSize) {
117 data = new char[bufferSize];
118 reply.read(data, bufferSize);
119 }
120 drmConstraints->put(&key, data);
121 }
122 }
123 return drmConstraints;
124}
125
126bool BpDrmManagerService::canHandle(int uniqueId, const String8& path, const String8& mimeType) {
127 LOGV("Can Handle");
128 Parcel data, reply;
129
130 data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
131 data.writeInt32(uniqueId);
132
133 data.writeString8(path);
134 data.writeString8(mimeType);
135
136 remote()->transact(CAN_HANDLE, data, &reply);
137
138 return static_cast<bool>(reply.readInt32());
139}
140
141DrmInfoStatus* BpDrmManagerService::processDrmInfo(int uniqueId, const DrmInfo* drmInfo) {
142 LOGV("Process DRM Info");
143 Parcel data, reply;
144
145 data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
146 data.writeInt32(uniqueId);
147
148 //Filling DRM info
149 data.writeInt32(drmInfo->getInfoType());
150 const DrmBuffer dataBuffer = drmInfo->getData();
151 const int dataBufferSize = dataBuffer.length;
152 data.writeInt32(dataBufferSize);
153 if (0 < dataBufferSize) {
154 data.write(dataBuffer.data, dataBufferSize);
155 }
156 data.writeString8(drmInfo->getMimeType());
157
158 data.writeInt32(drmInfo->getCount());
159 DrmInfo::KeyIterator keyIt = drmInfo->keyIterator();
160
161 while (keyIt.hasNext()) {
162 const String8 key = keyIt.next();
163 data.writeString8(key);
164 const String8 value = drmInfo->get(key);
165 data.writeString8((value == String8("")) ? String8("NULL") : value);
166 }
167
168 remote()->transact(PROCESS_DRM_INFO, data, &reply);
169
170 DrmInfoStatus* drmInfoStatus = NULL;
171 if (0 != reply.dataAvail()) {
172 //Filling DRM Info Status
173 const int statusCode = reply.readInt32();
Takeshi Aimie943f842010-10-08 23:05:49 +0900174 const int infoType = reply.readInt32();
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900175 const String8 mimeType = reply.readString8();
176
177 DrmBuffer* drmBuffer = NULL;
178 if (0 != reply.dataAvail()) {
179 const int bufferSize = reply.readInt32();
180 char* data = NULL;
181 if (0 < bufferSize) {
182 data = new char[bufferSize];
183 reply.read(data, bufferSize);
184 }
185 drmBuffer = new DrmBuffer(data, bufferSize);
186 }
Takeshi Aimie943f842010-10-08 23:05:49 +0900187 drmInfoStatus = new DrmInfoStatus(statusCode, infoType, drmBuffer, mimeType);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900188 }
189 return drmInfoStatus;
190}
191
192DrmInfo* BpDrmManagerService::acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInforequest) {
193 LOGV("Acquire DRM Info");
194 Parcel data, reply;
195
196 data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
197 data.writeInt32(uniqueId);
198
199 //Filling DRM Info Request
200 data.writeInt32(drmInforequest->getInfoType());
201 data.writeString8(drmInforequest->getMimeType());
202
203 data.writeInt32(drmInforequest->getCount());
204 DrmInfoRequest::KeyIterator keyIt = drmInforequest->keyIterator();
205
206 while (keyIt.hasNext()) {
207 const String8 key = keyIt.next();
208 data.writeString8(key);
209 const String8 value = drmInforequest->get(key);
210 data.writeString8((value == String8("")) ? String8("NULL") : value);
211 }
212
213 remote()->transact(ACQUIRE_DRM_INFO, data, &reply);
214
215 DrmInfo* drmInfo = NULL;
216 if (0 != reply.dataAvail()) {
217 //Filling DRM Info
218 const int infoType = reply.readInt32();
219 const int bufferSize = reply.readInt32();
220 char* data = NULL;
221
222 if (0 < bufferSize) {
223 data = new char[bufferSize];
224 reply.read(data, bufferSize);
225 }
226 drmInfo = new DrmInfo(infoType, DrmBuffer(data, bufferSize), reply.readString8());
227
228 const int size = reply.readInt32();
229 for (int index = 0; index < size; ++index) {
230 const String8 key(reply.readString8());
231 const String8 value(reply.readString8());
232 drmInfo->put(key, (value == String8("NULL")) ? String8("") : value);
233 }
234 }
235 return drmInfo;
236}
237
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900238status_t BpDrmManagerService::saveRights(
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900239 int uniqueId, const DrmRights& drmRights,
240 const String8& rightsPath, const String8& contentPath) {
241 LOGV("Save Rights");
242 Parcel data, reply;
243
244 data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
245 data.writeInt32(uniqueId);
246
247 //Filling Drm Rights
248 const DrmBuffer dataBuffer = drmRights.getData();
249 data.writeInt32(dataBuffer.length);
250 data.write(dataBuffer.data, dataBuffer.length);
251
252 const String8 mimeType = drmRights.getMimeType();
253 data.writeString8((mimeType == String8("")) ? String8("NULL") : mimeType);
254
255 const String8 accountId = drmRights.getAccountId();
256 data.writeString8((accountId == String8("")) ? String8("NULL") : accountId);
257
258 const String8 subscriptionId = drmRights.getSubscriptionId();
259 data.writeString8((subscriptionId == String8("")) ? String8("NULL") : subscriptionId);
260
261 data.writeString8((rightsPath == String8("")) ? String8("NULL") : rightsPath);
262 data.writeString8((contentPath == String8("")) ? String8("NULL") : contentPath);
263
264 remote()->transact(SAVE_RIGHTS, data, &reply);
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900265 return reply.readInt32();
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900266}
267
268String8 BpDrmManagerService::getOriginalMimeType(int uniqueId, const String8& path) {
269 LOGV("Get Original MimeType");
270 Parcel data, reply;
271
272 data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
273 data.writeInt32(uniqueId);
274 data.writeString8(path);
275
276 remote()->transact(GET_ORIGINAL_MIMETYPE, data, &reply);
277 return reply.readString8();
278}
279
280int BpDrmManagerService::getDrmObjectType(
281 int uniqueId, const String8& path, const String8& mimeType) {
282 LOGV("Get Drm object type");
283 Parcel data, reply;
284
285 data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
286 data.writeInt32(uniqueId);
287 data.writeString8(path);
288 data.writeString8(mimeType);
289
290 remote()->transact(GET_DRM_OBJECT_TYPE, data, &reply);
291
292 return reply.readInt32();
293}
294
295int BpDrmManagerService::checkRightsStatus(int uniqueId, const String8& path, int action) {
296 LOGV("checkRightsStatus");
297 Parcel data, reply;
298
299 data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
300 data.writeInt32(uniqueId);
301 data.writeString8(path);
302 data.writeInt32(action);
303
304 remote()->transact(CHECK_RIGHTS_STATUS, data, &reply);
305
306 return reply.readInt32();
307}
308
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900309status_t BpDrmManagerService::consumeRights(
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900310 int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) {
311 LOGV("consumeRights");
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900312 Parcel data, reply;
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900313
314 data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
315 data.writeInt32(uniqueId);
316
317 data.writeInt32(decryptHandle->decryptId);
318 data.writeString8(decryptHandle->mimeType);
319 data.writeInt32(decryptHandle->decryptApiType);
320 data.writeInt32(decryptHandle->status);
321
322 if (NULL != decryptHandle->decryptInfo) {
323 data.writeInt32(decryptHandle->decryptInfo->decryptBufferLength);
324 } else {
325 data.writeInt32(INVALID_BUFFER_LENGTH);
326 }
327
328 data.writeInt32(action);
329 data.writeInt32(static_cast< int>(reserve));
330
331 remote()->transact(CONSUME_RIGHTS, data, &reply);
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900332 return reply.readInt32();
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900333}
334
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900335status_t BpDrmManagerService::setPlaybackStatus(
Gloria Wanga2cd44c2010-11-19 15:19:36 -0800336 int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int64_t position) {
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900337 LOGV("setPlaybackStatus");
338 Parcel data, reply;
339
340 data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
341 data.writeInt32(uniqueId);
342
343 data.writeInt32(decryptHandle->decryptId);
344 data.writeString8(decryptHandle->mimeType);
345 data.writeInt32(decryptHandle->decryptApiType);
346 data.writeInt32(decryptHandle->status);
347
348 if (NULL != decryptHandle->decryptInfo) {
349 data.writeInt32(decryptHandle->decryptInfo->decryptBufferLength);
350 } else {
351 data.writeInt32(INVALID_BUFFER_LENGTH);
352 }
353
354 data.writeInt32(playbackStatus);
355 data.writeInt32(position);
356
357 remote()->transact(SET_PLAYBACK_STATUS, data, &reply);
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900358 return reply.readInt32();
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900359}
360
361bool BpDrmManagerService::validateAction(
362 int uniqueId, const String8& path,
363 int action, const ActionDescription& description) {
364 LOGV("validateAction");
365 Parcel data, reply;
366
367 data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
368 data.writeInt32(uniqueId);
369 data.writeString8(path);
370 data.writeInt32(action);
371 data.writeInt32(description.outputType);
372 data.writeInt32(description.configuration);
373
374 remote()->transact(VALIDATE_ACTION, data, &reply);
375
376 return static_cast<bool>(reply.readInt32());
377}
378
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900379status_t BpDrmManagerService::removeRights(int uniqueId, const String8& path) {
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900380 LOGV("removeRights");
381 Parcel data, reply;
382
383 data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
384 data.writeInt32(uniqueId);
385 data.writeString8(path);
386
387 remote()->transact(REMOVE_RIGHTS, data, &reply);
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900388 return reply.readInt32();
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900389}
390
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900391status_t BpDrmManagerService::removeAllRights(int uniqueId) {
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900392 LOGV("removeAllRights");
393 Parcel data, reply;
394
395 data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
396 data.writeInt32(uniqueId);
397
398 remote()->transact(REMOVE_ALL_RIGHTS, data, &reply);
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900399 return reply.readInt32();
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900400}
401
402int BpDrmManagerService::openConvertSession(int uniqueId, const String8& mimeType) {
403 LOGV("openConvertSession");
404 Parcel data, reply;
405
406 data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
407 data.writeInt32(uniqueId);
408 data.writeString8(mimeType);
409
410 remote()->transact(OPEN_CONVERT_SESSION, data, &reply);
411 return reply.readInt32();
412}
413
414DrmConvertedStatus* BpDrmManagerService::convertData(
415 int uniqueId, int convertId, const DrmBuffer* inputData) {
416 LOGV("convertData");
417 Parcel data, reply;
418
419 data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
420 data.writeInt32(uniqueId);
421 data.writeInt32(convertId);
422 data.writeInt32(inputData->length);
423 data.write(inputData->data, inputData->length);
424
425 remote()->transact(CONVERT_DATA, data, &reply);
426
427 DrmConvertedStatus* drmConvertedStatus = NULL;
428
429 if (0 != reply.dataAvail()) {
430 //Filling DRM Converted Status
431 const int statusCode = reply.readInt32();
Gloria Wanga2cd44c2010-11-19 15:19:36 -0800432 const off64_t offset = reply.readInt64();
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900433
434 DrmBuffer* convertedData = NULL;
435 if (0 != reply.dataAvail()) {
436 const int bufferSize = reply.readInt32();
437 char* data = NULL;
438 if (0 < bufferSize) {
439 data = new char[bufferSize];
440 reply.read(data, bufferSize);
441 }
442 convertedData = new DrmBuffer(data, bufferSize);
443 }
444 drmConvertedStatus = new DrmConvertedStatus(statusCode, convertedData, offset);
445 }
446 return drmConvertedStatus;
447}
448
449DrmConvertedStatus* BpDrmManagerService::closeConvertSession(int uniqueId, int convertId) {
450 LOGV("closeConvertSession");
451 Parcel data, reply;
452
453 data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
454 data.writeInt32(uniqueId);
455 data.writeInt32(convertId);
456
457 remote()->transact(CLOSE_CONVERT_SESSION, data, &reply);
458
459 DrmConvertedStatus* drmConvertedStatus = NULL;
460
461 if (0 != reply.dataAvail()) {
462 //Filling DRM Converted Status
463 const int statusCode = reply.readInt32();
Gloria Wanga2cd44c2010-11-19 15:19:36 -0800464 const off64_t offset = reply.readInt64();
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900465
466 DrmBuffer* convertedData = NULL;
467 if (0 != reply.dataAvail()) {
468 const int bufferSize = reply.readInt32();
469 char* data = NULL;
470 if (0 < bufferSize) {
471 data = new char[bufferSize];
472 reply.read(data, bufferSize);
473 }
474 convertedData = new DrmBuffer(data, bufferSize);
475 }
476 drmConvertedStatus = new DrmConvertedStatus(statusCode, convertedData, offset);
477 }
478 return drmConvertedStatus;
479}
480
481status_t BpDrmManagerService::getAllSupportInfo(
482 int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray) {
483 LOGV("Get All Support Info");
484 Parcel data, reply;
485
486 data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
487 data.writeInt32(uniqueId);
488
489 remote()->transact(GET_ALL_SUPPORT_INFO, data, &reply);
490
491 //Filling DRM Support Info
492 const int arraySize = reply.readInt32();
493 if (0 < arraySize) {
494 *drmSupportInfoArray = new DrmSupportInfo[arraySize];
495
496 for (int index = 0; index < arraySize; ++index) {
497 DrmSupportInfo drmSupportInfo;
498
499 const int fileSuffixVectorSize = reply.readInt32();
500 for (int i = 0; i < fileSuffixVectorSize; ++i) {
501 drmSupportInfo.addFileSuffix(reply.readString8());
502 }
503
504 const int mimeTypeVectorSize = reply.readInt32();
505 for (int i = 0; i < mimeTypeVectorSize; ++i) {
506 drmSupportInfo.addMimeType(reply.readString8());
507 }
508
509 drmSupportInfo.setDescription(reply.readString8());
510 (*drmSupportInfoArray)[index] = drmSupportInfo;
511 }
512 }
513 *length = arraySize;
514 return reply.readInt32();
515}
516
517DecryptHandle* BpDrmManagerService::openDecryptSession(
Gloria Wanga2cd44c2010-11-19 15:19:36 -0800518 int uniqueId, int fd, off64_t offset, off64_t length) {
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900519 LOGV("Entering BpDrmManagerService::openDecryptSession");
520 Parcel data, reply;
521
Takeshi Aimie943f842010-10-08 23:05:49 +0900522 data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900523 data.writeInt32(uniqueId);
524 data.writeFileDescriptor(fd);
Gloria Wanga2cd44c2010-11-19 15:19:36 -0800525 data.writeInt64(offset);
526 data.writeInt64(length);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900527
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900528 remote()->transact(OPEN_DECRYPT_SESSION, data, &reply);
529
530 DecryptHandle* handle = NULL;
531 if (0 != reply.dataAvail()) {
532 handle = new DecryptHandle();
533 handle->decryptId = reply.readInt32();
534 handle->mimeType = reply.readString8();
535 handle->decryptApiType = reply.readInt32();
536 handle->status = reply.readInt32();
537 handle->decryptInfo = NULL;
538 if (0 != reply.dataAvail()) {
539 handle->decryptInfo = new DecryptInfo();
540 handle->decryptInfo->decryptBufferLength = reply.readInt32();
541 }
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900542 }
543 return handle;
544}
545
Takeshi Aimie943f842010-10-08 23:05:49 +0900546DecryptHandle* BpDrmManagerService::openDecryptSession(int uniqueId, const char* uri) {
547 LOGV("Entering BpDrmManagerService::openDecryptSession");
548 Parcel data, reply;
549
550 data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
551 data.writeInt32(uniqueId);
552 data.writeString8(String8(uri));
553
554 remote()->transact(OPEN_DECRYPT_SESSION_FROM_URI, data, &reply);
555
556 DecryptHandle* handle = NULL;
557 if (0 != reply.dataAvail()) {
558 handle = new DecryptHandle();
559 handle->decryptId = reply.readInt32();
560 handle->mimeType = reply.readString8();
561 handle->decryptApiType = reply.readInt32();
562 handle->status = reply.readInt32();
563 handle->decryptInfo = NULL;
564 if (0 != reply.dataAvail()) {
565 handle->decryptInfo = new DecryptInfo();
566 handle->decryptInfo->decryptBufferLength = reply.readInt32();
567 }
568 } else {
569 LOGE("no decryptHandle is generated in service side");
570 }
571 return handle;
572}
573
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900574status_t BpDrmManagerService::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) {
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900575 LOGV("closeDecryptSession");
576 Parcel data, reply;
577
578 data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
579 data.writeInt32(uniqueId);
580
581 data.writeInt32(decryptHandle->decryptId);
582 data.writeString8(decryptHandle->mimeType);
583 data.writeInt32(decryptHandle->decryptApiType);
584 data.writeInt32(decryptHandle->status);
585
586 if (NULL != decryptHandle->decryptInfo) {
587 data.writeInt32(decryptHandle->decryptInfo->decryptBufferLength);
588 } else {
589 data.writeInt32(INVALID_BUFFER_LENGTH);
590 }
591
592 remote()->transact(CLOSE_DECRYPT_SESSION, data, &reply);
593
594 if (NULL != decryptHandle->decryptInfo) {
595 LOGV("deleting decryptInfo");
596 delete decryptHandle->decryptInfo; decryptHandle->decryptInfo = NULL;
597 }
598 delete decryptHandle; decryptHandle = NULL;
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900599 return reply.readInt32();
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900600}
601
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900602status_t BpDrmManagerService::initializeDecryptUnit(
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900603 int uniqueId, DecryptHandle* decryptHandle,
604 int decryptUnitId, const DrmBuffer* headerInfo) {
605 LOGV("initializeDecryptUnit");
606 Parcel data, reply;
607
608 data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
609 data.writeInt32(uniqueId);
610
611 data.writeInt32(decryptHandle->decryptId);
612 data.writeString8(decryptHandle->mimeType);
613 data.writeInt32(decryptHandle->decryptApiType);
614 data.writeInt32(decryptHandle->status);
615
616 if (NULL != decryptHandle->decryptInfo) {
617 data.writeInt32(decryptHandle->decryptInfo->decryptBufferLength);
618 } else {
619 data.writeInt32(INVALID_BUFFER_LENGTH);
620 }
621 data.writeInt32(decryptUnitId);
622
623 data.writeInt32(headerInfo->length);
624 data.write(headerInfo->data, headerInfo->length);
625
626 remote()->transact(INITIALIZE_DECRYPT_UNIT, data, &reply);
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900627 return reply.readInt32();
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900628}
629
630status_t BpDrmManagerService::decrypt(
631 int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId,
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900632 const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) {
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900633 LOGV("decrypt");
634 Parcel data, reply;
635
636 data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
637 data.writeInt32(uniqueId);
638
639 data.writeInt32(decryptHandle->decryptId);
640 data.writeString8(decryptHandle->mimeType);
641 data.writeInt32(decryptHandle->decryptApiType);
642 data.writeInt32(decryptHandle->status);
643
644 if (NULL != decryptHandle->decryptInfo) {
645 data.writeInt32(decryptHandle->decryptInfo->decryptBufferLength);
646 } else {
647 data.writeInt32(INVALID_BUFFER_LENGTH);
648 }
649
650 data.writeInt32(decryptUnitId);
651 data.writeInt32((*decBuffer)->length);
652
653 data.writeInt32(encBuffer->length);
654 data.write(encBuffer->data, encBuffer->length);
655
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900656 if (NULL != IV) {
657 data.writeInt32(IV->length);
658 data.write(IV->data, IV->length);
659 }
660
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900661 remote()->transact(DECRYPT, data, &reply);
662
663 const status_t status = reply.readInt32();
664 LOGV("Return value of decrypt() is %d", status);
665
666 const int size = reply.readInt32();
667 (*decBuffer)->length = size;
668 reply.read((void *)(*decBuffer)->data, size);
669
670 return status;
671}
672
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900673status_t BpDrmManagerService::finalizeDecryptUnit(
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900674 int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) {
675 LOGV("finalizeDecryptUnit");
676 Parcel data, reply;
677
678 data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
679 data.writeInt32(uniqueId);
680
681 data.writeInt32(decryptHandle->decryptId);
682 data.writeString8(decryptHandle->mimeType);
683 data.writeInt32(decryptHandle->decryptApiType);
684 data.writeInt32(decryptHandle->status);
685
686 if (NULL != decryptHandle->decryptInfo) {
687 data.writeInt32(decryptHandle->decryptInfo->decryptBufferLength);
688 } else {
689 data.writeInt32(INVALID_BUFFER_LENGTH);
690 }
691
692 data.writeInt32(decryptUnitId);
693
694 remote()->transact(FINALIZE_DECRYPT_UNIT, data, &reply);
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900695 return reply.readInt32();
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900696}
697
698ssize_t BpDrmManagerService::pread(
699 int uniqueId, DecryptHandle* decryptHandle, void* buffer,
Gloria Wanga2cd44c2010-11-19 15:19:36 -0800700 ssize_t numBytes, off64_t offset) {
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900701 LOGV("read");
702 Parcel data, reply;
703 int result;
704
705 data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
706 data.writeInt32(uniqueId);
707
708 data.writeInt32(decryptHandle->decryptId);
709 data.writeString8(decryptHandle->mimeType);
710 data.writeInt32(decryptHandle->decryptApiType);
711 data.writeInt32(decryptHandle->status);
712
713 if (NULL != decryptHandle->decryptInfo) {
714 data.writeInt32(decryptHandle->decryptInfo->decryptBufferLength);
715 } else {
716 data.writeInt32(INVALID_BUFFER_LENGTH);
717 }
718
719 data.writeInt32(numBytes);
Gloria Wanga2cd44c2010-11-19 15:19:36 -0800720 data.writeInt64(offset);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900721
722 remote()->transact(PREAD, data, &reply);
723 result = reply.readInt32();
724 if (0 < result) {
725 reply.read(buffer, result);
726 }
727 return result;
728}
729
730IMPLEMENT_META_INTERFACE(DrmManagerService, "drm.IDrmManagerService");
731
732status_t BnDrmManagerService::onTransact(
733 uint32_t code, const Parcel& data,
734 Parcel* reply, uint32_t flags) {
735 LOGV("Entering BnDrmManagerService::onTransact with code %d", code);
736
737 switch (code) {
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900738 case ADD_UNIQUEID:
739 {
740 LOGV("BnDrmManagerService::onTransact :ADD_UNIQUEID");
741 CHECK_INTERFACE(IDrmManagerService, data, reply);
742 int uniqueId = addUniqueId(data.readInt32());
743 reply->writeInt32(uniqueId);
744 return DRM_NO_ERROR;
745 }
746
747 case REMOVE_UNIQUEID:
748 {
749 LOGV("BnDrmManagerService::onTransact :REMOVE_UNIQUEID");
750 CHECK_INTERFACE(IDrmManagerService, data, reply);
751 removeUniqueId(data.readInt32());
752 return DRM_NO_ERROR;
753 }
754
Takeshi Aimie943f842010-10-08 23:05:49 +0900755 case ADD_CLIENT:
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900756 {
Takeshi Aimie943f842010-10-08 23:05:49 +0900757 LOGV("BnDrmManagerService::onTransact :ADD_CLIENT");
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900758 CHECK_INTERFACE(IDrmManagerService, data, reply);
Takeshi Aimie943f842010-10-08 23:05:49 +0900759 addClient(data.readInt32());
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900760 return DRM_NO_ERROR;
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900761 }
762
Takeshi Aimie943f842010-10-08 23:05:49 +0900763 case REMOVE_CLIENT:
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900764 {
Takeshi Aimie943f842010-10-08 23:05:49 +0900765 LOGV("BnDrmManagerService::onTransact :REMOVE_CLIENT");
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900766 CHECK_INTERFACE(IDrmManagerService, data, reply);
Takeshi Aimie943f842010-10-08 23:05:49 +0900767 removeClient(data.readInt32());
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900768 return DRM_NO_ERROR;
769 }
770
771 case SET_DRM_SERVICE_LISTENER:
772 {
773 LOGV("BnDrmManagerService::onTransact :SET_DRM_SERVICE_LISTENER");
774 CHECK_INTERFACE(IDrmManagerService, data, reply);
775
776 const int uniqueId = data.readInt32();
777 const sp<IDrmServiceListener> drmServiceListener
778 = interface_cast<IDrmServiceListener> (data.readStrongBinder());
779
780 status_t status = setDrmServiceListener(uniqueId, drmServiceListener);
781
782 reply->writeInt32(status);
783 return DRM_NO_ERROR;
784 }
785
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900786 case INSTALL_DRM_ENGINE:
787 {
788 LOGV("BnDrmManagerService::onTransact :INSTALL_DRM_ENGINE");
789 CHECK_INTERFACE(IDrmManagerService, data, reply);
790
791 status_t status = installDrmEngine(data.readInt32(), data.readString8());
792
793 reply->writeInt32(status);
794 return DRM_NO_ERROR;
795 }
796
797 case GET_CONSTRAINTS_FROM_CONTENT:
798 {
799 LOGV("BnDrmManagerService::onTransact :GET_CONSTRAINTS_FROM_CONTENT");
800 CHECK_INTERFACE(IDrmManagerService, data, reply);
801
802 const int uniqueId = data.readInt32();
803 const String8 path = data.readString8();
804
805 DrmConstraints* drmConstraints = getConstraints(uniqueId, &path, data.readInt32());
806
807 if (NULL != drmConstraints) {
808 //Filling DRM Constraints contents
809 reply->writeInt32(drmConstraints->getCount());
810
811 DrmConstraints::KeyIterator keyIt = drmConstraints->keyIterator();
812 while (keyIt.hasNext()) {
813 const String8 key = keyIt.next();
814 reply->writeString8(key);
815 const char* value = drmConstraints->getAsByteArray(&key);
816 int bufferSize = 0;
817 if (NULL != value) {
818 bufferSize = strlen(value);
819 }
820 reply->writeInt32(bufferSize + 1);
821 reply->write(value, bufferSize + 1);
822 }
823 }
824 delete drmConstraints; drmConstraints = NULL;
825 return DRM_NO_ERROR;
826 }
827
828 case CAN_HANDLE:
829 {
830 LOGV("BnDrmManagerService::onTransact :CAN_HANDLE");
831 CHECK_INTERFACE(IDrmManagerService, data, reply);
832
833 const int uniqueId = data.readInt32();
834 const String8 path = data.readString8();
835 const String8 mimeType = data.readString8();
836
837 bool result = canHandle(uniqueId, path, mimeType);
838
839 reply->writeInt32(result);
840 return DRM_NO_ERROR;
841 }
842
843 case PROCESS_DRM_INFO:
844 {
845 LOGV("BnDrmManagerService::onTransact :PROCESS_DRM_INFO");
846 CHECK_INTERFACE(IDrmManagerService, data, reply);
847
848 const int uniqueId = data.readInt32();
849
850 //Filling DRM info
851 const int infoType = data.readInt32();
852 const int bufferSize = data.readInt32();
853 char* buffer = NULL;
854 if (0 < bufferSize) {
855 buffer = (char *)data.readInplace(bufferSize);
856 }
857 const DrmBuffer drmBuffer(buffer, bufferSize);
858 DrmInfo* drmInfo = new DrmInfo(infoType, drmBuffer, data.readString8());
859
860 const int size = data.readInt32();
861 for (int index = 0; index < size; ++index) {
862 const String8 key(data.readString8());
863 const String8 value(data.readString8());
864 drmInfo->put(key, (value == String8("NULL")) ? String8("") : value);
865 }
866
867 DrmInfoStatus* drmInfoStatus = processDrmInfo(uniqueId, drmInfo);
868
869 if (NULL != drmInfoStatus) {
870 //Filling DRM Info Status contents
871 reply->writeInt32(drmInfoStatus->statusCode);
Takeshi Aimie943f842010-10-08 23:05:49 +0900872 reply->writeInt32(drmInfoStatus->infoType);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900873 reply->writeString8(drmInfoStatus->mimeType);
874
875 if (NULL != drmInfoStatus->drmBuffer) {
876 const DrmBuffer* drmBuffer = drmInfoStatus->drmBuffer;
877 const int bufferSize = drmBuffer->length;
878 reply->writeInt32(bufferSize);
879 if (0 < bufferSize) {
880 reply->write(drmBuffer->data, bufferSize);
881 }
882 delete [] drmBuffer->data;
883 delete drmBuffer; drmBuffer = NULL;
884 }
885 }
886 delete drmInfo; drmInfo = NULL;
887 delete drmInfoStatus; drmInfoStatus = NULL;
888 return DRM_NO_ERROR;
889 }
890
891 case ACQUIRE_DRM_INFO:
892 {
893 LOGV("BnDrmManagerService::onTransact :ACQUIRE_DRM_INFO");
894 CHECK_INTERFACE(IDrmManagerService, data, reply);
895
896 const int uniqueId = data.readInt32();
897
898 //Filling DRM info Request
899 DrmInfoRequest* drmInfoRequest = new DrmInfoRequest(data.readInt32(), data.readString8());
900
901 const int size = data.readInt32();
902 for (int index = 0; index < size; ++index) {
903 const String8 key(data.readString8());
904 const String8 value(data.readString8());
905 drmInfoRequest->put(key, (value == String8("NULL")) ? String8("") : value);
906 }
907
908 DrmInfo* drmInfo = acquireDrmInfo(uniqueId, drmInfoRequest);
909
910 if (NULL != drmInfo) {
911 //Filling DRM Info
912 const DrmBuffer drmBuffer = drmInfo->getData();
913 reply->writeInt32(drmInfo->getInfoType());
914
915 const int bufferSize = drmBuffer.length;
916 reply->writeInt32(bufferSize);
917 if (0 < bufferSize) {
918 reply->write(drmBuffer.data, bufferSize);
919 }
920 reply->writeString8(drmInfo->getMimeType());
921 reply->writeInt32(drmInfo->getCount());
922
923 DrmInfo::KeyIterator keyIt = drmInfo->keyIterator();
924 while (keyIt.hasNext()) {
925 const String8 key = keyIt.next();
926 reply->writeString8(key);
927 const String8 value = drmInfo->get(key);
928 reply->writeString8((value == String8("")) ? String8("NULL") : value);
929 }
930 delete [] drmBuffer.data;
931 }
932 delete drmInfoRequest; drmInfoRequest = NULL;
933 delete drmInfo; drmInfo = NULL;
934 return DRM_NO_ERROR;
935 }
936
937 case SAVE_RIGHTS:
938 {
939 LOGV("BnDrmManagerService::onTransact :SAVE_RIGHTS");
940 CHECK_INTERFACE(IDrmManagerService, data, reply);
941
942 const int uniqueId = data.readInt32();
943
944 //Filling DRM Rights
945 const int bufferSize = data.readInt32();
946 const DrmBuffer drmBuffer((char *)data.readInplace(bufferSize), bufferSize);
947
948 const String8 mimeType(data.readString8());
949 const String8 accountId(data.readString8());
950 const String8 subscriptionId(data.readString8());
951 const String8 rightsPath(data.readString8());
952 const String8 contentPath(data.readString8());
953
954 DrmRights drmRights(drmBuffer,
955 ((mimeType == String8("NULL")) ? String8("") : mimeType),
956 ((accountId == String8("NULL")) ? String8("") : accountId),
957 ((subscriptionId == String8("NULL")) ? String8("") : subscriptionId));
958
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900959 const status_t status = saveRights(uniqueId, drmRights,
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900960 ((rightsPath == String8("NULL")) ? String8("") : rightsPath),
961 ((contentPath == String8("NULL")) ? String8("") : contentPath));
962
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900963 reply->writeInt32(status);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900964 return DRM_NO_ERROR;
965 }
966
967 case GET_ORIGINAL_MIMETYPE:
968 {
969 LOGV("BnDrmManagerService::onTransact :GET_ORIGINAL_MIMETYPE");
970 CHECK_INTERFACE(IDrmManagerService, data, reply);
971
972 const String8 originalMimeType = getOriginalMimeType(data.readInt32(), data.readString8());
973
974 reply->writeString8(originalMimeType);
975 return DRM_NO_ERROR;
976 }
977
978 case GET_DRM_OBJECT_TYPE:
979 {
980 LOGV("BnDrmManagerService::onTransact :GET_DRM_OBJECT_TYPE");
981 CHECK_INTERFACE(IDrmManagerService, data, reply);
982
983 const int drmObjectType
984 = getDrmObjectType(data.readInt32(), data.readString8(), data.readString8());
985
986 reply->writeInt32(drmObjectType);
987 return DRM_NO_ERROR;
988 }
989
990 case CHECK_RIGHTS_STATUS:
991 {
992 LOGV("BnDrmManagerService::onTransact :CHECK_RIGHTS_STATUS");
993 CHECK_INTERFACE(IDrmManagerService, data, reply);
994
995 const int result
996 = checkRightsStatus(data.readInt32(), data.readString8(), data.readInt32());
997
998 reply->writeInt32(result);
999 return DRM_NO_ERROR;
1000 }
1001
1002 case CONSUME_RIGHTS:
1003 {
1004 LOGV("BnDrmManagerService::onTransact :CONSUME_RIGHTS");
1005 CHECK_INTERFACE(IDrmManagerService, data, reply);
1006
1007 const int uniqueId = data.readInt32();
1008
1009 DecryptHandle handle;
1010 handle.decryptId = data.readInt32();
1011 handle.mimeType = data.readString8();
1012 handle.decryptApiType = data.readInt32();
1013 handle.status = data.readInt32();
1014 handle.decryptInfo = NULL;
1015
1016 const int bufferLength = data.readInt32();
1017 if (INVALID_BUFFER_LENGTH != bufferLength) {
1018 handle.decryptInfo = new DecryptInfo();
1019 handle.decryptInfo->decryptBufferLength = bufferLength;
1020 }
1021
Takeshi Aimi2272ee22010-09-20 23:40:41 +09001022 const status_t status
1023 = consumeRights(uniqueId, &handle, data.readInt32(),
1024 static_cast<bool>(data.readInt32()));
1025 reply->writeInt32(status);
aimitakeshi27ed8ad2010-07-29 10:12:27 +09001026
1027 delete handle.decryptInfo; handle.decryptInfo = NULL;
1028 return DRM_NO_ERROR;
1029 }
1030
1031 case SET_PLAYBACK_STATUS:
1032 {
1033 LOGV("BnDrmManagerService::onTransact :SET_PLAYBACK_STATUS");
1034 CHECK_INTERFACE(IDrmManagerService, data, reply);
1035
1036 const int uniqueId = data.readInt32();
1037
1038 DecryptHandle handle;
1039 handle.decryptId = data.readInt32();
1040 handle.mimeType = data.readString8();
1041 handle.decryptApiType = data.readInt32();
1042 handle.status = data.readInt32();
1043 handle.decryptInfo = NULL;
1044
1045 const int bufferLength = data.readInt32();
1046 if (INVALID_BUFFER_LENGTH != bufferLength) {
1047 handle.decryptInfo = new DecryptInfo();
1048 handle.decryptInfo->decryptBufferLength = bufferLength;
1049 }
1050
Takeshi Aimi2272ee22010-09-20 23:40:41 +09001051 const status_t status
1052 = setPlaybackStatus(uniqueId, &handle, data.readInt32(), data.readInt32());
1053 reply->writeInt32(status);
aimitakeshi27ed8ad2010-07-29 10:12:27 +09001054
1055 delete handle.decryptInfo; handle.decryptInfo = NULL;
1056 return DRM_NO_ERROR;
1057 }
1058
1059 case VALIDATE_ACTION:
1060 {
1061 LOGV("BnDrmManagerService::onTransact :VALIDATE_ACTION");
1062 CHECK_INTERFACE(IDrmManagerService, data, reply);
1063
1064 bool result = validateAction(
1065 data.readInt32(),
1066 data.readString8(),
1067 data.readInt32(),
1068 ActionDescription(data.readInt32(), data.readInt32()));
1069
1070 reply->writeInt32(result);
1071 return DRM_NO_ERROR;
1072 }
1073
1074 case REMOVE_RIGHTS:
1075 {
1076 LOGV("BnDrmManagerService::onTransact :REMOVE_RIGHTS");
1077 CHECK_INTERFACE(IDrmManagerService, data, reply);
1078
Takeshi Aimi2272ee22010-09-20 23:40:41 +09001079 const status_t status = removeRights(data.readInt32(), data.readString8());
1080 reply->writeInt32(status);
aimitakeshi27ed8ad2010-07-29 10:12:27 +09001081
1082 return DRM_NO_ERROR;
1083 }
1084
1085 case REMOVE_ALL_RIGHTS:
1086 {
1087 LOGV("BnDrmManagerService::onTransact :REMOVE_ALL_RIGHTS");
1088 CHECK_INTERFACE(IDrmManagerService, data, reply);
1089
Takeshi Aimi2272ee22010-09-20 23:40:41 +09001090 const status_t status = removeAllRights(data.readInt32());
1091 reply->writeInt32(status);
aimitakeshi27ed8ad2010-07-29 10:12:27 +09001092
1093 return DRM_NO_ERROR;
1094 }
1095
1096 case OPEN_CONVERT_SESSION:
1097 {
1098 LOGV("BnDrmManagerService::onTransact :OPEN_CONVERT_SESSION");
1099 CHECK_INTERFACE(IDrmManagerService, data, reply);
1100
1101 const int convertId = openConvertSession(data.readInt32(), data.readString8());
1102
1103 reply->writeInt32(convertId);
1104 return DRM_NO_ERROR;
1105 }
1106
1107 case CONVERT_DATA:
1108 {
1109 LOGV("BnDrmManagerService::onTransact :CONVERT_DATA");
1110 CHECK_INTERFACE(IDrmManagerService, data, reply);
1111
1112 const int uniqueId = data.readInt32();
1113 const int convertId = data.readInt32();
1114
1115 //Filling input data
1116 const int bufferSize = data.readInt32();
1117 DrmBuffer* inputData = new DrmBuffer((char *)data.readInplace(bufferSize), bufferSize);
1118
1119 DrmConvertedStatus* drmConvertedStatus = convertData(uniqueId, convertId, inputData);
1120
1121 if (NULL != drmConvertedStatus) {
1122 //Filling Drm Converted Ststus
1123 reply->writeInt32(drmConvertedStatus->statusCode);
Gloria Wanga2cd44c2010-11-19 15:19:36 -08001124 reply->writeInt64(drmConvertedStatus->offset);
aimitakeshi27ed8ad2010-07-29 10:12:27 +09001125
1126 if (NULL != drmConvertedStatus->convertedData) {
1127 const DrmBuffer* convertedData = drmConvertedStatus->convertedData;
1128 const int bufferSize = convertedData->length;
1129 reply->writeInt32(bufferSize);
1130 if (0 < bufferSize) {
1131 reply->write(convertedData->data, bufferSize);
1132 }
1133 delete [] convertedData->data;
1134 delete convertedData; convertedData = NULL;
1135 }
1136 }
1137 delete inputData; inputData = NULL;
1138 delete drmConvertedStatus; drmConvertedStatus = NULL;
1139 return DRM_NO_ERROR;
1140 }
1141
1142 case CLOSE_CONVERT_SESSION:
1143 {
1144 LOGV("BnDrmManagerService::onTransact :CLOSE_CONVERT_SESSION");
1145 CHECK_INTERFACE(IDrmManagerService, data, reply);
1146
1147 DrmConvertedStatus* drmConvertedStatus
1148 = closeConvertSession(data.readInt32(), data.readInt32());
1149
1150 if (NULL != drmConvertedStatus) {
1151 //Filling Drm Converted Ststus
1152 reply->writeInt32(drmConvertedStatus->statusCode);
Gloria Wanga2cd44c2010-11-19 15:19:36 -08001153 reply->writeInt64(drmConvertedStatus->offset);
aimitakeshi27ed8ad2010-07-29 10:12:27 +09001154
1155 if (NULL != drmConvertedStatus->convertedData) {
1156 const DrmBuffer* convertedData = drmConvertedStatus->convertedData;
1157 const int bufferSize = convertedData->length;
1158 reply->writeInt32(bufferSize);
1159 if (0 < bufferSize) {
1160 reply->write(convertedData->data, bufferSize);
1161 }
1162 delete [] convertedData->data;
1163 delete convertedData; convertedData = NULL;
1164 }
1165 }
1166 delete drmConvertedStatus; drmConvertedStatus = NULL;
1167 return DRM_NO_ERROR;
1168 }
1169
1170 case GET_ALL_SUPPORT_INFO:
1171 {
1172 LOGV("BnDrmManagerService::onTransact :GET_ALL_SUPPORT_INFO");
1173 CHECK_INTERFACE(IDrmManagerService, data, reply);
1174
1175 const int uniqueId = data.readInt32();
1176 int length = 0;
1177 DrmSupportInfo* drmSupportInfoArray = NULL;
1178
1179 status_t status = getAllSupportInfo(uniqueId, &length, &drmSupportInfoArray);
1180
1181 reply->writeInt32(length);
1182 for (int i = 0; i < length; ++i) {
1183 DrmSupportInfo drmSupportInfo = drmSupportInfoArray[i];
1184
1185 reply->writeInt32(drmSupportInfo.getFileSuffixCount());
1186 DrmSupportInfo::FileSuffixIterator fileSuffixIt
1187 = drmSupportInfo.getFileSuffixIterator();
1188 while (fileSuffixIt.hasNext()) {
1189 reply->writeString8(fileSuffixIt.next());
1190 }
1191
1192 reply->writeInt32(drmSupportInfo.getMimeTypeCount());
1193 DrmSupportInfo::MimeTypeIterator mimeTypeIt = drmSupportInfo.getMimeTypeIterator();
1194 while (mimeTypeIt.hasNext()) {
1195 reply->writeString8(mimeTypeIt.next());
1196 }
1197 reply->writeString8(drmSupportInfo.getDescription());
1198 }
1199 delete [] drmSupportInfoArray; drmSupportInfoArray = NULL;
1200 reply->writeInt32(status);
1201 return DRM_NO_ERROR;
1202 }
1203
1204 case OPEN_DECRYPT_SESSION:
1205 {
1206 LOGV("BnDrmManagerService::onTransact :OPEN_DECRYPT_SESSION");
1207 CHECK_INTERFACE(IDrmManagerService, data, reply);
1208
1209 const int uniqueId = data.readInt32();
1210 const int fd = data.readFileDescriptor();
1211
1212 DecryptHandle* handle
Gloria Wanga2cd44c2010-11-19 15:19:36 -08001213 = openDecryptSession(uniqueId, fd, data.readInt64(), data.readInt64());
aimitakeshi27ed8ad2010-07-29 10:12:27 +09001214
1215 if (NULL != handle) {
1216 reply->writeInt32(handle->decryptId);
1217 reply->writeString8(handle->mimeType);
1218 reply->writeInt32(handle->decryptApiType);
1219 reply->writeInt32(handle->status);
1220 if (NULL != handle->decryptInfo) {
1221 reply->writeInt32(handle->decryptInfo->decryptBufferLength);
1222 delete handle->decryptInfo; handle->decryptInfo = NULL;
1223 }
aimitakeshi27ed8ad2010-07-29 10:12:27 +09001224 }
1225 delete handle; handle = NULL;
1226 return DRM_NO_ERROR;
1227 }
1228
Takeshi Aimie943f842010-10-08 23:05:49 +09001229 case OPEN_DECRYPT_SESSION_FROM_URI:
1230 {
1231 LOGV("BnDrmManagerService::onTransact :OPEN_DECRYPT_SESSION_FROM_URI");
1232 CHECK_INTERFACE(IDrmManagerService, data, reply);
1233
1234 const int uniqueId = data.readInt32();
1235 const String8 uri = data.readString8();
1236
1237 DecryptHandle* handle = openDecryptSession(uniqueId, uri.string());
1238
1239 if (NULL != handle) {
1240 reply->writeInt32(handle->decryptId);
1241 reply->writeString8(handle->mimeType);
1242 reply->writeInt32(handle->decryptApiType);
1243 reply->writeInt32(handle->status);
1244 if (NULL != handle->decryptInfo) {
1245 reply->writeInt32(handle->decryptInfo->decryptBufferLength);
1246 delete handle->decryptInfo; handle->decryptInfo = NULL;
1247 }
1248 } else {
1249 LOGE("NULL decryptHandle is returned");
1250 }
1251 delete handle; handle = NULL;
1252 return DRM_NO_ERROR;
1253 }
1254
aimitakeshi27ed8ad2010-07-29 10:12:27 +09001255 case CLOSE_DECRYPT_SESSION:
1256 {
1257 LOGV("BnDrmManagerService::onTransact :CLOSE_DECRYPT_SESSION");
1258 CHECK_INTERFACE(IDrmManagerService, data, reply);
1259
1260 const int uniqueId = data.readInt32();
1261
1262 DecryptHandle* handle = new DecryptHandle();
1263 handle->decryptId = data.readInt32();
1264 handle->mimeType = data.readString8();
1265 handle->decryptApiType = data.readInt32();
1266 handle->status = data.readInt32();
1267 handle->decryptInfo = NULL;
1268
1269 const int bufferLength = data.readInt32();
1270 if (INVALID_BUFFER_LENGTH != bufferLength) {
1271 handle->decryptInfo = new DecryptInfo();
1272 handle->decryptInfo->decryptBufferLength = bufferLength;
1273 }
1274
Takeshi Aimi2272ee22010-09-20 23:40:41 +09001275 const status_t status = closeDecryptSession(uniqueId, handle);
1276 reply->writeInt32(status);
aimitakeshi27ed8ad2010-07-29 10:12:27 +09001277 return DRM_NO_ERROR;
1278 }
1279
1280 case INITIALIZE_DECRYPT_UNIT:
1281 {
1282 LOGV("BnDrmManagerService::onTransact :INITIALIZE_DECRYPT_UNIT");
1283 CHECK_INTERFACE(IDrmManagerService, data, reply);
1284
1285 const int uniqueId = data.readInt32();
1286
1287 DecryptHandle handle;
1288 handle.decryptId = data.readInt32();
1289 handle.mimeType = data.readString8();
1290 handle.decryptApiType = data.readInt32();
1291 handle.status = data.readInt32();
1292 handle.decryptInfo = NULL;
1293
1294 const int bufferLength = data.readInt32();
1295 if (INVALID_BUFFER_LENGTH != bufferLength) {
1296 handle.decryptInfo = new DecryptInfo();
1297 handle.decryptInfo->decryptBufferLength = bufferLength;
1298 }
1299 const int decryptUnitId = data.readInt32();
1300
1301 //Filling Header info
1302 const int bufferSize = data.readInt32();
1303 DrmBuffer* headerInfo = NULL;
1304 headerInfo = new DrmBuffer((char *)data.readInplace(bufferSize), bufferSize);
1305
Takeshi Aimi2272ee22010-09-20 23:40:41 +09001306 const status_t status
1307 = initializeDecryptUnit(uniqueId, &handle, decryptUnitId, headerInfo);
1308 reply->writeInt32(status);
aimitakeshi27ed8ad2010-07-29 10:12:27 +09001309
1310 delete handle.decryptInfo; handle.decryptInfo = NULL;
1311 delete headerInfo; headerInfo = NULL;
1312 return DRM_NO_ERROR;
1313 }
1314
1315 case DECRYPT:
1316 {
1317 LOGV("BnDrmManagerService::onTransact :DECRYPT");
1318 CHECK_INTERFACE(IDrmManagerService, data, reply);
1319
1320 const int uniqueId = data.readInt32();
1321
1322 DecryptHandle handle;
1323 handle.decryptId = data.readInt32();
1324 handle.mimeType = data.readString8();
1325 handle.decryptApiType = data.readInt32();
1326 handle.status = data.readInt32();
1327 handle.decryptInfo = NULL;
1328
1329 const int bufferLength = data.readInt32();
1330 if (INVALID_BUFFER_LENGTH != bufferLength) {
1331 handle.decryptInfo = new DecryptInfo();
1332 handle.decryptInfo->decryptBufferLength = bufferLength;
1333 }
1334 const int decryptUnitId = data.readInt32();
1335 const int decBufferSize = data.readInt32();
1336
1337 const int encBufferSize = data.readInt32();
1338 DrmBuffer* encBuffer
1339 = new DrmBuffer((char *)data.readInplace(encBufferSize), encBufferSize);
1340
1341 char* buffer = NULL;
1342 buffer = new char[decBufferSize];
1343 DrmBuffer* decBuffer = new DrmBuffer(buffer, decBufferSize);
1344
Takeshi Aimi2272ee22010-09-20 23:40:41 +09001345 DrmBuffer* IV = NULL;
1346 if (0 != data.dataAvail()) {
1347 const int ivBufferlength = data.readInt32();
1348 IV = new DrmBuffer((char *)data.readInplace(ivBufferlength), ivBufferlength);
1349 }
1350
1351 const status_t status
1352 = decrypt(uniqueId, &handle, decryptUnitId, encBuffer, &decBuffer, IV);
aimitakeshi27ed8ad2010-07-29 10:12:27 +09001353
1354 reply->writeInt32(status);
1355
1356 const int size = decBuffer->length;
1357 reply->writeInt32(size);
1358 reply->write(decBuffer->data, size);
1359
1360 delete handle.decryptInfo; handle.decryptInfo = NULL;
1361 delete encBuffer; encBuffer = NULL;
1362 delete decBuffer; decBuffer = NULL;
1363 delete [] buffer; buffer = NULL;
Takeshi Aimi2272ee22010-09-20 23:40:41 +09001364 delete IV; IV = NULL;
aimitakeshi27ed8ad2010-07-29 10:12:27 +09001365 return DRM_NO_ERROR;
1366 }
1367
1368 case FINALIZE_DECRYPT_UNIT:
1369 {
1370 LOGV("BnDrmManagerService::onTransact :FINALIZE_DECRYPT_UNIT");
1371 CHECK_INTERFACE(IDrmManagerService, data, reply);
1372
1373 const int uniqueId = data.readInt32();
1374
1375 DecryptHandle handle;
1376 handle.decryptId = data.readInt32();
1377 handle.mimeType = data.readString8();
1378 handle.decryptApiType = data.readInt32();
1379 handle.status = data.readInt32();
1380 handle.decryptInfo = NULL;
1381
1382 const int bufferLength = data.readInt32();
1383 if (INVALID_BUFFER_LENGTH != bufferLength) {
1384 handle.decryptInfo = new DecryptInfo();
1385 handle.decryptInfo->decryptBufferLength = bufferLength;
1386 }
1387
Takeshi Aimi2272ee22010-09-20 23:40:41 +09001388 const status_t status = finalizeDecryptUnit(uniqueId, &handle, data.readInt32());
1389 reply->writeInt32(status);
aimitakeshi27ed8ad2010-07-29 10:12:27 +09001390
1391 delete handle.decryptInfo; handle.decryptInfo = NULL;
1392 return DRM_NO_ERROR;
1393 }
1394
1395 case PREAD:
1396 {
1397 LOGV("BnDrmManagerService::onTransact :READ");
1398 CHECK_INTERFACE(IDrmManagerService, data, reply);
1399
1400 const int uniqueId = data.readInt32();
1401
1402 DecryptHandle handle;
1403 handle.decryptId = data.readInt32();
1404 handle.mimeType = data.readString8();
1405 handle.decryptApiType = data.readInt32();
1406 handle.status = data.readInt32();
1407 handle.decryptInfo = NULL;
1408
1409 const int bufferLength = data.readInt32();
1410 if (INVALID_BUFFER_LENGTH != bufferLength) {
1411 handle.decryptInfo = new DecryptInfo();
1412 handle.decryptInfo->decryptBufferLength = bufferLength;
1413 }
1414
1415 const int numBytes = data.readInt32();
1416 char* buffer = new char[numBytes];
1417
Gloria Wanga2cd44c2010-11-19 15:19:36 -08001418 const off64_t offset = data.readInt64();
aimitakeshi27ed8ad2010-07-29 10:12:27 +09001419
1420 ssize_t result = pread(uniqueId, &handle, buffer, numBytes, offset);
1421 reply->writeInt32(result);
1422 if (0 < result) {
1423 reply->write(buffer, result);
1424 }
1425
1426 delete handle.decryptInfo; handle.decryptInfo = NULL;
1427 delete [] buffer, buffer = NULL;
1428 return DRM_NO_ERROR;
1429 }
1430
1431 default:
1432 return BBinder::onTransact(code, data, reply, flags);
1433 }
1434}
1435