aimitakeshi | 27ed8ad | 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 | 27ed8ad | 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 | e943f84 | 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 | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | DrmManagerClient::~DrmManagerClient() { |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 32 | DrmManagerClientImpl::remove(mUniqueId); |
Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 33 | mDrmManagerClientImpl->removeClient(mUniqueId); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 34 | delete mDrmManagerClientImpl; mDrmManagerClientImpl = NULL; |
| 35 | } |
| 36 | |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 37 | status_t DrmManagerClient::setOnInfoListener( |
| 38 | const sp<DrmManagerClient::OnInfoListener>& infoListener) { |
| 39 | return mDrmManagerClientImpl->setOnInfoListener(mUniqueId, infoListener); |
| 40 | } |
| 41 | |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 42 | DrmConstraints* DrmManagerClient::getConstraints(const String8* path, const int action) { |
| 43 | return mDrmManagerClientImpl->getConstraints(mUniqueId, path, action); |
| 44 | } |
| 45 | |
Takeshi Aimi | 3473846 | 2010-11-16 13:56:11 +0900 | [diff] [blame^] | 46 | DrmMetadata* DrmManagerClient::getMetadata(const String8* path) { |
| 47 | return mDrmManagerClientImpl->getMetadata(mUniqueId, path); |
| 48 | } |
| 49 | |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 50 | bool DrmManagerClient::canHandle(const String8& path, const String8& mimeType) { |
| 51 | return mDrmManagerClientImpl->canHandle(mUniqueId, path, mimeType); |
| 52 | } |
| 53 | |
| 54 | DrmInfoStatus* DrmManagerClient::processDrmInfo(const DrmInfo* drmInfo) { |
| 55 | return mDrmManagerClientImpl->processDrmInfo(mUniqueId, drmInfo); |
| 56 | } |
| 57 | |
| 58 | DrmInfo* DrmManagerClient::acquireDrmInfo(const DrmInfoRequest* drmInfoRequest) { |
| 59 | return mDrmManagerClientImpl->acquireDrmInfo(mUniqueId, drmInfoRequest); |
| 60 | } |
| 61 | |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 62 | status_t DrmManagerClient::saveRights( |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 63 | const DrmRights& drmRights, const String8& rightsPath, const String8& contentPath) { |
| 64 | return mDrmManagerClientImpl->saveRights(mUniqueId, drmRights, rightsPath, contentPath); |
| 65 | } |
| 66 | |
| 67 | String8 DrmManagerClient::getOriginalMimeType(const String8& path) { |
| 68 | return mDrmManagerClientImpl->getOriginalMimeType(mUniqueId, path); |
| 69 | } |
| 70 | |
| 71 | int DrmManagerClient::getDrmObjectType(const String8& path, const String8& mimeType) { |
| 72 | return mDrmManagerClientImpl->getDrmObjectType( mUniqueId, path, mimeType); |
| 73 | } |
| 74 | |
| 75 | int DrmManagerClient::checkRightsStatus(const String8& path, int action) { |
| 76 | return mDrmManagerClientImpl->checkRightsStatus(mUniqueId, path, action); |
| 77 | } |
| 78 | |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 79 | status_t DrmManagerClient::consumeRights(DecryptHandle* decryptHandle, int action, bool reserve) { |
Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 80 | Mutex::Autolock _l(mDecryptLock); |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 81 | return mDrmManagerClientImpl->consumeRights(mUniqueId, decryptHandle, action, reserve); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 82 | } |
| 83 | |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 84 | status_t DrmManagerClient::setPlaybackStatus( |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 85 | DecryptHandle* decryptHandle, int playbackStatus, int position) { |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 86 | return mDrmManagerClientImpl |
| 87 | ->setPlaybackStatus(mUniqueId, decryptHandle, playbackStatus, position); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | bool DrmManagerClient::validateAction( |
| 91 | const String8& path, int action, const ActionDescription& description) { |
| 92 | return mDrmManagerClientImpl->validateAction(mUniqueId, path, action, description); |
| 93 | } |
| 94 | |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 95 | status_t DrmManagerClient::removeRights(const String8& path) { |
| 96 | return mDrmManagerClientImpl->removeRights(mUniqueId, path); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 97 | } |
| 98 | |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 99 | status_t DrmManagerClient::removeAllRights() { |
| 100 | return mDrmManagerClientImpl->removeAllRights(mUniqueId); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | int DrmManagerClient::openConvertSession(const String8& mimeType) { |
| 104 | return mDrmManagerClientImpl->openConvertSession(mUniqueId, mimeType); |
| 105 | } |
| 106 | |
| 107 | DrmConvertedStatus* DrmManagerClient::convertData(int convertId, const DrmBuffer* inputData) { |
| 108 | return mDrmManagerClientImpl->convertData(mUniqueId, convertId, inputData); |
| 109 | } |
| 110 | |
| 111 | DrmConvertedStatus* DrmManagerClient::closeConvertSession(int convertId) { |
| 112 | return mDrmManagerClientImpl->closeConvertSession(mUniqueId, convertId); |
| 113 | } |
| 114 | |
| 115 | status_t DrmManagerClient::getAllSupportInfo(int* length, DrmSupportInfo** drmSupportInfoArray) { |
| 116 | return mDrmManagerClientImpl->getAllSupportInfo(mUniqueId, length, drmSupportInfoArray); |
| 117 | } |
| 118 | |
| 119 | DecryptHandle* DrmManagerClient::openDecryptSession(int fd, int offset, int length) { |
| 120 | return mDrmManagerClientImpl->openDecryptSession(mUniqueId, fd, offset, length); |
| 121 | } |
| 122 | |
Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 123 | DecryptHandle* DrmManagerClient::openDecryptSession(const char* uri) { |
| 124 | return mDrmManagerClientImpl->openDecryptSession(mUniqueId, uri); |
| 125 | } |
| 126 | |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 127 | status_t DrmManagerClient::closeDecryptSession(DecryptHandle* decryptHandle) { |
| 128 | return mDrmManagerClientImpl->closeDecryptSession(mUniqueId, decryptHandle); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 129 | } |
| 130 | |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 131 | status_t DrmManagerClient::initializeDecryptUnit( |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 132 | DecryptHandle* decryptHandle, int decryptUnitId, const DrmBuffer* headerInfo) { |
Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 133 | Mutex::Autolock _l(mDecryptLock); |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 134 | return mDrmManagerClientImpl->initializeDecryptUnit( |
| 135 | mUniqueId, decryptHandle, decryptUnitId, headerInfo); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | status_t DrmManagerClient::decrypt( |
| 139 | DecryptHandle* decryptHandle, int decryptUnitId, |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 140 | const DrmBuffer* encBuffer, DrmBuffer** decBuffer, DrmBuffer* IV) { |
Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 141 | Mutex::Autolock _l(mDecryptLock); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 142 | return mDrmManagerClientImpl->decrypt( |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 143 | mUniqueId, decryptHandle, decryptUnitId, encBuffer, decBuffer, IV); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 144 | } |
| 145 | |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 146 | status_t DrmManagerClient::finalizeDecryptUnit(DecryptHandle* decryptHandle, int decryptUnitId) { |
Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 147 | Mutex::Autolock _l(mDecryptLock); |
Takeshi Aimi | 2272ee2 | 2010-09-20 23:40:41 +0900 | [diff] [blame] | 148 | return mDrmManagerClientImpl->finalizeDecryptUnit(mUniqueId, decryptHandle, decryptUnitId); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | ssize_t DrmManagerClient::pread( |
| 152 | DecryptHandle* decryptHandle, void* buffer, ssize_t numBytes, off_t offset) { |
Takeshi Aimi | e943f84 | 2010-10-08 23:05:49 +0900 | [diff] [blame] | 153 | Mutex::Autolock _l(mDecryptLock); |
aimitakeshi | 27ed8ad | 2010-07-29 10:12:27 +0900 | [diff] [blame] | 154 | return mDrmManagerClientImpl->pread(mUniqueId, decryptHandle, buffer, numBytes, offset); |
| 155 | } |
| 156 | |