• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 NWEB_CONFIG_HELPER_H
17 #define NWEB_CONFIG_HELPER_H
18 
19 #include "bundle_mgr_interface.h"
20 #include "libxml/parser.h"
21 #include "libxml/tree.h"
22 #include "iservice_registry.h"
23 #include "nweb_init_params.h"
24 #include "nweb_helper.h"
25 #include "system_ability_definition.h"
26 
27 namespace OHOS::NWeb {
28 
29 class OHOS_NWEB_EXPORT NWebConfigHelper {
30 public:
31     static NWebConfigHelper &Instance();
32     ~NWebConfigHelper() = default;
33 
34     void ParseConfig(std::shared_ptr<NWebEngineInitArgsImpl> initArgs);
35     void ReadConfigIfNeeded();
36     std::string ParsePerfConfig(const std::string &configNodeName, const std::string &argsNodeName);
37     std::vector<FrameRateSetting> GetPerfConfig(const std::string& settingName);
38     bool IsLTPODynamicApp(const std::string& bundleName);
39     int32_t GetLTPOStrategy();
40     int safeGetPropAsInt(xmlNode* node, const xmlChar* propName, int defaultValue);
41     std::string GetBundleName();
42     void SetBundleName(const std::string& bundleName);
43     bool IsWebPlayGroundEnable();
44     const std::string& GetWebPlayGroundInitArg();
45     const std::string& GetWebPlayGroundHapPath();
46 
47 private:
48     NWebConfigHelper();
49     std::string GetConfigPath(const std::string &configFileName);
50     void ParseNWebLTPOConfig(xmlNodePtr nodePtr);
51     void ReadConfig(const xmlNodePtr &rootPtr, std::shared_ptr<NWebEngineInitArgsImpl> initArgs);
52     xmlNodePtr GetChildrenNode(xmlNodePtr NodePtr, const std::string &childrenNodeName);
53     void ParsePerfConfig(xmlNodePtr NodePtr);
54     void ParseWebConfigXml(const std::string &configFilePath, std::shared_ptr<NWebEngineInitArgsImpl> initArgs);
55     void WriteConfigValueToSysPara(const std::string &configName, const std::string &value);
56     void ParseDeleteConfig(const xmlNodePtr &rootPtr, std::shared_ptr<NWebEngineInitArgsImpl> initArgs);
57     void ParseNWebLTPOApp(xmlNodePtr nodePtr);
58     void ParseNWebLTPOStrategy(xmlNodePtr nodePtr);
59     void ParseWindowOrientationConfig(xmlNodePtr nodePtr, std::shared_ptr<NWebEngineInitArgsImpl> initArgs);
60     bool IsDeveloperModeEnabled();
61     bool IsPerfConfigEmpty();
62 
63     std::map<std::string, std::string> perfConfig_;
64     std::map<std::string, std::vector<FrameRateSetting>> ltpoConfig_;
65     std::set<std::string> ltpoAllowedApps_ {};
66     int32_t ltpoStrategy_ {0};
67     std::string bundleName_;
68     mutable std::mutex lock_;
69 
70     // add for web play ground
71     const std::string PLAYGROUND = "enableArkWebPlayGround";
72     const std::string NULL_STR = "";
73     const std::string SINGLE_PROCESS = "--single-process";
74     const std::string PLAY_GROUND_HAP_PATH = "/data/storage/el1/bundle/entry/resources/resfile/nweb.hap";
75     bool web_play_ground_enabled_ = false;
76 };
77 } // namespace OHOS
78 
79 #endif // NWEB_CONFIG_HELPER_H