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