• 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_AMS_MGR_SCHEDULER_H
17 #define OHOS_ABILITY_RUNTIME_AMS_MGR_SCHEDULER_H
18 
19 #include "ability_info.h"
20 #include "ability_running_record.h"
21 #include "ams_mgr_stub.h"
22 #include "app_debug_listener_interface.h"
23 #include "app_mgr_constants.h"
24 #include "app_mgr_service_inner.h"
25 #include "app_record_id.h"
26 #include "app_running_record.h"
27 #include "app_scheduler_proxy.h"
28 #include "appexecfwk_errors.h"
29 #include "application_info.h"
30 #include "if_system_ability_manager.h"
31 #include "nocopyable.h"
32 #include "system_ability.h"
33 #include "task_handler_wrap.h"
34 
35 namespace OHOS {
36 namespace AppExecFwk {
37 class AmsMgrScheduler : public AmsMgrStub {
38 public:
39     AmsMgrScheduler(
40         const std::shared_ptr<AppMgrServiceInner> &MgrServiceInner_,
41         const std::shared_ptr<AAFwk::TaskHandlerWrap> &Handler_);
42     virtual ~AmsMgrScheduler() override;
43 
44     /**
45      * LoadAbility, call LoadAbility() through proxy project, load the ability that needed to be started.
46      *
47      * @param token, the unique identification to start the ability.
48      * @param preToken, the unique identification to call the ability.
49      * @param abilityInfo, the ability information.
50      * @param appInfo, the app information.
51      * @param want, the starting information.
52      */
53     virtual void LoadAbility(const std::shared_ptr<AbilityInfo> &abilityInfo,
54         const std::shared_ptr<ApplicationInfo> &appInfo,
55         const std::shared_ptr<AAFwk::Want> &want, std::shared_ptr<AbilityRuntime::LoadParam> loadParam) override;
56 
57     /**
58      * TerminateAbility, call TerminateAbility() through the proxy object, terminate the token ability.
59      *
60      * @param token, token, he unique identification to terminate the ability.
61      * @param clearMissionFlag, indicates whether terminate the ability when clearMission.
62      * @return
63      */
64     virtual void TerminateAbility(const sptr<IRemoteObject> &token, bool clearMissionFlag) override;
65 
66     /**
67      * UpdateAbilityState, call UpdateAbilityState() through the proxy object, update the ability status.
68      *
69      * @param token, the unique identification to update the ability.
70      * @param state, ability status that needs to be updated.
71      * @return
72      */
73     virtual void UpdateAbilityState(const sptr<IRemoteObject> &token, const AbilityState state) override;
74 
75     /**
76      * UpdateExtensionState, call UpdateExtensionState() through the proxy object, update the extension status.
77      *
78      * @param token, the unique identification to update the extension.
79      * @param state, extension status that needs to be updated.
80      * @return
81      */
82     virtual void UpdateExtensionState(const sptr<IRemoteObject> &token, const ExtensionState state) override;
83 
84     /**
85      * RegisterAppStateCallback, call RegisterAppStateCallback() through the proxy object, register the callback.
86      *
87      * @param callback, Ams register the callback.
88      * @return
89      */
90     virtual void RegisterAppStateCallback(const sptr<IAppStateCallback> &callback) override;
91 
92     /**
93      * AbilityBehaviorAnalysis, ability behavior analysis assistant process optimization.
94      *
95      * @param token, the unique identification to start the ability.
96      * @param preToken, the unique identification to call the ability.
97      * @param visibility, the visibility information about windows info.
98      * @param perceptibility, the Perceptibility information about windows info.
99      * @param connectionState, the service ability connection state.
100      * @return
101      */
102     virtual void AbilityBehaviorAnalysis(const sptr<IRemoteObject> &token, const sptr<IRemoteObject> &preToken,
103         const int32_t visibility, const int32_t perceptibility, const int32_t connectionState) override;
104 
105     /**
106      * KillProcessByAbilityToken, call KillProcessByAbilityToken() through proxy object,
107      * kill the process by ability token.
108      *
109      * @param token, the unique identification to the ability.
110      * @return
111      */
112     virtual void KillProcessByAbilityToken(const sptr<IRemoteObject> &token) override;
113 
114     /**
115      * KillProcessesByUserId, call KillProcessesByUserId() through proxy object,
116      * kill the processes by userId.
117      *
118      * @param userId, the user id.
119      * @return
120      */
121     virtual void KillProcessesByUserId(int32_t userId) override;
122 
123     virtual void KillProcessesByPids(std::vector<int32_t> &pids) override;
124 
125     virtual void AttachPidToParent(const sptr<IRemoteObject> &token, const sptr<IRemoteObject> &callerToken) override;
126 
127     /**
128      * KillProcessWithAccount, call KillProcessWithAccount() through proxy object, kill the
129      * process.
130      *
131      * @param bundleName, bundle name in Application record.
132      * @param accountId, account ID.
133      * @return ERR_OK, return back success, others fail.
134      */
135     virtual int32_t KillProcessWithAccount(const std::string &bundleName, const int accountId) override;
136 
137     /**
138      * UpdateApplicationInfoInstalled, call UpdateApplicationInfoInstalled() through proxy object,
139      * update the application info after new module installed.
140      *
141      * @param bundleName, bundle name in Application record.
142      * @param  uid, uid.
143      * @return ERR_OK, return back success, others fail.
144      */
145     virtual int32_t UpdateApplicationInfoInstalled(const std::string &bundleName, const int uid) override;
146 
147     /**
148      * KillApplication, call KillApplication() through proxy object, kill the application.
149      *
150      * @param  bundleName, bundle name in Application record.
151      * @return ERR_OK, return back success, others fail.
152      */
153     virtual int32_t KillApplication(const std::string &bundleName) override;
154 
155     /**
156      * ForceKillApplication, force kill the application.
157      *
158      * @param  bundleName, bundle name in Application record.
159      * @param  userId, userId.
160      * @param  appIndex, appIndex.
161      * @return ERR_OK, return back success, others fail.
162      */
163     virtual int32_t ForceKillApplication(const std::string &bundleName, const int userId = -1,
164         const int appIndex = 0) override;
165 
166     /**
167      * KillProcessesByAccessTokenId.
168      *
169      * @param  accessTokenId, accessTokenId.
170      * @return ERR_OK, return back success, others fail.
171      */
172     virtual int32_t KillProcessesByAccessTokenId(const uint32_t accessTokenId) override;
173 
174     /**
175      * KillApplicationByUid, call KillApplicationByUid() through proxy object, kill the application.
176      *
177      * @param  bundleName, bundle name in Application record.
178      * @param  uid, uid.
179      * @param  reason, caller function name.
180      * @return ERR_OK, return back success, others fail.
181      */
182     virtual int KillApplicationByUid(const std::string &bundleName, const int uid,
183         const std::string& reason = "KillApplicationByUid") override;
184 
185     virtual int KillApplicationSelf(const std::string& reason = "KillApplicationSelf") override;
186 
187     int GetApplicationInfoByProcessID(const int pid, AppExecFwk::ApplicationInfo &application, bool &debug) override;
188 
189     virtual int32_t NotifyAppMgrRecordExitReason(int32_t pid, int32_t reason, const std::string &exitMsg) override;
190 
191     virtual void AbilityAttachTimeOut(const sptr<IRemoteObject> &token) override;
192 
193     virtual void PrepareTerminate(const sptr<IRemoteObject> &token, bool clearMissionFlag = false) override;
194 
195     virtual void GetRunningProcessInfoByToken(
196         const sptr<IRemoteObject> &token, AppExecFwk::RunningProcessInfo &info) override;
197 
198     /**
199      * Set AbilityForegroundingFlag of an app-record to true.
200      *
201      * @param pid, pid.
202      *
203      */
204     void SetAbilityForegroundingFlagToAppRecord(const pid_t pid) override;
205 
206     virtual void StartSpecifiedAbility(
207         const AAFwk::Want &want, const AppExecFwk::AbilityInfo &abilityInfo, int32_t requestId = 0) override;
208 
209     virtual void RegisterStartSpecifiedAbilityResponse(const sptr<IStartSpecifiedAbilityResponse> &response) override;
210 
211     virtual void StartSpecifiedProcess(const AAFwk::Want &want, const AppExecFwk::AbilityInfo &abilityInfo,
212         int32_t requestId = 0) override;
213 
214     virtual void SetCurrentUserId(const int32_t userId) override;
215 
216     virtual void SetEnableStartProcessFlagByUserId(int32_t userId, bool enableStartProcess) override;
217 
218     virtual int32_t GetBundleNameByPid(const int pid, std::string &bundleName, int32_t &uid) override;
219 
220     /**
221      * @brief Register app debug listener.
222      * @param listener App debug listener.
223      * @return ERR_OK, return back success, others fail.
224      */
225     int32_t RegisterAppDebugListener(const sptr<IAppDebugListener> &listener) override;
226 
227     /**
228      * @brief Unregister app debug listener.
229      * @param listener App debug listener.
230      * @return ERR_OK, return back success, others fail.
231      */
232     int32_t UnregisterAppDebugListener(const sptr<IAppDebugListener> &listener) override;
233 
234     /**
235      * @brief Attach app debug.
236      * @param bundleName The application bundle name.
237      * @return Returns ERR_OK on success, others on failure.
238      */
239     int32_t AttachAppDebug(const std::string &bundleName) override;
240 
241     /**
242      * @brief Detach app debug.
243      * @param bundleName The application bundle name.
244      * @return Returns ERR_OK on success, others on failure.
245      */
246     int32_t DetachAppDebug(const std::string &bundleName) override;
247 
248     /**
249      * @brief Set app waiting debug mode.
250      * @param bundleName The application bundle name.
251      * @param isPersist The persist flag.
252      * @return Returns ERR_OK on success, others on failure.
253      */
254     int32_t SetAppWaitingDebug(const std::string &bundleName, bool isPersist) override;
255 
256     /**
257      * @brief Cancel app waiting debug mode.
258      * @return Returns ERR_OK on success, others on failure.
259      */
260     int32_t CancelAppWaitingDebug() override;
261 
262     /**
263      * @brief Get waiting debug mode application.
264      * @param debugInfoList The debug info list, including bundle name and persist flag.
265      * @return Returns ERR_OK on success, others on failure.
266      */
267     int32_t GetWaitingDebugApp(std::vector<std::string> &debugInfoList) override;
268 
269     /**
270      * @brief Determine whether it is a waiting debug application based on the bundle name.
271      * @return Returns true if it is a waiting debug application, otherwise it returns false.
272      */
273     bool IsWaitingDebugApp(const std::string &bundleName) override;
274 
275     /**
276      * @brief Clear non persist waiting debug flag.
277      */
278     void ClearNonPersistWaitingDebugFlag() override;
279 
280     /**
281      * @brief Registering ability debug mode response.
282      * @param response Response for ability debug object.
283      * @return Returns ERR_OK on success, others on failure.
284      */
285     int32_t RegisterAbilityDebugResponse(const sptr<IAbilityDebugResponse> &response) override;
286 
287     /**
288      * @brief Determine whether it is an attachment debug application based on the bundle name.
289      * @param bundleName The application bundle name.
290      * @return Returns true if it is an attach debug application, otherwise it returns false.
291      */
292     bool IsAttachDebug(const std::string &bundleName) override;
293 
294     /**
295      * @brief Set resident process enable status.
296      * @param bundleName The application bundle name.
297      * @param enable The current updated enable status.
298      */
299     void SetKeepAliveEnableState(const std::string &bundleName, bool enable, int32_t uid) override;
300 
301     /**
302      * To clear the process by ability token.
303      *
304      * @param token the unique identification to the ability.
305      */
306     virtual void ClearProcessByToken(sptr<IRemoteObject> token) override;
307 
308     /**
309      * whether memory size is sufficent.
310      * @return Returns true is sufficent memory size, others return false.
311      */
312     virtual bool IsMemorySizeSufficent() override;
313 
314     /**
315      * Notifies that one ability is attached to status bar.
316      *
317      * @param token the token of the abilityRecord that is attached to status bar.
318      */
319     void AttachedToStatusBar(const sptr<IRemoteObject> &token) override;
320 
321     virtual void BlockProcessCacheByPids(const std::vector<int32_t> &pids) override;
322 
323     /**
324      * whether killed for upgrade web.
325      *
326      * @param bundleName the bundle name is killed for upgrade web.
327      * @return Returns true is killed for upgrade web, others return false.
328      */
329     virtual bool IsKilledForUpgradeWeb(const std::string &bundleName) override;
330 
331     /**
332      * Request to clean uiability from user.
333      *
334      * @param token the token of ability.
335      * @return Returns true if clean success, others return false.
336      */
337     virtual bool CleanAbilityByUserRequest(const sptr<IRemoteObject> &token) override;
338 
339     /**
340      * whether the abilities of process specified by pid type only UIAbility.
341      * @return Returns true is only UIAbility, otherwise return false
342      */
343     virtual bool IsProcessContainsOnlyUIAbility(const pid_t pid) override;
344 
345     virtual bool IsProcessAttached(sptr<IRemoteObject> token) override;
346 
347 private:
348     /**
349      * @brief Judge whether the application service is ready.
350      *
351      * @return Returns true means service is ready, otherwise service is not ready.
352      */
353     bool IsReady() const;
354 
355 private:
356     std::shared_ptr<AppMgrServiceInner> amsMgrServiceInner_;
357     std::shared_ptr<AAFwk::TaskHandlerWrap> amsHandler_;
358     sptr<ISystemAbilityManager> systemAbilityMgr_;
359 
360     DISALLOW_COPY_AND_MOVE(AmsMgrScheduler);
361 };
362 }  // namespace AppExecFwk
363 }  // namespace OHOS
364 #endif  // OHOS_ABILITY_RUNTIME_AMS_MGR_SCHEDULER_H
365