• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2025 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_ABILITY_MANAGER_SERVICE_H
17 #define OHOS_ABILITY_RUNTIME_ABILITY_MANAGER_SERVICE_H
18 
19 #include <cstdint>
20 #include <future>
21 #include <map>
22 #include <memory>
23 #include <shared_mutex>
24 #include <singleton.h>
25 #include <thread_ex.h>
26 #include <unordered_map>
27 
28 #include "ability_auto_startup_service.h"
29 #include "ability_bundle_event_callback.h"
30 #include "ability_config.h"
31 #include "ability_connect_manager.h"
32 #include "ability_debug_deal.h"
33 #include "ability_event_handler.h"
34 #include "ability_info.h"
35 #include "ability_manager_event_subscriber.h"
36 #include "ability_manager_stub.h"
37 #include "ability_keep_alive_service.h"
38 #include "ams_configuration_parameter.h"
39 #include "app_debug_listener_interface.h"
40 #include "app_exit_reason_helper.h"
41 #include "app_mgr_interface.h"
42 #include "app_scheduler.h"
43 #include "auto_startup_info.h"
44 #ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE
45 #include "background_task_observer.h"
46 #endif
47 #include "bundle_constants.h"
48 #include "bundle_mgr_helper.h"
49 #include "data_ability_manager.h"
50 #include "deeplink_reserve/deeplink_reserve_config.h"
51 #include "event_report.h"
52 #include "free_install_manager.h"
53 #include "iacquire_share_data_callback_interface.h"
54 #include "interceptor/ability_interceptor_executer.h"
55 #include "iremote_object.h"
56 #include "mission_list_manager_interface.h"
57 #include "parameter.h"
58 #include "pending_want_manager.h"
59 #include "permission_verification.h"
60 #include "resident_process_manager.h"
61 #include "scene_board/ui_ability_lifecycle_manager.h"
62 #include "start_ability_handler.h"
63 #include "sub_managers_helper.h"
64 #include "system_ability.h"
65 #include "task_handler_wrap.h"
66 #include "uri.h"
67 #include "user_controller.h"
68 #include "intent_exemption_info.h"
69 #ifdef SUPPORT_GRAPHICS
70 #include "implicit_start_processor.h"
71 #include "system_dialog_scheduler.h"
72 #endif
73 
74 namespace OHOS {
75 namespace AbilityRuntime {
76 class IStatusBarDelegate;
77 }
78 namespace Rosen {
79 class FocusChangeInfo;
80 class WindowVisibilityInfo;
81 }
82 
83 namespace AAFwk {
84 using AutoStartupInfo = AbilityRuntime::AutoStartupInfo;
85 enum class ServiceRunningState { STATE_NOT_START, STATE_RUNNING };
86 constexpr int32_t BASE_USER_RANGE = 200000;
87 constexpr int32_t U0_USER_ID = 0;
88 constexpr int32_t INVALID_USER_ID = -1;
89 constexpr const char* KEY_SESSION_ID = "com.ohos.param.sessionId";
90 using OHOS::AppExecFwk::IAbilityController;
91 struct StartAbilityInfo;
92 class WindowFocusChangedListener;
93 class WindowVisibilityChangedListener;
94 
95 /**
96  * @class AbilityManagerService
97  * AbilityManagerService provides a facility for managing ability life cycle.
98  */
99 class AbilityManagerService : public SystemAbility,
100                               public AbilityManagerStub,
101                               public AppStateCallback,
102                               public std::enable_shared_from_this<AbilityManagerService> {
103     DECLARE_DELAYED_SINGLETON(AbilityManagerService)
104     DECLEAR_SYSTEM_ABILITY(AbilityManagerService)
105 public:
106     static std::shared_ptr<AbilityManagerService> GetPubInstance();
107 
108     void OnStart() override;
109     void OnStop() override;
110 
111     virtual void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override;
112 
113     virtual void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override;
114 
115     ServiceRunningState QueryServiceState() const;
116 
117     /**
118      * StartSelfUIAbility with want, start self uiability only on 2-in-1 devices.
119      *
120      * @param want, the want of the ability to start.
121      * @return Returns ERR_OK on success, others on failure.
122      */
123     virtual int StartSelfUIAbility(const Want &want) override;
124 
125     /**
126      * StartSelfUIAbility with want and startOptions, start self uiability only on 2-in-1 devices.
127      *
128      * @param want, the want of the ability to start.
129      * @param options, the startOptions of the ability to start.
130      * @return Returns ERR_OK on success, others on failure.
131      */
132     virtual int StartSelfUIAbilityWithStartOptions(const Want &want,
133         const StartOptions &options) override;
134 
135     /**
136      * StartAbility with want, send want to ability manager service.
137      *
138      * @param want, the want of the ability to start.
139      * @param requestCode, Ability request code.
140      * @param userId, Designation User ID.
141      * @return Returns ERR_OK on success, others on failure.
142      */
143     virtual int StartAbility(
144         const Want &want, int32_t userId = DEFAULT_INVAL_VALUE, int requestCode = DEFAULT_INVAL_VALUE) override;
145 
146     /**
147      * StartAbility with want, send want to ability manager service.
148      *
149      * @param want, the want of the ability to start.
150      * @param callerToken, caller ability token.
151      * @param userId, Designation User ID.
152      * @param requestCode the resultCode of the ability to start.
153      * @return Returns ERR_OK on success, others on failure.
154      */
155     virtual int StartAbility(
156         const Want &want,
157         const sptr<IRemoteObject> &callerToken,
158         int32_t userId = DEFAULT_INVAL_VALUE,
159         int requestCode = DEFAULT_INVAL_VALUE) override;
160 
161     /**
162      * StartAbilityWithSpecifyTokenIdInner with want and specialId, send want to ability manager service.
163      *
164      * @param want, the want of the ability to start.
165      * @param callerToken, caller ability token.
166      * @param specialId the caller Id.
167      * @param userId, Designation User ID.
168      * @param requestCode the resultCode of the ability to start.
169      * @return Returns ERR_OK on success, others on failure.
170      */
171     int StartAbilityWithSpecifyTokenIdInner(
172         const Want &want,
173         const sptr<IRemoteObject> &callerToken,
174         uint32_t specifyTokenId,
175         bool isPendingWantCaller,
176         int32_t userId = DEFAULT_INVAL_VALUE,
177         int requestCode = DEFAULT_INVAL_VALUE);
178 
179     /**
180      * Starts a new ability with specific start options and specialId, send want to ability manager service.
181      *
182      * @param want the want of the ability to start.
183      * @param startOptions Indicates the options used to start.
184      * @param callerToken caller ability token.
185      * @param userId Designation User ID.
186      * @param requestCode the resultCode of the ability to start.
187      * @param specifyTokenId The Caller ID.
188      * @return Returns ERR_OK on success, others on failure.
189      */
190     int StartAbilityWithSpecifyTokenIdInner(
191         const Want &want,
192         const StartOptions &startOptions,
193         const sptr<IRemoteObject> &callerToken,
194         bool isPendingWantCaller,
195         int32_t userId = DEFAULT_INVAL_VALUE,
196         int requestCode = DEFAULT_INVAL_VALUE,
197         uint32_t specifyTokenId = 0);
198 
199     /**
200      * StartAbilityWithSpecifyTokenId with want and specialId, send want to ability manager service.
201      *
202      * @param want, the want of the ability to start.
203      * @param callerToken, caller ability token.
204      * @param specialId the caller Id.
205      * @param userId, Designation User ID.
206      * @param requestCode the resultCode of the ability to start.
207      * @return Returns ERR_OK on success, others on failure.
208      */
209     virtual int StartAbilityWithSpecifyTokenId(
210         const Want &want,
211         const sptr<IRemoteObject> &callerToken,
212         uint32_t specifyTokenId,
213         int32_t userId = DEFAULT_INVAL_VALUE,
214         int requestCode = DEFAULT_INVAL_VALUE) override;
215 
216     /**
217      * StartAbility by insight intent, send want to ability manager service.
218      *
219      * @param want Ability want.
220      * @param callerToken caller ability token.
221      * @param intentId insight intent id.
222      * @param userId userId of target ability.
223      * @return Returns ERR_OK on success, others on failure.
224      */
225     int32_t StartAbilityByInsightIntent(
226         const Want &want,
227         const sptr<IRemoteObject> &callerToken,
228         uint64_t intentId,
229         int32_t userId = DEFAULT_INVAL_VALUE) override;
230 
231     /**
232      * Starts a new ability with specific start settings.
233      *
234      * @param want Indicates the ability to start.
235      * @param abilityStartSetting Indicates the setting ability used to start.
236      * @param callerToken, caller ability token.
237      * @param userId, Designation User ID.
238      * @param requestCode the resultCode of the ability to start.
239      * @return Returns ERR_OK on success, others on failure.
240      */
241     virtual int StartAbility(
242         const Want &want,
243         const AbilityStartSetting &abilityStartSetting,
244         const sptr<IRemoteObject> &callerToken,
245         int32_t userId = DEFAULT_INVAL_VALUE,
246         int requestCode = DEFAULT_INVAL_VALUE) override;
247 
248     /**
249      * Starts a new ability with specific start options.
250      *
251      * @param want the want of the ability to start.
252      * @param startOptions Indicates the options used to start.
253      * @param callerToken caller ability token.
254      * @param userId Designation User ID.
255      * @param requestCode the resultCode of the ability to start.
256      * @return Returns ERR_OK on success, others on failure.
257      */
258     virtual int StartAbility(
259         const Want &want,
260         const StartOptions &startOptions,
261         const sptr<IRemoteObject> &callerToken,
262         int32_t userId = DEFAULT_INVAL_VALUE,
263         int requestCode = DEFAULT_INVAL_VALUE) override;
264 
265     /**
266      * Starts a new ability using the original caller information.
267      *
268      * @param want the want of the ability to start.
269      * @param callerToken current caller ability token.
270      * @param asCallerSourceToken source caller ability token
271      * @param userId Designation User ID.
272      * @param requestCode the resultCode of the ability to start.
273      * @return Returns ERR_OK on success, others on failure.
274      */
275     virtual int StartAbilityAsCaller(
276             const Want &want,
277             const sptr<IRemoteObject> &callerToken,
278             sptr<IRemoteObject> asCallerSourceToken,
279             int32_t userId = DEFAULT_INVAL_VALUE,
280             int requestCode = DEFAULT_INVAL_VALUE) override;
281 
282     /**
283      * Starts a new ability using the original caller information.
284      *
285      * @param want the want of the ability to start.
286      * @param startOptions Indicates the options used to start.
287      * @param callerToken current caller ability token.
288      * @param asCallerSourceToken source caller ability token
289      * @param userId Designation User ID.
290      * @param requestCode the resultCode of the ability to start.
291      * @return Returns ERR_OK on success, others on failure.
292      */
293     virtual int StartAbilityAsCaller(
294         const Want &want,
295         const StartOptions &startOptions,
296         const sptr<IRemoteObject> &callerToken,
297         sptr<IRemoteObject> asCallerSourceToken,
298         int32_t userId = DEFAULT_INVAL_VALUE,
299         int requestCode = DEFAULT_INVAL_VALUE) override;
300 
301     /**
302      * Starts a new ability for result using the original caller information.
303      *
304      * @param want the want of the ability to start.
305      * @param callerToken current caller ability token.
306      * @param requestCode the resultCode of the ability to start.
307      * @param userId Designation User ID.
308      * @return Returns ERR_OK on success, others on failure.
309      */
310     int StartAbilityForResultAsCaller(
311         const Want &want,
312         const sptr<IRemoteObject> &callerToken,
313         int requestCode = DEFAULT_INVAL_VALUE,
314         int32_t userId = DEFAULT_INVAL_VALUE) override;
315 
316     /**
317      * Starts a new ability for result using the original caller information.
318      *
319      * @param want the want of the ability to start.
320      * @param startOptions Indicates the options used to start.
321      * @param callerToken current caller ability token.
322      * @param requestCode the resultCode of the ability to start.
323      * @param userId Designation User ID.
324      * @return Returns ERR_OK on success, others on failure.
325      */
326     int StartAbilityForResultAsCaller(
327         const Want &want,
328         const StartOptions &startOptions,
329         const sptr<IRemoteObject> &callerToken,
330         int requestCode = DEFAULT_INVAL_VALUE,
331         int32_t userId = DEFAULT_INVAL_VALUE) override;
332 
333     /**
334      * Start ui session ability with extension session info, send session info to ability manager service.
335      *
336      * @param want, the want of the ability to start.
337      * @param callerToken caller ability token.
338      * @param sessionInfo the information of UIExtensionContentSession.
339      * @param userId, Designation User ID.
340      * @param requestCode, Ability request code.
341      * @return Returns ERR_OK on success, others on failure.
342      */
343     virtual int StartAbilityByUIContentSession(
344         const Want &want,
345         const sptr<IRemoteObject> &callerToken,
346         const sptr<SessionInfo> &sessionInfo,
347         int32_t userId,
348         int requestCode) override;
349 
350     /**
351      * Start ui session ability with extension session info, send session info to ability manager service.
352      *
353      * @param want, the want of the ability to start.
354      * @param startOptions Indicates the options used to start.
355      * @param callerToken, caller ability token.
356      * @param sessionInfo the information of UIExtensionContentSession.
357      * @param userId, Designation User ID.
358      * @param requestCode the resultCode of the ability to start.
359      * @return Returns ERR_OK on success, others on failure.
360      */
361     virtual int StartAbilityByUIContentSession(
362         const Want &want,
363         const StartOptions &startOptions,
364         const sptr<IRemoteObject> &callerToken,
365         const sptr<SessionInfo> &sessionInfo,
366         int32_t userId,
367         int requestCode) override;
368 
369     /**
370      * Start ui ability
371      *
372      * @param want the want of the ability to start.
373      * @param callerToken caller ability token.
374      * @param specifyTokenId The Caller ID.
375      * @return Returns ERR_OK on success, others on failure.
376      */
377     virtual int StartAbilityOnlyUIAbility(
378         const Want &want,
379         const sptr<IRemoteObject> &callerToken,
380         uint32_t specifyTokenId) override;
381 
382     /**
383      * Open link of ability and atomic service.
384      *
385      * @param want Ability want.
386      * @param callerToken Caller ability token.
387      * @param userId User ID.
388      * @param requestCode Ability request code.
389      * @return Returns ERR_OK on success, others on failure.
390      */
391     virtual int32_t OpenLink(const Want& want, sptr<IRemoteObject> callerToken,
392         int32_t userId = DEFAULT_INVAL_VALUE, int requestCode = DEFAULT_INVAL_VALUE) override;
393 
394     /**
395      * Pop-up launch of full-screen atomic service.
396      *
397      * @param want The want with parameters.
398      * @param callerToken caller ability token.
399      * @param requestCode Ability request code.
400      * @param userId The User ID.
401      * @return Returns ERR_OK on success, others on failure.
402      */
403     virtual int32_t OpenAtomicService(Want& want, const StartOptions &options, sptr<IRemoteObject> callerToken,
404         int32_t requestCode = DEFAULT_INVAL_VALUE, int32_t userId = DEFAULT_INVAL_VALUE) override;
405 
406     /**
407      * @brief Querying whether to allow embedded startup of atomic service.
408      *
409      * @param token The caller UIAbility token.
410      * @param appId The ID of the application to which this bundle belongs.
411      * @return Returns true to allow ability to start, or false to reject.
412      */
413     virtual bool IsEmbeddedOpenAllowed(sptr<IRemoteObject> callerToken, const std::string &appId) override;
414 
415     /**
416      * Start extension ability with want, send want to ability manager service.
417      *
418      * @param want, the want of the ability to start.
419      * @param callerToken, caller ability token.
420      * @param userId, Designation User ID.
421      * @param extensionType If an ExtensionAbilityType is set, only extension of that type can be started.
422      * @return Returns ERR_OK on success, others on failure.
423      */
424     virtual int32_t StartExtensionAbility(
425         const Want &want,
426         const sptr<IRemoteObject> &callerToken,
427         int32_t userId = DEFAULT_INVAL_VALUE,
428         AppExecFwk::ExtensionAbilityType extensionType = AppExecFwk::ExtensionAbilityType::UNSPECIFIED) override;
429 
430     /**
431      * Request modal UIExtension with want, send want to ability manager service.
432      *
433      * @param want, the want contains ability info about caller and called.
434      * @return Returns ERR_OK on success, others on failure.
435      */
436     int RequestModalUIExtension(const Want &want) override;
437 
438     int PreloadUIExtensionAbility(const Want &want, std::string &hostBundleName,
439         int32_t userId = DEFAULT_INVAL_VALUE, int32_t hostPid = DEFAULT_INVAL_VALUE) override;
440 
441     int UnloadUIExtensionAbility(const std::shared_ptr<AAFwk::AbilityRecord> &abilityRecord, std::string &bundleName);
442 
443     int ChangeAbilityVisibility(sptr<IRemoteObject> token, bool isShow) override;
444 
445     int ChangeUIAbilityVisibilityBySCB(sptr<SessionInfo> sessionInfo, bool isShow) override;
446 
447     /**
448      * Start ui extension ability with extension session info, send extension session info to ability manager service.
449      *
450      * @param extensionSessionInfo the extension session info of the ability to start.
451      * @param userId, Designation User ID.
452      * @return Returns ERR_OK on success, others on failure.
453      */
454     virtual int StartUIExtensionAbility(
455         const sptr<SessionInfo> &extensionSessionInfo,
456         int32_t userId = DEFAULT_INVAL_VALUE) override;
457 
458     /**
459      * Start ui ability with want, send want to ability manager service.
460      *
461      * @param sessionInfo the session info of the ability to start.
462      * @param isColdStart the session info of the ability is or not cold start.
463      * @return Returns ERR_OK on success, others on failure.
464      */
465     virtual int StartUIAbilityBySCB(sptr<SessionInfo> sessionInfo, bool &isColdStart, uint32_t sceneFlag = 0) override;
466 
467     /**
468      * Stop extension ability with want, send want to ability manager service.
469      *
470      * @param want, the want of the ability to stop.
471      * @param callerToken, caller ability token.
472      * @param userId, Designation User ID.
473      * @param extensionType If an ExtensionAbilityType is set, only extension of that type can be stopped.
474      * @return Returns ERR_OK on success, others on failure.
475      */
476     virtual int StopExtensionAbility(
477         const Want& want,
478         const sptr<IRemoteObject>& callerToken,
479         int32_t userId = DEFAULT_INVAL_VALUE,
480         AppExecFwk::ExtensionAbilityType extensionType = AppExecFwk::ExtensionAbilityType::UNSPECIFIED) override;
481 
482     /**
483      * TerminateAbility, terminate the special ability.
484      *
485      * @param token, the token of the ability to terminate.
486      * @param resultCode, the resultCode of the ability to terminate.
487      * @param resultWant, the Want of the ability to return.
488      * @return Returns ERR_OK on success, others on failure.
489      */
490     virtual int TerminateAbility(const sptr<IRemoteObject> &token, int resultCode = DEFAULT_INVAL_VALUE,
491         const Want *resultWant = nullptr) override;
492 
493     /**
494      * TerminateUIServiceExtensionAbility, terminate the UIServiceExtensionAbility.
495      *
496      * @param token, the token of the ability to terminate.
497      * @return Returns ERR_OK on success, others on failure.
498      */
499     virtual int32_t TerminateUIServiceExtensionAbility(const sptr<IRemoteObject> &token) override;
500 
501     /**
502      * BackToCallerAbilityWithResult, return to the caller ability.
503      *
504      * @param token, the token of the ability to terminate.
505      * @param resultCode, the resultCode of the ability to terminate.
506      * @param resultWant, the Want of the ability to return.
507      * @param callerRequestCode, the requestCode of caller ability.
508      * @return Returns ERR_OK on success, others on failure.
509      */
510     virtual int BackToCallerAbilityWithResult(const sptr<IRemoteObject> &token, int resultCode,
511         const Want *resultWant, int64_t callerRequestCode) override;
512 
513     /**
514      * TerminateAbility, terminate the special ui extension ability.
515      *
516      * @param extensionSessionInfo the extension session info of the ability to terminate.
517      * @param resultCode, the resultCode of the ui extension ability to terminate.
518      * @param resultWant, the Want of the ui extension ability to return.
519      * @return Returns ERR_OK on success, others on failure.
520      */
521     virtual int TerminateUIExtensionAbility(const sptr<SessionInfo> &extensionSessionInfo,
522         int resultCode = DEFAULT_INVAL_VALUE, const Want *resultWant = nullptr) override;
523 
524     /**
525      * CloseUIExtensionAbilityBySCB, terminate the specified ui extension ability by SCB.
526      *
527      * @param token the ability token.
528      * @return Returns ERR_OK on success, others on failure.
529      */
530     int CloseUIExtensionAbilityBySCB(const sptr<IRemoteObject> token) override;
531 
532     /**
533      *  CloseUIAbilityBySCB, close the special ability by scb.
534      *
535      * @param sessionInfo the session info of the ability to terminate.
536      * @param sceneFlag the reason info of the ability to terminate.
537      * @return Returns ERR_OK on success, others on failure.
538      */
539     virtual int CloseUIAbilityBySCB(const sptr<SessionInfo> &sessionInfo, bool isUserRequestedExit,
540         uint32_t sceneFlag = 0) override;
541 
542     /**
543      * SendResultToAbility with want, return want from ability manager service.
544      *
545      * @param requestCode, request code.
546      * @param resultCode, resultCode to return.
547      * @param resultWant, the Want of the ability to return.
548      * @return Returns ERR_OK on success, others on failure.
549      */
550     virtual int SendResultToAbility(int32_t requestCode, int32_t resultCode, Want& resultWant) override;
551 
552     /**
553      * MoveAbilityToBackground.
554      *
555      * @param token, the token of the ability to move background.
556      * @return Returns ERR_OK on success, others on failure.
557      */
558     virtual int MoveAbilityToBackground(const sptr<IRemoteObject> &token) override;
559 
560     /**
561      * Move the UIAbility to background, called by app self.
562      *
563      * @param token the token of the ability to move.
564      * @return Returns ERR_OK on success, others on failure.
565      */
566     virtual int32_t MoveUIAbilityToBackground(const sptr<IRemoteObject> token) override;
567 
568     /**
569      * CloseAbility, close the special ability.
570      *
571      * @param token, the token of the ability to terminate.
572      * @param resultCode, the resultCode of the ability to terminate.
573      * @param resultWant, the Want of the ability to return.
574      * @return Returns ERR_OK on success, others on failure.
575      */
576     virtual int CloseAbility(const sptr<IRemoteObject> &token, int resultCode = DEFAULT_INVAL_VALUE,
577         const Want *resultWant = nullptr) override;
578 
579     /**
580      * MinimizeAbility, minimize the special ability.
581      *
582      * @param token, ability token.
583      * @param fromUser mark the minimize operation source.
584      * @return Returns ERR_OK on success, others on failure.
585      */
586     virtual int MinimizeAbility(const sptr<IRemoteObject> &token, bool fromUser = false) override;
587 
588     /**
589      * MinimizeUIExtensionAbility, minimize the special ui extension ability.
590      *
591      * @param extensionSessionInfo the extension session info of the ability to minimize.
592      * @param fromUser mark the minimize operation source.
593      * @return Returns ERR_OK on success, others on failure.
594      */
595     virtual int MinimizeUIExtensionAbility(const sptr<SessionInfo> &extensionSessionInfo,
596         bool fromUser = false) override;
597 
598     /**
599      * MinimizeUIAbilityBySCB, minimize the special ability by scb.
600      *
601      * @param sessionInfo the extension session info of the ability to minimize.
602      * @param fromUser, Whether form user.
603      * @return Returns ERR_OK on success, others on failure.
604      */
605     virtual int MinimizeUIAbilityBySCB(const sptr<SessionInfo> &sessionInfo, bool fromUser = false,
606         uint32_t sceneFlag = 0) override;
607 
608     /**
609      * ConnectAbility, connect session with service ability.
610      *
611      * @param want, Special want for service type's ability.
612      * @param connect, Callback used to notify caller the result of connecting or disconnecting.
613      * @param callerToken, caller ability token.
614      * @param userId, Designation User ID.
615      * @return Returns ERR_OK on success, others on failure.
616      */
617     virtual int32_t ConnectAbility(
618         const Want &want,
619         const sptr<IAbilityConnection> &connect,
620         const sptr<IRemoteObject> &callerToken,
621         int32_t userId = DEFAULT_INVAL_VALUE) override;
622 
623     virtual int32_t ConnectAbilityCommon(
624         const Want &want,
625         const sptr<IAbilityConnection> &connect,
626         const sptr<IRemoteObject> &callerToken,
627         AppExecFwk::ExtensionAbilityType extensionType,
628         int32_t userId = DEFAULT_INVAL_VALUE,
629         bool isQueryExtensionOnly = false) override;
630 
631     virtual int ConnectUIExtensionAbility(
632         const Want &want,
633         const sptr<IAbilityConnection> &connect,
634         const sptr<SessionInfo> &sessionInfo,
635         int32_t userId = DEFAULT_INVAL_VALUE,
636         sptr<UIExtensionAbilityConnectInfo> connectInfo = nullptr) override;
637 
638     /**
639      * ContinueMission, continue ability from mission center.
640      *
641      * @param srcDeviceId, origin deviceId.
642      * @param dstDeviceId, target deviceId.
643      * @param missionId, indicates which ability to continue.
644      * @param callBack, notify result back.
645      * @param wantParams, extended params.
646      * @return Returns ERR_OK on success, others on failure.
647      */
648     virtual int ContinueMission(const std::string &srcDeviceId, const std::string &dstDeviceId,
649         int32_t missionId, const sptr<IRemoteObject> &callBack, AAFwk::WantParams &wantParams) override;
650 
651     /**
652      * ContinueMission, continue ability from mission center.
653      *
654      * @param srcDeviceId, origin deviceId.
655      * @param dstDeviceId, target deviceId.
656      * @param bundleName, indicates which ability to continue.
657      * @param callBack, notify result back.
658      * @param wantParams, extended params.
659      * @return Returns ERR_OK on success, others on failure.
660      */
661     virtual int ContinueMission(AAFwk::ContinueMissionInfo continueMissionInfo,
662         const sptr<IRemoteObject> &callback) override;
663 
664     /**
665      * ContinueAbility, continue ability to ability.
666      *
667      * @param deviceId, target deviceId.
668      * @param missionId, indicates which ability to continue.
669      * @param versionCode, target bundle version.
670      * @return Returns ERR_OK on success, others on failure.
671      */
672     virtual int ContinueAbility(const std::string &deviceId, int32_t missionId, uint32_t versionCode) override;
673 
674     /**
675      * StartContinuation, continue ability to remote.
676      *
677      * @param want, Indicates the ability to start.
678      * @param abilityToken, Caller ability token.
679      * @param status, continue status.
680      * @return Returns ERR_OK on success, others on failure.
681      */
682     virtual int StartContinuation(const Want &want, const sptr<IRemoteObject> &abilityToken, int32_t status) override;
683 
684     /**
685      * NotifyCompleteContinuation, notify continuation complete to dms.
686      * @param deviceId, source device which start a continuation.
687      * @param sessionId, represent a continuation.
688      * @param isSuccess, continuation result.
689      * @return
690      */
691     virtual void NotifyCompleteContinuation(const std::string &deviceId, int32_t sessionId, bool isSuccess) override;
692 
693     /**
694      * NotifyContinuationResult, notify continue result to ability.
695      *
696      * @param missionId, Caller mission id.
697      * @param result, continuation result.
698      * @return Returns ERR_OK on success, others on failure.
699      */
700     virtual int NotifyContinuationResult(int32_t missionId, int32_t result) override;
701 
702     /**
703      * RegisterMissionListener, register remote device mission listener.
704      *
705      * @param deviceId, Indicates the remote device Id.
706      * @param listener, listener.
707      * @return Returns ERR_OK on success, others on failure.
708      */
709     virtual int RegisterMissionListener(const std::string &deviceId,
710         const sptr<IRemoteMissionListener> &listener) override;
711 
712     /**
713      * RegisterOnListener, register on notify mission listener.
714      *
715      * @param type, Indicates the notify type.
716      * @param listener, listener.
717      * @return Returns ERR_OK on success, others on failure.
718      */
719     virtual int RegisterOnListener(const std::string &type,
720         const sptr<IRemoteOnListener> &listener) override;
721 
722     /**
723      * RegisterOffListener, register on notify mission listener.
724      *
725      * @param type, Indicates the notify type.
726      * @param listener, listener.
727      * @return Returns ERR_OK on success, others on failure.
728      */
729     virtual int RegisterOffListener(const std::string &type,
730         const sptr<IRemoteOnListener> &listener) override;
731 
732     /**
733      * UnRegisterMissionListener, unregister remote device mission listener.
734      *
735      * @param deviceId, Indicates the remote device Id.
736      * @param listener, listener.
737      * @return Returns ERR_OK on success, others on failure.
738      */
739     virtual int UnRegisterMissionListener(const std::string &deviceId,
740         const sptr<IRemoteMissionListener> &listener)override;
741 
742     virtual int DisconnectAbility(sptr<IAbilityConnection> connect) override;
743 
744     /**
745      * AcquireDataAbility, acquire a data ability by its authority, if it not existed,
746      * AMS loads it synchronously.
747      *
748      * @param uri, data ability uri.
749      * @param tryBind, true: when a data ability is died, ams will kill this client, or do nothing.
750      * @param callerToken, specifies the caller ability token.
751      * @return returns the data ability ipc object, or nullptr for failed.
752      */
753     virtual sptr<IAbilityScheduler> AcquireDataAbility(
754         const Uri &uri, bool tryBind, const sptr<IRemoteObject> &callerToken) override;
755 
756     /**
757      * ReleaseDataAbility, release the data ability that referenced by 'dataAbilityToken'.
758      *
759      * @param dataAbilityToken, specifies the data ability that will be released.
760      * @param callerToken, specifies the caller ability token.
761      * @return returns ERR_OK if succeeded, or error codes for failed.
762      */
763     virtual int ReleaseDataAbility(
764         sptr<IAbilityScheduler> dataAbilityScheduler, const sptr<IRemoteObject> &callerToken) override;
765 
766     /**
767      * AttachAbilityThread, ability call this interface after loaded.
768      *
769      * @param scheduler,.the interface handler of kit ability.
770      * @param token,.ability's token.
771      * @return Returns ERR_OK on success, others on failure.
772      */
773     virtual int AttachAbilityThread(
774         const sptr<IAbilityScheduler> &scheduler, const sptr<IRemoteObject> &token) override;
775 
776     /**
777      * AbilityTransitionDone, ability call this interface after lift cycle was changed.
778      *
779      * @param token,.ability's token.
780      * @param state,.the state of ability lift cycle.
781      * @return Returns ERR_OK on success, others on failure.
782      */
783     virtual int AbilityTransitionDone(const sptr<IRemoteObject> &token, int state, const PacMap &saveData) override;
784 
785     /**
786      * AbilityWindowConfigTransitionDone, ability call this interface after lift cycle was changed.
787      *
788      * @param token,.ability's token.
789      * @return Returns ERR_OK on success, others on failure.
790      */
791     virtual int AbilityWindowConfigTransitionDone(
792         const sptr<IRemoteObject> &token, const WindowConfig &windowConfig) override;
793 
794     /**
795      * ScheduleConnectAbilityDone, service ability call this interface while session was connected.
796      *
797      * @param token,.service ability's token.
798      * @param remoteObject,.the session proxy of service ability.
799      * @return Returns ERR_OK on success, others on failure.
800      */
801     virtual int ScheduleConnectAbilityDone(
802         const sptr<IRemoteObject> &token, const sptr<IRemoteObject> &remoteObject) override;
803 
804     /**
805      * ScheduleDisconnectAbilityDone, service ability call this interface while session was disconnected.
806      *
807      * @param token,.service ability's token.
808      * @return Returns ERR_OK on success, others on failure.
809      */
810     virtual int ScheduleDisconnectAbilityDone(const sptr<IRemoteObject> &token) override;
811 
812     /**
813      * ScheduleCommandAbilityDone, service ability call this interface while session was commanded.
814      *
815      * @param token,.service ability's token.
816      * @return Returns ERR_OK on success, others on failure.
817      */
818     virtual int ScheduleCommandAbilityDone(const sptr<IRemoteObject> &token) override;
819 
820     virtual int ScheduleCommandAbilityWindowDone(
821         const sptr<IRemoteObject> &token,
822         const sptr<SessionInfo> &sessionInfo,
823         WindowCommand winCmd,
824         AbilityCommand abilityCmd) override;
825 
826     /**
827      *  Request to clean UIAbility from user.
828      *
829      * @param sessionInfo the session info of the ability to clean.
830      * @param sceneFlag the reason info of the ability to terminate.
831      * @return Returns ERR_OK on success, others on failure.
832      */
833     virtual int32_t CleanUIAbilityBySCB(const sptr<SessionInfo> &sessionInfo, bool isUserRequestedExit,
834         uint32_t sceneFlag = 0) override;
835 
GetTaskHandler()836     std::shared_ptr<TaskHandlerWrap> GetTaskHandler() const
837     {
838         return taskHandler_;
839     }
840 
GetDelayClearReasonHandler()841     std::shared_ptr<TaskHandlerWrap> GetDelayClearReasonHandler() const
842     {
843         return delayClearReasonHandler_;
844     }
845     /**
846      * GetEventHandler, get the ability manager service's handler.
847      *
848      * @return Returns AbilityEventHandler ptr.
849      */
850     std::shared_ptr<AbilityEventHandler> GetEventHandler();
851 
852     /**
853      * @brief Ability hidump.
854      * @param fd Indicates the fd.
855      * @param args Indicates the params.
856      * @return Returns the dump result.
857      */
858     int Dump(int fd, const std::vector<std::u16string>& args) override;
859 
860     /**
861      * dump ability stack info, about userID, mission stack info,
862      * mission record info and ability info.
863      *
864      * @param state Ability stack info.
865      * @return Returns ERR_OK on success, others on failure.
866      */
867     virtual void DumpState(const std::string &args, std::vector<std::string> &info) override;
868     virtual void DumpSysState(
869         const std::string& args, std::vector<std::string>& info, bool isClient, bool isUserID, int UserID) override;
870 
871     /**
872      * Destroys this Service ability by Want.
873      *
874      * @param want, Special want for service type's ability.
875      * @param token ability's token.
876      * @return Returns true if this Service ability will be destroyed; returns false otherwise.
877      */
878     virtual int StopServiceAbility(const Want &want, int32_t userId = DEFAULT_INVAL_VALUE,
879         const sptr<IRemoteObject> &token = nullptr) override;
880 
881     /**
882      * Kill the process immediately.
883      *
884      * @param bundleName.
885      * @return Returns ERR_OK on success, others on failure.
886      */
887     virtual int KillProcess(const std::string &bundleName, bool clearPageStack = false, int32_t appIndex = 0) override;
888 
889     /**
890      * Uninstall app
891      *
892      * @param bundleName bundle name of uninstalling app.
893      * @param uid uid of bundle.
894      * @return Returns ERR_OK on success, others on failure.
895      */
896     virtual int UninstallApp(const std::string &bundleName, int32_t uid) override;
897 
898     /**
899      * Uninstall app
900      *
901      * @param bundleName bundle name of uninstalling app.
902      * @param uid uid of bundle.
903      * @param appIndex the app index of app clone.
904      * @return Returns ERR_OK on success, others on failure.
905      */
906     virtual int32_t UninstallApp(const std::string &bundleName, int32_t uid, int32_t appIndex) override;
907 
908     /**
909      * Upgrade app, record exit reason and kill application
910      *
911      * @param bundleName bundle name of upgrading app.
912      * @param uid uid of bundle.
913      * @param exitMsg the exit reason message.
914      * @param appIndex the app index of app clone.
915      * @return Returns ERR_OK on success, others on failure.
916      */
917     virtual int32_t UpgradeApp(const std::string &bundleName, const int32_t uid, const std::string &exitMsg,
918         int32_t appIndex = 0) override;
919 
920     virtual sptr<IWantSender> GetWantSender(
921         const WantSenderInfo &wantSenderInfo, const sptr<IRemoteObject> &callerToken, int32_t uid = -1) override;
922 
923     virtual int SendWantSender(sptr<IWantSender> target, const SenderInfo &senderInfo) override;
924 
925     virtual void CancelWantSender(const sptr<IWantSender> &sender) override;
926 
927     virtual int GetPendingWantUid(const sptr<IWantSender> &target) override;
928 
929     virtual int GetPendingWantUserId(const sptr<IWantSender> &target) override;
930 
931     virtual std::string GetPendingWantBundleName(const sptr<IWantSender> &target) override;
932 
933     virtual int GetPendingWantCode(const sptr<IWantSender> &target) override;
934 
935     virtual int GetPendingWantType(const sptr<IWantSender> &target) override;
936 
937     virtual void RegisterCancelListener(const sptr<IWantSender> &sender, const sptr<IWantReceiver> &receiver) override;
938 
939     virtual void UnregisterCancelListener(
940         const sptr<IWantSender> &sender, const sptr<IWantReceiver> &receiver) override;
941 
942     virtual int GetPendingRequestWant(const sptr<IWantSender> &target, std::shared_ptr<Want> &want) override;
943 
944     virtual int GetWantSenderInfo(const sptr<IWantSender> &target, std::shared_ptr<WantSenderInfo> &info) override;
945 
946     virtual int RegisterObserver(const sptr<AbilityRuntime::IConnectionObserver> &observer) override;
947 
948     virtual int UnregisterObserver(const sptr<AbilityRuntime::IConnectionObserver> &observer) override;
949 
950 #ifdef WITH_DLP
951     virtual int GetDlpConnectionInfos(std::vector<AbilityRuntime::DlpConnectionInfo> &infos) override;
952 #endif // WITH_DLP
953 
954     virtual int GetConnectionData(std::vector<AbilityRuntime::ConnectionData> &connectionData) override;
955 
956     virtual void CancelWantSenderByFlags(const sptr<IWantSender> &sender, uint32_t flags) override;
957 
958     virtual int LockMissionForCleanup(int32_t missionId) override;
959 
960     virtual int UnlockMissionForCleanup(int32_t missionId) override;
961 
962     virtual void SetLockedState(int32_t sessionId, bool lockedState) override;
963 
964     virtual int RegisterMissionListener(const sptr<IMissionListener> &listener) override;
965 
966     virtual int UnRegisterMissionListener(const sptr<IMissionListener> &listener) override;
967 
968     virtual int GetMissionInfos(const std::string& deviceId, int32_t numMax,
969         std::vector<MissionInfo> &missionInfos) override;
970 
971     virtual int GetMissionInfo(const std::string& deviceId, int32_t missionId,
972         MissionInfo &missionInfo) override;
973 
974     virtual int CleanMission(int32_t missionId) override;
975 
976     virtual int CleanAllMissions() override;
977 
978     virtual int MoveMissionToFront(int32_t missionId) override;
979 
980     virtual int MoveMissionToFront(int32_t missionId, const StartOptions &startOptions) override;
981 
982     virtual int MoveMissionsToForeground(const std::vector<int32_t>& missionIds, int32_t topMissionId) override;
983 
984     virtual int MoveMissionsToBackground(const std::vector<int32_t>& missionIds,
985         std::vector<int32_t>& result) override;
986 
987     virtual int32_t GetMissionIdByToken(const sptr<IRemoteObject> &token) override;
988 
989     void GetAbilityTokenByCalleeObj(const sptr<IRemoteObject> &callStub, sptr<IRemoteObject> &token) override;
990 
991     virtual int StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) override;
992 
993     virtual int StopSyncRemoteMissions(const std::string& devId) override;
994 
995     virtual int GetAppMemorySize() override;
996 
997     virtual bool IsRamConstrainedDevice() override;
998     /**
999      * Start Ability, connect session with common ability.
1000      *
1001      * @param want, Special want for service type's ability.
1002      * @param connect, Callback used to notify caller the result of connecting or disconnecting.
1003      * @param accountId Indicates the account to start.
1004      * @return Returns ERR_OK on success, others on failure.
1005      */
1006     virtual int StartAbilityByCall(const Want &want, const sptr<IAbilityConnection> &connect,
1007         const sptr<IRemoteObject> &callerToken, int32_t accountId = DEFAULT_INVAL_VALUE) override;
1008 
1009     virtual int StartAbilityByCallWithErrMsg(const Want &want, const sptr<IAbilityConnection> &connect,
1010         const sptr<IRemoteObject> &callerToken, int32_t accountId, std::string &errMsg) override;
1011 
1012     /**
1013      * As abilityRequest is prepared, just execute starting ability procedure.
1014      * By now, this is only used by start_ability_sandbox_savefile.
1015      * @param abilityRequest, Prepared with all info for starting a ability.
1016      * @param validUserId, Valid user id.
1017      */
1018     int StartAbilityJust(AbilityRequest &abilityRequest, int32_t validUserId);
1019 
1020     /**
1021      * CallRequestDone, after invoke callRequest, ability will call this interface to return callee.
1022      *
1023      * @param token, ability's token.
1024      * @param callStub, ability's callee.
1025      */
1026     void CallRequestDone(const sptr<IRemoteObject> &token, const sptr<IRemoteObject> &callStub) override;
1027 
1028     /**
1029      * Release the call between Ability, disconnect session with common ability.
1030      *
1031      * @param connect, Callback used to notify caller the result of connecting or disconnecting.
1032      * @param element, the element of target service.
1033      * @return Returns ERR_OK on success, others on failure.
1034      */
1035     virtual int ReleaseCall(
1036         const sptr<IAbilityConnection> &connect, const AppExecFwk::ElementName &element) override;
1037 
1038     std::list<std::shared_ptr<ConnectionRecord>> GetConnectRecordListByCallback(sptr<IAbilityConnection> callback);
1039 
1040     void OnAbilityDied(std::shared_ptr<AbilityRecord> abilityRecord);
1041     void OnCallConnectDied(std::shared_ptr<CallRecord> callRecord);
1042     void HandleLoadTimeOut(int64_t abilityRecordId, bool isHalf = false, bool isExtension = false);
1043     void HandleActiveTimeOut(int64_t abilityRecordId);
1044     void HandleInactiveTimeOut(int64_t abilityRecordId);
1045     void HandleForegroundTimeOut(int64_t abilityRecordId, bool isHalf = false, bool isExtension = false);
1046     void HandleShareDataTimeOut(int64_t uniqueId);
1047     int32_t GetShareDataPairAndReturnData(std::shared_ptr<AbilityRecord> abilityRecord,
1048         const int32_t &resultCode, const int32_t &uniqueId, WantParams &wantParam);
1049 
1050     int32_t StartAbilityByFreeInstall(const Want &want, sptr<IRemoteObject> callerToken, int32_t userId,
1051         int32_t requestCode);
1052 
1053     int StartAbilityWrap(
1054         const Want &want,
1055         const sptr<IRemoteObject> &callerToken,
1056         int requestCode,
1057         bool isPendingWantCaller,
1058         int32_t userId = DEFAULT_INVAL_VALUE,
1059         bool isStartAsCaller = false,
1060         uint32_t specifyTokenId = 0,
1061         bool isForegroundToRestartApp = false,
1062         bool isImplicit = false,
1063         bool isUIAbilityOnly = false);
1064 
1065     int StartAbilityInner(
1066         const Want &want,
1067         const sptr<IRemoteObject> &callerToken,
1068         int requestCode,
1069         bool isPendingWantCaller,
1070         int32_t userId = DEFAULT_INVAL_VALUE,
1071         bool isStartAsCaller = false,
1072         uint32_t specifyTokenId = 0,
1073         bool isForegroundToRestartApp = false,
1074         bool isImplicit = false,
1075         bool isUIAbilityOnly = false);
1076 
1077     int32_t StartExtensionAbilityInner(
1078         const Want &want,
1079         const sptr<IRemoteObject> &callerToken,
1080         int32_t userId,
1081         AppExecFwk::ExtensionAbilityType extensionType,
1082         bool checkSystemCaller = true,
1083         bool isImplicit = false,
1084         bool isDlp = false,
1085         bool isStartAsCaller = false);
1086 
1087     int RequestModalUIExtensionInner(Want want);
1088 
1089     int PreloadUIExtensionAbilityInner(const Want &want, std::string &bundleName,
1090         int32_t userId = DEFAULT_INVAL_VALUE, int32_t hostPid = DEFAULT_INVAL_VALUE);
1091 
1092     int StartAbilityForOptionWrap(
1093         const Want &want,
1094         const StartOptions &startOptions,
1095         const sptr<IRemoteObject> &callerToken,
1096         bool isPendingWantCaller,
1097         int32_t userId = DEFAULT_INVAL_VALUE,
1098         int requestCode = DEFAULT_INVAL_VALUE,
1099         bool isStartAsCaller = false,
1100         uint32_t callerTokenId = 0,
1101         bool isImplicit = false,
1102         bool isCallByShortcut = false);
1103 
1104     int StartAbilityForOptionInner(
1105         const Want &want,
1106         const StartOptions &startOptions,
1107         const sptr<IRemoteObject> &callerToken,
1108         bool isPendingWantCaller,
1109         int32_t userId = DEFAULT_INVAL_VALUE,
1110         int requestCode = DEFAULT_INVAL_VALUE,
1111         bool isStartAsCaller = false,
1112         uint32_t specifyTokenId = 0,
1113         bool isImplicit = false,
1114         bool isCallByShortcut = false);
1115 
1116     int ImplicitStartAbility(
1117         const Want &want,
1118         const AbilityStartSetting &abilityStartSetting,
1119         const sptr<IRemoteObject> &callerToken,
1120         int32_t userId = DEFAULT_INVAL_VALUE,
1121         int requestCode = DEFAULT_INVAL_VALUE);
1122 
1123     int StartAbilityDetails(
1124         const Want &want,
1125         const AbilityStartSetting &abilityStartSetting,
1126         const sptr<IRemoteObject> &callerToken,
1127         int32_t userId = DEFAULT_INVAL_VALUE,
1128         int requestCode = DEFAULT_INVAL_VALUE,
1129         bool isImplicit = false);
1130 
1131     int ImplicitStartAbility(
1132         const Want &want,
1133         const StartOptions &startOptions,
1134         const sptr<IRemoteObject> &callerToken,
1135         int32_t userId = DEFAULT_INVAL_VALUE,
1136         int requestCode = DEFAULT_INVAL_VALUE);
1137 
1138     int ImplicitStartExtensionAbility(
1139         const Want &want,
1140         const sptr<IRemoteObject> &callerToken,
1141         int32_t userId = DEFAULT_INVAL_VALUE,
1142         AppExecFwk::ExtensionAbilityType extensionType = AppExecFwk::ExtensionAbilityType::UNSPECIFIED);
1143 
1144     int StartAbilityAsCallerDetails(
1145         const Want &want,
1146         const sptr<IRemoteObject> &callerToken,
1147         sptr<IRemoteObject> asCallerSourceToken,
1148         int32_t userId = DEFAULT_INVAL_VALUE,
1149         int requestCode = DEFAULT_INVAL_VALUE,
1150         bool isImplicit = false);
1151 
1152     int ImplicitStartAbilityAsCaller(
1153         const Want &want,
1154         const sptr<IRemoteObject> &callerToken,
1155         sptr<IRemoteObject> asCallerSourceToken,
1156         int32_t userId = DEFAULT_INVAL_VALUE,
1157         int requestCode = DEFAULT_INVAL_VALUE);
1158 
1159     void OnAcceptWantResponse(const AAFwk::Want &want, const std::string &flag, int32_t requestId = 0);
1160     void OnStartSpecifiedAbilityTimeoutResponse(const AAFwk::Want &want, int32_t requestId = 0);
1161 
1162     void OnStartSpecifiedProcessResponse(const AAFwk::Want &want, const std::string &flag,
1163         int32_t requestId = 0);
1164     void OnStartSpecifiedProcessTimeoutResponse(const AAFwk::Want &want, int32_t requestId = 0);
1165     void OnStartSpecifiedFailed(int32_t requestId);
1166 
1167     virtual int GetAbilityRunningInfos(std::vector<AbilityRunningInfo> &info) override;
1168     virtual int GetExtensionRunningInfos(int upperLimit, std::vector<ExtensionRunningInfo> &info) override;
1169     virtual int GetProcessRunningInfos(std::vector<AppExecFwk::RunningProcessInfo> &info) override;
1170     virtual int GetAllIntentExemptionInfo(std::vector<AppExecFwk::IntentExemptionInfo> &info) override;
1171     int GetProcessRunningInfosByUserId(std::vector<AppExecFwk::RunningProcessInfo> &info, int32_t userId);
1172     void GetAbilityRunningInfo(std::vector<AbilityRunningInfo> &info, std::shared_ptr<AbilityRecord> &abilityRecord);
1173     void GetExtensionRunningInfo(std::shared_ptr<AbilityRecord> &abilityRecord, const int32_t userId,
1174         std::vector<ExtensionRunningInfo> &info);
1175 
1176     int GetMissionSaveTime() const;
1177 
1178     /**
1179      * generate ability request.
1180      *
1181      */
1182     int GenerateAbilityRequest(
1183         const Want &want,
1184         int requestCode,
1185         AbilityRequest &request,
1186         const sptr<IRemoteObject> &callerToken,
1187         int32_t userId);
1188 
1189     /**
1190      * Get mission id by target ability token.
1191      *
1192      * @param token target ability token.
1193      * @return the missionId of target mission.
1194      */
1195     int32_t GetMissionIdByAbilityToken(const sptr<IRemoteObject> &token);
1196 
1197     /**
1198      * Get ability token by target mission id.
1199      *
1200      * @param missionId target missionId.
1201      * @return the ability token of target mission.
1202      */
1203     sptr<IRemoteObject> GetAbilityTokenByMissionId(int32_t missionId);
1204 
1205     virtual int StartUser(int userId, sptr<IUserCallback> callback, bool isAppRecovery = false) override;
1206 
1207     virtual int StopUser(int userId, const sptr<IUserCallback> &callback) override;
1208 
1209     virtual int LogoutUser(int32_t userId, sptr<IUserCallback> callback) override;
1210 
1211     /**
1212      * Called when client complete dump.
1213      *
1214      * @param infos The dump info.
1215      * @param callerToken The caller ability token.
1216      * @return Returns ERR_OK on success, others on failure.
1217      */
1218     virtual int DumpAbilityInfoDone(std::vector<std::string> &infos, const sptr<IRemoteObject> &callerToken) override;
1219 
1220     virtual int SetMissionContinueState(const sptr<IRemoteObject> &abilityToken,
1221         const AAFwk::ContinueState &state) override;
1222 
1223 #ifdef SUPPORT_SCREEN
1224     virtual int SetMissionLabel(const sptr<IRemoteObject> &abilityToken, const std::string &label) override;
1225 
1226     virtual int SetMissionIcon(const sptr<IRemoteObject> &token,
1227         const std::shared_ptr<OHOS::Media::PixelMap> &icon) override;
1228 
1229     virtual int RegisterWindowManagerServiceHandler(const sptr<IWindowManagerServiceHandler>& handler,
1230         bool animationEnabled) override;
1231 
1232     virtual void CompleteFirstFrameDrawing(const sptr<IRemoteObject> &abilityToken) override;
1233 
1234     virtual void CompleteFirstFrameDrawing(int32_t sessionId) override;
1235 
1236     sptr<IWindowManagerServiceHandler> GetWMSHandler() const;
1237 
1238     virtual int PrepareTerminateAbility(const sptr<IRemoteObject> &token,
1239         sptr<IPrepareTerminateCallback> &callback) override;
1240 
1241     void HandleFocused(const sptr<OHOS::Rosen::FocusChangeInfo> &focusChangeInfo);
1242 
1243     void HandleUnfocused(const sptr<OHOS::Rosen::FocusChangeInfo> &focusChangeInfo);
1244 
1245     void HandleWindowVisibilityChanged(
1246         const std::vector<sptr<OHOS::Rosen::WindowVisibilityInfo>> &windowVisibilityInfos);
1247 
1248     virtual int GetDialogSessionInfo(const std::string &dialogSessionId,
1249         sptr<DialogSessionInfo> &dialogSessionInfo) override;
1250 
1251     virtual int SendDialogResult(const Want &want, const std::string &dialogSessionId, bool isAllowed) override;
1252 
1253     int CreateCloneSelectorDialog(AbilityRequest &request, int32_t userId, const std::string &replaceWantString = "");
1254 
1255     void RemoveSelectorIdentity(int32_t tokenId);
1256 
1257     void SetTargetCloneIndexInSameBundle(const Want &want, sptr<IRemoteObject> callerToken);
1258 
1259     virtual int RegisterAbilityFirstFrameStateObserver(const sptr<IAbilityFirstFrameStateObserver> &observer,
1260         const std::string &bundleName) override;
1261 
1262     virtual int UnregisterAbilityFirstFrameStateObserver(
1263         const sptr<IAbilityFirstFrameStateObserver> &observer) override;
1264 
1265     bool GetAnimationFlag();
1266 
1267 #endif
1268 
1269     void ClearUserData(int32_t userId);
1270 
1271     virtual int RegisterSnapshotHandler(const sptr<ISnapshotHandler>& handler) override;
1272 
1273     virtual int32_t GetMissionSnapshot(const std::string& deviceId, int32_t missionId,
1274         MissionSnapshot& snapshot, bool isLowResolution) override;
1275 
1276     /**
1277      * Set ability controller.
1278      *
1279      * @param abilityController, The ability controller.
1280      * @return Returns ERR_OK on success, others on failure.
1281      */
1282     virtual int SetAbilityController(const sptr<IAbilityController> &abilityController, bool imAStabilityTest) override;
1283 
1284     /**
1285      * Is user a stability test.
1286      *
1287      * @return Returns true if user is a stability test.
1288      */
1289     virtual bool IsRunningInStabilityTest() override;
1290 
1291     virtual int StartUserTest(const Want &want, const sptr<IRemoteObject> &observer) override;
1292 
1293     virtual int FinishUserTest(
1294         const std::string &msg, const int64_t &resultCode, const std::string &bundleName) override;
1295 
1296     /**
1297      * GetTopAbility, get the token of top ability.
1298      *
1299      * @param token, the token of top ability.
1300      * @return Returns ERR_OK on success, others on failure.
1301      */
1302     virtual int GetTopAbility(sptr<IRemoteObject> &token) override;
1303 
1304     virtual int CheckUIExtensionIsFocused(uint32_t uiExtensionTokenId, bool& isFocused) override;
1305 
1306     /**
1307      * The delegator calls this interface to move the ability to the foreground.
1308      *
1309      * @param token, ability's token.
1310      * @return Returns ERR_OK on success, others on failure.
1311      */
1312     virtual int DelegatorDoAbilityForeground(const sptr<IRemoteObject> &token) override;
1313 
1314     /**
1315      * The delegator calls this interface to move the ability to the background.
1316      *
1317      * @param token, ability's token.
1318      * @return Returns ERR_OK on success, others on failure.
1319      */
1320     virtual int DelegatorDoAbilityBackground(const sptr<IRemoteObject> &token) override;
1321 
1322     /**
1323      * Calls this interface to move the ability to the foreground.
1324      *
1325      * @param token, ability's token.
1326      * @param flag, use for lock or unlock flag and so on.
1327      * @return Returns ERR_OK on success, others on failure.
1328      */
1329     virtual int DoAbilityForeground(const sptr<IRemoteObject> &token, uint32_t flag) override;
1330 
1331     /**
1332      * Calls this interface to move the ability to the background.
1333      *
1334      * @param token, ability's token.
1335      * @param flag, use for lock or unlock flag and so on.
1336      * @return Returns ERR_OK on success, others on failure.
1337      */
1338     virtual int DoAbilityBackground(const sptr<IRemoteObject> &token, uint32_t flag) override;
1339 
1340     bool IsAbilityControllerStart(const Want &want, const std::string &bundleName);
1341 
1342     bool IsAbilityControllerForeground(const std::string &bundleName);
1343 
1344     bool IsAbilityControllerStartById(int32_t missionId);
1345 
1346     #ifdef ABILITY_COMMAND_FOR_TEST
1347     /**
1348      * force timeout ability.
1349      *
1350      * @param abilityName.
1351      * @param state.
1352      * @return Returns ERR_OK on success, others on failure.
1353      */
1354     virtual int ForceTimeoutForTest(const std::string &abilityName, const std::string &state) override;
1355     #endif
1356 
1357     bool GetDataAbilityUri(const std::vector<AppExecFwk::AbilityInfo> &abilityInfos,
1358         const std::string &mainAbility, std::string &uri);
1359 
1360     virtual AppExecFwk::ElementName GetTopAbility(bool isNeedLocalDeviceId = true) override;
1361 
1362     virtual AppExecFwk::ElementName GetElementNameByToken(sptr<IRemoteObject> token,
1363         bool isNeedLocalDeviceId = true) override;
1364 
1365     /**
1366      * AtomicServiceStatusCallback OnInstallFinished callback.
1367      *
1368      * @param resultCode FreeInstall result code.
1369      * @param want Want has been installed.
1370      * @param userId User id.
1371      */
1372     void OnInstallFinished(int resultCode, const Want &want, int32_t userId);
1373 
1374     /**
1375      * AtomicServiceStatusCallback OnRemoteInstallFinished callback.
1376      *
1377      * @param resultCode FreeInstall result code.
1378      * @param want Want has been installed.
1379      * @param userId User id.
1380      */
1381     void OnRemoteInstallFinished(int resultCode, const Want &want, int32_t userId);
1382 
1383     /**
1384      * FreeInstall form remote call.
1385      *
1386      * @param want Want need to install.
1387      * @param callback DMS callback.
1388      * @param userId User id.
1389      * @param requestCode Ability request code.
1390      * @return Returns ERR_OK on success, others on failure.
1391      */
1392     virtual int FreeInstallAbilityFromRemote(const Want &want, const sptr<IRemoteObject> &callback,
1393         int32_t userId, int requestCode = DEFAULT_INVAL_VALUE) override;
1394 
1395     /**
1396      * Add FreeInstall Observer
1397      *
1398      * @param observer the observer of ability free install start.
1399      * @return Returns ERR_OK on success, others on failure.
1400      */
1401     virtual int AddFreeInstallObserver(const sptr<IRemoteObject> &callerToken,
1402         const sptr<AbilityRuntime::IFreeInstallObserver> &observer) override;
1403 
1404     /**
1405      * Check the uid is background task uid.
1406      *
1407      * @param uid userId.
1408      * @return Returns whether the uid is background task uid.
1409      */
1410     bool IsBackgroundTaskUid(const int uid);
1411 
1412     bool GetLocalDeviceId(std::string& localDeviceId);
1413 
1414     int JudgeAbilityVisibleControl(const AppExecFwk::AbilityInfo &abilityInfo);
1415 
1416     /**
1417      * Called to update mission snapshot.
1418      * @param token The target ability.
1419      * @param pixelMap The snapshot.
1420      */
1421 #ifdef SUPPORT_SCREEN
1422     virtual void UpdateMissionSnapShot(const sptr<IRemoteObject> &token,
1423         const std::shared_ptr<Media::PixelMap> &pixelMap) override;
1424 #endif // SUPPORT_SCREEN
1425     virtual void EnableRecoverAbility(const sptr<IRemoteObject>& token) override;
1426     virtual void SubmitSaveRecoveryInfo(const sptr<IRemoteObject>& token) override;
1427     virtual void ScheduleRecoverAbility(const sptr<IRemoteObject> &token, int32_t reason,
1428         const Want *want = nullptr) override;
1429 
1430     virtual void ScheduleClearRecoveryPageStack() override;
1431 
1432     /**
1433      * Called to verify that the MissionId is valid.
1434      * @param missionIds Query mission list.
1435      * @param results Output parameters, return results up to 20 query results.
1436      * @return Returns ERR_OK on success, others on failure.
1437      */
1438     int32_t IsValidMissionIds(
1439         const std::vector<int32_t> &missionIds, std::vector<MissionValidResult> &results) override;
1440 
1441     virtual int32_t RequestDialogService(const Want &want, const sptr<IRemoteObject> &callerToken) override;
1442 
1443     int32_t ReportDrawnCompleted(const sptr<IRemoteObject> &callerToken) override;
1444 
1445     virtual int32_t AcquireShareData(
1446         const int32_t &missionId, const sptr<IAcquireShareDataCallback> &shareData) override;
1447     virtual int32_t ShareDataDone(const sptr<IRemoteObject>& token,
1448         const int32_t &requestCode, const int32_t &uniqueId, WantParams &wantParam) override;
1449 
1450     bool GetStartUpNewRuleFlag() const;
1451 
1452     std::shared_ptr<AbilityRecord> GetFocusAbility();
1453 
1454     /**
1455      * Query whether the application of the specified PID and UID has been granted a certain permission
1456      * @param permission
1457      * @param pid Process id
1458      * @param uid
1459      * @return Returns ERR_OK if the current process has the permission, others on failure.
1460      */
1461     virtual int VerifyPermission(const std::string &permission, int pid, int uid) override;
1462 
1463     bool IsDmsAlive() const;
1464 
1465     /**
1466      * Upgrade app completed event.
1467      * @param uid.
1468      */
1469     void AppUpgradeCompleted(int32_t uid);
1470 
1471     /**
1472      * Record app exit reason.
1473      * @param exitReason The reason of app exit.
1474      * @return Returns ERR_OK on success, others on failure.
1475      */
1476     virtual int32_t RecordAppExitReason(const ExitReason &exitReason) override;
1477 
1478     /**
1479      * Force app exit and record exit reason.
1480      * @param pid Process id .
1481      * @param exitReason The reason of app exit.
1482      * @return Returns ERR_OK on success, others on failure.
1483      */
1484     virtual int32_t ForceExitApp(const int32_t pid, const ExitReason &exitReason) override;
1485 
1486     /**
1487      * Record the process exit reason before the process being killed.
1488      * @param pid The process id.
1489      * @param exitReason The reason of process exit.
1490      * @return Returns ERR_OK on success, others on failure.
1491      */
1492     virtual int32_t RecordProcessExitReason(const int32_t pid, const ExitReason &exitReason) override;
1493 
1494     /**
1495      * Record the exit reason of a killed process.
1496      * @param pid The process id.
1497      * @param uid The process uid.
1498      * @param exitReason The reason of process exit.
1499      * @return Returns ERR_OK on success, others on failure.
1500      */
1501     virtual int32_t RecordProcessExitReason(int32_t pid, int32_t uid, const ExitReason &exitReason) override;
1502 
1503     int32_t GetConfiguration(AppExecFwk::Configuration& config);
1504 
1505     /**
1506      * Set rootSceneSession by SCB.
1507      *
1508      * @param rootSceneSession Indicates root scene session of SCB.
1509      */
1510     virtual void SetRootSceneSession(const sptr<IRemoteObject> &rootSceneSession) override;
1511 
1512     /**
1513      * Call UIAbility by SCB.
1514      *
1515      * @param sessionInfo the session info of the ability to be called.
1516      * @param isColdStart the session of the ability is or not cold start.
1517      */
1518     virtual void CallUIAbilityBySCB(const sptr<SessionInfo> &sessionInfo, bool &isColdStart) override;
1519 
1520     /**
1521      * Start specified ability by SCB.
1522      *
1523      * @param want Want information.
1524      */
1525     virtual void StartSpecifiedAbilityBySCB(const Want &want) override;
1526 
1527     /**
1528      * Notify sandbox app the result of saving file.
1529      * @param want Result of saving file, which contains the file's uri if success.
1530      * @param resultCode Indicates the action's result.
1531      * @param requestCode Pass the requestCode to match request.
1532      * @return Returns ERR_OK on success, others on failure.
1533      */
1534     virtual int32_t NotifySaveAsResult(const Want &want, int resultCode, int requestCode) override;
1535 
1536     /**
1537      * Set sessionManagerService
1538      * @param sessionManagerService the point of sessionManagerService.
1539      *
1540      * @return Returns ERR_OK on success, others on failure.
1541      */
1542     virtual int32_t SetSessionManagerService(const sptr<IRemoteObject> &sessionManagerService) override;
1543 
1544     /**
1545      * @brief Register collaborator.
1546      * @param type collaborator type.
1547      * @param impl collaborator.
1548      * @return 0 or else.
1549     */
1550     virtual int32_t RegisterIAbilityManagerCollaborator(
1551         int32_t type, const sptr<IAbilityManagerCollaborator> &impl) override;
1552 
1553     /**
1554      * @brief Unregister collaborator.
1555      * @param type collaborator type.
1556      * @return 0 or else.
1557     */
1558     virtual int32_t UnregisterIAbilityManagerCollaborator(int32_t type) override;
1559 
1560     /**
1561      * @brief Get collaborator.
1562      * @param type collaborator type.
1563      * @return nullptr or IAbilityManagerCollaborator stpr.
1564     */
1565     sptr<IAbilityManagerCollaborator> GetCollaborator(int32_t type);
1566 
1567     /**
1568      * get the user id.
1569      *
1570      */
1571     int32_t GetUserId() const;
1572 
1573     virtual int32_t RegisterStatusBarDelegate(sptr<AbilityRuntime::IStatusBarDelegate> delegate) override;
1574 
1575     virtual int32_t KillProcessWithPrepareTerminate(const std::vector<int32_t>& pids) override;
1576 
1577     virtual int32_t KillProcessWithReason(int32_t pid, const ExitReason &reason) override;
1578 
1579     /**
1580      * @brief Register auto start up callback for system api.
1581      * @param callback The point of JsAbilityAutoStartupCallBack.
1582      * @return Returns ERR_OK on success, others on failure.
1583      */
1584     virtual int32_t RegisterAutoStartupSystemCallback(const sptr<IRemoteObject> &callback) override;
1585 
1586     /**
1587      * @brief Unregister auto start up callback for system api.
1588      * @param callback The point of JsAbilityAutoStartupCallBack.
1589      * @return Returns ERR_OK on success, others on failure.
1590      */
1591     virtual int32_t UnregisterAutoStartupSystemCallback(const sptr<IRemoteObject> &callback) override;
1592 
1593     /**
1594      * @brief Set every application auto start up state.
1595      * @param info The auto startup info,include bundle name, module name, ability name.
1596      * @return Returns ERR_OK on success, others on failure.
1597      */
1598     virtual int32_t SetApplicationAutoStartup(const AutoStartupInfo &info) override;
1599 
1600     /**
1601      * @brief Cancel every application auto start up .
1602      * @param info The auto startup info,include bundle name, module name, ability name.
1603      * @return Returns ERR_OK on success, others on failure.
1604      */
1605     virtual int32_t CancelApplicationAutoStartup(const AutoStartupInfo &info) override;
1606 
1607     /**
1608      * @brief Query auto startup state all application.
1609      * @param infoList Output parameters, return auto startup info list.
1610      * @return Returns ERR_OK on success, others on failure.
1611      */
1612     virtual int32_t QueryAllAutoStartupApplications(std::vector<AutoStartupInfo> &infoList) override;
1613 
1614     /**
1615      * PrepareTerminateAbilityBySCB, prepare to terminate ability by scb.
1616      *
1617      * @param sessionInfo the session info of the ability to start.
1618      * @param isTerminate the result of ability onPrepareToTerminate.
1619      * @return Returns ERR_OK on success, others on failure.
1620      */
1621     virtual int PrepareTerminateAbilityBySCB(const sptr<SessionInfo> &sessionInfo, bool &isTerminate) override;
1622 
1623     /**
1624      * @brief Register app debug listener.
1625      * @param listener App debug listener.
1626      * @return Returns ERR_OK on success, others on failure.
1627      */
1628     int32_t RegisterAppDebugListener(sptr<AppExecFwk::IAppDebugListener> listener) override;
1629 
1630     /**
1631      * @brief Unregister app debug listener.
1632      * @param listener App debug listener.
1633      * @return Returns ERR_OK on success, others on failure.
1634      */
1635     int32_t UnregisterAppDebugListener(sptr<AppExecFwk::IAppDebugListener> listener) override;
1636 
1637     /**
1638      * @brief Attach app debug.
1639      * @param bundleName The application bundle name.
1640      * @return Returns ERR_OK on success, others on failure.
1641      */
1642     int32_t AttachAppDebug(const std::string &bundleName, bool isDebugFromLocal) override;
1643 
1644     /**
1645      * @brief Detach app debug.
1646      * @param bundleName The application bundle name.
1647      * @return Returns ERR_OK on success, others on failure.
1648      */
1649     int32_t DetachAppDebug(const std::string &bundleName, bool isDebugFromLocal) override;
1650 
1651     /**
1652      * @brief Execute intent.
1653      * @param key The key of intent executing client.
1654      * @param callerToken Caller ability token.
1655      * @param param The Intent execute param.
1656      * @return Returns ERR_OK on success, others on failure.
1657      */
1658     int32_t ExecuteIntent(uint64_t key, const sptr<IRemoteObject> &callerToken,
1659         const InsightIntentExecuteParam &param) override;
1660 
1661     /**
1662      * @brief Execute intent.
1663      * @param abilityRequest The abilityRequest.
1664      */
1665     int32_t OnExecuteIntent(AbilityRequest &abilityRequest, std::shared_ptr<AbilityRecord> &targetRecord);
1666 
1667     int32_t StartAbilityWithInsightIntent(const Want &want, int32_t userId = DEFAULT_INVAL_VALUE,
1668         int requestCode = DEFAULT_INVAL_VALUE);
1669 
1670     int32_t StartAbilityByCallWithInsightIntent(const Want &want, const sptr<IRemoteObject> &callerToken,
1671         const InsightIntentExecuteParam &param);
1672 
1673     /**
1674      * @brief Check if ability controller can start.
1675      * @param want The want of ability to start.
1676      * @return Return true to allow ability to start, or false to reject.
1677      */
1678     virtual bool IsAbilityControllerStart(const Want &want) override;
1679 
1680     /**
1681      * @brief Called when insight intent execute finished.
1682      *
1683      * @param token ability's token.
1684      * @param intentId insight intent id.
1685      * @param result insight intent execute result.
1686      * @return Returns ERR_OK on success, others on failure.
1687      */
1688     int32_t ExecuteInsightIntentDone(const sptr<IRemoteObject> &token, uint64_t intentId,
1689         const InsightIntentExecuteResult &result) override;
1690 
1691     /**
1692      * @brief Open file by uri.
1693      * @param uri The file uri.
1694      * @param flag Want::FLAG_AUTH_READ_URI_PERMISSION or Want::FLAG_AUTH_WRITE_URI_PERMISSION.
1695      * @return int The file descriptor.
1696      */
1697     virtual int32_t OpenFile(const Uri& uri, uint32_t flag) override;
1698 
1699     void RemoveLauncherDeathRecipient(int32_t userId);
1700     /**
1701      * @brief Set application auto start up state by EDM.
1702      * @param info The auto startup info, include bundle name, module name, ability name.
1703      * @param flag Indicate whether to allow the application to change the auto start up state.
1704      * @return Returns ERR_OK on success, others on failure.
1705      */
1706     int32_t SetApplicationAutoStartupByEDM(const AutoStartupInfo &info, bool flag) override;
1707 
1708     /**
1709      * @brief Cancel application auto start up state by EDM.
1710      * @param info The auto startup info, include bundle name, module name, ability name.
1711      * @param flag Indicate whether to allow the application to change the auto start up state.
1712      * @return Returns ERR_OK on success, others on failure.
1713      */
1714     int32_t CancelApplicationAutoStartupByEDM(const AutoStartupInfo &info, bool flag) override;
1715 
1716     /**
1717      * @brief Get foreground ui abilities.
1718      * @param list Foreground ui abilities.
1719      * @return Returns ERR_OK on success, others on failure.
1720      */
1721     int32_t GetForegroundUIAbilities(std::vector<AppExecFwk::AbilityStateData> &list) override;
1722 
1723     /**
1724      * @brief Update session info.
1725      * @param sessionInfos The vector of session info.
1726      */
1727     virtual int32_t UpdateSessionInfoBySCB(std::list<SessionInfo> &sessionInfos, int32_t userId,
1728         std::vector<int32_t> &sessionIds) override;
1729 
1730     /**
1731      * @brief Restart app self.
1732      * @param want The ability type must be UIAbility.
1733      * @param isAppRecovery True indicates that the app is restarted because of recovery.
1734      * @return Returns ERR_OK on success, others on failure.
1735      */
1736     int32_t RestartApp(const AAFwk::Want &want, bool isAppRecovery = false) override;
1737 
1738     /**
1739      * @brief Get host info of root caller.
1740      *
1741      * @param token The ability token.
1742      * @param hostInfo The host info of root caller.
1743      * @param userId The user id.
1744      * @return int32_t Returns ERR_OK on success, others on failure.
1745      */
1746     int32_t GetUIExtensionRootHostInfo(const sptr<IRemoteObject> token, UIExtensionHostInfo &hostInfo,
1747         int32_t userId = DEFAULT_INVAL_VALUE) override;
1748 
1749     /**
1750      * @brief Get ui extension session info
1751      *
1752      * @param token The ability token.
1753      * @param uiExtensionSessionInfo The ui extension session info.
1754      * @param userId The user id.
1755      * @return int32_t Returns ERR_OK on success, others on failure.
1756      */
1757     int32_t GetUIExtensionSessionInfo(const sptr<IRemoteObject> token, UIExtensionSessionInfo &uiExtensionSessionInfo,
1758         int32_t userId = DEFAULT_INVAL_VALUE) override;
1759 
1760     /**
1761      * Set the enable status for starting and stopping resident processes.
1762      * The caller application can only set the resident status of the configured process.
1763      * @param bundleName The bundle name of the resident process.
1764      * @param enable Set resident process enable status.
1765      * @return Returns ERR_OK on success, others on failure.
1766      */
1767     int32_t SetResidentProcessEnabled(const std::string &bundleName, bool enable) override;
1768 
1769     /**
1770      * @brief Request to display assert fault dialog.
1771      * @param callback Listen for user operation callbacks.
1772      * @param wantParams Assert dialog box display information.
1773      * @return Returns ERR_OK on success, others on failure.
1774      */
1775     virtual int32_t RequestAssertFaultDialog(
1776         const sptr<IRemoteObject> &callback, const AAFwk::WantParams &wantParams) override;
1777 
1778     /**
1779      * @brief Notify the operation status of the user.
1780      * @param assertFaultSessionId Indicates the request ID of AssertFault.
1781      * @param userStatus Operation status of the user.
1782      * @return Returns ERR_OK on success, others on failure.
1783      */
1784     virtual int32_t NotifyDebugAssertResult(uint64_t assertFaultSessionId, AAFwk::UserStatus userStatus) override;
1785 
1786     /**
1787      * Starts a new ability with specific start options.
1788      *
1789      * @param want, the want of the ability to start.
1790      * @param startOptions Indicates the options used to start.
1791      * @return Returns ERR_OK on success, others on failure.
1792      */
1793     virtual int32_t StartShortcut(const Want &want, const StartOptions &startOptions) override;
1794 
1795     /**
1796      * Get ability state by persistent id.
1797      *
1798      * @param persistentId, the persistentId of the session.
1799      * @param state Indicates the ability state.
1800      * @return Returns ERR_OK on success, others on failure.
1801      */
1802     virtual int32_t GetAbilityStateByPersistentId(int32_t persistentId, bool &state) override;
1803 
1804     /**
1805      * Transfer resultCode & want to ability manager service.
1806      *
1807      * @param callerToken Caller ability token.
1808      * @param requestCode The resultCode of the ability to start.
1809      * @param want Indicates the ability to start.
1810      * @return Returns ERR_OK on success, others on failure.
1811      */
1812     virtual int32_t TransferAbilityResultForExtension(const sptr<IRemoteObject> &callerToken, int32_t resultCode,
1813         const Want &want) override;
1814 
1815     std::shared_ptr<MissionListManagerInterface> GetMissionListManagerByUserId(int32_t userId);
1816     std::shared_ptr<MissionListWrap> GetMissionListWrap();
1817 
1818     /**
1819      * Notify ability manager service frozen process.
1820      *
1821      * @param pidList, the pid list of the frozen process.
1822      * @param uid, the uid of the frozen process.
1823      */
1824     virtual void NotifyFrozenProcessByRSS(const std::vector<int32_t> &pidList, int32_t uid) override;
1825 
1826     /**
1827      * Open atomic service window prior to finishing free install.
1828      *
1829      * @param bundleName, the bundle name of the atomic service.
1830      * @param moduleName, the module name of the atomic service.
1831      * @param abilityName, the ability name of the atomic service.
1832      * @param startTime, the starting time of the free install task.
1833      * @return Returns ERR_OK on success, others on failure.
1834      */
1835     virtual int32_t PreStartMission(const std::string& bundleName, const std::string& moduleName,
1836         const std::string& abilityName, const std::string& startTime) override;
1837 
1838     int32_t StartUIAbilityByPreInstall(const FreeInstallInfo &taskInfo);
1839 
1840     void NotifySCBToHandleAtomicServiceException(const std::string& sessionId, int errCode,
1841         const std::string& reason);
1842 
1843     void HandleRestartResidentProcessDependedOnWeb();
1844 
1845     int32_t TerminateMission(int32_t missionId) override;
1846 
1847     int32_t UpdateAssociateConfigList(const std::map<std::string, std::list<std::string>>& configs,
1848         const std::list<std::string>& exportConfigs, int32_t flag) override;
1849 
1850     int32_t BlockAllAppStart(bool flag) override;
1851 
1852     int SetWantForSessionInfo(sptr<SessionInfo> sessionInfo);
1853 
1854     int32_t StartUIAbilityBySCBDefaultCommon(AbilityRequest &abilityRequest, sptr<SessionInfo> sessionInfo,
1855         uint32_t sceneFlag, bool &isColdStart);
1856 
1857     int32_t NotifySCBToRecoveryAfterInterception(const AbilityRequest &abilityRequest);
1858 
1859     /**
1860      * Judge if Caller-Application is in background state.
1861      *
1862      * @param abilityRequest, abilityRequest.
1863      * @param isBackgroundCall, Indicates the Caller-Application state.
1864      *                          TRUE: The Caller-Application is not in focus and not in foreground state.
1865      *                          FALSE: The Caller-Application is in focus or in foreground state.
1866      * @return Returns ERR_OK on check success, others on check failure.
1867      */
1868     int IsCallFromBackground(const AbilityRequest &abilityRequest, bool &isBackgroundCall, bool isData = false);
1869 
1870     void EnableListForSCBRecovery(int32_t userId) const;
1871 
1872     int32_t UpdateKeepAliveEnableState(const std::string &bundleName, const std::string &moduleName,
1873         const std::string &mainElement, bool updateEnable, int32_t userId);
1874 
1875     bool IsInStatusBar(uint32_t accessTokenId, int32_t uid, bool isMultiInstance);
1876 
1877     bool IsSupportStatusBar(int32_t uid);
1878 
1879     /**
1880      * Set keep-alive flag for application under a specific user.
1881      * @param bundleName Bundle name.
1882      * @param userId User Id.
1883      * @param flag Keep-alive flag.
1884      * @return Returns ERR_OK on success, others on failure.
1885      */
1886     virtual int32_t SetApplicationKeepAlive(const std::string &bundleName, int32_t userId, bool flag) override;
1887 
1888     /**
1889      * Get keep-alive applications by EDM.
1890      * @param appType Application type.
1891      * @param userId User Id.
1892      * @param list List of Keep-alive information.
1893      * @return Returns ERR_OK on success, others on failure.
1894      */
1895     virtual int32_t QueryKeepAliveApplications(int32_t appType, int32_t userId,
1896         std::vector<KeepAliveInfo> &list) override;
1897 
1898     /**
1899      * Set keep-alive flag for application under a specific user by EDM.
1900      * @param bundleName Bundle name.
1901      * @param userId User Id.
1902      * @param flag Keep-alive flag.
1903      * @return Returns ERR_OK on success, others on failure.
1904      */
1905     virtual int32_t SetApplicationKeepAliveByEDM(const std::string &bundleName, int32_t userId, bool flag) override;
1906 
1907     /**
1908      * Get keep-alive applications by EDM.
1909      * @param appType Application type.
1910      * @param userId User Id.
1911      * @param list List of Keep-alive information.
1912      * @return Returns ERR_OK on success, others on failure.
1913      */
1914     virtual int32_t QueryKeepAliveApplicationsByEDM(int32_t appType, int32_t userId,
1915         std::vector<KeepAliveInfo> &list) override;
1916 
1917     /**
1918      * Add query ERMS observer.
1919      *
1920      * @param callerToken, The caller ability token.
1921      * @param observer, The observer of the ability to query ERMS.
1922      * @return Returns ERR_OK on success, others on failure.
1923      */
1924     virtual int32_t AddQueryERMSObserver(sptr<IRemoteObject> callerToken,
1925         sptr<AbilityRuntime::IQueryERMSObserver> observer) override;
1926 
1927     /**
1928      * Query atomic service ERMS rule.
1929      *
1930      * @param callerToken, The caller ability token.
1931      * @param appId, The appId of the atomic service.
1932      * @param startTime, The startTime of the query.
1933      * @param rule, The returned ERMS rule.
1934      * @return Returns ERR_OK on success, others on failure.
1935      */
1936     virtual int32_t QueryAtomicServiceStartupRule(sptr<IRemoteObject> callerToken,
1937         const std::string &appId, const std::string &startTime, AtomicServiceStartupRule &rule) override;
1938 
1939     int StartUIAbilityForOptionWrap(const Want &want, const StartOptions &options, sptr<IRemoteObject> callerToken,
1940         bool isPendingWantCaller, int32_t userId, int requestCode, uint32_t callerTokenId = 0, bool isImplicit = false,
1941         bool isCallByShortcut = false);
1942 
1943     /**
1944      * PrepareTerminateAbilityDone, called when PrepareTerminateAbility call is done.
1945      *
1946      * @param token, the token of the ability to terminate.
1947      * @param callback callback.
1948      */
1949     virtual void PrepareTerminateAbilityDone(const sptr<IRemoteObject> &token, bool isTerminate) override;
1950 
1951     /**
1952      * KillProcessForPermissionUpdate, call KillProcessForPermissionUpdate() through proxy object,
1953      * force kill the application by accessTokenId, notify exception to SCB.
1954      *
1955      * @param  accessTokenId, accessTokenId.
1956      * @return ERR_OK, return back success, others fail.
1957      */
1958     virtual int32_t KillProcessForPermissionUpdate(uint32_t accessTokenId) override;
1959 
1960     /**
1961      * KillProcessWithPrepareTerminateDone, called when KillProcessWithPrepareTerminate call is done.
1962      *
1963      * @param moduleName, the module name of the application.
1964      * @param prepareTermination, the result of prepareTermination call of the module.
1965      * @param isExist, whether the prepareTerminate functions are implemented.
1966      */
1967     virtual void KillProcessWithPrepareTerminateDone(const std::string &moduleName,
1968         int32_t prepareTermination, bool isExist) override;
GetAppExitReasonHelper()1969     std::shared_ptr<AppExitReasonHelper> GetAppExitReasonHelper()
1970     {
1971         return appExitReasonHelper_;
1972     }
1973 
1974     /**
1975      * Register hidden start observer.
1976      * @param observer, ability token.
1977      * @return Returns ERR_OK on success, others on failure.
1978      */
1979     virtual int32_t RegisterHiddenStartObserver(const sptr<IHiddenStartObserver> &observer) override;
1980 
1981     /**
1982      * Unregister hidden start observer.
1983      * @param observer, ability token.
1984      * @return Returns ERR_OK on success, others on failure.
1985      */
1986     virtual int32_t UnregisterHiddenStartObserver(const sptr<IHiddenStartObserver> &observer) override;
1987 
1988     /**
1989      * Query preload uiextension record.
1990      *
1991      * @param element, The uiextension ElementName.
1992      * @param moduleName, The uiextension moduleName.
1993      * @param hostBundleName, The uiextension caller hostBundleName.
1994      * @param recordNum, The returned count of uiextension.
1995      * @param userId, The User Id.
1996      * @return Returns ERR_OK on success, others on failure.
1997      */
1998     virtual int32_t QueryPreLoadUIExtensionRecord(const AppExecFwk::ElementName &element,
1999                                                   const std::string &moduleName,
2000                                                   const std::string &hostBundleName,
2001                                                   int32_t &recordNum,
2002                                                   int32_t userId = DEFAULT_INVAL_VALUE) override;
2003 
2004     // MSG 0 - 20 represents timeout message
2005     static constexpr uint32_t LOAD_TIMEOUT_MSG = 0;
2006     static constexpr uint32_t ACTIVE_TIMEOUT_MSG = 1;
2007     static constexpr uint32_t INACTIVE_TIMEOUT_MSG = 2;
2008     static constexpr uint32_t TERMINATE_TIMEOUT_MSG = 4;
2009     static constexpr uint32_t FOREGROUND_TIMEOUT_MSG = 5;
2010     static constexpr uint32_t BACKGROUND_TIMEOUT_MSG = 6;
2011     static constexpr uint32_t SHAREDATA_TIMEOUT_MSG = 7;
2012     static constexpr uint32_t LOAD_HALF_TIMEOUT_MSG = 8;
2013     static constexpr uint32_t FOREGROUND_HALF_TIMEOUT_MSG = 9;
2014 
2015     static constexpr uint32_t MIN_DUMP_ARGUMENT_NUM = 2;
2016     static constexpr uint32_t MAX_WAIT_SYSTEM_UI_NUM = 600;
2017     static constexpr uint32_t MAX_WAIT_SETTINGS_DATA_NUM = 300;
2018 
2019     enum {
2020         ABILITY_MOVE_TO_FOREGROUND_CODE = 0,
2021         ABILITY_MOVE_TO_BACKGROUND_CODE,
2022         TERMINATE_ABILITY_CODE
2023     };
2024 
2025     friend class UserController;
2026 
2027 protected:
2028     void OnAbilityRequestDone(const sptr<IRemoteObject> &token, const int32_t state) override;
2029     int GetUidByBundleName(std::string bundleName);
2030 
2031     void OnAppStateChanged(const AppInfo &info) override;
2032 
2033     void NotifyConfigurationChange(const AppExecFwk::Configuration &config, int32_t userId) override;
2034 
2035     void NotifyStartResidentProcess(std::vector<AppExecFwk::BundleInfo> &bundleInfos) override;
2036 
2037     void NotifyStartKeepAliveProcess(std::vector<AppExecFwk::BundleInfo> &bundleInfos) override;
2038 
2039     /**
2040      * @brief Notify abilityms app process pre cache
2041      * @param pid process pid.
2042      * @param userId userId Designation User ID.
2043      */
2044     void NotifyAppPreCache(int32_t pid, int32_t userId) override;
2045 
2046     /**
2047      * @brief Notify abilityms app process OnRemoteDied
2048      * @param abilityTokens abilities in died process.
2049      */
2050     void OnAppRemoteDied(const std::vector<sptr<IRemoteObject>> &abilityTokens) override;
2051 
2052     void OnStartProcessFailed(sptr<IRemoteObject> token) override;
2053 
2054     void OnCacheExitInfo(uint32_t accessTokenId, const AAFwk::LastExitDetailInfo &exitInfo,
2055         const std::string &bundleName, const std::vector<std::string> &abilityNames,
2056         const std::vector<std::string> &uiExtensionNames) override;
2057 
2058 private:
2059     int TerminateAbilityWithFlag(const sptr<IRemoteObject> &token, int resultCode = DEFAULT_INVAL_VALUE,
2060         const Want *resultWant = nullptr, bool flag = true);
2061     /**
2062      * initialization of ability manager service.
2063      *
2064      */
2065     bool Init();
2066     /**
2067      * initialization of u0 user.
2068      *
2069      */
2070     void InitU0User();
2071     void InitStartAbilityChain();
2072     /**
2073      * start highest priority ability.
2074      *
2075      */
2076     int StartHighestPriorityAbility(int32_t userId, bool isBoot, bool isAppRecovery = false);
2077     /**
2078      * connect bms.
2079      *
2080      */
2081     void ConnectServices();
2082 
2083     /**
2084      * Determine whether it is a system APP
2085      *
2086      */
2087     bool IsSystemUiApp(const AppExecFwk::AbilityInfo &info) const;
2088     /**
2089      * Init parameters from the global
2090      *
2091      */
2092     void InitGlobalConfiguration();
2093 
2094     int StartRemoteAbility(const Want &want, int requestCode, int32_t validUserId,
2095         const sptr<IRemoteObject> &callerToken);
2096     int StartUIAbilityBySCBDefault(sptr<SessionInfo> sessionInfo, uint32_t sceneFlag, bool &isColdStart);
2097     int StartUIAbilityByPreInstallInner(sptr<SessionInfo> sessionInfo, uint32_t specifyTokenId,
2098         uint32_t sceneFlag, bool &isColdStart);
2099     int32_t PreStartInner(const FreeInstallInfo& taskInfo);
2100     void RemovePreStartSession(const std::string& sessionId);
2101 
2102     int32_t ConnectLocalAbility(
2103         const Want &want,
2104         const int32_t userId,
2105         const sptr<IAbilityConnection> &connect,
2106         const sptr<IRemoteObject> &callerToken,
2107         AppExecFwk::ExtensionAbilityType extensionType,
2108         const sptr<SessionInfo> &sessionInfo = nullptr,
2109         bool isQueryExtensionOnly = false,
2110         sptr<UIExtensionAbilityConnectInfo> connectInfo = nullptr);
2111     int DisconnectLocalAbility(const sptr<IAbilityConnection> &connect);
2112     int ConnectRemoteAbility(Want &want, const sptr<IRemoteObject> &callerToken, const sptr<IRemoteObject> &connect);
2113     int DisconnectRemoteAbility(const sptr<IRemoteObject> &connect);
2114     int PreLoadAppDataAbilities(const std::string &bundleName, const int32_t userId);
2115     void PreLoadAppDataAbilitiesTask(const std::string &bundleName, const int32_t userId);
2116     int StartAbilityPublicPrechainCheck(StartAbilityParams &params);
2117     int StartAbilityPrechainInterceptor(StartAbilityParams &params);
2118     bool StartAbilityInChain(StartAbilityParams &params, int &result);
2119     void InitWindowVisibilityChangedListener();
2120     void FreeWindowVisibilityChangedListener();
2121     bool CheckProcessIsBackground(int32_t pid, AbilityState currentState);
2122 
2123     bool CheckIfOperateRemote(const Want &want);
2124     std::string AnonymizeDeviceId(const std::string& deviceId);
2125     bool VerificationToken(const sptr<IRemoteObject> &token);
2126     void RequestPermission(const Want *resultWant);
2127 
2128     bool CheckIsRemote(const std::string& deviceId);
2129     int GetRemoteMissionInfos(const std::string& deviceId, int32_t numMax,
2130         std::vector<MissionInfo> &missionInfos);
2131     int GetRemoteMissionInfo(const std::string& deviceId, int32_t missionId,
2132         MissionInfo &missionInfo);
2133     int32_t GetRemoteMissionSnapshotInfo(const std::string& deviceId, int32_t missionId,
2134         MissionSnapshot& missionSnapshot);
2135     int StartRemoteAbilityByCall(const Want &want, const sptr<IRemoteObject> &callerToken,
2136         const sptr<IRemoteObject> &connect);
2137     int ReleaseRemoteAbility(const sptr<IRemoteObject> &connect, const AppExecFwk::ElementName &element);
2138     void ForceTerminateServiceExtensionByPid(int32_t pid, int32_t userId);
2139 
2140     void DumpInner(const std::string &args, std::vector<std::string> &info);
2141     void DumpMissionInner(const std::string &args, std::vector<std::string> &info);
2142     void DumpStateInner(const std::string &args, std::vector<std::string> &info);
2143     void DataDumpStateInner(const std::string &args, std::vector<std::string> &info);
2144     void DumpMissionListInner(const std::string &args, std::vector<std::string> &info);
2145     void DumpMissionInfosInner(const std::string &args, std::vector<std::string> &info);
2146 
2147     bool JudgeMultiUserConcurrency(const int32_t userId);
2148     bool CheckCrossUser(const int32_t userId, AppExecFwk::ExtensionAbilityType extensionType);
2149     /**
2150      * dumpsys info
2151      *
2152      */
2153     void DumpSysInner(
2154         const std::string &args, std::vector<std::string> &info, bool isClient, bool isUserID, int userId);
2155     void DumpSysMissionListInner(
2156         const std::string &args, std::vector<std::string> &info, bool isClient, bool isUserID, int userId);
2157     void DumpSysMissionListInnerBySCB(
2158         const std::string &args, std::vector<std::string> &info, bool isClient, bool isUserID, int userId);
2159     void DumpSysAbilityInner(
2160         const std::string &args, std::vector<std::string> &info, bool isClient, bool isUserID, int userId);
2161     void DumpSysAbilityInnerBySCB(
2162         const std::string &args, std::vector<std::string> &info, bool isClient, bool isUserID, int userId);
2163     void DumpSysStateInner(
2164         const std::string &args, std::vector<std::string> &info, bool isClient, bool isUserID, int userId);
2165     void DumpSysPendingInner(
2166         const std::string &args, std::vector<std::string> &info, bool isClient, bool isUserID, int userId);
2167     void DumpSysProcess(
2168         const std::string &args, std::vector<std::string> &info, bool isClient, bool isUserID, int userId);
2169     void DumpUIExtensionRootHostRunningInfos(pid_t pid, std::vector<std::string> &info);
2170     void DumpUIExtensionProviderRunningInfos(pid_t pid, std::vector<std::string> &info);
2171     void DataDumpSysStateInner(
2172         const std::string &args, std::vector<std::string> &info, bool isClient, bool isUserID, int userId);
2173     ErrCode ProcessMultiParam(std::vector<std::string>& argsStr, std::string& result);
2174     void ShowHelp(std::string& result);
2175     void ShowIllegalInfomation(std::string& result);
2176     int Dump(const std::vector<std::u16string>& args, std::string& result);
2177 
2178     // multi user
2179     void StartFreezingScreen();
2180     void StopFreezingScreen();
2181     void UserStarted(int32_t userId);
2182     int SwitchToUser(int32_t oldUserId, int32_t userId, sptr<IUserCallback> callback,
2183         bool isAppRecovery = false);
2184     void SwitchManagers(int32_t userId, bool switchUser = true);
2185     void StartUserApps();
2186     void PauseOldUser(int32_t userId);
2187     void PauseOldMissionListManager(int32_t userId);
2188     void PauseOldConnectManager(int32_t userId);
2189     bool IsSystemUI(const std::string &bundleName) const;
2190 
2191     bool VerificationAllToken(const sptr<IRemoteObject> &token);
2192     std::shared_ptr<DataAbilityManager> GetCurrentDataAbilityManager();
2193     std::shared_ptr<DataAbilityManager> GetDataAbilityManager(const sptr<IAbilityScheduler> &scheduler);
2194     std::shared_ptr<DataAbilityManager> GetDataAbilityManagerByUserId(int32_t userId);
2195     std::shared_ptr<DataAbilityManager> GetDataAbilityManagerByToken(const sptr<IRemoteObject> &token);
2196     std::unordered_map<int, std::shared_ptr<AbilityConnectManager>> GetConnectManagers();
2197     std::shared_ptr<AbilityConnectManager> GetCurrentConnectManager();
2198     std::shared_ptr<AbilityConnectManager> GetConnectManagerByUserId(int32_t userId);
2199     std::shared_ptr<AbilityConnectManager> GetConnectManagerByToken(const sptr<IRemoteObject> &token);
2200     std::shared_ptr<AbilityConnectManager> GetConnectManagerByAbilityRecordId(const int64_t &abilityRecordId);
2201     std::shared_ptr<PendingWantManager> GetCurrentPendingWantManager();
2202     std::shared_ptr<PendingWantManager> GetPendingWantManagerByUserId(int32_t userId);
2203     std::unordered_map<int, std::shared_ptr<MissionListManagerInterface>> GetMissionListManagers();
2204     std::shared_ptr<MissionListManagerInterface> GetCurrentMissionListManager();
2205     std::unordered_map<int, std::shared_ptr<UIAbilityLifecycleManager>> GetUIAbilityManagers();
2206     std::shared_ptr<UIAbilityLifecycleManager> GetCurrentUIAbilityManager();
2207     std::shared_ptr<UIAbilityLifecycleManager> GetUIAbilityManagerByUserId(int32_t userId) const;
2208     std::shared_ptr<UIAbilityLifecycleManager> GetUIAbilityManagerByUid(int32_t uid);
2209     bool JudgeSelfCalled(const std::shared_ptr<AbilityRecord> &abilityRecord);
2210     bool IsAppSelfCalled(const std::shared_ptr<AbilityRecord> &abilityRecord);
2211 
2212     int32_t GetValidUserId(const int32_t userId);
2213 
2214     int DelegatorMoveMissionToFront(int32_t missionId);
2215 
2216     bool IsNeedTimeoutForTest(const std::string &abilityName, const std::string &state) const;
2217 
2218     void StartResidentApps(int32_t userId);
2219 
2220     void StartKeepAliveApps(int32_t userId);
2221 
2222     void StartAutoStartupApps();
2223     void StartAutoStartupApps(std::queue<AutoStartupInfo> infoList);
2224     void SubscribeScreenUnlockedEvent();
2225     std::function<void()> GetScreenUnlockCallback();
2226     std::function<void()> GetUserScreenUnlockCallback();
2227     void UnSubscribeScreenUnlockedEvent();
2228     void RetrySubscribeScreenUnlockedEvent(int32_t retryCount);
2229     void RemoveScreenUnlockInterceptor();
2230     void RemoveUnauthorizedLaunchReasonMessage(const Want &want, AbilityRequest &abilityRequest,
2231         const sptr<IRemoteObject> &callerToken);
2232 
2233     int VerifyAccountPermission(int32_t userId);
2234 
2235     int CheckStaticCfgPermissionForAbility(const AppExecFwk::AbilityInfo &abilityInfo, uint32_t tokenId);
2236 
2237     int CheckStaticCfgPermissionForSkill(const AppExecFwk::AbilityRequest &abilityRequest, uint32_t tokenId);
2238 
2239     bool CheckOneSkillPermission(const AppExecFwk::Skill &skill, uint32_t tokenId);
2240 
2241     int CheckStaticCfgPermission(const AppExecFwk::AbilityRequest &abilityRequest, bool isStartAsCaller,
2242         uint32_t callerTokenId, bool isData = false, bool isSaCall = false, bool isImplicit = false);
2243 
2244     int CheckPermissionForUIService(AppExecFwk::ExtensionAbilityType extensionType,
2245         const Want &want, const AbilityRequest &abilityRequest);
2246 
2247     bool GetValidDataAbilityUri(const std::string &abilityInfoUri, std::string &adjustUri);
2248 
2249     int GenerateExtensionAbilityRequest(const Want &want, AbilityRequest &request,
2250         const sptr<IRemoteObject> &callerToken, int32_t userId);
2251     int32_t InitialAbilityRequest(AbilityRequest &request, const StartAbilityInfo &abilityInfo) const;
2252     int CheckOptExtensionAbility(const Want &want, AbilityRequest &abilityRequest,
2253         int32_t validUserId, AppExecFwk::ExtensionAbilityType extensionType, bool isImplicit = false,
2254         bool isStartAsCaller = false);
2255 
2256     void SubscribeBackgroundTask();
2257 
2258     void UnSubscribeBackgroundTask();
2259 
2260     void SubscribeBundleEventCallback();
2261 
2262     void UnsubscribeBundleEventCallback();
2263 
2264     void ReportAbilityStartInfoToRSS(const AppExecFwk::AbilityInfo &abilityInfo);
2265 
2266     void ReportAbilityAssociatedStartInfoToRSS(const AppExecFwk::AbilityInfo &abilityInfo, int64_t type,
2267         const sptr<IRemoteObject> &callerToken);
2268 
2269     void ReportEventToRSS(const AppExecFwk::AbilityInfo &abilityInfo, sptr<IRemoteObject> callerToken);
2270 
2271     void ReportAppConnectOtherExtensionEvent(const AppExecFwk::AbilityInfo &abilityInfo, const Want &want);
2272 
2273     void ReportAppRecoverResult(const int32_t appId, const AppExecFwk::ApplicationInfo &appInfo,
2274         const std::string& abilityName, const std::string& result);
2275 
2276     void AppRecoverKill(pid_t pid, int32_t reason);
2277 
2278     int32_t GenerateEmbeddableUIAbilityRequest(const Want &want, AbilityRequest &request,
2279         const sptr<IRemoteObject> &callerToken, int32_t userId);
2280 
2281     bool GenerateDataAbilityRequestByUri(const std::string& dataAbilityUri,
2282         AbilityRequest &abilityRequest, sptr<IRemoteObject> callerToken, int32_t userId);
2283 
2284     /**
2285      * Check if Caller is allowed to start ServiceAbility(FA) or ServiceExtension(Stage) or DataShareExtension(Stage).
2286      *
2287      * @param abilityRequest, abilityRequest.
2288      * @return Returns whether the caller is allowed to start Service.
2289      */
2290     int CheckCallServicePermission(const AbilityRequest &abilityRequest);
2291 
2292     /**
2293      * Check if Caller is allowed to start DataAbility(FA)
2294      *
2295      * @param abilityRequest, abilityRequest.
2296      * @return Returns whether the caller is allowed to start DataAbility.
2297      */
2298     int CheckCallDataAbilityPermission(AbilityRequest &abilityRequest, bool isShell, bool IsSACall = false);
2299 
2300     /**
2301      * Check if Caller is allowed to start ServiceExtension(Stage) or DataShareExtension(Stage).
2302      *
2303      * @param abilityRequest, abilityRequest.
2304      * @return Returns whether the caller is allowed to start ServiceExtension.
2305      */
2306     int CheckCallServiceExtensionPermission(const AbilityRequest &abilityRequest);
2307 
2308 #ifdef SUPPORT_AUTO_FILL
2309     /**
2310      * Check if Caller is allowed to start AutoFillExtension.
2311      *
2312      * @param abilityRequest, abilityRequest.
2313      * @return Returns whether the caller is allowed to start ServiceExtension.
2314      */
2315     int CheckCallAutoFillExtensionPermission(const AbilityRequest &abilityRequest);
2316 #endif // SUPPORT_AUTO_FILL
2317     /**
2318      * Check if Caller is allowed to start other Extension(Stage).
2319      *
2320      * @param abilityRequest, abilityRequest.
2321      * @return Returns whether the caller is allowed to start OtherExtension.
2322      */
2323     int CheckCallOtherExtensionPermission(const AbilityRequest &abilityRequest);
2324 
2325     /**
2326      * Check if Caller is allowed to start ServiceAbility(FA).
2327      *
2328      * @param abilityRequest, abilityRequest.
2329      * @return Returns whether the caller is allowed to start ServiceAbility.
2330      */
2331     int CheckCallServiceAbilityPermission(const AbilityRequest &abilityRequest);
2332 
2333     /**
2334      * Check if Caller is allowed to start PageAbility(FA) or Ability(Stage).
2335      *
2336      * @param abilityRequest, abilityRequest.
2337      * @return Returns whether the caller is allowed to start Ability.
2338      */
2339     int CheckCallAbilityPermission(const AbilityRequest &abilityRequest, uint32_t specifyTokenId = 0,
2340         bool isCallByShortcut = false);
2341 
2342     /**
2343      * Check if Caller is allowed to start Ability(Stage) by call.
2344      *
2345      * @param abilityRequest, abilityRequest.
2346      * @return Returns whether the caller is allowed to start Ability by call.
2347      */
2348     int CheckStartByCallPermission(const AbilityRequest &abilityRequest);
2349 
2350     /**
2351      * @brief Check some specified uiextension type should be a system app.
2352      * Consider expanding it to table-driven in the future.
2353      *
2354      * @param abilityRequest The ability request.
2355      * @return Returns ERR_OK when allowed, others when check failed.
2356      */
2357     int CheckUIExtensionPermission(const AbilityRequest &abilityRequest);
2358 
2359     /**
2360      * @brief Check CallerInfoQueryExtension permission
2361      *
2362      * @param abilityRequest The ability request.
2363      * @return Returns ERR_OK when allowed, others when check failed.
2364      */
2365     int CheckCallerInfoQueryExtensionPermission(const AbilityRequest &abilityRequest);
2366 
2367     int CheckFileAccessExtensionPermission(const AbilityRequest &abilityRequest);
2368 
2369     bool IsTargetPermission(const Want &want) const;
2370 
2371     bool IsDelegatorCall(const AppExecFwk::RunningProcessInfo &processInfo, const AbilityRequest &abilityRequest) const;
2372 
2373     bool CheckNewRuleSwitchState(const std::string &param);
2374 
2375     void UpdateFocusState(std::vector<AbilityRunningInfo> &info);
2376 
2377     AAFwk::PermissionVerification::VerificationInfo CreateVerificationInfo(
2378         const AbilityRequest &abilityRequest, bool isData = false, bool isShell = false, bool isSA = false);
2379 
2380     int AddStartControlParam(Want &want, const sptr<IRemoteObject> &callerToken);
2381 
2382     AAFwk::EventInfo BuildEventInfo(const Want &want, int32_t userId);
2383 
2384 #ifdef WITH_DLP
2385     int CheckDlpForExtension(
2386         const Want &want, const sptr<IRemoteObject> &callerToken,
2387         int32_t userId, AAFwk::EventInfo &eventInfo, const EventName &eventName);
2388 #endif // WITH_DLP
2389 
2390     void InitStartupFlag();
2391 
IsCrossUserCall(int32_t userId)2392     inline bool IsCrossUserCall(int32_t userId)
2393     {
2394         return (userId != INVALID_USER_ID && userId != U0_USER_ID && userId != GetUserId());
2395     }
2396 
2397     int32_t RequestDialogServiceInner(const Want &want, const sptr<IRemoteObject> &callerToken,
2398         int requestCode, int32_t userId);
2399 
2400     bool CheckCallingTokenId(const std::string &bundleName, int32_t userId = INVALID_USER_ID, int32_t appIndex = 0);
2401     bool IsCallerSceneBoard();
2402 
2403     void ReleaseAbilityTokenMap(const sptr<IRemoteObject> &token);
2404 
2405     bool CheckCollaboratorType(int32_t type);
2406 
2407     bool CheckUserIdActive(int32_t userId);
2408 
2409     int32_t CheckProcessOptions(const Want &want, const StartOptions &startOptions, int32_t userId);
2410 
2411     int32_t CheckStartSelfUIAbilityStartOptions(const Want &want, const StartOptions &startOptions);
2412 
2413     void GetConnectManagerAndUIExtensionBySessionInfo(const sptr<SessionInfo> &sessionInfo,
2414         std::shared_ptr<AbilityConnectManager> &connectManager, std::shared_ptr<AbilityRecord> &targetAbility,
2415         bool needCheck = false);
2416 
2417     virtual int RegisterSessionHandler(const sptr<IRemoteObject> &object) override;
2418 
2419     /**
2420      * Start switch user dialog Extension ability.
2421      */
2422     void StartSwitchUserDialog();
2423 
2424     /**
2425      * Start switch user dialog inner.
2426      * @param want, The want of the dialog box to start.
2427      * @param startUserId, The userId who wants to start the dialog box.
2428      */
2429     void StartSwitchUserDialogInner(const Want &want, int32_t startUserId);
2430 
2431     /**
2432      * Stop switch user dialog Extension ability.
2433      */
2434     void StopSwitchUserDialog();
2435 
2436     /**
2437      * Stop switch user dialog inner.
2438      * @param want, The want of the dialog box to stop.
2439      * @param stopUserId, The userId who wants to stop the dialog box.
2440      */
2441     void StopSwitchUserDialogInner(const Want &want, const int32_t stopUserId);
2442 
2443     void SetPickerElementName(const sptr<SessionInfo> &extensionSessionInfo, int32_t userId);
2444 
2445     void SetAutoFillElementName(const sptr<SessionInfo> &extensionSessionInfo);
2446 
2447     /**
2448      * @brief Start extension ability with insight intent
2449      * @param want, the want of the ability to start.
2450      * @param extensionType If an ExtensionAbilityType is set, only extension of that type can be started.
2451      * @return Returns ERR_OK on success, others on failure.
2452      */
2453     int32_t StartExtensionAbilityWithInsightIntent(const Want &want,
2454         AppExecFwk::ExtensionAbilityType extensionType = AppExecFwk::ExtensionAbilityType::UNSPECIFIED);
2455 
2456     bool IsAbilityStarted(AbilityRequest &abilityRequest, std::shared_ptr<AbilityRecord> &targetRecord,
2457         const int32_t oriValidUserId);
2458 
2459     void InitInterceptor();
2460     void InitInterceptorForScreenUnlock();
2461     void InitPushTask();
2462     void InitDeepLinkReserve();
2463 
2464     bool CheckSenderWantInfo(int32_t callerUid, const WantSenderInfo &wantSenderInfo);
2465 
2466     int32_t UninstallAppInner(const std::string &bundleName, const int32_t uid, int32_t appIndex, const bool isUpgrade,
2467         const std::string &exitMsg);
2468 
2469     int32_t GetMissionIdByAbilityTokenInner(const sptr<IRemoteObject> &token);
2470     bool CheckCallerIsDmsProcess();
2471 
2472     void WaitBootAnimationStart();
2473 
2474     int32_t SignRestartAppFlag(int32_t userId, int32_t uid, const std::string &instanceKey,
2475         AppExecFwk::MultiAppModeType type, bool isAppRecovery = false);
2476     int32_t CheckRestartAppWant(const AAFwk::Want &want, int32_t appIndex, int32_t userId);
2477 
2478     int32_t CheckDebugAssertPermission();
2479     std::shared_ptr<AbilityDebugDeal> ConnectInitAbilityDebugDeal();
2480 
2481     int32_t SetBackgroundCall(const AppExecFwk::RunningProcessInfo &processInfo,
2482         const AbilityRequest &abilityRequest, bool &isBackgroundCall) const;
2483 
2484     int CheckUIExtensionUsage(AppExecFwk::UIExtensionUsage uiExtensionUsage,
2485         AppExecFwk::ExtensionAbilityType extensionType);
2486 
2487     bool CheckUIExtensionCallerIsForeground(const AbilityRequest &abilityRequest);
2488     bool CheckUIExtensionCallerIsUIAbility(const AbilityRequest &abilityRequest);
2489     std::shared_ptr<AbilityRecord> GetUIExtensionRootCaller(const sptr<IRemoteObject> token, int32_t userId);
2490 
2491     bool CheckUIExtensionCallerPidByHostWindowId(const AbilityRequest &abilityRequest);
2492 
2493     int CheckExtensionCallPermission(const Want& want, const AbilityRequest& abilityRequest, uint32_t specifyTokenId);
2494 
2495     int CheckServiceCallPermission(const AbilityRequest& abilityRequest,
2496         const AppExecFwk::AbilityInfo& abilityInfo);
2497 
2498     int CheckBrokerCallPermission(const AbilityRequest& abilityRequest,
2499         const AppExecFwk::AbilityInfo& abilityInfo);
2500 
2501     int CheckAbilityCallPermission(const AbilityRequest& abilityRequest,
2502         const AppExecFwk::AbilityInfo& abilityInfo, uint32_t specifyTokenId);
2503 
2504     int CheckCallPermission(const Want& want, const AppExecFwk::AbilityInfo& abilityInfo,
2505         const AbilityRequest& abilityRequest, bool isForegroundToRestartApp,
2506         bool isSendDialogResult, uint32_t specifyTokenId,
2507         const std::string& callerBundleName);
2508 
2509     int StartAbilityByConnectManager(const Want& want, const AbilityRequest& abilityRequest,
2510         const AppExecFwk::AbilityInfo& abilityInfo, int validUserId, sptr<IRemoteObject> callerToken);
2511 
2512     int PreStartFreeInstall(const Want &want, sptr<IRemoteObject> callerToken,
2513         uint32_t specifyTokenId, bool isStartAsCaller, Want &localWant);
2514 
2515     void ReportCleanSession(const sptr<SessionInfo> &sessionInfo,
2516         const std::shared_ptr<AbilityRecord> &abilityRecord, int32_t errCode);
2517 
2518     void SendStartAbilityOtherExtensionEvent(const AppExecFwk::AbilityInfo& abilityInfo,
2519         const Want& want, uint32_t specifyTokenId);
2520 
2521     void SetMinimizedDuringFreeInstall(const sptr<SessionInfo>& sessionInfo);
2522 
2523     bool CheckWorkSchedulerPermission(const sptr<IRemoteObject> &callerToken, const uint32_t uid);
2524 
2525     /**
2526      * @brief Check debug app in developer mode.
2527      * @param applicationInfo. The application info.
2528      * @return Returns true or false.
2529      */
2530     bool CheckDebugAppNotInDeveloperMode(const AppExecFwk::ApplicationInfo &applicationInfo);
2531 
2532     /**
2533      * @brief Prompt user that developer mode has not been turned on.
2534      * @param bundleName. The bundleName of the blocked hap.
2535      * @param abilityName. The abilityName of the blocked hap.
2536      */
2537     void ShowDeveloperModeDialog(const std::string &bundleName, const std::string &abilityName);
2538 
2539     void StartKeepAliveAppsInner(int32_t userId);
2540 
2541     bool ProcessLowMemoryKill(int32_t pid, const ExitReason &reason);
2542 
2543     struct StartSelfUIAbilityParam {
2544         Want want;
2545         StartOptions options;
2546         bool hasStartOptions = false;
2547     };
2548     int StartSelfUIAbilityInner(StartSelfUIAbilityParam param);
2549 
2550     bool controllerIsAStabilityTest_ = false;
2551     bool isParamStartAbilityEnable_ = false;
2552     // Component StartUp rule switch
2553     bool startUpNewRule_ = true;
2554     /** It only takes effect when startUpNewRule_ is TRUE
2555      *  TRUE: When Caller-Application is Launcher or SystemUI, use old rule.
2556      *  FALSE: Apply new rule to all application
2557      */
2558     bool newRuleExceptLauncherSystemUI_ = true;
2559     /** Indicates the criteria for judging whether the Caller-Application is in the background
2560      *  TRUE: Determine the state by AAFwk::AppState::FOREGROUND.
2561      *  FALSE: Determine the state by AppExecFwk::AppProcessState::APP_STATE_FOCUS.
2562      */
2563     bool backgroundJudgeFlag_ = true;
2564     /** The applications in white list can associatedWakeUp
2565      *  TRUE: white list enable.
2566      *  FALSE: white list unable.
2567      */
2568     bool whiteListassociatedWakeUpFlag_ = true;
2569     bool shouldBlockAllAppStart_ = false;
2570 
2571     int32_t uniqueId_ = 0;
2572     std::unordered_set<int32_t> windowVisibleList_;
2573 
2574     sptr<WindowVisibilityChangedListener> windowVisibilityChangedListener_;
2575     std::shared_ptr<TaskHandlerWrap> taskHandler_;
2576     std::shared_ptr<TaskHandlerWrap> delayClearReasonHandler_;
2577     std::shared_ptr<AbilityEventHandler> eventHandler_;
2578     ServiceRunningState state_;
2579 
2580     std::shared_ptr<FreeInstallManager> freeInstallManager_;
2581     std::shared_ptr<SubManagersHelper> subManagersHelper_;
2582     std::shared_ptr<UserController> userController_;
2583     sptr<AppExecFwk::IAbilityController> abilityController_ = nullptr;
2584 
2585     std::multimap<std::string, std::string> timeoutMap_;
2586     std::map<std::string, sptr<SessionInfo>> preStartSessionMap_;
2587 
2588     static sptr<AbilityManagerService> instance_;
2589     std::map<int32_t, std::pair<int64_t, const sptr<IAcquireShareDataCallback>>> iAcquireShareDataMap_;
2590     // first is callstub, second is ability token
2591     std::map<sptr<IRemoteObject>, sptr<IRemoteObject>> callStubTokenMap_;
2592 #ifdef SUPPORT_GRAPHICS
2593     sptr<WindowFocusChangedListener> focusListener_;
2594 #endif // SUPPORT_GRAPHICS
2595 
2596     std::shared_ptr<AbilityRuntime::AbilityManagerEventSubscriber> screenSubscriber_;
2597 
2598     std::shared_ptr<AbilityAutoStartupService> abilityAutoStartupService_;
2599 
2600     std::map<std::string, std::list<std::string>> whiteListMap_;
2601 
2602     std::list<std::string> exportWhiteList_;
2603 
2604     bool ShouldPreventStartAbility(const AbilityRequest &abilityRequest);
2605 
2606     void PrintStartAbilityInfo(AppExecFwk::AbilityInfo callerInfo, AppExecFwk::AbilityInfo calledInfo);
2607 
2608     bool IsInWhiteList(const std::string &callerBundleName, const std::string &calleeBundleName,
2609         const std::string &calleeAbilityName);
2610 
2611     std::string GetConfigFileAbsolutePath(const std::string &relativePath);
2612 
2613     int32_t ParseJsonValueFromFile(nlohmann::json &value, const std::string& fullPath);
2614 
2615     bool ConvertFullPath(const std::string& partialPath, std::string& fullPath);
2616 
2617     bool GetJsonFromFile(const char *filePath, Json::Value &root);
2618 
2619     bool ParseJsonFromBoot(const std::string &relativePath);
2620 
2621     void SetReserveInfo(const std::string &linkString, AbilityRequest& abilityRequest);
2622     void CloseAssertDialog(const std::string &assertSessionId);
2623 
2624     void ReportPreventStartAbilityResult(const AppExecFwk::AbilityInfo &callerAbilityInfo,
2625         const AppExecFwk::AbilityInfo &abilityInfo);
2626 
2627     void SetAbilityRequestSessionInfo(AbilityRequest &abilityRequest, AppExecFwk::ExtensionAbilityType extensionType);
2628 
2629     bool ShouldBlockAllAppStart();
2630 
2631     std::string InsightIntentGetcallerBundleName();
2632 
2633 #ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE
2634     std::shared_ptr<BackgroundTaskObserver> bgtaskObserver_;
2635 #endif
2636 
2637     sptr<AbilityBundleEventCallback> abilityBundleEventCallback_;
2638 
2639 #ifdef SUPPORT_SCREEN
2640     bool isAnimationEnabled_ = true; //only use on mission list
2641     bool CheckWindowMode(int32_t windowMode, const std::vector<AppExecFwk::SupportWindowMode>& windowModes) const;
2642     int32_t ShowPickerDialog(const Want& want, int32_t userId, const sptr<IRemoteObject> &token);
2643     void InitFocusListener();
2644     void RegisterFocusListener();
2645     std::shared_ptr<ImplicitStartProcessor> implicitStartProcessor_;
2646     sptr<IWindowManagerServiceHandler> wmsHandler_;
2647 #endif
2648     std::shared_ptr<AbilityInterceptorExecuter> interceptorExecuter_;
2649     std::shared_ptr<AbilityInterceptorExecuter> afterCheckExecuter_;
2650 
2651     std::unordered_map<int32_t, int64_t> appRecoveryHistory_; // uid:time
2652     std::multimap<int, std::shared_ptr<StartAbilityHandler>, std::greater<int>> startAbilityChain_;
2653     std::unordered_map<int32_t, sptr<IAbilityManagerCollaborator>> collaboratorMap_;
2654 
2655     std::shared_ptr<AbilityDebugDeal> abilityDebugDeal_;
2656     std::shared_ptr<AppExitReasonHelper> appExitReasonHelper_;
2657 
2658     ffrt::mutex globalLock_;
2659     ffrt::mutex bgtaskObserverMutex_;
2660     ffrt::mutex abilityTokenLock_;
2661     ffrt::mutex preStartSessionMapLock_;
2662     ffrt::mutex windowVisibleListLock_;
2663     ffrt::mutex iAcquireShareDataMapLock_;
2664     ffrt::mutex collaboratorMapLock_;
2665     ffrt::mutex abilityDebugDealLock_;
2666     ffrt::mutex shouldBlockAllAppStartMutex_;
2667     mutable ffrt::mutex timeoutMapLock_;
2668     std::mutex whiteListMutex_;
2669 
2670     std::mutex prepareTermiationCallbackMutex_;
2671     std::map<std::string, sptr<IPrepareTerminateCallback>> prepareTermiationCallbacks_;
2672 };
2673 }  // namespace AAFwk
2674 }  // namespace OHOS
2675 #endif  // OHOS_ABILITY_RUNTIME_ABILITY_MANAGER_SERVICE_H
2676