1 /*
2 * Copyright (c) 2023 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 "config_parse.h"
17
18 #include <fstream>
19 #include <iostream>
20 #include <sstream>
21
22 #include "constant.h"
23 #include "dupdate_json_utils.h"
24 #include "firmware_constant.h"
25
26 namespace OHOS {
27 namespace UpdateEngine {
ConfigParse()28 ConfigParse::ConfigParse()
29 {
30 ENGINE_LOGI("ConfigParse::ConfigParse");
31 }
32
~ConfigParse()33 ConfigParse::~ConfigParse()
34 {
35 ENGINE_LOGI("ConfigParse::~ConfigParse");
36 }
37
GetAbInstallerTimeout()38 uint32_t ConfigParse::GetAbInstallerTimeout()
39 {
40 return configInfo_.abInstallTimeout;
41 }
42
GetModuleLibPath()43 std::string ConfigParse::GetModuleLibPath()
44 {
45 return configInfo_.moduleLibPath;
46 }
47
LoadConfigInfo()48 void ConfigParse::LoadConfigInfo()
49 {
50 std::ifstream readFile;
51 readFile.open(Constant::DUPDATE_ENGINE_CONFIG_PATH);
52 if (readFile.fail()) {
53 ENGINE_LOGE("open config fail");
54 return;
55 }
56 std::stringstream streambuffer;
57 streambuffer << readFile.rdbuf();
58 std::string rawJson(streambuffer.str());
59 readFile.close();
60
61 nlohmann::json root = nlohmann::json::parse(rawJson, nullptr, false);
62 if (root.is_discarded()) {
63 ENGINE_LOGE("json Create error!");
64 return;
65 }
66
67 JsonUtils::GetValueAndSetTo(root, "abInstallTimeout", configInfo_.abInstallTimeout);
68 JsonUtils::GetValueAndSetTo(root, "moduleLibPath", configInfo_.moduleLibPath);
69 }
70 } // namespace UpdateEngine
71 } // namespace OHOS
72