blob: 583669e980a0aed68515ffbbd6cebde3ed4f2b6f [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>
James Donged732462011-03-14 17:01:38 -070022#include <media/MemoryLeakTrackUtil.h>
Takeshi Aimidc9186562010-11-16 13:56:11 +090023
aimitakeshid074e302010-07-29 10:12:27 +090024#include <errno.h>
25#include <utils/threads.h>
26#include <binder/IServiceManager.h>
Takeshi Aimidc9186562010-11-16 13:56:11 +090027#include <binder/IPCThreadState.h>
aimitakeshid074e302010-07-29 10:12:27 +090028#include <sys/stat.h>
29#include "DrmManagerService.h"
30#include "DrmManager.h"
31
32using namespace android;
33
Takeshi Aimidc9186562010-11-16 13:56:11 +090034static Vector<uid_t> trustedUids;
35
36static bool isProtectedCallAllowed() {
37 // TODO
38 // Following implementation is just for reference.
39 // Each OEM manufacturer should implement/replace with their own solutions.
40 bool result = false;
41
42 IPCThreadState* ipcState = IPCThreadState::self();
43 uid_t uid = ipcState->getCallingUid();
44
45 for (unsigned int i = 0; i < trustedUids.size(); ++i) {
46 if (trustedUids[i] == uid) {
47 result = true;
48 break;
49 }
50 }
51 return result;
52}
53
aimitakeshid074e302010-07-29 10:12:27 +090054void DrmManagerService::instantiate() {
55 LOGV("instantiate");
Takeshi Aimic7b3ccc2010-10-08 23:05:49 +090056 defaultServiceManager()->addService(String16("drm.drmManager"), new DrmManagerService());
Takeshi Aimidc9186562010-11-16 13:56:11 +090057
58 if (0 >= trustedUids.size()) {
59 // TODO
60 // Following implementation is just for reference.
61 // Each OEM manufacturer should implement/replace with their own solutions.
62
63 // Add trusted uids here
64 trustedUids.push(AID_MEDIA);
65 }
aimitakeshid074e302010-07-29 10:12:27 +090066}
67
Takeshi Aimic7b3ccc2010-10-08 23:05:49 +090068DrmManagerService::DrmManagerService() :
69 mDrmManager(NULL) {
aimitakeshid074e302010-07-29 10:12:27 +090070 LOGV("created");
aimitakeshid074e302010-07-29 10:12:27 +090071 mDrmManager = new DrmManager();
Takeshi Aimic7b3ccc2010-10-08 23:05:49 +090072 mDrmManager->loadPlugIns();
aimitakeshid074e302010-07-29 10:12:27 +090073}
74
75DrmManagerService::~DrmManagerService() {
76 LOGV("Destroyed");
Takeshi Aimic7b3ccc2010-10-08 23:05:49 +090077 mDrmManager->unloadPlugIns();
aimitakeshid074e302010-07-29 10:12:27 +090078 delete mDrmManager; mDrmManager = NULL;
79}
80
Takeshi Aimidc549d62010-09-20 23:40:41 +090081int DrmManagerService::addUniqueId(int uniqueId) {
82 return mDrmManager->addUniqueId(uniqueId);
83}
84
85void DrmManagerService::removeUniqueId(int uniqueId) {
86 mDrmManager->removeUniqueId(uniqueId);
87}
88
Takeshi Aimic7b3ccc2010-10-08 23:05:49 +090089void DrmManagerService::addClient(int uniqueId) {
90 mDrmManager->addClient(uniqueId);
aimitakeshid074e302010-07-29 10:12:27 +090091}
92
Takeshi Aimic7b3ccc2010-10-08 23:05:49 +090093void DrmManagerService::removeClient(int uniqueId) {
94 mDrmManager->removeClient(uniqueId);
aimitakeshid074e302010-07-29 10:12:27 +090095}
96
97status_t DrmManagerService::setDrmServiceListener(
98 int uniqueId, const sp<IDrmServiceListener>& drmServiceListener) {
99 LOGV("Entering setDrmServiceListener");
100 mDrmManager->setDrmServiceListener(uniqueId, drmServiceListener);
101 return DRM_NO_ERROR;
102}
103
aimitakeshid074e302010-07-29 10:12:27 +0900104status_t DrmManagerService::installDrmEngine(int uniqueId, const String8& drmEngineFile) {
105 LOGV("Entering installDrmEngine");
106 return mDrmManager->installDrmEngine(uniqueId, drmEngineFile);
107}
108
109DrmConstraints* DrmManagerService::getConstraints(
110 int uniqueId, const String8* path, const int action) {
111 LOGV("Entering getConstraints from content");
112 return mDrmManager->getConstraints(uniqueId, path, action);
113}
114
Takeshi Aimidc9186562010-11-16 13:56:11 +0900115DrmMetadata* DrmManagerService::getMetadata(int uniqueId, const String8* path) {
116 LOGV("Entering getMetadata from content");
117 return mDrmManager->getMetadata(uniqueId, path);
118}
119
aimitakeshid074e302010-07-29 10:12:27 +0900120bool DrmManagerService::canHandle(int uniqueId, const String8& path, const String8& mimeType) {
121 LOGV("Entering canHandle");
122 return mDrmManager->canHandle(uniqueId, path, mimeType);
123}
124
125DrmInfoStatus* DrmManagerService::processDrmInfo(int uniqueId, const DrmInfo* drmInfo) {
126 LOGV("Entering processDrmInfo");
127 return mDrmManager->processDrmInfo(uniqueId, drmInfo);
128}
129
130DrmInfo* DrmManagerService::acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest) {
131 LOGV("Entering acquireDrmInfo");
132 return mDrmManager->acquireDrmInfo(uniqueId, drmInfoRequest);
133}
134
Takeshi Aimidc549d62010-09-20 23:40:41 +0900135status_t DrmManagerService::saveRights(
aimitakeshid074e302010-07-29 10:12:27 +0900136 int uniqueId, const DrmRights& drmRights,
137 const String8& rightsPath, const String8& contentPath) {
138 LOGV("Entering saveRights");
139 return mDrmManager->saveRights(uniqueId, drmRights, rightsPath, contentPath);
140}
141
142String8 DrmManagerService::getOriginalMimeType(int uniqueId, const String8& path) {
143 LOGV("Entering getOriginalMimeType");
144 return mDrmManager->getOriginalMimeType(uniqueId, path);
145}
146
147int DrmManagerService::getDrmObjectType(
148 int uniqueId, const String8& path, const String8& mimeType) {
149 LOGV("Entering getDrmObjectType");
150 return mDrmManager->getDrmObjectType(uniqueId, path, mimeType);
151}
152
153int DrmManagerService::checkRightsStatus(
154 int uniqueId, const String8& path, int action) {
155 LOGV("Entering checkRightsStatus");
156 return mDrmManager->checkRightsStatus(uniqueId, path, action);
157}
158
Takeshi Aimidc549d62010-09-20 23:40:41 +0900159status_t DrmManagerService::consumeRights(
aimitakeshid074e302010-07-29 10:12:27 +0900160 int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) {
161 LOGV("Entering consumeRights");
Takeshi Aimidc549d62010-09-20 23:40:41 +0900162 return mDrmManager->consumeRights(uniqueId, decryptHandle, action, reserve);
aimitakeshid074e302010-07-29 10:12:27 +0900163}
164
Takeshi Aimidc549d62010-09-20 23:40:41 +0900165status_t DrmManagerService::setPlaybackStatus(
Gloria Wang5fc3edb2010-11-19 15:19:36 -0800166 int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int64_t position) {
aimitakeshid074e302010-07-29 10:12:27 +0900167 LOGV("Entering setPlaybackStatus");
Takeshi Aimidc549d62010-09-20 23:40:41 +0900168 return mDrmManager->setPlaybackStatus(uniqueId, decryptHandle, playbackStatus, position);
aimitakeshid074e302010-07-29 10:12:27 +0900169}
170
171bool DrmManagerService::validateAction(
172 int uniqueId, const String8& path,
173 int action, const ActionDescription& description) {
174 LOGV("Entering validateAction");
175 return mDrmManager->validateAction(uniqueId, path, action, description);
176}
177
Takeshi Aimidc549d62010-09-20 23:40:41 +0900178status_t DrmManagerService::removeRights(int uniqueId, const String8& path) {
aimitakeshid074e302010-07-29 10:12:27 +0900179 LOGV("Entering removeRights");
Takeshi Aimidc549d62010-09-20 23:40:41 +0900180 return mDrmManager->removeRights(uniqueId, path);
aimitakeshid074e302010-07-29 10:12:27 +0900181}
182
Takeshi Aimidc549d62010-09-20 23:40:41 +0900183status_t DrmManagerService::removeAllRights(int uniqueId) {
aimitakeshid074e302010-07-29 10:12:27 +0900184 LOGV("Entering removeAllRights");
Takeshi Aimidc549d62010-09-20 23:40:41 +0900185 return mDrmManager->removeAllRights(uniqueId);
aimitakeshid074e302010-07-29 10:12:27 +0900186}
187
188int DrmManagerService::openConvertSession(int uniqueId, const String8& mimeType) {
189 LOGV("Entering openConvertSession");
190 return mDrmManager->openConvertSession(uniqueId, mimeType);
191}
192
193DrmConvertedStatus* DrmManagerService::convertData(
194 int uniqueId, int convertId, const DrmBuffer* inputData) {
195 LOGV("Entering convertData");
196 return mDrmManager->convertData(uniqueId, convertId, inputData);
197}
198
199DrmConvertedStatus* DrmManagerService::closeConvertSession(int uniqueId, int convertId) {
200 LOGV("Entering closeConvertSession");
201 return mDrmManager->closeConvertSession(uniqueId, convertId);
202}
203
204status_t DrmManagerService::getAllSupportInfo(
205 int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray) {
206 LOGV("Entering getAllSupportInfo");
207 return mDrmManager->getAllSupportInfo(uniqueId, length, drmSupportInfoArray);
208}
209
210DecryptHandle* DrmManagerService::openDecryptSession(
Gloria Wang5fc3edb2010-11-19 15:19:36 -0800211 int uniqueId, int fd, off64_t offset, off64_t length) {
aimitakeshid074e302010-07-29 10:12:27 +0900212 LOGV("Entering DrmManagerService::openDecryptSession");
Takeshi Aimidc9186562010-11-16 13:56:11 +0900213 if (isProtectedCallAllowed()) {
214 return mDrmManager->openDecryptSession(uniqueId, fd, offset, length);
215 }
216
217 return NULL;
aimitakeshid074e302010-07-29 10:12:27 +0900218}
219
Takeshi Aimic7b3ccc2010-10-08 23:05:49 +0900220DecryptHandle* DrmManagerService::openDecryptSession(
221 int uniqueId, const char* uri) {
222 LOGV("Entering DrmManagerService::openDecryptSession with uri");
Takeshi Aimidc9186562010-11-16 13:56:11 +0900223 if (isProtectedCallAllowed()) {
224 return mDrmManager->openDecryptSession(uniqueId, uri);
225 }
226
227 return NULL;
Takeshi Aimic7b3ccc2010-10-08 23:05:49 +0900228}
229
Takeshi Aimidc549d62010-09-20 23:40:41 +0900230status_t DrmManagerService::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) {
aimitakeshid074e302010-07-29 10:12:27 +0900231 LOGV("Entering closeDecryptSession");
Takeshi Aimidc549d62010-09-20 23:40:41 +0900232 return mDrmManager->closeDecryptSession(uniqueId, decryptHandle);
aimitakeshid074e302010-07-29 10:12:27 +0900233}
234
Takeshi Aimidc549d62010-09-20 23:40:41 +0900235status_t DrmManagerService::initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle,
aimitakeshid074e302010-07-29 10:12:27 +0900236 int decryptUnitId, const DrmBuffer* headerInfo) {
237 LOGV("Entering initializeDecryptUnit");
Takeshi Aimidc549d62010-09-20 23:40:41 +0900238 return mDrmManager->initializeDecryptUnit(uniqueId,decryptHandle, decryptUnitId, headerInfo);
aimitakeshid074e302010-07-29 10:12:27 +0900239}
240
241status_t DrmManagerService::decrypt(
Takeshi Aimidc549d62010-09-20 23:40:41 +0900242 int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId,
243 const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) {
aimitakeshid074e302010-07-29 10:12:27 +0900244 LOGV("Entering decrypt");
Takeshi Aimidc549d62010-09-20 23:40:41 +0900245 return mDrmManager->decrypt(uniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer, IV);
aimitakeshid074e302010-07-29 10:12:27 +0900246}
247
Takeshi Aimidc549d62010-09-20 23:40:41 +0900248status_t DrmManagerService::finalizeDecryptUnit(
aimitakeshid074e302010-07-29 10:12:27 +0900249 int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) {
250 LOGV("Entering finalizeDecryptUnit");
Takeshi Aimidc549d62010-09-20 23:40:41 +0900251 return mDrmManager->finalizeDecryptUnit(uniqueId, decryptHandle, decryptUnitId);
aimitakeshid074e302010-07-29 10:12:27 +0900252}
253
254ssize_t DrmManagerService::pread(int uniqueId, DecryptHandle* decryptHandle,
Gloria Wang5fc3edb2010-11-19 15:19:36 -0800255 void* buffer, ssize_t numBytes, off64_t offset) {
aimitakeshid074e302010-07-29 10:12:27 +0900256 LOGV("Entering pread");
257 return mDrmManager->pread(uniqueId, decryptHandle, buffer, numBytes, offset);
258}
259
James Donged732462011-03-14 17:01:38 -0700260status_t DrmManagerService::dump(int fd, const Vector<String16>& args)
261{
262 const size_t SIZE = 256;
263 char buffer[SIZE];
264 String8 result;
265 if (checkCallingPermission(String16("android.permission.DUMP")) == false) {
266 snprintf(buffer, SIZE, "Permission Denial: "
267 "can't dump DrmManagerService from pid=%d, uid=%d\n",
268 IPCThreadState::self()->getCallingPid(),
269 IPCThreadState::self()->getCallingUid());
270 result.append(buffer);
271 } else {
272#if DRM_MEMORY_LEAK_TRACK
273 bool dumpMem = false;
274 for (size_t i = 0; i < args.size(); i++) {
275 if (args[i] == String16("-m")) {
276 dumpMem = true;
277 }
278 }
279 if (dumpMem) {
280 dumpMemoryAddresses(fd);
281 }
282#endif
283 }
284 write(fd, result.string(), result.size());
285 return NO_ERROR;
286}
287