1 /* 2 * Copyright (c) 2022-2023 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 }; 48 49 enum class BundleEventType { 50 UNKNOW = 0, 51 INSTALL, 52 UNINSTALL, 53 UPDATE, 54 RECOVER, 55 QUICK_FIX 56 }; 57 58 enum class InstallScene { 59 NORMAL = 0, 60 BOOT, 61 REBOOT, 62 CREATE_USER, 63 REMOVE_USER, 64 }; 65 66 enum HiSysEventType { 67 FAULT = 1, // system fault event 68 STATISTIC = 2, // system statistic event 69 SECURITY = 3, // system security event 70 BEHAVIOR = 4 // system behavior event 71 }; 72 73 enum class UserEventType { 74 UNKNOW = 0, 75 CREATE_START, 76 CREATE_END, 77 REMOVE_START, 78 REMOVE_END, 79 }; 80 81 struct EventInfo { 82 int32_t userId = Constants::INVALID_USERID; 83 std::string bundleName; 84 std::string moduleName; 85 std::string abilityName; 86 int64_t timeStamp = 0; 87 uint32_t versionCode = 0; 88 89 // for install and uninstall 90 int32_t callingUid = 0; 91 std::string callingAppId; 92 std::string callingBundleName; 93 std::vector<std::string> filePath; 94 std::vector<std::string> hashValue; 95 // only for install 96 std::string fingerprint; 97 bool hideDesktopIcon = false; 98 std::string appDistributionType; 99 100 // only used for preBundle 101 bool isPreInstallApp = false; 102 InstallScene preBundleScene = InstallScene::NORMAL; 103 104 // only used for clean cache 105 bool isCleanCache = true; 106 107 // only used for component disable or enable 108 bool isEnable = false; 109 110 // only used for free install 111 bool isFreeInstallMode = false; 112 113 // only used in fault event 114 ErrCode errCode = ERR_OK; 115 116 // only used in user event 117 UserEventType userEventType = UserEventType::UNKNOW; 118 119 // for quick fix 120 int32_t applyQuickFixFrequency = 0; 121 ResetEventInfo122 void Reset() 123 { 124 userId = Constants::INVALID_USERID; 125 bundleName.clear(); 126 moduleName.clear(); 127 abilityName.clear(); 128 versionCode = 0; 129 timeStamp = 0; 130 preBundleScene = InstallScene::NORMAL; 131 isCleanCache = false; 132 isPreInstallApp = false; 133 isFreeInstallMode = false; 134 isEnable = false; 135 errCode = ERR_OK; 136 userEventType = UserEventType::UNKNOW; 137 callingUid = 0; 138 callingAppId.clear(); 139 callingBundleName.clear(); 140 filePath.clear(); 141 hashValue.clear(); 142 fingerprint.clear(); 143 hideDesktopIcon = false; 144 appDistributionType.clear(); 145 applyQuickFixFrequency = 0; 146 } 147 }; 148 149 class EventReport { 150 public: 151 /** 152 * @brief Send bundle system events. 153 * @param bundleEventType Indicates the bundle eventType. 154 * @param eventInfo Indicates the eventInfo. 155 */ 156 static void SendBundleSystemEvent(BundleEventType bundleEventType, const EventInfo& eventInfo); 157 /** 158 * @brief Send scan system events. 159 * @param bMSEventType Indicates the bMSEventType. 160 */ 161 static void SendScanSysEvent(BMSEventType bMSEventType); 162 /** 163 * @brief Send component diable or enable system events. 164 * @param bundleName Indicates the bundleName. 165 * @param abilityName Indicates the abilityName. 166 * @param userId Indicates the userId. 167 * @param isEnable Indicates the isEnable. 168 * @param exception Indicates the exception. 169 */ 170 static void SendComponentStateSysEvent(const std::string &bundleName, 171 const std::string &abilityName, int32_t userId, bool isEnable, bool exception); 172 /** 173 * @brief Send clean cache system events. 174 * @param bundleName Indicates the bundleName. 175 * @param userId Indicates the userId. 176 * @param isCleanCache Indicates the isCleanCache. 177 * @param exception Indicates the exception. 178 */ 179 static void SendCleanCacheSysEvent( 180 const std::string &bundleName, int32_t userId, bool isCleanCache, bool exception); 181 /** 182 * @brief Send system events. 183 * @param eventType Indicates the bms eventInfo. 184 * @param eventInfo Indicates the eventInfo. 185 */ 186 static void SendSystemEvent(BMSEventType eventType, const EventInfo& eventInfo); 187 /** 188 * @brief Send user system events. 189 * @param userEventType Indicates the userEventType. 190 * @param userId Indicates the userId. 191 */ 192 static void SendUserSysEvent(UserEventType userEventType, int32_t userId); 193 }; 194 } // namespace AppExecFwk 195 } // namespace OHOS 196 #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_EVENT_REPORT_H 197