blob: 0901a44f01299b29dabe529404028cfec248651a [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
Takeshi Aimidc9186562010-11-16 13:56:11 +090021#include <private/android_filesystem_config.h>
22
aimitakeshid074e302010-07-29 10:12:27 +090023#include <errno.h>
24#include <utils/threads.h>
25#include <binder/IServiceManager.h>
Takeshi Aimidc9186562010-11-16 13:56:11 +090026#include <binder/IPCThreadState.h>
aimitakeshid074e302010-07-29 10:12:27 +090027#include <sys/stat.h>
28#include "DrmManagerService.h"
29#include "DrmManager.h"
30
31using namespace android;
32
Takeshi Aimidc9186562010-11-16 13:56:11 +090033static Vector<uid_t> trustedUids;
34
35static bool isProtectedCallAllowed() {
36 // TODO
37 // Following implementation is just for reference.
38 // Each OEM manufacturer should implement/replace with their own solutions.
39 bool result = false;
40
41 IPCThreadState* ipcState = IPCThreadState::self();
42 uid_t uid = ipcState->getCallingUid();
43
44 for (unsigned int i = 0; i < trustedUids.size(); ++i) {
45 if (trustedUids[i] == uid) {
46 result = true;
47 break;
48 }
49 }
50 return result;
51}
52
aimitakeshid074e302010-07-29 10:12:27 +090053void DrmManagerService::instantiate() {
54 LOGV("instantiate");
Takeshi Aimic7b3ccc2010-10-08 23:05:49 +090055 defaultServiceManager()->addService(String16("drm.drmManager"), new DrmManagerService());
Takeshi Aimidc9186562010-11-16 13:56:11 +090056
57 if (0 >= trustedUids.size()) {
58 // TODO
59 // Following implementation is just for reference.
60 // Each OEM manufacturer should implement/replace with their own solutions.
61
62 // Add trusted uids here
63 trustedUids.push(AID_MEDIA);
64 }
aimitakeshid074e302010-07-29 10:12:27 +090065}
66
Takeshi Aimic7b3ccc2010-10-08 23:05:49 +090067DrmManagerService::DrmManagerService() :
68 mDrmManager(NULL) {
aimitakeshid074e302010-07-29 10:12:27 +090069 LOGV("created");
aimitakeshid074e302010-07-29 10:12:27 +090070 mDrmManager = new DrmManager();
Takeshi Aimic7b3ccc2010-10-08 23:05:49 +090071 mDrmManager->loadPlugIns();
aimitakeshid074e302010-07-29 10:12:27 +090072}
73
74DrmManagerService::~DrmManagerService() {
75 LOGV("Destroyed");
Takeshi Aimic7b3ccc2010-10-08 23:05:49 +090076 mDrmManager->unloadPlugIns();
aimitakeshid074e302010-07-29 10:12:27 +090077 delete mDrmManager; mDrmManager = NULL;
78}
79
Takeshi Aimidc549d62010-09-20 23:40:41 +090080int DrmManagerService::addUniqueId(int uniqueId) {
81 return mDrmManager->addUniqueId(uniqueId);
82}
83
84void DrmManagerService::removeUniqueId(int uniqueId) {
85 mDrmManager->removeUniqueId(uniqueId);
86}
87
Takeshi Aimic7b3ccc2010-10-08 23:05:49 +090088void DrmManagerService::addClient(int uniqueId) {
89 mDrmManager->addClient(uniqueId);
aimitakeshid074e302010-07-29 10:12:27 +090090}
91
Takeshi Aimic7b3ccc2010-10-08 23:05:49 +090092void DrmManagerService::removeClient(int uniqueId) {
93 mDrmManager->removeClient(uniqueId);
aimitakeshid074e302010-07-29 10:12:27 +090094}
95
96status_t DrmManagerService::setDrmServiceListener(
97 int uniqueId, const sp<IDrmServiceListener>& drmServiceListener) {
98 LOGV("Entering setDrmServiceListener");
99 mDrmManager->setDrmServiceListener(uniqueId, drmServiceListener);
100 return DRM_NO_ERROR;
101}
102
aimitakeshid074e302010-07-29 10:12:27 +0900103status_t DrmManagerService::installDrmEngine(int uniqueId, const String8& drmEngineFile) {
104 LOGV("Entering installDrmEngine");
105 return mDrmManager->installDrmEngine(uniqueId, drmEngineFile);
106}
107
108DrmConstraints* DrmManagerService::getConstraints(
109 int uniqueId, const String8* path, const int action) {
110 LOGV("Entering getConstraints from content");
111 return mDrmManager->getConstraints(uniqueId, path, action);
112}
113
Takeshi Aimidc9186562010-11-16 13:56:11 +0900114DrmMetadata* DrmManagerService::getMetadata(int uniqueId, const String8* path) {
115 LOGV("Entering getMetadata from content");
116 return mDrmManager->getMetadata(uniqueId, path);
117}
118
aimitakeshid074e302010-07-29 10:12:27 +0900119bool DrmManagerService::canHandle(int uniqueId, const String8& path, const String8& mimeType) {
120 LOGV("Entering canHandle");
121 return mDrmManager->canHandle(uniqueId, path, mimeType);
122}
123
124DrmInfoStatus* DrmManagerService::processDrmInfo(int uniqueId, const DrmInfo* drmInfo) {
125 LOGV("Entering processDrmInfo");
126 return mDrmManager->processDrmInfo(uniqueId, drmInfo);
127}
128
129DrmInfo* DrmManagerService::acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest) {
130 LOGV("Entering acquireDrmInfo");
131 return mDrmManager->acquireDrmInfo(uniqueId, drmInfoRequest);
132}
133
Takeshi Aimidc549d62010-09-20 23:40:41 +0900134status_t DrmManagerService::saveRights(
aimitakeshid074e302010-07-29 10:12:27 +0900135 int uniqueId, const DrmRights& drmRights,
136 const String8& rightsPath, const String8& contentPath) {
137 LOGV("Entering saveRights");
138 return mDrmManager->saveRights(uniqueId, drmRights, rightsPath, contentPath);
139}
140
141String8 DrmManagerService::getOriginalMimeType(int uniqueId, const String8& path) {
142 LOGV("Entering getOriginalMimeType");
143 return mDrmManager->getOriginalMimeType(uniqueId, path);
144}
145
146int DrmManagerService::getDrmObjectType(
147 int uniqueId, const String8& path, const String8& mimeType) {
148 LOGV("Entering getDrmObjectType");
149 return mDrmManager->getDrmObjectType(uniqueId, path, mimeType);
150}
151
152int DrmManagerService::checkRightsStatus(
153 int uniqueId, const String8& path, int action) {
154 LOGV("Entering checkRightsStatus");
155 return mDrmManager->checkRightsStatus(uniqueId, path, action);
156}
157
Takeshi Aimidc549d62010-09-20 23:40:41 +0900158status_t DrmManagerService::consumeRights(
aimitakeshid074e302010-07-29 10:12:27 +0900159 int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) {
160 LOGV("Entering consumeRights");
Takeshi Aimidc549d62010-09-20 23:40:41 +0900161 return mDrmManager->consumeRights(uniqueId, decryptHandle, action, reserve);
aimitakeshid074e302010-07-29 10:12:27 +0900162}
163
Takeshi Aimidc549d62010-09-20 23:40:41 +0900164status_t DrmManagerService::setPlaybackStatus(
Gloria Wang5fc3edb2010-11-19 15:19:36 -0800165 int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int64_t position) {
aimitakeshid074e302010-07-29 10:12:27 +0900166 LOGV("Entering setPlaybackStatus");
Takeshi Aimidc549d62010-09-20 23:40:41 +0900167 return mDrmManager->setPlaybackStatus(uniqueId, decryptHandle, playbackStatus, position);
aimitakeshid074e302010-07-29 10:12:27 +0900168}
169
170bool DrmManagerService::validateAction(
171 int uniqueId, const String8& path,
172 int action, const ActionDescription& description) {
173 LOGV("Entering validateAction");
174 return mDrmManager->validateAction(uniqueId, path, action, description);
175}
176
Takeshi Aimidc549d62010-09-20 23:40:41 +0900177status_t DrmManagerService::removeRights(int uniqueId, const String8& path) {
aimitakeshid074e302010-07-29 10:12:27 +0900178 LOGV("Entering removeRights");
Takeshi Aimidc549d62010-09-20 23:40:41 +0900179 return mDrmManager->removeRights(uniqueId, path);
aimitakeshid074e302010-07-29 10:12:27 +0900180}
181
Takeshi Aimidc549d62010-09-20 23:40:41 +0900182status_t DrmManagerService::removeAllRights(int uniqueId) {
aimitakeshid074e302010-07-29 10:12:27 +0900183 LOGV("Entering removeAllRights");
Takeshi Aimidc549d62010-09-20 23:40:41 +0900184 return mDrmManager->removeAllRights(uniqueId);
aimitakeshid074e302010-07-29 10:12:27 +0900185}
186
187int DrmManagerService::openConvertSession(int uniqueId, const String8& mimeType) {
188 LOGV("Entering openConvertSession");
189 return mDrmManager->openConvertSession(uniqueId, mimeType);
190}
191
192DrmConvertedStatus* DrmManagerService::convertData(
193 int uniqueId, int convertId, const DrmBuffer* inputData) {
194 LOGV("Entering convertData");
195 return mDrmManager->convertData(uniqueId, convertId, inputData);
196}
197
198DrmConvertedStatus* DrmManagerService::closeConvertSession(int uniqueId, int convertId) {
199 LOGV("Entering closeConvertSession");
200 return mDrmManager->closeConvertSession(uniqueId, convertId);
201}
202
203status_t DrmManagerService::getAllSupportInfo(
204 int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray) {
205 LOGV("Entering getAllSupportInfo");
206 return mDrmManager->getAllSupportInfo(uniqueId, length, drmSupportInfoArray);
207}
208
209DecryptHandle* DrmManagerService::openDecryptSession(
Gloria Wang5fc3edb2010-11-19 15:19:36 -0800210 int uniqueId, int fd, off64_t offset, off64_t length) {
aimitakeshid074e302010-07-29 10:12:27 +0900211 LOGV("Entering DrmManagerService::openDecryptSession");
Takeshi Aimidc9186562010-11-16 13:56:11 +0900212 if (isProtectedCallAllowed()) {
213 return mDrmManager->openDecryptSession(uniqueId, fd, offset, length);
214 }
215
216 return NULL;
aimitakeshid074e302010-07-29 10:12:27 +0900217}
218
Takeshi Aimic7b3ccc2010-10-08 23:05:49 +0900219DecryptHandle* DrmManagerService::openDecryptSession(
220 int uniqueId, const char* uri) {
221 LOGV("Entering DrmManagerService::openDecryptSession with uri");
Takeshi Aimidc9186562010-11-16 13:56:11 +0900222 if (isProtectedCallAllowed()) {
223 return mDrmManager->openDecryptSession(uniqueId, uri);
224 }
225
226 return NULL;
Takeshi Aimic7b3ccc2010-10-08 23:05:49 +0900227}
228
Takeshi Aimidc549d62010-09-20 23:40:41 +0900229status_t DrmManagerService::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) {
aimitakeshid074e302010-07-29 10:12:27 +0900230 LOGV("Entering closeDecryptSession");
Takeshi Aimidc549d62010-09-20 23:40:41 +0900231 return mDrmManager->closeDecryptSession(uniqueId, decryptHandle);
aimitakeshid074e302010-07-29 10:12:27 +0900232}
233
Takeshi Aimidc549d62010-09-20 23:40:41 +0900234status_t DrmManagerService::initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle,
aimitakeshid074e302010-07-29 10:12:27 +0900235 int decryptUnitId, const DrmBuffer* headerInfo) {
236 LOGV("Entering initializeDecryptUnit");
Takeshi Aimidc549d62010-09-20 23:40:41 +0900237 return mDrmManager->initializeDecryptUnit(uniqueId,decryptHandle, decryptUnitId, headerInfo);
aimitakeshid074e302010-07-29 10:12:27 +0900238}
239
240status_t DrmManagerService::decrypt(
Takeshi Aimidc549d62010-09-20 23:40:41 +0900241 int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId,
242 const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) {
aimitakeshid074e302010-07-29 10:12:27 +0900243 LOGV("Entering decrypt");
Takeshi Aimidc549d62010-09-20 23:40:41 +0900244 return mDrmManager->decrypt(uniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer, IV);
aimitakeshid074e302010-07-29 10:12:27 +0900245}
246
Takeshi Aimidc549d62010-09-20 23:40:41 +0900247status_t DrmManagerService::finalizeDecryptUnit(
aimitakeshid074e302010-07-29 10:12:27 +0900248 int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) {
249 LOGV("Entering finalizeDecryptUnit");
Takeshi Aimidc549d62010-09-20 23:40:41 +0900250 return mDrmManager->finalizeDecryptUnit(uniqueId, decryptHandle, decryptUnitId);
aimitakeshid074e302010-07-29 10:12:27 +0900251}
252
253ssize_t DrmManagerService::pread(int uniqueId, DecryptHandle* decryptHandle,
Gloria Wang5fc3edb2010-11-19 15:19:36 -0800254 void* buffer, ssize_t numBytes, off64_t offset) {
aimitakeshid074e302010-07-29 10:12:27 +0900255 LOGV("Entering pread");
256 return mDrmManager->pread(uniqueId, decryptHandle, buffer, numBytes, offset);
257}
258