• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023-2023 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 OHOS_WIFI_APP_PARSE_H
17 #define OHOS_WIFI_APP_PARSE_H
18 
19 #include "xml_parser.h"
20 #include <vector>
21 #include <string>
22 #include <shared_mutex>
23 
24 namespace OHOS {
25 namespace Wifi {
26 enum class AppType {
27     LOW_LATENCY_APP = 0,
28     WHITE_LIST_APP,
29     BLACK_LIST_APP,
30     MULTILINK_BLACK_LIST_APP,
31     CHARIOT_APP,
32     HIGH_TEMP_LIMIT_SPEED_APP,
33     KEY_FOREGROUND_LIST_APP,
34     KEY_BACKGROUND_LIMIT_LIST_APP,
35     ASYNC_DELAY_TIME,
36     GAME_RTT,
37     LIVE_STREAM_APP,
38     GAME_BACKGROUND_LIMIT_LIST_APP,
39     OTHER_APP
40 };
41 
42 struct CommonAppInfo {
43     std::string packageName;
44 };
45 
46 struct LowLatencyAppInfo : CommonAppInfo {};
47 struct WhiteListAppInfo : CommonAppInfo {};
48 struct BlackListAppInfo : CommonAppInfo {};
49 struct MultiLinkAppInfo : CommonAppInfo {};
50 struct ChariotAppInfo : CommonAppInfo {};
51 struct HighTempLimitSpeedAppInfo : CommonAppInfo {};
52 struct KeyForegroundListAppInfo : CommonAppInfo {};
53 struct KeyBackgroundLimitListAppInfo : CommonAppInfo {};
54 struct GameBackgroundLimitListAppInfo : CommonAppInfo {};
55 struct LiveStreamAppInfo : CommonAppInfo {};
56 
57 struct AppParserResult {
58     std::vector<LowLatencyAppInfo> m_lowLatencyAppVec {};
59     std::vector<WhiteListAppInfo> m_whiteAppVec {};
60     std::vector<BlackListAppInfo> m_blackAppVec {};
61     std::vector<MultiLinkAppInfo> m_multilinkAppVec {};
62     std::vector<ChariotAppInfo> m_chariotAppVec {};
63     std::vector<HighTempLimitSpeedAppInfo> m_highTempLimitSpeedAppVec {};
64     std::vector<KeyForegroundListAppInfo> m_keyForegroundListAppVec {};
65     std::vector<KeyBackgroundLimitListAppInfo> m_keyBackgroundLimitListAppVec {};
66     std::vector<LiveStreamAppInfo> m_liveStreamAppVec {};
67     std::vector<GameBackgroundLimitListAppInfo> m_gameBackgroundLimitListAppVec {};
68     std::unordered_map<std::string, int> m_gameRtt {};
69     std::string m_delayTime = "";
70 };
71 
72 class AppParserInner : public XmlParser {
73 public:
74     AppParserInner();
75     ~AppParserInner() override;
76     bool Init(AppParserResult &result, std::vector<const char*> appFileList = {});
77 private:
78     bool InitAppParser(const char *appXmlFilePath);
79     bool ParseInternal(xmlNodePtr node) override;
80     void ParseAppList(const xmlNodePtr &innode);
81     void ParseNetworkControlAppList(const xmlNodePtr &innode);
82     LowLatencyAppInfo ParseLowLatencyAppInfo(const xmlNodePtr &innode);
83     WhiteListAppInfo ParseWhiteAppInfo(const xmlNodePtr &innode);
84     BlackListAppInfo ParseBlackAppInfo(const xmlNodePtr &innode);
85     MultiLinkAppInfo ParseMultiLinkAppInfo(const xmlNodePtr &innode);
86     ChariotAppInfo ParseChariotAppInfo(const xmlNodePtr &innode);
87     HighTempLimitSpeedAppInfo ParseHighTempLimitSpeedAppInfo(const xmlNodePtr &innode);
88     KeyForegroundListAppInfo ParseKeyForegroundListAppInfo(const xmlNodePtr &innode);
89     KeyBackgroundLimitListAppInfo ParseKeyBackgroundLimitListAppInfo(const xmlNodePtr &innode);
90     LiveStreamAppInfo ParseLiveStreamAppInfo(const xmlNodePtr &innode);
91     GameBackgroundLimitListAppInfo ParseGameBackgroundLimitListAppInfo(const xmlNodePtr &innode);
92     void ParseAsyncLimitSpeedDelayTime(const xmlNodePtr &innode);
93     AppType GetAppTypeAsInt(const xmlNodePtr &innode);
94     std::string GetLocalFileVersion(const xmlNodePtr &innode);
95 private:
96     AppParserResult result_;
97     std::atomic<bool> initFlag_ {false};
98 };
99 
100 class AppParser {
101 public:
102     static AppParser &GetInstance();
103     bool Init();
104     bool IsLowLatencyApp(const std::string &bundleName) const;
105     bool IsWhiteListApp(const std::string &bundleName) const;
106     bool IsBlackListApp(const std::string &bundleName) const;
107     bool IsMultiLinkApp(const std::string &bundleName) const;
108     bool IsChariotApp(const std::string &bundleName) const;
109     bool IsHighTempLimitSpeedApp(const std::string &bundleName) const;
110     bool IsKeyForegroundApp(const std::string &bundleName) const;
111     bool IsKeyBackgroundLimitApp(const std::string &bundleName) const;
112     std::string GetAsyncLimitSpeedDelayTime() const;
113     bool IsLiveStreamApp(const std::string &bundleName) const;
114     bool IsGameBackgroundLimitApp(const std::string &bundleName) const;
115     bool IsOverGameRtt(const std::string &bundleName, const int gameRtt) const;
116 private:
117     AppParser();
118     ~AppParser();
119 private:
120     mutable std::shared_mutex appParserMutex_;
121     std::unique_ptr<AppParserInner> appParserInner_;
122     AppParserResult result_;
123     std::atomic<bool> initFlag_ {false};
124 };
125 } // namespace Wifi
126 } // namespace OHOS
127 
128 #endif