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
15627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshiDrmConstraints* BpDrmManagerService::getConstraints(
15727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            int uniqueId, const String8* path, const int action) {
1583856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("Get Constraints");
15927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    Parcel data, reply;
16027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
16127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
16227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
16327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeString8(*path);
16427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(action);
16527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
16627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    remote()->transact(GET_CONSTRAINTS_FROM_CONTENT, data, &reply);
16727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
16827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    DrmConstraints* drmConstraints = NULL;
16927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    if (0 != reply.dataAvail()) {
17027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        //Filling Drm Constraints
17127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        drmConstraints = new DrmConstraints();
17227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
17327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        const int size = reply.readInt32();
17427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        for (int index = 0; index < size; ++index) {
17527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            const String8 key(reply.readString8());
17627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            const int bufferSize = reply.readInt32();
17727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            char* data = NULL;
17827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            if (0 < bufferSize) {
17927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi                data = new char[bufferSize];
18027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi                reply.read(data, bufferSize);
1810bf43848adb00922122b0a0eed2fa0318bde8317Hung Nguyen                drmConstraints->put(&key, data);
1820bf43848adb00922122b0a0eed2fa0318bde8317Hung Nguyen                delete[] data;
18327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            }
18427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        }
18527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    }
18627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return drmConstraints;
18727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
18827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
1893473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi AimiDrmMetadata* BpDrmManagerService::getMetadata(int uniqueId, const String8* path) {
1903856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("Get Metadata");
1913473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi    Parcel data, reply;
1923473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
1933473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi    data.writeInt32(uniqueId);
1943473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi
1953473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi    DrmMetadata* drmMetadata = NULL;
1963473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi    data.writeString8(*path);
1973473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi    remote()->transact(GET_METADATA_FROM_CONTENT, data, &reply);
1983473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi
1993473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi    if (0 != reply.dataAvail()) {
2003473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi        //Filling Drm Metadata
2013473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi        drmMetadata = new DrmMetadata();
2023473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi
2033473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi        const int size = reply.readInt32();
2043473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi        for (int index = 0; index < size; ++index) {
2053473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi            const String8 key(reply.readString8());
2063473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi            const int bufferSize = reply.readInt32();
2073473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi            char* data = NULL;
2083473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi            if (0 < bufferSize) {
2093473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi                data = new char[bufferSize];
2103473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi                reply.read(data, bufferSize);
2110bf43848adb00922122b0a0eed2fa0318bde8317Hung Nguyen                drmMetadata->put(&key, data);
2120bf43848adb00922122b0a0eed2fa0318bde8317Hung Nguyen                delete[] data;
2133473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi            }
2143473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi        }
2153473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi    }
2163473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi    return drmMetadata;
2173473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi}
2183473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi
21927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshibool BpDrmManagerService::canHandle(int uniqueId, const String8& path, const String8& mimeType) {
2203856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("Can Handle");
22127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    Parcel data, reply;
22227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
22327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
22427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
22527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
22627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeString8(path);
22727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeString8(mimeType);
22827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
22927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    remote()->transact(CAN_HANDLE, data, &reply);
23027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
23127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return static_cast<bool>(reply.readInt32());
23227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
23327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
23427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshiDrmInfoStatus* BpDrmManagerService::processDrmInfo(int uniqueId, const DrmInfo* drmInfo) {
2353856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("Process DRM Info");
23627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    Parcel data, reply;
23727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
23827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
23927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
24027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
24127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    //Filling DRM info
24227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(drmInfo->getInfoType());
24327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    const DrmBuffer dataBuffer = drmInfo->getData();
24427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    const int dataBufferSize = dataBuffer.length;
24527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(dataBufferSize);
24627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    if (0 < dataBufferSize) {
24727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        data.write(dataBuffer.data, dataBufferSize);
24827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    }
24927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeString8(drmInfo->getMimeType());
25027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
25127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(drmInfo->getCount());
25227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    DrmInfo::KeyIterator keyIt = drmInfo->keyIterator();
25327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
25427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    while (keyIt.hasNext()) {
25527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        const String8 key = keyIt.next();
25627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        data.writeString8(key);
25727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        const String8 value = drmInfo->get(key);
25827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        data.writeString8((value == String8("")) ? String8("NULL") : value);
25927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    }
26027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
26127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    remote()->transact(PROCESS_DRM_INFO, data, &reply);
26227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
26327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    DrmInfoStatus* drmInfoStatus = NULL;
26427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    if (0 != reply.dataAvail()) {
26527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        //Filling DRM Info Status
26627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        const int statusCode = reply.readInt32();
267e943f84129326ab885cc7a69dcfa17f766b72b89Takeshi Aimi        const int infoType = reply.readInt32();
26827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        const String8 mimeType = reply.readString8();
26927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
27027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        DrmBuffer* drmBuffer = NULL;
27127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        if (0 != reply.dataAvail()) {
27227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            const int bufferSize = reply.readInt32();
27327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            char* data = NULL;
27427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            if (0 < bufferSize) {
27527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi                data = new char[bufferSize];
27627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi                reply.read(data, bufferSize);
27727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            }
27827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            drmBuffer = new DrmBuffer(data, bufferSize);
27927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        }
280e943f84129326ab885cc7a69dcfa17f766b72b89Takeshi Aimi        drmInfoStatus = new DrmInfoStatus(statusCode, infoType, drmBuffer, mimeType);
28127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    }
28227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return drmInfoStatus;
28327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
28427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
28527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshiDrmInfo* BpDrmManagerService::acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInforequest) {
2863856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("Acquire DRM Info");
28727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    Parcel data, reply;
28827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
28927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
29027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
29127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
29227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    //Filling DRM Info Request
29327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(drmInforequest->getInfoType());
29427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeString8(drmInforequest->getMimeType());
29527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
29627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(drmInforequest->getCount());
29727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    DrmInfoRequest::KeyIterator keyIt = drmInforequest->keyIterator();
29827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
29927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    while (keyIt.hasNext()) {
30027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        const String8 key = keyIt.next();
30127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        data.writeString8(key);
30227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        const String8 value = drmInforequest->get(key);
3030abeaca9d1b53ee40ce9c9d2ef543dd83b5a4cc2Gene Morgan        if (key == String8("FileDescriptorKey")) {
3040abeaca9d1b53ee40ce9c9d2ef543dd83b5a4cc2Gene Morgan            int fd = -1;
3050abeaca9d1b53ee40ce9c9d2ef543dd83b5a4cc2Gene Morgan            sscanf(value.string(), "FileDescriptor[%d]", &fd);
3060abeaca9d1b53ee40ce9c9d2ef543dd83b5a4cc2Gene Morgan            data.writeFileDescriptor(fd);
3070abeaca9d1b53ee40ce9c9d2ef543dd83b5a4cc2Gene Morgan        } else {
3080abeaca9d1b53ee40ce9c9d2ef543dd83b5a4cc2Gene Morgan            data.writeString8((value == String8("")) ? String8("NULL") : value);
3090abeaca9d1b53ee40ce9c9d2ef543dd83b5a4cc2Gene Morgan        }
31027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    }
31127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
31227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    remote()->transact(ACQUIRE_DRM_INFO, data, &reply);
31327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
31427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    DrmInfo* drmInfo = NULL;
31527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    if (0 != reply.dataAvail()) {
31627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        //Filling DRM Info
31727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        const int infoType = reply.readInt32();
31827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        const int bufferSize = reply.readInt32();
31927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        char* data = NULL;
32027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
32127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        if (0 < bufferSize) {
32227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            data = new char[bufferSize];
32327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            reply.read(data, bufferSize);
32427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        }
32527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        drmInfo = new DrmInfo(infoType, DrmBuffer(data, bufferSize), reply.readString8());
32627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
32727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        const int size = reply.readInt32();
32827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        for (int index = 0; index < size; ++index) {
32927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            const String8 key(reply.readString8());
33027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            const String8 value(reply.readString8());
33127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            drmInfo->put(key, (value == String8("NULL")) ? String8("") : value);
33227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        }
33327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    }
33427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return drmInfo;
33527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
33627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
3372272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimistatus_t BpDrmManagerService::saveRights(
33827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            int uniqueId, const DrmRights& drmRights,
33927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            const String8& rightsPath, const String8& contentPath) {
3403856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("Save Rights");
34127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    Parcel data, reply;
34227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
34327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
34427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
34527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
34627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    //Filling Drm Rights
34727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    const DrmBuffer dataBuffer = drmRights.getData();
34827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(dataBuffer.length);
34927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.write(dataBuffer.data, dataBuffer.length);
35027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
35127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    const String8 mimeType = drmRights.getMimeType();
35227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeString8((mimeType == String8("")) ? String8("NULL") : mimeType);
35327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
35427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    const String8 accountId = drmRights.getAccountId();
35527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeString8((accountId == String8("")) ? String8("NULL") : accountId);
35627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
35727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    const String8 subscriptionId = drmRights.getSubscriptionId();
35827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeString8((subscriptionId == String8("")) ? String8("NULL") : subscriptionId);
35927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
36027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeString8((rightsPath == String8("")) ? String8("NULL") : rightsPath);
36127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeString8((contentPath == String8("")) ? String8("NULL") : contentPath);
36227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
36327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    remote()->transact(SAVE_RIGHTS, data, &reply);
3642272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi    return reply.readInt32();
36527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
36627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
367bf5b3b29e31b293313788d7464cfb258ac0da803James DongString8 BpDrmManagerService::getOriginalMimeType(int uniqueId, const String8& path, int fd) {
3683856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("Get Original MimeType");
36927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    Parcel data, reply;
37027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
37127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
37227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
37327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeString8(path);
374bf5b3b29e31b293313788d7464cfb258ac0da803James Dong    int32_t isFdValid = (fd >= 0);
375bf5b3b29e31b293313788d7464cfb258ac0da803James Dong    data.writeInt32(isFdValid);
376bf5b3b29e31b293313788d7464cfb258ac0da803James Dong    if (isFdValid) {
377bf5b3b29e31b293313788d7464cfb258ac0da803James Dong        data.writeFileDescriptor(fd);
378bf5b3b29e31b293313788d7464cfb258ac0da803James Dong    }
37927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
38027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    remote()->transact(GET_ORIGINAL_MIMETYPE, data, &reply);
38127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return reply.readString8();
38227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
38327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
38427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshiint BpDrmManagerService::getDrmObjectType(
38527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            int uniqueId, const String8& path, const String8& mimeType) {
3863856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("Get Drm object type");
38727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    Parcel data, reply;
38827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
38927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
39027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
39127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeString8(path);
39227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeString8(mimeType);
39327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
39427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    remote()->transact(GET_DRM_OBJECT_TYPE, data, &reply);
39527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
39627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return reply.readInt32();
39727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
39827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
39927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshiint BpDrmManagerService::checkRightsStatus(int uniqueId, const String8& path, int action) {
4003856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("checkRightsStatus");
40127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    Parcel data, reply;
40227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
40327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
40427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
40527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeString8(path);
40627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(action);
40727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
40827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    remote()->transact(CHECK_RIGHTS_STATUS, data, &reply);
40927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
41027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return reply.readInt32();
41127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
41227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
4132272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimistatus_t BpDrmManagerService::consumeRights(
41427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) {
4153856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("consumeRights");
4162272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi    Parcel data, reply;
41727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
41827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
41927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
42027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
421c10ce33302f91896fc2a87c13b00518a4bc26e3aGloria Wang    writeDecryptHandleToParcelData(decryptHandle, &data);
42227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
42327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(action);
42427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(static_cast< int>(reserve));
42527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
42627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    remote()->transact(CONSUME_RIGHTS, data, &reply);
4272272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi    return reply.readInt32();
42827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
42927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
4302272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimistatus_t BpDrmManagerService::setPlaybackStatus(
431a2cd44cb5067b4fe98794860690394254d3ac73cGloria Wang            int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int64_t position) {
4323856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("setPlaybackStatus");
43327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    Parcel data, reply;
43427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
43527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
43627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
43727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
438c10ce33302f91896fc2a87c13b00518a4bc26e3aGloria Wang    writeDecryptHandleToParcelData(decryptHandle, &data);
43927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
44027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(playbackStatus);
4412ed8a921ef55aa2f3dd4b7ac33b7ded6ec33d92dGloria Wang    data.writeInt64(position);
44227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
44327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    remote()->transact(SET_PLAYBACK_STATUS, data, &reply);
4442272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi    return reply.readInt32();
44527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
44627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
44727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshibool BpDrmManagerService::validateAction(
44827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            int uniqueId, const String8& path,
44927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            int action, const ActionDescription& description) {
4503856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("validateAction");
45127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    Parcel data, reply;
45227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
45327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
45427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
45527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeString8(path);
45627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(action);
45727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(description.outputType);
45827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(description.configuration);
45927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
46027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    remote()->transact(VALIDATE_ACTION, data, &reply);
46127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
46227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return static_cast<bool>(reply.readInt32());
46327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
46427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
4652272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimistatus_t BpDrmManagerService::removeRights(int uniqueId, const String8& path) {
4663856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("removeRights");
46727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    Parcel data, reply;
46827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
46927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
47027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
47127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeString8(path);
47227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
47327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    remote()->transact(REMOVE_RIGHTS, data, &reply);
4742272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi    return reply.readInt32();
47527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
47627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
4772272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimistatus_t BpDrmManagerService::removeAllRights(int uniqueId) {
4783856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("removeAllRights");
47927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    Parcel data, reply;
48027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
48127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
48227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
48327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
48427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    remote()->transact(REMOVE_ALL_RIGHTS, data, &reply);
4852272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi    return reply.readInt32();
48627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
48727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
48827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshiint BpDrmManagerService::openConvertSession(int uniqueId, const String8& mimeType) {
4893856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("openConvertSession");
49027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    Parcel data, reply;
49127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
49227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
49327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
49427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeString8(mimeType);
49527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
49627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    remote()->transact(OPEN_CONVERT_SESSION, data, &reply);
49727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return reply.readInt32();
49827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
49927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
50027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshiDrmConvertedStatus* BpDrmManagerService::convertData(
50127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            int uniqueId, int convertId, const DrmBuffer* inputData) {
5023856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("convertData");
50327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    Parcel data, reply;
50427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
50527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
50627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
50727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(convertId);
50827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(inputData->length);
50927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.write(inputData->data, inputData->length);
51027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
51127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    remote()->transact(CONVERT_DATA, data, &reply);
51227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
51327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    DrmConvertedStatus* drmConvertedStatus = NULL;
51427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
51527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    if (0 != reply.dataAvail()) {
51627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        //Filling DRM Converted Status
51727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        const int statusCode = reply.readInt32();
518a2cd44cb5067b4fe98794860690394254d3ac73cGloria Wang        const off64_t offset = reply.readInt64();
51927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
52027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        DrmBuffer* convertedData = NULL;
52127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        if (0 != reply.dataAvail()) {
52227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            const int bufferSize = reply.readInt32();
52327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            char* data = NULL;
52427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            if (0 < bufferSize) {
52527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi                data = new char[bufferSize];
52627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi                reply.read(data, bufferSize);
52727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            }
52827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            convertedData = new DrmBuffer(data, bufferSize);
52927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        }
53027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        drmConvertedStatus = new DrmConvertedStatus(statusCode, convertedData, offset);
53127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    }
53227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return drmConvertedStatus;
53327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
53427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
53527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshiDrmConvertedStatus* BpDrmManagerService::closeConvertSession(int uniqueId, int convertId) {
5363856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("closeConvertSession");
53727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    Parcel data, reply;
53827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
53927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
54027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
54127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(convertId);
54227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
54327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    remote()->transact(CLOSE_CONVERT_SESSION, data, &reply);
54427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
54527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    DrmConvertedStatus* drmConvertedStatus = NULL;
54627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
54727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    if (0 != reply.dataAvail()) {
54827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        //Filling DRM Converted Status
54927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        const int statusCode = reply.readInt32();
550a2cd44cb5067b4fe98794860690394254d3ac73cGloria Wang        const off64_t offset = reply.readInt64();
55127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
55227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        DrmBuffer* convertedData = NULL;
55327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        if (0 != reply.dataAvail()) {
55427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            const int bufferSize = reply.readInt32();
55527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            char* data = NULL;
55627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            if (0 < bufferSize) {
55727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi                data = new char[bufferSize];
55827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi                reply.read(data, bufferSize);
55927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            }
56027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            convertedData = new DrmBuffer(data, bufferSize);
56127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        }
56227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        drmConvertedStatus = new DrmConvertedStatus(statusCode, convertedData, offset);
56327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    }
56427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return drmConvertedStatus;
56527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
56627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
56727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshistatus_t BpDrmManagerService::getAllSupportInfo(
56827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray) {
5693856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("Get All Support Info");
57027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    Parcel data, reply;
57127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
57227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
57327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    data.writeInt32(uniqueId);
57427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
57527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    remote()->transact(GET_ALL_SUPPORT_INFO, data, &reply);
57627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
57727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    //Filling DRM Support Info
57827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    const int arraySize = reply.readInt32();
57927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    if (0 < arraySize) {
58027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        *drmSupportInfoArray = new DrmSupportInfo[arraySize];
58127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
58227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        for (int index = 0; index < arraySize; ++index) {
58327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            DrmSupportInfo drmSupportInfo;
58427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
58527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            const int fileSuffixVectorSize = reply.readInt32();
58627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            for (int i = 0; i < fileSuffixVectorSize; ++i) {
58727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi                drmSupportInfo.addFileSuffix(reply.readString8());
58827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            }
58927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
59027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            const int mimeTypeVectorSize = reply.readInt32();
59127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            for (int i = 0; i < mimeTypeVectorSize; ++i) {
59227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi                drmSupportInfo.addMimeType(reply.readString8());
593