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