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 "updateservice_json_utils.h"
24 #include "firmware_constant.h"
25
26 namespace OHOS {
27 namespace UpdateService {
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
GetStreamInstallerTimeout()43 uint32_t ConfigParse::GetStreamInstallerTimeout()
44 {
45 return configInfo_.streamInstallTimeout;
46 }
47
GetModuleLibPath()48 std::string ConfigParse::GetModuleLibPath()
49 {
50 return configInfo_.moduleLibPath;
51 }
52
LoadConfigInfo()53 void ConfigParse::LoadConfigInfo()
54 {
55 std::ifstream readFile;
56 readFile.open(Constant::DUPDATE_ENGINE_CONFIG_PATH);
57 if (readFile.fail()) {
58 ENGINE_LOGE("open config fail");
59 return;
60 }
61 std::stringstream streambuffer;
62 streambuffer << readFile.rdbuf();
63 std::string rawJson(streambuffer.str());
64 readFile.close();
65
66 auto root = UpdateServiceJsonUtils::ParseJson(rawJson.c_str());
67 if (root == nullptr) {
68 ENGINE_LOGE("json Create error!");
69 return;
70 }
71
72 UpdateServiceJsonUtils::GetValueAndSetTo(root.get(), "abInstallTimeout", configInfo_.abInstallTimeout);
73 UpdateServiceJsonUtils::GetValueAndSetTo(root.get(), "streamInstallTimeout", configInfo_.streamInstallTimeout);
74 UpdateServiceJsonUtils::GetValueAndSetTo(root.get(), "moduleLibPath", configInfo_.moduleLibPath);
75 }
76 } // namespace UpdateService
77 } // namespace OHOS
78