• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 #include "adapter/ohos/capability/feature_config/feature_param_manager.h"
17 
18 #include "adapter/ohos/capability/feature_config/config_xml_parser_base.h"
19 #include "adapter/ohos/capability/feature_config/features/sync_load_parser.h"
20 #include "adapter/ohos/capability/feature_config/features/ui_node_gc_params_parser.h"
21 #include "base/log/log.h"
22 #include "base/utils/system_properties.h"
23 
24 namespace OHOS::Ace {
25 #define ADD_PARSER_MODEL(cls)         \
26     {                                 \
27         #cls, std::make_shared<cls>() \
28     }
29 
30 const std::unordered_map<std::string, std::shared_ptr<ConfigXMLParserBase>> FeatureParamManager::featureParamMap_ = {
31     ADD_PARSER_MODEL(UINodeGcParamParser),
32     ADD_PARSER_MODEL(SyncLoadParser),
33 };
34 
35 FeatureParamManager::FeatureParamManager() = default;
36 FeatureParamManager::~FeatureParamManager() = default;
37 
Init(const std::string & bundleName)38 void FeatureParamManager::Init(const std::string& bundleName)
39 {
40     FeatureParamParseEntry(bundleName);
41 }
42 
FeatureParamParseEntry(const std::string & bundleName)43 void FeatureParamManager::FeatureParamParseEntry(const std::string& bundleName)
44 {
45     if (!featureParser_) {
46         featureParser_ = std::make_shared<ConfigXMLParserBase>();
47     }
48 
49     if (featureParser_->LoadPerformanceConfigXML() != PARSE_EXEC_SUCCESS) {
50         LOGW("ArkUiFeatureParamManager failed to load xml file");
51         return;
52     }
53 
54     if (featureParser_->ParsePerformanceConfigXMLWithBundleName(bundleName) != PARSE_EXEC_SUCCESS) {
55         LOGW("ArkUiFeatureParamManager failed to parse xml file");
56     }
57 }
58 
SetSyncLoadEnableParam(bool enabled,uint32_t deadline)59 void FeatureParamManager::SetSyncLoadEnableParam(bool enabled, uint32_t deadline)
60 {
61     syncLoadEnabled_ = enabled;
62     syncloadResponseDeadline_ = deadline;
63 }
64 
IsSyncLoadEnabled() const65 bool FeatureParamManager::IsSyncLoadEnabled() const
66 {
67     return syncLoadEnabled_ || SystemProperties::IsSyncLoadEnabled();
68 }
69 
GetSyncloadResponseDeadline() const70 uint32_t FeatureParamManager::GetSyncloadResponseDeadline() const
71 {
72     return syncloadResponseDeadline_;
73 }
74 
SetUINodeGcEnabled(bool enabled)75 void FeatureParamManager::SetUINodeGcEnabled(bool enabled)
76 {
77     uiNodeGcEnabled_ = enabled;
78 }
79 
IsUINodeGcEnabled() const80 bool FeatureParamManager::IsUINodeGcEnabled() const
81 {
82     return uiNodeGcEnabled_;
83 }
84 } // namespace OHOS::Ace
85