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 
23 namespace OHOS {
24 namespace Wifi {
25 enum class AppType {
26     LOW_LATENCY_APP = 0,
27     WHITE_LIST_APP,
28     BLACK_LIST_APP,
29     MULTILINK_BLACK_LIST_APP,
30     CHARIOT_APP,
31     HIGH_TEMP_LIMIT_SPEED_APP,
32     OTHER_APP
33 };
34 
35 struct CommonAppInfo {
36     std::string packageName;
37 };
38 
39 struct LowLatencyAppInfo : CommonAppInfo {};
40 struct WhiteListAppInfo : CommonAppInfo {};
41 struct BlackListAppInfo : CommonAppInfo {};
42 struct MultiLinkAppInfo : CommonAppInfo {};
43 struct ChariotAppInfo : CommonAppInfo {};
44 struct HighTempLimitSpeedAppInfo : CommonAppInfo {};
45 
46 class AppParser : public XmlParser {
47 public:
48     AppParser();
49     ~AppParser() override;
50     static AppParser &GetInstance();
51     bool IsLowLatencyApp(const std::string &bundleName) const;
52     bool IsWhiteListApp(const std::string &bundleName) const;
53     bool IsBlackListApp(const std::string &bundleName) const;
54     bool IsMultiLinkApp(const std::string &bundleName) const;
55     bool IsChariotApp(const std::string &bundleName) const;
56     bool IsHighTempLimitSpeedApp(const std::string &bundleName) const;
57     bool Init();
58 
59 private:
60     bool InitAppParser(const char *appXmlFilePath);
61     bool ParseInternal(xmlNodePtr node) override;
62     void ParseAppList(const xmlNodePtr &innode);
63     LowLatencyAppInfo ParseLowLatencyAppInfo(const xmlNodePtr &innode);
64     WhiteListAppInfo ParseWhiteAppInfo(const xmlNodePtr &innode);
65     BlackListAppInfo ParseBlackAppInfo(const xmlNodePtr &innode);
66     MultiLinkAppInfo ParseMultiLinkAppInfo(const xmlNodePtr &innode);
67     ChariotAppInfo ParseChariotAppInfo(const xmlNodePtr &innode);
68     HighTempLimitSpeedAppInfo ParseHighTempLimitSpeedAppInfo(const xmlNodePtr &innode);
69     AppType GetAppTypeAsInt(const xmlNodePtr &innode);
70     bool ReadPackageCloudFilterConfig();
71     bool IsReadCloudConfig();
72     std::string GetLocalFileVersion(const char *appXmlVersionFilePath);
73     std::string GetCloudPushFileVersion(const char *appVersionFilePath);
74     std::string GetCloudPushVersionFilePath();
75     std::string GetCloudPushJsonFilePath();
76 private:
77     std::vector<LowLatencyAppInfo> m_lowLatencyAppVec {};
78     std::vector<WhiteListAppInfo> m_whiteAppVec {};
79     std::vector<BlackListAppInfo> m_blackAppVec {};
80     std::vector<MultiLinkAppInfo> m_multilinkAppVec {};
81     std::vector<ChariotAppInfo> m_chariotAppVec {};
82     std::vector<HighTempLimitSpeedAppInfo> m_highTempLimitSpeedAppVec {};
83     std::vector<HighTempLimitSpeedAppInfo> m_highTempLimitSpeedAppVecCloudPush {};
84     bool mIshighTempLimitSpeedReadCloudPush = false;
85     bool initFlag_ = false;
86 };
87 } // namespace Wifi
88 } // namespace OHOS
89 
90 #endif