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