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