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 
24 namespace OHOS {
25 namespace AppExecFwk {
26 class AppSchedulerProxy : public IRemoteProxy<IAppScheduler> {
27 public:
28     explicit AppSchedulerProxy(const sptr<IRemoteObject> &impl);
29     virtual ~AppSchedulerProxy() = default;
30 
31     /**
32      * ScheduleForegroundApplication, call ScheduleForegroundApplication() through proxy project,
33      * Notify application to switch to foreground.
34      *
35      * @return
36      */
37     virtual bool ScheduleForegroundApplication() override;
38 
39     /**
40      * ScheduleBackgroundApplication, call ScheduleBackgroundApplication() through proxy project,
41      * Notify application to switch to background.
42      *
43      * @return
44      */
45     virtual void ScheduleBackgroundApplication() override;
46 
47     /**
48      * ScheduleTerminateApplication, call ScheduleTerminateApplication() through proxy project,
49      * Notify application to terminate.
50      *
51      * @param isLastProcess When it is the last application process, pass in true.
52      */
53     virtual void ScheduleTerminateApplication(bool isLastProcess = false) override;
54 
55     /**
56      * ScheduleShrinkMemory, call ScheduleShrinkMemory() through proxy project,
57      * Notifies the application of the memory seen.
58      *
59      * @param The memory value.
60      *
61      * @return
62      */
63     virtual void ScheduleShrinkMemory(const int32_t level) override;
64 
65     /**
66      * ScheduleLowMemory, call ScheduleLowMemory() through proxy project,
67      * Notify application to low memory.
68      *
69      * @return
70      */
71     virtual void ScheduleLowMemory() override;
72 
73     /**
74      * ScheduleMemoryLevel, call ScheduleMemoryLevel() through proxy project,
75      * Notify applications background the current memory level.
76      *
77      * @return
78      */
79     virtual void ScheduleMemoryLevel(int32_t level) override;
80 
81     /**
82      * ScheduleHeapMemory, call ScheduleHeapMemory() through proxy project,
83      * Get the application's memory allocation info.
84      *
85      * @param pid, pid input.
86      * @param mallocInfo, dynamic storage information output.
87      *
88      * @return
89      */
90     virtual void ScheduleHeapMemory(const int32_t pid, OHOS::AppExecFwk::MallocInfo &mallocInfo) override;
91 
92     /**
93      * ScheduleJsHeapMemory, call ScheduleJsHeapMemory() through proxy project,
94      * triggerGC and dump the application's jsheap memory info.
95      *
96      * @param info, pid, tid, needGc, needSnapshot
97      *
98      * @return
99      */
100     virtual void ScheduleJsHeapMemory(OHOS::AppExecFwk::JsHeapDumpInfo &info) override;
101 
102     /**
103      * ScheduleLaunchApplication, call ScheduleLaunchApplication() through proxy project,
104      * Notify application to launch application.
105      *
106      * @param The app data value.
107      *
108      * @return
109      */
110     virtual void ScheduleLaunchApplication(const AppLaunchData &launchData, const Configuration &config) override;
111 
112     /**
113      * ScheduleUpdateApplicationInfoInstalled, call ScheduleUpdateApplicationInfoInstalled() through proxy object,
114      * update the application info after new module installed.
115      *
116      * @param appInfo The latest application info obtained from bms for update abilityRuntimeContext.
117      *
118      * @return
119      */
120     virtual void ScheduleUpdateApplicationInfoInstalled(const ApplicationInfo &) override;
121 
122     /**
123      * Notify application to launch ability stage.
124      *
125      * @param The resident process data value.
126      */
127     virtual void ScheduleAbilityStage(const HapModuleInfo &abilityStage) override;
128 
129     /**
130      * ScheduleLaunchAbility, call ScheduleLaunchAbility() through proxy project,
131      * Notify application to launch ability.
132      *
133      * @param The ability info.
134      * @param The ability token.
135      * @param The ability want.
136      * @return
137      */
138     virtual void ScheduleLaunchAbility(const AbilityInfo &, const sptr<IRemoteObject> &,
139         const std::shared_ptr<AAFwk::Want> &want, int32_t abilityRecordId) override;
140 
141     /**
142      * ScheduleCleanAbility, call ScheduleCleanAbility() through proxy project,
143      * Notify application to clean ability.
144      *
145      * @param The ability token.
146      * @return
147      */
148     virtual void ScheduleCleanAbility(const sptr<IRemoteObject> &token, bool isCacheProcess = false) override;
149 
150     /**
151      * ScheduleProfileChanged, call ScheduleProfileChanged() through proxy project,
152      * Notify application to profile update.
153      *
154      * @param The profile data.
155      * @return
156      */
157     virtual void ScheduleProfileChanged(const Profile &profile) override;
158 
159     /**
160      * ScheduleConfigurationUpdated, call ScheduleConfigurationUpdated() through proxy project,
161      * Notify application to configuration update.
162      *
163      * @param The configuration data.
164      * @return
165      */
166     virtual void ScheduleConfigurationUpdated(const Configuration &config) override;
167 
168     /**
169      * ScheduleProcessSecurityExit, call ScheduleProcessSecurityExit() through proxy project,
170      * Notify application process exit safely.
171      *
172      * @return
173      */
174     virtual void ScheduleProcessSecurityExit() override;
175 
176     virtual void ScheduleClearPageStack() override;
177 
178     virtual void ScheduleAcceptWant(const AAFwk::Want &want, const std::string &moduleName) override;
179 
180     virtual void ScheduleNewProcessRequest(const AAFwk::Want &want, const std::string &moduleName) override;
181 
182     int32_t ScheduleNotifyLoadRepairPatch(const std::string &bundleName,
183         const sptr<IQuickFixCallback> &callback, const int32_t recordId) override;
184 
185     int32_t ScheduleNotifyHotReloadPage(const sptr<IQuickFixCallback> &callback, const int32_t recordId) override;
186 
187     int32_t ScheduleNotifyUnLoadRepairPatch(const std::string &bundleName,
188         const sptr<IQuickFixCallback> &callback, const int32_t recordId) override;
189 
190     int32_t ScheduleNotifyAppFault(const FaultData &faultData) override;
191 
192     virtual int32_t ScheduleChangeAppGcState(int32_t state) override;
193 
194     void AttachAppDebug() override;
195     void DetachAppDebug() override;
196 
197     /**
198      * ScheduleDumpIpcStart, call ScheduleDumpIpcStart(std::string& result) through proxy project,
199      * Start querying the application's IPC payload info.
200      *
201      * @param result, start IPC dump result output.
202      *
203      * @return Returns 0 on success, error code on failure.
204      */
205     virtual int32_t ScheduleDumpIpcStart(std::string& result) override;
206 
207     /**
208      * ScheduleDumpIpcStop, call ScheduleDumpIpcStop(std::string& result) through proxy project,
209      * Stop querying the application's IPC payload info.
210      *
211      * @param result, stop IPC dump result output.
212      *
213      * @return Returns 0 on success, error code on failure.
214      */
215     virtual int32_t ScheduleDumpIpcStop(std::string& result) override;
216 
217     /**
218      * ScheduleDumpIpcStat, call ScheduleDumpIpcStat(std::string& result) through proxy project,
219      * Collect the application's IPC payload info.
220      *
221      * @param result, IPC payload result output.
222      *
223      * @return Returns 0 on success, error code on failure.
224      */
225     virtual int32_t ScheduleDumpIpcStat(std::string& result) override;
226 
227     virtual void ScheduleCacheProcess() override;
228 
229     /**
230      * ScheduleDumpFfrt, call ScheduleDumpFfrt(std::string& result) through proxy project,
231      * Start querying the application's ffrt usage.
232      *
233      * @param result, ffrt dump result output.
234      *
235      * @return Returns 0 on success, error code on failure.
236      */
237     virtual int32_t ScheduleDumpFfrt(std::string& result) override;
238 
239 private:
240     bool WriteInterfaceToken(MessageParcel &data);
241     void ScheduleMemoryCommon(const int32_t level, const uint32_t operation);
242     int32_t SendTransactCmd(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
243     static inline BrokerDelegator<AppSchedulerProxy> delegator_;
244 };
245 }  // namespace AppExecFwk
246 }  // namespace OHOS
247 #endif  // OHOS_ABILITY_RUNTIME_APP_SCHEDULER_PROXY_H
248