FwdLockEngine.cpp revision 3856b090cd04ba5dd4a59a12430ed724d5995909
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 "FwdLockEngineConst.h" 39fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#include "MimeTypeUtil.h" 40fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 41fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#undef LOG_TAG 42fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#define LOG_TAG "FwdLockEngine" 43fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 4490855078eb989944bca1824058d7231cd68e5021Henrik B Andersson#ifdef DRM_OMA_FL_ENGINE_DEBUG 4590855078eb989944bca1824058d7231cd68e5021Henrik B Andersson#define LOG_NDEBUG 0 463856b090cd04ba5dd4a59a12430ed724d5995909Steve Block#define LOG_VERBOSE(...) ALOGV(__VA_ARGS__) 4790855078eb989944bca1824058d7231cd68e5021Henrik B Andersson#else 4890855078eb989944bca1824058d7231cd68e5021Henrik B Andersson#define LOG_VERBOSE(...) 4990855078eb989944bca1824058d7231cd68e5021Henrik B Andersson#endif 5090855078eb989944bca1824058d7231cd68e5021Henrik B Andersson 51fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherausing namespace android; 52fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera// This extern "C" is mandatory to be managed by TPlugInManager 53fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeheraextern "C" IDrmEngine* create() { 54fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return new FwdLockEngine(); 55fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 56fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 57fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera// This extern "C" is mandatory to be managed by TPlugInManager 58fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeheraextern "C" void destroy(IDrmEngine* plugIn) { 59fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera delete plugIn; 60fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 61fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 62fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat DalbeheraFwdLockEngine::FwdLockEngine() { 6390855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOG_VERBOSE("FwdLockEngine Construction"); 64fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 65fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 66fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat DalbeheraFwdLockEngine::~FwdLockEngine() { 6790855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOG_VERBOSE("FwdLockEngine Destruction"); 6890855078eb989944bca1824058d7231cd68e5021Henrik B Andersson 6990855078eb989944bca1824058d7231cd68e5021Henrik B Andersson int size = decodeSessionMap.getSize(); 70fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 7190855078eb989944bca1824058d7231cd68e5021Henrik B Andersson for (int i = 0; i < size; i++) { 7290855078eb989944bca1824058d7231cd68e5021Henrik B Andersson DecodeSession *session = (DecodeSession*) decodeSessionMap.getValueAt(i); 7390855078eb989944bca1824058d7231cd68e5021Henrik B Andersson FwdLockFile_detach(session->fileDesc); 7490855078eb989944bca1824058d7231cd68e5021Henrik B Andersson ::close(session->fileDesc); 7590855078eb989944bca1824058d7231cd68e5021Henrik B Andersson } 7690855078eb989944bca1824058d7231cd68e5021Henrik B Andersson 7790855078eb989944bca1824058d7231cd68e5021Henrik B Andersson size = convertSessionMap.getSize(); 7890855078eb989944bca1824058d7231cd68e5021Henrik B Andersson for (int i = 0; i < size; i++) { 7990855078eb989944bca1824058d7231cd68e5021Henrik B Andersson ConvertSession *convSession = (ConvertSession*) convertSessionMap.getValueAt(i); 8090855078eb989944bca1824058d7231cd68e5021Henrik B Andersson FwdLockConv_CloseSession(convSession->uniqueId, &(convSession->output)); 8190855078eb989944bca1824058d7231cd68e5021Henrik B Andersson } 82fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 83fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 84fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeheraint FwdLockEngine::getConvertedStatus(FwdLockConv_Status_t status) { 85fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera int retStatus = DrmConvertedStatus::STATUS_ERROR; 86fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 87fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera switch(status) { 88fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera case FwdLockConv_Status_OK: 89fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera retStatus = DrmConvertedStatus::STATUS_OK; 90fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera break; 91fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera case FwdLockConv_Status_SyntaxError: 92fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera case FwdLockConv_Status_InvalidArgument: 93fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera case FwdLockConv_Status_UnsupportedFileFormat: 94fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera case FwdLockConv_Status_UnsupportedContentTransferEncoding: 9590855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOGE("FwdLockEngine getConvertedStatus: file conversion Error %d. " 96fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera "Returning STATUS_INPUTDATA_ERROR", status); 97fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera retStatus = DrmConvertedStatus::STATUS_INPUTDATA_ERROR; 98fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera break; 99fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera default: 10090855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOGE("FwdLockEngine getConvertedStatus: file conversion Error %d. " 101fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera "Returning STATUS_ERROR", status); 102fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera retStatus = DrmConvertedStatus::STATUS_ERROR; 103fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera break; 104fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 105fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 106fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return retStatus; 107fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 108fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 109fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat DalbeheraDrmConstraints* FwdLockEngine::onGetConstraints(int uniqueId, const String8* path, int action) { 110fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera DrmConstraints* drmConstraints = NULL; 111fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 11290855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOG_VERBOSE("FwdLockEngine::onGetConstraints"); 113fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 114fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (NULL != path && 115fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera (RightsStatus::RIGHTS_VALID == onCheckRightsStatus(uniqueId, *path, action))) { 116fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera // Return the empty constraints to show no error condition. 117fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera drmConstraints = new DrmConstraints(); 118fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 119fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 120fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return drmConstraints; 121fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 122fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 123fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat DalbeheraDrmMetadata* FwdLockEngine::onGetMetadata(int uniqueId, const String8* path) { 124fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera DrmMetadata* drmMetadata = NULL; 125fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 12690855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOG_VERBOSE("FwdLockEngine::onGetMetadata"); 127fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 128fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (NULL != path) { 129fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera // Returns empty metadata to show no error condition. 130fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera drmMetadata = new DrmMetadata(); 131fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 132fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 133fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return drmMetadata; 134fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 135fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 136fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeheraandroid::status_t FwdLockEngine::onInitialize(int uniqueId) { 13790855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOG_VERBOSE("FwdLockEngine::onInitialize"); 138fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 139fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (FwdLockGlue_InitializeKeyEncryption()) { 14090855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOG_VERBOSE("FwdLockEngine::onInitialize -- FwdLockGlue_InitializeKeyEncryption succeeded"); 141fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } else { 14290855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOGE("FwdLockEngine::onInitialize -- FwdLockGlue_InitializeKeyEncryption failed:" 143fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera "errno = %d", errno); 144fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 145fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 146fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return DRM_NO_ERROR; 147fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 148fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 149fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeheraandroid::status_t 150fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat DalbeheraFwdLockEngine::onSetOnInfoListener(int uniqueId, const IDrmEngine::OnInfoListener* infoListener) { 151fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera // Not used 15290855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOG_VERBOSE("FwdLockEngine::onSetOnInfoListener"); 153fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 154fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return DRM_NO_ERROR; 155fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 156fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 157fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeheraandroid::status_t FwdLockEngine::onTerminate(int uniqueId) { 15890855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOG_VERBOSE("FwdLockEngine::onTerminate"); 159fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 160fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return DRM_NO_ERROR; 161fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 162fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 163fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat DalbeheraDrmSupportInfo* FwdLockEngine::onGetSupportInfo(int uniqueId) { 164fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera DrmSupportInfo* pSupportInfo = new DrmSupportInfo(); 165fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 16690855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOG_VERBOSE("FwdLockEngine::onGetSupportInfo"); 167fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 168fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera // fill all Forward Lock mimetypes and extensions 169fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (NULL != pSupportInfo) { 170fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera pSupportInfo->addMimeType(String8(FWDLOCK_MIMETYPE_FL)); 171fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera pSupportInfo->addFileSuffix(String8(FWDLOCK_DOTEXTENSION_FL)); 172fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera pSupportInfo->addMimeType(String8(FWDLOCK_MIMETYPE_DM)); 173fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera pSupportInfo->addFileSuffix(String8(FWDLOCK_DOTEXTENSION_DM)); 174fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 175fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera pSupportInfo->setDescription(String8(FWDLOCK_DESCRIPTION)); 176fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 177fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 178fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return pSupportInfo; 179fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 180fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 181fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherabool FwdLockEngine::onCanHandle(int uniqueId, const String8& path) { 182fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera bool result = false; 183fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 184fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera String8 extString = path.getPathExtension(); 185fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 186fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera extString.toLower(); 187fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 188fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if ((extString == String8(FWDLOCK_DOTEXTENSION_FL)) || 189fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera (extString == String8(FWDLOCK_DOTEXTENSION_DM))) { 190fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera result = true; 191fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 192fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return result; 193fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 194fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 195fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat DalbeheraDrmInfoStatus* FwdLockEngine::onProcessDrmInfo(int uniqueId, const DrmInfo* drmInfo) { 196fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera DrmInfoStatus *drmInfoStatus = NULL; 197fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 198fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera // Nothing to process 199fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 200fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera drmInfoStatus = new DrmInfoStatus((int)DrmInfoStatus::STATUS_OK, 0, NULL, String8("")); 201fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 20290855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOG_VERBOSE("FwdLockEngine::onProcessDrmInfo"); 203fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 204fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return drmInfoStatus; 205fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 206fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 207fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherastatus_t FwdLockEngine::onSaveRights( 208fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera int uniqueId, 209fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera const DrmRights& drmRights, 210fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera const String8& rightsPath, 211fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera const String8& contentPath) { 212fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera // No rights to save. Return 21390855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOG_VERBOSE("FwdLockEngine::onSaveRights"); 214fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return DRM_ERROR_UNKNOWN; 215fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 216fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 217fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat DalbeheraDrmInfo* FwdLockEngine::onAcquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest) { 218fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera DrmInfo* drmInfo = NULL; 219fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 220fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera // Nothing to be done for Forward Lock file 22190855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOG_VERBOSE("FwdLockEngine::onAcquireDrmInfo"); 222fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 223fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return drmInfo; 224fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 225fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 226fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeheraint FwdLockEngine::onCheckRightsStatus(int uniqueId, 227fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera const String8& path, 228fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera int action) { 229fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera int result = RightsStatus::RIGHTS_INVALID; 230fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 23190855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOG_VERBOSE("FwdLockEngine::onCheckRightsStatus"); 232fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 233fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera // Only Transfer action is not allowed for forward Lock files. 234fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (onCanHandle(uniqueId, path)) { 235fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera switch(action) { 236fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera case Action::DEFAULT: 237fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera case Action::PLAY: 238fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera case Action::RINGTONE: 239fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera case Action::OUTPUT: 240fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera case Action::PREVIEW: 241fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera case Action::EXECUTE: 242fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera case Action::DISPLAY: 243fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera result = RightsStatus::RIGHTS_VALID; 244fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera break; 245fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 246fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera case Action::TRANSFER: 247fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera default: 248fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera result = RightsStatus::RIGHTS_INVALID; 249fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera break; 250fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 251fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 252fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 253fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return result; 254fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 255fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 256fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherastatus_t FwdLockEngine::onConsumeRights(int uniqueId, 257fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera DecryptHandle* decryptHandle, 258fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera int action, 259fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera bool reserve) { 260fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera // No rights consumption 26190855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOG_VERBOSE("FwdLockEngine::onConsumeRights"); 262fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return DRM_NO_ERROR; 263fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 264fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 265fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherabool FwdLockEngine::onValidateAction(int uniqueId, 266fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera const String8& path, 267fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera int action, 268fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera const ActionDescription& description) { 26990855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOG_VERBOSE("FwdLockEngine::onValidateAction"); 270fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 271fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera // For the forwardlock engine checkRights and ValidateAction are the same. 272fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return (onCheckRightsStatus(uniqueId, path, action) == RightsStatus::RIGHTS_VALID); 273fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 274fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 275fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat DalbeheraString8 FwdLockEngine::onGetOriginalMimeType(int uniqueId, const String8& path) { 27690855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOG_VERBOSE("FwdLockEngine::onGetOriginalMimeType"); 277fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera String8 mimeString = String8(""); 278fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera int fileDesc = FwdLockFile_open(path.string()); 279fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 280fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (-1 < fileDesc) { 281fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera const char* pMimeType = FwdLockFile_GetContentType(fileDesc); 282fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 283fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (NULL != pMimeType) { 284fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera String8 contentType = String8(pMimeType); 285fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera contentType.toLower(); 286fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera mimeString = MimeTypeUtil::convertMimeType(contentType); 287fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 288fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 289fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera FwdLockFile_close(fileDesc); 290fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 291fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 292fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return mimeString; 293fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 294fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 295fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeheraint FwdLockEngine::onGetDrmObjectType(int uniqueId, 296fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera const String8& path, 297fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera const String8& mimeType) { 298fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera String8 mimeStr = String8(mimeType); 299fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 30090855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOG_VERBOSE("FwdLockEngine::onGetDrmObjectType"); 301fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 302fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera mimeStr.toLower(); 303fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 304fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera /* Checks whether 305fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * 1. path and mime type both are not empty strings (meaning unavailable) else content is unknown 306fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * 2. if one of them is empty string and if other is known then its a DRM Content Object. 307fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * 3. if both of them are available, then both may be of known type 308fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * (regardless of the relation between them to make it compatible with other DRM Engines) 309fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera */ 310fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (((0 == path.length()) || onCanHandle(uniqueId, path)) && 311fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera ((0 == mimeType.length()) || ((mimeStr == String8(FWDLOCK_MIMETYPE_FL)) || 312fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera (mimeStr == String8(FWDLOCK_MIMETYPE_DM)))) && (mimeType != path) ) { 313fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return DrmObjectType::CONTENT; 314fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 315fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 316fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return DrmObjectType::UNKNOWN; 317fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 318fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 319fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherastatus_t FwdLockEngine::onRemoveRights(int uniqueId, const String8& path) { 320fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera // No Rights to remove 32190855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOG_VERBOSE("FwdLockEngine::onRemoveRights"); 322fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return DRM_NO_ERROR; 323fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 324fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 325fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherastatus_t FwdLockEngine::onRemoveAllRights(int uniqueId) { 326fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera // No rights to remove 32790855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOG_VERBOSE("FwdLockEngine::onRemoveAllRights"); 328fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return DRM_NO_ERROR; 329fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 330fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 331fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#ifdef USE_64BIT_DRM_API 332fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherastatus_t FwdLockEngine::onSetPlaybackStatus(int uniqueId, DecryptHandle* decryptHandle, 333fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera int playbackStatus, int64_t position) { 334fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#else 335fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherastatus_t FwdLockEngine::onSetPlaybackStatus(int uniqueId, DecryptHandle* decryptHandle, 336fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera int playbackStatus, int position) { 337fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#endif 338fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera // Not used 33990855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOG_VERBOSE("FwdLockEngine::onSetPlaybackStatus"); 340fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return DRM_NO_ERROR; 341fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 342fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 343fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherastatus_t FwdLockEngine::onOpenConvertSession(int uniqueId, 344fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera int convertId) { 345fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera status_t result = DRM_ERROR_UNKNOWN; 34690855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOG_VERBOSE("FwdLockEngine::onOpenConvertSession"); 347fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (!convertSessionMap.isCreated(convertId)) { 348fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera ConvertSession *newSession = new ConvertSession(); 349fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (FwdLockConv_Status_OK == 350fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera FwdLockConv_OpenSession(&(newSession->uniqueId), &(newSession->output))) { 351fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera convertSessionMap.addValue(convertId, newSession); 352fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera result = DRM_NO_ERROR; 353fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } else { 35490855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOGE("FwdLockEngine::onOpenConvertSession -- FwdLockConv_OpenSession failed."); 355fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera delete newSession; 356fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 357fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 358fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return result; 359fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 360fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 361fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat DalbeheraDrmConvertedStatus* FwdLockEngine::onConvertData(int uniqueId, 362fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera int convertId, 363fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera const DrmBuffer* inputData) { 364fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera FwdLockConv_Status_t retStatus = FwdLockConv_Status_InvalidArgument; 365fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera DrmBuffer *convResult = new DrmBuffer(NULL, 0); 366fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera int offset = -1; 367fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 368fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (NULL != inputData && convertSessionMap.isCreated(convertId)) { 369fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera ConvertSession *convSession = convertSessionMap.getValue(convertId); 370fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 371fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (NULL != convSession) { 372fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera retStatus = FwdLockConv_ConvertData(convSession->uniqueId, 373fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera inputData->data, 374fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera inputData->length, 375fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera &(convSession->output)); 376fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 377fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (FwdLockConv_Status_OK == retStatus) { 378fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera // return bytes from conversion if available 379fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (convSession->output.fromConvertData.numBytes > 0) { 380fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera convResult->data = new char[convSession->output.fromConvertData.numBytes]; 381fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 382fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (NULL != convResult->data) { 383fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera convResult->length = convSession->output.fromConvertData.numBytes; 384fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera memcpy(convResult->data, 385fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera (char *)convSession->output.fromConvertData.pBuffer, 386fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera convResult->length); 387fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 388fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 389fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } else { 390fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera offset = convSession->output.fromConvertData.errorPos; 391fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 392fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 393fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 394fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return new DrmConvertedStatus(getConvertedStatus(retStatus), convResult, offset); 395fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 396fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 397fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat DalbeheraDrmConvertedStatus* FwdLockEngine::onCloseConvertSession(int uniqueId, 398fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera int convertId) { 399fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera FwdLockConv_Status_t retStatus = FwdLockConv_Status_InvalidArgument; 400fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera DrmBuffer *convResult = new DrmBuffer(NULL, 0); 401fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera int offset = -1; 402fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 40390855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOG_VERBOSE("FwdLockEngine::onCloseConvertSession"); 404fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 405fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (convertSessionMap.isCreated(convertId)) { 406fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera ConvertSession *convSession = convertSessionMap.getValue(convertId); 407fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 408fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (NULL != convSession) { 409fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera retStatus = FwdLockConv_CloseSession(convSession->uniqueId, &(convSession->output)); 410fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 411fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (FwdLockConv_Status_OK == retStatus) { 412fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera offset = convSession->output.fromCloseSession.fileOffset; 413fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera convResult->data = new char[FWD_LOCK_SIGNATURES_SIZE]; 414fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 415fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (NULL != convResult->data) { 416fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera convResult->length = FWD_LOCK_SIGNATURES_SIZE; 417fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera memcpy(convResult->data, 418fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera (char *)convSession->output.fromCloseSession.signatures, 419fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera convResult->length); 420fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 421fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 422fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 423fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera convertSessionMap.removeValue(convertId); 424fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 425fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return new DrmConvertedStatus(getConvertedStatus(retStatus), convResult, offset); 426fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 427fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 428fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#ifdef USE_64BIT_DRM_API 429fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherastatus_t FwdLockEngine::onOpenDecryptSession(int uniqueId, 430fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera DecryptHandle* decryptHandle, 431fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera int fd, 432fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera off64_t offset, 433fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera off64_t length) { 434fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#else 435fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherastatus_t FwdLockEngine::onOpenDecryptSession(int uniqueId, 436fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera DecryptHandle* decryptHandle, 437fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera int fd, 438fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera int offset, 439fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera int length) { 440fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#endif 441fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera status_t result = DRM_ERROR_CANNOT_HANDLE; 442fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera int fileDesc = -1; 443fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 44490855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOG_VERBOSE("FwdLockEngine::onOpenDecryptSession"); 445fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 446fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if ((-1 < fd) && 447fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera (NULL != decryptHandle) && 448fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera (!decodeSessionMap.isCreated(decryptHandle->decryptId))) { 449fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera fileDesc = dup(fd); 450fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } else { 45190855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOGE("FwdLockEngine::onOpenDecryptSession parameter error"); 452fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return result; 453fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 454fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 455fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (-1 < fileDesc && 456fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera -1 < ::lseek(fileDesc, offset, SEEK_SET) && 457fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera -1 < FwdLockFile_attach(fileDesc)) { 458fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera // check for file integrity. This must be done to protect the content mangling. 459fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera int retVal = FwdLockFile_CheckHeaderIntegrity(fileDesc); 460fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera DecodeSession* decodeSession = new DecodeSession(fileDesc); 461fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 462fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (retVal && NULL != decodeSession) { 463fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera decodeSessionMap.addValue(decryptHandle->decryptId, decodeSession); 464fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera const char *pmime= FwdLockFile_GetContentType(fileDesc); 465fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera String8 contentType = String8(pmime == NULL ? "" : pmime); 466fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera contentType.toLower(); 467fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera decryptHandle->mimeType = MimeTypeUtil::convertMimeType(contentType); 468fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera decryptHandle->decryptApiType = DecryptApiType::CONTAINER_BASED; 469fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera decryptHandle->status = RightsStatus::RIGHTS_VALID; 470fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera decryptHandle->decryptInfo = NULL; 471fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera result = DRM_NO_ERROR; 472fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } else { 47390855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOG_VERBOSE("FwdLockEngine::onOpenDecryptSession Integrity Check failed for the fd"); 474fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera FwdLockFile_detach(fileDesc); 475fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera delete decodeSession; 476fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 477fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 478fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 47950872c0b6563b75bb02e0de2fd578b40db8227dbGloria Wang if (DRM_NO_ERROR != result && -1 < fileDesc) { 48050872c0b6563b75bb02e0de2fd578b40db8227dbGloria Wang ::close(fileDesc); 48150872c0b6563b75bb02e0de2fd578b40db8227dbGloria Wang } 48250872c0b6563b75bb02e0de2fd578b40db8227dbGloria Wang 48390855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOG_VERBOSE("FwdLockEngine::onOpenDecryptSession Exit. result = %d", result); 484fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 485fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return result; 486fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 487fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 488fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherastatus_t FwdLockEngine::onOpenDecryptSession(int uniqueId, 489fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera DecryptHandle* decryptHandle, 490fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera const char* uri) { 491fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera status_t result = DRM_ERROR_CANNOT_HANDLE; 492fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera const char fileTag [] = "file://"; 493fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 494fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (NULL != decryptHandle && NULL != uri && strlen(uri) > sizeof(fileTag)) { 495fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera String8 uriTag = String8(uri); 496fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera uriTag.toLower(); 497fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 498fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (0 == strncmp(uriTag.string(), fileTag, sizeof(fileTag) - 1)) { 499fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera const char *filePath = strchr(uri + sizeof(fileTag) - 1, '/'); 500fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (NULL != filePath && onCanHandle(uniqueId, String8(filePath))) { 501fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera int fd = open(filePath, O_RDONLY); 502fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 503fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (-1 < fd) { 504fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera // offset is always 0 and length is not used. so any positive size. 505fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera result = onOpenDecryptSession(uniqueId, decryptHandle, fd, 0, 1); 506fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 507fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera // fd is duplicated already if success. closing the file 508fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera close(fd); 509fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 510fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 511fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 512fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 513fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 514fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return result; 515fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 516fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 517fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherastatus_t FwdLockEngine::onCloseDecryptSession(int uniqueId, 518fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera DecryptHandle* decryptHandle) { 519fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera status_t result = DRM_ERROR_UNKNOWN; 52090855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOG_VERBOSE("FwdLockEngine::onCloseDecryptSession"); 521fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 522fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (NULL != decryptHandle && decodeSessionMap.isCreated(decryptHandle->decryptId)) { 523fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera DecodeSession* session = decodeSessionMap.getValue(decryptHandle->decryptId); 524fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (NULL != session && session->fileDesc > -1) { 525fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera FwdLockFile_detach(session->fileDesc); 526fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera ::close(session->fileDesc); 527fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera decodeSessionMap.removeValue(decryptHandle->decryptId); 528fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera result = DRM_NO_ERROR; 529fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 530fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 531fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 532409e5a07f044239aac2059c9ba3b3f6f48eeaba1Gloria Wang if (NULL != decryptHandle) { 533409e5a07f044239aac2059c9ba3b3f6f48eeaba1Gloria Wang if (NULL != decryptHandle->decryptInfo) { 534409e5a07f044239aac2059c9ba3b3f6f48eeaba1Gloria Wang delete decryptHandle->decryptInfo; 535409e5a07f044239aac2059c9ba3b3f6f48eeaba1Gloria Wang decryptHandle->decryptInfo = NULL; 536409e5a07f044239aac2059c9ba3b3f6f48eeaba1Gloria Wang } 537409e5a07f044239aac2059c9ba3b3f6f48eeaba1Gloria Wang 538409e5a07f044239aac2059c9ba3b3f6f48eeaba1Gloria Wang decryptHandle->copyControlVector.clear(); 539409e5a07f044239aac2059c9ba3b3f6f48eeaba1Gloria Wang decryptHandle->extendedData.clear(); 540409e5a07f044239aac2059c9ba3b3f6f48eeaba1Gloria Wang 541409e5a07f044239aac2059c9ba3b3f6f48eeaba1Gloria Wang delete decryptHandle; 542409e5a07f044239aac2059c9ba3b3f6f48eeaba1Gloria Wang decryptHandle = NULL; 543409e5a07f044239aac2059c9ba3b3f6f48eeaba1Gloria Wang } 544409e5a07f044239aac2059c9ba3b3f6f48eeaba1Gloria Wang 54590855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOG_VERBOSE("FwdLockEngine::onCloseDecryptSession Exit"); 546fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return result; 547fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 548fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 549fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherastatus_t FwdLockEngine::onInitializeDecryptUnit(int uniqueId, 550fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera DecryptHandle* decryptHandle, 551fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera int decryptUnitId, 552fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera const DrmBuffer* headerInfo) { 55390855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOGE("FwdLockEngine::onInitializeDecryptUnit is not supported for this DRM scheme"); 554fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return DRM_ERROR_UNKNOWN; 555fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 556fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 557fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherastatus_t FwdLockEngine::onDecrypt(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, 558fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) { 55990855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOGE("FwdLockEngine::onDecrypt is not supported for this DRM scheme"); 560fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return DRM_ERROR_UNKNOWN; 561fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 562fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 563fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherastatus_t FwdLockEngine::onDecrypt(int uniqueId, 564fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera DecryptHandle* decryptHandle, 565fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera int decryptUnitId, 566fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera const DrmBuffer* encBuffer, 567fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera DrmBuffer** decBuffer) { 56890855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOGE("FwdLockEngine::onDecrypt is not supported for this DRM scheme"); 569fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return DRM_ERROR_UNKNOWN; 570fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 571fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 572fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherastatus_t FwdLockEngine::onFinalizeDecryptUnit(int uniqueId, 573fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera DecryptHandle* decryptHandle, 574fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera int decryptUnitId) { 57590855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOGE("FwdLockEngine::onFinalizeDecryptUnit is not supported for this DRM scheme"); 576fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return DRM_ERROR_UNKNOWN; 577fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 578fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 579fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherassize_t FwdLockEngine::onRead(int uniqueId, 580fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera DecryptHandle* decryptHandle, 581fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera void* buffer, 582fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera int numBytes) { 583fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera ssize_t size = -1; 584fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 585fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (NULL != decryptHandle && 586fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera decodeSessionMap.isCreated(decryptHandle->decryptId) && 587fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera NULL != buffer && 588fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera numBytes > -1) { 589fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera DecodeSession* session = decodeSessionMap.getValue(decryptHandle->decryptId); 590fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (NULL != session && session->fileDesc > -1) { 591fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera size = FwdLockFile_read(session->fileDesc, buffer, numBytes); 592fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 593fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (0 > size) { 594fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera session->offset = ((off_t)-1); 595fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } else { 596fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera session->offset += size; 597fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 598fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 599fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 600fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 601fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return size; 602fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 603fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 604fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#ifdef USE_64BIT_DRM_API 605fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeheraoff64_t FwdLockEngine::onLseek(int uniqueId, DecryptHandle* decryptHandle, 606fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera off64_t offset, int whence) { 607fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#else 608fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeheraoff_t FwdLockEngine::onLseek(int uniqueId, DecryptHandle* decryptHandle, 609fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera off_t offset, int whence) { 610fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#endif 611fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera off_t offval = -1; 612fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 613fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (NULL != decryptHandle && decodeSessionMap.isCreated(decryptHandle->decryptId)) { 614fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera DecodeSession* session = decodeSessionMap.getValue(decryptHandle->decryptId); 615fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (NULL != session && session->fileDesc > -1) { 616fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera offval = FwdLockFile_lseek(session->fileDesc, offset, whence); 617fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera session->offset = offval; 618fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 619fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 620fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 621fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return offval; 622fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 623fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 624fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#ifdef USE_64BIT_DRM_API 625fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherassize_t FwdLockEngine::onPread(int uniqueId, 626fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera DecryptHandle* decryptHandle, 627fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera void* buffer, 628fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera ssize_t numBytes, 629fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera off64_t offset) { 630fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#else 631fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherassize_t FwdLockEngine::onPread(int uniqueId, 632fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera DecryptHandle* decryptHandle, 633fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera void* buffer, 634fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera ssize_t numBytes, 635fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera off_t offset) { 636fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#endif 637fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera ssize_t bytesRead = -1; 638fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 639fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera DecodeSession* decoderSession = NULL; 640fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 641fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if ((NULL != decryptHandle) && 642fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera (NULL != (decoderSession = decodeSessionMap.getValue(decryptHandle->decryptId))) && 643fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera (NULL != buffer) && 644fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera (numBytes > -1) && 645fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera (offset > -1)) { 646fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (offset != decoderSession->offset) { 647fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera decoderSession->offset = onLseek(uniqueId, decryptHandle, offset, SEEK_SET); 648fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 649fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 650fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (((off_t)-1) != decoderSession->offset) { 651fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera bytesRead = onRead(uniqueId, decryptHandle, buffer, numBytes); 652fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera if (bytesRead < 0) { 65390855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOGE("FwdLockEngine::onPread error reading"); 654fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 655fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 656fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } else { 65790855078eb989944bca1824058d7231cd68e5021Henrik B Andersson LOGE("FwdLockEngine::onPread decryptId not found"); 658fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera } 659fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 660fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera return bytesRead; 661fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 662