aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 1 | /* |
| 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 Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 17 | //#define LOG_NDEBUG 0 |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 18 | #define LOG_TAG "DrmManagerService(Native)" |
| 19 | #include <utils/Log.h> |
| 20 | |
Takeshi Aimi | 3473846 | 2010-11-16 13:56:11 +0900 | [diff] [blame] | 21 | #include <private/android_filesystem_config.h> |
James Dong | 8635b7b | 2011-03-14 17:01:38 -0700 | [diff] [blame] | 22 | #include <media/MemoryLeakTrackUtil.h> |
Takeshi Aimi | 3473846 | 2010-11-16 13:56:11 +0900 | [diff] [blame] | 23 | |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 24 | #include <errno.h> |
| 25 | #include <utils/threads.h> |
| 26 | #include <binder/IServiceManager.h> |
Takeshi Aimi | 3473846 | 2010-11-16 13:56:11 +0900 | [diff] [blame] | 27 | #include <binder/IPCThreadState.h> |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 28 | #include <sys/stat.h> |
| 29 | #include "DrmManagerService.h" |
| 30 | #include "DrmManager.h" |
| 31 | |
Riley Spahn | f785f49 | 2014-07-01 15:32:31 -0700 | [diff] [blame] | 32 | #include <selinux/android.h> |
| 33 | |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 34 | using namespace android; |
| 35 | |
Riley Spahn | f785f49 | 2014-07-01 15:32:31 -0700 | [diff] [blame] | 36 | static int selinux_enabled; |
| 37 | static char *drmserver_context; |
Takeshi Aimi | 3473846 | 2010-11-16 13:56:11 +0900 | [diff] [blame] | 38 | static Vector<uid_t> trustedUids; |
| 39 | |
Riley Spahn | f785f49 | 2014-07-01 15:32:31 -0700 | [diff] [blame] | 40 | const char *const DrmManagerService::drm_perm_labels[] = { |
| 41 | "consumeRights", |
| 42 | "setPlaybackStatus", |
| 43 | "openDecryptSession", |
| 44 | "closeDecryptSession", |
| 45 | "initializeDecryptUnit", |
| 46 | "decrypt", |
| 47 | "finalizeDecryptUnit", |
| 48 | "pread" |
| 49 | }; |
| 50 | |
| 51 | const char *DrmManagerService::get_perm_label(drm_perm_t perm) { |
| 52 | unsigned int index = perm; |
| 53 | |
Aurimas Liutikas | c903684 | 2016-02-18 15:58:04 -0800 | [diff] [blame] | 54 | if (index >= (sizeof(drm_perm_labels) / sizeof(drm_perm_labels[0]))) { |
Riley Spahn | f785f49 | 2014-07-01 15:32:31 -0700 | [diff] [blame] | 55 | ALOGE("SELinux: Failed to retrieve permission label(perm=%d).\n", perm); |
| 56 | abort(); |
| 57 | } |
| 58 | return drm_perm_labels[index]; |
| 59 | } |
| 60 | |
| 61 | bool DrmManagerService::selinuxIsProtectedCallAllowed(pid_t spid, drm_perm_t perm) { |
| 62 | if (selinux_enabled <= 0) { |
| 63 | return true; |
| 64 | } |
| 65 | |
| 66 | char *sctx; |
| 67 | const char *selinux_class = "drmservice"; |
| 68 | const char *str_perm = get_perm_label(perm); |
| 69 | |
| 70 | if (getpidcon(spid, &sctx) != 0) { |
| 71 | ALOGE("SELinux: getpidcon(pid=%d) failed.\n", spid); |
| 72 | return false; |
| 73 | } |
| 74 | |
| 75 | bool allowed = (selinux_check_access(sctx, drmserver_context, selinux_class, |
| 76 | str_perm, NULL) == 0); |
| 77 | freecon(sctx); |
| 78 | |
| 79 | return allowed; |
| 80 | } |
| 81 | |
| 82 | bool DrmManagerService::isProtectedCallAllowed(drm_perm_t perm) { |
Jeff Tinker | 6868e98 | 2014-06-17 16:45:46 -0700 | [diff] [blame] | 83 | // TODO |
| 84 | // Following implementation is just for reference. |
| 85 | // Each OEM manufacturer should implement/replace with their own solutions. |
| 86 | IPCThreadState* ipcState = IPCThreadState::self(); |
| 87 | uid_t uid = ipcState->getCallingUid(); |
Riley Spahn | f785f49 | 2014-07-01 15:32:31 -0700 | [diff] [blame] | 88 | pid_t spid = ipcState->getCallingPid(); |
Jeff Tinker | 6868e98 | 2014-06-17 16:45:46 -0700 | [diff] [blame] | 89 | |
| 90 | for (unsigned int i = 0; i < trustedUids.size(); ++i) { |
| 91 | if (trustedUids[i] == uid) { |
Riley Spahn | f785f49 | 2014-07-01 15:32:31 -0700 | [diff] [blame] | 92 | return selinuxIsProtectedCallAllowed(spid, perm); |
Jeff Tinker | 6868e98 | 2014-06-17 16:45:46 -0700 | [diff] [blame] | 93 | } |
| 94 | } |
| 95 | return false; |
Takeshi Aimi | 3473846 | 2010-11-16 13:56:11 +0900 | [diff] [blame] | 96 | } |
| 97 | |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 98 | void DrmManagerService::instantiate() { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 99 | ALOGV("instantiate"); |
Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 100 | defaultServiceManager()->addService(String16("drm.drmManager"), new DrmManagerService()); |
Takeshi Aimi | 3473846 | 2010-11-16 13:56:11 +0900 | [diff] [blame] | 101 | |
| 102 | if (0 >= trustedUids.size()) { |
| 103 | // TODO |
| 104 | // Following implementation is just for reference. |
| 105 | // Each OEM manufacturer should implement/replace with their own solutions. |
| 106 | |
| 107 | // Add trusted uids here |
| 108 | trustedUids.push(AID_MEDIA); |
| 109 | } |
Riley Spahn | f785f49 | 2014-07-01 15:32:31 -0700 | [diff] [blame] | 110 | |
| 111 | selinux_enabled = is_selinux_enabled(); |
| 112 | if (selinux_enabled > 0 && getcon(&drmserver_context) != 0) { |
| 113 | ALOGE("SELinux: DrmManagerService failed to get context for DrmManagerService. Aborting.\n"); |
| 114 | abort(); |
| 115 | } |
| 116 | |
| 117 | union selinux_callback cb; |
| 118 | cb.func_log = selinux_log_callback; |
| 119 | selinux_set_callback(SELINUX_CB_LOG, cb); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 120 | } |
| 121 | |
Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 122 | DrmManagerService::DrmManagerService() : |
| 123 | mDrmManager(NULL) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 124 | ALOGV("created"); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 125 | mDrmManager = new DrmManager(); |
Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 126 | mDrmManager->loadPlugIns(); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | DrmManagerService::~DrmManagerService() { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 130 | ALOGV("Destroyed"); |
Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 131 | mDrmManager->unloadPlugIns(); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 132 | delete mDrmManager; mDrmManager = NULL; |
| 133 | } |
| 134 | |
Gloria Wang | 8f00151 | 2011-07-21 15:10:22 -0700 | [diff] [blame] | 135 | int DrmManagerService::addUniqueId(bool isNative) { |
| 136 | return mDrmManager->addUniqueId(isNative); |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | void DrmManagerService::removeUniqueId(int uniqueId) { |
| 140 | mDrmManager->removeUniqueId(uniqueId); |
| 141 | } |
| 142 | |
Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 143 | void DrmManagerService::addClient(int uniqueId) { |
| 144 | mDrmManager->addClient(uniqueId); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 145 | } |
| 146 | |
Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 147 | void DrmManagerService::removeClient(int uniqueId) { |
| 148 | mDrmManager->removeClient(uniqueId); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | status_t DrmManagerService::setDrmServiceListener( |
| 152 | int uniqueId, const sp<IDrmServiceListener>& drmServiceListener) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 153 | ALOGV("Entering setDrmServiceListener"); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 154 | mDrmManager->setDrmServiceListener(uniqueId, drmServiceListener); |
| 155 | return DRM_NO_ERROR; |
| 156 | } |
| 157 | |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 158 | DrmConstraints* DrmManagerService::getConstraints( |
| 159 | int uniqueId, const String8* path, const int action) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 160 | ALOGV("Entering getConstraints from content"); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 161 | return mDrmManager->getConstraints(uniqueId, path, action); |
| 162 | } |
| 163 | |
Takeshi Aimi | 3473846 | 2010-11-16 13:56:11 +0900 | [diff] [blame] | 164 | DrmMetadata* DrmManagerService::getMetadata(int uniqueId, const String8* path) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 165 | ALOGV("Entering getMetadata from content"); |
Takeshi Aimi | 3473846 | 2010-11-16 13:56:11 +0900 | [diff] [blame] | 166 | return mDrmManager->getMetadata(uniqueId, path); |
| 167 | } |
| 168 | |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 169 | bool DrmManagerService::canHandle(int uniqueId, const String8& path, const String8& mimeType) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 170 | ALOGV("Entering canHandle"); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 171 | return mDrmManager->canHandle(uniqueId, path, mimeType); |
| 172 | } |
| 173 | |
| 174 | DrmInfoStatus* DrmManagerService::processDrmInfo(int uniqueId, const DrmInfo* drmInfo) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 175 | ALOGV("Entering processDrmInfo"); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 176 | return mDrmManager->processDrmInfo(uniqueId, drmInfo); |
| 177 | } |
| 178 | |
| 179 | DrmInfo* DrmManagerService::acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInfoRequest) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 180 | ALOGV("Entering acquireDrmInfo"); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 181 | return mDrmManager->acquireDrmInfo(uniqueId, drmInfoRequest); |
| 182 | } |
| 183 | |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 184 | status_t DrmManagerService::saveRights( |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 185 | int uniqueId, const DrmRights& drmRights, |
| 186 | const String8& rightsPath, const String8& contentPath) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 187 | ALOGV("Entering saveRights"); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 188 | return mDrmManager->saveRights(uniqueId, drmRights, rightsPath, contentPath); |
| 189 | } |
| 190 | |
James Dong | bf5b3b2 | 2012-07-30 17:57:39 -0700 | [diff] [blame] | 191 | String8 DrmManagerService::getOriginalMimeType(int uniqueId, const String8& path, int fd) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 192 | ALOGV("Entering getOriginalMimeType"); |
James Dong | bf5b3b2 | 2012-07-30 17:57:39 -0700 | [diff] [blame] | 193 | return mDrmManager->getOriginalMimeType(uniqueId, path, fd); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | int DrmManagerService::getDrmObjectType( |
| 197 | int uniqueId, const String8& path, const String8& mimeType) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 198 | ALOGV("Entering getDrmObjectType"); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 199 | return mDrmManager->getDrmObjectType(uniqueId, path, mimeType); |
| 200 | } |
| 201 | |
| 202 | int DrmManagerService::checkRightsStatus( |
| 203 | int uniqueId, const String8& path, int action) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 204 | ALOGV("Entering checkRightsStatus"); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 205 | return mDrmManager->checkRightsStatus(uniqueId, path, action); |
| 206 | } |
| 207 | |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 208 | status_t DrmManagerService::consumeRights( |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 209 | int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 210 | ALOGV("Entering consumeRights"); |
Riley Spahn | f785f49 | 2014-07-01 15:32:31 -0700 | [diff] [blame] | 211 | if (!isProtectedCallAllowed(CONSUME_RIGHTS)) { |
James Dong | 328745b | 2012-02-28 13:55:55 -0800 | [diff] [blame] | 212 | return DRM_ERROR_NO_PERMISSION; |
| 213 | } |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 214 | return mDrmManager->consumeRights(uniqueId, decryptHandle, action, reserve); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 215 | } |
| 216 | |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 217 | status_t DrmManagerService::setPlaybackStatus( |
Gloria Wang | a2cd44c | 2010-11-19 15:19:36 -0800 | [diff] [blame] | 218 | int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int64_t position) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 219 | ALOGV("Entering setPlaybackStatus"); |
Riley Spahn | f785f49 | 2014-07-01 15:32:31 -0700 | [diff] [blame] | 220 | if (!isProtectedCallAllowed(SET_PLAYBACK_STATUS)) { |
James Dong | 328745b | 2012-02-28 13:55:55 -0800 | [diff] [blame] | 221 | return DRM_ERROR_NO_PERMISSION; |
| 222 | } |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 223 | return mDrmManager->setPlaybackStatus(uniqueId, decryptHandle, playbackStatus, position); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | bool DrmManagerService::validateAction( |
| 227 | int uniqueId, const String8& path, |
| 228 | int action, const ActionDescription& description) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 229 | ALOGV("Entering validateAction"); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 230 | return mDrmManager->validateAction(uniqueId, path, action, description); |
| 231 | } |
| 232 | |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 233 | status_t DrmManagerService::removeRights(int uniqueId, const String8& path) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 234 | ALOGV("Entering removeRights"); |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 235 | return mDrmManager->removeRights(uniqueId, path); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 236 | } |
| 237 | |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 238 | status_t DrmManagerService::removeAllRights(int uniqueId) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 239 | ALOGV("Entering removeAllRights"); |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 240 | return mDrmManager->removeAllRights(uniqueId); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | int DrmManagerService::openConvertSession(int uniqueId, const String8& mimeType) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 244 | ALOGV("Entering openConvertSession"); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 245 | return mDrmManager->openConvertSession(uniqueId, mimeType); |
| 246 | } |
| 247 | |
| 248 | DrmConvertedStatus* DrmManagerService::convertData( |
| 249 | int uniqueId, int convertId, const DrmBuffer* inputData) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 250 | ALOGV("Entering convertData"); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 251 | return mDrmManager->convertData(uniqueId, convertId, inputData); |
| 252 | } |
| 253 | |
| 254 | DrmConvertedStatus* DrmManagerService::closeConvertSession(int uniqueId, int convertId) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 255 | ALOGV("Entering closeConvertSession"); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 256 | return mDrmManager->closeConvertSession(uniqueId, convertId); |
| 257 | } |
| 258 | |
| 259 | status_t DrmManagerService::getAllSupportInfo( |
| 260 | int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 261 | ALOGV("Entering getAllSupportInfo"); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 262 | return mDrmManager->getAllSupportInfo(uniqueId, length, drmSupportInfoArray); |
| 263 | } |
| 264 | |
| 265 | DecryptHandle* DrmManagerService::openDecryptSession( |
James Dong | 9d2f386 | 2012-01-10 08:24:37 -0800 | [diff] [blame] | 266 | int uniqueId, int fd, off64_t offset, off64_t length, const char* mime) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 267 | ALOGV("Entering DrmManagerService::openDecryptSession"); |
Riley Spahn | f785f49 | 2014-07-01 15:32:31 -0700 | [diff] [blame] | 268 | if (isProtectedCallAllowed(OPEN_DECRYPT_SESSION)) { |
James Dong | 9d2f386 | 2012-01-10 08:24:37 -0800 | [diff] [blame] | 269 | return mDrmManager->openDecryptSession(uniqueId, fd, offset, length, mime); |
Takeshi Aimi | 3473846 | 2010-11-16 13:56:11 +0900 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | return NULL; |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 273 | } |
| 274 | |
Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 275 | DecryptHandle* DrmManagerService::openDecryptSession( |
James Dong | 9d2f386 | 2012-01-10 08:24:37 -0800 | [diff] [blame] | 276 | int uniqueId, const char* uri, const char* mime) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 277 | ALOGV("Entering DrmManagerService::openDecryptSession with uri"); |
Riley Spahn | f785f49 | 2014-07-01 15:32:31 -0700 | [diff] [blame] | 278 | if (isProtectedCallAllowed(OPEN_DECRYPT_SESSION)) { |
James Dong | 9d2f386 | 2012-01-10 08:24:37 -0800 | [diff] [blame] | 279 | return mDrmManager->openDecryptSession(uniqueId, uri, mime); |
Takeshi Aimi | 3473846 | 2010-11-16 13:56:11 +0900 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | return NULL; |
Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 283 | } |
| 284 | |
Kei Takahashi | cba7b32 | 2012-01-18 17:10:19 +0900 | [diff] [blame] | 285 | DecryptHandle* DrmManagerService::openDecryptSession( |
| 286 | int uniqueId, const DrmBuffer& buf, const String8& mimeType) { |
| 287 | ALOGV("Entering DrmManagerService::openDecryptSession for streaming"); |
Riley Spahn | f785f49 | 2014-07-01 15:32:31 -0700 | [diff] [blame] | 288 | if (isProtectedCallAllowed(OPEN_DECRYPT_SESSION)) { |
Kei Takahashi | cba7b32 | 2012-01-18 17:10:19 +0900 | [diff] [blame] | 289 | return mDrmManager->openDecryptSession(uniqueId, buf, mimeType); |
| 290 | } |
| 291 | |
| 292 | return NULL; |
| 293 | } |
| 294 | |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 295 | status_t DrmManagerService::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 296 | ALOGV("Entering closeDecryptSession"); |
Riley Spahn | f785f49 | 2014-07-01 15:32:31 -0700 | [diff] [blame] | 297 | if (!isProtectedCallAllowed(CLOSE_DECRYPT_SESSION)) { |
James Dong | 328745b | 2012-02-28 13:55:55 -0800 | [diff] [blame] | 298 | return DRM_ERROR_NO_PERMISSION; |
| 299 | } |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 300 | return mDrmManager->closeDecryptSession(uniqueId, decryptHandle); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 301 | } |
| 302 | |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 303 | status_t DrmManagerService::initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle, |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 304 | int decryptUnitId, const DrmBuffer* headerInfo) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 305 | ALOGV("Entering initializeDecryptUnit"); |
Riley Spahn | f785f49 | 2014-07-01 15:32:31 -0700 | [diff] [blame] | 306 | if (!isProtectedCallAllowed(INITIALIZE_DECRYPT_UNIT)) { |
James Dong | 328745b | 2012-02-28 13:55:55 -0800 | [diff] [blame] | 307 | return DRM_ERROR_NO_PERMISSION; |
| 308 | } |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 309 | return mDrmManager->initializeDecryptUnit(uniqueId,decryptHandle, decryptUnitId, headerInfo); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | status_t DrmManagerService::decrypt( |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 313 | int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, |
| 314 | const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 315 | ALOGV("Entering decrypt"); |
Riley Spahn | f785f49 | 2014-07-01 15:32:31 -0700 | [diff] [blame] | 316 | if (!isProtectedCallAllowed(DECRYPT)) { |
James Dong | 328745b | 2012-02-28 13:55:55 -0800 | [diff] [blame] | 317 | return DRM_ERROR_NO_PERMISSION; |
| 318 | } |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 319 | return mDrmManager->decrypt(uniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer, IV); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 320 | } |
| 321 | |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 322 | status_t DrmManagerService::finalizeDecryptUnit( |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 323 | int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 324 | ALOGV("Entering finalizeDecryptUnit"); |
Riley Spahn | f785f49 | 2014-07-01 15:32:31 -0700 | [diff] [blame] | 325 | if (!isProtectedCallAllowed(FINALIZE_DECRYPT_UNIT)) { |
James Dong | 328745b | 2012-02-28 13:55:55 -0800 | [diff] [blame] | 326 | return DRM_ERROR_NO_PERMISSION; |
| 327 | } |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 328 | return mDrmManager->finalizeDecryptUnit(uniqueId, decryptHandle, decryptUnitId); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | ssize_t DrmManagerService::pread(int uniqueId, DecryptHandle* decryptHandle, |
Gloria Wang | a2cd44c | 2010-11-19 15:19:36 -0800 | [diff] [blame] | 332 | void* buffer, ssize_t numBytes, off64_t offset) { |
Steve Block | 3856b09 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 333 | ALOGV("Entering pread"); |
Riley Spahn | f785f49 | 2014-07-01 15:32:31 -0700 | [diff] [blame] | 334 | if (!isProtectedCallAllowed(PREAD)) { |
James Dong | 328745b | 2012-02-28 13:55:55 -0800 | [diff] [blame] | 335 | return DRM_ERROR_NO_PERMISSION; |
| 336 | } |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 337 | return mDrmManager->pread(uniqueId, decryptHandle, buffer, numBytes, offset); |
| 338 | } |
| 339 | |
Andy Hung | 07b745e | 2016-05-23 16:21:07 -0700 | [diff] [blame] | 340 | status_t DrmManagerService::dump(int fd, const Vector<String16>& args) |
James Dong | 8635b7b | 2011-03-14 17:01:38 -0700 | [diff] [blame] | 341 | { |
| 342 | const size_t SIZE = 256; |
| 343 | char buffer[SIZE]; |
| 344 | String8 result; |
| 345 | if (checkCallingPermission(String16("android.permission.DUMP")) == false) { |
| 346 | snprintf(buffer, SIZE, "Permission Denial: " |
| 347 | "can't dump DrmManagerService from pid=%d, uid=%d\n", |
| 348 | IPCThreadState::self()->getCallingPid(), |
| 349 | IPCThreadState::self()->getCallingUid()); |
| 350 | result.append(buffer); |
| 351 | } else { |
| 352 | #if DRM_MEMORY_LEAK_TRACK |
| 353 | bool dumpMem = false; |
| 354 | for (size_t i = 0; i < args.size(); i++) { |
| 355 | if (args[i] == String16("-m")) { |
| 356 | dumpMem = true; |
| 357 | } |
| 358 | } |
| 359 | if (dumpMem) { |
Andy Hung | 07b745e | 2016-05-23 16:21:07 -0700 | [diff] [blame] | 360 | result.append("\nDumping memory:\n"); |
| 361 | std::string s = dumpMemoryAddresses(100 /* limit */); |
| 362 | result.append(s.c_str(), s.size()); |
James Dong | 8635b7b | 2011-03-14 17:01:38 -0700 | [diff] [blame] | 363 | } |
Andy Hung | 07b745e | 2016-05-23 16:21:07 -0700 | [diff] [blame] | 364 | #else |
| 365 | (void)args; |
James Dong | 8635b7b | 2011-03-14 17:01:38 -0700 | [diff] [blame] | 366 | #endif |
| 367 | } |
| 368 | write(fd, result.string(), result.size()); |
| 369 | return NO_ERROR; |
| 370 | } |
| 371 | |