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