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