/* * Copyright (C) 2020 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. */ #pragma once #include #include #include #include #include #include // clang-format off #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 PATH(APM_XSD_ENUMS_H_FILENAME) #include PATH(APM_XSD_H_FILENAME) 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; } class PolicyConfig { public: explicit PolicyConfig(const std::string& configFileName) : mConfigFileName{configFileName}, mFilePath{findExistingConfigurationFile(mConfigFileName)}, mConfig{xsd::read(mFilePath.c_str())} { init(); } PolicyConfig(const std::string& configPath, const std::string& configFileName) : mConfigFileName{configFileName}, mFilePath{configPath + "/" + mConfigFileName}, mConfig{xsd::read(mFilePath.c_str())} { init(); } android::status_t getStatus() const { return mStatus; } std::string getError() const; const std::string& getFilePath() const { return mFilePath; } const xsd::Module* getModuleFromName(const std::string& name) const; const xsd::Module* getPrimaryModule() const { return mPrimaryModule; } const std::set& getModulesWithDevicesNames() const { return mModulesWithDevicesNames; } std::optional getDeviceAddressOfSinkDeviceAttachedToMixPort( const std::string& moduleName, const std::string& mixPortName) const { const auto attachedDevicePort = getAttachedSinkDeviceForMixPort(moduleName, mixPortName); if (attachedDevicePort.empty()) return {}; return getDeviceAddressOfDevicePort(moduleName, attachedDevicePort); } std::optional getDeviceAddressOfSourceDeviceAttachedToMixPort( const std::string& moduleName, const std::string& mixPortName) const { const auto attachedDevicePort = getAttachedSourceDeviceForMixPort(moduleName, mixPortName); if (attachedDevicePort.empty()) return {}; return getDeviceAddressOfDevicePort(moduleName, attachedDevicePort); } std::string getAttachedSinkDeviceForMixPort(const std::string& moduleName, const std::string& mixPortName) const { return findAttachedDevice(getAttachedDevices(moduleName), getSinkDevicesForMixPort(moduleName, mixPortName)); } std::string getAttachedSourceDeviceForMixPort(const std::string& moduleName, const std::string& mixPortName) const { return findAttachedDevice(getAttachedDevices(moduleName), getSourceDevicesForMixPort(moduleName, mixPortName)); } std::optional getSinkDeviceForMixPort(const std::string& moduleName, const std::string& mixPortName) const; std::optional getSourceDeviceForMixPort(const std::string& moduleName, const std::string& mixPortName) const; bool haveInputProfilesInModule(const std::string& name) const; private: static std::string findExistingConfigurationFile(const std::string& fileName); std::string findAttachedDevice(const std::vector& attachedDevices, const std::set& possibleDevices) const; const std::vector& getAttachedDevices(const std::string& moduleName) const; std::optional getDeviceAddressOfDevicePort( const std::string& moduleName, const std::string& devicePortName) const; std::set getSinkDevicesForMixPort(const std::string& moduleName, const std::string& mixPortName) const; std::set getSourceDevicesForMixPort(const std::string& moduleName, const std::string& mixPortName) const; void init(); const std::string mConfigFileName; const std::string mFilePath; std::optional mConfig; android::status_t mStatus = android::NO_INIT; const xsd::Module* mPrimaryModule; std::set mModulesWithDevicesNames; };