• 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_INTERFACE_H
17 #define OHOS_ABILITY_RUNTIME_AMS_MGR_INTERFACE_H
18 
19 #include "ability_debug_response_interface.h"
20 #include "ability_info.h"
21 #include "app_debug_listener_interface.h"
22 #include "app_record_id.h"
23 #include "application_info.h"
24 #include "configuration.h"
25 #include "iapp_state_callback.h"
26 #include "iremote_broker.h"
27 #include "iremote_object.h"
28 #include "istart_specified_ability_response.h"
29 #include "running_process_info.h"
30 
31 namespace OHOS {
32 namespace AbilityRuntime {
33 struct LoadParam;
34 }
35 namespace AppExecFwk {
36 class IAmsMgr : public IRemoteBroker {
37 public:
38     DECLARE_INTERFACE_DESCRIPTOR(u"ohos.appexecfwk.IAmsMgr");
39 
40     /**
41      * LoadAbility, call LoadAbility() through proxy project, load the ability that needed to be started.
42      *
43      * @param token, the unique identification to start the ability.
44      * @param preToken, the unique identification to call the ability.
45      * @param abilityInfo, the ability information.
46      * @param appInfo, the app information.
47      * @return
48      */
LoadAbility(const std::shared_ptr<AbilityInfo> & abilityInfo,const std::shared_ptr<ApplicationInfo> & appInfo,const std::shared_ptr<AAFwk::Want> & want,std::shared_ptr<AbilityRuntime::LoadParam> loadParam)49     virtual void LoadAbility(const std::shared_ptr<AbilityInfo> &abilityInfo,
50         const std::shared_ptr<ApplicationInfo> &appInfo,
51         const std::shared_ptr<AAFwk::Want> &want, std::shared_ptr<AbilityRuntime::LoadParam> loadParam) {};
52 
53     /**
54      * TerminateAbility, call TerminateAbility() through the proxy object, terminate the token ability.
55      *
56      * @param token, token, he unique identification to terminate the ability.
57      * @param clearMissionFlag, indicates whether terminate the ability when clearMission.
58      * @return
59      */
60     virtual void TerminateAbility(const sptr<IRemoteObject> &token, bool clearMissionFlag) = 0;
61 
62     /**
63      * UpdateAbilityState, call UpdateAbilityState() through the proxy object, update the ability status.
64      *
65      * @param token, the unique identification to update the ability.
66      * @param state, ability status that needs to be updated.
67      * @return
68      */
69     virtual void UpdateAbilityState(const sptr<IRemoteObject> &token, const AbilityState state) = 0;
70 
71     /**
72      * UpdateExtensionState, call UpdateExtensionState() through the proxy object, update the extension status.
73      *
74      * @param token, the unique identification to update the extension.
75      * @param state, extension status that needs to be updated.
76      * @return
77      */
78     virtual void UpdateExtensionState(const sptr<IRemoteObject> &token, const ExtensionState state) = 0;
79 
80     /**
81      * RegisterAppStateCallback, call RegisterAppStateCallback() through the proxy object, register the callback.
82      *
83      * @param callback, Ams register the callback.
84      * @return
85      */
86     virtual void RegisterAppStateCallback(const sptr<IAppStateCallback> &callback) = 0;
87 
88     /**
89      * AbilityBehaviorAnalysis,call AbilityBehaviorAnalysis() through the proxy object,
90      * ability behavior analysis assistant process optimization.
91      *
92      * @param token, the unique identification to start the ability.
93      * @param preToken, the unique identification to call the ability.
94      * @param visibility, the visibility information about windows info.
95      * @param perceptibility, the Perceptibility information about windows info.
96      * @param connectionState, the service ability connection state.
97      * @return
98      */
99     virtual void AbilityBehaviorAnalysis(const sptr<IRemoteObject> &token, const sptr<IRemoteObject> &preToken,
100         const int32_t visibility, const int32_t perceptibility, const int32_t connectionState) = 0;
101 
102     /**
103      * KillProcessByAbilityToken, call KillProcessByAbilityToken() through proxy object,
104      * kill the process by ability token.
105      *
106      * @param token, the unique identification to the ability.
107      * @return
108      */
109     virtual void KillProcessByAbilityToken(const sptr<IRemoteObject> &token) = 0;
110 
111     /**
112      * KillProcessesByUserId, call KillProcessesByUserId() through proxy object,
113      * kill the processes by userId.
114      *
115      * @param userId, the user id.
116      * @return
117      */
118     virtual void KillProcessesByUserId(int32_t userId) = 0;
119 
KillProcessesByPids(std::vector<int32_t> & pids)120     virtual void KillProcessesByPids(std::vector<int32_t> &pids) {}
121 
AttachPidToParent(const sptr<IRemoteObject> & token,const sptr<IRemoteObject> & callerToken)122     virtual void AttachPidToParent(const sptr<IRemoteObject> &token, const sptr<IRemoteObject> &callerToken) {}
123 
124     /**
125      * KillProcessWithAccount, call KillProcessWithAccount() through proxy object,
126      * kill the process.
127      *
128      * @param bundleName, bundle name in Application record.
129      * @param accountId, account ID.
130      * @return ERR_OK, return back success, others fail.
131      */
132     virtual int KillProcessWithAccount(const std::string &bundleName, const int accountId) = 0;
133 
134     /**
135      * UpdateApplicationInfoInstalled, call UpdateApplicationInfoInstalled() through proxy object,
136      * update the application info after new module installed.
137      *
138      * @param bundleName, bundle name in Application record.
139      * @param  uid, uid.
140      * @return ERR_OK, return back success, others fail.
141      */
142     virtual int UpdateApplicationInfoInstalled(const std::string &bundleName, const int uid) = 0;
143 
144     /**
145      * KillApplication, call KillApplication() through proxy object, kill the application.
146      *
147      * @param  bundleName, bundle name in Application record.
148      * @return ERR_OK, return back success, others fail.
149      */
150     virtual int KillApplication(const std::string &bundleName) = 0;
151 
152     /**
153      * ForceKillApplication, call ForceKillApplication() through proxy object, force kill the application.
154      *
155      * @param  bundleName, bundle name in Application record.
156      * @param  userId, userId.
157      * @param  appIndex, appIndex.
158      * @return ERR_OK, return back success, others fail.
159      */
160     virtual int ForceKillApplication(const std::string &bundleName, const int userId = -1, const int appIndex = 0) = 0;
161 
162     /**
163      * KillProcessesByAccessTokenId, call KillProcessesByAccessTokenId() through proxy object,
164      * force kill the application.
165      *
166      * @param  accessTokenId, accessTokenId.
167      * @return ERR_OK, return back success, others fail.
168      */
169     virtual int KillProcessesByAccessTokenId(const uint32_t accessTokenId) = 0;
170 
171     /**
172      * KillApplicationByUid, call KillApplicationByUid() through proxy object, kill the application.
173      *
174      * @param  bundleName, bundle name in Application record.
175      * @param  userId, userId.
176      * @param  reason, caller function name.
177      * @return ERR_OK, return back success, others fail.
178      */
179     virtual int KillApplicationByUid(const std::string &bundleName, const int uid,
180         const std::string& reason = "KillApplicationByUid") = 0;
181 
182     /**
183      * Kill the application self.
184      *
185      * @return Returns ERR_OK on success, others on failure.
186      */
187     virtual int KillApplicationSelf(const std::string& reason = "KillApplicationSelf")
188     {
189         return ERR_OK;
190     }
191 
192     virtual void AbilityAttachTimeOut(const sptr<IRemoteObject> &token) = 0;
193 
194     virtual void PrepareTerminate(const sptr<IRemoteObject> &token, bool clearMissionFlag = false) = 0;
195 
196     virtual void GetRunningProcessInfoByToken(
197         const sptr<IRemoteObject> &token, OHOS::AppExecFwk::RunningProcessInfo &info) = 0;
198 
199     virtual void SetAbilityForegroundingFlagToAppRecord(const pid_t pid) = 0;
200 
201     virtual void StartSpecifiedAbility(const AAFwk::Want &want, const AppExecFwk::AbilityInfo &abilityInfo,
202         int32_t requestId = 0) = 0;
203 
204     virtual void RegisterStartSpecifiedAbilityResponse(const sptr<IStartSpecifiedAbilityResponse> &response) = 0;
205 
206     virtual void StartSpecifiedProcess(const AAFwk::Want &want, const AppExecFwk::AbilityInfo &abilityInfo,
207         int32_t requestId = 0) = 0;
208 
209     virtual int GetApplicationInfoByProcessID(const int pid, AppExecFwk::ApplicationInfo &application, bool &debug) = 0;
210 
211     /**
212      * Record process exit reason to appRunningRecord
213      * @param pid pid
214      * @param reason reason enum
215      * @param exitMsg exitMsg
216      * @return Returns ERR_OK on success, others on failure.
217      */
218     virtual int32_t NotifyAppMgrRecordExitReason(int32_t pid, int32_t reason, const std::string &exitMsg) = 0;
219 
220     /**
221      * Set the current userId of appMgr.
222      *
223      * @param userId the user id.
224      *
225      * @return
226      */
227     virtual void SetCurrentUserId(const int32_t userId) = 0;
228 
229     /**
230      * Set enable start process flag by userId
231      * @param userId the user id.
232      * @param enableStartProcess enable start process.
233      * @return
234      */
SetEnableStartProcessFlagByUserId(int32_t userId,bool enableStartProcess)235     virtual void SetEnableStartProcessFlagByUserId(int32_t userId, bool enableStartProcess) {}
236 
237     /**
238      * Get bundleName by pid.
239      *
240      * @param pid process id.
241      * @param bundleName Output parameters, return bundleName.
242      * @param uid Output parameters, return userId.
243      * @return Returns ERR_OK on success, others on failure.
244      */
245     virtual int32_t GetBundleNameByPid(const int pid, std::string &bundleName, int32_t &uid) = 0;
246 
247     /**
248      * @brief Register app debug listener.
249      * @param listener App debug listener.
250      * @return Returns ERR_OK on success, others on failure.
251      */
252     virtual int32_t RegisterAppDebugListener(const sptr<IAppDebugListener> &listener) = 0;
253 
254     /**
255      * @brief Unregister app debug listener.
256      * @param listener App debug listener.
257      * @return Returns ERR_OK on success, others on failure.
258      */
259     virtual int32_t UnregisterAppDebugListener(const sptr<IAppDebugListener> &listener) = 0;
260 
261     /**
262      * @brief Attach app debug.
263      * @param bundleName The application bundle name.
264      * @return Returns ERR_OK on success, others on failure.
265      */
266     virtual int32_t AttachAppDebug(const std::string &bundleName) = 0;
267 
268     /**
269      * @brief Detach app debug.
270      * @param bundleName The application bundle name.
271      * @return Returns ERR_OK on success, others on failure.
272      */
273     virtual int32_t DetachAppDebug(const std::string &bundleName) = 0;
274 
275     /**
276      * @brief Set app waiting debug mode.
277      * @param bundleName The application bundle name.
278      * @param isPersist The persist flag.
279      * @return Returns ERR_OK on success, others on failure.
280      */
281     virtual int32_t SetAppWaitingDebug(const std::string &bundleName, bool isPersist) = 0;
282 
283     /**
284      * @brief Cancel app waiting debug mode.
285      * @return Returns ERR_OK on success, others on failure.
286      */
287     virtual int32_t CancelAppWaitingDebug() = 0;
288 
289     /**
290      * @brief Get waiting debug mode application.
291      * @param debugInfoList The debug info list, including bundle name and persist flag.
292      * @return Returns ERR_OK on success, others on failure.
293      */
294     virtual int32_t GetWaitingDebugApp(std::vector<std::string> &debugInfoList) = 0;
295 
296     /**
297      * @brief Determine whether it is a waiting debug application based on the bundle name.
298      * @return Returns true if it is a waiting debug application, otherwise it returns false.
299      */
300     virtual bool IsWaitingDebugApp(const std::string &bundleName) = 0;
301 
302     /**
303      * @brief Clear non persist waiting debug flag.
304      */
305     virtual void ClearNonPersistWaitingDebugFlag() = 0;
306 
307     /**
308      * @brief Registering ability debug mode response.
309      * @param response Response for ability debug object.
310      * @return Returns ERR_OK on success, others on failure.
311      */
312     virtual int32_t RegisterAbilityDebugResponse(const sptr<IAbilityDebugResponse> &response) = 0;
313 
314     /**
315      * @brief Determine whether it is an attachment debug application based on the bundle name.
316      * @param bundleName The application bundle name.
317      * @return Returns true if it is an attach debug application, otherwise it returns false.
318      */
319     virtual bool IsAttachDebug(const std::string &bundleName) = 0;
320 
321     /**
322      * @brief Set resident process enable status.
323      * @param bundleName The application bundle name.
324      * @param enable The current updated enable status.
325      */
SetKeepAliveEnableState(const std::string & bundleName,bool enable,int32_t uid)326     virtual void SetKeepAliveEnableState(const std::string &bundleName, bool enable, int32_t uid) {};
327 
328     /**
329      * To clear the process by ability token.
330      *
331      * @param token the unique identification to the ability.
332      */
ClearProcessByToken(sptr<IRemoteObject> token)333     virtual void ClearProcessByToken(sptr<IRemoteObject> token) {}
334 
335     /**
336      * whether memory size is sufficent.
337      * @return Returns true is sufficent memory size, others return false.
338      */
339     virtual bool IsMemorySizeSufficent() = 0;
340 
341     /**
342      * Notifies that one ability is attached to status bar.
343      *
344      * @param token the token of the abilityRecord that is attached to status bar.
345      */
AttachedToStatusBar(const sptr<IRemoteObject> & token)346     virtual void AttachedToStatusBar(const sptr<IRemoteObject> &token) {}
347 
348     /**
349      * Temporarily block the process cache feature.
350      *
351      * @param pids the pids of the processes that should be blocked.
352      */
BlockProcessCacheByPids(const std::vector<int32_t> & pids)353     virtual void BlockProcessCacheByPids(const std::vector<int32_t> &pids) {}
354 
355     /**
356      * whether killed for upgrade web.
357      *
358      * @param bundleName the bundle name is killed for upgrade web.
359      * @return Returns true is killed for upgrade web, others return false.
360      */
IsKilledForUpgradeWeb(const std::string & bundleName)361     virtual bool IsKilledForUpgradeWeb(const std::string &bundleName)
362     {
363         return true;
364     }
365 
366     /**
367      * Request to clean uiability from user.
368      *
369      * @param token the token of ability.
370      * @return Returns true if clean success, others return false.
371      */
CleanAbilityByUserRequest(const sptr<IRemoteObject> & token)372     virtual bool CleanAbilityByUserRequest(const sptr<IRemoteObject> &token)
373     {
374         return false;
375     }
376 
377     /**
378      * whether the abilities of process specified by pid type only UIAbility.
379      * @return Returns true is only UIAbility, otherwise return false
380      */
IsProcessContainsOnlyUIAbility(const pid_t pid)381     virtual bool IsProcessContainsOnlyUIAbility(const pid_t pid)
382     {
383         return false;
384     }
385 
IsProcessAttached(sptr<IRemoteObject> token)386     virtual bool IsProcessAttached(sptr<IRemoteObject> token)
387     {
388         return false;
389     }
390 
391     enum class Message {
392         LOAD_ABILITY = 0,
393         TERMINATE_ABILITY,
394         UPDATE_ABILITY_STATE,
395         UPDATE_EXTENSION_STATE,
396         REGISTER_APP_STATE_CALLBACK,
397         ABILITY_BEHAVIOR_ANALYSIS,
398         KILL_PEOCESS_BY_ABILITY_TOKEN,
399         KILL_PROCESSES_BY_USERID,
400         KILL_PROCESS_WITH_ACCOUNT,
401         KILL_APPLICATION,
402         ABILITY_ATTACH_TIMEOUT,
403         PREPARE_TERMINATE_ABILITY,
404         KILL_APPLICATION_BYUID,
405         GET_RUNNING_PROCESS_INFO_BY_TOKEN,
406         START_SPECIFIED_ABILITY,
407         REGISTER_START_SPECIFIED_ABILITY_RESPONSE,
408         UPDATE_CONFIGURATION,
409         GET_CONFIGURATION,
410         GET_APPLICATION_INFO_BY_PROCESS_ID,
411         KILL_APPLICATION_SELF,
412         UPDATE_APPLICATION_INFO_INSTALLED,
413         SET_CURRENT_USER_ID,
414         Get_BUNDLE_NAME_BY_PID,
415         SET_ABILITY_FOREGROUNDING_FLAG,
416         REGISTER_APP_DEBUG_LISTENER,
417         UNREGISTER_APP_DEBUG_LISTENER,
418         ATTACH_APP_DEBUG,
419         DETACH_APP_DEBUG,
420         SET_APP_WAITING_DEBUG,
421         CANCEL_APP_WAITING_DEBUG,
422         GET_WAITING_DEBUG_APP,
423         IS_WAITING_DEBUG_APP,
424         CLEAR_NON_PERSIST_WAITING_DEBUG_FLAG,
425         REGISTER_ABILITY_DEBUG_RESPONSE,
426         IS_ATTACH_DEBUG,
427         START_SPECIFIED_PROCESS,
428         CLEAR_PROCESS_BY_TOKEN,
429         REGISTER_ABILITY_MS_DELEGATE,
430         KILL_PROCESSES_BY_PIDS,
431         ATTACH_PID_TO_PARENT,
432         IS_MEMORY_SIZE_SUFFICIENT,
433         NOTIFY_APP_MGR_RECORD_EXIT_REASON,
434         SET_KEEP_ALIVE_ENABLE_STATE,
435         ATTACHED_TO_STATUS_BAR,
436         BLOCK_PROCESS_CACHE_BY_PIDS,
437         IS_KILLED_FOR_UPGRADE_WEB,
438         IS_PROCESS_CONTAINS_ONLY_UI_EXTENSION,
439         FORCE_KILL_APPLICATION,
440         CLEAN_UIABILITY_BY_USER_REQUEST,
441         FORCE_KILL_APPLICATION_BY_ACCESS_TOKEN_ID = 49,
442         IS_PROCESS_ATTACHED,
443         ENABLE_START_PROCESS_FLAG_BY_USER_ID,
444     };
445 };
446 }  // namespace AppExecFwk
447 }  // namespace OHOS
448 
449 #endif  // OHOS_ABILITY_RUNTIME_AMS_MGR_INTERFACE_H
450