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 struct UpdateTime { 55 int64_t latestUpdateTime = 0; 56 int64_t delayUpdateTime = 0; 57 int64_t installWindowStart = 0; 58 int64_t installWindowEnd = 0; 59 }; 60 61 struct UpdatePolicy { 62 UpdatePolicyType type = UpdatePolicyType::DEFAULT; 63 std::string version; 64 UpdateTime installTime; 65 }; 66 67 struct Package { 68 std::string path; 69 PackageType type = PackageType::UNKNOWN; 70 int32_t fd = -1; 71 }; 72 73 struct NotifyDescription { 74 std::string installTips; 75 std::string installTipsDetail; 76 }; 77 78 struct PackageDescription { 79 NotifyDescription notify; 80 }; 81 82 struct UpgradePackageInfo { 83 std::string version; 84 std::vector<Package> packages; 85 PackageDescription description; 86 char authInfo[EdmConstants::AUTH_INFO_MAX_SIZE] = {0}; 87 uint32_t authInfoSize = 0; 88 }; 89 90 struct UpgradeResult { 91 std::string version; 92 UpgradeStatus status = UpgradeStatus::UPGRADE_SUCCESS; 93 int32_t errorCode = 0; 94 std::string errorMessage; 95 }; 96 97 class UpdatePolicyUtils { 98 public: 99 static bool ProcessUpdatePolicyType(int32_t type, UpdatePolicyType &updatePolicyType); 100 static void ProcessPackageType(int32_t type, PackageType &packageType); 101 static void ProcessUpgradeStatus(int32_t status, UpgradeStatus &upgradeStatus); 102 static void WriteUpdatePolicy(MessageParcel &data, const UpdatePolicy &updatePolicy); 103 static void ReadUpdatePolicy(MessageParcel &data, UpdatePolicy &updatePolicy); 104 static void WriteUpgradePackageInfo(MessageParcel &data, UpgradePackageInfo &packageInfo); 105 static void ReadUpgradePackageInfo(MessageParcel &data, UpgradePackageInfo &packageInfo); 106 static void WriteUpgradeResult(MessageParcel &data, const UpgradeResult &result); 107 static void ReadUpgradeResult(MessageParcel &data, UpgradeResult &result); 108 static void ClosePackagesFileHandle(std::vector<Package> &packages); 109 }; 110 } // namespace EDM 111 } // namespace OHOS 112 113 #endif // INTERFACES_INNER_API_KITS_SYSTEM_MANAGER_INCLUDE_UPDATE_POLICY_UTILS_H 114