diff --git a/wmserver/BUILD.gn b/wmserver/BUILD.gn index af1ecf0c..2abb5997 100644 --- a/wmserver/BUILD.gn +++ b/wmserver/BUILD.gn @@ -71,6 +71,7 @@ ohos_shared_library("libwms") { "src/window_layout_policy_cascade.cpp", "src/window_layout_policy_tile.cpp", "src/window_manager_agent_controller.cpp", + "src/window_manager_config.cpp", "src/window_manager_service.cpp", "src/window_manager_stub.cpp", "src/window_node.cpp", diff --git a/wmserver/include/window_manager_config.h b/wmserver/include/window_manager_config.h new file mode 100644 index 00000000..7efe7f3d --- /dev/null +++ b/wmserver/include/window_manager_config.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2022 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 OHOS_ROSEN_WINDOW_MANAGER_CONFIG_H +#define OHOS_ROSEN_WINDOW_MANAGER_CONFIG_H + +#include +#include +#include + +#include +#include "libxml/parser.h" +#include "libxml/tree.h" + +namespace OHOS { +namespace Rosen { +class WindowManagerConfig : public RefBase { +public: + WindowManagerConfig() = delete; + ~WindowManagerConfig() = default; + + static bool LoadConfigXml(const std::string& configFilePath); + static const std::map& GetEnableConfig(); + static const std::map>& GetNumbersConfig(); + static void DumpConfig(); + +private: + static std::map enableConfig_; + static std::map> numbersConfig_; + + static bool IsValidNode(const xmlNode& currNode); + static void ReadEnableConfigInfo(const xmlNodePtr& currNode); + static void ReadNumbersConfigInfo(const xmlNodePtr& currNode); +}; +} // namespace Rosen +} // namespace OHOS +#endif // OHOS_ROSEN_WINDOW_MANAGER_CONFIG_H diff --git a/wmserver/include/window_manager_service.h b/wmserver/include/window_manager_service.h index a4dcd159..b2029b98 100644 --- a/wmserver/include/window_manager_service.h +++ b/wmserver/include/window_manager_service.h @@ -32,9 +32,6 @@ #include "window_root.h" #include "snapshot_controller.h" -#include "libxml/parser.h" -#include "libxml/tree.h" - namespace OHOS { namespace Rosen { class DisplayChangeListener : public IDisplayChangeListener { @@ -89,8 +86,7 @@ private: void RegisterWindowManagerServiceHandler(); void OnWindowEvent(Event event, uint32_t windowId); void NotifyDisplayStateChange(DisplayId id, DisplayStateChangeType type); - bool LoadConfigXmlFile(std::string configFile); - bool ParseChildNode(xmlNode* child); + void ConfigureWindowManagerService(); static inline SingletonDelegator delegator; std::recursive_mutex mutex_; diff --git a/wmserver/src/window_manager_config.cpp b/wmserver/src/window_manager_config.cpp new file mode 100644 index 00000000..0c2b1378 --- /dev/null +++ b/wmserver/src/window_manager_config.cpp @@ -0,0 +1,138 @@ +/* + * Copyright (c) 2022 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 "window_manager_config.h" +#include "window_helper.h" +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowManagerConfig"}; +} + +std::map WindowManagerConfig::enableConfig_; +std::map> WindowManagerConfig::numbersConfig_; + +bool WindowManagerConfig::LoadConfigXml(const std::string& configFilePath) +{ + xmlDocPtr docPtr = xmlReadFile(configFilePath.c_str(), nullptr, XML_PARSE_NOBLANKS); + WLOGFI("[WmConfig] filePath: %{public}s", configFilePath.c_str()); + if (docPtr == nullptr) { + WLOGFE("[WmConfig] load xml error!"); + return false; + } + + xmlNodePtr rootPtr = xmlDocGetRootElement(docPtr); + if (rootPtr == nullptr || rootPtr->name == nullptr || + xmlStrcmp(rootPtr->name, reinterpret_cast("Configs"))) { + WLOGFE("[WmConfig] get root element failed!"); + xmlFreeDoc(docPtr); + return false; + } + + for (xmlNodePtr curNodePtr = rootPtr->xmlChildrenNode; curNodePtr != nullptr; curNodePtr = curNodePtr->next) { + if (!IsValidNode(*curNodePtr)) { + WLOGFE("[WmConfig]: invalid node!"); + continue; + } + + auto nodeName = curNodePtr->name; + if (!xmlStrcmp(nodeName, reinterpret_cast("decor")) || + !xmlStrcmp(nodeName, reinterpret_cast("minimizeByOther"))) { + ReadEnableConfigInfo(curNodePtr); + continue; + } + if (!xmlStrcmp(nodeName, reinterpret_cast("maxAppWindowNumber")) || + !xmlStrcmp(nodeName, reinterpret_cast("modeChangeHotZones"))) { + ReadNumbersConfigInfo(curNodePtr); + continue; + } + } + xmlFreeDoc(docPtr); + return true; +} + +bool WindowManagerConfig::IsValidNode(const xmlNode& currNode) +{ + if (currNode.name == nullptr || currNode.type == XML_COMMENT_NODE) { + return false; + } + return true; +} + +void WindowManagerConfig::ReadEnableConfigInfo(const xmlNodePtr& currNode) +{ + xmlChar* enable = xmlGetProp(currNode, reinterpret_cast("enable")); + if (enable == nullptr) { + WLOGFE("[WmConfig] read xml node error: nodeName:(%{public}s)", currNode->name); + return; + } + + std::string nodeName = reinterpret_cast(currNode->name); + enableConfig_[nodeName] = xmlStrcmp(enable, reinterpret_cast("true")) ? false : true; + xmlFree(enable); +} + +void WindowManagerConfig::ReadNumbersConfigInfo(const xmlNodePtr& currNode) +{ + xmlChar* context = xmlNodeGetContent(currNode); + if (context == nullptr) { + WLOGFE("[WmConfig] read xml node error: nodeName:(%{public}s)", currNode->name); + return; + } + + std::vector numbersVec; + std::string numbersStr = reinterpret_cast(context); + auto numbers = WindowHelper::Split(numbersStr, " "); + for (auto& num : numbers) { + if (!WindowHelper::IsNumber(num)) { + WLOGFE("[WmConfig] read number error: nodeName:(%{public}s)", currNode->name); + xmlFree(context); + return; + } + numbersVec.emplace_back(std::stoi(num)); + } + + std::string nodeName = reinterpret_cast(currNode->name); + numbersConfig_[nodeName] = numbersVec; + xmlFree(context); +} + +const std::map& WindowManagerConfig::GetEnableConfig() +{ + return enableConfig_; +} + +const std::map>& WindowManagerConfig::GetNumbersConfig() +{ + return numbersConfig_; +} + +void WindowManagerConfig::DumpConfig() +{ + for (auto& enable : enableConfig_) { + WLOGFI("[WmConfig] Enable: %{public}s %{public}u", enable.first.c_str(), enable.second); + } + + for (auto& numbers : numbersConfig_) { + WLOGFI("[WmConfig] Numbers: %{public}s %{public}zu", numbers.first.c_str(), numbers.second.size()); + for (auto& num : numbers.second) { + WLOGFI("[WmConfig] Num: %{public}d", num); + } + } +} +} // namespace Rosen +} // namespace OHOS diff --git a/wmserver/src/window_manager_service.cpp b/wmserver/src/window_manager_service.cpp index c071aa09..d0f12a06 100644 --- a/wmserver/src/window_manager_service.cpp +++ b/wmserver/src/window_manager_service.cpp @@ -29,6 +29,7 @@ #include "window_helper.h" #include "window_inner_manager.h" #include "window_manager_agent_controller.h" +#include "window_manager_config.h" #include "window_manager_hilog.h" #include "wm_common.h" #include "wm_trace.h" @@ -106,99 +107,43 @@ bool WindowManagerService::Init() WLOGFW("WindowManagerService::Init failed"); return false; } - if (!LoadConfigXmlFile(WINDOW_MANAGER_CONFIG_XML)) { - WLOGFW("Failed to load %{public}s", WINDOW_MANAGER_CONFIG_XML.c_str()); - return false; + if (WindowManagerConfig::LoadConfigXml(WINDOW_MANAGER_CONFIG_XML)) { + WindowManagerConfig::DumpConfig(); + ConfigureWindowManagerService(); } WLOGFI("WindowManagerService::Init success"); return true; } -bool WindowManagerService::LoadConfigXmlFile(std::string configFile) +void WindowManagerService::ConfigureWindowManagerService() { - xmlKeepBlanksDefault(0); - xmlDoc* file = xmlReadFile(configFile.c_str(), nullptr, 0); - if (!file) { - WLOGFE("Failed to open xml file"); - return false; - } - xmlNode* rootNode = xmlDocGetRootElement(file); - if (!rootNode) { - WLOGFE("Failed to get xml file's RootNode"); - xmlFreeDoc(file); - return false; - } - if (!xmlStrcmp(rootNode->name, reinterpret_cast("Configs"))) { - xmlNode* child = rootNode->children; - for (; child; child = child->next) { - if (!ParseChildNode(child)) { - WLOGFE("Invalid resource name for %{public}s", configFile.c_str()); - xmlFreeDoc(file); - return false; - } - } - } else { - WLOGFE("Wrong format for xml file"); - xmlFreeDoc(file); - return false; - } - xmlFreeDoc(file); - WLOGFI("Success to Load %{public}s", configFile.c_str()); - return true; -} + auto enableConfig = WindowManagerConfig::GetEnableConfig(); + auto numbersConfig = WindowManagerConfig::GetNumbersConfig(); -bool WindowManagerService::ParseChildNode(xmlNode* child) -{ - if (!xmlStrcmp(child->name, reinterpret_cast("decor"))) { - char* enable = reinterpret_cast(xmlGetProp(child, reinterpret_cast("enable"))); - if (!enable) { - return false; - } - if (!strcmp(enable, "false")) { - isSystemDecorEnable_ = false; - } else if (!strcmp(enable, "true")) { - isSystemDecorEnable_ = true; - } else { - WLOGFW("Invalid resource prop"); - } - } else if (!xmlStrcmp(child->name, reinterpret_cast("maxAppWindowNumber"))) { - const char* maxAppWindowNumberStr = reinterpret_cast(xmlNodeGetContent(child)); - if (!maxAppWindowNumberStr || !WindowHelper::IsNumber(maxAppWindowNumberStr)) { - WLOGFW("Invalid maxAppWindowNumber"); - return false; - } - windowRoot_->SetMaxAppWindowNumber(std::atoi(maxAppWindowNumberStr)); - } else if (!xmlStrcmp(child->name, reinterpret_cast("minimizeByOther"))) { - char* enable = reinterpret_cast(xmlGetProp(child, reinterpret_cast("enable"))); - if (!enable) { - return false; - } - if (!strcmp(enable, "false")) { - windowRoot_->SetMinimizedByOtherWindow(false); - } else if (!strcmp(enable, "true")) { - windowRoot_->SetMinimizedByOtherWindow(true); - } else { - WLOGFW("Invalid resource prop"); - } - } else if (!xmlStrcmp(child->name, reinterpret_cast("modeChangeHotZones"))) { - const char* hotZones = reinterpret_cast(xmlNodeGetContent(child)); - if (!hotZones) { - WLOGFW("Invalid hotZones"); - return false; - } - std::string hotZonesStr = hotZones; - auto result = WindowHelper::Split(hotZonesStr, " "); - if (result.size() != 3 || !WindowHelper::IsNumber(result[0]) || // 3 hot zones, 0 fullscreen - !WindowHelper::IsNumber(result[1]) || !WindowHelper::IsNumber(result[2])) { // 1 primary, 2 secondary - return false; - } - hotZonesConfig_.fullscreenRange_ = static_cast(std::stoi(result[0])); // 0 fullscreen - hotZonesConfig_.primaryRange_ = static_cast(std::stoi(result[1])); // 1 primary - hotZonesConfig_.secondaryRange_ = static_cast(std::stoi(result[2])); // 2 secondary - hotZonesConfig_.isModeChangeHotZoneConfigured_ = true; + if (enableConfig.count("decor") != 0) { + isSystemDecorEnable_ = enableConfig["decor"]; } - return true; + if (enableConfig.count("minimizeByOther") != 0) { + windowRoot_->SetMinimizedByOtherWindow(enableConfig["minimizeByOther"]); + } + + if (numbersConfig.count("maxAppWindowNumber") != 0) { + auto numbers = numbersConfig["maxAppWindowNumber"]; + if (numbers.size() == 1) { + windowRoot_->SetMaxAppWindowNumber(numbers[0]); + } + } + + if (numbersConfig.count("modeChangeHotZones") != 0) { + auto numbers = numbersConfig["modeChangeHotZones"]; + if (numbers.size() == 3) { // 3 hot zones + hotZonesConfig_.fullscreenRange_ = static_cast(numbers[0]); // 0 fullscreen + hotZonesConfig_.primaryRange_ = static_cast(numbers[1]); // 1 primary + hotZonesConfig_.secondaryRange_ = static_cast(numbers[2]); // 2 secondary + hotZonesConfig_.isModeChangeHotZoneConfigured_ = true; + } + } } void WindowManagerService::OnStop()