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