1 /* 2 * Copyright (c) 2021 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_AAFWK_ABILITY_STACK_MANAGER_H 17 #define OHOS_AAFWK_ABILITY_STACK_MANAGER_H 18 19 #include <mutex> 20 #include <list> 21 #include <queue> 22 #include <unordered_map> 23 #include <vector> 24 25 #include "ability_info.h" 26 #include "ability_record.h" 27 #include "application_info.h" 28 #include "mission_record.h" 29 #include "mission_snapshot.h" 30 #include "mission_stack.h" 31 #include "mission_index_info.h" 32 #include "mission_option.h" 33 #include "ability_mission_info.h" 34 #include "lock_mission_container.h" 35 #include "lock_screen_event_subscriber.h" 36 #include "lock_screen_white_list.h" 37 #include "resume_mission_container.h" 38 #include "stack_info.h" 39 #include "power_storage.h" 40 #include "want.h" 41 #include "screenshot_handler.h" 42 43 namespace OHOS { 44 namespace AAFwk { 45 enum class SystemWindowMode { 46 DEFAULT_WINDOW_MODE = 0, 47 SPLITSCREEN_WINDOW_MODE, 48 FLOATING_WINDOW_MODE, 49 FLOATING_AND_SPLITSCREEN_WINDOW_MODE, 50 }; 51 52 struct TerminatingAbility { 53 std::shared_ptr<AbilityRecord> abilityRecord; 54 int resultCode; 55 const Want *resultWant; 56 }; 57 58 /** 59 * @class AbilityStackManager 60 * AbilityStackManager provides a facility for managing page ability life cycle. 61 */ 62 class AbilityStackManager : public std::enable_shared_from_this<AbilityStackManager> { 63 public: 64 explicit AbilityStackManager(int userId); 65 ~AbilityStackManager(); 66 67 /** 68 * init ability stack manager. 69 * 70 */ 71 void Init(); 72 73 /** 74 * StartAbility with request. 75 * 76 * @param abilityRequest, the request of the service ability to start. 77 * @return Returns ERR_OK on success, others on failure. 78 */ 79 int StartAbility(const AbilityRequest &abilityRequest); 80 81 /** 82 * TerminateAbility with token and result want. 83 * 84 * @param token, the token of service type's ability to terminate. 85 * @param resultCode, the result code of service type's ability to terminate. 86 * @param resultWant, the result want for service type's ability to terminate. 87 * @return Returns ERR_OK on success, others on failure. 88 */ 89 int TerminateAbility(const sptr<IRemoteObject> &token, int resultCode, const Want *resultWant); 90 91 /** 92 * TerminateAbility, terminate the special ability. 93 * 94 * @param caller, caller ability record. 95 * @param requestCode, abililty request code 96 * @return Returns ERR_OK on success, others on failure. 97 */ 98 int TerminateAbility(const std::shared_ptr<AbilityRecord> &caller, int requestCode); 99 100 /** 101 * MinimizeAbility, minimize the special ability. 102 * 103 * @param token, ability token. 104 * @return Returns ERR_OK on success, others on failure. 105 */ 106 int MinimizeAbility(const sptr<IRemoteObject> &token); 107 108 /** 109 * get ability stack manager's user id. 110 * 111 * @return Returns userId. 112 */ 113 int GetAbilityStackManagerUserId() const; 114 115 /** 116 * get current working mission stack. 117 * 118 * @return current mission stack. 119 */ GetCurrentMissionStack()120 std::shared_ptr<MissionStack> GetCurrentMissionStack() const 121 { 122 return currentMissionStack_; 123 } 124 125 /** 126 * get current top ability's token of stack. 127 * 128 * @return top ability record's token. 129 */ 130 sptr<Token> GetCurrentTopAbilityToken(); 131 132 /** 133 * get the ability record by token. 134 * 135 * @param recordId, ability record id. 136 * @return ability record. 137 */ 138 std::shared_ptr<AbilityRecord> GetAbilityRecordById(const int64_t recordId); 139 140 /** 141 * get the stack by id. 142 * 143 * @param recordId, stack id. 144 * @return MissionStack. 145 */ 146 std::shared_ptr<MissionStack> GetStackById(int stackId); 147 148 /** 149 * get current top mission of stack. 150 * 151 * @return top mission record. 152 */ 153 std::shared_ptr<MissionRecord> GetTopMissionRecord() const; 154 155 /** 156 * get the ability record by token. 157 * 158 * @param token, the token of ability. 159 * @return ability record. 160 */ 161 std::shared_ptr<AbilityRecord> GetAbilityRecordByToken(const sptr<IRemoteObject> &token); 162 163 /** 164 * get terminating ability from terminate list. 165 * 166 * @param token, the token of ability. 167 */ 168 std::shared_ptr<AbilityRecord> GetAbilityFromTerminateList(const sptr<IRemoteObject> &token); 169 170 /** 171 * get the mission record by record id. 172 * 173 * @param id, the record id of mission. 174 * @return mission record. 175 */ 176 std::shared_ptr<MissionRecord> GetMissionRecordById(int id) const; 177 178 /** 179 * get the mission record by record name. 180 * 181 * @param name, the record name of mission. 182 * @return mission record. 183 */ 184 std::shared_ptr<MissionRecord> GetMissionRecordByName(std::string name) const; 185 186 /** 187 * get the mission record by record id from all stacks. 188 * 189 * @param id, the record id of mission. 190 * @return mission record. 191 */ 192 std::shared_ptr<MissionRecord> GetMissionRecordFromAllStacks(int id) const; 193 194 /** 195 * remove the mission record by record id. 196 * 197 * @param id, the record id of mission. 198 * @return Returns true on success, false on failure. 199 */ 200 bool RemoveMissionRecordById(int id); 201 202 /** 203 * attach ability thread ipc object. 204 * 205 * @param scheduler, ability thread ipc object. 206 * @param token, the token of ability. 207 * @return Returns ERR_OK on success, others on failure. 208 */ 209 int AttachAbilityThread(const sptr<IAbilityScheduler> &scheduler, const sptr<IRemoteObject> &token); 210 211 /** 212 * AbilityTransitionDone, ability call this interface after lift cycle was changed. 213 * 214 * @param token,.ability's token. 215 * @param state,.the state of ability lift cycle. 216 * @param saveData, save ability data 217 * @return Returns ERR_OK on success, others on failure. 218 */ 219 int AbilityTransitionDone(const sptr<IRemoteObject> &token, int state, const PacMap &saveData); 220 221 /** 222 * AddWindowInfo, add windowToken to AbilityRecord. 223 * 224 * @param token, the token of the ability. 225 * @param windowToken, window id of the ability. 226 */ 227 void AddWindowInfo(const sptr<IRemoteObject> &token, int32_t windowToken); 228 229 /** 230 * OnAbilityRequestDone, app manager service call this interface after ability request done. 231 * 232 * @param token,ability's token. 233 * @param state,the state of ability lift cycle. 234 */ 235 void OnAbilityRequestDone(const sptr<IRemoteObject> &token, const int32_t state); 236 237 void OnAppStateChanged(const AppInfo &info); 238 239 /** 240 * Remove the specified mission from the stack by mission id. 241 * 242 * @param missionId, target mission id. 243 * @return Returns ERR_OK on success, others on failure. 244 */ 245 int RemoveMissionById(int missionId); 246 247 /** 248 * move the mission stack to the top. 249 * 250 * @param stack, target mission stack. 251 */ 252 void MoveMissionStackToTop(const std::shared_ptr<MissionStack> &stack); 253 254 int GetMaxHoldMissionsByStackId(int stackId) const; 255 bool SupportSyncVisualByStackId(int stackId) const; 256 257 void SetMissionStackSetting(const StackSetting &stackSetting); 258 259 /** 260 * complete ability life cycle . 261 * 262 * @param abilityRecord. 263 */ 264 void CompleteActive(const std::shared_ptr<AbilityRecord> &abilityRecord); 265 void CompleteInactive(const std::shared_ptr<AbilityRecord> &abilityRecord); 266 void CompleteBackground(const std::shared_ptr<AbilityRecord> &abilityRecord); 267 void CompleteTerminate(const std::shared_ptr<AbilityRecord> &abilityRecord); 268 269 void MoveToBackgroundTask(const std::shared_ptr<AbilityRecord> &abilityRecord); 270 271 /** 272 * dump ability stack info, about userID, mission stack info, 273 * mission record info and ability info. 274 * 275 * @param info Ability stack info. 276 * @return Returns ERR_OK on success, others on failure. 277 */ 278 void Dump(std::vector<std::string> &info); 279 void DumpWaittingAbilityQueue(std::string &result); 280 void DumpTopAbility(std::vector<std::string> &info); 281 void DumpMission(int missionId, std::vector<std::string> &info); 282 void DumpStack(int missionStackId, std::vector<std::string> &info); 283 void DumpStackList(std::vector<std::string> &info); 284 void DumpFocusMap(std::vector<std::string> &info); 285 void DumpWindowMode(std::vector<std::string> &info); 286 287 /** 288 * get the target mission stack by want info. 289 * 290 * @param want , the want for starting ability. 291 */ 292 std::shared_ptr<MissionStack> GetTargetMissionStack(const AbilityRequest &abilityRequest); 293 std::shared_ptr<MissionStack> GetTargetMissionStackByDefault(const AbilityRequest &abilityRequest); 294 std::shared_ptr<MissionStack> GetTargetMissionStackBySetting(const AbilityRequest &abilityRequest); 295 296 /** 297 * Obtains information about ability stack that are running on the device. 298 * 299 * @param stackInfo Ability stack info. 300 * @return Returns ERR_OK on success, others on failure. 301 */ 302 void GetAllStackInfo(StackInfo &stackInfo); 303 304 /** 305 * Get the list of the missions that the user has recently launched, 306 * with the most recent being first and older ones after in order. 307 * 308 * @param recentList recent mission info 309 * @param numMax The maximum number of entries to return in the list. The 310 * actual number returned may be smaller, depending on how many tasks the 311 * user has started and the maximum number the system can remember. 312 * @param falgs Information about what to return. May be any combination 313 * of {@link #RECENT_WITH_EXCLUDED} and {@link #RECENT_IGNORE_UNAVAILABLE}. 314 * @return Returns ERR_OK on success, others on failure. 315 */ 316 int GetRecentMissions(const int32_t numMax, const int32_t flags, std::vector<AbilityMissionInfo> &recentList); 317 318 /** 319 * Ask that the mission associated with a given mission ID be moved to the 320 * front of the stack, so it is now visible to the user. 321 * 322 * @param missionId. 323 * @return Returns ERR_OK on success, others on failure. 324 */ 325 int MoveMissionToTop(int32_t missionId); 326 327 /** 328 * Requires that tasks associated with a given capability token be moved to the background 329 * 330 * @param token ability token 331 * @param nonFirst If nonfirst is false and not the lowest ability of the mission, you cannot move mission to end 332 * @return Returns ERR_OK on success, others on failure. 333 */ 334 int MoveMissionToEnd(const sptr<IRemoteObject> &token, const bool nonFirst); 335 336 int MoveMissionToEndLocked(int missionId); 337 338 /** 339 * Ability detects death 340 * 341 * @param abilityRecord 342 */ 343 void OnAbilityDied(std::shared_ptr<AbilityRecord> abilityRecord); 344 345 /** 346 * Uninstall app 347 * 348 * @param bundleName. 349 */ 350 void UninstallApp(const std::string &bundleName); 351 352 void OnTimeOut(uint32_t msgId, int64_t eventId); 353 bool IsFirstInMission(const sptr<IRemoteObject> &token); 354 bool IsFrontInAllStack(const std::shared_ptr<MissionStack> &stack) const; 355 bool IsTopInMission(const std::shared_ptr<AbilityRecord> &abilityRecord) const; 356 357 /** 358 * Moving some missions to the specified stack by mission option(Enter splitscreen or floating window mode). 359 * @param missionOption, target mission option 360 * @return Returns ERR_OK on success, others on failure. 361 */ 362 int MoveMissionToFloatingStack(const MissionOption &missionOption); 363 364 /** 365 * Moving mission to the specified stack by mission option(Enter floating window mode). 366 * @param primary, display primary mission option 367 * @param secondary, display secondary mission option 368 * @return Returns ERR_OK on success, others on failure. 369 */ 370 int MoveMissionToSplitScreenStack(const MissionOption &primary, const MissionOption &secondary); 371 372 /** 373 * minimize multiwindow by mission id. 374 * @param missionId, the id of target mission 375 * @return Returns ERR_OK on success, others on failure. 376 */ 377 int MinimizeMultiWindow(int missionId); 378 /** 379 * maximize multiwindow by mission id. 380 * @param missionId, the id of target mission 381 * @return Returns ERR_OK on success, others on failure. 382 */ 383 int MaximizeMultiWindow(int missionId); 384 385 /** 386 * Change the focus of ability in the mission stack. 387 * @param lostToken, the token of lost focus ability 388 * @param getToken, the token of get focus ability 389 * @return Returns ERR_OK on success, others on failure. 390 */ 391 int ChangeFocusAbility(const sptr<IRemoteObject> &lostFocusToken, const sptr<IRemoteObject> &getFocusToken); 392 393 /** 394 * get missions info of floating mission stack. 395 * @param list, mission info. 396 * @return Returns ERR_OK on success, others on failure. 397 */ 398 int GetFloatingMissions(std::vector<AbilityMissionInfo> &list); 399 400 /** 401 * close multiwindow by mission id. 402 * @param missionId, the id of target mission. 403 * @return Returns ERR_OK on success, others on failure. 404 */ 405 int CloseMultiWindow(int missionId); 406 407 void JudgingIsRemoveMultiScreenStack(std::shared_ptr<MissionStack> &stack); 408 409 /** 410 * Save the top ability States and move them to the background 411 * @return Returns ERR_OK on success, others on failure. 412 */ 413 int PowerOff(); 414 415 /** 416 * Restore the state before top ability poweroff 417 * @return Returns ERR_OK on success, others on failure. 418 */ 419 int PowerOn(); 420 421 int StartLockMission(int uid, int missionId, bool isSystemApp, int isLock); 422 int SetMissionDescriptionInfo( 423 const std::shared_ptr<AbilityRecord> &abilityRecord, const MissionDescriptionInfo &description); 424 int GetMissionLockModeState(); 425 426 void RestartAbility(const std::shared_ptr<AbilityRecord> abilityRecord); 427 428 int GetMissionSnapshot(int32_t missionId, MissionPixelMap &missionPixelMap); 429 430 int SetShowOnLockScreen(const std::string &bundleName, bool isAllow); 431 void UpdateLockScreenState(bool isLockScreen); 432 433 bool IsStarted(); 434 void PauseManager(); 435 void ResumeManager(); 436 private: 437 /** 438 * dispatch ability life cycle . 439 * 440 * @param abilityRecord. 441 * @param state. 442 */ 443 int DispatchState(const std::shared_ptr<AbilityRecord> &abilityRecord, int state); 444 int DispatchActive(const std::shared_ptr<AbilityRecord> &abilityRecord, int state); 445 int DispatchInactive(const std::shared_ptr<AbilityRecord> &abilityRecord, int state); 446 int DispatchBackground(const std::shared_ptr<AbilityRecord> &abilityRecord, int state); 447 int DispatchTerminate(const std::shared_ptr<AbilityRecord> &abilityRecord, int state); 448 int DispatchLifecycle(const std::shared_ptr<AbilityRecord> &lastTopAbility, 449 const std::shared_ptr<AbilityRecord> ¤tTopAbility, bool isTopFullScreen = false); 450 void ContinueLifecycle(); 451 452 /** 453 * get current top ability of stack. 454 * 455 * @return top ability record. 456 */ 457 std::shared_ptr<AbilityRecord> GetCurrentTopAbility() const; 458 459 /** 460 * StartAbilityLocked. 461 * 462 * @param currentTopAbilityRecord, current top ability. 463 * @param abilityRequest the request of the ability to start. 464 * @return Returns ERR_OK on success, others on failure. 465 */ 466 int StartAbilityLocked( 467 const std::shared_ptr<AbilityRecord> ¤tTopAbility, const AbilityRequest &abilityRequest); 468 469 int StartAbilityAsDefaultLocked( 470 const std::shared_ptr<AbilityRecord> ¤tTopAbility, const AbilityRequest &abilityRequest); 471 472 int StartAbilityAsMultiWindowLocked( 473 const std::shared_ptr<AbilityRecord> ¤tTopAbility, const AbilityRequest &abilityRequest); 474 475 int StartAbilityByAllowListLocked( 476 const std::shared_ptr<AbilityRecord> ¤tTopAbility, const AbilityRequest &abilityRequest); 477 478 /** 479 * TerminateAbilityLocked. 480 * 481 * @param abilityRecord, target ability. 482 * @param resultCode the result code of the ability to terminate. 483 * @param resultWant the result Want of the ability to terminate. 484 * @return Returns ERR_OK on success, others on failure. 485 */ 486 int TerminateAbilityLocked(std::list<TerminatingAbility> &terminateLists); 487 488 /** 489 * MinimizeAbilityLocked. 490 * 491 * @param abilityRecord, target ability. 492 * @return Returns ERR_OK on success, others on failure. 493 */ 494 int MinimizeAbilityLocked(const std::shared_ptr<AbilityRecord> &abilityRecord); 495 496 /** 497 * Remove the specified mission from the stack by mission id. 498 * 499 * @param missionId, target mission id. 500 * @return Returns ERR_OK on success, others on failure. 501 */ 502 int RemoveMissionByIdLocked(int missionId); 503 504 /** 505 * remove terminating ability from stack. 506 * 507 * @param abilityRecord, target ability. 508 */ 509 void RemoveTerminatingAbility( 510 const std::shared_ptr<AbilityRecord> &abilityRecord, const std::shared_ptr<AbilityRecord> &lastActiveAbility); 511 512 /** 513 * push waitting ability to queue. 514 * 515 * @param abilityRequest, the request of ability. 516 */ 517 void EnqueueWaittingAbility(const AbilityRequest &abilityRequest); 518 519 /** 520 * start waitting ability. 521 */ 522 void StartWaittingAbility(); 523 524 /** 525 * get tartget ability and mission by request and top ability. 526 * 527 * @param abilityRequest, the request of ability. 528 * @param currentTopAbility, top ability. 529 * @param tragetAbilityRecord, out param. 530 * @param targetMissionRecord, out param. 531 */ 532 void GetMissionRecordAndAbilityRecord(const AbilityRequest &abilityRequest, 533 const std::shared_ptr<AbilityRecord> ¤tTopAbility, std::shared_ptr<AbilityRecord> &tragetAbilityRecord, 534 std::shared_ptr<MissionRecord> &targetMissionRecord); 535 536 /** 537 * check wheather the ability is launcher. 538 * 539 * @param abilityRequest, the abilityRequest fot starting ability. 540 * @return Returns true on success, false on failure. 541 */ 542 bool IsLauncherAbility(const AbilityRequest &abilityRequest) const; 543 544 /** 545 * check wheather the mission has launcher ability. 546 * 547 * @param id, mission id. 548 * @return Returns true on success, false on failure. 549 */ 550 bool IsLauncherMission(int id); 551 552 /** 553 * Get the list of the missions that the user has recently launched, 554 * with the most recent being first and older ones after in order. 555 * 556 * @param recentList recent mission info 557 * @param numMax The maximum number of entries to return in the list. The 558 * actual number returned may be smaller, depending on how many tasks the 559 * user has started and the maximum number the system can remember. 560 * @param falgs Information about what to return. May be any combination 561 * of {@link #RECENT_WITH_EXCLUDED} and {@link #RECENT_IGNORE_UNAVAILABLE}. 562 * @return Returns ERR_OK on success, others on failure. 563 */ 564 int GetRecentMissionsLocked(const int32_t numMax, const int32_t flags, std::vector<AbilityMissionInfo> &recentList); 565 566 void CreateRecentMissionInfo(const MissionRecordInfo &mission, AbilityMissionInfo &recentMissionInfo); 567 568 /** 569 * Ask that the mission associated with a given mission ID be moved to the 570 * front of the stack, so it is now visible to the user. 571 * 572 * @param missionId. 573 * @return Returns ERR_OK on success, others on failure. 574 */ 575 int MoveMissionToTopLocked(int32_t missionId); 576 577 /** 578 * Requires that tasks associated with a given capability token be moved to the background 579 * 580 * @param token ability token 581 * @param nonFirst If nonfirst is false and not the lowest ability of the mission, you cannot move mission to end 582 * @return Returns ERR_OK on success, others on failure. 583 */ 584 int MoveMissionToEndLocked(const sptr<IRemoteObject> &token, const bool nonFirst); 585 586 /** 587 * Remove the specified mission stack by stack id 588 * 589 * @param id. 590 * @return Returns ERR_OK on success, others on failure. 591 */ 592 int RemoveStackLocked(int stackId); 593 594 /** 595 * Force return to launcher 596 */ 597 void BackToLauncher(); 598 void DelayedStartLauncher(); 599 600 /** 601 * Ability from default stack detects death 602 * 603 * @param abilityRecord 604 */ 605 void HandleAbilityDied(std::shared_ptr<AbilityRecord> abilityRecord); 606 607 /** 608 * Add uninstall tags to ability 609 * 610 * @param bundleName 611 */ 612 void AddUninstallTags(const std::string &bundleName); 613 614 /** 615 * Get target record by start mode. 616 */ 617 void GetRecordBySingleton(const AbilityRequest &abilityRequest, 618 const std::shared_ptr<AbilityRecord> ¤tTopAbility, std::shared_ptr<AbilityRecord> &targetAbilityRecord, 619 std::shared_ptr<MissionRecord> &targetMissionRecord); 620 621 void GetRecordByStandard(const AbilityRequest &abilityRequest, 622 const std::shared_ptr<AbilityRecord> ¤tTopAbility, std::shared_ptr<AbilityRecord> &targetAbilityRecord, 623 std::shared_ptr<MissionRecord> &targetMissionRecord); 624 625 void GetRecordBySplitScreenMode(const AbilityRequest &abilityRequest, 626 std::shared_ptr<AbilityRecord> &targetAbilityRecord, std::shared_ptr<MissionRecord> &targetMissionRecord); 627 628 /** 629 * Get root ability from launcher mission stack. 630 */ 631 std::shared_ptr<AbilityRecord> GetLauncherRootAbility() const; 632 633 /** 634 * Get ability record by event id. 635 * @param eventId 636 * @return Returns target record. 637 */ 638 std::shared_ptr<AbilityRecord> GetAbilityRecordByEventId(int64_t eventId) const; 639 640 /** 641 * Get or Create mission stack by stack id, 642 * @param stackId, target stack id 643 * @param isCreateFlag, if the stack is not exist, decide whether or not to create a new mission stack, 644 * default is fasle. 645 * @return Returns target missionStack. 646 */ 647 std::shared_ptr<MissionStack> GetOrCreateMissionStack(int stackId, bool isCreateFlag = false); 648 649 /** 650 * Moving some missions to the specified stack by mission option(Enter splitscreen or floating window mode). 651 * @param missionOption, target mission option 652 * @return Returns ERR_OK on success, others on failure. 653 */ 654 int MoveMissionsToStackLocked(const std::list<MissionOption> &missionOptions); 655 int CheckMultiWindowCondition(const std::list<MissionOption> &missionOptions) const; 656 int CheckMultiWindowCondition(const std::shared_ptr<AbilityRecord> ¤tTopAbility, 657 const std::shared_ptr<AbilityRecord> &topFullAbility, const AbilityRequest &abilityRequest) const; 658 bool CheckSplitSrceenCondition( 659 const AbilityRequest &abilityRequest, const std::shared_ptr<AbilityRecord> &topFullAbility) const; 660 bool CheckMissionStackWillOverflow(const std::list<MissionOption> &missionOptions) const; 661 int CompleteMoveMissionToStack( 662 const std::shared_ptr<MissionRecord> &missionRecord, const std::shared_ptr<MissionStack> &stack); 663 void EmplaceMissionToStack( 664 const std::shared_ptr<MissionRecord> &sourceMission, const std::shared_ptr<MissionStack> &targetStack); 665 int CompleteMissionMoving(std::shared_ptr<MissionRecord> &missionRecord, int stackId); 666 SystemWindowMode JudgingTargetSystemWindowMode(AbilityWindowConfiguration config) const; 667 SystemWindowMode GetLatestSystemWindowMode(); 668 int JudgingTargetStackId(AbilityWindowConfiguration config) const; 669 int StartAbilityLifeCycle(std::shared_ptr<AbilityRecord> lastTopAbility, 670 std::shared_ptr<AbilityRecord> currentTopAbility, std::shared_ptr<AbilityRecord> targetAbility); 671 672 void ActiveTopAbility(const std::shared_ptr<AbilityRecord> &abilityRecord); 673 void MoveMissionAndAbility(const std::shared_ptr<AbilityRecord> ¤tTopAbility, 674 std::shared_ptr<AbilityRecord> &targetAbilityRecord, std::shared_ptr<MissionRecord> &targetMissionRecord); 675 676 void SortPreMission( 677 const std::shared_ptr<MissionRecord> &mission, const std::shared_ptr<MissionRecord> &nextMission); 678 679 int PowerOffLocked(); 680 int PowerOnLocked(); 681 682 bool CheckLockMissionCondition( 683 int uid, int missionId, int isLock, bool isSystemApp, std::shared_ptr<MissionRecord> &mission, int &lockUid); 684 bool CanStartInLockMissionState( 685 const AbilityRequest &abilityRequest, const std::shared_ptr<AbilityRecord> ¤tTopAbility) const; 686 bool CanStopInLockMissionState(const std::shared_ptr<AbilityRecord> &terminateAbility) const; 687 void SendUnlockMissionMessage(); 688 std::shared_ptr<MissionStack> GetTopFullScreenStack(); 689 std::shared_ptr<MissionStack> GetTopSplitScreenStack(); 690 std::shared_ptr<MissionStack> GetTopFullScreenStackIncludeSplitScreen(); 691 bool InFrontOfFullScreenStack() const; 692 bool IsExistSplitScreenStack() const; 693 bool IsFullScreenStack(int stackId) const; 694 bool IsLockScreenStack(int stackId) const; 695 bool IsSplitScreenStack(int stackId) const; 696 std::shared_ptr<AbilityRecord> GetTopAbilityOfFullScreen(); 697 int GenerateMissinOptionsOfSplitScreen( 698 const MissionOption &primary, const MissionOption &secondary, std::list<MissionOption> &missionOptions); 699 int GenerateMissinOptionsOfSplitScreen(std::list<MissionOption> &missionOptions, 700 const std::shared_ptr<MissionStack> &targetStack, std::shared_ptr<MissionRecord> &targetMissionRecord); 701 int GetTargetChangeType(bool isMissionChanged, bool isStackChanged, bool isCurrentFull, bool isTargetFull, 702 std::shared_ptr<AbilityRecord> lastTopAbility, std::shared_ptr<AbilityRecord> targetAbility, 703 std::shared_ptr<AbilityRecord> &needBackgroundAbility); 704 705 int SetShowOnLockScreenLocked(const std::string &bundleName, bool isAllow); 706 /** 707 * minimize multiwindow by mission id. 708 * @param missionId, the id of target mission 709 * @return Returns ERR_OK on success, others on failure. 710 */ 711 int MinimizeMultiWindowLocked(int missionId); 712 int ChangeFocusAbilityLocked(const std::shared_ptr<AbilityRecord> &targetAbility); 713 714 void NotifyWindowModeChanged(const SystemWindowMode &windowMode); 715 716 void UpdateFocusAbilityRecord( 717 int displayId, const std::shared_ptr<AbilityRecord> &focusAbility, bool isNotify = false); 718 void UpdateFocusAbilityRecord(const std::shared_ptr<AbilityRecord> &abilityRecord, bool isNotify = false); 719 void CheckMissionRecordIsResume(const std::shared_ptr<MissionRecord> &mission); 720 int ChangedPowerStorageAbilityToActive(std::shared_ptr<PowerStorage> &powerStorage, 721 bool isPowerStateLockScreen = false); 722 void HandleActiveTimeout(const std::shared_ptr<AbilityRecord> &ability); 723 bool IsLockScreenState(); 724 bool CheckMissionRecordInWhiteList(const std::shared_ptr<MissionRecord> &mission); 725 bool DeleteMissionRecordInStackOnLockScreen(const std::shared_ptr<MissionRecord> &missionRecord); 726 void RestoreMissionRecordOnLockScreen(const std::shared_ptr<MissionRecord> &missionRecord); 727 void UpdatePowerOffRecord(int32_t missionId, const std::shared_ptr<AbilityRecord> &ability); 728 void SetPowerOffRecordWhenLockScreen(std::shared_ptr<PowerStorage> &powerStorage); 729 void DelayedStartLockScreenApp(); 730 void BackToLockScreen(); 731 std::shared_ptr<AbilityRecord> GetLockScreenRootAbility() const; 732 void lockScreenStackAbilityDied(std::shared_ptr<MissionRecord> &mission); 733 bool SubscribeEvent(); 734 735 void MakeTerminatingAbility(TerminatingAbility &unit, const std::shared_ptr<AbilityRecord> &abilityRecord, 736 int resultCode, const Want *resultWant); 737 738 void SortAndGetLastActiveAbility( 739 std::list<TerminatingAbility> &terminateLists, std::shared_ptr<AbilityRecord> &lastActiveAbility); 740 741 std::shared_ptr<MissionRecord> GetFriendMissionBySplitScreen( 742 const std::shared_ptr<MissionStack> &stack, const int missionId); 743 744 void SortRecentMissions(std::vector<MissionRecordInfo> &missions); 745 746 void UpdateMissionOption(const std::shared_ptr<MissionRecord> &mission, 747 const std::shared_ptr<MissionStack> &moveToStack, const AbilityWindowConfiguration winModeKey); 748 749 std::string ConvertWindowModeState(const SystemWindowMode &mode); 750 751 void ProcessInactivateInMoving(const std::shared_ptr<AbilityRecord> &abilityRecord); 752 753 void CompleteInactiveByNewVersion(const std::shared_ptr<AbilityRecord> &abilityRecord); 754 int DispatchForegroundNew(const std::shared_ptr<AbilityRecord> &abilityRecord, int state); 755 void CompleteForegroundNew(const std::shared_ptr<AbilityRecord> &abilityRecord); 756 757 int DispatchBackgroundNew(const std::shared_ptr<AbilityRecord> &abilityRecord, int state); 758 void CompleteBackgroundNew(const std::shared_ptr<AbilityRecord> &abilityRecord); 759 760 private: 761 static constexpr int MIN_MISSION_STACK_ID = LAUNCHER_MISSION_STACK_ID; 762 static constexpr int MAX_CAN_MOVE_MISSIONS = 2; 763 static constexpr int FLOATING_MAX_STACK_MISSION_NUM = 5; 764 765 int userId_; 766 bool powerOffing_ = false; 767 std::recursive_mutex stackLock_; 768 std::shared_ptr<MissionStack> launcherMissionStack_; 769 std::shared_ptr<MissionStack> defaultMissionStack_; 770 std::shared_ptr<MissionStack> currentMissionStack_; 771 std::shared_ptr<MissionStack> lastMissionStack_; 772 std::shared_ptr<MissionStack> lockScreenMissionStack_ = nullptr; 773 std::list<std::shared_ptr<MissionStack>> missionStackList_; 774 std::list<std::shared_ptr<AbilityRecord>> terminateAbilityRecordList_; // abilities on terminating put in this 775 // list. 776 std::queue<AbilityRequest> waittingAbilityQueue_; 777 std::list<wptr<IRemoteObject>> focusWaitingList_; 778 std::shared_ptr<PowerStorage> powerStorage_; 779 // find AbilityRecord by windowToken. one windowToken has one and only one AbilityRecord. 780 std::unordered_map<int, std::shared_ptr<AbilityRecord>> windowTokenToAbilityMap_; 781 std::shared_ptr<LockMissionContainer> lockMissionContainer_ = nullptr; 782 SystemWindowMode curSysWindowMode_ = SystemWindowMode::DEFAULT_WINDOW_MODE; 783 bool isMultiWinMoving_ = false; 784 std::vector<StackSetting> stackSettings_; 785 std::map<int, std::weak_ptr<AbilityRecord>> focusAbilityRecordMap_; // abilities has been focused , 786 // key : display id, value: focused ability 787 std::shared_ptr<ResumeMissionContainer> resumeMissionContainer_; 788 std::shared_ptr<ScreenshotHandler> screenshotHandler_; 789 static int64_t splitScreenStackId; 790 const static std::map<SystemWindowMode, std::string> windowModeToStrMap_; 791 std::shared_ptr<LockScreenEventSubscriber> subscriber_ = nullptr; 792 bool isLockScreen_ = false; 793 }; 794 } // namespace AAFwk 795 } // namespace OHOS 796 #endif // OHOS_AAFWK_ABILITY_STACK_MANAGER_H 797