1/* 2 * Copyright (c) 2021-2023 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#include "mission.h" 17 18#include "mission_list.h" 19 20namespace OHOS { 21namespace AAFwk { 22Mission::Mission(int32_t id, const std::shared_ptr<AbilityRecord> abilityRecord, const std::string &missionName, 23 int32_t startMethod) 24 : missionId_(id), startMethod_(startMethod), abilityRecord_(abilityRecord), missionName_(missionName) 25{ 26} 27 28Mission::Mission(const std::shared_ptr<Mission> &mission) 29{ 30 if (!mission) { 31 return; 32 } 33 34 missionId_ = mission->missionId_; 35 startMethod_ = mission->startMethod_; 36 abilityRecord_ = mission->abilityRecord_; 37 missionName_ = mission->missionName_; 38 lockedState_ = mission->lockedState_; 39 ownerMissionList_ = mission->ownerMissionList_; 40 unclearable_ = mission->unclearable_; 41} 42 43Mission::~Mission() 44{} 45 46std::shared_ptr<AbilityRecord> Mission::GetAbilityRecord() const 47{ 48 return abilityRecord_; 49} 50 51int32_t Mission::GetMissionId() const 52{ 53 return missionId_; 54} 55 56bool Mission::IsSingletonAbility() const 57{ 58 if (abilityRecord_) { 59 return abilityRecord_->GetAbilityInfo().launchMode == AppExecFwk::LaunchMode::SINGLETON; 60 } 61 62 return false; 63} 64 65bool Mission::IsSpecifiedAbility() const 66{ 67 if (abilityRecord_) { 68 return abilityRecord_->GetAbilityInfo().launchMode == AppExecFwk::LaunchMode::SPECIFIED; 69 } 70 71 return false; 72} 73 74bool Mission::IsStandardAbility() const 75{ 76 if (abilityRecord_) { 77 return abilityRecord_->GetAbilityInfo().launchMode == AppExecFwk::LaunchMode::STANDARD; 78 } 79 80 return false; 81} 82 83void Mission::SetSpecifiedFlag(const std::string &flag) 84{ 85 specifiedFlag_ = flag; 86} 87 88std::string Mission::GetSpecifiedFlag() const 89{ 90 return specifiedFlag_; 91} 92 93std::shared_ptr<MissionList> Mission::GetMissionList() 94{ 95 return ownerMissionList_.lock(); 96} 97 98std::string Mission::GetMissionName() const 99{ 100 return missionName_; 101} 102 103void Mission::SetMissionList(const std::shared_ptr<MissionList> &missionList) 104{ 105 ownerMissionList_ = missionList; 106} 107 108void Mission::SetLockedState(bool lockedState) 109{ 110 lockedState_ = lockedState; 111} 112 113bool Mission::IsLockedState() const 114{ 115 return lockedState_; 116} 117 118void Mission::SetMovingState(bool movingState) 119{ 120 isMovingToFront_ = movingState; 121} 122 123bool Mission::IsMovingState() const 124{ 125 return isMovingToFront_; 126} 127 128void Mission::SetANRState(bool state) 129{ 130 isANRState_ = state; 131} 132 133bool Mission::IsANRState() const 134{ 135 return isANRState_; 136} 137 138void Mission::Dump(std::vector<std::string> &info) 139{ 140 std::string dumpInfo = " Mission ID #" + std::to_string(missionId_); 141 dumpInfo += " mission name #[" + missionName_ + "]" + " lockedState #" + std::to_string(lockedState_) 142 + " ANR State #" + std::to_string(isANRState_); 143 info.push_back(dumpInfo); 144 if (abilityRecord_) { 145 abilityRecord_->Dump(info); 146 } 147} 148 149bool Mission::IsStartByCall() 150{ 151 return static_cast<int32_t>(StartMethod::START_CALL) == startMethod_; 152} 153 154bool Mission::UpdateMissionId(int32_t id, int32_t method) 155{ 156 if (method == startMethod_ && id > 0) { 157 return false; 158 } 159 160 startMethod_ = method; 161 missionId_ = id; 162 return true; 163} 164} // namespace AAFwk 165} // namespace OHOS 166