• 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 "ans_log_wrapper.h"
17 #include "event_report.h"
18 
19 namespace OHOS {
20 namespace Notification {
21 namespace {
22 // event params
23 const std::string EVENT_PARAM_USER_ID = "USER_ID";
24 const std::string EVENT_PARAM_BUNDLE_NAME = "BUNDLE_NAME";
25 const std::string EVENT_PARAM_ERROR_CODE = "ERROR_CODE";
26 const std::string EVENT_PARAM_PID = "PID";
27 const std::string EVENT_PARAM_UID = "UID";
28 const std::string EVENT_PARAM_ENABLE = "ENABLE";
29 const std::string EVENT_PARAM_SLOT_TYPE = "SLOT_TYPE";
30 const std::string EVENT_PARAM_NOTIFICATION_ID = "NOTIFICATION_ID";
31 const std::string EVENT_PARAM_NOTIFICATION_LABEL = "NOTIFICATION_LABEL";
32 const std::string EVENT_PARAM_CONTENT_TYPE = "CONTENT_TYPE";
33 const std::string EVENT_PARAM_OPERATE_FLAG = "OPERATE_FLAG";
34 const std::string EVENT_MESSAGE_TYPE = "MESSAGE_TYPE";
35 const std::string EVENT_REASON = "REASON";
36 const std::string EVENT_PARAM_REASON = "REASON";
37 const std::string EVENT_PARAM_CLASS = "CLASS";
38 const std::string EVENT_PARAM_REMINDERFLAGS = "REMINDERFLAGS";
39 const std::string EVENT_PARAM_CONTROLFLAGS = "CONTROLFLAGS";
40 } // namespace
41 
SendHiSysEvent(const std::string & eventName,const EventInfo & eventInfo)42 void EventReport::SendHiSysEvent(const std::string &eventName, const EventInfo &eventInfo)
43 {
44 #ifndef HAS_HISYSEVENT_PART
45     ANS_LOGD("Hisysevent is disabled");
46 #else
47     auto iter = ansSysEventFuncMap_.find(eventName);
48     if (iter == ansSysEventFuncMap_.end()) {
49         return;
50     }
51 
52     iter->second(eventInfo);
53 #endif
54 }
55 
56 #ifdef HAS_HISYSEVENT_PART
57 std::unordered_map<std::string, void (*)(const EventInfo& eventInfo)> EventReport::ansSysEventFuncMap_ = {
__anona357841a0202() 58     {SUBSCRIBE_ERROR, [](const EventInfo& eventInfo) {
59         InnerSendSubscribeErrorEvent(eventInfo);
60     }},
__anona357841a0302() 61     {ENABLE_NOTIFICATION_ERROR, [](const EventInfo& eventInfo) {
62         InnerSendEnableNotificationErrorEvent(eventInfo);
63     }},
__anona357841a0402() 64     {ENABLE_NOTIFICATION_SLOT_ERROR, [](const EventInfo& eventInfo) {
65         InnerSendEnableNotificationSlotErrorEvent(eventInfo);
66     }},
__anona357841a0502() 67     {PUBLISH_ERROR, [](const EventInfo& eventInfo) {
68         InnerSendPublishErrorEvent(eventInfo);
69     }},
__anona357841a0602() 70     {EVENT_NOTIFICATION_ERROR, [](const EventInfo& eventInfo) {
71         InnerSendNotificationSystemErrorEvent(eventInfo);
72     }},
__anona357841a0702() 73     {FLOW_CONTROL_OCCUR, [](const EventInfo& eventInfo) {
74         InnerSendFlowControlOccurEvent(eventInfo);
75     }},
__anona357841a0802() 76     {SUBSCRIBE, [](const EventInfo& eventInfo) {
77         InnerSendSubscribeEvent(eventInfo);
78     }},
__anona357841a0902() 79     {UNSUBSCRIBE, [](const EventInfo& eventInfo) {
80         InnerSendUnSubscribeEvent(eventInfo);
81     }},
__anona357841a0a02() 82     {ENABLE_NOTIFICATION, [](const EventInfo& eventInfo) {
83         InnerSendEnableNotificationEvent(eventInfo);
84     }},
__anona357841a0b02() 85     {ENABLE_NOTIFICATION_SLOT, [](const EventInfo& eventInfo) {
86         InnerSendEnableNotificationSlotEvent(eventInfo);
87     }},
__anona357841a0c02() 88     {PUBLISH, [](const EventInfo& eventInfo) {
89         InnerSendPublishEvent(eventInfo);
90     }},
__anona357841a0d02() 91     {CANCEL, [](const EventInfo& eventInfo) {
92         InnerSendCancelEvent(eventInfo);
93     }},
__anona357841a0e02() 94     {REMOVE, [](const EventInfo& eventInfo) {
95         InnerSendRemoveEvent(eventInfo);
96     }},
__anona357841a0f02() 97     {STATIC_LIVE_VIEW_UPLOAD, [](const EventInfo& eventInfo) {
98         InnerSendLiveviewUploadEvent(eventInfo);
99     }},
100 };
101 
InnerSendSubscribeErrorEvent(const EventInfo & eventInfo)102 void EventReport::InnerSendSubscribeErrorEvent(const EventInfo &eventInfo)
103 {
104     InnerEventWrite(
105         SUBSCRIBE_ERROR,
106         HiviewDFX::HiSysEvent::EventType::FAULT,
107         EVENT_PARAM_PID, eventInfo.pid,
108         EVENT_PARAM_UID, eventInfo.uid,
109         EVENT_PARAM_USER_ID, eventInfo.userId,
110         EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
111         EVENT_PARAM_ERROR_CODE, eventInfo.errCode);
112 }
113 
InnerSendEnableNotificationErrorEvent(const EventInfo & eventInfo)114 void EventReport::InnerSendEnableNotificationErrorEvent(const EventInfo &eventInfo)
115 {
116     InnerEventWrite(
117         ENABLE_NOTIFICATION_ERROR,
118         HiviewDFX::HiSysEvent::EventType::FAULT,
119         EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
120         EVENT_PARAM_UID, eventInfo.uid,
121         EVENT_PARAM_ENABLE, eventInfo.enable,
122         EVENT_PARAM_ERROR_CODE, eventInfo.errCode);
123 }
124 
InnerSendEnableNotificationSlotErrorEvent(const EventInfo & eventInfo)125 void EventReport::InnerSendEnableNotificationSlotErrorEvent(const EventInfo &eventInfo)
126 {
127     InnerEventWrite(
128         ENABLE_NOTIFICATION_SLOT_ERROR,
129         HiviewDFX::HiSysEvent::EventType::FAULT,
130         EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
131         EVENT_PARAM_UID, eventInfo.uid,
132         EVENT_PARAM_SLOT_TYPE, eventInfo.slotType,
133         EVENT_PARAM_ENABLE, eventInfo.enable,
134         EVENT_PARAM_ERROR_CODE, eventInfo.errCode);
135 }
136 
InnerSendPublishErrorEvent(const EventInfo & eventInfo)137 void EventReport::InnerSendPublishErrorEvent(const EventInfo &eventInfo)
138 {
139     InnerEventWrite(
140         PUBLISH_ERROR,
141         HiviewDFX::HiSysEvent::EventType::STATISTIC,
142         EVENT_PARAM_NOTIFICATION_ID, eventInfo.notificationId,
143         EVENT_PARAM_CONTENT_TYPE, eventInfo.contentType,
144         EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
145         EVENT_PARAM_USER_ID, eventInfo.userId,
146         EVENT_PARAM_ERROR_CODE, eventInfo.errCode);
147 }
148 
InnerSendFlowControlOccurEvent(const EventInfo & eventInfo)149 void EventReport::InnerSendFlowControlOccurEvent(const EventInfo &eventInfo)
150 {
151     InnerEventWrite(
152         FLOW_CONTROL_OCCUR,
153         HiviewDFX::HiSysEvent::EventType::FAULT,
154         EVENT_PARAM_NOTIFICATION_ID, eventInfo.notificationId,
155         EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
156         EVENT_PARAM_UID, eventInfo.uid);
157 }
158 
InnerSendNotificationSystemErrorEvent(const EventInfo & eventInfo)159 void EventReport::InnerSendNotificationSystemErrorEvent(const EventInfo &eventInfo)
160 {
161     InnerEventWrite(
162         EVENT_NOTIFICATION_ERROR,
163         HiviewDFX::HiSysEvent::EventType::FAULT,
164         EVENT_MESSAGE_TYPE, eventInfo.messageType,
165         EVENT_PARAM_ERROR_CODE, eventInfo.errCode,
166         EVENT_REASON, eventInfo.reason);
167 }
168 
InnerSendSubscribeEvent(const EventInfo & eventInfo)169 void EventReport::InnerSendSubscribeEvent(const EventInfo &eventInfo)
170 {
171     InnerEventWrite(
172         SUBSCRIBE,
173         HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
174         EVENT_PARAM_PID, eventInfo.pid,
175         EVENT_PARAM_UID, eventInfo.uid,
176         EVENT_PARAM_USER_ID, eventInfo.userId,
177         EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName);
178 }
179 
InnerSendUnSubscribeEvent(const EventInfo & eventInfo)180 void EventReport::InnerSendUnSubscribeEvent(const EventInfo &eventInfo)
181 {
182     InnerEventWrite(
183         UNSUBSCRIBE,
184         HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
185         EVENT_PARAM_PID, eventInfo.pid,
186         EVENT_PARAM_UID, eventInfo.uid,
187         EVENT_PARAM_USER_ID, eventInfo.userId,
188         EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName);
189 }
190 
InnerSendEnableNotificationEvent(const EventInfo & eventInfo)191 void EventReport::InnerSendEnableNotificationEvent(const EventInfo &eventInfo)
192 {
193     InnerEventWrite(
194         ENABLE_NOTIFICATION,
195         HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
196         EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
197         EVENT_PARAM_UID, eventInfo.uid,
198         EVENT_PARAM_ENABLE, eventInfo.enable);
199 }
200 
InnerSendEnableNotificationSlotEvent(const EventInfo & eventInfo)201 void EventReport::InnerSendEnableNotificationSlotEvent(const EventInfo &eventInfo)
202 {
203     InnerEventWrite(
204         ENABLE_NOTIFICATION_SLOT,
205         HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
206         EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
207         EVENT_PARAM_UID, eventInfo.uid,
208         EVENT_PARAM_SLOT_TYPE, eventInfo.slotType,
209         EVENT_PARAM_ENABLE, eventInfo.enable);
210 }
211 
InnerSendLiveviewUploadEvent(const EventInfo & eventInfo)212 void EventReport::InnerSendLiveviewUploadEvent(const EventInfo &eventInfo)
213 {
214     InnerEventWrite(
215         STATIC_LIVE_VIEW_UPLOAD,
216         HiviewDFX::HiSysEvent::EventType::STATISTIC,
217         EVENT_PARAM_NOTIFICATION_ID, eventInfo.notificationId,
218         EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
219         EVENT_PARAM_CONTENT_TYPE, eventInfo.contentType,
220         EVENT_PARAM_OPERATE_FLAG, eventInfo.operateFlag);
221 }
222 
InnerSendPublishEvent(const EventInfo & eventInfo)223 void EventReport::InnerSendPublishEvent(const EventInfo &eventInfo)
224 {
225     InnerEventWrite(
226         PUBLISH,
227         HiviewDFX::HiSysEvent::EventType::STATISTIC,
228         EVENT_PARAM_NOTIFICATION_ID, eventInfo.notificationId,
229         EVENT_PARAM_CONTENT_TYPE, eventInfo.contentType,
230         EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
231         EVENT_PARAM_USER_ID, eventInfo.userId,
232         EVENT_PARAM_SLOT_TYPE, eventInfo.slotType,
233         EVENT_PARAM_CLASS, eventInfo.classification,
234         EVENT_PARAM_CONTROLFLAGS, eventInfo.notificationControlFlags,
235         EVENT_PARAM_REMINDERFLAGS, eventInfo.reminderFlags);
236 }
237 
InnerSendCancelEvent(const EventInfo & eventInfo)238 void EventReport::InnerSendCancelEvent(const EventInfo &eventInfo)
239 {
240     InnerEventWrite(
241         CANCEL,
242         HiviewDFX::HiSysEvent::EventType::STATISTIC,
243         EVENT_PARAM_NOTIFICATION_ID, eventInfo.notificationId,
244         EVENT_PARAM_NOTIFICATION_LABEL, eventInfo.notificationLabel,
245         EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
246         EVENT_PARAM_UID, eventInfo.uid);
247 }
248 
InnerSendRemoveEvent(const EventInfo & eventInfo)249 void EventReport::InnerSendRemoveEvent(const EventInfo &eventInfo)
250 {
251     InnerEventWrite(
252         REMOVE,
253         HiviewDFX::HiSysEvent::EventType::STATISTIC,
254         EVENT_PARAM_NOTIFICATION_ID, eventInfo.notificationId,
255         EVENT_PARAM_NOTIFICATION_LABEL, eventInfo.notificationLabel,
256         EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
257         EVENT_PARAM_UID, eventInfo.uid);
258 }
259 
260 template<typename... Types>
InnerEventWrite(const std::string & eventName,HiviewDFX::HiSysEvent::EventType type,Types...keyValues)261 void EventReport::InnerEventWrite(const std::string &eventName,
262     HiviewDFX::HiSysEvent::EventType type, Types... keyValues)
263 {
264     HiSysEventWrite(
265         HiviewDFX::HiSysEvent::Domain::NOTIFICATION,
266         eventName,
267         static_cast<HiviewDFX::HiSysEvent::EventType>(type),
268         keyValues...);
269 }
270 #endif
271 } // namespace Notification
272 } // namespace OHOS