aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 17 | #include <utils/String8.h> |
| 18 | #include <binder/IServiceManager.h> |
| 19 | #include <drm/DrmManagerClient.h> |
| 20 | |
| 21 | #include "DrmManagerClientImpl.h" |
| 22 | |
| 23 | using namespace android; |
| 24 | |
Takeshi Aimi | c7b3ccc | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 25 | DrmManagerClient::DrmManagerClient(): |
| 26 | mUniqueId(0), mDrmManagerClientImpl(NULL) { |
| 27 | mDrmManagerClientImpl = DrmManagerClientImpl::create(&mUniqueId); |
| 28 | mDrmManagerClientImpl->addClient(mUniqueId); |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | DrmManagerClient::~DrmManagerClient() { |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 32 | DrmManagerClientImpl::remove(mUniqueId); |
Takeshi Aimi | c7b3ccc | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 33 | mDrmManagerClientImpl->removeClient(mUniqueId); |
Takeshi Aimi | f05913a | 2010-11-30 16:27:42 +0900 | [diff] [blame] | 34 | mDrmManagerClientImpl->setOnInfoListener(mUniqueId, NULL); |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 35 | delete mDrmManagerClientImpl; mDrmManagerClientImpl = NULL; |
| 36 | } |
| 37 | |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 38 | status_t DrmManagerClient::setOnInfoListener( |
| 39 | const sp<DrmManagerClient::OnInfoListener>& infoListener) { |
| 40 | return mDrmManagerClientImpl->setOnInfoListener(mUniqueId, infoListener); |
| 41 | } |
| 42 | |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 43 | DrmConstraints* DrmManagerClient::getConstraints(const String8* path, const int action) { |
| 44 | return mDrmManagerClientImpl->getConstraints(mUniqueId, path, action); |
| 45 | } |
| 46 | |
Takeshi Aimi | dc918656 | 2010-11-16 13:56:11 +0900 | [diff] [blame] | 47 | DrmMetadata* DrmManagerClient::getMetadata(const String8* path) { |
| 48 | return mDrmManagerClientImpl->getMetadata(mUniqueId, path); |
| 49 | } |
| 50 | |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 51 | bool DrmManagerClient::canHandle(const String8& path, const String8& mimeType) { |
| 52 | return mDrmManagerClientImpl->canHandle(mUniqueId, path, mimeType); |
| 53 | } |
| 54 | |
| 55 | DrmInfoStatus* DrmManagerClient::processDrmInfo(const DrmInfo* drmInfo) { |
| 56 | return mDrmManagerClientImpl->processDrmInfo(mUniqueId, drmInfo); |
| 57 | } |
| 58 | |
| 59 | DrmInfo* DrmManagerClient::acquireDrmInfo(const DrmInfoRequest* drmInfoRequest) { |
| 60 | return mDrmManagerClientImpl->acquireDrmInfo(mUniqueId, drmInfoRequest); |
| 61 | } |
| 62 | |
Takeshi Aimi | dc549d6 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 63 | status_t DrmManagerClient::saveRights( |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 64 | const DrmRights& drmRights, const String8& rightsPath, const String8& contentPath) { |
| 65 | return mDrmManagerClientImpl->saveRights(mUniqueId, drmRights, rightsPath, contentPath); |
| 66 | } |
| 67 | |
| 68 | String8 DrmManagerClient::getOriginalMimeType(const String8& path) { |
| 69 | return mDrmManagerClientImpl->getOriginalMimeType(mUniqueId, path); |
| 70 | } |
| 71 | |
| 72 | int DrmManagerClient::getDrmObjectType(const String8& path, const String8& mimeType) { |
| 73 | return mDrmManagerClientImpl->getDrmObjectType( mUniqueId, path, mimeType); |
| 74 | } |
| 75 | |
| 76 | int DrmManagerClient::checkRightsStatus(const String8& path, int action) { |
| 77 | return mDrmManagerClientImpl->checkRightsStatus(mUniqueId, path, action); |
| 78 | } |
| 79 | |
Takeshi Aimi | dc549d6 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 80 | status_t DrmManagerClient::consumeRights(DecryptHandle* decryptHandle, int action, bool reserve) { |
Takeshi Aimi | c7b3ccc | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 81 | Mutex::Autolock _l(mDecryptLock); |
Takeshi Aimi | dc549d6 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 82 | return mDrmManagerClientImpl->consumeRights(mUniqueId, decryptHandle, action, reserve); |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 83 | } |
| 84 | |
Takeshi Aimi | dc549d6 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 85 | status_t DrmManagerClient::setPlaybackStatus( |
Gloria Wang | 5fc3edb | 2010-11-19 15:19:36 -0800 | [diff] [blame] | 86 | DecryptHandle* decryptHandle, int playbackStatus, int64_t position) { |
Takeshi Aimi | dc549d6 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 87 | return mDrmManagerClientImpl |
| 88 | ->setPlaybackStatus(mUniqueId, decryptHandle, playbackStatus, position); |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | bool DrmManagerClient::validateAction( |
| 92 | const String8& path, int action, const ActionDescription& description) { |
| 93 | return mDrmManagerClientImpl->validateAction(mUniqueId, path, action, description); |
| 94 | } |
| 95 | |
Takeshi Aimi | dc549d6 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 96 | status_t DrmManagerClient::removeRights(const String8& path) { |
| 97 | return mDrmManagerClientImpl->removeRights(mUniqueId, path); |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 98 | } |
| 99 | |
Takeshi Aimi | dc549d6 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 100 | status_t DrmManagerClient::removeAllRights() { |
| 101 | return mDrmManagerClientImpl->removeAllRights(mUniqueId); |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | int DrmManagerClient::openConvertSession(const String8& mimeType) { |
| 105 | return mDrmManagerClientImpl->openConvertSession(mUniqueId, mimeType); |
| 106 | } |
| 107 | |
| 108 | DrmConvertedStatus* DrmManagerClient::convertData(int convertId, const DrmBuffer* inputData) { |
| 109 | return mDrmManagerClientImpl->convertData(mUniqueId, convertId, inputData); |
| 110 | } |
| 111 | |
| 112 | DrmConvertedStatus* DrmManagerClient::closeConvertSession(int convertId) { |
| 113 | return mDrmManagerClientImpl->closeConvertSession(mUniqueId, convertId); |
| 114 | } |
| 115 | |
| 116 | status_t DrmManagerClient::getAllSupportInfo(int* length, DrmSupportInfo** drmSupportInfoArray) { |
| 117 | return mDrmManagerClientImpl->getAllSupportInfo(mUniqueId, length, drmSupportInfoArray); |
| 118 | } |
| 119 | |
Gloria Wang | 5fc3edb | 2010-11-19 15:19:36 -0800 | [diff] [blame] | 120 | DecryptHandle* DrmManagerClient::openDecryptSession(int fd, off64_t offset, off64_t length) { |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 121 | return mDrmManagerClientImpl->openDecryptSession(mUniqueId, fd, offset, length); |
| 122 | } |
| 123 | |
Takeshi Aimi | c7b3ccc | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 124 | DecryptHandle* DrmManagerClient::openDecryptSession(const char* uri) { |
| 125 | return mDrmManagerClientImpl->openDecryptSession(mUniqueId, uri); |
| 126 | } |
| 127 | |
Takeshi Aimi | dc549d6 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 128 | status_t DrmManagerClient::closeDecryptSession(DecryptHandle* decryptHandle) { |
| 129 | return mDrmManagerClientImpl->closeDecryptSession(mUniqueId, decryptHandle); |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 130 | } |
| 131 | |
Takeshi Aimi | dc549d6 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 132 | status_t DrmManagerClient::initializeDecryptUnit( |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 133 | DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo) { |
Takeshi Aimi | c7b3ccc | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 134 | Mutex::Autolock _l(mDecryptLock); |
Takeshi Aimi | dc549d6 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 135 | return mDrmManagerClientImpl->initializeDecryptUnit( |
| 136 | mUniqueId, decryptHandle, decryptUnitId, headerInfo); |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | status_t DrmManagerClient::decrypt( |
| 140 | DecryptHandle* decryptHandle, int decryptUnitId, |
Takeshi Aimi | dc549d6 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 141 | const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) { |
Takeshi Aimi | c7b3ccc | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 142 | Mutex::Autolock _l(mDecryptLock); |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 143 | return mDrmManagerClientImpl->decrypt( |
Takeshi Aimi | dc549d6 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 144 | mUniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer, IV); |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 145 | } |
| 146 | |
Takeshi Aimi | dc549d6 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 147 | status_t DrmManagerClient::finalizeDecryptUnit(DecryptHandle* decryptHandle, int decryptUnitId) { |
Takeshi Aimi | c7b3ccc | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 148 | Mutex::Autolock _l(mDecryptLock); |
Takeshi Aimi | dc549d6 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 149 | return mDrmManagerClientImpl->finalizeDecryptUnit(mUniqueId, decryptHandle, decryptUnitId); |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | ssize_t DrmManagerClient::pread( |
Gloria Wang | 5fc3edb | 2010-11-19 15:19:36 -0800 | [diff] [blame] | 153 | DecryptHandle* decryptHandle, void* buffer, ssize_t numBytes, off64_t offset) { |
Takeshi Aimi | c7b3ccc | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 154 | Mutex::Autolock _l(mDecryptLock); |
aimitakeshi | d074e30 | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 155 | return mDrmManagerClientImpl->pread(mUniqueId, decryptHandle, buffer, numBytes, offset); |
| 156 | } |
| 157 | |