summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorandroid-build-team Robot2017-10-11 02:21:12 -0500
committerandroid-build-team Robot2017-10-11 02:21:12 -0500
commitb72c8722a7e6cfe84f75fbd7996d6f9ea6abee51 (patch)
treed519a1472bf2b2424da6cf1fe8536342c9eb5c0d
parent9fd500490010bf10238840bcb2b3e9e6dced5207 (diff)
parent0b9f25d5c9eadb5eda353f5cc01a8bd2d05cf5f2 (diff)
downloadplatform-hardware-interfaces-b72c8722a7e6cfe84f75fbd7996d6f9ea6abee51.tar.gz
platform-hardware-interfaces-b72c8722a7e6cfe84f75fbd7996d6f9ea6abee51.tar.xz
platform-hardware-interfaces-b72c8722a7e6cfe84f75fbd7996d6f9ea6abee51.zip
Snap for 4388906 from 0b9f25d5c9eadb5eda353f5cc01a8bd2d05cf5f2 to oc-mr1-release
Change-Id: I4d9f66c09a4eaa9bb2237ab1cceddc5914e18f76
-rw-r--r--audio/2.0/default/Stream.h7
-rw-r--r--audio/2.0/default/StreamIn.cpp12
-rw-r--r--audio/2.0/default/StreamOut.cpp11
-rw-r--r--cas/1.0/vts/functional/Android.bp3
-rw-r--r--cas/1.0/vts/functional/VtsHalCasV1_0TargetTest.cpp69
-rw-r--r--keymaster/3.0/vts/functional/attestation_record.cpp10
6 files changed, 63 insertions, 49 deletions
diff --git a/audio/2.0/default/Stream.h b/audio/2.0/default/Stream.h
index 82f05a77..e29af531 100644
--- a/audio/2.0/default/Stream.h
+++ b/audio/2.0/default/Stream.h
@@ -49,6 +49,13 @@ using ::android::sp;
49struct Stream : public IStream, public ParametersUtil { 49struct Stream : public IStream, public ParametersUtil {
50 explicit Stream(audio_stream_t* stream); 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 // Methods from ::android::hardware::audio::V2_0::IStream follow. 59 // Methods from ::android::hardware::audio::V2_0::IStream follow.
53 Return<uint64_t> getFrameSize() override; 60 Return<uint64_t> getFrameSize() override;
54 Return<uint64_t> getFrameCount() override; 61 Return<uint64_t> getFrameCount() override;
diff --git a/audio/2.0/default/StreamIn.cpp b/audio/2.0/default/StreamIn.cpp
index b81cbb92..9c933a92 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,
347 sendError(Result::INVALID_ARGUMENTS); 347 sendError(Result::INVALID_ARGUMENTS);
348 return Void(); 348 return Void();
349 } 349 }
350 // A message queue asserts if it can not handle the requested buffer, 350
351 // thus the client has to guess the maximum size it can handle 351 if (frameSize > Stream::MAX_BUFFER_SIZE / framesCount) {
352 // Choose an arbitrary margin for the overhead of a message queue 352 ALOGE("Buffer too big: %u*%u bytes > MAX_BUFFER_SIZE (%u)", frameSize, framesCount,
353 size_t metadataOverhead = 100000; 353 Stream::MAX_BUFFER_SIZE);
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);
358 sendError(Result::INVALID_ARGUMENTS); 354 sendError(Result::INVALID_ARGUMENTS);
359 return Void(); 355 return Void();
360 } 356 }
diff --git a/audio/2.0/default/StreamOut.cpp b/audio/2.0/default/StreamOut.cpp
index 290d0b10..22dcd0c9 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,
323 sendError(Result::INVALID_ARGUMENTS); 323 sendError(Result::INVALID_ARGUMENTS);
324 return Void(); 324 return Void();
325 } 325 }
326 // A message queue asserts if it can not handle the requested buffer, 326 if (frameSize > Stream::MAX_BUFFER_SIZE / framesCount) {
327 // thus the client has to guess the maximum size it can handle 327 ALOGE("Buffer too big: %u*%u bytes > MAX_BUFFER_SIZE (%u)", frameSize, framesCount,
328 size_t metadataOverhead = 328 Stream::MAX_BUFFER_SIZE);
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);
334 sendError(Result::INVALID_ARGUMENTS); 329 sendError(Result::INVALID_ARGUMENTS);
335 return Void(); 330 return Void();
336 } 331 }
diff --git a/cas/1.0/vts/functional/Android.bp b/cas/1.0/vts/functional/Android.bp
index 872bb2c5..e1e09e9c 100644
--- a/cas/1.0/vts/functional/Android.bp
+++ b/cas/1.0/vts/functional/Android.bp
@@ -25,5 +25,8 @@ cc_test {
25 "android.hidl.memory@1.0", 25 "android.hidl.memory@1.0",
26 "libhidlmemory", 26 "libhidlmemory",
27 ], 27 ],
28 shared_libs: [
29 "libbinder",
30 ],
28} 31}
29 32
diff --git a/cas/1.0/vts/functional/VtsHalCasV1_0TargetTest.cpp b/cas/1.0/vts/functional/VtsHalCasV1_0TargetTest.cpp
index 062ee203..4a6ccd76 100644
--- a/cas/1.0/vts/functional/VtsHalCasV1_0TargetTest.cpp
+++ b/cas/1.0/vts/functional/VtsHalCasV1_0TargetTest.cpp
@@ -25,12 +25,10 @@
25#include <android/hardware/cas/1.0/types.h> 25#include <android/hardware/cas/1.0/types.h>
26#include <android/hardware/cas/native/1.0/IDescrambler.h> 26#include <android/hardware/cas/native/1.0/IDescrambler.h>
27#include <android/hardware/cas/native/1.0/types.h> 27#include <android/hardware/cas/native/1.0/types.h>
28#include <android/hidl/allocator/1.0/IAllocator.h> 28#include <binder/MemoryDealer.h>
29#include <android/hidl/memory/1.0/IMapper.h>
30#include <hidl/HidlSupport.h> 29#include <hidl/HidlSupport.h>
31#include <hidl/HidlTransportSupport.h> 30#include <hidl/HidlTransportSupport.h>
32#include <hidl/Status.h> 31#include <hidl/Status.h>
33#include <hidlmemory/mapping.h>
34#include <utils/Condition.h> 32#include <utils/Condition.h>
35#include <utils/Mutex.h> 33#include <utils/Mutex.h>
36 34
@@ -69,9 +67,9 @@ using android::hardware::hidl_handle;
69using android::hardware::hidl_memory; 67using android::hardware::hidl_memory;
70using android::hardware::Return; 68using android::hardware::Return;
71using android::hardware::cas::V1_0::Status; 69using android::hardware::cas::V1_0::Status;
72using android::hidl::allocator::V1_0::IAllocator; 70using android::IMemory;
73using android::hidl::memory::V1_0::IMemory; 71using android::IMemoryHeap;
74using android::hidl::memory::V1_0::IMapper; 72using android::MemoryDealer;
75using android::Mutex; 73using android::Mutex;
76using android::sp; 74using android::sp;
77 75
@@ -230,7 +228,7 @@ class MediaCasHidlTest : public ::testing::VtsHalHidlTargetTestBase {
230 ::testing::AssertionResult openCasSession(std::vector<uint8_t>* sessionId); 228 ::testing::AssertionResult openCasSession(std::vector<uint8_t>* sessionId);
231 ::testing::AssertionResult descrambleTestInputBuffer(const sp<IDescrambler>& descrambler, 229 ::testing::AssertionResult descrambleTestInputBuffer(const sp<IDescrambler>& descrambler,
232 Status* descrambleStatus, 230 Status* descrambleStatus,
233 hidl_memory* hidlInMemory); 231 sp<IMemory>* hidlInMemory);
234}; 232};
235 233
236::testing::AssertionResult MediaCasHidlTest::createCasPlugin(int32_t caSystemId) { 234::testing::AssertionResult MediaCasHidlTest::createCasPlugin(int32_t caSystemId) {
@@ -271,34 +269,48 @@ class MediaCasHidlTest : public ::testing::VtsHalHidlTargetTestBase {
271} 269}
272 270
273::testing::AssertionResult MediaCasHidlTest::descrambleTestInputBuffer( 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 hidl_vec<SubSample> hidlSubSamples; 273 hidl_vec<SubSample> hidlSubSamples;
276 hidlSubSamples.setToExternal(const_cast<SubSample*>(kSubSamples), 274 hidlSubSamples.setToExternal(const_cast<SubSample*>(kSubSamples),
277 (sizeof(kSubSamples) / sizeof(SubSample)), false /*own*/); 275 (sizeof(kSubSamples) / sizeof(SubSample)), false /*own*/);
278 sp<IAllocator> allocator = IAllocator::getService("ashmem"); 276
279 if (nullptr == allocator.get()) { 277 sp<MemoryDealer> dealer = new MemoryDealer(sizeof(kInBinaryBuffer), "vts-cas");
278 if (nullptr == dealer.get()) {
279 ALOGE("couldn't get MemoryDealer!");
280 return ::testing::AssertionFailure(); 280 return ::testing::AssertionFailure();
281 } 281 }
282 282
283 bool allocateStatus; 283 sp<IMemory> mem = dealer->allocate(sizeof(kInBinaryBuffer));
284 auto returnStatus = 284 if (nullptr == mem.get()) {
285 allocator->allocate(sizeof(kInBinaryBuffer), [&](bool status, hidl_memory const& mem) { 285 ALOGE("couldn't allocate IMemory!");
286 allocateStatus = status;
287 *hidlInMemory = mem;
288 });
289 if (!returnStatus.isOk() || !allocateStatus) {
290 return ::testing::AssertionFailure(); 286 return ::testing::AssertionFailure();
291 } 287 }
292 android::sp<IMemory> inMemory = mapMemory(*hidlInMemory); 288 *inMemory = mem;
293 if (nullptr == inMemory.get()) { 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 return ::testing::AssertionFailure(); 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 memcpy(ipBuffer, kInBinaryBuffer, sizeof(kInBinaryBuffer)); 307 memcpy(ipBuffer, kInBinaryBuffer, sizeof(kInBinaryBuffer));
299 308
300 SharedBuffer srcBuffer = { 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 DestinationBuffer dstBuffer; 315 DestinationBuffer dstBuffer;
304 dstBuffer.type = BufferType::SHARED_MEMORY; 316 dstBuffer.type = BufferType::SHARED_MEMORY;
@@ -461,14 +473,13 @@ TEST_F(MediaCasHidlTest, TestClearKeyApis) {
461 ASSERT_NE(descrambler, nullptr); 473 ASSERT_NE(descrambler, nullptr);
462 474
463 Status descrambleStatus = Status::OK; 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 EXPECT_EQ(Status::OK, descrambleStatus); 479 EXPECT_EQ(Status::OK, descrambleStatus);
468 480
469 android::sp<IMemory> outMemory = mapMemory(hidlDataMemory); 481 ASSERT_NE(nullptr, dataMemory.get());
470 ASSERT_NE(nullptr, outMemory.get()); 482 uint8_t* opBuffer = static_cast<uint8_t*>(static_cast<void*>(dataMemory->pointer()));
471 uint8_t* opBuffer = static_cast<uint8_t*>(static_cast<void*>(outMemory->getPointer()));
472 483
473 int compareResult = 484 int compareResult =
474 memcmp(static_cast<const void*>(opBuffer), static_cast<const void*>(kOutRefBinaryBuffer), 485 memcmp(static_cast<const void*>(opBuffer), static_cast<const void*>(kOutRefBinaryBuffer),
@@ -572,9 +583,9 @@ TEST_F(MediaCasHidlTest, TestClearKeyErrors) {
572 ASSERT_NE(descrambler, nullptr); 583 ASSERT_NE(descrambler, nullptr);
573 584
574 Status descrambleStatus = Status::OK; 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 EXPECT_EQ(Status::ERROR_CAS_DECRYPT_UNIT_NOT_INITIALIZED, descrambleStatus); 589 EXPECT_EQ(Status::ERROR_CAS_DECRYPT_UNIT_NOT_INITIALIZED, descrambleStatus);
579 590
580 // Now set a valid session, should still fail because no valid ecm is processed 591 // Now set a valid session, should still fail because no valid ecm is processed
@@ -582,7 +593,7 @@ TEST_F(MediaCasHidlTest, TestClearKeyErrors) {
582 EXPECT_TRUE(returnStatus.isOk()); 593 EXPECT_TRUE(returnStatus.isOk());
583 EXPECT_EQ(Status::OK, returnStatus); 594 EXPECT_EQ(Status::OK, returnStatus);
584 595
585 ASSERT_TRUE(descrambleTestInputBuffer(descrambler, &descrambleStatus, &hidlInMemory)); 596 ASSERT_TRUE(descrambleTestInputBuffer(descrambler, &descrambleStatus, &dataMemory));
586 EXPECT_EQ(Status::ERROR_CAS_DECRYPT, descrambleStatus); 597 EXPECT_EQ(Status::ERROR_CAS_DECRYPT, descrambleStatus);
587} 598}
588 599
diff --git a/keymaster/3.0/vts/functional/attestation_record.cpp b/keymaster/3.0/vts/functional/attestation_record.cpp
index 5d96fff8..a428989d 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
274 *keymaster_security_level = 274 *keymaster_security_level =
275 static_cast<SecurityLevel>(ASN1_ENUMERATED_get(record->keymaster_security_level)); 275 static_cast<SecurityLevel>(ASN1_ENUMERATED_get(record->keymaster_security_level));
276 276
277 attestation_challenge->setToExternal(record->attestation_challenge->data, 277 auto& chall = record->attestation_challenge;
278 record->attestation_challenge->length); 278 attestation_challenge->resize(chall->length);
279 279 memcpy(attestation_challenge->data(), chall->data, chall->length);
280 unique_id->setToExternal(record->unique_id->data, record->unique_id->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 ErrorCode error = extract_auth_list(record->software_enforced, software_enforced); 284 ErrorCode error = extract_auth_list(record->software_enforced, software_enforced);
283 if (error != ErrorCode::OK) return error; 285 if (error != ErrorCode::OK) return error;