| 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 |  | 
 | 36 | DrmManagerClientImpl* DrmManagerClientImpl::create(int* pUniqueId) { | 
 | 37 |     if (0 == *pUniqueId) { | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 38 |         int uniqueId = getDrmManagerService()->addUniqueId(*pUniqueId); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 39 |         *pUniqueId = uniqueId; | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 40 |     } else { | 
 | 41 |         getDrmManagerService()->addUniqueId(*pUniqueId); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 42 |     } | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 43 |     return new DrmManagerClientImpl(); | 
 | 44 | } | 
 | 45 |  | 
 | 46 | void DrmManagerClientImpl::remove(int uniqueId) { | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 47 |     getDrmManagerService()->removeUniqueId(uniqueId); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 48 | } | 
 | 49 |  | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 50 | const sp<IDrmManagerService>& DrmManagerClientImpl::getDrmManagerService() { | 
| Gloria Wang | 8d2577b | 2011-03-15 10:52:28 -0700 | [diff] [blame^] | 51 |     Mutex::Autolock lock(sMutex); | 
 | 52 |     if (NULL == sDrmManagerService.get()) { | 
| aimitakeshi | 27ed8ad | 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 | 8d2577b | 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 | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 71 |     } | 
| Gloria Wang | 8d2577b | 2011-03-15 10:52:28 -0700 | [diff] [blame^] | 72 |     return sDrmManagerService; | 
| 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::addClient(int uniqueId) { | 
 | 76 |     getDrmManagerService()->addClient(uniqueId); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 77 | } | 
 | 78 |  | 
| Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 79 | void DrmManagerClientImpl::removeClient(int uniqueId) { | 
 | 80 |     getDrmManagerService()->removeClient(uniqueId); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 81 | } | 
 | 82 |  | 
 | 83 | status_t DrmManagerClientImpl::setOnInfoListener( | 
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 84 |             int uniqueId, | 
 | 85 |             const sp<DrmManagerClient::OnInfoListener>& infoListener) { | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 86 |     Mutex::Autolock _l(mLock); | 
 | 87 |     mOnInfoListener = infoListener; | 
| Takeshi Aimi | c618b5a | 2010-11-30 16:27:42 +0900 | [diff] [blame] | 88 |     return getDrmManagerService()->setDrmServiceListener(uniqueId, | 
 | 89 |             (NULL != infoListener.get()) ? this : NULL); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 90 | } | 
 | 91 |  | 
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 92 | status_t DrmManagerClientImpl::installDrmEngine( | 
 | 93 |         int uniqueId, const String8& drmEngineFile) { | 
| aimitakeshi | 27ed8ad | 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 | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 105 |         drmConstraints = | 
 | 106 |             getDrmManagerService()->getConstraints(uniqueId, path, action); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 107 |     } | 
 | 108 |     return drmConstraints; | 
 | 109 | } | 
 | 110 |  | 
