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_CLIENT_H
17 #define OHOS_ABILITY_RUNTIME_ABILITY_MANAGER_CLIENT_H
18 
19 #include <mutex>
20 
21 #include "ability_connect_callback_interface.h"
22 #include "ability_manager_errors.h"
23 #include "ability_manager_interface.h"
24 #include "ability_scheduler_interface.h"
25 #include "auto_startup_info.h"
26 #include "iremote_object.h"
27 #include "mission_info.h"
28 #include "snapshot.h"
29 #include "system_memory_attr.h"
30 #include "ui_extension_window_command.h"
31 #include "want.h"
32 
33 namespace OHOS {
34 namespace AAFwk {
35 using AutoStartupInfo = AbilityRuntime::AutoStartupInfo;
36 /**
37  * @class AbilityManagerClient
38  * AbilityManagerClient is used to access ability manager services.
39  */
40 class AbilityManagerClient {
41 public:
42     virtual ~AbilityManagerClient();
43     static std::shared_ptr<AbilityManagerClient> GetInstance();
44     void RemoveDeathRecipient();
45 
46     /**
47      * AttachAbilityThread, ability call this interface after loaded.
48      *
49      * @param scheduler,.the interface handler of kit ability.
50      * @param token,.ability's token.
51      * @return Returns ERR_OK on success, others on failure.
52      */
53     ErrCode AttachAbilityThread(sptr<IAbilityScheduler> scheduler, sptr<IRemoteObject> token);
54 
55     /**
56      * AbilityTransitionDone, ability call this interface after lift cycle was changed.
57      *
58      * @param token,.ability's token.
59      * @param state,.the state of ability lift cycle.
60      * @return Returns ERR_OK on success, others on failure.
61      */
62     ErrCode AbilityTransitionDone(sptr<IRemoteObject> token, int state, const PacMap &saveData);
63 
64     /**
65      * AbilityWindowConfigTransitionDone, ability call this interface after lift cycle was changed.
66      *
67      * @param token,.ability's token.
68      * @return Returns ERR_OK on success, others on failure.
69      */
70     ErrCode AbilityWindowConfigTransitionDone(sptr<IRemoteObject> token, const WindowConfig &windowConfig);
71 
72     /**
73      * ScheduleConnectAbilityDone, service ability call this interface while session was connected.
74      *
75      * @param token,.service ability's token.
76      * @param remoteObject,.the session proxy of service ability.
77      * @return Returns ERR_OK on success, others on failure.
78      */
79     ErrCode ScheduleConnectAbilityDone(sptr<IRemoteObject> token, sptr<IRemoteObject> remoteObject);
80 
81     /**
82      * ScheduleDisconnectAbilityDone, service ability call this interface while session was disconnected.
83      *
84      * @param token,.service ability's token.
85      * @return Returns ERR_OK on success, others on failure.
86      */
87     ErrCode ScheduleDisconnectAbilityDone(sptr<IRemoteObject> token);
88 
89     /**
90      * ScheduleCommandAbilityDone, service ability call this interface while session was commanded.
91      *
92      * @param token,.service ability's token.
93      * @return Returns ERR_OK on success, others on failure.
94      */
95     ErrCode ScheduleCommandAbilityDone(sptr<IRemoteObject> token);
96 
97     ErrCode ScheduleCommandAbilityWindowDone(
98         sptr<IRemoteObject> token,
99         sptr<SessionInfo> sessionInfo,
100         WindowCommand winCmd,
101         AbilityCommand abilityCmd);
102 
103     /**
104      * Get top ability.
105      *
106      * @param isNeedLocalDeviceId is need local device id.
107      * @return Returns front desk focus ability elementName.
108      */
109     AppExecFwk::ElementName GetTopAbility(bool isNeedLocalDeviceId = true);
110 
111     /**
112      * Get element name by token.
113      *
114      * @param token ability's token.
115      * @param isNeedLocalDeviceId is need local device id.
116      * @return Returns front desk focus ability elementName by token.
117      */
118     AppExecFwk::ElementName GetElementNameByToken(sptr<IRemoteObject> token, bool isNeedLocalDeviceId = true);
119 
120     /**
121      * StartAbility with want, send want to ability manager service.
122      *
123      * @param want Ability want.
124      * @param requestCode Ability request code.
125      * @return Returns ERR_OK on success, others on failure.
126      */
127     ErrCode StartAbility(const Want &want, int requestCode = DEFAULT_INVAL_VALUE,
128         int32_t userId = DEFAULT_INVAL_VALUE);
129 
130     /**
131      * StartAbility with want, send want to ability manager service.
132      *
133      * @param want Ability want.
134      * @param callerToken caller ability token.
135      * @param requestCode Ability request code.
136      * @return Returns ERR_OK on success, others on failure.
137      */
138     ErrCode StartAbility(
139         const Want &want,
140         sptr<IRemoteObject> callerToken,
141         int requestCode = DEFAULT_INVAL_VALUE,
142         int32_t userId = DEFAULT_INVAL_VALUE);
143 
144     /**
145      * StartAbility by insight intent, send want to ability manager service.
146      *
147      * @param want Ability want.
148      * @param callerToken caller ability token.
149      * @param intentId insight intent id.
150      * @param userId userId of target ability.
151      * @return Returns ERR_OK on success, others on failure.
152      */
153     ErrCode StartAbilityByInsightIntent(
154         const Want &want,
155         sptr<IRemoteObject> callerToken,
156         uint64_t intentId,
157         int32_t userId = DEFAULT_INVAL_VALUE);
158 
159     /**
160      * Starts a new ability with specific start settings.
161      *
162      * @param want Indicates the ability to start.
163      * @param requestCode the resultCode of the ability to start.
164      * @param abilityStartSetting Indicates the setting ability used to start.
165      * @return Returns ERR_OK on success, others on failure.
166      */
167     ErrCode StartAbility(
168         const Want &want,
169         const AbilityStartSetting &abilityStartSetting,
170         sptr<IRemoteObject> callerToken,
171         int requestCode = DEFAULT_INVAL_VALUE,
172         int32_t userId = DEFAULT_INVAL_VALUE);
173 
174     /**
175      * Starts a new ability with specific start options.
176      *
177      * @param want, the want of the ability to start.
178      * @param startOptions Indicates the options used to start.
179      * @param callerToken caller ability token.
180      * @param requestCode the resultCode of the ability to start.
181      * @return Returns ERR_OK on success, others on failure.
182      */
183     ErrCode StartAbility(
184         const Want &want,
185         const StartOptions &startOptions,
186         sptr<IRemoteObject> callerToken,
187         int requestCode = DEFAULT_INVAL_VALUE,
188         int32_t userId = DEFAULT_INVAL_VALUE);
189 
190     /**
191      * Starts a new ability using the original caller information.
192      *
193      * @param want Ability want.
194      * @param callerToken current caller ability token.
195      * @param asCallerSourceToken source caller ability token.
196      * @param requestCode Ability request code.
197      * @param userId Ability userId
198      * @return Returns ERR_OK on success, others on failure.
199      */
200     ErrCode StartAbilityAsCaller(
201             const Want &want,
202             sptr<IRemoteObject> callerToken,
203             sptr<IRemoteObject> asCallerSourceToken,
204             int requestCode = DEFAULT_INVAL_VALUE,
205             int32_t userId = DEFAULT_INVAL_VALUE);
206 
207     /**
208      * Starts a new ability using the original caller information.
209      *
210      * @param want Indicates the ability to start.
211      * @param startOptions current Indicates the options used to start.
212      * @param callerToken caller ability token.
213      * @param asCallerSourceToken source caller ability token.
214      * @param requestCode the resultCode of the ability to start.
215      * @param userId Ability userId
216      * @return Returns ERR_OK on success, others on failure.
217      */
218     ErrCode StartAbilityAsCaller(
219             const Want &want,
220             const StartOptions &startOptions,
221             sptr<IRemoteObject> callerToken,
222             sptr<IRemoteObject> asCallerSourceToken,
223             int requestCode = DEFAULT_INVAL_VALUE,
224             int32_t userId = DEFAULT_INVAL_VALUE);
225 
226     /**
227      * Starts a new ability for result using the original caller information.
228      *
229      * @param want the want of the ability to start.
230      * @param callerToken current caller ability token.
231      * @param requestCode the resultCode of the ability to start.
232      * @param userId Designation User ID.
233      * @return Returns ERR_OK on success, others on failure.
234      */
235     ErrCode StartAbilityForResultAsCaller(
236         const Want &want,
237         sptr<IRemoteObject> callerToken,
238         int requestCode = DEFAULT_INVAL_VALUE,
239         int32_t userId = DEFAULT_INVAL_VALUE);
240 
241     /**
242      * Starts a new ability for result using the original caller information.
243      *
244      * @param want the want of the ability to start.
245      * @param startOptions Indicates the options used to start.
246      * @param callerToken current caller ability token.
247      * @param requestCode the resultCode of the ability to start.
248      * @param userId Designation User ID.
249      * @return Returns ERR_OK on success, others on failure.
250      */
251     ErrCode StartAbilityForResultAsCaller(
252         const Want &want,
253         const StartOptions &startOptions,
254         sptr<IRemoteObject> callerToken,
255         int requestCode = DEFAULT_INVAL_VALUE,
256         int32_t userId = DEFAULT_INVAL_VALUE);
257 
258     /**
259      * Start ui session ability with extension session info, send session info to ability manager service.
260      *
261      * @param want Ability want.
262      * @param callerToken caller ability token.
263      * @param sessionInfo the information of UIExtensionContentSession.
264      * @param requestCode Ability request code.
265      * @return Returns ERR_OK on success, others on failure.
266      */
267     ErrCode StartAbilityByUIContentSession(
268         const Want &want,
269         sptr<IRemoteObject> callerToken,
270         sptr<AAFwk::SessionInfo> sessionInfo,
271         int requestCode = DEFAULT_INVAL_VALUE,
272         int32_t userId = DEFAULT_INVAL_VALUE);
273 
274     /**
275      * Start ui session ability with extension session info, send session info to ability manager service.
276      *
277      * @param want, the want of the ability to start.
278      * @param startOptions Indicates the options used to start.
279      * @param callerToken caller ability token.
280      * @param sessionInfo the information of UIExtensionContentSession.
281      * @param requestCode the resultCode of the ability to start.
282      * @return Returns ERR_OK on success, others on failure.
283      */
284     ErrCode StartAbilityByUIContentSession(
285         const Want &want,
286         const StartOptions &startOptions,
287         sptr<IRemoteObject> callerToken,
288         sptr<AAFwk::SessionInfo> sessionInfo,
289         int requestCode = DEFAULT_INVAL_VALUE,
290         int32_t userId = DEFAULT_INVAL_VALUE);
291 
292     /**
293      * Start ui ability
294      *
295      * @param want the want of the ability to start.
296      * @param callerToken caller ability token.
297      * @param specifyTokenId The Caller ID.
298      * @return Returns ERR_OK on success, others on failure.
299      */
300     ErrCode StartAbilityOnlyUIAbility(
301         const Want &want,
302         sptr<IRemoteObject> callerToken,
303         uint32_t specifyTokenId);
304 
305     /**
306      * Start extension ability with want, send want to ability manager service.
307      *
308      * @param want, the want of the ability to start.
309      * @param callerToken, caller ability token.
310      * @param userId, Designation User ID.
311      * @param extensionType If an ExtensionAbilityType is set, only extension of that type can be started.
312      * @return Returns ERR_OK on success, others on failure.
313      */
314     ErrCode StartExtensionAbility(
315         const Want &want,
316         sptr<IRemoteObject> callerToken,
317         int32_t userId = DEFAULT_INVAL_VALUE,
318         AppExecFwk::ExtensionAbilityType extensionType = AppExecFwk::ExtensionAbilityType::UNSPECIFIED);
319 
320     /**
321      * Create UIExtension with want, send want to ability manager service.
322      *
323      * @param want, the want of the ability to start.
324      * @return Returns ERR_OK on success, others on failure.
325      */
326     ErrCode RequestModalUIExtension(const Want &want);
327 
328     /**
329      * Preload UIExtension with want, send want to ability manager service.
330      *
331      * @param want, the want of the ability to start.
332      * @param hostBundleName, the caller application bundle name.
333      * @param userId, the extension runs in.
334      * @return Returns ERR_OK on success, others on failure.
335      */
336     ErrCode PreloadUIExtensionAbility(const Want &want, std::string &hostBundleName,
337         int32_t userId = DEFAULT_INVAL_VALUE);
338 
339     ErrCode ChangeAbilityVisibility(sptr<IRemoteObject> token, bool isShow);
340 
341     ErrCode ChangeUIAbilityVisibilityBySCB(sptr<SessionInfo> sessionInfo, bool isShow);
342 
343     /**
344      * Start ui extension ability with extension session info, send extension session info to ability manager service.
345      *
346      * @param extensionSessionInfo the extension session info of the ability to start.
347      * @param userId, Designation User ID.
348      * @return Returns ERR_OK on success, others on failure.
349      */
350     ErrCode StartUIExtensionAbility(
351         sptr<SessionInfo> extensionSessionInfo,
352         int32_t userId = DEFAULT_INVAL_VALUE);
353 
354     /**
355      * Start ui ability with want, send want to ability manager service.
356      *
357      * @param sessionInfo the session info of the ability to start.
358      * @param isColdStart the session info of the ability is or not cold start.
359      * @return Returns ERR_OK on success, others on failure.
360      */
361     ErrCode StartUIAbilityBySCB(sptr<SessionInfo> sessionInfo, bool &isColdStart, uint32_t sceneFlag = 0);
362 
363     /**
364      * Stop extension ability with want, send want to ability manager service.
365      *
366      * @param want, the want of the ability to stop.
367      * @param callerToken, caller ability token.
368      * @param userId, Designation User ID.
369      * @param extensionType If an ExtensionAbilityType is set, only extension of that type can be stopped.
370      * @return Returns ERR_OK on success, others on failure.
371      */
372     ErrCode StopExtensionAbility(
373         const Want& want,
374         sptr<IRemoteObject> callerToken,
375         int32_t userId = DEFAULT_INVAL_VALUE,
376         AppExecFwk::ExtensionAbilityType extensionType = AppExecFwk::ExtensionAbilityType::UNSPECIFIED);
377 
378     /**
379      * TerminateAbility with want, return want from ability manager service.
380      *
381      * @param token Ability token.
382      * @param resultCode resultCode.
383      * @param Want Ability want returned.
384      * @return Returns ERR_OK on success, others on failure.
385      */
386     ErrCode TerminateAbility(sptr<IRemoteObject> token, int resultCode, const Want *resultWant);
387 
388     /**
389      * BackToCallerAbilityWithResult, return to the caller ability.
390      *
391      * @param token, the token of the ability to terminate.
392      * @param resultCode, the resultCode of the ability to terminate.
393      * @param resultWant, the Want of the ability to return.
394      * @param callerRequestCode, the requestCode of caller ability.
395      * @return Returns ERR_OK on success, others on failure.
396      */
397     ErrCode BackToCallerAbilityWithResult(const sptr<IRemoteObject> &token, int resultCode,
398         const Want *resultWant, int64_t callerRequestCode);
399 
400     /**
401      * TerminateUIServiceExtensionAbility with token.
402      *
403      * @param token Ability token.
404      * @return Returns ERR_OK on success, others on failure.
405      */
406     ErrCode TerminateUIServiceExtensionAbility(sptr<IRemoteObject> token);
407 
408     /**
409      * TerminateUIExtensionAbility with want, return want from ability manager service.
410      *
411      * @param extensionSessionInfo the extension session info of the ability to terminate.
412      * @param resultCode resultCode.
413      * @param Want Ability want returned.
414      * @return Returns ERR_OK on success, others on failure.
415      */
416     ErrCode TerminateUIExtensionAbility(sptr<SessionInfo> extensionSessionInfo,
417         int resultCode = DEFAULT_INVAL_VALUE, const Want *resultWant = nullptr);
418 
419     /**
420      * CloseUIExtensionAbilityBySCB, terminate the specified ui extension ability by SCB.
421      *
422      * @param token the ability token.
423      * @return Returns ERR_OK on success, others on failure.
424      */
425     ErrCode CloseUIExtensionAbilityBySCB(const sptr<IRemoteObject> token);
426 
427     /**
428      *  CloseUIAbilityBySCB, close the special ability by scb.
429      *
430      * @param sessionInfo the session info of the ability to terminate.
431      * @return Returns ERR_OK on success, others on failure.
432      */
433     ErrCode CloseUIAbilityBySCB(sptr<SessionInfo> sessionInfo);
434 
435     /**
436      * SendResultToAbility with want, return resultWant from ability manager service.
437      *
438      * @param requestCode requestCode.
439      * @param resultCode resultCode.
440      * @param resultWant Ability want returned.
441      * @return Returns ERR_OK on success, others on failure.
442      */
443     ErrCode SendResultToAbility(int requestCode, int resultCode, Want& resultWant);
444 
445     /**
446      * MoveAbilityToBackground.
447      *
448      * @param token Ability token.
449      * @return Returns ERR_OK on success, others on failure.
450      */
451     ErrCode MoveAbilityToBackground(sptr<IRemoteObject> token);
452 
453     /**
454      * Move the UIAbility to background, called by app self.
455      *
456      * @param token the token of the ability to move.
457      * @return Returns ERR_OK on success, others on failure.
458      */
459     ErrCode MoveUIAbilityToBackground(const sptr<IRemoteObject> token);
460 
461     /**
462      * CloseAbility with want, return want from ability manager service.
463      *
464      * @param token Ability token.
465      * @param resultCode resultCode.
466      * @param Want Ability want returned.
467      * @return Returns ERR_OK on success, others on failure.
468      */
469     ErrCode CloseAbility(sptr<IRemoteObject> token, int resultCode = DEFAULT_INVAL_VALUE,
470         const Want *resultWant = nullptr);
471 
472     /**
473      * MinimizeAbility, minimize the special ability.
474      *
475      * @param token, ability token.
476      * @param fromUser mark the minimize operation source.
477      * @return Returns ERR_OK on success, others on failure.
478      */
479     ErrCode MinimizeAbility(sptr<IRemoteObject> token, bool fromUser = false);
480 
481     /**
482      * MinimizeUIExtensionAbility, minimize the special ui extension ability.
483      *
484      * @param extensionSessionInfo the extension session info of the ability to minimize.
485      * @param fromUser mark the minimize operation source.
486      * @return Returns ERR_OK on success, others on failure.
487      */
488     ErrCode MinimizeUIExtensionAbility(sptr<SessionInfo> extensionSessionInfo, bool fromUser = false);
489 
490     /**
491      * MinimizeUIAbilityBySCB, minimize the special ability by scb.
492      *
493      * @param sessionInfo the session info of the ability to minimize.
494      * @param fromUser, Whether form user.
495      * @return Returns ERR_OK on success, others on failure.
496      */
497     ErrCode MinimizeUIAbilityBySCB(sptr<SessionInfo> sessionInfo, bool fromUser = false, uint32_t sceneFlag = 0);
498 
499     /**
500      * ConnectAbility, connect session with service ability.
501      *
502      * @param want, Special want for service type's ability.
503      * @param connect, Callback used to notify caller the result of connecting or disconnecting.
504      * @return Returns ERR_OK on success, others on failure.
505      */
506     ErrCode ConnectAbility(const Want &want, sptr<IAbilityConnection> connect, int32_t userId);
507 
508     /**
509      * ConnectAbility, connect session with service ability.
510      *
511      * @param want, Special want for service type's ability.
512      * @param connect, Callback used to notify caller the result of connecting or disconnecting.
513      * @param callerToken, caller ability token.
514      * @return Returns ERR_OK on success, others on failure.
515      */
516     ErrCode ConnectAbility(
517         const Want &want,
518         sptr<IAbilityConnection> connect,
519         sptr<IRemoteObject> callerToken,
520         int32_t userId = DEFAULT_INVAL_VALUE);
521 
522     /**
523      * ConnectUIServiceExtesnionAbility, connect session with uiService ability.
524      *
525      * @param want, Special want for uiService type's ability.
526      * @param connect, Callback used to notify caller the result of connecting or disconnecting.
527      * @param callerToken, caller ability token.
528      * @return Returns ERR_OK on success, others on failure.
529      */
530     ErrCode ConnectUIServiceExtesnionAbility(
531         const Want &want,
532         sptr<IAbilityConnection> connect,
533         sptr<IRemoteObject> callerToken,
534         int32_t userId = DEFAULT_INVAL_VALUE);
535 
536     /**
537      * Connect data share extension ability.
538      *
539      * @param want, special want for the data share extension ability.
540      * @param connect, callback used to notify caller the result of connecting or disconnecting.
541      * @param userId, the extension runs in.
542      * @return Returns ERR_OK on success, others on failure.
543      */
544     ErrCode ConnectDataShareExtensionAbility(const Want &want, sptr<IAbilityConnection> connect,
545         int32_t userId = DEFAULT_INVAL_VALUE);
546 
547     /**
548      * Connect extension ability.
549      *
550      * @param want, special want for the extension ability.
551      * @param connect, callback used to notify caller the result of connecting or disconnecting.
552      * @param userId, the extension runs in.
553      * @return Returns ERR_OK on success, others on failure.
554      */
555     ErrCode ConnectExtensionAbility(const Want &want, sptr<IAbilityConnection> connect,
556         int32_t userId = DEFAULT_INVAL_VALUE);
557 
558     /**
559      * Connect ui extension ability.
560      *
561      * @param want, special want for the ui extension ability.
562      * @param connect, callback used to notify caller the result of connecting or disconnecting.
563      * @param sessionInfo the extension session info of the ability to connect.
564      * @param userId, the extension runs in.
565      * @param connectInfo the connect info.
566      * @return Returns ERR_OK on success, others on failure.
567      */
568     ErrCode ConnectUIExtensionAbility(const Want &want, sptr<IAbilityConnection> connect,
569         sptr<SessionInfo> sessionInfo, int32_t userId = DEFAULT_INVAL_VALUE,
570         sptr<UIExtensionAbilityConnectInfo> connectInfo = nullptr);
571 
572     /**
573      * DisconnectAbility, disconnect session with service ability.
574      *
575      * @param connect, Callback used to notify caller the result of connecting or disconnecting.
576      * @return Returns ERR_OK on success, others on failure.
577      */
578     ErrCode DisconnectAbility(sptr<IAbilityConnection> connect);
579 
580     /**
581      * AcquireDataAbility, acquire a data ability by its authority, if it not existed,
582      * AMS loads it synchronously.
583      *
584      * @param uri, data ability uri.
585      * @param tryBind, true: when a data ability is died, ams will kill this client, or do nothing.
586      * @param callerToken, specifies the caller ability token.
587      * @return returns the data ability ipc object, or nullptr for failed.
588      */
589     sptr<IAbilityScheduler> AcquireDataAbility(const Uri &uri, bool tryBind, sptr<IRemoteObject> callerToken);
590 
591     /**
592      * ReleaseDataAbility, release the data ability that referenced by 'dataAbilityToken'.
593      *
594      * @param dataAbilityToken, specifies the data ability that will be released.
595      * @param callerToken, specifies the caller ability token.
596      * @return returns ERR_OK if succeeded, or error codes for failed.
597      */
598     ErrCode ReleaseDataAbility(sptr<IAbilityScheduler> dataAbilityScheduler, sptr<IRemoteObject> callerToken);
599 
600     /**
601      * dump ability stack info, about userID, mission stack info,
602      * mission record info and ability info.
603      *
604      * @param state Ability stack info.
605      * @return Returns ERR_OK on success, others on failure.
606      */
607     ErrCode DumpState(const std::string &args, std::vector<std::string> &state);
608     ErrCode DumpSysState(
609         const std::string& args, std::vector<std::string>& state, bool isClient, bool isUserID, int UserID);
610     /**
611      * Connect ability manager service.
612      *
613      * @return Returns ERR_OK on success, others on failure.
614      */
615     ErrCode Connect();
616 
617     /**
618      * Destroys this Service ability by Want.
619      *
620      * @param want, Special want for service type's ability.
621      * @param token ability's token.
622      * @return Returns true if this Service ability will be destroyed; returns false otherwise.
623      */
624     ErrCode StopServiceAbility(const Want &want, sptr<IRemoteObject> token = nullptr);
625 
626     /**
627      * Kill the process immediately.
628      *
629      * @param bundleName.
630      * @param clearPageStack.
631      * @return Returns ERR_OK on success, others on failure.
632      */
633     ErrCode KillProcess(const std::string &bundleName, const bool clearPageStack = true);
634 
635     #ifdef ABILITY_COMMAND_FOR_TEST
636     /**
637      * Force ability timeout.
638      *
639      * @param abilityName.
640      * @param state. ability lifecycle state.
641      * @return Returns ERR_OK on success, others on failure.
642      */
643     ErrCode ForceTimeoutForTest(const std::string &abilityName, const std::string &state);
644     #endif
645 
646     /**
647      * ContinueMission, continue ability from mission center.
648      *
649      * @param srcDeviceId, origin deviceId.
650      * @param dstDeviceId, target deviceId.
651      * @param missionId, indicates which ability to continue.
652      * @param callBack, notify result back.
653      * @param wantParams, extended params.
654      * @return Returns ERR_OK on success, others on failure.
655      */
656     ErrCode ContinueMission(const std::string &srcDeviceId, const std::string &dstDeviceId, int32_t missionId,
657         sptr<IRemoteObject> callback, AAFwk::WantParams &wantParams);
658 
659     /**
660      * ContinueMission, continue ability from mission center.
661      *
662      * @param srcDeviceId, origin deviceId.
663      * @param dstDeviceId, target deviceId.
664      * @param bundleName, indicates which bundleName to continue.
665      * @param callBack, notify result back.
666      * @param wantParams, extended params.
667      * @return Returns ERR_OK on success, others on failure.
668      */
669     ErrCode ContinueMission(AAFwk::ContinueMissionInfo continueMissionInfo, const sptr<IRemoteObject> &callback);
670 
671     /**
672      * start continuation.
673      * @param want, used to start a ability.
674      * @param abilityToken, ability token.
675      * @param status, continue status.
676      * @return Returns ERR_OK on success, others on failure.
677      */
678     ErrCode StartContinuation(const Want &want, sptr<IRemoteObject> abilityToken, int32_t status);
679 
680     /**
681      * notify continuation complete to dms.
682      * @param deviceId, source device which start a continuation.
683      * @param sessionId, represent a continuaion.
684      * @param isSuccess, continuation result.
685      * @return
686      */
687     void NotifyCompleteContinuation(const std::string &deviceId, int32_t sessionId, bool isSuccess);
688 
689     /**
690      * ContinueMission, continue ability from mission center.
691      * @param deviceId, target deviceId.
692      * @param missionId, indicates which ability to continue.
693      * @param versionCode, version of the remote target ability.
694      * @return Returns ERR_OK on success, others on failure.
695      */
696     ErrCode ContinueAbility(const std::string &deviceId, int32_t missionId, uint32_t versionCode);
697 
698     /**
699      * notify continuation result to application.
700      * @param missionId, indicates which ability to notify.
701      * @param result, continuation result.
702      * @return
703      */
704     ErrCode NotifyContinuationResult(int32_t missionId, int32_t result);
705 
706     /**
707      * @brief Lock specified mission.
708      * @param missionId The id of target mission.
709      *
710      * @return Returns ERR_OK on success, others on failure.
711      */
712     ErrCode LockMissionForCleanup(int32_t missionId);
713 
714     /**
715      * @brief Unlock specified mission.
716      * @param missionId The id of target mission.
717      *
718      * @return Returns ERR_OK on success, others on failure.
719      */
720     ErrCode UnlockMissionForCleanup(int32_t missionId);
721 
722     /**
723      * @brief change specified AbilityRecord lockState.
724      * @param sessionId The id of target AbilityRecord.
725      * @param lockState The lockState of target AbilityRecord.
726      *
727      * @return Returns ERR_OK on success, others on failure.
728      */
729     void SetLockedState(int32_t sessionId, bool lockedState);
730 
731     /**
732      * @brief Register mission listener to ams.
733      * @param listener The handler of listener.
734      *
735      * @return Returns ERR_OK on success, others on failure.
736      */
737     ErrCode RegisterMissionListener(sptr<IMissionListener> listener);
738 
739     /**
740      * @brief UnRegister mission listener from ams.
741      * @param listener The handler of listener.
742      *
743      * @return Returns ERR_OK on success, others on failure.
744      */
745     ErrCode UnRegisterMissionListener(sptr<IMissionListener> listener);
746 
747     /**
748      * @brief Register mission listener to ability manager service.
749      * @param deviceId The remote device Id.
750      * @param listener The handler of listener.
751      *
752      * @return Returns ERR_OK on success, others on failure.
753      */
754     ErrCode RegisterMissionListener(const std::string &deviceId, sptr<IRemoteMissionListener> listener);
755 
756     /**
757      * @brief Register mission listener to ability manager service.
758      * @param deviceId The remote device Id.
759      * @param listener The handler of listener.
760      *
761      * @return Returns ERR_OK on success, others on failure.
762      */
763     ErrCode RegisterOnListener(const std::string &type, sptr<IRemoteOnListener> listener);
764 
765     /**
766      * @brief Register mission listener to ability manager service.
767      * @param deviceId The remote device Id.
768      * @param listener The handler of listener.
769      *
770      * @return Returns ERR_OK on success, others on failure.
771      */
772     ErrCode RegisterOffListener(const std::string &type, sptr<IRemoteOnListener> listener);
773 
774     /**
775      * @brief UnRegister mission listener from ability manager service.
776      * @param deviceId The remote device Id.
777      * @param listener The handler of listener.
778      *
779      * @return Returns ERR_OK on success, others on failure.
780      */
781     ErrCode UnRegisterMissionListener(const std::string &deviceId, sptr<IRemoteMissionListener> listener);
782 
783     /**
784      * @brief Get mission infos from ams.
785      * @param deviceId local or remote deviceid.
786      * @param numMax max number of missions.
787      * @param missionInfos mission info result.
788      *
789      * @return Returns ERR_OK on success, others on failure.
790      */
791     ErrCode GetMissionInfos(const std::string &deviceId, int32_t numMax, std::vector<MissionInfo> &missionInfos);
792 
793     /**
794      * @brief Get mission info by id.
795      * @param deviceId local or remote deviceid.
796      * @param missionId Id of target mission.
797      * @param missionInfo mision info of target mission.
798      *
799      * @return Returns ERR_OK on success, others on failure.
800      */
801     ErrCode GetMissionInfo(const std::string &deviceId, int32_t missionId, MissionInfo &missionInfo);
802 
803     /**
804      * @brief Get the Mission Snapshot Info object
805      * @param deviceId local or remote deviceid.
806      * @param missionId Id of target mission.
807      * @param snapshot snapshot of target mission.
808      * @param isLowResolution get low resolution snapshot.
809      * @return Returns ERR_OK on success, others on failure.
810      */
811     ErrCode GetMissionSnapshot(const std::string& deviceId, int32_t missionId,
812         MissionSnapshot& snapshot, bool isLowResolution = false);
813 
814     /**
815      * @brief Clean mission by id.
816      * @param missionId Id of target mission.
817      *
818      * @return Returns ERR_OK on success, others on failure.
819      */
820     ErrCode CleanMission(int32_t missionId);
821 
822     /**
823      * @brief Clean all missions in system.
824      *
825      * @return Returns ERR_OK on success, others on failure.
826      */
827     ErrCode CleanAllMissions();
828 
829     /**
830      * @brief Move a mission to front.
831      * @param missionId Id of target mission.
832      * @param startOptions Special startOptions for target mission.
833      *
834      * @return Returns ERR_OK on success, others on failure.
835      */
836     ErrCode MoveMissionToFront(int32_t missionId);
837     ErrCode MoveMissionToFront(int32_t missionId, const StartOptions &startOptions);
838 
839     /**
840      * Move missions to front
841      * @param missionIds Ids of target missions
842      * @param topMissionId Indicate which mission will be moved to top, if set to -1, missions' order won't change
843      * @return Returns ERR_OK on success, others on failure.
844      */
845     ErrCode MoveMissionsToForeground(const std::vector<int32_t>& missionIds, int32_t topMissionId);
846 
847     /**
848      * Move missions to background
849      * @param missionIds Ids of target missions
850      * @param result The result of move missions to background, and the array is sorted by zOrder
851      * @return Returns ERR_OK on success, others on failure.
852      */
853     ErrCode MoveMissionsToBackground(const std::vector<int32_t>& missionIds, std::vector<int32_t>& result);
854 
855     /**
856      * @brief Get mission id by ability token.
857      *
858      * @param token ability token.
859      * @param missionId output mission id.
860      * @return Returns ERR_OK on success, others on failure.
861      */
862     ErrCode GetMissionIdByToken(sptr<IRemoteObject> token, int32_t &missionId);
863 
864     /**
865      * Start Ability, connect session with common ability.
866      *
867      * @param want, Special want for service type's ability.
868      * @param connect, Callback used to notify caller the result of connecting or disconnecting.
869      * @return Returns ERR_OK on success, others on failure.
870      */
871     ErrCode StartAbilityByCall(const Want &want, sptr<IAbilityConnection> connect);
872 
873     /**
874      * Start Ability, connect session with common ability.
875      *
876      * @param want, Special want for service type's ability.
877      * @param connect, Callback used to notify caller the result of connecting or disconnecting.
878      * @param accountId Indicates the account to start.
879      * @return Returns ERR_OK on success, others on failure.
880      */
881     ErrCode StartAbilityByCall(const Want &want, sptr<IAbilityConnection> connect,
882         sptr<IRemoteObject> callToken, int32_t accountId = DEFAULT_INVAL_VALUE);
883 
884     /**
885      * CallRequestDone, after invoke callRequest, ability will call this interface to return callee.
886      *
887      * @param token, ability's token.
888      * @param callStub, ability's callee.
889      */
890     void CallRequestDone(sptr<IRemoteObject> token, sptr<IRemoteObject> callStub);
891 
892     /**
893      * Get ability token by connect.
894      *
895      * @param token The token of ability.
896      * @param callStub The callee object.
897      */
898     void GetAbilityTokenByCalleeObj(sptr<IRemoteObject> callStub, sptr<IRemoteObject> &token);
899 
900     /**
901      * Release the call between Ability, disconnect session with common ability.
902      *
903      * @param connect, Callback used to notify caller the result of connecting or disconnecting.
904      * @return Returns ERR_OK on success, others on failure.
905      */
906     ErrCode ReleaseCall(sptr<IAbilityConnection> connect, const AppExecFwk::ElementName &element);
907 
908     /**
909      * @brief Get the ability running information.
910      *
911      * @param info Ability running information.
912      * @return Returns ERR_OK on success, others on failure.
913      */
914     ErrCode GetAbilityRunningInfos(std::vector<AbilityRunningInfo> &info);
915 
916     /**
917      * @brief Get the extension running information.
918      *
919      * @param upperLimit The maximum limit of information wish to get.
920      * @param info Extension running information.
921      * @return Returns ERR_OK on success, others on failure.
922      */
923     ErrCode GetExtensionRunningInfos(int upperLimit, std::vector<ExtensionRunningInfo> &info);
924 
925     /**
926      * @brief Get running process information.
927      *
928      * @param info Running process information.
929      * @return Returns ERR_OK on success, others on failure.
930      */
931     ErrCode GetProcessRunningInfos(std::vector<AppExecFwk::RunningProcessInfo> &info);
932 
933     /**
934      * Start synchronizing remote device mission
935      * @param devId, deviceId.
936      * @param fixConflict, resolve synchronizing conflicts flag.
937      * @param tag, call tag.
938      * @return Returns ERR_OK on success, others on failure.
939      */
940     ErrCode StartSyncRemoteMissions(const std::string &devId, bool fixConflict, int64_t tag);
941 
942     /**
943      * Stop synchronizing remote device mission
944      * @param devId, deviceId.
945      * @return Returns ERR_OK on success, others on failure.
946      */
947     ErrCode StopSyncRemoteMissions(const std::string &devId);
948 
949     /**
950      * @brief start user.
951      * @param accountId accountId.
952      *
953      * @return Returns ERR_OK on success, others on failure.
954      */
955     ErrCode StartUser(int accountId, sptr<IUserCallback> callback);
956 
957     /**
958      * @brief stop user.
959      * @param accountId accountId.
960      * @param callback callback.
961      *
962      * @return Returns ERR_OK on success, others on failure.
963      */
964     ErrCode StopUser(int accountId, sptr<IUserCallback> callback);
965 
966     /**
967      * @brief logout user.
968      * @param accountId accountId.
969      *
970      * @return Returns ERR_OK on success, others on failure.
971      */
972     ErrCode LogoutUser(int32_t accountId);
973 
974     /**
975      * @brief Register the snapshot handler
976      * @param handler snapshot handler
977      * @return ErrCode Returns ERR_OK on success, others on failure.
978      */
979     ErrCode RegisterSnapshotHandler(sptr<ISnapshotHandler> handler);
980 
981     /**
982      * PrepareTerminateAbility with want, if terminate, return want from ability manager service.
983      *
984      * @param token Ability token.
985      * @param callback callback.
986      * @return Returns ERR_OK on success, others on failure.
987      */
988     ErrCode PrepareTerminateAbility(sptr<IRemoteObject> token, sptr<IPrepareTerminateCallback> callback);
989 
990     ErrCode RegisterStatusBarDelegate(sptr<AbilityRuntime::IStatusBarDelegate> delegate);
991 
992     ErrCode KillProcessWithPrepareTerminate(const std::vector<int32_t>& pids);
993 
994     /**
995      * @brief Register auto start up callback for system api.
996      * @param callback The point of JsAbilityAutoStartupCallBack.
997      * @return Returns ERR_OK on success, others on failure.
998      */
999     ErrCode RegisterAutoStartupSystemCallback(sptr<IRemoteObject> callback);
1000 
1001     /**
1002      * @brief Unregister auto start up callback for system api.
1003      * @param callback The point of JsAbilityAutoStartupCallBack.
1004      * @return Returns ERR_OK on success, others on failure.
1005      */
1006     ErrCode UnregisterAutoStartupSystemCallback(sptr<IRemoteObject> callback);
1007 
1008     /**
1009      * @brief Set every application auto start up state.
1010      * @param info The auto startup info,include bundle name, module name, ability name.
1011      * @return Returns ERR_OK on success, others on failure.
1012      */
1013     ErrCode SetApplicationAutoStartup(const AutoStartupInfo &info);
1014 
1015     /**
1016      * @brief Cancel every application auto start up .
1017      * @param info The auto startup info,include bundle name, module name, ability name.
1018      * @return Returns ERR_OK on success, others on failure.
1019      */
1020     ErrCode CancelApplicationAutoStartup(const AutoStartupInfo &info);
1021 
1022     /**
1023      * @brief Query auto startup state all application.
1024      * @param infoList Output parameters, return auto startup info list.
1025      * @return Returns ERR_OK on success, others on failure.
1026      */
1027     ErrCode QueryAllAutoStartupApplications(std::vector<AutoStartupInfo> &infoList);
1028 
1029     /**
1030      * PrepareTerminateAbilityBySCB, prepare to terminate ability by scb.
1031      *
1032      * @param sessionInfo the session info of the ability to terminate.
1033      * @param isPrepareTerminate the result of ability onPrepareToTermiante.
1034      * @return Returns ERR_OK on success, others on failure.
1035      */
1036     ErrCode PrepareTerminateAbilityBySCB(sptr<SessionInfo> sessionInfo, bool &isPrepareTerminate);
1037 
1038     /**
1039      * Set mission continue state of this ability.
1040      *
1041      * @param token Indidate token of ability.
1042      * @param state the mission continuation state of this ability.
1043      * @return Returns ERR_OK if success.
1044      */
1045     ErrCode SetMissionContinueState(sptr<IRemoteObject> token, const AAFwk::ContinueState &state,
1046         sptr<IRemoteObject> sessionToken);
1047 
1048 #ifdef SUPPORT_GRAPHICS
1049     /**
1050      * Set mission label of this ability.
1051      *
1052      * @param abilityToken Indidate token of ability.
1053      * @param label Indidate the label showed of the ability in recent missions.
1054      * @return Returns ERR_OK on success, others on failure.
1055      */
1056     ErrCode SetMissionLabel(sptr<IRemoteObject> abilityToken, const std::string &label);
1057 
1058     /**
1059      * Set mission icon of this ability.
1060      *
1061      * @param abilityToken Indidate token of ability.
1062      * @param icon Indidate the icon showed of the ability in recent missions.
1063      * @return Returns ERR_OK on success, others on failure.
1064      */
1065     ErrCode SetMissionIcon(sptr<IRemoteObject> abilityToken,
1066         std::shared_ptr<OHOS::Media::PixelMap> icon);
1067 
1068     /**
1069      * Register the WindowManagerService handler
1070      *
1071      * @param handler Indidate handler of WindowManagerService.
1072      * @return ErrCode Returns ERR_OK on success, others on failure.
1073      */
1074     ErrCode RegisterWindowManagerServiceHandler(sptr<IWindowManagerServiceHandler> handler,
1075         bool animationEnabled = true);
1076 
1077     /**
1078      * WindowManager notification AbilityManager after the first frame is drawn.
1079      *
1080      * @param abilityToken Indidate token of ability.
1081      */
1082     void CompleteFirstFrameDrawing(sptr<IRemoteObject> abilityToken);
1083 
1084     /**
1085      * WindowManager notification AbilityManager after the first frame is drawn.
1086      *
1087      * @param sessionId Indidate session id.
1088      */
1089     void CompleteFirstFrameDrawing(int32_t sessionId);
1090 
1091     /**
1092      * Called to update mission snapshot.
1093      * @param token The target ability.
1094      * @param pixelMap The snapshot.
1095      */
1096     void UpdateMissionSnapShot(sptr<IRemoteObject> token,
1097         std::shared_ptr<OHOS::Media::PixelMap> pixelMap);
1098 
1099     ErrCode GetDialogSessionInfo(const std::string &dialogSessionId, sptr<DialogSessionInfo> &info);
1100     ErrCode SendDialogResult(const Want &want, const std::string &dialogSessionId, bool isAllow);
1101 #endif
1102 
1103     /**
1104      * @brief start user test.
1105      * @param want the want of the ability user test to start.
1106      * @param observer test observer callback.
1107      *
1108      * @return Returns ERR_OK on success, others on failure.
1109      */
1110     ErrCode StartUserTest(const Want &want, sptr<IRemoteObject> observer);
1111 
1112     /**
1113      * @brief Finish user test.
1114      * @param msg user test message.
1115      * @param resultCode user test result Code.
1116      * @param bundleName user test bundleName.
1117      *
1118      * @return Returns ERR_OK on success, others on failure.
1119      */
1120     ErrCode FinishUserTest(const std::string &msg, const int64_t &resultCode, const std::string &bundleName);
1121 
1122      /**
1123      * GetTopAbility, get the token of top ability.
1124      *
1125      * @param token, the token of top ability.
1126      * @return Returns ERR_OK on success, others on failure.
1127      */
1128     ErrCode GetTopAbility(sptr<IRemoteObject> &token);
1129 
1130     ErrCode CheckUIExtensionIsFocused(uint32_t uiExtensionTokenId, bool& isFocused);
1131 
1132     /**
1133      * DelegatorDoAbilityForeground, the delegator calls this interface to move the ability to the foreground.
1134      *
1135      * @param token, ability's token.
1136      * @return Returns ERR_OK on success, others on failure.
1137      */
1138     ErrCode DelegatorDoAbilityForeground(sptr<IRemoteObject> token);
1139 
1140     /**
1141      * DelegatorDoAbilityBackground, the delegator calls this interface to move the ability to the background.
1142      *
1143      * @param token, ability's token.
1144      * @return Returns ERR_OK on success, others on failure.
1145      */
1146     ErrCode DelegatorDoAbilityBackground(sptr<IRemoteObject> token);
1147 
1148    /**
1149      * Calls this interface to move the ability to the foreground.
1150      *
1151      * @param token, ability's token.
1152      * @param flag, use for lock or unlock flag and so on.
1153      * @return Returns ERR_OK on success, others on failure.
1154      */
1155     ErrCode DoAbilityForeground(sptr<IRemoteObject> token, uint32_t flag);
1156 
1157     /**
1158      * Calls this interface to move the ability to the background.
1159      *
1160      * @param token, ability's token.
1161      * @param flag, use for lock or unlock flag and so on.
1162      * @return Returns ERR_OK on success, others on failure.
1163      */
1164     ErrCode DoAbilityBackground(sptr<IRemoteObject> token, uint32_t flag);
1165 
1166     /**
1167      * Set ability controller.
1168      *
1169      * @param abilityController, The ability controller.
1170      * @return Returns ERR_OK on success, others on failure.
1171      */
1172     virtual int SetAbilityController(sptr<AppExecFwk::IAbilityController> abilityController,
1173         bool imAStabilityTest);
1174 
1175     /**
1176      * Free install ability from remote DMS.
1177      *
1178      * @param want Ability want.
1179      * @param callback Callback used to notify free install result.
1180      * @param userId User ID.
1181      * @param requestCode Ability request code.
1182      * @return Returns ERR_OK on success, others on failure.
1183      */
1184     ErrCode FreeInstallAbilityFromRemote(const Want &want, sptr<IRemoteObject> callback, int32_t userId,
1185         int requestCode = DEFAULT_INVAL_VALUE);
1186 
1187     /**
1188      * Called when client complete dump.
1189      *
1190      * @param infos The dump info.
1191      * @param callerToken The caller ability token.
1192      * @return Returns ERR_OK on success, others on failure.
1193      */
1194     ErrCode DumpAbilityInfoDone(std::vector<std::string> &infos, sptr<IRemoteObject> callerToken);
1195 
1196     /**
1197      * @brief Enable recover ability.
1198      *
1199      * @param token Ability identify.
1200      */
1201     void EnableRecoverAbility(sptr<IRemoteObject> token);
1202 
1203     /**
1204      * @brief Submit save recovery info.
1205      *
1206      * @param token Ability identify.
1207      */
1208     void SubmitSaveRecoveryInfo(sptr<IRemoteObject> token);
1209 
1210     /**
1211      * @brief Schedule recovery ability.
1212      *
1213      * @param token Ability identify.
1214      * @param reason See AppExecFwk::StateReason.
1215      * @param want Want information.
1216      */
1217     void ScheduleRecoverAbility(sptr<IRemoteObject> token, int32_t reason, const Want *want = nullptr);
1218 
1219     /**
1220      * @brief Schedule clear recovery page stack.
1221      *
1222      * @param bundleName application bundleName.
1223      */
1224     void ScheduleClearRecoveryPageStack();
1225 
1226     /**
1227      * @brief Add free install observer.
1228      *
1229      * @param callerToken The caller ability token.
1230      * @param observer Free install observer.
1231      * @return Returns ERR_OK on success, others on failure.
1232      */
1233     ErrCode AddFreeInstallObserver(const sptr<IRemoteObject> callToken,
1234         const sptr<AbilityRuntime::IFreeInstallObserver> observer);
1235 
1236     /**
1237      * Called to verify that the MissionId is valid.
1238      * @param missionIds Query mission list.
1239      * @param results Output parameters, return results up to 20 query results.
1240      * @return Returns ERR_OK on success, others on failure.
1241      */
1242     int32_t IsValidMissionIds(const std::vector<int32_t> &missionIds, std::vector<MissionValidResult> &results);
1243 
1244     /**
1245      * Query whether the application of the specified PID and UID has been granted a certain permission
1246      * @param permission
1247      * @param pid Process id
1248      * @param uid
1249      * @return Returns ERR_OK if the current process has the permission, others on failure.
1250      */
1251     ErrCode VerifyPermission(const std::string &permission, int pid, int uid);
1252 
1253     /**
1254      * Acquire the shared data.
1255      * @param missionId The missionId of Target ability.
1256      * @param The IAcquireShareDataCallback object.
1257      * @return Returns ERR_OK on success, others on failure.
1258      */
1259     ErrCode AcquireShareData(int32_t missionId, sptr<IAcquireShareDataCallback> shareData);
1260 
1261     /**
1262      * Notify sharing data finished.
1263      * @param resultCode The result of sharing data.
1264      * @param uniqueId The uniqueId from request object.
1265      * @param wantParam The params of acquiring sharing data from target ability.
1266      * @return Returns ERR_OK on success, others on failure.
1267      */
1268     ErrCode ShareDataDone(
1269         sptr<IRemoteObject> token, int32_t resultCode, int32_t uniqueId, WantParams &wantParam);
1270 
1271     /**
1272      * Request dialog service with want, send want to ability manager service.
1273      *
1274      * @param want target component.
1275      * @param callerToken caller ability token.
1276      * @return Returns ERR_OK on success, others on failure.
1277      */
1278     ErrCode RequestDialogService(
1279         const Want &want,
1280         sptr<IRemoteObject> callerToken);
1281 
1282     /**
1283      * Force app exit and record exit reason.
1284      * @param pid Process id .
1285      * @param exitReason The reason of app exit.
1286      * @return Returns ERR_OK on success, others on failure.
1287      */
1288     ErrCode ForceExitApp(const int32_t pid, const ExitReason &exitReason);
1289 
1290     /**
1291      * Record app exit reason.
1292      * @param exitReason The reason of app exit.
1293      * @return Returns ERR_OK on success, others on failure.
1294      */
1295     ErrCode RecordAppExitReason(const ExitReason &exitReason);
1296 
1297     /**
1298      * Record the process exit reason before the process being killed.
1299      * @param pid The process id.
1300      * @param exitReason The reason of process exit.
1301      * @return Returns ERR_OK on success, others on failure.
1302      */
1303     int32_t RecordProcessExitReason(const int32_t pid, const ExitReason &exitReason);
1304 
1305     /**
1306      * Set rootSceneSession by SCB.
1307      *
1308      * @param rootSceneSession Indicates root scene session of SCB.
1309      */
1310     void SetRootSceneSession(sptr<IRemoteObject> rootSceneSession);
1311 
1312     /**
1313      * Call UIAbility by SCB.
1314      *
1315      * @param sessionInfo the session info of the ability to be called.
1316      * @param isColdStart the session of the ability is or not cold start.
1317      */
1318     void CallUIAbilityBySCB(sptr<SessionInfo> sessionInfo, bool &isColdStart);
1319 
1320     /**
1321      * Start specified ability by SCB.
1322      *
1323      * @param want Want information.
1324      */
1325     void StartSpecifiedAbilityBySCB(const Want &want);
1326 
1327     /**
1328      * Notify sandbox app the result of saving file.
1329      * @param want Result of saving file, which contains the file's uri if success.
1330      * @param resultCode Indicates the action's result.
1331      * @param requestCode Pass the requestCode to match request.
1332      * @return Returns ERR_OK on success, others on failure.
1333      */
1334     ErrCode NotifySaveAsResult(const Want &want, int resultCode, int requestCode);
1335 
1336     /**
1337      * Set sessionManagerService
1338      * @param sessionManagerService the point of sessionManagerService.
1339      *
1340      * @return Returns ERR_OK on success, others on failure.
1341      */
1342     ErrCode SetSessionManagerService(sptr<IRemoteObject> sessionManagerService);
1343 
1344     ErrCode ReportDrawnCompleted(sptr<IRemoteObject> token);
1345 
1346     /**
1347      * @brief Register collaborator.
1348      * @param type collaborator type.
1349      * @param impl collaborator.
1350      * @return Returns ERR_OK on success, others on failure.
1351     */
1352     ErrCode RegisterIAbilityManagerCollaborator(
1353         int32_t type, sptr<IAbilityManagerCollaborator> impl);
1354 
1355     /**
1356      * @brief Unregister collaborator.
1357      * @param type collaborator type.
1358      * @return Returns ERR_OK on success, others on failure.
1359     */
1360     ErrCode UnregisterIAbilityManagerCollaborator(int32_t type);
1361 
1362     /**
1363      * @brief Register session handler.
1364      * @param object The handler.
1365      *
1366      * @return Returns ERR_OK on success, others on failure.
1367     */
1368     ErrCode RegisterSessionHandler(sptr<IRemoteObject> object);
1369 
1370     /**
1371      * @brief Register app debug listener.
1372      * @param listener App debug listener.
1373      * @return Returns ERR_OK on success, others on failure.
1374      */
1375     ErrCode RegisterAppDebugListener(sptr<AppExecFwk::IAppDebugListener> listener);
1376 
1377     /**
1378      * @brief Unregistering app debug listener.
1379      * @param listener App debug listener.
1380      * @return Returns ERR_OK on success, others on failure.
1381      */
1382     ErrCode UnregisterAppDebugListener(sptr<AppExecFwk::IAppDebugListener> listener);
1383 
1384     /**
1385      * @brief Attach app debug.
1386      * @param bundleName The application bundle name.
1387      * @return Returns ERR_OK on success, others on failure.
1388      */
1389     ErrCode AttachAppDebug(const std::string &bundleName);
1390 
1391     /**
1392      * @brief Detach app debug.
1393      * @param bundleName The application bundle name.
1394      * @return Returns ERR_OK on success, others on failure.
1395      */
1396     ErrCode DetachAppDebug(const std::string &bundleName);
1397 
1398     /**
1399      * @brief Check if ability controller can start.
1400      * @param want The want of ability to start.
1401      * @return Return true to allow ability to start, or false to reject.
1402      */
1403     bool IsAbilityControllerStart(const Want &want);
1404 
1405     /**
1406      * @brief Open file by uri.
1407      * @param uri The file uri.
1408      * @param flag Want::FLAG_AUTH_READ_URI_PERMISSION or Want::FLAG_AUTH_WRITE_URI_PERMISSION.
1409      * @return int The file descriptor.
1410      */
1411     int32_t OpenFile(const Uri& uri, uint32_t flag);
1412 
1413     /**
1414      * @brief Execute intent.
1415      * @param key The key of intent executing client.
1416      * @param callerToken Caller ability token.
1417      * @param param The Intent execute param.
1418      * @return Returns ERR_OK on success, others on failure.
1419      */
1420     ErrCode ExecuteIntent(uint64_t key, sptr<IRemoteObject> callerToken,
1421         const InsightIntentExecuteParam &param);
1422 
1423     /**
1424      * @brief Called when insight intent execute finished.
1425      *
1426      * @param token ability's token.
1427      * @param intentId insight intent id.
1428      * @param result insight intent execute result.
1429      * @return Returns ERR_OK on success, others on failure.
1430      */
1431     ErrCode ExecuteInsightIntentDone(sptr<IRemoteObject> token, uint64_t intentId,
1432         const InsightIntentExecuteResult &result);
1433 
1434     /**
1435      * @brief Get foreground ui abilities.
1436      * @param list Foreground ui abilities.
1437      * @return Returns ERR_OK on success, others on failure.
1438      */
1439     int32_t GetForegroundUIAbilities(std::vector<AppExecFwk::AbilityStateData> &list);
1440 
1441     /**
1442      * @brief Update session info.
1443      * @param sessionInfos The vector of session info.
1444      */
1445     int32_t UpdateSessionInfoBySCB(std::list<SessionInfo> &sessionInfos, int32_t userId,
1446         std::vector<int32_t> &sessionIds);
1447 
1448     /**
1449      * @brief Restart app self.
1450      * @param want The ability type must be UIAbility.
1451      * @return Returns ERR_OK on success, others on failure.
1452      */
1453     int32_t RestartApp(const AAFwk::Want &want);
1454 
1455     /**
1456      * @brief Get host info of root caller.
1457      *
1458      * @param token The ability token.
1459      * @param hostInfo The host info of root caller.
1460      * @param userId The user id.
1461      * @return ErrCode Returns ERR_OK on success, others on failure.
1462      */
1463     ErrCode GetUIExtensionRootHostInfo(const sptr<IRemoteObject> token, UIExtensionHostInfo &hostInfo,
1464         int32_t userId = DEFAULT_INVAL_VALUE);
1465 
1466     /**
1467      * @brief Get ui extension session info
1468      *
1469      * @param token The ability token.
1470      * @param uiExtensionSessionInfo The ui extension session info.
1471      * @param userId The user id.
1472      * @return int32_t Returns ERR_OK on success, others on failure.
1473      */
1474     ErrCode GetUIExtensionSessionInfo(const sptr<IRemoteObject> token, UIExtensionSessionInfo &uiExtensionSessionInfo,
1475         int32_t userId = DEFAULT_INVAL_VALUE);
1476 
1477     /**
1478      * Pop-up launch of full-screen atomic service.
1479      *
1480      * @param want The want with parameters.
1481      * @param callerToken caller ability token.
1482      * @param requestCode Ability request code.
1483      * @param userId The User ID.
1484      * @return Returns ERR_OK on success, others on failure.
1485      */
1486     int32_t OpenAtomicService(Want& want, const StartOptions &options, sptr<IRemoteObject> callerToken,
1487         int32_t requestCode = DEFAULT_INVAL_VALUE, int32_t userId = DEFAULT_INVAL_VALUE);
1488 
1489     /**
1490      * @brief Querying whether to allow embedded startup of atomic service.
1491      *
1492      * @param token The caller UIAbility token.
1493      * @param appId The ID of the application to which this bundle belongs.
1494      * @return Returns true to allow ability to start, or false to reject.
1495      */
1496     bool IsEmbeddedOpenAllowed(sptr<IRemoteObject> callerToken, const std::string &appId);
1497 
1498     /**
1499      * @brief Request to display assert fault dialog.
1500      * @param callback Listen for user operation callbacks.
1501      * @param wantParams Assert dialog box display information.
1502      * @return Returns ERR_OK on success, others on failure.
1503      */
1504     int32_t RequestAssertFaultDialog(const sptr<IRemoteObject> &callback, const AAFwk::WantParams &wantParams);
1505 
1506     /**
1507      * @brief Notify the operation status of the user.
1508      * @param assertFaultSessionId Indicates the request ID of AssertFault.
1509      * @param userStatus Operation status of the user.
1510      * @return Returns ERR_OK on success, others on failure.
1511      */
1512     int32_t NotifyDebugAssertResult(uint64_t assertFaultSessionId, AAFwk::UserStatus userStatus);
1513 
1514     /**
1515      * Set the enable status for starting and stopping resident processes.
1516      * The caller application can only set the resident status of the configured process.
1517      * @param bundleName The bundle name of the resident process.
1518      * @param enable Set resident process enable status.
1519      * @return Returns ERR_OK on success, others on failure.
1520      */
1521     int32_t SetResidentProcessEnabled(const std::string &bundleName, bool enable);
1522 
1523     /**
1524      * Starts a new ability with specific start options.
1525      *
1526      * @param want, the want of the ability to start.
1527      * @param startOptions Indicates the options used to start.
1528      * @return Returns ERR_OK on success, others on failure.
1529      */
1530     int32_t StartShortcut(const Want &want, const StartOptions &startOptions);
1531 
1532     /**
1533      * Get ability state by persistent id.
1534      *
1535      * @param persistentId, the persistentId of the session.
1536      * @param state Indicates the ability state.
1537      * @return Returns ERR_OK on success, others on failure.
1538      */
1539     int32_t GetAbilityStateByPersistentId(int32_t persistentId, bool &state);
1540 
1541     /**
1542      * Transfer resultCode & want to abms.
1543      *
1544      * @param callerToken caller ability token.
1545      * @param requestCode the resultCode of the ability to start.
1546      * @param want Indicates the ability to start.
1547      * @return Returns ERR_OK on success, others on failure.
1548      */
1549     int32_t TransferAbilityResultForExtension(const sptr<IRemoteObject> &callerToken, int32_t resultCode,
1550         const Want &want);
1551 
1552     /**
1553      * Notify ability manager service frozen process.
1554      *
1555      * @param pidList, the pid list of the frozen process.
1556      * @param uid, the uid of the frozen process.
1557      */
1558     void NotifyFrozenProcessByRSS(const std::vector<int32_t> &pidList, int32_t uid);
1559 
1560     /**
1561      * Open atomic service window prior to finishing free install.
1562      *
1563      * @param bundleName, the bundle name of the atomic service.
1564      * @param moduleName, the module name of the atomic service.
1565      * @param abilityName, the ability name of the atomic service.
1566      * @param startTime, the starting time of the free install task.
1567      * @return Returns ERR_OK on success, others on failure.
1568      */
1569     int32_t PreStartMission(const std::string& bundleName, const std::string& moduleName,
1570         const std::string& abilityName, const std::string& startTime);
1571 
1572     /**
1573      *  Request to clean UIAbility from user.
1574      *
1575      * @param sessionInfo the session info of the ability to clean.
1576      * @return Returns ERR_OK on success, others on failure.
1577      */
1578     ErrCode CleanUIAbilityBySCB(sptr<SessionInfo> sessionInfo);
1579 
1580     /**
1581      * Open link of ability and atomic service.
1582      *
1583      * @param want Ability want.
1584      * @param callerToken Caller ability token.
1585      * @param userId User ID.
1586      * @param requestCode Ability request code.
1587      * @return Returns ERR_OK on success, others on failure.
1588     */
1589     int32_t OpenLink(const Want& want, sptr<IRemoteObject> callerToken, int32_t userId, int requestCode);
1590 
1591     /**
1592      * Terminate process by bundleName.
1593      *
1594      * @param missionId, The mission id of the UIAbility need to be terminated.
1595      * @return Returns ERR_OK on success, others on failure.
1596      */
1597     ErrCode TerminateMission(int32_t missionId);
1598 
1599     /**
1600      * update associate config list by rss.
1601      *
1602      * @param configs The rss config info.
1603      * @param exportConfigs The rss export config info.
1604      * @param flag UPDATE_CONFIG_FLAG_COVER is cover config, UPDATE_CONFIG_FLAG_APPEND is append config.
1605      */
1606     ErrCode UpdateAssociateConfigList(const std::map<std::string, std::list<std::string>>& configs,
1607         const std::list<std::string>& exportConfigs, int32_t flag);
1608 
1609 private:
1610     AbilityManagerClient();
1611     DISALLOW_COPY_AND_MOVE(AbilityManagerClient);
1612 
1613     class AbilityMgrDeathRecipient : public IRemoteObject::DeathRecipient {
1614     public:
1615         AbilityMgrDeathRecipient() = default;
1616         ~AbilityMgrDeathRecipient() = default;
1617         void OnRemoteDied(const wptr<IRemoteObject>& remote) override;
1618     private:
1619         DISALLOW_COPY_AND_MOVE(AbilityMgrDeathRecipient);
1620     };
1621 
1622     sptr<IAbilityManager> GetAbilityManager();
1623     void ResetProxy(wptr<IRemoteObject> remote);
1624     void HandleDlpApp(Want &want);
1625 
1626     static std::once_flag singletonFlag_;
1627     std::recursive_mutex mutex_;
1628     std::mutex topAbilityMutex_;
1629     static std::shared_ptr<AbilityManagerClient> instance_;
1630     sptr<IAbilityManager> proxy_;
1631     sptr<IRemoteObject::DeathRecipient> deathRecipient_;
1632 };
1633 }  // namespace AAFwk
1634 }  // namespace OHOS
1635 #endif  // OHOS_ABILITY_RUNTIME_ABILITY_MANAGER_CLIENT_H
1636