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