127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi/*
227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi * Copyright (C) 2010 The Android Open Source Project
327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi *
427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi * Licensed under the Apache License, Version 2.0 (the "License");
527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi * you may not use this file except in compliance with the License.
627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi * You may obtain a copy of the License at
727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi *
827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi *      http://www.apache.org/licenses/LICENSE-2.0
927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi *
1027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi * Unless required by applicable law or agreed to in writing, software
1127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi * distributed under the License is distributed on an "AS IS" BASIS,
1227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi * See the License for the specific language governing permissions and
1427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi * limitations under the License.
1527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi */
1627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
170a38af09ebbacdc9aa0d5ecb24e2f0484bf4f191James Dong//#define LOG_NDEBUG 0
1827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi#define LOG_TAG "DrmPassthruPlugIn"
1927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi#include <utils/Log.h>
2027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
2127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi#include <drm/DrmRights.h>
2227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi#include <drm/DrmConstraints.h>
233473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi#include <drm/DrmMetadata.h>
2427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi#include <drm/DrmInfo.h>
2527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi#include <drm/DrmInfoEvent.h>
2627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi#include <drm/DrmInfoStatus.h>
2727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi#include <drm/DrmConvertedStatus.h>
2827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi#include <drm/DrmInfoRequest.h>
2927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi#include <drm/DrmSupportInfo.h>
3027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi#include <DrmPassthruPlugIn.h>
3127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
3227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshiusing namespace android;
3327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
3427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
3527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi// This extern "C" is mandatory to be managed by TPlugInManager
3627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshiextern "C" IDrmEngine* create() {
3727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return new DrmPassthruPlugIn();
3827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
3927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
4027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi// This extern "C" is mandatory to be managed by TPlugInManager
4127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshiextern "C" void destroy(IDrmEngine* pPlugIn) {
4227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    delete pPlugIn;
4327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    pPlugIn = NULL;
4427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
4527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
4627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshiDrmPassthruPlugIn::DrmPassthruPlugIn()
4727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    : DrmEngineBase() {
4827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
4927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
5027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
5127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshiDrmPassthruPlugIn::~DrmPassthruPlugIn() {
5227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
5327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
5427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
553473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi AimiDrmMetadata* DrmPassthruPlugIn::onGetMetadata(int uniqueId, const String8* path) {
563473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi    return NULL;
573473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi}
583473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi
5927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshiDrmConstraints* DrmPassthruPlugIn::onGetConstraints(
6027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        int uniqueId, const String8* path, int action) {
610a38af09ebbacdc9aa0d5ecb24e2f0484bf4f191James Dong    ALOGV("DrmPassthruPlugIn::onGetConstraints From Path: %d", uniqueId);
6227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    DrmConstraints* drmConstraints = new DrmConstraints();
6327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
6427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    String8 value("dummy_available_time");
6527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    char* charValue = NULL;
6627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    charValue = new char[value.length() + 1];
6727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    strncpy(charValue, value.string(), value.length());
6827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
6927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    //Just add dummy available time for verification
7027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    drmConstraints->put(&(DrmConstraints::LICENSE_AVAILABLE_TIME), charValue);
7127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
7227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return drmConstraints;
7327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
7427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
7527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshiDrmInfoStatus* DrmPassthruPlugIn::onProcessDrmInfo(int uniqueId, const DrmInfo* drmInfo) {
760a38af09ebbacdc9aa0d5ecb24e2f0484bf4f191James Dong    ALOGV("DrmPassthruPlugIn::onProcessDrmInfo - Enter : %d", uniqueId);
7727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    DrmInfoStatus* drmInfoStatus = NULL;
7827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    if (NULL != drmInfo) {
7927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        switch (drmInfo->getInfoType()) {
8027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        case DrmInfoRequest::TYPE_REGISTRATION_INFO: {
8127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            const DrmBuffer* emptyBuffer = new DrmBuffer();
82e943f84129326ab885cc7a69dcfa17f766b72b89Takeshi Aimi            drmInfoStatus = new DrmInfoStatus(DrmInfoStatus::STATUS_OK,
83e943f84129326ab885cc7a69dcfa17f766b72b89Takeshi Aimi                    DrmInfoRequest::TYPE_REGISTRATION_INFO, emptyBuffer, drmInfo->getMimeType());
8427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            break;
8527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        }
8627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        case DrmInfoRequest::TYPE_UNREGISTRATION_INFO: {
8727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            const DrmBuffer* emptyBuffer = new DrmBuffer();
88e943f84129326ab885cc7a69dcfa17f766b72b89Takeshi Aimi            drmInfoStatus = new DrmInfoStatus(DrmInfoStatus::STATUS_OK,
89e943f84129326ab885cc7a69dcfa17f766b72b89Takeshi Aimi                    DrmInfoRequest::TYPE_UNREGISTRATION_INFO, emptyBuffer, drmInfo->getMimeType());
9027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            break;
9127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        }
9227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        case DrmInfoRequest::TYPE_RIGHTS_ACQUISITION_INFO: {
9327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            String8 licenseString("dummy_license_string");
9427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            const int bufferSize = licenseString.size();
9527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            char* data = NULL;
9627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            data = new char[bufferSize];
9727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            memcpy(data, licenseString.string(), bufferSize);
9827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            const DrmBuffer* buffer = new DrmBuffer(data, bufferSize);
99e943f84129326ab885cc7a69dcfa17f766b72b89Takeshi Aimi            drmInfoStatus = new DrmInfoStatus(DrmInfoStatus::STATUS_OK,
100e943f84129326ab885cc7a69dcfa17f766b72b89Takeshi Aimi                    DrmInfoRequest::TYPE_RIGHTS_ACQUISITION_INFO, buffer, drmInfo->getMimeType());
10127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            break;
10227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        }
10327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        }
10427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    }
1050a38af09ebbacdc9aa0d5ecb24e2f0484bf4f191James Dong    ALOGV("DrmPassthruPlugIn::onProcessDrmInfo - Exit");
10627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return drmInfoStatus;
10727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
10827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
10927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshistatus_t DrmPassthruPlugIn::onSetOnInfoListener(
11027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            int uniqueId, const IDrmEngine::OnInfoListener* infoListener) {
1110a38af09ebbacdc9aa0d5ecb24e2f0484bf4f191James Dong    ALOGV("DrmPassthruPlugIn::onSetOnInfoListener : %d", uniqueId);
11227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return DRM_NO_ERROR;
11327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
11427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
11527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshistatus_t DrmPassthruPlugIn::onInitialize(int uniqueId) {
1160a38af09ebbacdc9aa0d5ecb24e2f0484bf4f191James Dong    ALOGV("DrmPassthruPlugIn::onInitialize : %d", uniqueId);
11727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return DRM_NO_ERROR;
11827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
11927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
12027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshistatus_t DrmPassthruPlugIn::onTerminate(int uniqueId) {
1210a38af09ebbacdc9aa0d5ecb24e2f0484bf4f191James Dong    ALOGV("DrmPassthruPlugIn::onTerminate : %d", uniqueId);
12227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return DRM_NO_ERROR;
12327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
12427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
12527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshiDrmSupportInfo* DrmPassthruPlugIn::onGetSupportInfo(int uniqueId) {
1260a38af09ebbacdc9aa0d5ecb24e2f0484bf4f191James Dong    ALOGV("DrmPassthruPlugIn::onGetSupportInfo : %d", uniqueId);
12727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    DrmSupportInfo* drmSupportInfo = new DrmSupportInfo();
12827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    // Add mimetype's
12927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    drmSupportInfo->addMimeType(String8("application/vnd.passthru.drm"));
13027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    // Add File Suffixes
13127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    drmSupportInfo->addFileSuffix(String8(".passthru"));
13227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    // Add plug-in description
13327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    drmSupportInfo->setDescription(String8("Passthru plug-in"));
13427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return drmSupportInfo;
13527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
13627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
1372272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimistatus_t DrmPassthruPlugIn::onSaveRights(int uniqueId, const DrmRights& drmRights,
13827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            const String8& rightsPath, const String8& contentPath) {
1390a38af09ebbacdc9aa0d5ecb24e2f0484bf4f191James Dong    ALOGV("DrmPassthruPlugIn::onSaveRights : %d", uniqueId);
1402272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi    return DRM_NO_ERROR;
14127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
14227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
14327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshiDrmInfo* DrmPassthruPlugIn::onAcquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest) {
1440a38af09ebbacdc9aa0d5ecb24e2f0484bf4f191James Dong    ALOGV("DrmPassthruPlugIn::onAcquireDrmInfo : %d", uniqueId);
14527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    DrmInfo* drmInfo = NULL;
14627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
14727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    if (NULL != drmInfoRequest) {
14827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        String8 dataString("dummy_acquistion_string");
14927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        int length = dataString.length();
15027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        char* data = NULL;
15127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        data = new char[length];
15227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        memcpy(data, dataString.string(), length);
15327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        drmInfo = new DrmInfo(drmInfoRequest->getInfoType(),
15427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            DrmBuffer(data, length), drmInfoRequest->getMimeType());
15527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    }
15627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return drmInfo;
15727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
15827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
15927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshibool DrmPassthruPlugIn::onCanHandle(int uniqueId, const String8& path) {
1600a38af09ebbacdc9aa0d5ecb24e2f0484bf4f191James Dong    ALOGV("DrmPassthruPlugIn::canHandle: %s ", path.string());
16127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    String8 extension = path.getPathExtension();
16227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    extension.toLower();
16327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return (String8(".passthru") == extension);
16427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
16527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
166bf5b3b29e31b293313788d7464cfb258ac0da803James DongString8 DrmPassthruPlugIn::onGetOriginalMimeType(int uniqueId, const String8& path, int fd) {
1670a38af09ebbacdc9aa0d5ecb24e2f0484bf4f191James Dong    ALOGV("DrmPassthruPlugIn::onGetOriginalMimeType() : %d", uniqueId);
16827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return String8("video/passthru");
16927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
17027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
17127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshiint DrmPassthruPlugIn::onGetDrmObjectType(
17227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            int uniqueId, const String8& path, const String8& mimeType) {
1730a38af09ebbacdc9aa0d5ecb24e2f0484bf4f191James Dong    ALOGV("DrmPassthruPlugIn::onGetDrmObjectType() : %d", uniqueId);
17427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return DrmObjectType::UNKNOWN;
17527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
17627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
17727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshiint DrmPassthruPlugIn::onCheckRightsStatus(int uniqueId, const String8& path, int action) {
1780a38af09ebbacdc9aa0d5ecb24e2f0484bf4f191James Dong    ALOGV("DrmPassthruPlugIn::onCheckRightsStatus() : %d", uniqueId);
17927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    int rightsStatus = RightsStatus::RIGHTS_VALID;
18027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return rightsStatus;
18127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
18227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
1832272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimistatus_t DrmPassthruPlugIn::onConsumeRights(int uniqueId, DecryptHandle* decryptHandle,
18427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            int action, bool reserve) {
1850a38af09ebbacdc9aa0d5ecb24e2f0484bf4f191James Dong    ALOGV("DrmPassthruPlugIn::onConsumeRights() : %d", uniqueId);
1862272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi    return DRM_NO_ERROR;
18727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
18827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
1892272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimistatus_t DrmPassthruPlugIn::onSetPlaybackStatus(int uniqueId, DecryptHandle* decryptHandle,
190a2cd44cb5067b4fe98794860690394254d3ac73cGloria Wang            int playbackStatus, int64_t position) {
1910a38af09ebbacdc9aa0d5ecb24e2f0484bf4f191James Dong    ALOGV("DrmPassthruPlugIn::onSetPlaybackStatus() : %d", uniqueId);
1922272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi    return DRM_NO_ERROR;
19327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
19427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
19527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshibool DrmPassthruPlugIn::onValidateAction(int uniqueId, const String8& path,
19627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            int action, const ActionDescription& description) {
1970a38af09ebbacdc9aa0d5ecb24e2f0484bf4f191James Dong    ALOGV("DrmPassthruPlugIn::onValidateAction() : %d", uniqueId);
19827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return true;
19927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
20027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
2012272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimistatus_t DrmPassthruPlugIn::onRemoveRights(int uniqueId, const String8& path) {
2020a38af09ebbacdc9aa0d5ecb24e2f0484bf4f191James Dong    ALOGV("DrmPassthruPlugIn::onRemoveRights() : %d", uniqueId);
2032272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi    return DRM_NO_ERROR;
20427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
20527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
2062272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimistatus_t DrmPassthruPlugIn::onRemoveAllRights(int uniqueId) {
2070a38af09ebbacdc9aa0d5ecb24e2f0484bf4f191James Dong    ALOGV("DrmPassthruPlugIn::onRemoveAllRights() : %d", uniqueId);
2082272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi    return DRM_NO_ERROR;
20927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
21027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
2112272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimistatus_t DrmPassthruPlugIn::onOpenConvertSession(int uniqueId, int convertId) {
2120a38af09ebbacdc9aa0d5ecb24e2f0484bf4f191James Dong    ALOGV("DrmPassthruPlugIn::onOpenConvertSession() : %d", uniqueId);
2132272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi    return DRM_NO_ERROR;
21427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
21527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
21627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshiDrmConvertedStatus* DrmPassthruPlugIn::onConvertData(
21727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            int uniqueId, int convertId, const DrmBuffer* inputData) {
2180a38af09ebbacdc9aa0d5ecb24e2f0484bf4f191James Dong    ALOGV("DrmPassthruPlugIn::onConvertData() : %d", uniqueId);
21927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    DrmBuffer* convertedData = NULL;
22027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
22127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    if (NULL != inputData && 0 < inputData->length) {
22227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        int length = inputData->length;
22327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        char* data = NULL;
22427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        data = new char[length];
22527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        convertedData = new DrmBuffer(data, length);
22627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        memcpy(convertedData->data, inputData->data, length);
22727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    }
22827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return new DrmConvertedStatus(DrmConvertedStatus::STATUS_OK, convertedData, 0 /*offset*/);
22927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
23027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
23127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshiDrmConvertedStatus* DrmPassthruPlugIn::onCloseConvertSession(int uniqueId, int convertId) {
2320a38af09ebbacdc9aa0d5ecb24e2f0484bf4f191James Dong    ALOGV("DrmPassthruPlugIn::onCloseConvertSession() : %d", uniqueId);
23327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return new DrmConvertedStatus(DrmConvertedStatus::STATUS_OK, NULL, 0 /*offset*/);
23427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
23527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
23627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshistatus_t DrmPassthruPlugIn::onOpenDecryptSession(
237a2cd44cb5067b4fe98794860690394254d3ac73cGloria Wang            int uniqueId, DecryptHandle* decryptHandle, int fd, off64_t offset, off64_t length) {
2380a38af09ebbacdc9aa0d5ecb24e2f0484bf4f191James Dong    ALOGV("DrmPassthruPlugIn::onOpenDecryptSession() : %d", uniqueId);
23927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
24027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi#ifdef ENABLE_PASSTHRU_DECRYPTION
24127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    decryptHandle->mimeType = String8("video/passthru");
24227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    decryptHandle->decryptApiType = DecryptApiType::ELEMENTARY_STREAM_BASED;
24327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    decryptHandle->status = DRM_NO_ERROR;
24427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    decryptHandle->decryptInfo = NULL;
24527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return DRM_NO_ERROR;
24627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi#endif
24727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
24827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return DRM_ERROR_CANNOT_HANDLE;
24927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
25027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
251e943f84129326ab885cc7a69dcfa17f766b72b89Takeshi Aimistatus_t DrmPassthruPlugIn::onOpenDecryptSession(
252e943f84129326ab885cc7a69dcfa17f766b72b89Takeshi Aimi            int uniqueId, DecryptHandle* decryptHandle, const char* uri) {
253e943f84129326ab885cc7a69dcfa17f766b72b89Takeshi Aimi    return DRM_ERROR_CANNOT_HANDLE;
254e943f84129326ab885cc7a69dcfa17f766b72b89Takeshi Aimi}
255e943f84129326ab885cc7a69dcfa17f766b72b89Takeshi Aimi
2562272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimistatus_t DrmPassthruPlugIn::onCloseDecryptSession(int uniqueId, DecryptHandle* decryptHandle) {
2570a38af09ebbacdc9aa0d5ecb24e2f0484bf4f191James Dong    ALOGV("DrmPassthruPlugIn::onCloseDecryptSession() : %d", uniqueId);
25827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    if (NULL != decryptHandle) {
25927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        if (NULL != decryptHandle->decryptInfo) {
26027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            delete decryptHandle->decryptInfo; decryptHandle->decryptInfo = NULL;
26127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        }
26227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        delete decryptHandle; decryptHandle = NULL;
26327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    }
2642272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi    return DRM_NO_ERROR;
26527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
26627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
2672272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimistatus_t DrmPassthruPlugIn::onInitializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle,
26827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            int decryptUnitId, const DrmBuffer* headerInfo) {
2690a38af09ebbacdc9aa0d5ecb24e2f0484bf4f191James Dong    ALOGV("DrmPassthruPlugIn::onInitializeDecryptUnit() : %d", uniqueId);
2702272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi    return DRM_NO_ERROR;
27127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
27227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
27327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshistatus_t DrmPassthruPlugIn::onDecrypt(int uniqueId, DecryptHandle* decryptHandle,
2742272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi            int decryptUnitId, const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) {
2750a38af09ebbacdc9aa0d5ecb24e2f0484bf4f191James Dong    ALOGV("DrmPassthruPlugIn::onDecrypt() : %d", uniqueId);
27627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    /**
27727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi     * As a workaround implementation passthru would copy the given
27827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi     * encrypted buffer as it is to decrypted buffer. Note, decBuffer
27927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi     * memory has to be allocated by the caller.
28027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi     */
28127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    if (NULL != (*decBuffer) && 0 < (*decBuffer)->length) {
28235250664455c9642cc14d3831b663880637a7d70James Dong        if ((*decBuffer)->length >= encBuffer->length) {
28335250664455c9642cc14d3831b663880637a7d70James Dong            memcpy((*decBuffer)->data, encBuffer->data, encBuffer->length);
28435250664455c9642cc14d3831b663880637a7d70James Dong            (*decBuffer)->length = encBuffer->length;
28535250664455c9642cc14d3831b663880637a7d70James Dong        } else {
28635250664455c9642cc14d3831b663880637a7d70James Dong            ALOGE("decBuffer size (%d) too small to hold %d bytes",
28735250664455c9642cc14d3831b663880637a7d70James Dong                (*decBuffer)->length, encBuffer->length);
28835250664455c9642cc14d3831b663880637a7d70James Dong            return DRM_ERROR_UNKNOWN;
28935250664455c9642cc14d3831b663880637a7d70James Dong        }
29027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    }
29127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return DRM_NO_ERROR;
29227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
29327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
2942272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimistatus_t DrmPassthruPlugIn::onFinalizeDecryptUnit(
29527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) {
2960a38af09ebbacdc9aa0d5ecb24e2f0484bf4f191James Dong    ALOGV("DrmPassthruPlugIn::onFinalizeDecryptUnit() : %d", uniqueId);
2972272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi    return DRM_NO_ERROR;
29827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
29927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
30027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshissize_t DrmPassthruPlugIn::onPread(int uniqueId, DecryptHandle* decryptHandle,
301a2cd44cb5067b4fe98794860690394254d3ac73cGloria Wang            void* buffer, ssize_t numBytes, off64_t offset) {
3020a38af09ebbacdc9aa0d5ecb24e2f0484bf4f191James Dong    ALOGV("DrmPassthruPlugIn::onPread() : %d", uniqueId);
30327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return 0;
30427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
30527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
306