DrmManagerService.cpp revision 2272ee27d9022d173b6eab45c409b3c3f57f30ec
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//#define LOG_NDEBUG 0
18#define LOG_TAG "DrmManagerService(Native)"
19#include <utils/Log.h>
20
21#include <errno.h>
22#include <utils/threads.h>
23#include <binder/IServiceManager.h>
24#include <sys/stat.h>
25#include "DrmManagerService.h"
26#include "DrmManager.h"
27
28using namespace android;
29
30#define SUCCESS 0
31#define DRM_DIRECTORY_PERMISSION 0700
32#define DRM_PLUGINS_ROOT "/data/drm/plugins"
33#define DRM_PLUGINS_NATIVE "/data/drm/plugins/native"
34#define DRM_PLUGINS_NATIVE_DATABASES "/data/drm/plugins/native/databases"
35
36void DrmManagerService::instantiate() {
37    LOGV("instantiate");
38
39    int res = mkdir(DRM_PLUGINS_ROOT, DRM_DIRECTORY_PERMISSION);
40    if (SUCCESS == res || EEXIST == errno) {
41        res = mkdir(DRM_PLUGINS_NATIVE, DRM_DIRECTORY_PERMISSION);
42        if (SUCCESS == res || EEXIST == errno) {
43            res = mkdir(DRM_PLUGINS_NATIVE_DATABASES, DRM_DIRECTORY_PERMISSION);
44            if (SUCCESS == res || EEXIST == errno) {
45                defaultServiceManager()
46                    ->addService(String16("drm.drmManager"), new DrmManagerService());
47            }
48        }
49    }
50}
51
52DrmManagerService::DrmManagerService() {
53    LOGV("created");
54    mDrmManager = NULL;
55    mDrmManager = new DrmManager();
56}
57
58DrmManagerService::~DrmManagerService() {
59    LOGV("Destroyed");
60    delete mDrmManager; mDrmManager = NULL;
61}
62
63int DrmManagerService::addUniqueId(int uniqueId) {
64    return mDrmManager->addUniqueId(uniqueId);
65}
66
67void DrmManagerService::removeUniqueId(int uniqueId) {
68    mDrmManager->removeUniqueId(uniqueId);
69}
70
71status_t DrmManagerService::loadPlugIns(int uniqueId) {
72    LOGV("Entering load plugins");
73    return mDrmManager->loadPlugIns(uniqueId);
74}
75
76status_t DrmManagerService::loadPlugIns(int uniqueId, const String8& plugInDirPath) {
77    LOGV("Entering load plugins from path");
78    return mDrmManager->loadPlugIns(uniqueId, plugInDirPath);
79}
80
81status_t DrmManagerService::setDrmServiceListener(
82            int uniqueId, const sp<IDrmServiceListener>& drmServiceListener) {
83    LOGV("Entering setDrmServiceListener");
84    mDrmManager->setDrmServiceListener(uniqueId, drmServiceListener);
85    return DRM_NO_ERROR;
86}
87
88status_t DrmManagerService::unloadPlugIns(int uniqueId) {
89    LOGV("Entering unload plugins");
90    return mDrmManager->unloadPlugIns(uniqueId);
91}
92
93status_t DrmManagerService::installDrmEngine(int uniqueId, const String8& drmEngineFile) {
94    LOGV("Entering installDrmEngine");
95    return mDrmManager->installDrmEngine(uniqueId, drmEngineFile);
96}
97
98DrmConstraints* DrmManagerService::getConstraints(
99            int uniqueId, const String8* path, const int action) {
100    LOGV("Entering getConstraints from content");
101    return mDrmManager->getConstraints(uniqueId, path, action);
102}
103
104bool DrmManagerService::canHandle(int uniqueId, const String8& path, const String8& mimeType) {
105    LOGV("Entering canHandle");
106    return mDrmManager->canHandle(uniqueId, path, mimeType);
107}
108
109DrmInfoStatus* DrmManagerService::processDrmInfo(int uniqueId, const DrmInfo* drmInfo) {
110    LOGV("Entering processDrmInfo");
111    return mDrmManager->processDrmInfo(uniqueId, drmInfo);
112}
113
114DrmInfo* DrmManagerService::acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest) {
115    LOGV("Entering acquireDrmInfo");
116    return mDrmManager->acquireDrmInfo(uniqueId, drmInfoRequest);
117}
118
119status_t DrmManagerService::saveRights(
120            int uniqueId, const DrmRights& drmRights,
121            const String8& rightsPath, const String8& contentPath) {
122    LOGV("Entering saveRights");
123    return mDrmManager->saveRights(uniqueId, drmRights, rightsPath, contentPath);
124}
125
126String8 DrmManagerService::getOriginalMimeType(int uniqueId, const String8& path) {
127    LOGV("Entering getOriginalMimeType");
128    return mDrmManager->getOriginalMimeType(uniqueId, path);
129}
130
131int DrmManagerService::getDrmObjectType(
132           int uniqueId, const String8& path, const String8& mimeType) {
133    LOGV("Entering getDrmObjectType");
134    return mDrmManager->getDrmObjectType(uniqueId, path, mimeType);
135}
136
137int DrmManagerService::checkRightsStatus(
138            int uniqueId, const String8& path, int action) {
139    LOGV("Entering checkRightsStatus");
140    return mDrmManager->checkRightsStatus(uniqueId, path, action);
141}
142
143status_t DrmManagerService::consumeRights(
144            int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) {
145    LOGV("Entering consumeRights");
146    return mDrmManager->consumeRights(uniqueId, decryptHandle, action, reserve);
147}
148
149status_t DrmManagerService::setPlaybackStatus(
150            int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position) {
151    LOGV("Entering setPlaybackStatus");
152    return mDrmManager->setPlaybackStatus(uniqueId, decryptHandle, playbackStatus, position);
153}
154
155bool DrmManagerService::validateAction(
156            int uniqueId, const String8& path,
157            int action, const ActionDescription& description) {
158    LOGV("Entering validateAction");
159    return mDrmManager->validateAction(uniqueId, path, action, description);
160}
161
162status_t DrmManagerService::removeRights(int uniqueId, const String8& path) {
163    LOGV("Entering removeRights");
164    return mDrmManager->removeRights(uniqueId, path);
165}
166
167status_t DrmManagerService::removeAllRights(int uniqueId) {
168    LOGV("Entering removeAllRights");
169    return mDrmManager->removeAllRights(uniqueId);
170}
171
172int DrmManagerService::openConvertSession(int uniqueId, const String8& mimeType) {
173    LOGV("Entering openConvertSession");
174    return mDrmManager->openConvertSession(uniqueId, mimeType);
175}
176
177DrmConvertedStatus* DrmManagerService::convertData(
178            int uniqueId, int convertId, const DrmBuffer* inputData) {
179    LOGV("Entering convertData");
180    return mDrmManager->convertData(uniqueId, convertId, inputData);
181}
182
183DrmConvertedStatus* DrmManagerService::closeConvertSession(int uniqueId, int convertId) {
184    LOGV("Entering closeConvertSession");
185    return mDrmManager->closeConvertSession(uniqueId, convertId);
186}
187
188status_t DrmManagerService::getAllSupportInfo(
189            int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray) {
190    LOGV("Entering getAllSupportInfo");
191    return mDrmManager->getAllSupportInfo(uniqueId, length, drmSupportInfoArray);
192}
193
194DecryptHandle* DrmManagerService::openDecryptSession(
195            int uniqueId, int fd, int offset, int length) {
196    LOGV("Entering DrmManagerService::openDecryptSession");
197    return mDrmManager->openDecryptSession(uniqueId, fd, offset, length);
198}
199
200status_t DrmManagerService::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) {
201    LOGV("Entering closeDecryptSession");
202    return mDrmManager->closeDecryptSession(uniqueId, decryptHandle);
203}
204
205status_t DrmManagerService::initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle,
206            int decryptUnitId, const DrmBuffer* headerInfo) {
207    LOGV("Entering initializeDecryptUnit");
208    return mDrmManager->initializeDecryptUnit(uniqueId,decryptHandle, decryptUnitId, headerInfo);
209}
210
211status_t DrmManagerService::decrypt(
212            int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId,
213            const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) {
214    LOGV("Entering decrypt");
215    return mDrmManager->decrypt(uniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer, IV);
216}
217
218status_t DrmManagerService::finalizeDecryptUnit(
219            int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) {
220    LOGV("Entering finalizeDecryptUnit");
221    return mDrmManager->finalizeDecryptUnit(uniqueId, decryptHandle, decryptUnitId);
222}
223
224ssize_t DrmManagerService::pread(int uniqueId, DecryptHandle* decryptHandle,
225            void* buffer, ssize_t numBytes, off_t offset) {
226    LOGV("Entering pread");
227    return mDrmManager->pread(uniqueId, decryptHandle, buffer, numBytes, offset);
228}
229
230