From 4a118d4e1006cc56d058e680bf5808445c22df9a Mon Sep 17 00:00:00 2001 From: Raj Goparaju Date: Sat, 13 May 2023 13:07:41 -0700 Subject: [PATCH] AudioControl: add version check for module change callback APIs With Stable-AIDL structure, we have the same VTS test serving multiple versions. It is possible that vendors implement older version on the latest tree. Therefore, the new API tests should not add new requirements on older versions. Protect the new tests with version check to ensure they are only executed if meeting version requirements. Bug: 281945739 Test: run vts --module VtsAidlHalAudioControlTest Change-Id: Ia186313088a3e8551b11a92259667edd0c6a3878 --- .../aidl/vts/VtsHalAudioControlTargetTest.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/automotive/audiocontrol/aidl/vts/VtsHalAudioControlTargetTest.cpp b/automotive/audiocontrol/aidl/vts/VtsHalAudioControlTargetTest.cpp index f4e3b5ab9d..4e7e963981 100644 --- a/automotive/audiocontrol/aidl/vts/VtsHalAudioControlTargetTest.cpp +++ b/automotive/audiocontrol/aidl/vts/VtsHalAudioControlTargetTest.cpp @@ -53,17 +53,25 @@ using namespace android::audio::policy::configuration::V7_0; namespace audiohalcommon = android::hardware::audio::common; namespace audiomediacommon = android::media::audio::common; +namespace { +constexpr int32_t kAidlVersionThree = 3; +} + class AudioControlAidl : public testing::TestWithParam { public: virtual void SetUp() override { audioControl = android::waitForDeclaredService(String16(GetParam().c_str())); ASSERT_NE(audioControl, nullptr); + aidlVersion = audioControl->getInterfaceVersion(); } void TearDown() override { audioControl = nullptr; } + bool isAidlVersionAtleast(int version) const { return aidlVersion >= version; } + sp audioControl; int32_t capabilities; + int32_t aidlVersion; }; TEST_P(AudioControlAidl, OnSetFadeTowardsFront) { @@ -250,6 +258,11 @@ struct ModuleChangeCallbackMock : BnModuleChangeCallback { TEST_P(AudioControlAidl, RegisterModuleChangeCallbackTwiceThrowsException) { ALOGI("Register Module change callback test"); + if (!isAidlVersionAtleast(kAidlVersionThree)) { + GTEST_SKIP() << "Device does not support the new APIs for module change callback"; + return; + } + // make sure no stale callbacks. audioControl->clearModuleChangeCallback(); @@ -269,6 +282,11 @@ TEST_P(AudioControlAidl, RegisterModuleChangeCallbackTwiceThrowsException) { TEST_P(AudioControlAidl, RegisterModuleChangeNullCallbackThrowsException) { ALOGI("Register Module change callback with nullptr test"); + if (!isAidlVersionAtleast(kAidlVersionThree)) { + GTEST_SKIP() << "Device does not support the new APIs for module change callback"; + return; + } + auto status = audioControl->setModuleChangeCallback(nullptr); EXPECT_THAT(status.exceptionCode(), AnyOf(Eq(Status::EX_ILLEGAL_ARGUMENT), Eq(Status::EX_UNSUPPORTED_OPERATION)));