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