• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2025 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 #ifndef FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_EVENT_REPORT_H
17 #define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_EVENT_REPORT_H
18 
19 #include <string>
20 #include <vector>
21 
22 #include "appexecfwk_errors.h"
23 #include "bundle_constants.h"
24 
25 namespace OHOS {
26 namespace AppExecFwk {
27 enum class BMSEventType : uint8_t {
28     UNKNOW = 0,
29     /***********FAULT EVENT**************/
30     BUNDLE_INSTALL_EXCEPTION,
31     BUNDLE_UNINSTALL_EXCEPTION,
32     BUNDLE_UPDATE_EXCEPTION,
33     PRE_BUNDLE_RECOVER_EXCEPTION,
34     BUNDLE_STATE_CHANGE_EXCEPTION,
35     BUNDLE_CLEAN_CACHE_EXCEPTION,
36     /***********BEHAVIOR EVENT***********/
37     BOOT_SCAN_START,
38     BOOT_SCAN_END,
39     BUNDLE_INSTALL,
40     BUNDLE_UNINSTALL,
41     BUNDLE_UPDATE,
42     PRE_BUNDLE_RECOVER,
43     BUNDLE_STATE_CHANGE,
44     BUNDLE_CLEAN_CACHE,
45     BMS_USER_EVENT,
46     APPLY_QUICK_FIX,
47     CPU_SCENE_ENTRY,
48     AOT_COMPILE_SUMMARY,
49     AOT_COMPILE_RECORD,
50     QUERY_OF_CONTINUE_TYPE,
51     FREE_INSTALL_EVENT,
52     BMS_DISK_SPACE,
53     APP_CONTROL_RULE,
54     DB_ERROR,
55     DATA_PARTITION_USAGE_EVENT,
56     DEFAULT_APP,
57     QUERY_BUNDLE_INFO,
58 };
59 
60 enum class BundleEventType : uint8_t {
61     UNKNOW = 0,
62     INSTALL,
63     UNINSTALL,
64     UPDATE,
65     RECOVER,
66     QUICK_FIX
67 };
68 
69 enum class InstallScene : uint8_t {
70     NORMAL = 0,
71     BOOT,
72     REBOOT,
73     CREATE_USER,
74     REMOVE_USER,
75 };
76 
77 enum HiSysEventType : uint8_t {
78     FAULT     = 1,    // system fault event
79     STATISTIC = 2,    // system statistic event
80     SECURITY  = 3,    // system security event
81     BEHAVIOR  = 4     // system behavior event
82 };
83 
84 enum class UserEventType : uint8_t {
85     UNKNOW = 0,
86     CREATE_START = 1,
87     CREATE_END = 2,
88     REMOVE_START = 3,
89     REMOVE_END = 4,
90     CREATE_WITH_SKIP_PRE_INSTALL_START = 5,
91     CREATE_WITH_SKIP_PRE_INSTALL_END = 6,
92 };
93 
94 enum class ControlActionType : uint8_t {
95     INSTALL = 1,
96     RUNUING = 2,
97     DISPOSE_STATUS = 3,
98     DISPOSE_RULE = 4,
99     UNINSTALL_DISPOSE_RULE = 5,
100 };
101 
102 enum class ControlOperationType : uint8_t {
103     ADD_RULE = 1,
104     REMOVE_RULE = 2,
105 };
106 
107 enum class DB_OPERATION_TYPE : uint8_t {
108     CREATE = 1,
109     OPEN = 2,
110     INSERT = 3,
111     UPDATE = 4,
112     QUERY = 5,
113     DELETE = 6,
114     REBUILD = 7,
115 };
116 
117 enum class DefaultAppActionType : uint8_t {
118     SET = 1,
119     RESET = 2,
120 };
121 
122 struct EventInfo {
123     bool hideDesktopIcon = false;
124 
125     // only used for clean cache
126     bool isCleanCache = true;
127 
128     // only used for component disable or enable
129     bool isEnable = false;
130 
131     // only used for free install
132     bool isFreeInstallMode = false;
133 
134     //for free install event
135     bool isFreeInstall = false;
136 
137     // only used for preBundle
138     bool isPreInstallApp = false;
139 
140     // AOT
141     bool compileResult = false;
142 
143     bool isPatch = false;
144 
145     InstallScene preBundleScene = InstallScene::NORMAL;
146 
147     // only used in user event
148     UserEventType userEventType = UserEventType::UNKNOW;
149     int32_t userId = Constants::INVALID_USERID;
150 
151     // for quick fix
152     int32_t applyQuickFixFrequency = 0;
153 
154     // for install and uninstall
155     int32_t callingUid = 0;
156     int32_t appIndex = 0;
157     int32_t sceneId = 0;
158     int32_t operationType = 0;
159     int32_t actionType = 0;
160     uint32_t versionCode = 0;
161     uint32_t successCnt = 0;
162 
163     // only used in fault event
164     ErrCode errCode = ERR_OK;
165     int64_t costTimeSeconds = 0;
166     int64_t timeStamp = 0;
167     int64_t freeSize = 0;
168     int32_t errorCode = 0;
169     int32_t rebuildType = 0;
170     int64_t lastReportEventTime = 0;
171     std::string bundleName;
172     std::string moduleName;
173     std::string abilityName;
174     std::string packageName;
175     std::string applicationVersion;
176     std::string callingAppId;
177     std::string callingBundleName;
178     std::string dbName;
179     // only for install
180     std::string fingerprint;
181     std::string appDistributionType;
182     std::string compileMode;
183     std::string failureReason;
184     std::string processName;
185 
186     //for query of continue type
187     std::string continueType;
188     std::string fileName;
189     std::string callingName;
190     std::string rule;
191     std::vector<std::string> filePath;
192     std::vector<std::string> hashValue;
193     std::vector<std::string> totalBundleNames;
194     std::vector<std::string> appIds;
195     bool isIntercepted = false;
196     std::vector<uint64_t> fileSize;
197     std::vector<uint64_t> partitionSize;
198     std::vector<int32_t> funcIdList;
199     std::vector<int32_t> uidList;
200     std::vector<int32_t> userIdList;
201     std::vector<int32_t> appIndexList;
202     std::vector<int32_t> callingUidList;
203     std::vector<int32_t> flagList;
204     std::vector<std::string> bundleNameList;
205     std::vector<std::string> callingAppIdList;
206     std::vector<std::string> callingBundleNameList;
207 
208     std::string want;
209     std::string utd;
210 
ResetEventInfo211     void Reset()
212     {
213         userId = Constants::INVALID_USERID;
214         bundleName.clear();
215         moduleName.clear();
216         abilityName.clear();
217         packageName.clear();
218         applicationVersion.clear();
219         versionCode = 0;
220         timeStamp = 0;
221         preBundleScene = InstallScene::NORMAL;
222         isCleanCache = false;
223         isPreInstallApp = false;
224         isFreeInstallMode = false;
225         isEnable = false;
226         errCode = ERR_OK;
227         userEventType = UserEventType::UNKNOW;
228         callingUid = 0;
229         callingAppId.clear();
230         callingBundleName.clear();
231         filePath.clear();
232         fileSize.clear();
233         partitionSize.clear();
234         hashValue.clear();
235         fingerprint.clear();
236         hideDesktopIcon = false;
237         appDistributionType.clear();
238         applyQuickFixFrequency = 0;
239         totalBundleNames.clear();
240         successCnt = 0;
241         compileMode.clear();
242         compileResult = false;
243         failureReason.clear();
244         costTimeSeconds = 0;
245         continueType.clear();
246         sceneId = 0;
247         processName.clear();
248         appIndex = 0;
249         isFreeInstall = false;
250         fileName.clear();
251         freeSize = 0;
252         operationType = 0;
253         appIds.clear();
254         callingName.clear();
255         actionType = 0;
256         rule.clear();
257         dbName.clear();
258         errorCode = 0;
259         rebuildType = 0;
260         want.clear();
261         utd.clear();
262         funcIdList.clear();
263         uidList.clear();
264         userIdList.clear();
265         appIndexList.clear();
266         callingUidList.clear();
267         flagList.clear();
268         bundleNameList.clear();
269         callingAppIdList.clear();
270         callingBundleNameList.clear();
271     }
272 };
273 
274 class EventReport {
275 public:
276     /**
277      * @brief Send bundle system events.
278      * @param bundleEventType Indicates the bundle eventType.
279      * @param eventInfo Indicates the eventInfo.
280      */
281     static void SendBundleSystemEvent(BundleEventType bundleEventType, const EventInfo& eventInfo);
282     /**
283      * @brief Send scan system events.
284      * @param bMSEventType Indicates the bMSEventType.
285      */
286     static void SendScanSysEvent(BMSEventType bMSEventType);
287     /**
288      * @brief Send component diable or enable system events.
289      * @param bundleName Indicates the bundleName.
290      * @param abilityName Indicates the abilityName.
291      * @param userId Indicates the userId.
292      * @param isEnable Indicates the isEnable.
293      * @param appIndex Indicates the app index for clone app.
294      */
295     static void SendComponentStateSysEventForException(const std::string &bundleName, const std::string &abilityName,
296         int32_t userId, bool isEnable, int32_t appIndex, const std::string &callingName);
297     /**
298      * @brief Send component diable or enable system events.
299      * @param bundleName Indicates the bundleName.
300      * @param abilityName Indicates the abilityName.
301      * @param userId Indicates the userId.
302      * @param isEnable Indicates the isEnable.
303      * @param appIndex Indicates the app index for clone app.
304      */
305     static void SendComponentStateSysEvent(const std::string &bundleName, const std::string &abilityName,
306         int32_t userId, bool isEnable, int32_t appIndex, const std::string &callingName);
307     /**
308      * @brief Send clean cache system events.
309      * @param bundleName Indicates the bundleName.
310      * @param userId Indicates the userId.
311      * @param isCleanCache Indicates the isCleanCache.
312      * @param exception Indicates the exception.
313      */
314     static void SendCleanCacheSysEvent(
315         const std::string &bundleName, int32_t userId, bool isCleanCache, bool exception,
316         int32_t callingUid, const std::string &callingBundleName);
317     /**
318      * @brief Send clean cache system events.
319      * @param bundleName Indicates the bundleName.
320      * @param userId Indicates the userId.
321      * @param appIndex Indicates the appIndex.
322      * @param isCleanCache Indicates the isCleanCache.
323      * @param exception Indicates the exception.
324      */
325     static void SendCleanCacheSysEventWithIndex(
326         const std::string &bundleName, int32_t userId, int32_t appIndex, bool isCleanCache, bool exception,
327         int32_t callingUid, const std::string &callingBundleName);
328     /**
329      * @brief Send system events.
330      * @param eventType Indicates the bms eventInfo.
331      * @param eventInfo Indicates the eventInfo.
332      */
333     static void SendSystemEvent(BMSEventType eventType, const EventInfo& eventInfo);
334     /**
335      * @brief Send user system events.
336      * @param userEventType Indicates the userEventType.
337      * @param userId Indicates the userId.
338      */
339     static void SendUserSysEvent(UserEventType userEventType, int32_t userId);
340 
341     /**
342      * @brief Send query abilityInfos by continueType system events.
343      * @param bundleName Indicates the bundleName.
344      * @param abilityName Indicates the abilityName.
345      * @param errCode code of result.
346      * @param continueType Indicates the continueType.
347      */
348     static void SendQueryAbilityInfoByContinueTypeSysEvent(const std::string &bundleName,
349         const std::string &abilityName, ErrCode errCode, int32_t userId, const std::string &continueType);
350 
351     static void SendCpuSceneEvent(const std::string &processName, const int32_t sceneId);
352     /**
353      *@brief send free install event
354      *@param bundleName Indicates the bundleName.
355      *@param abilityName Indicates the abilityName.
356      *@param moduleName Indicates the moduleName.
357      *@param isFreeInstall Indicates the isFreeInstall.
358      *@param timeStamp Indicates the timeStamp.
359      */
360     static void SendFreeInstallEvent(const std::string &bundleName, const std::string &abilityName,
361         const std::string &moduleName, bool isFreeInstall, int64_t timeStamp);
362 
363     /**
364      * @brief Send system events the disk space in insufficient when an applicaiton is begin installed ir uninstall .
365      * @param fileName file name.
366      * @param freeSize free size.
367      * @param operationType operation type.
368      */
369     static void SendDiskSpaceEvent(const std::string &fileName,
370         int64_t freeSize, int32_t operationType);
371 
372     /**
373      * @brief Send info when add or remove app contitol rule.
374      * @param eventInfo report info.
375      */
376     static void SendAppControlRuleEvent(const EventInfo& eventInfo);
377 
378     /**
379      * @brief Send system event when DB occur error.
380      * @param dbName DB name.
381      * @param operationType DB operation type.
382      * @param errorCode DB error code.
383      * @param rebuildType DB rebuild type.
384      */
385     static void SendDbErrorEvent(const std::string &dbName, int32_t operationType, int32_t errorCode);
386 
387     /**
388      * @brief process is intercepted.
389      * @param eventInfo event info.
390      */
391     static EventInfo ProcessIsIntercepted(const EventInfo &eventInfo);
392 
393     /**
394      * @brief rport the usage event of data partition.
395      */
396     static void ReportDataPartitionUsageEvent();
397 
398     /**
399      * @brief Send info when set or reset default app.
400      * @param actionType set default app method type.
401      * @param userId Indicates the userId.
402      * @param callingName Indicates method caller
403      * @param want Indicates the want
404      * @param utd Indicates the utd
405      */
406     static void SendDefaultAppEvent(DefaultAppActionType actionType, int32_t userId, const std::string& callingName,
407         const std::string& want, const std::string& utd);
408 };
409 }  // namespace AppExecFwk
410 }  // namespace OHOS
411 #endif  // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_EVENT_REPORT_H
412