summaryrefslogtreecommitdiffstats
path: root/libs/gui
diff options
context:
space:
mode:
authorJamie Gennis <jgennis@google.com>2012-08-30 18:36:22 -0700
committerJamie Gennis <jgennis@google.com>2012-09-04 14:54:34 -0700
commitc68f2ecfa02037144d1a3856f637a77f523cf416 (patch)
tree070c904edf7d136ab08a31b5cd0ae72de1ba436e /libs/gui
parent9e75ddda93888755d0b14144b62e896cd9f78f3a (diff)
downloadframeworks_native-c68f2ecfa02037144d1a3856f637a77f523cf416.zip
frameworks_native-c68f2ecfa02037144d1a3856f637a77f523cf416.tar.gz
frameworks_native-c68f2ecfa02037144d1a3856f637a77f523cf416.tar.bz2
BufferQueue: add a setMaxAcquiredBufferCount check
This change adds a check to verify the validity of the value passed to setMaxAcquiredBufferCount. Change-Id: I39730557aa58261e678bd6e4fce11bab78e98362
Diffstat (limited to 'libs/gui')
-rw-r--r--libs/gui/BufferQueue.cpp5
-rw-r--r--libs/gui/tests/BufferQueue_test.cpp21
2 files changed, 26 insertions, 0 deletions
diff --git a/libs/gui/BufferQueue.cpp b/libs/gui/BufferQueue.cpp
index 4640149..2eee6f5 100644
--- a/libs/gui/BufferQueue.cpp
+++ b/libs/gui/BufferQueue.cpp
@@ -974,6 +974,11 @@ status_t BufferQueue::setDefaultMaxBufferCount(int bufferCount) {
status_t BufferQueue::setMaxAcquiredBufferCount(int maxAcquiredBuffers) {
ATRACE_CALL();
Mutex::Autolock lock(mMutex);
+ if (maxAcquiredBuffers < 1 || maxAcquiredBuffers > MAX_MAX_ACQUIRED_BUFFERS) {
+ ST_LOGE("setMaxAcquiredBufferCount: invalid count specified: %d",
+ maxAcquiredBuffers);
+ return BAD_VALUE;
+ }
if (mConnectedApi != NO_CONNECTED_API) {
return INVALID_OPERATION;
}
diff --git a/libs/gui/tests/BufferQueue_test.cpp b/libs/gui/tests/BufferQueue_test.cpp
index 8601789..817abb4 100644
--- a/libs/gui/tests/BufferQueue_test.cpp
+++ b/libs/gui/tests/BufferQueue_test.cpp
@@ -93,4 +93,25 @@ TEST_F(BufferQueueTest, AcquireBuffer_ExceedsMaxAcquireCount_Fails) {
ASSERT_EQ(INVALID_OPERATION, mBQ->acquireBuffer(&item));
}
+TEST_F(BufferQueueTest, SetMaxAcquiredBufferCountWithIllegalValues_ReturnsError) {
+ sp<DummyConsumer> dc(new DummyConsumer);
+ mBQ->consumerConnect(dc);
+
+ ASSERT_EQ(BAD_VALUE, mBQ->setMaxAcquiredBufferCount(0));
+ ASSERT_EQ(BAD_VALUE, mBQ->setMaxAcquiredBufferCount(-3));
+ ASSERT_EQ(BAD_VALUE, mBQ->setMaxAcquiredBufferCount(
+ BufferQueue::MAX_MAX_ACQUIRED_BUFFERS+1));
+ ASSERT_EQ(BAD_VALUE, mBQ->setMaxAcquiredBufferCount(100));
+}
+
+TEST_F(BufferQueueTest, SetMaxAcquiredBufferCountWithLegalValues_Succeeds) {
+ sp<DummyConsumer> dc(new DummyConsumer);
+ mBQ->consumerConnect(dc);
+
+ ASSERT_EQ(OK, mBQ->setMaxAcquiredBufferCount(1));
+ ASSERT_EQ(OK, mBQ->setMaxAcquiredBufferCount(2));
+ ASSERT_EQ(OK, mBQ->setMaxAcquiredBufferCount(
+ BufferQueue::MAX_MAX_ACQUIRED_BUFFERS));
+}
+
} // namespace android