127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi/*
227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi * Copyright (C) 2010 The Android Open Source Project
327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi *
427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi * Licensed under the Apache License, Version 2.0 (the "License");
527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi * you may not use this file except in compliance with the License.
627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi * You may obtain a copy of the License at
727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi *
827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi *      http://www.apache.org/licenses/LICENSE-2.0
927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi *
1027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi * Unless required by applicable law or agreed to in writing, software
1127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi * distributed under the License is distributed on an "AS IS" BASIS,
1227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi * See the License for the specific language governing permissions and
1427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi * limitations under the License.
1527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi */
1627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
172272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi//#define LOG_NDEBUG 0
1827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi#define LOG_TAG "IDrmManagerService(Native)"
1927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi#include <utils/Log.h>
2027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
2127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi#include <stdint.h>
2227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi#include <sys/types.h>
2327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi#include <binder/IPCThreadState.h>
2427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
2527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi#include <drm/DrmInfo.h>
2627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi#include <drm/DrmConstraints.h>
273473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi#include <drm/DrmMetadata.h>
2827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi#include <drm/DrmRights.h>
2927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi#include <drm/DrmInfoStatus.h>
3027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi#include <drm/DrmConvertedStatus.h>
3127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi#include <drm/DrmInfoRequest.h>
3227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi#include <drm/DrmSupportInfo.h>
3327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
3427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi#include "IDrmManagerService.h"
3527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
3627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi#define INVALID_BUFFER_LENGTH -1
37b408fa26c782c57272f11b46a235cca8c9ccb9beJeff Tinker#define MAX_BINDER_TRANSACTION_SIZE ((1*1024*1024)-(4096*2))
3827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
3927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshiusing namespace android;
4027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
41c10ce33302f91896fc2a87c13b00518a4bc26e3aGloria Wangstatic void writeDecryptHandleToParcelData(
421da9aa606096e14985924e8433a087d04f68ea22Gloria Wang        const DecryptHandle* handle, Parcel* data) {
431da9aa606096e14985924e8433a087d04f68ea22Gloria Wang    data->writeInt32(handle->decryptId);
441da9aa606096e14985924e8433a087d04f68ea22Gloria Wang    data->writeString8(handle->mimeType);
451da9aa606096e14985924e8433a087d04f68ea22Gloria Wang    data->writeInt32(handle->decryptApiType);
461da9aa606096e14985924e8433a087d04f68ea22Gloria Wang    data->writeInt32(handle->status);
471da9aa606096e14985924e8433a087d04f68ea22Gloria Wang
481da9aa606096e14985924e8433a087d04f68ea22Gloria Wang    int size = handle->copyControlVector.size();
491da9aa606096e14985924e8433a087d04f68ea22Gloria Wang    data->writeInt32(size);
50c10ce33302f91896fc2a87c13b00518a4bc26e3aGloria Wang    for (int i = 0; i < size; i++) {
511da9aa606096e14985924e8433a087d04f68ea22Gloria Wang        data->writeInt32(handle->copyControlVector.keyAt(i));
521da9aa606096e14985924e8433a087d04f68ea22Gloria Wang        data->writeInt32(handle->copyControlVector.valueAt(i));
531da9aa606096e14985924e8433a087d04f68ea22Gloria Wang    }
541da9aa606096e14985924e8433a087d04f68ea22Gloria Wang
556b2a35bbec228ce012065260ba153ee894f17a4eGloria Wang    size = handle->extendedData.size();
566b2a35bbec228ce012065260ba153ee894f17a4eGloria Wang    data->writeInt32(size);
57c10ce33302f91896fc2a87c13b00518a4bc26e3aGloria Wang    for (int i = 0; i < size; i++) {
586b2a35bbec228ce012065260ba153ee894f17a4eGloria Wang        data->writeString8(handle->extendedData.keyAt(i));
596b2a35bbec228ce012065260ba153ee894f17a4eGloria Wang        data->writeString8(handle->extendedData.valueAt(i));
606b2a35bbec228ce012065260ba153ee894f17a4eGloria Wang    }
616b2a35bbec228ce012065260ba153ee894f17a4eGloria Wang
621da9aa606096e14985924e8433a087d04f68ea22Gloria Wang    if (NULL != handle->decryptInfo) {
631da9aa606096e14985924e8433a087d04f68ea22Gloria Wang        data->writeInt32(handle->decryptInfo->decryptBufferLength);
641da9aa606096e14985924e8433a087d04f68ea22Gloria Wang    } else {
651da9aa606096e14985924e8433a087d04f68ea22Gloria Wang        data->writeInt32(INVALID_BUFFER_LENGTH);
661da9aa606096e14985924e8433a087d04f68ea22Gloria Wang    }
671da9aa606096e14985924e8433a087d04f68ea22Gloria Wang}
681da9aa606096e14985924e8433a087d04f68ea22Gloria Wang
691da9aa606096e14985924e8433a087d04f68ea22Gloria Wangstatic void readDecryptHandleFromParcelData(
701da9aa606096e14985924e8433a087d04f68ea22Gloria Wang        DecryptHandle* handle, const Parcel& data) {
711da9aa606096e14985924e8433a087d04f68ea22Gloria Wang    if (0 == data.dataAvail()) {
721da9aa606096e14985924e8433a087d04f68ea22Gloria Wang        return;
731da9aa606096e14985924e8433a087d04f68ea22Gloria Wang    }
741da9aa606096e14985924e8433a087d04f68ea22Gloria Wang
751da9aa606096e14985924e8433a087d04f68ea22Gloria Wang    handle->decryptId = data.readInt32();
761da9aa606096e14985924e8433a087d04f68ea22Gloria Wang    handle->mimeType = data.readString8();
771da9aa606096e14985924e8433a087d04f68ea22Gloria Wang    handle->decryptApiType = data.readInt32();
781da9aa606096e14985924e8433a087d04f68ea22Gloria Wang    handle->status = data.readInt32();
791da9aa606096e14985924e8433a087d04f68ea22Gloria Wang
801da9aa606096e14985924e8433a087d04f68ea22Gloria Wang    int size = data.readInt32();
81c10ce33302f91896fc2a87c13b00518a4bc26e3aGloria Wang    for (int i = 0; i < size; i++) {
826b2a35bbec228ce012065260ba153ee894f17a4eGloria Wang        DrmCopyControl key = (DrmCopyControl)data.readInt32();
836b2a35bbec228ce012065260ba153ee894f17a4eGloria Wang        int value = data.readInt32();
846b2a35bbec228ce012065260ba153ee894f17a4eGloria Wang        handle->copyControlVector.add(key, value);
856b2a35bbec228ce012065260ba153ee894f17a4eGloria Wang    }
866b2a35bbec228ce012065260ba153ee894f17a4eGloria Wang
876b2a35bbec228ce012065260ba153ee894f17a4eGloria Wang    size = data.readInt32();
88c10ce33302f91896fc2a87c13b00518a4bc26e3aGloria Wang    for (int i = 0; i < size; i++) {
896b2a35bbec228ce012065260ba153ee894f17a4eGloria Wang        String8 key = data.readString8();
906b2a35bbec228ce012065260ba153ee894f17a4eGloria Wang        String8 value = data.readString8();
916b2a35bbec228ce012065260ba153ee894f17a4eGloria Wang        handle->extendedData.add(key, value);
921da9aa606096e14985924e8433a087d04f68ea22Gloria Wang    }
931da9aa606096e14985924e8433a087d04f68ea22Gloria Wang
941da9aa606096e14985924e8433a087d04f68ea22Gloria Wang    handle->decryptInfo = NULL;
951da9aa606096e14985924e8433a087d04f68ea22Gloria Wang    const int bufferLen = data.readInt32();
961da9aa606096e14985924e8433a087d04f68ea22Gloria Wang    if (INVALID_BUFFER_LENGTH != bufferLen) {
971da9aa606096e14985924e8433a087d04f68ea22Gloria Wang        handle->decryptInfo = new DecryptInfo();
981da9aa606096e14985924e8433a087d04f68ea22Gloria Wang        handle->decryptInfo->decryptBufferLength = bufferLen;
991da9aa606096e14985924e8433a087d04f68ea22Gloria Wang    }
1001da9aa606096e14985924e8433a087d04f68ea22Gloria Wang}
1011da9aa606096e14985924e8433a087d04f68ea22Gloria Wang
1021da9aa606096e14985924e8433a087d04f68ea22Gloria Wangstatic void clearDecryptHandle(DecryptHandle* handle) {
1031da9aa606096e14985924e8433a087d04f68ea22Gloria Wang    if (handle == NULL) {
1041da9aa606096e14985924e8433a087d04f68ea22Gloria Wang        return;
1051da9aa606096e14985924e8433a087d04f68ea22Gloria Wang    }
1061da9aa606096e14985924e8433a087d04f68ea22Gloria Wang    if (handle->decryptInfo) {
1071da9aa606096e14985924e8433a087d04f68ea22Gloria Wang        delete handle->decryptInfo;
1081da9aa606096e14985924e8433a087d04f68ea22Gloria Wang        handle->decryptInfo = NULL;
1091da9aa606096e14985924e8433a087d04f68ea22Gloria Wang    }
1101da9aa606096e14985924e8433a087d04f68ea22Gloria Wang    handle->copyControlVector.clear();
111ab00df4d8585b181e9058eb1b9c7996aa3bbaeabGloria Wang    handle->extendedData.clear();
1121da9aa606096e14985924e8433a087d04f68ea22Gloria Wang}
1131da9aa606096e14985924e8433a087d04f68ea22Gloria Wang
1148f00151cbe693d52f3e233757c57fab3b6396d21Gloria Wangint BpDrmManagerService::addUniqueId(bool isNative) {
1153856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("add uniqueid");
1162272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi    Parcel data, reply;
1172272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
1188f00151cbe693d52f3e233757c57fab3b6396d21Gloria Wang    data.writeInt32(isNative);
1192272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi    remote()->transact(ADD_UNIQUEID, data, &reply);
1202272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi    return reply.readInt32();
1212272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi}
1222272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi
1232272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimivoid BpDrmManagerService::removeUniqueId(int uniqueId) {
1243856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("remove uniqueid");
1252272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi    Parcel data, reply;
1262272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
1272272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi    data.writeInt32(uniqueId);
1282272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi    remote()->transact(REMOVE_UNIQUEID, data, &reply);
1292272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi}
1302272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi
131e943f84129326ab885cc7a69dcfa17f766b72b89Takeshi Aimivoid BpDrmManagerService::addClient(int uniqueId) {
13227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    Parcel data, reply;
13327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
13427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
135e943f84129326ab885cc7a69dcfa17f766b72b89Takeshi Aimi    remote()->transact(ADD_CLIENT, data, &reply);
13627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
13727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
138e943f84129326ab885cc7a69dcfa17f766b72b89Takeshi Aimivoid BpDrmManagerService::removeClient(int uniqueId) {
13927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    Parcel data, reply;
14027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
14127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
142e943f84129326ab885cc7a69dcfa17f766b72b89Takeshi Aimi    remote()->transact(REMOVE_CLIENT, data, &reply);
14327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
14427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
14527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshistatus_t BpDrmManagerService::setDrmServiceListener(
14627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            int uniqueId, const sp<IDrmServiceListener>& drmServiceListener) {
1473856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("setDrmServiceListener");
14827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    Parcel data, reply;
14927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
15027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
15127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
15206b46062d2f8bc82ca3061a23d197734ae51918bMarco Nelissen    data.writeStrongBinder(IInterface::asBinder(drmServiceListener));
15327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    remote()->transact(SET_DRM_SERVICE_LISTENER, data, &reply);
15427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return reply.readInt32();
15527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
15627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
15727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshiDrmConstraints* BpDrmManagerService::getConstraints(
15827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            int uniqueId, const String8* path, const int action) {
1593856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("Get Constraints");
16027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    Parcel data, reply;
16127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
16227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
16327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
16427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeString8(*path);
16527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(action);
16627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
16727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    remote()->transact(GET_CONSTRAINTS_FROM_CONTENT, data, &reply);
16827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
16927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    DrmConstraints* drmConstraints = NULL;
17027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    if (0 != reply.dataAvail()) {
17127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        //Filling Drm Constraints
17227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        drmConstraints = new DrmConstraints();
17327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
17427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        const int size = reply.readInt32();
17527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        for (int index = 0; index < size; ++index) {
17627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            const String8 key(reply.readString8());
17727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            const int bufferSize = reply.readInt32();
17827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            char* data = NULL;
17927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            if (0 < bufferSize) {
18027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi                data = new char[bufferSize];
18127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi                reply.read(data, bufferSize);
1820bf43848adb00922122b0a0eed2fa0318bde8317Hung Nguyen                drmConstraints->put(&key, data);
1830bf43848adb00922122b0a0eed2fa0318bde8317Hung Nguyen                delete[] data;
18427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            }
18527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        }
18627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    }
18727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return drmConstraints;
18827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
18927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
1903473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi AimiDrmMetadata* BpDrmManagerService::getMetadata(int uniqueId, const String8* path) {
1913856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("Get Metadata");
1923473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi    Parcel data, reply;
1933473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
1943473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi    data.writeInt32(uniqueId);
1953473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi
1963473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi    DrmMetadata* drmMetadata = NULL;
1973473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi    data.writeString8(*path);
1983473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi    remote()->transact(GET_METADATA_FROM_CONTENT, data, &reply);
1993473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi
2003473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi    if (0 != reply.dataAvail()) {
2013473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi        //Filling Drm Metadata
2023473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi        drmMetadata = new DrmMetadata();
2033473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi
2043473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi        const int size = reply.readInt32();
2053473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi        for (int index = 0; index < size; ++index) {
2063473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi            const String8 key(reply.readString8());
2073473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi            const int bufferSize = reply.readInt32();
2083473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi            char* data = NULL;
2093473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi            if (0 < bufferSize) {
2103473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi                data = new char[bufferSize];
2113473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi                reply.read(data, bufferSize);
2120bf43848adb00922122b0a0eed2fa0318bde8317Hung Nguyen                drmMetadata->put(&key, data);
2130bf43848adb00922122b0a0eed2fa0318bde8317Hung Nguyen                delete[] data;
2143473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi            }
2153473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi        }
2163473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi    }
2173473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi    return drmMetadata;
2183473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi}
2193473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi
22027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshibool BpDrmManagerService::canHandle(int uniqueId, const String8& path, const String8& mimeType) {
2213856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("Can Handle");
22227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    Parcel data, reply;
22327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
22427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
22527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
22627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
22727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeString8(path);
22827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeString8(mimeType);
22927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
23027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    remote()->transact(CAN_HANDLE, data, &reply);
23127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
23227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return static_cast<bool>(reply.readInt32());
23327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
23427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
23527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshiDrmInfoStatus* BpDrmManagerService::processDrmInfo(int uniqueId, const DrmInfo* drmInfo) {
2363856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("Process DRM Info");
23727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    Parcel data, reply;
23827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
23927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
24027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
24127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
24227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    //Filling DRM info
24327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(drmInfo->getInfoType());
24427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    const DrmBuffer dataBuffer = drmInfo->getData();
24527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    const int dataBufferSize = dataBuffer.length;
24627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(dataBufferSize);
24727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    if (0 < dataBufferSize) {
24827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        data.write(dataBuffer.data, dataBufferSize);
24927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    }
25027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeString8(drmInfo->getMimeType());
25127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
25227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(drmInfo->getCount());
25327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    DrmInfo::KeyIterator keyIt = drmInfo->keyIterator();
25427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
25527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    while (keyIt.hasNext()) {
25627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        const String8 key = keyIt.next();
25727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        data.writeString8(key);
25827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        const String8 value = drmInfo->get(key);
25927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        data.writeString8((value == String8("")) ? String8("NULL") : value);
26027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    }
26127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
26227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    remote()->transact(PROCESS_DRM_INFO, data, &reply);
26327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
26427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    DrmInfoStatus* drmInfoStatus = NULL;
26527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    if (0 != reply.dataAvail()) {
26627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        //Filling DRM Info Status
26727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        const int statusCode = reply.readInt32();
268e943f84129326ab885cc7a69dcfa17f766b72b89Takeshi Aimi        const int infoType = reply.readInt32();
26927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        const String8 mimeType = reply.readString8();
27027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
27127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        DrmBuffer* drmBuffer = NULL;
27227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        if (0 != reply.dataAvail()) {
27327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            const int bufferSize = reply.readInt32();
27427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            char* data = NULL;
27527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            if (0 < bufferSize) {
27627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi                data = new char[bufferSize];
27727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi                reply.read(data, bufferSize);
27827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            }
27927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            drmBuffer = new DrmBuffer(data, bufferSize);
28027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        }
281e943f84129326ab885cc7a69dcfa17f766b72b89Takeshi Aimi        drmInfoStatus = new DrmInfoStatus(statusCode, infoType, drmBuffer, mimeType);
28227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    }
28327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return drmInfoStatus;
28427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
28527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
28627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshiDrmInfo* BpDrmManagerService::acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInforequest) {
2873856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("Acquire DRM Info");
28827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    Parcel data, reply;
28927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
29027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
29127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
29227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
29327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    //Filling DRM Info Request
29427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(drmInforequest->getInfoType());
29527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeString8(drmInforequest->getMimeType());
29627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
29727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(drmInforequest->getCount());
29827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    DrmInfoRequest::KeyIterator keyIt = drmInforequest->keyIterator();
29927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
30027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    while (keyIt.hasNext()) {
30127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        const String8 key = keyIt.next();
30227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        data.writeString8(key);
30327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        const String8 value = drmInforequest->get(key);
3040abeaca9d1b53ee40ce9c9d2ef543dd83b5a4cc2Gene Morgan        if (key == String8("FileDescriptorKey")) {
3050abeaca9d1b53ee40ce9c9d2ef543dd83b5a4cc2Gene Morgan            int fd = -1;
3062b7561f802bac06981dc46867d959e627085a8f7Jeff Tinker            if (sscanf(value.string(), "FileDescriptor[%d]", &fd) != 1) {
3072b7561f802bac06981dc46867d959e627085a8f7Jeff Tinker                sscanf(value.string(), "%d", &fd);
3082b7561f802bac06981dc46867d959e627085a8f7Jeff Tinker            }
3090abeaca9d1b53ee40ce9c9d2ef543dd83b5a4cc2Gene Morgan            data.writeFileDescriptor(fd);
3100abeaca9d1b53ee40ce9c9d2ef543dd83b5a4cc2Gene Morgan        } else {
3110abeaca9d1b53ee40ce9c9d2ef543dd83b5a4cc2Gene Morgan            data.writeString8((value == String8("")) ? String8("NULL") : value);
3120abeaca9d1b53ee40ce9c9d2ef543dd83b5a4cc2Gene Morgan        }
31327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    }
31427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
31527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    remote()->transact(ACQUIRE_DRM_INFO, data, &reply);
31627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
31727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    DrmInfo* drmInfo = NULL;
31827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    if (0 != reply.dataAvail()) {
31927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        //Filling DRM Info
32027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        const int infoType = reply.readInt32();
32127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        const int bufferSize = reply.readInt32();
32227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        char* data = NULL;
32327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
32427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        if (0 < bufferSize) {
32527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            data = new char[bufferSize];
32627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            reply.read(data, bufferSize);
32727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        }
32827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        drmInfo = new DrmInfo(infoType, DrmBuffer(data, bufferSize), reply.readString8());
32927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
33027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        const int size = reply.readInt32();
33127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        for (int index = 0; index < size; ++index) {
33227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            const String8 key(reply.readString8());
33327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            const String8 value(reply.readString8());
33427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            drmInfo->put(key, (value == String8("NULL")) ? String8("") : value);
33527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        }
33627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    }
33727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return drmInfo;
33827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
33927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
3402272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimistatus_t BpDrmManagerService::saveRights(
34127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            int uniqueId, const DrmRights& drmRights,
34227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            const String8& rightsPath, const String8& contentPath) {
3433856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("Save Rights");
34427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    Parcel data, reply;
34527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
34627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
34727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
34827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
34927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    //Filling Drm Rights
35027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    const DrmBuffer dataBuffer = drmRights.getData();
35127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(dataBuffer.length);
35227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.write(dataBuffer.data, dataBuffer.length);
35327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
35427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    const String8 mimeType = drmRights.getMimeType();
35527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeString8((mimeType == String8("")) ? String8("NULL") : mimeType);
35627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
35727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    const String8 accountId = drmRights.getAccountId();
35827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeString8((accountId == String8("")) ? String8("NULL") : accountId);
35927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
36027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    const String8 subscriptionId = drmRights.getSubscriptionId();
36127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeString8((subscriptionId == String8("")) ? String8("NULL") : subscriptionId);
36227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
36327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeString8((rightsPath == String8("")) ? String8("NULL") : rightsPath);
36427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeString8((contentPath == String8("")) ? String8("NULL") : contentPath);
36527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
36627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    remote()->transact(SAVE_RIGHTS, data, &reply);
3672272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi    return reply.readInt32();
36827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
36927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
370bf5b3b29e31b293313788d7464cfb258ac0da803James DongString8 BpDrmManagerService::getOriginalMimeType(int uniqueId, const String8& path, int fd) {
3713856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("Get Original MimeType");
37227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    Parcel data, reply;
37327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
37427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
37527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
37627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeString8(path);
377bf5b3b29e31b293313788d7464cfb258ac0da803James Dong    int32_t isFdValid = (fd >= 0);
378bf5b3b29e31b293313788d7464cfb258ac0da803James Dong    data.writeInt32(isFdValid);
379bf5b3b29e31b293313788d7464cfb258ac0da803James Dong    if (isFdValid) {
380bf5b3b29e31b293313788d7464cfb258ac0da803James Dong        data.writeFileDescriptor(fd);
381bf5b3b29e31b293313788d7464cfb258ac0da803James Dong    }
38227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
38327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    remote()->transact(GET_ORIGINAL_MIMETYPE, data, &reply);
38427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return reply.readString8();
38527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
38627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
38727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshiint BpDrmManagerService::getDrmObjectType(
38827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            int uniqueId, const String8& path, const String8& mimeType) {
3893856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("Get Drm object type");
39027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    Parcel data, reply;
39127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
39227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
39327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
39427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeString8(path);
39527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeString8(mimeType);
39627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
39727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    remote()->transact(GET_DRM_OBJECT_TYPE, data, &reply);
39827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
39927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return reply.readInt32();
40027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
40127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
40227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshiint BpDrmManagerService::checkRightsStatus(int uniqueId, const String8& path, int action) {
4033856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("checkRightsStatus");
40427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    Parcel data, reply;
40527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
40627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
40727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
40827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeString8(path);
40927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(action);
41027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
41127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    remote()->transact(CHECK_RIGHTS_STATUS, data, &reply);
41227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
41327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return reply.readInt32();
41427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
41527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
4162272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimistatus_t BpDrmManagerService::consumeRights(
41727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) {
4183856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("consumeRights");
4192272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi    Parcel data, reply;
42027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
42127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
42227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
42327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
424c10ce33302f91896fc2a87c13b00518a4bc26e3aGloria Wang    writeDecryptHandleToParcelData(decryptHandle, &data);
42527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
42627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(action);
42727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(static_cast< int>(reserve));
42827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
42927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    remote()->transact(CONSUME_RIGHTS, data, &reply);
4302272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi    return reply.readInt32();
43127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
43227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
4332272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimistatus_t BpDrmManagerService::setPlaybackStatus(
434a2cd44cb5067b4fe98794860690394254d3ac73cGloria Wang            int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int64_t position) {
4353856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("setPlaybackStatus");
43627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    Parcel data, reply;
43727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
43827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
43927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
44027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
441c10ce33302f91896fc2a87c13b00518a4bc26e3aGloria Wang    writeDecryptHandleToParcelData(decryptHandle, &data);
44227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
44327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(playbackStatus);
4442ed8a921ef55aa2f3dd4b7ac33b7ded6ec33d92dGloria Wang    data.writeInt64(position);
44527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
44627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    remote()->transact(SET_PLAYBACK_STATUS, data, &reply);
4472272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi    return reply.readInt32();
44827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
44927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
45027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshibool BpDrmManagerService::validateAction(
45127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            int uniqueId, const String8& path,
45227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            int action, const ActionDescription& description) {
4533856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("validateAction");
45427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    Parcel data, reply;
45527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
45627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
45727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
45827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeString8(path);
45927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(action);
46027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(description.outputType);
46127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(description.configuration);
46227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
46327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    remote()->transact(VALIDATE_ACTION, data, &reply);
46427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
46527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return static_cast<bool>(reply.readInt32());
46627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
46727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
4682272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimistatus_t BpDrmManagerService::removeRights(int uniqueId, const String8& path) {
4693856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("removeRights");
47027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    Parcel data, reply;
47127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
47227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
47327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
47427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeString8(path);
47527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
47627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    remote()->transact(REMOVE_RIGHTS, data, &reply);
4772272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi    return reply.readInt32();
47827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
47927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
4802272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimistatus_t BpDrmManagerService::removeAllRights(int uniqueId) {
4813856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("removeAllRights");
48227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    Parcel data, reply;
48327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
48427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
48527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
48627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
48727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    remote()->transact(REMOVE_ALL_RIGHTS, data, &reply);
4882272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi    return reply.readInt32();
48927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
49027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
49127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshiint BpDrmManagerService::openConvertSession(int uniqueId, const String8& mimeType) {
4923856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("openConvertSession");
49327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    Parcel data, reply;
49427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
49527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
49627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
49727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeString8(mimeType);
49827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
49927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    remote()->transact(OPEN_CONVERT_SESSION, data, &reply);
50027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return reply.readInt32();
50127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
50227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
50327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshiDrmConvertedStatus* BpDrmManagerService::convertData(
50427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            int uniqueId, int convertId, const DrmBuffer* inputData) {
5053856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("convertData");
50627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    Parcel data, reply;
50727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
50827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
50927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
51027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(convertId);
51127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(inputData->length);
51227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.write(inputData->data, inputData->length);
51327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
51427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    remote()->transact(CONVERT_DATA, data, &reply);
51527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
51627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    DrmConvertedStatus* drmConvertedStatus = NULL;
51727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
51827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    if (0 != reply.dataAvail()) {
51927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        //Filling DRM Converted Status
52027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        const int statusCode = reply.readInt32();
521a2cd44cb5067b4fe98794860690394254d3ac73cGloria Wang        const off64_t offset = reply.readInt64();
52227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
52327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        DrmBuffer* convertedData = NULL;
52427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        if (0 != reply.dataAvail()) {
52527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            const int bufferSize = reply.readInt32();
52627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            char* data = NULL;
52727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            if (0 < bufferSize) {
52827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi                data = new char[bufferSize];
52927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi                reply.read(data, bufferSize);
53027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            }
53127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            convertedData = new DrmBuffer(data, bufferSize);
53227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        }
53327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        drmConvertedStatus = new DrmConvertedStatus(statusCode, convertedData, offset);
53427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    }
53527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return drmConvertedStatus;
53627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
53727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
53827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshiDrmConvertedStatus* BpDrmManagerService::closeConvertSession(int uniqueId, int convertId) {
5393856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("closeConvertSession");
54027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    Parcel data, reply;
54127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
54227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
54327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
54427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(convertId);
54527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
54627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    remote()->transact(CLOSE_CONVERT_SESSION, data, &reply);
54727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
54827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    DrmConvertedStatus* drmConvertedStatus = NULL;
54927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
55027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    if (0 != reply.dataAvail()) {
55127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        //Filling DRM Converted Status
55227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        const int statusCode = reply.readInt32();
553a2cd44cb5067b4fe98794860690394254d3ac73cGloria Wang        const off64_t offset = reply.readInt64();
55427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
55527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        DrmBuffer* convertedData = NULL;
55627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        if (0 != reply.dataAvail()) {
55727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            const int bufferSize = reply.readInt32();
55827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            char* data = NULL;
55927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            if (0 < bufferSize) {
56027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi                data = new char[bufferSize];
56127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi                reply.read(data, bufferSize);
56227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            }
56327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            convertedData = new DrmBuffer(data, bufferSize);
56427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        }
56527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        drmConvertedStatus = new DrmConvertedStatus(statusCode, convertedData, offset);
56627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    }
56727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return drmConvertedStatus;
56827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
56927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
57027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshistatus_t BpDrmManagerService::getAllSupportInfo(
57127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray) {
5723856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("Get All Support Info");
57327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    Parcel data, reply;
57427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
57527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
57627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
57727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
57827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    remote()->transact(GET_ALL_SUPPORT_INFO, data, &reply);
57927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
58027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    //Filling DRM Support Info
58127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    const int arraySize = reply.readInt32();
58227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    if (0 < arraySize) {
58327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        *drmSupportInfoArray = new DrmSupportInfo[arraySize];
58427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
58527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        for (int index = 0; index < arraySize; ++index) {
58627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            DrmSupportInfo drmSupportInfo;
58727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
58827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            const int fileSuffixVectorSize = reply.readInt32();
58927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            for (int i = 0; i < fileSuffixVectorSize; ++i) {
59027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi                drmSupportInfo.addFileSuffix(reply.readString8());
59127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            }
59227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
59327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            const int mimeTypeVectorSize = reply.readInt32();
59427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            for (int i = 0; i < mimeTypeVectorSize; ++i) {
595