hardware/interfaces
修订版 | b72c8722a7e6cfe84f75fbd7996d6f9ea6abee51 (tree) |
---|---|
时间 | 2017-10-11 16:21:12 |
作者 | android-build-team Robot <android-build-team-robot@goog...> |
Commiter | android-build-team Robot |
Snap for 4388906 from 0b9f25d5c9eadb5eda353f5cc01a8bd2d05cf5f2 to oc-mr1-release
Change-Id: I4d9f66c09a4eaa9bb2237ab1cceddc5914e18f76
@@ -49,6 +49,13 @@ using ::android::sp; | ||
49 | 49 | struct Stream : public IStream, public ParametersUtil { |
50 | 50 | explicit Stream(audio_stream_t* stream); |
51 | 51 | |
52 | + /** 1GiB is the maximum buffer size the HAL client is allowed to request. | |
53 | + * This value has been chosen to be under SIZE_MAX and still big enough | |
54 | + * for all audio use case. | |
55 | + * Keep private for 2.0, put in .hal in 2.1 | |
56 | + */ | |
57 | + static constexpr uint32_t MAX_BUFFER_SIZE = 2 << 30 /* == 1GiB */; | |
58 | + | |
52 | 59 | // Methods from ::android::hardware::audio::V2_0::IStream follow. |
53 | 60 | Return<uint64_t> getFrameSize() override; |
54 | 61 | Return<uint64_t> getFrameCount() override; |
@@ -347,14 +347,10 @@ Return<void> StreamIn::prepareForReading(uint32_t frameSize, | ||
347 | 347 | sendError(Result::INVALID_ARGUMENTS); |
348 | 348 | return Void(); |
349 | 349 | } |
350 | - // A message queue asserts if it can not handle the requested buffer, | |
351 | - // thus the client has to guess the maximum size it can handle | |
352 | - // Choose an arbitrary margin for the overhead of a message queue | |
353 | - size_t metadataOverhead = 100000; | |
354 | - if (frameSize > | |
355 | - (std::numeric_limits<size_t>::max() - metadataOverhead) / framesCount) { | |
356 | - ALOGE("Buffer too big: %u*%u bytes can not fit in a message queue", | |
357 | - frameSize, framesCount); | |
350 | + | |
351 | + if (frameSize > Stream::MAX_BUFFER_SIZE / framesCount) { | |
352 | + ALOGE("Buffer too big: %u*%u bytes > MAX_BUFFER_SIZE (%u)", frameSize, framesCount, | |
353 | + Stream::MAX_BUFFER_SIZE); | |
358 | 354 | sendError(Result::INVALID_ARGUMENTS); |
359 | 355 | return Void(); |
360 | 356 | } |
@@ -323,14 +323,9 @@ Return<void> StreamOut::prepareForWriting(uint32_t frameSize, | ||
323 | 323 | sendError(Result::INVALID_ARGUMENTS); |
324 | 324 | return Void(); |
325 | 325 | } |
326 | - // A message queue asserts if it can not handle the requested buffer, | |
327 | - // thus the client has to guess the maximum size it can handle | |
328 | - size_t metadataOverhead = | |
329 | - 100000; // Arbitrary margin for the overhead of a message queue | |
330 | - if (frameSize > | |
331 | - (std::numeric_limits<size_t>::max() - metadataOverhead) / framesCount) { | |
332 | - ALOGE("Buffer too big: %u*%u bytes can not fit in a message queue", | |
333 | - frameSize, framesCount); | |
326 | + if (frameSize > Stream::MAX_BUFFER_SIZE / framesCount) { | |
327 | + ALOGE("Buffer too big: %u*%u bytes > MAX_BUFFER_SIZE (%u)", frameSize, framesCount, | |
328 | + Stream::MAX_BUFFER_SIZE); | |
334 | 329 | sendError(Result::INVALID_ARGUMENTS); |
335 | 330 | return Void(); |
336 | 331 | } |
@@ -25,5 +25,8 @@ cc_test { | ||
25 | 25 | "android.hidl.memory@1.0", |
26 | 26 | "libhidlmemory", |
27 | 27 | ], |
28 | + shared_libs: [ | |
29 | + "libbinder", | |
30 | + ], | |
28 | 31 | } |
29 | 32 |
@@ -25,12 +25,10 @@ | ||
25 | 25 | #include <android/hardware/cas/1.0/types.h> |
26 | 26 | #include <android/hardware/cas/native/1.0/IDescrambler.h> |
27 | 27 | #include <android/hardware/cas/native/1.0/types.h> |
28 | -#include <android/hidl/allocator/1.0/IAllocator.h> | |
29 | -#include <android/hidl/memory/1.0/IMapper.h> | |
28 | +#include <binder/MemoryDealer.h> | |
30 | 29 | #include <hidl/HidlSupport.h> |
31 | 30 | #include <hidl/HidlTransportSupport.h> |
32 | 31 | #include <hidl/Status.h> |
33 | -#include <hidlmemory/mapping.h> | |
34 | 32 | #include <utils/Condition.h> |
35 | 33 | #include <utils/Mutex.h> |
36 | 34 |
@@ -69,9 +67,9 @@ using android::hardware::hidl_handle; | ||
69 | 67 | using android::hardware::hidl_memory; |
70 | 68 | using android::hardware::Return; |
71 | 69 | using android::hardware::cas::V1_0::Status; |
72 | -using android::hidl::allocator::V1_0::IAllocator; | |
73 | -using android::hidl::memory::V1_0::IMemory; | |
74 | -using android::hidl::memory::V1_0::IMapper; | |
70 | +using android::IMemory; | |
71 | +using android::IMemoryHeap; | |
72 | +using android::MemoryDealer; | |
75 | 73 | using android::Mutex; |
76 | 74 | using android::sp; |
77 | 75 |
@@ -230,7 +228,7 @@ class MediaCasHidlTest : public ::testing::VtsHalHidlTargetTestBase { | ||
230 | 228 | ::testing::AssertionResult openCasSession(std::vector<uint8_t>* sessionId); |
231 | 229 | ::testing::AssertionResult descrambleTestInputBuffer(const sp<IDescrambler>& descrambler, |
232 | 230 | Status* descrambleStatus, |
233 | - hidl_memory* hidlInMemory); | |
231 | + sp<IMemory>* hidlInMemory); | |
234 | 232 | }; |
235 | 233 | |
236 | 234 | ::testing::AssertionResult MediaCasHidlTest::createCasPlugin(int32_t caSystemId) { |
@@ -271,34 +269,48 @@ class MediaCasHidlTest : public ::testing::VtsHalHidlTargetTestBase { | ||
271 | 269 | } |
272 | 270 | |
273 | 271 | ::testing::AssertionResult MediaCasHidlTest::descrambleTestInputBuffer( |
274 | - const sp<IDescrambler>& descrambler, Status* descrambleStatus, hidl_memory* hidlInMemory) { | |
272 | + const sp<IDescrambler>& descrambler, Status* descrambleStatus, sp<IMemory>* inMemory) { | |
275 | 273 | hidl_vec<SubSample> hidlSubSamples; |
276 | 274 | hidlSubSamples.setToExternal(const_cast<SubSample*>(kSubSamples), |
277 | 275 | (sizeof(kSubSamples) / sizeof(SubSample)), false /*own*/); |
278 | - sp<IAllocator> allocator = IAllocator::getService("ashmem"); | |
279 | - if (nullptr == allocator.get()) { | |
276 | + | |
277 | + sp<MemoryDealer> dealer = new MemoryDealer(sizeof(kInBinaryBuffer), "vts-cas"); | |
278 | + if (nullptr == dealer.get()) { | |
279 | + ALOGE("couldn't get MemoryDealer!"); | |
280 | 280 | return ::testing::AssertionFailure(); |
281 | 281 | } |
282 | 282 | |
283 | - bool allocateStatus; | |
284 | - auto returnStatus = | |
285 | - allocator->allocate(sizeof(kInBinaryBuffer), [&](bool status, hidl_memory const& mem) { | |
286 | - allocateStatus = status; | |
287 | - *hidlInMemory = mem; | |
288 | - }); | |
289 | - if (!returnStatus.isOk() || !allocateStatus) { | |
283 | + sp<IMemory> mem = dealer->allocate(sizeof(kInBinaryBuffer)); | |
284 | + if (nullptr == mem.get()) { | |
285 | + ALOGE("couldn't allocate IMemory!"); | |
290 | 286 | return ::testing::AssertionFailure(); |
291 | 287 | } |
292 | - android::sp<IMemory> inMemory = mapMemory(*hidlInMemory); | |
293 | - if (nullptr == inMemory.get()) { | |
288 | + *inMemory = mem; | |
289 | + | |
290 | + // build hidl_memory from memory heap | |
291 | + ssize_t offset; | |
292 | + size_t size; | |
293 | + sp<IMemoryHeap> heap = mem->getMemory(&offset, &size); | |
294 | + if (nullptr == heap.get()) { | |
295 | + ALOGE("couldn't get memory heap!"); | |
296 | + return ::testing::AssertionFailure(); | |
297 | + } | |
298 | + | |
299 | + native_handle_t* nativeHandle = native_handle_create(1, 0); | |
300 | + if (!nativeHandle) { | |
301 | + ALOGE("failed to create native handle!"); | |
294 | 302 | return ::testing::AssertionFailure(); |
295 | 303 | } |
304 | + nativeHandle->data[0] = heap->getHeapID(); | |
296 | 305 | |
297 | - uint8_t* ipBuffer = static_cast<uint8_t*>(static_cast<void*>(inMemory->getPointer())); | |
306 | + uint8_t* ipBuffer = static_cast<uint8_t*>(static_cast<void*>(mem->pointer())); | |
298 | 307 | memcpy(ipBuffer, kInBinaryBuffer, sizeof(kInBinaryBuffer)); |
299 | 308 | |
300 | 309 | SharedBuffer srcBuffer = { |
301 | - .heapBase = *hidlInMemory, .offset = (uint64_t)0, .size = sizeof(kInBinaryBuffer)}; | |
310 | + .heapBase = hidl_memory("ashmem", hidl_handle(nativeHandle), heap->getSize()), | |
311 | + .offset = (uint64_t) offset, | |
312 | + .size = (uint64_t) size | |
313 | + }; | |
302 | 314 | |
303 | 315 | DestinationBuffer dstBuffer; |
304 | 316 | dstBuffer.type = BufferType::SHARED_MEMORY; |
@@ -461,14 +473,13 @@ TEST_F(MediaCasHidlTest, TestClearKeyApis) { | ||
461 | 473 | ASSERT_NE(descrambler, nullptr); |
462 | 474 | |
463 | 475 | Status descrambleStatus = Status::OK; |
464 | - hidl_memory hidlDataMemory; | |
476 | + sp<IMemory> dataMemory; | |
465 | 477 | |
466 | - ASSERT_TRUE(descrambleTestInputBuffer(descrambler, &descrambleStatus, &hidlDataMemory)); | |
478 | + ASSERT_TRUE(descrambleTestInputBuffer(descrambler, &descrambleStatus, &dataMemory)); | |
467 | 479 | EXPECT_EQ(Status::OK, descrambleStatus); |
468 | 480 | |
469 | - android::sp<IMemory> outMemory = mapMemory(hidlDataMemory); | |
470 | - ASSERT_NE(nullptr, outMemory.get()); | |
471 | - uint8_t* opBuffer = static_cast<uint8_t*>(static_cast<void*>(outMemory->getPointer())); | |
481 | + ASSERT_NE(nullptr, dataMemory.get()); | |
482 | + uint8_t* opBuffer = static_cast<uint8_t*>(static_cast<void*>(dataMemory->pointer())); | |
472 | 483 | |
473 | 484 | int compareResult = |
474 | 485 | memcmp(static_cast<const void*>(opBuffer), static_cast<const void*>(kOutRefBinaryBuffer), |
@@ -572,9 +583,9 @@ TEST_F(MediaCasHidlTest, TestClearKeyErrors) { | ||
572 | 583 | ASSERT_NE(descrambler, nullptr); |
573 | 584 | |
574 | 585 | Status descrambleStatus = Status::OK; |
575 | - hidl_memory hidlInMemory; | |
586 | + sp<IMemory> dataMemory; | |
576 | 587 | |
577 | - ASSERT_TRUE(descrambleTestInputBuffer(descrambler, &descrambleStatus, &hidlInMemory)); | |
588 | + ASSERT_TRUE(descrambleTestInputBuffer(descrambler, &descrambleStatus, &dataMemory)); | |
578 | 589 | EXPECT_EQ(Status::ERROR_CAS_DECRYPT_UNIT_NOT_INITIALIZED, descrambleStatus); |
579 | 590 | |
580 | 591 | // Now set a valid session, should still fail because no valid ecm is processed |
@@ -582,7 +593,7 @@ TEST_F(MediaCasHidlTest, TestClearKeyErrors) { | ||
582 | 593 | EXPECT_TRUE(returnStatus.isOk()); |
583 | 594 | EXPECT_EQ(Status::OK, returnStatus); |
584 | 595 | |
585 | - ASSERT_TRUE(descrambleTestInputBuffer(descrambler, &descrambleStatus, &hidlInMemory)); | |
596 | + ASSERT_TRUE(descrambleTestInputBuffer(descrambler, &descrambleStatus, &dataMemory)); | |
586 | 597 | EXPECT_EQ(Status::ERROR_CAS_DECRYPT, descrambleStatus); |
587 | 598 | } |
588 | 599 |
@@ -274,10 +274,12 @@ ErrorCode parse_attestation_record(const uint8_t* asn1_key_desc, size_t asn1_key | ||
274 | 274 | *keymaster_security_level = |
275 | 275 | static_cast<SecurityLevel>(ASN1_ENUMERATED_get(record->keymaster_security_level)); |
276 | 276 | |
277 | - attestation_challenge->setToExternal(record->attestation_challenge->data, | |
278 | - record->attestation_challenge->length); | |
279 | - | |
280 | - unique_id->setToExternal(record->unique_id->data, record->unique_id->length); | |
277 | + auto& chall = record->attestation_challenge; | |
278 | + attestation_challenge->resize(chall->length); | |
279 | + memcpy(attestation_challenge->data(), chall->data, chall->length); | |
280 | + auto& uid = record->unique_id; | |
281 | + unique_id->resize(uid->length); | |
282 | + memcpy(unique_id->data(), uid->data, uid->length); | |
281 | 283 | |
282 | 284 | ErrorCode error = extract_auth_list(record->software_enforced, software_enforced); |
283 | 285 | if (error != ErrorCode::OK) return error; |