• 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 } // namespace
34 
SendHiSysEvent(const std::string & eventName,const EventInfo & eventInfo)35 void EventReport::SendHiSysEvent(const std::string &eventName, const EventInfo &eventInfo)
36 {
37 #ifndef HAS_HISYSEVENT_PART
38     ANS_LOGD("Hisysevent is disabled");
39 #else
40     auto iter = ansSysEventFuncMap_.find(eventName);
41     if (iter == ansSysEventFuncMap_.end()) {
42         return;
43     }
44 
45     iter->second(eventInfo);
46 #endif
47 }
48 
49 #ifdef HAS_HISYSEVENT_PART
50 std::unordered_map<std::string, void (*)(const EventInfo& eventInfo)> EventReport::ansSysEventFuncMap_ = {
__anonaf74e69c0202() 51     {SUBSCRIBE_ERROR, [](const EventInfo& eventInfo) {
52         InnerSendSubscribeErrorEvent(eventInfo);
53     }},
__anonaf74e69c0302() 54     {ENABLE_NOTIFICATION_ERROR, [](const EventInfo& eventInfo) {
55         InnerSendEnableNotificationErrorEvent(eventInfo);
56     }},
__anonaf74e69c0402() 57     {ENABLE_NOTIFICATION_SLOT_ERROR, [](const EventInfo& eventInfo) {
58         InnerSendEnableNotificationSlotErrorEvent(eventInfo);
59     }},
__anonaf74e69c0502() 60     {PUBLISH_ERROR, [](const EventInfo& eventInfo) {
61         InnerSendPublishErrorEvent(eventInfo);
62     }},
__anonaf74e69c0602() 63     {FLOW_CONTROL_OCCUR, [](const EventInfo& eventInfo) {
64         InnerSendFlowControlOccurEvent(eventInfo);
65     }},
__anonaf74e69c0702() 66     {SUBSCRIBE, [](const EventInfo& eventInfo) {
67         InnerSendSubscribeEvent(eventInfo);
68     }},
__anonaf74e69c0802() 69     {UNSUBSCRIBE, [](const EventInfo& eventInfo) {
70         InnerSendUnSubscribeEvent(eventInfo);
71     }},
__anonaf74e69c0902() 72     {ENABLE_NOTIFICATION, [](const EventInfo& eventInfo) {
73         InnerSendEnableNotificationEvent(eventInfo);
74     }},
__anonaf74e69c0a02() 75     {ENABLE_NOTIFICATION_SLOT, [](const EventInfo& eventInfo) {
76         InnerSendEnableNotificationSlotEvent(eventInfo);
77     }},
__anonaf74e69c0b02() 78     {PUBLISH, [](const EventInfo& eventInfo) {
79         InnerSendPublishEvent(eventInfo);
80     }},
__anonaf74e69c0c02() 81     {CANCEL, [](const EventInfo& eventInfo) {
82         InnerSendCancelEvent(eventInfo);
83     }},
__anonaf74e69c0d02() 84     {REMOVE, [](const EventInfo& eventInfo) {
85         InnerSendRemoveEvent(eventInfo);
86     }},
87 };
88 
InnerSendSubscribeErrorEvent(const EventInfo & eventInfo)89 void EventReport::InnerSendSubscribeErrorEvent(const EventInfo &eventInfo)
90 {
91     InnerEventWrite(
92         SUBSCRIBE_ERROR,
93         HiviewDFX::HiSysEvent::EventType::FAULT,
94         EVENT_PARAM_PID, eventInfo.pid,
95         EVENT_PARAM_UID, eventInfo.uid,
96         EVENT_PARAM_USER_ID, eventInfo.userId,
97         EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
98         EVENT_PARAM_ERROR_CODE, eventInfo.errCode);
99 }
100 
InnerSendEnableNotificationErrorEvent(const EventInfo & eventInfo)101 void EventReport::InnerSendEnableNotificationErrorEvent(const EventInfo &eventInfo)
102 {
103     InnerEventWrite(
104         ENABLE_NOTIFICATION_ERROR,
105         HiviewDFX::HiSysEvent::EventType::FAULT,
106         EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
107         EVENT_PARAM_UID, eventInfo.uid,
108         EVENT_PARAM_ENABLE, eventInfo.enable,
109         EVENT_PARAM_ERROR_CODE, eventInfo.errCode);
110 }
111 
InnerSendEnableNotificationSlotErrorEvent(const EventInfo & eventInfo)112 void EventReport::InnerSendEnableNotificationSlotErrorEvent(const EventInfo &eventInfo)
113 {
114     InnerEventWrite(
115         ENABLE_NOTIFICATION_SLOT_ERROR,
116         HiviewDFX::HiSysEvent::EventType::FAULT,
117         EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
118         EVENT_PARAM_UID, eventInfo.uid,
119         EVENT_PARAM_SLOT_TYPE, eventInfo.slotType,
120         EVENT_PARAM_ENABLE, eventInfo.enable,
121         EVENT_PARAM_ERROR_CODE, eventInfo.errCode);
122 }
123 
InnerSendPublishErrorEvent(const EventInfo & eventInfo)124 void EventReport::InnerSendPublishErrorEvent(const EventInfo &eventInfo)
125 {
126     InnerEventWrite(
127         PUBLISH_ERROR,
128         HiviewDFX::HiSysEvent::EventType::FAULT,
129         EVENT_PARAM_NOTIFICATION_ID, eventInfo.notificationId,
130         EVENT_PARAM_CONTENT_TYPE, eventInfo.contentType,
131         EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
132         EVENT_PARAM_USER_ID, eventInfo.userId,
133         EVENT_PARAM_ERROR_CODE, eventInfo.errCode);
134 }
135 
InnerSendFlowControlOccurEvent(const EventInfo & eventInfo)136 void EventReport::InnerSendFlowControlOccurEvent(const EventInfo &eventInfo)
137 {
138     InnerEventWrite(
139         FLOW_CONTROL_OCCUR,
140         HiviewDFX::HiSysEvent::EventType::FAULT,
141         EVENT_PARAM_NOTIFICATION_ID, eventInfo.notificationId,
142         EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
143         EVENT_PARAM_UID, eventInfo.uid);
144 }
145 
InnerSendSubscribeEvent(const EventInfo & eventInfo)146 void EventReport::InnerSendSubscribeEvent(const EventInfo &eventInfo)
147 {
148     InnerEventWrite(
149         SUBSCRIBE,
150         HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
151         EVENT_PARAM_PID, eventInfo.pid,
152         EVENT_PARAM_UID, eventInfo.uid,
153         EVENT_PARAM_USER_ID, eventInfo.userId,
154         EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName);
155 }
156 
InnerSendUnSubscribeEvent(const EventInfo & eventInfo)157 void EventReport::InnerSendUnSubscribeEvent(const EventInfo &eventInfo)
158 {
159     InnerEventWrite(
160         UNSUBSCRIBE,
161         HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
162         EVENT_PARAM_PID, eventInfo.pid,
163         EVENT_PARAM_UID, eventInfo.uid,
164         EVENT_PARAM_USER_ID, eventInfo.userId,
165         EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName);
166 }
167 
InnerSendEnableNotificationEvent(const EventInfo & eventInfo)168 void EventReport::InnerSendEnableNotificationEvent(const EventInfo &eventInfo)
169 {
170     InnerEventWrite(
171         ENABLE_NOTIFICATION,
172         HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
173         EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
174         EVENT_PARAM_UID, eventInfo.uid,
175         EVENT_PARAM_ENABLE, eventInfo.enable);
176 }
177 
InnerSendEnableNotificationSlotEvent(const EventInfo & eventInfo)178 void EventReport::InnerSendEnableNotificationSlotEvent(const EventInfo &eventInfo)
179 {
180     InnerEventWrite(
181         ENABLE_NOTIFICATION_SLOT,
182         HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
183         EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
184         EVENT_PARAM_UID, eventInfo.uid,
185         EVENT_PARAM_SLOT_TYPE, eventInfo.slotType,
186         EVENT_PARAM_ENABLE, eventInfo.enable);
187 }
188 
InnerSendPublishEvent(const EventInfo & eventInfo)189 void EventReport::InnerSendPublishEvent(const EventInfo &eventInfo)
190 {
191     InnerEventWrite(
192         PUBLISH,
193         HiviewDFX::HiSysEvent::EventType::STATISTIC,
194         EVENT_PARAM_NOTIFICATION_ID, eventInfo.notificationId,
195         EVENT_PARAM_CONTENT_TYPE, eventInfo.contentType,
196         EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
197         EVENT_PARAM_USER_ID, eventInfo.userId);
198 }
199 
InnerSendCancelEvent(const EventInfo & eventInfo)200 void EventReport::InnerSendCancelEvent(const EventInfo &eventInfo)
201 {
202     InnerEventWrite(
203         CANCEL,
204         HiviewDFX::HiSysEvent::EventType::STATISTIC,
205         EVENT_PARAM_NOTIFICATION_ID, eventInfo.notificationId,
206         EVENT_PARAM_NOTIFICATION_LABEL, eventInfo.notificationLabel,
207         EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
208         EVENT_PARAM_UID, eventInfo.uid);
209 }
210 
InnerSendRemoveEvent(const EventInfo & eventInfo)211 void EventReport::InnerSendRemoveEvent(const EventInfo &eventInfo)
212 {
213     InnerEventWrite(
214         REMOVE,
215         HiviewDFX::HiSysEvent::EventType::STATISTIC,
216         EVENT_PARAM_NOTIFICATION_ID, eventInfo.notificationId,
217         EVENT_PARAM_NOTIFICATION_LABEL, eventInfo.notificationLabel,
218         EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
219         EVENT_PARAM_UID, eventInfo.uid);
220 }
221 
222 template<typename... Types>
InnerEventWrite(const std::string & eventName,HiviewDFX::HiSysEvent::EventType type,Types...keyValues)223 void EventReport::InnerEventWrite(const std::string &eventName,
224     HiviewDFX::HiSysEvent::EventType type, Types... keyValues)
225 {
226     HiviewDFX::HiSysEvent::Write(
227         HiviewDFX::HiSysEvent::Domain::NOTIFICATION,
228         eventName,
229         static_cast<HiviewDFX::HiSysEvent::EventType>(type),
230         keyValues...);
231 }
232 #endif
233 } // namespace Notification
234 } // namespace OHOS