• 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_INTERFACE_H
17 #define OHOS_ABILITY_RUNTIME_AMS_MGR_INTERFACE_H
18 
19 #include "iremote_broker.h"
20 #include "iremote_object.h"
21 
22 #include "ability_info.h"
23 #include "application_info.h"
24 #include "app_record_id.h"
25 #include "iapp_state_callback.h"
26 #include "running_process_info.h"
27 #include "istart_specified_ability_response.h"
28 #include "configuration.h"
29 
30 namespace OHOS {
31 namespace AppExecFwk {
32 class IAmsMgr : public IRemoteBroker {
33 public:
34     DECLARE_INTERFACE_DESCRIPTOR(u"ohos.appexecfwk.IAmsMgr");
35 
36     /**
37      * LoadAbility, call LoadAbility() through proxy project, load the ability that needed to be started.
38      *
39      * @param token, the unique identification to start the ability.
40      * @param preToken, the unique identification to call the ability.
41      * @param abilityInfo, the ability information.
42      * @param appInfo, the app information.
43      * @return
44      */
45     virtual void LoadAbility(const sptr<IRemoteObject> &token, const sptr<IRemoteObject> &preToken,
46         const std::shared_ptr<AbilityInfo> &abilityInfo, const std::shared_ptr<ApplicationInfo> &appInfo,
47         const std::shared_ptr<AAFwk::Want> &want) = 0;
48 
49     /**
50      * TerminateAbility, call TerminateAbility() through the proxy object, terminate the token ability.
51      *
52      * @param token, token, he unique identification to terminate the ability.
53      * @param clearMissionFlag, indicates whether terminate the ability when clearMission.
54      * @return
55      */
56     virtual void TerminateAbility(const sptr<IRemoteObject> &token, bool clearMissionFlag) = 0;
57 
58     /**
59      * UpdateAbilityState, call UpdateAbilityState() through the proxy object, update the ability status.
60      *
61      * @param token, the unique identification to update the ability.
62      * @param state, ability status that needs to be updated.
63      * @return
64      */
65     virtual void UpdateAbilityState(const sptr<IRemoteObject> &token, const AbilityState state) = 0;
66 
67     /**
68      * UpdateExtensionState, call UpdateExtensionState() through the proxy object, update the extension status.
69      *
70      * @param token, the unique identification to update the extension.
71      * @param state, extension status that needs to be updated.
72      * @return
73      */
74     virtual void UpdateExtensionState(const sptr<IRemoteObject> &token, const ExtensionState state) = 0;
75 
76     /**
77      * RegisterAppStateCallback, call RegisterAppStateCallback() through the proxy object, register the callback.
78      *
79      * @param callback, Ams register the callback.
80      * @return
81      */
82     virtual void RegisterAppStateCallback(const sptr<IAppStateCallback> &callback) = 0;
83 
84     /**
85      * AbilityBehaviorAnalysis,call AbilityBehaviorAnalysis() through the proxy object,
86      * ability behavior analysis assistant process optimization.
87      *
88      * @param token, the unique identification to start the ability.
89      * @param preToken, the unique identification to call the ability.
90      * @param visibility, the visibility information about windows info.
91      * @param perceptibility, the Perceptibility information about windows info.
92      * @param connectionState, the service ability connection state.
93      * @return
94      */
95     virtual void AbilityBehaviorAnalysis(const sptr<IRemoteObject> &token, const sptr<IRemoteObject> &preToken,
96         const int32_t visibility, const int32_t perceptibility, const int32_t connectionState) = 0;
97 
98     /**
99      * KillProcessByAbilityToken, call KillProcessByAbilityToken() through proxy object,
100      * kill the process by ability token.
101      *
102      * @param token, the unique identification to the ability.
103      * @return
104      */
105     virtual void KillProcessByAbilityToken(const sptr<IRemoteObject> &token) = 0;
106 
107     /**
108      * KillProcessesByUserId, call KillProcessesByUserId() through proxy object,
109      * kill the processes by userId.
110      *
111      * @param userId, the user id.
112      * @return
113      */
114     virtual void KillProcessesByUserId(int32_t userId) = 0;
115 
116     /**
117      * KillProcessWithAccount, call KillProcessWithAccount() through proxy object,
118      * kill the process.
119      *
120      * @param bundleName, bundle name in Application record.
121      * @param accountId, account ID.
122      * @return ERR_OK, return back success, others fail.
123      */
124     virtual int KillProcessWithAccount(const std::string &bundleName, const int accountId) = 0;
125 
126     /**
127      * UpdateApplicationInfoInstalled, call UpdateApplicationInfoInstalled() through proxy object,
128      * update the application info after new module installed.
129      *
130      * @param bundleName, bundle name in Application record.
131      * @param  uid, uid.
132      * @return ERR_OK, return back success, others fail.
133      */
134     virtual int UpdateApplicationInfoInstalled(const std::string &bundleName, const int uid) = 0;
135 
136     /**
137      * KillApplication, call KillApplication() through proxy object, kill the application.
138      *
139      * @param  bundleName, bundle name in Application record.
140      * @return ERR_OK, return back success, others fail.
141      */
142     virtual int KillApplication(const std::string &bundleName) = 0;
143 
144     /**
145      * KillApplicationByUid, call KillApplicationByUid() through proxy object, kill the application.
146      *
147      * @param  bundleName, bundle name in Application record.
148      * @param  userId, userId.
149      * @return ERR_OK, return back success, others fail.
150      */
151     virtual int KillApplicationByUid(const std::string &bundleName, const int uid) = 0;
152 
153     /**
154      * Kill the application self.
155      *
156      * @return Returns ERR_OK on success, others on failure.
157      */
KillApplicationSelf()158     virtual int KillApplicationSelf()
159     {
160         return ERR_OK;
161     }
162 
163     virtual void AbilityAttachTimeOut(const sptr<IRemoteObject> &token) = 0;
164 
165     virtual void PrepareTerminate(const sptr<IRemoteObject> &token) = 0;
166 
167     virtual void GetRunningProcessInfoByToken(
168         const sptr<IRemoteObject> &token, OHOS::AppExecFwk::RunningProcessInfo &info) = 0;
169 
170     virtual void GetRunningProcessInfoByPid(const pid_t pid, OHOS::AppExecFwk::RunningProcessInfo &info) = 0;
171 
172     virtual void SetAbilityForegroundingFlagToAppRecord(const pid_t pid) = 0;
173 
174     virtual void StartSpecifiedAbility(const AAFwk::Want &want, const AppExecFwk::AbilityInfo &abilityInfo) = 0;
175 
176     virtual void RegisterStartSpecifiedAbilityResponse(const sptr<IStartSpecifiedAbilityResponse> &response) = 0;
177 
178     virtual int GetApplicationInfoByProcessID(const int pid, AppExecFwk::ApplicationInfo &application, bool &debug) = 0;
179 
180     /**
181      * Set the current userId of appMgr.
182      *
183      * @param userId the user id.
184      *
185      * @return
186      */
187     virtual void SetCurrentUserId(const int32_t userId) = 0;
188 
189     /**
190      * Get bundleName by pid.
191      *
192      * @param pid process id.
193      * @param bundleName Output parameters, return bundleName.
194      * @param uid Output parameters, return userId.
195      * @return Returns ERR_OK on success, others on failure.
196      */
197     virtual int32_t GetBundleNameByPid(const int pid, std::string &bundleName, int32_t &uid) = 0;
198 
199     enum class Message {
200         LOAD_ABILITY = 0,
201         TERMINATE_ABILITY,
202         UPDATE_ABILITY_STATE,
203         UPDATE_EXTENSION_STATE,
204         REGISTER_APP_STATE_CALLBACK,
205         ABILITY_BEHAVIOR_ANALYSIS,
206         KILL_PEOCESS_BY_ABILITY_TOKEN,
207         KILL_PROCESSES_BY_USERID,
208         KILL_PROCESS_WITH_ACCOUNT,
209         KILL_APPLICATION,
210         ABILITY_ATTACH_TIMEOUT,
211         PREPARE_TERMINATE_ABILITY,
212         KILL_APPLICATION_BYUID,
213         GET_RUNNING_PROCESS_INFO_BY_TOKEN,
214         START_SPECIFIED_ABILITY,
215         REGISTER_START_SPECIFIED_ABILITY_RESPONSE,
216         UPDATE_CONFIGURATION,
217         GET_CONFIGURATION,
218         GET_APPLICATION_INFO_BY_PROCESS_ID,
219         KILL_APPLICATION_SELF,
220         GET_RUNNING_PROCESS_INFO_BY_PID,
221         UPDATE_APPLICATION_INFO_INSTALLED,
222         SET_CURRENT_USER_ID,
223         Get_BUNDLE_NAME_BY_PID,
224         SET_ABILITY_FOREGROUNDING_FLAG
225     };
226 };
227 }  // namespace AppExecFwk
228 }  // namespace OHOS
229 
230 #endif  // OHOS_ABILITY_RUNTIME_AMS_MGR_INTERFACE_H
231