1 /* 2 * Copyright (c) 2023-2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef AUDIO_DEVICE_PARSER_H 17 #define AUDIO_DEVICE_PARSER_H 18 19 #include <list> 20 #include <unordered_map> 21 #include <string> 22 #include <sstream> 23 24 #include "audio_policy_log.h" 25 #include "iport_observer.h" 26 #include "parser.h" 27 #include "audio_device_manager.h" 28 #include "audio_xml_parser.h" 29 30 namespace OHOS { 31 namespace AudioStandard { 32 33 enum DeviceNodeName { 34 UNKNOWN_NODE = -1, 35 ADAPTER, 36 DEVICES, 37 DEVICE, 38 }; 39 40 class AudioDeviceParser : public Parser { 41 public: 42 static constexpr char PRIVACY_TYPE[] = "privacy"; 43 static constexpr char PUBLIC_TYPE[] = "public"; 44 static constexpr char DEVICE_CONFIG_FILE[] = "etc/audio/audio_device_privacy.xml"; 45 46 bool LoadConfiguration() final; 47 void Destroy() final; 48 AudioDeviceParser(AudioDeviceManager * audioDeviceManager)49 AudioDeviceParser(AudioDeviceManager *audioDeviceManager) 50 { 51 curNode_ = AudioXmlNode::Create(); 52 audioDeviceManager_ = audioDeviceManager; 53 } 54 ~AudioDeviceParser()55 virtual ~AudioDeviceParser() 56 { 57 AUDIO_INFO_LOG("AudioDeviceParser dtor"); 58 Destroy(); 59 curNode_ = nullptr; 60 } 61 62 private: 63 DeviceNodeName GetDeviceNodeNameAsInt(std::shared_ptr<AudioXmlNode> curNode); 64 bool ParseInternal(std::shared_ptr<AudioXmlNode> curNode); 65 void ParseDevicePrivacyInfo(std::shared_ptr<AudioXmlNode> curNode, std::list<DevicePrivacyInfo> &deviceLists); 66 void ParserDevicePrivacyInfoList(std::shared_ptr<AudioXmlNode> curNode, std::list<DevicePrivacyInfo> &deviceLists); 67 void ParseAudioDevicePrivacyType(std::shared_ptr<AudioXmlNode> curNode, AudioDevicePrivacyType &deviceType); 68 void ParseDeviceRole(const std::string &deviceRole, uint32_t &deviceRoleFlag); 69 void ParseDeviceCategory(const std::string &deviceCategory, uint32_t &deviceCategoryFlag); 70 void ParseDeviceUsage(const std::string &deviceUsage, uint32_t &deviceUsageFlag); 71 AudioDevicePrivacyType GetDevicePrivacyType(const std::string &devicePrivacyType); 72 73 std::shared_ptr<AudioXmlNode> curNode_ = nullptr; 74 AudioDevicePrivacyType devicePrivacyType_ = {}; 75 AudioDeviceManager *audioDeviceManager_; 76 std::unordered_map<AudioDevicePrivacyType, std::list<DevicePrivacyInfo>> devicePrivacyMaps_ = {}; 77 }; 78 } // namespace AudioStandard 79 } // namespace OHOS 80 81 #endif // AUDIO_DEVICE_PARSER_H 82