122736c2fSopenharmony_ci/*
222736c2fSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd.
322736c2fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
422736c2fSopenharmony_ci * you may not use this file except in compliance with the License.
522736c2fSopenharmony_ci * You may obtain a copy of the License at
622736c2fSopenharmony_ci *
722736c2fSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
822736c2fSopenharmony_ci *
922736c2fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1022736c2fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1122736c2fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1222736c2fSopenharmony_ci * See the License for the specific language governing permissions and
1322736c2fSopenharmony_ci * limitations under the License.
1422736c2fSopenharmony_ci */
1522736c2fSopenharmony_ci
1622736c2fSopenharmony_ci#include "sys_cfg_parser.h"
1722736c2fSopenharmony_ci
1822736c2fSopenharmony_ci#include <map>
1922736c2fSopenharmony_ci
2022736c2fSopenharmony_ci#include "file_operator.h"
2122736c2fSopenharmony_ci#include "global.h"
2222736c2fSopenharmony_cinamespace OHOS {
2322736c2fSopenharmony_cinamespace MiscServices {
2422736c2fSopenharmony_cibool SysCfgParser::ParseSystemConfig(SystemConfig &systemConfig)
2522736c2fSopenharmony_ci{
2622736c2fSopenharmony_ci    auto content = GetSysCfgContent(GET_NAME(systemConfig));
2722736c2fSopenharmony_ci    if (content.empty()) {
2822736c2fSopenharmony_ci        IMSA_HILOGE("content is empty");
2922736c2fSopenharmony_ci        return false;
3022736c2fSopenharmony_ci    }
3122736c2fSopenharmony_ci    ImeSystemConfig imeSysCfg;
3222736c2fSopenharmony_ci    auto ret = imeSysCfg.Unmarshall(content);
3322736c2fSopenharmony_ci    systemConfig = imeSysCfg.systemConfig;
3422736c2fSopenharmony_ci    return ret;
3522736c2fSopenharmony_ci}
3622736c2fSopenharmony_ci
3722736c2fSopenharmony_cibool SysCfgParser::ParseInputType(std::vector<InputTypeInfo> &inputType)
3822736c2fSopenharmony_ci{
3922736c2fSopenharmony_ci    auto content = GetSysCfgContent(GET_NAME(supportedInputTypeList));
4022736c2fSopenharmony_ci    if (content.empty()) {
4122736c2fSopenharmony_ci        IMSA_HILOGD("content is empty");
4222736c2fSopenharmony_ci        return false;
4322736c2fSopenharmony_ci    }
4422736c2fSopenharmony_ci    InputTypeCfg inputTypeCfg;
4522736c2fSopenharmony_ci    auto ret = inputTypeCfg.Unmarshall(content);
4622736c2fSopenharmony_ci    inputType = inputTypeCfg.inputType;
4722736c2fSopenharmony_ci    return ret;
4822736c2fSopenharmony_ci}
4922736c2fSopenharmony_ci
5022736c2fSopenharmony_cibool SysCfgParser::ParsePanelAdjust(std::vector<SysPanelAdjust> &sysPanelAdjust)
5122736c2fSopenharmony_ci{
5222736c2fSopenharmony_ci    auto content = GetSysCfgContent(GET_NAME(sysPanelAdjust));
5322736c2fSopenharmony_ci    if (content.empty()) {
5422736c2fSopenharmony_ci        IMSA_HILOGE("content is empty");
5522736c2fSopenharmony_ci        return false;
5622736c2fSopenharmony_ci    }
5722736c2fSopenharmony_ci    SysPanelAdjustCfg sysPanelAdjustCfg;
5822736c2fSopenharmony_ci    auto ret = sysPanelAdjustCfg.Unmarshall(content);
5922736c2fSopenharmony_ci    sysPanelAdjust = sysPanelAdjustCfg.panelAdjust;
6022736c2fSopenharmony_ci    return ret;
6122736c2fSopenharmony_ci}
6222736c2fSopenharmony_ci
6322736c2fSopenharmony_cibool SysCfgParser::ParseDefaultFullIme(std::vector<DefaultFullImeInfo> &defaultFullImeList)
6422736c2fSopenharmony_ci{
6522736c2fSopenharmony_ci    auto content = GetSysCfgContent(GET_NAME(defaultFullImeList));
6622736c2fSopenharmony_ci    if (content.empty()) {
6722736c2fSopenharmony_ci        IMSA_HILOGD("content is empty");
6822736c2fSopenharmony_ci        return false;
6922736c2fSopenharmony_ci    }
7022736c2fSopenharmony_ci    DefaultFullImeCfg defaultFullImeCfg;
7122736c2fSopenharmony_ci    auto ret = defaultFullImeCfg.Unmarshall(content);
7222736c2fSopenharmony_ci    defaultFullImeList = defaultFullImeCfg.defaultFullImeList;
7322736c2fSopenharmony_ci    return ret;
7422736c2fSopenharmony_ci}
7522736c2fSopenharmony_ci
7622736c2fSopenharmony_cistd::string SysCfgParser::GetSysCfgContent(const std::string &key)
7722736c2fSopenharmony_ci{
7822736c2fSopenharmony_ci    std::string content;
7922736c2fSopenharmony_ci    auto ret = FileOperator::Read(SYS_CFG_FILE_PATH, key, content);
8022736c2fSopenharmony_ci    if (!ret) {
8122736c2fSopenharmony_ci        IMSA_HILOGD("get content by %{public}s failed.", key.c_str());
8222736c2fSopenharmony_ci    }
8322736c2fSopenharmony_ci    return content;
8422736c2fSopenharmony_ci}
8522736c2fSopenharmony_ci} // namespace MiscServices
8622736c2fSopenharmony_ci} // namespace OHOS