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