• 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 #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 };
56 
57 enum class BundleEventType : uint8_t {
58     UNKNOW = 0,
59     INSTALL,
60     UNINSTALL,
61     UPDATE,
62     RECOVER,
63     QUICK_FIX
64 };
65 
66 enum class InstallScene : uint8_t {
67     NORMAL = 0,
68     BOOT,
69     REBOOT,
70     CREATE_USER,
71     REMOVE_USER,
72 };
73 
74 enum HiSysEventType : uint8_t {
75     FAULT     = 1,    // system fault event
76     STATISTIC = 2,    // system statistic event
77     SECURITY  = 3,    // system security event
78     BEHAVIOR  = 4     // system behavior event
79 };
80 
81 enum class UserEventType : uint8_t {
82     UNKNOW = 0,
83     CREATE_START = 1,
84     CREATE_END = 2,
85     REMOVE_START = 3,
86     REMOVE_END = 4,
87     CREATE_WITH_SKIP_PRE_INSTALL_START = 5,
88     CREATE_WITH_SKIP_PRE_INSTALL_END = 6,
89 };
90 
91 enum class ACTION_TYPE_ENUM : uint8_t {
92     ACTION_TYPE_OF_INSTALL = 1,
93     ACTION_TYPE_OF_RUNUING = 2,
94     ACTION_TYPE_DISPOSE_STATUS = 3,
95     ACTION_TYPE_DISPOSE_RULE = 4,
96     ACTION_TYPE_UNINSTALL_DISPOSE_RULE = 5,
97 };
98 
99 enum class OPERATION_TYPE_ENUM : uint8_t {
100     OPERATION_TYPE_ADD_RULE = 1,
101     OPERATION_TYPE_REMOVE_RULE = 2,
102 };
103 
104 enum class DB_OPERATION_TYPE : uint8_t {
105     CREATE = 1,
106     OPEN = 2,
107     INSERT = 3,
108     UPDATE = 4,
109     QUERY = 5,
110     DELETE = 6,
111     REBUILD = 7,
112 };
113 
114 struct EventInfo {
115     bool hideDesktopIcon = false;
116 
117     // only used for clean cache
118     bool isCleanCache = true;
119 
120     // only used for component disable or enable
121     bool isEnable = false;
122 
123     // only used for free install
124     bool isFreeInstallMode = false;
125 
126     //for free install event
127     bool isFreeInstall = false;
128 
129     // only used for preBundle
130     bool isPreInstallApp = false;
131 
132     // AOT
133     bool compileResult = false;
134     InstallScene preBundleScene = InstallScene::NORMAL;
135 
136     // only used in user event
137     UserEventType userEventType = UserEventType::UNKNOW;
138     int32_t userId = Constants::INVALID_USERID;
139 
140     // for quick fix
141     int32_t applyQuickFixFrequency = 0;
142 
143     // for install and uninstall
144     int32_t callingUid = 0;
145     int32_t appIndex = 0;
146     int32_t sceneId = 0;
147     int32_t operationType = 0;
148     int32_t actionType = 0;
149     uint32_t versionCode = 0;
150     uint32_t successCnt = 0;
151 
152     // only used in fault event
153     ErrCode errCode = ERR_OK;
154     int64_t costTimeSeconds = 0;
155     int64_t timeStamp = 0;
156     int64_t freeSize = 0;
157     int32_t errorCode = 0;
158     int32_t rebuildType = 0;
159     std::string bundleName;
160     std::string moduleName;
161     std::string abilityName;
162     std::string packageName;
163     std::string applicationVersion;
164     std::string callingAppId;
165     std::string callingBundleName;
166     std::string dbName;
167     // only for install
168     std::string fingerprint;
169     std::string appDistributionType;
170     std::string compileMode;
171     std::string failureReason;
172     std::string processName;
173 
174     //for query of continue type
175     std::string continueType;
176     std::string fileName;
177     std::string callingName;
178     std::string rule;
179     std::vector<std::string> filePath;
180     std::vector<std::string> hashValue;
181     std::vector<std::string> totalBundleNames;
182     std::vector<std::string> appIds;
183 
ResetEventInfo184     void Reset()
185     {
186         userId = Constants::INVALID_USERID;
187         bundleName.clear();
188         moduleName.clear();
189         abilityName.clear();
190         packageName.clear();
191         applicationVersion.clear();
192         versionCode = 0;
193         timeStamp = 0;
194         preBundleScene = InstallScene::NORMAL;
195         isCleanCache = false;
196         isPreInstallApp = false;
197         isFreeInstallMode = false;
198         isEnable = false;
199         errCode = ERR_OK;
200         userEventType = UserEventType::UNKNOW;
201         callingUid = 0;
202         callingAppId.clear();
203         callingBundleName.clear();
204         filePath.clear();
205         hashValue.clear();
206         fingerprint.clear();
207         hideDesktopIcon = false;
208         appDistributionType.clear();
209         applyQuickFixFrequency = 0;
210         totalBundleNames.clear();
211         successCnt = 0;
212         compileMode.clear();
213         compileResult = false;
214         failureReason.clear();
215         costTimeSeconds = 0;
216         continueType.clear();
217         sceneId = 0;
218         processName.clear();
219         appIndex = 0;
220         isFreeInstall = false;
221         fileName.clear();
222         freeSize = 0;
223         operationType = 0;
224         appIds.clear();
225         callingName.clear();
226         actionType = 0;
227         rule.clear();
228         dbName.clear();
229         errorCode = 0;
230         rebuildType = 0;
231     }
232 };
233 
234 class EventReport {
235 public:
236     /**
237      * @brief Send bundle system events.
238      * @param bundleEventType Indicates the bundle eventType.
239      * @param eventInfo Indicates the eventInfo.
240      */
241     static void SendBundleSystemEvent(BundleEventType bundleEventType, const EventInfo& eventInfo);
242     /**
243      * @brief Send scan system events.
244      * @param bMSEventType Indicates the bMSEventType.
245      */
246     static void SendScanSysEvent(BMSEventType bMSEventType);
247     /**
248      * @brief Send component diable or enable system events.
249      * @param bundleName Indicates the bundleName.
250      * @param abilityName Indicates the abilityName.
251      * @param userId Indicates the userId.
252      * @param isEnable Indicates the isEnable.
253      * @param appIndex Indicates the app index for clone app.
254      */
255     static void SendComponentStateSysEventForException(const std::string &bundleName, const std::string &abilityName,
256         int32_t userId, bool isEnable, int32_t appIndex, const std::string &callingName);
257     /**
258      * @brief Send component diable or enable system events.
259      * @param bundleName Indicates the bundleName.
260      * @param abilityName Indicates the abilityName.
261      * @param userId Indicates the userId.
262      * @param isEnable Indicates the isEnable.
263      * @param appIndex Indicates the app index for clone app.
264      */
265     static void SendComponentStateSysEvent(const std::string &bundleName, const std::string &abilityName,
266         int32_t userId, bool isEnable, int32_t appIndex, const std::string &callingName);
267     /**
268      * @brief Send clean cache system events.
269      * @param bundleName Indicates the bundleName.
270      * @param userId Indicates the userId.
271      * @param isCleanCache Indicates the isCleanCache.
272      * @param exception Indicates the exception.
273      */
274     static void SendCleanCacheSysEvent(
275         const std::string &bundleName, int32_t userId, bool isCleanCache, bool exception);
276     /**
277      * @brief Send clean cache system events.
278      * @param bundleName Indicates the bundleName.
279      * @param userId Indicates the userId.
280      * @param appIndex Indicates the appIndex.
281      * @param isCleanCache Indicates the isCleanCache.
282      * @param exception Indicates the exception.
283      */
284     static void SendCleanCacheSysEventWithIndex(
285         const std::string &bundleName, int32_t userId, int32_t appIndex, bool isCleanCache, bool exception);
286     /**
287      * @brief Send system events.
288      * @param eventType Indicates the bms eventInfo.
289      * @param eventInfo Indicates the eventInfo.
290      */
291     static void SendSystemEvent(BMSEventType eventType, const EventInfo& eventInfo);
292     /**
293      * @brief Send user system events.
294      * @param userEventType Indicates the userEventType.
295      * @param userId Indicates the userId.
296      */
297     static void SendUserSysEvent(UserEventType userEventType, int32_t userId);
298 
299     /**
300      * @brief Send query abilityInfos by continueType system events.
301      * @param bundleName Indicates the bundleName.
302      * @param abilityName Indicates the abilityName.
303      * @param errCode code of result.
304      * @param continueType Indicates the continueType.
305      */
306     static void SendQueryAbilityInfoByContinueTypeSysEvent(const std::string &bundleName,
307         const std::string &abilityName, ErrCode errCode, int32_t userId, const std::string &continueType);
308 
309     static void SendCpuSceneEvent(const std::string &processName, const int32_t sceneId);
310     /**
311      *@brief send free install event
312      *@param bundleName Indicates the bundleName.
313      *@param abilityName Indicates the abilityName.
314      *@param moduleName Indicates the moduleName.
315      *@param isFreeInstall Indicates the isFreeInstall.
316      *@param timeStamp Indicates the timeStamp.
317      */
318     static void SendFreeInstallEvent(const std::string &bundleName, const std::string &abilityName,
319         const std::string &moduleName, bool isFreeInstall, int64_t timeStamp);
320 
321     /**
322      * @brief Send system events the disk space in insufficient when an applicaiton is begin installed ir uninstall .
323      * @param fileName file name.
324      * @param freeSize free size.
325      * @param operationType operation type.
326      */
327     static void SendDiskSpaceEvent(const std::string &fileName,
328         int64_t freeSize, int32_t operationType);
329 
330     /**
331      * @brief Send info when add or remove app contitol rule.
332      * @param eventInfo report info.
333      */
334     static void SendAppControlRuleEvent(const EventInfo& eventInfo);
335 
336     /**
337      * @brief Send system event when DB occur error.
338      * @param dbName DB name.
339      * @param operationType DB operation type.
340      * @param errorCode DB error code.
341      * @param rebuildType DB rebuild type.
342      */
343     static void SendDbErrorEvent(const std::string &dbName, int32_t operationType, int32_t errorCode);
344 };
345 }  // namespace AppExecFwk
346 }  // namespace OHOS
347 #endif  // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_EVENT_REPORT_H
348