1/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <utils/String8.h>
18#include <binder/IServiceManager.h>
19#include <drm/DrmManagerClient.h>
20
21#include "DrmManagerClientImpl.h"
22
23using namespace android;
24
25DrmManagerClient::DrmManagerClient():
26        mUniqueId(0), mDrmManagerClientImpl(NULL) {
27    mDrmManagerClientImpl = DrmManagerClientImpl::create(&mUniqueId, true);
28    mDrmManagerClientImpl->addClient(mUniqueId);
29}
30
31DrmManagerClient::~DrmManagerClient() {
32    DrmManagerClientImpl::remove(mUniqueId);
33    mDrmManagerClientImpl->removeClient(mUniqueId);
34    mDrmManagerClientImpl->setOnInfoListener(mUniqueId, NULL);
35}
36
37status_t DrmManagerClient::setOnInfoListener(
38                    const sp<DrmManagerClient::OnInfoListener>& infoListener) {
39    return mDrmManagerClientImpl->setOnInfoListener(mUniqueId, infoListener);
40}
41
42DrmConstraints* DrmManagerClient::getConstraints(const String8* path, const int action) {
43    return mDrmManagerClientImpl->getConstraints(mUniqueId, path, action);
44}
45
46DrmMetadata* DrmManagerClient::getMetadata(const String8* path) {
47    return mDrmManagerClientImpl->getMetadata(mUniqueId, path);
48}
49
50bool DrmManagerClient::canHandle(const String8& path, const String8& mimeType) {
51    return mDrmManagerClientImpl->canHandle(mUniqueId, path, mimeType);
52}
53
54DrmInfoStatus* DrmManagerClient::processDrmInfo(const DrmInfo* drmInfo) {
55    return mDrmManagerClientImpl->processDrmInfo(mUniqueId, drmInfo);
56}
57
58DrmInfo* DrmManagerClient::acquireDrmInfo(const DrmInfoRequest* drmInfoRequest) {
59    return mDrmManagerClientImpl->acquireDrmInfo(mUniqueId, drmInfoRequest);
60}
61
62status_t DrmManagerClient::saveRights(
63        const DrmRights& drmRights, const String8& rightsPath, const String8& contentPath) {
64    return mDrmManagerClientImpl->saveRights(mUniqueId, drmRights, rightsPath, contentPath);
65}
66
67String8 DrmManagerClient::getOriginalMimeType(const String8& path, int fd) {
68    return mDrmManagerClientImpl->getOriginalMimeType(mUniqueId, path, fd);
69}
70
71int DrmManagerClient::getDrmObjectType(const String8& path, const String8& mimeType) {
72    return mDrmManagerClientImpl->getDrmObjectType( mUniqueId, path, mimeType);
73}
74
75int DrmManagerClient::checkRightsStatus(const String8& path, int action) {
76    return mDrmManagerClientImpl->checkRightsStatus(mUniqueId, path, action);
77}
78
79status_t DrmManagerClient::consumeRights(
80            sp<DecryptHandle> &decryptHandle, int action, bool reserve) {
81    return mDrmManagerClientImpl->consumeRights(mUniqueId, decryptHandle, action, reserve);
82}
83
84status_t DrmManagerClient::setPlaybackStatus(
85            sp<DecryptHandle> &decryptHandle, int playbackStatus, int64_t position) {
86    return mDrmManagerClientImpl
87            ->setPlaybackStatus(mUniqueId, decryptHandle, playbackStatus, position);
88}
89
90bool DrmManagerClient::validateAction(
91            const String8& path, int action, const ActionDescription& description) {
92    return mDrmManagerClientImpl->validateAction(mUniqueId, path, action, description);
93}
94
95status_t DrmManagerClient::removeRights(const String8& path) {
96    return mDrmManagerClientImpl->removeRights(mUniqueId, path);
97}
98
99status_t DrmManagerClient::removeAllRights() {
100    return mDrmManagerClientImpl->removeAllRights(mUniqueId);
101}
102
103int DrmManagerClient::openConvertSession(const String8& mimeType) {
104    return mDrmManagerClientImpl->openConvertSession(mUniqueId, mimeType);
105}
106
107DrmConvertedStatus* DrmManagerClient::convertData(int convertId, const DrmBuffer* inputData) {
108    return mDrmManagerClientImpl->convertData(mUniqueId, convertId, inputData);
109}
110
111DrmConvertedStatus* DrmManagerClient::closeConvertSession(int convertId) {
112    return mDrmManagerClientImpl->closeConvertSession(mUniqueId, convertId);
113}
114
115status_t DrmManagerClient::getAllSupportInfo(int* length, DrmSupportInfo** drmSupportInfoArray) {
116    return mDrmManagerClientImpl->getAllSupportInfo(mUniqueId, length, drmSupportInfoArray);
117}
118
119sp<DecryptHandle> DrmManagerClient::openDecryptSession(
120        int fd, off64_t offset, off64_t length, const char* mime) {
121
122    return mDrmManagerClientImpl->openDecryptSession(
123                    mUniqueId, fd, offset, length, mime);
124}
125
126sp<DecryptHandle> DrmManagerClient::openDecryptSession(
127        const char* uri, const char* mime) {
128
129    return mDrmManagerClientImpl->openDecryptSession(
130                    mUniqueId, uri, mime);
131}
132
133sp<DecryptHandle> DrmManagerClient::openDecryptSession(
134            const DrmBuffer& buf, const String8& mimeType) {
135    return mDrmManagerClientImpl->openDecryptSession(mUniqueId, buf, mimeType);
136}
137
138status_t DrmManagerClient::closeDecryptSession(sp<DecryptHandle> &decryptHandle) {
139    return mDrmManagerClientImpl->closeDecryptSession(mUniqueId, decryptHandle);
140}
141
142status_t DrmManagerClient::initializeDecryptUnit(
143            sp<DecryptHandle> &decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo) {
144    return mDrmManagerClientImpl->initializeDecryptUnit(
145            mUniqueId, decryptHandle, decryptUnitId, headerInfo);
146}
147
148status_t DrmManagerClient::decrypt(
149            sp<DecryptHandle> &decryptHandle, int decryptUnitId,
150            const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) {
151    return mDrmManagerClientImpl->decrypt(
152            mUniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer, IV);
153}
154
155status_t DrmManagerClient::finalizeDecryptUnit(
156            sp<DecryptHandle> &decryptHandle, int decryptUnitId) {
157    return mDrmManagerClientImpl->finalizeDecryptUnit(mUniqueId,
158            decryptHandle, decryptUnitId);
159}
160
161ssize_t DrmManagerClient::pread(
162            sp<DecryptHandle> &decryptHandle, void* buffer, ssize_t numBytes, off64_t offset) {
163    return mDrmManagerClientImpl->pread(mUniqueId, decryptHandle, buffer, numBytes, offset);
164}
165
166