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