Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d6191e18 authored by Mikhail Naganov's avatar Mikhail Naganov Committed by Automerger Merge Worker
Browse files

audio: Require exact implementation version match am: 7c92256c am: 541eb409 am: 5571021c

parents 66d00d9b 5571021c
Loading
Loading
Loading
Loading
+39 −9
Original line number Diff line number Diff line
@@ -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