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