audio: Require exact implementation version match am: 7c92256c1a
am: 541eb4099c
am: 5571021c52
Original change: https://android-review.googlesource.com/c/platform/hardware/interfaces/+/2058922 Change-Id: I230abccbbd62b6dbb3cafead89ddfea5ff050154 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
commit
d6191e1899
1 changed files with 39 additions and 9 deletions
|
@ -34,6 +34,7 @@
|
|||
|
||||
#include <hwbinder/IPCThreadState.h>
|
||||
|
||||
#include <android-base/expected.h>
|
||||
#include <android-base/logging.h>
|
||||
#include <system/audio_config.h>
|
||||
|
||||
|
@ -130,6 +131,33 @@ class HidlTest : public ::testing::Test {
|
|||
using IDevice = ::android::hardware::audio::CPP_VERSION::IDevice;
|
||||
using IDevicesFactory = ::android::hardware::audio::CPP_VERSION::IDevicesFactory;
|
||||
|
||||
static android::base::expected<std::vector<std::string>, std::string> getAllFactoryInstances() {
|
||||
using ::android::hardware::audio::CPP_VERSION::IDevicesFactory;
|
||||
const std::string factoryDescriptor = IDevicesFactory::descriptor;
|
||||
// Make sure that the instance is the exact minor version.
|
||||
// Using a 7.1 factory for 7.0 test is not always possible because
|
||||
// 7.1 can be configured via the XML config to use features that are
|
||||
// absent in 7.0.
|
||||
auto instances = ::android::hardware::getAllHalInstanceNames(factoryDescriptor);
|
||||
if (instances.empty()) return instances;
|
||||
// Use the default instance for checking the implementation version.
|
||||
auto defaultInstance = IDevicesFactory::getService("default");
|
||||
if (defaultInstance == nullptr) {
|
||||
return ::android::base::unexpected("Failed to obtain IDevicesFactory/default");
|
||||
}
|
||||
std::string actualDescriptor;
|
||||
auto intDescRet = defaultInstance->interfaceDescriptor(
|
||||
[&](const auto& descriptor) { actualDescriptor = descriptor; });
|
||||
if (!intDescRet.isOk()) {
|
||||
return ::android::base::unexpected("Failed to obtain interface descriptor: " +
|
||||
intDescRet.description());
|
||||
}
|
||||
if (factoryDescriptor == actualDescriptor)
|
||||
return instances;
|
||||
else
|
||||
return {};
|
||||
}
|
||||
|
||||
virtual ~HidlTest() = default;
|
||||
// public access to avoid annoyances when using this method in template classes
|
||||
// derived from test classes
|
||||
|
@ -174,9 +202,11 @@ const PolicyConfig& getCachedPolicyConfig() {
|
|||
}
|
||||
|
||||
TEST(CheckConfig, audioPolicyConfigurationValidation) {
|
||||
const auto factories = ::android::hardware::getAllHalInstanceNames(
|
||||
::android::hardware::audio::CPP_VERSION::IDevicesFactory::descriptor);
|
||||
if (factories.size() == 0) {
|
||||
const auto factories = HidlTest::getAllFactoryInstances();
|
||||
if (!factories.ok()) {
|
||||
FAIL() << factories.error();
|
||||
}
|
||||
if (factories.value().size() == 0) {
|
||||
GTEST_SKIP() << "Skipping audioPolicyConfigurationValidation because no factory instances "
|
||||
"are found.";
|
||||
}
|
||||
|
@ -205,11 +235,11 @@ static inline std::string DeviceParameterToString(
|
|||
const std::vector<DeviceParameter>& getDeviceParameters() {
|
||||
static std::vector<DeviceParameter> parameters = [] {
|
||||
std::vector<DeviceParameter> result;
|
||||
const auto factories = ::android::hardware::getAllHalInstanceNames(
|
||||
::android::hardware::audio::CPP_VERSION::IDevicesFactory::descriptor);
|
||||
const auto factories = HidlTest::getAllFactoryInstances();
|
||||
if (!factories.ok()) return result;
|
||||
const auto devices = getCachedPolicyConfig().getModulesWithDevicesNames();
|
||||
result.reserve(devices.size());
|
||||
for (const auto& factoryName : factories) {
|
||||
for (const auto& factoryName : factories.value()) {
|
||||
for (const auto& deviceName : devices) {
|
||||
if (DeviceManager::getInstance().get(factoryName, deviceName) != nullptr) {
|
||||
result.emplace_back(factoryName, deviceName);
|
||||
|
@ -224,9 +254,9 @@ const std::vector<DeviceParameter>& getDeviceParameters() {
|
|||
const std::vector<DeviceParameter>& getDeviceParametersForFactoryTests() {
|
||||
static std::vector<DeviceParameter> parameters = [] {
|
||||
std::vector<DeviceParameter> result;
|
||||
const auto factories = ::android::hardware::getAllHalInstanceNames(
|
||||
::android::hardware::audio::CPP_VERSION::IDevicesFactory::descriptor);
|
||||
for (const auto& factoryName : factories) {
|
||||
const auto factories = HidlTest::getAllFactoryInstances();
|
||||
if (!factories.ok()) return result;
|
||||
for (const auto& factoryName : factories.value()) {
|
||||
result.emplace_back(factoryName,
|
||||
DeviceManager::getInstance().getPrimary(factoryName) != nullptr
|
||||
? DeviceManager::kPrimaryDevice
|
||||
|
|
Loading…
Reference in a new issue