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 
23 using namespace android;
24 
DrmManagerClient()25 DrmManagerClient::DrmManagerClient():
26         mUniqueId(0), mDrmManagerClientImpl(NULL) {
27     mDrmManagerClientImpl = DrmManagerClientImpl::create(&mUniqueId, true);
28     mDrmManagerClientImpl->addClient(mUniqueId);
29 }
30 
~DrmManagerClient()31 DrmManagerClient::~DrmManagerClient() {
32     mDrmManagerClientImpl->remove(mUniqueId);
33     mDrmManagerClientImpl->removeClient(mUniqueId);
34     mDrmManagerClientImpl->setOnInfoListener(mUniqueId, NULL);
35 }
36 
setOnInfoListener(const sp<DrmManagerClient::OnInfoListener> & infoListener)37 status_t DrmManagerClient::setOnInfoListener(
38                     const sp<DrmManagerClient::OnInfoListener>& infoListener) {
39     return mDrmManagerClientImpl->setOnInfoListener(mUniqueId, infoListener);
40 }
41 
getConstraints(const String8 * path,const int action)42 DrmConstraints* DrmManagerClient::getConstraints(const String8* path, const int action) {
43     return mDrmManagerClientImpl->getConstraints(mUniqueId, path, action);
44 }
45 
getMetadata(const String8 * path)46 DrmMetadata* DrmManagerClient::getMetadata(const String8* path) {
47     return mDrmManagerClientImpl->getMetadata(mUniqueId, path);
48 }
49 
canHandle(const String8 & path,const String8 & mimeType)50 bool DrmManagerClient::canHandle(const String8& path, const String8& mimeType) {
51     return mDrmManagerClientImpl->canHandle(mUniqueId, path, mimeType);
52 }
53 
processDrmInfo(const DrmInfo * drmInfo)54 DrmInfoStatus* DrmManagerClient::processDrmInfo(const DrmInfo* drmInfo) {
55     return mDrmManagerClientImpl->processDrmInfo(mUniqueId, drmInfo);
56 }
57 
acquireDrmInfo(const DrmInfoRequest * drmInfoRequest)58 DrmInfo* DrmManagerClient::acquireDrmInfo(const DrmInfoRequest* drmInfoRequest) {
59     return mDrmManagerClientImpl->acquireDrmInfo(mUniqueId, drmInfoRequest);
60 }
61 
saveRights(const DrmRights & drmRights,const String8 & rightsPath,const String8 & contentPath)62 status_t DrmManagerClient::saveRights(
63         const DrmRights& drmRights, const String8& rightsPath, const String8& contentPath) {
64     return mDrmManagerClientImpl->saveRights(mUniqueId, drmRights, rightsPath, contentPath);
65 }
66 
getOriginalMimeType(const String8 & path,int fd)67 String8 DrmManagerClient::getOriginalMimeType(const String8& path, int fd) {
68     return mDrmManagerClientImpl->getOriginalMimeType(mUniqueId, path, fd);
69 }
70 
getDrmObjectType(const String8 & path,const String8 & mimeType)71 int DrmManagerClient::getDrmObjectType(const String8& path, const String8& mimeType) {
72     return mDrmManagerClientImpl->getDrmObjectType( mUniqueId, path, mimeType);
73 }
74 
checkRightsStatus(const String8 & path,int action)75 int DrmManagerClient::checkRightsStatus(const String8& path, int action) {
76     return mDrmManagerClientImpl->checkRightsStatus(mUniqueId, path, action);
77 }
78 
consumeRights(sp<DecryptHandle> & decryptHandle,int action,bool reserve)79 status_t DrmManagerClient::consumeRights(
80             sp<DecryptHandle> &decryptHandle, int action, bool reserve) {
81     return mDrmManagerClientImpl->consumeRights(mUniqueId, decryptHandle, action, reserve);
82 }
83 
setPlaybackStatus(sp<DecryptHandle> & decryptHandle,int playbackStatus,int64_t position)84 status_t DrmManagerClient::setPlaybackStatus(
85             sp<DecryptHandle> &decryptHandle, int playbackStatus, int64_t position) {
86     return mDrmManagerClientImpl
87             ->setPlaybackStatus(mUniqueId, decryptHandle, playbackStatus, position);
88 }
89 
validateAction(const String8 & path,int action,const ActionDescription & description)90 bool DrmManagerClient::validateAction(
91             const String8& path, int action, const ActionDescription& description) {
92     return mDrmManagerClientImpl->validateAction(mUniqueId, path, action, description);
93 }
94 
removeRights(const String8 & path)95 status_t DrmManagerClient::removeRights(const String8& path) {
96     return mDrmManagerClientImpl->removeRights(mUniqueId, path);
97 }
98 
removeAllRights()99 status_t DrmManagerClient::removeAllRights() {
100     return mDrmManagerClientImpl->removeAllRights(mUniqueId);
101 }
102 
openConvertSession(const String8 & mimeType)103 int DrmManagerClient::openConvertSession(const String8& mimeType) {
104     return mDrmManagerClientImpl->openConvertSession(mUniqueId, mimeType);
105 }
106 
convertData(int convertId,const DrmBuffer * inputData)107 DrmConvertedStatus* DrmManagerClient::convertData(int convertId, const DrmBuffer* inputData) {
108     return mDrmManagerClientImpl->convertData(mUniqueId, convertId, inputData);
109 }
110 
closeConvertSession(int convertId)111 DrmConvertedStatus* DrmManagerClient::closeConvertSession(int convertId) {
112     return mDrmManagerClientImpl->closeConvertSession(mUniqueId, convertId);
113 }
114 
getAllSupportInfo(int * length,DrmSupportInfo ** drmSupportInfoArray)115 status_t DrmManagerClient::getAllSupportInfo(int* length, DrmSupportInfo** drmSupportInfoArray) {
116     return mDrmManagerClientImpl->getAllSupportInfo(mUniqueId, length, drmSupportInfoArray);
117 }
118 
openDecryptSession(int fd,off64_t offset,off64_t length,const char * mime)119 sp<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 
openDecryptSession(const char * uri,const char * mime)126 sp<DecryptHandle> DrmManagerClient::openDecryptSession(
127         const char* uri, const char* mime) {
128 
129     return mDrmManagerClientImpl->openDecryptSession(
130                     mUniqueId, uri, mime);
131 }
132 
openDecryptSession(const DrmBuffer & buf,const String8 & mimeType)133 sp<DecryptHandle> DrmManagerClient::openDecryptSession(
134             const DrmBuffer& buf, const String8& mimeType) {
135     return mDrmManagerClientImpl->openDecryptSession(mUniqueId, buf, mimeType);
136 }
137 
closeDecryptSession(sp<DecryptHandle> & decryptHandle)138 status_t DrmManagerClient::closeDecryptSession(sp<DecryptHandle> &decryptHandle) {
139     return mDrmManagerClientImpl->closeDecryptSession(mUniqueId, decryptHandle);
140 }
141 
initializeDecryptUnit(sp<DecryptHandle> & decryptHandle,int decryptUnitId,const DrmBuffer * headerInfo)142 status_t DrmManagerClient::initializeDecryptUnit(
143             sp<DecryptHandle> &decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo) {
144     return mDrmManagerClientImpl->initializeDecryptUnit(
145             mUniqueId, decryptHandle, decryptUnitId, headerInfo);
146 }
147 
decrypt(sp<DecryptHandle> & decryptHandle,int decryptUnitId,const DrmBuffer * encBuffer,DrmBuffer ** decBuffer,DrmBuffer * IV)148 status_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 
finalizeDecryptUnit(sp<DecryptHandle> & decryptHandle,int decryptUnitId)155 status_t DrmManagerClient::finalizeDecryptUnit(
156             sp<DecryptHandle> &decryptHandle, int decryptUnitId) {
157     return mDrmManagerClientImpl->finalizeDecryptUnit(mUniqueId,
158             decryptHandle, decryptUnitId);
159 }
160 
pread(sp<DecryptHandle> & decryptHandle,void * buffer,ssize_t numBytes,off64_t offset)161 ssize_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