• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "event_report.h"
17 
18 #include "app_log_wrapper.h"
19 #include "bundle_util.h"
20 #ifdef HISYSEVENT_ENABLE
21 #include "inner_event_report.h"
22 #endif
23 
24 namespace OHOS {
25 namespace AppExecFwk {
26 namespace {
27 const BundleEventType BUNDLE_EXCEPTION_SYS_EVENT_MAP_KEY[] = {
28     BundleEventType::INSTALL, BundleEventType::UNINSTALL,
29     BundleEventType::UPDATE, BundleEventType::RECOVER
30 };
31 const BMSEventType BUNDLE_EXCEPTION_SYS_EVENT_MAP_VALUE[] = {
32     BMSEventType::BUNDLE_INSTALL_EXCEPTION, BMSEventType::BUNDLE_UNINSTALL_EXCEPTION,
33     BMSEventType::BUNDLE_UPDATE_EXCEPTION, BMSEventType::PRE_BUNDLE_RECOVER_EXCEPTION
34 };
35 
36 const BundleEventType BUNDLE_SYS_EVENT_MAP_KEY[] = {
37     BundleEventType::INSTALL, BundleEventType::UNINSTALL,
38     BundleEventType::UPDATE, BundleEventType::RECOVER,
39     BundleEventType::QUICK_FIX,
40 };
41 const BMSEventType BUNDLE_SYS_EVENT_MAP_VALUE[] = {
42     BMSEventType::BUNDLE_INSTALL, BMSEventType::BUNDLE_UNINSTALL,
43     BMSEventType::BUNDLE_UPDATE, BMSEventType::PRE_BUNDLE_RECOVER,
44     BMSEventType::APPLY_QUICK_FIX,
45 };
46 }
47 
SendBundleSystemEvent(BundleEventType bundleEventType,const EventInfo & eventInfo)48 void EventReport::SendBundleSystemEvent(BundleEventType bundleEventType, const EventInfo& eventInfo)
49 {
50     BMSEventType bmsEventType = BMSEventType::UNKNOW;
51     if (eventInfo.errCode != ERR_OK) {
52         size_t len = sizeof(BUNDLE_EXCEPTION_SYS_EVENT_MAP_KEY) / sizeof(BundleEventType);
53         for (size_t i = 0; i < len; i++) {
54             if (bundleEventType == BUNDLE_EXCEPTION_SYS_EVENT_MAP_KEY[i]) {
55                 bmsEventType = BUNDLE_EXCEPTION_SYS_EVENT_MAP_VALUE[i];
56                 break;
57             }
58         }
59         SendSystemEvent(bmsEventType, eventInfo);
60         return;
61     }
62 
63     size_t len = sizeof(BUNDLE_SYS_EVENT_MAP_KEY) / sizeof(BundleEventType);
64     for (size_t i = 0; i < len; i++) {
65         if (bundleEventType == BUNDLE_SYS_EVENT_MAP_KEY[i]) {
66             bmsEventType = BUNDLE_SYS_EVENT_MAP_VALUE[i];
67             break;
68         }
69     }
70 
71     SendSystemEvent(bmsEventType, eventInfo);
72 }
73 
SendScanSysEvent(BMSEventType bMSEventType)74 void EventReport::SendScanSysEvent(BMSEventType bMSEventType)
75 {
76     EventInfo eventInfo;
77     eventInfo.timeStamp = BundleUtil::GetCurrentTimeMs();
78     EventReport::SendSystemEvent(bMSEventType, eventInfo);
79 }
80 
SendUserSysEvent(UserEventType userEventType,int32_t userId)81 void EventReport::SendUserSysEvent(UserEventType userEventType, int32_t userId)
82 {
83     EventInfo eventInfo;
84     eventInfo.timeStamp = BundleUtil::GetCurrentTimeMs();
85     eventInfo.userId = userId;
86     eventInfo.userEventType = userEventType;
87     EventReport::SendSystemEvent(BMSEventType::BMS_USER_EVENT, eventInfo);
88 }
89 
SendComponentStateSysEventForException(const std::string & bundleName,const std::string & abilityName,int32_t userId,bool isEnable,int32_t appIndex,const std::string & caller)90 void EventReport::SendComponentStateSysEventForException(const std::string &bundleName, const std::string &abilityName,
91     int32_t userId, bool isEnable, int32_t appIndex, const std::string &caller)
92 {
93     EventInfo eventInfo;
94     eventInfo.bundleName = bundleName;
95     eventInfo.abilityName = abilityName;
96     eventInfo.userId = userId;
97     eventInfo.isEnable = isEnable;
98     eventInfo.appIndex = appIndex;
99     eventInfo.callingBundleName = caller;
100     BMSEventType bmsEventType = BMSEventType::BUNDLE_STATE_CHANGE_EXCEPTION;
101 
102     EventReport::SendSystemEvent(bmsEventType, eventInfo);
103 }
104 
SendComponentStateSysEvent(const std::string & bundleName,const std::string & abilityName,int32_t userId,bool isEnable,int32_t appIndex,const std::string & caller)105 void EventReport::SendComponentStateSysEvent(const std::string &bundleName, const std::string &abilityName,
106     int32_t userId, bool isEnable, int32_t appIndex, const std::string &caller)
107 {
108     EventInfo eventInfo;
109     eventInfo.bundleName = bundleName;
110     eventInfo.abilityName = abilityName;
111     eventInfo.userId = userId;
112     eventInfo.isEnable = isEnable;
113     eventInfo.appIndex = appIndex;
114     eventInfo.callingBundleName = caller;
115     BMSEventType bmsEventType = BMSEventType::BUNDLE_STATE_CHANGE;
116 
117     EventReport::SendSystemEvent(bmsEventType, eventInfo);
118 }
119 
SendCleanCacheSysEvent(const std::string & bundleName,int32_t userId,bool isCleanCache,bool exception)120 void EventReport::SendCleanCacheSysEvent(
121     const std::string &bundleName, int32_t userId, bool isCleanCache, bool exception)
122 {
123     EventInfo eventInfo;
124     eventInfo.bundleName = bundleName;
125     eventInfo.userId = userId;
126     eventInfo.isCleanCache = isCleanCache;
127     BMSEventType bmsEventType;
128     if (exception) {
129         bmsEventType = BMSEventType::BUNDLE_CLEAN_CACHE_EXCEPTION;
130     } else {
131         bmsEventType = BMSEventType::BUNDLE_CLEAN_CACHE;
132     }
133 
134     EventReport::SendSystemEvent(bmsEventType, eventInfo);
135 }
136 
SendCleanCacheSysEventWithIndex(const std::string & bundleName,int32_t userId,int32_t appIndex,bool isCleanCache,bool exception)137 void EventReport::SendCleanCacheSysEventWithIndex(
138     const std::string &bundleName, int32_t userId, int32_t appIndex, bool isCleanCache, bool exception)
139 {
140     EventInfo eventInfo;
141     eventInfo.bundleName = bundleName;
142     eventInfo.userId = userId;
143     eventInfo.appIndex = appIndex;
144     eventInfo.isCleanCache = isCleanCache;
145     BMSEventType bmsEventType;
146     if (exception) {
147         bmsEventType = BMSEventType::BUNDLE_CLEAN_CACHE_EXCEPTION;
148     } else {
149         bmsEventType = BMSEventType::BUNDLE_CLEAN_CACHE;
150     }
151 
152     EventReport::SendSystemEvent(bmsEventType, eventInfo);
153 }
154 
SendQueryAbilityInfoByContinueTypeSysEvent(const std::string & bundleName,const std::string & abilityName,ErrCode errCode,int32_t userId,const std::string & continueType)155 void EventReport::SendQueryAbilityInfoByContinueTypeSysEvent(const std::string &bundleName,
156     const std::string &abilityName, ErrCode errCode, int32_t userId, const std::string &continueType)
157 {
158     EventInfo eventInfo;
159     eventInfo.bundleName = bundleName;
160     eventInfo.abilityName = abilityName;
161     eventInfo.errCode = errCode;
162     eventInfo.continueType = continueType;
163     eventInfo.userId = userId,
164     EventReport::SendSystemEvent(BMSEventType::QUERY_OF_CONTINUE_TYPE, eventInfo);
165 }
166 
SendCpuSceneEvent(const std::string & processName,const int32_t sceneId)167 void EventReport::SendCpuSceneEvent(const std::string &processName, const int32_t sceneId)
168 {
169     EventInfo eventInfo;
170     eventInfo.sceneId = sceneId;
171     eventInfo.processName = processName;
172     eventInfo.timeStamp = BundleUtil::GetCurrentTimeMs();
173     EventReport::SendSystemEvent(BMSEventType::CPU_SCENE_ENTRY, eventInfo);
174 }
175 
SendFreeInstallEvent(const std::string & bundleName,const std::string & abilityName,const std::string & moduleName,bool isFreeInstall,int64_t timeStamp)176 void EventReport::SendFreeInstallEvent(const std::string &bundleName, const std::string &abilityName,
177     const std::string &moduleName, bool isFreeInstall, int64_t timeStamp)
178 {
179     EventInfo eventInfo;
180     eventInfo.bundleName = bundleName;
181     eventInfo.abilityName = abilityName;
182     eventInfo.moduleName = moduleName;
183     eventInfo.isFreeInstall = isFreeInstall;
184     eventInfo.timeStamp = timeStamp;
185     EventReport::SendSystemEvent(BMSEventType::FREE_INSTALL_EVENT, eventInfo);
186 }
187 
SendDiskSpaceEvent(const std::string & fileName,int64_t freeSize,int32_t operationType)188 void EventReport::SendDiskSpaceEvent(const std::string &fileName,
189     int64_t freeSize, int32_t operationType)
190 {
191     EventInfo eventInfo;
192     eventInfo.fileName = fileName;
193     eventInfo.freeSize = freeSize;
194     eventInfo.operationType = operationType;
195     EventReport::SendSystemEvent(BMSEventType::BMS_DISK_SPACE, eventInfo);
196 }
197 
SendAppControlRuleEvent(const EventInfo & eventInfo)198 void EventReport::SendAppControlRuleEvent(const EventInfo& eventInfo)
199 {
200     EventReport::SendSystemEvent(BMSEventType::APP_CONTROL_RULE, eventInfo);
201 }
202 
SendDbErrorEvent(const std::string & dbName,int32_t operationType,int32_t errorCode)203 void EventReport::SendDbErrorEvent(const std::string &dbName, int32_t operationType, int32_t errorCode)
204 {
205     APP_LOGI("SendDbErrorEvent dbname:%{public}s operation:%{public}d", dbName.c_str(), operationType);
206     EventInfo eventInfo;
207     eventInfo.dbName = dbName;
208     eventInfo.operationType = operationType;
209     eventInfo.errorCode = errorCode;
210     EventReport::SendSystemEvent(BMSEventType::DB_ERROR, eventInfo);
211 }
212 
SendSystemEvent(BMSEventType bmsEventType,const EventInfo & eventInfo)213 void EventReport::SendSystemEvent(BMSEventType bmsEventType, const EventInfo& eventInfo)
214 {
215 #ifdef HISYSEVENT_ENABLE
216     InnerEventReport::SendSystemEvent(bmsEventType, eventInfo);
217 #else
218     APP_LOGD("Hisysevent is disabled");
219 #endif
220 }
221 }  // namespace AppExecFwk
222 }  // namespace OHOS