• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 UPDATE_HELPER_H
17 #define UPDATE_HELPER_H
18 
19 #include <cstdlib>
20 #include <cstdio>
21 #include <cstring>
22 #include <iostream>
23 #include <ipc_types.h>
24 #include <list>
25 #include <string>
26 #include <string_ex.h>
27 #include "parcel.h"
28 #include "message_parcel.h"
29 #include "hilog/log.h"
30 #include "system_ability_definition.h"
31 
32 namespace OHOS {
33 namespace UpdateEngine {
34 const int CALL_RESULT_OFFSET = 2000;
35 
36 #define COUNT_OF(array) (sizeof(array) / sizeof((array)[0]))
37 
38 #define CAST_INT(enumClass) (static_cast<int32_t>(enumClass))
39 
40 enum class CallResult {
41     SUCCESS = 0,
42     FAIL = 100,
43     UN_SUPPORT = 101,
44     DEV_UPG_INFO_ERR = 102,
45     FORBIDDEN = 103,
46     IPC_ERR = 104,
47     APP_NOT_GRANTED = 200,
48     PARAM_ERR = 401,
49     TIME_OUT = 402,
50     DB_ERROR = 501,
51     IO_ERROR = 502,
52     NET_ERROR = 503
53 };
54 
55 constexpr int32_t INT_CALL_SUCCESS = CAST_INT(CallResult::SUCCESS);
56 constexpr int32_t INT_CALL_FAIL = CAST_INT(CallResult::FAIL);
57 constexpr int32_t INT_UN_SUPPORT = CAST_INT(CallResult::UN_SUPPORT);
58 constexpr int32_t INT_FORBIDDEN = CAST_INT(CallResult::FORBIDDEN);
59 constexpr int32_t INT_CALL_IPC_ERR = CAST_INT(CallResult::IPC_ERR);
60 constexpr int32_t INT_APP_NOT_GRANTED = CAST_INT(CallResult::APP_NOT_GRANTED);
61 constexpr int32_t INT_PARAM_ERR = CAST_INT(CallResult::PARAM_ERR);
62 
63 // 搜索状态
64 enum SearchStatus {
65     NET_ERROR = -2,
66     SYSTEM_ERROR,
67     HAS_NEW_VERSION,
68     NO_NEW_VERSION,
69     SERVER_BUSY,
70     CHECK_EXECUTE_ERR,
71 };
72 
73 enum UpgradeStatus {
74     UPDATE_STATE_INIT = 0,
75     UPDATE_STATE_CHECK_VERSION_ON = 10,
76     UPDATE_STATE_CHECK_VERSION_FAIL,
77     UPDATE_STATE_CHECK_VERSION_SUCCESS,
78     UPDATE_STATE_DOWNLOAD_ON = 20,
79     UPDATE_STATE_DOWNLOAD_PAUSE,
80     UPDATE_STATE_DOWNLOAD_CANCEL,
81     UPDATE_STATE_DOWNLOAD_FAIL,
82     UPDATE_STATE_DOWNLOAD_SUCCESS,
83     UPDATE_STATE_VERIFY_ON = 30,
84     UPDATE_STATE_VERIFY_FAIL,
85     UPDATE_STATE_VERIFY_SUCCESS,
86     UPDATE_STATE_PACKAGE_TRANS_ON = 70,
87     UPDATE_STATE_PACKAGE_TRANS_FAIL,
88     UPDATE_STATE_PACKAGE_TRANS_SUCCESS,
89     UPDATE_STATE_INSTALL_ON = 80,
90     UPDATE_STATE_INSTALL_FAIL,
91     UPDATE_STATE_INSTALL_SUCCESS,
92     UPDATE_STATE_UPDATE_ON = 90,
93     UPDATE_STATE_UPDATE_FAIL,
94     UPDATE_STATE_UPDATE_SUCCESS
95 };
96 
97 enum PackageType {
98     PACKAGE_TYPE_DYNAMIC = 0,
99     PACKAGE_TYPE_NORMAL = 1,
100     PACKAGE_TYPE_BASE = 2,
101     PACKAGE_TYPE_CUST = 3,
102     PACKAGE_TYPE_PRELOAD = 4,
103     PACKAGE_TYPE_COTA = 5,
104     PACKAGE_TYPE_VERSION = 6,
105     PACKAGE_TYPE_PATCH = 7
106 };
107 
108 enum class ComponentType {
109     INVALID = 0,
110     OTA = 1,
111     PATCH = 2,
112     COTA = 4,
113     PARAM = 8
114 };
115 
116 enum class EffectiveMode {
117     COLD = 1,
118     LIVE = 2,
119     LIVE_AND_COLD = 3
120 };
121 
122 enum class NetType {
123     CELLULAR = 1,
124     METERED_WIFI = 2,
125     NOT_METERED_WIFI = 4,
126     WIFI = METERED_WIFI | NOT_METERED_WIFI,
127     CELLULAR_AND_WIFI = CELLULAR | WIFI
128 };
129 
130 enum class Order {
131     DOWNLOAD = 1,
132     INSTALL = 2,
133     DOWNLOAD_AND_INSTALL = DOWNLOAD | INSTALL,
134     APPLY = 4,
135     INSTALL_AND_APPLY = INSTALL | APPLY
136 };
137 
138 enum class EventClassify {
139     TASK = 0x01000000,
140 };
141 
142 enum class BusinessSubType {
143     FIRMWARE = 1
144 };
145 
146 enum class DescriptionType {
147     CONTENT = 0,
148     URI = 1
149 };
150 
151 enum class DescriptionFormat {
152     STANDARD = 0,
153     SIMPLIFIED = 1
154 };
155 
156 enum class EventId {
157     EVENT_TASK_BASE = 0x01000000,
158     EVENT_TASK_RECEIVE,
159     EVENT_TASK_CANCEL,
160     EVENT_DOWNLOAD_WAIT,
161     EVENT_DOWNLOAD_START,
162     EVENT_DOWNLOAD_UPDATE,
163     EVENT_DOWNLOAD_PAUSE,
164     EVENT_DOWNLOAD_RESUME,
165     EVENT_DOWNLOAD_SUCCESS,
166     EVENT_DOWNLOAD_FAIL,
167     EVENT_UPGRADE_WAIT,
168     EVENT_UPGRADE_START,
169     EVENT_UPGRADE_UPDATE,
170     EVENT_APPLY_WAIT,
171     EVENT_APPLY_START,
172     EVENT_UPGRADE_SUCCESS,
173     EVENT_UPGRADE_FAIL
174 };
175 
176 class UpgradeAction {
177 public:
178     static constexpr const char *UPGRADE = "upgrade";
179     static constexpr const char *RECOVERY = "recovery";
180 };
181 
182 class BusinessVendor {
183 public:
184     static constexpr const char *PUBLIC = "public";
185 };
186 
187 struct BusinessType {
188     std::string vendor; // BusinessVendor
189     BusinessSubType subType = BusinessSubType::FIRMWARE;
190 
191     bool operator<(const BusinessType &businessType) const
192     {
193         if (vendor < businessType.vendor) return true;
194         if (vendor > businessType.vendor) return false;
195 
196         if (CAST_INT(subType) < CAST_INT(businessType.subType)) return true;
197         if (CAST_INT(subType) > CAST_INT(businessType.subType)) return false;
198 
199         return false;
200     }
201 };
202 
203 const std::string LOCAL_UPGRADE_INFO = "LocalUpgradeInfo";
204 struct UpgradeInfo {
205     std::string upgradeApp;
206     BusinessType businessType;
207     std::string upgradeDevId;
208     std::string controlDevId;
209 
210     UpgradeInfo &operator=(const UpgradeInfo &source)
211     {
212         if (&source != this) {
213             upgradeApp = source.upgradeApp;
214             businessType = source.businessType;
215             upgradeDevId = source.upgradeDevId;
216             controlDevId = source.controlDevId;
217         }
218         return *this;
219     }
220 
221     bool operator<(const UpgradeInfo &r) const
222     {
223         if (upgradeApp < r.upgradeApp) return true;
224         if (upgradeApp > r.upgradeApp) return false;
225 
226         if (businessType < r.businessType) return true;
227         if (r.businessType < businessType) return false;
228 
229         if (upgradeDevId < r.upgradeDevId) return true;
230         if (upgradeDevId > r.upgradeDevId) return false;
231 
232         if (controlDevId < r.controlDevId) return true;
233         if (controlDevId > r.controlDevId) return false;
234 
235         return false;
236     }
237 
238     std::string ToString() const;
239 
IsLocalUpgradeInfo240     bool IsLocal() const
241     {
242         return upgradeApp == LOCAL_UPGRADE_INFO;
243     }
244 };
245 
246 struct VersionDigestInfo {
247     std::string versionDigest;
248 };
249 
250 struct ErrorMessage {
251     int32_t errorCode = 0;
252     std::string errorMessage;
253 };
254 
255 struct DescriptionOptions {
256     DescriptionFormat format;
257     std::string language;
258 };
259 
260 struct DownloadOptions {
261     NetType allowNetwork = NetType::WIFI;
262     Order order = Order::DOWNLOAD;
263 };
264 
265 struct ResumeDownloadOptions {
266     NetType allowNetwork = NetType::WIFI;
267 };
268 
269 struct PauseDownloadOptions {
270     bool isAllowAutoResume = false;
271 };
272 
273 struct UpgradeOptions {
274     Order order = Order::INSTALL;
275 };
276 
277 struct ClearOptions {
278     UpgradeStatus status = UpgradeStatus::UPDATE_STATE_INIT;
279 };
280 
281 struct DescriptionInfo {
282     DescriptionType descriptionType = DescriptionType::CONTENT;
283     std::string content;
284 };
285 
286 struct ComponentDescription {
287     std::string componentId;
288     DescriptionInfo descriptionInfo;
289 
290     ComponentDescription &operator=(const ComponentDescription &source)
291     {
292         if (&source != this) {
293             componentId = source.componentId;
294             descriptionInfo = source.descriptionInfo;
295         }
296         return *this;
297     }
298 };
299 
300 struct CheckResult {
301     size_t size;
302     PackageType packageType;
303     std::string versionName;
304     std::string versionCode;
305     std::string verifyInfo;
306     std::string descriptPackageId;
307 };
308 
309 struct VersionInfo {
310     SearchStatus status;
311     std::string errMsg;
312     CheckResult result[2];
313     DescriptionInfo descriptInfo[2];
314 
315     VersionInfo &operator=(const VersionInfo &source)
316     {
317         if (&source != this) {
318             status = source.status;
319             errMsg = source.errMsg;
320             result[0] = source.result[0];
321             result[1] = source.result[1];
322             descriptInfo[0] = source.descriptInfo[0];
323             descriptInfo[1] = source.descriptInfo[1];
324         }
325         return *this;
326     }
327 };
328 
329 struct VersionComponent {
330     std::string componentId;
331     uint32_t componentType = static_cast<uint32_t>(ComponentType::INVALID);
332     std::string upgradeAction;
333     std::string displayVersion;
334     std::string innerVersion;
335     size_t size;
336     size_t effectiveMode;
337     DescriptionInfo descriptionInfo;
338 
339     VersionComponent &operator=(const VersionComponent &source)
340     {
341         if (&source != this) {
342             componentId = source.componentId;
343             componentType = source.componentType;
344             upgradeAction = source.upgradeAction;
345             displayVersion = source.displayVersion;
346             innerVersion = source.innerVersion;
347             size = source.size;
348             effectiveMode = source.effectiveMode;
349             descriptionInfo = source.descriptionInfo;
350         }
351         return *this;
352     }
353 };
354 
355 struct CurrentVersionInfo {
356     std::string osVersion;
357     std::string deviceName;
358     VersionComponent versionComponents[2];
359 
360     CurrentVersionInfo &operator=(const CurrentVersionInfo &source)
361     {
362         if (&source != this) {
363             osVersion = source.osVersion;
364             deviceName = source.deviceName;
365             versionComponents[0] = source.versionComponents[0];
366             versionComponents[1] = source.versionComponents[1];
367         }
368         return *this;
369     }
370 };
371 
372 struct NewVersionInfo {
373     VersionDigestInfo versionDigestInfo;
374     VersionComponent versionComponents[2];
375 
376     NewVersionInfo &operator=(const NewVersionInfo &source)
377     {
378         if (&source != this) {
379             versionDigestInfo = source.versionDigestInfo;
380             versionComponents[0] = source.versionComponents[0];
381             versionComponents[1] = source.versionComponents[1];
382         }
383         return *this;
384     }
385 };
386 
387 struct VersionDescriptionInfo {
388     ComponentDescription componentDescriptions[2];
389 
390     VersionDescriptionInfo &operator=(const VersionDescriptionInfo &source)
391     {
392         if (&source != this) {
393             componentDescriptions[0] = source.componentDescriptions[0];
394             componentDescriptions[1] = source.componentDescriptions[1];
395         }
396         return *this;
397     }
398 };
399 
400 struct CheckResultEx {
401     bool isExistNewVersion;
402     NewVersionInfo newVersionInfo;
403 
404     CheckResultEx &operator=(const CheckResultEx &source)
405     {
406         if (&source != this) {
407             isExistNewVersion = source.isExistNewVersion;
408             newVersionInfo = source.newVersionInfo;
409         }
410         return *this;
411     }
412 };
413 
414 struct TaskBody {
415     VersionDigestInfo versionDigestInfo;
416     UpgradeStatus status = UPDATE_STATE_INIT;
417     int32_t subStatus;
418     uint32_t progress;
419     int32_t installMode;
420     ErrorMessage errorMessages[2];
421     VersionComponent versionComponents[2];
422 
423     TaskBody &operator=(const TaskBody &source)
424     {
425         if (&source != this) {
426             versionDigestInfo = source.versionDigestInfo;
427             status = source.status;
428             subStatus = source.subStatus;
429             progress = source.progress;
430             installMode = source.installMode;
431             errorMessages[0] = source.errorMessages[0];
432             errorMessages[1] = source.errorMessages[1];
433             versionComponents[0] = source.versionComponents[0];
434             versionComponents[1] = source.versionComponents[1];
435         }
436         return *this;
437     }
438 };
439 
440 struct TaskInfo {
441     bool existTask;
442     TaskBody taskBody;
443 
444     TaskInfo &operator=(const TaskInfo &source)
445     {
446         if (&source != this) {
447             existTask = source.existTask;
448             taskBody = source.taskBody;
449         }
450         return *this;
451     }
452 };
453 
454 struct Progress {
455     uint32_t percent = 0;
456     UpgradeStatus status;
457     std::string endReason;
458 };
459 
460 struct ErrMsg {
461     int32_t errorCode = 0;
462     std::string errorMsg;
463 
464     ErrMsg &operator=(const ErrMsg &source)
465     {
466         if (&source != this) {
467             errorCode = source.errorCode;
468             errorMsg = source.errorMsg;
469         }
470         return *this;
471     }
472 };
473 
474 struct OtaStatus {
475     uint32_t progress;
476     UpgradeStatus status;
477     int32_t subStatus;
478     ErrMsg errMsg[1];
479 
480     OtaStatus &operator=(const OtaStatus &source)
481     {
482         if (&source != this) {
483             progress = source.progress;
484             status = source.status;
485             subStatus = source.subStatus;
486             errMsg[0] = source.errMsg[0];
487         }
488         return *this;
489     }
490 };
491 
492 struct UpgradeInterval {
493     uint64_t timeStart;
494     uint64_t timeEnd;
495 };
496 
497 enum InstallMode {
498     INSTALLMODE_NORMAL = 0,
499     INSTALLMODE_NIGHT,
500     INSTALLMODE_AUTO
501 };
502 
503 enum AutoUpgradeCondition {
504     AUTOUPGRADECONDITION_IDLE = 0,
505 };
506 
507 struct BusinessError {
508     std::string message;
509     CallResult errorNum = CallResult::SUCCESS;
510     ErrorMessage data[2];
511 
512     BusinessError &operator=(const BusinessError &source)
513     {
514         if (&source != this) {
515             message = source.message;
516             errorNum = source.errorNum;
517             data[0] = source.data[0];
518             data[1] = source.data[1];
519         }
520         return *this;
521     }
522 
BuildBusinessError523     BusinessError &Build(CallResult callResult, const std::string &msg)
524     {
525         errorNum = callResult;
526         message = msg;
527         return *this;
528     }
529 };
530 
531 struct UpgradePeriod {
532     uint32_t start;
533     uint32_t end;
534 };
535 
536 struct UpgradePolicy {
537     bool downloadStrategy;
538     bool autoUpgradeStrategy;
539     UpgradePeriod autoUpgradePeriods[2];
540 
541     UpgradePolicy &operator=(const UpgradePolicy &source)
542     {
543         if (&source != this) {
544             downloadStrategy = source.downloadStrategy;
545             autoUpgradeStrategy = source.autoUpgradeStrategy;
546             autoUpgradePeriods[0] = source.autoUpgradePeriods[0];
547             autoUpgradePeriods[1] = source.autoUpgradePeriods[1];
548         }
549         return *this;
550     }
551 };
552 
553 struct UpgradeFile {
554     ComponentType fileType;
555     std::string filePath;
556 };
557 
558 struct EventClassifyInfo {
559     EventClassify eventClassify;
560     std::string extraInfo;
561 
EventClassifyInfoEventClassifyInfo562     EventClassifyInfo() : eventClassify(EventClassify::TASK) {}
EventClassifyInfoEventClassifyInfo563     EventClassifyInfo(EventClassify classify) : eventClassify(classify) {}
EventClassifyInfoEventClassifyInfo564     EventClassifyInfo(EventClassify classify, const std::string &info) : eventClassify(classify), extraInfo(info) {}
565 };
566 
567 struct EventInfo {
568     EventId eventId;
569     TaskBody taskBody;
570 
EventInfoEventInfo571     EventInfo() {}
EventInfoEventInfo572     EventInfo(EventId id, TaskBody body) : eventId(id), taskBody(body) {}
573 
574     EventInfo &operator=(const EventInfo &source)
575     {
576         if (&source != this) {
577             eventId = source.eventId;
578             taskBody = source.taskBody;
579         }
580         return *this;
581     }
582 };
583 
584 using CheckNewVersionDone = std::function<void(const BusinessError &businessError, const CheckResultEx &checkResultEx)>;
585 using OnEvent = std::function<void(const EventInfo &eventInfo)>;
586 
587 // 回调函数
588 struct UpdateCallbackInfo {
589     CheckNewVersionDone checkNewVersionDone;
590     OnEvent onEvent;
591 
592     UpdateCallbackInfo &operator=(const UpdateCallbackInfo &source)
593     {
594         if (&source != this) {
595             checkNewVersionDone = source.checkNewVersionDone;
596             onEvent = source.onEvent;
597         }
598         return *this;
599     }
600 };
601 
602 #ifdef UPDATE_SERVICE
603 static constexpr OHOS::HiviewDFX::HiLogLabel UPDATE_LABEL = {LOG_CORE, 0XD002E00, "UPDATE_SA"};
604 #else
605 static constexpr OHOS::HiviewDFX::HiLogLabel UPDATE_LABEL = {LOG_CORE, 0XD002E00, "UPDATE_KITS"};
606 #endif
607 
608 enum class UpdateLogLevel {
609     UPDATE_DEBUG = 0,
610     UPDATE_INFO,
611     UPDATE_WARN,
612     UPDATE_ERROR,
613     UPDATE_FATAL
614 };
615 
616 template<typename T>
IsValidEnum(const std::list<T> & enumList,int32_t number)617 bool IsValidEnum(const std::list<T> &enumList, int32_t number)
618 {
619     for (auto i : enumList) {
620         if (number == static_cast<int32_t>(i)) {
621             return true;
622         }
623     }
624     return false;
625 }
626 
627 class UpdateHelper {
628 public:
629     static int32_t ReadUpgradeInfo(MessageParcel &reply, UpgradeInfo &info);
630     static int32_t WriteUpgradeInfo(MessageParcel &data, const UpgradeInfo &info);
631 
632     static int32_t ReadVersionDescriptionInfo(MessageParcel &reply,
633         VersionDescriptionInfo &newVersionDescriptionInfo);
634     static int32_t WriteVersionDescriptionInfo(MessageParcel &data,
635         const VersionDescriptionInfo &newVersionDescriptionInfo);
636 
637     static int32_t ReadBusinessError(MessageParcel &reply, BusinessError &businessError);
638     static int32_t WriteBusinessError(MessageParcel &data, const BusinessError &businessError);
639 
640     static int32_t ReadCheckResult(MessageParcel &reply, CheckResultEx &checkResultEx);
641     static int32_t WriteCheckResult(MessageParcel &data, const CheckResultEx &checkResultEx);
642 
643     static int32_t ReadNewVersionInfo(MessageParcel &reply, NewVersionInfo &newVersionInfo);
644     static int32_t WriteNewVersionInfo(MessageParcel &data, const NewVersionInfo &newVersionInfo);
645 
646     static int32_t ReadCurrentVersionInfo(MessageParcel &reply, CurrentVersionInfo &info);
647     static int32_t WriteCurrentVersionInfo(MessageParcel &data, const CurrentVersionInfo &info);
648 
649     static int32_t ReadTaskInfo(MessageParcel &reply, TaskInfo &info);
650     static int32_t WriteTaskInfo(MessageParcel &data, const TaskInfo &info);
651 
652     static int32_t ReadUpgradePolicy(MessageParcel &reply, UpgradePolicy &policy);
653     static int32_t WriteUpgradePolicy(MessageParcel &data, const UpgradePolicy &policy);
654 
655     static int32_t ReadEventInfo(MessageParcel &reply, EventInfo &eventInfo);
656     static int32_t WriteEventInfo(MessageParcel &data, const EventInfo &eventInfo);
657 
658     static int32_t ReadVersionDigestInfo(MessageParcel &reply, VersionDigestInfo &versionDigestInfo);
659     static int32_t WriteVersionDigestInfo(MessageParcel &data, const VersionDigestInfo &versionDigestInfo);
660 
661     static int32_t ReadDescriptionOptions(MessageParcel &reply, DescriptionOptions &descriptionOptions);
662     static int32_t WriteDescriptionOptions(MessageParcel &data, const DescriptionOptions &descriptionOptions);
663 
664     static int32_t ReadDownloadOptions(MessageParcel &reply, DownloadOptions &downloadOptions);
665     static int32_t WriteDownloadOptions(MessageParcel &data, const DownloadOptions &downloadOptions);
666 
667     static int32_t ReadPauseDownloadOptions(MessageParcel &reply, PauseDownloadOptions &pauseDownloadOptions);
668     static int32_t WritePauseDownloadOptions(MessageParcel &data, const PauseDownloadOptions &pauseDownloadOptions);
669 
670     static int32_t ReadResumeDownloadOptions(MessageParcel &reply, ResumeDownloadOptions &resumeDownloadOptions);
671     static int32_t WriteResumeDownloadOptions(MessageParcel &data, const ResumeDownloadOptions &resumeDownloadOptions);
672 
673     static int32_t ReadUpgradeOptions(MessageParcel &reply, UpgradeOptions &upgradeOptions);
674     static int32_t WriteUpgradeOptions(MessageParcel &data, const UpgradeOptions &upgradeOptions);
675 
676     static int32_t ReadClearOptions(MessageParcel &reply, ClearOptions &clearOptions);
677     static int32_t WriteClearOptions(MessageParcel &data, const ClearOptions &clearOptions);
678 
679     static std::vector<uint8_t> HexToDegist(const std::string &str);
680     static int32_t CompareVersion(const std::string &version1, const std::string &version2);
681     static std::vector<std::string> SplitString(const std::string &str, const std::string &delimiter);
682 
683     static bool IsErrorExist(const BusinessError &businessError);
684 
685     static std::string BuildEventDevId(const UpgradeInfo &info);
686     static std::string BuildEventVersionInfo(const VersionInfo &ver);
687 
688     static std::string Anonymization(const std::string &src);
689 
690     static bool JudgeLevel(const UpdateLogLevel& level);
691 
SetLogLevel(const UpdateLogLevel & level)692     static void SetLogLevel(const UpdateLogLevel& level)
693     {
694         level_ = level;
695     }
696 
GetLogLevel()697     static const UpdateLogLevel& GetLogLevel()
698     {
699         return level_;
700     }
701 
702     static std::string GetBriefFileName(const std::string &file);
703 
704 private:
705     static UpdateLogLevel level_;
706 };
707 
708 // 暂时记录两边日志
709 #define PRINT_LOG(LEVEL, Level, fmt, ...) \
710     if (UpdateHelper::JudgeLevel(UpdateLogLevel::LEVEL)) \
711         OHOS::HiviewDFX::HiLog::Level(UPDATE_LABEL, "[%{public}s(%{public}d)] " fmt, \
712         UpdateHelper::GetBriefFileName(std::string(__FILE__)).c_str(), __LINE__, ##__VA_ARGS__)
713 
714 #define ENGINE_LOGI(fmt, ...) PRINT_LOG(UPDATE_INFO, Info, fmt, ##__VA_ARGS__)
715 #define ENGINE_LOGE(fmt, ...) PRINT_LOG(UPDATE_ERROR, Error, fmt, ##__VA_ARGS__)
716 
717 #define ENGINE_CHECK(retCode, exper, ...) \
718     do { \
719         if (!(retCode)) {                     \
720             ENGINE_LOGE(__VA_ARGS__);         \
721             exper;                            \
722         } \
723     } while (0)
724 } // namespace UpdateEngine
725 } // namespace OHOS
726 #endif // UPDATE_HELPER_H
727