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