• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 "appexecfwk_errors.h"
23 #include "application_info.h"
24 #include "app_mgr_constants.h"
25 #include "task_handler_wrap.h"
26 #include "app_mgr_service_inner.h"
27 #include "app_record_id.h"
28 #include "app_running_record.h"
29 #include "app_scheduler_proxy.h"
30 #include "if_system_ability_manager.h"
31 #include "nocopyable.h"
32 #include "system_ability.h"
33 
34 namespace OHOS {
35 namespace AppExecFwk {
36 class AmsMgrScheduler : public AmsMgrStub {
37 public:
38     AmsMgrScheduler(
39         const std::shared_ptr<AppMgrServiceInner> &MgrServiceInner_,
40         const std::shared_ptr<AAFwk::TaskHandlerWrap> &Handler_);
41     virtual ~AmsMgrScheduler() override;
42 
43     /**
44      * LoadAbility, call LoadAbility() through proxy project, load the ability that needed to be started.
45      *
46      * @param token, the unique identification to start the ability.
47      * @param preToken, the unique identification to call the ability.
48      * @param abilityInfo, the ability information.
49      * @param appInfo, the app information.
50      * @param want, the starting information.
51      */
52     virtual void LoadAbility(const sptr<IRemoteObject> &token, const sptr<IRemoteObject> &preToken,
53         const std::shared_ptr<AbilityInfo> &abilityInfo, const std::shared_ptr<ApplicationInfo> &appInfo,
54         const std::shared_ptr<AAFwk::Want> &want) override;
55 
56     /**
57      * TerminateAbility, call TerminateAbility() through the proxy object, terminate the token ability.
58      *
59      * @param token, token, he unique identification to terminate the ability.
60      * @param clearMissionFlag, indicates whether terminate the ability when clearMission.
61      * @return
62      */
63     virtual void TerminateAbility(const sptr<IRemoteObject> &token, bool clearMissionFlag) override;
64 
65     /**
66      * UpdateAbilityState, call UpdateAbilityState() through the proxy object, update the ability status.
67      *
68      * @param token, the unique identification to update the ability.
69      * @param state, ability status that needs to be updated.
70      * @return
71      */
72     virtual void UpdateAbilityState(const sptr<IRemoteObject> &token, const AbilityState state) override;
73 
74     /**
75      * UpdateExtensionState, call UpdateExtensionState() through the proxy object, update the extension status.
76      *
77      * @param token, the unique identification to update the extension.
78      * @param state, extension status that needs to be updated.
79      * @return
80      */
81     virtual void UpdateExtensionState(const sptr<IRemoteObject> &token, const ExtensionState state) override;
82 
83     /**
84      * RegisterAppStateCallback, call RegisterAppStateCallback() through the proxy object, register the callback.
85      *
86      * @param callback, Ams register the callback.
87      * @return
88      */
89     virtual void RegisterAppStateCallback(const sptr<IAppStateCallback> &callback) override;
90 
91     /**
92      * AbilityBehaviorAnalysis, ability behavior analysis assistant process optimization.
93      *
94      * @param token, the unique identification to start the ability.
95      * @param preToken, the unique identification to call the ability.
96      * @param visibility, the visibility information about windows info.
97      * @param perceptibility, the Perceptibility information about windows info.
98      * @param connectionState, the service ability connection state.
99      * @return
100      */
101     virtual void AbilityBehaviorAnalysis(const sptr<IRemoteObject> &token, const sptr<IRemoteObject> &preToken,
102         const int32_t visibility, const int32_t perceptibility, const int32_t connectionState) override;
103 
104     /**
105      * KillProcessByAbilityToken, call KillProcessByAbilityToken() through proxy object,
106      * kill the process by ability token.
107      *
108      * @param token, the unique identification to the ability.
109      * @return
110      */
111     virtual void KillProcessByAbilityToken(const sptr<IRemoteObject> &token) override;
112 
113     /**
114      * KillProcessesByUserId, call KillProcessesByUserId() through proxy object,
115      * kill the processes by userId.
116      *
117      * @param userId, the user id.
118      * @return
119      */
120     virtual void KillProcessesByUserId(int32_t userId) override;
121 
122     /**
123      * KillProcessWithAccount, call KillProcessWithAccount() through proxy object, kill the
124      * process.
125      *
126      * @param bundleName, bundle name in Application record.
127      * @param accountId, account ID.
128      * @return ERR_OK, return back success, others fail.
129      */
130     virtual int32_t KillProcessWithAccount(const std::string &bundleName, const int accountId) override;
131 
132     /**
133      * UpdateApplicationInfoInstalled, call UpdateApplicationInfoInstalled() through proxy object,
134      * update the application info after new module installed.
135      *
136      * @param bundleName, bundle name in Application record.
137      * @param  uid, uid.
138      * @return ERR_OK, return back success, others fail.
139      */
140     virtual int32_t UpdateApplicationInfoInstalled(const std::string &bundleName, const int uid) override;
141 
142     /**
143      * KillApplication, call KillApplication() through proxy object, kill the application.
144      *
145      * @param  bundleName, bundle name in Application record.
146      * @return ERR_OK, return back success, others fail.
147      */
148     virtual int32_t KillApplication(const std::string &bundleName) override;
149 
150     /**
151      * KillApplicationByUid, call KillApplicationByUid() through proxy object, kill the application.
152      *
153      * @param  bundleName, bundle name in Application record.
154      * @param  uid, uid.
155      * @return ERR_OK, return back success, others fail.
156      */
157     virtual int KillApplicationByUid(const std::string &bundleName, const int uid) override;
158 
159     virtual int KillApplicationSelf() override;
160 
161     int GetApplicationInfoByProcessID(const int pid, AppExecFwk::ApplicationInfo &application, bool &debug) override;
162 
163     virtual void AbilityAttachTimeOut(const sptr<IRemoteObject> &token) override;
164 
165     virtual void PrepareTerminate(const sptr<IRemoteObject> &token) override;
166 
167     virtual void GetRunningProcessInfoByToken(
168         const sptr<IRemoteObject> &token, AppExecFwk::RunningProcessInfo &info) override;
169 
170     void GetRunningProcessInfoByPid(const pid_t pid, OHOS::AppExecFwk::RunningProcessInfo &info) override;
171 
172     /**
173      * Set AbilityForegroundingFlag of an app-record to true.
174      *
175      * @param pid, pid.
176      *
177      */
178     void SetAbilityForegroundingFlagToAppRecord(const pid_t pid) override;
179 
180     virtual void StartSpecifiedAbility(
181         const AAFwk::Want &want, const AppExecFwk::AbilityInfo &abilityInfo) override;
182 
183     virtual void RegisterStartSpecifiedAbilityResponse(const sptr<IStartSpecifiedAbilityResponse> &response) override;
184 
185     virtual void SetCurrentUserId(const int32_t userId) override;
186 
187     virtual int32_t GetBundleNameByPid(const int pid, std::string &bundleName, int32_t &uid) override;
188 
189 private:
190     /**
191      * @brief Judge whether the application service is ready.
192      *
193      * @return Returns true means service is ready, otherwise service is not ready.
194      */
195     bool IsReady() const;
196 
197 private:
198     std::shared_ptr<AppMgrServiceInner> amsMgrServiceInner_;
199     std::shared_ptr<AAFwk::TaskHandlerWrap> amsHandler_;
200     sptr<ISystemAbilityManager> systemAbilityMgr_;
201 
202     DISALLOW_COPY_AND_MOVE(AmsMgrScheduler);
203 };
204 }  // namespace AppExecFwk
205 }  // namespace OHOS
206 #endif  // OHOS_ABILITY_RUNTIME_AMS_MGR_SCHEDULER_H
207