• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifdef SUPPORT_CHILD_PROCESS
22 #include "child_process_record.h"
23 #endif // SUPPORT_CHILD_PROCESS
24 #include "common_event_data.h"
25 #include "common_event_subscribe_info.h"
26 #include "common_event_subscriber.h"
27 #include "event_report.h"
28 
29 namespace OHOS {
30 namespace AppExecFwk {
31 enum class ProcessStartFailedReason {
32     UNKNOWN = 0,
33     APPSPAWN_FAILED = 1,
34     CREATE_START_MSG_FAILED = 2,
35     GET_SPAWN_CLIENT_FAILED = 3,
36     GENERATE_RENDER_UID_FAILED = 4,
37     CHECK_CHILD_FDS_FAILED = 5,
38 };
39 
40 class AppMgrEventSubscriber : public EventFwk::CommonEventSubscriber {
41 public:
42     AppMgrEventSubscriber(
43         const EventFwk::CommonEventSubscribeInfo &subcribeInfo, const std::function<void()> &callback);
44 
45     ~AppMgrEventSubscriber() override = default;
46 
47     void OnReceiveEvent(const EventFwk::CommonEventData &data) override;
48 
49 private:
50     std::function<void()> callback_;
51 };
52 
53 class AppMgrEventUtil {
54 public:
55     static bool SendCreateAtomicServiceProcessEvent(const std::shared_ptr<AppRunningRecord> &callerAppRecord,
56         const std::shared_ptr<AppRunningRecord> &appRecord, const std::string &moduleName,
57         const std::string &abilityName);
58 
59     static bool SendProcessStartEvent(const std::shared_ptr<AppRunningRecord> &callerAppRecord,
60         const std::shared_ptr<AppRunningRecord> &appRecord, AAFwk::EventInfo &eventInfo);
61 
62     static bool SendProcessStartFailedEvent(std::shared_ptr<AppRunningRecord> callerAppRecord,
63         std::shared_ptr<AppRunningRecord> appRecord, AAFwk::EventInfo &eventInfo);
64 
65 #ifdef SUPPORT_CHILD_PROCESS
66     static bool SendChildProcessStartFailedEvent(std::shared_ptr<ChildProcessRecord> childRecord,
67         ProcessStartFailedReason reason, int32_t subReason);
68 #endif // SUPPORT_CHILD_PROCESS
69 
70     static bool SendRenderProcessStartFailedEvent(std::shared_ptr<RenderRecord> renderRecord,
71         ProcessStartFailedReason reason, int32_t subReason);
72 
73     static void SendReStartProcessEvent(AAFwk::EventInfo &eventInfo, int32_t appUid, int64_t restartTime);
74 
75 private:
76     static int32_t GetCallerPid(const std::shared_ptr<AppRunningRecord> &callerAppRecord);
77 
78     static void UpdateStartupType(const std::shared_ptr<AbilityInfo> &abilityInfo, int32_t &abilityType,
79         int32_t &extensionType);
80 
81     static void UpdateCallerInfo(AAFwk::EventInfo &eventInfo, std::shared_ptr<AppRunningRecord> callerAppRecord,
82         std::shared_ptr<AppRunningRecord> appRecord);
83 };
84 }
85 }
86 #endif  // OHOS_ABILITY_RUNTIME_APP_MGR_EVENT_H