• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 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 sptr<IRemoteObject> &token, const sptr<IRemoteObject> &preToken,
54         const std::shared_ptr<AbilityInfo> &abilityInfo, const std::shared_ptr<ApplicationInfo> &appInfo,
55         const std::shared_ptr<AAFwk::Want> &want) 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     /**
124      * KillProcessWithAccount, call KillProcessWithAccount() through proxy object, kill the
125      * process.
126      *
127      * @param bundleName, bundle name in Application record.
128      * @param accountId, account ID.
129      * @return ERR_OK, return back success, others fail.
130      */
131     virtual int32_t KillProcessWithAccount(const std::string &bundleName, const int accountId) override;
132 
133     /**
134      * UpdateApplicationInfoInstalled, call UpdateApplicationInfoInstalled() through proxy object,
135      * update the application info after new module installed.
136      *
137      * @param bundleName, bundle name in Application record.
138      * @param  uid, uid.
139      * @return ERR_OK, return back success, others fail.
140      */
141     virtual int32_t UpdateApplicationInfoInstalled(const std::string &bundleName, const int uid) override;
142 
143     /**
144      * KillApplication, call KillApplication() through proxy object, kill the application.
145      *
146      * @param  bundleName, bundle name in Application record.
147      * @return ERR_OK, return back success, others fail.
148      */
149     virtual int32_t KillApplication(const std::string &bundleName) override;
150 
151     /**
152      * KillApplicationByUid, call KillApplicationByUid() through proxy object, kill the application.
153      *
154      * @param  bundleName, bundle name in Application record.
155      * @param  uid, uid.
156      * @return ERR_OK, return back success, others fail.
157      */
158     virtual int KillApplicationByUid(const std::string &bundleName, const int uid) override;
159 
160     virtual int KillApplicationSelf() override;
161 
162     int GetApplicationInfoByProcessID(const int pid, AppExecFwk::ApplicationInfo &application, bool &debug) override;
163 
164     virtual void AbilityAttachTimeOut(const sptr<IRemoteObject> &token) override;
165 
166     virtual void PrepareTerminate(const sptr<IRemoteObject> &token) override;
167 
168     virtual void GetRunningProcessInfoByToken(
169         const sptr<IRemoteObject> &token, AppExecFwk::RunningProcessInfo &info) override;
170 
171     void GetRunningProcessInfoByPid(const pid_t pid, OHOS::AppExecFwk::RunningProcessInfo &info) override;
172 
173     /**
174      * Set AbilityForegroundingFlag of an app-record to true.
175      *
176      * @param pid, pid.
177      *
178      */
179     void SetAbilityForegroundingFlagToAppRecord(const pid_t pid) override;
180 
181     virtual void StartSpecifiedAbility(
182         const AAFwk::Want &want, const AppExecFwk::AbilityInfo &abilityInfo) override;
183 
184     virtual void RegisterStartSpecifiedAbilityResponse(const sptr<IStartSpecifiedAbilityResponse> &response) override;
185 
186     virtual void StartSpecifiedProcess(const AAFwk::Want &want, const AppExecFwk::AbilityInfo &abilityInfo) override;
187 
188     virtual void SetCurrentUserId(const int32_t userId) override;
189 
190     virtual int32_t GetBundleNameByPid(const int pid, std::string &bundleName, int32_t &uid) override;
191 
192     /**
193      * @brief Register app debug listener.
194      * @param listener App debug listener.
195      * @return ERR_OK, return back success, others fail.
196      */
197     int32_t RegisterAppDebugListener(const sptr<IAppDebugListener> &listener) override;
198 
199     /**
200      * @brief Unregister app debug listener.
201      * @param listener App debug listener.
202      * @return ERR_OK, return back success, others fail.
203      */
204     int32_t UnregisterAppDebugListener(const sptr<IAppDebugListener> &listener) override;
205 
206     /**
207      * @brief Attach app debug.
208      * @param bundleName The application bundle name.
209      * @return Returns ERR_OK on success, others on failure.
210      */
211     int32_t AttachAppDebug(const std::string &bundleName) override;
212 
213     /**
214      * @brief Detach app debug.
215      * @param bundleName The application bundle name.
216      * @return Returns ERR_OK on success, others on failure.
217      */
218     int32_t DetachAppDebug(const std::string &bundleName) override;
219 
220     /**
221      * @brief Registering ability debug mode response.
222      * @param response Response for ability debug object.
223      * @return Returns ERR_OK on success, others on failure.
224      */
225     int32_t RegisterAbilityDebugResponse(const sptr<IAbilityDebugResponse> &response) override;
226 
227     /**
228      * @brief Determine whether it is an attachment debug application based on the bundle name.
229      * @param bundleName The application bundle name.
230      * @return Returns true if it is an attach debug application, otherwise it returns false.
231      */
232     bool IsAttachDebug(const std::string &bundleName) override;
233 
234     /**
235      * To clear the process by ability token.
236      *
237      * @param token the unique identification to the ability.
238      */
239     virtual void ClearProcessByToken(sptr<IRemoteObject> token) override;
240 
241 private:
242     /**
243      * @brief Judge whether the application service is ready.
244      *
245      * @return Returns true means service is ready, otherwise service is not ready.
246      */
247     bool IsReady() const;
248 
249 private:
250     std::shared_ptr<AppMgrServiceInner> amsMgrServiceInner_;
251     std::shared_ptr<AAFwk::TaskHandlerWrap> amsHandler_;
252     sptr<ISystemAbilityManager> systemAbilityMgr_;
253 
254     DISALLOW_COPY_AND_MOVE(AmsMgrScheduler);
255 };
256 }  // namespace AppExecFwk
257 }  // namespace OHOS
258 #endif  // OHOS_ABILITY_RUNTIME_AMS_MGR_SCHEDULER_H
259