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