• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef OHOS_ABILITY_RUNTIME_ABILITY_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 
25 #include "ability_connect_callback_interface.h"
26 #include "ability_info.h"
27 #include "ability_start_setting.h"
28 #include "ability_state.h"
29 #include "ability_token_stub.h"
30 #include "app_scheduler.h"
31 #include "application_info.h"
32 #include "bundlemgr/bundle_mgr_interface.h"
33 #include "call_container.h"
34 #include "ipc_skeleton.h"
35 #include "lifecycle_deal.h"
36 #include "lifecycle_state_info.h"
37 #include "uri.h"
38 #include "want.h"
39 #ifdef SUPPORT_GRAPHICS
40 #include "ability_window_configuration.h"
41 #include "resource_manager.h"
42 #include "start_options.h"
43 #include "window_manager_service_handler.h"
44 #endif
45 
46 namespace OHOS {
47 namespace AAFwk {
48 using Closure = std::function<void()>;
49 
50 class AbilityRecord;
51 class ConnectionRecord;
52 class Mission;
53 class MissionList;
54 class CallContainer;
55 
56 constexpr const char* ABILITY_TOKEN_NAME = "AbilityToken";
57 constexpr const char* LAUNCHER_BUNDLE_NAME = "com.ohos.launcher";
58 
59 /**
60  * @class Token
61  * Token is identification of ability and used to interact with kit and wms.
62  */
63 class Token : public AbilityTokenStub {
64 public:
65     explicit Token(std::weak_ptr<AbilityRecord> abilityRecord);
66     virtual ~Token();
67 
68     std::shared_ptr<AbilityRecord> GetAbilityRecord() const;
69     static std::shared_ptr<AbilityRecord> GetAbilityRecordByToken(const sptr<IRemoteObject> &token);
70 
71 private:
72     std::weak_ptr<AbilityRecord> abilityRecord_;  // ability of this token
73 };
74 
75 /**
76  * @class AbilityResult
77  * Record requestCode of for-result start mode and result.
78  */
79 class AbilityResult {
80 public:
81     AbilityResult() = default;
AbilityResult(int requestCode,int resultCode,const Want & resultWant)82     AbilityResult(int requestCode, int resultCode, const Want &resultWant)
83         : requestCode_(requestCode), resultCode_(resultCode), resultWant_(resultWant)
84     {}
~AbilityResult()85     virtual ~AbilityResult()
86     {}
87 
88     int requestCode_ = -1;  // requestCode of for-result start mode
89     int resultCode_ = -1;   // resultCode of for-result start mode
90     Want resultWant_;       // for-result start mode ability will send the result to caller
91 };
92 
93 /**
94  * @class SystemAbilityCallerRecord
95  * Record system caller ability of for-result start mode and result.
96  */
97 class SystemAbilityCallerRecord {
98 public:
SystemAbilityCallerRecord(std::string & srcAbilityId,const sptr<IRemoteObject> & callerToken)99     SystemAbilityCallerRecord(std::string &srcAbilityId, const sptr<IRemoteObject> &callerToken)
100         : srcAbilityId_(srcAbilityId), callerToken_(callerToken)
101     {}
~SystemAbilityCallerRecord()102     virtual ~SystemAbilityCallerRecord()
103     {}
104 
GetSrcAbilityId()105     std::string GetSrcAbilityId()
106     {
107         return srcAbilityId_;
108     }
GetCallerToken()109     const sptr<IRemoteObject> GetCallerToken()
110     {
111         return callerToken_;
112     }
SetResult(Want & want,int resultCode)113     void SetResult(Want &want, int resultCode)
114     {
115         resultWant_ = want;
116         resultCode_ = resultCode;
117     }
GetResultWant()118     Want &GetResultWant()
119     {
120         return resultWant_;
121     }
GetResultCode()122     int &GetResultCode()
123     {
124         return resultCode_;
125     }
126     /**
127      * Set result to system ability.
128      *
129      */
130     void SetResultToSystemAbility(std::shared_ptr<SystemAbilityCallerRecord> callerSystemAbilityRecord,
131         Want &resultWant, int resultCode);
132     /**
133      * Send result to system ability.
134      *
135      */
136     void SendResultToSystemAbility(int requestCode, int resultCode, Want &resultWant,
137         const sptr<IRemoteObject> &callerToken);
138 
139 private:
140     std::string srcAbilityId_;
141     sptr<IRemoteObject> callerToken_;
142     Want resultWant_;
143     int resultCode_ = -1;
144 };
145 
146 /**
147  * @class CallerRecord
148  * Record caller ability of for-result start mode and result.
149  */
150 class CallerRecord {
151 public:
152     CallerRecord() = default;
CallerRecord(int requestCode,std::weak_ptr<AbilityRecord> caller)153     CallerRecord(int requestCode, std::weak_ptr<AbilityRecord> caller) : requestCode_(requestCode), caller_(caller)
154     {}
CallerRecord(int requestCode,std::shared_ptr<SystemAbilityCallerRecord> saCaller)155     CallerRecord(int requestCode, std::shared_ptr<SystemAbilityCallerRecord> saCaller) : requestCode_(requestCode),
156         saCaller_(saCaller)
157     {}
~CallerRecord()158     virtual ~CallerRecord()
159     {}
160 
GetRequestCode()161     int GetRequestCode()
162     {
163         return requestCode_;
164     }
GetCaller()165     std::shared_ptr<AbilityRecord> GetCaller()
166     {
167         return caller_.lock();
168     }
GetSaCaller()169     std::shared_ptr<SystemAbilityCallerRecord> GetSaCaller()
170     {
171         return saCaller_;
172     }
173 
174 private:
175     int requestCode_ = -1;  // requestCode of for-result start mode
176     std::weak_ptr<AbilityRecord> caller_;
177     std::shared_ptr<SystemAbilityCallerRecord> saCaller_ = nullptr;
178 };
179 
180 /**
181  * @class AbilityRequest
182  * Wrap parameters of starting ability.
183  */
184 enum AbilityCallType {
185     INVALID_TYPE = 0,
186     CALL_REQUEST_TYPE,
187     START_OPTIONS_TYPE,
188     START_SETTINGS_TYPE,
189     START_EXTENSION_TYPE,
190 };
191 
192 struct ComponentRequest {
193     sptr<IRemoteObject> callerToken = nullptr;
194     int requestCode = 0;
195     int componentStatus = 0;
196     int requestResult = 0;
197 };
198 
199 struct AbilityRequest {
200     Want want;
201     AppExecFwk::AbilityInfo abilityInfo;
202     AppExecFwk::ApplicationInfo appInfo;
203     int32_t uid = 0;
204     int requestCode = -1;
205     bool restart = false;
206     int32_t restartCount = -1;
207     bool startRecent = false;
208     int64_t restartTime = 0;
209 
210     // call ability
211     int callerUid = -1;
212     AbilityCallType callType = AbilityCallType::INVALID_TYPE;
213     sptr<IRemoteObject> callerToken = nullptr;
214     uint32_t callerAccessTokenId = -1;
215     sptr<IAbilityConnection> connect = nullptr;
216 
217     std::shared_ptr<AbilityStartSetting> startSetting = nullptr;
218     std::string specifiedFlag;
219     sptr<IRemoteObject> abilityInfoCallback = nullptr;
220 
221     AppExecFwk::ExtensionAbilityType extensionType = AppExecFwk::ExtensionAbilityType::UNSPECIFIED;
222 
IsContinuationAbilityRequest223     bool IsContinuation() const
224     {
225         auto flags = want.GetFlags();
226         if ((flags & Want::FLAG_ABILITY_CONTINUATION) == Want::FLAG_ABILITY_CONTINUATION) {
227             return true;
228         }
229         return false;
230     }
231 
IsAppRecoveryAbilityRequest232     bool IsAppRecovery() const
233     {
234         return want.GetBoolParam(Want::PARAM_ABILITY_RECOVERY_RESTART, false);
235     }
236 
IsCallTypeAbilityRequest237     bool IsCallType(const AbilityCallType & type) const
238     {
239         return (callType == type);
240     }
241 
DumpAbilityRequest242     void Dump(std::vector<std::string> &state)
243     {
244         std::string dumpInfo = "      want [" + want.ToUri() + "]";
245         state.push_back(dumpInfo);
246         dumpInfo = "      app name [" + abilityInfo.applicationName + "]";
247         state.push_back(dumpInfo);
248         dumpInfo = "      main name [" + abilityInfo.name + "]";
249         state.push_back(dumpInfo);
250         dumpInfo = "      request code [" + std::to_string(requestCode) + "]";
251         state.push_back(dumpInfo);
252     }
253 
254     void Voluation(const Want &srcWant, int srcRequestCode,
255         const sptr<IRemoteObject> &srcCallerToken, const std::shared_ptr<AbilityStartSetting> srcStartSetting = nullptr,
256         int srcCallerUid = -1)
257     {
258         want = srcWant;
259         requestCode = srcRequestCode;
260         callerToken = srcCallerToken;
261         startSetting = srcStartSetting;
262         callerUid = srcCallerUid == -1 ? IPCSkeleton::GetCallingUid() : srcCallerUid;
263     }
264 };
265 
266 // new version
267 enum ResolveResultType {
268     OK_NO_REMOTE_OBJ = 0,
269     OK_HAS_REMOTE_OBJ,
270     NG_INNER_ERROR,
271 };
272 /**
273  * @class AbilityRecord
274  * AbilityRecord records ability info and states and used to schedule ability life.
275  */
276 class AbilityRecord : public std::enable_shared_from_this<AbilityRecord> {
277 public:
278     AbilityRecord(const Want &want, const AppExecFwk::AbilityInfo &abilityInfo,
279         const AppExecFwk::ApplicationInfo &applicationInfo, int requestCode = -1);
280 
281     virtual ~AbilityRecord();
282 
283     /**
284      * CreateAbilityRecord.
285      *
286      * @param abilityRequest,create ability record.
287      * @return Returns ability record ptr.
288      */
289     static std::shared_ptr<AbilityRecord> CreateAbilityRecord(const AbilityRequest &abilityRequest);
290 
291     /**
292      * Init ability record.
293      *
294      * @return Returns true on success, others on failure.
295      */
296     bool Init();
297 
298     /**
299      * load ability.
300      *
301      * @return Returns ERR_OK on success, others on failure.
302      */
303     int LoadAbility();
304 
305     /**
306      * foreground the ability.
307      *
308      */
309     void ForegroundAbility(uint32_t sceneFlag = 0);
310 
311     /**
312      * process request of foregrounding the ability.
313      *
314      */
315     void ProcessForegroundAbility(uint32_t sceneFlag = 0);
316 
317     /**
318      * move the ability to back ground.
319      *
320      * @param task timeout task.
321      */
322     void BackgroundAbility(const Closure &task);
323 
324     /**
325      * terminate ability.
326      *
327      * @return Returns ERR_OK on success, others on failure.
328      */
329     int TerminateAbility();
330 
331     /**
332      * get ability's info.
333      *
334      * @return ability info.
335      */
336     const AppExecFwk::AbilityInfo &GetAbilityInfo() const;
337 
338     /**
339      * get application's info.
340      *
341      * @return application info.
342      */
343     const AppExecFwk::ApplicationInfo &GetApplicationInfo() const;
344 
345     /**
346      * set ability's state.
347      *
348      * @param state, ability's state.
349      */
350     void SetAbilityState(AbilityState state);
351 
352     /**
353      * get ability's state.
354      *
355      * @return ability state.
356      */
357     AbilityState GetAbilityState() const;
358 
359     bool IsForeground() const;
360 
361     /**
362      * set ability scheduler for accessing ability thread.
363      *
364      * @param scheduler , ability scheduler.
365      */
366     void SetScheduler(const sptr<IAbilityScheduler> &scheduler);
367 
GetScheduler()368     inline sptr<IAbilityScheduler> GetScheduler() const
369     {
370         return scheduler_;
371     }
372 
373     /**
374      * get ability's token.
375      *
376      * @return ability's token.
377      */
378     sptr<Token> GetToken() const;
379 
380     /**
381      * set ability's previous ability record.
382      *
383      * @param abilityRecord , previous ability record
384      */
385     void SetPreAbilityRecord(const std::shared_ptr<AbilityRecord> &abilityRecord);
386 
387     /**
388      * get ability's previous ability record.
389      *
390      * @return previous ability record
391      */
392     std::shared_ptr<AbilityRecord> GetPreAbilityRecord() const;
393 
394     /**
395      * set ability's next ability record.
396      *
397      * @param abilityRecord , next ability record
398      */
399     void SetNextAbilityRecord(const std::shared_ptr<AbilityRecord> &abilityRecord);
400 
401     /**
402      * get ability's previous ability record.
403      *
404      * @return previous ability record
405      */
406     std::shared_ptr<AbilityRecord> GetNextAbilityRecord() const;
407 
408     /**
409      * set event id.
410      *
411      * @param eventId
412      */
413     void SetEventId(int64_t eventId);
414 
415     /**
416      * get event id.
417      *
418      * @return eventId
419      */
420     int64_t GetEventId() const;
421 
422     /**
423      * check whether the ability is ready.
424      *
425      * @return true : ready ,false: not ready
426      */
427     bool IsReady() const;
428 
429 #ifdef SUPPORT_GRAPHICS
430     /**
431      * check whether the ability 's window is attached.
432      *
433      * @return true : attached ,false: not attached
434      */
435     bool IsWindowAttached() const;
436 
IsStartingWindow()437     inline bool IsStartingWindow() const
438     {
439         return isStartingWindow_;
440     }
441 
SetStartingWindow(bool isStartingWindow)442     inline void SetStartingWindow(bool isStartingWindow)
443     {
444         isStartingWindow_ = isStartingWindow;
445     }
446 
447     void PostCancelStartingWindowHotTask();
448 
449     /**
450      * process request of foregrounding the ability.
451      *
452      */
453     void ProcessForegroundAbility(bool isRecent, const AbilityRequest &abilityRequest,
454         std::shared_ptr<StartOptions> &startOptions, const std::shared_ptr<AbilityRecord> &callerAbility,
455         uint32_t sceneFlag = 0);
456 
457     void ProcessForegroundAbility(const std::shared_ptr<AbilityRecord> &callerAbility, uint32_t sceneFlag = 0);
458     void NotifyAnimationFromTerminatingAbility() const;
459 
460     void SetCompleteFirstFrameDrawing(const bool flag);
461     bool IsCompleteFirstFrameDrawing() const;
462 #endif
463 
464     /**
465      * check whether the ability is launcher.
466      *
467      * @return true : lanucher ,false: not lanucher
468      */
469     bool IsLauncherAbility() const;
470 
471     /**
472      * check whether the ability is terminating.
473      *
474      * @return true : yes ,false: not
475      */
476     bool IsTerminating() const;
477 
478     /**
479      * set the ability is terminating.
480      *
481      */
482     void SetTerminatingState();
483 
484     /**
485      * set the ability is new want flag.
486      *
487      * @return isNewWant
488      */
489     void SetIsNewWant(bool isNewWant);
490 
491     /**
492      * check whether the ability is new want flag.
493      *
494      * @return true : yes ,false: not
495      */
496     bool IsNewWant() const;
497 
498     /**
499      * check whether the ability is created by connect ability mode.
500      *
501      * @return true : yes ,false: not
502      */
503     bool IsCreateByConnect() const;
504 
505     /**
506      * set the ability is created by connect ability mode.
507      *
508      */
509     void SetCreateByConnectMode();
510 
511     /**
512      * active the ability.
513      *
514      */
515     virtual void Activate();
516 
517     /**
518      * inactive the ability.
519      *
520      */
521     virtual void Inactivate();
522 
523     /**
524      * terminate the ability.
525      *
526      */
527     void Terminate(const Closure &task);
528 
529     /**
530      * connect the ability.
531      *
532      */
533     void ConnectAbility();
534 
535     /**
536      * disconnect the ability.
537      *
538      */
539     void DisconnectAbility();
540 
541     /**
542      * Command the ability.
543      *
544      */
545     void CommandAbility();
546 
547     /**
548      * save ability state.
549      *
550      */
551     void SaveAbilityState();
552     void SaveAbilityState(const PacMap &inState);
553 
554     /**
555      * restore ability state.
556      *
557      */
558     void RestoreAbilityState();
559 
560     /**
561      * notify top active ability updated.
562      *
563      */
564     void TopActiveAbilityChanged(bool flag);
565 
566     /**
567      * set the want for start ability.
568      *
569      */
570     void SetWant(const Want &want);
571 
572     /**
573      * get the want for start ability.
574      *
575      */
576     const Want &GetWant() const;
577 
578     /**
579      * get request code of the ability to start.
580      *
581      */
582     int GetRequestCode() const;
583 
584     /**
585      * set the result object of the ability which one need to be terminated.
586      *
587      */
588     void SetResult(const std::shared_ptr<AbilityResult> &result);
589 
590     /**
591      * get the result object of the ability which one need to be terminated.
592      *
593      */
594     std::shared_ptr<AbilityResult> GetResult() const;
595 
596     /**
597      * send result object to caller ability thread.
598      *
599      */
600     void SendResult();
601 
602     /**
603      * send result object to caller ability.
604      *
605      */
606     void SendResultToCallers();
607 
608     /**
609      * save result object to caller ability.
610      *
611      */
612     void SaveResultToCallers(const int resultCode, const Want *resultWant);
613 
614     /**
615      * save result to caller ability.
616      *
617      */
618     void SaveResult(int resultCode, const Want *resultWant, std::shared_ptr<CallerRecord> caller);
619 
620     /**
621      * add connect record to the list.
622      *
623      */
624     void AddConnectRecordToList(const std::shared_ptr<ConnectionRecord> &connRecord);
625 
626     /**
627      * get the list of connect record.
628      *
629      */
630     std::list<std::shared_ptr<ConnectionRecord>> GetConnectRecordList() const;
631 
632     /**
633      * get the list of connect record.
634      *
635      */
636     std::list<std::shared_ptr<ConnectionRecord>> GetConnectingRecordList();
637 
638     /**
639      * remove the connect record from list.
640      *
641      */
642     void RemoveConnectRecordFromList(const std::shared_ptr<ConnectionRecord> &connRecord);
643 
644     /**
645      * check whether connect list is empty.
646      *
647      */
648     bool IsConnectListEmpty();
649 
650     /**
651      * add caller record
652      *
653      */
654     void AddCallerRecord(const sptr<IRemoteObject> &callerToken, int requestCode, std::string srcAbilityId = "");
655 
656     /**
657      * get caller record to list.
658      *
659      */
660     std::list<std::shared_ptr<CallerRecord>> GetCallerRecordList() const;
661     std::shared_ptr<AbilityRecord> GetCallerRecord() const;
662 
663     /**
664      * get connecting record from list.
665      *
666      */
667     std::shared_ptr<ConnectionRecord> GetConnectingRecord() const;
668 
669     /**
670      * get disconnecting record from list.
671      *
672      */
673     std::shared_ptr<ConnectionRecord> GetDisconnectingRecord() const;
674 
675     /**
676      * convert ability state (enum type to string type).
677      *
678      */
679     static std::string ConvertAbilityState(const AbilityState &state);
680 
681     static std::string ConvertAppState(const AppState &state);
682 
683     /**
684      * convert life cycle state to ability state .
685      *
686      */
687     static int ConvertLifeCycleToAbilityState(const AbilityLifeCycleState &state);
688 
689     /**
690      * get the ability record id.
691      *
692      */
GetRecordId()693     inline int GetRecordId() const
694     {
695         return recordId_;
696     }
697 
698     /**
699      * dump ability info.
700      *
701      */
702     void Dump(std::vector<std::string> &info);
703 
704     void DumpClientInfo(std::vector<std::string> &info, const std::vector<std::string> &params,
705         bool isClient = false, bool dumpConfig = true) const;
706 
707     /**
708      * Called when client complete dump.
709      *
710      * @param infos The dump info.
711      */
712     void DumpAbilityInfoDone(std::vector<std::string> &infos);
713 
714     /**
715      * dump ability state info.
716      *
717      */
718     void DumpAbilityState(std::vector<std::string> &info, bool isClient, const std::vector<std::string> &params);
719 
720     void SetStartTime();
721 
722     int64_t GetStartTime() const;
723 
724     /**
725      * dump service info.
726      *
727      */
728     void DumpService(std::vector<std::string> &info, bool isClient = false) const;
729 
730     /**
731      * dump service info.
732      *
733      */
734     void DumpService(std::vector<std::string> &info, std::vector<std::string> &params, bool isClient = false) const;
735 
736     /**
737      * set aconnect remote object.
738      *
739      */
740     void SetConnRemoteObject(const sptr<IRemoteObject> &remoteObject);
741 
742     /**
743      * get connect remote object.
744      *
745      */
746     sptr<IRemoteObject> GetConnRemoteObject() const;
747 
748     void AddStartId();
749     int GetStartId() const;
750 
751     void SetIsUninstallAbility();
752     /**
753      * Determine whether ability is uninstalled
754      *
755      * @return true: uninstalled false: installed
756      */
757     bool IsUninstallAbility() const;
758 
759     void SetLauncherRoot();
760     bool IsLauncherRoot() const;
761 
762     bool IsAbilityState(const AbilityState &state) const;
763     bool IsActiveState() const;
764 
765     void SetStartSetting(const std::shared_ptr<AbilityStartSetting> &setting);
766     std::shared_ptr<AbilityStartSetting> GetStartSetting() const;
767 
768     void SetRestarting(const bool isRestart);
769     void SetRestarting(const bool isRestart, int32_t canReStartCount);
770     int32_t GetRestartCount() const;
771     void SetRestartCount(int32_t restartCount);
772     void SetKeepAlive();
773     int64_t GetRestartTime();
774     void SetRestartTime(const int64_t restartTime);
775     void SetAppIndex(const int32_t appIndex);
776     int32_t GetAppIndex() const;
777     bool IsRestarting() const;
778     void SetAppState(const AppState &state);
779     AppState GetAppState() const;
780 
781     void SetLaunchReason(const LaunchReason &reason);
782     void SetLastExitReason(const LastExitReason &reason);
783     void ContinueAbility(const std::string &deviceId, uint32_t versionCode);
784     void NotifyContinuationResult(int32_t result);
785     std::shared_ptr<MissionList> GetOwnedMissionList() const;
786 
787     void SetMission(const std::shared_ptr<Mission> &mission);
788     void SetMissionList(const std::shared_ptr<MissionList> &missionList);
789     std::shared_ptr<Mission> GetMission() const;
790     int32_t GetMissionId() const;
791 
792     void SetUid(int32_t uid);
793     int32_t GetUid();
794     int32_t GetPid();
795     void SetSwitchingPause(bool state);
796     bool IsSwitchingPause();
797     void SetOwnerMissionUserId(int32_t userId);
798     int32_t GetOwnerMissionUserId();
799 
800     // new version
801     ResolveResultType Resolve(const AbilityRequest &abilityRequest);
802     bool ReleaseCall(const sptr<IAbilityConnection> &connect);
803     bool IsNeedToCallRequest() const;
804     bool IsStartedByCall() const;
805     void SetStartedByCall(const bool isFlag);
806     void CallRequest();
807     bool CallRequestDone(const sptr<IRemoteObject> &callStub) const;
808     bool IsStartToBackground() const;
809     void SetStartToBackground(const bool flag);
810     bool IsStartToForeground() const;
811     void SetStartToForeground(const bool flag);
812     void SetMinimizeReason(bool fromUser);
813     bool IsMinimizeFromUser() const;
814     void SetClearMissionFlag(bool clearMissionFlag);
815     bool IsClearMissionFlag();
816 
817     void SetSpecifiedFlag(const std::string &flag);
818     std::string GetSpecifiedFlag() const;
819     void SetWindowMode(int32_t windowMode);
820     void RemoveWindowMode();
821     LifeCycleStateInfo lifeCycleStateInfo_;                // target life state info
822     #ifdef ABILITY_COMMAND_FOR_TEST
823     int BlockAbility();
824     #endif
825 
826     bool CanRestartRootLauncher();
827 
828     bool CanRestartResident();
829 
830     std::string GetLabel();
831 
832     void SetPendingState(AbilityState state);
833     AbilityState GetPendingState() const;
834 
835     bool IsNeedBackToOtherMissionStack();
836     void SetNeedBackToOtherMissionStack(bool isNeedBackToOtherMissionStack);
837     std::shared_ptr<AbilityRecord> GetOtherMissionStackAbilityRecord() const;
838     void SetOtherMissionStackAbilityRecord(const std::shared_ptr<AbilityRecord> &abilityRecord);
839     void RemoveUriPermission();
840 
841 protected:
842     void SendEvent(uint32_t msg, uint32_t timeOut);
843 
844     sptr<Token> token_ = {};                               // used to interact with kit and wms
845     std::unique_ptr<LifecycleDeal> lifecycleDeal_ = {};    // life manager used to schedule life
846     AbilityState currentState_ = AbilityState::INITIAL;    // current life state
847     Want want_ = {};                                       // want to start this ability
848     static int64_t g_abilityRecordEventId_;
849     int64_t eventId_ = 0;                                  // post event id
850 
851 private:
852     /**
853      * get the type of ability.
854      *
855      */
856     void GetAbilityTypeString(std::string &typeStr);
857     void OnSchedulerDied(const wptr<IRemoteObject> &remote);
858     void GrantUriPermission(const Want &want, int32_t userId, uint32_t targetTokenId);
859     int32_t GetCurrentAccountId() const;
860 
861     /**
862      * add system ability caller record
863      *
864      */
865     void AddSystemAbilityCallerRecord(const sptr<IRemoteObject> &callerToken, int requestCode,
866         std::string srcAbilityId);
867 
868     bool IsSystemAbilityCall(const sptr<IRemoteObject> &callerToken);
869 
870     void HandleDlpAttached();
871     void HandleDlpClosed();
SetCallerAccessTokenId(uint32_t callerAccessTokenId)872     inline void SetCallerAccessTokenId(uint32_t callerAccessTokenId)
873     {
874         callerAccessTokenId_ = callerAccessTokenId;
875     }
876 
877 #ifdef SUPPORT_GRAPHICS
878     std::shared_ptr<Want> GetWantFromMission() const;
879     void SetShowWhenLocked(const AppExecFwk::AbilityInfo &abilityInfo, sptr<AbilityTransitionInfo> &info) const;
880     void SetAbilityTransitionInfo(const AppExecFwk::AbilityInfo &abilityInfo,
881         sptr<AbilityTransitionInfo> &info) const;
882     void SetAbilityTransitionInfo(sptr<AbilityTransitionInfo>& info) const;
883     sptr<IWindowManagerServiceHandler> GetWMSHandler() const;
884     void SetWindowModeAndDisplayId(sptr<AbilityTransitionInfo> &info, const std::shared_ptr<Want> &want) const;
885     sptr<AbilityTransitionInfo> CreateAbilityTransitionInfo();
886     sptr<AbilityTransitionInfo> CreateAbilityTransitionInfo(const std::shared_ptr<StartOptions> &startOptions,
887         const std::shared_ptr<Want> &want) const;
888     sptr<AbilityTransitionInfo> CreateAbilityTransitionInfo(const AbilityRequest &abilityRequest) const;
889     sptr<AbilityTransitionInfo> CreateAbilityTransitionInfo(const std::shared_ptr<StartOptions> &startOptions,
890         const std::shared_ptr<Want> &want, const AbilityRequest &abilityRequest);
891     std::shared_ptr<Global::Resource::ResourceManager> CreateResourceManager() const;
892     std::shared_ptr<Media::PixelMap> GetPixelMap(const uint32_t windowIconId,
893         std::shared_ptr<Global::Resource::ResourceManager> resourceMgr) const;
894 
895     void AnimationTask(bool isRecent, const AbilityRequest &abilityRequest,
896         const std::shared_ptr<StartOptions> &startOptions, const std::shared_ptr<AbilityRecord> &callerAbility);
897     void NotifyAnimationFromStartingAbility(const std::shared_ptr<AbilityRecord> &callerAbility,
898         const AbilityRequest &abilityRequest) const;
899     void NotifyAnimationFromRecentTask(const std::shared_ptr<StartOptions> &startOptions,
900         const std::shared_ptr<Want> &want) const;
901     void NotifyAnimationFromTerminatingAbility(const std::shared_ptr<AbilityRecord> &callerAbility, bool flag);
902 
903     void StartingWindowTask(bool isRecent, bool isCold, const AbilityRequest &abilityRequest,
904         std::shared_ptr<StartOptions> &startOptions);
905     void StartingWindowColdTask(bool isRecnet, const AbilityRequest &abilityRequest,
906         std::shared_ptr<StartOptions> &startOptions);
907     void PostCancelStartingWindowColdTask();
908     void StartingWindowHot(const std::shared_ptr<StartOptions> &startOptions, const std::shared_ptr<Want> &want,
909         const AbilityRequest &abilityRequest);
910     void StartingWindowHot();
911     void StartingWindowCold(const std::shared_ptr<StartOptions> &startOptions, const std::shared_ptr<Want> &want,
912         const AbilityRequest &abilityRequest);
913     void InitColdStartingWindowResource(const std::shared_ptr<Global::Resource::ResourceManager> &resourceMgr);
914     void GetColdStartingWindowResource(std::shared_ptr<Media::PixelMap> &bg, uint32_t &bgColor);
915 #endif
916 
917     static int64_t abilityRecordId;
918     int recordId_ = 0;                                // record id
919     AppExecFwk::AbilityInfo abilityInfo_ = {};             // the ability info get from BMS
920     AppExecFwk::ApplicationInfo applicationInfo_ = {};     // the ability info get from BMS
921     std::weak_ptr<AbilityRecord> preAbilityRecord_ = {};   // who starts this ability record
922     std::weak_ptr<AbilityRecord> nextAbilityRecord_ = {};  // ability that started by this ability
923     int64_t startTime_ = 0;                           // records first time of ability start
924     int64_t restartTime_ = 0;                         // the time of last trying restart
925     bool isReady_ = false;                            // is ability thread attached?
926     bool isWindowAttached_ = false;                   // Is window of this ability attached?
927     bool isLauncherAbility_ = false;                  // is launcher?
928     bool isKeepAlive_ = false;                 // is keep alive or resident ability?
929 
930     sptr<IAbilityScheduler> scheduler_ = {};       // kit scheduler
931     bool isTerminating_ = false;              // is terminating ?
932     bool isCreateByConnect_ = false;          // is created by connect ability mode?
933 
934     int requestCode_ = -1;  // requestCode_: >= 0 for-result start mode; <0 for normal start mode in default.
935     sptr<IRemoteObject::DeathRecipient> schedulerDeathRecipient_ = {};  // scheduler binderDied Recipient
936 
937     /**
938      * result_: ability starts with for-result mode will send result before being terminated.
939      * Its caller will receive results before active.
940      * Now we assume only one result generate when terminate.
941      */
942     std::shared_ptr<AbilityResult> result_ = {};
943 
944     // service(ability) can be connected by multi-pages(abilites), so need to store this service's connections
945     std::list<std::shared_ptr<ConnectionRecord>> connRecordList_ = {};
946     // service(ability) onConnect() return proxy of service ability
947     sptr<IRemoteObject> connRemoteObject_ = {};
948     int startId_ = 0;  // service(ability) start id
949 
950     // page(ability) can be started by multi-pages(abilites), so need to store this ability's caller
951     std::list<std::shared_ptr<CallerRecord>> callerList_ = {};
952 
953     bool isUninstall_ = false;
954     const static std::map<AbilityState, std::string> stateToStrMap;
955     const static std::map<AbilityLifeCycleState, AbilityState> convertStateMap;
956     const static std::map<AppState, std::string> appStateToStrMap_;
957 
958     bool isLauncherRoot_ = false;
959 
960     PacMap stateDatas_;             // ability saved ability state data
961     bool isRestarting_ = false;     // is restarting ?
962     AppState appState_ = AppState::BEGIN;
963 
964     int32_t uid_ = 0;
965     int32_t pid_ = 0;
966     std::weak_ptr<MissionList> missionList_;
967     std::weak_ptr<Mission> mission_;
968     int32_t missionId_ = -1;
969     int32_t ownerMissionUserId_ = -1;
970     bool isSwitchingPause_ = false;
971 
972 	// new version
973     std::shared_ptr<CallContainer> callContainer_ = nullptr;
974     bool isStartedByCall_ = false;
975     bool isStartToBackground_ = false;
976     bool isStartToForeground_ = false;
977     int32_t appIndex_ = 0;
978     bool minimizeReason_ = false;
979 
980     bool clearMissionFlag_ = false;
981 
982     int32_t restartCount_ = -1;
983     int32_t restartMax_ = -1;
984     std::string specifiedFlag_;
985     std::mutex lock_;
986     mutable std::mutex dumpInfoLock_;
987     mutable std::mutex dumpLock_;
988     mutable std::condition_variable dumpCondition_;
989     mutable bool isDumpTimeout_ = false;
990     std::vector<std::string> dumpInfos_;
991     std::atomic<AbilityState> pendingState_ = AbilityState::INITIAL;    // pending life state
992 
993 #ifdef SUPPORT_GRAPHICS
994     bool isStartingWindow_ = false;
995     uint32_t bgColor_ = 0;
996     std::shared_ptr<Media::PixelMap> startingWindowBg_ = nullptr;
997 
998     bool isCompleteFirstFrameDrawing_ = false;
999 #endif
1000 
1001     bool isGrantedUriPermission_ = false;
1002     uint32_t callerAccessTokenId_ = -1;
1003     bool isNeedBackToOtherMissionStack_ = false;
1004     std::weak_ptr<AbilityRecord> otherMissionStackAbilityRecord_; // who starts this ability record by SA
1005 };
1006 }  // namespace AAFwk
1007 }  // namespace OHOS
1008 #endif  // OHOS_ABILITY_RUNTIME_ABILITY_RECORD_H
1009