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 #ifndef FIRMWARE_UPDATE_HELPER_H
17 #define FIRMWARE_UPDATE_HELPER_H
18 
19 #include <algorithm>
20 
21 #include "nlohmann/json.hpp"
22 
23 #include "current_version_info.h"
24 #include "firmware_changelog_utils.h"
25 #include "firmware_constant.h"
26 #include "firmware_combine_version_utils.h"
27 #include "firmware_common.h"
28 #include "firmware_component.h"
29 #include "firmware_component_operator.h"
30 #include "firmware_file_utils.h"
31 #include "firmware_log.h"
32 #include "firmware_preferences_utils.h"
33 #include "firmware_task_operator.h"
34 #include "device_adapter.h"
35 #include "sha256_utils.h"
36 #include "time_utils.h"
37 #include "version_component.h"
38 
39 namespace OHOS {
40 namespace UpdateEngine {
41 class FirmwareUpdateHelper {
42 public:
43     static bool IsBatteryEnough(int32_t batteryLimit);
44     static bool IsUpgradePackagesReady(const std::vector<FirmwareComponent> &componentList);
45 
46     static void ClearFirmwareInfo();
47     static void BuildCurrentVersionInfo(CurrentVersionInfo &currentVersionInfo);
48     static void BuildNewVersionInfo(const std::vector<FirmwareComponent> &components,
49         std::vector<VersionComponent> &versionComponents);
50     static bool IsUpgradeFailed(UpgradeStatus status);
51     static std::string BuildTaskId(const std::vector<FirmwareComponent> &componentList);
52     static InstallType GetInstallType();
53 
54 private:
55     static VersionComponent BuildHotaVersionComponent(std::vector<FirmwareComponent> &hotaComponents);
56 };
57 } // namespace UpdateEngine
58 } // namespace OHOS
59 #endif // FIRMWARE_UPDATE_HELPER_H