1eace7efcSopenharmony_ci/*
2eace7efcSopenharmony_ci * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
3eace7efcSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4eace7efcSopenharmony_ci * you may not use this file except in compliance with the License.
5eace7efcSopenharmony_ci * You may obtain a copy of the License at
6eace7efcSopenharmony_ci *
7eace7efcSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8eace7efcSopenharmony_ci *
9eace7efcSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10eace7efcSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11eace7efcSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12eace7efcSopenharmony_ci * See the License for the specific language governing permissions and
13eace7efcSopenharmony_ci * limitations under the License.
14eace7efcSopenharmony_ci */
15eace7efcSopenharmony_ci
16eace7efcSopenharmony_ci#ifndef OHOS_ABILITY_RUNTIME_APP_MGR_SERVICE_H
17eace7efcSopenharmony_ci#define OHOS_ABILITY_RUNTIME_APP_MGR_SERVICE_H
18eace7efcSopenharmony_ci
19eace7efcSopenharmony_ci#include <list>
20eace7efcSopenharmony_ci#include <string>
21eace7efcSopenharmony_ci#include <vector>
22eace7efcSopenharmony_ci
23eace7efcSopenharmony_ci#include "ability_info.h"
24eace7efcSopenharmony_ci#include "ability_running_record.h"
25eace7efcSopenharmony_ci#include "ams_mgr_scheduler.h"
26eace7efcSopenharmony_ci#include "app_malloc_info.h"
27eace7efcSopenharmony_ci#include "app_mgr_constants.h"
28eace7efcSopenharmony_ci#include "app_mgr_service_event_handler.h"
29eace7efcSopenharmony_ci#include "app_mgr_service_inner.h"
30eace7efcSopenharmony_ci#include "app_mgr_stub.h"
31eace7efcSopenharmony_ci#include "app_record_id.h"
32eace7efcSopenharmony_ci#include "app_running_record.h"
33eace7efcSopenharmony_ci#include "app_running_status_listener_interface.h"
34eace7efcSopenharmony_ci#include "app_scheduler_proxy.h"
35eace7efcSopenharmony_ci#include "appexecfwk_errors.h"
36eace7efcSopenharmony_ci#include "application_info.h"
37eace7efcSopenharmony_ci#include "if_system_ability_manager.h"
38eace7efcSopenharmony_ci#include "nocopyable.h"
39eace7efcSopenharmony_ci#include "system_ability.h"
40eace7efcSopenharmony_ci#include "task_handler_wrap.h"
41eace7efcSopenharmony_ci#include "app_jsheap_mem_info.h"
42eace7efcSopenharmony_ci
43eace7efcSopenharmony_cinamespace OHOS {
44eace7efcSopenharmony_cinamespace AppExecFwk {
45eace7efcSopenharmony_cienum class ServiceRunningState { STATE_NOT_START, STATE_RUNNING };
46eace7efcSopenharmony_ci
47eace7efcSopenharmony_cistruct AppMgrServiceState {
48eace7efcSopenharmony_ci    ServiceRunningState serviceRunningState = ServiceRunningState::STATE_NOT_START;
49eace7efcSopenharmony_ci    SpawnConnectionState connectionState = SpawnConnectionState::STATE_NOT_CONNECT;
50eace7efcSopenharmony_ci};
51eace7efcSopenharmony_ci
52eace7efcSopenharmony_ciclass AMSEventHandler;
53eace7efcSopenharmony_ci
54eace7efcSopenharmony_ciclass AppMgrService : public SystemAbility, public AppMgrStub {
55eace7efcSopenharmony_cipublic:
56eace7efcSopenharmony_ci    DECLEAR_SYSTEM_ABILITY(AppMgrService);
57eace7efcSopenharmony_ci
58eace7efcSopenharmony_ci    AppMgrService();
59eace7efcSopenharmony_ci    explicit AppMgrService(const int32_t serviceId, bool runOnCreate = false);
60eace7efcSopenharmony_ci    virtual ~AppMgrService() override;
61eace7efcSopenharmony_ci
62eace7efcSopenharmony_ci    // the function about application
63eace7efcSopenharmony_ci    // attach the application to ability mgr, then ability mgr can control it.
64eace7efcSopenharmony_ci    /**
65eace7efcSopenharmony_ci     * AttachApplication, call AttachApplication() through proxy object,
66eace7efcSopenharmony_ci     * get all the information needed to start the Application (data related to the Application ).
67eace7efcSopenharmony_ci     *
68eace7efcSopenharmony_ci     * @param app, information needed to start the Application.
69eace7efcSopenharmony_ci     * @return
70eace7efcSopenharmony_ci     */
71eace7efcSopenharmony_ci    virtual void AttachApplication(const sptr<IRemoteObject> &app) override;
72eace7efcSopenharmony_ci
73eace7efcSopenharmony_ci    /**
74eace7efcSopenharmony_ci     * Preload application.
75eace7efcSopenharmony_ci     *
76eace7efcSopenharmony_ci     * @param bundleName The bundle name of the application to preload.
77eace7efcSopenharmony_ci     * @param userId Indicates the user identification.
78eace7efcSopenharmony_ci     * @param preloadMode Preload application mode.
79eace7efcSopenharmony_ci     * @param appIndex The index of application clone.
80eace7efcSopenharmony_ci     * @return Returns ERR_OK on success, others on failure.
81eace7efcSopenharmony_ci     */
82eace7efcSopenharmony_ci    virtual int32_t PreloadApplication(const std::string &bundleName, int32_t userId,
83eace7efcSopenharmony_ci        AppExecFwk::PreloadMode preloadMode, int32_t appIndex) override;
84eace7efcSopenharmony_ci
85eace7efcSopenharmony_ci    // notify the ams update the state of an app, when it entered foreground.
86eace7efcSopenharmony_ci
87eace7efcSopenharmony_ci    /**
88eace7efcSopenharmony_ci     * ApplicationForegrounded, call ApplicationForegrounded() through proxy object,
89eace7efcSopenharmony_ci     * set the application to Foreground State.
90eace7efcSopenharmony_ci     *
91eace7efcSopenharmony_ci     * @param recordId, a unique record that identifies this Application from others.
92eace7efcSopenharmony_ci     * @return
93eace7efcSopenharmony_ci     */
94eace7efcSopenharmony_ci    virtual void ApplicationForegrounded(const int32_t recordId) override;
95eace7efcSopenharmony_ci
96eace7efcSopenharmony_ci    /**
97eace7efcSopenharmony_ci     * ApplicationBackgrounded, call ApplicationBackgrounded() through proxy object,
98eace7efcSopenharmony_ci     * set the application to Backgrounded State.
99eace7efcSopenharmony_ci     *
100eace7efcSopenharmony_ci     * @param recordId, a unique record that identifies this Application from others.
101eace7efcSopenharmony_ci     * @return
102eace7efcSopenharmony_ci     */
103eace7efcSopenharmony_ci    virtual void ApplicationBackgrounded(const int32_t recordId) override;
104eace7efcSopenharmony_ci
105eace7efcSopenharmony_ci    /**
106eace7efcSopenharmony_ci     * ApplicationTerminated, call ApplicationTerminated() through proxy object,
107eace7efcSopenharmony_ci     * terminate the application.
108eace7efcSopenharmony_ci     *
109eace7efcSopenharmony_ci     * @param recordId, a unique record that identifies this Application from others.
110eace7efcSopenharmony_ci     * @return
111eace7efcSopenharmony_ci     */
112eace7efcSopenharmony_ci    virtual void ApplicationTerminated(const int32_t recordId) override;
113eace7efcSopenharmony_ci
114eace7efcSopenharmony_ci    /**
115eace7efcSopenharmony_ci     * AbilityCleaned,call through AbilityCleaned() proxy project, clean Ability record.
116eace7efcSopenharmony_ci     *
117eace7efcSopenharmony_ci     * @param token, a unique record that identifies AbilityCleaned from others.
118eace7efcSopenharmony_ci     * @return
119eace7efcSopenharmony_ci     */
120eace7efcSopenharmony_ci    virtual void AbilityCleaned(const sptr<IRemoteObject> &token) override;
121eace7efcSopenharmony_ci
122eace7efcSopenharmony_ci    /**
123eace7efcSopenharmony_ci     * ClearUpApplicationData, call ClearUpApplicationData() through proxy project,
124eace7efcSopenharmony_ci     * clear the application data.
125eace7efcSopenharmony_ci     *
126eace7efcSopenharmony_ci     * @param bundleName, bundle name in Application record.
127eace7efcSopenharmony_ci     * @param appCloneIndex the app clone id.
128eace7efcSopenharmony_ci     * @param userId the user id.
129eace7efcSopenharmony_ci     * @return Returns ERR_OK on success, others on failure.
130eace7efcSopenharmony_ci     */
131eace7efcSopenharmony_ci    virtual int32_t ClearUpApplicationData(const std::string &bundleName, int32_t appCloneIndex,
132eace7efcSopenharmony_ci        int32_t userId = -1) override;
133eace7efcSopenharmony_ci
134eace7efcSopenharmony_ci    /**
135eace7efcSopenharmony_ci     * ClearUpApplicationDataBySelf, call ClearUpApplicationDataBySelf() through proxy project,
136eace7efcSopenharmony_ci     * clear the application data by self.
137eace7efcSopenharmony_ci     *
138eace7efcSopenharmony_ci     * @param userId, user ID.
139eace7efcSopenharmony_ci     * @return Returns ERR_OK on success, others on failure.
140eace7efcSopenharmony_ci     */
141eace7efcSopenharmony_ci    virtual int32_t ClearUpApplicationDataBySelf(int32_t userId = -1) override;
142eace7efcSopenharmony_ci
143eace7efcSopenharmony_ci    /**
144eace7efcSopenharmony_ci     * GetAllRunningProcesses, call GetAllRunningProcesses() through proxy project.
145eace7efcSopenharmony_ci     * Obtains information about application processes that are running on the device.
146eace7efcSopenharmony_ci     *
147eace7efcSopenharmony_ci     * @param info, app name in Application record.
148eace7efcSopenharmony_ci     * @return Returns ERR_OK on success, others on failure.
149eace7efcSopenharmony_ci     */
150eace7efcSopenharmony_ci    virtual int32_t GetAllRunningProcesses(std::vector<RunningProcessInfo> &info) override;
151eace7efcSopenharmony_ci
152eace7efcSopenharmony_ci    /**
153eace7efcSopenharmony_ci     * GetRunningMultiAppInfoByBundleName, call GetRunningMultiAppInfoByBundleName() through proxy project.
154eace7efcSopenharmony_ci     * Obtains information about multiapp that are running on the device.
155eace7efcSopenharmony_ci     *
156eace7efcSopenharmony_ci     * @param bundlename, input.
157eace7efcSopenharmony_ci     * @param info, output multiapp information.
158eace7efcSopenharmony_ci     * @return ERR_OK ,return back success,others fail.
159eace7efcSopenharmony_ci     */
160eace7efcSopenharmony_ci    virtual int32_t GetRunningMultiAppInfoByBundleName(const std::string &bundleName,
161eace7efcSopenharmony_ci        RunningMultiAppInfo &info) override;
162eace7efcSopenharmony_ci
163eace7efcSopenharmony_ci    /**
164eace7efcSopenharmony_ci     * GetAllRunningInstanceKeysBySelf, call GetAllRunningInstanceKeysBySelf() through proxy project.
165eace7efcSopenharmony_ci     * Obtains running instance keys of multi-instance app that are running on the device.
166eace7efcSopenharmony_ci     *
167eace7efcSopenharmony_ci     * @param instanceKeys, output instance keys of the multi-instance app.
168eace7efcSopenharmony_ci     * @return ERR_OK ,return back success,others fail.
169eace7efcSopenharmony_ci     */
170eace7efcSopenharmony_ci    virtual int32_t GetAllRunningInstanceKeysBySelf(std::vector<std::string> &instanceKeys) override;
171eace7efcSopenharmony_ci
172eace7efcSopenharmony_ci    /**
173eace7efcSopenharmony_ci     * GetAllRunningInstanceKeysByBundleName, call GetAllRunningInstanceKeysByBundleName() through proxy project.
174eace7efcSopenharmony_ci     * Obtains running instance keys of multi-instance app that are running on the device.
175eace7efcSopenharmony_ci     *
176eace7efcSopenharmony_ci     * @param bundlename, bundle name in Application record.
177eace7efcSopenharmony_ci     * @param instanceKeys, output instance keys of the multi-instance app.
178eace7efcSopenharmony_ci     * @param userId, user id.
179eace7efcSopenharmony_ci     * @return ERR_OK ,return back success,others fail.
180eace7efcSopenharmony_ci     */
181eace7efcSopenharmony_ci    virtual int32_t GetAllRunningInstanceKeysByBundleName(const std::string &bundleName,
182eace7efcSopenharmony_ci        std::vector<std::string> &instanceKeys, int32_t userId = -1) override;
183eace7efcSopenharmony_ci
184eace7efcSopenharmony_ci    /**
185eace7efcSopenharmony_ci     * GetRunningProcessesByBundleType, call GetRunningProcessesByBundleType() through proxy project.
186eace7efcSopenharmony_ci     * Obtains information about application processes by bundle type that are running on the device.
187eace7efcSopenharmony_ci     *
188eace7efcSopenharmony_ci     * @param bundleType, bundle type of the processes
189eace7efcSopenharmony_ci     * @param info, app name in Application record.
190eace7efcSopenharmony_ci     * @return ERR_OK ,return back success,others fail.
191eace7efcSopenharmony_ci     */
192eace7efcSopenharmony_ci    virtual int GetRunningProcessesByBundleType(const BundleType bundleType,
193eace7efcSopenharmony_ci        std::vector<RunningProcessInfo> &info) override;
194eace7efcSopenharmony_ci
195eace7efcSopenharmony_ci    /**
196eace7efcSopenharmony_ci     * GetAllRenderProcesses, call GetAllRenderProcesses() through proxy project.
197eace7efcSopenharmony_ci     * Obtains information about render processes that are running on the device.
198eace7efcSopenharmony_ci     *
199eace7efcSopenharmony_ci     * @param info, render process info.
200eace7efcSopenharmony_ci     * @return ERR_OK, return back success, others fail.
201eace7efcSopenharmony_ci     */
202eace7efcSopenharmony_ci    virtual int32_t GetAllRenderProcesses(std::vector<RenderProcessInfo> &info) override;
203eace7efcSopenharmony_ci
204eace7efcSopenharmony_ci    /**
205eace7efcSopenharmony_ci     * GetAllChildrenProcesses, call GetAllChildrenProcesses() through proxy project.
206eace7efcSopenharmony_ci     * Obtains information about children processes that are running on the device.
207eace7efcSopenharmony_ci     *
208eace7efcSopenharmony_ci     * @param info, child process info.
209eace7efcSopenharmony_ci     * @return ERR_OK, return back success, others fail.
210eace7efcSopenharmony_ci     */
211eace7efcSopenharmony_ci    virtual int GetAllChildrenProcesses(std::vector<ChildProcessInfo> &info) override;
212eace7efcSopenharmony_ci
213eace7efcSopenharmony_ci    /**
214eace7efcSopenharmony_ci     * JudgeSandboxByPid, call JudgeSandboxByPid() through proxy project.
215eace7efcSopenharmony_ci     * Obtains information about application processes that are running on the device.
216eace7efcSopenharmony_ci     *
217eace7efcSopenharmony_ci     * @param pid, the pid of current app running record.
218eace7efcSopenharmony_ci     * @param isSandbox, current app is or not a sandbox.
219eace7efcSopenharmony_ci     * @return Returns ERR_OK on success, others on failure.
220eace7efcSopenharmony_ci     */
221eace7efcSopenharmony_ci    virtual int32_t JudgeSandboxByPid(pid_t pid, bool &isSandbox) override;
222eace7efcSopenharmony_ci
223eace7efcSopenharmony_ci    /**
224eace7efcSopenharmony_ci     * GetProcessRunningInfosByUserId, call GetProcessRunningInfosByUserId() through proxy project.
225eace7efcSopenharmony_ci     * Obtains information about application processes that are running on the device.
226eace7efcSopenharmony_ci     *
227eace7efcSopenharmony_ci     * @param info, app name in Application record.
228eace7efcSopenharmony_ci     * @param userId, userId.
229eace7efcSopenharmony_ci     *
230eace7efcSopenharmony_ci     * @return Returns ERR_OK on success, others on failure.
231eace7efcSopenharmony_ci     */
232eace7efcSopenharmony_ci    virtual int32_t GetProcessRunningInfosByUserId(std::vector<RunningProcessInfo> &info, int32_t userId) override;
233eace7efcSopenharmony_ci
234eace7efcSopenharmony_ci    /**
235eace7efcSopenharmony_ci     * GetProcessRunningInformation, call GetProcessRunningInformation() through proxy project.
236eace7efcSopenharmony_ci     * Obtains information about current application process which is running on the device.
237eace7efcSopenharmony_ci     *
238eace7efcSopenharmony_ci     * @param info, app name in Application record.
239eace7efcSopenharmony_ci     *
240eace7efcSopenharmony_ci     * @return Returns ERR_OK on success, others on failure.
241eace7efcSopenharmony_ci     */
242eace7efcSopenharmony_ci    virtual int32_t GetProcessRunningInformation(RunningProcessInfo &info) override;
243eace7efcSopenharmony_ci
244eace7efcSopenharmony_ci    /**
245eace7efcSopenharmony_ci     * NotifyMemoryLevel, call NotifyMemoryLevel() through proxy project.
246eace7efcSopenharmony_ci     * Notify applications background the current memory level.
247eace7efcSopenharmony_ci     *
248eace7efcSopenharmony_ci     * @param level, current memory level.
249eace7efcSopenharmony_ci     * @return Returns ERR_OK on success, others on failure.
250eace7efcSopenharmony_ci     */
251eace7efcSopenharmony_ci    virtual int32_t NotifyMemoryLevel(int32_t level) override;
252eace7efcSopenharmony_ci
253eace7efcSopenharmony_ci    /**
254eace7efcSopenharmony_ci     * NotifyProcMemoryLevel, call NotifyMemoryLevel() through proxy project.
255eace7efcSopenharmony_ci     * Notify applications the current memory level.
256eace7efcSopenharmony_ci     *
257eace7efcSopenharmony_ci     * @param  procLevelMap , <pid_t, MemoryLevel> map.
258eace7efcSopenharmony_ci     * @return Returns ERR_OK on success, others on failure.
259eace7efcSopenharmony_ci     */
260eace7efcSopenharmony_ci    virtual int32_t NotifyProcMemoryLevel(const std::map<pid_t, MemoryLevel> &procLevelMap) override;
261eace7efcSopenharmony_ci
262eace7efcSopenharmony_ci    /**
263eace7efcSopenharmony_ci     * DumpHeapMemory, call DumpHeapMemory() through proxy project.
264eace7efcSopenharmony_ci     * Get the application's memory allocation info.
265eace7efcSopenharmony_ci     *
266eace7efcSopenharmony_ci     * @param pid, pid input.
267eace7efcSopenharmony_ci     * @param mallocInfo, dynamic storage information output.
268eace7efcSopenharmony_ci     * @return Returns ERR_OK on success, others on failure.
269eace7efcSopenharmony_ci     */
270eace7efcSopenharmony_ci    virtual int32_t DumpHeapMemory(const int32_t pid, OHOS::AppExecFwk::MallocInfo &mallocInfo) override;
271eace7efcSopenharmony_ci
272eace7efcSopenharmony_ci    /**
273eace7efcSopenharmony_ci     * Authenticate dump permissions
274eace7efcSopenharmony_ci     *
275eace7efcSopenharmony_ci     * @return Returns true on permission, others on false
276eace7efcSopenharmony_ci     */
277eace7efcSopenharmony_ci    bool HasDumpPermission() const;
278eace7efcSopenharmony_ci    /**
279eace7efcSopenharmony_ci     * DumpJsHeapMemory, call DumpJsHeapMemory() through proxy project.
280eace7efcSopenharmony_ci     * triggerGC and dump the application's jsheap memory info.
281eace7efcSopenharmony_ci     *
282eace7efcSopenharmony_ci     * @param info, pid, tid, needGc, needSnapshot
283eace7efcSopenharmony_ci     * @return Returns ERR_OK on success, others on failure.
284eace7efcSopenharmony_ci     */
285eace7efcSopenharmony_ci    virtual int32_t DumpJsHeapMemory(OHOS::AppExecFwk::JsHeapDumpInfo &info) override;
286eace7efcSopenharmony_ci
287eace7efcSopenharmony_ci    // the function about service running info
288eace7efcSopenharmony_ci    /**
289eace7efcSopenharmony_ci     * QueryServiceState, Query application service status.
290eace7efcSopenharmony_ci     *
291eace7efcSopenharmony_ci     * @return the application service status.
292eace7efcSopenharmony_ci     */
293eace7efcSopenharmony_ci    AppMgrServiceState QueryServiceState();
294eace7efcSopenharmony_ci
295eace7efcSopenharmony_ci    /**
296eace7efcSopenharmony_ci     * GetAmsMgr, call GetAmsMgr() through proxy object, get AMS interface instance.
297eace7efcSopenharmony_ci     *
298eace7efcSopenharmony_ci     * @return sptr<IAmsMgr>, return to AMS interface instance.
299eace7efcSopenharmony_ci     */
300eace7efcSopenharmony_ci    virtual sptr<IAmsMgr> GetAmsMgr() override;
301eace7efcSopenharmony_ci
302eace7efcSopenharmony_ci    /**
303eace7efcSopenharmony_ci     * Notify that the ability stage has been updated
304eace7efcSopenharmony_ci     * @param recordId, the app record.
305eace7efcSopenharmony_ci     */
306eace7efcSopenharmony_ci    virtual void AddAbilityStageDone(const int32_t recordId) override;
307eace7efcSopenharmony_ci
308eace7efcSopenharmony_ci    /**
309eace7efcSopenharmony_ci     * Start all resident process
310eace7efcSopenharmony_ci     */
311eace7efcSopenharmony_ci    virtual void StartupResidentProcess(const std::vector<AppExecFwk::BundleInfo> &bundleInfos) override;
312eace7efcSopenharmony_ci
313eace7efcSopenharmony_ci    /**
314eace7efcSopenharmony_ci     * Start user test process.
315eace7efcSopenharmony_ci     * @param want, want object.
316eace7efcSopenharmony_ci     * @param observer, test observer remote object.
317eace7efcSopenharmony_ci     * @param bundleInfo, bundle info.
318eace7efcSopenharmony_ci     * @param userId the user id.
319eace7efcSopenharmony_ci     * @return Returns ERR_OK on success, others on failure.
320eace7efcSopenharmony_ci     */
321eace7efcSopenharmony_ci    virtual int StartUserTestProcess(const AAFwk::Want &want, const sptr<IRemoteObject> &observer,
322eace7efcSopenharmony_ci        const AppExecFwk::BundleInfo &bundleInfo, int32_t userId) override;
323eace7efcSopenharmony_ci
324eace7efcSopenharmony_ci    /**
325eace7efcSopenharmony_ci     * @brief Finish user test.
326eace7efcSopenharmony_ci     * @param msg user test message.
327eace7efcSopenharmony_ci     * @param resultCode user test result Code.
328eace7efcSopenharmony_ci     * @param bundleName user test bundleName.
329eace7efcSopenharmony_ci     *
330eace7efcSopenharmony_ci     * @return Returns ERR_OK on success, others on failure.
331eace7efcSopenharmony_ci     */
332eace7efcSopenharmony_ci    virtual int FinishUserTest(
333eace7efcSopenharmony_ci        const std::string &msg, const int64_t &resultCode, const std::string &bundleName) override;
334eace7efcSopenharmony_ci
335eace7efcSopenharmony_ci    /**
336eace7efcSopenharmony_ci     * @brief Application hidumper.
337eace7efcSopenharmony_ci     * @param fd Indicates the fd.
338eace7efcSopenharmony_ci     * @param args Indicates the params.
339eace7efcSopenharmony_ci     * @return Returns the dump result.
340eace7efcSopenharmony_ci     */
341eace7efcSopenharmony_ci    int Dump(int fd, const std::vector<std::u16string>& args) override;
342eace7efcSopenharmony_ci
343eace7efcSopenharmony_ci    /**
344eace7efcSopenharmony_ci     * @brief called when the abilityStage's onAcceptWant lifecycle completed.
345eace7efcSopenharmony_ci     * @param recordId record id of the ability.
346eace7efcSopenharmony_ci     * @param want want has been accepted.
347eace7efcSopenharmony_ci     * @param flag flag get from OnAcceptWant.
348eace7efcSopenharmony_ci     */
349eace7efcSopenharmony_ci    virtual void ScheduleAcceptWantDone(
350eace7efcSopenharmony_ci        const int32_t recordId, const AAFwk::Want &want, const std::string &flag) override;
351eace7efcSopenharmony_ci
352eace7efcSopenharmony_ci    virtual void ScheduleNewProcessRequestDone(
353eace7efcSopenharmony_ci        const int32_t recordId, const AAFwk::Want &want, const std::string &flag) override;
354eace7efcSopenharmony_ci
355eace7efcSopenharmony_ci    /**
356eace7efcSopenharmony_ci     *  Get the token of ability records by process ID.
357eace7efcSopenharmony_ci     *
358eace7efcSopenharmony_ci     * @param pid The process id.
359eace7efcSopenharmony_ci     * @param tokens The token of ability records.
360eace7efcSopenharmony_ci     * @return Returns ERR_OK on success, others on failure.
361eace7efcSopenharmony_ci     */
362eace7efcSopenharmony_ci    virtual int GetAbilityRecordsByProcessID(const int pid, std::vector<sptr<IRemoteObject>> &tokens) override;
363eace7efcSopenharmony_ci
364eace7efcSopenharmony_ci    /**
365eace7efcSopenharmony_ci     * Prestart nwebspawn process.
366eace7efcSopenharmony_ci     *
367eace7efcSopenharmony_ci     * @return Returns ERR_OK on success, others on failure.
368eace7efcSopenharmony_ci     */
369eace7efcSopenharmony_ci    virtual int PreStartNWebSpawnProcess() override;
370eace7efcSopenharmony_ci
371eace7efcSopenharmony_ci    /**
372eace7efcSopenharmony_ci     * Start nweb render process, called by nweb host.
373eace7efcSopenharmony_ci     *
374eace7efcSopenharmony_ci     * @param renderParam, params passed to renderProcess.
375eace7efcSopenharmony_ci     * @param ipcFd, ipc file descriptor for web browser and render process.
376eace7efcSopenharmony_ci     * @param sharedFd, shared memory file descriptor.
377eace7efcSopenharmony_ci     * @param crashFd, crash signal file descriptor.
378eace7efcSopenharmony_ci     * @param renderPid, created render pid.
379eace7efcSopenharmony_ci     * @param isGPU, is or not gpu process
380eace7efcSopenharmony_ci     * @return Returns ERR_OK on success, others on failure.
381eace7efcSopenharmony_ci     */
382eace7efcSopenharmony_ci    virtual int StartRenderProcess(const std::string &renderParam,
383eace7efcSopenharmony_ci                                   int32_t ipcFd, int32_t sharedFd,
384eace7efcSopenharmony_ci                                   int32_t crashFd, pid_t &renderPid, bool isGPU = false) override;
385eace7efcSopenharmony_ci
386eace7efcSopenharmony_ci    /**
387eace7efcSopenharmony_ci     * Render process call this to attach to app manager service.
388eace7efcSopenharmony_ci     *
389eace7efcSopenharmony_ci     * @param renderScheduler scheduler of render process.
390eace7efcSopenharmony_ci     */
391eace7efcSopenharmony_ci    virtual void AttachRenderProcess(const sptr<IRemoteObject> &shceduler) override;
392eace7efcSopenharmony_ci
393eace7efcSopenharmony_ci    /**
394eace7efcSopenharmony_ci     * Get render process termination status, called by nweb host.
395eace7efcSopenharmony_ci     *
396eace7efcSopenharmony_ci     * @param renderPid, target render pid.
397eace7efcSopenharmony_ci     * @param status, termination status of the render process.
398eace7efcSopenharmony_ci     * @return Returns ERR_OK on success, others on failure.
399eace7efcSopenharmony_ci     */
400eace7efcSopenharmony_ci    virtual int GetRenderProcessTerminationStatus(pid_t renderPid, int &status) override;
401eace7efcSopenharmony_ci
402eace7efcSopenharmony_ci    /**
403eace7efcSopenharmony_ci     * GetConfiguration
404eace7efcSopenharmony_ci     *
405eace7efcSopenharmony_ci     * @param info to retrieve configuration data.
406eace7efcSopenharmony_ci     * @return ERR_OK ,return back success,others fail.
407eace7efcSopenharmony_ci     */
408eace7efcSopenharmony_ci    virtual int32_t GetConfiguration(Configuration& config) override;
409eace7efcSopenharmony_ci
410eace7efcSopenharmony_ci    /**
411eace7efcSopenharmony_ci     * UpdateConfiguration, ANotify application update system environment changes.
412eace7efcSopenharmony_ci     *
413eace7efcSopenharmony_ci     * @param config System environment change parameters.
414eace7efcSopenharmony_ci     * @param userId configuration for the user
415eace7efcSopenharmony_ci     * @return Returns ERR_OK on success, others on failure.
416eace7efcSopenharmony_ci     */
417eace7efcSopenharmony_ci    virtual int32_t UpdateConfiguration(const Configuration &config, const int32_t userId = -1) override;
418eace7efcSopenharmony_ci
419eace7efcSopenharmony_ci    /**
420eace7efcSopenharmony_ci     *  Update config by bundle name.
421eace7efcSopenharmony_ci     *
422eace7efcSopenharmony_ci     * @param config Application environment change parameters.
423eace7efcSopenharmony_ci     * @param name Application bundle name.
424eace7efcSopenharmony_ci     * @return Returns ERR_OK on success, others on failure.
425eace7efcSopenharmony_ci     */
426eace7efcSopenharmony_ci    virtual int32_t UpdateConfigurationByBundleName(const Configuration &config, const std::string &name) override;
427eace7efcSopenharmony_ci
428eace7efcSopenharmony_ci    /**
429eace7efcSopenharmony_ci     * @brief register a configuration observer which will receive notifies when updated.
430eace7efcSopenharmony_ci     * @param observer the configuration observer to receive notify.
431eace7efcSopenharmony_ci     *
432eace7efcSopenharmony_ci     * @return Returns ERR_OK on success, others on failure.
433eace7efcSopenharmony_ci     */
434eace7efcSopenharmony_ci    virtual int32_t RegisterConfigurationObserver(const sptr<IConfigurationObserver> &observer) override;
435eace7efcSopenharmony_ci
436eace7efcSopenharmony_ci    /**
437eace7efcSopenharmony_ci     * @brief unregister a configuration observer registered before.
438eace7efcSopenharmony_ci     * @param observer the configuration observer registered before.
439eace7efcSopenharmony_ci     *
440eace7efcSopenharmony_ci     * @return Returns ERR_OK on success, others on failure.
441eace7efcSopenharmony_ci     */
442eace7efcSopenharmony_ci    virtual int32_t UnregisterConfigurationObserver(const sptr<IConfigurationObserver> &observer) override;
443eace7efcSopenharmony_ci
444eace7efcSopenharmony_ci    /**
445eace7efcSopenharmony_ci     * Register KIA interceptor.
446eace7efcSopenharmony_ci     * @param interceptor KIA interceptor.
447eace7efcSopenharmony_ci     * @return Returns ERR_OK on success, others on failure.
448eace7efcSopenharmony_ci     */
449eace7efcSopenharmony_ci    virtual int32_t RegisterKiaInterceptor(const sptr<IKiaInterceptor> &interceptor) override;
450eace7efcSopenharmony_ci
451eace7efcSopenharmony_ci    /**
452eace7efcSopenharmony_ci     * Check if the given pid is a KIA process.
453eace7efcSopenharmony_ci     * @param pid process id.
454eace7efcSopenharmony_ci     * @return Returns true if it is a KIA process, false otherwise.
455eace7efcSopenharmony_ci     */
456eace7efcSopenharmony_ci    virtual int32_t CheckIsKiaProcess(pid_t pid, bool &isKia) override;
457eace7efcSopenharmony_ci
458eace7efcSopenharmony_ci    /**
459eace7efcSopenharmony_ci     * @brief Get the running state of application by bundle name.
460eace7efcSopenharmony_ci     *
461eace7efcSopenharmony_ci     * @param bundleName Bundle name
462eace7efcSopenharmony_ci     * @return Returns true if process is running, false if process isn't running.
463eace7efcSopenharmony_ci     */
464eace7efcSopenharmony_ci    bool GetAppRunningStateByBundleName(const std::string &bundleName) override;
465eace7efcSopenharmony_ci
466eace7efcSopenharmony_ci    /**
467eace7efcSopenharmony_ci     * @brief Notify application load patch.
468eace7efcSopenharmony_ci     *
469eace7efcSopenharmony_ci     * @param bundleName Bundle name
470eace7efcSopenharmony_ci     * @param callback called when LoadPatch finished.
471eace7efcSopenharmony_ci     * @return Returns ERR_OK on success, error code on failure.
472eace7efcSopenharmony_ci     */
473eace7efcSopenharmony_ci    int32_t NotifyLoadRepairPatch(const std::string &bundleName, const sptr<IQuickFixCallback> &callback) override;
474eace7efcSopenharmony_ci
475eace7efcSopenharmony_ci    /**
476eace7efcSopenharmony_ci     * @brief Notify application reload page.
477eace7efcSopenharmony_ci     *
478eace7efcSopenharmony_ci     * @param bundleName Bundle name
479eace7efcSopenharmony_ci     * @param callback called when HotReload finished.
480eace7efcSopenharmony_ci     * @return Returns ERR_OK on success, error code on failure.
481eace7efcSopenharmony_ci     */
482eace7efcSopenharmony_ci    int32_t NotifyHotReloadPage(const std::string &bundleName, const sptr<IQuickFixCallback> &callback) override;
483eace7efcSopenharmony_ci
484eace7efcSopenharmony_ci    /**
485eace7efcSopenharmony_ci     * @brief Notify application unload patch.
486eace7efcSopenharmony_ci     *
487eace7efcSopenharmony_ci     * @param bundleName Bundle name
488eace7efcSopenharmony_ci     * @param callback called when UnloadPatch finished.
489eace7efcSopenharmony_ci     * @return Returns ERR_OK on success, error code on failure.
490eace7efcSopenharmony_ci     */
491eace7efcSopenharmony_ci    int32_t NotifyUnLoadRepairPatch(const std::string &bundleName, const sptr<IQuickFixCallback> &callback) override;
492eace7efcSopenharmony_ci
493eace7efcSopenharmony_ci#ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE
494eace7efcSopenharmony_ci    int32_t SetContinuousTaskProcess(int32_t pid, bool isContinuousTask) override;
495eace7efcSopenharmony_ci#endif
496eace7efcSopenharmony_ci
497eace7efcSopenharmony_ci    /**
498eace7efcSopenharmony_ci     * @brief Check whether the shared bundle is running.
499eace7efcSopenharmony_ci     *
500eace7efcSopenharmony_ci     * @param bundleName Shared bundle name.
501eace7efcSopenharmony_ci     * @param versionCode Shared bundle version code.
502eace7efcSopenharmony_ci     * @return Returns the shared bundle running result. The result is true if running, false otherwise.
503eace7efcSopenharmony_ci     */
504eace7efcSopenharmony_ci    virtual bool IsSharedBundleRunning(const std::string &bundleName, uint32_t versionCode) override;
505eace7efcSopenharmony_ci
506eace7efcSopenharmony_ci    /**
507eace7efcSopenharmony_ci     * start native process for debugger.
508eace7efcSopenharmony_ci     *
509eace7efcSopenharmony_ci     * @param want param to start a process.
510eace7efcSopenharmony_ci     */
511eace7efcSopenharmony_ci    virtual int32_t StartNativeProcessForDebugger(const AAFwk::Want &want) override;
512eace7efcSopenharmony_ci
513eace7efcSopenharmony_ci    /**
514eace7efcSopenharmony_ci     * Get bundleName by pid.
515eace7efcSopenharmony_ci     *
516eace7efcSopenharmony_ci     * @param pid process id.
517eace7efcSopenharmony_ci     * @param bundleName Output parameters, return bundleName.
518eace7efcSopenharmony_ci     * @param uid Output parameters, return userId.
519eace7efcSopenharmony_ci     * @return Returns ERR_OK on success, others on failure.
520eace7efcSopenharmony_ci     */
521eace7efcSopenharmony_ci    virtual int32_t GetBundleNameByPid(const int32_t pid, std::string &bundleName, int32_t &uid) override;
522eace7efcSopenharmony_ci
523eace7efcSopenharmony_ci    /**
524eace7efcSopenharmony_ci     * Get running process information by pid.
525eace7efcSopenharmony_ci     *
526eace7efcSopenharmony_ci     * @param pid process id.
527eace7efcSopenharmony_ci     * @param info Output parameters, return runningProcessInfo.
528eace7efcSopenharmony_ci     * @return Returns ERR_OK on success, others on failure.
529eace7efcSopenharmony_ci     */
530eace7efcSopenharmony_ci    virtual int32_t GetRunningProcessInfoByPid(const pid_t pid, OHOS::AppExecFwk::RunningProcessInfo &info) override;
531eace7efcSopenharmony_ci
532eace7efcSopenharmony_ci    /**
533eace7efcSopenharmony_ci     * Notify Fault Data
534eace7efcSopenharmony_ci     *
535eace7efcSopenharmony_ci     * @param faultData the fault data.
536eace7efcSopenharmony_ci     * @return Returns ERR_OK on success, others on failure.
537eace7efcSopenharmony_ci     */
538eace7efcSopenharmony_ci    int32_t NotifyAppFault(const FaultData &faultData) override;
539eace7efcSopenharmony_ci
540eace7efcSopenharmony_ci    /**
541eace7efcSopenharmony_ci     * Notify Fault Data By SA
542eace7efcSopenharmony_ci     *
543eace7efcSopenharmony_ci     * @param faultData the fault data notified by SA.
544eace7efcSopenharmony_ci     * @return Returns ERR_OK on success, others on failure.
545eace7efcSopenharmony_ci     */
546eace7efcSopenharmony_ci    int32_t NotifyAppFaultBySA(const AppFaultDataBySA &faultData) override;
547eace7efcSopenharmony_ci
548eace7efcSopenharmony_ci    /**
549eace7efcSopenharmony_ci     * Set Appfreeze Detect Filter
550eace7efcSopenharmony_ci     *
551eace7efcSopenharmony_ci     * @param pid the process pid.
552eace7efcSopenharmony_ci     * @return Returns true on success, others on failure.
553eace7efcSopenharmony_ci     */
554eace7efcSopenharmony_ci    bool SetAppFreezeFilter(int32_t pid) override;
555eace7efcSopenharmony_ci
556eace7efcSopenharmony_ci    /**
557eace7efcSopenharmony_ci     * get memorySize by pid.
558eace7efcSopenharmony_ci     *
559eace7efcSopenharmony_ci     * @param pid process id.
560eace7efcSopenharmony_ci     * @param memorySize Output parameters, return memorySize in KB.
561eace7efcSopenharmony_ci     * @return Returns ERR_OK on success, others on failure.
562eace7efcSopenharmony_ci     */
563eace7efcSopenharmony_ci    virtual int32_t GetProcessMemoryByPid(const int32_t pid, int32_t &memorySize) override;
564eace7efcSopenharmony_ci
565eace7efcSopenharmony_ci    /**
566eace7efcSopenharmony_ci     * get application processes information list by bundleName.
567eace7efcSopenharmony_ci     *
568eace7efcSopenharmony_ci     * @param bundleName Bundle name.
569eace7efcSopenharmony_ci     * @param userId user Id in Application record.
570eace7efcSopenharmony_ci     * @param info Output parameters, return running process info list.
571eace7efcSopenharmony_ci     * @return Returns ERR_OK on success, others on failure.
572eace7efcSopenharmony_ci     */
573eace7efcSopenharmony_ci    virtual int32_t GetRunningProcessInformation(
574eace7efcSopenharmony_ci        const std::string &bundleName, int32_t userId, std::vector<RunningProcessInfo> &info) override;
575eace7efcSopenharmony_ci
576eace7efcSopenharmony_ci    /**
577eace7efcSopenharmony_ci     * on add systemAbility.
578eace7efcSopenharmony_ci     *
579eace7efcSopenharmony_ci     * @return
580eace7efcSopenharmony_ci     */
581eace7efcSopenharmony_ci    virtual void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override;
582eace7efcSopenharmony_ci
583eace7efcSopenharmony_ci    /**
584eace7efcSopenharmony_ci     * on remove systemAbility.
585eace7efcSopenharmony_ci     *
586eace7efcSopenharmony_ci     * @return
587eace7efcSopenharmony_ci     */
588eace7efcSopenharmony_ci    virtual void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override;
589eace7efcSopenharmony_ci
590eace7efcSopenharmony_ci    /**
591eace7efcSopenharmony_ci     * @brief Notify NativeEngine GC of status change.
592eace7efcSopenharmony_ci     *
593eace7efcSopenharmony_ci     * @param state GC state
594eace7efcSopenharmony_ci     * @param pid pid
595eace7efcSopenharmony_ci     *
596eace7efcSopenharmony_ci     * @return Is the status change completed.
597eace7efcSopenharmony_ci     */
598eace7efcSopenharmony_ci    virtual int32_t ChangeAppGcState(pid_t pid, int32_t state) override;
599eace7efcSopenharmony_ci
600eace7efcSopenharmony_ci    /**
601eace7efcSopenharmony_ci     * Register appRunning status listener.
602eace7efcSopenharmony_ci     *
603eace7efcSopenharmony_ci     * @param listener Running status listener.
604eace7efcSopenharmony_ci     * @return Returns ERR_OK on success, others on failure.
605eace7efcSopenharmony_ci     */
606eace7efcSopenharmony_ci    int32_t RegisterAppRunningStatusListener(const sptr<IRemoteObject> &listener) override;
607eace7efcSopenharmony_ci
608eace7efcSopenharmony_ci    /**
609eace7efcSopenharmony_ci     * Unregister appRunning status listener.
610eace7efcSopenharmony_ci     *
611eace7efcSopenharmony_ci     * @param listener Running status listener.
612eace7efcSopenharmony_ci     * @return Returns ERR_OK on success, others on failure.
613eace7efcSopenharmony_ci     */
614eace7efcSopenharmony_ci    int32_t UnregisterAppRunningStatusListener(const sptr<IRemoteObject> &listener) override;
615eace7efcSopenharmony_ci
616eace7efcSopenharmony_ci    /**
617eace7efcSopenharmony_ci     * Register application foreground state observer.
618eace7efcSopenharmony_ci     * @param observer Is App Foreground Statue Observer
619eace7efcSopenharmony_ci     * @return Returns ERR_OK on success, others on failure.
620eace7efcSopenharmony_ci     */
621eace7efcSopenharmony_ci    int32_t RegisterAppForegroundStateObserver(const sptr<IAppForegroundStateObserver> &observer) override;
622eace7efcSopenharmony_ci
623eace7efcSopenharmony_ci    /**
624eace7efcSopenharmony_ci     * Unregister application foreground state observer.
625eace7efcSopenharmony_ci     * @param observer Is App Foreground Statue Observer
626eace7efcSopenharmony_ci     * @return Returns ERR_OK on success, others on failure.
627eace7efcSopenharmony_ci     */
628eace7efcSopenharmony_ci    int32_t UnregisterAppForegroundStateObserver(const sptr<IAppForegroundStateObserver> &observer) override;
629eace7efcSopenharmony_ci
630eace7efcSopenharmony_ci    /**
631eace7efcSopenharmony_ci     * Start child process, called by ChildProcessManager.
632eace7efcSopenharmony_ci     *
633eace7efcSopenharmony_ci     * @param childPid Created child process pid.
634eace7efcSopenharmony_ci     * @param request Child process start request params.
635eace7efcSopenharmony_ci     * @return Returns ERR_OK on success, others on failure.
636eace7efcSopenharmony_ci     */
637eace7efcSopenharmony_ci    int32_t StartChildProcess(pid_t &childPid, const ChildProcessRequest &request) override;
638eace7efcSopenharmony_ci
639eace7efcSopenharmony_ci    /**
640eace7efcSopenharmony_ci     * Get child process record for self.
641eace7efcSopenharmony_ci     *
642eace7efcSopenharmony_ci     * @return child process info.
643eace7efcSopenharmony_ci     */
644eace7efcSopenharmony_ci    int32_t GetChildProcessInfoForSelf(ChildProcessInfo &info) override;
645eace7efcSopenharmony_ci
646eace7efcSopenharmony_ci    /**
647eace7efcSopenharmony_ci     * Attach child process scheduler to app manager service.
648eace7efcSopenharmony_ci     *
649eace7efcSopenharmony_ci     * @param childScheduler scheduler of child process.
650eace7efcSopenharmony_ci     */
651eace7efcSopenharmony_ci    void AttachChildProcess(const sptr<IRemoteObject> &childScheduler) override;
652eace7efcSopenharmony_ci
653eace7efcSopenharmony_ci    /**
654eace7efcSopenharmony_ci     * Exit child process, called by itself.
655eace7efcSopenharmony_ci     */
656eace7efcSopenharmony_ci    void ExitChildProcessSafely() override;
657eace7efcSopenharmony_ci
658eace7efcSopenharmony_ci    /**
659eace7efcSopenharmony_ci     * @brief register a render process state observer to receive change.
660eace7efcSopenharmony_ci     * @param observer the render process state observer to receive notify.
661eace7efcSopenharmony_ci     *
662eace7efcSopenharmony_ci     * @return Returns ERR_OK on success, others on failure.
663eace7efcSopenharmony_ci     */
664eace7efcSopenharmony_ci    int32_t RegisterRenderStateObserver(const sptr<IRenderStateObserver> &observer) override;
665eace7efcSopenharmony_ci
666eace7efcSopenharmony_ci    /**
667eace7efcSopenharmony_ci     * @brief unregister a render process state observer registered before.
668eace7efcSopenharmony_ci     * @param observer the render process state observer registered before.
669eace7efcSopenharmony_ci     *
670eace7efcSopenharmony_ci     * @return Returns ERR_OK on success, others on failure.
671eace7efcSopenharmony_ci     */
672eace7efcSopenharmony_ci    int32_t UnregisterRenderStateObserver(const sptr<IRenderStateObserver> &observer) override;
673eace7efcSopenharmony_ci
674eace7efcSopenharmony_ci    /**
675eace7efcSopenharmony_ci     * @brief update a render process state.
676eace7efcSopenharmony_ci     * @param renderPid the pid of the render process to be updated.
677eace7efcSopenharmony_ci     * @param state the new state value of the render process.
678eace7efcSopenharmony_ci     *
679eace7efcSopenharmony_ci     * @return Returns ERR_OK on success, others on failure.
680eace7efcSopenharmony_ci     */
681eace7efcSopenharmony_ci    int32_t UpdateRenderState(pid_t renderPid, int32_t state) override;
682eace7efcSopenharmony_ci
683eace7efcSopenharmony_ci    /**
684eace7efcSopenharmony_ci     * @brief mark a process which is going restart.
685eace7efcSopenharmony_ci     * @param uid the uid of the process.
686eace7efcSopenharmony_ci     *
687eace7efcSopenharmony_ci     * @return Returns ERR_OK on success, others on failure.
688eace7efcSopenharmony_ci     */
689eace7efcSopenharmony_ci    int32_t SignRestartAppFlag(int32_t uid) override;
690eace7efcSopenharmony_ci
691eace7efcSopenharmony_ci    /**
692eace7efcSopenharmony_ci     * Get appRunningUniqueId by pid.
693eace7efcSopenharmony_ci     * @param pid pid.
694eace7efcSopenharmony_ci     * @param appRunningUniqueId appRunningUniqueId.
695eace7efcSopenharmony_ci     * @return Returns ERR_OK on success, others on failure.
696eace7efcSopenharmony_ci     */
697eace7efcSopenharmony_ci    int32_t GetAppRunningUniqueIdByPid(pid_t pid, std::string &appRunningUniqueId) override;
698eace7efcSopenharmony_ci
699eace7efcSopenharmony_ci    /*
700eace7efcSopenharmony_ci     * Get all uiextension root host process id, need apply permission ohos.permission.GET_RUNNING_INFO.
701eace7efcSopenharmony_ci     * If specified pid mismatch UIExtensionAbility type, return empty vector.
702eace7efcSopenharmony_ci     * @param pid Process id.
703eace7efcSopenharmony_ci     * @param hostPids All host process id.
704eace7efcSopenharmony_ci     * @return Returns ERR_OK on success, others on failure.
705eace7efcSopenharmony_ci     */
706eace7efcSopenharmony_ci    int32_t GetAllUIExtensionRootHostPid(pid_t pid, std::vector<pid_t> &hostPids) override;
707eace7efcSopenharmony_ci
708eace7efcSopenharmony_ci    /**
709eace7efcSopenharmony_ci     * Get all uiextension provider process id, need apply permission ohos.permission.GET_RUNNING_INFO.
710eace7efcSopenharmony_ci     * If specified hostPid didn't start any UIExtensionAbility, return empty vector.
711eace7efcSopenharmony_ci     * @param hostPid Host process id.
712eace7efcSopenharmony_ci     * @param providerPids All provider process id started by specified hostPid.
713eace7efcSopenharmony_ci     * @return Returns ERR_OK on success, others on failure.
714eace7efcSopenharmony_ci     */
715eace7efcSopenharmony_ci    int32_t GetAllUIExtensionProviderPid(pid_t hostPid, std::vector<pid_t> &providerPids) override;
716eace7efcSopenharmony_ci
717eace7efcSopenharmony_ci    /**
718eace7efcSopenharmony_ci     * @brief Notify memory size state changed to sufficient or insufficient.
719eace7efcSopenharmony_ci     * @param isMemorySizeSufficient Indicates the memory size state.
720eace7efcSopenharmony_ci     * @return Returns ERR_OK on success, others on failure.
721eace7efcSopenharmony_ci     */
722eace7efcSopenharmony_ci    int32_t NotifyMemorySizeStateChanged(bool isMemorySizeSufficient) override;
723eace7efcSopenharmony_ci
724eace7efcSopenharmony_ci    /**
725eace7efcSopenharmony_ci     * Set application assertion pause state.
726eace7efcSopenharmony_ci     *
727eace7efcSopenharmony_ci     * @param flag assertion pause state.
728eace7efcSopenharmony_ci     */
729eace7efcSopenharmony_ci    void SetAppAssertionPauseState(bool flag) override;
730eace7efcSopenharmony_ci
731eace7efcSopenharmony_ci    /**
732eace7efcSopenharmony_ci     * @brief set support process cache by self
733eace7efcSopenharmony_ci     */
734eace7efcSopenharmony_ci    int32_t SetSupportedProcessCacheSelf(bool isSupport) override;
735eace7efcSopenharmony_ci
736eace7efcSopenharmony_ci    int32_t SetSupportedProcessCache(int32_t pid, bool isSupport) override;
737eace7efcSopenharmony_ci
738eace7efcSopenharmony_ci    /**
739eace7efcSopenharmony_ci     * set browser channel for caller
740eace7efcSopenharmony_ci     */
741eace7efcSopenharmony_ci    virtual void SaveBrowserChannel(sptr<IRemoteObject> browser) override;
742eace7efcSopenharmony_ci
743eace7efcSopenharmony_ci    /**
744eace7efcSopenharmony_ci     * Check caller is test ability
745eace7efcSopenharmony_ci     *
746eace7efcSopenharmony_ci     * @param pid, the pid of ability.
747eace7efcSopenharmony_ci     * @return Returns ERR_OK is test ability, others is not test ability.
748eace7efcSopenharmony_ci     */
749eace7efcSopenharmony_ci    int32_t CheckCallingIsUserTestMode(const pid_t pid, bool &isUserTest) override;
750eace7efcSopenharmony_ci    /**
751eace7efcSopenharmony_ci     * Start native child process, callde by ChildProcessManager.
752eace7efcSopenharmony_ci     * @param libName lib file name to be load in child process
753eace7efcSopenharmony_ci     * @param childProcessCount current started child process count
754eace7efcSopenharmony_ci     * @param callback callback for notify start result
755eace7efcSopenharmony_ci     * @return Returns ERR_OK on success, others on failure.
756eace7efcSopenharmony_ci     */
757eace7efcSopenharmony_ci    int32_t StartNativeChildProcess(const std::string &libName, int32_t childProcessCount,
758eace7efcSopenharmony_ci        const sptr<IRemoteObject> &callback) override;
759eace7efcSopenharmony_ci
760eace7efcSopenharmony_ci    /**
761eace7efcSopenharmony_ci     * Notify that the process depends on web by itself.
762eace7efcSopenharmony_ci     */
763eace7efcSopenharmony_ci    virtual int32_t NotifyProcessDependedOnWeb() override;
764eace7efcSopenharmony_ci
765eace7efcSopenharmony_ci    /**
766eace7efcSopenharmony_ci     * Kill process depended on web by sa.
767eace7efcSopenharmony_ci     */
768eace7efcSopenharmony_ci    virtual void KillProcessDependedOnWeb() override;
769eace7efcSopenharmony_ci
770eace7efcSopenharmony_ci    /**
771eace7efcSopenharmony_ci     * Restart resident process depended on web.
772eace7efcSopenharmony_ci     */
773eace7efcSopenharmony_ci    virtual void RestartResidentProcessDependedOnWeb() override;
774eace7efcSopenharmony_ci
775eace7efcSopenharmony_ci    int32_t GetAppIndexByPid(pid_t pid, int32_t &appIndex) override;
776eace7efcSopenharmony_ciprivate:
777eace7efcSopenharmony_ci    /**
778eace7efcSopenharmony_ci     * Init, Initialize application services.
779eace7efcSopenharmony_ci     *
780eace7efcSopenharmony_ci     * @return ERR_OK, return back success, others fail.
781eace7efcSopenharmony_ci     */
782eace7efcSopenharmony_ci    ErrCode Init();
783eace7efcSopenharmony_ci
784eace7efcSopenharmony_ci    // the function that overrode from SystemAbility
785eace7efcSopenharmony_ci    /**
786eace7efcSopenharmony_ci     * OnStart, Start application service.
787eace7efcSopenharmony_ci     *
788eace7efcSopenharmony_ci     * @return
789eace7efcSopenharmony_ci     */
790eace7efcSopenharmony_ci    virtual void OnStart() override;
791eace7efcSopenharmony_ci
792eace7efcSopenharmony_ci    /**
793eace7efcSopenharmony_ci     * OnStop, Stop application service.
794eace7efcSopenharmony_ci     *
795eace7efcSopenharmony_ci     * @return
796eace7efcSopenharmony_ci     */
797eace7efcSopenharmony_ci    virtual void OnStop() override;
798eace7efcSopenharmony_ci
799eace7efcSopenharmony_ci    /**
800eace7efcSopenharmony_ci     * @brief Judge whether the application service is ready.
801eace7efcSopenharmony_ci     *
802eace7efcSopenharmony_ci     * @return Returns true means service is ready, otherwise service is not ready.
803eace7efcSopenharmony_ci     */
804eace7efcSopenharmony_ci    bool IsReady() const;
805eace7efcSopenharmony_ci
806eace7efcSopenharmony_ci    /**
807eace7efcSopenharmony_ci     * SetInnerService, Setting application service Inner instance.
808eace7efcSopenharmony_ci     *
809eace7efcSopenharmony_ci     * @return
810eace7efcSopenharmony_ci     */
811eace7efcSopenharmony_ci    void SetInnerService(const std::shared_ptr<AppMgrServiceInner> &innerService);
812eace7efcSopenharmony_ci
813eace7efcSopenharmony_ci    /**
814eace7efcSopenharmony_ci     * Register application or process state observer.
815eace7efcSopenharmony_ci     * @param observer, ability token.
816eace7efcSopenharmony_ci     * @return Returns ERR_OK on success, others on failure.
817eace7efcSopenharmony_ci     */
818eace7efcSopenharmony_ci    virtual int32_t RegisterApplicationStateObserver(const sptr<IApplicationStateObserver> &observer,
819eace7efcSopenharmony_ci        const std::vector<std::string> &bundleNameList = {}) override;
820eace7efcSopenharmony_ci
821eace7efcSopenharmony_ci    /**
822eace7efcSopenharmony_ci     * Unregister application or process state observer.
823eace7efcSopenharmony_ci     * @param observer, ability token.
824eace7efcSopenharmony_ci     * @return Returns ERR_OK on success, others on failure.
825eace7efcSopenharmony_ci     */
826eace7efcSopenharmony_ci    virtual int32_t UnregisterApplicationStateObserver(const sptr<IApplicationStateObserver> &observer) override;
827eace7efcSopenharmony_ci
828eace7efcSopenharmony_ci    /**
829eace7efcSopenharmony_ci     * Register application or process state observer.
830eace7efcSopenharmony_ci     * @param observer, Is ability foreground state observer
831eace7efcSopenharmony_ci     * @return Returns ERR_OK on success, others on failure.
832eace7efcSopenharmony_ci     */
833eace7efcSopenharmony_ci    int32_t RegisterAbilityForegroundStateObserver(const sptr<IAbilityForegroundStateObserver> &observer) override;
834eace7efcSopenharmony_ci
835eace7efcSopenharmony_ci    /**
836eace7efcSopenharmony_ci     * Unregister application or process state observer.
837eace7efcSopenharmony_ci     * @param observer, Is ability foreground state observer
838eace7efcSopenharmony_ci     * @return Returns ERR_OK on success, others on failure.
839eace7efcSopenharmony_ci     */
840eace7efcSopenharmony_ci    int32_t UnregisterAbilityForegroundStateObserver(const sptr<IAbilityForegroundStateObserver> &observer) override;
841eace7efcSopenharmony_ci
842eace7efcSopenharmony_ci    /**
843eace7efcSopenharmony_ci     * Get foreground applications.
844eace7efcSopenharmony_ci     * @param list, foreground apps.
845eace7efcSopenharmony_ci     * @return Returns ERR_OK on success, others on failure.
846eace7efcSopenharmony_ci     */
847eace7efcSopenharmony_ci    virtual int32_t GetForegroundApplications(std::vector<AppStateData> &list) override;
848eace7efcSopenharmony_ci
849eace7efcSopenharmony_ci    int Dump(const std::vector<std::u16string>& args, std::string& result);
850eace7efcSopenharmony_ci    int ShowHelp(const std::vector<std::u16string>& args, std::string& result);
851eace7efcSopenharmony_ci    int DumpIpc(const std::vector<std::u16string>& args, std::string& result);
852eace7efcSopenharmony_ci    int DumpIpcAllStart(std::string& result);
853eace7efcSopenharmony_ci    int DumpIpcAllStop(std::string& result);
854eace7efcSopenharmony_ci    int DumpIpcAllStat(std::string& result);
855eace7efcSopenharmony_ci    int DumpIpcStart(const int32_t pid, std::string& result);
856eace7efcSopenharmony_ci    int DumpIpcStop(const int32_t pid, std::string& result);
857eace7efcSopenharmony_ci    int DumpIpcStat(const int32_t pid, std::string& result);
858eace7efcSopenharmony_ci
859eace7efcSopenharmony_ci    int DumpFfrt(const std::vector<std::u16string>& args, std::string& result);
860eace7efcSopenharmony_ci
861eace7efcSopenharmony_ci    bool JudgeAppSelfCalled(int32_t recordId);
862eace7efcSopenharmony_ci
863eace7efcSopenharmony_ci    /**
864eace7efcSopenharmony_ci     * @brief Notify AbilityManagerService the page show.
865eace7efcSopenharmony_ci     * @param token Ability identify.
866eace7efcSopenharmony_ci     * @param pageStateData The data of ability's page state.
867eace7efcSopenharmony_ci     * @return Returns ERR_OK on success, others on failure.
868eace7efcSopenharmony_ci     */
869eace7efcSopenharmony_ci    virtual int32_t NotifyPageShow(const sptr<IRemoteObject> &token, const PageStateData &pageStateData) override;
870eace7efcSopenharmony_ci
871eace7efcSopenharmony_ci    /**
872eace7efcSopenharmony_ci     * @brief Notify AbilityManagerService the page hide.
873eace7efcSopenharmony_ci     * @param token Ability identify.
874eace7efcSopenharmony_ci     * @param pageStateData The data of ability's page state.
875eace7efcSopenharmony_ci     * @return Returns ERR_OK on success, others on failure.
876eace7efcSopenharmony_ci     */
877eace7efcSopenharmony_ci    virtual int32_t NotifyPageHide(const sptr<IRemoteObject> &token, const PageStateData &pageStateData) override;
878eace7efcSopenharmony_ci
879eace7efcSopenharmony_ci    /**
880eace7efcSopenharmony_ci     * Check whether the bundle is running.
881eace7efcSopenharmony_ci     *
882eace7efcSopenharmony_ci     * @param bundleName Indicates the bundle name of the bundle.
883eace7efcSopenharmony_ci     * @param isRunning Obtain the running status of the application, the result is true if running, false otherwise.
884eace7efcSopenharmony_ci     * @return Return ERR_OK if success, others fail.
885eace7efcSopenharmony_ci     */
886eace7efcSopenharmony_ci    int32_t IsApplicationRunning(const std::string &bundleName, bool &isRunning) override;
887eace7efcSopenharmony_ci
888eace7efcSopenharmony_ci    /**
889eace7efcSopenharmony_ci     * Check whether the bundle is running.
890eace7efcSopenharmony_ci     *
891eace7efcSopenharmony_ci     * @param bundleName Indicates the bundle name of the bundle.
892eace7efcSopenharmony_ci     * @param appCloneIndex the appindex of the bundle.
893eace7efcSopenharmony_ci     * @param isRunning Obtain the running status of the application, the result is true if running, false otherwise.
894eace7efcSopenharmony_ci     * @return Return ERR_OK if success, others fail.
895eace7efcSopenharmony_ci     */
896eace7efcSopenharmony_ci    int32_t IsAppRunning(const std::string &bundleName, int32_t appCloneIndex, bool &isRunning) override;
897eace7efcSopenharmony_ci
898eace7efcSopenharmony_ci    /**
899eace7efcSopenharmony_ci     * Whether the current application process is the last surviving process.
900eace7efcSopenharmony_ci     *
901eace7efcSopenharmony_ci     * @return Returns true is final application process, others return false.
902eace7efcSopenharmony_ci     */
903eace7efcSopenharmony_ci    bool IsFinalAppProcess() override;
904eace7efcSopenharmony_ci
905eace7efcSopenharmony_ci    /**
906eace7efcSopenharmony_ci     * Get pids of processes which belong to specific bundle name and support process cache feature.
907eace7efcSopenharmony_ci     *
908eace7efcSopenharmony_ci     * @param bundleName bundle name.
909eace7efcSopenharmony_ci     * @param pidList pid list of processes that support process cache.
910eace7efcSopenharmony_ci     * @return Returns ERR_OK on success, others on failure.
911eace7efcSopenharmony_ci     */
912eace7efcSopenharmony_ci    virtual int32_t GetSupportedProcessCachePids(const std::string &bundleName,
913eace7efcSopenharmony_ci        std::vector<int32_t> &pidList) override;
914eace7efcSopenharmony_ci
915eace7efcSopenharmony_ci    enum DumpIpcKey {
916eace7efcSopenharmony_ci        KEY_DUMP_IPC_START = 0,
917eace7efcSopenharmony_ci        KEY_DUMP_IPC_STOP,
918eace7efcSopenharmony_ci        KEY_DUMP_IPC_STAT,
919eace7efcSopenharmony_ci    };
920eace7efcSopenharmony_ci
921eace7efcSopenharmony_ciprivate:
922eace7efcSopenharmony_ci    int DumpIpcAllInner(const AppMgrService::DumpIpcKey key, std::string& result);
923eace7efcSopenharmony_ci    int DumpIpcWithPidInner(const AppMgrService::DumpIpcKey key,
924eace7efcSopenharmony_ci        const std::string& optionPid, std::string& result);
925eace7efcSopenharmony_ci
926eace7efcSopenharmony_ci    int DumpFfrtInner(const std::string& pidsRaw, std::string& result);
927eace7efcSopenharmony_ci
928eace7efcSopenharmony_ciprivate:
929eace7efcSopenharmony_ci    std::shared_ptr<AppMgrServiceInner> appMgrServiceInner_;
930eace7efcSopenharmony_ci    AppMgrServiceState appMgrServiceState_;
931eace7efcSopenharmony_ci    std::shared_ptr<AAFwk::TaskHandlerWrap> taskHandler_;
932eace7efcSopenharmony_ci    std::shared_ptr<AMSEventHandler> eventHandler_;
933eace7efcSopenharmony_ci    sptr<ISystemAbilityManager> systemAbilityMgr_;
934eace7efcSopenharmony_ci    sptr<IAmsMgr> amsMgrScheduler_;
935eace7efcSopenharmony_ci
936eace7efcSopenharmony_ci    bool GetDumpIpcKeyByOption(const std::string &option, DumpIpcKey &key);
937eace7efcSopenharmony_ci
938eace7efcSopenharmony_ci    DISALLOW_COPY_AND_MOVE(AppMgrService);
939eace7efcSopenharmony_ci};
940eace7efcSopenharmony_ci}  // namespace AppExecFwk
941eace7efcSopenharmony_ci}  // namespace OHOS
942eace7efcSopenharmony_ci#endif  // OHOS_ABILITY_RUNTIME_APP_MGR_SERVICE_H
943