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 "IDrmManagerService(Native)" |
| 19 | #include <utils/Log.h> |
| 20 | |
| 21 | #include <stdint.h> |
| 22 | #include <sys/types.h> |
| 23 | #include <binder/IPCThreadState.h> |
| 24 | |
| 25 | #include <drm/DrmInfo.h> |
| 26 | #include <drm/DrmConstraints.h> |
| 27 | #include <drm/DrmRights.h> |
| 28 | #include <drm/DrmInfoStatus.h> |
| 29 | #include <drm/DrmConvertedStatus.h> |
| 30 | #include <drm/DrmInfoRequest.h> |
| 31 | #include <drm/DrmSupportInfo.h> |
| 32 | |
| 33 | #include "IDrmManagerService.h" |
| 34 | |
| 35 | #define INVALID_BUFFER_LENGTH -1 |
| 36 | |
| 37 | using namespace android; |
| 38 | |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 39 | int BpDrmManagerService::addUniqueId(int uniqueId) { |
| 40 | LOGV("add uniqueid"); |
| 41 | Parcel data, reply; |
| 42 | data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); |
| 43 | data.writeInt32(uniqueId); |
| 44 | remote()->transact(ADD_UNIQUEID, data, &reply); |
| 45 | return reply.readInt32(); |
| 46 | } |
| 47 | |
| 48 | void BpDrmManagerService::removeUniqueId(int uniqueId) { |
| 49 | LOGV("remove uniqueid"); |
| 50 | Parcel data, reply; |
| 51 | data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); |
| 52 | data.writeInt32(uniqueId); |
| 53 | remote()->transact(REMOVE_UNIQUEID, data, &reply); |
| 54 | } |
| 55 | |
Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame^] | 56 | void BpDrmManagerService::addClient(int uniqueId) { |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 57 | Parcel data, reply; |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 58 | data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); |
| 59 | data.writeInt32(uniqueId); |
Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame^] | 60 | remote()->transact(ADD_CLIENT, data, &reply); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 61 | } |
| 62 | |
Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame^] | 63 | void BpDrmManagerService::removeClient(int uniqueId) { |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 64 | Parcel data, reply; |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 65 | data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); |
| 66 | data.writeInt32(uniqueId); |
Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame^] | 67 | remote()->transact(REMOVE_CLIENT, data, &reply); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | status_t BpDrmManagerService::setDrmServiceListener( |
| 71 | int uniqueId, const sp<IDrmServiceListener>& drmServiceListener) { |
| 72 | LOGV("setDrmServiceListener"); |
| 73 | Parcel data, reply; |
| 74 | |
| 75 | data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); |
| 76 | data.writeInt32(uniqueId); |
| 77 | data.writeStrongBinder(drmServiceListener->asBinder()); |
| 78 | remote()->transact(SET_DRM_SERVICE_LISTENER, data, &reply); |
| 79 | return reply.readInt32(); |
| 80 | } |
| 81 | |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 82 | status_t BpDrmManagerService::installDrmEngine(int uniqueId, const String8& drmEngineFile) { |
| 83 | LOGV("Install DRM Engine"); |
| 84 | Parcel data, reply; |
| 85 | |
| 86 | data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); |
| 87 | data.writeInt32(uniqueId); |
| 88 | data.writeString8(drmEngineFile); |
| 89 | |
| 90 | remote()->transact(INSTALL_DRM_ENGINE, data, &reply); |
| 91 | return reply.readInt32(); |
| 92 | } |
| 93 | |
| 94 | DrmConstraints* BpDrmManagerService::getConstraints( |
| 95 | int uniqueId, const String8* path, const int action) { |
| 96 | LOGV("Get Constraints"); |
| 97 | Parcel data, reply; |
| 98 | |
| 99 | data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); |
| 100 | data.writeInt32(uniqueId); |
| 101 | data.writeString8(*path); |
| 102 | data.writeInt32(action); |
| 103 | |
| 104 | remote()->transact(GET_CONSTRAINTS_FROM_CONTENT, data, &reply); |
| 105 | |
| 106 | DrmConstraints* drmConstraints = NULL; |
| 107 | if (0 != reply.dataAvail()) { |
| 108 | //Filling Drm Constraints |
| 109 | drmConstraints = new DrmConstraints(); |
| 110 | |
| 111 | const int size = reply.readInt32(); |
| 112 | for (int index = 0; index < size; ++index) { |
| 113 | const String8 key(reply.readString8()); |
| 114 | const int bufferSize = reply.readInt32(); |
| 115 | char* data = NULL; |
| 116 | if (0 < bufferSize) { |
| 117 | data = new char[bufferSize]; |
| 118 | reply.read(data, bufferSize); |
| 119 | } |
| 120 | drmConstraints->put(&key, data); |
| 121 | } |
| 122 | } |
| 123 | return drmConstraints; |
| 124 | } |
| 125 | |
| 126 | bool BpDrmManagerService::canHandle(int uniqueId, const String8& path, const String8& mimeType) { |
| 127 | LOGV("Can Handle"); |
| 128 | Parcel data, reply; |
| 129 | |
| 130 | data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); |
| 131 | data.writeInt32(uniqueId); |
| 132 | |
| 133 | data.writeString8(path); |
| 134 | data.writeString8(mimeType); |
| 135 | |
| 136 | remote()->transact(CAN_HANDLE, data, &reply); |
| 137 | |
| 138 | return static_cast<bool>(reply.readInt32()); |
| 139 | } |
| 140 | |
| 141 | DrmInfoStatus* BpDrmManagerService::processDrmInfo(int uniqueId, const DrmInfo* drmInfo) { |
| 142 | LOGV("Process DRM Info"); |
| 143 | Parcel data, reply; |
| 144 | |
| 145 | data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); |
| 146 | data.writeInt32(uniqueId); |
| 147 | |
| 148 | //Filling DRM info |
| 149 | data.writeInt32(drmInfo->getInfoType()); |
| 150 | const DrmBuffer dataBuffer = drmInfo->getData(); |
| 151 | const int dataBufferSize = dataBuffer.length; |
| 152 | data.writeInt32(dataBufferSize); |
| 153 | if (0 < dataBufferSize) { |
| 154 | data.write(dataBuffer.data, dataBufferSize); |
| 155 | } |
| 156 | data.writeString8(drmInfo->getMimeType()); |
| 157 | |
| 158 | data.writeInt32(drmInfo->getCount()); |
| 159 | DrmInfo::KeyIterator keyIt = drmInfo->keyIterator(); |
| 160 | |
| 161 | while (keyIt.hasNext()) { |
| 162 | const String8 key = keyIt.next(); |
| 163 | data.writeString8(key); |
| 164 | const String8 value = drmInfo->get(key); |
| 165 | data.writeString8((value == String8("")) ? String8("NULL") : value); |
| 166 | } |
| 167 | |
| 168 | remote()->transact(PROCESS_DRM_INFO, data, &reply); |
| 169 | |
| 170 | DrmInfoStatus* drmInfoStatus = NULL; |
| 171 | if (0 != reply.dataAvail()) { |
| 172 | //Filling DRM Info Status |
| 173 | const int statusCode = reply.readInt32(); |
Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame^] | 174 | const int infoType = reply.readInt32(); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 175 | const String8 mimeType = reply.readString8(); |
| 176 | |
| 177 | DrmBuffer* drmBuffer = NULL; |
| 178 | if (0 != reply.dataAvail()) { |
| 179 | const int bufferSize = reply.readInt32(); |
| 180 | char* data = NULL; |
| 181 | if (0 < bufferSize) { |
| 182 | data = new char[bufferSize]; |
| 183 | reply.read(data, bufferSize); |
| 184 | } |
| 185 | drmBuffer = new DrmBuffer(data, bufferSize); |
| 186 | } |
Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame^] | 187 | drmInfoStatus = new DrmInfoStatus(statusCode, infoType, drmBuffer, mimeType); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 188 | } |
| 189 | return drmInfoStatus; |
| 190 | } |
| 191 | |
| 192 | DrmInfo* BpDrmManagerService::acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInforequest) { |
| 193 | LOGV("Acquire DRM Info"); |
| 194 | Parcel data, reply; |
| 195 | |
| 196 | data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); |
| 197 | data.writeInt32(uniqueId); |
| 198 | |
| 199 | //Filling DRM Info Request |
| 200 | data.writeInt32(drmInforequest->getInfoType()); |
| 201 | data.writeString8(drmInforequest->getMimeType()); |
| 202 | |
| 203 | data.writeInt32(drmInforequest->getCount()); |
| 204 | DrmInfoRequest::KeyIterator keyIt = drmInforequest->keyIterator(); |
| 205 | |
| 206 | while (keyIt.hasNext()) { |
| 207 | const String8 key = keyIt.next(); |
| 208 | data.writeString8(key); |
| 209 | const String8 value = drmInforequest->get(key); |
| 210 | data.writeString8((value == String8("")) ? String8("NULL") : value); |
| 211 | } |
| 212 | |
| 213 | remote()->transact(ACQUIRE_DRM_INFO, data, &reply); |
| 214 | |
| 215 | DrmInfo* drmInfo = NULL; |
| 216 | if (0 != reply.dataAvail()) { |
| 217 | //Filling DRM Info |
| 218 | const int infoType = reply.readInt32(); |
| 219 | const int bufferSize = reply.readInt32(); |
| 220 | char* data = NULL; |
| 221 | |
| 222 | if (0 < bufferSize) { |
| 223 | data = new char[bufferSize]; |
| 224 | reply.read(data, bufferSize); |
| 225 | } |
| 226 | drmInfo = new DrmInfo(infoType, DrmBuffer(data, bufferSize), reply.readString8()); |
| 227 | |
| 228 | const int size = reply.readInt32(); |
| 229 | for (int index = 0; index < size; ++index) { |
| 230 | const String8 key(reply.readString8()); |
| 231 | const String8 value(reply.readString8()); |
| 232 | drmInfo->put(key, (value == String8("NULL")) ? String8("") : value); |
| 233 | } |
| 234 | } |
| 235 | return drmInfo; |
| 236 | } |
| 237 | |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 238 | status_t BpDrmManagerService::saveRights( |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 239 | int uniqueId, const DrmRights& drmRights, |
| 240 | const String8& rightsPath, const String8& contentPath) { |
| 241 | LOGV("Save Rights"); |
| 242 | Parcel data, reply; |
| 243 | |
| 244 | data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); |
| 245 | data.writeInt32(uniqueId); |
| 246 | |
| 247 | //Filling Drm Rights |
| 248 | const DrmBuffer dataBuffer = drmRights.getData(); |
| 249 | data.writeInt32(dataBuffer.length); |
| 250 | data.write(dataBuffer.data, dataBuffer.length); |
| 251 | |
| 252 | const String8 mimeType = drmRights.getMimeType(); |
| 253 | data.writeString8((mimeType == String8("")) ? String8("NULL") : mimeType); |
| 254 | |
| 255 | const String8 accountId = drmRights.getAccountId(); |
| 256 | data.writeString8((accountId == String8("")) ? String8("NULL") : accountId); |
| 257 | |
| 258 | const String8 subscriptionId = drmRights.getSubscriptionId(); |
| 259 | data.writeString8((subscriptionId == String8("")) ? String8("NULL") : subscriptionId); |
| 260 | |
| 261 | data.writeString8((rightsPath == String8("")) ? String8("NULL") : rightsPath); |
| 262 | data.writeString8((contentPath == String8("")) ? String8("NULL") : contentPath); |
| 263 | |
| 264 | remote()->transact(SAVE_RIGHTS, data, &reply); |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 265 | return reply.readInt32(); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | String8 BpDrmManagerService::getOriginalMimeType(int uniqueId, const String8& path) { |
| 269 | LOGV("Get Original MimeType"); |
| 270 | Parcel data, reply; |
| 271 | |
| 272 | data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); |
| 273 | data.writeInt32(uniqueId); |
| 274 | data.writeString8(path); |
| 275 | |
| 276 | remote()->transact(GET_ORIGINAL_MIMETYPE, data, &reply); |
| 277 | return reply.readString8(); |
| 278 | } |
| 279 | |
| 280 | int BpDrmManagerService::getDrmObjectType( |
| 281 | int uniqueId, const String8& path, const String8& mimeType) { |
| 282 | LOGV("Get Drm object type"); |
| 283 | Parcel data, reply; |
| 284 | |
| 285 | data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); |
| 286 | data.writeInt32(uniqueId); |
| 287 | data.writeString8(path); |
| 288 | data.writeString8(mimeType); |
| 289 | |
| 290 | remote()->transact(GET_DRM_OBJECT_TYPE, data, &reply); |
| 291 | |
| 292 | return reply.readInt32(); |
| 293 | } |
| 294 | |
| 295 | int BpDrmManagerService::checkRightsStatus(int uniqueId, const String8& path, int action) { |
| 296 | LOGV("checkRightsStatus"); |
| 297 | Parcel data, reply; |
| 298 | |
| 299 | data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); |
| 300 | data.writeInt32(uniqueId); |
| 301 | data.writeString8(path); |
| 302 | data.writeInt32(action); |
| 303 | |
| 304 | remote()->transact(CHECK_RIGHTS_STATUS, data, &reply); |
| 305 | |
| 306 | return reply.readInt32(); |
| 307 | } |
| 308 | |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 309 | status_t BpDrmManagerService::consumeRights( |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 310 | int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) { |
| 311 | LOGV("consumeRights"); |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 312 | Parcel data, reply; |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 313 | |
| 314 | data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); |
| 315 | data.writeInt32(uniqueId); |
| 316 | |
| 317 | data.writeInt32(decryptHandle->decryptId); |
| 318 | data.writeString8(decryptHandle->mimeType); |
| 319 | data.writeInt32(decryptHandle->decryptApiType); |
| 320 | data.writeInt32(decryptHandle->status); |
| 321 | |
| 322 | if (NULL != decryptHandle->decryptInfo) { |
| 323 | data.writeInt32(decryptHandle->decryptInfo->decryptBufferLength); |
| 324 | } else { |
| 325 | data.writeInt32(INVALID_BUFFER_LENGTH); |
| 326 | } |
| 327 | |
| 328 | data.writeInt32(action); |
| 329 | data.writeInt32(static_cast< int>(reserve)); |
| 330 | |
| 331 | remote()->transact(CONSUME_RIGHTS, data, &reply); |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 332 | return reply.readInt32(); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 333 | } |
| 334 | |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 335 | status_t BpDrmManagerService::setPlaybackStatus( |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 336 | int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int position) { |
| 337 | LOGV("setPlaybackStatus"); |
| 338 | Parcel data, reply; |
| 339 | |
| 340 | data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); |
| 341 | data.writeInt32(uniqueId); |
| 342 | |
| 343 | data.writeInt32(decryptHandle->decryptId); |
| 344 | data.writeString8(decryptHandle->mimeType); |
| 345 | data.writeInt32(decryptHandle->decryptApiType); |
| 346 | data.writeInt32(decryptHandle->status); |
| 347 | |
| 348 | if (NULL != decryptHandle->decryptInfo) { |
| 349 | data.writeInt32(decryptHandle->decryptInfo->decryptBufferLength); |
| 350 | } else { |
| 351 | data.writeInt32(INVALID_BUFFER_LENGTH); |
| 352 | } |
| 353 | |
| 354 | data.writeInt32(playbackStatus); |
| 355 | data.writeInt32(position); |
| 356 | |
| 357 | remote()->transact(SET_PLAYBACK_STATUS, data, &reply); |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 358 | return reply.readInt32(); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | bool BpDrmManagerService::validateAction( |
| 362 | int uniqueId, const String8& path, |
| 363 | int action, const ActionDescription& description) { |
| 364 | LOGV("validateAction"); |
| 365 | Parcel data, reply; |
| 366 | |
| 367 | data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); |
| 368 | data.writeInt32(uniqueId); |
| 369 | data.writeString8(path); |
| 370 | data.writeInt32(action); |
| 371 | data.writeInt32(description.outputType); |
| 372 | data.writeInt32(description.configuration); |
| 373 | |
| 374 | remote()->transact(VALIDATE_ACTION, data, &reply); |
| 375 | |
| 376 | return static_cast<bool>(reply.readInt32()); |
| 377 | } |
| 378 | |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 379 | status_t BpDrmManagerService::removeRights(int uniqueId, const String8& path) { |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 380 | LOGV("removeRights"); |
| 381 | Parcel data, reply; |
| 382 | |
| 383 | data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); |
| 384 | data.writeInt32(uniqueId); |
| 385 | data.writeString8(path); |
| 386 | |
| 387 | remote()->transact(REMOVE_RIGHTS, data, &reply); |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 388 | return reply.readInt32(); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 389 | } |
| 390 | |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 391 | status_t BpDrmManagerService::removeAllRights(int uniqueId) { |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 392 | LOGV("removeAllRights"); |
| 393 | Parcel data, reply; |
| 394 | |
| 395 | data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); |
| 396 | data.writeInt32(uniqueId); |
| 397 | |
| 398 | remote()->transact(REMOVE_ALL_RIGHTS, data, &reply); |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 399 | return reply.readInt32(); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | int BpDrmManagerService::openConvertSession(int uniqueId, const String8& mimeType) { |
| 403 | LOGV("openConvertSession"); |
| 404 | Parcel data, reply; |
| 405 | |
| 406 | data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); |
| 407 | data.writeInt32(uniqueId); |
| 408 | data.writeString8(mimeType); |
| 409 | |
| 410 | remote()->transact(OPEN_CONVERT_SESSION, data, &reply); |
| 411 | return reply.readInt32(); |
| 412 | } |
| 413 | |
| 414 | DrmConvertedStatus* BpDrmManagerService::convertData( |
| 415 | int uniqueId, int convertId, const DrmBuffer* inputData) { |
| 416 | LOGV("convertData"); |
| 417 | Parcel data, reply; |
| 418 | |
| 419 | data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); |
| 420 | data.writeInt32(uniqueId); |
| 421 | data.writeInt32(convertId); |
| 422 | data.writeInt32(inputData->length); |
| 423 | data.write(inputData->data, inputData->length); |
| 424 | |
| 425 | remote()->transact(CONVERT_DATA, data, &reply); |
| 426 | |
| 427 | DrmConvertedStatus* drmConvertedStatus = NULL; |
| 428 | |
| 429 | if (0 != reply.dataAvail()) { |
| 430 | //Filling DRM Converted Status |
| 431 | const int statusCode = reply.readInt32(); |
| 432 | const int offset = reply.readInt32(); |
| 433 | |
| 434 | DrmBuffer* convertedData = NULL; |
| 435 | if (0 != reply.dataAvail()) { |
| 436 | const int bufferSize = reply.readInt32(); |
| 437 | char* data = NULL; |
| 438 | if (0 < bufferSize) { |
| 439 | data = new char[bufferSize]; |
| 440 | reply.read(data, bufferSize); |
| 441 | } |
| 442 | convertedData = new DrmBuffer(data, bufferSize); |
| 443 | } |
| 444 | drmConvertedStatus = new DrmConvertedStatus(statusCode, convertedData, offset); |
| 445 | } |
| 446 | return drmConvertedStatus; |
| 447 | } |
| 448 | |
| 449 | DrmConvertedStatus* BpDrmManagerService::closeConvertSession(int uniqueId, int convertId) { |
| 450 | LOGV("closeConvertSession"); |
| 451 | Parcel data, reply; |
| 452 | |
| 453 | data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); |
| 454 | data.writeInt32(uniqueId); |
| 455 | data.writeInt32(convertId); |
| 456 | |
| 457 | remote()->transact(CLOSE_CONVERT_SESSION, data, &reply); |
| 458 | |
| 459 | DrmConvertedStatus* drmConvertedStatus = NULL; |
| 460 | |
| 461 | if (0 != reply.dataAvail()) { |
| 462 | //Filling DRM Converted Status |
| 463 | const int statusCode = reply.readInt32(); |
| 464 | const int offset = reply.readInt32(); |
| 465 | |
| 466 | DrmBuffer* convertedData = NULL; |
| 467 | if (0 != reply.dataAvail()) { |
| 468 | const int bufferSize = reply.readInt32(); |
| 469 | char* data = NULL; |
| 470 | if (0 < bufferSize) { |
| 471 | data = new char[bufferSize]; |
| 472 | reply.read(data, bufferSize); |
| 473 | } |
| 474 | convertedData = new DrmBuffer(data, bufferSize); |
| 475 | } |
| 476 | drmConvertedStatus = new DrmConvertedStatus(statusCode, convertedData, offset); |
| 477 | } |
| 478 | return drmConvertedStatus; |
| 479 | } |
| 480 | |
| 481 | status_t BpDrmManagerService::getAllSupportInfo( |
| 482 | int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray) { |
| 483 | LOGV("Get All Support Info"); |
| 484 | Parcel data, reply; |
| 485 | |
| 486 | data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); |
| 487 | data.writeInt32(uniqueId); |
| 488 | |
| 489 | remote()->transact(GET_ALL_SUPPORT_INFO, data, &reply); |
| 490 | |
| 491 | //Filling DRM Support Info |
| 492 | const int arraySize = reply.readInt32(); |
| 493 | if (0 < arraySize) { |
| 494 | *drmSupportInfoArray = new DrmSupportInfo[arraySize]; |
| 495 | |
| 496 | for (int index = 0; index < arraySize; ++index) { |
| 497 | DrmSupportInfo drmSupportInfo; |
| 498 | |
| 499 | const int fileSuffixVectorSize = reply.readInt32(); |
| 500 | for (int i = 0; i < fileSuffixVectorSize; ++i) { |
| 501 | drmSupportInfo.addFileSuffix(reply.readString8()); |
| 502 | } |
| 503 | |
| 504 | const int mimeTypeVectorSize = reply.readInt32(); |
| 505 | for (int i = 0; i < mimeTypeVectorSize; ++i) { |
| 506 | drmSupportInfo.addMimeType(reply.readString8()); |
| 507 | } |
| 508 | |
| 509 | drmSupportInfo.setDescription(reply.readString8()); |
| 510 | (*drmSupportInfoArray)[index] = drmSupportInfo; |
| 511 | } |
| 512 | } |
| 513 | *length = arraySize; |
| 514 | return reply.readInt32(); |
| 515 | } |
| 516 | |
| 517 | DecryptHandle* BpDrmManagerService::openDecryptSession( |
| 518 | int uniqueId, int fd, int offset, int length) { |
| 519 | LOGV("Entering BpDrmManagerService::openDecryptSession"); |
| 520 | Parcel data, reply; |
| 521 | |
Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame^] | 522 | data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 523 | data.writeInt32(uniqueId); |
| 524 | data.writeFileDescriptor(fd); |
| 525 | data.writeInt32(offset); |
| 526 | data.writeInt32(length); |
| 527 | |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 528 | remote()->transact(OPEN_DECRYPT_SESSION, data, &reply); |
| 529 | |
| 530 | DecryptHandle* handle = NULL; |
| 531 | if (0 != reply.dataAvail()) { |
| 532 | handle = new DecryptHandle(); |
| 533 | handle->decryptId = reply.readInt32(); |
| 534 | handle->mimeType = reply.readString8(); |
| 535 | handle->decryptApiType = reply.readInt32(); |
| 536 | handle->status = reply.readInt32(); |
| 537 | handle->decryptInfo = NULL; |
| 538 | if (0 != reply.dataAvail()) { |
| 539 | handle->decryptInfo = new DecryptInfo(); |
| 540 | handle->decryptInfo->decryptBufferLength = reply.readInt32(); |
| 541 | } |
| 542 | } else { |
| 543 | LOGE("no decryptHandle is generated in service side"); |
| 544 | } |
| 545 | return handle; |
| 546 | } |
| 547 | |
Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame^] | 548 | DecryptHandle* BpDrmManagerService::openDecryptSession(int uniqueId, const char* uri) { |
| 549 | LOGV("Entering BpDrmManagerService::openDecryptSession"); |
| 550 | Parcel data, reply; |
| 551 | |
| 552 | data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); |
| 553 | data.writeInt32(uniqueId); |
| 554 | data.writeString8(String8(uri)); |
| 555 | |
| 556 | remote()->transact(OPEN_DECRYPT_SESSION_FROM_URI, data, &reply); |
| 557 | |
| 558 | DecryptHandle* handle = NULL; |
| 559 | if (0 != reply.dataAvail()) { |
| 560 | handle = new DecryptHandle(); |
| 561 | handle->decryptId = reply.readInt32(); |
| 562 | handle->mimeType = reply.readString8(); |
| 563 | handle->decryptApiType = reply.readInt32(); |
| 564 | handle->status = reply.readInt32(); |
| 565 | handle->decryptInfo = NULL; |
| 566 | if (0 != reply.dataAvail()) { |
| 567 | handle->decryptInfo = new DecryptInfo(); |
| 568 | handle->decryptInfo->decryptBufferLength = reply.readInt32(); |
| 569 | } |
| 570 | } else { |
| 571 | LOGE("no decryptHandle is generated in service side"); |
| 572 | } |
| 573 | return handle; |
| 574 | } |
| 575 | |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 576 | status_t BpDrmManagerService::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) { |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 577 | LOGV("closeDecryptSession"); |
| 578 | Parcel data, reply; |
| 579 | |
| 580 | data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); |
| 581 | data.writeInt32(uniqueId); |
| 582 | |
| 583 | data.writeInt32(decryptHandle->decryptId); |
| 584 | data.writeString8(decryptHandle->mimeType); |
| 585 | data.writeInt32(decryptHandle->decryptApiType); |
| 586 | data.writeInt32(decryptHandle->status); |
| 587 | |
| 588 | if (NULL != decryptHandle->decryptInfo) { |
| 589 | data.writeInt32(decryptHandle->decryptInfo->decryptBufferLength); |
| 590 | } else { |
| 591 | data.writeInt32(INVALID_BUFFER_LENGTH); |
| 592 | } |
| 593 | |
| 594 | remote()->transact(CLOSE_DECRYPT_SESSION, data, &reply); |
| 595 | |
| 596 | if (NULL != decryptHandle->decryptInfo) { |
| 597 | LOGV("deleting decryptInfo"); |
| 598 | delete decryptHandle->decryptInfo; decryptHandle->decryptInfo = NULL; |
| 599 | } |
| 600 | delete decryptHandle; decryptHandle = NULL; |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 601 | return reply.readInt32(); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 602 | } |
| 603 | |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 604 | status_t BpDrmManagerService::initializeDecryptUnit( |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 605 | int uniqueId, DecryptHandle* decryptHandle, |
| 606 | int decryptUnitId, const DrmBuffer* headerInfo) { |
| 607 | LOGV("initializeDecryptUnit"); |
| 608 | Parcel data, reply; |
| 609 | |
| 610 | data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); |
| 611 | data.writeInt32(uniqueId); |
| 612 | |
| 613 | data.writeInt32(decryptHandle->decryptId); |
| 614 | data.writeString8(decryptHandle->mimeType); |
| 615 | data.writeInt32(decryptHandle->decryptApiType); |
| 616 | data.writeInt32(decryptHandle->status); |
| 617 | |
| 618 | if (NULL != decryptHandle->decryptInfo) { |
| 619 | data.writeInt32(decryptHandle->decryptInfo->decryptBufferLength); |
| 620 | } else { |
| 621 | data.writeInt32(INVALID_BUFFER_LENGTH); |
| 622 | } |
| 623 | data.writeInt32(decryptUnitId); |
| 624 | |
| 625 | data.writeInt32(headerInfo->length); |
| 626 | data.write(headerInfo->data, headerInfo->length); |
| 627 | |
| 628 | remote()->transact(INITIALIZE_DECRYPT_UNIT, data, &reply); |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 629 | return reply.readInt32(); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | status_t BpDrmManagerService::decrypt( |
| 633 | int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 634 | const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) { |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 635 | LOGV("decrypt"); |
| 636 | Parcel data, reply; |
| 637 | |
| 638 | data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); |
| 639 | data.writeInt32(uniqueId); |
| 640 | |
| 641 | data.writeInt32(decryptHandle->decryptId); |
| 642 | data.writeString8(decryptHandle->mimeType); |
| 643 | data.writeInt32(decryptHandle->decryptApiType); |
| 644 | data.writeInt32(decryptHandle->status); |
| 645 | |
| 646 | if (NULL != decryptHandle->decryptInfo) { |
| 647 | data.writeInt32(decryptHandle->decryptInfo->decryptBufferLength); |
| 648 | } else { |
| 649 | data.writeInt32(INVALID_BUFFER_LENGTH); |
| 650 | } |
| 651 | |
| 652 | data.writeInt32(decryptUnitId); |
| 653 | data.writeInt32((*decBuffer)->length); |
| 654 | |
| 655 | data.writeInt32(encBuffer->length); |
| 656 | data.write(encBuffer->data, encBuffer->length); |
| 657 | |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 658 | if (NULL != IV) { |
| 659 | data.writeInt32(IV->length); |
| 660 | data.write(IV->data, IV->length); |
| 661 | } |
| 662 | |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 663 | remote()->transact(DECRYPT, data, &reply); |
| 664 | |
| 665 | const status_t status = reply.readInt32(); |
| 666 | LOGV("Return value of decrypt() is %d", status); |
| 667 | |
| 668 | const int size = reply.readInt32(); |
| 669 | (*decBuffer)->length = size; |
| 670 | reply.read((void *)(*decBuffer)->data, size); |
| 671 | |
| 672 | return status; |
| 673 | } |
| 674 | |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 675 | status_t BpDrmManagerService::finalizeDecryptUnit( |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 676 | int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) { |
| 677 | LOGV("finalizeDecryptUnit"); |
| 678 | Parcel data, reply; |
| 679 | |
| 680 | data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); |
| 681 | data.writeInt32(uniqueId); |
| 682 | |
| 683 | data.writeInt32(decryptHandle->decryptId); |
| 684 | data.writeString8(decryptHandle->mimeType); |
| 685 | data.writeInt32(decryptHandle->decryptApiType); |
| 686 | data.writeInt32(decryptHandle->status); |
| 687 | |
| 688 | if (NULL != decryptHandle->decryptInfo) { |
| 689 | data.writeInt32(decryptHandle->decryptInfo->decryptBufferLength); |
| 690 | } else { |
| 691 | data.writeInt32(INVALID_BUFFER_LENGTH); |
| 692 | } |
| 693 | |
| 694 | data.writeInt32(decryptUnitId); |
| 695 | |
| 696 | remote()->transact(FINALIZE_DECRYPT_UNIT, data, &reply); |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 697 | return reply.readInt32(); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | ssize_t BpDrmManagerService::pread( |
| 701 | int uniqueId, DecryptHandle* decryptHandle, void* buffer, |
| 702 | ssize_t numBytes, off_t offset) { |
| 703 | LOGV("read"); |
| 704 | Parcel data, reply; |
| 705 | int result; |
| 706 | |
| 707 | data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); |
| 708 | data.writeInt32(uniqueId); |
| 709 | |
| 710 | data.writeInt32(decryptHandle->decryptId); |
| 711 | data.writeString8(decryptHandle->mimeType); |
| 712 | data.writeInt32(decryptHandle->decryptApiType); |
| 713 | data.writeInt32(decryptHandle->status); |
| 714 | |
| 715 | if (NULL != decryptHandle->decryptInfo) { |
| 716 | data.writeInt32(decryptHandle->decryptInfo->decryptBufferLength); |
| 717 | } else { |
| 718 | data.writeInt32(INVALID_BUFFER_LENGTH); |
| 719 | } |
| 720 | |
| 721 | data.writeInt32(numBytes); |
| 722 | data.writeInt32(offset); |
| 723 | |
| 724 | remote()->transact(PREAD, data, &reply); |
| 725 | result = reply.readInt32(); |
| 726 | if (0 < result) { |
| 727 | reply.read(buffer, result); |
| 728 | } |
| 729 | return result; |
| 730 | } |
| 731 | |
| 732 | IMPLEMENT_META_INTERFACE(DrmManagerService, "drm.IDrmManagerService"); |
| 733 | |
| 734 | status_t BnDrmManagerService::onTransact( |
| 735 | uint32_t code, const Parcel& data, |
| 736 | Parcel* reply, uint32_t flags) { |
| 737 | LOGV("Entering BnDrmManagerService::onTransact with code %d", code); |
| 738 | |
| 739 | switch (code) { |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 740 | case ADD_UNIQUEID: |
| 741 | { |
| 742 | LOGV("BnDrmManagerService::onTransact :ADD_UNIQUEID"); |
| 743 | CHECK_INTERFACE(IDrmManagerService, data, reply); |
| 744 | int uniqueId = addUniqueId(data.readInt32()); |
| 745 | reply->writeInt32(uniqueId); |
| 746 | return DRM_NO_ERROR; |
| 747 | } |
| 748 | |
| 749 | case REMOVE_UNIQUEID: |
| 750 | { |
| 751 | LOGV("BnDrmManagerService::onTransact :REMOVE_UNIQUEID"); |
| 752 | CHECK_INTERFACE(IDrmManagerService, data, reply); |
| 753 | removeUniqueId(data.readInt32()); |
| 754 | return DRM_NO_ERROR; |
| 755 | } |
| 756 | |
Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame^] | 757 | case ADD_CLIENT: |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 758 | { |
Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame^] | 759 | LOGV("BnDrmManagerService::onTransact :ADD_CLIENT"); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 760 | CHECK_INTERFACE(IDrmManagerService, data, reply); |
Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame^] | 761 | addClient(data.readInt32()); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 762 | return DRM_NO_ERROR; |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 763 | } |
| 764 | |
Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame^] | 765 | case REMOVE_CLIENT: |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 766 | { |
Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame^] | 767 | LOGV("BnDrmManagerService::onTransact :REMOVE_CLIENT"); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 768 | CHECK_INTERFACE(IDrmManagerService, data, reply); |
Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame^] | 769 | removeClient(data.readInt32()); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 770 | return DRM_NO_ERROR; |
| 771 | } |
| 772 | |
| 773 | case SET_DRM_SERVICE_LISTENER: |
| 774 | { |
| 775 | LOGV("BnDrmManagerService::onTransact :SET_DRM_SERVICE_LISTENER"); |
| 776 | CHECK_INTERFACE(IDrmManagerService, data, reply); |
| 777 | |
| 778 | const int uniqueId = data.readInt32(); |
| 779 | const sp<IDrmServiceListener> drmServiceListener |
| 780 | = interface_cast<IDrmServiceListener> (data.readStrongBinder()); |
| 781 | |
| 782 | status_t status = setDrmServiceListener(uniqueId, drmServiceListener); |
| 783 | |
| 784 | reply->writeInt32(status); |
| 785 | return DRM_NO_ERROR; |
| 786 | } |
| 787 | |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 788 | case INSTALL_DRM_ENGINE: |
| 789 | { |
| 790 | LOGV("BnDrmManagerService::onTransact :INSTALL_DRM_ENGINE"); |
| 791 | CHECK_INTERFACE(IDrmManagerService, data, reply); |
| 792 | |
| 793 | status_t status = installDrmEngine(data.readInt32(), data.readString8()); |
| 794 | |
| 795 | reply->writeInt32(status); |
| 796 | return DRM_NO_ERROR; |
| 797 | } |
| 798 | |
| 799 | case GET_CONSTRAINTS_FROM_CONTENT: |
| 800 | { |
| 801 | LOGV("BnDrmManagerService::onTransact :GET_CONSTRAINTS_FROM_CONTENT"); |
| 802 | CHECK_INTERFACE(IDrmManagerService, data, reply); |
| 803 | |
| 804 | const int uniqueId = data.readInt32(); |
| 805 | const String8 path = data.readString8(); |
| 806 | |
| 807 | DrmConstraints* drmConstraints = getConstraints(uniqueId, &path, data.readInt32()); |
| 808 | |
| 809 | if (NULL != drmConstraints) { |
| 810 | //Filling DRM Constraints contents |
| 811 | reply->writeInt32(drmConstraints->getCount()); |
| 812 | |
| 813 | DrmConstraints::KeyIterator keyIt = drmConstraints->keyIterator(); |
| 814 | while (keyIt.hasNext()) { |
| 815 | const String8 key = keyIt.next(); |
| 816 | reply->writeString8(key); |
| 817 | const char* value = drmConstraints->getAsByteArray(&key); |
| 818 | int bufferSize = 0; |
| 819 | if (NULL != value) { |
| 820 | bufferSize = strlen(value); |
| 821 | } |
| 822 | reply->writeInt32(bufferSize + 1); |
| 823 | reply->write(value, bufferSize + 1); |
| 824 | } |
| 825 | } |
| 826 | delete drmConstraints; drmConstraints = NULL; |
| 827 | return DRM_NO_ERROR; |
| 828 | } |
| 829 | |
| 830 | case CAN_HANDLE: |
| 831 | { |
| 832 | LOGV("BnDrmManagerService::onTransact :CAN_HANDLE"); |
| 833 | CHECK_INTERFACE(IDrmManagerService, data, reply); |
| 834 | |
| 835 | const int uniqueId = data.readInt32(); |
| 836 | const String8 path = data.readString8(); |
| 837 | const String8 mimeType = data.readString8(); |
| 838 | |
| 839 | bool result = canHandle(uniqueId, path, mimeType); |
| 840 | |
| 841 | reply->writeInt32(result); |
| 842 | return DRM_NO_ERROR; |
| 843 | } |
| 844 | |
| 845 | case PROCESS_DRM_INFO: |
| 846 | { |
| 847 | LOGV("BnDrmManagerService::onTransact :PROCESS_DRM_INFO"); |
| 848 | CHECK_INTERFACE(IDrmManagerService, data, reply); |
| 849 | |
| 850 | const int uniqueId = data.readInt32(); |
| 851 | |
| 852 | //Filling DRM info |
| 853 | const int infoType = data.readInt32(); |
| 854 | const int bufferSize = data.readInt32(); |
| 855 | char* buffer = NULL; |
| 856 | if (0 < bufferSize) { |
| 857 | buffer = (char *)data.readInplace(bufferSize); |
| 858 | } |
| 859 | const DrmBuffer drmBuffer(buffer, bufferSize); |
| 860 | DrmInfo* drmInfo = new DrmInfo(infoType, drmBuffer, data.readString8()); |
| 861 | |
| 862 | const int size = data.readInt32(); |
| 863 | for (int index = 0; index < size; ++index) { |
| 864 | const String8 key(data.readString8()); |
| 865 | const String8 value(data.readString8()); |
| 866 | drmInfo->put(key, (value == String8("NULL")) ? String8("") : value); |
| 867 | } |
| 868 | |
| 869 | DrmInfoStatus* drmInfoStatus = processDrmInfo(uniqueId, drmInfo); |
| 870 | |
| 871 | if (NULL != drmInfoStatus) { |
| 872 | //Filling DRM Info Status contents |
| 873 | reply->writeInt32(drmInfoStatus->statusCode); |
Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame^] | 874 | reply->writeInt32(drmInfoStatus->infoType); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 875 | reply->writeString8(drmInfoStatus->mimeType); |
| 876 | |
| 877 | if (NULL != drmInfoStatus->drmBuffer) { |
| 878 | const DrmBuffer* drmBuffer = drmInfoStatus->drmBuffer; |
| 879 | const int bufferSize = drmBuffer->length; |
| 880 | reply->writeInt32(bufferSize); |
| 881 | if (0 < bufferSize) { |
| 882 | reply->write(drmBuffer->data, bufferSize); |
| 883 | } |
| 884 | delete [] drmBuffer->data; |
| 885 | delete drmBuffer; drmBuffer = NULL; |
| 886 | } |
| 887 | } |
| 888 | delete drmInfo; drmInfo = NULL; |
| 889 | delete drmInfoStatus; drmInfoStatus = NULL; |
| 890 | return DRM_NO_ERROR; |
| 891 | } |
| 892 | |
| 893 | case ACQUIRE_DRM_INFO: |
| 894 | { |
| 895 | LOGV("BnDrmManagerService::onTransact :ACQUIRE_DRM_INFO"); |
| 896 | CHECK_INTERFACE(IDrmManagerService, data, reply); |
| 897 | |
| 898 | const int uniqueId = data.readInt32(); |
| 899 | |
| 900 | //Filling DRM info Request |
| 901 | DrmInfoRequest* drmInfoRequest = new DrmInfoRequest(data.readInt32(), data.readString8()); |
| 902 | |
| 903 | const int size = data.readInt32(); |
| 904 | for (int index = 0; index < size; ++index) { |
| 905 | const String8 key(data.readString8()); |
| 906 | const String8 value(data.readString8()); |
| 907 | drmInfoRequest->put(key, (value == String8("NULL")) ? String8("") : value); |
| 908 | } |
| 909 | |
| 910 | DrmInfo* drmInfo = acquireDrmInfo(uniqueId, drmInfoRequest); |
| 911 | |
| 912 | if (NULL != drmInfo) { |
| 913 | //Filling DRM Info |
| 914 | const DrmBuffer drmBuffer = drmInfo->getData(); |
| 915 | reply->writeInt32(drmInfo->getInfoType()); |
| 916 | |
| 917 | const int bufferSize = drmBuffer.length; |
| 918 | reply->writeInt32(bufferSize); |
| 919 | if (0 < bufferSize) { |
| 920 | reply->write(drmBuffer.data, bufferSize); |
| 921 | } |
| 922 | reply->writeString8(drmInfo->getMimeType()); |
| 923 | reply->writeInt32(drmInfo->getCount()); |
| 924 | |
| 925 | DrmInfo::KeyIterator keyIt = drmInfo->keyIterator(); |
| 926 | while (keyIt.hasNext()) { |
| 927 | const String8 key = keyIt.next(); |
| 928 | reply->writeString8(key); |
| 929 | const String8 value = drmInfo->get(key); |
| 930 | reply->writeString8((value == String8("")) ? String8("NULL") : value); |
| 931 | } |
| 932 | delete [] drmBuffer.data; |
| 933 | } |
| 934 | delete drmInfoRequest; drmInfoRequest = NULL; |
| 935 | delete drmInfo; drmInfo = NULL; |
| 936 | return DRM_NO_ERROR; |
| 937 | } |
| 938 | |
| 939 | case SAVE_RIGHTS: |
| 940 | { |
| 941 | LOGV("BnDrmManagerService::onTransact :SAVE_RIGHTS"); |
| 942 | CHECK_INTERFACE(IDrmManagerService, data, reply); |
| 943 | |
| 944 | const int uniqueId = data.readInt32(); |
| 945 | |
| 946 | //Filling DRM Rights |
| 947 | const int bufferSize = data.readInt32(); |
| 948 | const DrmBuffer drmBuffer((char *)data.readInplace(bufferSize), bufferSize); |
| 949 | |
| 950 | const String8 mimeType(data.readString8()); |
| 951 | const String8 accountId(data.readString8()); |
| 952 | const String8 subscriptionId(data.readString8()); |
| 953 | const String8 rightsPath(data.readString8()); |
| 954 | const String8 contentPath(data.readString8()); |
| 955 | |
| 956 | DrmRights drmRights(drmBuffer, |
| 957 | ((mimeType == String8("NULL")) ? String8("") : mimeType), |
| 958 | ((accountId == String8("NULL")) ? String8("") : accountId), |
| 959 | ((subscriptionId == String8("NULL")) ? String8("") : subscriptionId)); |
| 960 | |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 961 | const status_t status = saveRights(uniqueId, drmRights, |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 962 | ((rightsPath == String8("NULL")) ? String8("") : rightsPath), |
| 963 | ((contentPath == String8("NULL")) ? String8("") : contentPath)); |
| 964 | |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 965 | reply->writeInt32(status); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 966 | return DRM_NO_ERROR; |
| 967 | } |
| 968 | |
| 969 | case GET_ORIGINAL_MIMETYPE: |
| 970 | { |
| 971 | LOGV("BnDrmManagerService::onTransact :GET_ORIGINAL_MIMETYPE"); |
| 972 | CHECK_INTERFACE(IDrmManagerService, data, reply); |
| 973 | |
| 974 | const String8 originalMimeType = getOriginalMimeType(data.readInt32(), data.readString8()); |
| 975 | |
| 976 | reply->writeString8(originalMimeType); |
| 977 | return DRM_NO_ERROR; |
| 978 | } |
| 979 | |
| 980 | case GET_DRM_OBJECT_TYPE: |
| 981 | { |
| 982 | LOGV("BnDrmManagerService::onTransact :GET_DRM_OBJECT_TYPE"); |
| 983 | CHECK_INTERFACE(IDrmManagerService, data, reply); |
| 984 | |
| 985 | const int drmObjectType |
| 986 | = getDrmObjectType(data.readInt32(), data.readString8(), data.readString8()); |
| 987 | |
| 988 | reply->writeInt32(drmObjectType); |
| 989 | return DRM_NO_ERROR; |
| 990 | } |
| 991 | |
| 992 | case CHECK_RIGHTS_STATUS: |
| 993 | { |
| 994 | LOGV("BnDrmManagerService::onTransact :CHECK_RIGHTS_STATUS"); |
| 995 | CHECK_INTERFACE(IDrmManagerService, data, reply); |
| 996 | |
| 997 | const int result |
| 998 | = checkRightsStatus(data.readInt32(), data.readString8(), data.readInt32()); |
| 999 | |
| 1000 | reply->writeInt32(result); |
| 1001 | return DRM_NO_ERROR; |
| 1002 | } |
| 1003 | |
| 1004 | case CONSUME_RIGHTS: |
| 1005 | { |
| 1006 | LOGV("BnDrmManagerService::onTransact :CONSUME_RIGHTS"); |
| 1007 | CHECK_INTERFACE(IDrmManagerService, data, reply); |
| 1008 | |
| 1009 | const int uniqueId = data.readInt32(); |
| 1010 | |
| 1011 | DecryptHandle handle; |
| 1012 | handle.decryptId = data.readInt32(); |
| 1013 | handle.mimeType = data.readString8(); |
| 1014 | handle.decryptApiType = data.readInt32(); |
| 1015 | handle.status = data.readInt32(); |
| 1016 | handle.decryptInfo = NULL; |
| 1017 | |
| 1018 | const int bufferLength = data.readInt32(); |
| 1019 | if (INVALID_BUFFER_LENGTH != bufferLength) { |
| 1020 | handle.decryptInfo = new DecryptInfo(); |
| 1021 | handle.decryptInfo->decryptBufferLength = bufferLength; |
| 1022 | } |
| 1023 | |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 1024 | const status_t status |
| 1025 | = consumeRights(uniqueId, &handle, data.readInt32(), |
| 1026 | static_cast<bool>(data.readInt32())); |
| 1027 | reply->writeInt32(status); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 1028 | |
| 1029 | delete handle.decryptInfo; handle.decryptInfo = NULL; |
| 1030 | return DRM_NO_ERROR; |
| 1031 | } |
| 1032 | |
| 1033 | case SET_PLAYBACK_STATUS: |
| 1034 | { |
| 1035 | LOGV("BnDrmManagerService::onTransact :SET_PLAYBACK_STATUS"); |
| 1036 | CHECK_INTERFACE(IDrmManagerService, data, reply); |
| 1037 | |
| 1038 | const int uniqueId = data.readInt32(); |
| 1039 | |
| 1040 | DecryptHandle handle; |
| 1041 | handle.decryptId = data.readInt32(); |
| 1042 | handle.mimeType = data.readString8(); |
| 1043 | handle.decryptApiType = data.readInt32(); |
| 1044 | handle.status = data.readInt32(); |
| 1045 | handle.decryptInfo = NULL; |
| 1046 | |
| 1047 | const int bufferLength = data.readInt32(); |
| 1048 | if (INVALID_BUFFER_LENGTH != bufferLength) { |
| 1049 | handle.decryptInfo = new DecryptInfo(); |
| 1050 | handle.decryptInfo->decryptBufferLength = bufferLength; |
| 1051 | } |
| 1052 | |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 1053 | const status_t status |
| 1054 | = setPlaybackStatus(uniqueId, &handle, data.readInt32(), data.readInt32()); |
| 1055 | reply->writeInt32(status); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 1056 | |
| 1057 | delete handle.decryptInfo; handle.decryptInfo = NULL; |
| 1058 | return DRM_NO_ERROR; |
| 1059 | } |
| 1060 | |
| 1061 | case VALIDATE_ACTION: |
| 1062 | { |
| 1063 | LOGV("BnDrmManagerService::onTransact :VALIDATE_ACTION"); |
| 1064 | CHECK_INTERFACE(IDrmManagerService, data, reply); |
| 1065 | |
| 1066 | bool result = validateAction( |
| 1067 | data.readInt32(), |
| 1068 | data.readString8(), |
| 1069 | data.readInt32(), |
| 1070 | ActionDescription(data.readInt32(), data.readInt32())); |
| 1071 | |
| 1072 | reply->writeInt32(result); |
| 1073 | return DRM_NO_ERROR; |
| 1074 | } |
| 1075 | |
| 1076 | case REMOVE_RIGHTS: |
| 1077 | { |
| 1078 | LOGV("BnDrmManagerService::onTransact :REMOVE_RIGHTS"); |
| 1079 | CHECK_INTERFACE(IDrmManagerService, data, reply); |
| 1080 | |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 1081 | const status_t status = removeRights(data.readInt32(), data.readString8()); |
| 1082 | reply->writeInt32(status); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 1083 | |
| 1084 | return DRM_NO_ERROR; |
| 1085 | } |
| 1086 | |
| 1087 | case REMOVE_ALL_RIGHTS: |
| 1088 | { |
| 1089 | LOGV("BnDrmManagerService::onTransact :REMOVE_ALL_RIGHTS"); |
| 1090 | CHECK_INTERFACE(IDrmManagerService, data, reply); |
| 1091 | |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 1092 | const status_t status = removeAllRights(data.readInt32()); |
| 1093 | reply->writeInt32(status); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 1094 | |
| 1095 | return DRM_NO_ERROR; |
| 1096 | } |
| 1097 | |
| 1098 | case OPEN_CONVERT_SESSION: |
| 1099 | { |
| 1100 | LOGV("BnDrmManagerService::onTransact :OPEN_CONVERT_SESSION"); |
| 1101 | CHECK_INTERFACE(IDrmManagerService, data, reply); |
| 1102 | |
| 1103 | const int convertId = openConvertSession(data.readInt32(), data.readString8()); |
| 1104 | |
| 1105 | reply->writeInt32(convertId); |
| 1106 | return DRM_NO_ERROR; |
| 1107 | } |
| 1108 | |
| 1109 | case CONVERT_DATA: |
| 1110 | { |
| 1111 | LOGV("BnDrmManagerService::onTransact :CONVERT_DATA"); |
| 1112 | CHECK_INTERFACE(IDrmManagerService, data, reply); |
| 1113 | |
| 1114 | const int uniqueId = data.readInt32(); |
| 1115 | const int convertId = data.readInt32(); |
| 1116 | |
| 1117 | //Filling input data |
| 1118 | const int bufferSize = data.readInt32(); |
| 1119 | DrmBuffer* inputData = new DrmBuffer((char *)data.readInplace(bufferSize), bufferSize); |
| 1120 | |
| 1121 | DrmConvertedStatus* drmConvertedStatus = convertData(uniqueId, convertId, inputData); |
| 1122 | |
| 1123 | if (NULL != drmConvertedStatus) { |
| 1124 | //Filling Drm Converted Ststus |
| 1125 | reply->writeInt32(drmConvertedStatus->statusCode); |
| 1126 | reply->writeInt32(drmConvertedStatus->offset); |
| 1127 | |
| 1128 | if (NULL != drmConvertedStatus->convertedData) { |
| 1129 | const DrmBuffer* convertedData = drmConvertedStatus->convertedData; |
| 1130 | const int bufferSize = convertedData->length; |
| 1131 | reply->writeInt32(bufferSize); |
| 1132 | if (0 < bufferSize) { |
| 1133 | reply->write(convertedData->data, bufferSize); |
| 1134 | } |
| 1135 | delete [] convertedData->data; |
| 1136 | delete convertedData; convertedData = NULL; |
| 1137 | } |
| 1138 | } |
| 1139 | delete inputData; inputData = NULL; |
| 1140 | delete drmConvertedStatus; drmConvertedStatus = NULL; |
| 1141 | return DRM_NO_ERROR; |
| 1142 | } |
| 1143 | |
| 1144 | case CLOSE_CONVERT_SESSION: |
| 1145 | { |
| 1146 | LOGV("BnDrmManagerService::onTransact :CLOSE_CONVERT_SESSION"); |
| 1147 | CHECK_INTERFACE(IDrmManagerService, data, reply); |
| 1148 | |
| 1149 | DrmConvertedStatus* drmConvertedStatus |
| 1150 | = closeConvertSession(data.readInt32(), data.readInt32()); |
| 1151 | |
| 1152 | if (NULL != drmConvertedStatus) { |
| 1153 | //Filling Drm Converted Ststus |
| 1154 | reply->writeInt32(drmConvertedStatus->statusCode); |
| 1155 | reply->writeInt32(drmConvertedStatus->offset); |
| 1156 | |
| 1157 | if (NULL != drmConvertedStatus->convertedData) { |
| 1158 | const DrmBuffer* convertedData = drmConvertedStatus->convertedData; |
| 1159 | const int bufferSize = convertedData->length; |
| 1160 | reply->writeInt32(bufferSize); |
| 1161 | if (0 < bufferSize) { |
| 1162 | reply->write(convertedData->data, bufferSize); |
| 1163 | } |
| 1164 | delete [] convertedData->data; |
| 1165 | delete convertedData; convertedData = NULL; |
| 1166 | } |
| 1167 | } |
| 1168 | delete drmConvertedStatus; drmConvertedStatus = NULL; |
| 1169 | return DRM_NO_ERROR; |
| 1170 | } |
| 1171 | |
| 1172 | case GET_ALL_SUPPORT_INFO: |
| 1173 | { |
| 1174 | LOGV("BnDrmManagerService::onTransact :GET_ALL_SUPPORT_INFO"); |
| 1175 | CHECK_INTERFACE(IDrmManagerService, data, reply); |
| 1176 | |
| 1177 | const int uniqueId = data.readInt32(); |
| 1178 | int length = 0; |
| 1179 | DrmSupportInfo* drmSupportInfoArray = NULL; |
| 1180 | |
| 1181 | status_t status = getAllSupportInfo(uniqueId, &length, &drmSupportInfoArray); |
| 1182 | |
| 1183 | reply->writeInt32(length); |
| 1184 | for (int i = 0; i < length; ++i) { |
| 1185 | DrmSupportInfo drmSupportInfo = drmSupportInfoArray[i]; |
| 1186 | |
| 1187 | reply->writeInt32(drmSupportInfo.getFileSuffixCount()); |
| 1188 | DrmSupportInfo::FileSuffixIterator fileSuffixIt |
| 1189 | = drmSupportInfo.getFileSuffixIterator(); |
| 1190 | while (fileSuffixIt.hasNext()) { |
| 1191 | reply->writeString8(fileSuffixIt.next()); |
| 1192 | } |
| 1193 | |
| 1194 | reply->writeInt32(drmSupportInfo.getMimeTypeCount()); |
| 1195 | DrmSupportInfo::MimeTypeIterator mimeTypeIt = drmSupportInfo.getMimeTypeIterator(); |
| 1196 | while (mimeTypeIt.hasNext()) { |
| 1197 | reply->writeString8(mimeTypeIt.next()); |
| 1198 | } |
| 1199 | reply->writeString8(drmSupportInfo.getDescription()); |
| 1200 | } |
| 1201 | delete [] drmSupportInfoArray; drmSupportInfoArray = NULL; |
| 1202 | reply->writeInt32(status); |
| 1203 | return DRM_NO_ERROR; |
| 1204 | } |
| 1205 | |
| 1206 | case OPEN_DECRYPT_SESSION: |
| 1207 | { |
| 1208 | LOGV("BnDrmManagerService::onTransact :OPEN_DECRYPT_SESSION"); |
| 1209 | CHECK_INTERFACE(IDrmManagerService, data, reply); |
| 1210 | |
| 1211 | const int uniqueId = data.readInt32(); |
| 1212 | const int fd = data.readFileDescriptor(); |
| 1213 | |
| 1214 | DecryptHandle* handle |
| 1215 | = openDecryptSession(uniqueId, fd, data.readInt32(), data.readInt32()); |
| 1216 | |
| 1217 | if (NULL != handle) { |
| 1218 | reply->writeInt32(handle->decryptId); |
| 1219 | reply->writeString8(handle->mimeType); |
| 1220 | reply->writeInt32(handle->decryptApiType); |
| 1221 | reply->writeInt32(handle->status); |
| 1222 | if (NULL != handle->decryptInfo) { |
| 1223 | reply->writeInt32(handle->decryptInfo->decryptBufferLength); |
| 1224 | delete handle->decryptInfo; handle->decryptInfo = NULL; |
| 1225 | } |
| 1226 | } else { |
| 1227 | LOGE("NULL decryptHandle is returned"); |
| 1228 | } |
| 1229 | delete handle; handle = NULL; |
| 1230 | return DRM_NO_ERROR; |
| 1231 | } |
| 1232 | |
Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame^] | 1233 | case OPEN_DECRYPT_SESSION_FROM_URI: |
| 1234 | { |
| 1235 | LOGV("BnDrmManagerService::onTransact :OPEN_DECRYPT_SESSION_FROM_URI"); |
| 1236 | CHECK_INTERFACE(IDrmManagerService, data, reply); |
| 1237 | |
| 1238 | const int uniqueId = data.readInt32(); |
| 1239 | const String8 uri = data.readString8(); |
| 1240 | |
| 1241 | DecryptHandle* handle = openDecryptSession(uniqueId, uri.string()); |
| 1242 | |
| 1243 | if (NULL != handle) { |
| 1244 | reply->writeInt32(handle->decryptId); |
| 1245 | reply->writeString8(handle->mimeType); |
| 1246 | reply->writeInt32(handle->decryptApiType); |
| 1247 | reply->writeInt32(handle->status); |
| 1248 | if (NULL != handle->decryptInfo) { |
| 1249 | reply->writeInt32(handle->decryptInfo->decryptBufferLength); |
| 1250 | delete handle->decryptInfo; handle->decryptInfo = NULL; |
| 1251 | } |
| 1252 | } else { |
| 1253 | LOGE("NULL decryptHandle is returned"); |
| 1254 | } |
| 1255 | delete handle; handle = NULL; |
| 1256 | return DRM_NO_ERROR; |
| 1257 | } |
| 1258 | |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 1259 | case CLOSE_DECRYPT_SESSION: |
| 1260 | { |
| 1261 | LOGV("BnDrmManagerService::onTransact :CLOSE_DECRYPT_SESSION"); |
| 1262 | CHECK_INTERFACE(IDrmManagerService, data, reply); |
| 1263 | |
| 1264 | const int uniqueId = data.readInt32(); |
| 1265 | |
| 1266 | DecryptHandle* handle = new DecryptHandle(); |
| 1267 | handle->decryptId = data.readInt32(); |
| 1268 | handle->mimeType = data.readString8(); |
| 1269 | handle->decryptApiType = data.readInt32(); |
| 1270 | handle->status = data.readInt32(); |
| 1271 | handle->decryptInfo = NULL; |
| 1272 | |
| 1273 | const int bufferLength = data.readInt32(); |
| 1274 | if (INVALID_BUFFER_LENGTH != bufferLength) { |
| 1275 | handle->decryptInfo = new DecryptInfo(); |
| 1276 | handle->decryptInfo->decryptBufferLength = bufferLength; |
| 1277 | } |
| 1278 | |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 1279 | const status_t status = closeDecryptSession(uniqueId, handle); |
| 1280 | reply->writeInt32(status); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 1281 | return DRM_NO_ERROR; |
| 1282 | } |
| 1283 | |
| 1284 | case INITIALIZE_DECRYPT_UNIT: |
| 1285 | { |
| 1286 | LOGV("BnDrmManagerService::onTransact :INITIALIZE_DECRYPT_UNIT"); |
| 1287 | CHECK_INTERFACE(IDrmManagerService, data, reply); |
| 1288 | |
| 1289 | const int uniqueId = data.readInt32(); |
| 1290 | |
| 1291 | DecryptHandle handle; |
| 1292 | handle.decryptId = data.readInt32(); |
| 1293 | handle.mimeType = data.readString8(); |
| 1294 | handle.decryptApiType = data.readInt32(); |
| 1295 | handle.status = data.readInt32(); |
| 1296 | handle.decryptInfo = NULL; |
| 1297 | |
| 1298 | const int bufferLength = data.readInt32(); |
| 1299 | if (INVALID_BUFFER_LENGTH != bufferLength) { |
| 1300 | handle.decryptInfo = new DecryptInfo(); |
| 1301 | handle.decryptInfo->decryptBufferLength = bufferLength; |
| 1302 | } |
| 1303 | const int decryptUnitId = data.readInt32(); |
| 1304 | |
| 1305 | //Filling Header info |
| 1306 | const int bufferSize = data.readInt32(); |
| 1307 | DrmBuffer* headerInfo = NULL; |
| 1308 | headerInfo = new DrmBuffer((char *)data.readInplace(bufferSize), bufferSize); |
| 1309 | |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 1310 | const status_t status |
| 1311 | = initializeDecryptUnit(uniqueId, &handle, decryptUnitId, headerInfo); |
| 1312 | reply->writeInt32(status); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 1313 | |
| 1314 | delete handle.decryptInfo; handle.decryptInfo = NULL; |
| 1315 | delete headerInfo; headerInfo = NULL; |
| 1316 | return DRM_NO_ERROR; |
| 1317 | } |
| 1318 | |
| 1319 | case DECRYPT: |
| 1320 | { |
| 1321 | LOGV("BnDrmManagerService::onTransact :DECRYPT"); |
| 1322 | CHECK_INTERFACE(IDrmManagerService, data, reply); |
| 1323 | |
| 1324 | const int uniqueId = data.readInt32(); |
| 1325 | |
| 1326 | DecryptHandle handle; |
| 1327 | handle.decryptId = data.readInt32(); |
| 1328 | handle.mimeType = data.readString8(); |
| 1329 | handle.decryptApiType = data.readInt32(); |
| 1330 | handle.status = data.readInt32(); |
| 1331 | handle.decryptInfo = NULL; |
| 1332 | |
| 1333 | const int bufferLength = data.readInt32(); |
| 1334 | if (INVALID_BUFFER_LENGTH != bufferLength) { |
| 1335 | handle.decryptInfo = new DecryptInfo(); |
| 1336 | handle.decryptInfo->decryptBufferLength = bufferLength; |
| 1337 | } |
| 1338 | const int decryptUnitId = data.readInt32(); |
| 1339 | const int decBufferSize = data.readInt32(); |
| 1340 | |
| 1341 | const int encBufferSize = data.readInt32(); |
| 1342 | DrmBuffer* encBuffer |
| 1343 | = new DrmBuffer((char *)data.readInplace(encBufferSize), encBufferSize); |
| 1344 | |
| 1345 | char* buffer = NULL; |
| 1346 | buffer = new char[decBufferSize]; |
| 1347 | DrmBuffer* decBuffer = new DrmBuffer(buffer, decBufferSize); |
| 1348 | |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 1349 | DrmBuffer* IV = NULL; |
| 1350 | if (0 != data.dataAvail()) { |
| 1351 | const int ivBufferlength = data.readInt32(); |
| 1352 | IV = new DrmBuffer((char *)data.readInplace(ivBufferlength), ivBufferlength); |
| 1353 | } |
| 1354 | |
| 1355 | const status_t status |
| 1356 | = decrypt(uniqueId, &handle, decryptUnitId, encBuffer, &decBuffer, IV); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 1357 | |
| 1358 | reply->writeInt32(status); |
| 1359 | |
| 1360 | const int size = decBuffer->length; |
| 1361 | reply->writeInt32(size); |
| 1362 | reply->write(decBuffer->data, size); |
| 1363 | |
| 1364 | delete handle.decryptInfo; handle.decryptInfo = NULL; |
| 1365 | delete encBuffer; encBuffer = NULL; |
| 1366 | delete decBuffer; decBuffer = NULL; |
| 1367 | delete [] buffer; buffer = NULL; |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 1368 | delete IV; IV = NULL; |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 1369 | return DRM_NO_ERROR; |
| 1370 | } |
| 1371 | |
| 1372 | case FINALIZE_DECRYPT_UNIT: |
| 1373 | { |
| 1374 | LOGV("BnDrmManagerService::onTransact :FINALIZE_DECRYPT_UNIT"); |
| 1375 | CHECK_INTERFACE(IDrmManagerService, data, reply); |
| 1376 | |
| 1377 | const int uniqueId = data.readInt32(); |
| 1378 | |
| 1379 | DecryptHandle handle; |
| 1380 | handle.decryptId = data.readInt32(); |
| 1381 | handle.mimeType = data.readString8(); |
| 1382 | handle.decryptApiType = data.readInt32(); |
| 1383 | handle.status = data.readInt32(); |
| 1384 | handle.decryptInfo = NULL; |
| 1385 | |
| 1386 | const int bufferLength = data.readInt32(); |
| 1387 | if (INVALID_BUFFER_LENGTH != bufferLength) { |
| 1388 | handle.decryptInfo = new DecryptInfo(); |
| 1389 | handle.decryptInfo->decryptBufferLength = bufferLength; |
| 1390 | } |
| 1391 | |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 1392 | const status_t status = finalizeDecryptUnit(uniqueId, &handle, data.readInt32()); |
| 1393 | reply->writeInt32(status); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 1394 | |
| 1395 | delete handle.decryptInfo; handle.decryptInfo = NULL; |
| 1396 | return DRM_NO_ERROR; |
| 1397 | } |
| 1398 | |
| 1399 | case PREAD: |
| 1400 | { |
| 1401 | LOGV("BnDrmManagerService::onTransact :READ"); |
| 1402 | CHECK_INTERFACE(IDrmManagerService, data, reply); |
| 1403 | |
| 1404 | const int uniqueId = data.readInt32(); |
| 1405 | |
| 1406 | DecryptHandle handle; |
| 1407 | handle.decryptId = data.readInt32(); |
| 1408 | handle.mimeType = data.readString8(); |
| 1409 | handle.decryptApiType = data.readInt32(); |
| 1410 | handle.status = data.readInt32(); |
| 1411 | handle.decryptInfo = NULL; |
| 1412 | |
| 1413 | const int bufferLength = data.readInt32(); |
| 1414 | if (INVALID_BUFFER_LENGTH != bufferLength) { |
| 1415 | handle.decryptInfo = new DecryptInfo(); |
| 1416 | handle.decryptInfo->decryptBufferLength = bufferLength; |
| 1417 | } |
| 1418 | |
| 1419 | const int numBytes = data.readInt32(); |
| 1420 | char* buffer = new char[numBytes]; |
| 1421 | |
| 1422 | const off_t offset = data.readInt32(); |
| 1423 | |
| 1424 | ssize_t result = pread(uniqueId, &handle, buffer, numBytes, offset); |
| 1425 | reply->writeInt32(result); |
| 1426 | if (0 < result) { |
| 1427 | reply->write(buffer, result); |
| 1428 | } |
| 1429 | |
| 1430 | delete handle.decryptInfo; handle.decryptInfo = NULL; |
| 1431 | delete [] buffer, buffer = NULL; |
| 1432 | return DRM_NO_ERROR; |
| 1433 | } |
| 1434 | |
| 1435 | default: |
| 1436 | return BBinder::onTransact(code, data, reply, flags); |
| 1437 | } |
| 1438 | } |
| 1439 | |