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