• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 <future>
20 #include <memory>
21 #include <shared_mutex>
22 #include <singleton.h>
23 #include <thread_ex.h>
24 #include <unordered_map>
25 #include <map>
26 
27 #include "ability_connect_manager.h"
28 #include "ability_event_handler.h"
29 #include "ability_interceptor_executer.h"
30 #include "ability_manager_stub.h"
31 #include "app_scheduler.h"
32 #ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE
33 #include "background_task_observer.h"
34 #endif
35 #include "bundlemgr/bundle_mgr_interface.h"
36 #include "bundle_constants.h"
37 #include "data_ability_manager.h"
38 #include "free_install_manager.h"
39 #include "hilog_wrapper.h"
40 #include "iremote_object.h"
41 #include "mission_list_manager.h"
42 #include "permission_verification.h"
43 #include "system_ability.h"
44 #include "uri.h"
45 #include "ability_config.h"
46 #include "parameter.h"
47 #include "pending_want_manager.h"
48 #include "ams_configuration_parameter.h"
49 #include "user_controller.h"
50 #include "resident_process_manager.h"
51 #ifdef SUPPORT_GRAPHICS
52 #include "application_anr_listener.h"
53 #include "implicit_start_processor.h"
54 #include "system_dialog_scheduler.h"
55 #endif
56 #include "event_report.h"
57 
58 namespace OHOS {
59 namespace AAFwk {
60 enum class ServiceRunningState { STATE_NOT_START, STATE_RUNNING };
61 const int32_t BASE_USER_RANGE = 200000;
62 using OHOS::AppExecFwk::IAbilityController;
63 class PendingWantManager;
64 /**
65  * @class AbilityManagerService
66  * AbilityManagerService provides a facility for managing ability life cycle.
67  */
68 class AbilityManagerService : public SystemAbility,
69                               public AbilityManagerStub,
70                               public AppStateCallback,
71                               public std::enable_shared_from_this<AbilityManagerService> {
72     DECLARE_DELAYED_SINGLETON(AbilityManagerService)
73     DECLEAR_SYSTEM_ABILITY(AbilityManagerService)
74 public:
75     void OnStart() override;
76     void OnStop() override;
77     ServiceRunningState QueryServiceState() const;
78 
79     /**
80      * StartAbility with want, send want to ability manager service.
81      *
82      * @param want, the want of the ability to start.
83      * @param requestCode, Ability request code.
84      * @param userId, Designation User ID.
85      * @return Returns ERR_OK on success, others on failure.
86      */
87     virtual int StartAbility(
88         const Want &want, int32_t userId = DEFAULT_INVAL_VALUE, int requestCode = DEFAULT_INVAL_VALUE) override;
89 
90     /**
91      * StartAbility with want, send want to ability manager service.
92      *
93      * @param want, the want of the ability to start.
94      * @param callerToken, caller ability token.
95      * @param userId, Designation User ID.
96      * @param requestCode the resultCode of the ability to start.
97      * @return Returns ERR_OK on success, others on failure.
98      */
99     virtual int StartAbility(
100         const Want &want,
101         const sptr<IRemoteObject> &callerToken,
102         int32_t userId = DEFAULT_INVAL_VALUE,
103         int requestCode = DEFAULT_INVAL_VALUE) override;
104 
105     /**
106      * Starts a new ability with specific start settings.
107      *
108      * @param want Indicates the ability to start.
109      * @param abilityStartSetting Indicates the setting ability used to start.
110      * @param callerToken, caller ability token.
111      * @param userId, Designation User ID.
112      * @param requestCode the resultCode of the ability to start.
113      * @return Returns ERR_OK on success, others on failure.
114      */
115     virtual int StartAbility(
116         const Want &want,
117         const AbilityStartSetting &abilityStartSetting,
118         const sptr<IRemoteObject> &callerToken,
119         int32_t userId = DEFAULT_INVAL_VALUE,
120         int requestCode = DEFAULT_INVAL_VALUE) override;
121 
122     /**
123      * Starts a new ability with specific start options.
124      *
125      * @param want, the want of the ability to start.
126      * @param startOptions Indicates the options used to start.
127      * @param callerToken, caller ability token.
128      * @param userId, Designation User ID.
129      * @param requestCode the resultCode of the ability to start.
130      * @return Returns ERR_OK on success, others on failure.
131      */
132     virtual int StartAbility(
133         const Want &want,
134         const StartOptions &startOptions,
135         const sptr<IRemoteObject> &callerToken,
136         int32_t userId = DEFAULT_INVAL_VALUE,
137         int requestCode = DEFAULT_INVAL_VALUE) override;
138 
139     /**
140      * Start extension ability with want, send want to ability manager service.
141      *
142      * @param want, the want of the ability to start.
143      * @param callerToken, caller ability token.
144      * @param userId, Designation User ID.
145      * @param extensionType If an ExtensionAbilityType is set, only extension of that type can be started.
146      * @return Returns ERR_OK on success, others on failure.
147      */
148     virtual int StartExtensionAbility(
149         const Want &want,
150         const sptr<IRemoteObject> &callerToken,
151         int32_t userId = DEFAULT_INVAL_VALUE,
152         AppExecFwk::ExtensionAbilityType extensionType = AppExecFwk::ExtensionAbilityType::UNSPECIFIED) override;
153 
154     /**
155      * Stop extension ability with want, send want to ability manager service.
156      *
157      * @param want, the want of the ability to stop.
158      * @param callerToken, caller ability token.
159      * @param userId, Designation User ID.
160      * @param extensionType If an ExtensionAbilityType is set, only extension of that type can be stopped.
161      * @return Returns ERR_OK on success, others on failure.
162      */
163     virtual int StopExtensionAbility(
164         const Want& want,
165         const sptr<IRemoteObject>& callerToken,
166         int32_t userId = DEFAULT_INVAL_VALUE,
167         AppExecFwk::ExtensionAbilityType extensionType = AppExecFwk::ExtensionAbilityType::UNSPECIFIED) override;
168 
169     /**
170      * TerminateAbility, terminate the special ability.
171      *
172      * @param token, the token of the ability to terminate.
173      * @param resultCode, the resultCode of the ability to terminate.
174      * @param resultWant, the Want of the ability to return.
175      * @return Returns ERR_OK on success, others on failure.
176      */
177     virtual int TerminateAbility(const sptr<IRemoteObject> &token, int resultCode = DEFAULT_INVAL_VALUE,
178         const Want *resultWant = nullptr) override;
179 
180     /**
181      * SendResultToAbility with want, return want from ability manager service.
182      *
183      * @param requestCode, request code.
184      * @param resultCode, resultCode to return.
185      * @param resultWant, the Want of the ability to return.
186      * @return Returns ERR_OK on success, others on failure.
187      */
188     virtual int SendResultToAbility(int32_t requestCode, int32_t resultCode, Want& resultWant) override;
189 
190     /**
191      * TerminateAbility, terminate the special ability.
192      *
193      * @param callerToken, caller ability token.
194      * @param requestCode, Ability request code.
195      * @return Returns ERR_OK on success, others on failure.
196      */
197     virtual int TerminateAbilityByCaller(const sptr<IRemoteObject> &callerToken, int requestCode) override;
198 
199     /**
200      * CloseAbility, close the special ability.
201      *
202      * @param token, the token of the ability to terminate.
203      * @param resultCode, the resultCode of the ability to terminate.
204      * @param resultWant, the Want of the ability to return.
205      * @return Returns ERR_OK on success, others on failure.
206      */
207     virtual int CloseAbility(const sptr<IRemoteObject> &token, int resultCode = DEFAULT_INVAL_VALUE,
208         const Want *resultWant = nullptr) override;
209 
210     /**
211      * MinimizeAbility, minimize the special ability.
212      *
213      * @param token, ability token.
214      * @param fromUser mark the minimize operation source.
215      * @return Returns ERR_OK on success, others on failure.
216      */
217     virtual int MinimizeAbility(const sptr<IRemoteObject> &token, bool fromUser = false) override;
218 
219     /**
220      * ConnectAbility, connect session with service ability.
221      *
222      * @param want, Special want for service type's ability.
223      * @param connect, Callback used to notify caller the result of connecting or disconnecting.
224      * @param callerToken, caller ability token.
225      * @param userId, Designation User ID.
226      * @return Returns ERR_OK on success, others on failure.
227      */
228     virtual int ConnectAbility(
229         const Want &want,
230         const sptr<IAbilityConnection> &connect,
231         const sptr<IRemoteObject> &callerToken,
232         int32_t userId = DEFAULT_INVAL_VALUE) override;
233 
234     virtual int ConnectAbilityCommon(
235         const Want &want,
236         const sptr<IAbilityConnection> &connect,
237         const sptr<IRemoteObject> &callerToken,
238         AppExecFwk::ExtensionAbilityType extensionType,
239         int32_t userId = DEFAULT_INVAL_VALUE) override;
240 
241     /**
242      * ContinueMission, continue ability from mission center.
243      *
244      * @param srcDeviceId, origin deviceId.
245      * @param dstDeviceId, target deviceId.
246      * @param missionId, indicates which ability to continue.
247      * @param callBack, notify result back.
248      * @param wantParams, extended params.
249      * @return Returns ERR_OK on success, others on failure.
250      */
251     virtual int ContinueMission(const std::string &srcDeviceId, const std::string &dstDeviceId,
252         int32_t missionId, const sptr<IRemoteObject> &callBack, AAFwk::WantParams &wantParams) override;
253 
254     /**
255      * ContinueAbility, continue ability to ability.
256      *
257      * @param deviceId, target deviceId.
258      * @param missionId, indicates which ability to continue.
259      * @param versionCode, target bundle version.
260      * @return Returns ERR_OK on success, others on failure.
261      */
262     virtual int ContinueAbility(const std::string &deviceId, int32_t missionId, uint32_t versionCode) override;
263 
264     /**
265      * StartContinuation, continue ability to remote.
266      *
267      * @param want, Indicates the ability to start.
268      * @param abilityToken, Caller ability token.
269      * @param status, continue status.
270      * @return Returns ERR_OK on success, others on failure.
271      */
272     virtual int StartContinuation(const Want &want, const sptr<IRemoteObject> &abilityToken, int32_t status) override;
273 
274     /**
275      * NotifyCompleteContinuation, notify continuation complete to dms.
276      * @param deviceId, source device which start a continuation.
277      * @param sessionId, represent a continuaion.
278      * @param isSuccess, continuation result.
279      * @return
280      */
281     virtual void NotifyCompleteContinuation(const std::string &deviceId, int32_t sessionId, bool isSuccess) override;
282 
283     /**
284      * NotifyContinuationResult, notify continue result to ability.
285      *
286      * @param missionId, Caller mission id.
287      * @param result, continuation result.
288      * @return Returns ERR_OK on success, others on failure.
289      */
290     virtual int NotifyContinuationResult(int32_t missionId, int32_t result) override;
291 
292     /**
293      * RegisterMissionListener, register remote device mission listener.
294      *
295      * @param deviceId, Indicates the remote device Id.
296      * @param listener, listener.
297      * @return Returns ERR_OK on success, others on failure.
298      */
299     virtual int RegisterMissionListener(const std::string &deviceId,
300         const sptr<IRemoteMissionListener> &listener) override;
301 
302     /**
303      * UnRegisterMissionListener, unregister remote device mission listener.
304      *
305      * @param deviceId, Indicates the remote device Id.
306      * @param listener, listener.
307      * @return Returns ERR_OK on success, others on failure.
308      */
309     virtual int UnRegisterMissionListener(const std::string &deviceId,
310         const sptr<IRemoteMissionListener> &listener)override;
311 
312     virtual int DisconnectAbility(const sptr<IAbilityConnection> &connect) override;
313 
314     /**
315      * AcquireDataAbility, acquire a data ability by its authority, if it not existed,
316      * AMS loads it synchronously.
317      *
318      * @param uri, data ability uri.
319      * @param tryBind, true: when a data ability is died, ams will kill this client, or do nothing.
320      * @param callerToken, specifies the caller ability token.
321      * @return returns the data ability ipc object, or nullptr for failed.
322      */
323     virtual sptr<IAbilityScheduler> AcquireDataAbility(
324         const Uri &uri, bool tryBind, const sptr<IRemoteObject> &callerToken) override;
325 
326     /**
327      * ReleaseDataAbility, release the data ability that referenced by 'dataAbilityToken'.
328      *
329      * @param dataAbilityToken, specifies the data ability that will be released.
330      * @param callerToken, specifies the caller ability token.
331      * @return returns ERR_OK if succeeded, or error codes for failed.
332      */
333     virtual int ReleaseDataAbility(
334         sptr<IAbilityScheduler> dataAbilityScheduler, const sptr<IRemoteObject> &callerToken) override;
335 
336     /**
337      * AttachAbilityThread, ability call this interface after loaded.
338      *
339      * @param scheduler,.the interface handler of kit ability.
340      * @param token,.ability's token.
341      * @return Returns ERR_OK on success, others on failure.
342      */
343     virtual int AttachAbilityThread(
344         const sptr<IAbilityScheduler> &scheduler, const sptr<IRemoteObject> &token) override;
345 
346     /**
347      * AbilityTransitionDone, ability call this interface after lift cycle was changed.
348      *
349      * @param token,.ability's token.
350      * @param state,.the state of ability lift cycle.
351      * @return Returns ERR_OK on success, others on failure.
352      */
353     virtual int AbilityTransitionDone(const sptr<IRemoteObject> &token, int state, const PacMap &saveData) override;
354 
355     /**
356      * ScheduleConnectAbilityDone, service ability call this interface while session was connected.
357      *
358      * @param token,.service ability's token.
359      * @param remoteObject,.the session proxy of service ability.
360      * @return Returns ERR_OK on success, others on failure.
361      */
362     virtual int ScheduleConnectAbilityDone(
363         const sptr<IRemoteObject> &token, const sptr<IRemoteObject> &remoteObject) override;
364 
365     /**
366      * ScheduleDisconnectAbilityDone, service ability call this interface while session was disconnected.
367      *
368      * @param token,.service ability's token.
369      * @return Returns ERR_OK on success, others on failure.
370      */
371     virtual int ScheduleDisconnectAbilityDone(const sptr<IRemoteObject> &token) override;
372 
373     /**
374      * ScheduleCommandAbilityDone, service ability call this interface while session was commanded.
375      *
376      * @param token,.service ability's token.
377      * @return Returns ERR_OK on success, others on failure.
378      */
379     virtual int ScheduleCommandAbilityDone(const sptr<IRemoteObject> &token) override;
380 
381     /**
382      * GetEventHandler, get the ability manager service's handler.
383      *
384      * @return Returns AbilityEventHandler ptr.
385      */
386     std::shared_ptr<AbilityEventHandler> GetEventHandler();
387 
388     /**
389      * @brief Ability hidump.
390      * @param fd Indicates the fd.
391      * @param args Indicates the params.
392      * @return Returns the dump result.
393      */
394     int Dump(int fd, const std::vector<std::u16string>& args) override;
395 
396     /**
397      * dump ability stack info, about userID, mission stack info,
398      * mission record info and ability info.
399      *
400      * @param state Ability stack info.
401      * @return Returns ERR_OK on success, others on failure.
402      */
403     virtual void DumpState(const std::string &args, std::vector<std::string> &info) override;
404     virtual void DumpSysState(
405         const std::string& args, std::vector<std::string>& info, bool isClient, bool isUserID, int UserID) override;
406 
407     /**
408      * Destroys this Service ability if the number of times it
409      * has been started equals the number represented by
410      * the given startId.
411      *
412      * @param token ability's token.
413      * @param startId is incremented by 1 every time this ability is started.
414      * @return Returns true if the startId matches the number of startup times
415      * and this Service ability will be destroyed; returns false otherwise.
416      */
417     virtual int TerminateAbilityResult(const sptr<IRemoteObject> &token, int startId) override;
418 
419     /**
420      * Destroys this Service ability by Want.
421      *
422      * @param want, Special want for service type's ability.
423      * @return Returns true if this Service ability will be destroyed; returns false otherwise.
424      */
425     virtual int StopServiceAbility(const Want &want, int32_t userId = DEFAULT_INVAL_VALUE) override;
426 
427     /**
428      * Kill the process immediately.
429      *
430      * @param bundleName.
431      * @return Returns ERR_OK on success, others on failure.
432      */
433     virtual int KillProcess(const std::string &bundleName) override;
434 
435     /**
436      * ClearUpApplicationData, call ClearUpApplicationData() through proxy project,
437      * clear the application data.
438      *
439      * @param bundleName, bundle name in Application record.
440      * @return ERR_OK, return back success, others fail.
441      */
442     virtual int ClearUpApplicationData(const std::string &bundleName) override;
443 
444     /**
445      * Uninstall app
446      *
447      * @param bundleName bundle name of uninstalling app.
448      * @param uid uid of bundle.
449      * @return Returns ERR_OK on success, others on failure.
450      */
451     virtual int UninstallApp(const std::string &bundleName, int32_t uid) override;
452     /**
453      * InitMissionListManager, set the user id of mission list manager.
454      *
455      * @param userId, user id.
456      */
457     void InitMissionListManager(int userId, bool switchUser);
458 
459     virtual sptr<IWantSender> GetWantSender(
460         const WantSenderInfo &wantSenderInfo, const sptr<IRemoteObject> &callerToken) override;
461 
462     virtual int SendWantSender(const sptr<IWantSender> &target, const SenderInfo &senderInfo) override;
463 
464     virtual void CancelWantSender(const sptr<IWantSender> &sender) override;
465 
466     virtual int GetPendingWantUid(const sptr<IWantSender> &target) override;
467 
468     virtual int GetPendingWantUserId(const sptr<IWantSender> &target) override;
469 
470     virtual std::string GetPendingWantBundleName(const sptr<IWantSender> &target) override;
471 
472     virtual int GetPendingWantCode(const sptr<IWantSender> &target) override;
473 
474     virtual int GetPendingWantType(const sptr<IWantSender> &target) override;
475 
476     virtual void RegisterCancelListener(const sptr<IWantSender> &sender, const sptr<IWantReceiver> &receiver) override;
477 
478     virtual void UnregisterCancelListener(
479         const sptr<IWantSender> &sender, const sptr<IWantReceiver> &receiver) override;
480 
481     virtual int GetPendingRequestWant(const sptr<IWantSender> &target, std::shared_ptr<Want> &want) override;
482 
483     virtual int GetWantSenderInfo(const sptr<IWantSender> &target, std::shared_ptr<WantSenderInfo> &info) override;
484 
485     virtual int RegisterObserver(const sptr<AbilityRuntime::IConnectionObserver> &observer) override;
486 
487     virtual int UnregisterObserver(const sptr<AbilityRuntime::IConnectionObserver> &observer) override;
488 
489     virtual int GetDlpConnectionInfos(std::vector<AbilityRuntime::DlpConnectionInfo> &infos) override;
490 
491     virtual int LockMissionForCleanup(int32_t missionId) override;
492 
493     virtual int UnlockMissionForCleanup(int32_t missionId) override;
494 
495     virtual int RegisterMissionListener(const sptr<IMissionListener> &listener) override;
496 
497     virtual int UnRegisterMissionListener(const sptr<IMissionListener> &listener) override;
498 
499     virtual int GetMissionInfos(const std::string& deviceId, int32_t numMax,
500         std::vector<MissionInfo> &missionInfos) override;
501 
502     virtual int GetMissionInfo(const std::string& deviceId, int32_t missionId,
503         MissionInfo &missionInfo) override;
504 
505     virtual int CleanMission(int32_t missionId) override;
506 
507     virtual int CleanAllMissions() override;
508 
509     virtual int MoveMissionToFront(int32_t missionId) override;
510 
511     virtual int MoveMissionToFront(int32_t missionId, const StartOptions &startOptions) override;
512 
513     virtual int32_t GetMissionIdByToken(const sptr<IRemoteObject> &token) override;
514 
515     virtual int StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) override;
516 
517     virtual int StopSyncRemoteMissions(const std::string& devId) override;
518 
519     virtual int GetAppMemorySize() override;
520 
521     virtual bool IsRamConstrainedDevice() override;
522     /**
523      * Start Ability, connect session with common ability.
524      *
525      * @param want, Special want for service type's ability.
526      * @param connect, Callback used to notify caller the result of connecting or disconnecting.
527      * @return Returns ERR_OK on success, others on failure.
528      */
529     virtual int StartAbilityByCall(
530         const Want &want, const sptr<IAbilityConnection> &connect, const sptr<IRemoteObject> &callerToken) override;
531 
532     /**
533      * CallRequestDone, after invoke callRequest, ability will call this interface to return callee.
534      *
535      * @param token, ability's token.
536      * @param callStub, ability's callee.
537      */
538     void CallRequestDone(const sptr<IRemoteObject> &token, const sptr<IRemoteObject> &callStub) override;
539 
540     /**
541      * Release the call between Ability, disconnect session with common ability.
542      *
543      * @param connect, Callback used to notify caller the result of connecting or disconnecting.
544      * @param element, the element of target service.
545      * @return Returns ERR_OK on success, others on failure.
546      */
547     virtual int ReleaseCall(
548         const sptr<IAbilityConnection> &connect, const AppExecFwk::ElementName &element) override;
549 
550     /**
551      * get service record by element name.
552      *
553      */
554     std::shared_ptr<AbilityRecord> GetServiceRecordByElementName(const std::string &element);
555     std::list<std::shared_ptr<ConnectionRecord>> GetConnectRecordListByCallback(sptr<IAbilityConnection> callback);
556 
557     void OnAbilityDied(std::shared_ptr<AbilityRecord> abilityRecord);
558     void OnCallConnectDied(std::shared_ptr<CallRecord> callRecord);
559     void GetMaxRestartNum(int &max, bool isRootLauncher);
560     void GetRestartIntervalTime(int &restartIntervalTime);
561     void HandleLoadTimeOut(int64_t eventId);
562     void HandleActiveTimeOut(int64_t eventId);
563     void HandleInactiveTimeOut(int64_t eventId);
564     void HandleForegroundTimeOut(int64_t eventId);
565     void HandleBackgroundTimeOut(int64_t eventId);
566 
567     int StartAbilityInner(
568         const Want &want,
569         const sptr<IRemoteObject> &callerToken,
570         int requestCode,
571         int callerUid = DEFAULT_INVAL_VALUE,
572         int32_t userId = DEFAULT_INVAL_VALUE);
573 
574     int CheckPermission(const std::string &bundleName, const std::string &permission);
575 
576     void OnAcceptWantResponse(const AAFwk::Want &want, const std::string &flag);
577     void OnStartSpecifiedAbilityTimeoutResponse(const AAFwk::Want &want);
578 
579     virtual int GetAbilityRunningInfos(std::vector<AbilityRunningInfo> &info) override;
580     virtual int GetExtensionRunningInfos(int upperLimit, std::vector<ExtensionRunningInfo> &info) override;
581     virtual int GetProcessRunningInfos(std::vector<AppExecFwk::RunningProcessInfo> &info) override;
582     int GetProcessRunningInfosByUserId(std::vector<AppExecFwk::RunningProcessInfo> &info, int32_t userId);
583     void GetAbilityRunningInfo(std::vector<AbilityRunningInfo> &info, std::shared_ptr<AbilityRecord> &abilityRecord);
584     void GetExtensionRunningInfo(std::shared_ptr<AbilityRecord> &abilityRecord, const int32_t userId,
585         std::vector<ExtensionRunningInfo> &info);
586 
587     int GetMissionSaveTime() const;
588 
589     /**
590      * generate ability request.
591      *
592      */
593     int GenerateAbilityRequest(
594         const Want &want,
595         int requestCode,
596         AbilityRequest &request,
597         const sptr<IRemoteObject> &callerToken,
598         int32_t userId);
599 
600     /**
601      * Get mission id by target ability token.
602      *
603      * @param token target ability token.
604      * @return the missionId of target mission.
605      */
606     int32_t GetMissionIdByAbilityToken(const sptr<IRemoteObject> &token);
607 
608     /**
609      * Get ability token by target mission id.
610      *
611      * @param missionId target missionId.
612      * @return the ability token of target mission.
613      */
614     sptr<IRemoteObject> GetAbilityTokenByMissionId(int32_t missionId);
615 
616     virtual int StartUser(int userId) override;
617 
618     virtual int StopUser(int userId, const sptr<IStopUserCallback> &callback) override;
619 
620     /**
621      * Called when client complete dump.
622      *
623      * @param infos The dump info.
624      * @param callerToken The caller ability token.
625      * @return Returns ERR_OK on success, others on failure.
626      */
627     virtual int DumpAbilityInfoDone(std::vector<std::string> &infos, const sptr<IRemoteObject> &callerToken) override;
628 
629 #ifdef SUPPORT_GRAPHICS
630     virtual int SetMissionLabel(const sptr<IRemoteObject> &abilityToken, const std::string &label) override;
631 
632     virtual int SetMissionIcon(const sptr<IRemoteObject> &token,
633         const std::shared_ptr<OHOS::Media::PixelMap> &icon) override;
634 
635     virtual int RegisterWindowManagerServiceHandler(const sptr<IWindowManagerServiceHandler>& handler) override;
636 
637     virtual void CompleteFirstFrameDrawing(const sptr<IRemoteObject> &abilityToken) override;
638 
639     sptr<IWindowManagerServiceHandler> GetWMSHandler() const;
640 #endif
641 
642     void ClearUserData(int32_t userId);
643 
644     virtual int RegisterSnapshotHandler(const sptr<ISnapshotHandler>& handler) override;
645 
646     virtual int32_t GetMissionSnapshot(const std::string& deviceId, int32_t missionId,
647         MissionSnapshot& snapshot, bool isLowResolution) override;
648 
649     /**
650      * Set ability controller.
651      *
652      * @param abilityController, The ability controller.
653      * @return Returns ERR_OK on success, others on failure.
654      */
655     virtual int SetAbilityController(const sptr<IAbilityController> &abilityController, bool imAStabilityTest) override;
656 
657     /**
658      * Is user a stability test.
659      *
660      * @return Returns true if user is a stability test.
661      */
662     virtual bool IsRunningInStabilityTest() override;
663 
664     virtual int StartUserTest(const Want &want, const sptr<IRemoteObject> &observer) override;
665 
666     virtual int FinishUserTest(
667         const std::string &msg, const int64_t &resultCode, const std::string &bundleName) override;
668 
669     /**
670      * GetTopAbility, get the token of top ability.
671      *
672      * @param token, the token of top ability.
673      * @return Returns ERR_OK on success, others on failure.
674      */
675     virtual int GetTopAbility(sptr<IRemoteObject> &token) override;
676     /**
677      * The delegator calls this interface to move the ability to the foreground.
678      *
679      * @param token, ability's token.
680      * @return Returns ERR_OK on success, others on failure.
681      */
682     virtual int DelegatorDoAbilityForeground(const sptr<IRemoteObject> &token) override;
683 
684     /**
685      * The delegator calls this interface to move the ability to the background.
686      *
687      * @param token, ability's token.
688      * @return Returns ERR_OK on success, others on failure.
689      */
690     virtual int DelegatorDoAbilityBackground(const sptr<IRemoteObject> &token) override;
691 
692     /**
693      * Calls this interface to move the ability to the foreground.
694      *
695      * @param token, ability's token.
696      * @param flag, use for lock or unlock flag and so on.
697      * @return Returns ERR_OK on success, others on failure.
698      */
699     virtual int DoAbilityForeground(const sptr<IRemoteObject> &token, uint32_t flag) override;
700 
701     /**
702      * Calls this interface to move the ability to the background.
703      *
704      * @param token, ability's token.
705      * @param flag, use for lock or unlock flag and so on.
706      * @return Returns ERR_OK on success, others on failure.
707      */
708     virtual int DoAbilityBackground(const sptr<IRemoteObject> &token, uint32_t flag) override;
709 
710     /**
711      * Set component interception.
712      *
713      * @param componentInterception, component interception.
714      * @return Returns ERR_OK on success, others on failure.
715      */
716     virtual int SetComponentInterception(
717         const sptr<AppExecFwk::IComponentInterception> &componentInterception) override;
718 
719     virtual int32_t SendResultToAbilityByToken(const Want &want, const sptr<IRemoteObject> &abilityToken,
720         int32_t requestCode, int32_t resultCode, int32_t userId) override;
721 
722     bool IsAbilityControllerStart(const Want &want, const std::string &bundleName);
723 
724     bool IsAbilityControllerForeground(const std::string &bundleName);
725 
726     bool IsAbilityControllerStartById(int32_t missionId);
727 
728     bool IsComponentInterceptionStart(const Want &want, ComponentRequest &componentRequest, AbilityRequest &request);
729 
730     void NotifyHandleAbilityStateChange(const sptr<IRemoteObject> &abilityToken, int opCode);
731 
732     /**
733      * Send not response process ID to ability manager service.
734      * @param pid The not response process ID.
735      * @return Returns ERR_OK on success, others on failure.
736      */
737     virtual int SendANRProcessID(int pid) override;
738 
739     #ifdef ABILITY_COMMAND_FOR_TEST
740     /**
741      * Block ability manager service.
742      * @return Returns ERR_OK on success, others on failure.
743      */
744     virtual int BlockAmsService() override;
745 
746     /**
747      * Block ability.
748      *
749      * @param abilityRecordId The Ability Record Id.
750      * @return Returns ERR_OK on success, others on failure.
751      */
752     virtual int BlockAbility(int32_t abilityRecordId) override;
753 
754     /**
755      * Block app manager service.
756      * @return Returns ERR_OK on success, others on failure.
757      */
758     virtual int BlockAppService() override;
759 
760     /**
761      * force timeout ability.
762      *
763      * @param abilityName.
764      * @param state.
765      * @return Returns ERR_OK on success, others on failure.
766      */
767     virtual int ForceTimeoutForTest(const std::string &abilityName, const std::string &state) override;
768     #endif
769 
770     bool GetDataAbilityUri(const std::vector<AppExecFwk::AbilityInfo> &abilityInfos,
771         const std::string &mainAbility, std::string &uri);
772 
773     virtual AppExecFwk::ElementName GetTopAbility() override;
774 
775     /**
776      * AtomicServiceStatusCallback OnInstallFinished callback.
777      *
778      * @param resultCode FreeInstall result code.
779      * @param want Want has been installed.
780      * @param userId User id.
781      */
782     void OnInstallFinished(int resultCode, const Want &want, int32_t userId);
783 
784     /**
785      * AtomicServiceStatusCallback OnRemoteInstallFinished callback.
786      *
787      * @param resultCode FreeInstall result code.
788      * @param want Want has been installed.
789      * @param userId User id.
790      */
791     void OnRemoteInstallFinished(int resultCode, const Want &want, int32_t userId);
792 
793     /**
794      * FreeInstall form remote call.
795      *
796      * @param want Want need to install.
797      * @param callback DMS callback.
798      * @param userId User id.
799      * @param requestCode Ability request code.
800      * @return Returns ERR_OK on success, others on failure.
801      */
802     virtual int FreeInstallAbilityFromRemote(const Want &want, const sptr<IRemoteObject> &callback,
803         int32_t userId, int requestCode = DEFAULT_INVAL_VALUE) override;
804 
805     /**
806      * Check the uid is background task uid.
807      *
808      * @param uid userId.
809      * @return Returns whether the uid is background task uid.
810      */
811     bool IsBackgroundTaskUid(const int uid);
812 
813     bool GetLocalDeviceId(std::string& localDeviceId);
814 
815     int JudgeAbilityVisibleControl(const AppExecFwk::AbilityInfo &abilityInfo, int callerUid = -1);
816 
817     /**
818      * Called to update mission snapshot.
819      * @param token The target ability.
820      */
821     virtual void UpdateMissionSnapShot(const sptr<IRemoteObject>& token) override;
822     virtual void EnableRecoverAbility(const sptr<IRemoteObject>& token) override;
823     virtual void ScheduleRecoverAbility(const sptr<IRemoteObject> &token, int32_t reason) override;
824 
825     bool GetStartUpNewRuleFlag() const;
826 
827     std::shared_ptr<AbilityRecord> GetFocusAbility();
828 
829     // MSG 0 - 20 represents timeout message
830     static constexpr uint32_t LOAD_TIMEOUT_MSG = 0;
831     static constexpr uint32_t ACTIVE_TIMEOUT_MSG = 1;
832     static constexpr uint32_t INACTIVE_TIMEOUT_MSG = 2;
833     static constexpr uint32_t TERMINATE_TIMEOUT_MSG = 4;
834     static constexpr uint32_t FOREGROUND_TIMEOUT_MSG = 5;
835     static constexpr uint32_t BACKGROUND_TIMEOUT_MSG = 6;
836 
837     static constexpr uint32_t LOAD_TIMEOUT_ASANENABLED = 150000;  //ms
838     static constexpr uint32_t TERMINATE_TIMEOUT_ASANENABLED = 150000; //ms
839 #ifdef SUPPORT_ASAN
840     static constexpr uint32_t COLDSTART_LOAD_TIMEOUT = 150000; // ms
841     static constexpr uint32_t LOAD_TIMEOUT = 150000;            // ms
842     static constexpr uint32_t ACTIVE_TIMEOUT = 75000;          // ms
843     static constexpr uint32_t INACTIVE_TIMEOUT = 7500;         // ms
844     static constexpr uint32_t TERMINATE_TIMEOUT = 150000;      // ms
845     static constexpr uint32_t CONNECT_TIMEOUT = 45000;         // ms
846     static constexpr uint32_t DISCONNECT_TIMEOUT = 7500;       // ms
847     static constexpr uint32_t COMMAND_TIMEOUT = 75000;         // ms
848     static constexpr uint32_t RESTART_TIMEOUT = 75000;         // ms
849     static constexpr uint32_t RESTART_ABILITY_TIMEOUT = 7500;  // ms
850     static constexpr uint32_t FOREGROUND_TIMEOUT = 75000;   // ms
851     static constexpr uint32_t BACKGROUND_TIMEOUT = 45000;   // ms
852     static constexpr uint32_t DUMP_TIMEOUT = 15000;            // ms
853     static constexpr uint32_t KILL_TIMEOUT = 45000;           // ms
854 #else
855     static constexpr uint32_t COLDSTART_LOAD_TIMEOUT = 10000; // ms
856     static constexpr uint32_t LOAD_TIMEOUT = 10000;            // ms
857     static constexpr uint32_t ACTIVE_TIMEOUT = 5000;          // ms
858     static constexpr uint32_t INACTIVE_TIMEOUT = 500;         // ms
859     static constexpr uint32_t TERMINATE_TIMEOUT = 10000;      // ms
860     static constexpr uint32_t CONNECT_TIMEOUT = 3000;         // ms
861     static constexpr uint32_t DISCONNECT_TIMEOUT = 500;       // ms
862     static constexpr uint32_t COMMAND_TIMEOUT = 5000;         // ms
863     static constexpr uint32_t RESTART_TIMEOUT = 5000;         // ms
864     static constexpr uint32_t RESTART_ABILITY_TIMEOUT = 500;  // ms
865     static constexpr uint32_t FOREGROUND_TIMEOUT = 5000;   // ms
866     static constexpr uint32_t BACKGROUND_TIMEOUT = 3000;   // ms
867     static constexpr uint32_t DUMP_TIMEOUT = 1000;            // ms
868     static constexpr uint32_t KILL_TIMEOUT = 3000;           // ms
869 #endif
870 
871     static constexpr uint32_t MIN_DUMP_ARGUMENT_NUM = 2;
872     static constexpr uint32_t MAX_WAIT_SYSTEM_UI_NUM = 600;
873     static constexpr uint32_t MAX_WAIT_SETTINGS_DATA_NUM = 300;
874 
875     enum DumpKey {
876         KEY_DUMP_ALL = 0,
877         KEY_DUMP_STACK_LIST,
878         KEY_DUMP_STACK,
879         KEY_DUMP_MISSION,
880         KEY_DUMP_TOP_ABILITY,
881         KEY_DUMP_WAIT_QUEUE,
882         KEY_DUMP_SERVICE,
883         KEY_DUMP_DATA,
884         KEY_DUMP_FOCUS_ABILITY,
885         KEY_DUMP_WINDOW_MODE,
886         KEY_DUMP_MISSION_LIST,
887         KEY_DUMP_MISSION_INFOS,
888     };
889 
890     enum DumpsysKey {
891         KEY_DUMPSYS_ALL = 0,
892         KEY_DUMPSYS_MISSION_LIST,
893         KEY_DUMPSYS_ABILITY,
894         KEY_DUMPSYS_SERVICE,
895         KEY_DUMPSYS_PENDING,
896         KEY_DUMPSYS_PROCESS,
897         KEY_DUMPSYS_DATA,
898     };
899 
900     enum {
901         ABILITY_MOVE_TO_FOREGROUND_CODE = 0,
902         ABILITY_MOVE_TO_BACKGROUND_CODE,
903         TERMINATE_ABILITY_CODE
904     };
905 
906     friend class UserController;
907 
908 protected:
909     void OnAbilityRequestDone(const sptr<IRemoteObject> &token, const int32_t state) override;
910     int GetUidByBundleName(std::string bundleName);
911 
912     void OnAppStateChanged(const AppInfo &info) override;
913 
914 private:
915     int TerminateAbilityWithFlag(const sptr<IRemoteObject> &token, int resultCode = DEFAULT_INVAL_VALUE,
916         const Want *resultWant = nullptr, bool flag = true);
917     /**
918      * initialization of ability manager service.
919      *
920      */
921     bool Init();
922     /**
923      * initialization of u0 user.
924      *
925      */
926     void InitU0User();
927     /**
928      * start highest priority ability.
929      *
930      */
931     void StartHighestPriorityAbility(int32_t userId, bool isBoot);
932     /**
933      * connet bms.
934      *
935      */
936     void ConnectBmsService();
937     /**
938      * get the user id.
939      *
940      */
941     int GetUserId();
942     /**
943      * Determine whether it is a system APP
944      *
945      */
946     bool IsSystemUiApp(const AppExecFwk::AbilityInfo &info) const;
947     /**
948      * Init parameters from the global
949      *
950      */
951     void InitGlobalConfiguration();
952 
953     sptr<AppExecFwk::IBundleMgr> GetBundleManager();
954     int StartRemoteAbility(const Want &want, int requestCode, int32_t validUserId,
955         const sptr<IRemoteObject> &callerToken);
956     int ConnectLocalAbility(
957         const Want &want,
958         const int32_t userId,
959         const sptr<IAbilityConnection> &connect,
960         const sptr<IRemoteObject> &callerToken,
961         AppExecFwk::ExtensionAbilityType extensionType);
962     int DisconnectLocalAbility(const sptr<IAbilityConnection> &connect);
963     int ConnectRemoteAbility(Want &want, const sptr<IRemoteObject> &callerToken, const sptr<IRemoteObject> &connect);
964     int DisconnectRemoteAbility(const sptr<IRemoteObject> &connect);
965     int PreLoadAppDataAbilities(const std::string &bundleName, const int32_t userId);
966     void UpdateCallerInfo(Want& want);
967 
968     bool CheckIfOperateRemote(const Want &want);
969     std::string AnonymizeDeviceId(const std::string& deviceId);
970     bool VerificationToken(const sptr<IRemoteObject> &token);
971     void RequestPermission(const Want *resultWant);
972 
973     bool CheckIsRemote(const std::string& deviceId);
974     int GetRemoteMissionInfos(const std::string& deviceId, int32_t numMax,
975         std::vector<MissionInfo> &missionInfos);
976     int GetRemoteMissionInfo(const std::string& deviceId, int32_t missionId,
977         MissionInfo &missionInfo);
978     int32_t GetRemoteMissionSnapshotInfo(const std::string& deviceId, int32_t missionId,
979         MissionSnapshot& missionSnapshot);
980     int StartRemoteAbilityByCall(const Want &want, const sptr<IRemoteObject> &callerToken,
981         const sptr<IRemoteObject> &connect);
982     int ReleaseRemoteAbility(const sptr<IRemoteObject> &connect, const AppExecFwk::ElementName &element);
983 
984     void DumpInner(const std::string &args, std::vector<std::string> &info);
985     void DumpMissionInner(const std::string &args, std::vector<std::string> &info);
986     void DumpStateInner(const std::string &args, std::vector<std::string> &info);
987     void DataDumpStateInner(const std::string &args, std::vector<std::string> &info);
988     void DumpMissionListInner(const std::string &args, std::vector<std::string> &info);
989     void DumpMissionInfosInner(const std::string &args, std::vector<std::string> &info);
990     void DumpFuncInit();
991 
992     bool JudgeMultiUserConcurrency(const int32_t userId);
993     /**
994      * dumpsys info
995      *
996      */
997     void DumpSysFuncInit();
998     void DumpSysInner(
999         const std::string &args, std::vector<std::string> &info, bool isClient, bool isUserID, int userId);
1000     void DumpSysMissionListInner(
1001         const std::string &args, std::vector<std::string> &info, bool isClient, bool isUserID, int userId);
1002     void DumpSysAbilityInner(
1003         const std::string &args, std::vector<std::string> &info, bool isClient, bool isUserID, int userId);
1004     void DumpSysStateInner(
1005         const std::string &args, std::vector<std::string> &info, bool isClient, bool isUserID, int userId);
1006     void DumpSysPendingInner(
1007         const std::string &args, std::vector<std::string> &info, bool isClient, bool isUserID, int userId);
1008     void DumpSysProcess(
1009         const std::string &args, std::vector<std::string> &info, bool isClient, bool isUserID, int userId);
1010     void DataDumpSysStateInner(
1011         const std::string &args, std::vector<std::string> &info, bool isClient, bool isUserID, int userId);
1012     ErrCode ProcessMultiParam(std::vector<std::string>& argsStr, std::string& result);
1013     void ShowHelp(std::string& result);
1014     void ShowIllegalInfomation(std::string& result);
1015     int Dump(const std::vector<std::u16string>& args, std::string& result);
1016 
1017     void InitConnectManager(int32_t userId, bool switchUser);
1018     void InitDataAbilityManager(int32_t userId, bool switchUser);
1019     void InitPendWantManager(int32_t userId, bool switchUser);
1020 
1021     int32_t InitAbilityInfoFromExtension(AppExecFwk::ExtensionAbilityInfo &extensionInfo,
1022         AppExecFwk::AbilityInfo &abilityInfo);
1023 
1024     // multi user
1025     void StartFreezingScreen();
1026     void StopFreezingScreen();
1027     void UserStarted(int32_t userId);
1028     void SwitchToUser(int32_t userId);
1029     void SwitchToUser(int32_t oldUserId, int32_t userId);
1030     void SwitchManagers(int32_t userId, bool switchUser = true);
1031     void StartUserApps(int32_t userId, bool isBoot);
1032     void PauseOldUser(int32_t userId);
1033     void PauseOldMissionListManager(int32_t userId);
1034     void PauseOldConnectManager(int32_t userId);
1035     bool IsSystemUI(const std::string &bundleName) const;
1036 
1037     bool VerificationAllToken(const sptr<IRemoteObject> &token);
1038     std::shared_ptr<DataAbilityManager> GetDataAbilityManager(const sptr<IAbilityScheduler> &scheduler);
1039     std::shared_ptr<MissionListManager> GetListManagerByUserId(int32_t userId);
1040     std::shared_ptr<AbilityConnectManager> GetConnectManagerByUserId(int32_t userId);
1041     std::shared_ptr<DataAbilityManager> GetDataAbilityManagerByUserId(int32_t userId);
1042     std::shared_ptr<MissionListManager> GetListManagerByToken(const sptr<IRemoteObject> &token);
1043     std::shared_ptr<AbilityConnectManager> GetConnectManagerByToken(const sptr<IRemoteObject> &token);
1044     std::shared_ptr<DataAbilityManager> GetDataAbilityManagerByToken(const sptr<IRemoteObject> &token);
1045     bool JudgeSelfCalled(const std::shared_ptr<AbilityRecord> &abilityRecord);
1046 
1047     int32_t GetValidUserId(const int32_t userId);
1048 
1049     int DelegatorMoveMissionToFront(int32_t missionId);
1050 
1051     bool IsNeedTimeoutForTest(const std::string &abilityName, const std::string &state) const;
1052 
1053     void StartResidentApps();
1054 
1055     int VerifyAccountPermission(int32_t userId);
1056 
1057     bool CheckCallerEligibility(const AppExecFwk::AbilityInfo &abilityInfo, int callerUid);
1058 
1059     using DumpFuncType = void (AbilityManagerService::*)(const std::string &args, std::vector<std::string> &info);
1060     std::map<uint32_t, DumpFuncType> dumpFuncMap_;
1061 
1062     using DumpSysFuncType = void (AbilityManagerService::*)(
1063         const std::string& args, std::vector<std::string>& state, bool isClient, bool isUserID, int UserID);
1064     std::map<uint32_t, DumpSysFuncType> dumpsysFuncMap_;
1065 
1066     int CheckStaticCfgPermission(AppExecFwk::AbilityInfo &abilityInfo);
1067 
1068     bool GetValidDataAbilityUri(const std::string &abilityInfoUri, std::string &adjustUri);
1069 
1070     int GenerateExtensionAbilityRequest(const Want &want, AbilityRequest &request,
1071         const sptr<IRemoteObject> &callerToken, int32_t userId);
1072     int CheckOptExtensionAbility(const Want &want, AbilityRequest &abilityRequest,
1073         int32_t validUserId, AppExecFwk::ExtensionAbilityType extensionType);
1074 
1075     void SubscribeBackgroundTask();
1076 
1077     void ReportAbilitStartInfoToRSS(const AppExecFwk::AbilityInfo &abilityInfo);
1078 
1079     void ReportEventToSuspendManager(const AppExecFwk::AbilityInfo &abilityInfo);
1080 
1081     /**
1082      * Check if Caller is allowed to start ServiceAbility(FA) or ServiceExtension(Stage) or DataShareExtension(Stage).
1083      *
1084      * @param abilityRequest, abilityRequest.
1085      * @return Returns whether the caller is allowed to start Service.
1086      */
1087     int CheckCallServicePermission(const AbilityRequest &abilityRequest);
1088 
1089     /**
1090      * Check if Caller is allowed to start DataAbility(FA)
1091      *
1092      * @param abilityRequest, abilityRequest.
1093      * @return Returns whether the caller is allowed to start DataAbility.
1094      */
1095     int CheckCallDataAbilityPermission(AbilityRequest &abilityRequest);
1096 
1097     /**
1098      * Check if Caller is allowed to start ServiceExtension(Stage) or DataShareExtension(Stage).
1099      *
1100      * @param abilityRequest, abilityRequest.
1101      * @return Returns whether the caller is allowed to start ServiceExtension.
1102      */
1103     int CheckCallServiceExtensionPermission(const AbilityRequest &abilityRequest);
1104 
1105     /**
1106      * Check if Caller is allowed to start other Extension(Stage).
1107      *
1108      * @param abilityRequest, abilityRequest.
1109      * @return Returns whether the caller is allowed to start OtherExtension.
1110      */
1111     int CheckCallOtherExtensionPermission(const AbilityRequest &abilityRequest);
1112 
1113     /**
1114      * Check if Caller is allowed to start ServiceAbility(FA).
1115      *
1116      * @param abilityRequest, abilityRequest.
1117      * @return Returns whether the caller is allowed to start ServiceAbility.
1118      */
1119     int CheckCallServiceAbilityPermission(const AbilityRequest &abilityRequest);
1120 
1121     /**
1122      * Check if Caller is allowed to start PageAbility(FA) or Ability(Stage).
1123      *
1124      * @param abilityRequest, abilityRequest.
1125      * @return Returns whether the caller is allowed to start Ability.
1126      */
1127     int CheckCallAbilityPermission(const AbilityRequest &abilityRequest);
1128 
1129     /**
1130      * Check if Caller is allowed to start Ability(Stage) by call.
1131      *
1132      * @param abilityRequest, abilityRequest.
1133      * @return Returns whether the caller is allowed to start Ability by call.
1134      */
1135     int CheckStartByCallPermission(const AbilityRequest &abilityRequest);
1136 
1137     /**
1138      * Judge if Caller-Application is in background state.
1139      *
1140      * @param abilityRequest, abilityRequest.
1141      * @param isBackgroundCall, Indicates the Caller-Application state.
1142      *                          TRUE: The Caller-Application is not in focus and not in foreground state.
1143      *                          FALSE: The Caller-Application is in focus or in foreground state.
1144      * @return Returns ERR_OK on check success, others on check failure.
1145      */
1146     int IsCallFromBackground(const AbilityRequest &abilityRequest, bool &isBackgroundCall);
1147 
1148     bool IsDelegatorCall(const AppExecFwk::RunningProcessInfo &processInfo, const AbilityRequest &abilityRequest);
1149 
1150     /**
1151      *  Temporary, use old rule to check permission.
1152      *
1153      * @param abilityRequest, abilityRequest.
1154      * @param isStartByCall, Indicates whether it is the StartAbilityByCall function call.
1155      *                       TRUE: Is StartAbilityByCall function call.
1156      *                       FALSE: Is other function call, such as StartAbility, ConnectAbility and so on.
1157      * @return Returns ERR_OK on check success, others on check failure.
1158      */
1159     int CheckCallerPermissionOldRule(const AbilityRequest &abilityRequest, const bool isStartByCall = false);
1160 
1161     /**
1162      *  Temporary, judge is use new check-permission rule to start ability.
1163      *
1164      * @param abilityRequest, abilityRequest.
1165      * @return Returns TRUE: Use new rule.
1166      *                 FALSE: Use old rule.
1167      */
1168     bool IsUseNewStartUpRule(const AbilityRequest &abilityRequest);
1169 
1170     bool CheckNewRuleSwitchState(const std::string &param);
1171 
1172     void UpdateFocusState(std::vector<AbilityRunningInfo> &info);
1173 
1174     AAFwk::PermissionVerification::VerificationInfo CreateVerificationInfo(
1175         const AbilityRequest &abilityRequest);
1176 
1177     int AddStartControlParam(Want &want, const sptr<IRemoteObject> &callerToken);
1178 
1179     void RecoverAbilityRestart(const Want &want);
1180 
1181     AAFwk::EventInfo BuildEventInfo(const Want &want, int32_t userId);
1182 
1183     void InitStartupFlag();
1184 
1185     void UpdateAbilityRequestInfo(const sptr<Want> &want, AbilityRequest &request);
1186     ComponentRequest initComponentRequest(const sptr<IRemoteObject> &callerToken = nullptr,
1187         const int requestCode = -1, const int componentStatus = 0);
1188 
1189     constexpr static int REPOLL_TIME_MICRO_SECONDS = 1000000;
1190     constexpr static int WAITING_BOOT_ANIMATION_TIMER = 5;
1191 
1192     std::shared_ptr<AppExecFwk::EventRunner> eventLoop_;
1193     std::shared_ptr<AbilityEventHandler> handler_;
1194     ServiceRunningState state_;
1195     std::unordered_map<int, std::shared_ptr<AbilityConnectManager>> connectManagers_;
1196     std::shared_ptr<AbilityConnectManager> connectManager_;
1197     sptr<AppExecFwk::IBundleMgr> iBundleManager_;
1198     std::unordered_map<int, std::shared_ptr<DataAbilityManager>> dataAbilityManagers_;
1199     std::shared_ptr<DataAbilityManager> dataAbilityManager_;
1200     std::shared_ptr<DataAbilityManager> systemDataAbilityManager_;
1201     std::unordered_map<int, std::shared_ptr<PendingWantManager>> pendingWantManagers_;
1202     std::shared_ptr<PendingWantManager> pendingWantManager_;
1203     std::shared_ptr<AmsConfigurationParameter> amsConfigResolver_;
1204     const static std::map<std::string, AbilityManagerService::DumpKey> dumpMap;
1205     const static std::map<std::string, AbilityManagerService::DumpsysKey> dumpsysMap;
1206     const static std::map<int32_t, AppExecFwk::SupportWindowMode> windowModeMap;
1207 
1208     std::unordered_map<int, std::shared_ptr<MissionListManager>> missionListManagers_;
1209     std::shared_ptr<MissionListManager> currentMissionListManager_;
1210 
1211     std::shared_ptr<FreeInstallManager> freeInstallManager_;
1212 
1213     std::shared_ptr<UserController> userController_;
1214     sptr<AppExecFwk::IAbilityController> abilityController_ = nullptr;
1215     bool controllerIsAStabilityTest_ = false;
1216     std::recursive_mutex globalLock_;
1217     std::shared_mutex managersMutex_;
1218     sptr<AppExecFwk::IComponentInterception> componentInterception_ = nullptr;
1219 
1220     std::multimap<std::string, std::string> timeoutMap_;
1221 
1222     static sptr<AbilityManagerService> instance_;
1223 
1224     // Component StartUp rule switch
1225     bool startUpNewRule_ = true;
1226     /** It only takes effect when startUpNewRule_ is TRUE
1227      *  TRUE: When Caller-Application is Launcher or SystemUI, use old rule.
1228      *  FALSE: Apply new rule to all application
1229      */
1230     bool newRuleExceptLauncherSystemUI_ = true;
1231     /** Indicates the criteria for judging whether the Caller-Application is in the background
1232      *  TRUE: Determine the state by AAFwk::AppState::FOREGROUND.
1233      *  FALSE: Determine the state by AppExecFwk::AppProcessState::APP_STATE_FOCUS.
1234      */
1235     bool backgroundJudgeFlag_ = true;
1236     /** The applications in white list use old rule
1237      *  TRUE: white list enable.
1238      *  FALSE: white list unable.
1239      */
1240     bool whiteListNormalFlag_ = true;
1241     /** The applications in white list can associatedWakeUp
1242      *  TRUE: white list enable.
1243      *  FALSE: white list unable.
1244      */
1245     bool whiteListassociatedWakeUpFlag_ = true;
1246 
1247 #ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE
1248     std::shared_ptr<BackgroundTaskObserver> bgtaskObserver_;
1249 #endif
1250 
1251 #ifdef SUPPORT_GRAPHICS
1252     int32_t ShowPickerDialog(const Want& want, int32_t userId, const sptr<IRemoteObject> &token);
1253     bool CheckWindowMode(int32_t windowMode, const std::vector<AppExecFwk::SupportWindowMode>& windowModes) const;
1254     std::shared_ptr<ImplicitStartProcessor> implicitStartProcessor_;
1255     sptr<IWindowManagerServiceHandler> wmsHandler_;
1256     std::shared_ptr<ApplicationAnrListener> anrListener_;
1257 #endif
1258     std::shared_ptr<AbilityInterceptorExecuter> interceptorExecuter_;
1259     std::unordered_map<int32_t, int64_t> appRecoveryHistory_; // uid:time
1260 };
1261 }  // namespace AAFwk
1262 }  // namespace OHOS
1263 #endif  // OHOS_ABILITY_RUNTIME_ABILITY_MANAGER_SERVICE_H
1264