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