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