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