From d6976527741b997ad2c70a6a312de35b3fb5d868 Mon Sep 17 00:00:00 2001 From: Yixiao Luo Date: Fri, 26 May 2023 15:24:03 -0700 Subject: [PATCH] Add native handle validation to TV Input HAL AIDL VTS Bug: 282862884 Test: VtsHalTvInputTargetTest Change-Id: I803b54e5b52a00ab845ef7ba4d5cec5bb8bd89ca --- .../vts/functional/VtsHalTvInputTargetTest.cpp | 16 ++++++++++++++++ .../vts/functional/VtsHalTvInputTargetTest.h | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/tv/input/aidl/vts/functional/VtsHalTvInputTargetTest.cpp b/tv/input/aidl/vts/functional/VtsHalTvInputTargetTest.cpp index 6433305ba3..8d3395b8d2 100644 --- a/tv/input/aidl/vts/functional/VtsHalTvInputTargetTest.cpp +++ b/tv/input/aidl/vts/functional/VtsHalTvInputTargetTest.cpp @@ -134,6 +134,19 @@ int32_t TvInputAidlTest::getNumNotIn(vector& nums) { return result; } +bool TvInputAidlTest::isValidHandle(NativeHandle& handle) { + if (handle.fds.empty()) { + return false; + } + for (size_t i = 0; i < handle.fds.size(); i++) { + int fd = handle.fds[i].get(); + if (fcntl(fd, F_GETFL) < 0) { + return false; + } + } + return true; +} + /* * GetStreamConfigTest: * Calls updateStreamConfigurations() for each existing device @@ -168,6 +181,8 @@ TEST_P(TvInputAidlTest, OpenAndCloseStreamTest) { ALOGD("OpenAndCloseStreamTest: open stream, device_id=%d, stream_id=%d", device_id, stream_id); ASSERT_TRUE(tv_input_->openStream(device_id, stream_id, &handle).isOk()); + ASSERT_TRUE(isValidHandle(handle)); + ALOGD("OpenAndCloseStreamTest: close stream, device_id=%d, stream_id=%d", device_id, stream_id); ASSERT_TRUE(tv_input_->closeStream(device_id, stream_id).isOk()); @@ -268,6 +283,7 @@ TEST_P(TvInputAidlTest, OpenAnOpenedStreamsTest) { ALOGD("OpenAnOpenedStreamsTest: open stream, device_id=%d, stream_id=%d", device_id, stream_id); ASSERT_TRUE(tv_input_->openStream(device_id, stream_id, &handle).isOk()); + ASSERT_TRUE(isValidHandle(handle)); ALOGD("OpenAnOpenedStreamsTest: open stream, device_id=%d, stream_id=%d", device_id, stream_id); ASSERT_TRUE(tv_input_->openStream(device_id, stream_id, &handle).getServiceSpecificError() == diff --git a/tv/input/aidl/vts/functional/VtsHalTvInputTargetTest.h b/tv/input/aidl/vts/functional/VtsHalTvInputTargetTest.h index 832b27ce44..7e66a88a32 100644 --- a/tv/input/aidl/vts/functional/VtsHalTvInputTargetTest.h +++ b/tv/input/aidl/vts/functional/VtsHalTvInputTargetTest.h @@ -17,6 +17,7 @@ #pragma once #include +#include #include #include @@ -84,6 +85,9 @@ class TvInputAidlTest : public testing::TestWithParam { */ int32_t getNumNotIn(vector& nums); + /* Checks if a native handle contains valid file descriptor(s). */ + bool isValidHandle(NativeHandle& handle); + protected: shared_ptr tv_input_; shared_ptr tv_input_callback_;