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