| Takeshi Aimi | 3473846 | 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 | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 119 | bool DrmManagerClientImpl::canHandle( | 
 | 120 |         int uniqueId, const String8& path, const String8& mimeType) { | 
| aimitakeshi | 27ed8ad | 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 | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 128 | DrmInfoStatus* DrmManagerClientImpl::processDrmInfo( | 
 | 129 |         int uniqueId, const DrmInfo* drmInfo) { | 
| aimitakeshi | 27ed8ad | 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 | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 137 | DrmInfo* DrmManagerClientImpl::acquireDrmInfo( | 
 | 138 |         int uniqueId, const DrmInfoRequest* drmInfoRequest) { | 
| aimitakeshi | 27ed8ad | 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 | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 146 | status_t DrmManagerClientImpl::saveRights(int uniqueId, const DrmRights& drmRights, | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 147 |             const String8& rightsPath, const String8& contentPath) { | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 148 |     status_t status = DRM_ERROR_UNKNOWN; | 
| Gloria Wang | 8d2577b | 2011-03-15 10:52:28 -0700 | [diff] [blame^] | 149 |     return getDrmManagerService()->saveRights( | 
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 150 |                 uniqueId, drmRights, rightsPath, contentPath); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 151 | } | 
 | 152 |  | 
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 153 | String8 DrmManagerClientImpl::getOriginalMimeType( | 
 | 154 |         int uniqueId, const String8& path) { | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 155 |     String8 mimeType = EMPTY_STRING; | 
 | 156 |     if (EMPTY_STRING != path) { | 
 | 157 |         mimeType = getDrmManagerService()->getOriginalMimeType(uniqueId, path); | 
 | 158 |     } | 
 | 159 |     return mimeType; | 
 | 160 | } | 
 | 161 |  | 
 | 162 | int DrmManagerClientImpl::getDrmObjectType( | 
 | 163 |             int uniqueId, const String8& path, const String8& mimeType) { | 
 | 164 |     int drmOjectType = DrmObjectType::UNKNOWN; | 
 | 165 |     if ((EMPTY_STRING != path) || (EMPTY_STRING != mimeType)) { | 
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 166 |          drmOjectType = | 
 | 167 |              getDrmManagerService()->getDrmObjectType(uniqueId, path, mimeType); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 168 |     } | 
 | 169 |     return drmOjectType; | 
 | 170 | } | 
 | 171 |  | 
 | 172 | int DrmManagerClientImpl::checkRightsStatus( | 
 | 173 |             int uniqueId, const String8& path, int action) { | 
 | 174 |     int rightsStatus = RightsStatus::RIGHTS_INVALID; | 
 | 175 |     if (EMPTY_STRING != path) { | 
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 176 |         rightsStatus = | 
 | 177 |             getDrmManagerService()->checkRightsStatus(uniqueId, path, action); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 178 |     } | 
 | 179 |     return rightsStatus; | 
 | 180 | } | 
 | 181 |  | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 182 | status_t DrmManagerClientImpl::consumeRights( | 
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 183 |             int uniqueId, sp<DecryptHandle> &decryptHandle, | 
 | 184 |             int action, bool reserve) { | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 185 |     status_t status = DRM_ERROR_UNKNOWN; | 
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 186 |     if (NULL != decryptHandle.get()) { | 
 | 187 |         status = getDrmManagerService()->consumeRights( | 
 | 188 |                 uniqueId, decryptHandle.get(), action, reserve); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 189 |     } | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 190 |     return status; | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 191 | } | 
 | 192 |  | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 193 | status_t DrmManagerClientImpl::setPlaybackStatus( | 
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 194 |             int uniqueId, sp<DecryptHandle> &decryptHandle, | 
 | 195 |             int playbackStatus, int64_t position) { | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 196 |     status_t status = DRM_ERROR_UNKNOWN; | 
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 197 |     if (NULL != decryptHandle.get()) { | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 198 |         status = getDrmManagerService()->setPlaybackStatus( | 
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 199 |                 uniqueId, decryptHandle.get(), playbackStatus, position); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 200 |     } | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 201 |     return status; | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 202 | } | 
 | 203 |  | 
 | 204 | bool DrmManagerClientImpl::validateAction( | 
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 205 |             int uniqueId, const String8& path, | 
 | 206 |             int action, const ActionDescription& description) { | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 207 |     bool retCode = false; | 
 | 208 |     if (EMPTY_STRING != path) { | 
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 209 |         retCode = getDrmManagerService()->validateAction( | 
 | 210 |                 uniqueId, path, action, description); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 211 |     } | 
 | 212 |     return retCode; | 
 | 213 | } | 
 | 214 |  | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 215 | status_t DrmManagerClientImpl::removeRights(int uniqueId, const String8& path) { | 
 | 216 |     status_t status = DRM_ERROR_UNKNOWN; | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 217 |     if (EMPTY_STRING != path) { | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 218 |         status = getDrmManagerService()->removeRights(uniqueId, path); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 219 |     } | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 220 |     return status; | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 221 | } | 
 | 222 |  | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 223 | status_t DrmManagerClientImpl::removeAllRights(int uniqueId) { | 
 | 224 |     return getDrmManagerService()->removeAllRights(uniqueId); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 225 | } | 
 | 226 |  | 
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 227 | int DrmManagerClientImpl::openConvertSession( | 
 | 228 |         int uniqueId, const String8& mimeType) { | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 229 |     int retCode = INVALID_VALUE; | 
 | 230 |     if (EMPTY_STRING != mimeType) { | 
 | 231 |         retCode = getDrmManagerService()->openConvertSession(uniqueId, mimeType); | 
 | 232 |     } | 
 | 233 |     return retCode; | 
 | 234 | } | 
 | 235 |  | 
 | 236 | DrmConvertedStatus* DrmManagerClientImpl::convertData( | 
 | 237 |             int uniqueId, int convertId, const DrmBuffer* inputData) { | 
 | 238 |     DrmConvertedStatus* drmConvertedStatus = NULL; | 
 | 239 |     if (NULL != inputData) { | 
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 240 |          drmConvertedStatus = | 
 | 241 |              getDrmManagerService()->convertData(uniqueId, convertId, inputData); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 242 |     } | 
 | 243 |     return drmConvertedStatus; | 
 | 244 | } | 
 | 245 |  | 
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 246 | DrmConvertedStatus* DrmManagerClientImpl::closeConvertSession( | 
 | 247 |         int uniqueId, int convertId) { | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 248 |     return getDrmManagerService()->closeConvertSession(uniqueId, convertId); | 
 | 249 | } | 
 | 250 |  | 
 | 251 | status_t DrmManagerClientImpl::getAllSupportInfo( | 
 | 252 |             int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray) { | 
 | 253 |     status_t status = DRM_ERROR_UNKNOWN; | 
 | 254 |     if ((NULL != drmSupportInfoArray) && (NULL != length)) { | 
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 255 |         status = getDrmManagerService()->getAllSupportInfo( | 
 | 256 |                 uniqueId, length, drmSupportInfoArray); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 257 |     } | 
 | 258 |     return status; | 
 | 259 | } | 
 | 260 |  | 
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 261 | sp<DecryptHandle> DrmManagerClientImpl::openDecryptSession( | 
| Gloria Wang | a2cd44c | 2010-11-19 15:19:36 -0800 | [diff] [blame] | 262 |             int uniqueId, int fd, off64_t offset, off64_t length) { | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 263 |     return getDrmManagerService()->openDecryptSession(uniqueId, fd, offset, length); | 
 | 264 | } | 
 | 265 |  | 
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 266 | sp<DecryptHandle> DrmManagerClientImpl::openDecryptSession( | 
 | 267 |         int uniqueId, const char* uri) { | 
| Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 268 |     DecryptHandle* handle = NULL; | 
 | 269 |     if (NULL != uri) { | 
 | 270 |         handle = getDrmManagerService()->openDecryptSession(uniqueId, uri); | 
 | 271 |     } | 
 | 272 |     return handle; | 
 | 273 | } | 
 | 274 |  | 
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 275 | status_t DrmManagerClientImpl::closeDecryptSession( | 
 | 276 |         int uniqueId, sp<DecryptHandle> &decryptHandle) { | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 277 |     status_t status = DRM_ERROR_UNKNOWN; | 
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 278 |     if (NULL != decryptHandle.get()) { | 
 | 279 |         status = getDrmManagerService()->closeDecryptSession( | 
 | 280 |                 uniqueId, decryptHandle.get()); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 281 |     } | 
 | 282 |     return status; | 
 | 283 | } | 
 | 284 |  | 
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 285 | status_t DrmManagerClientImpl::initializeDecryptUnit( | 
 | 286 |         int uniqueId, sp<DecryptHandle> &decryptHandle, | 
 | 287 |         int decryptUnitId, const DrmBuffer* headerInfo) { | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 288 |     status_t status = DRM_ERROR_UNKNOWN; | 
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 289 |     if ((NULL != decryptHandle.get()) && (NULL != headerInfo)) { | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 290 |         status = getDrmManagerService()->initializeDecryptUnit( | 
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 291 |                 uniqueId, decryptHandle.get(), decryptUnitId, headerInfo); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 292 |     } | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 293 |     return status; | 
 | 294 | } | 
 | 295 |  | 
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 296 | status_t DrmManagerClientImpl::decrypt( | 
 | 297 |         int uniqueId, sp<DecryptHandle> &decryptHandle, | 
 | 298 |         int decryptUnitId, const DrmBuffer* encBuffer, | 
 | 299 |         DrmBuffer** decBuffer, DrmBuffer* IV) { | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 300 |     status_t status = DRM_ERROR_UNKNOWN; | 
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 301 |     if ((NULL != decryptHandle.get()) && (NULL != encBuffer) | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 302 |         && (NULL != decBuffer) && (NULL != *decBuffer)) { | 
 | 303 |         status = getDrmManagerService()->decrypt( | 
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 304 |                 uniqueId, decryptHandle.get(), decryptUnitId, | 
 | 305 |                 encBuffer, decBuffer, IV); | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 306 |     } | 
 | 307 |     return status; | 
 | 308 | } | 
 | 309 |  | 
 | 310 | status_t DrmManagerClientImpl::finalizeDecryptUnit( | 
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 311 |             int uniqueId, sp<DecryptHandle> &decryptHandle, int decryptUnitId) { | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 312 |     status_t status = DRM_ERROR_UNKNOWN; | 
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 313 |     if (NULL != decryptHandle.get()) { | 
 | 314 |         status = getDrmManagerService()->finalizeDecryptUnit( | 
 | 315 |                     uniqueId, decryptHandle.get(), decryptUnitId); | 
| Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 316 |     } | 
 | 317 |     return status; | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 318 | } | 
 | 319 |  | 
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 320 | ssize_t DrmManagerClientImpl::pread(int uniqueId, sp<DecryptHandle> &decryptHandle, | 
| Gloria Wang | a2cd44c | 2010-11-19 15:19:36 -0800 | [diff] [blame] | 321 |             void* buffer, ssize_t numBytes, off64_t offset) { | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 322 |     ssize_t retCode = INVALID_VALUE; | 
| Gloria Wang | b5ce361 | 2011-02-24 16:40:57 -0800 | [diff] [blame] | 323 |     if ((NULL != decryptHandle.get()) && (NULL != buffer) && (0 < numBytes)) { | 
 | 324 |         retCode = getDrmManagerService()->pread( | 
 | 325 |                 uniqueId, decryptHandle.get(), buffer, numBytes, offset); | 
| aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 326 |     } | 
 | 327 |     return retCode; | 
 | 328 | } | 
 | 329 |  | 
 | 330 | status_t DrmManagerClientImpl::notify(const DrmInfoEvent& event) { | 
 | 331 |     if (NULL != mOnInfoListener.get()) { | 
 | 332 |         Mutex::Autolock _l(mLock); | 
 | 333 |         sp<DrmManagerClient::OnInfoListener> listener = mOnInfoListener; | 
 | 334 |         listener->onInfo(event); | 
 | 335 |     } | 
 | 336 |     return DRM_NO_ERROR; | 
 | 337 | } | 
 | 338 |  | 
| Gloria Wang | 8d2577b | 2011-03-15 10:52:28 -0700 | [diff] [blame^] | 339 | DrmManagerClientImpl::DeathNotifier::~DeathNotifier() { | 
 | 340 |     Mutex::Autolock lock(sMutex); | 
 | 341 |     if (NULL != sDrmManagerService.get()) { | 
 | 342 |         sDrmManagerService->asBinder()->unlinkToDeath(this); | 
 | 343 |     } | 
 | 344 | } | 
 | 345 |  | 
 | 346 | void DrmManagerClientImpl::DeathNotifier::binderDied(const wp<IBinder>& who) { | 
 | 347 |     Mutex::Autolock lock(sMutex); | 
 | 348 |     DrmManagerClientImpl::sDrmManagerService.clear(); | 
 | 349 |     LOGW("DrmManager server died!"); | 
 | 350 | } | 
 | 351 |  |