• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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_LIFECYCLE_DEAL_H
17 #define OHOS_ABILITY_RUNTIME_APP_LIFECYCLE_DEAL_H
18 
19 #include "app_scheduler_proxy.h"
20 #include "app_launch_data.h"
21 #include "ability_running_record.h"
22 #include "fault_data.h"
23 #include "hap_module_info.h"
24 #include "want.h"
25 #include "app_malloc_info.h"
26 #include "app_jsheap_mem_info.h"
27 #include "app_cjheap_mem_info.h"
28 
29 namespace OHOS {
30 namespace AppExecFwk {
31 class AppLifeCycleDeal {
32 public:
33     AppLifeCycleDeal();
34     virtual ~AppLifeCycleDeal();
35 
36     /**
37      * LaunchApplication, call ScheduleLaunchApplication() through proxy project,
38      * Notify application to launch application.
39      *
40      * @param launchData The app data when launch.
41      * @param config The app config when launch.
42      * @return
43      */
44     void LaunchApplication(const AppLaunchData &launchData, const Configuration &config);
45 
46     /**
47      * update the application info after new module installed.
48      *
49      * @param appInfo The latest application info obtained from bms for update abilityRuntimeContext.
50      *
51      * @return
52      */
53     void UpdateApplicationInfoInstalled(const ApplicationInfo &appInfo, const std::string &moduleName);
54 
55     /**
56      * AddAbilityStageInfo, call ScheduleAbilityStageInfo() through proxy project,
57      * Notify application to launch application.
58      *
59      * @param abilityStage The app data value.
60      *
61      * @return
62      */
63     void AddAbilityStage(const HapModuleInfo &abilityStage);
64 
65     /**
66      * LaunchAbility, call ScheduleLaunchAbility() through proxy project,
67      * Notify application to launch ability.
68      *
69      * @param ability The ability info.
70      * @return
71      */
72     void LaunchAbility(const std::shared_ptr<AbilityRunningRecord> &ability);
73 
74     /**
75      * ScheduleTerminate, call ScheduleTerminateApplication() through proxy project,
76      * Notify application to terminate.
77      *
78      * @param isLastProcess When it is the last application process, pass in true.
79      *
80      * @return
81      */
82     void ScheduleTerminate(bool isLastProcess = false);
83 
84     /**
85      * ScheduleForegroundRunning, call ScheduleForegroundApplication() through proxy project,
86      * Notify application to switch to foreground.
87      *
88      * @return bool operation status
89      */
90     bool ScheduleForegroundRunning();
91 
92     /**
93      * ScheduleBackgroundRunning, call ScheduleBackgroundApplication() through proxy project,
94      * Notify application to switch to background.
95      *
96      * @return
97      */
98     void ScheduleBackgroundRunning();
99 
100     /**
101      * ScheduleTrimMemory, call ScheduleShrinkMemory() through proxy project,
102      * Notifies the application of the memory seen.
103      *
104      * @param timeLevel The memory value.
105      *
106      * @return
107      */
108     void ScheduleTrimMemory(int32_t timeLevel);
109 
110     /**
111      * ScheduleMemoryLevel, call ScheduleMemoryLevel() through proxy project,
112      * Notifies the application of the current memory.
113      *
114      * @param The memory level.
115      *
116      * @return
117      */
118     void ScheduleMemoryLevel(int32_t Level);
119 
120     /**
121      * ScheduleHeapMemory, call ScheduleHeapMemory() through proxy project,
122      * Get the application's memory allocation info.
123      *
124      * @param pid, pid input.
125      * @param mallocInfo, dynamic storage information output.
126      *
127      * @return
128      */
129     void ScheduleHeapMemory(const int32_t pid, OHOS::AppExecFwk::MallocInfo &mallocInfo);
130 
131     /**
132      * ScheduleJsHeapMemory, call ScheduleJsHeapMemory() through proxy project,
133      * triggerGC and dump the application's jsheap memory info.
134      *
135      * @param info, pid, tid, needGc, needSnapshot
136      *
137      * @return
138      */
139     void ScheduleJsHeapMemory(OHOS::AppExecFwk::JsHeapDumpInfo &info);
140 
141     /**
142      * ScheduleCjHeapMemory, call ScheduleCjHeapMemory() through proxy project,
143      * triggerGC and dump the application's cjheap memory info.
144      *
145      * @param info, pid, needGc, needSnapshot
146      *
147      * @return
148      */
149     void ScheduleCjHeapMemory(OHOS::AppExecFwk::CjHeapDumpInfo &info);
150 
151     /**
152      * LowMemoryWarning, call ScheduleLowMemory() through proxy project,
153      * Notify application to low memory.
154      *
155      * @return
156      */
157     void LowMemoryWarning();
158 
159     /**
160      * ScheduleCleanAbility, call ScheduleCleanAbility() through proxy project,
161      * Notify application to clean ability.
162      *
163      * @param token, The ability token.
164      * @return
165      */
166     void ScheduleCleanAbility(const sptr<IRemoteObject> &token, bool isCacheProcess = false);
167 
168     /**
169      * ScheduleProcessSecurityExit, call ScheduleTerminateApplication() through proxy project,
170      * Notify application process exit safely.
171      *
172      * @return
173      */
174     void ScheduleProcessSecurityExit();
175 
176     /**
177      * scheduleClearPageStack, call scheduleClearPageStack() through proxy project,
178      * Notify application clear recovery page stack.
179      *
180      * @return
181      */
182     void ScheduleClearPageStack();
183 
184     /**
185      * @brief Setting client for application record.
186      *
187      * @param thread, the application client.
188      */
189     void SetApplicationClient(const sptr<IAppScheduler> &thread);
190 
191     /**
192      * @brief Obtains the client of the application record.
193      *
194      * @return Returns the application client.
195      */
196     sptr<IAppScheduler> GetApplicationClient() const;
197 
198     /**
199      * @brief Schedule the given module the onAcceptWant lifecycle call.
200      *
201      * @param want the param passed to onAcceptWant lifecycle.
202      * @param want the moduleName of which being scheduled.
203      */
204     void ScheduleAcceptWant(const AAFwk::Want &want, const std::string &moduleName);
205 
206     void SchedulePrepareTerminate(const std::string &moduleName);
207 
208     void ScheduleNewProcessRequest(const AAFwk::Want &want, const std::string &moduleName);
209 
210     /**
211      * UpdateConfiguration, ANotify application update system environment changes.
212      *
213      * @param config, System environment change parameters.
214      * @return Returns ERR_OK on success, others on failure.
215      */
216     int32_t UpdateConfiguration(const Configuration &config);
217 
218     /**
219      * @brief Notify application load patch.
220      *
221      * @param bundleName Bundle name
222      * @param callback called when LoadPatch finished.
223      * @param recordId callback data
224      * @return Returns 0 on success, error code on failure.
225      */
226     int32_t NotifyLoadRepairPatch(const std::string &bundleName, const sptr<IQuickFixCallback> &callback,
227         const int32_t recordId);
228 
229     /**
230      * @brief Notify application reload page.
231      *
232      * @param callback called when HotReload finished.
233      * @param recordId callback data
234      * @return Returns 0 on success, error code on failure.
235      */
236     int32_t NotifyHotReloadPage(const sptr<IQuickFixCallback> &callback, const int32_t recordId);
237 
238     /**
239      * @brief Notify application unload patch.
240      *
241      * @param bundleName Bundle name
242      * @param callback called when UnloadPatch finished.
243      * @param recordId callback data
244      * @return Returns 0 on success, error code on failure.
245      */
246     int32_t NotifyUnLoadRepairPatch(const std::string &bundleName, const sptr<IQuickFixCallback> &callback,
247         const int32_t recordId);
248 
249     /**
250      * Notify Fault Data
251      *
252      * @param faultData the fault data.
253      * @return Returns ERR_OK on success, others on failure.
254      */
255     int32_t NotifyAppFault(const FaultData &faultData);
256 
257     /**
258      * @brief Notify NativeEngine GC of status change.
259      *
260      * @param state GC state
261      *
262      * @return Is the status change completed.
263      */
264     int32_t ChangeAppGcState(int32_t state, uint64_t tid = 0);
265 
266     /**
267      * @brief attach to a process to debug.
268      *
269      * @return ERR_OK, return back success, others fail.
270      */
271     int32_t AttachAppDebug(bool isDebugFromLocal);
272 
273     /**
274      * @brief detach a debugging process.
275      *
276      * @return ERR_OK, return back success, others fail.
277      */
278     int32_t DetachAppDebug();
279 
280     /**
281      * Whether the current application process is the last surviving process.
282      *
283      * @return Returns true is final application process, others return false.
284      */
285     bool IsFinalAppProcess();
286 
287     int DumpIpcStart(std::string& result);
288 
289     int DumpIpcStop(std::string& result);
290 
291     int DumpIpcStat(std::string& result);
292 
293     /**
294      * Notifies the application of process caching.
295      */
296     void ScheduleCacheProcess();
297 
298     int DumpFfrt(std::string& result);
299 
300     /**
301      * SetWatchdogBackgroundStatusRunning , call SetWatchdogBackgroundStatusRunning(bool status) through proxy project,
302      * Notify application to set watchdog background status.
303      *
304      * @return
305      */
306     void SetWatchdogBackgroundStatusRunning(bool status);
307 
308 private:
309     mutable std::mutex schedulerMutex_;
310     sptr<IAppScheduler> appThread_ = nullptr;
311 };
312 }  // namespace AppExecFwk
313 }  // namespace OHOS
314 
315 #endif  // OHOS_ABILITY_RUNTIME_APP_LIFECYCLE_DEAL_H
316