• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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_ABILITY_RECORD_H
17 #define OHOS_ABILITY_RUNTIME_ABILITY_RECORD_H
18 
19 #include <ctime>
20 #include <functional>
21 #include <list>
22 #include <memory>
23 #include <vector>
24 #include <set>
25 #include <utility>
26 #include "cpp/mutex.h"
27 #include "cpp/condition_variable.h"
28 
29 #include "ability_connect_callback_interface.h"
30 #include "ability_info.h"
31 #include "ability_start_setting.h"
32 #include "ability_state.h"
33 #include "ability_token_stub.h"
34 #include "app_scheduler.h"
35 #include "application_info.h"
36 #include "bundlemgr/bundle_mgr_interface.h"
37 #include "call_container.h"
38 #include "exit_reason.h"
39 #include "ipc_skeleton.h"
40 #include "lifecycle_deal.h"
41 #include "lifecycle_state_info.h"
42 #include "session_info.h"
43 #include "ui_extension_window_command.h"
44 #include "uri.h"
45 #include "want.h"
46 #include "window_config.h"
47 #ifdef SUPPORT_GRAPHICS
48 #include "ability_window_configuration.h"
49 #include "resource_manager.h"
50 #include "start_options.h"
51 #include "window_manager_service_handler.h"
52 #endif
53 
54 namespace OHOS {
55 namespace AAFwk {
56 using Closure = std::function<void()>;
57 
58 class AbilityRecord;
59 class ConnectionRecord;
60 class CallContainer;
61 struct EventInfo;
62 
63 constexpr const char* ABILITY_TOKEN_NAME = "AbilityToken";
64 constexpr const char* LAUNCHER_BUNDLE_NAME = "com.ohos.launcher";
65 
66 /**
67  * @class Token
68  * Token is identification of ability and used to interact with kit and wms.
69  */
70 class Token : public AbilityTokenStub {
71 public:
72     explicit Token(std::weak_ptr<AbilityRecord> abilityRecord);
73     virtual ~Token();
74 
75     std::shared_ptr<AbilityRecord> GetAbilityRecord() const;
76     static std::shared_ptr<AbilityRecord> GetAbilityRecordByToken(const sptr<IRemoteObject> &token);
77 
78 private:
79     std::weak_ptr<AbilityRecord> abilityRecord_;  // ability of this token
80 };
81 
82 /**
83  * @class AbilityResult
84  * Record requestCode of for-result start mode and result.
85  */
86 class AbilityResult {
87 public:
88     AbilityResult() = default;
AbilityResult(int requestCode,int resultCode,const Want & resultWant)89     AbilityResult(int requestCode, int resultCode, const Want &resultWant)
90         : requestCode_(requestCode), resultCode_(resultCode), resultWant_(resultWant)
91     {}
~AbilityResult()92     virtual ~AbilityResult()
93     {}
94 
95     int requestCode_ = -1;  // requestCode of for-result start mode
96     int resultCode_ = -1;   // resultCode of for-result start mode
97     Want resultWant_;       // for-result start mode ability will send the result to caller
98 };
99 
100 /**
101  * @class SystemAbilityCallerRecord
102  * Record system caller ability of for-result start mode and result.
103  */
104 class SystemAbilityCallerRecord {
105 public:
SystemAbilityCallerRecord(std::string & srcAbilityId,const sptr<IRemoteObject> & callerToken)106     SystemAbilityCallerRecord(std::string &srcAbilityId, const sptr<IRemoteObject> &callerToken)
107         : srcAbilityId_(srcAbilityId), callerToken_(callerToken)
108     {}
~SystemAbilityCallerRecord()109     virtual ~SystemAbilityCallerRecord()
110     {}
111 
GetSrcAbilityId()112     std::string GetSrcAbilityId()
113     {
114         return srcAbilityId_;
115     }
GetCallerToken()116     const sptr<IRemoteObject> GetCallerToken()
117     {
118         return callerToken_;
119     }
SetResult(Want & want,int resultCode)120     void SetResult(Want &want, int resultCode)
121     {
122         resultWant_ = want;
123         resultCode_ = resultCode;
124     }
GetResultWant()125     Want &GetResultWant()
126     {
127         return resultWant_;
128     }
GetResultCode()129     int &GetResultCode()
130     {
131         return resultCode_;
132     }
133     /**
134      * Set result to system ability.
135      *
136      */
137     void SetResultToSystemAbility(std::shared_ptr<SystemAbilityCallerRecord> callerSystemAbilityRecord,
138         Want &resultWant, int resultCode);
139     /**
140      * Send result to system ability.
141      *
142      */
143     void SendResultToSystemAbility(int requestCode,
144         const std::shared_ptr<SystemAbilityCallerRecord> callerSystemAbilityRecord,
145         int32_t callerUid, uint32_t accessToken, bool schedulerdied);
146 
147 private:
148     std::string srcAbilityId_;
149     sptr<IRemoteObject> callerToken_;
150     Want resultWant_;
151     int resultCode_ = -1;
152 };
153 
154 /**
155  * @struct CallerAbilityInfo
156  * caller ability info.
157  */
158 struct CallerAbilityInfo {
159 public:
160     int32_t callerTokenId = 0;
161     int32_t callerUid = 0;
162     int32_t callerPid = 0;
163     int32_t callerAppCloneIndex = 0;
164     std::string callerNativeName;
165     std::string callerBundleName;
166     std::string callerAbilityName;
167 };
168 
169 /**
170  * @class CallerRecord
171  * Record caller ability of for-result start mode and result.
172  */
173 class CallerRecord {
174 public:
175     CallerRecord() = default;
176     CallerRecord(int requestCode, std::weak_ptr<AbilityRecord> caller);
CallerRecord(int requestCode,std::shared_ptr<SystemAbilityCallerRecord> saCaller)177     CallerRecord(int requestCode, std::shared_ptr<SystemAbilityCallerRecord> saCaller) : requestCode_(requestCode),
178         saCaller_(saCaller)
179     {}
~CallerRecord()180     virtual ~CallerRecord()
181     {}
182 
GetRequestCode()183     int GetRequestCode()
184     {
185         return requestCode_;
186     }
GetCaller()187     std::shared_ptr<AbilityRecord> GetCaller()
188     {
189         return caller_.lock();
190     }
GetSaCaller()191     std::shared_ptr<SystemAbilityCallerRecord> GetSaCaller()
192     {
193         return saCaller_;
194     }
GetCallerInfo()195     std::shared_ptr<CallerAbilityInfo> GetCallerInfo()
196     {
197         return callerInfo_;
198     }
IsHistoryRequestCode(int32_t requestCode)199     bool IsHistoryRequestCode(int32_t requestCode)
200     {
201         return requestCodeSet_.count(requestCode) > 0;
202     }
RemoveHistoryRequestCode(int32_t requestCode)203     void RemoveHistoryRequestCode(int32_t requestCode)
204     {
205         requestCodeSet_.erase(requestCode);
206     }
AddHistoryRequestCode(int32_t requestCode)207     void AddHistoryRequestCode(int32_t requestCode)
208     {
209         requestCodeSet_.insert(requestCode);
210     }
SetRequestCodeSet(const std::set<int32_t> & requestCodeSet)211     void SetRequestCodeSet(const std::set<int32_t> &requestCodeSet)
212     {
213         requestCodeSet_ = requestCodeSet;
214     }
GetRequestCodeSet()215     std::set<int32_t> GetRequestCodeSet()
216     {
217         return requestCodeSet_;
218     }
219 
220 private:
221     int requestCode_ = -1;  // requestCode of for-result start mode
222     std::weak_ptr<AbilityRecord> caller_;
223     std::shared_ptr<SystemAbilityCallerRecord> saCaller_ = nullptr;
224     std::shared_ptr<CallerAbilityInfo> callerInfo_ = nullptr;
225     std::set<int32_t> requestCodeSet_;
226 };
227 
228 /**
229  * @class AbilityRequest
230  * Wrap parameters of starting ability.
231  */
232 enum AbilityCallType {
233     INVALID_TYPE = 0,
234     CALL_REQUEST_TYPE,
235     START_OPTIONS_TYPE,
236     START_SETTINGS_TYPE,
237     START_EXTENSION_TYPE,
238 };
239 
240 enum CollaboratorType {
241     DEFAULT_TYPE = 0,
242     RESERVE_TYPE,
243     OTHERS_TYPE
244 };
245 
246 struct AbilityRequest {
247     bool restart = false;
248     bool startRecent = false;
249     bool uriReservedFlag = false;
250     bool isFromIcon = false;
251     bool isShellCall = false;
252     // ERMS embedded atomic service
253     bool isQueryERMS = false;
254     bool isEmbeddedAllowed = false;
255     bool callSpecifiedFlagTimeout = false;
256     bool hideStartWindow = false;
257     int32_t restartCount = -1;
258     int32_t uid = 0;
259     int32_t collaboratorType = CollaboratorType::DEFAULT_TYPE;
260     int32_t callerTokenRecordId = -1;
261     int32_t userId = -1;
262     uint32_t callerAccessTokenId = -1;
263     uint32_t specifyTokenId = 0;
264     int callerUid = -1;         // call ability
265     int requestCode = -1;
266     AbilityCallType callType = AbilityCallType::INVALID_TYPE;           // call ability
267     int64_t restartTime = 0;
268     sptr<IRemoteObject> callerToken = nullptr;          // call ability
269     sptr<IRemoteObject> asCallerSourceToken = nullptr;          // call ability
270     sptr<IAbilityConnection> connect = nullptr;
271     sptr<IRemoteObject> abilityInfoCallback = nullptr;
272     sptr<SessionInfo> sessionInfo;
273     std::shared_ptr<AbilityStartSetting> startSetting = nullptr;
274     std::shared_ptr<ProcessOptions> processOptions = nullptr;
275     std::shared_ptr<StartWindowOption> startWindowOption = nullptr;
276     std::vector<AppExecFwk::SupportWindowMode> supportWindowModes;
277     AppExecFwk::ExtensionAbilityType extensionType = AppExecFwk::ExtensionAbilityType::UNSPECIFIED;
278     AppExecFwk::ExtensionProcessMode extensionProcessMode = AppExecFwk::ExtensionProcessMode::UNDEFINED;
279     std::string specifiedFlag;
280     std::string customProcess;
281     std::string reservedBundleName;
282     std::string appId;
283     std::string startTime;
284     Want want;
285     AppExecFwk::AbilityInfo abilityInfo;
286     AppExecFwk::ApplicationInfo appInfo;
287     StartOptions startOptions;
IsContinuationAbilityRequest288     std::pair<bool, LaunchReason> IsContinuation() const
289     {
290         auto flags = want.GetFlags();
291         if ((flags & Want::FLAG_ABILITY_CONTINUATION) == Want::FLAG_ABILITY_CONTINUATION) {
292             return {true, LaunchReason::LAUNCHREASON_CONTINUATION};
293         }
294         if ((flags & Want::FLAG_ABILITY_PREPARE_CONTINUATION) == Want::FLAG_ABILITY_PREPARE_CONTINUATION) {
295             return {true, LaunchReason::LAUNCHREASON_PREPARE_CONTINUATION};
296         }
297         return {false, LaunchReason::LAUNCHREASON_UNKNOWN};
298     }
299 
IsAcquireShareDataAbilityRequest300     bool IsAcquireShareData() const
301     {
302         return want.GetBoolParam(Want::PARAM_ABILITY_ACQUIRE_SHARE_DATA, false);
303     }
304 
IsAppRecoveryAbilityRequest305     bool IsAppRecovery() const
306     {
307         return want.GetBoolParam(Want::PARAM_ABILITY_RECOVERY_RESTART, false);
308     }
309 
IsCallTypeAbilityRequest310     bool IsCallType(const AbilityCallType & type) const
311     {
312         return (callType == type);
313     }
314 
DumpAbilityRequest315     void Dump(std::vector<std::string> &state)
316     {
317         std::string dumpInfo = "      want [" + want.ToUri() + "]";
318         state.push_back(dumpInfo);
319         dumpInfo = "      app name [" + abilityInfo.applicationName + "]";
320         state.push_back(dumpInfo);
321         dumpInfo = "      main name [" + abilityInfo.name + "]";
322         state.push_back(dumpInfo);
323         dumpInfo = "      request code [" + std::to_string(requestCode) + "]";
324         state.push_back(dumpInfo);
325     }
326 
327     void Voluation(const Want &srcWant, int srcRequestCode,
328         const sptr<IRemoteObject> &srcCallerToken, const std::shared_ptr<AbilityStartSetting> srcStartSetting = nullptr,
329         int srcCallerUid = -1)
330     {
331         want = srcWant;
332         requestCode = srcRequestCode;
333         callerToken = srcCallerToken;
334         startSetting = srcStartSetting;
335         callerUid = srcCallerUid == -1 ? IPCSkeleton::GetCallingUid() : srcCallerUid;
336     }
337 };
338 
339 // new version
340 enum ResolveResultType {
341     OK_NO_REMOTE_OBJ = 0,
342     OK_HAS_REMOTE_OBJ,
343     NG_INNER_ERROR,
344 };
345 
346 enum class AbilityWindowState {
347     FOREGROUND = 0,
348     BACKGROUND,
349     TERMINATE,
350     FOREGROUNDING,
351     BACKGROUNDING,
352     TERMINATING
353 };
354 
355 enum class AbilityVisibilityState {
356     INITIAL = 0,
357     FOREGROUND_HIDE,
358     FOREGROUND_SHOW,
359     UNSPECIFIED,
360 };
361 
362 struct LaunchDebugInfo {
363 public:
364     void Update(const Want &want);
365 
366     bool isDebugAppSet = false;
367     bool isNativeDebugSet = false;
368     bool isPerfCmdSet = false;
369     bool debugApp = false;
370     bool nativeDebug = false;
371     std::string perfCmd;
372 };
373 
374 /**
375  * @class AbilityRecord
376  * AbilityRecord records ability info and states and used to schedule ability life.
377  */
378 class AbilityRecord : public std::enable_shared_from_this<AbilityRecord> {
379 public:
380     AbilityRecord(const Want &want, const AppExecFwk::AbilityInfo &abilityInfo,
381         const AppExecFwk::ApplicationInfo &applicationInfo, int requestCode = -1);
382 
383     virtual ~AbilityRecord();
384 
385     /**
386      * CreateAbilityRecord.
387      *
388      * @param abilityRequest,create ability record.
389      * @return Returns ability record ptr.
390      */
391     static std::shared_ptr<AbilityRecord> CreateAbilityRecord(const AbilityRequest &abilityRequest);
392 
393     /**
394      * Init ability record.
395      *
396      * @return Returns true on success, others on failure.
397      */
398     bool Init();
399 
400     /**
401      * load UI ability.
402      *
403      */
404     void LoadUIAbility();
405 
406     /**
407      * load ability.
408      *
409      * @return Returns ERR_OK on success, others on failure.
410      */
411     int LoadAbility(bool isShellCall = false, bool isStartupHide = false);
412 
413     /**
414      * foreground the ability.
415      *
416      */
417     void ForegroundAbility(uint32_t sceneFlag = 0, bool hasLastWant = false);
418     void ForegroundUIExtensionAbility(uint32_t sceneFlag = 0);
419 
420     /**
421      * process request of foregrounding the ability.
422      *
423      */
424     void ProcessForegroundAbility(
425         uint32_t tokenId, uint32_t sceneFlag = 0, bool isShellCall = false, bool isStartupHide = false);
426 
427      /**
428      * post foreground timeout task for ui ability.
429      *
430      */
431     void PostForegroundTimeoutTask();
432 
433     void RemoveForegroundTimeoutTask();
434 
435     void RemoveLoadTimeoutTask();
436 
437     void PostUIExtensionAbilityTimeoutTask(uint32_t messageId);
438 
439     /**
440      * move the ability to back ground.
441      *
442      * @param task timeout task.
443      */
444     void BackgroundAbility(const Closure &task);
445 
446     /**
447      * prepare terminate ability.
448      *
449      * @param isSCBCall, if the call is from SCB.
450      * @return Returns true on stop terminating; returns false on terminate.
451      */
452     bool PrepareTerminateAbility(bool isSCBCall);
453 
454     /**
455      * prepare terminate ability done.
456      *
457      * @param isTerminate, the result of the onPrepareToTerminate/onPrepareToTerminateAsync.
458      */
459     void PrepareTerminateAbilityDone(bool isTerminate);
460 
461     /**
462      * terminate ability.
463      *
464      * @return Returns ERR_OK on success, others on failure.
465      */
466     int TerminateAbility();
467 
468     /**
469      * get ability's info.
470      *
471      * @return ability info.
472      */
473     const AppExecFwk::AbilityInfo &GetAbilityInfo() const;
474 
475     /**
476      * get application's info.
477      *
478      * @return application info.
479      */
480     const AppExecFwk::ApplicationInfo &GetApplicationInfo() const;
481 
482     /**
483      * set ability's state.
484      *
485      * @param state, ability's state.
486      */
487     void SetAbilityState(AbilityState state);
488 
489     bool GetAbilityForegroundingFlag() const;
490 
491     void SetAbilityForegroundingFlag();
492 
493     /**
494      * get ability's state.
495      *
496      * @return ability state.
497      */
498     AbilityState GetAbilityState() const;
499 
500     /**
501      * get ability's windowconfig.
502      *
503      * @return ability windowconfig.
504      */
505     WindowConfig GetAbilityWindowConfig() const;
506 
507     bool IsForeground() const;
508 
509     AbilityVisibilityState GetAbilityVisibilityState() const;
510     void SetAbilityVisibilityState(AbilityVisibilityState state);
511 
512     void UpdateAbilityVisibilityState();
513 
514     /**
515      * set ability scheduler for accessing ability thread.
516      *
517      * @param scheduler , ability scheduler.
518      */
519     void SetScheduler(const sptr<IAbilityScheduler> &scheduler);
520 
GetScheduler()521     inline sptr<IAbilityScheduler> GetScheduler() const
522     {
523         return scheduler_;
524     }
525 
526     sptr<SessionInfo> GetSessionInfo() const;
527 
528     /**
529      * get ability's token.
530      *
531      * @return ability's token.
532      */
533     sptr<Token> GetToken() const;
534 
535     /**
536      * set ability's previous ability record.
537      *
538      * @param abilityRecord , previous ability record
539      */
540     void SetPreAbilityRecord(const std::shared_ptr<AbilityRecord> &abilityRecord);
541 
542     /**
543      * get ability's previous ability record.
544      *
545      * @return previous ability record
546      */
547     std::shared_ptr<AbilityRecord> GetPreAbilityRecord() const;
548 
549     /**
550      * set ability's next ability record.
551      *
552      * @param abilityRecord , next ability record
553      */
554     void SetNextAbilityRecord(const std::shared_ptr<AbilityRecord> &abilityRecord);
555 
556     /**
557      * get ability's previous ability record.
558      *
559      * @return previous ability record
560      */
561     std::shared_ptr<AbilityRecord> GetNextAbilityRecord() const;
562 
563     /**
564      * check whether the ability is ready.
565      *
566      * @return true : ready ,false: not ready
567      */
568     bool IsReady() const;
569 
570     void UpdateRecoveryInfo(bool hasRecoverInfo);
571 
572     bool GetRecoveryInfo();
573 
574 #ifdef SUPPORT_SCREEN
575     /**
576      * check whether the ability 's window is attached.
577      *
578      * @return true : attached ,false: not attached
579      */
580     bool IsWindowAttached() const;
581 
IsStartingWindow()582     inline bool IsStartingWindow() const
583     {
584         return isStartingWindow_;
585     }
586 
SetStartingWindow(bool isStartingWindow)587     inline void SetStartingWindow(bool isStartingWindow)
588     {
589         isStartingWindow_ = isStartingWindow;
590     }
591 
SetKillReason(const std::string & reason)592     inline void SetKillReason(const std::string &reason)
593     {
594         killReason_ = reason;
595     }
596 
GetKillReason()597     inline std::string GetKillReason()
598     {
599         return killReason_;
600     }
601 
SetIsKillPrecedeStart(bool isKillPrecedeStart)602     inline void SetIsKillPrecedeStart(bool isKillPrecedeStart)
603     {
604         isKillPrecedeStart_.store(isKillPrecedeStart);
605     }
606 
IsKillPrecedeStart()607     inline bool IsKillPrecedeStart()
608     {
609         return isKillPrecedeStart_.load();
610     }
611 
612     void PostCancelStartingWindowHotTask();
613 
614     /**
615      * process request of foregrounding the ability.
616      *
617      */
618     void ProcessForegroundAbility(bool isRecent, const AbilityRequest &abilityRequest,
619         std::shared_ptr<StartOptions> &startOptions, const std::shared_ptr<AbilityRecord> &callerAbility,
620         uint32_t sceneFlag = 0);
621 
622     void ProcessForegroundAbility(const std::shared_ptr<AbilityRecord> &callerAbility, bool needExit = true,
623         uint32_t sceneFlag = 0);
624     void NotifyAnimationFromTerminatingAbility() const;
625     void NotifyAnimationFromMinimizeAbility(bool& animaEnabled);
626 
627     bool ReportAtomicServiceDrawnCompleteEvent();
628     void SetCompleteFirstFrameDrawing(const bool flag);
629     bool IsCompleteFirstFrameDrawing() const;
630     bool GetColdStartFlag();
631     void SetColdStartFlag(bool isColdStart);
632 #endif
633 
634     /**
635      * check whether the ability is launcher.
636      *
637      * @return true : launcher ,false: not launcher
638      */
639     bool IsLauncherAbility() const;
640 
641     /**
642      * check whether the ability is terminating.
643      *
644      * @return true : yes ,false: not
645      */
646     bool IsTerminating() const;
647 
648     /**
649      * set the ability is terminating.
650      *
651      */
652     void SetTerminatingState();
653 
654     /**
655      * set the ability is new want flag.
656      *
657      * @return isNewWant
658      */
659     void SetIsNewWant(bool isNewWant);
660 
661     /**
662      * check whether the ability is new want flag.
663      *
664      * @return true : yes ,false: not
665      */
666     bool IsNewWant() const;
667 
668     /**
669      * check whether the ability is created by connect ability mode.
670      *
671      * @return true : yes ,false: not
672      */
673     bool IsCreateByConnect() const;
674 
675     /**
676      * set the ability is created by connect ability mode.
677      *
678      */
679     void SetCreateByConnectMode(bool isCreatedByConnect = true);
680 
681     /**
682      * active the ability.
683      *
684      */
685     virtual void Activate();
686 
687     /**
688      * inactive the ability.
689      *
690      */
691     virtual void Inactivate();
692 
693     /**
694      * terminate the ability.
695      *
696      */
697     void Terminate(const Closure &task);
698 
699     /**
700      * connect the ability.
701      *
702      */
703     void ConnectAbility();
704 
705     /**
706      * connect the ability with want.
707      *
708      */
709     void ConnectAbilityWithWant(const Want &want);
710 
711     /**
712      * disconnect the ability.
713      *
714      */
715     void DisconnectAbility();
716 
717     /**
718      * disconnect the ability with want
719      *
720      */
721     void DisconnectAbilityWithWant(const Want &want);
722 
723     /**
724      * Command the ability.
725      *
726      */
727     void CommandAbility();
728 
729     void CommandAbilityWindow(const sptr<SessionInfo> &sessionInfo, WindowCommand winCmd);
730 
731     /**
732      * save ability state.
733      *
734      */
735     void SaveAbilityState();
736     void SaveAbilityState(const PacMap &inState);
737     void SaveAbilityWindowConfig(const WindowConfig &windowConfig);
738 
739     /**
740      * restore ability state.
741      *
742      */
743     void RestoreAbilityState();
744 
745     /**
746      * notify top active ability updated.
747      *
748      */
749     void TopActiveAbilityChanged(bool flag);
750 
751     /**
752      * set the want for start ability.
753      *
754      */
755     void SetWant(const Want &want);
756 
757     /**
758      * get the want for start ability.
759      *
760      */
761     Want GetWant() const;
762 
763     /**
764      * remove signature info of want.
765      *
766      */
767     void RemoveSignatureInfo();
768 
769     /**
770      * remove specified wantParam for start ability.
771      *
772      */
773     void RemoveSpecifiedWantParam(const std::string &key);
774 
775     /**
776      * get request code of the ability to start.
777      *
778      */
779     int GetRequestCode() const;
780 
781     /**
782      * set the result object of the ability which one need to be terminated.
783      *
784      */
785     void SetResult(const std::shared_ptr<AbilityResult> &result);
786 
787     /**
788      * get the result object of the ability which one need to be terminated.
789      *
790      */
791     std::shared_ptr<AbilityResult> GetResult() const;
792 
793     /**
794      * send result object to caller ability thread.
795      *
796      */
797     void SendResult(bool isSandboxApp, uint32_t tokeId);
798 
799     /**
800      * send result object to caller ability thread.
801      *
802      */
803     void SendResultByBackToCaller(const std::shared_ptr<AbilityResult> &result);
804 
805     /**
806      * send result object to caller ability thread for sandbox app file saving.
807      */
808     void SendSandboxSavefileResult(const Want &want, int resultCode, int requestCode);
809 
810     /**
811      * send result object to caller ability.
812      *
813      */
814     void SendResultToCallers(bool schedulerdied = false);
815 
816     /**
817      * save result object to caller ability.
818      *
819      */
820     void SaveResultToCallers(const int resultCode, const Want *resultWant);
821 
822     std::shared_ptr<AbilityRecord> GetCallerByRequestCode(int32_t requestCode, int32_t pid);
823 
824     /**
825      * save result to caller ability.
826      *
827      */
828     void SaveResult(int resultCode, const Want *resultWant, std::shared_ptr<CallerRecord> caller);
829 
830     bool NeedConnectAfterCommand();
831 
832     /**
833      * add connect record to the list.
834      *
835      */
836     void AddConnectRecordToList(const std::shared_ptr<ConnectionRecord> &connRecord);
837 
838     /**
839      * get the list of connect record.
840      *
841      */
842     std::list<std::shared_ptr<ConnectionRecord>> GetConnectRecordList() const;
843 
844     /**
845      * get the list of connect record.
846      *
847      */
848     std::list<std::shared_ptr<ConnectionRecord>> GetConnectingRecordList();
849 
850     /**
851      * get the count of In Progress record.
852      *
853      */
854     uint32_t GetInProgressRecordCount();
855     /**
856      * remove the connect record from list.
857      *
858      */
859     void RemoveConnectRecordFromList(const std::shared_ptr<ConnectionRecord> &connRecord);
860 
861     /**
862      * check whether connect list is empty.
863      *
864      */
865     bool IsConnectListEmpty();
866 
867     size_t GetConnectedListSize();
868 
869     size_t GetConnectingListSize();
870 
871     void RemoveCallerRequestCode(std::shared_ptr<AbilityRecord> callerAbilityRecord, int32_t requestCode);
872 
873     /**
874      * add caller record
875      *
876      */
877     void AddCallerRecord(const sptr<IRemoteObject> &callerToken, int requestCode, const Want &want,
878         std::string srcAbilityId = "", uint32_t callingTokenId = 0);
879 
880     /**
881      * get caller record to list.
882      *
883      */
884     std::list<std::shared_ptr<CallerRecord>> GetCallerRecordList() const;
885     std::shared_ptr<AbilityRecord> GetCallerRecord() const;
886 
887     std::shared_ptr<CallerAbilityInfo> GetCallerInfo() const;
888 
889     /**
890      * get connecting record from list.
891      *
892      */
893     std::shared_ptr<ConnectionRecord> GetConnectingRecord() const;
894 
895     /**
896      * get disconnecting record from list.
897      *
898      */
899     std::shared_ptr<ConnectionRecord> GetDisconnectingRecord() const;
900 
901     /**
902      * convert ability state (enum type to string type).
903      *
904      */
905     static std::string ConvertAbilityState(const AbilityState &state);
906 
907     static std::string ConvertAppState(const AppState &state);
908 
909     /**
910      * convert life cycle state to ability state .
911      *
912      */
913     static int ConvertLifeCycleToAbilityState(const AbilityLifeCycleState &state);
914 
915     /**
916      * get the ability record id.
917      *
918      */
GetRecordId()919     inline int GetRecordId() const
920     {
921         return recordId_;
922     }
923 
924     /**
925      * dump ability info.
926      *
927      */
928     void Dump(std::vector<std::string> &info);
929 
930     void DumpClientInfo(std::vector<std::string> &info, const std::vector<std::string> &params,
931         bool isClient = false, bool dumpConfig = true) const;
932 
933     /**
934      * Called when client complete dump.
935      *
936      * @param infos The dump info.
937      */
938     void DumpAbilityInfoDone(std::vector<std::string> &infos);
939 
940     /**
941      * dump ability state info.
942      *
943      */
944     void DumpAbilityState(std::vector<std::string> &info, bool isClient, const std::vector<std::string> &params);
945 
946     void SetStartTime();
947 
948     int64_t GetStartTime() const;
949 
950     /**
951      * dump service info.
952      *
953      */
954     void DumpService(std::vector<std::string> &info, bool isClient = false) const;
955 
956     /**
957      * dump service info.
958      *
959      */
960     void DumpService(std::vector<std::string> &info, std::vector<std::string> &params, bool isClient = false) const;
961 
962     /**
963      * set connect remote object.
964      *
965      */
966     void SetConnRemoteObject(const sptr<IRemoteObject> &remoteObject);
967 
968     /**
969      * get connect remote object.
970      *
971      */
972     sptr<IRemoteObject> GetConnRemoteObject() const;
973 
974     /**
975      * check whether the ability is never started.
976      */
977     bool IsNeverStarted() const;
978 
979     void AddStartId();
980     int GetStartId() const;
981 
982     void SetIsUninstallAbility();
983     /**
984      * Determine whether ability is uninstalled
985      *
986      * @return true: uninstalled false: installed
987      */
988     bool IsUninstallAbility() const;
989     void ShareData(const int32_t &uniqueId);
990     void SetLauncherRoot();
991     bool IsLauncherRoot() const;
992     bool IsAbilityState(const AbilityState &state) const;
993     bool IsActiveState() const;
994 
995     void SetStartSetting(const std::shared_ptr<AbilityStartSetting> &setting);
996     std::shared_ptr<AbilityStartSetting> GetStartSetting() const;
997 
998     void SetRestarting(const bool isRestart);
999     void SetRestarting(const bool isRestart, int32_t canReStartCount);
1000     int32_t GetRestartCount() const;
1001     void SetRestartCount(int32_t restartCount);
1002     bool GetKeepAlive() const;
SetKeepAliveBundle(bool value)1003     void SetKeepAliveBundle(bool value)
1004     {
1005         keepAliveBundle_ = value;
1006     }
IsKeepAliveBundle()1007     bool IsKeepAliveBundle() const
1008     {
1009         return keepAliveBundle_;
1010     }
1011     void SetLoading(bool status);
1012     bool IsLoading() const;
1013     int64_t GetRestartTime();
1014     void SetRestartTime(const int64_t restartTime);
1015     void SetAppIndex(const int32_t appIndex);
1016     int32_t GetAppIndex() const;
1017     void SetWantAppIndex(const int32_t appIndex);
1018     int32_t GetWantAppIndex() const;
1019     bool IsRestarting() const;
1020     void SetAppState(const AppState &state);
1021     AppState GetAppState() const;
1022 
1023     void SetLaunchReason(const LaunchReason &reason);
1024     void SetLaunchReasonMessage(const std::string &launchReasonMessage);
1025     void SetLastExitReason(const ExitReason &exitReason, const AppExecFwk::RunningProcessInfo &processsInfo,
1026         const int64_t timestamp, bool withKillReason);
1027     void ContinueAbility(const std::string &deviceId, uint32_t versionCode);
1028     void NotifyContinuationResult(int32_t result);
1029 
1030     void SetMissionId(int32_t missionId);
1031     int32_t GetMissionId() const;
1032 
1033     void SetUid(int32_t uid);
1034     int32_t GetUid();
1035     pid_t GetPid();
1036     void SetPid(pid_t pid);
1037     void SetSwitchingPause(bool state);
1038     bool IsSwitchingPause();
1039     void SetOwnerMissionUserId(int32_t userId);
1040     int32_t GetOwnerMissionUserId();
1041 
1042     // new version
1043     ResolveResultType Resolve(const AbilityRequest &abilityRequest);
1044     bool ReleaseCall(const sptr<IAbilityConnection> &connect);
1045     bool IsNeedToCallRequest() const;
1046     bool IsStartedByCall() const;
1047     void SetStartedByCall(const bool isFlag);
1048     void CallRequest();
1049     bool CallRequestDone(const sptr<IRemoteObject> &callStub) const;
1050     bool IsStartToBackground() const;
1051     void SetStartToBackground(const bool flag);
1052     bool IsStartToForeground() const;
1053     void SetStartToForeground(const bool flag);
1054     bool IsCallerSetProcess() const;
1055     void SetCallerSetProcess(const bool flag);
1056     void SetSessionInfo(sptr<SessionInfo> sessionInfo);
1057     void UpdateSessionInfo(sptr<IRemoteObject> sessionToken);
1058     void SetMinimizeReason(bool fromUser);
1059     void SetSceneFlag(uint32_t sceneFlag);
1060     bool IsMinimizeFromUser() const;
1061     void SetClearMissionFlag(bool clearMissionFlag);
1062     bool IsClearMissionFlag();
1063 
1064     void SetSpecifiedFlag(const std::string &flag);
1065     std::string GetSpecifiedFlag() const;
1066     void SetWindowMode(int32_t windowMode);
1067     void RemoveWindowMode();
1068     LifeCycleStateInfo lifeCycleStateInfo_;                // target life state info
1069 
1070     bool CanRestartRootLauncher();
1071 
1072     bool CanRestartResident();
1073 
1074     std::string GetLabel();
GetAbilityRecordId()1075     inline int64_t GetAbilityRecordId() const
1076     {
1077         return recordId_;
1078     }
1079 
1080     void SetPendingState(AbilityState state);
1081     AbilityState GetPendingState() const;
1082 
1083     bool IsNeedBackToOtherMissionStack();
1084     void SetNeedBackToOtherMissionStack(bool isNeedBackToOtherMissionStack);
1085     std::shared_ptr<AbilityRecord> GetOtherMissionStackAbilityRecord() const;
1086     void SetOtherMissionStackAbilityRecord(const std::shared_ptr<AbilityRecord> &abilityRecord);
1087     void RemoveAbilityDeathRecipient() const;
1088     bool IsExistConnection(const sptr<IAbilityConnection> &connect);
1089 
1090     int32_t GetCollaboratorType() const;
1091 
1092     std::string GetMissionAffinity() const;
1093 
1094     void SetLockedState(bool lockedState);
1095     bool GetLockedState();
1096 
1097     void SetAttachDebug(const bool isAttachDebug);
1098     void SetAssertDebug(bool isAssertDebug);
1099     int32_t CreateModalUIExtension(const Want &want);
1100 
1101     AppExecFwk::ElementName GetElementName() const;
1102     bool IsDebugApp() const;
1103     bool IsDebug() const;
1104 
1105     void AddAbilityWindowStateMap(uint64_t uiExtensionComponentId,
1106         AbilityWindowState abilityWindowState);
1107 
1108     void RemoveAbilityWindowStateMap(uint64_t uiExtensionComponentId);
1109 
1110     bool IsAbilityWindowReady();
1111 
1112     void SetAbilityWindowState(const sptr<SessionInfo> &sessionInfo,
1113         WindowCommand winCmd, bool isFinished);
1114 
1115     void SetUIExtensionAbilityId(const int32_t uiExtensionAbilityId);
1116     int32_t GetUIExtensionAbilityId() const;
1117 
1118     void OnProcessDied();
1119 
1120     void SetProcessName(const std::string &process);
1121 
1122     std::string GetProcessName() const;
1123 
1124     void SetCustomProcessFlag(const std::string &process);
1125 
1126     std::string GetCustomProcessFlag() const;
1127 
1128     void SetExtensionProcessMode(const uint32_t &extensionProcessMode);
1129 
1130     uint32_t GetExtensionProcessMode() const;
1131 
1132     void SetURI(const std::string &uri);
1133     std::string GetURI() const;
1134 
1135     void DoBackgroundAbilityWindowDelayed(bool needBackground);
1136     bool BackgroundAbilityWindowDelayed();
1137 
1138     bool IsSceneBoard() const;
1139 
1140     void SetRestartAppFlag(bool isRestartApp);
1141     bool GetRestartAppFlag() const;
1142 
1143     void SetKillForPermissionUpdateFlag(bool isKillForPermissionUpdate);
1144     bool GetKillForPermissionUpdateFlag() const;
1145 
1146     void UpdateUIExtensionInfo(const WantParams &wantParams);
1147 
1148     void SetSpecifyTokenId(const uint32_t specifyTokenId);
1149 
1150     void SaveConnectWant(const Want &want);
1151 
1152     void UpdateConnectWant();
1153 
1154     void RemoveConnectWant();
1155 
1156     void UpdateDmsCallerInfo(Want &want);
1157 
1158     void SetDebugUIExtension();
1159 
1160 #ifdef SUPPORT_UPMS
1161     void GrantUriPermission();
1162 
1163     void GrantUriPermission(const std::vector<std::string> &uriVec, int32_t flag,
1164         const std::string &targetBundleName, uint32_t callerTokenId);
1165 #endif // SUPPORT_UPMS
1166 
GetInstanceKey()1167     inline std::string GetInstanceKey() const
1168     {
1169         return instanceKey_;
1170     }
1171 
SetInstanceKey(const std::string & key)1172     void SetInstanceKey(const std::string& key)
1173     {
1174         instanceKey_ = key;
1175     }
1176 
SetSecurityFlag(bool securityFlag)1177     void SetSecurityFlag(bool securityFlag)
1178     {
1179         securityFlag_ = securityFlag;
1180     }
1181 
GetSecurityFlag()1182     bool GetSecurityFlag() const
1183     {
1184         return securityFlag_;
1185     }
1186 
IsPluginAbility()1187     bool IsPluginAbility() const
1188     {
1189         return isPluginAbility_;
1190     }
1191 
1192     void NotifyAbilityRequestFailure(const std::string &requestId, const AppExecFwk::ElementName &element,
1193         const std::string &message, int32_t resultCode = 0);
1194 
1195     void NotifyAbilityRequestSuccess(const std::string &requestId, const AppExecFwk::ElementName &element);
1196     void NotifyAbilitiesRequestDone(const std::string &requestKey, int32_t resultCode);
1197 
1198     void ScheduleCollaborate(const Want &want);
1199 
IsHook()1200     bool IsHook () const
1201     {
1202         return isHook_;
1203     }
1204 
SetIsHook(bool isHook)1205     inline void SetIsHook(bool isHook)
1206     {
1207         isHook_ = isHook;
1208     }
1209 
GetHookOff()1210     bool GetHookOff () const
1211     {
1212         return hookOff_;
1213     }
1214 
SetHookOff(bool hookOff)1215     inline void SetHookOff(bool hookOff)
1216     {
1217         hookOff_ = hookOff;
1218     }
1219 
SetLaunchWant(std::shared_ptr<Want> launchWant)1220     inline void SetLaunchWant(std::shared_ptr<Want> launchWant)
1221     {
1222         launchWant_ = launchWant;
1223     }
1224 
GetLaunchWant()1225     inline std::shared_ptr<Want> GetLaunchWant() const
1226     {
1227         return launchWant_;
1228     }
1229 
SetLastWant(std::shared_ptr<Want> lastWant)1230     inline void SetLastWant(std::shared_ptr<Want> lastWant)
1231     {
1232         lastWant_ = lastWant;
1233     }
1234 
HasLastWant()1235     inline bool HasLastWant() const
1236     {
1237         return lastWant_ != nullptr;
1238     }
1239 
SetBackgroundDrivenFlag(bool isLastWantBackgroundDriven)1240     inline void SetBackgroundDrivenFlag(bool isLastWantBackgroundDriven)
1241     {
1242         isLastWantBackgroundDriven_.store(isLastWantBackgroundDriven);
1243     }
1244 
IsLastWantBackgroundDriven()1245     inline bool IsLastWantBackgroundDriven() const
1246     {
1247         return isLastWantBackgroundDriven_.load();
1248     }
1249 
SetOnNewWantSkipScenarios(int32_t scenarios)1250     inline void SetOnNewWantSkipScenarios(int32_t scenarios)
1251     {
1252         scenarios_.store(scenarios);
1253     }
1254 
GetOnNewWantSkipScenarios()1255     inline int32_t GetOnNewWantSkipScenarios() const
1256     {
1257         return scenarios_.load();
1258     }
1259 
SetPreloadStart(bool isPreloadStart)1260     inline void SetPreloadStart(bool isPreloadStart)
1261     {
1262         isPreloadStart_.store(isPreloadStart);
1263     }
1264 
IsPreloadStart()1265     inline bool IsPreloadStart() const
1266     {
1267         return isPreloadStart_.load();
1268     }
1269 
SetPreloaded()1270     inline void SetPreloaded()
1271     {
1272         isPreloaded_.store(true);
1273     }
1274 
IsPreloaded()1275     inline bool IsPreloaded() const
1276     {
1277         return isPreloaded_.load();
1278     }
1279 
SetFrozenByPreload(bool isFrozenByPreload)1280     inline void SetFrozenByPreload(bool isFrozenByPreload)
1281     {
1282         isFrozenByPreload_.store(isFrozenByPreload);
1283     }
1284 
IsFrozenByPreload()1285     inline bool IsFrozenByPreload() const
1286     {
1287         return isFrozenByPreload_.load();
1288     }
1289 
1290     void SendEvent(uint32_t msg, uint32_t timeOut, int32_t param = -1, bool isExtension = false,
1291         const std::string &taskName = "");
1292 
1293     void UpdateUIExtensionBindInfo(const WantParams &wantParams);
1294 
1295     void SendTerminateAbilityErrorEvent(int32_t errCode);
1296 protected:
1297 
1298     sptr<Token> token_ = {};                               // used to interact with kit and wms
1299     std::unique_ptr<LifecycleDeal> lifecycleDeal_ = {};    // life manager used to schedule life
1300     AbilityState currentState_ = AbilityState::INITIAL;    // current life state
1301     Want want_ = {};                                       // want to start this ability
1302 
1303 private:
1304     /**
1305      * get the type of ability.
1306      *
1307      */
1308     void GetAbilityTypeString(std::string &typeStr);
1309     void OnSchedulerDied(const wptr<IRemoteObject> &remote);
1310 #ifdef SUPPORT_UPMS
1311     void GrantUriPermission(Want &want, std::string targetBundleName, bool isSandboxApp, uint32_t tokenId);
1312 #endif // SUPPORT_UPMS
1313     int32_t GetCurrentAccountId() const;
1314 
1315     /**
1316      * add system ability caller record
1317      *
1318      */
1319     void AddSystemAbilityCallerRecord(const sptr<IRemoteObject> &callerToken, int requestCode,
1320         std::string srcAbilityId);
1321 
1322     bool IsSystemAbilityCall(const sptr<IRemoteObject> &callerToken, uint32_t callingTokenId = 0);
1323 
1324     void RecordSaCallerInfo(const Want &want);
1325 
1326 #ifdef WITH_DLP
1327     void HandleDlpAttached();
1328     void HandleDlpClosed();
1329 #endif // WITH_DLP
1330     void NotifyRemoveShellProcess(int32_t type);
1331     void NotifyAnimationAbilityDied();
SetCallerAccessTokenId(uint32_t callerAccessTokenId)1332     inline void SetCallerAccessTokenId(uint32_t callerAccessTokenId)
1333     {
1334         callerAccessTokenId_ = callerAccessTokenId;
1335     }
1336 
1337     LastExitReason CovertAppExitReasonToLastReason(const Reason exitReason);
1338 
1339     void NotifyMissionBindPid();
1340 
1341     void DumpUIExtensionRootHostInfo(std::vector<std::string> &info) const;
1342 
1343     void DumpUIExtensionPid(std::vector<std::string> &info, bool isUIExtension) const;
1344 
1345     void SetDebugAppByWaitingDebugFlag();
1346     void AfterLoaded();
1347 
1348     void CancelPrepareTerminate();
1349 
1350     void BuildTerminateAbilityEventInfo(EventInfo &eventInfo, int32_t errCode);
1351 
1352 #ifdef SUPPORT_SCREEN
1353     std::shared_ptr<Want> GetWantFromMission() const;
1354     void SetShowWhenLocked(const AppExecFwk::AbilityInfo &abilityInfo, sptr<AbilityTransitionInfo> &info) const;
1355     void SetAbilityTransitionInfo(const AppExecFwk::AbilityInfo &abilityInfo,
1356         sptr<AbilityTransitionInfo> &info) const;
1357     void SetAbilityTransitionInfo(sptr<AbilityTransitionInfo>& info) const;
1358     sptr<IWindowManagerServiceHandler> GetWMSHandler() const;
1359     void SetWindowModeAndDisplayId(sptr<AbilityTransitionInfo> &info, const std::shared_ptr<Want> &want) const;
1360     sptr<AbilityTransitionInfo> CreateAbilityTransitionInfo();
1361     sptr<AbilityTransitionInfo> CreateAbilityTransitionInfo(const std::shared_ptr<StartOptions> &startOptions,
1362         const std::shared_ptr<Want> &want) const;
1363     sptr<AbilityTransitionInfo> CreateAbilityTransitionInfo(const AbilityRequest &abilityRequest) const;
1364     sptr<AbilityTransitionInfo> CreateAbilityTransitionInfo(const std::shared_ptr<StartOptions> &startOptions,
1365         const std::shared_ptr<Want> &want, const AbilityRequest &abilityRequest);
1366     std::shared_ptr<Global::Resource::ResourceManager> CreateResourceManager() const;
1367     std::shared_ptr<Media::PixelMap> GetPixelMap(const uint32_t windowIconId,
1368         std::shared_ptr<Global::Resource::ResourceManager> resourceMgr) const;
1369 
1370     void AnimationTask(bool isRecent, const AbilityRequest &abilityRequest,
1371         const std::shared_ptr<StartOptions> &startOptions, const std::shared_ptr<AbilityRecord> &callerAbility);
1372     void NotifyAnimationFromStartingAbility(const std::shared_ptr<AbilityRecord> &callerAbility,
1373         const AbilityRequest &abilityRequest) const;
1374     void NotifyAnimationFromRecentTask(const std::shared_ptr<StartOptions> &startOptions,
1375         const std::shared_ptr<Want> &want) const;
1376     void NotifyAnimationFromTerminatingAbility(const std::shared_ptr<AbilityRecord> &callerAbility, bool needExit,
1377         bool flag);
1378 
1379     void StartingWindowTask(bool isRecent, bool isCold, const AbilityRequest &abilityRequest,
1380         std::shared_ptr<StartOptions> &startOptions);
1381     void StartingWindowColdTask(bool isRecent, const AbilityRequest &abilityRequest,
1382         std::shared_ptr<StartOptions> &startOptions);
1383     void PostCancelStartingWindowColdTask();
1384     void StartingWindowHot(const std::shared_ptr<StartOptions> &startOptions, const std::shared_ptr<Want> &want,
1385         const AbilityRequest &abilityRequest);
1386     void StartingWindowHot();
1387     void StartingWindowCold(const std::shared_ptr<StartOptions> &startOptions, const std::shared_ptr<Want> &want,
1388         const AbilityRequest &abilityRequest);
1389     void InitColdStartingWindowResource(const std::shared_ptr<Global::Resource::ResourceManager> &resourceMgr);
1390     void GetColdStartingWindowResource(std::shared_ptr<Media::PixelMap> &bg, uint32_t &bgColor);
1391     void SetAbilityStateInner(AbilityState state);
1392 #endif
1393     void SendAppStartupTypeEvent(const AppExecFwk::AppStartType startType);
1394     std::atomic<bool> isPreloadStart_ = false;           // is ability started via preload
1395 
1396     static std::atomic<int64_t> abilityRecordId;
1397     bool isReady_ = false;                            // is ability thread attached?
1398     bool isWindowStarted_ = false;                     // is window hotstart or coldstart?
1399     bool isWindowAttached_ = false;                   // Is window of this ability attached?
1400     bool isLauncherAbility_ = false;                  // is launcher?
1401     bool isLoading_ = false;        // is loading?
1402     bool isTerminating_ = false;              // is terminating ?
1403     bool isCreateByConnect_ = false;          // is created by connect ability mode?
1404     bool isUninstall_ = false;
1405     bool isLauncherRoot_ = false;
1406     bool isSwitchingPause_ = false;
1407     /**
1408      * When this ability startAbilityForResult another ability, if another ability is terminated,
1409      * this ability will move to foreground, during this time, isAbilityForegrounding_ is true,
1410      * isAbilityForegrounding_ will be set to false when this ability is background
1411      */
1412     bool isAbilityForegrounding_ = false;
1413     bool isRestarting_ = false;     // is restarting ?
1414     bool isStartedByCall_ = false;       // new version
1415     bool isStartToBackground_ = false;         // new version
1416     bool isStartToForeground_ = false;        // new version
1417     bool minimizeReason_ = false;           // new version
1418     bool clearMissionFlag_ = false;
1419     bool keepAliveBundle_ = false;
1420     bool isNeedBackToOtherMissionStack_ = false;
1421     bool lockedState_ = false;
1422     bool isAttachDebug_ = false;
1423     bool isAssertDebug_ = false;
1424     bool isAppAutoStartup_ = false;
1425     bool isConnected = false;
1426     bool isRestartApp_ = false; // Only app calling RestartApp can be set to true
1427     bool isLaunching_ = true;
1428     bool securityFlag_ = false;
1429     bool isHook_ = false;
1430     bool hookOff_ = false;
1431     bool isPluginAbility_ = false;
1432     std::atomic_bool isCallerSetProcess_ = false;       // new version
1433     std::atomic_bool backgroundAbilityWindowDelayed_ = false;
1434 
1435     int32_t uiExtensionAbilityId_ = 0;                // uiextension ability id
1436     int32_t uid_ = 0;
1437     pid_t pid_ = 0;
1438     int32_t missionId_ = -1;
1439     int32_t ownerMissionUserId_ = -1;
1440     uint32_t extensionProcessMode_ = 0;       // new version
1441     int32_t appIndex_ = 0;          // new version
1442     int32_t restartCount_ = -1;
1443     int32_t restartMax_ = -1;
1444     int32_t collaboratorType_ = 0;
1445     uint32_t callerAccessTokenId_ = -1;
1446     uint32_t specifyTokenId_ = 0;
1447 
1448     int recordId_ = 0;                                // record id
1449     int requestCode_ = -1;  // requestCode_: >= 0 for-result start mode; <0 for normal start mode in default.
1450     int startId_ = 0;  // service(ability) start id
1451 
1452     AppExecFwk::AbilityInfo abilityInfo_ = {};             // the ability info get from BMS
1453     std::weak_ptr<AbilityRecord> preAbilityRecord_ = {};   // who starts this ability record
1454     std::weak_ptr<AbilityRecord> nextAbilityRecord_ = {};  // ability that started by this ability
1455     int64_t startTime_ = 0;                           // records first time of ability start
1456     int64_t restartTime_ = 0;                         // the time of last trying restart
1457     sptr<IAbilityScheduler> scheduler_ = {};       // kit scheduler
1458     sptr<IRemoteObject::DeathRecipient> schedulerDeathRecipient_ = {};  // scheduler binderDied Recipient
1459 
1460     /**
1461      * result_: ability starts with for-result mode will send result before being terminated.
1462      * Its caller will receive results before active.
1463      * Now we assume only one result generate when terminate.
1464      */
1465     std::shared_ptr<AbilityResult> result_ = {};
1466 
1467     // service(ability) can be connected by multi-pages(abilities), so need to store this service's connections
1468     mutable ffrt::mutex connRecordListMutex_;
1469     std::list<std::shared_ptr<ConnectionRecord>> connRecordList_ = {};
1470     // service(ability) onConnect() return proxy of service ability
1471     sptr<IRemoteObject> connRemoteObject_ = {};
1472 
1473     // page(ability) can be started by multi-pages(abilities), so need to store this ability's caller
1474     std::list<std::shared_ptr<CallerRecord>> callerList_ = {};
1475     mutable ffrt::mutex callerListLock_;
1476 
1477     PacMap stateDatas_;             // ability saved ability state data
1478     WindowConfig windowConfig_;
1479     AppState appState_ = AppState::BEGIN;
1480 
1481     std::shared_ptr<CallContainer> callContainer_ = nullptr;       // new version
1482     std::string customProcessFlag_ = "";        // new version
1483     std::string specifiedFlag_;
1484     std::string uri_;
1485 
1486     mutable ffrt::mutex dumpInfoLock_;
1487     mutable ffrt::mutex dumpLock_;
1488     mutable ffrt::mutex resultLock_;
1489     mutable ffrt::mutex wantLock_;
1490     mutable ffrt::condition_variable dumpCondition_;
1491     mutable bool isDumpTimeout_ = false;
1492     std::vector<std::string> dumpInfos_;
1493     std::atomic<AbilityState> pendingState_ = AbilityState::INITIAL;    // pending life state
1494     std::atomic<AbilityVisibilityState> abilityVisibilityState_ = AbilityVisibilityState::INITIAL;
1495 
1496     // scene session
1497     sptr<SessionInfo> sessionInfo_ = nullptr;
1498     mutable ffrt::mutex sessionLock_;
1499     std::map<uint64_t, AbilityWindowState> abilityWindowStateMap_;
1500 
1501 #ifdef SUPPORT_SCREEN
1502     bool isStartingWindow_ = false;
1503     bool isCompleteFirstFrameDrawing_ = false;
1504     bool coldStart_ = false;
1505     uint32_t bgColor_ = 0;
1506     std::shared_ptr<Media::PixelMap> startingWindowBg_ = nullptr;
1507 #endif
1508 
1509     std::weak_ptr<AbilityRecord> otherMissionStackAbilityRecord_; // who starts this ability record by SA
1510 
1511     std::shared_ptr<Want> connectWant_ = nullptr;
1512     std::shared_ptr<CallerAbilityInfo> saCallerInfo_ = nullptr;
1513     LaunchDebugInfo launchDebugInfo_;
1514 
1515     std::string instanceKey_ = "";
1516     std::string missionAffinity_ = "";
1517 
1518     ffrt::mutex lock_;
1519     ffrt::mutex connectWantLock_;
1520     std::mutex collaborateWantLock_;
1521 
1522     bool isKillForPermissionUpdate_ = false;
1523 
1524     std::mutex isPrepareTerminateAbilityMutex_;
1525     std::condition_variable isPrepareTerminateAbilityCv_;
1526     std::atomic_bool isPrepareTerminateAbilityCalled_ = false;
1527     std::atomic_bool isPrepareTerminateAbilityDone_ = false;
1528     bool isPrepareTerminate_ = false;
1529 
1530     std::string killReason_ = "";
1531     std::atomic_bool isKillPrecedeStart_ = false;
1532     std::shared_ptr<Want> launchWant_ = nullptr;
1533     std::shared_ptr<Want> lastWant_ = nullptr;
1534     std::atomic_bool isLastWantBackgroundDriven_ = false;
1535     std::atomic<int32_t> scenarios_ = 0;
1536     std::atomic<bool> isPreloaded_ = false;
1537     std::atomic<bool> isFrozenByPreload_ = false;
1538 };
1539 }  // namespace AAFwk
1540 }  // namespace OHOS
1541 #endif  // OHOS_ABILITY_RUNTIME_ABILITY_RECORD_H
1542