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