blob: 2600a2c23e612f211aa5f57de86f2383d44513f1 [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
Riley Spahnf785f492014-07-01 15:32:31 -070032#include <selinux/android.h>
33
aimitakeshi27ed8ad2010-07-29 10:12:27 +090034using namespace android;
35
Riley Spahnf785f492014-07-01 15:32:31 -070036static int selinux_enabled;
37static char *drmserver_context;
Takeshi Aimi34738462010-11-16 13:56:11 +090038static Vector<uid_t> trustedUids;
39
Riley Spahnf785f492014-07-01 15:32:31 -070040const char *const DrmManagerService::drm_perm_labels[] = {
41 "consumeRights",
42 "setPlaybackStatus",
43 "openDecryptSession",
44 "closeDecryptSession",
45 "initializeDecryptUnit",
46 "decrypt",
47 "finalizeDecryptUnit",
48 "pread"
49};
50
51const char *DrmManagerService::get_perm_label(drm_perm_t perm) {
52 unsigned int index = perm;
53
Aurimas Liutikasc9036842016-02-18 15:58:04 -080054 if (index >= (sizeof(drm_perm_labels) / sizeof(drm_perm_labels[0]))) {
Riley Spahnf785f492014-07-01 15:32:31 -070055 ALOGE("SELinux: Failed to retrieve permission label(perm=%d).\n", perm);
56 abort();
57 }
58 return drm_perm_labels[index];
59}
60
Steven Moreland1a394d52019-01-11 15:49:24 -080061bool DrmManagerService::selinuxIsProtectedCallAllowed(pid_t spid, const char* ssid, drm_perm_t perm) {
Riley Spahnf785f492014-07-01 15:32:31 -070062 if (selinux_enabled <= 0) {
63 return true;
64 }
65
Steven Moreland1a394d52019-01-11 15:49:24 -080066 char *sctx = NULL;
Riley Spahnf785f492014-07-01 15:32:31 -070067 const char *selinux_class = "drmservice";
68 const char *str_perm = get_perm_label(perm);
69
Steven Moreland1a394d52019-01-11 15:49:24 -080070 if (ssid == NULL) {
71 android_errorWriteLog(0x534e4554, "121035042");
72
73 if (getpidcon(spid, &sctx) != 0) {
74 ALOGE("SELinux: getpidcon(pid=%d) failed.\n", spid);
75 return false;
76 }
Riley Spahnf785f492014-07-01 15:32:31 -070077 }
78
Steven Moreland1a394d52019-01-11 15:49:24 -080079 bool allowed = (selinux_check_access(ssid ? ssid : sctx, drmserver_context,
80 selinux_class, str_perm, NULL) == 0);
Riley Spahnf785f492014-07-01 15:32:31 -070081 freecon(sctx);
82
83 return allowed;
84}
85
86bool DrmManagerService::isProtectedCallAllowed(drm_perm_t perm) {
Jeff Tinker6868e982014-06-17 16:45:46 -070087 // TODO
88 // Following implementation is just for reference.
89 // Each OEM manufacturer should implement/replace with their own solutions.
90 IPCThreadState* ipcState = IPCThreadState::self();
91 uid_t uid = ipcState->getCallingUid();
Riley Spahnf785f492014-07-01 15:32:31 -070092 pid_t spid = ipcState->getCallingPid();
Steven Moreland1a394d52019-01-11 15:49:24 -080093 const char* ssid = ipcState->getCallingSid();
Jeff Tinker6868e982014-06-17 16:45:46 -070094
95 for (unsigned int i = 0; i < trustedUids.size(); ++i) {
96 if (trustedUids[i] == uid) {
Steven Moreland1a394d52019-01-11 15:49:24 -080097 return selinuxIsProtectedCallAllowed(spid, ssid, perm);
Jeff Tinker6868e982014-06-17 16:45:46 -070098 }
99 }
100 return false;
Takeshi Aimi34738462010-11-16 13:56:11 +0900101}
102
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900103void DrmManagerService::instantiate() {
Steve Block3856b092011-10-20 11:56:00 +0100104 ALOGV("instantiate");
Steven Moreland1a394d52019-01-11 15:49:24 -0800105 sp<DrmManagerService> service = new DrmManagerService();
106 service->setRequestingSid(true);
107 defaultServiceManager()->addService(String16("drm.drmManager"), service);
Takeshi Aimi34738462010-11-16 13:56:11 +0900108
109 if (0 >= trustedUids.size()) {
110 // TODO
111 // Following implementation is just for reference.
112 // Each OEM manufacturer should implement/replace with their own solutions.
113
114 // Add trusted uids here
115 trustedUids.push(AID_MEDIA);
116 }
Riley Spahnf785f492014-07-01 15:32:31 -0700117
118 selinux_enabled = is_selinux_enabled();
119 if (selinux_enabled > 0 && getcon(&drmserver_context) != 0) {
120 ALOGE("SELinux: DrmManagerService failed to get context for DrmManagerService. Aborting.\n");
121 abort();
122 }
123
124 union selinux_callback cb;
125 cb.func_log = selinux_log_callback;
126 selinux_set_callback(SELINUX_CB_LOG, cb);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900127}
128
Takeshi Aimie943f842010-10-08 23:05:49 +0900129DrmManagerService::DrmManagerService() :
130 mDrmManager(NULL) {
Steve Block3856b092011-10-20 11:56:00 +0100131 ALOGV("created");
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900132 mDrmManager = new DrmManager();
Takeshi Aimie943f842010-10-08 23:05:49 +0900133 mDrmManager->loadPlugIns();
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900134}
135
136DrmManagerService::~DrmManagerService() {
Steve Block3856b092011-10-20 11:56:00 +0100137 ALOGV("Destroyed");
Takeshi Aimie943f842010-10-08 23:05:49 +0900138 mDrmManager->unloadPlugIns();
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900139 delete mDrmManager; mDrmManager = NULL;
140}
141
Gloria Wang8f001512011-07-21 15:10:22 -0700142int DrmManagerService::addUniqueId(bool isNative) {
143 return mDrmManager->addUniqueId(isNative);
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900144}
145
146void DrmManagerService::removeUniqueId(int uniqueId) {
147 mDrmManager->removeUniqueId(uniqueId);
148}
149
Takeshi Aimie943f842010-10-08 23:05:49 +0900150void DrmManagerService::addClient(int uniqueId) {
151 mDrmManager->addClient(uniqueId);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900152}
153
Takeshi Aimie943f842010-10-08 23:05:49 +0900154void DrmManagerService::removeClient(int uniqueId) {
155 mDrmManager->removeClient(uniqueId);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900156}
157
158status_t DrmManagerService::setDrmServiceListener(
159 int uniqueId, const sp<IDrmServiceListener>& drmServiceListener) {
Steve Block3856b092011-10-20 11:56:00 +0100160 ALOGV("Entering setDrmServiceListener");
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900161 mDrmManager->setDrmServiceListener(uniqueId, drmServiceListener);
162 return DRM_NO_ERROR;
163}
164
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900165DrmConstraints* DrmManagerService::getConstraints(
166 int uniqueId, const String8* path, const int action) {
Steve Block3856b092011-10-20 11:56:00 +0100167 ALOGV("Entering getConstraints from content");
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900168 return mDrmManager->getConstraints(uniqueId, path, action);
169}
170
Takeshi Aimi34738462010-11-16 13:56:11 +0900171DrmMetadata* DrmManagerService::getMetadata(int uniqueId, const String8* path) {
Steve Block3856b092011-10-20 11:56:00 +0100172 ALOGV("Entering getMetadata from content");
Takeshi Aimi34738462010-11-16 13:56:11 +0900173 return mDrmManager->getMetadata(uniqueId, path);
174}
175
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900176bool DrmManagerService::canHandle(int uniqueId, const String8& path, const String8& mimeType) {
Steve Block3856b092011-10-20 11:56:00 +0100177 ALOGV("Entering canHandle");
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900178 return mDrmManager->canHandle(uniqueId, path, mimeType);
179}
180
181DrmInfoStatus* DrmManagerService::processDrmInfo(int uniqueId, const DrmInfo* drmInfo) {
Steve Block3856b092011-10-20 11:56:00 +0100182 ALOGV("Entering processDrmInfo");
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900183 return mDrmManager->processDrmInfo(uniqueId, drmInfo);
184}
185
186DrmInfo* DrmManagerService::acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest) {
Steve Block3856b092011-10-20 11:56:00 +0100187 ALOGV("Entering acquireDrmInfo");
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900188 return mDrmManager->acquireDrmInfo(uniqueId, drmInfoRequest);
189}
190
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900191status_t DrmManagerService::saveRights(
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900192 int uniqueId, const DrmRights& drmRights,
193 const String8& rightsPath, const String8& contentPath) {
Steve Block3856b092011-10-20 11:56:00 +0100194 ALOGV("Entering saveRights");
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900195 return mDrmManager->saveRights(uniqueId, drmRights, rightsPath, contentPath);
196}
197
James Dongbf5b3b22012-07-30 17:57:39 -0700198String8 DrmManagerService::getOriginalMimeType(int uniqueId, const String8& path, int fd) {
Steve Block3856b092011-10-20 11:56:00 +0100199 ALOGV("Entering getOriginalMimeType");
James Dongbf5b3b22012-07-30 17:57:39 -0700200 return mDrmManager->getOriginalMimeType(uniqueId, path, fd);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900201}
202
203int DrmManagerService::getDrmObjectType(
204 int uniqueId, const String8& path, const String8& mimeType) {
Steve Block3856b092011-10-20 11:56:00 +0100205 ALOGV("Entering getDrmObjectType");
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900206 return mDrmManager->getDrmObjectType(uniqueId, path, mimeType);
207}
208
209int DrmManagerService::checkRightsStatus(
210 int uniqueId, const String8& path, int action) {
Steve Block3856b092011-10-20 11:56:00 +0100211 ALOGV("Entering checkRightsStatus");
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900212 return mDrmManager->checkRightsStatus(uniqueId, path, action);
213}
214
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900215status_t DrmManagerService::consumeRights(
Jeff Tinker5d49bef2018-10-03 23:01:09 -0700216 int uniqueId, sp<DecryptHandle>& decryptHandle, int action, bool reserve) {
Steve Block3856b092011-10-20 11:56:00 +0100217 ALOGV("Entering consumeRights");
Riley Spahnf785f492014-07-01 15:32:31 -0700218 if (!isProtectedCallAllowed(CONSUME_RIGHTS)) {
James Dong328745b2012-02-28 13:55:55 -0800219 return DRM_ERROR_NO_PERMISSION;
220 }
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900221 return mDrmManager->consumeRights(uniqueId, decryptHandle, action, reserve);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900222}
223
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900224status_t DrmManagerService::setPlaybackStatus(
Jeff Tinker5d49bef2018-10-03 23:01:09 -0700225 int uniqueId, sp<DecryptHandle>& decryptHandle, int playbackStatus, int64_t position) {
Steve Block3856b092011-10-20 11:56:00 +0100226 ALOGV("Entering setPlaybackStatus");
Riley Spahnf785f492014-07-01 15:32:31 -0700227 if (!isProtectedCallAllowed(SET_PLAYBACK_STATUS)) {
James Dong328745b2012-02-28 13:55:55 -0800228 return DRM_ERROR_NO_PERMISSION;
229 }
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900230 return mDrmManager->setPlaybackStatus(uniqueId, decryptHandle, playbackStatus, position);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900231}
232
233bool DrmManagerService::validateAction(
234 int uniqueId, const String8& path,
235 int action, const ActionDescription& description) {
Steve Block3856b092011-10-20 11:56:00 +0100236 ALOGV("Entering validateAction");
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900237 return mDrmManager->validateAction(uniqueId, path, action, description);
238}
239
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900240status_t DrmManagerService::removeRights(int uniqueId, const String8& path) {
Steve Block3856b092011-10-20 11:56:00 +0100241 ALOGV("Entering removeRights");
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900242 return mDrmManager->removeRights(uniqueId, path);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900243}
244
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900245status_t DrmManagerService::removeAllRights(int uniqueId) {
Steve Block3856b092011-10-20 11:56:00 +0100246 ALOGV("Entering removeAllRights");
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900247 return mDrmManager->removeAllRights(uniqueId);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900248}
249
250int DrmManagerService::openConvertSession(int uniqueId, const String8& mimeType) {
Steve Block3856b092011-10-20 11:56:00 +0100251 ALOGV("Entering openConvertSession");
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900252 return mDrmManager->openConvertSession(uniqueId, mimeType);
253}
254
255DrmConvertedStatus* DrmManagerService::convertData(
256 int uniqueId, int convertId, const DrmBuffer* inputData) {
Steve Block3856b092011-10-20 11:56:00 +0100257 ALOGV("Entering convertData");
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900258 return mDrmManager->convertData(uniqueId, convertId, inputData);
259}
260
261DrmConvertedStatus* DrmManagerService::closeConvertSession(int uniqueId, int convertId) {
Steve Block3856b092011-10-20 11:56:00 +0100262 ALOGV("Entering closeConvertSession");
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900263 return mDrmManager->closeConvertSession(uniqueId, convertId);
264}
265
266status_t DrmManagerService::getAllSupportInfo(
267 int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray) {
Steve Block3856b092011-10-20 11:56:00 +0100268 ALOGV("Entering getAllSupportInfo");
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900269 return mDrmManager->getAllSupportInfo(uniqueId, length, drmSupportInfoArray);
270}
271
Jeff Tinker5d49bef2018-10-03 23:01:09 -0700272sp<DecryptHandle> DrmManagerService::openDecryptSession(
James Dong9d2f3862012-01-10 08:24:37 -0800273 int uniqueId, int fd, off64_t offset, off64_t length, const char* mime) {
Steve Block3856b092011-10-20 11:56:00 +0100274 ALOGV("Entering DrmManagerService::openDecryptSession");
Riley Spahnf785f492014-07-01 15:32:31 -0700275 if (isProtectedCallAllowed(OPEN_DECRYPT_SESSION)) {
James Dong9d2f3862012-01-10 08:24:37 -0800276 return mDrmManager->openDecryptSession(uniqueId, fd, offset, length, mime);
Takeshi Aimi34738462010-11-16 13:56:11 +0900277 }
278
279 return NULL;
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900280}
281
Jeff Tinker5d49bef2018-10-03 23:01:09 -0700282sp<DecryptHandle> DrmManagerService::openDecryptSession(
James Dong9d2f3862012-01-10 08:24:37 -0800283 int uniqueId, const char* uri, const char* mime) {
Steve Block3856b092011-10-20 11:56:00 +0100284 ALOGV("Entering DrmManagerService::openDecryptSession with uri");
Riley Spahnf785f492014-07-01 15:32:31 -0700285 if (isProtectedCallAllowed(OPEN_DECRYPT_SESSION)) {
James Dong9d2f3862012-01-10 08:24:37 -0800286 return mDrmManager->openDecryptSession(uniqueId, uri, mime);
Takeshi Aimi34738462010-11-16 13:56:11 +0900287 }
288
289 return NULL;
Takeshi Aimie943f842010-10-08 23:05:49 +0900290}
291
Jeff Tinker5d49bef2018-10-03 23:01:09 -0700292sp<DecryptHandle> DrmManagerService::openDecryptSession(
Kei Takahashicba7b322012-01-18 17:10:19 +0900293 int uniqueId, const DrmBuffer& buf, const String8& mimeType) {
294 ALOGV("Entering DrmManagerService::openDecryptSession for streaming");
Riley Spahnf785f492014-07-01 15:32:31 -0700295 if (isProtectedCallAllowed(OPEN_DECRYPT_SESSION)) {
Kei Takahashicba7b322012-01-18 17:10:19 +0900296 return mDrmManager->openDecryptSession(uniqueId, buf, mimeType);
297 }
298
299 return NULL;
300}
301
Jeff Tinker5d49bef2018-10-03 23:01:09 -0700302status_t DrmManagerService::closeDecryptSession(int uniqueId, sp<DecryptHandle>& decryptHandle) {
Steve Block3856b092011-10-20 11:56:00 +0100303 ALOGV("Entering closeDecryptSession");
Riley Spahnf785f492014-07-01 15:32:31 -0700304 if (!isProtectedCallAllowed(CLOSE_DECRYPT_SESSION)) {
James Dong328745b2012-02-28 13:55:55 -0800305 return DRM_ERROR_NO_PERMISSION;
306 }
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900307 return mDrmManager->closeDecryptSession(uniqueId, decryptHandle);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900308}
309
Jeff Tinker5d49bef2018-10-03 23:01:09 -0700310status_t DrmManagerService::initializeDecryptUnit(int uniqueId, sp<DecryptHandle>& decryptHandle,
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900311 int decryptUnitId, const DrmBuffer* headerInfo) {
Steve Block3856b092011-10-20 11:56:00 +0100312 ALOGV("Entering initializeDecryptUnit");
Riley Spahnf785f492014-07-01 15:32:31 -0700313 if (!isProtectedCallAllowed(INITIALIZE_DECRYPT_UNIT)) {
James Dong328745b2012-02-28 13:55:55 -0800314 return DRM_ERROR_NO_PERMISSION;
315 }
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900316 return mDrmManager->initializeDecryptUnit(uniqueId,decryptHandle, decryptUnitId, headerInfo);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900317}
318
319status_t DrmManagerService::decrypt(
Jeff Tinker5d49bef2018-10-03 23:01:09 -0700320 int uniqueId, sp<DecryptHandle>& decryptHandle, int decryptUnitId,
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900321 const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) {
Steve Block3856b092011-10-20 11:56:00 +0100322 ALOGV("Entering decrypt");
Riley Spahnf785f492014-07-01 15:32:31 -0700323 if (!isProtectedCallAllowed(DECRYPT)) {
James Dong328745b2012-02-28 13:55:55 -0800324 return DRM_ERROR_NO_PERMISSION;
325 }
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900326 return mDrmManager->decrypt(uniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer, IV);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900327}
328
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900329status_t DrmManagerService::finalizeDecryptUnit(
Jeff Tinker5d49bef2018-10-03 23:01:09 -0700330 int uniqueId, sp<DecryptHandle>& decryptHandle, int decryptUnitId) {
Steve Block3856b092011-10-20 11:56:00 +0100331 ALOGV("Entering finalizeDecryptUnit");
Riley Spahnf785f492014-07-01 15:32:31 -0700332 if (!isProtectedCallAllowed(FINALIZE_DECRYPT_UNIT)) {
James Dong328745b2012-02-28 13:55:55 -0800333 return DRM_ERROR_NO_PERMISSION;
334 }
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900335 return mDrmManager->finalizeDecryptUnit(uniqueId, decryptHandle, decryptUnitId);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900336}
337
Jeff Tinker5d49bef2018-10-03 23:01:09 -0700338ssize_t DrmManagerService::pread(int uniqueId, sp<DecryptHandle>& decryptHandle,
Gloria Wanga2cd44c2010-11-19 15:19:36 -0800339 void* buffer, ssize_t numBytes, off64_t offset) {
Steve Block3856b092011-10-20 11:56:00 +0100340 ALOGV("Entering pread");
Riley Spahnf785f492014-07-01 15:32:31 -0700341 if (!isProtectedCallAllowed(PREAD)) {
James Dong328745b2012-02-28 13:55:55 -0800342 return DRM_ERROR_NO_PERMISSION;
343 }
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900344 return mDrmManager->pread(uniqueId, decryptHandle, buffer, numBytes, offset);
345}
346
Andy Hung07b745e2016-05-23 16:21:07 -0700347status_t DrmManagerService::dump(int fd, const Vector<String16>& args)
James Dong8635b7b2011-03-14 17:01:38 -0700348{
349 const size_t SIZE = 256;
350 char buffer[SIZE];
351 String8 result;
352 if (checkCallingPermission(String16("android.permission.DUMP")) == false) {
353 snprintf(buffer, SIZE, "Permission Denial: "
354 "can't dump DrmManagerService from pid=%d, uid=%d\n",
355 IPCThreadState::self()->getCallingPid(),
356 IPCThreadState::self()->getCallingUid());
357 result.append(buffer);
358 } else {
359#if DRM_MEMORY_LEAK_TRACK
360 bool dumpMem = false;
361 for (size_t i = 0; i < args.size(); i++) {
362 if (args[i] == String16("-m")) {
363 dumpMem = true;
364 }
365 }
366 if (dumpMem) {
Andy Hung07b745e2016-05-23 16:21:07 -0700367 result.append("\nDumping memory:\n");
368 std::string s = dumpMemoryAddresses(100 /* limit */);
369 result.append(s.c_str(), s.size());
James Dong8635b7b2011-03-14 17:01:38 -0700370 }
Andy Hung07b745e2016-05-23 16:21:07 -0700371#else
372 (void)args;
James Dong8635b7b2011-03-14 17:01:38 -0700373#endif
374 }
375 write(fd, result.string(), result.size());
376 return NO_ERROR;
377}
378