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