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