diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2017-10-11 07:21:12 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2017-10-11 07:21:12 +0000 |
commit | b72c8722a7e6cfe84f75fbd7996d6f9ea6abee51 (patch) | |
tree | d519a1472bf2b2424da6cf1fe8536342c9eb5c0d | |
parent | 9fd500490010bf10238840bcb2b3e9e6dced5207 (diff) | |
parent | 0b9f25d5c9eadb5eda353f5cc01a8bd2d05cf5f2 (diff) | |
download | android_hardware_interfaces-b72c8722a7e6cfe84f75fbd7996d6f9ea6abee51.tar.gz android_hardware_interfaces-b72c8722a7e6cfe84f75fbd7996d6f9ea6abee51.tar.bz2 android_hardware_interfaces-b72c8722a7e6cfe84f75fbd7996d6f9ea6abee51.zip |
Snap for 4388906 from 0b9f25d5c9eadb5eda353f5cc01a8bd2d05cf5f2 to oc-mr1-release
Change-Id: I4d9f66c09a4eaa9bb2237ab1cceddc5914e18f76
-rw-r--r-- | audio/2.0/default/Stream.h | 7 | ||||
-rw-r--r-- | audio/2.0/default/StreamIn.cpp | 12 | ||||
-rw-r--r-- | audio/2.0/default/StreamOut.cpp | 11 | ||||
-rw-r--r-- | cas/1.0/vts/functional/Android.bp | 3 | ||||
-rw-r--r-- | cas/1.0/vts/functional/VtsHalCasV1_0TargetTest.cpp | 69 | ||||
-rw-r--r-- | keymaster/3.0/vts/functional/attestation_record.cpp | 10 |
6 files changed, 63 insertions, 49 deletions
diff --git a/audio/2.0/default/Stream.h b/audio/2.0/default/Stream.h index 82f05a77b..e29af5318 100644 --- a/audio/2.0/default/Stream.h +++ b/audio/2.0/default/Stream.h @@ -49,6 +49,13 @@ using ::android::sp; struct Stream : public IStream, public ParametersUtil { explicit Stream(audio_stream_t* stream); + /** 1GiB is the maximum buffer size the HAL client is allowed to request. + * This value has been chosen to be under SIZE_MAX and still big enough + * for all audio use case. + * Keep private for 2.0, put in .hal in 2.1 + */ + static constexpr uint32_t MAX_BUFFER_SIZE = 2 << 30 /* == 1GiB */; + // Methods from ::android::hardware::audio::V2_0::IStream follow. Return<uint64_t> getFrameSize() override; Return<uint64_t> getFrameCount() override; diff --git a/audio/2.0/default/StreamIn.cpp b/audio/2.0/default/StreamIn.cpp index b81cbb924..9c933a920 100644 --- a/audio/2.0/default/StreamIn.cpp +++ b/audio/2.0/default/StreamIn.cpp @@ -347,14 +347,10 @@ Return<void> StreamIn::prepareForReading(uint32_t frameSize, sendError(Result::INVALID_ARGUMENTS); return Void(); } - // A message queue asserts if it can not handle the requested buffer, - // thus the client has to guess the maximum size it can handle - // Choose an arbitrary margin for the overhead of a message queue - size_t metadataOverhead = 100000; - if (frameSize > - (std::numeric_limits<size_t>::max() - metadataOverhead) / framesCount) { - ALOGE("Buffer too big: %u*%u bytes can not fit in a message queue", - frameSize, framesCount); + + if (frameSize > Stream::MAX_BUFFER_SIZE / framesCount) { + ALOGE("Buffer too big: %u*%u bytes > MAX_BUFFER_SIZE (%u)", frameSize, framesCount, + Stream::MAX_BUFFER_SIZE); sendError(Result::INVALID_ARGUMENTS); return Void(); } diff --git a/audio/2.0/default/StreamOut.cpp b/audio/2.0/default/StreamOut.cpp index 290d0b103..22dcd0c99 100644 --- a/audio/2.0/default/StreamOut.cpp +++ b/audio/2.0/default/StreamOut.cpp @@ -323,14 +323,9 @@ Return<void> StreamOut::prepareForWriting(uint32_t frameSize, sendError(Result::INVALID_ARGUMENTS); return Void(); } - // A message queue asserts if it can not handle the requested buffer, - // thus the client has to guess the maximum size it can handle - size_t metadataOverhead = - 100000; // Arbitrary margin for the overhead of a message queue - if (frameSize > - (std::numeric_limits<size_t>::max() - metadataOverhead) / framesCount) { - ALOGE("Buffer too big: %u*%u bytes can not fit in a message queue", - frameSize, framesCount); + if (frameSize > Stream::MAX_BUFFER_SIZE / framesCount) { + ALOGE("Buffer too big: %u*%u bytes > MAX_BUFFER_SIZE (%u)", frameSize, framesCount, + Stream::MAX_BUFFER_SIZE); sendError(Result::INVALID_ARGUMENTS); return Void(); } diff --git a/cas/1.0/vts/functional/Android.bp b/cas/1.0/vts/functional/Android.bp index 872bb2c55..e1e09e9ce 100644 --- a/cas/1.0/vts/functional/Android.bp +++ b/cas/1.0/vts/functional/Android.bp @@ -25,5 +25,8 @@ cc_test { "android.hidl.memory@1.0", "libhidlmemory", ], + shared_libs: [ + "libbinder", + ], } diff --git a/cas/1.0/vts/functional/VtsHalCasV1_0TargetTest.cpp b/cas/1.0/vts/functional/VtsHalCasV1_0TargetTest.cpp index 062ee2038..4a6ccd764 100644 --- a/cas/1.0/vts/functional/VtsHalCasV1_0TargetTest.cpp +++ b/cas/1.0/vts/functional/VtsHalCasV1_0TargetTest.cpp @@ -25,12 +25,10 @@ #include <android/hardware/cas/1.0/types.h> #include <android/hardware/cas/native/1.0/IDescrambler.h> #include <android/hardware/cas/native/1.0/types.h> -#include <android/hidl/allocator/1.0/IAllocator.h> -#include <android/hidl/memory/1.0/IMapper.h> +#include <binder/MemoryDealer.h> #include <hidl/HidlSupport.h> #include <hidl/HidlTransportSupport.h> #include <hidl/Status.h> -#include <hidlmemory/mapping.h> #include <utils/Condition.h> #include <utils/Mutex.h> @@ -69,9 +67,9 @@ using android::hardware::hidl_handle; using android::hardware::hidl_memory; using android::hardware::Return; using android::hardware::cas::V1_0::Status; -using android::hidl::allocator::V1_0::IAllocator; -using android::hidl::memory::V1_0::IMemory; -using android::hidl::memory::V1_0::IMapper; +using android::IMemory; +using android::IMemoryHeap; +using android::MemoryDealer; using android::Mutex; using android::sp; @@ -230,7 +228,7 @@ class MediaCasHidlTest : public ::testing::VtsHalHidlTargetTestBase { ::testing::AssertionResult openCasSession(std::vector<uint8_t>* sessionId); ::testing::AssertionResult descrambleTestInputBuffer(const sp<IDescrambler>& descrambler, Status* descrambleStatus, - hidl_memory* hidlInMemory); + sp<IMemory>* hidlInMemory); }; ::testing::AssertionResult MediaCasHidlTest::createCasPlugin(int32_t caSystemId) { @@ -271,34 +269,48 @@ class MediaCasHidlTest : public ::testing::VtsHalHidlTargetTestBase { } ::testing::AssertionResult MediaCasHidlTest::descrambleTestInputBuffer( - const sp<IDescrambler>& descrambler, Status* descrambleStatus, hidl_memory* hidlInMemory) { + const sp<IDescrambler>& descrambler, Status* descrambleStatus, sp<IMemory>* inMemory) { hidl_vec<SubSample> hidlSubSamples; hidlSubSamples.setToExternal(const_cast<SubSample*>(kSubSamples), (sizeof(kSubSamples) / sizeof(SubSample)), false /*own*/); - sp<IAllocator> allocator = IAllocator::getService("ashmem"); - if (nullptr == allocator.get()) { + + sp<MemoryDealer> dealer = new MemoryDealer(sizeof(kInBinaryBuffer), "vts-cas"); + if (nullptr == dealer.get()) { + ALOGE("couldn't get MemoryDealer!"); return ::testing::AssertionFailure(); } - bool allocateStatus; - auto returnStatus = - allocator->allocate(sizeof(kInBinaryBuffer), [&](bool status, hidl_memory const& mem) { - allocateStatus = status; - *hidlInMemory = mem; - }); - if (!returnStatus.isOk() || !allocateStatus) { + sp<IMemory> mem = dealer->allocate(sizeof(kInBinaryBuffer)); + if (nullptr == mem.get()) { + ALOGE("couldn't allocate IMemory!"); return ::testing::AssertionFailure(); } - android::sp<IMemory> inMemory = mapMemory(*hidlInMemory); - if (nullptr == inMemory.get()) { + *inMemory = mem; + + // build hidl_memory from memory heap + ssize_t offset; + size_t size; + sp<IMemoryHeap> heap = mem->getMemory(&offset, &size); + if (nullptr == heap.get()) { + ALOGE("couldn't get memory heap!"); + return ::testing::AssertionFailure(); + } + + native_handle_t* nativeHandle = native_handle_create(1, 0); + if (!nativeHandle) { + ALOGE("failed to create native handle!"); return ::testing::AssertionFailure(); } + nativeHandle->data[0] = heap->getHeapID(); - uint8_t* ipBuffer = static_cast<uint8_t*>(static_cast<void*>(inMemory->getPointer())); + uint8_t* ipBuffer = static_cast<uint8_t*>(static_cast<void*>(mem->pointer())); memcpy(ipBuffer, kInBinaryBuffer, sizeof(kInBinaryBuffer)); SharedBuffer srcBuffer = { - .heapBase = *hidlInMemory, .offset = (uint64_t)0, .size = sizeof(kInBinaryBuffer)}; + .heapBase = hidl_memory("ashmem", hidl_handle(nativeHandle), heap->getSize()), + .offset = (uint64_t) offset, + .size = (uint64_t) size + }; DestinationBuffer dstBuffer; dstBuffer.type = BufferType::SHARED_MEMORY; @@ -461,14 +473,13 @@ TEST_F(MediaCasHidlTest, TestClearKeyApis) { ASSERT_NE(descrambler, nullptr); Status descrambleStatus = Status::OK; - hidl_memory hidlDataMemory; + sp<IMemory> dataMemory; - ASSERT_TRUE(descrambleTestInputBuffer(descrambler, &descrambleStatus, &hidlDataMemory)); + ASSERT_TRUE(descrambleTestInputBuffer(descrambler, &descrambleStatus, &dataMemory)); EXPECT_EQ(Status::OK, descrambleStatus); - android::sp<IMemory> outMemory = mapMemory(hidlDataMemory); - ASSERT_NE(nullptr, outMemory.get()); - uint8_t* opBuffer = static_cast<uint8_t*>(static_cast<void*>(outMemory->getPointer())); + ASSERT_NE(nullptr, dataMemory.get()); + uint8_t* opBuffer = static_cast<uint8_t*>(static_cast<void*>(dataMemory->pointer())); int compareResult = memcmp(static_cast<const void*>(opBuffer), static_cast<const void*>(kOutRefBinaryBuffer), @@ -572,9 +583,9 @@ TEST_F(MediaCasHidlTest, TestClearKeyErrors) { ASSERT_NE(descrambler, nullptr); Status descrambleStatus = Status::OK; - hidl_memory hidlInMemory; + sp<IMemory> dataMemory; - ASSERT_TRUE(descrambleTestInputBuffer(descrambler, &descrambleStatus, &hidlInMemory)); + ASSERT_TRUE(descrambleTestInputBuffer(descrambler, &descrambleStatus, &dataMemory)); EXPECT_EQ(Status::ERROR_CAS_DECRYPT_UNIT_NOT_INITIALIZED, descrambleStatus); // Now set a valid session, should still fail because no valid ecm is processed @@ -582,7 +593,7 @@ TEST_F(MediaCasHidlTest, TestClearKeyErrors) { EXPECT_TRUE(returnStatus.isOk()); EXPECT_EQ(Status::OK, returnStatus); - ASSERT_TRUE(descrambleTestInputBuffer(descrambler, &descrambleStatus, &hidlInMemory)); + ASSERT_TRUE(descrambleTestInputBuffer(descrambler, &descrambleStatus, &dataMemory)); EXPECT_EQ(Status::ERROR_CAS_DECRYPT, descrambleStatus); } diff --git a/keymaster/3.0/vts/functional/attestation_record.cpp b/keymaster/3.0/vts/functional/attestation_record.cpp index 5d96fff80..a428989de 100644 --- a/keymaster/3.0/vts/functional/attestation_record.cpp +++ b/keymaster/3.0/vts/functional/attestation_record.cpp @@ -274,10 +274,12 @@ ErrorCode parse_attestation_record(const uint8_t* asn1_key_desc, size_t asn1_key *keymaster_security_level = static_cast<SecurityLevel>(ASN1_ENUMERATED_get(record->keymaster_security_level)); - attestation_challenge->setToExternal(record->attestation_challenge->data, - record->attestation_challenge->length); - - unique_id->setToExternal(record->unique_id->data, record->unique_id->length); + auto& chall = record->attestation_challenge; + attestation_challenge->resize(chall->length); + memcpy(attestation_challenge->data(), chall->data, chall->length); + auto& uid = record->unique_id; + unique_id->resize(uid->length); + memcpy(unique_id->data(), uid->data, uid->length); ErrorCode error = extract_auth_list(record->software_enforced, software_enforced); if (error != ErrorCode::OK) return error; |