• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_COMMON_H
17 #define FIRMWARE_COMMON_H
18 
19 #include <string>
20 
21 #include "nlohmann/json.hpp"
22 
23 #include "constant.h"
24 #include "encrypt_utils.h"
25 #include "firmware_component.h"
26 #include "firmware_log.h"
27 #include "update_helper.h"
28 
29 namespace OHOS {
30 namespace UpdateEngine {
31 enum class FirmwareStep {
32     INIT = 0,
33     CHECK_STEP,
34     DOWNLOAD_STEP,
35     AUTH_STEP,
36     INSTALL_STEP,
37     APPLY_STEP,
38     COMPLETE = 10
39 };
40 
41 enum class CheckStatus {
42     CHECK_SUCCESS = 0,
43     CHECK_FAIL,
44     FILE_LIST_REQUEST_SUCCESS,
45     FILE_LIST_REQUEST_FAIL,
46     CHANGELOG_REQUEST_SUCCESS,
47     CHANGELOG_REQUEST_FAIL
48 };
49 
50 enum class BlType {
51     HOTA_TYPE = 1,
52     COTA_TYPE = 2,
53     DYNAMIC_TYPE = 100
54 };
55 
56 enum class CheckResultStatus {
57     STATUS_SYSTEM_ERROR = -1,
58     STATUS_NEW_VERSION_AVAILABLE = 0,
59     STATUS_NEW_VERSION_NOT_AVAILABLE = 1,
60     STATUS_SERVER_IS_BUSY = 2
61 };
62 
63 enum class InstallType {
64     QUICK_FIX = 1,
65     SYS_INSTALLER,
66     UPDATER
67 };
68 
69 struct Duration {
70     int32_t duration = -1; // 搜包周期 单位:小时
71 };
72 
73 struct VersionPackageRule {
74 public:
75     std::string versionNumber;
76     std::string displayVersionNumber;
77     std::string versionPackageType;
78 
ToCheckJsonVersionPackageRule79     nlohmann::ordered_json ToCheckJson()
80     {
81         nlohmann::ordered_json json = nlohmann::ordered_json::object();
82         json["versionPackageType"] = versionPackageType;
83         json["versionNumber"] = versionNumber;
84         return json;
85     }
86 };
87 
88 enum VersionIndex {
89     BASE_INDEX = 0,
90     CUST_INDEX,
91     PRELOAD_INDEX
92 };
93 
94 enum StorageType {
95     COMMERCIAL = 1,
96     BETA = 2
97 };
98 
99 struct UpdatePackage {
100     std::string versionId;
101     int32_t packageIndex = 0;
102     PackageType versionPackageType = PackageType::DYNAMIC;
103 
ToJsonUpdatePackage104     nlohmann::ordered_json ToJson()
105     {
106         nlohmann::ordered_json json = nlohmann::ordered_json::object();
107         json["versionId"] = versionId;
108         json["packageIndex"] = packageIndex;
109         json["versionPackageType"] = CAST_INT(versionPackageType);
110         return json;
111     }
112 };
113 
114 struct TargetBlComponent {
115     std::string versionNumber;
116     std::string displayVersionNumber;
117     PackageType versionPackageType = PackageType::DYNAMIC;
118 };
119 
120 struct BlVersionCheckResult {
121     std::string status;
122     std::string pollingPeriod;
123     std::string blVersionInfo;
124     int32_t blVersionType = 0;
125     std::string descriptPackageId;
126     std::vector<UpdatePackage> updatePackages;
127     std::vector<TargetBlComponent> targetBlComponents;
128 };
129 
130 struct Version {
131     std::string url;
132     std::string reserveUrl;
133     int32_t storageType = 0;
134     std::string versionId;
135     std::string versionNumber;
136 };
137 
138 struct BlCheckResponse {
139     std::string status;
140     std::vector<BlVersionCheckResult> blVersionCheckResults;
141     std::vector<Version> versionList;
142 };
143 
144 struct CheckAndAuthInfo {
145     std::string responseStatus;
146 };
147 
148 enum class CombinationType {
149     INVALLID_TYPE = 0,
150     HOTA = 1
151 };
152 
153 enum class DownloadMode {
154     MANUAL = 0,
155     AUTO
156 };
157 
158 enum class UpgradeMode {
159     MANUAL = 0,
160     NIGHT
161 };
162 
163 enum class RequestType {
164     CHECK = 0,
165     AUTH
166 };
167 
168 enum class DownloadEndReason {
169     INIT = 0,
170     SUCCESS = 1,
171     DOWNLOADING = 2,
172     FAIL = 3,
173     VERIFY_FAIL = 4,
174     IO_EXCEPTION = 5,
175     REDIRECT = 6,
176     SERVER_TIMEOUT = 7,
177     PAUSE = 8,
178     CANCEL = 9,
179     NO_ENOUGH_MEMORY = 10,
180     NET_NOT_AVAILIABLE,
181     DOWNLAOD_INFO_EMPTY,
182     CURL_ERROR,
183     SYSTEM_BUSY,
184     INIT_PACKAGE_FAIL,
185     NET_CHANGE,
186 };
187 } // namespace UpdateEngine
188 } // namespace OHOS
189 #endif // FIRMWARE_COMMON_H
190