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