1 /* 2 * Copyright (c) 2022 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 21 #include "appexecfwk_errors.h" 22 #include "bundle_constants.h" 23 24 namespace OHOS { 25 namespace AppExecFwk { 26 enum class BMSEventType { 27 UNKNOW = 0, 28 /***********FAULT EVENT**************/ 29 BUNDLE_INSTALL_EXCEPTION, 30 BUNDLE_UNINSTALL_EXCEPTION, 31 BUNDLE_UPDATE_EXCEPTION, 32 PRE_BUNDLE_RECOVER_EXCEPTION, 33 BUNDLE_STATE_CHANGE_EXCEPTION, 34 BUNDLE_CLEAN_CACHE_EXCEPTION, 35 /***********BEHAVIOR EVENT***********/ 36 BOOT_SCAN_START, 37 BOOT_SCAN_END, 38 BUNDLE_INSTALL, 39 BUNDLE_UNINSTALL, 40 BUNDLE_UPDATE, 41 PRE_BUNDLE_RECOVER, 42 BUNDLE_STATE_CHANGE, 43 BUNDLE_CLEAN_CACHE, 44 }; 45 46 enum class BundleEventType { 47 UNKNOW = 0, 48 INSTALL, 49 UNINSTALL, 50 UPDATE, 51 RECOVER, 52 }; 53 54 enum class InstallScene { 55 NORMAL = 0, 56 BOOT, 57 REBOOT, 58 CREATE_USER, 59 REMOVE_USER, 60 }; 61 62 enum HiSysEventType { 63 FAULT = 1, // system fault event 64 STATISTIC = 2, // system statistic event 65 SECURITY = 3, // system security event 66 BEHAVIOR = 4 // system behavior event 67 }; 68 69 struct EventInfo { 70 int32_t userId = Constants::INVALID_USERID; 71 std::string bundleName; 72 std::string moduleName; 73 std::string abilityName; 74 int64_t timeStamp = 0; 75 uint32_t versionCode = 0; 76 77 // olny used for preBundle 78 bool isPreInstallApp = false; 79 InstallScene preBundleScene = InstallScene::NORMAL; 80 81 // olny used for clean cache 82 bool isCleanCache = true; 83 84 // olny used for component diable or enable 85 bool isEnable = false; 86 87 // olny used for free install 88 bool isFreeInstallMode = false; 89 90 // olny used in fault event 91 ErrCode errCode = ERR_OK; 92 ResetEventInfo93 void Reset() 94 { 95 userId = Constants::INVALID_USERID; 96 bundleName.clear(); 97 moduleName.clear(); 98 abilityName.clear(); 99 versionCode = 0; 100 timeStamp = 0; 101 preBundleScene = InstallScene::NORMAL; 102 isCleanCache = false; 103 isPreInstallApp = false; 104 isFreeInstallMode = false; 105 isEnable = false; 106 errCode = ERR_OK; 107 } 108 }; 109 110 class EventReport { 111 public: 112 /** 113 * @brief Send bundle system events. 114 * @param bundleEventType Indicates the bundle eventType. 115 * @param eventInfo Indicates the eventInfo. 116 */ 117 static void SendBundleSystemEvent(BundleEventType bundleEventType, const EventInfo& eventInfo); 118 /** 119 * @brief Send scan system events. 120 * @param bMSEventType Indicates the bMSEventType. 121 */ 122 static void SendScanSysEvent(BMSEventType bMSEventType); 123 /** 124 * @brief Send component diable or enable system events. 125 * @param bundleName Indicates the bundleName. 126 * @param abilityName Indicates the abilityName. 127 * @param userId Indicates the userId. 128 * @param isEnable Indicates the isEnable. 129 * @param exception Indicates the exception. 130 */ 131 static void SendComponentStateSysEvent(const std::string &bundleName, 132 const std::string &abilityName, int32_t userId, bool isEnable, bool exception); 133 /** 134 * @brief Send clean cache system events. 135 * @param bundleName Indicates the bundleName. 136 * @param userId Indicates the userId. 137 * @param isCleanCache Indicates the isCleanCache. 138 * @param exception Indicates the exception. 139 */ 140 static void SendCleanCacheSysEvent( 141 const std::string &bundleName, int32_t userId, bool isCleanCache, bool exception); 142 /** 143 * @brief Send system events. 144 * @param eventType Indicates the bms eventInfo. 145 * @param eventInfo Indicates the eventInfo. 146 */ 147 static void SendSystemEvent(BMSEventType eventType, const EventInfo& eventInfo); 148 }; 149 } // namespace AppExecFwk 150 } // namespace OHOS 151 #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_EVENT_REPORT_H 152