FwdLockEngine.cpp revision 409e5a07f044239aac2059c9ba3b3f6f48eeaba1
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
44fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherausing namespace android;
45fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera// This extern "C" is mandatory to be managed by TPlugInManager
46fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeheraextern "C" IDrmEngine* create() {
47fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    return new FwdLockEngine();
48fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera}
49fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
50fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera// This extern "C" is mandatory to be managed by TPlugInManager
51fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeheraextern "C" void destroy(IDrmEngine* plugIn) {
52fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    delete plugIn;
53fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera}
54fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
55fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat DalbeheraFwdLockEngine::FwdLockEngine() {
56b432603d711cd504d0de62f7fbb095b90c9a4283Gloria Wang    LOGV("FwdLockEngine Construction");
57fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera}
58fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
59fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat DalbeheraFwdLockEngine::~FwdLockEngine() {
60b432603d711cd504d0de62f7fbb095b90c9a4283Gloria Wang    LOGV("FwdLockEngine Destruction");
61fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
62fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    convertSessionMap.destroyMap();
63fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    decodeSessionMap.destroyMap();
64fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera}
65fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
66fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeheraint FwdLockEngine::getConvertedStatus(FwdLockConv_Status_t status) {
67fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    int retStatus = DrmConvertedStatus::STATUS_ERROR;
68fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
69fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    switch(status) {
70fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        case FwdLockConv_Status_OK:
71fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            retStatus = DrmConvertedStatus::STATUS_OK;
72fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            break;
73fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        case FwdLockConv_Status_SyntaxError:
74fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        case FwdLockConv_Status_InvalidArgument:
75fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        case FwdLockConv_Status_UnsupportedFileFormat:
76fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        case FwdLockConv_Status_UnsupportedContentTransferEncoding:
77fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            LOGD("FwdLockEngine getConvertedStatus: file conversion Error %d. " \
78fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                  "Returning STATUS_INPUTDATA_ERROR", status);
79fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            retStatus = DrmConvertedStatus::STATUS_INPUTDATA_ERROR;
80fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            break;
81fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        default:
82fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            LOGD("FwdLockEngine getConvertedStatus: file conversion Error %d. " \
83fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                  "Returning STATUS_ERROR", status);
84fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            retStatus = DrmConvertedStatus::STATUS_ERROR;
85fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            break;
86fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    }
87fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
88fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    return retStatus;
89fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera}
90fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
91fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat DalbeheraDrmConstraints* FwdLockEngine::onGetConstraints(int uniqueId, const String8* path, int action) {
92fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    DrmConstraints* drmConstraints = NULL;
93fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
94b432603d711cd504d0de62f7fbb095b90c9a4283Gloria Wang    LOGV("FwdLockEngine::onGetConstraints");
95fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
96fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    if (NULL != path &&
97fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        (RightsStatus::RIGHTS_VALID == onCheckRightsStatus(uniqueId, *path, action))) {
98fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        // Return the empty constraints to show no error condition.
99fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        drmConstraints = new DrmConstraints();
100fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    }
101fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
102fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    return drmConstraints;
103fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera}
104fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
105fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat DalbeheraDrmMetadata* FwdLockEngine::onGetMetadata(int uniqueId, const String8* path) {
106fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    DrmMetadata* drmMetadata = NULL;
107fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
108b432603d711cd504d0de62f7fbb095b90c9a4283Gloria Wang    LOGV("FwdLockEngine::onGetMetadata");
109fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
110fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    if (NULL != path) {
111fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        // Returns empty metadata to show no error condition.
112fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        drmMetadata = new DrmMetadata();
113fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    }
114fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
115fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    return drmMetadata;
116fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera}
117fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
118fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeheraandroid::status_t FwdLockEngine::onInitialize(int uniqueId) {
119b432603d711cd504d0de62f7fbb095b90c9a4283Gloria Wang    LOGV("FwdLockEngine::onInitialize");
120fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
121fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
122fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    if (FwdLockGlue_InitializeKeyEncryption()) {
123b432603d711cd504d0de62f7fbb095b90c9a4283Gloria Wang        LOGV("FwdLockEngine::onInitialize -- FwdLockGlue_InitializeKeyEncryption succeeded");
124fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    } else {
125fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        LOGD("FwdLockEngine::onInitialize -- FwdLockGlue_InitializeKeyEncryption failed:"
126fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera             "errno = %d", errno);
127fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    }
128fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
129fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    return DRM_NO_ERROR;
130fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera}
131fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
132fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeheraandroid::status_t
133fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat DalbeheraFwdLockEngine::onSetOnInfoListener(int uniqueId, const IDrmEngine::OnInfoListener* infoListener) {
134fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    // Not used
135b432603d711cd504d0de62f7fbb095b90c9a4283Gloria Wang    LOGV("FwdLockEngine::onSetOnInfoListener");
136fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
137fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    return DRM_NO_ERROR;
138fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera}
139fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
140fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeheraandroid::status_t FwdLockEngine::onTerminate(int uniqueId) {
141b432603d711cd504d0de62f7fbb095b90c9a4283Gloria Wang    LOGV("FwdLockEngine::onTerminate");
142fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
143fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    return DRM_NO_ERROR;
144fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera}
145fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
146fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat DalbeheraDrmSupportInfo* FwdLockEngine::onGetSupportInfo(int uniqueId) {
147fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    DrmSupportInfo* pSupportInfo = new DrmSupportInfo();
148fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
149b432603d711cd504d0de62f7fbb095b90c9a4283Gloria Wang    LOGV("FwdLockEngine::onGetSupportInfo");
150fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
151fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    // fill all Forward Lock mimetypes and extensions
152fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    if (NULL != pSupportInfo) {
153fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        pSupportInfo->addMimeType(String8(FWDLOCK_MIMETYPE_FL));
154fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        pSupportInfo->addFileSuffix(String8(FWDLOCK_DOTEXTENSION_FL));
155fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        pSupportInfo->addMimeType(String8(FWDLOCK_MIMETYPE_DM));
156fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        pSupportInfo->addFileSuffix(String8(FWDLOCK_DOTEXTENSION_DM));
157fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
158fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        pSupportInfo->setDescription(String8(FWDLOCK_DESCRIPTION));
159fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    }
160fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
161fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    return pSupportInfo;
162fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera}
163fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
164fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherabool FwdLockEngine::onCanHandle(int uniqueId, const String8& path) {
165fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    bool result = false;
166fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
167fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    String8 extString = path.getPathExtension();
168fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
169fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    extString.toLower();
170fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
171fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    if ((extString == String8(FWDLOCK_DOTEXTENSION_FL)) ||
172fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        (extString == String8(FWDLOCK_DOTEXTENSION_DM))) {
173fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        result = true;
174fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    }
175fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    return result;
176fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera}
177fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
178fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat DalbeheraDrmInfoStatus* FwdLockEngine::onProcessDrmInfo(int uniqueId, const DrmInfo* drmInfo) {
179fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    DrmInfoStatus *drmInfoStatus = NULL;
180fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
181fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    // Nothing to process
182fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
183fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    drmInfoStatus = new DrmInfoStatus((int)DrmInfoStatus::STATUS_OK, 0, NULL, String8(""));
184fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
185b432603d711cd504d0de62f7fbb095b90c9a4283Gloria Wang    LOGV("FwdLockEngine::onProcessDrmInfo");
186fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
187fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    return drmInfoStatus;
188fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera}
189fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
190fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherastatus_t FwdLockEngine::onSaveRights(
191fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            int uniqueId,
192fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            const DrmRights& drmRights,
193fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            const String8& rightsPath,
194fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            const String8& contentPath) {
195fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    // No rights to save. Return
196b432603d711cd504d0de62f7fbb095b90c9a4283Gloria Wang    LOGV("FwdLockEngine::onSaveRights");
197fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    return DRM_ERROR_UNKNOWN;
198fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera}
199fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
200fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat DalbeheraDrmInfo* FwdLockEngine::onAcquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest) {
201fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    DrmInfo* drmInfo = NULL;
202fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
203fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    // Nothing to be done for Forward Lock file
204b432603d711cd504d0de62f7fbb095b90c9a4283Gloria Wang    LOGV("FwdLockEngine::onAcquireDrmInfo");
205fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
206fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    return drmInfo;
207fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera}
208fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
209fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeheraint FwdLockEngine::onCheckRightsStatus(int uniqueId,
210fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                                       const String8& path,
211fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                                       int action) {
212fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    int result = RightsStatus::RIGHTS_INVALID;
213fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
214b432603d711cd504d0de62f7fbb095b90c9a4283Gloria Wang    LOGV("FwdLockEngine::onCheckRightsStatus");
215fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
216fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    // Only Transfer action is not allowed for forward Lock files.
217fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    if (onCanHandle(uniqueId, path)) {
218fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        switch(action) {
219fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            case Action::DEFAULT:
220fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            case Action::PLAY:
221fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            case Action::RINGTONE:
222fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            case Action::OUTPUT:
223fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            case Action::PREVIEW:
224fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            case Action::EXECUTE:
225fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            case Action::DISPLAY:
226fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                result = RightsStatus::RIGHTS_VALID;
227fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                break;
228fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
229fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            case Action::TRANSFER:
230fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            default:
231fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                result = RightsStatus::RIGHTS_INVALID;
232fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                break;
233fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        }
234fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    }
235fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
236fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    return result;
237fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera}
238fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
239fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherastatus_t FwdLockEngine::onConsumeRights(int uniqueId,
240fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                                        DecryptHandle* decryptHandle,
241fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                                        int action,
242fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                                        bool reserve) {
243fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    // No rights consumption
244b432603d711cd504d0de62f7fbb095b90c9a4283Gloria Wang    LOGV("FwdLockEngine::onConsumeRights");
245fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    return DRM_NO_ERROR;
246fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera}
247fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
248fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherabool FwdLockEngine::onValidateAction(int uniqueId,
249fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                                     const String8& path,
250fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                                     int action,
251fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                                     const ActionDescription& description) {
252b432603d711cd504d0de62f7fbb095b90c9a4283Gloria Wang    LOGV("FwdLockEngine::onValidateAction");
253fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
254fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    // For the forwardlock engine checkRights and ValidateAction are the same.
255fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    return (onCheckRightsStatus(uniqueId, path, action) == RightsStatus::RIGHTS_VALID);
256fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera}
257fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
258fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat DalbeheraString8 FwdLockEngine::onGetOriginalMimeType(int uniqueId, const String8& path) {
259b432603d711cd504d0de62f7fbb095b90c9a4283Gloria Wang    LOGV("FwdLockEngine::onGetOriginalMimeType");
260fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    String8 mimeString = String8("");
261fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    int fileDesc = FwdLockFile_open(path.string());
262fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
263fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    if (-1 < fileDesc) {
264fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        const char* pMimeType = FwdLockFile_GetContentType(fileDesc);
265fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
266fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        if (NULL != pMimeType) {
267fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            String8 contentType = String8(pMimeType);
268fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            contentType.toLower();
269fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            mimeString = MimeTypeUtil::convertMimeType(contentType);
270fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        }
271fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
272fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        FwdLockFile_close(fileDesc);
273fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    }
274fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
275fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    return mimeString;
276fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera}
277fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
278fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeheraint FwdLockEngine::onGetDrmObjectType(int uniqueId,
279fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                                      const String8& path,
280fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                                      const String8& mimeType) {
281fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    String8 mimeStr = String8(mimeType);
282fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
283b432603d711cd504d0de62f7fbb095b90c9a4283Gloria Wang    LOGV("FwdLockEngine::onGetDrmObjectType");
284fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
285fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    mimeStr.toLower();
286fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
287fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    /* Checks whether
288fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    * 1. path and mime type both are not empty strings (meaning unavailable) else content is unknown
289fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    * 2. if one of them is empty string and if other is known then its a DRM Content Object.
290fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    * 3. if both of them are available, then both may be of known type
291fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    *    (regardless of the relation between them to make it compatible with other DRM Engines)
292fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    */
293fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    if (((0 == path.length()) || onCanHandle(uniqueId, path)) &&
294fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        ((0 == mimeType.length()) || ((mimeStr == String8(FWDLOCK_MIMETYPE_FL)) ||
295fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        (mimeStr == String8(FWDLOCK_MIMETYPE_DM)))) && (mimeType != path) ) {
296fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            return DrmObjectType::CONTENT;
297fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    }
298fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
299fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    return DrmObjectType::UNKNOWN;
300fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera}
301fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
302fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherastatus_t FwdLockEngine::onRemoveRights(int uniqueId, const String8& path) {
303fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    // No Rights to remove
304b432603d711cd504d0de62f7fbb095b90c9a4283Gloria Wang    LOGV("FwdLockEngine::onRemoveRights");
305fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    return DRM_NO_ERROR;
306fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera}
307fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
308fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherastatus_t FwdLockEngine::onRemoveAllRights(int uniqueId) {
309fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    // No rights to remove
310b432603d711cd504d0de62f7fbb095b90c9a4283Gloria Wang    LOGV("FwdLockEngine::onRemoveAllRights");
311fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    return DRM_NO_ERROR;
312fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera}
313fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
314fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#ifdef USE_64BIT_DRM_API
315fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherastatus_t FwdLockEngine::onSetPlaybackStatus(int uniqueId, DecryptHandle* decryptHandle,
316fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                                            int playbackStatus, int64_t position) {
317fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#else
318fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherastatus_t FwdLockEngine::onSetPlaybackStatus(int uniqueId, DecryptHandle* decryptHandle,
319fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                                            int playbackStatus, int position) {
320fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#endif
321fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    // Not used
322b432603d711cd504d0de62f7fbb095b90c9a4283Gloria Wang    LOGV("FwdLockEngine::onSetPlaybackStatus");
323fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    return DRM_NO_ERROR;
324fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera}
325fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
326fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherastatus_t FwdLockEngine::onOpenConvertSession(int uniqueId,
327fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                                         int convertId) {
328fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    status_t result = DRM_ERROR_UNKNOWN;
329b432603d711cd504d0de62f7fbb095b90c9a4283Gloria Wang    LOGV("FwdLockEngine::onOpenConvertSession");
330fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    if (!convertSessionMap.isCreated(convertId)) {
331fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        ConvertSession *newSession = new ConvertSession();
332fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        if (FwdLockConv_Status_OK ==
333fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            FwdLockConv_OpenSession(&(newSession->uniqueId), &(newSession->output))) {
334fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            convertSessionMap.addValue(convertId, newSession);
335fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            result = DRM_NO_ERROR;
336fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        } else {
337fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            LOGD("FwdLockEngine::onOpenConvertSession -- FwdLockConv_OpenSession failed.");
338fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            delete newSession;
339fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        }
340fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    }
341fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    return result;
342fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera}
343fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
344fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat DalbeheraDrmConvertedStatus* FwdLockEngine::onConvertData(int uniqueId,
345fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                                                 int convertId,
346fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                                                 const DrmBuffer* inputData) {
347fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    FwdLockConv_Status_t retStatus = FwdLockConv_Status_InvalidArgument;
348fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    DrmBuffer *convResult = new DrmBuffer(NULL, 0);
349fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    int offset = -1;
350fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
351fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    if (NULL != inputData && convertSessionMap.isCreated(convertId)) {
352fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        ConvertSession *convSession = convertSessionMap.getValue(convertId);
353fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
354fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        if (NULL != convSession) {
355fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            retStatus = FwdLockConv_ConvertData(convSession->uniqueId,
356fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                                                inputData->data,
357fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                                                inputData->length,
358fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                                                &(convSession->output));
359fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
360fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            if (FwdLockConv_Status_OK == retStatus) {
361fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                // return bytes from conversion if available
362fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                if (convSession->output.fromConvertData.numBytes > 0) {
363fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                    convResult->data = new char[convSession->output.fromConvertData.numBytes];
364fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
365fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                    if (NULL != convResult->data) {
366fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                        convResult->length = convSession->output.fromConvertData.numBytes;
367fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                        memcpy(convResult->data,
368fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                               (char *)convSession->output.fromConvertData.pBuffer,
369fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                               convResult->length);
370fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                    }
371fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                }
372fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            } else {
373fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                offset = convSession->output.fromConvertData.errorPos;
374fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            }
375fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        }
376fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    }
377fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    return new DrmConvertedStatus(getConvertedStatus(retStatus), convResult, offset);
378fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera}
379fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
380fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat DalbeheraDrmConvertedStatus* FwdLockEngine::onCloseConvertSession(int uniqueId,
381fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                                                         int convertId) {
382fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    FwdLockConv_Status_t retStatus = FwdLockConv_Status_InvalidArgument;
383fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    DrmBuffer *convResult = new DrmBuffer(NULL, 0);
384fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    int offset = -1;
385fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
386b432603d711cd504d0de62f7fbb095b90c9a4283Gloria Wang    LOGV("FwdLockEngine::onCloseConvertSession");
387fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
388fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    if (convertSessionMap.isCreated(convertId)) {
389fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        ConvertSession *convSession = convertSessionMap.getValue(convertId);
390fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
391fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        if (NULL != convSession) {
392fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            retStatus = FwdLockConv_CloseSession(convSession->uniqueId, &(convSession->output));
393fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
394fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            if (FwdLockConv_Status_OK == retStatus) {
395fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                offset = convSession->output.fromCloseSession.fileOffset;
396fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                convResult->data = new char[FWD_LOCK_SIGNATURES_SIZE];
397fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
398fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                if (NULL != convResult->data) {
399fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                      convResult->length = FWD_LOCK_SIGNATURES_SIZE;
400fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                      memcpy(convResult->data,
401fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                             (char *)convSession->output.fromCloseSession.signatures,
402fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                             convResult->length);
403fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                }
404fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            }
405fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        }
406fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        convertSessionMap.removeValue(convertId);
407fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    }
408fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    return new DrmConvertedStatus(getConvertedStatus(retStatus), convResult, offset);
409fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera}
410fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
411fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#ifdef USE_64BIT_DRM_API
412fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherastatus_t FwdLockEngine::onOpenDecryptSession(int uniqueId,
413fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                                             DecryptHandle* decryptHandle,
414fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                                             int fd,
415fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                                             off64_t offset,
416fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                                             off64_t length) {
417fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#else
418fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherastatus_t FwdLockEngine::onOpenDecryptSession(int uniqueId,
419fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                                             DecryptHandle* decryptHandle,
420fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                                             int fd,
421fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                                             int offset,
422fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                                             int length) {
423fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#endif
424fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    status_t result = DRM_ERROR_CANNOT_HANDLE;
425fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    int fileDesc = -1;
426fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
427b432603d711cd504d0de62f7fbb095b90c9a4283Gloria Wang    LOGV("FwdLockEngine::onOpenDecryptSession");
428fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
429fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    if ((-1 < fd) &&
430fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        (NULL != decryptHandle) &&
431fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        (!decodeSessionMap.isCreated(decryptHandle->decryptId))) {
432fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        fileDesc = dup(fd);
433fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    } else {
434fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        LOGD("FwdLockEngine::onOpenDecryptSession parameter error");
435fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        return result;
436fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    }
437fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
438fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    if (-1 < fileDesc &&
439fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        -1 < ::lseek(fileDesc, offset, SEEK_SET) &&
440fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        -1 < FwdLockFile_attach(fileDesc)) {
441fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        // check for file integrity. This must be done to protect the content mangling.
442fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        int retVal = FwdLockFile_CheckHeaderIntegrity(fileDesc);
443fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        DecodeSession* decodeSession = new DecodeSession(fileDesc);
444fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
445fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        if (retVal && NULL != decodeSession) {
446fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            decodeSessionMap.addValue(decryptHandle->decryptId, decodeSession);
447fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            const char *pmime= FwdLockFile_GetContentType(fileDesc);
448fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            String8 contentType = String8(pmime == NULL ? "" : pmime);
449fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            contentType.toLower();
450fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            decryptHandle->mimeType = MimeTypeUtil::convertMimeType(contentType);
451fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            decryptHandle->decryptApiType = DecryptApiType::CONTAINER_BASED;
452fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            decryptHandle->status = RightsStatus::RIGHTS_VALID;
453fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            decryptHandle->decryptInfo = NULL;
454fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            result = DRM_NO_ERROR;
455fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        } else {
456fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            LOGD("FwdLockEngine::onOpenDecryptSession Integrity Check failed for the fd");
457fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            FwdLockFile_detach(fileDesc);
458fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            delete decodeSession;
459fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        }
460fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    }
461fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
46250872c0b6563b75bb02e0de2fd578b40db8227dbGloria Wang    if (DRM_NO_ERROR != result && -1 < fileDesc) {
46350872c0b6563b75bb02e0de2fd578b40db8227dbGloria Wang        ::close(fileDesc);
46450872c0b6563b75bb02e0de2fd578b40db8227dbGloria Wang    }
46550872c0b6563b75bb02e0de2fd578b40db8227dbGloria Wang
466b432603d711cd504d0de62f7fbb095b90c9a4283Gloria Wang    LOGV("FwdLockEngine::onOpenDecryptSession Exit. result = %d", result);
467fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
468fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    return result;
469fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera}
470fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
471fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherastatus_t FwdLockEngine::onOpenDecryptSession(int uniqueId,
472fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                                             DecryptHandle* decryptHandle,
473fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                                             const char* uri) {
474fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    status_t result = DRM_ERROR_CANNOT_HANDLE;
475fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    const char fileTag [] = "file://";
476fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
477fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    if (NULL != decryptHandle && NULL != uri && strlen(uri) > sizeof(fileTag)) {
478fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        String8 uriTag = String8(uri);
479fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        uriTag.toLower();
480fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
481fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        if (0 == strncmp(uriTag.string(), fileTag, sizeof(fileTag) - 1)) {
482fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            const char *filePath = strchr(uri + sizeof(fileTag) - 1, '/');
483fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            if (NULL != filePath && onCanHandle(uniqueId, String8(filePath))) {
484fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                int fd = open(filePath, O_RDONLY);
485fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
486fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                if (-1 < fd) {
487fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                    // offset is always 0 and length is not used. so any positive size.
488fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                    result = onOpenDecryptSession(uniqueId, decryptHandle, fd, 0, 1);
489fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
490fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                    // fd is duplicated already if success. closing the file
491fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                    close(fd);
492fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                }
493fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            }
494fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        }
495fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    }
496fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
497fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    return result;
498fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera}
499fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
500fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherastatus_t FwdLockEngine::onCloseDecryptSession(int uniqueId,
501fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                                              DecryptHandle* decryptHandle) {
502fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    status_t result = DRM_ERROR_UNKNOWN;
503b432603d711cd504d0de62f7fbb095b90c9a4283Gloria Wang    LOGV("FwdLockEngine::onCloseDecryptSession");
504fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
505fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    if (NULL != decryptHandle && decodeSessionMap.isCreated(decryptHandle->decryptId)) {
506fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        DecodeSession* session = decodeSessionMap.getValue(decryptHandle->decryptId);
507fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        if (NULL != session && session->fileDesc > -1) {
508fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            FwdLockFile_detach(session->fileDesc);
509fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            ::close(session->fileDesc);
510fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            decodeSessionMap.removeValue(decryptHandle->decryptId);
511fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            result = DRM_NO_ERROR;
512fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        }
513fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    }
514fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
515409e5a07f044239aac2059c9ba3b3f6f48eeaba1Gloria Wang    if (NULL != decryptHandle) {
516409e5a07f044239aac2059c9ba3b3f6f48eeaba1Gloria Wang        if (NULL != decryptHandle->decryptInfo) {
517409e5a07f044239aac2059c9ba3b3f6f48eeaba1Gloria Wang            delete decryptHandle->decryptInfo;
518409e5a07f044239aac2059c9ba3b3f6f48eeaba1Gloria Wang            decryptHandle->decryptInfo = NULL;
519409e5a07f044239aac2059c9ba3b3f6f48eeaba1Gloria Wang        }
520409e5a07f044239aac2059c9ba3b3f6f48eeaba1Gloria Wang
521409e5a07f044239aac2059c9ba3b3f6f48eeaba1Gloria Wang        decryptHandle->copyControlVector.clear();
522409e5a07f044239aac2059c9ba3b3f6f48eeaba1Gloria Wang        decryptHandle->extendedData.clear();
523409e5a07f044239aac2059c9ba3b3f6f48eeaba1Gloria Wang
524409e5a07f044239aac2059c9ba3b3f6f48eeaba1Gloria Wang        delete decryptHandle;
525409e5a07f044239aac2059c9ba3b3f6f48eeaba1Gloria Wang        decryptHandle = NULL;
526409e5a07f044239aac2059c9ba3b3f6f48eeaba1Gloria Wang    }
527409e5a07f044239aac2059c9ba3b3f6f48eeaba1Gloria Wang
528b432603d711cd504d0de62f7fbb095b90c9a4283Gloria Wang    LOGV("FwdLockEngine::onCloseDecryptSession Exit");
529fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    return result;
530fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera}
531fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
532fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherastatus_t FwdLockEngine::onInitializeDecryptUnit(int uniqueId,
533fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                                                DecryptHandle* decryptHandle,
534fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                                                int decryptUnitId,
535fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                                                const DrmBuffer* headerInfo) {
536b432603d711cd504d0de62f7fbb095b90c9a4283Gloria Wang    LOGV("FwdLockEngine::onInitializeDecryptUnit");
537fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    return DRM_ERROR_UNKNOWN;
538fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera}
539fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
540fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherastatus_t FwdLockEngine::onDecrypt(int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId,
541fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) {
542b432603d711cd504d0de62f7fbb095b90c9a4283Gloria Wang    LOGV("FwdLockEngine::onDecrypt");
543fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    return DRM_ERROR_UNKNOWN;
544fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera}
545fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
546fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherastatus_t FwdLockEngine::onDecrypt(int uniqueId,
547fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                                  DecryptHandle* decryptHandle,
548fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                                  int decryptUnitId,
549fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                                  const DrmBuffer* encBuffer,
550fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                                  DrmBuffer** decBuffer) {
551b432603d711cd504d0de62f7fbb095b90c9a4283Gloria Wang    LOGV("FwdLockEngine::onDecrypt");
552fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    return DRM_ERROR_UNKNOWN;
553fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera}
554fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
555fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherastatus_t FwdLockEngine::onFinalizeDecryptUnit(int uniqueId,
556fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                                              DecryptHandle* decryptHandle,
557fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                                              int decryptUnitId) {
558b432603d711cd504d0de62f7fbb095b90c9a4283Gloria Wang    LOGV("FwdLockEngine::onFinalizeDecryptUnit");
559fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    return DRM_ERROR_UNKNOWN;
560fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera}
561fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
562fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherassize_t FwdLockEngine::onRead(int uniqueId,
563fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                              DecryptHandle* decryptHandle,
564fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                              void* buffer,
565fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                              int numBytes) {
566fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    ssize_t size = -1;
567fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
568fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    if (NULL != decryptHandle &&
569fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera       decodeSessionMap.isCreated(decryptHandle->decryptId) &&
570fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        NULL != buffer &&
571fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        numBytes > -1) {
572fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        DecodeSession* session = decodeSessionMap.getValue(decryptHandle->decryptId);
573fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        if (NULL != session && session->fileDesc > -1) {
574fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            size = FwdLockFile_read(session->fileDesc, buffer, numBytes);
575fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
576fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            if (0 > size) {
577fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                session->offset = ((off_t)-1);
578fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            } else {
579fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                session->offset += size;
580fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            }
581fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        }
582fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    }
583fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
584fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    return size;
585fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera}
586fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
587fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#ifdef USE_64BIT_DRM_API
588fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeheraoff64_t FwdLockEngine::onLseek(int uniqueId, DecryptHandle* decryptHandle,
589fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                               off64_t offset, int whence) {
590fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#else
591fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeheraoff_t FwdLockEngine::onLseek(int uniqueId, DecryptHandle* decryptHandle,
592fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                             off_t offset, int whence) {
593fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#endif
594fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    off_t offval = -1;
595fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
596fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    if (NULL != decryptHandle && decodeSessionMap.isCreated(decryptHandle->decryptId)) {
597fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        DecodeSession* session = decodeSessionMap.getValue(decryptHandle->decryptId);
598fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        if (NULL != session && session->fileDesc > -1) {
599fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            offval = FwdLockFile_lseek(session->fileDesc, offset, whence);
600fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            session->offset = offval;
601fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        }
602fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    }
603fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
604fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    return offval;
605fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera}
606fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
607fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#ifdef USE_64BIT_DRM_API
608fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherassize_t FwdLockEngine::onPread(int uniqueId,
609fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                               DecryptHandle* decryptHandle,
610fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                               void* buffer,
611fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                               ssize_t numBytes,
612fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                               off64_t offset) {
613fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#else
614fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherassize_t FwdLockEngine::onPread(int uniqueId,
615fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                               DecryptHandle* decryptHandle,
616fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                               void* buffer,
617fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                               ssize_t numBytes,
618fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                               off_t offset) {
619fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#endif
620fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    ssize_t bytesRead = -1;
621fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
622fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    DecodeSession* decoderSession = NULL;
623fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
624fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    if ((NULL != decryptHandle) &&
625fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        (NULL != (decoderSession = decodeSessionMap.getValue(decryptHandle->decryptId))) &&
626fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        (NULL != buffer) &&
627fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        (numBytes > -1) &&
628fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        (offset > -1)) {
629fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        if (offset != decoderSession->offset) {
630fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            decoderSession->offset = onLseek(uniqueId, decryptHandle, offset, SEEK_SET);
631fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        }
632fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
633fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        if (((off_t)-1) != decoderSession->offset) {
634fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            bytesRead = onRead(uniqueId, decryptHandle, buffer, numBytes);
635fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            if (bytesRead < 0) {
636fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera                LOGD("FwdLockEngine::onPread error reading");
637fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera            }
638fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        }
639fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    } else {
640fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera        LOGD("FwdLockEngine::onPread decryptId not found");
641fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    }
642fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
643fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera    return bytesRead;
644fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera}
645