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