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_SCHEDULER_INTERFACE_H
17 #define OHOS_ABILITY_RUNTIME_APP_SCHEDULER_INTERFACE_H
18 
19 #include "iremote_broker.h"
20 #include "ability_info.h"
21 #include "app_launch_data.h"
22 #include "configuration.h"
23 #include "fault_data.h"
24 #include "hap_module_info.h"
25 #include "iquick_fix_callback.h"
26 #include "want.h"
27 #include "app_malloc_info.h"
28 #include "app_jsheap_mem_info.h"
29 
30 namespace OHOS {
31 namespace AppExecFwk {
32 class IAppScheduler : public IRemoteBroker {
33 public:
34     DECLARE_INTERFACE_DESCRIPTOR(u"ohos.appexecfwk.AppScheduler");
35 
36     /**
37      * ScheduleForegroundApplication, call ScheduleForegroundApplication() through proxy project,
38      * Notify application to switch to foreground.
39      *
40      * @return
41      */
42     virtual bool ScheduleForegroundApplication() = 0;
43 
44     /**
45      * ScheduleBackgroundApplication, call ScheduleBackgroundApplication() through proxy project,
46      * Notify application to switch to background.
47      *
48      * @return
49      */
50     virtual void ScheduleBackgroundApplication() = 0;
51 
52     /**
53      * ScheduleTerminateApplication, call ScheduleTerminateApplication() through proxy project,
54      * Notify application to terminate.
55      *
56      * @param isLastProcess When it is the last application process, pass in true.
57      */
58     virtual void ScheduleTerminateApplication(bool isLastProcess = false) = 0;
59 
60     /**
61      * ScheduleShrinkMemory, call ScheduleShrinkMemory() through proxy project,
62      * Notifies the application of the memory seen.
63      *
64      * @param The memory value.
65      *
66      * @return
67      */
68     virtual void ScheduleShrinkMemory(const int) = 0;
69 
70     /**
71      * ScheduleLowMemory, call ScheduleLowMemory() through proxy project,
72      * Notify application to low memory.
73      *
74      * @return
75      */
76     virtual void ScheduleLowMemory() = 0;
77 
78     /**
79      * ScheduleMemoryLevel, call ScheduleMemoryLevel() through proxy project,
80      * Notify applications background the current memory level.
81      *
82      * @return
83      */
84     virtual void ScheduleMemoryLevel(int32_t level) = 0;
85 
86     /**
87      * ScheduleHeapMemory, call ScheduleHeapMemory() through proxy project,
88      * Get the application's memory allocation info.
89      *
90      * @param pid, pid input.
91      * @param mallocInfo, dynamic storage information output.
92      *
93      * @return
94      */
95     virtual void ScheduleHeapMemory(const int32_t pid, OHOS::AppExecFwk::MallocInfo &mallocInfo) = 0;
96 
97     /**
98      * ScheduleJsHeapMemory, call ScheduleJsHeapMemory() through proxy project,
99      * triggerGC and dump the application's jsheap memory info.
100      *
101      * @param info, pid, tid, needGc, needSnapshot
102      *
103      * @return
104      */
105     virtual void ScheduleJsHeapMemory(OHOS::AppExecFwk::JsHeapDumpInfo &info) = 0;
106 
107     /**
108      * ScheduleLaunchApplication, call ScheduleLaunchApplication() through proxy project,
109      * Notify application to launch application.
110      *
111      * @param The app data value.
112      *
113      * @return
114      */
115     virtual void ScheduleLaunchApplication(const AppLaunchData &, const Configuration &) = 0;
116 
117     /**
118      * ScheduleUpdateApplicationInfoInstalled, call ScheduleUpdateApplicationInfoInstalled() through proxy object,
119      * update the application info after new module installed.
120      *
121      * @param appInfo The latest application info obtained from bms for update abilityRuntimeContext.
122      *
123      * @return
124      */
125     virtual void ScheduleUpdateApplicationInfoInstalled(const ApplicationInfo &) = 0;
126 
127     /**
128      * ScheduleAbilityStageInfo, call ScheduleAbilityStageInfo() through proxy project,
129      * Notify application to launch application.
130      *
131      * @param The app data value.
132      *
133      * @return
134      */
135     virtual void ScheduleAbilityStage(const HapModuleInfo &) = 0;
136 
137     virtual void ScheduleLaunchAbility(const AbilityInfo &, const sptr<IRemoteObject> &,
138         const std::shared_ptr<AAFwk::Want> &want, int32_t abilityRecordId) = 0;
139 
140     /**
141      * ScheduleCleanAbility, call ScheduleCleanAbility() through proxy project,
142      * Notify application to clean ability.
143      *
144      * @param The ability token.
145      * @return
146      */
147     virtual void ScheduleCleanAbility(const sptr<IRemoteObject> &, bool isCacheProcess = false) = 0;
148 
149     /**
150      * ScheduleProfileChanged, call ScheduleProfileChanged() through proxy project,
151      * Notify application to profile update.
152      *
153      * @param The profile data.
154      * @return
155      */
156     virtual void ScheduleProfileChanged(const Profile &) = 0;
157 
158     /**
159      * ScheduleConfigurationUpdated, call ScheduleConfigurationUpdated() through proxy project,
160      * Notify application to configuration update.
161      *
162      * @param The configuration data.
163      * @return
164      */
165     virtual void ScheduleConfigurationUpdated(const Configuration &config) = 0;
166 
167     /**
168      * ScheduleProcessSecurityExit, call ScheduleProcessSecurityExit() through proxy project,
169      * Notify application process exit safely.
170      *
171      * @return
172      */
173     virtual void ScheduleProcessSecurityExit() = 0;
174 
175     virtual void ScheduleClearPageStack() = 0;
176 
177     virtual void ScheduleAcceptWant(const AAFwk::Want &want, const std::string &moduleName) = 0;
178 
179     virtual void ScheduleNewProcessRequest(const AAFwk::Want &want, const std::string &moduleName) = 0;
180 
181     /**
182      * @brief Notify application load patch.
183      *
184      * @param bundleName Bundle name
185      * @param callback called when LoadPatch finished.
186      * @return Returns 0 on success, error code on failure.
187      */
188     virtual int32_t ScheduleNotifyLoadRepairPatch(const std::string &bundleName,
189         const sptr<IQuickFixCallback> &callback, const int32_t recordId) = 0;
190 
191     /**
192      * @brief Notify application reload page.
193      *
194      * @param callback called when HotReload finished.
195      * @return Returns 0 on success, error code on failure.
196      */
197     virtual int32_t ScheduleNotifyHotReloadPage(const sptr<IQuickFixCallback> &callback, const int32_t recordId) = 0;
198 
199     /**
200      * @brief Notify application unload patch.
201      *
202      * @param bundleName Bundle name
203      * @param callback called when UnloadPatch finished.
204      * @return Returns 0 on success, error code on failure.
205      */
206     virtual int32_t ScheduleNotifyUnLoadRepairPatch(const std::string &bundleName,
207         const sptr<IQuickFixCallback> &callback, const int32_t recordId) = 0;
208 
209     /**
210      * @brief Schedule Notify App Fault Data.
211      *
212      * @param faultData fault data
213      * @return Returns ERR_OK on success, error code on failure.
214      */
215     virtual int32_t ScheduleNotifyAppFault(const FaultData &faultData) = 0;
216 
217     /**
218      * @brief Notify NativeEngine GC of status change.
219      *
220      * @param state GC state
221      * @param pid pid
222      *
223      * @return Is the status change completed.
224      */
225     virtual int32_t ScheduleChangeAppGcState(int32_t state) = 0;
226 
227     /**
228      * @brief Attach app debug.
229      */
230     virtual void AttachAppDebug() = 0;
231 
232     /**
233      * @brief Detach app debug.
234      */
235     virtual void DetachAppDebug() = 0;
236 
237     /**
238      * ScheduleDumpIpcStart, call ScheduleDumpIpcStart(std::string& result) through proxy project,
239      * Start querying the application's IPC payload info.
240      *
241      * @param result, start IPC dump result output.
242      *
243      * @return Returns 0 on success, error code on failure.
244      */
245     virtual int32_t ScheduleDumpIpcStart(std::string& result) = 0;
246 
247     /**
248      * ScheduleDumpIpcStop, call ScheduleDumpIpcStop(std::string& result) through proxy project,
249      * Stop querying the application's IPC payload info.
250      *
251      * @param result, stop IPC dump result output.
252      *
253      * @return Returns 0 on success, error code on failure.
254      */
255     virtual int32_t ScheduleDumpIpcStop(std::string& result) = 0;
256 
257     /**
258      * ScheduleDumpIpcStat, call ScheduleDumpIpcStat(std::string& result) through proxy project,
259      * Collect the application's IPC payload info.
260      *
261      * @param result, IPC payload result output.
262      *
263      * @return Returns 0 on success, error code on failure.
264      */
265     virtual int32_t ScheduleDumpIpcStat(std::string& result) = 0;
266 
267     virtual void ScheduleCacheProcess() = 0;
268 
269     /**
270      * ScheduleDumpFfrt, call ScheduleDumpFfrt(std::string& result) through proxy project,
271      * Start querying the application's ffrt usage.
272      *
273      * @param result, ffrt dump result output.
274      *
275      * @return Returns 0 on success, error code on failure.
276      */
277     virtual int32_t ScheduleDumpFfrt(std::string& result) = 0;
278 
279     enum class Message {
280         SCHEDULE_FOREGROUND_APPLICATION_TRANSACTION = 0,
281         SCHEDULE_BACKGROUND_APPLICATION_TRANSACTION,
282         SCHEDULE_TERMINATE_APPLICATION_TRANSACTION,
283         SCHEDULE_LOWMEMORY_APPLICATION_TRANSACTION,
284         SCHEDULE_SHRINK_MEMORY_APPLICATION_TRANSACTION,
285         SCHEDULE_LAUNCH_ABILITY_TRANSACTION,
286         SCHEDULE_CLEAN_ABILITY_TRANSACTION,
287         SCHEDULE_LAUNCH_APPLICATION_TRANSACTION,
288         SCHEDULE_PROFILE_CHANGED_TRANSACTION,
289         SCHEDULE_CONFIGURATION_UPDATED,
290         SCHEDULE_PROCESS_SECURITY_EXIT_TRANSACTION,
291         SCHEDULE_ABILITY_STAGE_INFO,
292         SCHEDULE_ACCEPT_WANT,
293         SCHEDULE_MEMORYLEVEL_APPLICATION_TRANSACTION,
294         SCHEDULE_NOTIFY_LOAD_REPAIR_PATCH,
295         SCHEDULE_NOTIFY_HOT_RELOAD_PAGE,
296         SCHEDULE_NOTIFY_UNLOAD_REPAIR_PATCH,
297         SCHEDULE_UPDATE_APPLICATION_INFO_INSTALLED,
298         SCHEDULE_HEAPMEMORY_APPLICATION_TRANSACTION,
299         SCHEDULE_NOTIFY_FAULT,
300         APP_GC_STATE_CHANGE,
301         SCHEDULE_ATTACH_APP_DEBUG,
302         SCHEDULE_DETACH_APP_DEBUG,
303         SCHEDULE_NEW_PROCESS_REQUEST,
304         SCHEDULE_JSHEAP_MEMORY_APPLICATION_TRANSACTION,
305         SCHEDULE_DUMP_IPC_START,
306         SCHEDULE_DUMP_IPC_STOP,
307         SCHEDULE_DUMP_IPC_STAT,
308         SCHEDULE_DUMP_FFRT,
309         SCHEDULE_CACHE_PROCESS,
310         SCHEDULE_CLEAR_PAGE_STACK,
311     };
312 };
313 }  // namespace AppExecFwk
314 }  // namespace OHOS
315 #endif  // OHOS_ABILITY_RUNTIME_APP_SCHEDULER_INTERFACE_H
316