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