1 /*
2  * Copyright (c) 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 OHOS_ABILITY_RUNTIME_APP_MGR_EVENT_H
17 #define OHOS_ABILITY_RUNTIME_APP_MGR_EVENT_H
18 
19 #include "ability_info.h"
20 #include "app_running_record.h"
21 #include "child_process_record.h"
22 #include "event_report.h"
23 
24 namespace OHOS {
25 namespace AppExecFwk {
26 enum class ProcessStartFailedReason {
27     UNKNOWN = 0,
28     APPSPAWN_FAILED = 1,
29     CREATE_START_MSG_FAILED = 2,
30     GET_SPAWN_CLIENT_FAILED = 3,
31     GENERATE_RENDER_UID_FAILED = 4,
32     CHECK_CHILD_FDS_FAILED = 5,
33 };
34 
35 class AppMgrEventUtil {
36 public:
37     static bool SendCreateAtomicServiceProcessEvent(const std::shared_ptr<AppRunningRecord> &callerAppRecord,
38         const std::shared_ptr<AppRunningRecord> &appRecord, const std::string &moduleName,
39         const std::string &abilityName);
40 
41     static bool SendProcessStartEvent(const std::shared_ptr<AppRunningRecord> &callerAppRecord,
42         const std::shared_ptr<AppRunningRecord> &appRecord, AAFwk::EventInfo &eventInfo);
43 
44     static bool SendProcessStartFailedEvent(std::shared_ptr<AppRunningRecord> callerAppRecord,
45         std::shared_ptr<AppRunningRecord> appRecord, AAFwk::EventInfo &eventInfo);
46 
47     static bool SendChildProcessStartFailedEvent(std::shared_ptr<ChildProcessRecord> childRecord,
48         ProcessStartFailedReason reason, int32_t subReason);
49 
50     static bool SendRenderProcessStartFailedEvent(std::shared_ptr<RenderRecord> renderRecord,
51         ProcessStartFailedReason reason, int32_t subReason);
52 
53     static void SendReStartProcessEvent(AAFwk::EventInfo &eventInfo, int32_t appUid, int64_t restartTime);
54 
55 private:
56     static int32_t GetCallerPid(const std::shared_ptr<AppRunningRecord> &callerAppRecord);
57 
58     static void UpdateStartupType(const std::shared_ptr<AbilityInfo> &abilityInfo, int32_t &abilityType,
59         int32_t &extensionType);
60 };
61 }
62 }
63 #endif  // OHOS_ABILITY_RUNTIME_APP_MGR_EVENT_H