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
3727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
3827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshiusing namespace android;
3927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
40c10ce33302f91896fc2a87c13b00518a4bc26e3aGloria Wangstatic void writeDecryptHandleToParcelData(
411da9aa606096e14985924e8433a087d04f68ea22Gloria Wang        const DecryptHandle* handle, Parcel* data) {
421da9aa606096e14985924e8433a087d04f68ea22Gloria Wang    data->writeInt32(handle->decryptId);
431da9aa606096e14985924e8433a087d04f68ea22Gloria Wang    data->writeString8(handle->mimeType);
441da9aa606096e14985924e8433a087d04f68ea22Gloria Wang    data->writeInt32(handle->decryptApiType);
451da9aa606096e14985924e8433a087d04f68ea22Gloria Wang    data->writeInt32(handle->status);
461da9aa606096e14985924e8433a087d04f68ea22Gloria Wang
471da9aa606096e14985924e8433a087d04f68ea22Gloria Wang    int size = handle->copyControlVector.size();
481da9aa606096e14985924e8433a087d04f68ea22Gloria Wang    data->writeInt32(size);
49c10ce33302f91896fc2a87c13b00518a4bc26e3aGloria Wang    for (int i = 0; i < size; i++) {
501da9aa606096e14985924e8433a087d04f68ea22Gloria Wang        data->writeInt32(handle->copyControlVector.keyAt(i));
511da9aa606096e14985924e8433a087d04f68ea22Gloria Wang        data->writeInt32(handle->copyControlVector.valueAt(i));
521da9aa606096e14985924e8433a087d04f68ea22Gloria Wang    }
531da9aa606096e14985924e8433a087d04f68ea22Gloria Wang
546b2a35bbec228ce012065260ba153ee894f17a4eGloria Wang    size = handle->extendedData.size();
556b2a35bbec228ce012065260ba153ee894f17a4eGloria Wang    data->writeInt32(size);
56c10ce33302f91896fc2a87c13b00518a4bc26e3aGloria Wang    for (int i = 0; i < size; i++) {
576b2a35bbec228ce012065260ba153ee894f17a4eGloria Wang        data->writeString8(handle->extendedData.keyAt(i));
586b2a35bbec228ce012065260ba153ee894f17a4eGloria Wang        data->writeString8(handle->extendedData.valueAt(i));
596b2a35bbec228ce012065260ba153ee894f17a4eGloria Wang    }
606b2a35bbec228ce012065260ba153ee894f17a4eGloria Wang
611da9aa606096e14985924e8433a087d04f68ea22Gloria Wang    if (NULL != handle->decryptInfo) {
621da9aa606096e14985924e8433a087d04f68ea22Gloria Wang        data->writeInt32(handle->decryptInfo->decryptBufferLength);
631da9aa606096e14985924e8433a087d04f68ea22Gloria Wang    } else {
641da9aa606096e14985924e8433a087d04f68ea22Gloria Wang        data->writeInt32(INVALID_BUFFER_LENGTH);
651da9aa606096e14985924e8433a087d04f68ea22Gloria Wang    }
661da9aa606096e14985924e8433a087d04f68ea22Gloria Wang}
671da9aa606096e14985924e8433a087d04f68ea22Gloria Wang
681da9aa606096e14985924e8433a087d04f68ea22Gloria Wangstatic void readDecryptHandleFromParcelData(
691da9aa606096e14985924e8433a087d04f68ea22Gloria Wang        DecryptHandle* handle, const Parcel& data) {
701da9aa606096e14985924e8433a087d04f68ea22Gloria Wang    if (0 == data.dataAvail()) {
711da9aa606096e14985924e8433a087d04f68ea22Gloria Wang        return;
721da9aa606096e14985924e8433a087d04f68ea22Gloria Wang    }
731da9aa606096e14985924e8433a087d04f68ea22Gloria Wang
741da9aa606096e14985924e8433a087d04f68ea22Gloria Wang    handle->decryptId = data.readInt32();
751da9aa606096e14985924e8433a087d04f68ea22Gloria Wang    handle->mimeType = data.readString8();
761da9aa606096e14985924e8433a087d04f68ea22Gloria Wang    handle->decryptApiType = data.readInt32();
771da9aa606096e14985924e8433a087d04f68ea22Gloria Wang    handle->status = data.readInt32();
781da9aa606096e14985924e8433a087d04f68ea22Gloria Wang
791da9aa606096e14985924e8433a087d04f68ea22Gloria Wang    int size = data.readInt32();
80c10ce33302f91896fc2a87c13b00518a4bc26e3aGloria Wang    for (int i = 0; i < size; i++) {
816b2a35bbec228ce012065260ba153ee894f17a4eGloria Wang        DrmCopyControl key = (DrmCopyControl)data.readInt32();
826b2a35bbec228ce012065260ba153ee894f17a4eGloria Wang        int value = data.readInt32();
836b2a35bbec228ce012065260ba153ee894f17a4eGloria Wang        handle->copyControlVector.add(key, value);
846b2a35bbec228ce012065260ba153ee894f17a4eGloria Wang    }
856b2a35bbec228ce012065260ba153ee894f17a4eGloria Wang
866b2a35bbec228ce012065260ba153ee894f17a4eGloria Wang    size = data.readInt32();
87c10ce33302f91896fc2a87c13b00518a4bc26e3aGloria Wang    for (int i = 0; i < size; i++) {
886b2a35bbec228ce012065260ba153ee894f17a4eGloria Wang        String8 key = data.readString8();
896b2a35bbec228ce012065260ba153ee894f17a4eGloria Wang        String8 value = data.readString8();
906b2a35bbec228ce012065260ba153ee894f17a4eGloria Wang        handle->extendedData.add(key, value);
911da9aa606096e14985924e8433a087d04f68ea22Gloria Wang    }
921da9aa606096e14985924e8433a087d04f68ea22Gloria Wang
931da9aa606096e14985924e8433a087d04f68ea22Gloria Wang    handle->decryptInfo = NULL;
941da9aa606096e14985924e8433a087d04f68ea22Gloria Wang    const int bufferLen = data.readInt32();
951da9aa606096e14985924e8433a087d04f68ea22Gloria Wang    if (INVALID_BUFFER_LENGTH != bufferLen) {
961da9aa606096e14985924e8433a087d04f68ea22Gloria Wang        handle->decryptInfo = new DecryptInfo();
971da9aa606096e14985924e8433a087d04f68ea22Gloria Wang        handle->decryptInfo->decryptBufferLength = bufferLen;
981da9aa606096e14985924e8433a087d04f68ea22Gloria Wang    }
991da9aa606096e14985924e8433a087d04f68ea22Gloria Wang}
1001da9aa606096e14985924e8433a087d04f68ea22Gloria Wang
1011da9aa606096e14985924e8433a087d04f68ea22Gloria Wangstatic void clearDecryptHandle(DecryptHandle* handle) {
1021da9aa606096e14985924e8433a087d04f68ea22Gloria Wang    if (handle == NULL) {
1031da9aa606096e14985924e8433a087d04f68ea22Gloria Wang        return;
1041da9aa606096e14985924e8433a087d04f68ea22Gloria Wang    }
1051da9aa606096e14985924e8433a087d04f68ea22Gloria Wang    if (handle->decryptInfo) {
1061da9aa606096e14985924e8433a087d04f68ea22Gloria Wang        delete handle->decryptInfo;
1071da9aa606096e14985924e8433a087d04f68ea22Gloria Wang        handle->decryptInfo = NULL;
1081da9aa606096e14985924e8433a087d04f68ea22Gloria Wang    }
1091da9aa606096e14985924e8433a087d04f68ea22Gloria Wang    handle->copyControlVector.clear();
110ab00df4d8585b181e9058eb1b9c7996aa3bbaeabGloria Wang    handle->extendedData.clear();
1111da9aa606096e14985924e8433a087d04f68ea22Gloria Wang}
1121da9aa606096e14985924e8433a087d04f68ea22Gloria Wang
1138f00151cbe693d52f3e233757c57fab3b6396d21Gloria Wangint BpDrmManagerService::addUniqueId(bool isNative) {
1143856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("add uniqueid");
1152272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi    Parcel data, reply;
1162272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
1178f00151cbe693d52f3e233757c57fab3b6396d21Gloria Wang    data.writeInt32(isNative);
1182272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi    remote()->transact(ADD_UNIQUEID, data, &reply);
1192272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi    return reply.readInt32();
1202272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi}
1212272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi
1222272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimivoid BpDrmManagerService::removeUniqueId(int uniqueId) {
1233856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("remove uniqueid");
1242272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi    Parcel data, reply;
1252272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
1262272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi    data.writeInt32(uniqueId);
1272272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi    remote()->transact(REMOVE_UNIQUEID, data, &reply);
1282272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi}
1292272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi
130e943f84129326ab885cc7a69dcfa17f766b72b89Takeshi Aimivoid BpDrmManagerService::addClient(int uniqueId) {
13127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    Parcel data, reply;
13227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
13327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
134e943f84129326ab885cc7a69dcfa17f766b72b89Takeshi Aimi    remote()->transact(ADD_CLIENT, data, &reply);
13527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
13627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
137e943f84129326ab885cc7a69dcfa17f766b72b89Takeshi Aimivoid BpDrmManagerService::removeClient(int uniqueId) {
13827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    Parcel data, reply;
13927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
14027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
141e943f84129326ab885cc7a69dcfa17f766b72b89Takeshi Aimi    remote()->transact(REMOVE_CLIENT, data, &reply);
14227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
14327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
14427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshistatus_t BpDrmManagerService::setDrmServiceListener(
14527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            int uniqueId, const sp<IDrmServiceListener>& drmServiceListener) {
1463856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("setDrmServiceListener");
14727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    Parcel data, reply;
14827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
14927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
15027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
15127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeStrongBinder(drmServiceListener->asBinder());
15227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    remote()->transact(SET_DRM_SERVICE_LISTENER, data, &reply);
15327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return reply.readInt32();
15427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
15527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
15627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshistatus_t BpDrmManagerService::installDrmEngine(int uniqueId, const String8& drmEngineFile) {
1573856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("Install DRM Engine");
15827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    Parcel data, reply;
15927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
16027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
16127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
16227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeString8(drmEngineFile);
16327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
16427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    remote()->transact(INSTALL_DRM_ENGINE, data, &reply);
16527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return reply.readInt32();
16627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
16727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
16827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshiDrmConstraints* BpDrmManagerService::getConstraints(
16927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            int uniqueId, const String8* path, const int action) {
1703856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("Get Constraints");
17127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    Parcel data, reply;
17227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
17327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
17427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
17527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeString8(*path);
17627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(action);
17727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
17827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    remote()->transact(GET_CONSTRAINTS_FROM_CONTENT, data, &reply);
17927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
18027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    DrmConstraints* drmConstraints = NULL;
18127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    if (0 != reply.dataAvail()) {
18227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        //Filling Drm Constraints
18327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        drmConstraints = new DrmConstraints();
18427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
18527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        const int size = reply.readInt32();
18627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        for (int index = 0; index < size; ++index) {
18727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            const String8 key(reply.readString8());
18827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            const int bufferSize = reply.readInt32();
18927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            char* data = NULL;
19027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            if (0 < bufferSize) {
19127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi                data = new char[bufferSize];
19227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi                reply.read(data, bufferSize);
19327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            }
19427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            drmConstraints->put(&key, data);
19527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        }
19627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    }
19727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return drmConstraints;
19827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
19927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
2003473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi AimiDrmMetadata* BpDrmManagerService::getMetadata(int uniqueId, const String8* path) {
2013856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("Get Metadata");
2023473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi    Parcel data, reply;
2033473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
2043473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi    data.writeInt32(uniqueId);
2053473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi
2063473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi    DrmMetadata* drmMetadata = NULL;
2073473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi    data.writeString8(*path);
2083473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi    remote()->transact(GET_METADATA_FROM_CONTENT, data, &reply);
2093473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi
2103473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi    if (0 != reply.dataAvail()) {
2113473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi        //Filling Drm Metadata
2123473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi        drmMetadata = new DrmMetadata();
2133473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi
2143473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi        const int size = reply.readInt32();
2153473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi        for (int index = 0; index < size; ++index) {
2163473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi            const String8 key(reply.readString8());
2173473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi            const int bufferSize = reply.readInt32();
2183473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi            char* data = NULL;
2193473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi            if (0 < bufferSize) {
2203473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi                data = new char[bufferSize];
2213473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi                reply.read(data, bufferSize);
2223473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi            }
2233473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi            drmMetadata->put(&key, data);
2243473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi        }
2253473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi    }
2263473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi    return drmMetadata;
2273473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi}
2283473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi
22927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshibool BpDrmManagerService::canHandle(int uniqueId, const String8& path, const String8& mimeType) {
2303856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("Can Handle");
23127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    Parcel data, reply;
23227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
23327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
23427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
23527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
23627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeString8(path);
23727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeString8(mimeType);
23827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
23927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    remote()->transact(CAN_HANDLE, data, &reply);
24027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
24127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return static_cast<bool>(reply.readInt32());
24227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
24327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
24427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshiDrmInfoStatus* BpDrmManagerService::processDrmInfo(int uniqueId, const DrmInfo* drmInfo) {
2453856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("Process DRM Info");
24627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    Parcel data, reply;
24727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
24827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
24927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
25027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
25127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    //Filling DRM info
25227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(drmInfo->getInfoType());
25327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    const DrmBuffer dataBuffer = drmInfo->getData();
25427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    const int dataBufferSize = dataBuffer.length;
25527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(dataBufferSize);
25627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    if (0 < dataBufferSize) {
25727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        data.write(dataBuffer.data, dataBufferSize);
25827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    }
25927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeString8(drmInfo->getMimeType());
26027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
26127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(drmInfo->getCount());
26227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    DrmInfo::KeyIterator keyIt = drmInfo->keyIterator();
26327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
26427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    while (keyIt.hasNext()) {
26527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        const String8 key = keyIt.next();
26627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        data.writeString8(key);
26727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        const String8 value = drmInfo->get(key);
26827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        data.writeString8((value == String8("")) ? String8("NULL") : value);
26927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    }
27027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
27127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    remote()->transact(PROCESS_DRM_INFO, data, &reply);
27227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
27327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    DrmInfoStatus* drmInfoStatus = NULL;
27427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    if (0 != reply.dataAvail()) {
27527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        //Filling DRM Info Status
27627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        const int statusCode = reply.readInt32();
277e943f84129326ab885cc7a69dcfa17f766b72b89Takeshi Aimi        const int infoType = reply.readInt32();
27827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        const String8 mimeType = reply.readString8();
27927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
28027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        DrmBuffer* drmBuffer = NULL;
28127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        if (0 != reply.dataAvail()) {
28227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            const int bufferSize = reply.readInt32();
28327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            char* data = NULL;
28427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            if (0 < bufferSize) {
28527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi                data = new char[bufferSize];
28627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi                reply.read(data, bufferSize);
28727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            }
28827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            drmBuffer = new DrmBuffer(data, bufferSize);
28927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        }
290e943f84129326ab885cc7a69dcfa17f766b72b89Takeshi Aimi        drmInfoStatus = new DrmInfoStatus(statusCode, infoType, drmBuffer, mimeType);
29127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    }
29227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return drmInfoStatus;
29327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
29427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
29527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshiDrmInfo* BpDrmManagerService::acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInforequest) {
2963856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("Acquire DRM Info");
29727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    Parcel data, reply;
29827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
29927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
30027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
30127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
30227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    //Filling DRM Info Request
30327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(drmInforequest->getInfoType());
30427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeString8(drmInforequest->getMimeType());
30527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
30627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(drmInforequest->getCount());
30727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    DrmInfoRequest::KeyIterator keyIt = drmInforequest->keyIterator();
30827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
30927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    while (keyIt.hasNext()) {
31027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        const String8 key = keyIt.next();
31127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        data.writeString8(key);
31227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        const String8 value = drmInforequest->get(key);
3130abeaca9d1b53ee40ce9c9d2ef543dd83b5a4cc2Gene Morgan        if (key == String8("FileDescriptorKey")) {
3140abeaca9d1b53ee40ce9c9d2ef543dd83b5a4cc2Gene Morgan            int fd = -1;
3150abeaca9d1b53ee40ce9c9d2ef543dd83b5a4cc2Gene Morgan            sscanf(value.string(), "FileDescriptor[%d]", &fd);
3160abeaca9d1b53ee40ce9c9d2ef543dd83b5a4cc2Gene Morgan            data.writeFileDescriptor(fd);
3170abeaca9d1b53ee40ce9c9d2ef543dd83b5a4cc2Gene Morgan        } else {
3180abeaca9d1b53ee40ce9c9d2ef543dd83b5a4cc2Gene Morgan            data.writeString8((value == String8("")) ? String8("NULL") : value);
3190abeaca9d1b53ee40ce9c9d2ef543dd83b5a4cc2Gene Morgan        }
32027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    }
32127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
32227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    remote()->transact(ACQUIRE_DRM_INFO, data, &reply);
32327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
32427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    DrmInfo* drmInfo = NULL;
32527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    if (0 != reply.dataAvail()) {
32627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        //Filling DRM Info
32727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        const int infoType = reply.readInt32();
32827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        const int bufferSize = reply.readInt32();
32927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        char* data = NULL;
33027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
33127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        if (0 < bufferSize) {
33227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            data = new char[bufferSize];
33327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            reply.read(data, bufferSize);
33427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        }
33527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        drmInfo = new DrmInfo(infoType, DrmBuffer(data, bufferSize), reply.readString8());
33627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
33727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        const int size = reply.readInt32();
33827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        for (int index = 0; index < size; ++index) {
33927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            const String8 key(reply.readString8());
34027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            const String8 value(reply.readString8());
34127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            drmInfo->put(key, (value == String8("NULL")) ? String8("") : value);
34227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        }
34327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    }
34427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return drmInfo;
34527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
34627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
3472272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimistatus_t BpDrmManagerService::saveRights(
34827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            int uniqueId, const DrmRights& drmRights,
34927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            const String8& rightsPath, const String8& contentPath) {
3503856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("Save Rights");
35127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    Parcel data, reply;
35227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
35327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
35427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
35527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
35627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    //Filling Drm Rights
35727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    const DrmBuffer dataBuffer = drmRights.getData();
35827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(dataBuffer.length);
35927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.write(dataBuffer.data, dataBuffer.length);
36027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
36127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    const String8 mimeType = drmRights.getMimeType();
36227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeString8((mimeType == String8("")) ? String8("NULL") : mimeType);
36327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
36427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    const String8 accountId = drmRights.getAccountId();
36527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeString8((accountId == String8("")) ? String8("NULL") : accountId);
36627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
36727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    const String8 subscriptionId = drmRights.getSubscriptionId();
36827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeString8((subscriptionId == String8("")) ? String8("NULL") : subscriptionId);
36927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
37027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeString8((rightsPath == String8("")) ? String8("NULL") : rightsPath);
37127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeString8((contentPath == String8("")) ? String8("NULL") : contentPath);
37227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
37327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    remote()->transact(SAVE_RIGHTS, data, &reply);
3742272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi    return reply.readInt32();
37527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
37627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
377bf5b3b29e31b293313788d7464cfb258ac0da803James DongString8 BpDrmManagerService::getOriginalMimeType(int uniqueId, const String8& path, int fd) {
3783856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("Get Original MimeType");
37927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    Parcel data, reply;
38027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
38127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
38227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
38327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeString8(path);
384bf5b3b29e31b293313788d7464cfb258ac0da803James Dong    int32_t isFdValid = (fd >= 0);
385bf5b3b29e31b293313788d7464cfb258ac0da803James Dong    data.writeInt32(isFdValid);
386bf5b3b29e31b293313788d7464cfb258ac0da803James Dong    if (isFdValid) {
387bf5b3b29e31b293313788d7464cfb258ac0da803James Dong        data.writeFileDescriptor(fd);
388bf5b3b29e31b293313788d7464cfb258ac0da803James Dong    }
38927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
39027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    remote()->transact(GET_ORIGINAL_MIMETYPE, data, &reply);
39127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return reply.readString8();
39227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
39327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
39427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshiint BpDrmManagerService::getDrmObjectType(
39527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            int uniqueId, const String8& path, const String8& mimeType) {
3963856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("Get Drm object type");
39727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    Parcel data, reply;
39827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
39927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
40027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
40127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeString8(path);
40227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeString8(mimeType);
40327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
40427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    remote()->transact(GET_DRM_OBJECT_TYPE, data, &reply);
40527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
40627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return reply.readInt32();
40727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
40827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
40927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshiint BpDrmManagerService::checkRightsStatus(int uniqueId, const String8& path, int action) {
4103856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("checkRightsStatus");
41127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    Parcel data, reply;
41227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
41327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
41427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
41527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeString8(path);
41627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(action);
41727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
41827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    remote()->transact(CHECK_RIGHTS_STATUS, data, &reply);
41927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
42027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return reply.readInt32();
42127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
42227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
4232272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimistatus_t BpDrmManagerService::consumeRights(
42427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) {
4253856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("consumeRights");
4262272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi    Parcel data, reply;
42727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
42827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
42927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
43027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
431c10ce33302f91896fc2a87c13b00518a4bc26e3aGloria Wang    writeDecryptHandleToParcelData(decryptHandle, &data);
43227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
43327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(action);
43427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(static_cast< int>(reserve));
43527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
43627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    remote()->transact(CONSUME_RIGHTS, data, &reply);
4372272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi    return reply.readInt32();
43827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
43927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
4402272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimistatus_t BpDrmManagerService::setPlaybackStatus(
441a2cd44cb5067b4fe98794860690394254d3ac73cGloria Wang            int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int64_t position) {
4423856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("setPlaybackStatus");
44327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    Parcel data, reply;
44427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
44527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
44627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
44727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
448c10ce33302f91896fc2a87c13b00518a4bc26e3aGloria Wang    writeDecryptHandleToParcelData(decryptHandle, &data);
44927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
45027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(playbackStatus);
4512ed8a921ef55aa2f3dd4b7ac33b7ded6ec33d92dGloria Wang    data.writeInt64(position);
45227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
45327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    remote()->transact(SET_PLAYBACK_STATUS, data, &reply);
4542272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi    return reply.readInt32();
45527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
45627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
45727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshibool BpDrmManagerService::validateAction(
45827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            int uniqueId, const String8& path,
45927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            int action, const ActionDescription& description) {
4603856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("validateAction");
46127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    Parcel data, reply;
46227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
46327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
46427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
46527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeString8(path);
46627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(action);
46727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(description.outputType);
46827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(description.configuration);
46927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
47027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    remote()->transact(VALIDATE_ACTION, data, &reply);
47127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
47227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return static_cast<bool>(reply.readInt32());
47327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
47427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
4752272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimistatus_t BpDrmManagerService::removeRights(int uniqueId, const String8& path) {
4763856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("removeRights");
47727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    Parcel data, reply;
47827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
47927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
48027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
48127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeString8(path);
48227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
48327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    remote()->transact(REMOVE_RIGHTS, data, &reply);
4842272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi    return reply.readInt32();
48527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
48627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
4872272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimistatus_t BpDrmManagerService::removeAllRights(int uniqueId) {
4883856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("removeAllRights");
48927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    Parcel data, reply;
49027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
49127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
49227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
49327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
49427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    remote()->transact(REMOVE_ALL_RIGHTS, data, &reply);
4952272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi    return reply.readInt32();
49627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
49727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
49827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshiint BpDrmManagerService::openConvertSession(int uniqueId, const String8& mimeType) {
4993856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("openConvertSession");
50027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    Parcel data, reply;
50127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
50227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
50327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
50427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeString8(mimeType);
50527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
50627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    remote()->transact(OPEN_CONVERT_SESSION, data, &reply);
50727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return reply.readInt32();
50827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
50927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
51027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshiDrmConvertedStatus* BpDrmManagerService::convertData(
51127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            int uniqueId, int convertId, const DrmBuffer* inputData) {
5123856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("convertData");
51327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    Parcel data, reply;
51427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
51527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
51627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
51727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(convertId);
51827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(inputData->length);
51927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.write(inputData->data, inputData->length);
52027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
52127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    remote()->transact(CONVERT_DATA, data, &reply);
52227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
52327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    DrmConvertedStatus* drmConvertedStatus = NULL;
52427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
52527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    if (0 != reply.dataAvail()) {
52627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        //Filling DRM Converted Status
52727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        const int statusCode = reply.readInt32();
528a2cd44cb5067b4fe98794860690394254d3ac73cGloria Wang        const off64_t offset = reply.readInt64();
52927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
53027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        DrmBuffer* convertedData = NULL;
53127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        if (0 != reply.dataAvail()) {
53227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            const int bufferSize = reply.readInt32();
53327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            char* data = NULL;
53427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            if (0 < bufferSize) {
53527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi                data = new char[bufferSize];
53627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi                reply.read(data, bufferSize);
53727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            }
53827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            convertedData = new DrmBuffer(data, bufferSize);
53927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        }
54027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        drmConvertedStatus = new DrmConvertedStatus(statusCode, convertedData, offset);
54127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    }
54227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return drmConvertedStatus;
54327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
54427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
54527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshiDrmConvertedStatus* BpDrmManagerService::closeConvertSession(int uniqueId, int convertId) {
5463856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("closeConvertSession");
54727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    Parcel data, reply;
54827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
54927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
55027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
55127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(convertId);
55227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
55327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    remote()->transact(CLOSE_CONVERT_SESSION, data, &reply);
55427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
55527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    DrmConvertedStatus* drmConvertedStatus = NULL;
55627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
55727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    if (0 != reply.dataAvail()) {
55827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        //Filling DRM Converted Status
55927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        const int statusCode = reply.readInt32();
560a2cd44cb5067b4fe98794860690394254d3ac73cGloria Wang        const off64_t offset = reply.readInt64();
56127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
56227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        DrmBuffer* convertedData = NULL;
56327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        if (0 != reply.dataAvail()) {
56427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            const int bufferSize = reply.readInt32();
56527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            char* data = NULL;
56627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            if (0 < bufferSize) {
56727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi                data = new char[bufferSize];
56827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi                reply.read(data, bufferSize);
56927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            }
57027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            convertedData = new DrmBuffer(data, bufferSize);
57127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        }
57227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        drmConvertedStatus = new DrmConvertedStatus(statusCode, convertedData, offset);
57327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    }
57427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return drmConvertedStatus;
57527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
57627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
57727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshistatus_t BpDrmManagerService::getAllSupportInfo(
57827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray) {
5793856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("Get All Support Info");
58027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    Parcel data, reply;
58127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
58227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
58327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
58427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
58527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    remote()->transact(GET_ALL_SUPPORT_INFO, data, &reply);
58627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
58727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    //Filling DRM Support Info
58827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    const int arraySize = reply.readInt32();
58927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    if (0 < arraySize) {
59027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        *drmSupportInfoArray = new DrmSupportInfo[arraySize];
59127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
592