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