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 #include "sys_cfg_parser.h" 17 18 #include <map> 19 20 #include "file_operator.h" 21 #include "global.h" 22 namespace OHOS { 23 namespace MiscServices { ParseSystemConfig(SystemConfig & systemConfig)24bool SysCfgParser::ParseSystemConfig(SystemConfig &systemConfig) 25 { 26 auto content = GetSysCfgContent(GET_NAME(systemConfig)); 27 if (content.empty()) { 28 IMSA_HILOGE("content is empty"); 29 return false; 30 } 31 ImeSystemConfig imeSysCfg; 32 auto ret = imeSysCfg.Unmarshall(content); 33 systemConfig = imeSysCfg.systemConfig; 34 return ret; 35 } 36 ParseInputType(std::vector<InputTypeInfo> & inputType)37bool SysCfgParser::ParseInputType(std::vector<InputTypeInfo> &inputType) 38 { 39 auto content = GetSysCfgContent(GET_NAME(supportedInputTypeList)); 40 if (content.empty()) { 41 IMSA_HILOGD("content is empty"); 42 return false; 43 } 44 InputTypeCfg inputTypeCfg; 45 auto ret = inputTypeCfg.Unmarshall(content); 46 inputType = inputTypeCfg.inputType; 47 return ret; 48 } 49 ParsePanelAdjust(std::vector<SysPanelAdjust> & sysPanelAdjust)50bool SysCfgParser::ParsePanelAdjust(std::vector<SysPanelAdjust> &sysPanelAdjust) 51 { 52 auto content = GetSysCfgContent(GET_NAME(sysPanelAdjust)); 53 if (content.empty()) { 54 IMSA_HILOGE("content is empty"); 55 return false; 56 } 57 SysPanelAdjustCfg sysPanelAdjustCfg; 58 auto ret = sysPanelAdjustCfg.Unmarshall(content); 59 sysPanelAdjust = sysPanelAdjustCfg.panelAdjust; 60 return ret; 61 } 62 ParseDefaultFullIme(std::vector<DefaultFullImeInfo> & defaultFullImeList)63bool SysCfgParser::ParseDefaultFullIme(std::vector<DefaultFullImeInfo> &defaultFullImeList) 64 { 65 auto content = GetSysCfgContent(GET_NAME(defaultFullImeList)); 66 if (content.empty()) { 67 IMSA_HILOGD("content is empty"); 68 return false; 69 } 70 DefaultFullImeCfg defaultFullImeCfg; 71 auto ret = defaultFullImeCfg.Unmarshall(content); 72 defaultFullImeList = defaultFullImeCfg.defaultFullImeList; 73 return ret; 74 } 75 GetSysCfgContent(const std::string & key)76std::string SysCfgParser::GetSysCfgContent(const std::string &key) 77 { 78 std::string content; 79 auto ret = FileOperator::Read(SYS_CFG_FILE_PATH, key, content); 80 if (!ret) { 81 IMSA_HILOGD("get content by %{public}s failed.", key.c_str()); 82 } 83 return content; 84 } 85 } // namespace MiscServices 86 } // namespace OHOS 87