1 /*
2 * Copyright (c) 2023-2025 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 "ability_event_util.h"
17 #include "app_scheduler.h"
18 #include "hilog_tag_wrapper.h"
19
20 namespace OHOS {
21 namespace AAFwk {
22 constexpr int32_t FFRT_TASK_TIMEOUT = 5 * 1000 * 1000; // 5s
HandleModuleInfoUpdated(const std::string & bundleName,const int uid,const std::string & moduleName,bool isPlugin)23 void AbilityEventUtil::HandleModuleInfoUpdated(const std::string &bundleName, const int uid,
24 const std::string& moduleName, bool isPlugin)
25 {
26 TAG_LOGD(AAFwkTag::ABILITYMGR, "HandleModuleInfoUpdated start.");
27 DelayedSingleton<AppScheduler>::GetInstance()->UpdateApplicationInfoInstalled(bundleName, uid, moduleName,
28 isPlugin);
29 }
30
SendStartAbilityErrorEvent(EventInfo & eventInfo,int32_t errCode,const std::string errMsg,bool isSystemError)31 void AbilityEventUtil::SendStartAbilityErrorEvent(EventInfo &eventInfo, int32_t errCode, const std::string errMsg,
32 bool isSystemError)
33 {
34 if (errCode == ERR_OK) {
35 return;
36 }
37 EventName name = isSystemError ? EventName::START_ABILITY_SYSTEM_ERROR : EventName::START_ABILITY_ERROR;
38 eventInfo.errCode = errCode;
39 eventInfo.errMsg = errMsg;
40 ffrt::submit([name, eventInfo]() {
41 EventReport::SendAbilityEvent(name, HiSysEventType::FAULT, eventInfo);
42 }, ffrt::task_attr().timeout(FFRT_TASK_TIMEOUT));
43 }
44
SendKillProcessWithReasonEvent(int32_t errCode,const std::string & errMsg,EventInfo & eventInfo)45 void AbilityEventUtil::SendKillProcessWithReasonEvent(int32_t errCode, const std::string &errMsg, EventInfo &eventInfo)
46 {
47 EventName name = EventName::KILL_PROCESS_WITH_REASON;
48 eventInfo.errCode = errCode;
49 eventInfo.errMsg = errMsg;
50 ffrt::submit([name, eventInfo]() {
51 EventReport::SendAbilityEvent(name, HiSysEventType::STATISTIC, eventInfo);
52 }, ffrt::task_attr().timeout(FFRT_TASK_TIMEOUT));
53 }
54 } // namespace AAFwk
55 } // namespace OHOS
56