blob: 843dddb8aa1820e7626c6b3e3bb1fdabfe4f2d81 [file] [log] [blame]
aimitakeshid074e302010-07-29 10:12:27 +09001/*
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
Takeshi Aimidc549d62010-09-20 23:40:41 +090017//#define LOG_NDEBUG 0
aimitakeshid074e302010-07-29 10:12:27 +090018#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
Takeshi Aimidc549d62010-09-20 23:40:41 +090032#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"
aimitakeshid074e302010-07-29 10:12:27 +090035
36void DrmManagerService::instantiate() {
37 LOGV("instantiate");
38
Takeshi Aimidc549d62010-09-20 23:40:41 +090039 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 }
aimitakeshid074e302010-07-29 10:12:27 +090049 }
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
Takeshi Aimidc549d62010-09-20 23:40:41 +090063int DrmManagerService::addUniqueId(int uniqueId) {
64 return mDrmManager->addUniqueId(uniqueId);
65}
66
67void DrmManagerService::removeUniqueId(int uniqueId) {
68 mDrmManager->removeUniqueId(uniqueId);
69}
70
aimitakeshid074e302010-07-29 10:12:27 +090071status_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
Takeshi Aimidc549d62010-09-20 23:40:41 +0900119status_t DrmManagerService::saveRights(
aimitakeshid074e302010-07-29 10:12:27 +0900120 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
Takeshi Aimidc549d62010-09-20 23:40:41 +0900143status_t DrmManagerService::consumeRights(
aimitakeshid074e302010-07-29 10:12:27 +0900144 int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) {
145 LOGV("Entering consumeRights");
Takeshi Aimidc549d62010-09-20 23:40:41 +0900146 return mDrmManager->consumeRights(uniqueId, decryptHandle, action, reserve);
aimitakeshid074e302010-07-29 10:12:27 +0900147}
148
Takeshi Aimidc549d62010-09-20 23:40:41 +0900149status_t DrmManagerService::setPlaybackStatus(
aimitakeshid074e302010-07-29 10:12:27 +0900150 int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position) {
151 LOGV("Entering setPlaybackStatus");
Takeshi Aimidc549d62010-09-20 23:40:41 +0900152 return mDrmManager->setPlaybackStatus(uniqueId, decryptHandle, playbackStatus, position);
aimitakeshid074e302010-07-29 10:12:27 +0900153}
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
Takeshi Aimidc549d62010-09-20 23:40:41 +0900162status_t DrmManagerService::removeRights(int uniqueId, const String8& path) {
aimitakeshid074e302010-07-29 10:12:27 +0900163 LOGV("Entering removeRights");
Takeshi Aimidc549d62010-09-20 23:40:41 +0900164 return mDrmManager->removeRights(uniqueId, path);
aimitakeshid074e302010-07-29 10:12:27 +0900165}
166
Takeshi Aimidc549d62010-09-20 23:40:41 +0900167status_t DrmManagerService::removeAllRights(int uniqueId) {
aimitakeshid074e302010-07-29 10:12:27 +0900168 LOGV("Entering removeAllRights");
Takeshi Aimidc549d62010-09-20 23:40:41 +0900169 return mDrmManager->removeAllRights(uniqueId);
aimitakeshid074e302010-07-29 10:12:27 +0900170}
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
Takeshi Aimidc549d62010-09-20 23:40:41 +0900200status_t DrmManagerService::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) {
aimitakeshid074e302010-07-29 10:12:27 +0900201 LOGV("Entering closeDecryptSession");
Takeshi Aimidc549d62010-09-20 23:40:41 +0900202 return mDrmManager->closeDecryptSession(uniqueId, decryptHandle);
aimitakeshid074e302010-07-29 10:12:27 +0900203}
204
Takeshi Aimidc549d62010-09-20 23:40:41 +0900205status_t DrmManagerService::initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle,
aimitakeshid074e302010-07-29 10:12:27 +0900206 int decryptUnitId, const DrmBuffer* headerInfo) {
207 LOGV("Entering initializeDecryptUnit");
Takeshi Aimidc549d62010-09-20 23:40:41 +0900208 return mDrmManager->initializeDecryptUnit(uniqueId,decryptHandle, decryptUnitId, headerInfo);
aimitakeshid074e302010-07-29 10:12:27 +0900209}
210
211status_t DrmManagerService::decrypt(
Takeshi Aimidc549d62010-09-20 23:40:41 +0900212 int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId,
213 const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) {
aimitakeshid074e302010-07-29 10:12:27 +0900214 LOGV("Entering decrypt");
Takeshi Aimidc549d62010-09-20 23:40:41 +0900215 return mDrmManager->decrypt(uniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer, IV);
aimitakeshid074e302010-07-29 10:12:27 +0900216}
217
Takeshi Aimidc549d62010-09-20 23:40:41 +0900218status_t DrmManagerService::finalizeDecryptUnit(
aimitakeshid074e302010-07-29 10:12:27 +0900219 int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) {
220 LOGV("Entering finalizeDecryptUnit");
Takeshi Aimidc549d62010-09-20 23:40:41 +0900221 return mDrmManager->finalizeDecryptUnit(uniqueId, decryptHandle, decryptUnitId);
aimitakeshid074e302010-07-29 10:12:27 +0900222}
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