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