• 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 const std::string EVENT_PARAM_COMPONENT_NAME = "COMPONENT_NAME";
41 const std::string EVENT_PARAM_PARTITION_NAME = "PARTITION_NAME";
42 const std::string EVENT_PARAM_REMAIN_PARTITION_SIZE = "REMAIN_PARTITION_SIZE";
43 const std::string EVENT_PARAM_FILE_OR_FOLDER_PATH = "FILE_OR_FOLDER_PATH";
44 const std::string EVENT_PARAM_FILE_OR_FOLDER_SIZE = "FILE_OR_FOLDER_SIZE";
45 } // namespace
46 
SendHiSysEvent(const std::string & eventName,const EventInfo & eventInfo)47 void EventReport::SendHiSysEvent(const std::string &eventName, const EventInfo &eventInfo)
48 {
49 #ifndef HAS_HISYSEVENT_PART
50     ANS_LOGD("Hisysevent is disabled");
51 #else
52     auto iter = ansSysEventFuncMap_.find(eventName);
53     if (iter == ansSysEventFuncMap_.end()) {
54         return;
55     }
56 
57     iter->second(eventInfo);
58 #endif
59 }
60 
SendHiSysEvent(const UserDataSizeInfo & userDataSizeInfo)61 void EventReport::SendHiSysEvent(const UserDataSizeInfo & userDataSizeInfo)
62 {
63 #ifndef HAS_HISYSEVENT_PART
64     ANS_LOGD("Hisysevent is disabled");
65 #else
66     InnerSendUserDataSizeEvent(userDataSizeInfo);
67 #endif
68 }
69 
70 #ifdef HAS_HISYSEVENT_PART
71 std::unordered_map<std::string, void (*)(const EventInfo& eventInfo)> EventReport::ansSysEventFuncMap_ = {
__anon83f599fc0202() 72     {SUBSCRIBE_ERROR, [](const EventInfo& eventInfo) {
73         InnerSendSubscribeErrorEvent(eventInfo);
74     }},
__anon83f599fc0302() 75     {ENABLE_NOTIFICATION_ERROR, [](const EventInfo& eventInfo) {
76         InnerSendEnableNotificationErrorEvent(eventInfo);
77     }},
__anon83f599fc0402() 78     {ENABLE_NOTIFICATION_SLOT_ERROR, [](const EventInfo& eventInfo) {
79         InnerSendEnableNotificationSlotErrorEvent(eventInfo);
80     }},
__anon83f599fc0502() 81     {PUBLISH_ERROR, [](const EventInfo& eventInfo) {
82         InnerSendPublishErrorEvent(eventInfo);
83     }},
__anon83f599fc0602() 84     {EVENT_NOTIFICATION_ERROR, [](const EventInfo& eventInfo) {
85         InnerSendNotificationSystemErrorEvent(eventInfo);
86     }},
__anon83f599fc0702() 87     {FLOW_CONTROL_OCCUR, [](const EventInfo& eventInfo) {
88         InnerSendFlowControlOccurEvent(eventInfo);
89     }},
__anon83f599fc0802() 90     {SUBSCRIBE, [](const EventInfo& eventInfo) {
91         InnerSendSubscribeEvent(eventInfo);
92     }},
__anon83f599fc0902() 93     {UNSUBSCRIBE, [](const EventInfo& eventInfo) {
94         InnerSendUnSubscribeEvent(eventInfo);
95     }},
__anon83f599fc0a02() 96     {ENABLE_NOTIFICATION, [](const EventInfo& eventInfo) {
97         InnerSendEnableNotificationEvent(eventInfo);
98     }},
__anon83f599fc0b02() 99     {ENABLE_NOTIFICATION_SLOT, [](const EventInfo& eventInfo) {
100         InnerSendEnableNotificationSlotEvent(eventInfo);
101     }},
__anon83f599fc0c02() 102     {PUBLISH, [](const EventInfo& eventInfo) {
103         InnerSendPublishEvent(eventInfo);
104     }},
__anon83f599fc0d02() 105     {CANCEL, [](const EventInfo& eventInfo) {
106         InnerSendCancelEvent(eventInfo);
107     }},
__anon83f599fc0e02() 108     {REMOVE, [](const EventInfo& eventInfo) {
109         InnerSendRemoveEvent(eventInfo);
110     }},
__anon83f599fc0f02() 111     {STATIC_LIVE_VIEW_UPLOAD, [](const EventInfo& eventInfo) {
112         InnerSendLiveviewUploadEvent(eventInfo);
113     }},
114 };
115 
InnerSendSubscribeErrorEvent(const EventInfo & eventInfo)116 void EventReport::InnerSendSubscribeErrorEvent(const EventInfo &eventInfo)
117 {
118     InnerEventWrite(
119         SUBSCRIBE_ERROR,
120         HiviewDFX::HiSysEvent::EventType::FAULT,
121         EVENT_PARAM_PID, eventInfo.pid,
122         EVENT_PARAM_UID, eventInfo.uid,
123         EVENT_PARAM_USER_ID, eventInfo.userId,
124         EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
125         EVENT_PARAM_ERROR_CODE, eventInfo.errCode);
126 }
127 
InnerSendEnableNotificationErrorEvent(const EventInfo & eventInfo)128 void EventReport::InnerSendEnableNotificationErrorEvent(const EventInfo &eventInfo)
129 {
130     InnerEventWrite(
131         ENABLE_NOTIFICATION_ERROR,
132         HiviewDFX::HiSysEvent::EventType::FAULT,
133         EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
134         EVENT_PARAM_UID, eventInfo.uid,
135         EVENT_PARAM_ENABLE, eventInfo.enable,
136         EVENT_PARAM_ERROR_CODE, eventInfo.errCode);
137 }
138 
InnerSendEnableNotificationSlotErrorEvent(const EventInfo & eventInfo)139 void EventReport::InnerSendEnableNotificationSlotErrorEvent(const EventInfo &eventInfo)
140 {
141     InnerEventWrite(
142         ENABLE_NOTIFICATION_SLOT_ERROR,
143         HiviewDFX::HiSysEvent::EventType::FAULT,
144         EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
145         EVENT_PARAM_UID, eventInfo.uid,
146         EVENT_PARAM_SLOT_TYPE, eventInfo.slotType,
147         EVENT_PARAM_ENABLE, eventInfo.enable,
148         EVENT_PARAM_ERROR_CODE, eventInfo.errCode);
149 }
150 
InnerSendPublishErrorEvent(const EventInfo & eventInfo)151 void EventReport::InnerSendPublishErrorEvent(const EventInfo &eventInfo)
152 {
153     InnerEventWrite(
154         PUBLISH_ERROR,
155         HiviewDFX::HiSysEvent::EventType::STATISTIC,
156         EVENT_PARAM_NOTIFICATION_ID, eventInfo.notificationId,
157         EVENT_PARAM_CONTENT_TYPE, eventInfo.contentType,
158         EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
159         EVENT_PARAM_USER_ID, eventInfo.userId,
160         EVENT_PARAM_ERROR_CODE, eventInfo.errCode);
161 }
162 
InnerSendFlowControlOccurEvent(const EventInfo & eventInfo)163 void EventReport::InnerSendFlowControlOccurEvent(const EventInfo &eventInfo)
164 {
165     InnerEventWrite(
166         FLOW_CONTROL_OCCUR,
167         HiviewDFX::HiSysEvent::EventType::FAULT,
168         EVENT_PARAM_NOTIFICATION_ID, eventInfo.notificationId,
169         EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
170         EVENT_PARAM_UID, eventInfo.uid);
171 }
172 
InnerSendNotificationSystemErrorEvent(const EventInfo & eventInfo)173 void EventReport::InnerSendNotificationSystemErrorEvent(const EventInfo &eventInfo)
174 {
175     InnerEventWrite(
176         EVENT_NOTIFICATION_ERROR,
177         HiviewDFX::HiSysEvent::EventType::FAULT,
178         EVENT_MESSAGE_TYPE, eventInfo.messageType,
179         EVENT_PARAM_ERROR_CODE, eventInfo.errCode,
180         EVENT_REASON, eventInfo.reason);
181 }
182 
InnerSendSubscribeEvent(const EventInfo & eventInfo)183 void EventReport::InnerSendSubscribeEvent(const EventInfo &eventInfo)
184 {
185     InnerEventWrite(
186         SUBSCRIBE,
187         HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
188         EVENT_PARAM_PID, eventInfo.pid,
189         EVENT_PARAM_UID, eventInfo.uid,
190         EVENT_PARAM_USER_ID, eventInfo.userId,
191         EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName);
192 }
193 
InnerSendUnSubscribeEvent(const EventInfo & eventInfo)194 void EventReport::InnerSendUnSubscribeEvent(const EventInfo &eventInfo)
195 {
196     InnerEventWrite(
197         UNSUBSCRIBE,
198         HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
199         EVENT_PARAM_PID, eventInfo.pid,
200         EVENT_PARAM_UID, eventInfo.uid,
201         EVENT_PARAM_USER_ID, eventInfo.userId,
202         EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName);
203 }
204 
InnerSendEnableNotificationEvent(const EventInfo & eventInfo)205 void EventReport::InnerSendEnableNotificationEvent(const EventInfo &eventInfo)
206 {
207     InnerEventWrite(
208         ENABLE_NOTIFICATION,
209         HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
210         EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
211         EVENT_PARAM_UID, eventInfo.uid,
212         EVENT_PARAM_ENABLE, eventInfo.enable);
213 }
214 
InnerSendEnableNotificationSlotEvent(const EventInfo & eventInfo)215 void EventReport::InnerSendEnableNotificationSlotEvent(const EventInfo &eventInfo)
216 {
217     InnerEventWrite(
218         ENABLE_NOTIFICATION_SLOT,
219         HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
220         EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
221         EVENT_PARAM_UID, eventInfo.uid,
222         EVENT_PARAM_SLOT_TYPE, eventInfo.slotType,
223         EVENT_PARAM_ENABLE, eventInfo.enable);
224 }
225 
InnerSendLiveviewUploadEvent(const EventInfo & eventInfo)226 void EventReport::InnerSendLiveviewUploadEvent(const EventInfo &eventInfo)
227 {
228     InnerEventWrite(
229         STATIC_LIVE_VIEW_UPLOAD,
230         HiviewDFX::HiSysEvent::EventType::STATISTIC,
231         EVENT_PARAM_NOTIFICATION_ID, eventInfo.notificationId,
232         EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
233         EVENT_PARAM_CONTENT_TYPE, eventInfo.contentType,
234         EVENT_PARAM_OPERATE_FLAG, eventInfo.operateFlag);
235 }
236 
InnerSendPublishEvent(const EventInfo & eventInfo)237 void EventReport::InnerSendPublishEvent(const EventInfo &eventInfo)
238 {
239     InnerEventWrite(
240         PUBLISH,
241         HiviewDFX::HiSysEvent::EventType::STATISTIC,
242         EVENT_PARAM_NOTIFICATION_ID, eventInfo.notificationId,
243         EVENT_PARAM_CONTENT_TYPE, eventInfo.contentType,
244         EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
245         EVENT_PARAM_USER_ID, eventInfo.userId,
246         EVENT_PARAM_SLOT_TYPE, eventInfo.slotType,
247         EVENT_PARAM_CLASS, eventInfo.classification,
248         EVENT_PARAM_CONTROLFLAGS, eventInfo.notificationControlFlags,
249         EVENT_PARAM_REMINDERFLAGS, eventInfo.reminderFlags);
250 }
251 
InnerSendCancelEvent(const EventInfo & eventInfo)252 void EventReport::InnerSendCancelEvent(const EventInfo &eventInfo)
253 {
254     InnerEventWrite(
255         CANCEL,
256         HiviewDFX::HiSysEvent::EventType::STATISTIC,
257         EVENT_PARAM_NOTIFICATION_ID, eventInfo.notificationId,
258         EVENT_PARAM_NOTIFICATION_LABEL, eventInfo.notificationLabel,
259         EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
260         EVENT_PARAM_UID, eventInfo.uid);
261 }
262 
InnerSendRemoveEvent(const EventInfo & eventInfo)263 void EventReport::InnerSendRemoveEvent(const EventInfo &eventInfo)
264 {
265     InnerEventWrite(
266         REMOVE,
267         HiviewDFX::HiSysEvent::EventType::STATISTIC,
268         EVENT_PARAM_NOTIFICATION_ID, eventInfo.notificationId,
269         EVENT_PARAM_NOTIFICATION_LABEL, eventInfo.notificationLabel,
270         EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
271         EVENT_PARAM_UID, eventInfo.uid);
272 }
273 
InnerSendUserDataSizeEvent(const UserDataSizeInfo & userDataSizeInfo)274 void EventReport::InnerSendUserDataSizeEvent(const UserDataSizeInfo & userDataSizeInfo)
275 {
276     InnerEventWrite(
277         USER_DATA_SIZE,
278         HiviewDFX::HiSysEvent::EventType::STATISTIC,
279         EVENT_PARAM_COMPONENT_NAME, userDataSizeInfo.componentName,
280         EVENT_PARAM_PARTITION_NAME, userDataSizeInfo.partitionName,
281         EVENT_PARAM_REMAIN_PARTITION_SIZE, userDataSizeInfo.remainPartitionSize,
282         EVENT_PARAM_FILE_OR_FOLDER_PATH, userDataSizeInfo.folderPath,
283         EVENT_PARAM_FILE_OR_FOLDER_SIZE, userDataSizeInfo.folderSize);
284 }
285 
286 template<typename... Types>
InnerEventWrite(const std::string & eventName,HiviewDFX::HiSysEvent::EventType type,Types...keyValues)287 void EventReport::InnerEventWrite(const std::string &eventName,
288     HiviewDFX::HiSysEvent::EventType type, Types... keyValues)
289 {
290     if (eventName == USER_DATA_SIZE) {
291         HiSysEventWrite(
292             HiviewDFX::HiSysEvent::Domain::FILEMANAGEMENT,
293             eventName,
294             static_cast<HiviewDFX::HiSysEvent::EventType>(type),
295             keyValues...);
296         return;
297     }
298     HiSysEventWrite(
299         HiviewDFX::HiSysEvent::Domain::NOTIFICATION,
300         eventName,
301         static_cast<HiviewDFX::HiSysEvent::EventType>(type),
302         keyValues...);
303 }
304 #endif
305 } // namespace Notification
306 } // namespace OHOS