1fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera/* 2fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * Copyright (C) 2010 The Android Open Source Project 3fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * 4fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * Licensed under the Apache License, Version 2.0 (the "License"); 5fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * you may not use this file except in compliance with the License. 6fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * You may obtain a copy of the License at 7fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * 8fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * http://www.apache.org/licenses/LICENSE-2.0 9fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * 10fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * Unless required by applicable law or agreed to in writing, software 11fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * distributed under the License is distributed on an "AS IS" BASIS, 12fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * See the License for the specific language governing permissions and 14fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * limitations under the License. 15fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera */ 16fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 17fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#include "SessionMap.h" 18fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#include "FwdLockEngine.h" 19fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#include <utils/Log.h> 20fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#include <errno.h> 21fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#include <stdio.h> 22fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#include <unistd.h> 23fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#include "drm_framework_common.h" 24fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#include <fcntl.h> 25fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#include <limits.h> 26fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#include <DrmRights.h> 27fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#include <DrmConstraints.h> 28fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#include <DrmMetadata.h> 29fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#include <DrmInfo.h> 30fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#include <DrmInfoStatus.h> 31fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#include <DrmInfoRequest.h> 32fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#include <DrmSupportInfo.h> 33fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#include <DrmConvertedStatus.h> 34fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#include <utils/String8.h> 35fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#include "FwdLockConv.h" 36fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#include "FwdLockFile.h" 37fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#include "FwdLockGlue.h" 38fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#include "MimeTypeUtil.h" 39fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 40fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#undef LOG_TAG 41fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#define LOG_TAG "FwdLockEngine" 42fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 4390855078eb989944bca1824058d7231cd68e5021Henrik B Andersson#ifdef DRM_OMA_FL_ENGINE_DEBUG 4490855078eb989944bca1824058d7231cd68e5021Henrik B Andersson#define LOG_NDEBUG 0 453856b090cd04ba5dd4a59a12430ed724d5995909Steve Block#define LOG_VERBOSE(...) ALOGV(__VA_ARGS__) 4690855078eb989944bca1824058d7231cd68e5021Henrik B Andersson#else 4790855078eb989944bca1824058d7231cd68e5021Henrik B Andersson#define LOG_VERBOSE(...) 4890855078eb989944bca1824058d7231cd68e5021Henrik B Andersson#endif 4990855078eb989944bca1824058d7231cd68e5021Henrik B Andersson 50fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherausing namespace android; 51fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera// This extern "C" is mandatory to be managed by TPlugInManager 52fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeheraextern "C" IDrmEngine* create() { 53fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return new FwdLockEngine(); 54fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 55fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 56fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera// This extern "C" is mandatory to be managed by TPlugInManager 57fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeheraextern "C" void destroy(IDrmEngine* plugIn) { 58fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera delete plugIn; 59fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 60fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 61fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat DalbeheraFwdLockEngine::FwdLockEngine() { 6290855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOG_VERBOSE("FwdLockEngine Construction"); 63fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 64fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 65fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat DalbeheraFwdLockEngine::~FwdLockEngine() { 6690855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOG_VERBOSE("FwdLockEngine Destruction"); 6790855078eb989944bca1824058d7231cd68e5021Henrik B Andersson 6890855078eb989944bca1824058d7231cd68e5021Henrik B Andersson int size = decodeSessionMap.getSize(); 69fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 7090855078eb989944bca1824058d7231cd68e5021Henrik B Andersson for (int i = 0; i < size; i++) { 7190855078eb989944bca1824058d7231cd68e5021Henrik B Andersson DecodeSession *session = (DecodeSession*) decodeSessionMap.getValueAt(i); 7290855078eb989944bca1824058d7231cd68e5021Henrik B Andersson FwdLockFile_detach(session->fileDesc); 7390855078eb989944bca1824058d7231cd68e5021Henrik B Andersson ::close(session->fileDesc); 7490855078eb989944bca1824058d7231cd68e5021Henrik B Andersson } 7590855078eb989944bca1824058d7231cd68e5021Henrik B Andersson 7690855078eb989944bca1824058d7231cd68e5021Henrik B Andersson size = convertSessionMap.getSize(); 7790855078eb989944bca1824058d7231cd68e5021Henrik B Andersson for (int i = 0; i < size; i++) { 7890855078eb989944bca1824058d7231cd68e5021Henrik B Andersson ConvertSession *convSession = (ConvertSession*) convertSessionMap.getValueAt(i); 7990855078eb989944bca1824058d7231cd68e5021Henrik B Andersson FwdLockConv_CloseSession(convSession->uniqueId, &(convSession->output)); 8090855078eb989944bca1824058d7231cd68e5021Henrik B Andersson } 81fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 82fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 83fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeheraint FwdLockEngine::getConvertedStatus(FwdLockConv_Status_t status) { 84fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera int retStatus = DrmConvertedStatus::STATUS_ERROR; 85fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 86fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera switch(status) { 87fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera case FwdLockConv_Status_OK: 88fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera retStatus = DrmConvertedStatus::STATUS_OK; 89fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera break; 90fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera case FwdLockConv_Status_SyntaxError: 91fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera case FwdLockConv_Status_InvalidArgument: 92fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera case FwdLockConv_Status_UnsupportedFileFormat: 93fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera case FwdLockConv_Status_UnsupportedContentTransferEncoding: 9429357bc2c0dd7c43ad3bd0c8e3efa4e6fd9bfd47Steve Block ALOGE("FwdLockEngine getConvertedStatus: file conversion Error %d. " 95fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera "Returning STATUS_INPUTDATA_ERROR", status); 96fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera retStatus = DrmConvertedStatus::STATUS_INPUTDATA_ERROR; 97fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera break; 98fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera default: 9929357bc2c0dd7c43ad3bd0c8e3efa4e6fd9bfd47Steve Block ALOGE("FwdLockEngine getConvertedStatus: file conversion Error %d. " 100fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera "Returning STATUS_ERROR", status); 101fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera retStatus = DrmConvertedStatus::STATUS_ERROR; 102fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera break; 103fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 104fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 105fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return retStatus; 106fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 107fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 108fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat DalbeheraDrmConstraints* FwdLockEngine::onGetConstraints(int uniqueId, const String8* path, int action) { 109fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera DrmConstraints* drmConstraints = NULL; 110fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 11190855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOG_VERBOSE("FwdLockEngine::onGetConstraints"); 112fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 113fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (NULL != path && 114fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera (RightsStatus::RIGHTS_VALID == onCheckRightsStatus(uniqueId, *path, action))) { 115fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera // Return the empty constraints to show no error condition. 116fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera drmConstraints = new DrmConstraints(); 117fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 118fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 119fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return drmConstraints; 120fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 121fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 122fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat DalbeheraDrmMetadata* FwdLockEngine::onGetMetadata(int uniqueId, const String8* path) { 123fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera DrmMetadata* drmMetadata = NULL; 124fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 12590855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOG_VERBOSE("FwdLockEngine::onGetMetadata"); 126fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 127fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (NULL != path) { 128fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera // Returns empty metadata to show no error condition. 129fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera drmMetadata = new DrmMetadata(); 130fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 131fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 132fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return drmMetadata; 133fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 134fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 135fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeheraandroid::status_t FwdLockEngine::onInitialize(int uniqueId) { 13690855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOG_VERBOSE("FwdLockEngine::onInitialize"); 137fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 138fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (FwdLockGlue_InitializeKeyEncryption()) { 13990855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOG_VERBOSE("FwdLockEngine::onInitialize -- FwdLockGlue_InitializeKeyEncryption succeeded"); 140fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } else { 14129357bc2c0dd7c43ad3bd0c8e3efa4e6fd9bfd47Steve Block ALOGE("FwdLockEngine::onInitialize -- FwdLockGlue_InitializeKeyEncryption failed:" 142fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera "errno = %d", errno); 143fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 144fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 145fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return DRM_NO_ERROR; 146fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 147fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 148fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeheraandroid::status_t 149fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat DalbeheraFwdLockEngine::onSetOnInfoListener(int uniqueId, const IDrmEngine::OnInfoListener* infoListener) { 150fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera // Not used 15190855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOG_VERBOSE("FwdLockEngine::onSetOnInfoListener"); 152fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 153fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return DRM_NO_ERROR; 154fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 155fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 156fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeheraandroid::status_t FwdLockEngine::onTerminate(int uniqueId) { 15790855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOG_VERBOSE("FwdLockEngine::onTerminate"); 158fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 159fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return DRM_NO_ERROR; 160fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 161fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 162ad6ec91c0bca37587e28bf72dfc38cde1b90544fJames Dong// make sure that lower-case letters are used. 163bd2f13ddbe7a9e7550205f6b53880329e09b9457James Dongconst String8 FwdLockEngine::FileSuffixes[] = { 164bd2f13ddbe7a9e7550205f6b53880329e09b9457James Dong String8(".fl"), 165bd2f13ddbe7a9e7550205f6b53880329e09b9457James Dong String8(".dm"), 166bd2f13ddbe7a9e7550205f6b53880329e09b9457James Dong}; 167bd2f13ddbe7a9e7550205f6b53880329e09b9457James Dong 168ad6ec91c0bca37587e28bf72dfc38cde1b90544fJames Dong// make sure that lower-case letters are used. 169bd2f13ddbe7a9e7550205f6b53880329e09b9457James Dongconst String8 FwdLockEngine::MimeTypes[] = { 170bd2f13ddbe7a9e7550205f6b53880329e09b9457James Dong String8("application/x-android-drm-fl"), 171bd2f13ddbe7a9e7550205f6b53880329e09b9457James Dong String8("application/vnd.oma.drm.message"), 172bd2f13ddbe7a9e7550205f6b53880329e09b9457James Dong}; 173bd2f13ddbe7a9e7550205f6b53880329e09b9457James Dong 174bd2f13ddbe7a9e7550205f6b53880329e09b9457James Dongconst String8 FwdLockEngine::Description("OMA V1 Forward Lock"); 175bd2f13ddbe7a9e7550205f6b53880329e09b9457James Dong 176bd2f13ddbe7a9e7550205f6b53880329e09b9457James Dongvoid FwdLockEngine::AddSupportedMimeTypes(DrmSupportInfo *info) { 177bd2f13ddbe7a9e7550205f6b53880329e09b9457James Dong for (size_t i = 0, n = sizeof(MimeTypes)/sizeof(MimeTypes[0]); i < n; ++i) { 178bd2f13ddbe7a9e7550205f6b53880329e09b9457James Dong info->addMimeType(MimeTypes[i]); 179bd2f13ddbe7a9e7550205f6b53880329e09b9457James Dong } 180bd2f13ddbe7a9e7550205f6b53880329e09b9457James Dong} 181bd2f13ddbe7a9e7550205f6b53880329e09b9457James Dong 182bd2f13ddbe7a9e7550205f6b53880329e09b9457James Dongvoid FwdLockEngine::AddSupportedFileSuffixes(DrmSupportInfo *info) { 183bd2f13ddbe7a9e7550205f6b53880329e09b9457James Dong for (size_t i = 0, n = sizeof(FileSuffixes)/sizeof(FileSuffixes[0]); i < n; ++i) { 184bd2f13ddbe7a9e7550205f6b53880329e09b9457James Dong info->addFileSuffix(FileSuffixes[i]); 185bd2f13ddbe7a9e7550205f6b53880329e09b9457James Dong } 186bd2f13ddbe7a9e7550205f6b53880329e09b9457James Dong} 187bd2f13ddbe7a9e7550205f6b53880329e09b9457James Dong 188bd2f13ddbe7a9e7550205f6b53880329e09b9457James Dongbool FwdLockEngine::IsMimeTypeSupported(const String8& mime) { 189ad6ec91c0bca37587e28bf72dfc38cde1b90544fJames Dong String8 tmp(mime); 190ad6ec91c0bca37587e28bf72dfc38cde1b90544fJames Dong tmp.toLower(); 191bd2f13ddbe7a9e7550205f6b53880329e09b9457James Dong for (size_t i = 0, n = sizeof(MimeTypes)/sizeof(MimeTypes[0]); i < n; ++i) { 192ad6ec91c0bca37587e28bf72dfc38cde1b90544fJames Dong if (tmp == MimeTypes[i]) { 193bd2f13ddbe7a9e7550205f6b53880329e09b9457James Dong return true; 194bd2f13ddbe7a9e7550205f6b53880329e09b9457James Dong } 195bd2f13ddbe7a9e7550205f6b53880329e09b9457James Dong } 196bd2f13ddbe7a9e7550205f6b53880329e09b9457James Dong return false; 197bd2f13ddbe7a9e7550205f6b53880329e09b9457James Dong} 198bd2f13ddbe7a9e7550205f6b53880329e09b9457James Dong 199bd2f13ddbe7a9e7550205f6b53880329e09b9457James Dongbool FwdLockEngine::IsFileSuffixSupported(const String8& suffix) { 200ad6ec91c0bca37587e28bf72dfc38cde1b90544fJames Dong String8 tmp(suffix); 201ad6ec91c0bca37587e28bf72dfc38cde1b90544fJames Dong tmp.toLower(); 202bd2f13ddbe7a9e7550205f6b53880329e09b9457James Dong for (size_t i = 0, n = sizeof(FileSuffixes)/sizeof(FileSuffixes[0]); i < n; ++i) { 203ad6ec91c0bca37587e28bf72dfc38cde1b90544fJames Dong if (tmp == FileSuffixes[i]) { 204bd2f13ddbe7a9e7550205f6b53880329e09b9457James Dong return true; 205bd2f13ddbe7a9e7550205f6b53880329e09b9457James Dong } 206bd2f13ddbe7a9e7550205f6b53880329e09b9457James Dong } 207bd2f13ddbe7a9e7550205f6b53880329e09b9457James Dong return false; 208bd2f13ddbe7a9e7550205f6b53880329e09b9457James Dong} 209bd2f13ddbe7a9e7550205f6b53880329e09b9457James Dong 210fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat DalbeheraDrmSupportInfo* FwdLockEngine::onGetSupportInfo(int uniqueId) { 211fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera DrmSupportInfo* pSupportInfo = new DrmSupportInfo(); 212fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 21390855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOG_VERBOSE("FwdLockEngine::onGetSupportInfo"); 214fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 215fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera // fill all Forward Lock mimetypes and extensions 216fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (NULL != pSupportInfo) { 217bd2f13ddbe7a9e7550205f6b53880329e09b9457James Dong AddSupportedMimeTypes(pSupportInfo); 218bd2f13ddbe7a9e7550205f6b53880329e09b9457James Dong AddSupportedFileSuffixes(pSupportInfo); 219bd2f13ddbe7a9e7550205f6b53880329e09b9457James Dong pSupportInfo->setDescription(Description); 220fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 221fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 222fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return pSupportInfo; 223fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 224fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 225fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherabool FwdLockEngine::onCanHandle(int uniqueId, const String8& path) { 226fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera bool result = false; 227fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 228fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera String8 extString = path.getPathExtension(); 229bd2f13ddbe7a9e7550205f6b53880329e09b9457James Dong return IsFileSuffixSupported(extString); 230fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 231fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 232fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat DalbeheraDrmInfoStatus* FwdLockEngine::onProcessDrmInfo(int uniqueId, const DrmInfo* drmInfo) { 233fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera DrmInfoStatus *drmInfoStatus = NULL; 234fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 235fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera // Nothing to process 236fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 237fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera drmInfoStatus = new DrmInfoStatus((int)DrmInfoStatus::STATUS_OK, 0, NULL, String8("")); 238fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 23990855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOG_VERBOSE("FwdLockEngine::onProcessDrmInfo"); 240fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 241fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return drmInfoStatus; 242fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 243fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 244fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherastatus_t FwdLockEngine::onSaveRights( 245fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera int uniqueId, 246fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera const DrmRights& drmRights, 247fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera const String8& rightsPath, 248fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera const String8& contentPath) { 249fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera // No rights to save. Return 25090855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOG_VERBOSE("FwdLockEngine::onSaveRights"); 251fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return DRM_ERROR_UNKNOWN; 252fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 253fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 254fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat DalbeheraDrmInfo* FwdLockEngine::onAcquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest) { 255fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera DrmInfo* drmInfo = NULL; 256fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 257fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera // Nothing to be done for Forward Lock file 25890855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOG_VERBOSE("FwdLockEngine::onAcquireDrmInfo"); 259fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 260fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return drmInfo; 261fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 262fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 263fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeheraint FwdLockEngine::onCheckRightsStatus(int uniqueId, 264fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera const String8& path, 265fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera int action) { 266fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera int result = RightsStatus::RIGHTS_INVALID; 267fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 26890855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOG_VERBOSE("FwdLockEngine::onCheckRightsStatus"); 269fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 270fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera // Only Transfer action is not allowed for forward Lock files. 271fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (onCanHandle(uniqueId, path)) { 272fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera switch(action) { 273fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera case Action::DEFAULT: 274fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera case Action::PLAY: 275fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera case Action::RINGTONE: 276fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera case Action::OUTPUT: 277fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera case Action::PREVIEW: 278fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera case Action::EXECUTE: 279fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera case Action::DISPLAY: 280fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera result = RightsStatus::RIGHTS_VALID; 281fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera break; 282fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 283fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera case Action::TRANSFER: 284fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera default: 285fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera result = RightsStatus::RIGHTS_INVALID; 286fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera break; 287fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 288fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 289fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 290fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return result; 291fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 292fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 293fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherastatus_t FwdLockEngine::onConsumeRights(int uniqueId, 294fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera DecryptHandle* decryptHandle, 295fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera int action, 296fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera bool reserve) { 297fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera // No rights consumption 29890855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOG_VERBOSE("FwdLockEngine::onConsumeRights"); 299fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return DRM_NO_ERROR; 300fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 301fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 302fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherabool FwdLockEngine::onValidateAction(int uniqueId, 303fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera const String8& path, 304fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera int action, 305fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera const ActionDescription& description) { 30690855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOG_VERBOSE("FwdLockEngine::onValidateAction"); 307fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 308fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera // For the forwardlock engine checkRights and ValidateAction are the same. 309fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return (onCheckRightsStatus(uniqueId, path, action) == RightsStatus::RIGHTS_VALID); 310fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 311fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 312bf5b3b29e31b293313788d7464cfb258ac0da803James DongString8 FwdLockEngine::onGetOriginalMimeType(int uniqueId, const String8& path, int fd) { 31390855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOG_VERBOSE("FwdLockEngine::onGetOriginalMimeType"); 314fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera String8 mimeString = String8(""); 315bf5b3b29e31b293313788d7464cfb258ac0da803James Dong int fileDesc = dup(fd); 316fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 317fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (-1 < fileDesc) { 318bf5b3b29e31b293313788d7464cfb258ac0da803James Dong if (FwdLockFile_attach(fileDesc) < 0) { 319bf5b3b29e31b293313788d7464cfb258ac0da803James Dong return mimeString; 320bf5b3b29e31b293313788d7464cfb258ac0da803James Dong } 321fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera const char* pMimeType = FwdLockFile_GetContentType(fileDesc); 322fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 323fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (NULL != pMimeType) { 324fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera String8 contentType = String8(pMimeType); 325fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera contentType.toLower(); 326fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera mimeString = MimeTypeUtil::convertMimeType(contentType); 327fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 328fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 329fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera FwdLockFile_close(fileDesc); 330fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 331fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 332fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return mimeString; 333fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 334fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 335fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeheraint FwdLockEngine::onGetDrmObjectType(int uniqueId, 336fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera const String8& path, 337fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera const String8& mimeType) { 338fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera String8 mimeStr = String8(mimeType); 339fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 34090855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOG_VERBOSE("FwdLockEngine::onGetDrmObjectType"); 341fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 342fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera /* Checks whether 343fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * 1. path and mime type both are not empty strings (meaning unavailable) else content is unknown 344fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * 2. if one of them is empty string and if other is known then its a DRM Content Object. 345fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * 3. if both of them are available, then both may be of known type 346fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * (regardless of the relation between them to make it compatible with other DRM Engines) 347fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera */ 348fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (((0 == path.length()) || onCanHandle(uniqueId, path)) && 349bd2f13ddbe7a9e7550205f6b53880329e09b9457James Dong ((0 == mimeType.length()) || IsMimeTypeSupported(mimeType)) && (mimeType != path) ) { 350fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return DrmObjectType::CONTENT; 351fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 352fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 353fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return DrmObjectType::UNKNOWN; 354fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 355fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 356fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherastatus_t FwdLockEngine::onRemoveRights(int uniqueId, const String8& path) { 357fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera // No Rights to remove 35890855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOG_VERBOSE("FwdLockEngine::onRemoveRights"); 359fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return DRM_NO_ERROR; 360fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 361fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 362fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherastatus_t FwdLockEngine::onRemoveAllRights(int uniqueId) { 363fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera // No rights to remove 36490855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOG_VERBOSE("FwdLockEngine::onRemoveAllRights"); 365fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return DRM_NO_ERROR; 366fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 367fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 368fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#ifdef USE_64BIT_DRM_API 369fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherastatus_t FwdLockEngine::onSetPlaybackStatus(int uniqueId, DecryptHandle* decryptHandle, 370fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera int playbackStatus, int64_t position) { 371fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#else 372fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherastatus_t FwdLockEngine::onSetPlaybackStatus(int uniqueId, DecryptHandle* decryptHandle, 373fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera int playbackStatus, int position) { 374fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#endif 375fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera // Not used 37690855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOG_VERBOSE("FwdLockEngine::onSetPlaybackStatus"); 377fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return DRM_NO_ERROR; 378fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 379fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 380fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherastatus_t FwdLockEngine::onOpenConvertSession(int uniqueId, 381fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera int convertId) { 382fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera status_t result = DRM_ERROR_UNKNOWN; 38390855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOG_VERBOSE("FwdLockEngine::onOpenConvertSession"); 384fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (!convertSessionMap.isCreated(convertId)) { 385fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera ConvertSession *newSession = new ConvertSession(); 386fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (FwdLockConv_Status_OK == 387fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera FwdLockConv_OpenSession(&(newSession->uniqueId), &(newSession->output))) { 388fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera convertSessionMap.addValue(convertId, newSession); 389fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera result = DRM_NO_ERROR; 390fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } else { 39129357bc2c0dd7c43ad3bd0c8e3efa4e6fd9bfd47Steve Block ALOGE("FwdLockEngine::onOpenConvertSession -- FwdLockConv_OpenSession failed."); 392fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera delete newSession; 393fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 394fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 395fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return result; 396fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 397fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 398fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat DalbeheraDrmConvertedStatus* FwdLockEngine::onConvertData(int uniqueId, 399fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera int convertId, 400fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera const DrmBuffer* inputData) { 401fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera FwdLockConv_Status_t retStatus = FwdLockConv_Status_InvalidArgument; 402fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera DrmBuffer *convResult = new DrmBuffer(NULL, 0); 403fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera int offset = -1; 404fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 405fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (NULL != inputData && convertSessionMap.isCreated(convertId)) { 406fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera ConvertSession *convSession = convertSessionMap.getValue(convertId); 407fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 408fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (NULL != convSession) { 409fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera retStatus = FwdLockConv_ConvertData(convSession->uniqueId, 410fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera inputData->data, 411fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera inputData->length, 412fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera &(convSession->output)); 413fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 414fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (FwdLockConv_Status_OK == retStatus) { 415fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera // return bytes from conversion if available 416fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (convSession->output.fromConvertData.numBytes > 0) { 417fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera convResult->data = new char[convSession->output.fromConvertData.numBytes]; 418fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 419fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (NULL != convResult->data) { 420fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera convResult->length = convSession->output.fromConvertData.numBytes; 421fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera memcpy(convResult->data, 422fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera (char *)convSession->output.fromConvertData.pBuffer, 423fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera convResult->length); 424fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 425fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 426fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } else { 427fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera offset = convSession->output.fromConvertData.errorPos; 428fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 429fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 430fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 431fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return new DrmConvertedStatus(getConvertedStatus(retStatus), convResult, offset); 432fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 433fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 434fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat DalbeheraDrmConvertedStatus* FwdLockEngine::onCloseConvertSession(int uniqueId, 435fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera int convertId) { 436fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera FwdLockConv_Status_t retStatus = FwdLockConv_Status_InvalidArgument; 437fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera DrmBuffer *convResult = new DrmBuffer(NULL, 0); 438fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera int offset = -1; 439fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 44090855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOG_VERBOSE("FwdLockEngine::onCloseConvertSession"); 441fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 442fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (convertSessionMap.isCreated(convertId)) { 443fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera ConvertSession *convSession = convertSessionMap.getValue(convertId); 444fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 445fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (NULL != convSession) { 446fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera retStatus = FwdLockConv_CloseSession(convSession->uniqueId, &(convSession->output)); 447fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 448fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (FwdLockConv_Status_OK == retStatus) { 449fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera offset = convSession->output.fromCloseSession.fileOffset; 450fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera convResult->data = new char[FWD_LOCK_SIGNATURES_SIZE]; 451fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 452fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (NULL != convResult->data) { 453fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera convResult->length = FWD_LOCK_SIGNATURES_SIZE; 454fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera memcpy(convResult->data, 455fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera (char *)convSession->output.fromCloseSession.signatures, 456fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera convResult->length); 457fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 458fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 459fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 460fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera convertSessionMap.removeValue(convertId); 461fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 462fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return new DrmConvertedStatus(getConvertedStatus(retStatus), convResult, offset); 463fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 464fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 465fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#ifdef USE_64BIT_DRM_API 466fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherastatus_t FwdLockEngine::onOpenDecryptSession(int uniqueId, 467fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera DecryptHandle* decryptHandle, 468fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera int fd, 469fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera off64_t offset, 470fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera off64_t length) { 471fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#else 472fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherastatus_t FwdLockEngine::onOpenDecryptSession(int uniqueId, 473fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera DecryptHandle* decryptHandle, 474fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera int fd, 475fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera int offset, 476fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera int length) { 477fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#endif 478fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera status_t result = DRM_ERROR_CANNOT_HANDLE; 479fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera int fileDesc = -1; 480fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 48190855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOG_VERBOSE("FwdLockEngine::onOpenDecryptSession"); 482fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 483fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if ((-1 < fd) && 484fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera (NULL != decryptHandle) && 485fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera (!decodeSessionMap.isCreated(decryptHandle->decryptId))) { 486fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera fileDesc = dup(fd); 487fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } else { 48829357bc2c0dd7c43ad3bd0c8e3efa4e6fd9bfd47Steve Block ALOGE("FwdLockEngine::onOpenDecryptSession parameter error"); 489fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return result; 490fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 491fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 492fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (-1 < fileDesc && 493fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera -1 < ::lseek(fileDesc, offset, SEEK_SET) && 494fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera -1 < FwdLockFile_attach(fileDesc)) { 495fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera // check for file integrity. This must be done to protect the content mangling. 496fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera int retVal = FwdLockFile_CheckHeaderIntegrity(fileDesc); 497fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera DecodeSession* decodeSession = new DecodeSession(fileDesc); 498fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 499fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (retVal && NULL != decodeSession) { 500fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera decodeSessionMap.addValue(decryptHandle->decryptId, decodeSession); 501fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera const char *pmime= FwdLockFile_GetContentType(fileDesc); 502fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera String8 contentType = String8(pmime == NULL ? "" : pmime); 503fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera contentType.toLower(); 504fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera decryptHandle->mimeType = MimeTypeUtil::convertMimeType(contentType); 505fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera decryptHandle->decryptApiType = DecryptApiType::CONTAINER_BASED; 506fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera decryptHandle->status = RightsStatus::RIGHTS_VALID; 507fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera decryptHandle->decryptInfo = NULL; 508fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera result = DRM_NO_ERROR; 509fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } else { 51090855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOG_VERBOSE("FwdLockEngine::onOpenDecryptSession Integrity Check failed for the fd"); 511fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera FwdLockFile_detach(fileDesc); 512fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera delete decodeSession; 513fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 514fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 515fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 51650872c0b6563b75bb02e0de2fd578b40db8227dbGloria Wang if (DRM_NO_ERROR != result && -1 < fileDesc) { 51750872c0b6563b75bb02e0de2fd578b40db8227dbGloria Wang ::close(fileDesc); 51850872c0b6563b75bb02e0de2fd578b40db8227dbGloria Wang } 51950872c0b6563b75bb02e0de2fd578b40db8227dbGloria Wang 52090855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOG_VERBOSE("FwdLockEngine::onOpenDecryptSession Exit. result = %d", result); 521fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 522fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return result; 523fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 524fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 525fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherastatus_t FwdLockEngine::onOpenDecryptSession(int uniqueId, 526fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera DecryptHandle* decryptHandle, 527fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera const char* uri) { 528fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera status_t result = DRM_ERROR_CANNOT_HANDLE; 529fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera const char fileTag [] = "file://"; 530fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 531fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (NULL != decryptHandle && NULL != uri && strlen(uri) > sizeof(fileTag)) { 532fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera String8 uriTag = String8(uri); 533fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera uriTag.toLower(); 534fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 535fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (0 == strncmp(uriTag.string(), fileTag, sizeof(fileTag) - 1)) { 536fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera const char *filePath = strchr(uri + sizeof(fileTag) - 1, '/'); 537fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (NULL != filePath && onCanHandle(uniqueId, String8(filePath))) { 538fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera int fd = open(filePath, O_RDONLY); 539fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 540fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (-1 < fd) { 541fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera // offset is always 0 and length is not used. so any positive size. 542fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera result = onOpenDecryptSession(uniqueId, decryptHandle, fd, 0, 1); 543fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 544fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera // fd is duplicated already if success. closing the file 545fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera close(fd); 546fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 547fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 548fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 549fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 550fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 551fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return result; 552fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 553fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 554fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherastatus_t FwdLockEngine::onCloseDecryptSession(int uniqueId, 555fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera DecryptHandle* decryptHandle) { 556fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera status_t result = DRM_ERROR_UNKNOWN; 55790855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOG_VERBOSE("FwdLockEngine::onCloseDecryptSession"); 558fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 559fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (NULL != decryptHandle && decodeSessionMap.isCreated(decryptHandle->decryptId)) { 560fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera DecodeSession* session = decodeSessionMap.getValue(decryptHandle->decryptId); 561fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (NULL != session && session->fileDesc > -1) { 562fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera FwdLockFile_detach(session->fileDesc); 563fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera ::close(session->fileDesc); 564fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera decodeSessionMap.removeValue(decryptHandle->decryptId); 565fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera result = DRM_NO_ERROR; 566fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 567fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 568fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 569409e5a07f044239aac2059c9ba3b3f6f48eeaba1Gloria Wang if (NULL != decryptHandle) { 570409e5a07f044239aac2059c9ba3b3f6f48eeaba1Gloria Wang if (NULL != decryptHandle->decryptInfo) { 571409e5a07f044239aac2059c9ba3b3f6f48eeaba1Gloria Wang delete decryptHandle->decryptInfo; 572409e5a07f044239aac2059c9ba3b3f6f48eeaba1Gloria Wang decryptHandle->decryptInfo = NULL; 573409e5a07f044239aac2059c9ba3b3f6f48eeaba1Gloria Wang } 574409e5a07f044239aac2059c9ba3b3f6f48eeaba1Gloria Wang 575409e5a07f044239aac2059c9ba3b3f6f48eeaba1Gloria Wang decryptHandle->copyControlVector.clear(); 576409e5a07f044239aac2059c9ba3b3f6f48eeaba1Gloria Wang decryptHandle->extendedData.clear(); 577409e5a07f044239aac2059c9ba3b3f6f48eeaba1Gloria Wang 578409e5a07f044239aac2059c9ba3b3f6f48eeaba1Gloria Wang delete decryptHandle; 579409e5a07f044239aac2059c9ba3b3f6f48eeaba1Gloria Wang decryptHandle = NULL; 580409e5a07f044239aac2059c9ba3b3f6f48eeaba1Gloria Wang } 581409e5a07f044239aac2059c9ba3b3f6f48eeaba1Gloria Wang 58290855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOG_VERBOSE("FwdLockEngine::onCloseDecryptSession Exit"); 583fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return result; 584fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 585fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 586fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherastatus_t FwdLockEngine::onInitializeDecryptUnit(int uniqueId, 587fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera DecryptHandle* decryptHandle, 588fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera int decryptUnitId, 589fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera const DrmBuffer* headerInfo) { 59029357bc2c0dd7c43ad3bd0c8e3efa4e6fd9bfd47Steve Block ALOGE("FwdLockEngine::onInitializeDecryptUnit is not supported for this DRM scheme"); 591fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return DRM_ERROR_UNKNOWN; 592fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 593fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 594fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherastatus_t FwdLockEngine::onDecrypt(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, 595fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) { 59629357bc2c0dd7c43ad3bd0c8e3efa4e6fd9bfd47Steve Block ALOGE("FwdLockEngine::onDecrypt is not supported for this DRM scheme"); 597fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return DRM_ERROR_UNKNOWN; 598fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 599fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 600fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherastatus_t FwdLockEngine::onDecrypt(int uniqueId, 601fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera DecryptHandle* decryptHandle, 602fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera int decryptUnitId, 603fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera const DrmBuffer* encBuffer, 604fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera DrmBuffer** decBuffer) { 60529357bc2c0dd7c43ad3bd0c8e3efa4e6fd9bfd47Steve Block ALOGE("FwdLockEngine::onDecrypt is not supported for this DRM scheme"); 606fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return DRM_ERROR_UNKNOWN; 607fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 608fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 609fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherastatus_t FwdLockEngine::onFinalizeDecryptUnit(int uniqueId, 610fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera DecryptHandle* decryptHandle, 611fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera int decryptUnitId) { 61229357bc2c0dd7c43ad3bd0c8e3efa4e6fd9bfd47Steve Block ALOGE("FwdLockEngine::onFinalizeDecryptUnit is not supported for this DRM scheme"); 613fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return DRM_ERROR_UNKNOWN; 614fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 615fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 616fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherassize_t FwdLockEngine::onRead(int uniqueId, 617fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera DecryptHandle* decryptHandle, 618fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera void* buffer, 619fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera int numBytes) { 620fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera ssize_t size = -1; 621fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 622fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (NULL != decryptHandle && 623fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera decodeSessionMap.isCreated(decryptHandle->decryptId) && 624fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera NULL != buffer && 625fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera numBytes > -1) { 626fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera DecodeSession* session = decodeSessionMap.getValue(decryptHandle->decryptId); 627fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (NULL != session && session->fileDesc > -1) { 628fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera size = FwdLockFile_read(session->fileDesc, buffer, numBytes); 629fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 630fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (0 > size) { 631fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera session->offset = ((off_t)-1); 632fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } else { 633fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera session->offset += size; 634fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 635fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 636fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 637fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 638fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return size; 639fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 640fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 641fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#ifdef USE_64BIT_DRM_API 642fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeheraoff64_t FwdLockEngine::onLseek(int uniqueId, DecryptHandle* decryptHandle, 643fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera off64_t offset, int whence) { 644fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#else 645fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeheraoff_t FwdLockEngine::onLseek(int uniqueId, DecryptHandle* decryptHandle, 646fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera off_t offset, int whence) { 647fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#endif 648fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera off_t offval = -1; 649fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 650fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (NULL != decryptHandle && decodeSessionMap.isCreated(decryptHandle->decryptId)) { 651fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera DecodeSession* session = decodeSessionMap.getValue(decryptHandle->decryptId); 652fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (NULL != session && session->fileDesc > -1) { 653fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera offval = FwdLockFile_lseek(session->fileDesc, offset, whence); 654fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera session->offset = offval; 655fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 656fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 657fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 658fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return offval; 659fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 660fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 661fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#ifdef USE_64BIT_DRM_API 662fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherassize_t FwdLockEngine::onPread(int uniqueId, 663fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera DecryptHandle* decryptHandle, 664fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera void* buffer, 665fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera ssize_t numBytes, 666fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera off64_t offset) { 667fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#else 668fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherassize_t FwdLockEngine::onPread(int uniqueId, 669fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera DecryptHandle* decryptHandle, 670fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera void* buffer, 671fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera ssize_t numBytes, 672fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera off_t offset) { 673fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#endif 674fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera ssize_t bytesRead = -1; 675fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 676fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera DecodeSession* decoderSession = NULL; 677fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 678fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if ((NULL != decryptHandle) && 679fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera (NULL != (decoderSession = decodeSessionMap.getValue(decryptHandle->decryptId))) && 680fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera (NULL != buffer) && 681fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera (numBytes > -1) && 682fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera (offset > -1)) { 683fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (offset != decoderSession->offset) { 684fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera decoderSession->offset = onLseek(uniqueId, decryptHandle, offset, SEEK_SET); 685fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 686fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 687fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (((off_t)-1) != decoderSession->offset) { 688fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera bytesRead = onRead(uniqueId, decryptHandle, buffer, numBytes); 689fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (bytesRead < 0) { 69029357bc2c0dd7c43ad3bd0c8e3efa4e6fd9bfd47Steve Block ALOGE("FwdLockEngine::onPread error reading"); 691fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 692fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 693fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } else { 69429357bc2c0dd7c43ad3bd0c8e3efa4e6fd9bfd47Steve Block ALOGE("FwdLockEngine::onPread decryptId not found"); 695fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 696fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 697fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return bytesRead; 698fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 699