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 namespace OHOS {
25 namespace EDM {
26 enum class UpdatePolicyType {
27     DEFAULT = 0,
28     PROHIBIT,
29     UPDATE_TO_SPECIFIC_VERSION,
30     WINDOWS,
31     POSTPONE
32 };
33 
34 enum class PackageType {
35     UNKNOWN = 0,
36     FIRMWARE = 1
37 };
38 
39 enum class UpgradeStatus {
40     NO_UPGRADE_PACKAGE = -4,
41     UPGRADE_WAITING = -3,
42     UPGRADING = -2,
43     UPGRADE_FAILURE = -1,
44     UPGRADE_SUCCESS = 0
45 };
46 
47 struct UpdateTime {
48     int64_t latestUpdateTime = 0;
49     int64_t delayUpdateTime = 0;
50     int64_t installWindowStart = 0;
51     int64_t installWindowEnd = 0;
52 };
53 
54 struct UpdatePolicy {
55     UpdatePolicyType type = UpdatePolicyType::DEFAULT;
56     std::string version;
57     UpdateTime installTime;
58 };
59 
60 struct Package {
61     std::string path;
62     PackageType type = PackageType::UNKNOWN;
63     int32_t fd = -1;
64 };
65 
66 struct NotifyDescription {
67     std::string installTips;
68     std::string installTipsDetail;
69 };
70 
71 struct PackageDescription {
72     NotifyDescription notify;
73 };
74 
75 struct UpgradePackageInfo {
76     std::string version;
77     std::vector<Package> packages;
78     PackageDescription description;
79 };
80 
81 struct UpgradeResult {
82     std::string version;
83     UpgradeStatus status = UpgradeStatus::UPGRADE_SUCCESS;
84     int32_t errorCode = 0;
85     std::string errorMessage;
86 };
87 
88 class UpdatePolicyUtils {
89 public:
90     static bool ProcessUpdatePolicyType(int32_t type, UpdatePolicyType &updatePolicyType);
91     static void ProcessPackageType(int32_t type, PackageType &packageType);
92     static void ProcessUpgradeStatus(int32_t status, UpgradeStatus &upgradeStatus);
93     static void WriteUpdatePolicy(MessageParcel &data, const UpdatePolicy &updatePolicy);
94     static void ReadUpdatePolicy(MessageParcel &data, UpdatePolicy &updatePolicy);
95     static void WriteUpgradePackageInfo(MessageParcel &data, const UpgradePackageInfo &packageInfo);
96     static void ReadUpgradePackageInfo(MessageParcel &data, UpgradePackageInfo &packageInfo);
97     static void WriteUpgradeResult(MessageParcel &data, const UpgradeResult &result);
98     static void ReadUpgradeResult(MessageParcel &data, UpgradeResult &result);
99     static void ClosePackagesFileHandle(std::vector<Package> &packages);
100 };
101 } // namespace EDM
102 } // namespace OHOS
103 
104 #endif // INTERFACES_INNER_API_KITS_SYSTEM_MANAGER_INCLUDE_UPDATE_POLICY_UTILS_H
105