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