blob: ee5ea936c4e9dfd3d342f7d5d58c323d7dff121c [file] [log] [blame]
Andreas Hubered3e3e02012-03-26 11:13:27 -07001/*
2 * Copyright (C) 2012 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
17//#define LOG_NDEBUG 0
18#define LOG_TAG "ICrypto"
Andreas Hubered3e3e02012-03-26 11:13:27 -070019#include <binder/Parcel.h>
Jeff Tinkerc481b502015-04-06 18:21:05 -070020#include <binder/IMemory.h>
Jeff Tinker5231cc12018-01-11 00:14:53 -080021#include <cutils/log.h>
Andreas Hubered3e3e02012-03-26 11:13:27 -070022#include <media/ICrypto.h>
Andreas Huber5b8987e2012-04-19 12:52:20 -070023#include <media/stagefright/MediaErrors.h>
Andreas Hubered3e3e02012-03-26 11:13:27 -070024#include <media/stagefright/foundation/ADebug.h>
Andreas Huber5b8987e2012-04-19 12:52:20 -070025#include <media/stagefright/foundation/AString.h>
Jeff Tinker5231cc12018-01-11 00:14:53 -080026#include <utils/Log.h>
Andreas Hubered3e3e02012-03-26 11:13:27 -070027
28namespace android {
29
30enum {
Andreas Huber1bd139a2012-04-03 14:19:20 -070031 INIT_CHECK = IBinder::FIRST_CALL_TRANSACTION,
32 IS_CRYPTO_SUPPORTED,
33 CREATE_PLUGIN,
34 DESTROY_PLUGIN,
35 REQUIRES_SECURE_COMPONENT,
36 DECRYPT,
Jeff Tinker2514d082014-11-03 13:29:35 -080037 NOTIFY_RESOLUTION,
Jeff Tinker18495702015-04-10 04:10:59 -070038 SET_MEDIADRM_SESSION,
Chong Zhangd07c9272017-03-28 11:02:06 -070039 SET_HEAP,
40 UNSET_HEAP,
Andreas Hubered3e3e02012-03-26 11:13:27 -070041};
42
43struct BpCrypto : public BpInterface<ICrypto> {
Chih-Hung Hsieh090ef602016-04-27 10:39:54 -070044 explicit BpCrypto(const sp<IBinder> &impl)
Andreas Hubered3e3e02012-03-26 11:13:27 -070045 : BpInterface<ICrypto>(impl) {
46 }
47
Andreas Huber1bd139a2012-04-03 14:19:20 -070048 virtual status_t initCheck() const {
Andreas Hubered3e3e02012-03-26 11:13:27 -070049 Parcel data, reply;
50 data.writeInterfaceToken(ICrypto::getInterfaceDescriptor());
Andreas Huber1bd139a2012-04-03 14:19:20 -070051 remote()->transact(INIT_CHECK, data, &reply);
Andreas Hubered3e3e02012-03-26 11:13:27 -070052
53 return reply.readInt32();
54 }
55
Jeff Tinkerbafb6822013-03-22 15:26:39 -070056 virtual bool isCryptoSchemeSupported(const uint8_t uuid[16]) {
Andreas Hubered3e3e02012-03-26 11:13:27 -070057 Parcel data, reply;
58 data.writeInterfaceToken(ICrypto::getInterfaceDescriptor());
Andreas Huber1bd139a2012-04-03 14:19:20 -070059 data.write(uuid, 16);
60 remote()->transact(IS_CRYPTO_SUPPORTED, data, &reply);
61
62 return reply.readInt32() != 0;
63 }
64
65 virtual status_t createPlugin(
66 const uint8_t uuid[16], const void *opaqueData, size_t opaqueSize) {
67 Parcel data, reply;
68 data.writeInterfaceToken(ICrypto::getInterfaceDescriptor());
69 data.write(uuid, 16);
70 data.writeInt32(opaqueSize);
Andreas Huber705868c2012-04-11 15:41:45 -070071
72 if (opaqueSize > 0) {
73 data.write(opaqueData, opaqueSize);
74 }
75
Andreas Huber1bd139a2012-04-03 14:19:20 -070076 remote()->transact(CREATE_PLUGIN, data, &reply);
Andreas Hubered3e3e02012-03-26 11:13:27 -070077
78 return reply.readInt32();
79 }
80
Andreas Huber1bd139a2012-04-03 14:19:20 -070081 virtual status_t destroyPlugin() {
Andreas Hubered3e3e02012-03-26 11:13:27 -070082 Parcel data, reply;
83 data.writeInterfaceToken(ICrypto::getInterfaceDescriptor());
Andreas Huber1bd139a2012-04-03 14:19:20 -070084 remote()->transact(DESTROY_PLUGIN, data, &reply);
Andreas Hubered3e3e02012-03-26 11:13:27 -070085
86 return reply.readInt32();
87 }
88
Andreas Huber1bd139a2012-04-03 14:19:20 -070089 virtual bool requiresSecureDecoderComponent(
90 const char *mime) const {
Andreas Hubered3e3e02012-03-26 11:13:27 -070091 Parcel data, reply;
92 data.writeInterfaceToken(ICrypto::getInterfaceDescriptor());
Andreas Huber1bd139a2012-04-03 14:19:20 -070093 data.writeCString(mime);
94 remote()->transact(REQUIRES_SECURE_COMPONENT, data, &reply);
Andreas Hubered3e3e02012-03-26 11:13:27 -070095
Andreas Huber1bd139a2012-04-03 14:19:20 -070096 return reply.readInt32() != 0;
Andreas Hubered3e3e02012-03-26 11:13:27 -070097 }
98
Jeff Tinkera53d6552017-01-20 00:31:46 -080099 virtual ssize_t decrypt(const uint8_t key[16], const uint8_t iv[16],
Jeff Tinker18cb1ec2015-12-18 11:55:22 -0800100 CryptoPlugin::Mode mode, const CryptoPlugin::Pattern &pattern,
Chong Zhang6dcab2b2017-03-28 14:18:27 -0700101 const SourceBuffer &source, size_t offset,
Andreas Huber1bd139a2012-04-03 14:19:20 -0700102 const CryptoPlugin::SubSample *subSamples, size_t numSubSamples,
Jeff Tinkera53d6552017-01-20 00:31:46 -0800103 const DestinationBuffer &destination, AString *errorDetailMsg) {
Andreas Hubered3e3e02012-03-26 11:13:27 -0700104 Parcel data, reply;
105 data.writeInterfaceToken(ICrypto::getInterfaceDescriptor());
Andreas Huber1bd139a2012-04-03 14:19:20 -0700106 data.writeInt32(mode);
Jeff Tinker18cb1ec2015-12-18 11:55:22 -0800107 data.writeInt32(pattern.mEncryptBlocks);
108 data.writeInt32(pattern.mSkipBlocks);
Andreas Huber4b75a9c2012-04-06 11:06:28 -0700109
110 static const uint8_t kDummy[16] = { 0 };
111
112 if (key == NULL) {
113 key = kDummy;
114 }
115
116 if (iv == NULL) {
117 iv = kDummy;
118 }
119
Andreas Huber1bd139a2012-04-03 14:19:20 -0700120 data.write(key, 16);
121 data.write(iv, 16);
Andreas Hubered3e3e02012-03-26 11:13:27 -0700122
Andreas Huber1bd139a2012-04-03 14:19:20 -0700123 size_t totalSize = 0;
124 for (size_t i = 0; i < numSubSamples; ++i) {
125 totalSize += subSamples[i].mNumBytesOfEncryptedData;
126 totalSize += subSamples[i].mNumBytesOfClearData;
Andreas Hubered3e3e02012-03-26 11:13:27 -0700127 }
128
Andreas Huber1bd139a2012-04-03 14:19:20 -0700129 data.writeInt32(totalSize);
Chong Zhang6dcab2b2017-03-28 14:18:27 -0700130 data.writeStrongBinder(IInterface::asBinder(source.mSharedMemory));
131 data.writeInt32(source.mHeapSeqNum);
Jeff Tinkerc481b502015-04-06 18:21:05 -0700132 data.writeInt32(offset);
Andreas Hubered3e3e02012-03-26 11:13:27 -0700133
Andreas Huber1bd139a2012-04-03 14:19:20 -0700134 data.writeInt32(numSubSamples);
135 data.write(subSamples, sizeof(CryptoPlugin::SubSample) * numSubSamples);
Andreas Hubered3e3e02012-03-26 11:13:27 -0700136
Jeff Tinkera53d6552017-01-20 00:31:46 -0800137 data.writeInt32((int32_t)destination.mType);
138 if (destination.mType == kDestinationTypeNativeHandle) {
139 if (destination.mHandle == NULL) {
140 return BAD_VALUE;
141 }
142 data.writeNativeHandle(destination.mHandle);
Jeff Tinker9ac86b32016-01-23 17:27:58 -0800143 } else {
Jeff Tinkera53d6552017-01-20 00:31:46 -0800144 if (destination.mSharedMemory == NULL) {
145 return BAD_VALUE;
146 }
147 data.writeStrongBinder(IInterface::asBinder(destination.mSharedMemory));
Andreas Hubered3e3e02012-03-26 11:13:27 -0700148 }
149
Andreas Huber1bd139a2012-04-03 14:19:20 -0700150 remote()->transact(DECRYPT, data, &reply);
Andreas Hubered3e3e02012-03-26 11:13:27 -0700151
Edwin Wongfa2b8f22012-07-10 20:01:13 -0700152 ssize_t result = reply.readInt32();
Andreas Hubered3e3e02012-03-26 11:13:27 -0700153
Jeff Tinkerceffd8c2015-05-05 15:09:14 -0700154 if (isCryptoError(result)) {
Jeff Tinker0be134a2017-03-09 17:01:10 -0800155 AString msg = reply.readCString();
156 if (errorDetailMsg) {
157 *errorDetailMsg = msg;
158 }
Andreas Hubered3e3e02012-03-26 11:13:27 -0700159 }
160
Edwin Wongfa2b8f22012-07-10 20:01:13 -0700161 return result;
Andreas Hubered3e3e02012-03-26 11:13:27 -0700162 }
163
Jeff Tinker2514d082014-11-03 13:29:35 -0800164 virtual void notifyResolution(
165 uint32_t width, uint32_t height) {
166 Parcel data, reply;
167 data.writeInterfaceToken(ICrypto::getInterfaceDescriptor());
168 data.writeInt32(width);
169 data.writeInt32(height);
170 remote()->transact(NOTIFY_RESOLUTION, data, &reply);
171 }
172
Jeff Tinker18495702015-04-10 04:10:59 -0700173 virtual status_t setMediaDrmSession(const Vector<uint8_t> &sessionId) {
174 Parcel data, reply;
175 data.writeInterfaceToken(ICrypto::getInterfaceDescriptor());
176
177 writeVector(data, sessionId);
178 remote()->transact(SET_MEDIADRM_SESSION, data, &reply);
179
180 return reply.readInt32();
181 }
182
Chong Zhang6dcab2b2017-03-28 14:18:27 -0700183 virtual int32_t setHeap(const sp<IMemoryHeap> &heap) {
Chong Zhangd07c9272017-03-28 11:02:06 -0700184 Parcel data, reply;
185 data.writeInterfaceToken(ICrypto::getInterfaceDescriptor());
186 data.writeStrongBinder(IInterface::asBinder(heap));
Chong Zhang6dcab2b2017-03-28 14:18:27 -0700187 status_t err = remote()->transact(SET_HEAP, data, &reply);
188 if (err != NO_ERROR) {
189 return -1;
190 }
191 int32_t seqNum;
192 if (reply.readInt32(&seqNum) != NO_ERROR) {
193 return -1;
194 }
195 return seqNum;
Chong Zhangd07c9272017-03-28 11:02:06 -0700196 }
197
Chong Zhang6dcab2b2017-03-28 14:18:27 -0700198 virtual void unsetHeap(int32_t seqNum) {
Chong Zhangd07c9272017-03-28 11:02:06 -0700199 Parcel data, reply;
200 data.writeInterfaceToken(ICrypto::getInterfaceDescriptor());
Chong Zhang6dcab2b2017-03-28 14:18:27 -0700201 data.writeInt32(seqNum);
Chong Zhangd07c9272017-03-28 11:02:06 -0700202 remote()->transact(UNSET_HEAP, data, &reply);
203 return;
204 }
205
206
Andreas Hubered3e3e02012-03-26 11:13:27 -0700207private:
Jeff Tinker18495702015-04-10 04:10:59 -0700208 void readVector(Parcel &reply, Vector<uint8_t> &vector) const {
209 uint32_t size = reply.readInt32();
210 vector.insertAt((size_t)0, size);
211 reply.read(vector.editArray(), size);
212 }
213
214 void writeVector(Parcel &data, Vector<uint8_t> const &vector) const {
215 data.writeInt32(vector.size());
216 data.write(vector.array(), vector.size());
217 }
218
Andreas Hubered3e3e02012-03-26 11:13:27 -0700219 DISALLOW_EVIL_CONSTRUCTORS(BpCrypto);
220};
221
222IMPLEMENT_META_INTERFACE(Crypto, "android.hardware.ICrypto");
223
224////////////////////////////////////////////////////////////////////////////////
225
Jeff Tinker18495702015-04-10 04:10:59 -0700226void BnCrypto::readVector(const Parcel &data, Vector<uint8_t> &vector) const {
227 uint32_t size = data.readInt32();
Jeff Tinkerc1bf68a2018-07-24 14:13:13 -0700228 if (vector.insertAt((size_t)0, size) < 0) {
229 vector.clear();
230 }
231 if (data.read(vector.editArray(), size) != NO_ERROR) {
232 vector.clear();
233 android_errorWriteWithInfoLog(0x534e4554, "62872384", -1, NULL, 0);
234 }
Jeff Tinker18495702015-04-10 04:10:59 -0700235}
236
237void BnCrypto::writeVector(Parcel *reply, Vector<uint8_t> const &vector) const {
238 reply->writeInt32(vector.size());
239 reply->write(vector.array(), vector.size());
240}
241
Andreas Hubered3e3e02012-03-26 11:13:27 -0700242status_t BnCrypto::onTransact(
243 uint32_t code, const Parcel &data, Parcel *reply, uint32_t flags) {
244 switch (code) {
Andreas Huber1bd139a2012-04-03 14:19:20 -0700245 case INIT_CHECK:
Andreas Hubered3e3e02012-03-26 11:13:27 -0700246 {
247 CHECK_INTERFACE(ICrypto, data, reply);
Andreas Huber1bd139a2012-04-03 14:19:20 -0700248 reply->writeInt32(initCheck());
Andreas Hubered3e3e02012-03-26 11:13:27 -0700249
250 return OK;
251 }
252
Andreas Huber1bd139a2012-04-03 14:19:20 -0700253 case IS_CRYPTO_SUPPORTED:
Andreas Hubered3e3e02012-03-26 11:13:27 -0700254 {
255 CHECK_INTERFACE(ICrypto, data, reply);
Andreas Huber1bd139a2012-04-03 14:19:20 -0700256 uint8_t uuid[16];
257 data.read(uuid, sizeof(uuid));
258 reply->writeInt32(isCryptoSchemeSupported(uuid));
Andreas Hubered3e3e02012-03-26 11:13:27 -0700259
260 return OK;
261 }
262
Andreas Huber1bd139a2012-04-03 14:19:20 -0700263 case CREATE_PLUGIN:
Andreas Hubered3e3e02012-03-26 11:13:27 -0700264 {
265 CHECK_INTERFACE(ICrypto, data, reply);
266
Andreas Huber1bd139a2012-04-03 14:19:20 -0700267 uint8_t uuid[16];
268 data.read(uuid, sizeof(uuid));
Andreas Hubered3e3e02012-03-26 11:13:27 -0700269
Andreas Huber1bd139a2012-04-03 14:19:20 -0700270 size_t opaqueSize = data.readInt32();
Andreas Huber705868c2012-04-11 15:41:45 -0700271 void *opaqueData = NULL;
272
Edwin Wong9247e102017-03-13 16:38:20 -0700273 const size_t kMaxOpaqueSize = 100 * 1024;
274 if (opaqueSize > kMaxOpaqueSize) {
275 return BAD_VALUE;
Andreas Huber705868c2012-04-11 15:41:45 -0700276 }
Andreas Hubered3e3e02012-03-26 11:13:27 -0700277
Edwin Wong9247e102017-03-13 16:38:20 -0700278 opaqueData = malloc(opaqueSize);
279 if (NULL == opaqueData) {
280 return NO_MEMORY;
281 }
282
283 data.read(opaqueData, opaqueSize);
Andreas Huber1bd139a2012-04-03 14:19:20 -0700284 reply->writeInt32(createPlugin(uuid, opaqueData, opaqueSize));
285
Edwin Wong9247e102017-03-13 16:38:20 -0700286 free(opaqueData);
287 opaqueData = NULL;
Andreas Hubered3e3e02012-03-26 11:13:27 -0700288
289 return OK;
290 }
291
Andreas Huber1bd139a2012-04-03 14:19:20 -0700292 case DESTROY_PLUGIN:
Andreas Hubered3e3e02012-03-26 11:13:27 -0700293 {
294 CHECK_INTERFACE(ICrypto, data, reply);
Andreas Huber1bd139a2012-04-03 14:19:20 -0700295 reply->writeInt32(destroyPlugin());
Andreas Hubered3e3e02012-03-26 11:13:27 -0700296
297 return OK;
298 }
299
Andreas Huber1bd139a2012-04-03 14:19:20 -0700300 case REQUIRES_SECURE_COMPONENT:
Andreas Hubered3e3e02012-03-26 11:13:27 -0700301 {
302 CHECK_INTERFACE(ICrypto, data, reply);
303
Andreas Huber1bd139a2012-04-03 14:19:20 -0700304 const char *mime = data.readCString();
Wei Jia2afac0c2016-01-07 12:13:07 -0800305 if (mime == NULL) {
306 reply->writeInt32(BAD_VALUE);
307 } else {
308 reply->writeInt32(requiresSecureDecoderComponent(mime));
309 }
Andreas Hubered3e3e02012-03-26 11:13:27 -0700310
Andreas Huber1bd139a2012-04-03 14:19:20 -0700311 return OK;
312 }
313
314 case DECRYPT:
315 {
316 CHECK_INTERFACE(ICrypto, data, reply);
317
Andreas Huber1bd139a2012-04-03 14:19:20 -0700318 CryptoPlugin::Mode mode = (CryptoPlugin::Mode)data.readInt32();
Jeff Tinker18cb1ec2015-12-18 11:55:22 -0800319 CryptoPlugin::Pattern pattern;
320 pattern.mEncryptBlocks = data.readInt32();
321 pattern.mSkipBlocks = data.readInt32();
Andreas Huber1bd139a2012-04-03 14:19:20 -0700322
323 uint8_t key[16];
324 data.read(key, sizeof(key));
325
326 uint8_t iv[16];
327 data.read(iv, sizeof(iv));
328
329 size_t totalSize = data.readInt32();
Chong Zhang6dcab2b2017-03-28 14:18:27 -0700330
331 SourceBuffer source;
332
333 source.mSharedMemory =
Jeff Tinkerc481b502015-04-06 18:21:05 -0700334 interface_cast<IMemory>(data.readStrongBinder());
Chong Zhang6dcab2b2017-03-28 14:18:27 -0700335 if (source.mSharedMemory == NULL) {
Wei Jia2afac0c2016-01-07 12:13:07 -0800336 reply->writeInt32(BAD_VALUE);
337 return OK;
338 }
Chong Zhang6dcab2b2017-03-28 14:18:27 -0700339 source.mHeapSeqNum = data.readInt32();
340
Jeff Tinkerc481b502015-04-06 18:21:05 -0700341 int32_t offset = data.readInt32();
Andreas Huber1bd139a2012-04-03 14:19:20 -0700342
343 int32_t numSubSamples = data.readInt32();
Jeff Tinker4183d532016-05-20 17:19:31 -0700344 if (numSubSamples < 0 || numSubSamples > 0xffff) {
345 reply->writeInt32(BAD_VALUE);
346 return OK;
347 }
Andreas Huber1bd139a2012-04-03 14:19:20 -0700348
349 CryptoPlugin::SubSample *subSamples =
Jeff Tinkera53d6552017-01-20 00:31:46 -0800350 new CryptoPlugin::SubSample[numSubSamples];
Andreas Huber1bd139a2012-04-03 14:19:20 -0700351
Jeff Tinkera53d6552017-01-20 00:31:46 -0800352 data.read(subSamples,
Andreas Huber1bd139a2012-04-03 14:19:20 -0700353 sizeof(CryptoPlugin::SubSample) * numSubSamples);
354
Jeff Tinkera53d6552017-01-20 00:31:46 -0800355 DestinationBuffer destination;
356 destination.mType = (DestinationType)data.readInt32();
357 if (destination.mType == kDestinationTypeNativeHandle) {
358 destination.mHandle = data.readNativeHandle();
359 if (destination.mHandle == NULL) {
360 reply->writeInt32(BAD_VALUE);
361 return OK;
362 }
363 } else if (destination.mType == kDestinationTypeSharedMemory) {
364 destination.mSharedMemory =
365 interface_cast<IMemory>(data.readStrongBinder());
366 if (destination.mSharedMemory == NULL) {
367 reply->writeInt32(BAD_VALUE);
368 return OK;
369 }
Jeff Tinker5231cc12018-01-11 00:14:53 -0800370 sp<IMemory> dest = destination.mSharedMemory;
371 if (totalSize > dest->size() ||
372 (size_t)dest->offset() > dest->size() - totalSize) {
373 reply->writeInt32(BAD_VALUE);
374 android_errorWriteLog(0x534e4554, "71389378");
375 return OK;
376 }
Jeff Tinker24420472018-01-11 17:46:16 -0800377 } else {
378 reply->writeInt32(BAD_VALUE);
379 android_errorWriteLog(0x534e4554, "70526702");
380 return OK;
Andreas Hubered3e3e02012-03-26 11:13:27 -0700381 }
382
Andreas Huber5b8987e2012-04-19 12:52:20 -0700383 AString errorDetailMsg;
Jeff Tinkerc481b502015-04-06 18:21:05 -0700384 ssize_t result;
385
Jeff Tinkerc6fc6a32015-08-26 20:22:39 -0700386 size_t sumSubsampleSizes = 0;
387 bool overflow = false;
388 for (int32_t i = 0; i < numSubSamples; ++i) {
389 CryptoPlugin::SubSample &ss = subSamples[i];
390 if (sumSubsampleSizes <= SIZE_MAX - ss.mNumBytesOfEncryptedData) {
391 sumSubsampleSizes += ss.mNumBytesOfEncryptedData;
392 } else {
393 overflow = true;
394 }
395 if (sumSubsampleSizes <= SIZE_MAX - ss.mNumBytesOfClearData) {
396 sumSubsampleSizes += ss.mNumBytesOfClearData;
397 } else {
398 overflow = true;
399 }
400 }
401
402 if (overflow || sumSubsampleSizes != totalSize) {
403 result = -EINVAL;
Chong Zhang6dcab2b2017-03-28 14:18:27 -0700404 } else if (totalSize > source.mSharedMemory->size()) {
Jeff Tinkerbb4877d2015-12-04 16:29:16 -0800405 result = -EINVAL;
Chong Zhang6dcab2b2017-03-28 14:18:27 -0700406 } else if ((size_t)offset > source.mSharedMemory->size() - totalSize) {
Jeff Tinkerc481b502015-04-06 18:21:05 -0700407 result = -EINVAL;
408 } else {
Jeff Tinkera53d6552017-01-20 00:31:46 -0800409 result = decrypt(key, iv, mode, pattern, source, offset,
410 subSamples, numSubSamples, destination, &errorDetailMsg);
Jeff Tinkerc481b502015-04-06 18:21:05 -0700411 }
Andreas Hubered3e3e02012-03-26 11:13:27 -0700412
Edwin Wongfa2b8f22012-07-10 20:01:13 -0700413 reply->writeInt32(result);
Andreas Hubered3e3e02012-03-26 11:13:27 -0700414
Jeff Tinkerceffd8c2015-05-05 15:09:14 -0700415 if (isCryptoError(result)) {
Andreas Huber5b8987e2012-04-19 12:52:20 -0700416 reply->writeCString(errorDetailMsg.c_str());
417 }
418
Jeff Tinkera53d6552017-01-20 00:31:46 -0800419 if (destination.mType == kDestinationTypeNativeHandle) {
Jeff Tinker9ac86b32016-01-23 17:27:58 -0800420 int err;
Jeff Tinkera53d6552017-01-20 00:31:46 -0800421 if ((err = native_handle_close(destination.mHandle)) < 0) {
Jeff Tinker9ac86b32016-01-23 17:27:58 -0800422 ALOGW("secure buffer native_handle_close failed: %d", err);
423 }
Jeff Tinkera53d6552017-01-20 00:31:46 -0800424 if ((err = native_handle_delete(destination.mHandle)) < 0) {
Jeff Tinker9ac86b32016-01-23 17:27:58 -0800425 ALOGW("secure buffer native_handle_delete failed: %d", err);
426 }
Andreas Huber1bd139a2012-04-03 14:19:20 -0700427 }
428
429 delete[] subSamples;
430 subSamples = NULL;
Andreas Hubered3e3e02012-03-26 11:13:27 -0700431
Andreas Hubered3e3e02012-03-26 11:13:27 -0700432 return OK;
433 }
434
Jeff Tinker2514d082014-11-03 13:29:35 -0800435 case NOTIFY_RESOLUTION:
436 {
437 CHECK_INTERFACE(ICrypto, data, reply);
438
439 int32_t width = data.readInt32();
440 int32_t height = data.readInt32();
441 notifyResolution(width, height);
442
443 return OK;
444 }
445
Jeff Tinker18495702015-04-10 04:10:59 -0700446 case SET_MEDIADRM_SESSION:
447 {
448 CHECK_INTERFACE(IDrm, data, reply);
449 Vector<uint8_t> sessionId;
450 readVector(data, sessionId);
451 reply->writeInt32(setMediaDrmSession(sessionId));
452 return OK;
453 }
454
Chong Zhangd07c9272017-03-28 11:02:06 -0700455 case SET_HEAP:
456 {
457 CHECK_INTERFACE(ICrypto, data, reply);
458 sp<IMemoryHeap> heap =
459 interface_cast<IMemoryHeap>(data.readStrongBinder());
Chong Zhang6dcab2b2017-03-28 14:18:27 -0700460 reply->writeInt32(setHeap(heap));
Chong Zhangd07c9272017-03-28 11:02:06 -0700461 return OK;
462 }
463
464 case UNSET_HEAP:
465 {
466 CHECK_INTERFACE(ICrypto, data, reply);
Chong Zhang6dcab2b2017-03-28 14:18:27 -0700467 int32_t seqNum = data.readInt32();
468 unsetHeap(seqNum);
Chong Zhangd07c9272017-03-28 11:02:06 -0700469 return OK;
470 }
471
Andreas Hubered3e3e02012-03-26 11:13:27 -0700472 default:
473 return BBinder::onTransact(code, data, reply, flags);
474 }
475}
476
477} // namespace android