blob: 25a4e7b4ec0018cfd4a3bed6bd435c0beb4ca76f [file] [log] [blame]
aimitakeshi27ed8ad2010-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 Aimi2272ee22010-09-20 23:40:41 +090017//#define LOG_NDEBUG 0
aimitakeshi27ed8ad2010-07-29 10:12:27 +090018#define LOG_TAG "DrmManagerService(Native)"
19#include <utils/Log.h>
20
Takeshi Aimi34738462010-11-16 13:56:11 +090021#include <private/android_filesystem_config.h>
James Dong8635b7b2011-03-14 17:01:38 -070022#include <media/MemoryLeakTrackUtil.h>
Takeshi Aimi34738462010-11-16 13:56:11 +090023
aimitakeshi27ed8ad2010-07-29 10:12:27 +090024#include <errno.h>
25#include <utils/threads.h>
26#include <binder/IServiceManager.h>
Takeshi Aimi34738462010-11-16 13:56:11 +090027#include <binder/IPCThreadState.h>
aimitakeshi27ed8ad2010-07-29 10:12:27 +090028#include <sys/stat.h>
29#include "DrmManagerService.h"
30#include "DrmManager.h"
31
32using namespace android;
33
Takeshi Aimi34738462010-11-16 13:56:11 +090034static Vector<uid_t> trustedUids;
35
36static bool isProtectedCallAllowed() {
Andreas Huber16087352012-04-13 14:54:36 -070037 return true;
Takeshi Aimi34738462010-11-16 13:56:11 +090038}
39
aimitakeshi27ed8ad2010-07-29 10:12:27 +090040void DrmManagerService::instantiate() {
Steve Block3856b092011-10-20 11:56:00 +010041 ALOGV("instantiate");
Takeshi Aimie943f842010-10-08 23:05:49 +090042 defaultServiceManager()->addService(String16("drm.drmManager"), new DrmManagerService());
Takeshi Aimi34738462010-11-16 13:56:11 +090043
44 if (0 >= trustedUids.size()) {
45 // TODO
46 // Following implementation is just for reference.
47 // Each OEM manufacturer should implement/replace with their own solutions.
48
49 // Add trusted uids here
50 trustedUids.push(AID_MEDIA);
51 }
aimitakeshi27ed8ad2010-07-29 10:12:27 +090052}
53
Takeshi Aimie943f842010-10-08 23:05:49 +090054DrmManagerService::DrmManagerService() :
55 mDrmManager(NULL) {
Steve Block3856b092011-10-20 11:56:00 +010056 ALOGV("created");
aimitakeshi27ed8ad2010-07-29 10:12:27 +090057 mDrmManager = new DrmManager();
Takeshi Aimie943f842010-10-08 23:05:49 +090058 mDrmManager->loadPlugIns();
aimitakeshi27ed8ad2010-07-29 10:12:27 +090059}
60
61DrmManagerService::~DrmManagerService() {
Steve Block3856b092011-10-20 11:56:00 +010062 ALOGV("Destroyed");
Takeshi Aimie943f842010-10-08 23:05:49 +090063 mDrmManager->unloadPlugIns();
aimitakeshi27ed8ad2010-07-29 10:12:27 +090064 delete mDrmManager; mDrmManager = NULL;
65}
66
Gloria Wang8f001512011-07-21 15:10:22 -070067int DrmManagerService::addUniqueId(bool isNative) {
68 return mDrmManager->addUniqueId(isNative);
Takeshi Aimi2272ee22010-09-20 23:40:41 +090069}
70
71void DrmManagerService::removeUniqueId(int uniqueId) {
72 mDrmManager->removeUniqueId(uniqueId);
73}
74
Takeshi Aimie943f842010-10-08 23:05:49 +090075void DrmManagerService::addClient(int uniqueId) {
76 mDrmManager->addClient(uniqueId);
aimitakeshi27ed8ad2010-07-29 10:12:27 +090077}
78
Takeshi Aimie943f842010-10-08 23:05:49 +090079void DrmManagerService::removeClient(int uniqueId) {
80 mDrmManager->removeClient(uniqueId);
aimitakeshi27ed8ad2010-07-29 10:12:27 +090081}
82
83status_t DrmManagerService::setDrmServiceListener(
84 int uniqueId, const sp<IDrmServiceListener>& drmServiceListener) {
Steve Block3856b092011-10-20 11:56:00 +010085 ALOGV("Entering setDrmServiceListener");
aimitakeshi27ed8ad2010-07-29 10:12:27 +090086 mDrmManager->setDrmServiceListener(uniqueId, drmServiceListener);
87 return DRM_NO_ERROR;
88}
89
aimitakeshi27ed8ad2010-07-29 10:12:27 +090090status_t DrmManagerService::installDrmEngine(int uniqueId, const String8& drmEngineFile) {
Steve Block3856b092011-10-20 11:56:00 +010091 ALOGV("Entering installDrmEngine");
aimitakeshi27ed8ad2010-07-29 10:12:27 +090092 return mDrmManager->installDrmEngine(uniqueId, drmEngineFile);
93}
94
95DrmConstraints* DrmManagerService::getConstraints(
96 int uniqueId, const String8* path, const int action) {
Steve Block3856b092011-10-20 11:56:00 +010097 ALOGV("Entering getConstraints from content");
aimitakeshi27ed8ad2010-07-29 10:12:27 +090098 return mDrmManager->getConstraints(uniqueId, path, action);
99}
100
Takeshi Aimi34738462010-11-16 13:56:11 +0900101DrmMetadata* DrmManagerService::getMetadata(int uniqueId, const String8* path) {
Steve Block3856b092011-10-20 11:56:00 +0100102 ALOGV("Entering getMetadata from content");
Takeshi Aimi34738462010-11-16 13:56:11 +0900103 return mDrmManager->getMetadata(uniqueId, path);
104}
105
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900106bool DrmManagerService::canHandle(int uniqueId, const String8& path, const String8& mimeType) {
Steve Block3856b092011-10-20 11:56:00 +0100107 ALOGV("Entering canHandle");
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900108 return mDrmManager->canHandle(uniqueId, path, mimeType);
109}
110
111DrmInfoStatus* DrmManagerService::processDrmInfo(int uniqueId, const DrmInfo* drmInfo) {
Steve Block3856b092011-10-20 11:56:00 +0100112 ALOGV("Entering processDrmInfo");
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900113 return mDrmManager->processDrmInfo(uniqueId, drmInfo);
114}
115
116DrmInfo* DrmManagerService::acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest) {
Steve Block3856b092011-10-20 11:56:00 +0100117 ALOGV("Entering acquireDrmInfo");
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900118 return mDrmManager->acquireDrmInfo(uniqueId, drmInfoRequest);
119}
120
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900121status_t DrmManagerService::saveRights(
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900122 int uniqueId, const DrmRights& drmRights,
123 const String8& rightsPath, const String8& contentPath) {
Steve Block3856b092011-10-20 11:56:00 +0100124 ALOGV("Entering saveRights");
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900125 return mDrmManager->saveRights(uniqueId, drmRights, rightsPath, contentPath);
126}
127
128String8 DrmManagerService::getOriginalMimeType(int uniqueId, const String8& path) {
Steve Block3856b092011-10-20 11:56:00 +0100129 ALOGV("Entering getOriginalMimeType");
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900130 return mDrmManager->getOriginalMimeType(uniqueId, path);
131}
132
133int DrmManagerService::getDrmObjectType(
134 int uniqueId, const String8& path, const String8& mimeType) {
Steve Block3856b092011-10-20 11:56:00 +0100135 ALOGV("Entering getDrmObjectType");
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900136 return mDrmManager->getDrmObjectType(uniqueId, path, mimeType);
137}
138
139int DrmManagerService::checkRightsStatus(
140 int uniqueId, const String8& path, int action) {
Steve Block3856b092011-10-20 11:56:00 +0100141 ALOGV("Entering checkRightsStatus");
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900142 return mDrmManager->checkRightsStatus(uniqueId, path, action);
143}
144
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900145status_t DrmManagerService::consumeRights(
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900146 int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) {
Steve Block3856b092011-10-20 11:56:00 +0100147 ALOGV("Entering consumeRights");
James Dong328745b2012-02-28 13:55:55 -0800148 if (!isProtectedCallAllowed()) {
149 return DRM_ERROR_NO_PERMISSION;
150 }
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900151 return mDrmManager->consumeRights(uniqueId, decryptHandle, action, reserve);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900152}
153
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900154status_t DrmManagerService::setPlaybackStatus(
Gloria Wanga2cd44c2010-11-19 15:19:36 -0800155 int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int64_t position) {
Steve Block3856b092011-10-20 11:56:00 +0100156 ALOGV("Entering setPlaybackStatus");
James Dong328745b2012-02-28 13:55:55 -0800157 if (!isProtectedCallAllowed()) {
158 return DRM_ERROR_NO_PERMISSION;
159 }
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900160 return mDrmManager->setPlaybackStatus(uniqueId, decryptHandle, playbackStatus, position);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900161}
162
163bool DrmManagerService::validateAction(
164 int uniqueId, const String8& path,
165 int action, const ActionDescription& description) {
Steve Block3856b092011-10-20 11:56:00 +0100166 ALOGV("Entering validateAction");
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900167 return mDrmManager->validateAction(uniqueId, path, action, description);
168}
169
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900170status_t DrmManagerService::removeRights(int uniqueId, const String8& path) {
Steve Block3856b092011-10-20 11:56:00 +0100171 ALOGV("Entering removeRights");
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900172 return mDrmManager->removeRights(uniqueId, path);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900173}
174
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900175status_t DrmManagerService::removeAllRights(int uniqueId) {
Steve Block3856b092011-10-20 11:56:00 +0100176 ALOGV("Entering removeAllRights");
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900177 return mDrmManager->removeAllRights(uniqueId);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900178}
179
180int DrmManagerService::openConvertSession(int uniqueId, const String8& mimeType) {
Steve Block3856b092011-10-20 11:56:00 +0100181 ALOGV("Entering openConvertSession");
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900182 return mDrmManager->openConvertSession(uniqueId, mimeType);
183}
184
185DrmConvertedStatus* DrmManagerService::convertData(
186 int uniqueId, int convertId, const DrmBuffer* inputData) {
Steve Block3856b092011-10-20 11:56:00 +0100187 ALOGV("Entering convertData");
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900188 return mDrmManager->convertData(uniqueId, convertId, inputData);
189}
190
191DrmConvertedStatus* DrmManagerService::closeConvertSession(int uniqueId, int convertId) {
Steve Block3856b092011-10-20 11:56:00 +0100192 ALOGV("Entering closeConvertSession");
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900193 return mDrmManager->closeConvertSession(uniqueId, convertId);
194}
195
196status_t DrmManagerService::getAllSupportInfo(
197 int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray) {
Steve Block3856b092011-10-20 11:56:00 +0100198 ALOGV("Entering getAllSupportInfo");
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900199 return mDrmManager->getAllSupportInfo(uniqueId, length, drmSupportInfoArray);
200}
201
202DecryptHandle* DrmManagerService::openDecryptSession(
James Dong9d2f3862012-01-10 08:24:37 -0800203 int uniqueId, int fd, off64_t offset, off64_t length, const char* mime) {
Steve Block3856b092011-10-20 11:56:00 +0100204 ALOGV("Entering DrmManagerService::openDecryptSession");
Takeshi Aimi34738462010-11-16 13:56:11 +0900205 if (isProtectedCallAllowed()) {
James Dong9d2f3862012-01-10 08:24:37 -0800206 return mDrmManager->openDecryptSession(uniqueId, fd, offset, length, mime);
Takeshi Aimi34738462010-11-16 13:56:11 +0900207 }
208
209 return NULL;
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900210}
211
Takeshi Aimie943f842010-10-08 23:05:49 +0900212DecryptHandle* DrmManagerService::openDecryptSession(
James Dong9d2f3862012-01-10 08:24:37 -0800213 int uniqueId, const char* uri, const char* mime) {
Steve Block3856b092011-10-20 11:56:00 +0100214 ALOGV("Entering DrmManagerService::openDecryptSession with uri");
Takeshi Aimi34738462010-11-16 13:56:11 +0900215 if (isProtectedCallAllowed()) {
James Dong9d2f3862012-01-10 08:24:37 -0800216 return mDrmManager->openDecryptSession(uniqueId, uri, mime);
Takeshi Aimi34738462010-11-16 13:56:11 +0900217 }
218
219 return NULL;
Takeshi Aimie943f842010-10-08 23:05:49 +0900220}
221
Kei Takahashicba7b322012-01-18 17:10:19 +0900222DecryptHandle* DrmManagerService::openDecryptSession(
223 int uniqueId, const DrmBuffer& buf, const String8& mimeType) {
224 ALOGV("Entering DrmManagerService::openDecryptSession for streaming");
225 if (isProtectedCallAllowed()) {
226 return mDrmManager->openDecryptSession(uniqueId, buf, mimeType);
227 }
228
229 return NULL;
230}
231
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900232status_t DrmManagerService::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) {
Steve Block3856b092011-10-20 11:56:00 +0100233 ALOGV("Entering closeDecryptSession");
James Dong328745b2012-02-28 13:55:55 -0800234 if (!isProtectedCallAllowed()) {
235 return DRM_ERROR_NO_PERMISSION;
236 }
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900237 return mDrmManager->closeDecryptSession(uniqueId, decryptHandle);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900238}
239
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900240status_t DrmManagerService::initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle,
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900241 int decryptUnitId, const DrmBuffer* headerInfo) {
Steve Block3856b092011-10-20 11:56:00 +0100242 ALOGV("Entering initializeDecryptUnit");
James Dong328745b2012-02-28 13:55:55 -0800243 if (!isProtectedCallAllowed()) {
244 return DRM_ERROR_NO_PERMISSION;
245 }
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900246 return mDrmManager->initializeDecryptUnit(uniqueId,decryptHandle, decryptUnitId, headerInfo);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900247}
248
249status_t DrmManagerService::decrypt(
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900250 int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId,
251 const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) {
Steve Block3856b092011-10-20 11:56:00 +0100252 ALOGV("Entering decrypt");
James Dong328745b2012-02-28 13:55:55 -0800253 if (!isProtectedCallAllowed()) {
254 return DRM_ERROR_NO_PERMISSION;
255 }
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900256 return mDrmManager->decrypt(uniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer, IV);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900257}
258
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900259status_t DrmManagerService::finalizeDecryptUnit(
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900260 int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) {
Steve Block3856b092011-10-20 11:56:00 +0100261 ALOGV("Entering finalizeDecryptUnit");
James Dong328745b2012-02-28 13:55:55 -0800262 if (!isProtectedCallAllowed()) {
263 return DRM_ERROR_NO_PERMISSION;
264 }
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900265 return mDrmManager->finalizeDecryptUnit(uniqueId, decryptHandle, decryptUnitId);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900266}
267
268ssize_t DrmManagerService::pread(int uniqueId, DecryptHandle* decryptHandle,
Gloria Wanga2cd44c2010-11-19 15:19:36 -0800269 void* buffer, ssize_t numBytes, off64_t offset) {
Steve Block3856b092011-10-20 11:56:00 +0100270 ALOGV("Entering pread");
James Dong328745b2012-02-28 13:55:55 -0800271 if (!isProtectedCallAllowed()) {
272 return DRM_ERROR_NO_PERMISSION;
273 }
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900274 return mDrmManager->pread(uniqueId, decryptHandle, buffer, numBytes, offset);
275}
276
James Dong8635b7b2011-03-14 17:01:38 -0700277status_t DrmManagerService::dump(int fd, const Vector<String16>& args)
278{
279 const size_t SIZE = 256;
280 char buffer[SIZE];
281 String8 result;
282 if (checkCallingPermission(String16("android.permission.DUMP")) == false) {
283 snprintf(buffer, SIZE, "Permission Denial: "
284 "can't dump DrmManagerService from pid=%d, uid=%d\n",
285 IPCThreadState::self()->getCallingPid(),
286 IPCThreadState::self()->getCallingUid());
287 result.append(buffer);
288 } else {
289#if DRM_MEMORY_LEAK_TRACK
290 bool dumpMem = false;
291 for (size_t i = 0; i < args.size(); i++) {
292 if (args[i] == String16("-m")) {
293 dumpMem = true;
294 }
295 }
296 if (dumpMem) {
297 dumpMemoryAddresses(fd);
298 }
299#endif
300 }
301 write(fd, result.string(), result.size());
302 return NO_ERROR;
303}
304