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