From fc231c2a27f8f987116718e335b01f37e8d25ba4 Mon Sep 17 00:00:00 2001 From: hw_ljz Date: Thu, 11 Sep 2025 10:53:14 +0800 Subject: [PATCH] add overflow feature config Signed-off-by: hw_ljz --- adapter/ohos/capability/BUILD.gn | 1 + .../feature_config/config_xml_parser_base.cpp | 51 +++++++++++++++---- .../feature_config/config_xml_parser_base.h | 14 ++++- .../feature_config/feature_param_manager.cpp | 33 ++++++++++++ .../feature_config/feature_param_manager.h | 7 +++ .../features/ui_correction_parser.cpp | 32 ++++++++++++ .../features/ui_correction_parser.h | 31 +++++++++++ adapter/ohos/osal/feature_param.cpp | 9 ++++ frameworks/base/utils/feature_param.h | 2 + test/mock/base/mock_feature_param.cpp | 10 ++++ .../ohos/capability/feature_config/BUILD.gn | 2 + 11 files changed, 181 insertions(+), 11 deletions(-) create mode 100644 adapter/ohos/capability/feature_config/features/ui_correction_parser.cpp create mode 100644 adapter/ohos/capability/feature_config/features/ui_correction_parser.h diff --git a/adapter/ohos/capability/BUILD.gn b/adapter/ohos/capability/BUILD.gn index 5d24628c84c..fdabba39e35 100644 --- a/adapter/ohos/capability/BUILD.gn +++ b/adapter/ohos/capability/BUILD.gn @@ -35,6 +35,7 @@ template("ace_capability_ohos_source_set") { "feature_config/config_xml_parser_base.cpp", "feature_config/features/ui_node_gc_params_parser.cpp", "feature_config/features/sync_load_parser.cpp", + "feature_config/features/ui_correction_parser.cpp", "html/html_to_span.cpp", "html/span_to_html.cpp", diff --git a/adapter/ohos/capability/feature_config/config_xml_parser_base.cpp b/adapter/ohos/capability/feature_config/config_xml_parser_base.cpp index d4bda7e5673..39e21f945aa 100644 --- a/adapter/ohos/capability/feature_config/config_xml_parser_base.cpp +++ b/adapter/ohos/capability/feature_config/config_xml_parser_base.cpp @@ -22,24 +22,18 @@ namespace OHOS::Ace { -enum ParseXmlNodeIndex : uint32_t { - PARSE_XML_UNDEFINED = 0, - PARSE_XML_PERFORMANCE_OPT_CONFIG, - PARSE_XML_BUNDLE_NAME, - PARSE_XML_FEATURE, - PARSE_XML_MAX_SIZE, -}; - namespace { static const std::array XML_NODE_NAME_ARRAY = { "undefine", // PARSE_XML_UNDEFINED "PerformanceOptConfig", // PARSE_XML_PERFORMANCE_OPT_CONFIG "bundleName", // PARSE_XML_BUNDLE_NAME "feature", // PARSE_XML_FEATURE + "UICorrectionAppList" // PARSE_XML_UI_CORRECTION }; static const std::array SYS_PATH = { "/etc" }; static constexpr char CONFIG_PATH[] = "/arkui/arkui_async_build_config.xml"; +static constexpr char UI_CORRECTION_CONFIG_PATH[] = "arkui/arkui_layout_config.xml"; } // namespace ConfigXMLParserBase::~ConfigXMLParserBase() @@ -72,6 +66,23 @@ ParseErrCode ConfigXMLParserBase::LoadPerformanceConfigXML() return PARSE_EXEC_SUCCESS; } +ParseErrCode ConfigXMLParserBase::LoadUICorrectionConfigXML() +{ + for (const std::string& configRootPath : SYS_PATH) { + std::string graphicFilePath = configRootPath + UI_CORRECTION_CONFIG_PATH; + xmlSysDocument_ = xmlReadFile(graphicFilePath.c_str(), nullptr, 0); + if (xmlSysDocument_ != nullptr) { + LOGD("ConfigXMLParserBase success to get sys UI correction config: %{public}s", graphicFilePath.c_str()); + break; + } + } + if (!xmlSysDocument_) { + LOGE("ConfigXMLParserBase read system UI correction config file failed"); + return PARSE_SYS_FILE_LOAD_FAIL; + } + return PARSE_EXEC_SUCCESS; +} + ParseErrCode ConfigXMLParserBase::ParsePerformanceConfigXMLWithBundleName(const std::string& bundleName) { if (!xmlSysDocument_) { @@ -91,7 +102,27 @@ ParseErrCode ConfigXMLParserBase::ParsePerformanceConfigXMLWithBundleName(const return ret; } -ParseErrCode ConfigXMLParserBase::ParseInternalWithBundleName(xmlNode& node, const std::string& bundleName) +ParseErrCode ConfigXMLParserBase::ParseUICorrectionConfigXMLWithBundleName(const std::string& bundleName) +{ + if (!xmlSysDocument_) { + LOGE("ConfigXMLParserBase xmlSysDocument is empty, LoadUICorrectionConfiguration first"); + return PARSE_SYS_FILE_LOAD_FAIL; + } + xmlNode* root = xmlDocGetRootElement(xmlSysDocument_); + if (root == nullptr) { + LOGE("ConfigXMLParserBase xmlDocGetRootElement failed"); + return PARSE_GET_ROOT_FAIL; + } + + auto ret = ParseInternalWithBundleName(*root, bundleName, PARSE_XML_UI_CORRECTION); + if (ret != PARSE_EXEC_SUCCESS) { + LOGE("ConfigXMLParserBase ParseInternalWithBundleName failed when parsing UI correction parameters"); + } + return ret; +} + +ParseErrCode ConfigXMLParserBase::ParseInternalWithBundleName(xmlNode& node, const std::string& bundleName, + ParseXmlNodeIndex xmlNodeIndex) { // skip root node xmlNode* currNode = node.children; @@ -102,7 +133,7 @@ ParseErrCode ConfigXMLParserBase::ParseInternalWithBundleName(xmlNode& node, con // find first PerformanceOptConfig node auto ret = PARSE_EXEC_SUCCESS; for (; currNode; currNode = currNode->next) { - ret = ParseXmlNodeNameWithIndex(*currNode, PARSE_XML_PERFORMANCE_OPT_CONFIG); + ret = ParseXmlNodeNameWithIndex(*currNode, xmlNodeIndex); if (ret == PARSE_EXEC_SUCCESS) { break; } diff --git a/adapter/ohos/capability/feature_config/config_xml_parser_base.h b/adapter/ohos/capability/feature_config/config_xml_parser_base.h index 136348502ca..bc51cf622e0 100644 --- a/adapter/ohos/capability/feature_config/config_xml_parser_base.h +++ b/adapter/ohos/capability/feature_config/config_xml_parser_base.h @@ -22,6 +22,15 @@ #include namespace OHOS::Ace { +enum ParseXmlNodeIndex : uint32_t { + PARSE_XML_UNDEFINED = 0, + PARSE_XML_PERFORMANCE_OPT_CONFIG, + PARSE_XML_BUNDLE_NAME, + PARSE_XML_FEATURE, + PARSE_XML_UI_CORRECTION, + PARSE_XML_MAX_SIZE, +}; + enum ParseErrCode { PARSE_ERROR = -1, PARSE_EXEC_SUCCESS = 0, @@ -51,9 +60,12 @@ protected: private: void Destroy(); ParseErrCode LoadPerformanceConfigXML(); + ParseErrCode LoadUICorrectionConfigXML(); ParseErrCode ParsePerformanceConfigXMLWithBundleName(const std::string& bundleName); + ParseErrCode ParseUICorrectionConfigXMLWithBundleName(const std::string& bundleName); ParseErrCode ParseXmlNodeNameWithIndex(xmlNode& node, uint32_t nodeNameIndex); - ParseErrCode ParseInternalWithBundleName(xmlNode& node, const std::string& bundleName); + ParseErrCode ParseInternalWithBundleName(xmlNode& node, const std::string& bundleName, + ParseXmlNodeIndex xmlNodeIndex = PARSE_XML_PERFORMANCE_OPT_CONFIG); void ParseFeatures(xmlNode& node); xmlDoc* xmlSysDocument_ = nullptr; diff --git a/adapter/ohos/capability/feature_config/feature_param_manager.cpp b/adapter/ohos/capability/feature_config/feature_param_manager.cpp index 0d14b6e5c11..e548c147924 100644 --- a/adapter/ohos/capability/feature_config/feature_param_manager.cpp +++ b/adapter/ohos/capability/feature_config/feature_param_manager.cpp @@ -18,6 +18,7 @@ #include "adapter/ohos/capability/feature_config/config_xml_parser_base.h" #include "adapter/ohos/capability/feature_config/features/sync_load_parser.h" #include "adapter/ohos/capability/feature_config/features/ui_node_gc_params_parser.h" +#include "adapter/ohos/capability/feature_config/features/ui_correction_parser.h" #include "base/log/log.h" #include "base/utils/system_properties.h" @@ -30,6 +31,7 @@ namespace OHOS::Ace { const std::unordered_map> FeatureParamManager::featureParamMap_ = { ADD_PARSER_MODEL(UINodeGcParamParser), ADD_PARSER_MODEL(SyncLoadParser), + ADD_PARSER_MODEL(UICorrectionParser), }; FeatureParamManager::FeatureParamManager() = default; @@ -38,6 +40,21 @@ FeatureParamManager::~FeatureParamManager() = default; void FeatureParamManager::Init(const std::string& bundleName) { FeatureParamParseEntry(bundleName); + UICorrectionParamParseEntry(bundleName); +} + +void FeatureParamManager::UICorrectionParamParseEntry(const std::string& bundleName) +{ + if (!uiCorrectionParser_) { + uiCorrectionParser_ = std::make_shared(); + } + if (uiCorrectionParser_->LoadUICorrectionConfigXML() != PARSE_EXEC_SUCCESS) { + LOGW("ArkUiFeatureParamManager failed to load ui correction config file"); + return; + } + if (uiCorrectionParser_->ParseUICorrectionConfigXMLWithBundleName(bundleName) != PARSE_EXEC_SUCCESS) { + LOGW("ArkUiFeatureParamManager failed to parse ui correction config file"); + } } void FeatureParamManager::FeatureParamParseEntry(const std::string& bundleName) @@ -67,6 +84,22 @@ bool FeatureParamManager::IsSyncLoadEnabled() const return syncLoadEnabled_ || SystemProperties::IsSyncLoadEnabled(); } +bool FeatureParamManager::IsPageOverflowEnabled() const +{ + return pageOverflowEnabled_; +} + +bool FeatureParamManager::IsDialogCorrectionEnabled() const +{ + return dialogCorrectionEnabled_; +} + +void FeatureParamManager::SetUiCorrectionEnableParam(bool pageOverflowEnabled, bool dialogCorrectionEnabled) +{ + pageOverflowEnabled_ = pageOverflowEnabled; + dialogCorrectionEnabled_ = dialogCorrectionEnabled; +} + uint32_t FeatureParamManager::GetSyncloadResponseDeadline() const { return syncloadResponseDeadline_; diff --git a/adapter/ohos/capability/feature_config/feature_param_manager.h b/adapter/ohos/capability/feature_config/feature_param_manager.h index a83095c656a..cae6b8054f0 100644 --- a/adapter/ohos/capability/feature_config/feature_param_manager.h +++ b/adapter/ohos/capability/feature_config/feature_param_manager.h @@ -38,19 +38,26 @@ public: void SetUINodeGcEnabled(bool enabled); bool IsUINodeGcEnabled() const; + bool IsPageOverflowEnabled() const; + bool IsDialogCorrectionEnabled() const; + void SetUiCorrectionEnableParam(bool pageOverflowEnabled, bool dialogCorrectionEnabled); private: void FeatureParamParseEntry(const std::string& bundleName); + void UICorrectionParamParseEntry(const std::string& bundleName); static const std::unordered_map> featureParamMap_; static constexpr uint32_t MAX_TIMER_SIZE = 3; // 3 is max size for responseDeadline static constexpr uint32_t DEFAULT_SYNCLOAD_DEADLINE = 50; // 50ms default time static constexpr uint32_t MS_TO_NS = 1000000; // 1000000 change time form ms to ns std::shared_ptr featureParser_; + std::shared_ptr uiCorrectionParser_; // SyncLoadParser bool syncLoadEnabled_ = false; uint32_t syncloadResponseDeadline_ = DEFAULT_SYNCLOAD_DEADLINE * MS_TO_NS; // UINodeGcParamParser bool uiNodeGcEnabled_ = false; + bool pageOverflowEnabled_ = false; + bool dialogCorrectionEnabled_ = false; friend class ConfigXMLParserBase; friend class SyncLoadParser; diff --git a/adapter/ohos/capability/feature_config/features/ui_correction_parser.cpp b/adapter/ohos/capability/feature_config/features/ui_correction_parser.cpp new file mode 100644 index 00000000000..ca184e5e27a --- /dev/null +++ b/adapter/ohos/capability/feature_config/features/ui_correction_parser.cpp @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "adapter/ohos/capability/feature_config/features/ui_correction_parser.h" + +#include "adapter/ohos/capability/feature_config/feature_param_manager.h" +#include "base/utils/string_utils.h" +#include "base/log/log.h" + +namespace OHOS::Ace { +ParseErrCode UICorrectionParser::ParseFeatureParam(xmlNode& node) +{ + auto& instance = FeatureParamManager::GetInstance(); + auto pageOverflowEnabled = ExtractPropertyValue("pageOverflowEnabled", node) == "true"; + auto dialogOverflowEnabled = ExtractPropertyValue("dialogOverflowEnabled", node) == "true"; + instance.SetUiCorrectionEnableParam(pageOverflowEnabled, dialogOverflowEnabled); + return PARSE_EXEC_SUCCESS; +} + +} // namespace OHOS::Ace diff --git a/adapter/ohos/capability/feature_config/features/ui_correction_parser.h b/adapter/ohos/capability/feature_config/features/ui_correction_parser.h new file mode 100644 index 00000000000..a9477e30213 --- /dev/null +++ b/adapter/ohos/capability/feature_config/features/ui_correction_parser.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FOUNDATION_ACE_ADAPTER_OHOS_CAPABILITY_FEATURE_CONFIG_FEATURES_UI_CORRECTION_PARSER_H +#define FOUNDATION_ACE_ADAPTER_OHOS_CAPABILITY_FEATURE_CONFIG_FEATURES_UI_CORRECTION_PARSER_H + +#include "adapter/ohos/capability/feature_config/config_xml_parser_base.h" + +namespace OHOS::Ace { +class UICorrectionParser : public ConfigXMLParserBase { +public: + UICorrectionParser() = default; + ~UICorrectionParser() = default; + + ParseErrCode ParseFeatureParam(xmlNode& node) override; +}; +} // namespace OHOS::Ace + +#endif // FOUNDATION_ACE_ADAPTER_OHOS_CAPABILITY_FEATURE_CONFIG_FEATURES_UI_CORRECTION_PARSER_H diff --git a/adapter/ohos/osal/feature_param.cpp b/adapter/ohos/osal/feature_param.cpp index d3313791035..5a1901b77cd 100644 --- a/adapter/ohos/osal/feature_param.cpp +++ b/adapter/ohos/osal/feature_param.cpp @@ -34,4 +34,13 @@ bool FeatureParam::IsUINodeGcEnabled() return FeatureParamManager::GetInstance().IsUINodeGcEnabled(); } +bool FeatureParam::IsPageOverflowEnabled() +{ + return FeatureParamManager::GetInstance().IsPageOverflowEnabled(); +} + +bool FeatureParam::IsDialogCorrectionEnabled() +{ + return FeatureParamManager::GetInstance().IsDialogCorrectionEnabled(); +} } // OHOS::Ace \ No newline at end of file diff --git a/frameworks/base/utils/feature_param.h b/frameworks/base/utils/feature_param.h index d4a0c705ec3..63be377fafb 100644 --- a/frameworks/base/utils/feature_param.h +++ b/frameworks/base/utils/feature_param.h @@ -31,6 +31,8 @@ public: static uint32_t GetSyncloadResponseDeadline(); // UINodeGcParamParser static bool IsUINodeGcEnabled(); + static bool IsPageOverflowEnabled(); + static bool IsDialogCorrectionEnabled(); }; } // namespace OHOS::Ace diff --git a/test/mock/base/mock_feature_param.cpp b/test/mock/base/mock_feature_param.cpp index 4717c0ac521..82d659d9a57 100644 --- a/test/mock/base/mock_feature_param.cpp +++ b/test/mock/base/mock_feature_param.cpp @@ -35,4 +35,14 @@ bool FeatureParam::IsUINodeGcEnabled() { return false; } + +bool FeatureParam::IsPageOverflowEnabled() +{ + return false; +} + +bool FeatureParam::IsDialogCorrectionEnabled() +{ + return false; +} } // OHOS::Ace \ No newline at end of file diff --git a/test/unittest/adapter/ohos/capability/feature_config/BUILD.gn b/test/unittest/adapter/ohos/capability/feature_config/BUILD.gn index 2cbbe9785f1..900646f988d 100644 --- a/test/unittest/adapter/ohos/capability/feature_config/BUILD.gn +++ b/test/unittest/adapter/ohos/capability/feature_config/BUILD.gn @@ -29,6 +29,7 @@ ohos_unittest("arkui_feature_param_manager_test") { "$ace_root/adapter/ohos/capability/feature_config/config_xml_parser_base.cpp", "$ace_root/adapter/ohos/capability/feature_config/features/ui_node_gc_params_parser.cpp", "$ace_root/adapter/ohos/capability/feature_config/features/sync_load_parser.cpp", + "$ace_root/adapter/ohos/capability/feature_config/features/ui_correction_parser.cpp", # mock "$ace_root/adapter/ohos/osal/log_wrapper.cpp", @@ -56,6 +57,7 @@ ohos_unittest("parser_test") { "$ace_root/adapter/ohos/capability/feature_config/config_xml_parser_base.cpp", "$ace_root/adapter/ohos/capability/feature_config/features/ui_node_gc_params_parser.cpp", "$ace_root/adapter/ohos/capability/feature_config/features/sync_load_parser.cpp", + "$ace_root/adapter/ohos/capability/feature_config/features/ui_correction_parser.cpp", # mock "$ace_root/adapter/ohos/osal/log_wrapper.cpp", -- Gitee