diff --git a/audio/common/all-versions/default/tests/hidlutils6_tests.cpp b/audio/common/all-versions/default/tests/hidlutils6_tests.cpp index 3a24e752bc..ca59b9de6c 100644 --- a/audio/common/all-versions/default/tests/hidlutils6_tests.cpp +++ b/audio/common/all-versions/default/tests/hidlutils6_tests.cpp @@ -23,14 +23,14 @@ #include using namespace android; -using namespace ::android::hardware::audio::common::CPP_VERSION; -using ::android::hardware::audio::common::CPP_VERSION::implementation::HidlUtils; +using namespace ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION; +using ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION::implementation::HidlUtils; // Not generated automatically because DeviceAddress contains // an union. // // operator== must be defined in the same namespace as the data type. -namespace android::hardware::audio::common::CPP_VERSION { +namespace android::hardware::audio::common::COMMON_TYPES_CPP_VERSION { inline bool operator==(const DeviceAddress& lhs, const DeviceAddress& rhs) { if (lhs.device != rhs.device) return false; @@ -49,7 +49,7 @@ inline bool operator==(const DeviceAddress& lhs, const DeviceAddress& rhs) { return lhs.busAddress == rhs.busAddress; } -} // namespace android::hardware::audio::common::CPP_VERSION +} // namespace android::hardware::audio::common::COMMON_TYPES_CPP_VERSION static void ConvertDeviceAddress(const DeviceAddress& device) { audio_devices_t halDeviceType; diff --git a/audio/common/all-versions/default/tests/hidlutils_tests.cpp b/audio/common/all-versions/default/tests/hidlutils_tests.cpp index c9e6fac7b2..2749cce748 100644 --- a/audio/common/all-versions/default/tests/hidlutils_tests.cpp +++ b/audio/common/all-versions/default/tests/hidlutils_tests.cpp @@ -29,8 +29,8 @@ using namespace android; using ::android::hardware::hidl_vec; -using namespace ::android::hardware::audio::common::CPP_VERSION; -using ::android::hardware::audio::common::CPP_VERSION::implementation::HidlUtils; +using namespace ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION; +using ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION::implementation::HidlUtils; namespace xsd { using namespace ::android::audio::policy::configuration::V7_0; } diff --git a/audio/core/all-versions/default/util/tests/coreutils_tests.cpp b/audio/core/all-versions/default/util/tests/coreutils_tests.cpp index 0c18482632..3976b088e4 100644 --- a/audio/core/all-versions/default/util/tests/coreutils_tests.cpp +++ b/audio/core/all-versions/default/util/tests/coreutils_tests.cpp @@ -28,7 +28,7 @@ #include using namespace android; -using namespace ::android::hardware::audio::common::CPP_VERSION; +using namespace ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION; using namespace ::android::hardware::audio::CPP_VERSION; using ::android::hardware::hidl_vec; using ::android::hardware::audio::CPP_VERSION::implementation::CoreUtils; diff --git a/audio/core/all-versions/vts/functional/2.0/AudioPrimaryHidlHalUtils.h b/audio/core/all-versions/vts/functional/2.0/AudioPrimaryHidlHalUtils.h index 1cffd41831..dd80dd6fbc 100644 --- a/audio/core/all-versions/vts/functional/2.0/AudioPrimaryHidlHalUtils.h +++ b/audio/core/all-versions/vts/functional/2.0/AudioPrimaryHidlHalUtils.h @@ -14,16 +14,18 @@ * limitations under the License. */ +// clang-format off #include PATH(android/hardware/audio/FILE_VERSION/IStream.h) -#include PATH(android/hardware/audio/FILE_VERSION/types.h) -#include PATH(android/hardware/audio/common/FILE_VERSION/types.h) +#include PATH(android/hardware/audio/CORE_TYPES_FILE_VERSION/types.h) +#include PATH(android/hardware/audio/common/COMMON_TYPES_FILE_VERSION/types.h) +// clang-format on #include using ::android::hardware::hidl_handle; using ::android::hardware::hidl_string; using ::android::hardware::hidl_vec; -using ::android::hardware::audio::common::CPP_VERSION::AudioChannelMask; -using ::android::hardware::audio::common::CPP_VERSION::AudioFormat; +using ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION::AudioChannelMask; +using ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION::AudioFormat; using ::android::hardware::audio::CPP_VERSION::IStream; using ::android::hardware::audio::CPP_VERSION::ParameterValue; using ::android::hardware::audio::CPP_VERSION::Result; diff --git a/audio/core/all-versions/vts/functional/4.0/AudioPrimaryHidlHalTest.cpp b/audio/core/all-versions/vts/functional/4.0/AudioPrimaryHidlHalTest.cpp index 787654bdd3..a9797bbfbd 100644 --- a/audio/core/all-versions/vts/functional/4.0/AudioPrimaryHidlHalTest.cpp +++ b/audio/core/all-versions/vts/functional/4.0/AudioPrimaryHidlHalTest.cpp @@ -17,7 +17,7 @@ #include "AudioPrimaryHidlHalTest.h" #if MAJOR_VERSION >= 7 -#include +#include PATH(APM_XSD_H_FILENAME) #include using android::xsdc_enum_range; @@ -28,17 +28,37 @@ TEST_P(AudioHidlTest, OpenPrimaryDeviceUsingGetDevice) { if (getDeviceName() != DeviceManager::kPrimaryDevice) { GTEST_SKIP() << "No primary device on this factory"; // returns } - - { // Scope for device SPs - sp baseDevice = - DeviceManager::getInstance().get(getFactoryName(), DeviceManager::kPrimaryDevice); - ASSERT_TRUE(baseDevice != nullptr); - Return> primaryDevice = IPrimaryDevice::castFrom(baseDevice); - EXPECT_TRUE(primaryDevice.isOk()); - EXPECT_TRUE(sp(primaryDevice) != nullptr); - } EXPECT_TRUE( DeviceManager::getInstance().reset(getFactoryName(), DeviceManager::kPrimaryDevice)); + + // Must use IDevicesFactory directly because DeviceManager always uses + // the latest interfaces version and corresponding methods for opening + // them. However, in minor package uprevs IPrimaryDevice does not inherit + // IDevice from the same package and thus IDevice can not be upcasted + // (see the interfaces in V7.1). + auto factory = DevicesFactoryManager::getInstance().get(getFactoryName()); + ASSERT_TRUE(factory != nullptr); + sp<::android::hardware::audio::CORE_TYPES_CPP_VERSION::IDevice> baseDevice; + Result result; + auto ret = factory->openDevice(DeviceManager::kPrimaryDevice, returnIn(result, baseDevice)); + ASSERT_TRUE(ret.isOk()) << ret.description(); + ASSERT_EQ(Result::OK, result); + ASSERT_TRUE(baseDevice != nullptr); + { + Return> + primaryDevice = ::android::hardware::audio::CORE_TYPES_CPP_VERSION::IPrimaryDevice:: + castFrom(baseDevice); + EXPECT_TRUE(primaryDevice.isOk()); + EXPECT_TRUE(sp<::android::hardware::audio::CORE_TYPES_CPP_VERSION::IPrimaryDevice>( + primaryDevice) != nullptr); + } +#if MAJOR_VERSION < 6 + baseDevice.clear(); + DeviceManager::waitForInstanceDestruction(); +#else + auto closeRet = baseDevice->close(); + EXPECT_TRUE(closeRet.isOk()); +#endif } ////////////////////////////////////////////////////////////////////////////// @@ -183,7 +203,7 @@ TEST_IO_STREAM(SetDevices, "Check that the stream can be rerouted to SPEAKER or areAudioPatchesSupported() ? doc::partialTest("Audio patches are supported") : testSetDevices(stream.get(), address)) -static void checkGetHwAVSync(IDevice* device) { +static void checkGetHwAVSync(::android::hardware::audio::CPP_VERSION::IDevice* device) { Result res; AudioHwSync sync; ASSERT_OK(device->getHwAvSync(returnIn(res, sync))); @@ -215,7 +235,7 @@ TEST_P(InputStreamTest, updateSinkMetadata) { ASSERT_OK(stream->updateSinkMetadata(initMetadata)); #elif MAJOR_VERSION >= 7 - xsdc_enum_range range; + xsdc_enum_range range; // Test all possible track configuration for (auto source : range) { for (float volume : {0.0, 0.5, 1.0}) { @@ -272,8 +292,9 @@ TEST_P(OutputStreamTest, updateSourceMetadata) { // Restore initial ASSERT_OK(stream->updateSourceMetadata(initMetadata)); #elif MAJOR_VERSION >= 7 - xsdc_enum_range usageRange; - xsdc_enum_range contentRange; + xsdc_enum_range usageRange; + xsdc_enum_range + contentRange; // Test all possible track configuration for (auto usage : usageRange) { for (auto content : contentRange) { diff --git a/audio/core/all-versions/vts/functional/4.0/AudioPrimaryHidlHalUtils.h b/audio/core/all-versions/vts/functional/4.0/AudioPrimaryHidlHalUtils.h index 81a1f7b4b7..a567cf90e2 100644 --- a/audio/core/all-versions/vts/functional/4.0/AudioPrimaryHidlHalUtils.h +++ b/audio/core/all-versions/vts/functional/4.0/AudioPrimaryHidlHalUtils.h @@ -14,33 +14,36 @@ * limitations under the License. */ -#include PATH(android/hardware/audio/FILE_VERSION/IStream.h) -#include PATH(android/hardware/audio/FILE_VERSION/types.h) -#include PATH(android/hardware/audio/common/FILE_VERSION/types.h) +// clang-format off +#include PATH(android/hardware/audio/FILE_VERSION/IStreamIn.h) +#include PATH(android/hardware/audio/FILE_VERSION/IStreamOut.h) +#include PATH(android/hardware/audio/CORE_TYPES_FILE_VERSION/types.h) +#include PATH(android/hardware/audio/common/COMMON_TYPES_FILE_VERSION/types.h) +// clang-format on #include using ::android::hardware::hidl_bitfield; using ::android::hardware::hidl_handle; using ::android::hardware::hidl_string; using ::android::hardware::hidl_vec; -using ::android::hardware::audio::common::CPP_VERSION::AudioChannelMask; -using ::android::hardware::audio::common::CPP_VERSION::AudioFormat; -using ::android::hardware::audio::CPP_VERSION::IStream; -using ::android::hardware::audio::CPP_VERSION::ParameterValue; -using ::android::hardware::audio::CPP_VERSION::Result; +using ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION::AudioChannelMask; +using ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION::AudioFormat; +using ::android::hardware::audio::CORE_TYPES_CPP_VERSION::IStream; +using ::android::hardware::audio::CORE_TYPES_CPP_VERSION::ParameterValue; +using ::android::hardware::audio::CORE_TYPES_CPP_VERSION::Result; using namespace ::android::hardware::audio::common::test::utility; -using Rotation = ::android::hardware::audio::CPP_VERSION::IPrimaryDevice::Rotation; -using ::android::hardware::audio::common::CPP_VERSION::AudioContentType; -using ::android::hardware::audio::common::CPP_VERSION::AudioUsage; -using ::android::hardware::audio::CPP_VERSION::MicrophoneInfo; +using Rotation = ::android::hardware::audio::CORE_TYPES_CPP_VERSION::IPrimaryDevice::Rotation; +using ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION::AudioContentType; +using ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION::AudioUsage; +using ::android::hardware::audio::CORE_TYPES_CPP_VERSION::MicrophoneInfo; #if MAJOR_VERSION < 5 using ::android::hardware::audio::CPP_VERSION::SinkMetadata; using ::android::hardware::audio::CPP_VERSION::SourceMetadata; #else -using ::android::hardware::audio::common::CPP_VERSION::SinkMetadata; -using ::android::hardware::audio::common::CPP_VERSION::SourceMetadata; +using ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION::SinkMetadata; +using ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION::SourceMetadata; #endif struct Parameters { diff --git a/audio/core/all-versions/vts/functional/6.0/AudioPrimaryHidlHalTest.cpp b/audio/core/all-versions/vts/functional/6.0/AudioPrimaryHidlHalTest.cpp index 8af4c7855a..aef94da6eb 100644 --- a/audio/core/all-versions/vts/functional/6.0/AudioPrimaryHidlHalTest.cpp +++ b/audio/core/all-versions/vts/functional/6.0/AudioPrimaryHidlHalTest.cpp @@ -59,7 +59,8 @@ TEST_P(DualMonoModeAccessorHidlTest, DualMonoModeTest) { testAccessors(&OutputStreamTest::getStream, "dual mono mode", Initial{DualMonoMode::OFF}, {DualMonoMode::LR, DualMonoMode::LL, DualMonoMode::RR}, - &IStreamOut::setDualMonoMode, &IStreamOut::getDualMonoMode); + &::android::hardware::audio::CPP_VERSION::IStreamOut::setDualMonoMode, + &::android::hardware::audio::CPP_VERSION::IStreamOut::getDualMonoMode); } GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(DualMonoModeAccessorHidlTest); @@ -73,7 +74,8 @@ TEST_P(AudioDescriptionMixLevelHidlTest, AudioDescriptionMixLevelTest) { testAccessors( &OutputStreamTest::getStream, "audio description mix level", Initial{-std::numeric_limits::infinity()}, {-48.0f, -1.0f, 0.0f, 1.0f, 48.0f}, - &IStreamOut::setAudioDescriptionMixLevel, &IStreamOut::getAudioDescriptionMixLevel, + &::android::hardware::audio::CPP_VERSION::IStreamOut::setAudioDescriptionMixLevel, + &::android::hardware::audio::CPP_VERSION::IStreamOut::getAudioDescriptionMixLevel, {48.5f, 1000.0f, std::numeric_limits::infinity()}); } @@ -105,7 +107,8 @@ TEST_P(PlaybackRateParametersHidlTest, PlaybackRateParametersTest) { PlaybackRate{0.5f, 0.5f, TimestretchMode::VOICE, TimestretchFallbackMode::MUTE}, PlaybackRate{1000.0f, 1000.0f, TimestretchMode::VOICE, TimestretchFallbackMode::MUTE}, PlaybackRate{1.0f, 1.0f, TimestretchMode::VOICE, TimestretchFallbackMode::FAIL}}, - &IStreamOut::setPlaybackRateParameters, &IStreamOut::getPlaybackRateParameters, + &::android::hardware::audio::CPP_VERSION::IStreamOut::setPlaybackRateParameters, + &::android::hardware::audio::CPP_VERSION::IStreamOut::getPlaybackRateParameters, {PlaybackRate{1000.0f, 1000.0f, TimestretchMode::DEFAULT, TimestretchFallbackMode::FAIL}, PlaybackRate{1000.0f, 1000.0f, TimestretchMode::VOICE, diff --git a/audio/core/all-versions/vts/functional/6.0/Generators.cpp b/audio/core/all-versions/vts/functional/6.0/Generators.cpp index e3b98c909f..dafd32697b 100644 --- a/audio/core/all-versions/vts/functional/6.0/Generators.cpp +++ b/audio/core/all-versions/vts/functional/6.0/Generators.cpp @@ -21,8 +21,8 @@ #include "PolicyConfig.h" // clang-format off -#include PATH(android/hardware/audio/FILE_VERSION/types.h) -#include PATH(android/hardware/audio/common/FILE_VERSION/types.h) +#include PATH(android/hardware/audio/CORE_TYPES_FILE_VERSION/types.h) +#include PATH(android/hardware/audio/common/COMMON_TYPES_FILE_VERSION/types.h) // clang-format on // Forward declaration for functions that are substituted @@ -30,7 +30,7 @@ const PolicyConfig& getCachedPolicyConfig(); const std::vector& getDeviceParameters(); -using namespace ::android::hardware::audio::common::CPP_VERSION; +using namespace ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION; using namespace ::android::hardware::audio::CPP_VERSION; std::vector generateOutputDeviceConfigParameters(bool oneProfilePerDevice) { diff --git a/audio/core/all-versions/vts/functional/7.0/AudioPrimaryHidlHalTest.cpp b/audio/core/all-versions/vts/functional/7.0/AudioPrimaryHidlHalTest.cpp index 27598012fe..96cd52716a 100644 --- a/audio/core/all-versions/vts/functional/7.0/AudioPrimaryHidlHalTest.cpp +++ b/audio/core/all-versions/vts/functional/7.0/AudioPrimaryHidlHalTest.cpp @@ -381,13 +381,13 @@ TEST_P(StreamOpenTest, OpenInputOrOutputStreamTest) { "IDevice::open{Input|Output}Stream method."); AudioConfig suggestedConfig{}; if (isParamForInputStream()) { - sp stream; + sp<::android::hardware::audio::CORE_TYPES_CPP_VERSION::IStreamIn> stream; ASSERT_OK(getDevice()->openInputStream(AudioIoHandle{}, getDeviceAddress(), getConfig(), getFlags(), getSinkMetadata(), returnIn(res, stream, suggestedConfig))); ASSERT_TRUE(stream == nullptr); } else { - sp stream; + sp<::android::hardware::audio::CORE_TYPES_CPP_VERSION::IStreamOut> stream; ASSERT_OK(getDevice()->openOutputStream(AudioIoHandle{}, getDeviceAddress(), getConfig(), getFlags(), getSourceMetadata(), returnIn(res, stream, suggestedConfig))); @@ -551,13 +551,15 @@ class PcmOnlyConfigOutputStreamTest : public OutputStreamTest { } void releasePatchIfNeeded() { - if (areAudioPatchesSupported()) { - if (mHasPatch) { + if (getDevice()) { + if (areAudioPatchesSupported() && mHasPatch) { EXPECT_OK(getDevice()->releaseAudioPatch(mPatchHandle)); mHasPatch = false; } } else { - EXPECT_OK(stream->setDevices({address})); + if (stream) { + EXPECT_OK(stream->setDevices({address})); + } } } @@ -724,13 +726,15 @@ class PcmOnlyConfigInputStreamTest : public InputStreamTest { } void releasePatchIfNeeded() { - if (areAudioPatchesSupported()) { - if (mHasPatch) { + if (getDevice()) { + if (areAudioPatchesSupported() && mHasPatch) { EXPECT_OK(getDevice()->releaseAudioPatch(mPatchHandle)); mHasPatch = false; } } else { - EXPECT_OK(stream->setDevices({address})); + if (stream) { + EXPECT_OK(stream->setDevices({address})); + } } } diff --git a/audio/core/all-versions/vts/functional/7.0/Generators.cpp b/audio/core/all-versions/vts/functional/7.0/Generators.cpp index 42bf1d341d..f936d0afbf 100644 --- a/audio/core/all-versions/vts/functional/7.0/Generators.cpp +++ b/audio/core/all-versions/vts/functional/7.0/Generators.cpp @@ -20,20 +20,20 @@ #include "7.0/PolicyConfig.h" // clang-format off -#include PATH(android/hardware/audio/FILE_VERSION/types.h) -#include PATH(android/hardware/audio/common/FILE_VERSION/types.h) +#include PATH(android/hardware/audio/CORE_TYPES_FILE_VERSION/types.h) +#include PATH(android/hardware/audio/common/COMMON_TYPES_FILE_VERSION/types.h) // clang-format on -#include -#include +#include PATH(APM_XSD_ENUMS_H_FILENAME) +#include PATH(APM_XSD_H_FILENAME) // Forward declaration for functions that are substituted // in generator unit tests. const PolicyConfig& getCachedPolicyConfig(); const std::vector& getDeviceParameters(); -using namespace ::android::hardware::audio::common::CPP_VERSION; -using namespace ::android::hardware::audio::CPP_VERSION; +using namespace ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION; +using namespace ::android::hardware::audio::CORE_TYPES_CPP_VERSION; namespace xsd { using namespace ::android::audio::policy::configuration::CPP_VERSION; } diff --git a/audio/core/all-versions/vts/functional/7.0/PolicyConfig.cpp b/audio/core/all-versions/vts/functional/7.0/PolicyConfig.cpp index 29882077d1..d674403a2c 100644 --- a/audio/core/all-versions/vts/functional/7.0/PolicyConfig.cpp +++ b/audio/core/all-versions/vts/functional/7.0/PolicyConfig.cpp @@ -30,9 +30,9 @@ using ::android::NO_ERROR; using ::android::OK; -using namespace ::android::hardware::audio::common::CPP_VERSION; -using namespace ::android::hardware::audio::CPP_VERSION; -using ::android::hardware::audio::common::CPP_VERSION::implementation::HidlUtils; +using namespace ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION; +using namespace ::android::hardware::audio::CORE_TYPES_CPP_VERSION; +using ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION::implementation::HidlUtils; using ::android::hardware::audio::common::utils::splitString; namespace xsd { using namespace ::android::audio::policy::configuration::CPP_VERSION; diff --git a/audio/core/all-versions/vts/functional/7.0/PolicyConfig.h b/audio/core/all-versions/vts/functional/7.0/PolicyConfig.h index f798839cb8..4aea503938 100644 --- a/audio/core/all-versions/vts/functional/7.0/PolicyConfig.h +++ b/audio/core/all-versions/vts/functional/7.0/PolicyConfig.h @@ -25,15 +25,15 @@ #include // clang-format off -#include PATH(android/hardware/audio/FILE_VERSION/types.h) -#include PATH(android/hardware/audio/common/FILE_VERSION/types.h) +#include PATH(android/hardware/audio/CORE_TYPES_FILE_VERSION/types.h) +#include PATH(android/hardware/audio/common/COMMON_TYPES_FILE_VERSION/types.h) // clang-format on -#include -#include +#include PATH(APM_XSD_ENUMS_H_FILENAME) +#include PATH(APM_XSD_H_FILENAME) -using namespace ::android::hardware::audio::common::CPP_VERSION; -using namespace ::android::hardware::audio::CPP_VERSION; +using namespace ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION; +using namespace ::android::hardware::audio::CORE_TYPES_CPP_VERSION; namespace xsd { using namespace ::android::audio::policy::configuration::CPP_VERSION; using Module = Modules::Module; diff --git a/audio/core/all-versions/vts/functional/7.1/AudioPrimaryHidlHalTest.cpp b/audio/core/all-versions/vts/functional/7.1/AudioPrimaryHidlHalTest.cpp new file mode 100644 index 0000000000..b750f56ca2 --- /dev/null +++ b/audio/core/all-versions/vts/functional/7.1/AudioPrimaryHidlHalTest.cpp @@ -0,0 +1,18 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// pull in all the <= 7.0 tests +#include "7.0/AudioPrimaryHidlHalTest.cpp" diff --git a/audio/core/all-versions/vts/functional/Android.bp b/audio/core/all-versions/vts/functional/Android.bp index b280d7c3ae..61ab1bbb6d 100644 --- a/audio/core/all-versions/vts/functional/Android.bp +++ b/audio/core/all-versions/vts/functional/Android.bp @@ -184,6 +184,39 @@ cc_test { test_config: "VtsHalAudioV7_0TargetTest.xml", } +cc_test { + name: "VtsHalAudioV7_1TargetTest", + defaults: ["VtsHalAudioTargetTest_defaults"], + srcs: [ + "7.1/AudioPrimaryHidlHalTest.cpp", + "7.0/Generators.cpp", + "7.0/PolicyConfig.cpp", + ], + generated_headers: ["audio_policy_configuration_V7_1_parser"], + generated_sources: ["audio_policy_configuration_V7_1_parser"], + static_libs: [ + "android.hardware.audio@7.0", + "android.hardware.audio@7.1", + "android.hardware.audio.common@7.0", + "android.hardware.audio.common@7.0-enums", + "android.hardware.audio.common@7.1-enums", + "android.hardware.audio.common@7.0-util", + ], + cflags: [ + "-DMAJOR_VERSION=7", + "-DMINOR_VERSION=1", + "-DCOMMON_TYPES_MINOR_VERSION=0", + "-DCORE_TYPES_MINOR_VERSION=0", + "-include common/all-versions/VersionMacro.h", + ], + data: [ + ":audio_policy_configuration_V7_1", + ], + // Use test_config for vts suite. + // TODO(b/146104851): Add auto-gen rules and remove it. + test_config: "VtsHalAudioV7_1TargetTest.xml", +} + // Note: the following aren't VTS tests, but rather unit tests // to verify correctness of test utilities. cc_test { diff --git a/audio/core/all-versions/vts/functional/AudioPrimaryHidlHalTest.h b/audio/core/all-versions/vts/functional/AudioPrimaryHidlHalTest.h index 340903a4ea..404532a6fa 100644 --- a/audio/core/all-versions/vts/functional/AudioPrimaryHidlHalTest.h +++ b/audio/core/all-versions/vts/functional/AudioPrimaryHidlHalTest.h @@ -37,15 +37,17 @@ #include #include +// clang-format off #include PATH(android/hardware/audio/FILE_VERSION/IDevice.h) #include PATH(android/hardware/audio/FILE_VERSION/IDevicesFactory.h) #include PATH(android/hardware/audio/FILE_VERSION/IPrimaryDevice.h) -#include PATH(android/hardware/audio/FILE_VERSION/types.h) -#include PATH(android/hardware/audio/common/FILE_VERSION/types.h) +#include PATH(android/hardware/audio/CORE_TYPES_FILE_VERSION/types.h) +#include PATH(android/hardware/audio/common/COMMON_TYPES_FILE_VERSION/types.h) #if MAJOR_VERSION >= 7 -#include -#include +#include PATH(APM_XSD_ENUMS_H_FILENAME) +#include PATH(APM_XSD_H_FILENAME) #endif +// clang-format on #include #include @@ -86,7 +88,7 @@ using ::android::hardware::audio::common::utils::EnumBitfield; using ::android::hardware::audio::common::utils::mkEnumBitfield; using ::android::hardware::details::toHexString; -using namespace ::android::hardware::audio::common::CPP_VERSION; +using namespace ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION; using namespace ::android::hardware::audio::common::test::utility; using namespace ::android::hardware::audio::CPP_VERSION; using ReadParameters = ::android::hardware::audio::CPP_VERSION::IStreamIn::ReadParameters; @@ -124,6 +126,9 @@ static auto invalidStateOrNotSupported = {Result::INVALID_STATE, Result::NOT_SUP class HidlTest : public ::testing::Test { public: + using IDevice = ::android::hardware::audio::CPP_VERSION::IDevice; + using IDevicesFactory = ::android::hardware::audio::CPP_VERSION::IDevicesFactory; + virtual ~HidlTest() = default; // public access to avoid annoyances when using this method in template classes // derived from test classes @@ -168,7 +173,8 @@ const PolicyConfig& getCachedPolicyConfig() { } TEST(CheckConfig, audioPolicyConfigurationValidation) { - const auto factories = ::android::hardware::getAllHalInstanceNames(IDevicesFactory::descriptor); + const auto factories = ::android::hardware::getAllHalInstanceNames( + ::android::hardware::audio::CPP_VERSION::IDevicesFactory::descriptor); if (factories.size() == 0) { GTEST_SKIP() << "Skipping audioPolicyConfigurationValidation because no factory instances " "are found."; @@ -198,8 +204,8 @@ static inline std::string DeviceParameterToString( const std::vector& getDeviceParameters() { static std::vector parameters = [] { std::vector result; - const auto factories = - ::android::hardware::getAllHalInstanceNames(IDevicesFactory::descriptor); + const auto factories = ::android::hardware::getAllHalInstanceNames( + ::android::hardware::audio::CPP_VERSION::IDevicesFactory::descriptor); const auto devices = getCachedPolicyConfig().getModulesWithDevicesNames(); result.reserve(devices.size()); for (const auto& factoryName : factories) { @@ -217,8 +223,8 @@ const std::vector& getDeviceParameters() { const std::vector& getDeviceParametersForFactoryTests() { static std::vector parameters = [] { std::vector result; - const auto factories = - ::android::hardware::getAllHalInstanceNames(IDevicesFactory::descriptor); + const auto factories = ::android::hardware::getAllHalInstanceNames( + ::android::hardware::audio::CPP_VERSION::IDevicesFactory::descriptor); for (const auto& factoryName : factories) { result.emplace_back(factoryName, DeviceManager::getInstance().getPrimary(factoryName) != nullptr @@ -288,6 +294,8 @@ GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(AudioPolicyConfigTest); // Test audio devices factory class AudioHidlTest : public AudioHidlTestWithDeviceParameter { public: + using IPrimaryDevice = ::android::hardware::audio::CPP_VERSION::IPrimaryDevice; + void SetUp() override { ASSERT_NO_FATAL_FAILURE(AudioHidlTestWithDeviceParameter::SetUp()); // setup base ASSERT_TRUE(getDevicesFactory() != nullptr); @@ -301,7 +309,7 @@ TEST_P(AudioHidlTest, GetAudioDevicesFactoryService) { TEST_P(AudioHidlTest, OpenDeviceInvalidParameter) { doc::test("Test passing an invalid parameter to openDevice"); Result result; - sp device; + sp<::android::hardware::audio::CORE_TYPES_CPP_VERSION::IDevice> device; #if MAJOR_VERSION == 2 auto invalidDevice = IDevicesFactory::Device(-1); #elif MAJOR_VERSION >= 4 @@ -572,8 +580,8 @@ static std::string DeviceConfigParameterToString( [](auto&& arg) -> std::string { using T = std::decay_t; // Need to use FQN of toString to avoid confusing the compiler - return ::android::hardware::audio::common::CPP_VERSION::toString( - hidl_bitfield(arg)); + return ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION:: + toString(hidl_bitfield(arg)); }, std::get(info.param))); #elif MAJOR_VERSION >= 7 @@ -890,6 +898,8 @@ class OpenStreamTest : public AudioHidlTestWithDeviceConfigParameter { class StreamWriter : public StreamWorker { public: + using IStreamOut = ::android::hardware::audio::CPP_VERSION::IStreamOut; + StreamWriter(IStreamOut* stream, size_t bufferSize) : mStream(stream), mBufferSize(bufferSize), mData(mBufferSize) {} ~StreamWriter() { @@ -998,7 +1008,8 @@ class StreamWriter : public StreamWorker { EventFlag* mEfGroup = nullptr; }; -class OutputStreamTest : public OpenStreamTest { +class OutputStreamTest + : public OpenStreamTest<::android::hardware::audio::CPP_VERSION::IStreamOut> { void SetUp() override { ASSERT_NO_FATAL_FAILURE(OpenStreamTest::SetUp()); // setup base #if MAJOR_VERSION <= 6 @@ -1012,9 +1023,12 @@ class OutputStreamTest : public OpenStreamTest { [&](AudioIoHandle handle, AudioConfig config, auto cb) { #if MAJOR_VERSION == 2 return getDevice()->openOutputStream(handle, address, config, flags, cb); -#elif MAJOR_VERSION >= 4 +#elif MAJOR_VERSION >= 4 && (MAJOR_VERSION < 7 || (MAJOR_VERSION == 7 && MINOR_VERSION == 0)) return getDevice()->openOutputStream(handle, address, config, flags, initMetadata, cb); +#elif MAJOR_VERSION == 7 && MINOR_VERSION == 1 + return getDevice()->openOutputStream_7_1(handle, address, config, flags, + initMetadata, cb); #endif }, config); @@ -1075,6 +1089,8 @@ GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(OutputStreamTest); class StreamReader : public StreamWorker { public: + using IStreamIn = ::android::hardware::audio::CPP_VERSION::IStreamIn; + StreamReader(IStreamIn* stream, size_t bufferSize) : mStream(stream), mBufferSize(bufferSize), mData(mBufferSize) {} ~StreamReader() { @@ -1188,7 +1204,7 @@ class StreamReader : public StreamWorker { EventFlag* mEfGroup = nullptr; }; -class InputStreamTest : public OpenStreamTest { +class InputStreamTest : public OpenStreamTest<::android::hardware::audio::CPP_VERSION::IStreamIn> { void SetUp() override { ASSERT_NO_FATAL_FAILURE(OpenStreamTest::SetUp()); // setup base #if MAJOR_VERSION <= 6 @@ -1210,8 +1226,13 @@ class InputStreamTest : public OpenStreamTest { auto flags = getInputFlags(); testOpen( [&](AudioIoHandle handle, AudioConfig config, auto cb) { +#if MAJOR_VERSION < 7 || (MAJOR_VERSION == 7 && MINOR_VERSION == 0) return getDevice()->openInputStream(handle, address, config, flags, initMetadata, cb); +#elif MAJOR_VERSION == 7 && MINOR_VERSION == 1 + return getDevice()->openInputStream_7_1(handle, address, config, flags, + initMetadata, cb); +#endif }, config); } @@ -1584,7 +1605,8 @@ TEST_P(InputStreamTest, SetGain) { "InputStream::setGain"); } -static void testPrepareForReading(IStreamIn* stream, uint32_t frameSize, uint32_t framesCount) { +static void testPrepareForReading(::android::hardware::audio::CPP_VERSION::IStreamIn* stream, + uint32_t frameSize, uint32_t framesCount) { Result res; // Ignore output parameters as the call should fail ASSERT_OK(stream->prepareForReading(frameSize, framesCount, @@ -1655,7 +1677,8 @@ TEST_P(OutputStreamTest, setVolume) { "setVolume"); } -static void testPrepareForWriting(IStreamOut* stream, uint32_t frameSize, uint32_t framesCount) { +static void testPrepareForWriting(::android::hardware::audio::CPP_VERSION::IStreamOut* stream, + uint32_t frameSize, uint32_t framesCount) { Result res; // Ignore output parameters as the call should fail ASSERT_OK(stream->prepareForWriting(frameSize, framesCount, @@ -1682,6 +1705,8 @@ TEST_P(OutputStreamTest, PrepareForWritingCheckOverflow) { } struct Capability { + using IStreamOut = ::android::hardware::audio::CPP_VERSION::IStreamOut; + Capability(IStreamOut* stream) { EXPECT_OK(stream->supportsPauseAndResume(returnIn(pause, resume))); drain = extract(stream->supportsDrain()); @@ -1725,7 +1750,7 @@ class MockOutCallbacks : public IStreamOutCallback { Return onError() override { return {}; } }; -static bool isAsyncModeSupported(IStreamOut* stream) { +static bool isAsyncModeSupported(::android::hardware::audio::CPP_VERSION::IStreamOut* stream) { auto res = stream->setCallback(new MockOutCallbacks); stream->clearCallback(); // try to restore the no callback state, ignore // any error @@ -1780,7 +1805,8 @@ TEST_P(OutputStreamTest, Pause) { ASSERT_RESULT(Result::INVALID_STATE, stream->pause()); } -static void testDrain(IStreamOut* stream, AudioDrain type) { +static void testDrain(::android::hardware::audio::CPP_VERSION::IStreamOut* stream, + AudioDrain type) { if (!Capability(stream).drain) { doc::partialTest("The output stream does not support drain"); return; @@ -1866,7 +1892,8 @@ TEST_P(BoolAccessorPrimaryHidlTest, setGetBtScoWidebandEnabled) { } using TtyModeAccessorPrimaryHidlTest = - AccessorHidlTest; + AccessorHidlTest<::android::hardware::audio::CPP_VERSION::IPrimaryDevice::TtyMode, + AudioPrimaryHidlTest>; TEST_P(TtyModeAccessorPrimaryHidlTest, setGetTtyMode) { doc::test("Query and set the TTY mode state"); testAccessors( diff --git a/audio/core/all-versions/vts/functional/AudioTestDefinitions.h b/audio/core/all-versions/vts/functional/AudioTestDefinitions.h index aa676308cb..802b87bc36 100644 --- a/audio/core/all-versions/vts/functional/AudioTestDefinitions.h +++ b/audio/core/all-versions/vts/functional/AudioTestDefinitions.h @@ -22,8 +22,8 @@ #include // clang-format off -#include PATH(android/hardware/audio/FILE_VERSION/types.h) -#include PATH(android/hardware/audio/common/FILE_VERSION/types.h) +#include PATH(android/hardware/audio/CORE_TYPES_FILE_VERSION/types.h) +#include PATH(android/hardware/audio/common/COMMON_TYPES_FILE_VERSION/types.h) // clang-format on enum { PARAM_FACTORY_NAME, PARAM_DEVICE_NAME }; @@ -34,14 +34,14 @@ using DeviceParameter = std::tuple; #if MAJOR_VERSION <= 6 enum { PARAM_DEVICE, PARAM_CONFIG, PARAM_FLAGS }; enum { INDEX_INPUT, INDEX_OUTPUT }; -using DeviceConfigParameter = - std::tuple>; +using DeviceConfigParameter = std::tuple< + DeviceParameter, android::hardware::audio::common::COMMON_TYPES_CPP_VERSION::AudioConfig, + std::variant>; #elif MAJOR_VERSION >= 7 enum { PARAM_DEVICE, PARAM_PORT_NAME, PARAM_CONFIG, PARAM_FLAGS }; using DeviceConfigParameter = std::tuple>; + android::hardware::audio::common::COMMON_TYPES_CPP_VERSION::AudioConfig, + std::vector>; #endif diff --git a/audio/core/all-versions/vts/functional/ConfigHelper.h b/audio/core/all-versions/vts/functional/ConfigHelper.h index a2bb1eecf0..e4008cf046 100644 --- a/audio/core/all-versions/vts/functional/ConfigHelper.h +++ b/audio/core/all-versions/vts/functional/ConfigHelper.h @@ -21,8 +21,8 @@ #include "PolicyConfig.h" // clang-format off -#include PATH(android/hardware/audio/FILE_VERSION/types.h) -#include PATH(android/hardware/audio/common/FILE_VERSION/types.h) +#include PATH(android/hardware/audio/CORE_TYPES_FILE_VERSION/types.h) +#include PATH(android/hardware/audio/common/COMMON_TYPES_FILE_VERSION/types.h) // clang-format on using ::android::hardware::audio::common::utils::EnumBitfield; diff --git a/audio/core/all-versions/vts/functional/DeviceManager.h b/audio/core/all-versions/vts/functional/DeviceManager.h index 6db78a77d6..c8e016731d 100644 --- a/audio/core/all-versions/vts/functional/DeviceManager.h +++ b/audio/core/all-versions/vts/functional/DeviceManager.h @@ -22,19 +22,21 @@ #include #include +#include // clang-format off #include PATH(android/hardware/audio/FILE_VERSION/IDevice.h) #include PATH(android/hardware/audio/FILE_VERSION/IDevicesFactory.h) #include PATH(android/hardware/audio/FILE_VERSION/IPrimaryDevice.h) -#include PATH(android/hardware/audio/FILE_VERSION/types.h) -#include PATH(android/hardware/audio/common/FILE_VERSION/types.h) +#include PATH(android/hardware/audio/CORE_TYPES_FILE_VERSION/types.h) +#include PATH(android/hardware/audio/common/COMMON_TYPES_FILE_VERSION/types.h) // clang-format on #include "utility/ReturnIn.h" using ::android::sp; -using namespace ::android::hardware::audio::common::CPP_VERSION; +using ::android::hardware::audio::CORE_TYPES_CPP_VERSION::Result; +using namespace ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION; using namespace ::android::hardware::audio::common::test::utility; using namespace ::android::hardware::audio::CPP_VERSION; @@ -104,21 +106,30 @@ class DeviceManager : public InterfaceManager createInterfaceInstance(const FactoryAndDevice& factoryAndDevice) { auto [factoryName, name] = factoryAndDevice; sp factory = DevicesFactoryManager::getInstance().get(factoryName); - return name == kPrimaryDevice ? openPrimaryDevice(factory) : openDevice(factory, name); + return openDevice(factory, name); } using InterfaceManager::reset; static constexpr const char* kPrimaryDevice = "primary"; sp get(const std::string& factoryName, const std::string& name) { + if (name == kPrimaryDevice) { + (void)getPrimary(factoryName); // for initializing primaryDevice if needed. + } return InterfaceManager::get(std::make_tuple(factoryName, name)); } sp getPrimary(const std::string& factoryName) { - sp device = get(factoryName, kPrimaryDevice); - return device != nullptr ? IPrimaryDevice::castFrom(device) : nullptr; + if (primaryDevice == nullptr) { + sp factory = DevicesFactoryManager::getInstance().get(factoryName); + primaryDevice = openPrimaryDevice(factory); + } + return primaryDevice; } bool reset(const std::string& factoryName, const std::string& name) __attribute__((warn_unused_result)) { + if (name == kPrimaryDevice) { + primaryDevice.clear(); + } #if MAJOR_VERSION <= 5 return InterfaceManager::reset(std::make_tuple(factoryName, name), true); #elif MAJOR_VERSION >= 6 @@ -140,35 +151,75 @@ class DeviceManager : public InterfaceManager openDevice(const sp& factory, const std::string& name) { if (factory == nullptr) return nullptr; - sp device; -#if MAJOR_VERSION >= 4 Result result; + sp device; +#if MAJOR_VERSION == 2 + IDevicesFactory::Device dev = IDevicesFactory::IDevicesFactory::Device(-1); + if (name == AUDIO_HARDWARE_MODULE_ID_PRIMARY) { + dev = IDevicesFactory::Device::PRIMARY; + } else if (name == AUDIO_HARDWARE_MODULE_ID_A2DP) { + dev = IDevicesFactory::Device::A2DP; + } else if (name == AUDIO_HARDWARE_MODULE_ID_USB) { + dev = IDevicesFactory::Device::USB; + } else if (name == AUDIO_HARDWARE_MODULE_ID_REMOTE_SUBMIX) { + dev = IDevicesFactory::Device::R_SUBMIX; + } else if (name == AUDIO_HARDWARE_MODULE_ID_STUB) { + dev = IDevicesFactory::Device::STUB; + } + auto ret = factory->openDevice(dev, returnIn(result, device)); +#elif MAJOR_VERSION >= 4 && (MAJOR_VERSION < 7 || (MAJOR_VERSION == 7 && MINOR_VERSION == 0)) auto ret = factory->openDevice(name, returnIn(result, device)); +#elif MAJOR_VERSION == 7 && MINOR_VERSION == 1 + auto ret = factory->openDevice_7_1(name, returnIn(result, device)); +#endif if (!ret.isOk() || result != Result::OK || device == nullptr) { ALOGW("Device %s can not be opened, transaction: %s, result %d, device %p", name.c_str(), ret.description().c_str(), result, device.get()); return nullptr; } -#else - (void)name; -#endif return device; } - static sp openPrimaryDevice(const sp& factory) { - if (factory == nullptr) return nullptr; + static sp openPrimaryDevice(const sp& factory) { + if (factory == nullptr) return {}; Result result; sp device; + sp primaryDevice; #if MAJOR_VERSION == 2 auto ret = factory->openDevice(IDevicesFactory::Device::PRIMARY, returnIn(result, device)); -#elif MAJOR_VERSION >= 4 + if (ret.isOk() && result == Result::OK && device != nullptr) { + primaryDevice = IPrimaryDevice::castFrom(device); + } +#elif MAJOR_VERSION >= 4 && (MAJOR_VERSION < 7 || (MAJOR_VERSION == 7 && MINOR_VERSION == 0)) auto ret = factory->openPrimaryDevice(returnIn(result, device)); + if (ret.isOk() && result == Result::OK && device != nullptr) { + primaryDevice = IPrimaryDevice::castFrom(device); + } +#elif MAJOR_VERSION == 7 && MINOR_VERSION == 1 + auto ret = factory->openPrimaryDevice_7_1(returnIn(result, primaryDevice)); + if (ret.isOk() && result == Result::OK && primaryDevice != nullptr) { + auto getDeviceRet = primaryDevice->getDevice(); + if (getDeviceRet.isOk()) { + device = getDeviceRet; + } else { + primaryDevice.clear(); + ALOGW("Primary device can not downcast, transaction: %s, primary %p", + getDeviceRet.description().c_str(), primaryDevice.get()); + return {}; + } + } #endif if (!ret.isOk() || result != Result::OK || device == nullptr) { ALOGW("Primary device can not be opened, transaction: %s, result %d, device %p", ret.description().c_str(), result, device.get()); - return nullptr; + return {}; } - return device; + return primaryDevice; } + + private: + // There can only be one primary device across all HAL modules. + // A reference to a complete interface is used because in V7.1 IDevice can not + // be upcasted to IPrimaryDevice. + sp primaryDevice; }; diff --git a/audio/core/all-versions/vts/functional/VtsHalAudioV7_1TargetTest.xml b/audio/core/all-versions/vts/functional/VtsHalAudioV7_1TargetTest.xml new file mode 100644 index 0000000000..7b33a8f340 --- /dev/null +++ b/audio/core/all-versions/vts/functional/VtsHalAudioV7_1TargetTest.xml @@ -0,0 +1,39 @@ + + + + diff --git a/audio/core/all-versions/vts/functional/tests/generators_tests.cpp b/audio/core/all-versions/vts/functional/tests/generators_tests.cpp index 3fdd8e6086..76bf93e2d7 100644 --- a/audio/core/all-versions/vts/functional/tests/generators_tests.cpp +++ b/audio/core/all-versions/vts/functional/tests/generators_tests.cpp @@ -33,7 +33,7 @@ #endif using namespace android; -using namespace ::android::hardware::audio::common::CPP_VERSION; +using namespace ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION; #if MAJOR_VERSION == 7 namespace xsd { using namespace ::android::audio::policy::configuration::CPP_VERSION; diff --git a/audio/effect/all-versions/default/util/tests/effectutils_tests.cpp b/audio/effect/all-versions/default/util/tests/effectutils_tests.cpp index d021fa0b92..adfa167e46 100644 --- a/audio/effect/all-versions/default/util/tests/effectutils_tests.cpp +++ b/audio/effect/all-versions/default/util/tests/effectutils_tests.cpp @@ -27,7 +27,7 @@ #include using namespace android; -using namespace ::android::hardware::audio::common::CPP_VERSION; +using namespace ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION; using namespace ::android::hardware::audio::effect::CPP_VERSION; using ::android::hardware::audio::effect::CPP_VERSION::implementation::EffectUtils; namespace xsd { diff --git a/audio/effect/all-versions/vts/functional/VtsHalAudioEffectTargetTest.cpp b/audio/effect/all-versions/vts/functional/VtsHalAudioEffectTargetTest.cpp index 23e77867a5..e59423fa98 100644 --- a/audio/effect/all-versions/vts/functional/VtsHalAudioEffectTargetTest.cpp +++ b/audio/effect/all-versions/vts/functional/VtsHalAudioEffectTargetTest.cpp @@ -50,7 +50,7 @@ using ::android::hardware::Void; using ::android::hardware::audio::common::utils::mkEnumBitfield; using ::android::hidl::allocator::V1_0::IAllocator; using ::android::hidl::memory::V1_0::IMemory; -using namespace ::android::hardware::audio::common::CPP_VERSION; +using namespace ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION; using namespace ::android::hardware::audio::effect::CPP_VERSION; #if MAJOR_VERSION >= 7 // Make an alias for enumerations generated from the APM config XSD.