• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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_APP_RUNNING_RECORD_H
17 #define OHOS_ABILITY_RUNTIME_APP_RUNNING_RECORD_H
18 
19 #include <list>
20 #include <map>
21 #include <memory>
22 #include <string>
23 #include <unordered_set>
24 
25 #include "cpp/mutex.h"
26 #include "iremote_object.h"
27 #include "irender_scheduler.h"
28 #include "ability_running_record.h"
29 #include "ability_state_data.h"
30 #include "application_info.h"
31 #include "task_handler_wrap.h"
32 #include "app_mgr_service_event_handler.h"
33 #include "app_death_recipient.h"
34 #include "app_launch_data.h"
35 #include "app_mgr_constants.h"
36 #include "app_scheduler_proxy.h"
37 #include "app_record_id.h"
38 #include "child_process_record.h"
39 #include "fault_data.h"
40 #include "profile.h"
41 #include "priority_object.h"
42 #include "app_lifecycle_deal.h"
43 #include "module_running_record.h"
44 #include "app_spawn_client.h"
45 #include "app_malloc_info.h"
46 #include "app_jsheap_mem_info.h"
47 
48 namespace OHOS {
49 namespace Rosen {
50 class WindowVisibilityInfo;
51 }
52 namespace AppExecFwk {
53 class AbilityRunningRecord;
54 class AppMgrServiceInner;
55 class AppRunningRecord;
56 
57 class MultiUserConfigurationMgr {
58 public:
59     void Insert(const int32_t userId, const Configuration& config);
60 
61     Configuration GetConfigurationByUserId(const int32_t userId);
62 
63 private:
64     std::map<int32_t, Configuration> multiUserConfiguration_;
65     std::mutex multiUserConfigurationMutex_;
66 };
67 
68 /**
69  * @class RenderRecord
70  * Record nweb render process info.
71  */
72 class RenderRecord {
73 public:
74     RenderRecord(pid_t hostPid, const std::string &renderParam, int32_t ipcFd,
75                  int32_t sharedFd, int32_t crashFd,
76                  const std::shared_ptr<AppRunningRecord> &host);
77 
78     virtual ~RenderRecord();
79 
80     static std::shared_ptr<RenderRecord>
81     CreateRenderRecord(pid_t hostPid, const std::string &renderParam,
82                        int32_t ipcFd, int32_t sharedFd, int32_t crashFd,
83                        const std::shared_ptr<AppRunningRecord> &host);
84 
85     void SetPid(pid_t pid);
86     pid_t GetPid() const ;
87     pid_t GetHostPid() const;
88     void SetUid(int32_t uid);
89     int32_t GetUid() const;
90     int32_t GetHostUid() const;
91     std::string GetHostBundleName() const;
92     std::string GetRenderParam() const;
93     std::string GetProcessName() const;
94     int32_t GetIpcFd() const;
95     int32_t GetSharedFd() const;
96     int32_t GetCrashFd() const;
97     ProcessType GetProcessType() const;
98     std::shared_ptr<AppRunningRecord> GetHostRecord() const;
99     sptr<IRenderScheduler> GetScheduler() const;
100     void SetScheduler(const sptr<IRenderScheduler> &scheduler);
101     void SetDeathRecipient(const sptr<AppDeathRecipient> recipient);
102     void RegisterDeathRecipient();
103     void SetState(int32_t state);
104     int32_t GetState() const;
105     void SetProcessType(ProcessType type);
106 
107 private:
108     void SetHostUid(const int32_t hostUid);
109     void SetHostBundleName(const std::string &hostBundleName);
110     void SetProcessName(const std::string &hostProcessName);
111 
112     pid_t pid_ = 0;
113     pid_t hostPid_ = 0;
114     int32_t uid_ = 0;
115     int32_t hostUid_ = 0;
116     std::string hostBundleName_;
117     std::string renderParam_;
118     std::string processName_;
119     int32_t ipcFd_ = 0;
120     int32_t sharedFd_ = 0;
121     int32_t crashFd_ = 0;
122     int32_t state_ = 0;
123     ProcessType processType_ = ProcessType::RENDER;
124     std::weak_ptr<AppRunningRecord> host_; // nweb host
125     sptr<IRenderScheduler> renderScheduler_ = nullptr;
126     sptr<AppDeathRecipient> deathRecipient_ = nullptr;
127 };
128 
129 class AppRunningRecord : public std::enable_shared_from_this<AppRunningRecord> {
130 public:
131     static int64_t appEventId_;
132 public:
133     AppRunningRecord(
134         const std::shared_ptr<ApplicationInfo> &info, const int32_t recordId, const std::string &processName);
135     virtual ~AppRunningRecord() = default;
136 
137     /**
138      * @brief Obtains the app record bundleName.
139      *
140      * @return Returns app record bundleName.
141      */
142     const std::string &GetBundleName() const;
143 
144     /**
145      * @brief Obtains the app record CallerPid.
146      *
147      * @return Returns app record CallerPid.
148      */
149     int32_t GetCallerPid() const;
150 
151     /**
152      * @brief Setting the Caller pid.
153      *
154      * @param CallerUid, the Caller pid.
155      */
156     void SetCallerPid(int32_t pid);
157 
158     /**
159      * @brief Obtains the app record CallerUid.
160      *
161      * @return Returns app record CallerUid.
162      */
163     int32_t GetCallerUid() const;
164 
165     /**
166      * @brief Setting the Caller uid.
167      *
168      * @param CallerUid, the Caller uid.
169      */
170     void SetCallerUid(int32_t uid);
171 
172     /**
173      * @brief Obtains the app record CallerTokenId.
174      *
175      * @return Returns app record CallerTokenId.
176      */
177     int32_t GetCallerTokenId() const;
178 
179     /**
180      * @brief Setting the Caller tokenId.
181      *
182      * @param CallerToken, the Caller tokenId.
183      */
184     void SetCallerTokenId(int32_t tokenId);
185 
186     /**
187      * @brief Obtains the app record isLauncherApp flag.
188      *
189      * @return Returns app record isLauncherApp flag.
190      */
191     bool IsLauncherApp() const;
192 
193     /**
194      * @brief Obtains the app record id.
195      *
196      * @return Returns app record id.
197      */
198     int32_t GetRecordId() const;
199 
200     /**
201      * @brief Obtains the app name.
202      *
203      * @return Returns the app name.
204      */
205     const std::string &GetName() const;
206 
207     /**
208      * @brief Obtains the process name.
209      *
210      * @return Returns the process name.
211      */
212     const std::string &GetProcessName() const;
213 
214     /**
215      * @brief Obtains the the flag of specified process.
216      *
217      * @return Returns the the flag of specified process.
218      */
219     const std::string &GetSpecifiedProcessFlag() const;
220 
221     /**
222      * @brief Setting the the flag of specified process.
223      *
224      * @param flag, the the flag of specified process.
225      */
226     void SetSpecifiedProcessFlag(const std::string &flag);
227 
228     /**
229      * @brief Obtains the sign code.
230      *
231      * @return Returns the sign code.
232      */
233     const std::string &GetSignCode() const;
234 
235     /**
236      * @brief Setting the sign code.
237      *
238      * @param code, the sign code.
239      */
240     void SetSignCode(const std::string &signCode);
241 
242     /**
243      * @brief Obtains the jointUserId.
244      *
245      * @return Returns the jointUserId.
246      */
247     const std::string &GetJointUserId() const;
248 
249     /**
250      * @brief Setting the jointUserId.
251      *
252      * @param jointUserId, the jointUserId.
253      */
254     void SetJointUserId(const std::string &jointUserId);
255 
256     /**
257      * @brief Obtains the application uid.
258      *
259      * @return Returns the application uid.
260      */
261     int32_t GetUid() const;
262 
263     /**
264      * @brief Setting the application uid.
265      *
266      * @param state, the application uid.
267      */
268     void SetUid(const int32_t uid);
269 
270     // Get current state for this process
271 
272     /**
273      * @brief Obtains the application state.
274      *
275      * @return Returns the application state.
276      */
277     ApplicationState GetState() const;
278 
279     // Set current state for this process
280 
281     /**
282      * @brief Setting the application state.
283      *
284      * @param state, the application state.
285      */
286     void SetState(const ApplicationState state);
287 
288     // Get abilities_ for this process
289     /**
290      * @brief Obtains the abilities info for the application record.
291      *
292      * @return Returns the abilities info for the application record.
293      */
294     const std::map<const sptr<IRemoteObject>, std::shared_ptr<AbilityRunningRecord>> GetAbilities();
295     // Update appThread with appThread
296 
297     /**
298      * @brief Setting the application client.
299      *
300      * @param thread, the application client.
301      */
302     void SetApplicationClient(const sptr<IAppScheduler> &thread);
303 
304     /**
305      * @brief Obtains the application client.
306      *
307      * @return Returns the application client.
308      */
309     sptr<IAppScheduler> GetApplicationClient() const;
310 
311     void AddModule(std::shared_ptr<ApplicationInfo> appInfo, std::shared_ptr<AbilityInfo> abilityInfo,
312         sptr<IRemoteObject> token, const HapModuleInfo &hapModuleInfo,
313         std::shared_ptr<AAFwk::Want> want, int32_t abilityRecordId);
314 
315     void AddModules(const std::shared_ptr<ApplicationInfo> &appInfo, const std::vector<HapModuleInfo> &moduleInfos);
316 
317     std::shared_ptr<ModuleRunningRecord> GetModuleRecordByModuleName(
318         const std::string bundleName, const std::string &moduleName);
319 
320     std::shared_ptr<ModuleRunningRecord> GetModuleRunningRecordByToken(const sptr<IRemoteObject> &token) const;
321 
322     std::shared_ptr<ModuleRunningRecord> GetModuleRunningRecordByTerminateLists(const sptr<IRemoteObject> &token) const;
323 
324     std::shared_ptr<AbilityRunningRecord> GetAbilityRunningRecord(const int64_t eventId) const;
325 
326     /**
327      * @brief Setting the Trim Memory Level.
328      *
329      * @param level, the Memory Level.
330      */
331     void SetTrimMemoryLevel(int32_t level);
332 
333     /**
334      * LaunchApplication, Notify application to launch application.
335      *
336      * @return
337      */
338     void LaunchApplication(const Configuration &config);
339 
340     /**
341      * AddAbilityStage, Notify application to ability stage.
342      *
343      * @return
344      */
345     void AddAbilityStage();
346 
347     /**
348      * AddAbilityStageBySpecifiedAbility, Notify application to ability stage.
349      *
350      * @return Return true if the ability stage need to be add, otherwise it returns false.
351      */
352     bool AddAbilityStageBySpecifiedAbility(const std::string &bundleName);
353 
354     void AddAbilityStageBySpecifiedProcess(const std::string &bundleName);
355 
356     /**
357      * AddAbilityStage Result returned.
358      *
359      * @return
360      */
361     void AddAbilityStageDone();
362 
363     /**
364      * update the application info after new module installed.
365      *
366      * @param appInfo The latest application info obtained from bms for update abilityRuntimeContext.
367      *
368      * @return
369      */
370     void UpdateApplicationInfoInstalled(const ApplicationInfo &appInfo);
371 
372     /**
373      * LaunchAbility, Notify application to launch ability.
374      *
375      * @param ability, the ability record.
376      *
377      * @return
378      */
379     void LaunchAbility(const std::shared_ptr<AbilityRunningRecord> &ability);
380 
381     /**
382      * LaunchPendingAbilities, Launch Pending Abilities.
383      *
384      * @return
385      */
386     void LaunchPendingAbilities();
387 
388     /**
389      * LowMemoryWarning, Low memory warning.
390      *
391      * @return
392      */
393     void LowMemoryWarning();
394 
395     /**
396      * ScheduleTerminate, Notify application to terminate.
397      *
398      * @return
399      */
400     void ScheduleTerminate();
401 
402     /**
403      * ScheduleTerminate, Notify application process exit safely.
404      *
405      * @return
406      */
407     void ScheduleProcessSecurityExit();
408 
409     /**
410      * ScheduleTrimMemory, Notifies the application of the memory seen.
411      *
412      * @return
413      */
414     void ScheduleTrimMemory();
415 
416     /**
417      * ScheduleMemoryLevel, Notifies the application of the current memory.
418      *
419      * @return
420      */
421     void ScheduleMemoryLevel(int32_t level);
422 
423     /**
424      * ScheduleHeapMemory, Get the application's memory allocation info.
425      *
426      * @param pid, pid input.
427      * @param mallocInfo, dynamic storage information output.
428      *
429      * @return
430      */
431     void ScheduleHeapMemory(const int32_t pid, OHOS::AppExecFwk::MallocInfo &mallocInfo);
432 
433     /**
434      * ScheduleJsHeapMemory, triggerGC and dump the application's jsheap memory info.
435      *
436      * @param info, pid, tid, needGc, needSnapshot
437      *
438      * @return
439      */
440     void ScheduleJsHeapMemory(OHOS::AppExecFwk::JsHeapDumpInfo &info);
441 
442     /**
443      * GetAbilityRunningRecordByToken, Obtaining the ability record through token.
444      *
445      * @param token, the unique identification to the ability.
446      *
447      * @return
448      */
449     std::shared_ptr<AbilityRunningRecord> GetAbilityRunningRecordByToken(const sptr<IRemoteObject> &token) const;
450 
451     std::shared_ptr<AbilityRunningRecord> GetAbilityByTerminateLists(const sptr<IRemoteObject> &token) const;
452 
453     /**
454      * UpdateAbilityState, update the ability status.
455      *
456      * @param token, the unique identification to update the ability.
457      * @param state, ability status that needs to be updated.
458      *
459      * @return
460      */
461     void UpdateAbilityState(const sptr<IRemoteObject> &token, const AbilityState state);
462 
463     /**
464      * PopForegroundingAbilityTokens, Extract the token record from the foreground tokens list.
465      *
466      * @return
467      */
468     void PopForegroundingAbilityTokens();
469 
470     /**
471      * TerminateAbility, terminate the token ability.
472      *
473      * @param token, he unique identification to terminate the ability.
474      *
475      * @return
476      */
477     void TerminateAbility(const sptr<IRemoteObject> &token, const bool isForce, bool isTimeout = false);
478 
479     /**
480      * AbilityTerminated, terminate the ability.
481      *
482      * @param token, the unique identification to terminated the ability.
483      *
484      * @return
485      */
486     void AbilityTerminated(const sptr<IRemoteObject> &token);
487 
488     /**
489      * @brief Setting application service internal handler instance.
490      *
491      * @param serviceInner, application service internal handler instance.
492      */
493     void SetAppMgrServiceInner(const std::weak_ptr<AppMgrServiceInner> &inner);
494 
495     /**
496      * @brief Setting application death recipient.
497      *
498      * @param appDeathRecipient, application death recipient instance.
499      */
500     void SetAppDeathRecipient(const sptr<AppDeathRecipient> &appDeathRecipient);
501 
502     /**
503      * @brief Obtains application priority info.
504      *
505      * @return Returns the application priority info.
506      */
507     std::shared_ptr<PriorityObject> GetPriorityObject();
508 
509     /**
510      * Remove application death recipient record.
511      *
512      * @return
513      */
514     void RemoveAppDeathRecipient() const;
515 
516     /**
517     *  Notify application update system environment changes.
518     *
519     * @param config System environment change parameters.
520     * @return Returns ERR_OK on success, others on failure.
521     */
522     int32_t UpdateConfiguration(const Configuration &config);
523 
524     void SetTaskHandler(std::shared_ptr<AAFwk::TaskHandlerWrap> taskHandler);
525     void SetEventHandler(const std::shared_ptr<AMSEventHandler> &handler);
526 
527     int64_t GetEventId() const;
528 
529     bool IsLastAbilityRecord(const sptr<IRemoteObject> &token);
530 
531     bool IsLastPageAbilityRecord(const sptr<IRemoteObject> &token);
532 
533     bool ExtensionAbilityRecordExists();
534 
535     void SetTerminating();
536 
537     bool IsTerminating();
538 
539     bool IsKeepAliveApp() const;
540 
541     bool IsEmptyKeepAliveApp() const;
542 
543     bool IsMainProcess() const;
544 
545     void SetEmptyKeepAliveAppState(bool isEmptyKeepAliveApp);
546 
547     void SetKeepAliveEnableState(bool isKeepAliveEnable);
548     void SetKeepAliveBundle(bool isKeepAliveBundle);
549 
550     void SetMainProcess(bool isMainProcess);
551 
552     void SetSingleton(bool isSingleton);
553 
554     void SetStageModelState(bool isStageBasedModel);
555 
556     std::list<std::shared_ptr<ModuleRunningRecord>> GetAllModuleRecord() const;
557 
558     const std::list<std::shared_ptr<ApplicationInfo>> GetAppInfoList();
559 
560     void SetAppIdentifier(const std::string &appIdentifier);
561     const std::string &GetAppIdentifier() const;
562 
GetApplicationInfo()563     inline const std::shared_ptr<ApplicationInfo> GetApplicationInfo()
564     {
565         return appInfo_;
566     }
567 
568     void SetRestartResidentProcCount(int count);
569     void DecRestartResidentProcCount();
570     int GetRestartResidentProcCount() const;
571     bool CanRestartResidentProc();
572 
573     /**
574      * Notify observers when state change.
575      *
576      * @param ability, ability or extension record.
577      * @param state, ability or extension state.
578      */
579     void StateChangedNotifyObserver(
580         const std::shared_ptr<AbilityRunningRecord> &ability,
581         int32_t state,
582         bool isAbility,
583         bool isFromWindowFocusChanged);
584 
585     void insertAbilityStageInfo(std::vector<HapModuleInfo> moduleInfos);
586 
587     void GetBundleNames(std::vector<std::string> &bundleNames);
588 
589     void SetUserTestInfo(const std::shared_ptr<UserTestRecord> &record);
590     std::shared_ptr<UserTestRecord> GetUserTestInfo();
591 
592     void SetProcessAndExtensionType(const std::shared_ptr<AbilityInfo> &abilityInfo);
593     void SetSpecifiedAbilityFlagAndWant(int requestId, const AAFwk::Want &want, const std::string &moduleName);
594     void SetScheduleNewProcessRequestState(int32_t requestId, const AAFwk::Want &want, const std::string &moduleName);
595     bool IsNewProcessRequest() const;
596     bool IsStartSpecifiedAbility() const;
597     int32_t GetSpecifiedRequestId() const;
598     void ResetSpecifiedRequestId();
599     void ScheduleAcceptWant(const std::string &moduleName);
600     void ScheduleAcceptWantDone();
601     void ScheduleNewProcessRequest(const AAFwk::Want &want, const std::string &moduleName);
602     void ScheduleNewProcessRequestDone();
603     void ApplicationTerminated();
604     AAFwk::Want GetSpecifiedWant() const;
605     AAFwk::Want GetNewProcessRequestWant() const;
606     int32_t GetNewProcessRequestId() const;
607     void ResetNewProcessRequestId();
608     void SetDebugApp(bool isDebugApp);
609     bool IsDebugApp();
610     bool IsDebugging() const;
611     void SetErrorInfoEnhance(const bool errorInfoEnhance);
612     void SetNativeDebug(bool isNativeDebug);
613     void SetPerfCmd(const std::string &perfCmd);
614     void SetMultiThread(const bool multiThread);
615     void AddRenderRecord(const std::shared_ptr<RenderRecord> &record);
616     void RemoveRenderRecord(const std::shared_ptr<RenderRecord> &record);
617     void RemoveRenderPid(pid_t pid);
618     bool ConstainsRenderPid(pid_t renderPid);
619     std::shared_ptr<RenderRecord> GetRenderRecordByPid(const pid_t pid);
620     std::map<int32_t, std::shared_ptr<RenderRecord>> GetRenderRecordMap();
621     void SetStartMsg(const AppSpawnStartMsg &msg);
622     AppSpawnStartMsg GetStartMsg();
623 
624     void SendEventForSpecifiedAbility(uint32_t msg, int64_t timeOut);
625 
626     void SendAppStartupTypeEvent(const std::shared_ptr<AbilityRunningRecord> &ability, const AppStartType startType);
627     void SetKilling();
628     bool IsKilling() const;
629     void SetAppIndex(const int32_t appIndex);
630     int32_t GetAppIndex() const;
631     void SetSecurityFlag(bool securityFlag);
632     bool GetSecurityFlag() const;
633 
634     using Closure = std::function<void()>;
635     void PostTask(std::string msg, int64_t timeOut, const Closure &task);
636     bool CancelTask(std::string msg);
637     void RemoveTerminateAbilityTimeoutTask(const sptr<IRemoteObject>& token) const;
638 
639     int32_t NotifyLoadRepairPatch(const std::string &bundleName, const sptr<IQuickFixCallback> &callback,
640         const int32_t recordId);
641 
642     int32_t NotifyHotReloadPage(const sptr<IQuickFixCallback> &callback, const int32_t recordId);
643 
644     int32_t NotifyUnLoadRepairPatch(const std::string &bundleName, const sptr<IQuickFixCallback> &callback,
645         const int32_t recordId);
646 
647     bool IsContinuousTask();
648 
649     void SetContinuousTaskAppState(bool isContinuousTask);
650 
651     /**
652      * Update target ability focus state.
653      *
654      * @param token the token of target ability.
655      * @param isFocus focus state.
656      *
657      * @return true if process focus state changed, false otherwise.
658      */
659     bool UpdateAbilityFocusState(const sptr<IRemoteObject> &token, bool isFocus);
660 
661     bool GetFocusFlag() const;
662 
663     int64_t GetAppStartTime() const;
664 
665     void SetRestartTimeMillis(const int64_t restartTimeMillis);
666     void SetRequestProcCode(int32_t requestProcCode);
667 
668     int32_t GetRequestProcCode() const;
669 
670     void SetProcessChangeReason(ProcessChangeReason reason);
671 
672     bool NeedUpdateConfigurationBackground();
673 
674     ProcessChangeReason GetProcessChangeReason() const;
675 
676     ExtensionAbilityType GetExtensionType() const;
677     ProcessType GetProcessType() const;
678 
679     int32_t NotifyAppFault(const FaultData &faultData);
680 
681     void OnWindowVisibilityChanged(const std::vector<sptr<OHOS::Rosen::WindowVisibilityInfo>> &windowVisibilityInfos);
682 
683     bool IsAbilitytiesBackground();
684 
SetAbilityForegroundingFlag()685     inline void SetAbilityForegroundingFlag()
686     {
687         isAbilityForegrounding_.store(true);
688     }
689 
GetAbilityForegroundingFlag()690     inline bool GetAbilityForegroundingFlag()
691     {
692         return isAbilityForegrounding_.load();
693     }
694 
SetSpawned()695     inline void SetSpawned()
696     {
697         isSpawned_.store(true);
698     }
699 
GetSpawned()700     inline bool GetSpawned() const
701     {
702         return isSpawned_.load();
703     }
704 
705     std::map<pid_t, std::weak_ptr<AppRunningRecord>> GetChildAppRecordMap() const;
706     void AddChildAppRecord(pid_t pid, std::shared_ptr<AppRunningRecord> appRecord);
707     void RemoveChildAppRecord(pid_t pid);
708     void ClearChildAppRecordMap();
709 
710     void SetParentAppRecord(std::shared_ptr<AppRunningRecord> appRecord);
711     std::shared_ptr<AppRunningRecord> GetParentAppRecord();
712 
713     /**
714      * @brief Notify NativeEngine GC of status change.
715      *
716      * @param state GC state
717      *
718      * @return Is the status change completed.
719      */
720     int32_t ChangeAppGcState(const int32_t state);
721 
722     void SetAttachDebug(const bool &isAttachDebug);
723     bool isAttachDebug() const;
724 
725     void SetApplicationPendingState(ApplicationPendingState pendingState);
726     ApplicationPendingState GetApplicationPendingState() const;
727 
728     void SetApplicationScheduleState(ApplicationScheduleState scheduleState);
729     ApplicationScheduleState GetApplicationScheduleState() const;
730 
731     void GetSplitModeAndFloatingMode(bool &isSplitScreenMode, bool &isFloatingWindowMode);
732 
733     void AddChildProcessRecord(pid_t pid, const std::shared_ptr<ChildProcessRecord> record);
734     void RemoveChildProcessRecord(const std::shared_ptr<ChildProcessRecord> record);
735     std::shared_ptr<ChildProcessRecord> GetChildProcessRecordByPid(const pid_t pid);
736     std::map<pid_t, std::shared_ptr<ChildProcessRecord>> GetChildProcessRecordMap();
737     int32_t GetChildProcessCount();
738 
739     void SetPreloadState(PreloadState state);
740 
741     bool IsPreloading() const;
742 
743     bool IsPreloaded() const;
744 
745     /**
746      * @brief Obtains the app record assign tokenId.
747      *
748      * @return Returns app record AssignTokenId.
749      */
750     int32_t GetAssignTokenId() const;
751 
752     /**
753      * @brief Setting the assign tokenId.
754      *
755      * @param AssignTokenId, the assign tokenId.
756      */
757     void SetAssignTokenId(int32_t tokenId);
758     /**
759      * @brief Setting is aa start with native.
760      *
761      * @param isNativeStart, is aa start with native.
762      */
763     void SetNativeStart(bool isNativeStart);
764     /**
765      * @brief Obtains is native start.
766      *
767      * @return Returns is native start.
768      */
769     bool isNativeStart() const;
770 
771     void SetRestartAppFlag(bool isRestartApp);
772     bool GetRestartAppFlag() const;
773 
774     void SetAssertionPauseFlag(bool flag);
775     bool IsAssertionPause() const;
776 
777     void SetJITEnabled(const bool jitEnabled);
778     bool IsJITEnabled() const;
779 
780     int DumpIpcStart(std::string& result);
781     int DumpIpcStop(std::string& result);
782     int DumpIpcStat(std::string& result);
783 
784     int DumpFfrt(std::string &result);
785 
786     void SetExitReason(int32_t reason);
787     int32_t GetExitReason() const;
788 
789     void SetExitMsg(const std::string &exitMsg);
790     std::string GetExitMsg() const;
791 
792     bool SetSupportedProcessCache(bool isSupport);
793     SupportProcessCacheState GetSupportProcessCacheState();
794     void SetAttachedToStatusBar(bool isAttached);
795     bool IsAttachedToStatusBar();
796 
797     bool SetEnableProcessCache(bool enable);
798     bool GetEnableProcessCache();
799 
800     void ScheduleCacheProcess();
801 
802     void SetBrowserHost(sptr<IRemoteObject> browser);
803     sptr<IRemoteObject> GetBrowserHost();
804     void SetIsGPU(bool gpu);
805     bool GetIsGPU();
806     void SetGPUPid(pid_t gpuPid);
807     pid_t GetGPUPid();
808 
SetStrictMode(bool strictMode)809     inline void SetStrictMode(bool strictMode)
810     {
811         isStrictMode_ = strictMode;
812     }
813 
IsStrictMode()814     inline bool IsStrictMode()
815     {
816         return isStrictMode_;
817     }
818 
SetIsDependedOnArkWeb(bool isDepend)819     inline void SetIsDependedOnArkWeb(bool isDepend)
820     {
821         isDependedOnArkWeb_ = isDepend;
822     }
823 
IsDependedOnArkWeb()824     inline bool IsDependedOnArkWeb()
825     {
826         return isDependedOnArkWeb_;
827     }
828 
829     void SetProcessCacheBlocked(bool isBlocked);
830     bool GetProcessCacheBlocked();
831 
832     void SetProcessCaching(bool isCaching);
833     bool IsCaching();
834 
835     /**
836      * ScheduleForegroundRunning, Notify application to switch to foreground.
837      *
838      * @return bool operation status
839      */
840     bool ScheduleForegroundRunning();
841 
842     /**
843      * ScheduleBackgroundRunning, Notify application to switch to background.
844      *
845      * @return
846      */
847     void ScheduleBackgroundRunning();
848 
849     void SetUserRequestCleaning();
850     bool IsUserRequestCleaning() const;
851     bool IsAllAbilityReadyToCleanedByUserRequest();
852     bool IsProcessAttached() const;
853 
854 	// reocrds whehter uiability has launched before
855     void SetUIAbilityLaunched(bool hasLaunched);
856     bool HasUIAbilityLaunched();
857 
858     void AddAppLifecycleEvent(const std::string &msg);
859     void SetNWebPreload(const bool isAllowedNWebPreload);
860 private:
861     /**
862      * SearchTheModuleInfoNeedToUpdated, Get an uninitialized abilityStage data.
863      *
864      * @return If an uninitialized data is found return true,Otherwise return false.
865      */
866     bool GetTheModuleInfoNeedToUpdated(const std::string bundleName, HapModuleInfo &info);
867 
868     /**
869      * AbilityForeground, Handling the ability process when switching to the foreground.
870      *
871      * @param ability, the ability info.
872      *
873      * @return
874      */
875     void AbilityForeground(const std::shared_ptr<AbilityRunningRecord> &ability);
876 
877     /**
878      * AbilityBackground, Handling the ability process when switching to the background.
879      *
880      * @param ability, the ability info.
881      *
882      * @return
883      */
884     void AbilityBackground(const std::shared_ptr<AbilityRunningRecord> &ability);
885     // drive application state changes when ability state changes.
886 
887     bool AbilityFocused(const std::shared_ptr<AbilityRunningRecord> &ability);
888 
889     bool AbilityUnfocused(const std::shared_ptr<AbilityRunningRecord> &ability);
890 
891     void SendEvent(uint32_t msg, int64_t timeOut);
892 
893     void SendClearTask(uint32_t msg, int64_t timeOut);
894 
895     void RemoveModuleRecord(const std::shared_ptr<ModuleRunningRecord> &record, bool isExtensionDebug = false);
896 
897 private:
898     class RemoteObjHash {
899     public:
operator()900         size_t operator() (const sptr<IRemoteObject> remoteObj) const
901         {
902             return reinterpret_cast<size_t>(remoteObj.GetRefPtr());
903         }
904     };
905 
906     bool isKeepAliveRdb_ = false;  // Only resident processes can be set to true, please choose carefully
907     bool isKeepAliveBundle_ = false;
908     bool isEmptyKeepAliveApp_ = false;  // Only empty resident processes can be set to true, please choose carefully
909     bool isMainProcess_ = true; // Only MainProcess can be keepalive
910     bool isSingleton_ = false;
911     bool isStageBasedModel_ = false;
912     ApplicationState curState_ = ApplicationState::APP_STATE_CREATE;  // current state of this process
913     ApplicationPendingState pendingState_ = ApplicationPendingState::READY;
914     ApplicationScheduleState scheduleState_ = ApplicationScheduleState::SCHEDULE_READY;
915     bool isFocused_ = false; // if process is focused.
916     /**
917      * If there is an ability is foregrounding, this flag will be true,
918      * and this flag will remain true until this application is background.
919      */
920     std::atomic_bool isAbilityForegrounding_ = false;
921 
922     std::shared_ptr<ApplicationInfo> appInfo_ = nullptr;  // the application's info of this process
923     int32_t appRecordId_ = 0;
924     std::string appName_;
925     std::string processName_;  // the name of this process
926     std::string specifiedProcessFlag_; // the flag of specified Process
927     int64_t eventId_ = 0;
928     int64_t startProcessSpecifiedAbilityEventId_ = 0;
929     int64_t addAbilityStageInfoEventId_ = 0;
930     std::unordered_set<sptr<IRemoteObject>, RemoteObjHash> foregroundingAbilityTokens_;
931     std::weak_ptr<AppMgrServiceInner> appMgrServiceInner_;
932     sptr<AppDeathRecipient> appDeathRecipient_ = nullptr;
933     std::shared_ptr<PriorityObject> priorityObject_;
934     std::shared_ptr<AppLifeCycleDeal> appLifeCycleDeal_ = nullptr;
935     std::shared_ptr<AAFwk::TaskHandlerWrap> taskHandler_;
936     std::shared_ptr<AMSEventHandler> eventHandler_;
937     bool isTerminating = false;
938     bool isCaching_  = false;
939     std::string signCode_;  // the sign of this hap
940     std::string jointUserId_;
941     std::map<std::string, std::shared_ptr<ApplicationInfo>> appInfos_;
942     ffrt::mutex appInfosLock_;
943     std::map<std::string, std::vector<std::shared_ptr<ModuleRunningRecord>>> hapModules_;
944     mutable ffrt::mutex hapModulesLock_;
945     int32_t mainUid_;
946     std::string mainBundleName_;
947     bool isLauncherApp_;
948     std::string mainAppName_;
949     int restartResidentProcCount_ = 0;
950     std::string appIdentifier_;
951 
952     mutable std::mutex specifiedMutex_;
953     int32_t specifiedRequestId_ = -1;
954     AAFwk::Want specifiedWant_;
955     std::string moduleName_;
956     int32_t newProcessRequestId_ = -1;
957     AAFwk::Want newProcessRequestWant_;
958 
959     bool isDebugApp_ = false;
960     bool isNativeDebug_ = false;
961     bool isAttachDebug_ = false;
962     std::string perfCmd_;
963     int64_t startTimeMillis_ = 0;   // The time of app start(CLOCK_MONOTONIC)
964     int64_t restartTimeMillis_ = 0; // The time of last trying app restart
965     bool jitEnabled_ = false;
966     PreloadState preloadState_ = PreloadState::NONE;
967     int32_t exitReason_ = 0;
968     std::string exitMsg_ = "";
969 
970     std::shared_ptr<UserTestRecord> userTestRecord_ = nullptr;
971 
972     bool isKilling_ = false;
973     bool isContinuousTask_ = false;    // Only continuesTask processes can be set to true, please choose carefully
974     std::atomic_bool isSpawned_ = false;
975 
976     std::weak_ptr<AppRunningRecord> parentAppRecord_;
977     std::map<pid_t, std::weak_ptr<AppRunningRecord>> childAppRecordMap_;
978 
979     // render record
980     std::map<int32_t, std::shared_ptr<RenderRecord>> renderRecordMap_;
981     ffrt::mutex renderRecordMapLock_;
982     std::set<pid_t> renderPidSet_; // Contains all render pid added, whether died or not
983     ffrt::mutex renderPidSetLock_;
984     AppSpawnStartMsg startMsg_;
985     int32_t appIndex_ = 0;
986     bool securityFlag_ = false;
987     int32_t requestProcCode_ = 0;
988     ProcessChangeReason processChangeReason_ = ProcessChangeReason::REASON_NONE;
989 
990     int32_t callerPid_ = -1;
991     int32_t callerUid_ = -1;
992     int32_t callerTokenId_ = -1;
993     int32_t assignTokenId_ = 0;
994     ProcessType processType_ = ProcessType::NORMAL;
995     ExtensionAbilityType extensionType_ = ExtensionAbilityType::UNSPECIFIED;
996 
997     std::set<uint32_t> windowIds_;
998     std::map<pid_t, std::shared_ptr<ChildProcessRecord>> childProcessRecordMap_;
999     ffrt::mutex childProcessRecordMapLock_;
1000 
1001     bool isRestartApp_ = false; // Only app calling RestartApp can be set to true
1002     bool isAssertPause_ = false;
1003     bool isErrorInfoEnhance_ = false;
1004     bool isNativeStart_ = false;
1005     bool isMultiThread_ = false;
1006     bool enableProcessCache_ = false;
1007     SupportProcessCacheState procCacheSupportState_ = SupportProcessCacheState::UNSPECIFIED;
1008     bool processCacheBlocked = false; // temporarily block process cache feature
1009     sptr<IRemoteObject> browserHost_;
1010     bool isGPU_ = false;
1011     pid_t gpuPid_ = 0;
1012     bool isStrictMode_ = false;
1013     bool isAttachedToStatusBar = false;
1014     bool isDependedOnArkWeb_ = false;
1015     bool isUserRequestCleaning_ = false;
1016     bool hasUIAbilityLaunched_ = false;
1017     bool isAllowedNWebPreload_ = false;
1018 };
1019 
1020 }  // namespace AppExecFwk
1021 }  // namespace OHOS
1022 #endif  // OHOS_ABILITY_RUNTIME_APP_RUNNING_RECORD_H
1023