1 /* 2 * Copyright (c) 2024 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 INTERFACES_INNER_API_KITS_SYSTEM_MANAGER_INCLUDE_UPDATE_POLICY_UTILS_H 17 #define INTERFACES_INNER_API_KITS_SYSTEM_MANAGER_INCLUDE_UPDATE_POLICY_UTILS_H 18 19 #include <string> 20 #include <vector> 21 22 #include "message_parcel.h" 23 24 #include "edm_constants.h" 25 26 namespace OHOS { 27 namespace EDM { 28 enum class UpdatePolicyType { 29 DEFAULT = 0, 30 PROHIBIT, 31 UPDATE_TO_SPECIFIC_VERSION, 32 WINDOWS, 33 POSTPONE 34 }; 35 36 enum class PackageType { 37 UNKNOWN = 0, 38 FIRMWARE = 1 39 }; 40 41 enum class UpgradeStatus { 42 NO_UPGRADE_PACKAGE = -4, 43 UPGRADE_WAITING = -3, 44 UPGRADING = -2, 45 UPGRADE_FAILURE = -1, 46 UPGRADE_SUCCESS = 0 47 }; 48 49 enum class GetUpdateInfo { 50 UPDATE_RESULT = 0, 51 UPDATE_AUTH_DATA = 1 52 }; 53 54 enum class OtaPolicyType { 55 DEFAULT = -1, // 默认值,不处理 56 ENABLE_OTA = 0, // 允许OTA 57 DISABLE_OTA = 1 // 不允许OTA 58 }; 59 60 struct UpdateTime { 61 int64_t latestUpdateTime = 0; 62 int64_t delayUpdateTime = 0; 63 int64_t installWindowStart = 0; 64 int64_t installWindowEnd = 0; 65 }; 66 67 struct UpdatePolicy { 68 UpdatePolicyType type = UpdatePolicyType::DEFAULT; 69 std::string version; 70 UpdateTime installTime; 71 OtaPolicyType otaPolicyType = OtaPolicyType::DEFAULT; 72 }; 73 74 struct Package { 75 std::string path; 76 PackageType type = PackageType::UNKNOWN; 77 int32_t fd = -1; 78 }; 79 80 struct NotifyDescription { 81 std::string installTips; 82 std::string installTipsDetail; 83 }; 84 85 struct PackageDescription { 86 NotifyDescription notify; 87 }; 88 89 struct UpgradePackageInfo { 90 std::string version; 91 std::vector<Package> packages; 92 PackageDescription description; 93 char authInfo[EdmConstants::AUTH_INFO_MAX_SIZE] = {0}; 94 uint32_t authInfoSize = 0; 95 }; 96 97 struct UpgradeResult { 98 std::string version; 99 UpgradeStatus status = UpgradeStatus::UPGRADE_SUCCESS; 100 int32_t errorCode = 0; 101 std::string errorMessage; 102 }; 103 104 class UpdatePolicyUtils { 105 public: 106 static bool ProcessUpdatePolicyType(int32_t type, UpdatePolicyType &updatePolicyType); 107 static void ProcessPackageType(int32_t type, PackageType &packageType); 108 static void ProcessUpgradeStatus(int32_t status, UpgradeStatus &upgradeStatus); 109 static void ProcessOtaPolicyType(int32_t type, OtaPolicyType &otaPolicyType); 110 static void WriteUpdatePolicy(MessageParcel &data, const UpdatePolicy &updatePolicy); 111 static void ReadUpdatePolicy(MessageParcel &data, UpdatePolicy &updatePolicy); 112 static void WriteUpgradePackageInfo(MessageParcel &data, UpgradePackageInfo &packageInfo); 113 static void ReadUpgradePackageInfo(MessageParcel &data, UpgradePackageInfo &packageInfo); 114 static void WriteUpgradeResult(MessageParcel &data, const UpgradeResult &result); 115 static void ReadUpgradeResult(MessageParcel &data, UpgradeResult &result); 116 static void ClosePackagesFileHandle(std::vector<Package> &packages); 117 }; 118 } // namespace EDM 119 } // namespace OHOS 120 121 #endif // INTERFACES_INNER_API_KITS_SYSTEM_MANAGER_INCLUDE_UPDATE_POLICY_UTILS_H 122