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