| 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 "DrmManagerClientImpl(Native)" |
| 19 | #include <utils/Log.h> |
| 20 | |
| 21 | #include <utils/String8.h> |
| 22 | #include <utils/Vector.h> |
| 23 | #include <binder/IServiceManager.h> |
| Adam Lesinski | 927634a | 2014-06-04 15:14:03 -0700 | [diff] [blame] | 24 | #include <cutils/properties.h> |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 25 | |
| 26 | #include "DrmManagerClientImpl.h" |
| Adam Lesinski | 927634a | 2014-06-04 15:14:03 -0700 | [diff] [blame] | 27 | #include "NoOpDrmManagerClientImpl.h" |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 28 | |
| 29 | using namespace android; |
| 30 | |
| Chih-Hung Hsieh | 92c6b82 | 2016-05-17 15:20:14 -0700 | [diff] [blame] | 31 | #define INVALID_VALUE (-1) |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 32 | |
| Gloria Wang | 8d2577b | 2011-03-15 10:52:28 -0700 | [diff] [blame] | 33 | Mutex DrmManagerClientImpl::sMutex; |
| 34 | sp<IDrmManagerService> DrmManagerClientImpl::sDrmManagerService; |
| 35 | sp<DrmManagerClientImpl::DeathNotifier> DrmManagerClientImpl::sDeathNotifier; |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 36 | const String8 DrmManagerClientImpl::EMPTY_STRING(""); |
| 37 | |
| Gloria Wang | 8f00151 | 2011-07-21 15:10:22 -0700 | [diff] [blame] | 38 | DrmManagerClientImpl* DrmManagerClientImpl::create( |
| 39 | int* pUniqueId, bool isNative) { |
| Adam Lesinski | 927634a | 2014-06-04 15:14:03 -0700 | [diff] [blame] | 40 | sp<IDrmManagerService> service = getDrmManagerService(); |
| 41 | if (service != NULL) { |
| 42 | *pUniqueId = getDrmManagerService()->addUniqueId(isNative); |
| 43 | return new DrmManagerClientImpl(); |
| 44 | } |
| 45 | return new NoOpDrmManagerClientImpl(); |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | void DrmManagerClientImpl::remove(int uniqueId) { |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 49 | getDrmManagerService()->removeUniqueId(uniqueId); |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 50 | } |
| 51 | |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 52 | const sp<IDrmManagerService>& DrmManagerClientImpl::getDrmManagerService() { |
| Gloria Wang | 8d2577b | 2011-03-15 10:52:28 -0700 | [diff] [blame] | 53 | Mutex::Autolock lock(sMutex); |
| 54 | if (NULL == sDrmManagerService.get()) { |
| Robert Shih | 0f5969b | 2021-07-02 18:08:13 -0700 | [diff] [blame^] | 55 | sp<IServiceManager> sm = defaultServiceManager(); |
| 56 | sp<IBinder> binder = sm->getService(String16("drm.drmManager")); |
| 57 | if (binder == NULL) { |
| 58 | // Do NOT retry; IServiceManager already waits for ~5 seconds |
| 59 | // in getService if a service doesn't yet exist. |
| Tian Tan | 9ddff08 | 2021-07-13 21:17:24 +0000 | [diff] [blame] | 60 | return sDrmManagerService; |
| 61 | } |
| Gloria Wang | 8d2577b | 2011-03-15 10:52:28 -0700 | [diff] [blame] | 62 | if (NULL == sDeathNotifier.get()) { |
| 63 | sDeathNotifier = new DeathNotifier(); |
| 64 | } |
| 65 | binder->linkToDeath(sDeathNotifier); |
| 66 | sDrmManagerService = interface_cast<IDrmManagerService>(binder); |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 67 | } |
| Gloria Wang | 8d2577b | 2011-03-15 10:52:28 -0700 | [diff] [blame] | 68 | return sDrmManagerService; |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 69 | } |
| 70 | |
| Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 71 | void DrmManagerClientImpl::addClient(int uniqueId) { |
| 72 | getDrmManagerService()->addClient(uniqueId); |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 73 | } |
| 74 | |
| Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 75 | void DrmManagerClientImpl::removeClient(int uniqueId) { |
| 76 | getDrmManagerService()->removeClient(uniqueId); |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | status_t DrmManagerClientImpl::setOnInfoListener( |
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 80 | int uniqueId, |
| 81 | const sp<DrmManagerClient::OnInfoListener>& infoListener) { |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 82 | Mutex::Autolock _l(mLock); |
| 83 | mOnInfoListener = infoListener; |
| Takeshi Aimi | c618b5a | 2010-11-30 16:27:42 +0900 | [diff] [blame] | 84 | return getDrmManagerService()->setDrmServiceListener(uniqueId, |
| 85 | (NULL != infoListener.get()) ? this : NULL); |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 86 | } |
| 87 | |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 88 | DrmConstraints* DrmManagerClientImpl::getConstraints( |
| 89 | int uniqueId, const String8* path, const int action) { |
| 90 | DrmConstraints *drmConstraints = NULL; |
| 91 | if ((NULL != path) && (EMPTY_STRING != *path)) { |
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 92 | drmConstraints = |
| 93 | getDrmManagerService()->getConstraints(uniqueId, path, action); |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 94 | } |
| 95 | return drmConstraints; |
| 96 | } |
| 97 | |
| Takeshi Aimi | 3473846 | 2010-11-16 13:56:11 +0900 | [diff] [blame] | 98 | DrmMetadata* DrmManagerClientImpl::getMetadata(int uniqueId, const String8* path) { |
| 99 | DrmMetadata *drmMetadata = NULL; |
| 100 | if ((NULL != path) && (EMPTY_STRING != *path)) { |
| 101 | drmMetadata = getDrmManagerService()->getMetadata(uniqueId, path); |
| 102 | } |
| 103 | return drmMetadata; |
| 104 | } |
| 105 | |
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 106 | bool DrmManagerClientImpl::canHandle( |
| 107 | int uniqueId, const String8& path, const String8& mimeType) { |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 108 | bool retCode = false; |
| 109 | if ((EMPTY_STRING != path) || (EMPTY_STRING != mimeType)) { |
| 110 | retCode = getDrmManagerService()->canHandle(uniqueId, path, mimeType); |
| 111 | } |
| 112 | return retCode; |
| 113 | } |
| 114 | |
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 115 | DrmInfoStatus* DrmManagerClientImpl::processDrmInfo( |
| 116 | int uniqueId, const DrmInfo* drmInfo) { |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 117 | DrmInfoStatus *drmInfoStatus = NULL; |
| 118 | if (NULL != drmInfo) { |
| 119 | drmInfoStatus = getDrmManagerService()->processDrmInfo(uniqueId, drmInfo); |
| 120 | } |
| 121 | return drmInfoStatus; |
| 122 | } |
| 123 | |
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 124 | DrmInfo* DrmManagerClientImpl::acquireDrmInfo( |
| 125 | int uniqueId, const DrmInfoRequest* drmInfoRequest) { |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 126 | DrmInfo* drmInfo = NULL; |
| 127 | if (NULL != drmInfoRequest) { |
| 128 | drmInfo = getDrmManagerService()->acquireDrmInfo(uniqueId, drmInfoRequest); |
| 129 | } |
| 130 | return drmInfo; |
| 131 | } |
| 132 | |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 133 | status_t DrmManagerClientImpl::saveRights(int uniqueId, const DrmRights& drmRights, |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 134 | const String8& rightsPath, const String8& contentPath) { |
| Gloria Wang | 8d2577b | 2011-03-15 10:52:28 -0700 | [diff] [blame] | 135 | return getDrmManagerService()->saveRights( |
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 136 | uniqueId, drmRights, rightsPath, contentPath); |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 137 | } |
| 138 | |
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 139 | String8 DrmManagerClientImpl::getOriginalMimeType( |
| James Dong | bf5b3b2 | 2012-07-30 17:57:39 -0700 | [diff] [blame] | 140 | int uniqueId, const String8& path, int fd) { |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 141 | String8 mimeType = EMPTY_STRING; |
| 142 | if (EMPTY_STRING != path) { |
| James Dong | bf5b3b2 | 2012-07-30 17:57:39 -0700 | [diff] [blame] | 143 | mimeType = getDrmManagerService()->getOriginalMimeType(uniqueId, path, fd); |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 144 | } |
| 145 | return mimeType; |
| 146 | } |
| 147 | |
| 148 | int DrmManagerClientImpl::getDrmObjectType( |
| 149 | int uniqueId, const String8& path, const String8& mimeType) { |
| 150 | int drmOjectType = DrmObjectType::UNKNOWN; |
| 151 | if ((EMPTY_STRING != path) || (EMPTY_STRING != mimeType)) { |
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 152 | drmOjectType = |
| 153 | getDrmManagerService()->getDrmObjectType(uniqueId, path, mimeType); |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 154 | } |
| 155 | return drmOjectType; |
| 156 | } |
| 157 | |
| 158 | int DrmManagerClientImpl::checkRightsStatus( |
| 159 | int uniqueId, const String8& path, int action) { |
| 160 | int rightsStatus = RightsStatus::RIGHTS_INVALID; |
| 161 | if (EMPTY_STRING != path) { |
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 162 | rightsStatus = |
| 163 | getDrmManagerService()->checkRightsStatus(uniqueId, path, action); |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 164 | } |
| 165 | return rightsStatus; |
| 166 | } |
| 167 | |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 168 | status_t DrmManagerClientImpl::consumeRights( |
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 169 | int uniqueId, sp<DecryptHandle> &decryptHandle, |
| 170 | int action, bool reserve) { |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 171 | status_t status = DRM_ERROR_UNKNOWN; |
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 172 | if (NULL != decryptHandle.get()) { |
| 173 | status = getDrmManagerService()->consumeRights( |
| Jeff Tinker | 5d49bef | 2018-10-03 23:01:09 -0700 | [diff] [blame] | 174 | uniqueId, decryptHandle, action, reserve); |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 175 | } |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 176 | return status; |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 177 | } |
| 178 | |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 179 | status_t DrmManagerClientImpl::setPlaybackStatus( |
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 180 | int uniqueId, sp<DecryptHandle> &decryptHandle, |
| 181 | int playbackStatus, int64_t position) { |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 182 | status_t status = DRM_ERROR_UNKNOWN; |
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 183 | if (NULL != decryptHandle.get()) { |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 184 | status = getDrmManagerService()->setPlaybackStatus( |
| Jeff Tinker | 5d49bef | 2018-10-03 23:01:09 -0700 | [diff] [blame] | 185 | uniqueId, decryptHandle, playbackStatus, position); |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 186 | } |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 187 | return status; |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | bool DrmManagerClientImpl::validateAction( |
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 191 | int uniqueId, const String8& path, |
| 192 | int action, const ActionDescription& description) { |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 193 | bool retCode = false; |
| 194 | if (EMPTY_STRING != path) { |
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 195 | retCode = getDrmManagerService()->validateAction( |
| 196 | uniqueId, path, action, description); |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 197 | } |
| 198 | return retCode; |
| 199 | } |
| 200 | |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 201 | status_t DrmManagerClientImpl::removeRights(int uniqueId, const String8& path) { |
| 202 | status_t status = DRM_ERROR_UNKNOWN; |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 203 | if (EMPTY_STRING != path) { |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 204 | status = getDrmManagerService()->removeRights(uniqueId, path); |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 205 | } |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 206 | return status; |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 207 | } |
| 208 | |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 209 | status_t DrmManagerClientImpl::removeAllRights(int uniqueId) { |
| 210 | return getDrmManagerService()->removeAllRights(uniqueId); |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 211 | } |
| 212 | |
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 213 | int DrmManagerClientImpl::openConvertSession( |
| 214 | int uniqueId, const String8& mimeType) { |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 215 | int retCode = INVALID_VALUE; |
| 216 | if (EMPTY_STRING != mimeType) { |
| 217 | retCode = getDrmManagerService()->openConvertSession(uniqueId, mimeType); |
| 218 | } |
| 219 | return retCode; |
| 220 | } |
| 221 | |
| 222 | DrmConvertedStatus* DrmManagerClientImpl::convertData( |
| 223 | int uniqueId, int convertId, const DrmBuffer* inputData) { |
| 224 | DrmConvertedStatus* drmConvertedStatus = NULL; |
| 225 | if (NULL != inputData) { |
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 226 | drmConvertedStatus = |
| 227 | getDrmManagerService()->convertData(uniqueId, convertId, inputData); |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 228 | } |
| 229 | return drmConvertedStatus; |
| 230 | } |
| 231 | |
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 232 | DrmConvertedStatus* DrmManagerClientImpl::closeConvertSession( |
| 233 | int uniqueId, int convertId) { |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 234 | return getDrmManagerService()->closeConvertSession(uniqueId, convertId); |
| 235 | } |
| 236 | |
| 237 | status_t DrmManagerClientImpl::getAllSupportInfo( |
| 238 | int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray) { |
| 239 | status_t status = DRM_ERROR_UNKNOWN; |
| 240 | if ((NULL != drmSupportInfoArray) && (NULL != length)) { |
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 241 | status = getDrmManagerService()->getAllSupportInfo( |
| 242 | uniqueId, length, drmSupportInfoArray); |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 243 | } |
| 244 | return status; |
| 245 | } |
| 246 | |
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 247 | sp<DecryptHandle> DrmManagerClientImpl::openDecryptSession( |
| James Dong | 9d2f386 | 2012-01-10 08:24:37 -0800 | [diff] [blame] | 248 | int uniqueId, int fd, off64_t offset, |
| 249 | off64_t length, const char* mime) { |
| 250 | |
| 251 | return getDrmManagerService()->openDecryptSession( |
| 252 | uniqueId, fd, offset, length, mime); |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 253 | } |
| 254 | |
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 255 | sp<DecryptHandle> DrmManagerClientImpl::openDecryptSession( |
| James Dong | 9d2f386 | 2012-01-10 08:24:37 -0800 | [diff] [blame] | 256 | int uniqueId, const char* uri, const char* mime) { |
| 257 | |
| Jeff Tinker | 5d49bef | 2018-10-03 23:01:09 -0700 | [diff] [blame] | 258 | sp<DecryptHandle> handle; |
| Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 259 | if (NULL != uri) { |
| James Dong | 9d2f386 | 2012-01-10 08:24:37 -0800 | [diff] [blame] | 260 | handle = getDrmManagerService()->openDecryptSession(uniqueId, uri, mime); |
| Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 261 | } |
| 262 | return handle; |
| 263 | } |
| 264 | |
| Kei Takahashi | cba7b32 | 2012-01-18 17:10:19 +0900 | [diff] [blame] | 265 | sp<DecryptHandle> DrmManagerClientImpl::openDecryptSession( |
| 266 | int uniqueId, const DrmBuffer& buf, const String8& mimeType) { |
| 267 | return getDrmManagerService()->openDecryptSession(uniqueId, buf, mimeType); |
| 268 | } |
| 269 | |
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 270 | status_t DrmManagerClientImpl::closeDecryptSession( |
| 271 | int uniqueId, sp<DecryptHandle> &decryptHandle) { |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 272 | status_t status = DRM_ERROR_UNKNOWN; |
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 273 | if (NULL != decryptHandle.get()) { |
| 274 | status = getDrmManagerService()->closeDecryptSession( |
| Jeff Tinker | 5d49bef | 2018-10-03 23:01:09 -0700 | [diff] [blame] | 275 | uniqueId, decryptHandle); |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 276 | } |
| 277 | return status; |
| 278 | } |
| 279 | |
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 280 | status_t DrmManagerClientImpl::initializeDecryptUnit( |
| 281 | int uniqueId, sp<DecryptHandle> &decryptHandle, |
| 282 | int decryptUnitId, const DrmBuffer* headerInfo) { |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 283 | status_t status = DRM_ERROR_UNKNOWN; |
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 284 | if ((NULL != decryptHandle.get()) && (NULL != headerInfo)) { |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 285 | status = getDrmManagerService()->initializeDecryptUnit( |
| Jeff Tinker | 5d49bef | 2018-10-03 23:01:09 -0700 | [diff] [blame] | 286 | uniqueId, decryptHandle, decryptUnitId, headerInfo); |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 287 | } |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 288 | return status; |
| 289 | } |
| 290 | |
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 291 | status_t DrmManagerClientImpl::decrypt( |
| 292 | int uniqueId, sp<DecryptHandle> &decryptHandle, |
| 293 | int decryptUnitId, const DrmBuffer* encBuffer, |
| 294 | DrmBuffer** decBuffer, DrmBuffer* IV) { |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 295 | status_t status = DRM_ERROR_UNKNOWN; |
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 296 | if ((NULL != decryptHandle.get()) && (NULL != encBuffer) |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 297 | && (NULL != decBuffer) && (NULL != *decBuffer)) { |
| 298 | status = getDrmManagerService()->decrypt( |
| Jeff Tinker | 5d49bef | 2018-10-03 23:01:09 -0700 | [diff] [blame] | 299 | uniqueId, decryptHandle, decryptUnitId, |
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 300 | encBuffer, decBuffer, IV); |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 301 | } |
| 302 | return status; |
| 303 | } |
| 304 | |
| 305 | status_t DrmManagerClientImpl::finalizeDecryptUnit( |
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 306 | int uniqueId, sp<DecryptHandle> &decryptHandle, int decryptUnitId) { |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 307 | status_t status = DRM_ERROR_UNKNOWN; |
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 308 | if (NULL != decryptHandle.get()) { |
| 309 | status = getDrmManagerService()->finalizeDecryptUnit( |
| Jeff Tinker | 5d49bef | 2018-10-03 23:01:09 -0700 | [diff] [blame] | 310 | uniqueId, decryptHandle, decryptUnitId); |
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 311 | } |
| 312 | return status; |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 313 | } |
| 314 | |
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 315 | ssize_t DrmManagerClientImpl::pread(int uniqueId, sp<DecryptHandle> &decryptHandle, |
| Gloria Wang | a2cd44c | 2010-11-19 15:19:36 -0800 | [diff] [blame] | 316 | void* buffer, ssize_t numBytes, off64_t offset) { |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 317 | ssize_t retCode = INVALID_VALUE; |
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 318 | if ((NULL != decryptHandle.get()) && (NULL != buffer) && (0 < numBytes)) { |
| 319 | retCode = getDrmManagerService()->pread( |
| Jeff Tinker | 5d49bef | 2018-10-03 23:01:09 -0700 | [diff] [blame] | 320 | uniqueId, decryptHandle, buffer, numBytes, offset); |
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 321 | } |
| 322 | return retCode; |
| 323 | } |
| 324 | |
| 325 | status_t DrmManagerClientImpl::notify(const DrmInfoEvent& event) { |
| 326 | if (NULL != mOnInfoListener.get()) { |
| 327 | Mutex::Autolock _l(mLock); |
| 328 | sp<DrmManagerClient::OnInfoListener> listener = mOnInfoListener; |
| 329 | listener->onInfo(event); |
| 330 | } |
| 331 | return DRM_NO_ERROR; |
| 332 | } |
| 333 | |
| Gloria Wang | 8d2577b | 2011-03-15 10:52:28 -0700 | [diff] [blame] | 334 | DrmManagerClientImpl::DeathNotifier::~DeathNotifier() { |
| 335 | Mutex::Autolock lock(sMutex); |
| 336 | if (NULL != sDrmManagerService.get()) { |
| Marco Nelissen | 06b4606 | 2014-11-14 07:58:25 -0800 | [diff] [blame] | 337 | IInterface::asBinder(sDrmManagerService)->unlinkToDeath(this); |
| Gloria Wang | 8d2577b | 2011-03-15 10:52:28 -0700 | [diff] [blame] | 338 | } |
| 339 | } |
| 340 | |
| Aurimas Liutikas | c52ca47 | 2016-02-12 13:10:19 -0800 | [diff] [blame] | 341 | void DrmManagerClientImpl::DeathNotifier::binderDied( |
| 342 | const wp<IBinder>& /* who */) { |
| Gloria Wang | 8d2577b | 2011-03-15 10:52:28 -0700 | [diff] [blame] | 343 | Mutex::Autolock lock(sMutex); |
| 344 | DrmManagerClientImpl::sDrmManagerService.clear(); |
| Steve Block | 5ff1dd5 | 2012-01-05 23:22:43 +0000 | [diff] [blame] | 345 | ALOGW("DrmManager server died!"); |
| Gloria Wang | 8d2577b | 2011-03-15 10:52:28 -0700 | [diff] [blame] | 346 | } |
| 347 | |