• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2025 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_UI_ABILITY_LIFECYCLE_MANAGER_H
17 #define OHOS_ABILITY_RUNTIME_UI_ABILITY_LIFECYCLE_MANAGER_H
18 
19 #include <list>
20 #include <map>
21 #include <memory>
22 #include <queue>
23 #include <unordered_map>
24 #include "cpp/mutex.h"
25 
26 #include "ability_manager_constants.h"
27 #include "ability_record.h"
28 #include "isession_handler_interface.h"
29 
30 namespace OHOS {
31 namespace AAFwk {
32 class SessionInfo;
33 class StatusBarDelegateManager;
34 struct AbilityRunningInfo;
35 struct MissionValidResult;
36 
37 enum class SpecifiedProcessState: u_int8_t {
38     STATE_NONE = 0,
39     STATE_PROCESS = 1,
40     STATE_ABILITY = 2
41 };
42 
43 struct SpecifiedRequest {
44     bool preCreateProcessName = false;
45     bool isCold = false;
46     SpecifiedProcessState specifiedProcessState = SpecifiedProcessState::STATE_NONE;
47     int32_t requestId = 0;
48     int32_t persistentId = 0;
49     int32_t requestListId = -1;
50     uint32_t sceneFlag = 0;
51     uint32_t callingTokenId = 0;
52     AbilityRequest abilityRequest;
53 
SpecifiedRequestSpecifiedRequest54     SpecifiedRequest(int32_t requestId, AbilityRequest request) : requestId(requestId), abilityRequest(request) {}
55 };
56 
57 struct AbilitiesRequest {
58     int32_t requestListId = -1;
59     std::string requestKey;
60     std::vector<std::pair<int32_t, sptr<SessionInfo>>> sessionInfoList;
61     uint32_t doneCount = 0;
62     sptr<IRemoteObject> callerToken;
63 };
64 
65 class UIAbilityLifecycleManager : public std::enable_shared_from_this<UIAbilityLifecycleManager> {
66 public:
67     UIAbilityLifecycleManager() = default;
68     explicit UIAbilityLifecycleManager(int32_t userId);
69     virtual ~UIAbilityLifecycleManager() = default;
70 
71     void SignRestartAppFlag(int32_t uid, const std::string &instanceKey, bool isAppRecovery = false);
72 
73     /**
74      * StartUIAbility with request.
75      *
76      * @param abilityRequest the request of the service ability to start.
77      * @param sessionInfo the info of scene session
78      * @param isColdStart the session info of the ability is or not cold start.
79      * @return Returns ERR_OK on success, others on failure.
80      */
81     int StartUIAbility(AbilityRequest &abilityRequest, sptr<SessionInfo> sessionInfo, uint32_t sceneFlag,
82         bool &isColdStart);
83 
84     /**
85      * @brief execute after the ability schedule the lifecycle
86      *
87      * @param token the ability token
88      * @param state the ability state
89      * @param saveData the saved data
90      * @return execute error code
91      */
92     int AbilityTransactionDone(const sptr<IRemoteObject> &token, int state, const AppExecFwk::PacMap &saveData);
93 
94     /**
95      * @brief execute after the ability schedule the lifecycle
96      *
97      * @param token the ability token
98      * @param windowConfig the windowconfig
99      * @return execute error code
100      */
101     int AbilityWindowConfigTransactionDone(
102         const sptr<IRemoteObject> &token, const WindowConfig &windowConfig);
103 
104     /**
105      * attach ability thread ipc object.
106      *
107      * @param scheduler ability thread ipc object.
108      * @param token the token of ability.
109      * @return Returns ERR_OK on success, others on failure.
110      */
111     int AttachAbilityThread(const sptr<IAbilityScheduler> &scheduler, const sptr<IRemoteObject> &token);
112 
113     /**
114      * app manager service call this interface after ability request done.
115      *
116      * @param token ability's token.
117      * @param state the state of ability lift cycle.
118      */
119     void OnAbilityRequestDone(const sptr<IRemoteObject> &token, int32_t state);
120 
121     /**
122      * Check whether the UIAbility is alive.
123      *
124      * @param token ability's token.
125      * @return Returns true on alive.
126      */
127     bool IsContainsAbility(const sptr<IRemoteObject> &token) const;
128 
129     /**
130      * Notify SCB to minimize UIAbility
131      *
132      * @param token ability's token
133      */
134     int32_t NotifySCBToMinimizeUIAbility(const sptr<IRemoteObject> token);
135 
136     /**
137      * MinimizeUIAbility, minimize the special ability by scb.
138      *
139      * @param abilityRecord, the ability to minimize.
140      * @param fromUser, Whether form user.
141      * @return Returns ERR_OK on success, others on failure.
142      */
143     int MinimizeUIAbility(const std::shared_ptr<AbilityRecord> &abilityRecord, bool fromUser, uint32_t sceneFlag);
144 
145     /**
146      * GetUIAbilityRecordBySessionInfo.
147      *
148      * @param sessionToken, service ability's session token.
149      * @return Returns AbilityRecord shared_ptr.
150      */
151     std::shared_ptr<AbilityRecord> GetUIAbilityRecordBySessionInfo(const sptr<SessionInfo> &sessionInfo);
152 
153     int32_t BackToCallerAbilityWithResult(std::shared_ptr<AbilityRecord> abilityRecord,
154         int resultCode, const Want *resultWant, int64_t callerRequestCode);
155 
156     int CloseUIAbility(const std::shared_ptr<AbilityRecord> &abilityRecord,
157         int resultCode, const Want *resultWant, bool isClearSession, bool isIndependentRecovery);
158 
159     /**
160      * Set rootSceneSession by SCB.
161      *
162      * @param rootSceneSession Indicates root scene session of SCB.
163      */
164     void SetRootSceneSession(const sptr<IRemoteObject> &rootSceneSession);
165 
166     int NotifySCBToStartUIAbility(AbilityRequest &abilityRequest);
167     int32_t NotifySCBToStartUIAbilities(std::vector<AbilityRequest> &abilityRequestList,
168         const std::string &requestKey);
169 
170     int NotifySCBToPreStartUIAbility(const AbilityRequest &abilityRequest,
171         sptr<SessionInfo> &sessionInfo);
172 
173     int32_t NotifySCBToRecoveryAfterInterception(const AbilityRequest &abilityRequest);
174 
175     /**
176      * @brief handle time out event
177      *
178      * @param msgId the msg id in ability record
179      * @param abilityRecordId the id of ability record
180      * @param isHalf is half
181      */
182     void OnTimeOut(uint32_t msgId, int64_t abilityRecordId, bool isHalf = false);
183 
184     /**
185      * @brief handle when ability died
186      *
187      * @param abilityRecord the died ability
188      */
189     void OnAbilityDied(std::shared_ptr<AbilityRecord> abilityRecord);
190 
191     /**
192      * resolve the call ipc of ability for scheduling oncall.
193      *
194      * @param abilityRequest target ability request.
195      */
196     int ResolveLocked(const AbilityRequest &abilityRequest, std::string &errMsg);
197 
198     /**
199      * Call UIAbility by SCB.
200      *
201      * @param sessionInfo the session info of the ability to be called.
202      * @param isColdStart the session of the ability is or not cold start.
203      */
204     void CallUIAbilityBySCB(const sptr<SessionInfo> &sessionInfo, bool &isColdStart);
205 
206     /**
207      * OnAcceptWantResponse.
208      *
209      * @param want the want of the ability to start.
210      * @param abilityRequest the flag of the ability to start.
211      * @return Returns ERR_OK on success, others on failure.
212      */
213     void OnAcceptWantResponse(const AAFwk::Want &want, const std::string &flag, int32_t requestId);
214 
215     /**
216      * OnStartSpecifiedProcessResponse.
217      *
218      * @param requestId target ability requestId.
219      */
220     void OnStartSpecifiedProcessResponse(const std::string &flag, int32_t requestId,
221         const std::string &callerProcessName = "");
222 
223     /**
224      * OnStartSpecifiedAbilityTimeoutResponse.
225      *
226      * @param requestId the requestId of the ability to start.
227      */
228     void OnStartSpecifiedAbilityTimeoutResponse(int32_t requestId);
229 
230     /**
231      * OnStartSpecifiedProcessTimeoutResponse.
232      *
233      * @param requestId the requestId of the ability to start.
234      */
235     void OnStartSpecifiedProcessTimeoutResponse(int32_t requestId);
236 
237     /**
238      * OnStartSpecifiedFailed.
239      *
240      * @param requestId request id of the failed request.
241      * @return Returns ERR_OK on success, others on failure.
242      */
243     void OnStartSpecifiedFailed(int32_t requestId);
244 
245     int32_t StartSpecifiedAbilityBySCB(AbilityRequest &abilityRequest);
246 
247     /**
248      * CallRequestDone, after invoke callRequest, ability will call this interface to return callee.
249      *
250      * @param abilityRecord ability's record.
251      * @param callStub ability's callee.
252      */
253     void CallRequestDone(const std::shared_ptr<AbilityRecord> &abilityRecord, const sptr<IRemoteObject> &callStub);
254 
255     /**
256      * release the connection of this call.
257      *
258      * @param connect caller callback ipc.
259      * @param element target ability name.
260      */
261     int ReleaseCallLocked(const sptr<IAbilityConnection> &connect, const AppExecFwk::ElementName &element);
262 
263     /**
264      * @brief handle when call connection died
265      *
266      * @param callRecord the died call connection
267      */
268     void OnCallConnectDied(const std::shared_ptr<CallRecord> &callRecord);
269 
270     /**
271      * Get sessionId by ability token.
272      *
273      * @param token the ability token.
274      * @return Returns sessionId on success, zero on failure.
275      */
276     int32_t GetSessionIdByAbilityToken(const sptr<IRemoteObject> &token);
277 
278     void GetActiveAbilityList(int32_t uid, std::vector<std::string> &abilityList, int32_t pid = NO_PID);
279 
280     bool PrepareTerminateAbility(const std::shared_ptr<AbilityRecord> &abilityRecord, bool isSCBCall);
281     void SetSessionHandler(const sptr<ISessionHandler> &handler);
282 
283     /**
284      * Get abilityRecord by session id.
285      *
286      * @param sessionId the session id.
287      * @return Returns abilityRecord on success, nullptr on failure.
288      */
289     std::shared_ptr<AbilityRecord> GetAbilityRecordsById(int32_t sessionId) const;
290 
291     /**
292      * Get check ability number.
293      *
294      * @param bundleName record ability info bundle name.
295      * @param abilityName record ability info ability name.
296      * @param moduleName recode ability info module name.
297      * @return Return find ability number.
298      */
299     int32_t CheckAbilityNumber(
300         const std::string &bundleName, const std::string &abilityName, const std::string &moduleName) const;
301 
302     /**
303      * If ability number more then one, send event info.
304      *
305      * @param userId record ability info user id.
306      * @param bundleName record ability info bundle name.
307      * @param abilityName record ability info ability name.
308      * @param moduleName recode ability info module name.
309      */
310     void MoreAbilityNumbersSendEventInfo(
311         int32_t userId, const std::string &bundleName, const std::string &abilityName, const std::string &moduleName);
312 
313     void OnAppStateChanged(const AppInfo &info);
314 
315     void UninstallApp(const std::string &bundleName, int32_t uid);
316 
317     void GetAbilityRunningInfos(std::vector<AbilityRunningInfo> &info, bool isPerm) const;
318 
319     /**
320      * @brief dump all abilities
321      *
322      * @param info dump result.
323      */
324     void Dump(std::vector<std::string>& info);
325 
326     /**
327      * @brief dump mission list
328      *
329      * @param info dump result.
330      */
331     void DumpMissionList(std::vector<std::string> &info, bool isClient, const std::string &args = "");
332 
333     /**
334      * @brief dump mission list by id with params
335      *
336      * @param info dump result.
337      * @param params dump params.
338      */
339     void DumpMissionListByRecordId(std::vector<std::string>& info, bool isClient, int32_t abilityRecordId,
340         const std::vector<std::string>& params);
341 
342     int MoveMissionToFront(int32_t sessionId, std::shared_ptr<StartOptions> startOptions = nullptr);
343 
344     bool IsAbilityStarted(AbilityRequest &abilityRequest, std::shared_ptr<AbilityRecord> &targetRecord);
345 
346     /**
347      * @brief Update session info.
348      * @param sessionInfos The vector of session info.
349      */
350     int32_t UpdateSessionInfoBySCB(std::list<SessionInfo> &sessionInfos, std::vector<int32_t> &sessionIds);
351 
352     int32_t RegisterStatusBarDelegate(sptr<AbilityRuntime::IStatusBarDelegate> delegate);
353 
354     bool IsCallerInStatusBar(const std::string &instanceKey);
355 
356     bool IsInStatusBar(uint32_t accessTokenId, bool isMultiInstance);
357 
358     bool IsSupportStatusBar();
359 
360     int32_t TryPrepareTerminateByPids(const std::vector<int32_t>& pids);
361 
362     int ChangeAbilityVisibility(sptr<IRemoteObject> token, bool isShow);
363 
364     int ChangeUIAbilityVisibilityBySCB(sptr<SessionInfo> sessionInfo, bool isShow);
365 
366     std::vector<std::shared_ptr<AbilityRecord>> GetAbilityRecordsByName(const AppExecFwk::ElementName &element);
367 
368     std::shared_ptr<AbilityRecord> GetAbilityRecordByToken(const sptr<IRemoteObject> &token) const;
369 
370 #ifdef SUPPORT_GRAPHICS
371     void CompleteFirstFrameDrawing(const sptr<IRemoteObject> &token);
372 #endif
373     void CompleteFirstFrameDrawing(int32_t sessionId) const;
374 
375     int32_t GetAbilityStateByPersistentId(int32_t persistentId, bool &state);
376 
377     void NotifySCBToHandleAtomicServiceException(sptr<SessionInfo> sessionInfo, int32_t errorCode,
378         const std::string& errorReason);
379 
380     int32_t CleanUIAbility(const std::shared_ptr<AbilityRecord> &abilityRecord);
381 
382     void EnableListForSCBRecovery();
383 
384     void SetKillForPermissionUpdateFlag(uint32_t accessTokenId);
385 
386     void PrepareTerminateAbilityDone(std::shared_ptr<AbilityRecord> abilityRecord, bool isTerminate);
387 
388     void TryPrepareTerminateByPidsDone(const std::string &moduleName, int32_t prepareTermination, bool isExist);
389 
390     int32_t RevokeDelegator(sptr<IRemoteObject> token);
391 
392     bool IsBundleStarting(pid_t pid);
393 
394     void RecordPidKilling(pid_t pid, const std::string &reason, bool isKillPrecedeStart);
395 
396     int32_t NotifyStartupExceptionBySCB(int32_t requestId, const std::string &reason);
397 
398 private:
399     void AddStartingPid(pid_t pid);
400     void RemoveStartingPid(pid_t pid);
401     void MarkStartingFlag(const AbilityRequest &abilityRequest);
402     int32_t GetPersistentIdByAbilityRequest(const AbilityRequest &abilityRequest, bool &reuse) const;
403     int32_t GetReusedSpecifiedPersistentId(const AbilityRequest &abilityRequest, bool &reuse) const;
404     int32_t GetReusedStandardPersistentId(const AbilityRequest &abilityRequest, bool &reuse) const;
405     int32_t GetReusedCollaboratorPersistentId(const AbilityRequest &abilityRequest, bool &reuse) const;
406     std::string GenerateProcessNameForNewProcessMode(const AppExecFwk::AbilityInfo& abilityInfo);
407     void PreCreateProcessName(AbilityRequest &abilityRequest);
408     void UpdateProcessName(const AbilityRequest &abilityRequest, std::shared_ptr<AbilityRecord> &abilityRecord);
409     void UpdateAbilityRecordLaunchReason(const AbilityRequest &abilityRequest,
410         std::shared_ptr<AbilityRecord> &abilityRecord) const;
411     void EraseAbilityRecord(const std::shared_ptr<AbilityRecord> &abilityRecord);
412     int DispatchState(const std::shared_ptr<AbilityRecord> &abilityRecord, int state);
413     int DispatchTerminate(const std::shared_ptr<AbilityRecord> &abilityRecord);
414     int DispatchBackground(const std::shared_ptr<AbilityRecord> &abilityRecord);
415     int DispatchForeground(const std::shared_ptr<AbilityRecord> &abilityRecord, bool success,
416         AbilityState state = AbilityState::INITIAL);
417     void CompleteForegroundSuccess(const std::shared_ptr<AbilityRecord> &abilityRecord);
418     void HandleLoadTimeout(const std::shared_ptr<AbilityRecord> &ability);
419     void HandleForegroundFailed(const std::shared_ptr<AbilityRecord> &ability,
420         AbilityState state = AbilityState::INITIAL);
421     void HandleForegroundTimeout(const std::shared_ptr<AbilityRecord> &ability);
422     void NotifySCBToHandleException(const std::shared_ptr<AbilityRecord> &ability, int32_t errorCode,
423         const std::string& errorReason, bool needClearCallerLink = true);
424     void MoveToBackground(const std::shared_ptr<AbilityRecord> &abilityRecord);
425     void CompleteBackground(const std::shared_ptr<AbilityRecord> &abilityRecord);
426     void PrintTimeOutLog(std::shared_ptr<AbilityRecord> ability, uint32_t msgId, bool isHalf = false);
427     void DelayCompleteTerminate(const std::shared_ptr<AbilityRecord> &abilityRecord);
428     void CompleteTerminate(const std::shared_ptr<AbilityRecord> &abilityRecord);
429     void CompleteTerminateLocked(const std::shared_ptr<AbilityRecord> &abilityRecord);
430     bool IsContainsAbilityInner(const sptr<IRemoteObject> &token) const;
431     bool CheckProperties(const std::shared_ptr<AbilityRecord> &abilityRecord, const AbilityRequest &abilityRequest,
432         AppExecFwk::LaunchMode launchMode) const;
433     void NotifyAbilityToken(const sptr<IRemoteObject> &token, const AbilityRequest &abilityRequest) const;
434     void PrepareCloseUIAbility(std::shared_ptr<AbilityRecord> abilityRecord,
435         int resultCode, const Want *resultWant, bool isClearSession);
436     int CloseUIAbilityInner(std::shared_ptr<AbilityRecord> abilityRecord);
437     int32_t BackToCallerAbilityWithResultLocked(sptr<SessionInfo> currentSessionInfo,
438         std::shared_ptr<AbilityRecord> callerAbilityRecord);
439 
440     // byCall
441     int CallAbilityLocked(const AbilityRequest &abilityRequest, std::string &errMsg);
442     sptr<SessionInfo> CreateSessionInfo(const AbilityRequest &abilityRequest, int32_t requestId) const;
443     int NotifySCBPendingActivation(sptr<SessionInfo> &sessionInfo,
444         const AbilityRequest &abilityRequest, std::string &errMsg);
445     int32_t BatchNotifySCBPendingActivations(const AbilitiesRequest &abilitiesRequest);
446     void HandleAbilitiesRequestDone(int32_t requestId, int32_t requestListId, sptr<SessionInfo> sessionInfo);
447     bool IsHookModule(const AbilityRequest &abilityRequest) const;
448     int ResolveAbility(const std::shared_ptr<AbilityRecord> &targetAbility, const AbilityRequest &abilityRequest) const;
449     std::vector<std::shared_ptr<AbilityRecord>> GetAbilityRecordsByNameInner(const AppExecFwk::ElementName &element);
450     void HandleForegroundCollaborate(const AbilityRequest &abilityRequest,
451         std::shared_ptr<AbilityRecord> abilityRecord);
452 
453     int32_t MoveAbilityToFront(const SpecifiedRequest &specifiedRequest,
454         const std::shared_ptr<AbilityRecord> abilityRecord, std::shared_ptr<AbilityRecord> callerAbility);
455     int SendSessionInfoToSCB(std::shared_ptr<AbilityRecord> &callerAbility, sptr<SessionInfo> &sessionInfo);
456     int32_t StartAbilityBySpecifed(const SpecifiedRequest &specifiedRequest,
457         std::shared_ptr<AbilityRecord> callerAbility);
458 
459     void SetLastExitReason(std::shared_ptr<AbilityRecord> &abilityRecord) const;
460     void SetReceiverInfo(const AbilityRequest &abilityRequest, std::shared_ptr<AbilityRecord> &abilityRecord) const;
461 
462     /**
463      * @brief Execute PrepareTerminateApp when it is implemented
464      *
465      * @param pid process id
466      * @param tokens the tokens of ability records
467      * @return Returns the tokens that still need to execute PrepareTerminate.
468      */
469     std::vector<sptr<IRemoteObject>> PrepareTerminateAppAndGetRemaining(
470         int32_t pid, const std::vector<sptr<IRemoteObject>> &tokens);
471 
472     bool GetContentAndTypeId(uint32_t msgId, std::string &msgContent, int &typeId) const;
473     void SendAbilityEvent(const AppExecFwk::AbilityInfo &abilityInfo, const std::string &reason) const;
474 
475     bool CheckSessionInfo(sptr<SessionInfo> sessionInfo) const;
476     std::shared_ptr<AbilityRecord> CreateAbilityRecord(AbilityRequest &abilityRequest,
477         sptr<SessionInfo> sessionInfo) const;
478     void AddCallerRecord(AbilityRequest &abilityRequest, sptr<SessionInfo> sessionInfo,
479         std::shared_ptr<AbilityRecord> uiAbilityRecord) const;
480     void SendKeyEvent(const AbilityRequest &abilityRequest) const;
481     bool CheckPid(const std::shared_ptr<AbilityRecord> abilityRecord, const int32_t pid) const;
482     std::shared_ptr<StatusBarDelegateManager> GetStatusBarDelegateManager();
483     int32_t DoProcessAttachment(std::shared_ptr<AbilityRecord> abilityRecord);
484     void BatchCloseUIAbility(const std::unordered_set<std::shared_ptr<AbilityRecord>>& abilitySet);
485     void TerminateSession(std::shared_ptr<AbilityRecord> abilityRecord);
486     int StartWithPersistentIdByDistributed(const AbilityRequest &abilityRequest, int32_t persistentId);
487     void CheckCallerFromBackground(std::shared_ptr<AbilityRecord> callerAbility, sptr<SessionInfo> &sessionInfo);
488     int32_t DoCallerProcessAttachment(std::shared_ptr<AbilityRecord> abilityRecord);
489     int32_t DoCallerProcessDetachment(std::shared_ptr<AbilityRecord> abilityRecord);
490     std::shared_ptr<AbilityRecord> GenerateAbilityRecord(AbilityRequest &abilityRequest, sptr<SessionInfo> sessionInfo,
491         bool &isColdStart);
492     std::shared_ptr<AbilityRecord> FindRecordFromTmpMap(const AbilityRequest &abilityRequest);
493     void PostCallTimeoutTask(int32_t requestId);
494     bool AddStartCallerTimestamp(int32_t callerUid);
495     std::shared_ptr<AbilityRecord> FindRecordFromSessionMap(const AbilityRequest &abilityRequest);
496     void AddSpecifiedRequest(std::shared_ptr<SpecifiedRequest> request);
497     void StartSpecifiedRequest(SpecifiedRequest &specifiedRequest);
498     std::shared_ptr<SpecifiedRequest> PopAndGetNextSpecified(int32_t requestId);
499     bool IsSpecifiedModuleLoaded(const AbilityRequest &abilityRequest, bool &isDebug);
500     bool HandleStartSpecifiedCold(AbilityRequest &abilityRequest, sptr<SessionInfo> sessionInfo, uint32_t sceneFlag);
501     bool HandleColdAcceptWantDone(const AAFwk::Want &want, const std::string &flag,
502         const SpecifiedRequest &specifiedRequest);
503     void HandleLegacyAcceptWantDone(SpecifiedRequest &specifiedRequest,
504         const std::string &flag, const AAFwk::Want &want);
505     std::shared_ptr<SpecifiedRequest> GetSpecifiedRequest(int32_t requestId);
506     bool CheckPrepareTerminateTokens(const std::vector<sptr<IRemoteObject>> &tokens,
507         uint32_t &tokenId, std::map<std::string, std::vector<sptr<IRemoteObject>>> &tokensPerModuleName);
508     void HandleAbilityStageOnPrepareTerminationTimeout(int32_t pid, const std::string &moduleName,
509         const std::vector<sptr<IRemoteObject>> &tokens);
510     std::vector<sptr<IRemoteObject>> PrepareTerminateAppAndGetRemainingInner(int32_t pid, const std::string &moduleName,
511         const std::vector<sptr<IRemoteObject>> &tokens);
512     void CancelPrepareTerminate(std::shared_ptr<AbilityRecord> abilityRecord);
513     bool UpdateSpecifiedFlag(std::shared_ptr<AbilityRecord> abilityRequest, const std::string &flag);
514     bool ProcessColdStartBranch(AbilityRequest &abilityRequest, sptr<SessionInfo> sessionInfo,
515         std::shared_ptr<AbilityRecord> uiAbilityRecord, bool isColdStart);
516     bool TryProcessHookModule(SpecifiedRequest &specifiedRequest, bool isHookModule);
517     bool IsStartSpecifiedProcessRequest(const AbilityRequest &abilityRequest);
518     int32_t StartSpecifiedProcessRequest(const AbilityRequest &abilityRequest,
519         std::shared_ptr<AbilitiesRequest> abilitiesRequest);
520     int32_t HandleUIAbilityRequestList(std::vector<AbilityRequest> &abilityRequestList);
521     void HandleAbilitiesNormalSessionInfo(AbilityRequest &abilityRequest,
522         std::shared_ptr<AbilitiesRequest> abilitiesRequest, int32_t requestId);
523     void RemoveInstanceKey(const AbilityRequest &abilityRequest) const;
524 
525     int32_t userId_ = -1;
526     mutable ffrt::mutex sessionLock_;
527     std::unordered_map<int32_t, std::shared_ptr<AbilityRecord>> sessionAbilityMap_;
528     std::unordered_map<int32_t, std::shared_ptr<AbilityRecord>> lowMemKillAbilityMap_;
529     std::unordered_map<int32_t, std::shared_ptr<AbilityRecord>> tmpAbilityMap_;
530     std::unordered_map<std::shared_ptr<AbilityRecord>, std::list<AbilityRequest>> callRequestCache_;
531     std::list<std::shared_ptr<AbilityRecord>> terminateAbilityList_;
532     sptr<IRemoteObject> rootSceneSession_;
533     sptr<ISessionHandler> handler_;
534     ffrt::mutex statusBarDelegateManagerLock_;
535     std::shared_ptr<StatusBarDelegateManager> statusBarDelegateManager_;
536     bool isSCBRecovery_ = false;
537     std::unordered_set<int32_t> coldStartInSCBRecovery_;
538 
539     ffrt::mutex startUIAbilityCallerTimestampsLock_;
540     std::map<int32_t, std::vector<int64_t>> startUIAbilityCallerTimestamps_;
541 
542     std::map<std::string, std::list<std::shared_ptr<SpecifiedRequest>>> specifiedRequestList_;
543 
544     struct PrepareTerminateByPidRecord {
545         pid_t pid_;
546         std::string moduleName_;
547         std::atomic_bool isTryPrepareTerminateByPidsDone_;
548         int32_t prepareTermination_;
549         bool isExist_;
550 
PrepareTerminateByPidRecordPrepareTerminateByPidRecord551         PrepareTerminateByPidRecord(pid_t pid, const std::string &moduleName, bool done,
552             int32_t prepareTermination, bool isExist) : pid_(pid), moduleName_(moduleName),
553             isTryPrepareTerminateByPidsDone_(done), prepareTermination_(prepareTermination),
554             isExist_(isExist) {}
555     };
556     std::mutex isTryPrepareTerminateByPidsDoneMutex_;
557     std::condition_variable isTryPrepareTerminateByPidsCv_;
558     std::vector<std::shared_ptr<PrepareTerminateByPidRecord>> prepareTerminateByPidRecords_;
559     std::unordered_map<int32_t, std::shared_ptr<AbilityRecord>> hookSpecifiedMap_;
560 
561     std::map<int32_t, std::shared_ptr<AbilitiesRequest>> abilitiesRequestMap_;
562     std::mutex startingPidsMutex_;
563     std::vector<pid_t> startingPids_;
564 };
565 }  // namespace AAFwk
566 }  // namespace OHOS
567 #endif  // OHOS_ABILITY_RUNTIME_UI_ABILITY_LIFECYCLE_MANAGER_H