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