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