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