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 #ifndef UPDATE_SYSTEM_EVENT_H
17 #define UPDATE_SYSTEM_EVENT_H
18 
19 #include <string>
20 
21 #include "hisysevent.h"
22 
23 namespace OHOS::UpdateEngine {
24 #define EVENT_WRITE(eventName, type, ...)  \
25     HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::UPDATE, eventName, type, ##__VA_ARGS__)
26 
27 #define SYS_EVENT_UPGRADE_INTERVAL(validCheck, versionInfo, type, interval)  \
28     if (!(validCheck)) {    \
29         EVENT_WRITE("UPGRADE_INTERVAL", OHOS::HiviewDFX::HiSysEvent::EventType::STATISTIC,    \
30             "VERSION_INFO", versionInfo, "TYPE", type, "INTERVAL", interval);    \
31     }
32 
33 #define SYS_EVENT_SYSTEM_UPGRADE_FAULT(validCheck, deviceId, versionInfo, reason, location)  \
34     if (!(validCheck)) {    \
35         EVENT_WRITE("SYSTEM_UPGRADE_FAULT", OHOS::HiviewDFX::HiSysEvent::EventType::FAULT,    \
36             "DEVICE_ID", deviceId, "VERSION_INFO", versionInfo, "FAILED_REASON", reason,    \
37             "LOCATION", location);    \
38     }
39 
40 #define SYS_EVENT_SYSTEM_UPGRADE(validCheck, result)  \
41     if (!(validCheck)) {    \
42         EVENT_WRITE("SYSTEM_UPGRADE", OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR,    \
43             "UPDATE_RESULT", result);    \
44     }
45 
46 #define SYS_EVENT_SYSTEM_RESET(validCheck, result)  \
47     if (!(validCheck)) {    \
48         EVENT_WRITE("SYSTEM_RESET", OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR,    \
49         "RESET_RESULT", result);    \
50     }
51 
52 #define SYS_EVENT_VERIFY_FAILED(validCheck, deviceId, description)  \
53     if (!(validCheck)) {    \
54         EVENT_WRITE("VERIFY_FAILED", OHOS::HiviewDFX::HiSysEvent::EventType::SECURITY,    \
55         "DEVICE_ID", deviceId, "DESCRIPTION", description);    \
56     }
57 
58 class UpdateSystemEvent {
59 public:
60     static constexpr const char *EMPTY = "";
61     static constexpr const char *UPGRADE_START = "upgrade start";
62     static constexpr const char *RESET_START = "reset start";
63     static constexpr const char *EVENT_FAILED_RESULT = "failed";
64     static constexpr const char *EVENT_SUCCESS_RESULT = "success";
65 
66     static constexpr const char *EVENT_UPGRADE_INTERVAL = "upgrade";
67     static constexpr const char *EVENT_CHECK_INTERVAL = "check";
68     static constexpr const char *EVENT_DOWNLOAD_INTERVAL = "download";
69 
70     static constexpr const char *EVENT_PERMISSION_VERIFY_FAILED = "permission verify failed";
71     static constexpr const char *EVENT_PKG_VERIFY_FAILED = "upgrade package verify failed";
72 };
73 } // namespace OHOS::UpdateEngine
74 #endif // UPDATE_SYSTEM_EVENT_H