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