IDrmManagerService.cpp revision 2272ee27d9022d173b6eab45c409b3c3f57f30ec
18e01cdce135d5d816f92d7bb83f9a930aa1b45aeLucas Eckels/*
28e01cdce135d5d816f92d7bb83f9a930aa1b45aeLucas Eckels * Copyright (C) 2010 The Android Open Source Project
38e01cdce135d5d816f92d7bb83f9a930aa1b45aeLucas Eckels *
48e01cdce135d5d816f92d7bb83f9a930aa1b45aeLucas Eckels * Licensed under the Apache License, Version 2.0 (the "License");
58e01cdce135d5d816f92d7bb83f9a930aa1b45aeLucas Eckels * you may not use this file except in compliance with the License.
68e01cdce135d5d816f92d7bb83f9a930aa1b45aeLucas Eckels * You may obtain a copy of the License at
78e01cdce135d5d816f92d7bb83f9a930aa1b45aeLucas Eckels *
88e01cdce135d5d816f92d7bb83f9a930aa1b45aeLucas Eckels *      http://www.apache.org/licenses/LICENSE-2.0
98e01cdce135d5d816f92d7bb83f9a930aa1b45aeLucas Eckels *
108e01cdce135d5d816f92d7bb83f9a930aa1b45aeLucas Eckels * Unless required by applicable law or agreed to in writing, software
118e01cdce135d5d816f92d7bb83f9a930aa1b45aeLucas Eckels * distributed under the License is distributed on an "AS IS" BASIS,
128e01cdce135d5d816f92d7bb83f9a930aa1b45aeLucas Eckels * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
138e01cdce135d5d816f92d7bb83f9a930aa1b45aeLucas Eckels * See the License for the specific language governing permissions and
148e01cdce135d5d816f92d7bb83f9a930aa1b45aeLucas Eckels * limitations under the License.
158e01cdce135d5d816f92d7bb83f9a930aa1b45aeLucas Eckels */
168e01cdce135d5d816f92d7bb83f9a930aa1b45aeLucas Eckels
178e01cdce135d5d816f92d7bb83f9a930aa1b45aeLucas Eckels//#define LOG_NDEBUG 0
188e01cdce135d5d816f92d7bb83f9a930aa1b45aeLucas Eckels#define LOG_TAG "IDrmManagerService(Native)"
198e01cdce135d5d816f92d7bb83f9a930aa1b45aeLucas Eckels#include <utils/Log.h>
208e01cdce135d5d816f92d7bb83f9a930aa1b45aeLucas Eckels
218e01cdce135d5d816f92d7bb83f9a930aa1b45aeLucas Eckels#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    } else {
563        LOGE("no decryptHandle is generated in service side");
564    }
565    return handle;
566}
567
568status_t BpDrmManagerService::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) {
569    LOGV("closeDecryptSession");
570    Parcel data, reply;
571
572    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
573    data.writeInt32(uniqueId);
574
575    data.writeInt32(decryptHandle->decryptId);
576    data.writeString8(decryptHandle->mimeType);
577    data.writeInt32(decryptHandle->decryptApiType);
578    data.writeInt32(decryptHandle->status);
579
580    if (NULL != decryptHandle->decryptInfo) {
581        data.writeInt32(decryptHandle->decryptInfo->decryptBufferLength);
582    } else {
583        data.writeInt32(INVALID_BUFFER_LENGTH);
584    }
585
586    remote()->transact(CLOSE_DECRYPT_SESSION, data, &reply);
587
588    if (NULL != decryptHandle->decryptInfo) {
589        LOGV("deleting decryptInfo");
590        delete decryptHandle->decryptInfo; decryptHandle->decryptInfo = NULL;
591    }
592    delete decryptHandle; decryptHandle = NULL;
593    return reply.readInt32();
594}
595
596status_t BpDrmManagerService::initializeDecryptUnit(
597            int uniqueId, DecryptHandle* decryptHandle,
598            int decryptUnitId, const DrmBuffer* headerInfo) {
599    LOGV("initializeDecryptUnit");
600    Parcel data, reply;
601
602    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
603    data.writeInt32(uniqueId);
604
605    data.writeInt32(decryptHandle->decryptId);
606    data.writeString8(decryptHandle->mimeType);
607    data.writeInt32(decryptHandle->decryptApiType);
608    data.writeInt32(decryptHandle->status);
609
610    if (NULL != decryptHandle->decryptInfo) {
611        data.writeInt32(decryptHandle->decryptInfo->decryptBufferLength);
612    } else {
613        data.writeInt32(INVALID_BUFFER_LENGTH);
614    }
615    data.writeInt32(decryptUnitId);
616
617    data.writeInt32(headerInfo->length);
618    data.write(headerInfo->data, headerInfo->length);
619
620    remote()->transact(INITIALIZE_DECRYPT_UNIT, data, &reply);
621    return reply.readInt32();
622}
623
624status_t BpDrmManagerService::decrypt(
625            int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId,
626            const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) {
627    LOGV("decrypt");
628    Parcel data, reply;
629
630    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
631    data.writeInt32(uniqueId);
632
633    data.writeInt32(decryptHandle->decryptId);
634    data.writeString8(decryptHandle->mimeType);
635    data.writeInt32(decryptHandle->decryptApiType);
636    data.writeInt32(decryptHandle->status);
637
638    if (NULL != decryptHandle->decryptInfo) {
639        data.writeInt32(decryptHandle->decryptInfo->decryptBufferLength);
640    } else {
641        data.writeInt32(INVALID_BUFFER_LENGTH);
642    }
643
644    data.writeInt32(decryptUnitId);
645    data.writeInt32((*decBuffer)->length);
646
647    data.writeInt32(encBuffer->length);
648    data.write(encBuffer->data, encBuffer->length);
649
650    if (NULL != IV) {
651        data.writeInt32(IV->length);
652        data.write(IV->data, IV->length);
653    }
654
655    remote()->transact(DECRYPT, data, &reply);
656
657    const status_t status = reply.readInt32();
658    LOGV("Return value of decrypt() is %d", status);
659
660    const int size = reply.readInt32();
661    (*decBuffer)->length = size;
662    reply.read((void *)(*decBuffer)->data, size);
663
664    return status;
665}
666
667status_t BpDrmManagerService::finalizeDecryptUnit(
668            int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) {
669    LOGV("finalizeDecryptUnit");
670    Parcel data, reply;
671
672    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
673    data.writeInt32(uniqueId);
674
675    data.writeInt32(decryptHandle->decryptId);
676    data.writeString8(decryptHandle->mimeType);
677    data.writeInt32(decryptHandle->decryptApiType);
678    data.writeInt32(decryptHandle->status);
679
680    if (NULL != decryptHandle->decryptInfo) {
681        data.writeInt32(decryptHandle->decryptInfo->decryptBufferLength);
682    } else {
683        data.writeInt32(INVALID_BUFFER_LENGTH);
684    }
685
686    data.writeInt32(decryptUnitId);
687
688    remote()->transact(FINALIZE_DECRYPT_UNIT, data, &reply);
689    return reply.readInt32();
690}
691
692ssize_t BpDrmManagerService::pread(
693            int uniqueId, DecryptHandle* decryptHandle, void* buffer,
694            ssize_t numBytes, off_t offset) {
695    LOGV("read");
696    Parcel data, reply;
697    int result;
698
699    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
700    data.writeInt32(uniqueId);
701
702    data.writeInt32(decryptHandle->decryptId);
703    data.writeString8(decryptHandle->mimeType);
704    data.writeInt32(decryptHandle->decryptApiType);
705    data.writeInt32(decryptHandle->status);
706
707    if (NULL != decryptHandle->decryptInfo) {
708        data.writeInt32(decryptHandle->decryptInfo->decryptBufferLength);
709    } else {
710        data.writeInt32(INVALID_BUFFER_LENGTH);
711    }
712
713    data.writeInt32(numBytes);
714    data.writeInt32(offset);
715
716    remote()->transact(PREAD, data, &reply);
717    result = reply.readInt32();
718    if (0 < result) {
719        reply.read(buffer, result);
720    }
721    return result;
722}
723
724IMPLEMENT_META_INTERFACE(DrmManagerService, "drm.IDrmManagerService");
725
726status_t BnDrmManagerService::onTransact(
727            uint32_t code, const Parcel& data,
728            Parcel* reply, uint32_t flags) {
729    LOGV("Entering BnDrmManagerService::onTransact with code %d", code);
730
731    switch (code) {
732    case ADD_UNIQUEID:
733    {
734        LOGV("BnDrmManagerService::onTransact :ADD_UNIQUEID");
735        CHECK_INTERFACE(IDrmManagerService, data, reply);
736        int uniqueId = addUniqueId(data.readInt32());
737        reply->writeInt32(uniqueId);
738        return DRM_NO_ERROR;
739    }
740
741    case REMOVE_UNIQUEID:
742    {
743        LOGV("BnDrmManagerService::onTransact :REMOVE_UNIQUEID");
744        CHECK_INTERFACE(IDrmManagerService, data, reply);
745        removeUniqueId(data.readInt32());
746        return DRM_NO_ERROR;
747    }
748
749    case LOAD_PLUGINS:
750    {
751        LOGV("BnDrmManagerService::onTransact :LOAD_PLUGINS");
752        CHECK_INTERFACE(IDrmManagerService, data, reply);
753
754        status_t status = loadPlugIns(data.readInt32());
755
756        reply->writeInt32(status);
757        return DRM_NO_ERROR;
758    }
759
760    case LOAD_PLUGINS_FROM_PATH:
761    {
762        LOGV("BnDrmManagerService::onTransact :LOAD_PLUGINS_FROM_PATH");
763        CHECK_INTERFACE(IDrmManagerService, data, reply);
764
765        status_t status = loadPlugIns(data.readInt32(), data.readString8());
766
767        reply->writeInt32(status);
768        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
786    case UNLOAD_PLUGINS:
787    {
788        LOGV("BnDrmManagerService::onTransact :UNLOAD_PLUGINS");
789        CHECK_INTERFACE(IDrmManagerService, data, reply);
790
791        const int uniqueId = data.readInt32();
792        status_t status = unloadPlugIns(uniqueId);
793
794        reply->writeInt32(status);
795        return DRM_NO_ERROR;
796    }
797
798    case INSTALL_DRM_ENGINE:
799    {
800        LOGV("BnDrmManagerService::onTransact :INSTALL_DRM_ENGINE");
801        CHECK_INTERFACE(IDrmManagerService, data, reply);
802
803        status_t status = installDrmEngine(data.readInt32(), data.readString8());
804
805        reply->writeInt32(status);
806        return DRM_NO_ERROR;
807    }
808
809    case GET_CONSTRAINTS_FROM_CONTENT:
810    {
811        LOGV("BnDrmManagerService::onTransact :GET_CONSTRAINTS_FROM_CONTENT");
812        CHECK_INTERFACE(IDrmManagerService, data, reply);
813
814        const int uniqueId = data.readInt32();
815        const String8 path = data.readString8();
816
817        DrmConstraints* drmConstraints = getConstraints(uniqueId, &path, data.readInt32());
818
819        if (NULL != drmConstraints) {
820            //Filling DRM Constraints contents
821            reply->writeInt32(drmConstraints->getCount());
822
823            DrmConstraints::KeyIterator keyIt = drmConstraints->keyIterator();
824            while (keyIt.hasNext()) {
825                const String8 key = keyIt.next();
826                reply->writeString8(key);
827                const char* value = drmConstraints->getAsByteArray(&key);
828                int bufferSize = 0;
829                if (NULL != value) {
830                    bufferSize = strlen(value);
831                }
832                reply->writeInt32(bufferSize + 1);
833                reply->write(value, bufferSize + 1);
834            }
835        }
836        delete drmConstraints; drmConstraints = NULL;
837        return DRM_NO_ERROR;
838    }
839
840    case CAN_HANDLE:
841    {
842        LOGV("BnDrmManagerService::onTransact :CAN_HANDLE");
843        CHECK_INTERFACE(IDrmManagerService, data, reply);
844
845        const int uniqueId = data.readInt32();
846        const String8 path = data.readString8();
847        const String8 mimeType = data.readString8();
848
849        bool result = canHandle(uniqueId, path, mimeType);
850
851        reply->writeInt32(result);
852        return DRM_NO_ERROR;
853    }
854
855    case PROCESS_DRM_INFO:
856    {
857        LOGV("BnDrmManagerService::onTransact :PROCESS_DRM_INFO");
858        CHECK_INTERFACE(IDrmManagerService, data, reply);
859
860        const int uniqueId = data.readInt32();
861
862        //Filling DRM info
863        const int infoType = data.readInt32();
864        const int bufferSize = data.readInt32();
865        char* buffer = NULL;
866        if (0 < bufferSize) {
867            buffer = (char *)data.readInplace(bufferSize);
868        }
869        const DrmBuffer drmBuffer(buffer, bufferSize);
870        DrmInfo* drmInfo = new DrmInfo(infoType, drmBuffer, data.readString8());
871
872        const int size = data.readInt32();
873        for (int index = 0; index < size; ++index) {
874            const String8 key(data.readString8());
875            const String8 value(data.readString8());
876            drmInfo->put(key, (value == String8("NULL")) ? String8("") : value);
877        }
878
879        DrmInfoStatus* drmInfoStatus = processDrmInfo(uniqueId, drmInfo);
880
881        if (NULL != drmInfoStatus) {
882            //Filling DRM Info Status contents
883            reply->writeInt32(drmInfoStatus->statusCode);
884            reply->writeString8(drmInfoStatus->mimeType);
885
886            if (NULL != drmInfoStatus->drmBuffer) {
887                const DrmBuffer* drmBuffer = drmInfoStatus->drmBuffer;
888                const int bufferSize = drmBuffer->length;
889                reply->writeInt32(bufferSize);
890                if (0 < bufferSize) {
891                    reply->write(drmBuffer->data, bufferSize);
892                }
893                delete [] drmBuffer->data;
894                delete drmBuffer; drmBuffer = NULL;
895            }
896        }
897        delete drmInfo; drmInfo = NULL;
898        delete drmInfoStatus; drmInfoStatus = NULL;
899        return DRM_NO_ERROR;
900    }
901
902    case ACQUIRE_DRM_INFO:
903    {
904        LOGV("BnDrmManagerService::onTransact :ACQUIRE_DRM_INFO");
905        CHECK_INTERFACE(IDrmManagerService, data, reply);
906
907        const int uniqueId = data.readInt32();
908
909        //Filling DRM info Request
910        DrmInfoRequest* drmInfoRequest = new DrmInfoRequest(data.readInt32(), data.readString8());
911
912        const int size = data.readInt32();
913        for (int index = 0; index < size; ++index) {
914            const String8 key(data.readString8());
915            const String8 value(data.readString8());
916            drmInfoRequest->put(key, (value == String8("NULL")) ? String8("") : value);
917        }
918
919        DrmInfo* drmInfo = acquireDrmInfo(uniqueId, drmInfoRequest);
920
921        if (NULL != drmInfo) {
922            //Filling DRM Info
923            const DrmBuffer drmBuffer = drmInfo->getData();
924            reply->writeInt32(drmInfo->getInfoType());
925
926            const int bufferSize = drmBuffer.length;
927            reply->writeInt32(bufferSize);
928            if (0 < bufferSize) {
929                reply->write(drmBuffer.data, bufferSize);
930            }
931            reply->writeString8(drmInfo->getMimeType());
932            reply->writeInt32(drmInfo->getCount());
933
934            DrmInfo::KeyIterator keyIt = drmInfo->keyIterator();
935            while (keyIt.hasNext()) {
936                const String8 key = keyIt.next();
937                reply->writeString8(key);
938                const String8 value = drmInfo->get(key);
939                reply->writeString8((value == String8("")) ? String8("NULL") : value);
940            }
941            delete [] drmBuffer.data;
942        }
943        delete drmInfoRequest; drmInfoRequest = NULL;
944        delete drmInfo; drmInfo = NULL;
945        return DRM_NO_ERROR;
946    }
947
948    case SAVE_RIGHTS:
949    {
950        LOGV("BnDrmManagerService::onTransact :SAVE_RIGHTS");
951        CHECK_INTERFACE(IDrmManagerService, data, reply);
952
953        const int uniqueId = data.readInt32();
954
955        //Filling DRM Rights
956        const int bufferSize = data.readInt32();
957        const DrmBuffer drmBuffer((char *)data.readInplace(bufferSize), bufferSize);
958
959        const String8 mimeType(data.readString8());
960        const String8 accountId(data.readString8());
961        const String8 subscriptionId(data.readString8());
962        const String8 rightsPath(data.readString8());
963        const String8 contentPath(data.readString8());
964
965        DrmRights drmRights(drmBuffer,
966                            ((mimeType == String8("NULL")) ? String8("") : mimeType),
967                            ((accountId == String8("NULL")) ? String8("") : accountId),
968                            ((subscriptionId == String8("NULL")) ? String8("") : subscriptionId));
969
970        const status_t status = saveRights(uniqueId, drmRights,
971                            ((rightsPath == String8("NULL")) ? String8("") : rightsPath),
972                            ((contentPath == String8("NULL")) ? String8("") : contentPath));
973
974        reply->writeInt32(status);
975        return DRM_NO_ERROR;
976    }
977
978    case GET_ORIGINAL_MIMETYPE:
979    {
980        LOGV("BnDrmManagerService::onTransact :GET_ORIGINAL_MIMETYPE");
981        CHECK_INTERFACE(IDrmManagerService, data, reply);
982
983        const String8 originalMimeType = getOriginalMimeType(data.readInt32(), data.readString8());
984
985        reply->writeString8(originalMimeType);
986        return DRM_NO_ERROR;
987    }
988
989    case GET_DRM_OBJECT_TYPE:
990    {
991        LOGV("BnDrmManagerService::onTransact :GET_DRM_OBJECT_TYPE");
992        CHECK_INTERFACE(IDrmManagerService, data, reply);
993
994        const int drmObjectType
995            = getDrmObjectType(data.readInt32(), data.readString8(), data.readString8());
996
997        reply->writeInt32(drmObjectType);
998        return DRM_NO_ERROR;
999    }
1000
1001    case CHECK_RIGHTS_STATUS:
1002    {
1003        LOGV("BnDrmManagerService::onTransact :CHECK_RIGHTS_STATUS");
1004        CHECK_INTERFACE(IDrmManagerService, data, reply);
1005
1006        const int result
1007            = checkRightsStatus(data.readInt32(), data.readString8(), data.readInt32());
1008
1009        reply->writeInt32(result);
1010        return DRM_NO_ERROR;
1011    }
1012
1013    case CONSUME_RIGHTS:
1014    {
1015        LOGV("BnDrmManagerService::onTransact :CONSUME_RIGHTS");
1016        CHECK_INTERFACE(IDrmManagerService, data, reply);
1017
1018        const int uniqueId = data.readInt32();
1019
1020        DecryptHandle handle;
1021        handle.decryptId = data.readInt32();
1022        handle.mimeType = data.readString8();
1023        handle.decryptApiType = data.readInt32();
1024        handle.status = data.readInt32();
1025        handle.decryptInfo = NULL;
1026
1027        const int bufferLength = data.readInt32();
1028        if (INVALID_BUFFER_LENGTH != bufferLength) {
1029            handle.decryptInfo = new DecryptInfo();
1030            handle.decryptInfo->decryptBufferLength = bufferLength;
1031        }
1032
1033        const status_t status
1034            = consumeRights(uniqueId, &handle, data.readInt32(),
1035                static_cast<bool>(data.readInt32()));
1036        reply->writeInt32(status);
1037
1038        delete handle.decryptInfo; handle.decryptInfo = NULL;
1039        return DRM_NO_ERROR;
1040    }
1041
1042    case SET_PLAYBACK_STATUS:
1043    {
1044        LOGV("BnDrmManagerService::onTransact :SET_PLAYBACK_STATUS");
1045        CHECK_INTERFACE(IDrmManagerService, data, reply);
1046
1047        const int uniqueId = data.readInt32();
1048
1049        DecryptHandle handle;
1050        handle.decryptId = data.readInt32();
1051        handle.mimeType = data.readString8();
1052        handle.decryptApiType = data.readInt32();
1053        handle.status = data.readInt32();
1054        handle.decryptInfo = NULL;
1055
1056        const int bufferLength = data.readInt32();
1057        if (INVALID_BUFFER_LENGTH != bufferLength) {
1058            handle.decryptInfo = new DecryptInfo();
1059            handle.decryptInfo->decryptBufferLength = bufferLength;
1060        }
1061
1062        const status_t status
1063            = setPlaybackStatus(uniqueId, &handle, data.readInt32(), data.readInt32());
1064        reply->writeInt32(status);
1065
1066        delete handle.decryptInfo; handle.decryptInfo = NULL;
1067        return DRM_NO_ERROR;
1068    }
1069
1070    case VALIDATE_ACTION:
1071    {
1072        LOGV("BnDrmManagerService::onTransact :VALIDATE_ACTION");
1073        CHECK_INTERFACE(IDrmManagerService, data, reply);
1074
1075        bool result = validateAction(
1076                                data.readInt32(),
1077                                data.readString8(),
1078                                data.readInt32(),
1079                                ActionDescription(data.readInt32(), data.readInt32()));
1080
1081        reply->writeInt32(result);
1082        return DRM_NO_ERROR;
1083    }
1084
1085    case REMOVE_RIGHTS:
1086    {
1087        LOGV("BnDrmManagerService::onTransact :REMOVE_RIGHTS");
1088        CHECK_INTERFACE(IDrmManagerService, data, reply);
1089
1090        const status_t status = removeRights(data.readInt32(), data.readString8());
1091        reply->writeInt32(status);
1092
1093        return DRM_NO_ERROR;
1094    }
1095
1096    case REMOVE_ALL_RIGHTS:
1097    {
1098        LOGV("BnDrmManagerService::onTransact :REMOVE_ALL_RIGHTS");
1099        CHECK_INTERFACE(IDrmManagerService, data, reply);
1100
1101        const status_t status = removeAllRights(data.readInt32());
1102        reply->writeInt32(status);
1103
1104        return DRM_NO_ERROR;
1105    }
1106
1107    case OPEN_CONVERT_SESSION:
1108    {
1109        LOGV("BnDrmManagerService::onTransact :OPEN_CONVERT_SESSION");
1110        CHECK_INTERFACE(IDrmManagerService, data, reply);
1111
1112        const int convertId = openConvertSession(data.readInt32(), data.readString8());
1113
1114        reply->writeInt32(convertId);
1115        return DRM_NO_ERROR;
1116    }
1117
1118    case CONVERT_DATA:
1119    {
1120        LOGV("BnDrmManagerService::onTransact :CONVERT_DATA");
1121        CHECK_INTERFACE(IDrmManagerService, data, reply);
1122
1123        const int uniqueId = data.readInt32();
1124        const int convertId = data.readInt32();
1125
1126        //Filling input data
1127        const int bufferSize = data.readInt32();
1128        DrmBuffer* inputData = new DrmBuffer((char *)data.readInplace(bufferSize), bufferSize);
1129
1130        DrmConvertedStatus*    drmConvertedStatus = convertData(uniqueId, convertId, inputData);
1131
1132        if (NULL != drmConvertedStatus) {
1133            //Filling Drm Converted Ststus
1134            reply->writeInt32(drmConvertedStatus->statusCode);
1135            reply->writeInt32(drmConvertedStatus->offset);
1136
1137            if (NULL != drmConvertedStatus->convertedData) {
1138                const DrmBuffer* convertedData = drmConvertedStatus->convertedData;
1139                const int bufferSize = convertedData->length;
1140                reply->writeInt32(bufferSize);
1141                if (0 < bufferSize) {
1142                    reply->write(convertedData->data, bufferSize);
1143                }
1144                delete [] convertedData->data;
1145                delete convertedData; convertedData = NULL;
1146            }
1147        }
1148        delete inputData; inputData = NULL;
1149        delete drmConvertedStatus; drmConvertedStatus = NULL;
1150        return DRM_NO_ERROR;
1151    }
1152
1153    case CLOSE_CONVERT_SESSION:
1154    {
1155        LOGV("BnDrmManagerService::onTransact :CLOSE_CONVERT_SESSION");
1156        CHECK_INTERFACE(IDrmManagerService, data, reply);
1157
1158        DrmConvertedStatus*    drmConvertedStatus
1159            = closeConvertSession(data.readInt32(), data.readInt32());
1160
1161        if (NULL != drmConvertedStatus) {
1162            //Filling Drm Converted Ststus
1163            reply->writeInt32(drmConvertedStatus->statusCode);
1164            reply->writeInt32(drmConvertedStatus->offset);
1165
1166            if (NULL != drmConvertedStatus->convertedData) {
1167                const DrmBuffer* convertedData = drmConvertedStatus->convertedData;
1168                const int bufferSize = convertedData->length;
1169                reply->writeInt32(bufferSize);
1170                if (0 < bufferSize) {
1171                    reply->write(convertedData->data, bufferSize);
1172                }
1173                delete [] convertedData->data;
1174                delete convertedData; convertedData = NULL;
1175            }
1176        }
1177        delete drmConvertedStatus; drmConvertedStatus = NULL;
1178        return DRM_NO_ERROR;
1179    }
1180
1181    case GET_ALL_SUPPORT_INFO:
1182    {
1183        LOGV("BnDrmManagerService::onTransact :GET_ALL_SUPPORT_INFO");
1184        CHECK_INTERFACE(IDrmManagerService, data, reply);
1185
1186        const int uniqueId = data.readInt32();
1187        int length = 0;
1188        DrmSupportInfo* drmSupportInfoArray = NULL;
1189
1190        status_t status = getAllSupportInfo(uniqueId, &length, &drmSupportInfoArray);
1191
1192        reply->writeInt32(length);
1193        for (int i = 0; i < length; ++i) {
1194            DrmSupportInfo drmSupportInfo = drmSupportInfoArray[i];
1195
1196            reply->writeInt32(drmSupportInfo.getFileSuffixCount());
1197            DrmSupportInfo::FileSuffixIterator fileSuffixIt
1198                = drmSupportInfo.getFileSuffixIterator();
1199            while (fileSuffixIt.hasNext()) {
1200                reply->writeString8(fileSuffixIt.next());
1201            }
1202
1203            reply->writeInt32(drmSupportInfo.getMimeTypeCount());
1204            DrmSupportInfo::MimeTypeIterator mimeTypeIt = drmSupportInfo.getMimeTypeIterator();
1205            while (mimeTypeIt.hasNext()) {
1206                reply->writeString8(mimeTypeIt.next());
1207            }
1208            reply->writeString8(drmSupportInfo.getDescription());
1209        }
1210        delete [] drmSupportInfoArray; drmSupportInfoArray = NULL;
1211        reply->writeInt32(status);
1212        return DRM_NO_ERROR;
1213    }
1214
1215    case OPEN_DECRYPT_SESSION:
1216    {
1217        LOGV("BnDrmManagerService::onTransact :OPEN_DECRYPT_SESSION");
1218        CHECK_INTERFACE(IDrmManagerService, data, reply);
1219
1220        const int uniqueId = data.readInt32();
1221        const int fd = data.readFileDescriptor();
1222
1223        DecryptHandle* handle
1224            = openDecryptSession(uniqueId, fd, data.readInt32(), data.readInt32());
1225
1226        if (NULL != handle) {
1227            reply->writeInt32(handle->decryptId);
1228            reply->writeString8(handle->mimeType);
1229            reply->writeInt32(handle->decryptApiType);
1230            reply->writeInt32(handle->status);
1231            if (NULL != handle->decryptInfo) {
1232                reply->writeInt32(handle->decryptInfo->decryptBufferLength);
1233                delete handle->decryptInfo; handle->decryptInfo = NULL;
1234            }
1235        } else {
1236            LOGE("NULL decryptHandle is returned");
1237        }
1238        delete handle; handle = NULL;
1239        return DRM_NO_ERROR;
1240    }
1241
1242    case CLOSE_DECRYPT_SESSION:
1243    {
1244        LOGV("BnDrmManagerService::onTransact :CLOSE_DECRYPT_SESSION");
1245        CHECK_INTERFACE(IDrmManagerService, data, reply);
1246
1247        const int uniqueId = data.readInt32();
1248
1249        DecryptHandle* handle = new DecryptHandle();
1250        handle->decryptId = data.readInt32();
1251        handle->mimeType = data.readString8();
1252        handle->decryptApiType = data.readInt32();
1253        handle->status = data.readInt32();
1254        handle->decryptInfo = NULL;
1255
1256        const int bufferLength = data.readInt32();
1257        if (INVALID_BUFFER_LENGTH != bufferLength) {
1258            handle->decryptInfo = new DecryptInfo();
1259            handle->decryptInfo->decryptBufferLength = bufferLength;
1260        }
1261
1262        const status_t status = closeDecryptSession(uniqueId, handle);
1263        reply->writeInt32(status);
1264        return DRM_NO_ERROR;
1265    }
1266
1267    case INITIALIZE_DECRYPT_UNIT:
1268    {
1269        LOGV("BnDrmManagerService::onTransact :INITIALIZE_DECRYPT_UNIT");
1270        CHECK_INTERFACE(IDrmManagerService, data, reply);
1271
1272        const int uniqueId = data.readInt32();
1273
1274        DecryptHandle handle;
1275        handle.decryptId = data.readInt32();
1276        handle.mimeType = data.readString8();
1277        handle.decryptApiType = data.readInt32();
1278        handle.status = data.readInt32();
1279        handle.decryptInfo = NULL;
1280
1281        const int bufferLength = data.readInt32();
1282        if (INVALID_BUFFER_LENGTH != bufferLength) {
1283            handle.decryptInfo = new DecryptInfo();
1284            handle.decryptInfo->decryptBufferLength = bufferLength;
1285        }
1286        const int decryptUnitId = data.readInt32();
1287
1288        //Filling Header info
1289        const int bufferSize = data.readInt32();
1290        DrmBuffer* headerInfo = NULL;
1291        headerInfo = new DrmBuffer((char *)data.readInplace(bufferSize), bufferSize);
1292
1293        const status_t status
1294            = initializeDecryptUnit(uniqueId, &handle, decryptUnitId, headerInfo);
1295        reply->writeInt32(status);
1296
1297        delete handle.decryptInfo; handle.decryptInfo = NULL;
1298        delete headerInfo; headerInfo = NULL;
1299        return DRM_NO_ERROR;
1300    }
1301
1302    case DECRYPT:
1303    {
1304        LOGV("BnDrmManagerService::onTransact :DECRYPT");
1305        CHECK_INTERFACE(IDrmManagerService, data, reply);
1306
1307        const int uniqueId = data.readInt32();
1308
1309        DecryptHandle handle;
1310        handle.decryptId = data.readInt32();
1311        handle.mimeType = data.readString8();
1312        handle.decryptApiType = data.readInt32();
1313        handle.status = data.readInt32();
1314        handle.decryptInfo = NULL;
1315
1316        const int bufferLength = data.readInt32();
1317        if (INVALID_BUFFER_LENGTH != bufferLength) {
1318            handle.decryptInfo = new DecryptInfo();
1319            handle.decryptInfo->decryptBufferLength = bufferLength;
1320        }
1321        const int decryptUnitId = data.readInt32();
1322        const int decBufferSize = data.readInt32();
1323
1324        const int encBufferSize = data.readInt32();
1325        DrmBuffer* encBuffer
1326            = new DrmBuffer((char *)data.readInplace(encBufferSize), encBufferSize);
1327
1328        char* buffer = NULL;
1329        buffer = new char[decBufferSize];
1330        DrmBuffer* decBuffer = new DrmBuffer(buffer, decBufferSize);
1331
1332        DrmBuffer* IV = NULL;
1333        if (0 != data.dataAvail()) {
1334            const int ivBufferlength = data.readInt32();
1335            IV = new DrmBuffer((char *)data.readInplace(ivBufferlength), ivBufferlength);
1336        }
1337
1338        const status_t status
1339            = decrypt(uniqueId, &handle, decryptUnitId, encBuffer, &decBuffer, IV);
1340
1341        reply->writeInt32(status);
1342
1343        const int size = decBuffer->length;
1344        reply->writeInt32(size);
1345        reply->write(decBuffer->data, size);
1346
1347        delete handle.decryptInfo; handle.decryptInfo = NULL;
1348        delete encBuffer; encBuffer = NULL;
1349        delete decBuffer; decBuffer = NULL;
1350        delete [] buffer; buffer = NULL;
1351        delete IV; IV = NULL;
1352        return DRM_NO_ERROR;
1353    }
1354
1355    case FINALIZE_DECRYPT_UNIT:
1356    {
1357        LOGV("BnDrmManagerService::onTransact :FINALIZE_DECRYPT_UNIT");
1358        CHECK_INTERFACE(IDrmManagerService, data, reply);
1359
1360        const int uniqueId = data.readInt32();
1361
1362        DecryptHandle handle;
1363        handle.decryptId = data.readInt32();
1364        handle.mimeType = data.readString8();
1365        handle.decryptApiType = data.readInt32();
1366        handle.status = data.readInt32();
1367        handle.decryptInfo = NULL;
1368
1369        const int bufferLength = data.readInt32();
1370        if (INVALID_BUFFER_LENGTH != bufferLength) {
1371            handle.decryptInfo = new DecryptInfo();
1372            handle.decryptInfo->decryptBufferLength = bufferLength;
1373        }
1374
1375        const status_t status = finalizeDecryptUnit(uniqueId, &handle, data.readInt32());
1376        reply->writeInt32(status);
1377
1378        delete handle.decryptInfo; handle.decryptInfo = NULL;
1379        return DRM_NO_ERROR;
1380    }
1381
1382    case PREAD:
1383    {
1384        LOGV("BnDrmManagerService::onTransact :READ");
1385        CHECK_INTERFACE(IDrmManagerService, data, reply);
1386
1387        const int uniqueId = data.readInt32();
1388
1389        DecryptHandle handle;
1390        handle.decryptId = data.readInt32();
1391        handle.mimeType = data.readString8();
1392        handle.decryptApiType = data.readInt32();
1393        handle.status = data.readInt32();
1394        handle.decryptInfo = NULL;
1395
1396        const int bufferLength = data.readInt32();
1397        if (INVALID_BUFFER_LENGTH != bufferLength) {
1398            handle.decryptInfo = new DecryptInfo();
1399            handle.decryptInfo->decryptBufferLength = bufferLength;
1400        }
1401
1402        const int numBytes = data.readInt32();
1403        char* buffer = new char[numBytes];
1404
1405        const off_t offset = data.readInt32();
1406
1407        ssize_t result = pread(uniqueId, &handle, buffer, numBytes, offset);
1408        reply->writeInt32(result);
1409        if (0 < result) {
1410            reply->write(buffer, result);
1411        }
1412
1413        delete handle.decryptInfo; handle.decryptInfo = NULL;
1414        delete [] buffer, buffer = NULL;
1415        return DRM_NO_ERROR;
1416    }
1417
1418    default:
1419        return BBinder::onTransact(code, data, reply, flags);
1420    }
1421}
1422
1423