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 "anonymous_utils.h" 24 #include "constant.h" 25 #include "firmware_component.h" 26 #include "firmware_log.h" 27 #include "update_define.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 STREAM_INSTALLLER, 67 UPDATER 68 }; 69 70 struct Duration { 71 int32_t duration = -1; // 搜包周期 单位:小时 72 }; 73 74 struct VersionPackageRule { 75 public: 76 std::string versionNumber; 77 std::string displayVersionNumber; 78 std::string versionPackageType; 79 ToCheckJsonVersionPackageRule80 nlohmann::ordered_json ToCheckJson() 81 { 82 nlohmann::ordered_json json = nlohmann::ordered_json::object(); 83 json["versionPackageType"] = versionPackageType; 84 json["versionNumber"] = versionNumber; 85 return json; 86 } 87 }; 88 89 enum VersionIndex { 90 BASE_INDEX = 0, 91 CUST_INDEX, 92 PRELOAD_INDEX 93 }; 94 95 enum StorageType { 96 COMMERCIAL = 1, 97 BETA = 2 98 }; 99 100 struct UpdatePackage { 101 std::string versionId; 102 int32_t packageIndex = 0; 103 PackageType versionPackageType = PackageType::DYNAMIC; 104 ToJsonUpdatePackage105 nlohmann::ordered_json ToJson() 106 { 107 nlohmann::ordered_json json = nlohmann::ordered_json::object(); 108 json["versionId"] = versionId; 109 json["packageIndex"] = packageIndex; 110 json["versionPackageType"] = CAST_INT(versionPackageType); 111 return json; 112 } 113 }; 114 115 struct TargetBlComponent { 116 std::string versionNumber; 117 std::string displayVersionNumber; 118 PackageType versionPackageType = PackageType::DYNAMIC; 119 }; 120 121 struct BlVersionCheckResult { 122 std::string status; 123 std::string pollingPeriod; 124 std::string blVersionInfo; 125 int32_t blVersionType = 0; 126 std::string descriptPackageId; 127 std::vector<UpdatePackage> updatePackages; 128 std::vector<TargetBlComponent> targetBlComponents; 129 }; 130 131 struct Version { 132 std::string url; 133 std::string reserveUrl; 134 int32_t storageType = 0; 135 std::string versionId; 136 std::string versionNumber; 137 }; 138 139 struct BlCheckResponse { 140 std::string status; 141 std::vector<BlVersionCheckResult> blVersionCheckResults; 142 std::vector<Version> versionList; 143 }; 144 145 struct CheckAndAuthInfo { 146 std::string responseStatus; 147 }; 148 149 enum class CombinationType { 150 INVALLID_TYPE = 0, 151 HOTA = 1 152 }; 153 154 enum class DownloadMode { 155 MANUAL = 0, 156 AUTO 157 }; 158 159 enum class UpgradeMode { 160 MANUAL = 0, 161 NIGHT 162 }; 163 164 enum class RequestType { 165 CHECK = 0, 166 AUTH 167 }; 168 169 enum class DownloadEndReason { 170 INIT = 0, 171 SUCCESS = 1, 172 DOWNLOADING = 2, 173 FAIL = 3, 174 VERIFY_FAIL = 4, 175 IO_EXCEPTION = 5, 176 REDIRECT = 6, 177 SERVER_TIMEOUT = 7, 178 PAUSE = 8, 179 CANCEL = 9, 180 NO_ENOUGH_MEMORY = 10, 181 NET_NOT_AVAILIABLE, 182 DOWNLAOD_INFO_EMPTY, 183 CURL_ERROR, 184 SYSTEM_BUSY, 185 INIT_PACKAGE_FAIL, 186 NET_CHANGE, 187 }; 188 } // namespace UpdateEngine 189 } // namespace OHOS 190 #endif // FIRMWARE_COMMON_H 191