• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 #ifndef AUDIO_FOCUS_PARSER_H
16 #define AUDIO_FOCUS_PARSER_H
17 
18 #include <map>
19 #include <string>
20 #include "audio_errors.h"
21 #include "audio_info.h"
22 #include "audio_policy_log.h"
23 #include "audio_xml_parser.h"
24 
25 namespace OHOS {
26 namespace AudioStandard {
27 
28 class AudioFocusParser {
29 public:
30     AudioFocusParser();
31     virtual ~AudioFocusParser();
32     int32_t LoadConfig(std::map<std::pair<AudioFocusType, AudioFocusType>, AudioFocusEntry> &focusMap);
33 
34 private:
35     #ifdef USE_CONFIG_POLICY
36     static constexpr char AUDIO_FOCUS_CONFIG_FILE[] = "etc/audio/audio_interrupt_policy_config.xml";
37     #else
38     static constexpr char AUDIO_FOCUS_CONFIG_FILE[] = "/system/etc/audio/audio_interrupt_policy_config.xml";
39     #endif
40     static std::map<std::string, AudioFocusType> audioFocusMap;
41     static std::map<std::string, InterruptHint> actionMap;
42     static std::map<std::string, ActionTarget> targetMap;
43     static std::map<std::string, InterruptForceType> forceMap;
44     std::shared_ptr<AudioXmlNode> curNode_ = nullptr;
45 
46     void LoadDefaultConfig(std::map<std::pair<AudioFocusType, AudioFocusType>, AudioFocusEntry> &focusMap);
47     void ParseFocusChildrenMap(std::shared_ptr<AudioXmlNode> curNode, const std::string &curStream,
48         std::map<std::pair<AudioFocusType, AudioFocusType>, AudioFocusEntry> &focusMap);
49     void ParseFocusMap(std::shared_ptr<AudioXmlNode> curNode, const std::string &curStream,
50         std::map<std::pair<AudioFocusType, AudioFocusType>, AudioFocusEntry> &focusMap);
51     void ParseStreams(std::shared_ptr<AudioXmlNode> curNode, std::map<std::pair<AudioFocusType, AudioFocusType>,
52         AudioFocusEntry> &focusMap);
53     void AddAllowedFocusEntry(std::shared_ptr<AudioXmlNode> curNode, const std::string &curStream,
54         std::map<std::pair<AudioFocusType, AudioFocusType>, AudioFocusEntry> &focusMap);
55     void ParseAllowedStreams(std::shared_ptr<AudioXmlNode> curNode, const std::string &curStream,
56         std::map<std::pair<AudioFocusType, AudioFocusType>, AudioFocusEntry> &focusMap);
57     void AddRejectedFocusEntry(std::shared_ptr<AudioXmlNode> curNode, const std::string &curStream,
58         std::map<std::pair<AudioFocusType, AudioFocusType>, AudioFocusEntry> &focusMap);
59     void ParseRejectedStreams(std::shared_ptr<AudioXmlNode> curNode, const std::string &curStream,
60         std::map<std::pair<AudioFocusType, AudioFocusType>, AudioFocusEntry> &focusMap);
61     void WriteConfigErrorEvent();
62 };
63 } // namespace AudioStandard
64 } // namespace OHOS
65 #endif // AUDIO_FOCUS_PARSER_H
66