mirror of
https://github.com/Evolution-X/hardware_interfaces
synced 2026-02-01 11:36:00 +00:00
audio: Require exact implementation version match am: 7c92256c1a
Original change: https://android-review.googlesource.com/c/platform/hardware/interfaces/+/2058922 Change-Id: I71f20086a50880412caf5e89a3f27bb285ed812f Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -34,6 +34,7 @@
|
|||||||
|
|
||||||
#include <hwbinder/IPCThreadState.h>
|
#include <hwbinder/IPCThreadState.h>
|
||||||
|
|
||||||
|
#include <android-base/expected.h>
|
||||||
#include <android-base/logging.h>
|
#include <android-base/logging.h>
|
||||||
#include <system/audio_config.h>
|
#include <system/audio_config.h>
|
||||||
|
|
||||||
@@ -130,6 +131,33 @@ class HidlTest : public ::testing::Test {
|
|||||||
using IDevice = ::android::hardware::audio::CPP_VERSION::IDevice;
|
using IDevice = ::android::hardware::audio::CPP_VERSION::IDevice;
|
||||||
using IDevicesFactory = ::android::hardware::audio::CPP_VERSION::IDevicesFactory;
|
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;
|
virtual ~HidlTest() = default;
|
||||||
// public access to avoid annoyances when using this method in template classes
|
// public access to avoid annoyances when using this method in template classes
|
||||||
// derived from test classes
|
// derived from test classes
|
||||||
@@ -174,9 +202,11 @@ const PolicyConfig& getCachedPolicyConfig() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(CheckConfig, audioPolicyConfigurationValidation) {
|
TEST(CheckConfig, audioPolicyConfigurationValidation) {
|
||||||
const auto factories = ::android::hardware::getAllHalInstanceNames(
|
const auto factories = HidlTest::getAllFactoryInstances();
|
||||||
::android::hardware::audio::CPP_VERSION::IDevicesFactory::descriptor);
|
if (!factories.ok()) {
|
||||||
if (factories.size() == 0) {
|
FAIL() << factories.error();
|
||||||
|
}
|
||||||
|
if (factories.value().size() == 0) {
|
||||||
GTEST_SKIP() << "Skipping audioPolicyConfigurationValidation because no factory instances "
|
GTEST_SKIP() << "Skipping audioPolicyConfigurationValidation because no factory instances "
|
||||||
"are found.";
|
"are found.";
|
||||||
}
|
}
|
||||||
@@ -205,11 +235,11 @@ static inline std::string DeviceParameterToString(
|
|||||||
const std::vector<DeviceParameter>& getDeviceParameters() {
|
const std::vector<DeviceParameter>& getDeviceParameters() {
|
||||||
static std::vector<DeviceParameter> parameters = [] {
|
static std::vector<DeviceParameter> parameters = [] {
|
||||||
std::vector<DeviceParameter> result;
|
std::vector<DeviceParameter> result;
|
||||||
const auto factories = ::android::hardware::getAllHalInstanceNames(
|
const auto factories = HidlTest::getAllFactoryInstances();
|
||||||
::android::hardware::audio::CPP_VERSION::IDevicesFactory::descriptor);
|
if (!factories.ok()) return result;
|
||||||
const auto devices = getCachedPolicyConfig().getModulesWithDevicesNames();
|
const auto devices = getCachedPolicyConfig().getModulesWithDevicesNames();
|
||||||
result.reserve(devices.size());
|
result.reserve(devices.size());
|
||||||
for (const auto& factoryName : factories) {
|
for (const auto& factoryName : factories.value()) {
|
||||||
for (const auto& deviceName : devices) {
|
for (const auto& deviceName : devices) {
|
||||||
if (DeviceManager::getInstance().get(factoryName, deviceName) != nullptr) {
|
if (DeviceManager::getInstance().get(factoryName, deviceName) != nullptr) {
|
||||||
result.emplace_back(factoryName, deviceName);
|
result.emplace_back(factoryName, deviceName);
|
||||||
@@ -224,9 +254,9 @@ const std::vector<DeviceParameter>& getDeviceParameters() {
|
|||||||
const std::vector<DeviceParameter>& getDeviceParametersForFactoryTests() {
|
const std::vector<DeviceParameter>& getDeviceParametersForFactoryTests() {
|
||||||
static std::vector<DeviceParameter> parameters = [] {
|
static std::vector<DeviceParameter> parameters = [] {
|
||||||
std::vector<DeviceParameter> result;
|
std::vector<DeviceParameter> result;
|
||||||
const auto factories = ::android::hardware::getAllHalInstanceNames(
|
const auto factories = HidlTest::getAllFactoryInstances();
|
||||||
::android::hardware::audio::CPP_VERSION::IDevicesFactory::descriptor);
|
if (!factories.ok()) return result;
|
||||||
for (const auto& factoryName : factories) {
|
for (const auto& factoryName : factories.value()) {
|
||||||
result.emplace_back(factoryName,
|
result.emplace_back(factoryName,
|
||||||
DeviceManager::getInstance().getPrimary(factoryName) != nullptr
|
DeviceManager::getInstance().getPrimary(factoryName) != nullptr
|
||||||
? DeviceManager::kPrimaryDevice
|
? DeviceManager::kPrimaryDevice
|
||||||
|
|||||||
Reference in New Issue
Block a user