• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 #include "update_service_cache.h"
17 
18 #include "update_define.h"
19 #include "update_helper.h"
20 #include "update_log.h"
21 
22 namespace OHOS {
23 namespace UpdateEngine {
24 UpgradeInfo UpdateServiceCache::upgradeInfo_{};
25 uint64_t UpdateServiceCache::checkInterval_ = 0;
26 uint64_t UpdateServiceCache::downloadInterval_ = 0;
27 UpgradeInterval UpdateServiceCache::upgradeInterval_{};
28 
29 UpgradeInfo UpdateServiceCache::paramUpgradeInfo_{};
30 uint64_t UpdateServiceCache::paramCheckInterval_ = 0;
31 uint64_t UpdateServiceCache::paramDownloadInterval_ = 0;
32 UpgradeInterval UpdateServiceCache::paramUpgradeInterval_{};
33 
IsTypelegal(BusinessSubType businessSubType)34 bool UpdateServiceCache::IsTypelegal(BusinessSubType businessSubType)
35 {
36     bool isLegal = businessSubType == BusinessSubType::FIRMWARE || businessSubType == BusinessSubType::PARAM;
37     if (!isLegal) {
38         ENGINE_LOGI("IsTypelegal type %{public}d", CAST_INT(businessSubType));
39     }
40     return isLegal;
41 }
42 
IsParamType(BusinessSubType businessSubType)43 bool UpdateServiceCache::IsParamType(BusinessSubType businessSubType)
44 {
45     return businessSubType == BusinessSubType::PARAM;
46 }
47 
GetUpgradeInfo(BusinessSubType businessSubType)48 UpgradeInfo UpdateServiceCache::GetUpgradeInfo(BusinessSubType businessSubType)
49 {
50     if (!IsTypelegal(businessSubType)) {
51         UpgradeInfo upgradeInfo;
52         return upgradeInfo;
53     }
54 
55     return IsParamType(businessSubType) ? paramUpgradeInfo_ : upgradeInfo_;
56 }
57 
SetUpgradeInfo(const UpgradeInfo & upgradeInfo)58 void UpdateServiceCache::SetUpgradeInfo(const UpgradeInfo &upgradeInfo)
59 {
60     if (!IsTypelegal(upgradeInfo.businessType.subType)) {
61         return;
62     }
63 
64     if (IsParamType(upgradeInfo.businessType.subType)) {
65         paramUpgradeInfo_ = upgradeInfo;
66     } else {
67         upgradeInfo_ = upgradeInfo;
68     }
69 }
70 
GetCheckInterval(BusinessSubType businessSubType)71 uint64_t UpdateServiceCache::GetCheckInterval(BusinessSubType businessSubType)
72 {
73     if (!IsTypelegal(businessSubType)) {
74         return 0;
75     }
76 
77     return IsParamType(businessSubType) ? paramCheckInterval_ : checkInterval_;
78 }
79 
SetCheckInterval(BusinessSubType businessSubType,uint64_t interval)80 void UpdateServiceCache::SetCheckInterval(BusinessSubType businessSubType, uint64_t interval)
81 {
82     if (!IsTypelegal(businessSubType)) {
83         return;
84     }
85 
86     if (IsParamType(businessSubType)) {
87         paramCheckInterval_ = interval;
88     } else {
89         checkInterval_ = interval;
90     }
91 }
92 
GetDownloadInterval(BusinessSubType businessSubType)93 uint64_t UpdateServiceCache::GetDownloadInterval(BusinessSubType businessSubType)
94 {
95     if (!IsTypelegal(businessSubType)) {
96         return 0;
97     }
98 
99     return IsParamType(businessSubType) ? paramDownloadInterval_ : downloadInterval_;
100 }
101 
SetDownloadInterval(BusinessSubType businessSubType,uint64_t interval)102 void UpdateServiceCache::SetDownloadInterval(BusinessSubType businessSubType, uint64_t interval)
103 {
104     if (!IsTypelegal(businessSubType)) {
105         return;
106     }
107 
108     if (IsParamType(businessSubType)) {
109         paramDownloadInterval_ = interval;
110     } else {
111         downloadInterval_ = interval;
112     }
113 }
114 
GetUpgradeInterval(BusinessSubType businessSubType)115 UpgradeInterval UpdateServiceCache::GetUpgradeInterval(BusinessSubType businessSubType)
116 {
117     if (!IsTypelegal(businessSubType)) {
118         UpgradeInterval upgradeInterval;
119         return upgradeInterval;
120     }
121 
122     return IsParamType(businessSubType) ? paramUpgradeInterval_ : upgradeInterval_;
123 }
124 
SetUpgradeStartTime(BusinessSubType businessSubType,uint64_t time)125 void UpdateServiceCache::SetUpgradeStartTime(BusinessSubType businessSubType, uint64_t time)
126 {
127     if (!IsTypelegal(businessSubType)) {
128         return;
129     }
130 
131     if (IsParamType(businessSubType)) {
132         paramUpgradeInterval_.timeStart = time;
133     } else {
134         upgradeInterval_.timeStart = time;
135     }
136 }
137 
SetUpgradeEndTime(BusinessSubType businessSubType,uint64_t time)138 void UpdateServiceCache::SetUpgradeEndTime(BusinessSubType businessSubType, uint64_t time)
139 {
140     if (!IsTypelegal(businessSubType)) {
141         return;
142     }
143 
144     if (IsParamType(businessSubType)) {
145         paramUpgradeInterval_.timeEnd = time;
146     } else {
147         upgradeInterval_.timeEnd = time;
148     }
149 }
150 } // namespace UpdateEngine
151 } // namespace OHOS
152