blob: 2b71904eb9e1722f3c605293580344b5371980d5 [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 +090090DrmConstraints* DrmManagerService::getConstraints(
91 int uniqueId, const String8* path, const int action) {
Steve Block3856b092011-10-20 11:56:00 +010092 ALOGV("Entering getConstraints from content");
aimitakeshi27ed8ad2010-07-29 10:12:27 +090093 return mDrmManager->getConstraints(uniqueId, path, action);
94}
95
Takeshi Aimi34738462010-11-16 13:56:11 +090096DrmMetadata* DrmManagerService::getMetadata(int uniqueId, const String8* path) {
Steve Block3856b092011-10-20 11:56:00 +010097 ALOGV("Entering getMetadata from content");
Takeshi Aimi34738462010-11-16 13:56:11 +090098 return mDrmManager->getMetadata(uniqueId, path);
99}
100
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900101bool DrmManagerService::canHandle(int uniqueId, const String8& path, const String8& mimeType) {
Steve Block3856b092011-10-20 11:56:00 +0100102 ALOGV("Entering canHandle");
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900103 return mDrmManager->canHandle(uniqueId, path, mimeType);
104}
105
106DrmInfoStatus* DrmManagerService::processDrmInfo(int uniqueId, const DrmInfo* drmInfo) {
Steve Block3856b092011-10-20 11:56:00 +0100107 ALOGV("Entering processDrmInfo");
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900108 return mDrmManager->processDrmInfo(uniqueId, drmInfo);
109}
110
111DrmInfo* DrmManagerService::acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest) {
Steve Block3856b092011-10-20 11:56:00 +0100112 ALOGV("Entering acquireDrmInfo");
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900113 return mDrmManager->acquireDrmInfo(uniqueId, drmInfoRequest);
114}
115
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900116status_t DrmManagerService::saveRights(
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900117 int uniqueId, const DrmRights& drmRights,
118 const String8& rightsPath, const String8& contentPath) {
Steve Block3856b092011-10-20 11:56:00 +0100119 ALOGV("Entering saveRights");
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900120 return mDrmManager->saveRights(uniqueId, drmRights, rightsPath, contentPath);
121}
122
James Dongbf5b3b22012-07-30 17:57:39 -0700123String8 DrmManagerService::getOriginalMimeType(int uniqueId, const String8& path, int fd) {
Steve Block3856b092011-10-20 11:56:00 +0100124 ALOGV("Entering getOriginalMimeType");
James Dongbf5b3b22012-07-30 17:57:39 -0700125 return mDrmManager->getOriginalMimeType(uniqueId, path, fd);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900126}
127
128int DrmManagerService::getDrmObjectType(
129 int uniqueId, const String8& path, const String8& mimeType) {
Steve Block3856b092011-10-20 11:56:00 +0100130 ALOGV("Entering getDrmObjectType");
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900131 return mDrmManager->getDrmObjectType(uniqueId, path, mimeType);
132}
133
134int DrmManagerService::checkRightsStatus(
135 int uniqueId, const String8& path, int action) {
Steve Block3856b092011-10-20 11:56:00 +0100136 ALOGV("Entering checkRightsStatus");
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900137 return mDrmManager->checkRightsStatus(uniqueId, path, action);
138}
139
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900140status_t DrmManagerService::consumeRights(
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900141 int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) {
Steve Block3856b092011-10-20 11:56:00 +0100142 ALOGV("Entering consumeRights");
James Dong328745b2012-02-28 13:55:55 -0800143 if (!isProtectedCallAllowed()) {
144 return DRM_ERROR_NO_PERMISSION;
145 }
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900146 return mDrmManager->consumeRights(uniqueId, decryptHandle, action, reserve);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900147}
148
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900149status_t DrmManagerService::setPlaybackStatus(
Gloria Wanga2cd44c2010-11-19 15:19:36 -0800150 int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int64_t position) {
Steve Block3856b092011-10-20 11:56:00 +0100151 ALOGV("Entering setPlaybackStatus");
James Dong328745b2012-02-28 13:55:55 -0800152 if (!isProtectedCallAllowed()) {
153 return DRM_ERROR_NO_PERMISSION;
154 }
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900155 return mDrmManager->setPlaybackStatus(uniqueId, decryptHandle, playbackStatus, position);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900156}
157
158bool DrmManagerService::validateAction(
159 int uniqueId, const String8& path,
160 int action, const ActionDescription& description) {
Steve Block3856b092011-10-20 11:56:00 +0100161 ALOGV("Entering validateAction");
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900162 return mDrmManager->validateAction(uniqueId, path, action, description);
163}
164
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900165status_t DrmManagerService::removeRights(int uniqueId, const String8& path) {
Steve Block3856b092011-10-20 11:56:00 +0100166 ALOGV("Entering removeRights");
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900167 return mDrmManager->removeRights(uniqueId, path);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900168}
169
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900170status_t DrmManagerService::removeAllRights(int uniqueId) {
Steve Block3856b092011-10-20 11:56:00 +0100171 ALOGV("Entering removeAllRights");
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900172 return mDrmManager->removeAllRights(uniqueId);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900173}
174
175int DrmManagerService::openConvertSession(int uniqueId, const String8& mimeType) {
Steve Block3856b092011-10-20 11:56:00 +0100176 ALOGV("Entering openConvertSession");
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900177 return mDrmManager->openConvertSession(uniqueId, mimeType);
178}
179
180DrmConvertedStatus* DrmManagerService::convertData(
181 int uniqueId, int convertId, const DrmBuffer* inputData) {
Steve Block3856b092011-10-20 11:56:00 +0100182 ALOGV("Entering convertData");
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900183 return mDrmManager->convertData(uniqueId, convertId, inputData);
184}
185
186DrmConvertedStatus* DrmManagerService::closeConvertSession(int uniqueId, int convertId) {
Steve Block3856b092011-10-20 11:56:00 +0100187 ALOGV("Entering closeConvertSession");
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900188 return mDrmManager->closeConvertSession(uniqueId, convertId);
189}
190
191status_t DrmManagerService::getAllSupportInfo(
192 int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray) {
Steve Block3856b092011-10-20 11:56:00 +0100193 ALOGV("Entering getAllSupportInfo");
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900194 return mDrmManager->getAllSupportInfo(uniqueId, length, drmSupportInfoArray);
195}
196
197DecryptHandle* DrmManagerService::openDecryptSession(
James Dong9d2f3862012-01-10 08:24:37 -0800198 int uniqueId, int fd, off64_t offset, off64_t length, const char* mime) {
Steve Block3856b092011-10-20 11:56:00 +0100199 ALOGV("Entering DrmManagerService::openDecryptSession");
Takeshi Aimi34738462010-11-16 13:56:11 +0900200 if (isProtectedCallAllowed()) {
James Dong9d2f3862012-01-10 08:24:37 -0800201 return mDrmManager->openDecryptSession(uniqueId, fd, offset, length, mime);
Takeshi Aimi34738462010-11-16 13:56:11 +0900202 }
203
204 return NULL;
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900205}
206
Takeshi Aimie943f842010-10-08 23:05:49 +0900207DecryptHandle* DrmManagerService::openDecryptSession(
James Dong9d2f3862012-01-10 08:24:37 -0800208 int uniqueId, const char* uri, const char* mime) {
Steve Block3856b092011-10-20 11:56:00 +0100209 ALOGV("Entering DrmManagerService::openDecryptSession with uri");
Takeshi Aimi34738462010-11-16 13:56:11 +0900210 if (isProtectedCallAllowed()) {
James Dong9d2f3862012-01-10 08:24:37 -0800211 return mDrmManager->openDecryptSession(uniqueId, uri, mime);
Takeshi Aimi34738462010-11-16 13:56:11 +0900212 }
213
214 return NULL;
Takeshi Aimie943f842010-10-08 23:05:49 +0900215}
216
Kei Takahashicba7b322012-01-18 17:10:19 +0900217DecryptHandle* DrmManagerService::openDecryptSession(
218 int uniqueId, const DrmBuffer& buf, const String8& mimeType) {
219 ALOGV("Entering DrmManagerService::openDecryptSession for streaming");
220 if (isProtectedCallAllowed()) {
221 return mDrmManager->openDecryptSession(uniqueId, buf, mimeType);
222 }
223
224 return NULL;
225}
226
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900227status_t DrmManagerService::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) {
Steve Block3856b092011-10-20 11:56:00 +0100228 ALOGV("Entering closeDecryptSession");
James Dong328745b2012-02-28 13:55:55 -0800229 if (!isProtectedCallAllowed()) {
230 return DRM_ERROR_NO_PERMISSION;
231 }
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900232 return mDrmManager->closeDecryptSession(uniqueId, decryptHandle);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900233}
234
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900235status_t DrmManagerService::initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle,
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900236 int decryptUnitId, const DrmBuffer* headerInfo) {
Steve Block3856b092011-10-20 11:56:00 +0100237 ALOGV("Entering initializeDecryptUnit");
James Dong328745b2012-02-28 13:55:55 -0800238 if (!isProtectedCallAllowed()) {
239 return DRM_ERROR_NO_PERMISSION;
240 }
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900241 return mDrmManager->initializeDecryptUnit(uniqueId,decryptHandle, decryptUnitId, headerInfo);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900242}
243
244status_t DrmManagerService::decrypt(
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900245 int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId,
246 const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) {
Steve Block3856b092011-10-20 11:56:00 +0100247 ALOGV("Entering decrypt");
James Dong328745b2012-02-28 13:55:55 -0800248 if (!isProtectedCallAllowed()) {
249 return DRM_ERROR_NO_PERMISSION;
250 }
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900251 return mDrmManager->decrypt(uniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer, IV);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900252}
253
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900254status_t DrmManagerService::finalizeDecryptUnit(
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900255 int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) {
Steve Block3856b092011-10-20 11:56:00 +0100256 ALOGV("Entering finalizeDecryptUnit");
James Dong328745b2012-02-28 13:55:55 -0800257 if (!isProtectedCallAllowed()) {
258 return DRM_ERROR_NO_PERMISSION;
259 }
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900260 return mDrmManager->finalizeDecryptUnit(uniqueId, decryptHandle, decryptUnitId);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900261}
262
263ssize_t DrmManagerService::pread(int uniqueId, DecryptHandle* decryptHandle,
Gloria Wanga2cd44c2010-11-19 15:19:36 -0800264 void* buffer, ssize_t numBytes, off64_t offset) {
Steve Block3856b092011-10-20 11:56:00 +0100265 ALOGV("Entering pread");
James Dong328745b2012-02-28 13:55:55 -0800266 if (!isProtectedCallAllowed()) {
267 return DRM_ERROR_NO_PERMISSION;
268 }
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900269 return mDrmManager->pread(uniqueId, decryptHandle, buffer, numBytes, offset);
270}
271
James Dong8635b7b2011-03-14 17:01:38 -0700272status_t DrmManagerService::dump(int fd, const Vector<String16>& args)
273{
274 const size_t SIZE = 256;
275 char buffer[SIZE];
276 String8 result;
277 if (checkCallingPermission(String16("android.permission.DUMP")) == false) {
278 snprintf(buffer, SIZE, "Permission Denial: "
279 "can't dump DrmManagerService from pid=%d, uid=%d\n",
280 IPCThreadState::self()->getCallingPid(),
281 IPCThreadState::self()->getCallingUid());
282 result.append(buffer);
283 } else {
284#if DRM_MEMORY_LEAK_TRACK
285 bool dumpMem = false;
286 for (size_t i = 0; i < args.size(); i++) {
287 if (args[i] == String16("-m")) {
288 dumpMem = true;
289 }
290 }
291 if (dumpMem) {
292 dumpMemoryAddresses(fd);
293 }
294#endif
295 }
296 write(fd, result.string(), result.size());
297 return NO_ERROR;
298}
299