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