IDrmManagerService.cpp revision 0abeaca9d1b53ee40ce9c9d2ef543dd83b5a4cc2
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 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 68static 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 101static 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 113int BpDrmManagerService::addUniqueId(bool isNative) { 114 ALOGV("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 122void BpDrmManagerService::removeUniqueId(int uniqueId) { 123 ALOGV("remove uniqueid"); 124 Parcel data, reply; 125 data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); 126 data.writeInt32(uniqueId); 127 remote()->transact(REMOVE_UNIQUEID, data, &reply); 128} 129 130void 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 137void 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 144status_t BpDrmManagerService::setDrmServiceListener( 145 int uniqueId, const sp<IDrmServiceListener>& drmServiceListener) { 146 ALOGV("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 156status_t BpDrmManagerService::installDrmEngine(int uniqueId, const String8& drmEngineFile) { 157 ALOGV("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 168DrmConstraints* BpDrmManagerService::getConstraints( 169 int uniqueId, const String8* path, const int action) { 170 ALOGV("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 200DrmMetadata* BpDrmManagerService::getMetadata(int uniqueId, const String8* path) { 201 ALOGV("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 229bool BpDrmManagerService::canHandle(int uniqueId, const String8& path, const String8& mimeType) { 230 ALOGV("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 244DrmInfoStatus* BpDrmManagerService::processDrmInfo(int uniqueId, const DrmInfo* drmInfo) { 245 ALOGV("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 295DrmInfo* BpDrmManagerService::acquireDrmInfo(int uniqueId, const DrmInfoRequest* drmInforequest) { 296 ALOGV("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 if (key == String8("FileDescriptorKey")) { 314 int fd = -1; 315 sscanf(value.string(), "FileDescriptor[%d]", &fd); 316 data.writeFileDescriptor(fd); 317 } else { 318 data.writeString8((value == String8("")) ? String8("NULL") : value); 319 } 320 } 321 322 remote()->transact(ACQUIRE_DRM_INFO, data, &reply); 323 324 DrmInfo* drmInfo = NULL; 325 if (0 != reply.dataAvail()) { 326 //Filling DRM Info 327 const int infoType = reply.readInt32(); 328 const int bufferSize = reply.readInt32(); 329 char* data = NULL; 330 331 if (0 < bufferSize) { 332 data = new char[bufferSize]; 333 reply.read(data, bufferSize); 334 } 335 drmInfo = new DrmInfo(infoType, DrmBuffer(data, bufferSize), reply.readString8()); 336 337 const int size = reply.readInt32(); 338 for (int index = 0; index < size; ++index) { 339 const String8 key(reply.readString8()); 340 const String8 value(reply.readString8()); 341 drmInfo->put(key, (value == String8("NULL")) ? String8("") : value); 342 } 343 } 344 return drmInfo; 345} 346 347status_t BpDrmManagerService::saveRights( 348 int uniqueId, const DrmRights& drmRights, 349 const String8& rightsPath, const String8& contentPath) { 350 ALOGV("Save Rights"); 351 Parcel data, reply; 352 353 data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); 354 data.writeInt32(uniqueId); 355 356 //Filling Drm Rights 357 const DrmBuffer dataBuffer = drmRights.getData(); 358 data.writeInt32(dataBuffer.length); 359 data.write(dataBuffer.data, dataBuffer.length); 360 361 const String8 mimeType = drmRights.getMimeType(); 362 data.writeString8((mimeType == String8("")) ? String8("NULL") : mimeType); 363 364 const String8 accountId = drmRights.getAccountId(); 365 data.writeString8((accountId == String8("")) ? String8("NULL") : accountId); 366 367 const String8 subscriptionId = drmRights.getSubscriptionId(); 368 data.writeString8((subscriptionId == String8("")) ? String8("NULL") : subscriptionId); 369 370 data.writeString8((rightsPath == String8("")) ? String8("NULL") : rightsPath); 371 data.writeString8((contentPath == String8("")) ? String8("NULL") : contentPath); 372 373 remote()->transact(SAVE_RIGHTS, data, &reply); 374 return reply.readInt32(); 375} 376 377String8 BpDrmManagerService::getOriginalMimeType(int uniqueId, const String8& path, int fd) { 378 ALOGV("Get Original MimeType"); 379 Parcel data, reply; 380 381 data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); 382 data.writeInt32(uniqueId); 383 data.writeString8(path); 384 int32_t isFdValid = (fd >= 0); 385 data.writeInt32(isFdValid); 386 if (isFdValid) { 387 data.writeFileDescriptor(fd); 388 } 389 390 remote()->transact(GET_ORIGINAL_MIMETYPE, data, &reply); 391 return reply.readString8(); 392} 393 394int BpDrmManagerService::getDrmObjectType( 395 int uniqueId, const String8& path, const String8& mimeType) { 396 ALOGV("Get Drm object type"); 397 Parcel data, reply; 398 399 data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); 400 data.writeInt32(uniqueId); 401 data.writeString8(path); 402 data.writeString8(mimeType); 403 404 remote()->transact(GET_DRM_OBJECT_TYPE, data, &reply); 405 406 return reply.readInt32(); 407} 408 409int BpDrmManagerService::checkRightsStatus(int uniqueId, const String8& path, int action) { 410 ALOGV("checkRightsStatus"); 411 Parcel data, reply; 412 413 data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); 414 data.writeInt32(uniqueId); 415 data.writeString8(path); 416 data.writeInt32(action); 417 418 remote()->transact(CHECK_RIGHTS_STATUS, data, &reply); 419 420 return reply.readInt32(); 421} 422 423status_t BpDrmManagerService::consumeRights( 424 int uniqueId, DecryptHandle* decryptHandle, int action, bool reserve) { 425 ALOGV("consumeRights"); 426 Parcel data, reply; 427 428 data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); 429 data.writeInt32(uniqueId); 430 431 writeDecryptHandleToParcelData(decryptHandle, &data); 432 433 data.writeInt32(action); 434 data.writeInt32(static_cast< int>(reserve)); 435 436 remote()->transact(CONSUME_RIGHTS, data, &reply); 437 return reply.readInt32(); 438} 439 440status_t BpDrmManagerService::setPlaybackStatus( 441 int uniqueId, DecryptHandle* decryptHandle, int playbackStatus, int64_t position) { 442 ALOGV("setPlaybackStatus"); 443 Parcel data, reply; 444 445 data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); 446 data.writeInt32(uniqueId); 447 448 writeDecryptHandleToParcelData(decryptHandle, &data); 449 450 data.writeInt32(playbackStatus); 451 data.writeInt64(position); 452 453 remote()->transact(SET_PLAYBACK_STATUS, data, &reply); 454 return reply.readInt32(); 455} 456 457bool BpDrmManagerService::validateAction( 458 int uniqueId, const String8& path, 459 int action, const ActionDescription& description) { 460 ALOGV("validateAction"); 461 Parcel data, reply; 462 463 data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); 464 data.writeInt32(uniqueId); 465 data.writeString8(path); 466 data.writeInt32(action); 467 data.writeInt32(description.outputType); 468 data.writeInt32(description.configuration); 469 470 remote()->transact(VALIDATE_ACTION, data, &reply); 471 472 return static_cast<bool>(reply.readInt32()); 473} 474 475status_t BpDrmManagerService::removeRights(int uniqueId, const String8& path) { 476 ALOGV("removeRights"); 477 Parcel data, reply; 478 479 data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); 480 data.writeInt32(uniqueId); 481 data.writeString8(path); 482 483 remote()->transact(REMOVE_RIGHTS, data, &reply); 484 return reply.readInt32(); 485} 486 487status_t BpDrmManagerService::removeAllRights(int uniqueId) { 488 ALOGV("removeAllRights"); 489 Parcel data, reply; 490 491 data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); 492 data.writeInt32(uniqueId); 493 494 remote()->transact(REMOVE_ALL_RIGHTS, data, &reply); 495 return reply.readInt32(); 496} 497 498int BpDrmManagerService::openConvertSession(int uniqueId, const String8& mimeType) { 499 ALOGV("openConvertSession"); 500 Parcel data, reply; 501 502 data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); 503 data.writeInt32(uniqueId); 504 data.writeString8(mimeType); 505 506 remote()->transact(OPEN_CONVERT_SESSION, data, &reply); 507 return reply.readInt32(); 508} 509 510DrmConvertedStatus* BpDrmManagerService::convertData( 511 int uniqueId, int convertId, const DrmBuffer* inputData) { 512 ALOGV("convertData"); 513 Parcel data, reply; 514 515 data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); 516 data.writeInt32(uniqueId); 517 data.writeInt32(convertId); 518 data.writeInt32(inputData->length); 519 data.write(inputData->data, inputData->length); 520 521 remote()->transact(CONVERT_DATA, data, &reply); 522 523 DrmConvertedStatus* drmConvertedStatus = NULL; 524 525 if (0 != reply.dataAvail()) { 526 //Filling DRM Converted Status 527 const int statusCode = reply.readInt32(); 528 const off64_t offset = reply.readInt64(); 529 530 DrmBuffer* convertedData = NULL; 531 if (0 != reply.dataAvail()) { 532 const int bufferSize = reply.readInt32(); 533 char* data = NULL; 534 if (0 < bufferSize) { 535 data = new char[bufferSize]; 536 reply.read(data, bufferSize); 537 } 538 convertedData = new DrmBuffer(data, bufferSize); 539 } 540 drmConvertedStatus = new DrmConvertedStatus(statusCode, convertedData, offset); 541 } 542 return drmConvertedStatus; 543} 544 545DrmConvertedStatus* BpDrmManagerService::closeConvertSession(int uniqueId, int convertId) { 546 ALOGV("closeConvertSession"); 547 Parcel data, reply; 548 549 data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); 550 data.writeInt32(uniqueId); 551 data.writeInt32(convertId); 552 553 remote()->transact(CLOSE_CONVERT_SESSION, data, &reply); 554 555 DrmConvertedStatus* drmConvertedStatus = NULL; 556 557 if (0 != reply.dataAvail()) { 558 //Filling DRM Converted Status 559 const int statusCode = reply.readInt32(); 560 const off64_t offset = reply.readInt64(); 561 562 DrmBuffer* convertedData = NULL; 563 if (0 != reply.dataAvail()) { 564 const int bufferSize = reply.readInt32(); 565 char* data = NULL; 566 if (0 < bufferSize) { 567 data = new char[bufferSize]; 568 reply.read(data, bufferSize); 569 } 570 convertedData = new DrmBuffer(data, bufferSize); 571 } 572 drmConvertedStatus = new DrmConvertedStatus(statusCode, convertedData, offset); 573 } 574 return drmConvertedStatus; 575} 576 577status_t BpDrmManagerService::getAllSupportInfo( 578 int uniqueId, int* length, DrmSupportInfo** drmSupportInfoArray) { 579 ALOGV("Get All Support Info"); 580 Parcel data, reply; 581 582 data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); 583 data.writeInt32(uniqueId); 584 585 remote()->transact(GET_ALL_SUPPORT_INFO, data, &reply); 586 587 //Filling DRM Support Info 588 const int arraySize = reply.readInt32(); 589 if (0 < arraySize) { 590 *drmSupportInfoArray = new DrmSupportInfo[arraySize]; 591 592 for (int index = 0; index < arraySize; ++index) { 593 DrmSupportInfo drmSupportInfo; 594 595 const int fileSuffixVectorSize = reply.readInt32(); 596 for (int i = 0; i < fileSuffixVectorSize; ++i) { 597 drmSupportInfo.addFileSuffix(reply.readString8()); 598 } 599 600 const int mimeTypeVectorSize = reply.readInt32(); 601 for (int i = 0; i < mimeTypeVectorSize; ++i) { 602 drmSupportInfo.addMimeType(reply.readString8()); 603 } 604 605 drmSupportInfo.setDescription(reply.readString8()); 606 (*drmSupportInfoArray)[index] = drmSupportInfo; 607 } 608 } 609 *length = arraySize; 610 return reply.readInt32(); 611} 612 613DecryptHandle* BpDrmManagerService::openDecryptSession( 614 int uniqueId, int fd, off64_t offset, off64_t length, const char* mime) { 615 ALOGV("Entering BpDrmManagerService::openDecryptSession"); 616 Parcel data, reply; 617 618 data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); 619 data.writeInt32(uniqueId); 620 data.writeFileDescriptor(fd); 621 data.writeInt64(offset); 622 data.writeInt64(length); 623 String8 mimeType; 624 if (mime) { 625 mimeType = mime; 626 } 627 data.writeString8(mimeType); 628 629 remote()->transact(OPEN_DECRYPT_SESSION, data, &reply); 630 631 DecryptHandle* handle = NULL; 632 if (0 != reply.dataAvail()) { 633 handle = new DecryptHandle(); 634 readDecryptHandleFromParcelData(handle, reply); 635 } 636 return handle; 637} 638 639DecryptHandle* BpDrmManagerService::openDecryptSession( 640 int uniqueId, const char* uri, const char* mime) { 641 642 ALOGV("Entering BpDrmManagerService::openDecryptSession: mime=%s", mime? mime: "NULL"); 643 Parcel data, reply; 644 645 data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); 646 data.writeInt32(uniqueId); 647 data.writeString8(String8(uri)); 648 String8 mimeType; 649 if (mime) { 650 mimeType = mime; 651 } 652 data.writeString8(mimeType); 653 654 remote()->transact(OPEN_DECRYPT_SESSION_FROM_URI, data, &reply); 655 656 DecryptHandle* handle = NULL; 657 if (0 != reply.dataAvail()) { 658 handle = new DecryptHandle(); 659 readDecryptHandleFromParcelData(handle, reply); 660 } else { 661 ALOGV("no decryptHandle is generated in service side"); 662 } 663 return handle; 664} 665 666DecryptHandle* BpDrmManagerService::openDecryptSession( 667 int uniqueId, const DrmBuffer& buf, const String8& mimeType) { 668 ALOGV("Entering BpDrmManagerService::openDecryptSession"); 669 Parcel data, reply; 670 671 data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); 672 data.writeInt32(uniqueId); 673 if (buf.data != NULL && buf.length > 0) { 674 data.writeInt32(buf.length); 675 data.write(buf.data, buf.length); 676 } else { 677 data.writeInt32(0); 678 } 679 data.writeString8(mimeType); 680 681 remote()->transact(OPEN_DECRYPT_SESSION_FOR_STREAMING, data, &reply); 682 683 DecryptHandle* handle = NULL; 684 if (0 != reply.dataAvail()) { 685 handle = new DecryptHandle(); 686 readDecryptHandleFromParcelData(handle, reply); 687 } else { 688 ALOGV("no decryptHandle is generated in service side"); 689 } 690 return handle; 691} 692 693status_t BpDrmManagerService::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) { 694 ALOGV("closeDecryptSession"); 695 Parcel data, reply; 696 697 data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); 698 data.writeInt32(uniqueId); 699 700 writeDecryptHandleToParcelData(decryptHandle, &data); 701 702 remote()->transact(CLOSE_DECRYPT_SESSION, data, &reply); 703 704 return reply.readInt32(); 705} 706 707status_t BpDrmManagerService::initializeDecryptUnit( 708 int uniqueId, DecryptHandle* decryptHandle, 709 int decryptUnitId, const DrmBuffer* headerInfo) { 710 ALOGV("initializeDecryptUnit"); 711 Parcel data, reply; 712 713 data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); 714 data.writeInt32(uniqueId); 715 716 writeDecryptHandleToParcelData(decryptHandle, &data); 717 718 data.writeInt32(decryptUnitId); 719 720 data.writeInt32(headerInfo->length); 721 data.write(headerInfo->data, headerInfo->length); 722 723 remote()->transact(INITIALIZE_DECRYPT_UNIT, data, &reply); 724 return reply.readInt32(); 725} 726 727status_t BpDrmManagerService::decrypt( 728 int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId, 729 const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) { 730 ALOGV("decrypt"); 731 Parcel data, reply; 732 733 data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); 734 data.writeInt32(uniqueId); 735 736 writeDecryptHandleToParcelData(decryptHandle, &data); 737 738 data.writeInt32(decryptUnitId); 739 data.writeInt32((*decBuffer)->length); 740 741 data.writeInt32(encBuffer->length); 742 data.write(encBuffer->data, encBuffer->length); 743 744 if (NULL != IV) { 745 data.writeInt32(IV->length); 746 data.write(IV->data, IV->length); 747 } 748 749 remote()->transact(DECRYPT, data, &reply); 750 751 const status_t status = reply.readInt32(); 752 ALOGV("Return value of decrypt() is %d", status); 753 754 const int size = reply.readInt32(); 755 (*decBuffer)->length = size; 756 reply.read((void *)(*decBuffer)->data, size); 757 758 return status; 759} 760 761status_t BpDrmManagerService::finalizeDecryptUnit( 762 int uniqueId, DecryptHandle* decryptHandle, int decryptUnitId) { 763 ALOGV("finalizeDecryptUnit"); 764 Parcel data, reply; 765 766 data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); 767 data.writeInt32(uniqueId); 768 769 writeDecryptHandleToParcelData(decryptHandle, &data); 770 771 data.writeInt32(decryptUnitId); 772 773 remote()->transact(FINALIZE_DECRYPT_UNIT, data, &reply); 774 return reply.readInt32(); 775} 776 777ssize_t BpDrmManagerService::pread( 778 int uniqueId, DecryptHandle* decryptHandle, void* buffer, 779 ssize_t numBytes, off64_t offset) { 780 ALOGV("read"); 781 Parcel data, reply; 782 int result; 783 784 data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor()); 785 data.writeInt32(uniqueId); 786 787 writeDecryptHandleToParcelData(decryptHandle, &data); 788 789 data.writeInt32(numBytes); 790 data.writeInt64(offset); 791 792 remote()->transact(PREAD, data, &reply); 793 result = reply.readInt32(); 794 if (0 < result) { 795 reply.read(buffer, result); 796 } 797 return result; 798} 799 800IMPLEMENT_META_INTERFACE(DrmManagerService, "drm.IDrmManagerService"); 801 802status_t BnDrmManagerService::onTransact( 803 uint32_t code, const Parcel& data, 804 Parcel* reply, uint32_t flags) { 805 ALOGV("Entering BnDrmManagerService::onTransact with code %d", code); 806 807 switch (code) { 808 case ADD_UNIQUEID: 809 { 810 ALOGV("BnDrmManagerService::onTransact :ADD_UNIQUEID"); 811 CHECK_INTERFACE(IDrmManagerService, data, reply); 812 int uniqueId = addUniqueId(data.readInt32()); 813 reply->writeInt32(uniqueId); 814 return DRM_NO_ERROR; 815 } 816 817 case REMOVE_UNIQUEID: 818 { 819 ALOGV("BnDrmManagerService::onTransact :REMOVE_UNIQUEID"); 820 CHECK_INTERFACE(IDrmManagerService, data, reply); 821 removeUniqueId(data.readInt32()); 822 return DRM_NO_ERROR; 823 } 824 825 case ADD_CLIENT: 826 { 827 ALOGV("BnDrmManagerService::onTransact :ADD_CLIENT"); 828 CHECK_INTERFACE(IDrmManagerService, data, reply); 829 addClient(data.readInt32()); 830 return DRM_NO_ERROR; 831 } 832 833 case REMOVE_CLIENT: 834 { 835 ALOGV("BnDrmManagerService::onTransact :REMOVE_CLIENT"); 836 CHECK_INTERFACE(IDrmManagerService, data, reply); 837 removeClient(data.readInt32()); 838 return DRM_NO_ERROR; 839 } 840 841 case SET_DRM_SERVICE_LISTENER: 842 { 843 ALOGV("BnDrmManagerService::onTransact :SET_DRM_SERVICE_LISTENER"); 844 CHECK_INTERFACE(IDrmManagerService, data, reply); 845 846 const int uniqueId = data.readInt32(); 847 const sp<IDrmServiceListener> drmServiceListener 848 = interface_cast<IDrmServiceListener> (data.readStrongBinder()); 849 850 status_t status = setDrmServiceListener(uniqueId, drmServiceListener); 851 852 reply->writeInt32(status); 853 return DRM_NO_ERROR; 854 } 855 856 case INSTALL_DRM_ENGINE: 857 { 858 ALOGV("BnDrmManagerService::onTransact :INSTALL_DRM_ENGINE"); 859 CHECK_INTERFACE(IDrmManagerService, data, reply); 860 861 const int uniqueId = data.readInt32(); 862 const String8 engineFile = data.readString8(); 863 status_t status = installDrmEngine(uniqueId, engineFile); 864 865 reply->writeInt32(status); 866 return DRM_NO_ERROR; 867 } 868 869 case GET_CONSTRAINTS_FROM_CONTENT: 870 { 871 ALOGV("BnDrmManagerService::onTransact :GET_CONSTRAINTS_FROM_CONTENT"); 872 CHECK_INTERFACE(IDrmManagerService, data, reply); 873 874 const int uniqueId = data.readInt32(); 875 const String8 path = data.readString8(); 876 877 DrmConstraints* drmConstraints 878 = getConstraints(uniqueId, &path, data.readInt32()); 879 880 if (NULL != drmConstraints) { 881 //Filling DRM Constraints contents 882 reply->writeInt32(drmConstraints->getCount()); 883 884 DrmConstraints::KeyIterator keyIt = drmConstraints->keyIterator(); 885 while (keyIt.hasNext()) { 886 const String8 key = keyIt.next(); 887 reply->writeString8(key); 888 const char* value = drmConstraints->getAsByteArray(&key); 889 int bufferSize = 0; 890 if (NULL != value) { 891 bufferSize = strlen(value); 892 } 893 reply->writeInt32(bufferSize + 1); 894 reply->write(value, bufferSize + 1); 895 } 896 } 897 delete drmConstraints; drmConstraints = NULL; 898 return DRM_NO_ERROR; 899 } 900 901 case GET_METADATA_FROM_CONTENT: 902 { 903 ALOGV("BnDrmManagerService::onTransact :GET_METADATA_FROM_CONTENT"); 904 CHECK_INTERFACE(IDrmManagerService, data, reply); 905 906 const int uniqueId = data.readInt32(); 907 const String8 path = data.readString8(); 908 909 DrmMetadata* drmMetadata = getMetadata(uniqueId, &path); 910 if (NULL != drmMetadata) { 911 //Filling DRM Metadata contents 912 reply->writeInt32(drmMetadata->getCount()); 913 914 DrmMetadata::KeyIterator keyIt = drmMetadata->keyIterator(); 915 while (keyIt.hasNext()) { 916 const String8 key = keyIt.next(); 917 reply->writeString8(key); 918 const char* value = drmMetadata->getAsByteArray(&key); 919 int bufferSize = 0; 920 if (NULL != value) { 921 bufferSize = strlen(value); 922 reply->writeInt32(bufferSize + 1); 923 reply->write(value, bufferSize + 1); 924 } else { 925 reply->writeInt32(0); 926 } 927 } 928 } 929 delete drmMetadata; drmMetadata = NULL; 930 return NO_ERROR; 931 } 932 933 case CAN_HANDLE: 934 { 935 ALOGV("BnDrmManagerService::onTransact :CAN_HANDLE"); 936 CHECK_INTERFACE(IDrmManagerService, data, reply); 937 938 const int uniqueId = data.readInt32(); 939 const String8 path = data.readString8(); 940 const String8 mimeType = data.readString8(); 941 942 bool result = canHandle(uniqueId, path, mimeType); 943 944 reply->writeInt32(result); 945 return DRM_NO_ERROR; 946 } 947 948 case PROCESS_DRM_INFO: 949 { 950 ALOGV("BnDrmManagerService::onTransact :PROCESS_DRM_INFO"); 951 CHECK_INTERFACE(IDrmManagerService, data, reply); 952 953 const int uniqueId = data.readInt32(); 954 955 //Filling DRM info 956 const int infoType = data.readInt32(); 957 const int bufferSize = data.readInt32(); 958 char* buffer = NULL; 959 if (0 < bufferSize) { 960 buffer = (char *)data.readInplace(bufferSize); 961 } 962 const DrmBuffer drmBuffer(buffer, bufferSize); 963 DrmInfo* drmInfo = new DrmInfo(infoType, drmBuffer, data.readString8()); 964 965 const int size = data.readInt32(); 966 for (int index = 0; index < size; ++index) { 967 const String8 key(data.readString8()); 968 const String8 value(data.readString8()); 969 drmInfo->put(key, (value == String8("NULL")) ? String8("") : value); 970 } 971 972 DrmInfoStatus* drmInfoStatus = processDrmInfo(uniqueId, drmInfo); 973 974 if (NULL != drmInfoStatus) { 975 //Filling DRM Info Status contents 976 reply->writeInt32(drmInfoStatus->statusCode); 977 reply->writeInt32(drmInfoStatus->infoType); 978 reply->writeString8(drmInfoStatus->mimeType); 979 980 if (NULL != drmInfoStatus->drmBuffer) { 981 const DrmBuffer* drmBuffer = drmInfoStatus->drmBuffer; 982 const int bufferSize = drmBuffer->length; 983 reply->writeInt32(bufferSize); 984 if (0 < bufferSize) { 985 reply->write(drmBuffer->data, bufferSize); 986 } 987 delete [] drmBuffer->data; 988 delete drmBuffer; drmBuffer = NULL; 989 } 990 } 991 delete drmInfo; drmInfo = NULL; 992 delete drmInfoStatus; drmInfoStatus = NULL; 993 return DRM_NO_ERROR; 994 } 995 996 case ACQUIRE_DRM_INFO: 997 { 998 ALOGV("BnDrmManagerService::onTransact :ACQUIRE_DRM_INFO"); 999 CHECK_INTERFACE(IDrmManagerService, data, reply); 1000 1001 const int uniqueId = data.readInt32(); 1002 1003 //Filling DRM info Request 1004 const int infoType = data.readInt32(); 1005 const String8 mimeType = data.readString8(); 1006 DrmInfoRequest* drmInfoRequest = new DrmInfoRequest(infoType, mimeType); 1007 1008 const int size = data.readInt32(); 1009 for (int index = 0; index < size; ++index) { 1010 const String8 key(data.readString8()); 1011 if (key == String8("FileDescriptorKey")) { 1012 char buffer[16]; 1013 int fd = data.readFileDescriptor(); 1014 sprintf(buffer, "%lu", (unsigned long)fd); 1015 drmInfoRequest->put(key, String8(buffer)); 1016 } else { 1017 const String8 value(data.readString8()); 1018 drmInfoRequest->put(key, (value == String8("NULL")) ? String8("") : value); 1019 } 1020 } 1021 1022 DrmInfo* drmInfo = acquireDrmInfo(uniqueId, drmInfoRequest); 1023 1024 if (NULL != drmInfo) { 1025 //Filling DRM Info 1026 const DrmBuffer drmBuffer = drmInfo->getData(); 1027 reply->writeInt32(drmInfo->getInfoType()); 1028 1029 const int bufferSize = drmBuffer.length; 1030 reply->writeInt32(bufferSize); 1031 if (0 < bufferSize) { 1032 reply->write(drmBuffer.data, bufferSize); 1033 } 1034 reply->writeString8(drmInfo->getMimeType()); 1035 reply->writeInt32(drmInfo->getCount()); 1036 1037 DrmInfo::KeyIterator keyIt = drmInfo->keyIterator(); 1038 while (keyIt.hasNext()) { 1039 const String8 key = keyIt.next(); 1040 reply->writeString8(key); 1041 const String8 value = drmInfo->get(key); 1042 reply->writeString8((value == String8("")) ? String8("NULL") : value); 1043 } 1044 delete [] drmBuffer.data; 1045 } 1046 delete drmInfoRequest; drmInfoRequest = NULL; 1047 delete drmInfo; drmInfo = NULL; 1048 return DRM_NO_ERROR; 1049 } 1050 1051 case SAVE_RIGHTS: 1052 { 1053 ALOGV("BnDrmManagerService::onTransact :SAVE_RIGHTS"); 1054 CHECK_INTERFACE(IDrmManagerService, data, reply); 1055 1056 const int uniqueId = data.readInt32(); 1057 1058 //Filling DRM Rights 1059 const int bufferSize = data.readInt32(); 1060 const DrmBuffer drmBuffer((char *)data.readInplace(bufferSize), bufferSize); 1061 1062 const String8 mimeType(data.readString8()); 1063 const String8 accountId(data.readString8()); 1064 const String8 subscriptionId(data.readString8()); 1065 const String8 rightsPath(data.readString8()); 1066 const String8 contentPath(data.readString8()); 1067 1068 DrmRights drmRights(drmBuffer, 1069 ((mimeType == String8("NULL")) ? String8("") : mimeType), 1070 ((accountId == String8("NULL")) ? String8("") : accountId), 1071 ((subscriptionId == String8("NULL")) ? String8("") : subscriptionId)); 1072 1073 const status_t status = saveRights(uniqueId, drmRights, 1074 ((rightsPath == String8("NULL")) ? String8("") : rightsPath), 1075 ((contentPath == String8("NULL")) ? String8("") : contentPath)); 1076 1077 reply->writeInt32(status); 1078 return DRM_NO_ERROR; 1079 } 1080 1081 case GET_ORIGINAL_MIMETYPE: 1082 { 1083 ALOGV("BnDrmManagerService::onTransact :GET_ORIGINAL_MIMETYPE"); 1084 CHECK_INTERFACE(IDrmManagerService, data, reply); 1085 1086 const int uniqueId = data.readInt32(); 1087 const String8 path = data.readString8(); 1088 const int32_t isFdValid = data.readInt32(); 1089 int fd = -1; 1090 if (isFdValid) { 1091 fd = data.readFileDescriptor(); 1092 } 1093 const String8 originalMimeType = getOriginalMimeType(uniqueId, path, fd); 1094 1095 reply->writeString8(originalMimeType); 1096 return DRM_NO_ERROR; 1097 } 1098 1099 case GET_DRM_OBJECT_TYPE: 1100 { 1101 ALOGV("BnDrmManagerService::onTransact :GET_DRM_OBJECT_TYPE"); 1102 CHECK_INTERFACE(IDrmManagerService, data, reply); 1103 1104 const int uniqueId = data.readInt32(); 1105 const String8 path = data.readString8(); 1106 const String8 mimeType = data.readString8(); 1107 const int drmObjectType = getDrmObjectType(uniqueId, path, mimeType); 1108 1109 reply->writeInt32(drmObjectType); 1110 return DRM_NO_ERROR; 1111 } 1112 1113 case CHECK_RIGHTS_STATUS: 1114 { 1115 ALOGV("BnDrmManagerService::onTransact :CHECK_RIGHTS_STATUS"); 1116 CHECK_INTERFACE(IDrmManagerService, data, reply); 1117 1118 const int uniqueId = data.readInt32(); 1119 const String8 path = data.readString8(); 1120 const int action = data.readInt32(); 1121 const int result = checkRightsStatus(uniqueId, path, action); 1122 1123 reply->writeInt32(result); 1124 return DRM_NO_ERROR; 1125 } 1126 1127 case CONSUME_RIGHTS: 1128 { 1129 ALOGV("BnDrmManagerService::onTransact :CONSUME_RIGHTS"); 1130 CHECK_INTERFACE(IDrmManagerService, data, reply); 1131 1132 const int uniqueId = data.readInt32(); 1133 1134 DecryptHandle handle; 1135 readDecryptHandleFromParcelData(&handle, data); 1136 1137 const int action = data.readInt32(); 1138 const bool reserve = static_cast<bool>(data.readInt32()); 1139 const status_t status 1140 = consumeRights(uniqueId, &handle, action, reserve); 1141 reply->writeInt32(status); 1142 1143 clearDecryptHandle(&handle); 1144 return DRM_NO_ERROR; 1145 } 1146 1147 case SET_PLAYBACK_STATUS: 1148 { 1149 ALOGV("BnDrmManagerService::onTransact :SET_PLAYBACK_STATUS"); 1150 CHECK_INTERFACE(IDrmManagerService, data, reply); 1151 1152 const int uniqueId = data.readInt32(); 1153 1154 DecryptHandle handle; 1155 readDecryptHandleFromParcelData(&handle, data); 1156 1157 const int playbackStatus = data.readInt32(); 1158 const int64_t position = data.readInt64(); 1159 const status_t status 1160 = setPlaybackStatus(uniqueId, &handle, playbackStatus, position); 1161 reply->writeInt32(status); 1162 1163 clearDecryptHandle(&handle); 1164 return DRM_NO_ERROR; 1165 } 1166 1167 case VALIDATE_ACTION: 1168 { 1169 ALOGV("BnDrmManagerService::onTransact :VALIDATE_ACTION"); 1170 CHECK_INTERFACE(IDrmManagerService, data, reply); 1171 1172 const int uniqueId = data.readInt32(); 1173 const String8 path = data.readString8(); 1174 const int action = data.readInt32(); 1175 const int outputType = data.readInt32(); 1176 const int configuration = data.readInt32(); 1177 bool result = validateAction(uniqueId, path, action, 1178 ActionDescription(outputType, configuration)); 1179 1180 reply->writeInt32(result); 1181 return DRM_NO_ERROR; 1182 } 1183 1184 case REMOVE_RIGHTS: 1185 { 1186 ALOGV("BnDrmManagerService::onTransact :REMOVE_RIGHTS"); 1187 CHECK_INTERFACE(IDrmManagerService, data, reply); 1188 1189 int uniqueId = data.readInt32(); 1190 String8 path = data.readString8(); 1191 const status_t status = removeRights(uniqueId, path); 1192 reply->writeInt32(status); 1193 1194 return DRM_NO_ERROR; 1195 } 1196 1197 case REMOVE_ALL_RIGHTS: 1198 { 1199 ALOGV("BnDrmManagerService::onTransact :REMOVE_ALL_RIGHTS"); 1200 CHECK_INTERFACE(IDrmManagerService, data, reply); 1201 1202 const status_t status = removeAllRights(data.readInt32()); 1203 reply->writeInt32(status); 1204 1205 return DRM_NO_ERROR; 1206 } 1207 1208 case OPEN_CONVERT_SESSION: 1209 { 1210 ALOGV("BnDrmManagerService::onTransact :OPEN_CONVERT_SESSION"); 1211 CHECK_INTERFACE(IDrmManagerService, data, reply); 1212 1213 const int uniqueId = data.readInt32(); 1214 const String8 mimeType = data.readString8(); 1215 const int convertId = openConvertSession(uniqueId, mimeType); 1216 1217 reply->writeInt32(convertId); 1218 return DRM_NO_ERROR; 1219 } 1220 1221 case CONVERT_DATA: 1222 { 1223 ALOGV("BnDrmManagerService::onTransact :CONVERT_DATA"); 1224 CHECK_INTERFACE(IDrmManagerService, data, reply); 1225 1226 const int uniqueId = data.readInt32(); 1227 const int convertId = data.readInt32(); 1228 1229 //Filling input data 1230 const int bufferSize = data.readInt32(); 1231 DrmBuffer* inputData = new DrmBuffer((char *)data.readInplace(bufferSize), bufferSize); 1232 1233 DrmConvertedStatus* drmConvertedStatus = convertData(uniqueId, convertId, inputData); 1234 1235 if (NULL != drmConvertedStatus) { 1236 //Filling Drm Converted Ststus 1237 reply->writeInt32(drmConvertedStatus->statusCode); 1238 reply->writeInt64(drmConvertedStatus->offset); 1239 1240 if (NULL != drmConvertedStatus->convertedData) { 1241 const DrmBuffer* convertedData = drmConvertedStatus->convertedData; 1242 const int bufferSize = convertedData->length; 1243 reply->writeInt32(bufferSize); 1244 if (0 < bufferSize) { 1245 reply->write(convertedData->data, bufferSize); 1246 } 1247 delete [] convertedData->data; 1248 delete convertedData; convertedData = NULL; 1249 } 1250 } 1251 delete inputData; inputData = NULL; 1252 delete drmConvertedStatus; drmConvertedStatus = NULL; 1253 return DRM_NO_ERROR; 1254 } 1255 1256 case CLOSE_CONVERT_SESSION: 1257 { 1258 ALOGV("BnDrmManagerService::onTransact :CLOSE_CONVERT_SESSION"); 1259 CHECK_INTERFACE(IDrmManagerService, data, reply); 1260 1261 const int uniqueId = data.readInt32(); 1262 const int convertId = data.readInt32(); 1263 DrmConvertedStatus* drmConvertedStatus 1264 = closeConvertSession(uniqueId, convertId); 1265 1266 if (NULL != drmConvertedStatus) { 1267 //Filling Drm Converted Ststus 1268 reply->writeInt32(drmConvertedStatus->statusCode); 1269 reply->writeInt64(drmConvertedStatus->offset); 1270 1271 if (NULL != drmConvertedStatus->convertedData) { 1272 const DrmBuffer* convertedData = drmConvertedStatus->convertedData; 1273 const int bufferSize = convertedData->length; 1274 reply->writeInt32(bufferSize); 1275 if (0 < bufferSize) { 1276 reply->write(convertedData->data, bufferSize); 1277 } 1278 delete [] convertedData->data; 1279 delete convertedData; convertedData = NULL; 1280 } 1281 } 1282 delete drmConvertedStatus; drmConvertedStatus = NULL; 1283 return DRM_NO_ERROR; 1284 } 1285 1286 case GET_ALL_SUPPORT_INFO: 1287 { 1288 ALOGV("BnDrmManagerService::onTransact :GET_ALL_SUPPORT_INFO"); 1289 CHECK_INTERFACE(IDrmManagerService, data, reply); 1290 1291 const int uniqueId = data.readInt32(); 1292 int length = 0; 1293 DrmSupportInfo* drmSupportInfoArray = NULL; 1294 1295 status_t status = getAllSupportInfo(uniqueId, &length, &drmSupportInfoArray); 1296 1297 reply->writeInt32(length); 1298 for (int i = 0; i < length; ++i) { 1299 DrmSupportInfo drmSupportInfo = drmSupportInfoArray[i]; 1300 1301 reply->writeInt32(drmSupportInfo.getFileSuffixCount()); 1302 DrmSupportInfo::FileSuffixIterator fileSuffixIt 1303 = drmSupportInfo.getFileSuffixIterator(); 1304 while (fileSuffixIt.hasNext()) { 1305 reply->writeString8(fileSuffixIt.next()); 1306 } 1307 1308 reply->writeInt32(drmSupportInfo.getMimeTypeCount()); 1309 DrmSupportInfo::MimeTypeIterator mimeTypeIt = drmSupportInfo.getMimeTypeIterator(); 1310 while (mimeTypeIt.hasNext()) { 1311 reply->writeString8(mimeTypeIt.next()); 1312 } 1313 reply->writeString8(drmSupportInfo.getDescription()); 1314 } 1315 delete [] drmSupportInfoArray; drmSupportInfoArray = NULL; 1316 reply->writeInt32(status); 1317 return DRM_NO_ERROR; 1318 } 1319 1320 case OPEN_DECRYPT_SESSION: 1321 { 1322 ALOGV("BnDrmManagerService::onTransact :OPEN_DECRYPT_SESSION"); 1323 CHECK_INTERFACE(IDrmManagerService, data, reply); 1324 1325 const int uniqueId = data.readInt32(); 1326 const int fd = data.readFileDescriptor(); 1327 1328 const off64_t offset = data.readInt64(); 1329 const off64_t length = data.readInt64(); 1330 const String8 mime = data.readString8(); 1331 1332 DecryptHandle* handle 1333 = openDecryptSession(uniqueId, fd, offset, length, mime.string()); 1334 1335 if (NULL != handle) { 1336 writeDecryptHandleToParcelData(handle, reply); 1337 clearDecryptHandle(handle); 1338 delete handle; handle = NULL; 1339 } 1340 return DRM_NO_ERROR; 1341 } 1342 1343 case OPEN_DECRYPT_SESSION_FROM_URI: 1344 { 1345 ALOGV("BnDrmManagerService::onTransact :OPEN_DECRYPT_SESSION_FROM_URI"); 1346 CHECK_INTERFACE(IDrmManagerService, data, reply); 1347 1348 const int uniqueId = data.readInt32(); 1349 const String8 uri = data.readString8(); 1350 const String8 mime = data.readString8(); 1351 1352 DecryptHandle* handle = openDecryptSession(uniqueId, uri.string(), mime.string()); 1353 1354 if (NULL != handle) { 1355 writeDecryptHandleToParcelData(handle, reply); 1356 1357 clearDecryptHandle(handle); 1358 delete handle; handle = NULL; 1359 } else { 1360 ALOGV("NULL decryptHandle is returned"); 1361 } 1362 return DRM_NO_ERROR; 1363 } 1364 1365 case OPEN_DECRYPT_SESSION_FOR_STREAMING: 1366 { 1367 ALOGV("BnDrmManagerService::onTransact :OPEN_DECRYPT_SESSION_FOR_STREAMING"); 1368 CHECK_INTERFACE(IDrmManagerService, data, reply); 1369 1370 const int uniqueId = data.readInt32(); 1371 const int bufferSize = data.readInt32(); 1372 DrmBuffer buf((bufferSize > 0) ? (char *)data.readInplace(bufferSize) : NULL, 1373 bufferSize); 1374 const String8 mimeType(data.readString8()); 1375 1376 DecryptHandle* handle = openDecryptSession(uniqueId, buf, mimeType); 1377 1378 if (handle != NULL) { 1379 writeDecryptHandleToParcelData(handle, reply); 1380 clearDecryptHandle(handle); 1381 delete handle; 1382 handle = NULL; 1383 } else { 1384 ALOGV("NULL decryptHandle is returned"); 1385 } 1386 return DRM_NO_ERROR; 1387 } 1388 1389 case CLOSE_DECRYPT_SESSION: 1390 { 1391 ALOGV("BnDrmManagerService::onTransact :CLOSE_DECRYPT_SESSION"); 1392 CHECK_INTERFACE(IDrmManagerService, data, reply); 1393 1394 const int uniqueId = data.readInt32(); 1395 1396 DecryptHandle* handle = new DecryptHandle(); 1397 readDecryptHandleFromParcelData(handle, data); 1398 1399 const status_t status = closeDecryptSession(uniqueId, handle); 1400 reply->writeInt32(status); 1401 return DRM_NO_ERROR; 1402 } 1403 1404 case INITIALIZE_DECRYPT_UNIT: 1405 { 1406 ALOGV("BnDrmManagerService::onTransact :INITIALIZE_DECRYPT_UNIT"); 1407 CHECK_INTERFACE(IDrmManagerService, data, reply); 1408 1409 const int uniqueId = data.readInt32(); 1410 1411 DecryptHandle handle; 1412 readDecryptHandleFromParcelData(&handle, data); 1413 1414 const int decryptUnitId = data.readInt32(); 1415 1416 //Filling Header info 1417 const int bufferSize = data.readInt32(); 1418 DrmBuffer* headerInfo = NULL; 1419 headerInfo = new DrmBuffer((char *)data.readInplace(bufferSize), bufferSize); 1420 1421 const status_t status 1422 = initializeDecryptUnit(uniqueId, &handle, decryptUnitId, headerInfo); 1423 reply->writeInt32(status); 1424 1425 clearDecryptHandle(&handle); 1426 delete headerInfo; headerInfo = NULL; 1427 return DRM_NO_ERROR; 1428 } 1429 1430 case DECRYPT: 1431 { 1432 ALOGV("BnDrmManagerService::onTransact :DECRYPT"); 1433 CHECK_INTERFACE(IDrmManagerService, data, reply); 1434 1435 const int uniqueId = data.readInt32(); 1436 1437 DecryptHandle handle; 1438 readDecryptHandleFromParcelData(&handle, data); 1439 1440 const int decryptUnitId = data.readInt32(); 1441 const int decBufferSize = data.readInt32(); 1442 1443 const int encBufferSize = data.readInt32(); 1444 DrmBuffer* encBuffer 1445 = new DrmBuffer((char *)data.readInplace(encBufferSize), encBufferSize); 1446 1447 char* buffer = NULL; 1448 buffer = new char[decBufferSize]; 1449 DrmBuffer* decBuffer = new DrmBuffer(buffer, decBufferSize); 1450 1451 DrmBuffer* IV = NULL; 1452 if (0 != data.dataAvail()) { 1453 const int ivBufferlength = data.readInt32(); 1454 IV = new DrmBuffer((char *)data.readInplace(ivBufferlength), ivBufferlength); 1455 } 1456 1457 const status_t status 1458 = decrypt(uniqueId, &handle, decryptUnitId, encBuffer, &decBuffer, IV); 1459 1460 reply->writeInt32(status); 1461 1462 const int size = decBuffer->length; 1463 reply->writeInt32(size); 1464 reply->write(decBuffer->data, size); 1465 1466 clearDecryptHandle(&handle); 1467 delete encBuffer; encBuffer = NULL; 1468 delete decBuffer; decBuffer = NULL; 1469 delete [] buffer; buffer = NULL; 1470 delete IV; IV = NULL; 1471 return DRM_NO_ERROR; 1472 } 1473 1474 case FINALIZE_DECRYPT_UNIT: 1475 { 1476 ALOGV("BnDrmManagerService::onTransact :FINALIZE_DECRYPT_UNIT"); 1477 CHECK_INTERFACE(IDrmManagerService, data, reply); 1478 1479 const int uniqueId = data.readInt32(); 1480 1481 DecryptHandle handle; 1482 readDecryptHandleFromParcelData(&handle, data); 1483 1484 const status_t status = finalizeDecryptUnit(uniqueId, &handle, data.readInt32()); 1485 reply->writeInt32(status); 1486 1487 clearDecryptHandle(&handle); 1488 return DRM_NO_ERROR; 1489 } 1490 1491 case PREAD: 1492 { 1493 ALOGV("BnDrmManagerService::onTransact :READ"); 1494 CHECK_INTERFACE(IDrmManagerService, data, reply); 1495 1496 const int uniqueId = data.readInt32(); 1497 1498 DecryptHandle handle; 1499 readDecryptHandleFromParcelData(&handle, data); 1500 1501 const int numBytes = data.readInt32(); 1502 char* buffer = new char[numBytes]; 1503 1504 const off64_t offset = data.readInt64(); 1505 1506 ssize_t result = pread(uniqueId, &handle, buffer, numBytes, offset); 1507 reply->writeInt32(result); 1508 if (0 < result) { 1509 reply->write(buffer, result); 1510 } 1511 1512 clearDecryptHandle(&handle); 1513 delete [] buffer, buffer = NULL; 1514 return DRM_NO_ERROR; 1515 } 1516 1517 default: 1518 return BBinder::onTransact(code, data, reply, flags); 1519 } 1520} 1521