1 /*
2  * Copyright (c) 2022-2024 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 "inner_event_report.h"
17 
18 #include "hisysevent.h"
19 
20 namespace OHOS {
21 namespace AppExecFwk {
22 namespace {
23 // event type
24 constexpr const char* BUNDLE_INSTALL_EXCEPTION = "BUNDLE_INSTALL_EXCEPTION";
25 constexpr const char* BUNDLE_UNINSTALL_EXCEPTION = "BUNDLE_UNINSTALL_EXCEPTION";
26 constexpr const char* BUNDLE_UPDATE_EXCEPTION = "BUNDLE_UPDATE_EXCEPTION";
27 constexpr const char* PRE_BUNDLE_RECOVER_EXCEPTION = "PRE_BUNDLE_RECOVER_EXCEPTION";
28 constexpr const char* BUNDLE_STATE_CHANGE_EXCEPTION = "BUNDLE_STATE_CHANGE_EXCEPTION";
29 constexpr const char* BUNDLE_CLEAN_CACHE_EXCEPTION = "BUNDLE_CLEAN_CACHE_EXCEPTION";
30 
31 constexpr const char* BOOT_SCAN_START = "BOOT_SCAN_START";
32 constexpr const char* BOOT_SCAN_END = "BOOT_SCAN_END";
33 constexpr const char* BUNDLE_INSTALL = "BUNDLE_INSTALL";
34 constexpr const char* BUNDLE_UNINSTALL = "BUNDLE_UNINSTALL";
35 constexpr const char* BUNDLE_UPDATE = "BUNDLE_UPDATE";
36 constexpr const char* PRE_BUNDLE_RECOVER = "PRE_BUNDLE_RECOVER";
37 constexpr const char* BUNDLE_STATE_CHANGE = "BUNDLE_STATE_CHANGE";
38 constexpr const char* BUNDLE_CLEAN_CACHE = "BUNDLE_CLEAN_CACHE";
39 constexpr const char* BMS_USER_EVENT = "BMS_USER_EVENT";
40 constexpr const char* BUNDLE_QUICK_FIX = "BUNDLE_QUICK_FIX";
41 constexpr const char* CPU_SCENE_ENTRY = "CPU_SCENE_ENTRY";
42 constexpr const char* FREE_INSTALL_EVENT = "FREE_INSTALL_EVENT";
43 static constexpr char PERFORMANCE_DOMAIN[] = "PERFORMANCE";
44 static constexpr char BUNDLE_MANAGER[] = "BUNDLE_MANAGER";
45 constexpr const char* AOT_COMPILE_SUMMARY = "AOT_COMPILE_SUMMARY";
46 constexpr const char* AOT_COMPILE_RECORD = "AOT_COMPILE_RECORD";
47 constexpr const char* QUERY_OF_CONTINUE_TYPE = "QUERY_OF_CONTINUE_TYPE";
48 constexpr const char* BMS_DISK_SPACE = "BMS_DISK_SPACE";
49 constexpr const char* APP_CONTROL_RULE = "APP_CONTROL_RULE";
50 
51 // event params
52 const char* EVENT_PARAM_PNAMEID = "PNAMEID";
53 const char* EVENT_PARAM_PVERSIONID = "PVERSIONID";
54 const char* EVENT_PARAM_USERID = "USERID";
55 const char* EVENT_PARAM_UID = "UID";
56 const char* EVENT_PARAM_BUNDLE_NAME = "BUNDLE_NAME";
57 const char* EVENT_PARAM_ERROR_CODE = "ERROR_CODE";
58 const char* EVENT_PARAM_ABILITY_NAME = "ABILITY_NAME";
59 const char* EVENT_PARAM_TIME = "TIME";
60 const char* EVENT_PARAM_VERSION = "VERSION";
61 const char* EVENT_PARAM_SCENE = "SCENE";
62 const char* EVENT_PARAM_CLEAN_TYPE = "CLEAN_TYPE";
63 const char* EVENT_PARAM_INSTALL_TYPE = "INSTALL_TYPE";
64 const char* EVENT_PARAM_STATE = "STATE";
65 const char* EVENT_PARAM_CALLING_BUNDLE_NAME = "CALLING_BUNDLE_NAME";
66 const char* EVENT_PARAM_CALLING_UID = "CALLING_UID";
67 const char* EVENT_PARAM_CALLING_APPID = "CALLING_APPID";
68 const char* EVENT_PARAM_FINGERPRINT = "FINGERPRINT";
69 const char* EVENT_PARAM_HIDE_DESKTOP_ICON = "HIDE_DESKTOP_ICON";
70 const char* EVENT_PARAM_APP_DISTRIBUTION_TYPE = "APP_DISTRIBUTION_TYPE";
71 const char* EVENT_PARAM_FILE_PATH = "FILE_PATH";
72 const char* EVENT_PARAM_HASH_VALUE = "HASH_VALUE";
73 const char* EVENT_PARAM_INSTALL_TIME = "INSTALL_TIME";
74 const char* EVENT_PARAM_APPLY_QUICK_FIX_FREQUENCY = "APPLY_QUICK_FIX_FREQUENCY";
75 const char* EVENT_PARAM_CONTINUE_TYPE = "CONTINUE_TYPE";
76 const char* EVENT_PARAM_PACKAGE_NAME = "PACKAGE_NAME";
77 const char* EVENT_PARAM_SCENE_ID = "SCENE_ID";
78 const char* EVENT_PARAM_HAPPEN_TIME = "HAPPEN_TIME";
79 const char* EVENT_PARAM_MODULE_NAME = "MODULE_NAME";
80 const char* EVENT_PARAM_IS_FREE_INSTALL = "IS_FREE_INSTALL";
81 const char* EVENT_PARAM_APP_IDS = "APP_IDS";
82 const char* EVENT_PARAM_CALLING_NAME = "CALLING_NAME";
83 const char* EVENT_PARAM_OPERATION_TYPE = "OPERATION_TYPE";
84 const char* EVENT_PARAM_ACTION_TYPE = "ACTION_TYPE";
85 const char* EVENT_PARAM_RULE = "ACTION_RULE";
86 const char* EVENT_PARAM_APP_INDEX = "APP_INDEX";
87 
88 const char* FREE_INSTALL_TYPE = "FreeInstall";
89 const char* PRE_BUNDLE_INSTALL_TYPE = "PreBundleInstall";
90 const char* NORMAL_INSTALL_TYPE = "normalInstall";
91 const char* NORMAL_SCENE = "Normal";
92 const char* BOOT_SCENE = "Boot";
93 const char* REBOOT_SCENE = "Reboot";
94 const char* CREATE_USER_SCENE = "CreateUser";
95 const char* REMOVE_USER_SCENE = "RemoveUser";
96 const char* CLEAN_CACHE = "cleanCache";
97 const char* CLEAN_DATA = "cleanData";
98 const char* ENABLE = "enable";
99 const char* DISABLE = "disable";
100 const char* APPLICATION = "application";
101 const char* ABILITY = "ability";
102 const char* TYPE = "TYPE";
103 const char* UNKNOW = "Unknow";
104 const char* CREATE_START = "CreateUserStart";
105 const char* CREATE_END = "CreateUserEnd";
106 const char* REMOVE_START = "RemoveUserStart";
107 const char* REMOVE_END = "RemoveUserEnd";
108 // AOT
109 const char* TOTAL_BUNDLE_NAMES = "totalBundleNames";
110 const char* TOTAL_SIZE = "totalSize";
111 const char* SUCCESS_SIZE = "successSize";
112 const char* COST_TIME_SECONDS = "costTimeSeconds";
113 const char* COMPILE_MODE = "compileMode";
114 const char* COMPILE_RESULT = "compileResult";
115 const char* FAILURE_REASON = "failureReason";
116 const char* FILE_NAME = "fileName";
117 const char* FREE_SIZE = "freeSize";
118 const char* OPERATION_TYPE = "operationType";
119 
120 const InstallScene INSTALL_SCENE_STR_MAP_KEY[] = {
121     InstallScene::NORMAL,
122     InstallScene::BOOT,
123     InstallScene::REBOOT,
124     InstallScene::CREATE_USER,
125     InstallScene::REMOVE_USER,
126 };
127 const char* g_installSceneStrMapValue[] = {
128     NORMAL_SCENE,
129     BOOT_SCENE,
130     REBOOT_SCENE,
131     CREATE_USER_SCENE,
132     REMOVE_USER_SCENE,
133 };
134 
135 const UserEventType USER_TYPE_STR_MAP_KEY[] = {
136     UserEventType::CREATE_START,
137     UserEventType::CREATE_END,
138     UserEventType::REMOVE_START,
139     UserEventType::REMOVE_END,
140 };
141 const char* g_userTypeStrMapValue[] = {
142     CREATE_START,
143     CREATE_END,
144     REMOVE_START,
145     REMOVE_END,
146 };
147 
GetInstallType(const EventInfo& eventInfo)148 std::string GetInstallType(const EventInfo& eventInfo)
149 {
150     std::string installType = NORMAL_INSTALL_TYPE;
151     if (eventInfo.isFreeInstallMode) {
152         installType = FREE_INSTALL_TYPE;
153     } else if (eventInfo.isPreInstallApp) {
154         installType = PRE_BUNDLE_INSTALL_TYPE;
155     }
156 
157     return installType;
158 }
159 
GetInstallScene(const EventInfo& eventInfo)160 std::string GetInstallScene(const EventInfo& eventInfo)
161 {
162     std::string installScene = NORMAL_SCENE;
163     size_t len = sizeof(INSTALL_SCENE_STR_MAP_KEY) / sizeof(INSTALL_SCENE_STR_MAP_KEY[0]);
164     for (size_t i = 0; i < len; i++) {
165         if (eventInfo.preBundleScene == INSTALL_SCENE_STR_MAP_KEY[i]) {
166             installScene = g_installSceneStrMapValue[i];
167             break;
168         }
169     }
170 
171     return installScene;
172 }
173 
GetUserEventType(const EventInfo& eventInfo)174 std::string GetUserEventType(const EventInfo& eventInfo)
175 {
176     std::string type = UNKNOW;
177     size_t len = sizeof(USER_TYPE_STR_MAP_KEY) / sizeof(USER_TYPE_STR_MAP_KEY[0]);
178     for (size_t i = 0; i < len; i++) {
179         if (eventInfo.userEventType == USER_TYPE_STR_MAP_KEY[i]) {
180             type = g_userTypeStrMapValue[i];
181             break;
182         }
183     }
184 
185     return type;
186 }
187 }
188 
189 std::unordered_map<BMSEventType, void (*)(const EventInfo& eventInfo)>
190     InnerEventReport::bmsSysEventMap_ = {
191         { BMSEventType::BUNDLE_INSTALL_EXCEPTION,
192             [](const EventInfo& eventInfo) {
193                 InnerSendBundleInstallExceptionEvent(eventInfo);
194             } },
195         { BMSEventType::BUNDLE_UNINSTALL_EXCEPTION,
196             [](const EventInfo& eventInfo) {
197                 InnerSendBundleUninstallExceptionEvent(eventInfo);
198             } },
199         { BMSEventType::BUNDLE_UPDATE_EXCEPTION,
200             [](const EventInfo& eventInfo) {
201                 InnerSendBundleUpdateExceptionEvent(eventInfo);
202             } },
203         { BMSEventType::PRE_BUNDLE_RECOVER_EXCEPTION,
204             [](const EventInfo& eventInfo) {
205                 InnerSendPreBundleRecoverExceptionEvent(eventInfo);
206             } },
207         { BMSEventType::BUNDLE_STATE_CHANGE_EXCEPTION,
208             [](const EventInfo& eventInfo) {
209                 InnerSendBundleStateChangeExceptionEvent(eventInfo);
210             } },
211         { BMSEventType::BUNDLE_CLEAN_CACHE_EXCEPTION,
212             [](const EventInfo& eventInfo) {
213                 InnerSendBundleCleanCacheExceptionEvent(eventInfo);
214             } },
215         { BMSEventType::BOOT_SCAN_START,
216             [](const EventInfo& eventInfo) {
217                 InnerSendBootScanStartEvent(eventInfo);
218             } },
219         { BMSEventType::BOOT_SCAN_END,
220             [](const EventInfo& eventInfo) {
221                 InnerSendBootScanEndEvent(eventInfo);
222             } },
223         { BMSEventType::BUNDLE_INSTALL,
224             [](const EventInfo& eventInfo) {
225                 InnerSendBundleInstallEvent(eventInfo);
226             } },
227         { BMSEventType::BUNDLE_UNINSTALL,
228             [](const EventInfo& eventInfo) {
229                 InnerSendBundleUninstallEvent(eventInfo);
230             } },
231         { BMSEventType::BUNDLE_UPDATE,
232             [](const EventInfo& eventInfo) {
233                 InnerSendBundleUpdateEvent(eventInfo);
234             } },
235         { BMSEventType::PRE_BUNDLE_RECOVER,
236             [](const EventInfo& eventInfo) {
237                 InnerSendPreBundleRecoverEvent(eventInfo);
238             } },
239         { BMSEventType::BUNDLE_STATE_CHANGE,
240             [](const EventInfo& eventInfo) {
241                 InnerSendBundleStateChangeEvent(eventInfo);
242             } },
243         { BMSEventType::BUNDLE_CLEAN_CACHE,
244             [](const EventInfo& eventInfo) {
245                 InnerSendBundleCleanCacheEvent(eventInfo);
246             } },
247         { BMSEventType::BMS_USER_EVENT,
248             [](const EventInfo& eventInfo) {
249                 InnerSendUserEvent(eventInfo);
250             } },
251         { BMSEventType::APPLY_QUICK_FIX,
252             [](const EventInfo& eventInfo) {
253                 InnerSendQuickFixEvent(eventInfo);
254             } },
255         { BMSEventType::CPU_SCENE_ENTRY,
256             [](const EventInfo& eventInfo) {
257                 InnerSendCpuSceneEvent(eventInfo);
258             } },
259         { BMSEventType::AOT_COMPILE_SUMMARY,
260             [](const EventInfo& eventInfo) {
261                 InnerSendAOTSummaryEvent(eventInfo);
262             } },
263         { BMSEventType::AOT_COMPILE_RECORD,
264             [](const EventInfo& eventInfo) {
265                 InnerSendAOTRecordEvent(eventInfo);
266             } },
267         { BMSEventType::QUERY_OF_CONTINUE_TYPE,
268             [](const EventInfo& eventInfo) {
269                 InnerSendQueryOfContinueTypeEvent(eventInfo);
270             } },
271         { BMSEventType::FREE_INSTALL_EVENT,
272             [](const EventInfo& eventInfo) {
273                 InnerSendFreeInstallEvent(eventInfo);
274             } },
275         { BMSEventType::BMS_DISK_SPACE,
276             [](const EventInfo& eventInfo) {
277                 InnerSendBmsDiskSpaceEvent(eventInfo);
278             } },
279         { BMSEventType::APP_CONTROL_RULE,
280             [](const EventInfo& eventInfo) {
281                 InnerSendAppConitolRule(eventInfo);
282             } }
283     };
284 
SendSystemEvent(BMSEventType bmsEventType, const EventInfo& eventInfo)285 void InnerEventReport::SendSystemEvent(BMSEventType bmsEventType, const EventInfo& eventInfo)
286 {
287     auto iter = bmsSysEventMap_.find(bmsEventType);
288     if (iter == bmsSysEventMap_.end()) {
289         return;
290     }
291 
292     iter->second(eventInfo);
293 }
294 
InnerSendBundleInstallExceptionEvent(const EventInfo& eventInfo)295 void InnerEventReport::InnerSendBundleInstallExceptionEvent(const EventInfo& eventInfo)
296 {
297     InnerEventWrite(
298         BUNDLE_INSTALL_EXCEPTION,
299         HiSysEventType::FAULT,
300         EVENT_PARAM_PNAMEID, eventInfo.packageName,
301         EVENT_PARAM_PVERSIONID, eventInfo.applicationVersion,
302         EVENT_PARAM_USERID, eventInfo.userId,
303         EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
304         EVENT_PARAM_VERSION, eventInfo.versionCode,
305         EVENT_PARAM_INSTALL_TYPE, GetInstallType(eventInfo),
306         EVENT_PARAM_SCENE, GetInstallScene(eventInfo),
307         EVENT_PARAM_ERROR_CODE, eventInfo.errCode);
308 }
309 
InnerSendBundleUninstallExceptionEvent(const EventInfo& eventInfo)310 void InnerEventReport::InnerSendBundleUninstallExceptionEvent(const EventInfo& eventInfo)
311 {
312     InnerEventWrite(
313         BUNDLE_UNINSTALL_EXCEPTION,
314         HiSysEventType::FAULT,
315         EVENT_PARAM_PNAMEID, eventInfo.packageName,
316         EVENT_PARAM_PVERSIONID, eventInfo.applicationVersion,
317         EVENT_PARAM_USERID, eventInfo.userId,
318         EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
319         EVENT_PARAM_VERSION, eventInfo.versionCode,
320         EVENT_PARAM_INSTALL_TYPE, GetInstallType(eventInfo),
321         EVENT_PARAM_ERROR_CODE, eventInfo.errCode);
322 }
323 
InnerSendBundleUpdateExceptionEvent(const EventInfo& eventInfo)324 void InnerEventReport::InnerSendBundleUpdateExceptionEvent(const EventInfo& eventInfo)
325 {
326     InnerEventWrite(
327         BUNDLE_UPDATE_EXCEPTION,
328         HiSysEventType::FAULT,
329         EVENT_PARAM_PNAMEID, eventInfo.packageName,
330         EVENT_PARAM_PVERSIONID, eventInfo.applicationVersion,
331         EVENT_PARAM_USERID, eventInfo.userId,
332         EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
333         EVENT_PARAM_VERSION, eventInfo.versionCode,
334         EVENT_PARAM_INSTALL_TYPE, GetInstallType(eventInfo),
335         EVENT_PARAM_ERROR_CODE, eventInfo.errCode);
336 }
337 
InnerSendPreBundleRecoverExceptionEvent(const EventInfo& eventInfo)338 void InnerEventReport::InnerSendPreBundleRecoverExceptionEvent(const EventInfo& eventInfo)
339 {
340     InnerEventWrite(
341         PRE_BUNDLE_RECOVER_EXCEPTION,
342         HiSysEventType::FAULT,
343         EVENT_PARAM_PNAMEID, eventInfo.packageName,
344         EVENT_PARAM_PVERSIONID, eventInfo.applicationVersion,
345         EVENT_PARAM_USERID, eventInfo.userId,
346         EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
347         EVENT_PARAM_VERSION, eventInfo.versionCode,
348         EVENT_PARAM_INSTALL_TYPE, PRE_BUNDLE_INSTALL_TYPE,
349         EVENT_PARAM_ERROR_CODE, eventInfo.errCode);
350 }
351 
InnerSendBundleStateChangeExceptionEvent(const EventInfo& eventInfo)352 void InnerEventReport::InnerSendBundleStateChangeExceptionEvent(const EventInfo& eventInfo)
353 {
354     std::string type = eventInfo.abilityName.empty() ? APPLICATION : ABILITY;
355     InnerEventWrite(
356         BUNDLE_STATE_CHANGE_EXCEPTION,
357         HiSysEventType::FAULT,
358         EVENT_PARAM_PNAMEID, eventInfo.packageName,
359         EVENT_PARAM_PVERSIONID, eventInfo.applicationVersion,
360         EVENT_PARAM_USERID, eventInfo.userId,
361         EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
362         EVENT_PARAM_ABILITY_NAME, eventInfo.abilityName,
363         TYPE, type);
364 }
365 
InnerSendBundleCleanCacheExceptionEvent(const EventInfo& eventInfo)366 void InnerEventReport::InnerSendBundleCleanCacheExceptionEvent(const EventInfo& eventInfo)
367 {
368     std::string cleanType = eventInfo.isCleanCache ? CLEAN_CACHE : CLEAN_DATA;
369     InnerEventWrite(
370         BUNDLE_CLEAN_CACHE_EXCEPTION,
371         HiSysEventType::FAULT,
372         EVENT_PARAM_PNAMEID, eventInfo.packageName,
373         EVENT_PARAM_PVERSIONID, eventInfo.applicationVersion,
374         EVENT_PARAM_USERID, eventInfo.userId,
375         EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
376         EVENT_PARAM_CLEAN_TYPE, cleanType);
377 }
378 
InnerSendBootScanStartEvent(const EventInfo& eventInfo)379 void InnerEventReport::InnerSendBootScanStartEvent(const EventInfo& eventInfo)
380 {
381     InnerEventWrite(
382         BOOT_SCAN_START,
383         HiSysEventType::BEHAVIOR,
384         EVENT_PARAM_PNAMEID, eventInfo.packageName,
385         EVENT_PARAM_PVERSIONID, eventInfo.applicationVersion,
386         EVENT_PARAM_TIME, eventInfo.timeStamp);
387 }
388 
InnerSendBootScanEndEvent(const EventInfo& eventInfo)389 void InnerEventReport::InnerSendBootScanEndEvent(const EventInfo& eventInfo)
390 {
391     InnerEventWrite(
392         BOOT_SCAN_END,
393         HiSysEventType::BEHAVIOR,
394         EVENT_PARAM_PNAMEID, eventInfo.packageName,
395         EVENT_PARAM_PVERSIONID, eventInfo.applicationVersion,
396         EVENT_PARAM_TIME, eventInfo.timeStamp);
397 }
398 
InnerSendBundleInstallEvent(const EventInfo& eventInfo)399 void InnerEventReport::InnerSendBundleInstallEvent(const EventInfo& eventInfo)
400 {
401     InnerEventWrite(
402         BUNDLE_INSTALL,
403         HiSysEventType::BEHAVIOR,
404         EVENT_PARAM_PNAMEID, eventInfo.packageName,
405         EVENT_PARAM_PVERSIONID, eventInfo.applicationVersion,
406         EVENT_PARAM_USERID, eventInfo.userId,
407         EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
408         EVENT_PARAM_VERSION, eventInfo.versionCode,
409         EVENT_PARAM_APP_DISTRIBUTION_TYPE, eventInfo.appDistributionType,
410         EVENT_PARAM_INSTALL_TIME, eventInfo.timeStamp,
411         EVENT_PARAM_CALLING_UID, eventInfo.callingUid,
412         EVENT_PARAM_CALLING_APPID, eventInfo.callingAppId,
413         EVENT_PARAM_CALLING_BUNDLE_NAME, eventInfo.callingBundleName,
414         EVENT_PARAM_FILE_PATH, eventInfo.filePath,
415         EVENT_PARAM_HASH_VALUE, eventInfo.hashValue,
416         EVENT_PARAM_FINGERPRINT, eventInfo.fingerprint,
417         EVENT_PARAM_HIDE_DESKTOP_ICON, eventInfo.hideDesktopIcon,
418         EVENT_PARAM_INSTALL_TYPE, GetInstallType(eventInfo),
419         EVENT_PARAM_SCENE, GetInstallScene(eventInfo));
420 }
421 
InnerSendBundleUninstallEvent(const EventInfo& eventInfo)422 void InnerEventReport::InnerSendBundleUninstallEvent(const EventInfo& eventInfo)
423 {
424     InnerEventWrite(
425         BUNDLE_UNINSTALL,
426         HiSysEventType::BEHAVIOR,
427         EVENT_PARAM_PNAMEID, eventInfo.packageName,
428         EVENT_PARAM_PVERSIONID, eventInfo.applicationVersion,
429         EVENT_PARAM_USERID, eventInfo.userId,
430         EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
431         EVENT_PARAM_VERSION, eventInfo.versionCode,
432         EVENT_PARAM_CALLING_UID, eventInfo.callingUid,
433         EVENT_PARAM_CALLING_APPID, eventInfo.callingAppId,
434         EVENT_PARAM_CALLING_BUNDLE_NAME, eventInfo.callingBundleName,
435         EVENT_PARAM_INSTALL_TYPE, GetInstallType(eventInfo));
436 }
437 
InnerSendBundleUpdateEvent(const EventInfo& eventInfo)438 void InnerEventReport::InnerSendBundleUpdateEvent(const EventInfo& eventInfo)
439 {
440     InnerEventWrite(
441         BUNDLE_UPDATE,
442         HiSysEventType::BEHAVIOR,
443         EVENT_PARAM_PNAMEID, eventInfo.packageName,
444         EVENT_PARAM_PVERSIONID, eventInfo.applicationVersion,
445         EVENT_PARAM_USERID, eventInfo.userId,
446         EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
447         EVENT_PARAM_VERSION, eventInfo.versionCode,
448         EVENT_PARAM_APP_DISTRIBUTION_TYPE, eventInfo.appDistributionType,
449         EVENT_PARAM_INSTALL_TIME, eventInfo.timeStamp,
450         EVENT_PARAM_CALLING_UID, eventInfo.callingUid,
451         EVENT_PARAM_CALLING_APPID, eventInfo.callingAppId,
452         EVENT_PARAM_CALLING_BUNDLE_NAME, eventInfo.callingBundleName,
453         EVENT_PARAM_FILE_PATH, eventInfo.filePath,
454         EVENT_PARAM_HASH_VALUE, eventInfo.hashValue,
455         EVENT_PARAM_FINGERPRINT, eventInfo.fingerprint,
456         EVENT_PARAM_HIDE_DESKTOP_ICON, eventInfo.hideDesktopIcon,
457         EVENT_PARAM_INSTALL_TYPE, GetInstallType(eventInfo));
458 }
459 
InnerSendPreBundleRecoverEvent(const EventInfo& eventInfo)460 void InnerEventReport::InnerSendPreBundleRecoverEvent(const EventInfo& eventInfo)
461 {
462     InnerEventWrite(
463         PRE_BUNDLE_RECOVER,
464         HiSysEventType::BEHAVIOR,
465         EVENT_PARAM_PNAMEID, eventInfo.packageName,
466         EVENT_PARAM_PVERSIONID, eventInfo.applicationVersion,
467         EVENT_PARAM_USERID, eventInfo.userId,
468         EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
469         EVENT_PARAM_VERSION, eventInfo.versionCode,
470         EVENT_PARAM_APP_DISTRIBUTION_TYPE, eventInfo.appDistributionType,
471         EVENT_PARAM_INSTALL_TIME, eventInfo.timeStamp,
472         EVENT_PARAM_CALLING_UID, eventInfo.callingUid,
473         EVENT_PARAM_CALLING_APPID, eventInfo.callingAppId,
474         EVENT_PARAM_CALLING_BUNDLE_NAME, eventInfo.callingBundleName,
475         EVENT_PARAM_FINGERPRINT, eventInfo.fingerprint,
476         EVENT_PARAM_HIDE_DESKTOP_ICON, eventInfo.hideDesktopIcon,
477         EVENT_PARAM_INSTALL_TYPE, PRE_BUNDLE_INSTALL_TYPE);
478 }
479 
InnerSendBundleStateChangeEvent(const EventInfo& eventInfo)480 void InnerEventReport::InnerSendBundleStateChangeEvent(const EventInfo& eventInfo)
481 {
482     std::string type = eventInfo.abilityName.empty() ? APPLICATION : ABILITY;
483     std::string state = eventInfo.isEnable ? ENABLE : DISABLE;
484     InnerEventWrite(
485         BUNDLE_STATE_CHANGE,
486         HiSysEventType::BEHAVIOR,
487         EVENT_PARAM_PNAMEID, eventInfo.packageName,
488         EVENT_PARAM_PVERSIONID, eventInfo.applicationVersion,
489         EVENT_PARAM_USERID, eventInfo.userId,
490         EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
491         EVENT_PARAM_ABILITY_NAME, eventInfo.abilityName,
492         TYPE, type,
493         EVENT_PARAM_STATE, state);
494 }
495 
InnerSendBundleCleanCacheEvent(const EventInfo& eventInfo)496 void InnerEventReport::InnerSendBundleCleanCacheEvent(const EventInfo& eventInfo)
497 {
498     std::string cleanType = eventInfo.isCleanCache ? CLEAN_CACHE : CLEAN_DATA;
499     InnerEventWrite(
500         BUNDLE_CLEAN_CACHE,
501         HiSysEventType::BEHAVIOR,
502         EVENT_PARAM_PNAMEID, eventInfo.packageName,
503         EVENT_PARAM_PVERSIONID, eventInfo.applicationVersion,
504         EVENT_PARAM_USERID, eventInfo.userId,
505         EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
506         EVENT_PARAM_CLEAN_TYPE, cleanType);
507 }
508 
InnerSendUserEvent(const EventInfo& eventInfo)509 void InnerEventReport::InnerSendUserEvent(const EventInfo& eventInfo)
510 {
511     InnerEventWrite(
512         BMS_USER_EVENT,
513         HiSysEventType::BEHAVIOR,
514         EVENT_PARAM_PNAMEID, eventInfo.packageName,
515         EVENT_PARAM_PVERSIONID, eventInfo.applicationVersion,
516         TYPE, GetUserEventType(eventInfo),
517         EVENT_PARAM_USERID, eventInfo.userId,
518         EVENT_PARAM_TIME, eventInfo.timeStamp);
519 }
520 
InnerSendQuickFixEvent(const EventInfo& eventInfo)521 void InnerEventReport::InnerSendQuickFixEvent(const EventInfo& eventInfo)
522 {
523     InnerEventWrite(
524         BUNDLE_QUICK_FIX,
525         HiSysEventType::BEHAVIOR,
526         EVENT_PARAM_PNAMEID, eventInfo.packageName,
527         EVENT_PARAM_PVERSIONID, eventInfo.applicationVersion,
528         EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
529         EVENT_PARAM_APP_DISTRIBUTION_TYPE, eventInfo.appDistributionType,
530         EVENT_PARAM_APPLY_QUICK_FIX_FREQUENCY, eventInfo.applyQuickFixFrequency,
531         EVENT_PARAM_FILE_PATH, eventInfo.filePath,
532         EVENT_PARAM_HASH_VALUE, eventInfo.hashValue);
533 }
534 
InnerSendCpuSceneEvent(const EventInfo& eventInfo)535 void InnerEventReport::InnerSendCpuSceneEvent(const EventInfo& eventInfo)
536 {
537     HiSysEventWrite(
538         PERFORMANCE_DOMAIN,
539         CPU_SCENE_ENTRY,
540         HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
541         EVENT_PARAM_PACKAGE_NAME, eventInfo.processName,
542         EVENT_PARAM_SCENE_ID, std::to_string(eventInfo.sceneId).c_str(),
543         EVENT_PARAM_HAPPEN_TIME, eventInfo.timeStamp);
544 }
545 
InnerSendAOTSummaryEvent(const EventInfo& eventInfo)546 void InnerEventReport::InnerSendAOTSummaryEvent(const EventInfo& eventInfo)
547 {
548     InnerEventWrite(
549         AOT_COMPILE_SUMMARY,
550         HiSysEventType::BEHAVIOR,
551         TOTAL_BUNDLE_NAMES, eventInfo.totalBundleNames,
552         TOTAL_SIZE, eventInfo.totalBundleNames.size(),
553         SUCCESS_SIZE, eventInfo.successCnt,
554         COST_TIME_SECONDS, eventInfo.costTimeSeconds,
555         EVENT_PARAM_TIME, eventInfo.timeStamp);
556 }
557 
InnerSendAOTRecordEvent(const EventInfo& eventInfo)558 void InnerEventReport::InnerSendAOTRecordEvent(const EventInfo& eventInfo)
559 {
560     InnerEventWrite(
561         AOT_COMPILE_RECORD,
562         HiSysEventType::BEHAVIOR,
563         EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
564         COMPILE_RESULT, eventInfo.compileResult,
565         FAILURE_REASON, eventInfo.failureReason,
566         COST_TIME_SECONDS, eventInfo.costTimeSeconds,
567         COMPILE_MODE, eventInfo.compileMode,
568         EVENT_PARAM_TIME, eventInfo.timeStamp);
569 }
570 
InnerSendQueryOfContinueTypeEvent(const EventInfo& eventInfo)571 void InnerEventReport::InnerSendQueryOfContinueTypeEvent(const EventInfo& eventInfo)
572 {
573     InnerEventWrite(
574         QUERY_OF_CONTINUE_TYPE,
575         HiSysEventType::BEHAVIOR,
576         EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
577         EVENT_PARAM_ABILITY_NAME, eventInfo.abilityName,
578         EVENT_PARAM_ERROR_CODE, eventInfo.errCode,
579         EVENT_PARAM_USERID, eventInfo.userId,
580         EVENT_PARAM_CONTINUE_TYPE, eventInfo.continueType);
581 }
582 
InnerSendFreeInstallEvent(const EventInfo& eventInfo)583 void InnerEventReport::InnerSendFreeInstallEvent(const EventInfo& eventInfo)
584 {
585     InnerEventWrite(
586         FREE_INSTALL_EVENT,
587         HiSysEventType::BEHAVIOR,
588         EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
589         EVENT_PARAM_ABILITY_NAME, eventInfo.abilityName,
590         EVENT_PARAM_MODULE_NAME, eventInfo.moduleName,
591         EVENT_PARAM_IS_FREE_INSTALL, eventInfo.isFreeInstall,
592         EVENT_PARAM_TIME, eventInfo.timeStamp);
593 }
594 
InnerSendBmsDiskSpaceEvent(const EventInfo& eventInfo)595 void InnerEventReport::InnerSendBmsDiskSpaceEvent(const EventInfo& eventInfo)
596 {
597     InnerEventWrite(
598         BMS_DISK_SPACE,
599         HiSysEventType::BEHAVIOR,
600         FILE_NAME, eventInfo.fileName,
601         FREE_SIZE, eventInfo.freeSize,
602         OPERATION_TYPE, eventInfo.operationType);
603 }
604 
InnerSendAppConitolRule(const EventInfo& eventInfo)605 void InnerEventReport::InnerSendAppConitolRule(const EventInfo& eventInfo)
606 {
607     InnerEventWrite(
608         APP_CONTROL_RULE,
609         HiSysEventType::BEHAVIOR,
610         EVENT_PARAM_PNAMEID, eventInfo.packageName,
611         EVENT_PARAM_PVERSIONID, eventInfo.applicationVersion,
612         EVENT_PARAM_APP_IDS, eventInfo.appIds,
613         EVENT_PARAM_USERID, eventInfo.userId,
614         EVENT_PARAM_CALLING_NAME, eventInfo.callingName,
615         EVENT_PARAM_OPERATION_TYPE, eventInfo.operationType,
616         EVENT_PARAM_ACTION_TYPE, eventInfo.actionType,
617         EVENT_PARAM_RULE, eventInfo.rule,
618         EVENT_PARAM_APP_INDEX, eventInfo.appIndex);
619 }
620 
621 template<typename... Types>
InnerEventWrite( const std::string &eventName, HiSysEventType type, Types... keyValues)622 void InnerEventReport::InnerEventWrite(
623     const std::string &eventName,
624     HiSysEventType type,
625     Types... keyValues)
626 {
627     HiSysEventWrite(
628         OHOS::HiviewDFX::HiSysEvent::Domain::BUNDLEMANAGER_UE,
629         eventName,
630         static_cast<OHOS::HiviewDFX::HiSysEvent::EventType>(type),
631         keyValues...);
632 }
633 }  // namespace AppExecFwk
634 }  // namespace OHOS