• 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 <sstream>
17 #include "uifirst_param_parse.h"
18 
19 namespace OHOS::Rosen {
20 
GetUIFirstSwitchType(const std::string & input)21 UIFirstSwitchType UIFirstParamParse::GetUIFirstSwitchType(const std::string& input)
22 {
23     static const std::map<std::string, UIFirstSwitchType> uifirstSwitchTypeMap = {
24         {"UIFirstEnabled", UIFirstSwitchType::UIFIRST_ENABLED},
25         {"CardUIFirstEnabled", UIFirstSwitchType::CARD_UIFIRST_ENABLED},
26         {"CacheOptimizeRotateEnabled", UIFirstSwitchType::ROTATE_ENABLED},
27         {"FreeMultiWindowEnabled", UIFirstSwitchType::FREE_MULTI_WINDOW_ENABLED}
28     };
29 
30     auto it = uifirstSwitchTypeMap.find(input);
31     if (it != uifirstSwitchTypeMap.end()) {
32         return it->second;
33     }
34     return UIFirstSwitchType::UNKNOWN;
35 }
36 
ParseFeatureParam(FeatureParamMapType & featureMap,xmlNode & node)37 int32_t UIFirstParamParse::ParseFeatureParam(FeatureParamMapType &featureMap, xmlNode &node)
38 {
39     xmlNode *currNode = &node;
40     if (currNode->xmlChildrenNode == nullptr) {
41         RS_LOGD("UIFirstParamParse stop parsing, no children nodes");
42         return PARSE_GET_CHILD_FAIL;
43     }
44 
45     currNode = currNode->xmlChildrenNode;
46     for (; currNode; currNode = currNode->next) {
47         if (currNode->type != XML_ELEMENT_NODE) {
48             continue;
49         }
50 
51         if (ParseUIFirstInternal(featureMap, *currNode) != PARSE_EXEC_SUCCESS) {
52             RS_LOGD("UIFirstParamParse stop parsing, parse internal fail");
53             return PARSE_INTERNAL_FAIL;
54         }
55     }
56     return PARSE_EXEC_SUCCESS;
57 }
58 
ParseUIFirstInternal(FeatureParamMapType & featureMap,xmlNode & node)59 int32_t UIFirstParamParse::ParseUIFirstInternal(FeatureParamMapType &featureMap, xmlNode &node)
60 {
61     xmlNode *currNode = &node;
62 
63     auto iter = featureMap.find(FEATURE_CONFIGS[UIFirst]);
64     if (iter == featureMap.end()) {
65         RS_LOGD("UIFirstParamParse stop parsing, no initializing param map");
66         return PARSE_INTERNAL_FAIL;
67     }
68     uifirstParam_ = std::static_pointer_cast<UIFirstParam>(iter->second);
69 
70     // Start Parse Feature Params
71     int xmlParamType = GetXmlNodeAsInt(*currNode);
72     auto name = ExtractPropertyValue("name", *currNode);
73     auto val = ExtractPropertyValue("value", *currNode);
74     if (xmlParamType == PARSE_XML_FEATURE_SWITCH) {
75         bool isEnabled = ParseFeatureSwitch(val);
76         switch (GetUIFirstSwitchType(name)) {
77             case UIFirstSwitchType::UIFIRST_ENABLED:
78                 uifirstParam_->SetUIFirstEnable(isEnabled);
79                 RS_LOGI("UIFirstParamParse parse UIFirstEnabled %{public}d", uifirstParam_->IsUIFirstEnable());
80                 break;
81             case UIFirstSwitchType::CARD_UIFIRST_ENABLED:
82                 uifirstParam_->SetCardUIFirstEnable(isEnabled);
83                 RS_LOGI("UIFirstParamParse parse CardUIFirstEnabled %{public}d",
84                     uifirstParam_->IsCardUIFirstEnable());
85                 break;
86             case UIFirstSwitchType::ROTATE_ENABLED:
87                 uifirstParam_->SetCacheOptimizeRotateEnable(isEnabled);
88                 RS_LOGI("UIFirstParamParse parse CacheOptimizeRotateEnabled %{public}d",
89                     uifirstParam_->IsCacheOptimizeRotateEnable());
90                 break;
91             case UIFirstSwitchType::FREE_MULTI_WINDOW_ENABLED:
92                 uifirstParam_->SetFreeMultiWindowEnable(isEnabled);
93                 RS_LOGI("UIFirstParamParse parse FreeMultiWindowEnabled %{public}d",
94                     uifirstParam_->IsFreeMultiWindowEnable());
95                 break;
96             default:
97                 RS_LOGI("UIFirstParamParse parse %{public}s is not support!", name.c_str());
98                 break;
99         }
100     } else if (xmlParamType == PARSE_XML_FEATURE_SINGLEPARAM) {
101         return ParseUIFirstSingleParam(name, val);
102     }
103 
104     return PARSE_EXEC_SUCCESS;
105 }
106 
ParseUIFirstSingleParam(const std::string & name,const std::string & value)107 int32_t UIFirstParamParse::ParseUIFirstSingleParam(const std::string& name, const std::string& value)
108 {
109     if (name == "UIFirstEnableWindowThreshold" && IsNumber(value)) {
110         int num;
111         std::istringstream iss(value);
112         if (iss >> num) {
113             uifirstParam_->SetUIFirstEnableWindowThreshold(num);
114             RS_LOGI("UIFirstParamParse parse UIFirstEnableWindowThreshold %{public}d",
115                 uifirstParam_->GetUIFirstEnableWindowThreshold());
116         }
117     } else if (name == "UIFirstType" && IsNumber(value)) {
118         int num;
119         std::istringstream iss(value);
120         if (iss >> num) {
121             uifirstParam_->SetUIFirstType(num);
122             RS_LOGI("UIFirstParamParse parse UIFirstType %{public}d", uifirstParam_->GetUIFirstType());
123         }
124     }
125     return PARSE_EXEC_SUCCESS;
126 }
127 } // namespace OHOS::Rosen