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
1727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi#include <utils/String8.h>
1827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi#include <binder/IServiceManager.h>
1927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi#include <drm/DrmManagerClient.h>
2027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
2127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi#include "DrmManagerClientImpl.h"
2227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
2327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshiusing namespace android;
2427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
25e943f84129326ab885cc7a69dcfa17f766b72b89Takeshi AimiDrmManagerClient::DrmManagerClient():
26e943f84129326ab885cc7a69dcfa17f766b72b89Takeshi Aimi        mUniqueId(0), mDrmManagerClientImpl(NULL) {
278f00151cbe693d52f3e233757c57fab3b6396d21Gloria Wang    mDrmManagerClientImpl = DrmManagerClientImpl::create(&mUniqueId, true);
28e943f84129326ab885cc7a69dcfa17f766b72b89Takeshi Aimi    mDrmManagerClientImpl->addClient(mUniqueId);
2927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
3027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
3127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshiDrmManagerClient::~DrmManagerClient() {
3227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    DrmManagerClientImpl::remove(mUniqueId);
33e943f84129326ab885cc7a69dcfa17f766b72b89Takeshi Aimi    mDrmManagerClientImpl->removeClient(mUniqueId);
34c618b5af98dec06d49374a61a5a94016f9fec2d3Takeshi Aimi    mDrmManagerClientImpl->setOnInfoListener(mUniqueId, NULL);
3527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
3627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
3727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshistatus_t DrmManagerClient::setOnInfoListener(
3827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi                    const sp<DrmManagerClient::OnInfoListener>& infoListener) {
3927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return mDrmManagerClientImpl->setOnInfoListener(mUniqueId, infoListener);
4027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
4127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
4227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshiDrmConstraints* DrmManagerClient::getConstraints(const String8* path, const int action) {
4327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return mDrmManagerClientImpl->getConstraints(mUniqueId, path, action);
4427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
4527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
463473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi AimiDrmMetadata* DrmManagerClient::getMetadata(const String8* path) {
473473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi    return mDrmManagerClientImpl->getMetadata(mUniqueId, path);
483473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi}
493473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi
5027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshibool DrmManagerClient::canHandle(const String8& path, const String8& mimeType) {
5127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return mDrmManagerClientImpl->canHandle(mUniqueId, path, mimeType);
5227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
5327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
5427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshiDrmInfoStatus* DrmManagerClient::processDrmInfo(const DrmInfo* drmInfo) {
5527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return mDrmManagerClientImpl->processDrmInfo(mUniqueId, drmInfo);
5627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
5727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
5827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshiDrmInfo* DrmManagerClient::acquireDrmInfo(const DrmInfoRequest* drmInfoRequest) {
5927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return mDrmManagerClientImpl->acquireDrmInfo(mUniqueId, drmInfoRequest);
6027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
6127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
622272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimistatus_t DrmManagerClient::saveRights(
6327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi        const DrmRights& drmRights, const String8& rightsPath, const String8& contentPath) {
6427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return mDrmManagerClientImpl->saveRights(mUniqueId, drmRights, rightsPath, contentPath);
6527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
6627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
67bf5b3b29e31b293313788d7464cfb258ac0da803James DongString8 DrmManagerClient::getOriginalMimeType(const String8& path, int fd) {
68bf5b3b29e31b293313788d7464cfb258ac0da803James Dong    return mDrmManagerClientImpl->getOriginalMimeType(mUniqueId, path, fd);
6927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
7027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
7127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshiint DrmManagerClient::getDrmObjectType(const String8& path, const String8& mimeType) {
7227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return mDrmManagerClientImpl->getDrmObjectType( mUniqueId, path, mimeType);
7327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
7427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
7527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshiint DrmManagerClient::checkRightsStatus(const String8& path, int action) {
7627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return mDrmManagerClientImpl->checkRightsStatus(mUniqueId, path, action);
7727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
7827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
79b5ce361d19e69fe156f7188c9ee0f4734b259874Gloria Wangstatus_t DrmManagerClient::consumeRights(
80b5ce361d19e69fe156f7188c9ee0f4734b259874Gloria Wang            sp<DecryptHandle> &decryptHandle, int action, bool reserve) {
812272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi    return mDrmManagerClientImpl->consumeRights(mUniqueId, decryptHandle, action, reserve);
8227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
8327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
842272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimistatus_t DrmManagerClient::setPlaybackStatus(
85b5ce361d19e69fe156f7188c9ee0f4734b259874Gloria Wang            sp<DecryptHandle> &decryptHandle, int playbackStatus, int64_t position) {
862272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi    return mDrmManagerClientImpl
872272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi            ->setPlaybackStatus(mUniqueId, decryptHandle, playbackStatus, position);
8827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
8927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
9027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshibool DrmManagerClient::validateAction(
9127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi            const String8& path, int action, const ActionDescription& description) {
9227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return mDrmManagerClientImpl->validateAction(mUniqueId, path, action, description);
9327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
9427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
952272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimistatus_t DrmManagerClient::removeRights(const String8& path) {
962272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi    return mDrmManagerClientImpl->removeRights(mUniqueId, path);
9727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
9827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
992272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimistatus_t DrmManagerClient::removeAllRights() {
1002272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi    return mDrmManagerClientImpl->removeAllRights(mUniqueId);
10127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
10227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
10327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshiint DrmManagerClient::openConvertSession(const String8& mimeType) {
10427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return mDrmManagerClientImpl->openConvertSession(mUniqueId, mimeType);
10527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
10627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
10727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshiDrmConvertedStatus* DrmManagerClient::convertData(int convertId, const DrmBuffer* inputData) {
10827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return mDrmManagerClientImpl->convertData(mUniqueId, convertId, inputData);
10927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
11027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
11127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshiDrmConvertedStatus* DrmManagerClient::closeConvertSession(int convertId) {
11227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return mDrmManagerClientImpl->closeConvertSession(mUniqueId, convertId);
11327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
11427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
11527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshistatus_t DrmManagerClient::getAllSupportInfo(int* length, DrmSupportInfo** drmSupportInfoArray) {
11627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return mDrmManagerClientImpl->getAllSupportInfo(mUniqueId, length, drmSupportInfoArray);
11727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
11827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
1199d2f386dd2885eaffa11fd494ae258bb09fe6397James Dongsp<DecryptHandle> DrmManagerClient::openDecryptSession(
1209d2f386dd2885eaffa11fd494ae258bb09fe6397James Dong        int fd, off64_t offset, off64_t length, const char* mime) {
1219d2f386dd2885eaffa11fd494ae258bb09fe6397James Dong
1229d2f386dd2885eaffa11fd494ae258bb09fe6397James Dong    return mDrmManagerClientImpl->openDecryptSession(
1239d2f386dd2885eaffa11fd494ae258bb09fe6397James Dong                    mUniqueId, fd, offset, length, mime);
12427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
12527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
1269d2f386dd2885eaffa11fd494ae258bb09fe6397James Dongsp<DecryptHandle> DrmManagerClient::openDecryptSession(
1279d2f386dd2885eaffa11fd494ae258bb09fe6397James Dong        const char* uri, const char* mime) {
1289d2f386dd2885eaffa11fd494ae258bb09fe6397James Dong
1299d2f386dd2885eaffa11fd494ae258bb09fe6397James Dong    return mDrmManagerClientImpl->openDecryptSession(
1309d2f386dd2885eaffa11fd494ae258bb09fe6397James Dong                    mUniqueId, uri, mime);
131e943f84129326ab885cc7a69dcfa17f766b72b89Takeshi Aimi}
132e943f84129326ab885cc7a69dcfa17f766b72b89Takeshi Aimi
133cba7b32d8f2c47632313f54118ed3733b4b02cc8Kei Takahashisp<DecryptHandle> DrmManagerClient::openDecryptSession(
134cba7b32d8f2c47632313f54118ed3733b4b02cc8Kei Takahashi            const DrmBuffer& buf, const String8& mimeType) {
135cba7b32d8f2c47632313f54118ed3733b4b02cc8Kei Takahashi    return mDrmManagerClientImpl->openDecryptSession(mUniqueId, buf, mimeType);
136cba7b32d8f2c47632313f54118ed3733b4b02cc8Kei Takahashi}
137cba7b32d8f2c47632313f54118ed3733b4b02cc8Kei Takahashi
138b5ce361d19e69fe156f7188c9ee0f4734b259874Gloria Wangstatus_t DrmManagerClient::closeDecryptSession(sp<DecryptHandle> &decryptHandle) {
1392272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi    return mDrmManagerClientImpl->closeDecryptSession(mUniqueId, decryptHandle);
14027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
14127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
1422272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimistatus_t DrmManagerClient::initializeDecryptUnit(
143b5ce361d19e69fe156f7188c9ee0f4734b259874Gloria Wang            sp<DecryptHandle> &decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo) {
1442272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi    return mDrmManagerClientImpl->initializeDecryptUnit(
1452272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi            mUniqueId, decryptHandle, decryptUnitId, headerInfo);
14627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
14727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
14827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshistatus_t DrmManagerClient::decrypt(
149b5ce361d19e69fe156f7188c9ee0f4734b259874Gloria Wang            sp<DecryptHandle> &decryptHandle, int decryptUnitId,
150b5ce361d19e69fe156f7188c9ee0f4734b259874Gloria Wang            const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) {
15127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return mDrmManagerClientImpl->decrypt(
1522272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimi            mUniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer, IV);
15327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
15427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
155b5ce361d19e69fe156f7188c9ee0f4734b259874Gloria Wangstatus_t DrmManagerClient::finalizeDecryptUnit(
156b5ce361d19e69fe156f7188c9ee0f4734b259874Gloria Wang            sp<DecryptHandle> &decryptHandle, int decryptUnitId) {
157b5ce361d19e69fe156f7188c9ee0f4734b259874Gloria Wang    return mDrmManagerClientImpl->finalizeDecryptUnit(mUniqueId,
158b5ce361d19e69fe156f7188c9ee0f4734b259874Gloria Wang            decryptHandle, decryptUnitId);
15927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
16027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
16127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshissize_t DrmManagerClient::pread(
162b5ce361d19e69fe156f7188c9ee0f4734b259874Gloria Wang            sp<DecryptHandle> &decryptHandle, void* buffer, ssize_t numBytes, off64_t offset) {
16327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi    return mDrmManagerClientImpl->pread(mUniqueId, decryptHandle, buffer, numBytes, offset);
16427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi}
16527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi
166