blob: d22ba7808b583c091c679876925e4f644b14d911 [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>
Andy Hunge9eb03e2020-04-04 14:08:23 -070022#include <mediautils/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
Steven Morelanda9f371a2024-12-07 00:43:15 +000073 LOG_ALWAYS_FATAL_IF(nullptr != IPCThreadState::self()->getServingStackPointer(),
74 "Missing SID from other process");
75
Steven Moreland1a394d52019-01-11 15:49:24 -080076 if (getpidcon(spid, &sctx) != 0) {
77 ALOGE("SELinux: getpidcon(pid=%d) failed.\n", spid);
78 return false;
79 }
Riley Spahnf785f492014-07-01 15:32:31 -070080 }
81
Steven Moreland1a394d52019-01-11 15:49:24 -080082 bool allowed = (selinux_check_access(ssid ? ssid : sctx, drmserver_context,
83 selinux_class, str_perm, NULL) == 0);
Riley Spahnf785f492014-07-01 15:32:31 -070084 freecon(sctx);
85
86 return allowed;
87}
88
89bool DrmManagerService::isProtectedCallAllowed(drm_perm_t perm) {
Jeff Tinker6868e982014-06-17 16:45:46 -070090 // TODO
91 // Following implementation is just for reference.
92 // Each OEM manufacturer should implement/replace with their own solutions.
93 IPCThreadState* ipcState = IPCThreadState::self();
94 uid_t uid = ipcState->getCallingUid();
Riley Spahnf785f492014-07-01 15:32:31 -070095 pid_t spid = ipcState->getCallingPid();
Steven Moreland1a394d52019-01-11 15:49:24 -080096 const char* ssid = ipcState->getCallingSid();
Jeff Tinker6868e982014-06-17 16:45:46 -070097
98 for (unsigned int i = 0; i < trustedUids.size(); ++i) {
99 if (trustedUids[i] == uid) {
Steven Moreland1a394d52019-01-11 15:49:24 -0800100 return selinuxIsProtectedCallAllowed(spid, ssid, perm);
Jeff Tinker6868e982014-06-17 16:45:46 -0700101 }
102 }
103 return false;
Takeshi Aimi34738462010-11-16 13:56:11 +0900104}
105
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900106void DrmManagerService::instantiate() {
Steve Block3856b092011-10-20 11:56:00 +0100107 ALOGV("instantiate");
Steven Moreland1a394d52019-01-11 15:49:24 -0800108 sp<DrmManagerService> service = new DrmManagerService();
109 service->setRequestingSid(true);
110 defaultServiceManager()->addService(String16("drm.drmManager"), service);
Takeshi Aimi34738462010-11-16 13:56:11 +0900111
112 if (0 >= trustedUids.size()) {
113 // TODO
114 // Following implementation is just for reference.
115 // Each OEM manufacturer should implement/replace with their own solutions.
116
117 // Add trusted uids here
118 trustedUids.push(AID_MEDIA);
119 }
Riley Spahnf785f492014-07-01 15:32:31 -0700120
121 selinux_enabled = is_selinux_enabled();
122 if (selinux_enabled > 0 && getcon(&drmserver_context) != 0) {
123 ALOGE("SELinux: DrmManagerService failed to get context for DrmManagerService. Aborting.\n");
124 abort();
125 }
126
127 union selinux_callback cb;
128 cb.func_log = selinux_log_callback;
129 selinux_set_callback(SELINUX_CB_LOG, cb);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900130}
131
Takeshi Aimie943f842010-10-08 23:05:49 +0900132DrmManagerService::DrmManagerService() :
133 mDrmManager(NULL) {
Steve Block3856b092011-10-20 11:56:00 +0100134 ALOGV("created");
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900135 mDrmManager = new DrmManager();
Robert Shih7bcf7922020-02-07 15:01:57 -0800136 mDrmManager->initMetricsLooper();
Takeshi Aimie943f842010-10-08 23:05:49 +0900137 mDrmManager->loadPlugIns();
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900138}
139
140DrmManagerService::~DrmManagerService() {
Steve Block3856b092011-10-20 11:56:00 +0100141 ALOGV("Destroyed");
Takeshi Aimie943f842010-10-08 23:05:49 +0900142 mDrmManager->unloadPlugIns();
Robert Shih7bcf7922020-02-07 15:01:57 -0800143 mDrmManager = NULL;
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900144}
145
Gloria Wang8f001512011-07-21 15:10:22 -0700146int DrmManagerService::addUniqueId(bool isNative) {
147 return mDrmManager->addUniqueId(isNative);
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900148}
149
150void DrmManagerService::removeUniqueId(int uniqueId) {
151 mDrmManager->removeUniqueId(uniqueId);
152}
153
Takeshi Aimie943f842010-10-08 23:05:49 +0900154void DrmManagerService::addClient(int uniqueId) {
155 mDrmManager->addClient(uniqueId);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900156}
157
Takeshi Aimie943f842010-10-08 23:05:49 +0900158void DrmManagerService::removeClient(int uniqueId) {
159 mDrmManager->removeClient(uniqueId);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900160}
161
162status_t DrmManagerService::setDrmServiceListener(
163 int uniqueId, const sp<IDrmServiceListener>& drmServiceListener) {
Steve Block3856b092011-10-20 11:56:00 +0100164 ALOGV("Entering setDrmServiceListener");
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900165 mDrmManager->setDrmServiceListener(uniqueId, drmServiceListener);
166 return DRM_NO_ERROR;
167}
168
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900169DrmConstraints* DrmManagerService::getConstraints(
170 int uniqueId, const String8* path, const int action) {
Steve Block3856b092011-10-20 11:56:00 +0100171 ALOGV("Entering getConstraints from content");
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900172 return mDrmManager->getConstraints(uniqueId, path, action);
173}
174
Takeshi Aimi34738462010-11-16 13:56:11 +0900175DrmMetadata* DrmManagerService::getMetadata(int uniqueId, const String8* path) {
Steve Block3856b092011-10-20 11:56:00 +0100176 ALOGV("Entering getMetadata from content");
Takeshi Aimi34738462010-11-16 13:56:11 +0900177 return mDrmManager->getMetadata(uniqueId, path);
178}
179
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900180bool DrmManagerService::canHandle(int uniqueId, const String8& path, const String8& mimeType) {
Steve Block3856b092011-10-20 11:56:00 +0100181 ALOGV("Entering canHandle");
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900182 return mDrmManager->canHandle(uniqueId, path, mimeType);
183}
184
185DrmInfoStatus* DrmManagerService::processDrmInfo(int uniqueId, const DrmInfo* drmInfo) {
Steve Block3856b092011-10-20 11:56:00 +0100186 ALOGV("Entering processDrmInfo");
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900187 return mDrmManager->processDrmInfo(uniqueId, drmInfo);
188}
189
190DrmInfo* DrmManagerService::acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest) {
Steve Block3856b092011-10-20 11:56:00 +0100191 ALOGV("Entering acquireDrmInfo");
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900192 return mDrmManager->acquireDrmInfo(uniqueId, drmInfoRequest);
193}
194
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900195status_t DrmManagerService::saveRights(
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900196 int uniqueId, const DrmRights& drmRights,
197 const String8& rightsPath, const String8& contentPath) {
Steve Block3856b092011-10-20 11:56:00 +0100198 ALOGV("Entering saveRights");
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900199 return mDrmManager->saveRights(uniqueId, drmRights, rightsPath, contentPath);
200}
201
James Dongbf5b3b22012-07-30 17:57:39 -0700202String8 DrmManagerService::getOriginalMimeType(int uniqueId, const String8& path, int fd) {
Steve Block3856b092011-10-20 11:56:00 +0100203 ALOGV("Entering getOriginalMimeType");
James Dongbf5b3b22012-07-30 17:57:39 -0700204 return mDrmManager->getOriginalMimeType(uniqueId, path, fd);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900205}
206
207int DrmManagerService::getDrmObjectType(
208 int uniqueId, const String8& path, const String8& mimeType) {
Steve Block3856b092011-10-20 11:56:00 +0100209 ALOGV("Entering getDrmObjectType");
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900210 return mDrmManager->getDrmObjectType(uniqueId, path, mimeType);
211}
212
213int DrmManagerService::checkRightsStatus(
214 int uniqueId, const String8& path, int action) {
Steve Block3856b092011-10-20 11:56:00 +0100215 ALOGV("Entering checkRightsStatus");
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900216 return mDrmManager->checkRightsStatus(uniqueId, path, action);
217}
218
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900219status_t DrmManagerService::consumeRights(
Jeff Tinker5d49bef2018-10-03 23:01:09 -0700220 int uniqueId, sp<DecryptHandle>& decryptHandle, int action, bool reserve) {
Steve Block3856b092011-10-20 11:56:00 +0100221 ALOGV("Entering consumeRights");
Riley Spahnf785f492014-07-01 15:32:31 -0700222 if (!isProtectedCallAllowed(CONSUME_RIGHTS)) {
James Dong328745b2012-02-28 13:55:55 -0800223 return DRM_ERROR_NO_PERMISSION;
224 }
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900225 return mDrmManager->consumeRights(uniqueId, decryptHandle, action, reserve);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900226}
227
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900228status_t DrmManagerService::setPlaybackStatus(
Jeff Tinker5d49bef2018-10-03 23:01:09 -0700229 int uniqueId, sp<DecryptHandle>& decryptHandle, int playbackStatus, int64_t position) {
Steve Block3856b092011-10-20 11:56:00 +0100230 ALOGV("Entering setPlaybackStatus");
Riley Spahnf785f492014-07-01 15:32:31 -0700231 if (!isProtectedCallAllowed(SET_PLAYBACK_STATUS)) {
James Dong328745b2012-02-28 13:55:55 -0800232 return DRM_ERROR_NO_PERMISSION;
233 }
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900234 return mDrmManager->setPlaybackStatus(uniqueId, decryptHandle, playbackStatus, position);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900235}
236
237bool DrmManagerService::validateAction(
238 int uniqueId, const String8& path,
239 int action, const ActionDescription& description) {
Steve Block3856b092011-10-20 11:56:00 +0100240 ALOGV("Entering validateAction");
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900241 return mDrmManager->validateAction(uniqueId, path, action, description);
242}
243
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900244status_t DrmManagerService::removeRights(int uniqueId, const String8& path) {
Steve Block3856b092011-10-20 11:56:00 +0100245 ALOGV("Entering removeRights");
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900246 return mDrmManager->removeRights(uniqueId, path);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900247}
248
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900249status_t DrmManagerService::removeAllRights(int uniqueId) {
Steve Block3856b092011-10-20 11:56:00 +0100250 ALOGV("Entering removeAllRights");
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900251 return mDrmManager->removeAllRights(uniqueId);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900252}
253
254int DrmManagerService::openConvertSession(int uniqueId, const String8& mimeType) {
Steve Block3856b092011-10-20 11:56:00 +0100255 ALOGV("Entering openConvertSession");
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900256 return mDrmManager->openConvertSession(uniqueId, mimeType);
257}
258
259DrmConvertedStatus* DrmManagerService::convertData(
260 int uniqueId, int convertId, const DrmBuffer* inputData) {
Steve Block3856b092011-10-20 11:56:00 +0100261 ALOGV("Entering convertData");
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900262 return mDrmManager->convertData(uniqueId, convertId, inputData);
263}
264
265DrmConvertedStatus* DrmManagerService::closeConvertSession(int uniqueId, int convertId) {
Steve Block3856b092011-10-20 11:56:00 +0100266 ALOGV("Entering closeConvertSession");
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900267 return mDrmManager->closeConvertSession(uniqueId, convertId);
268}
269
270status_t DrmManagerService::getAllSupportInfo(
271 int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray) {
Steve Block3856b092011-10-20 11:56:00 +0100272 ALOGV("Entering getAllSupportInfo");
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900273 return mDrmManager->getAllSupportInfo(uniqueId, length, drmSupportInfoArray);
274}
275
Jeff Tinker5d49bef2018-10-03 23:01:09 -0700276sp<DecryptHandle> DrmManagerService::openDecryptSession(
James Dong9d2f3862012-01-10 08:24:37 -0800277 int uniqueId, int fd, off64_t offset, off64_t length, const char* mime) {
Steve Block3856b092011-10-20 11:56:00 +0100278 ALOGV("Entering DrmManagerService::openDecryptSession");
Riley Spahnf785f492014-07-01 15:32:31 -0700279 if (isProtectedCallAllowed(OPEN_DECRYPT_SESSION)) {
James Dong9d2f3862012-01-10 08:24:37 -0800280 return mDrmManager->openDecryptSession(uniqueId, fd, offset, length, mime);
Takeshi Aimi34738462010-11-16 13:56:11 +0900281 }
282
283 return NULL;
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900284}
285
Jeff Tinker5d49bef2018-10-03 23:01:09 -0700286sp<DecryptHandle> DrmManagerService::openDecryptSession(
James Dong9d2f3862012-01-10 08:24:37 -0800287 int uniqueId, const char* uri, const char* mime) {
Steve Block3856b092011-10-20 11:56:00 +0100288 ALOGV("Entering DrmManagerService::openDecryptSession with uri");
Riley Spahnf785f492014-07-01 15:32:31 -0700289 if (isProtectedCallAllowed(OPEN_DECRYPT_SESSION)) {
James Dong9d2f3862012-01-10 08:24:37 -0800290 return mDrmManager->openDecryptSession(uniqueId, uri, mime);
Takeshi Aimi34738462010-11-16 13:56:11 +0900291 }
292
293 return NULL;
Takeshi Aimie943f842010-10-08 23:05:49 +0900294}
295
Jeff Tinker5d49bef2018-10-03 23:01:09 -0700296sp<DecryptHandle> DrmManagerService::openDecryptSession(
Kei Takahashicba7b322012-01-18 17:10:19 +0900297 int uniqueId, const DrmBuffer& buf, const String8& mimeType) {
298 ALOGV("Entering DrmManagerService::openDecryptSession for streaming");
Riley Spahnf785f492014-07-01 15:32:31 -0700299 if (isProtectedCallAllowed(OPEN_DECRYPT_SESSION)) {
Kei Takahashicba7b322012-01-18 17:10:19 +0900300 return mDrmManager->openDecryptSession(uniqueId, buf, mimeType);
301 }
302
303 return NULL;
304}
305
Jeff Tinker5d49bef2018-10-03 23:01:09 -0700306status_t DrmManagerService::closeDecryptSession(int uniqueId, sp<DecryptHandle>& decryptHandle) {
Steve Block3856b092011-10-20 11:56:00 +0100307 ALOGV("Entering closeDecryptSession");
Riley Spahnf785f492014-07-01 15:32:31 -0700308 if (!isProtectedCallAllowed(CLOSE_DECRYPT_SESSION)) {
James Dong328745b2012-02-28 13:55:55 -0800309 return DRM_ERROR_NO_PERMISSION;
310 }
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900311 return mDrmManager->closeDecryptSession(uniqueId, decryptHandle);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900312}
313
Jeff Tinker5d49bef2018-10-03 23:01:09 -0700314status_t DrmManagerService::initializeDecryptUnit(int uniqueId, sp<DecryptHandle>& decryptHandle,
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900315 int decryptUnitId, const DrmBuffer* headerInfo) {
Steve Block3856b092011-10-20 11:56:00 +0100316 ALOGV("Entering initializeDecryptUnit");
Riley Spahnf785f492014-07-01 15:32:31 -0700317 if (!isProtectedCallAllowed(INITIALIZE_DECRYPT_UNIT)) {
James Dong328745b2012-02-28 13:55:55 -0800318 return DRM_ERROR_NO_PERMISSION;
319 }
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900320 return mDrmManager->initializeDecryptUnit(uniqueId,decryptHandle, decryptUnitId, headerInfo);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900321}
322
323status_t DrmManagerService::decrypt(
Jeff Tinker5d49bef2018-10-03 23:01:09 -0700324 int uniqueId, sp<DecryptHandle>& decryptHandle, int decryptUnitId,
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900325 const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) {
Steve Block3856b092011-10-20 11:56:00 +0100326 ALOGV("Entering decrypt");
Riley Spahnf785f492014-07-01 15:32:31 -0700327 if (!isProtectedCallAllowed(DECRYPT)) {
James Dong328745b2012-02-28 13:55:55 -0800328 return DRM_ERROR_NO_PERMISSION;
329 }
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900330 return mDrmManager->decrypt(uniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer, IV);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900331}
332
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900333status_t DrmManagerService::finalizeDecryptUnit(
Jeff Tinker5d49bef2018-10-03 23:01:09 -0700334 int uniqueId, sp<DecryptHandle>& decryptHandle, int decryptUnitId) {
Steve Block3856b092011-10-20 11:56:00 +0100335 ALOGV("Entering finalizeDecryptUnit");
Riley Spahnf785f492014-07-01 15:32:31 -0700336 if (!isProtectedCallAllowed(FINALIZE_DECRYPT_UNIT)) {
James Dong328745b2012-02-28 13:55:55 -0800337 return DRM_ERROR_NO_PERMISSION;
338 }
Takeshi Aimi2272ee22010-09-20 23:40:41 +0900339 return mDrmManager->finalizeDecryptUnit(uniqueId, decryptHandle, decryptUnitId);
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900340}
341
Jeff Tinker5d49bef2018-10-03 23:01:09 -0700342ssize_t DrmManagerService::pread(int uniqueId, sp<DecryptHandle>& decryptHandle,
Gloria Wanga2cd44c2010-11-19 15:19:36 -0800343 void* buffer, ssize_t numBytes, off64_t offset) {
Steve Block3856b092011-10-20 11:56:00 +0100344 ALOGV("Entering pread");
Riley Spahnf785f492014-07-01 15:32:31 -0700345 if (!isProtectedCallAllowed(PREAD)) {
James Dong328745b2012-02-28 13:55:55 -0800346 return DRM_ERROR_NO_PERMISSION;
347 }
aimitakeshi27ed8ad2010-07-29 10:12:27 +0900348 return mDrmManager->pread(uniqueId, decryptHandle, buffer, numBytes, offset);
349}
350
Andy Hung07b745e2016-05-23 16:21:07 -0700351status_t DrmManagerService::dump(int fd, const Vector<String16>& args)
James Dong8635b7b2011-03-14 17:01:38 -0700352{
353 const size_t SIZE = 256;
354 char buffer[SIZE];
355 String8 result;
356 if (checkCallingPermission(String16("android.permission.DUMP")) == false) {
357 snprintf(buffer, SIZE, "Permission Denial: "
358 "can't dump DrmManagerService from pid=%d, uid=%d\n",
359 IPCThreadState::self()->getCallingPid(),
360 IPCThreadState::self()->getCallingUid());
361 result.append(buffer);
362 } else {
363#if DRM_MEMORY_LEAK_TRACK
364 bool dumpMem = false;
365 for (size_t i = 0; i < args.size(); i++) {
366 if (args[i] == String16("-m")) {
367 dumpMem = true;
368 }
369 }
370 if (dumpMem) {
Andy Hung07b745e2016-05-23 16:21:07 -0700371 result.append("\nDumping memory:\n");
372 std::string s = dumpMemoryAddresses(100 /* limit */);
373 result.append(s.c_str(), s.size());
James Dong8635b7b2011-03-14 17:01:38 -0700374 }
Andy Hung07b745e2016-05-23 16:21:07 -0700375#else
376 (void)args;
James Dong8635b7b2011-03-14 17:01:38 -0700377#endif
378 }
Tomasz Wasilczyk09977ff2023-08-11 15:52:22 +0000379 write(fd, result.c_str(), result.size());
James Dong8635b7b2011-03-14 17:01:38 -0700380 return NO_ERROR;
381}
382