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