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