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