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
20 namespace OHOS {
21 namespace AAFwk {
Mission(int32_t id,const std::shared_ptr<AbilityRecord> abilityRecord,const std::string & missionName,int32_t startMethod)22 Mission::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
Mission(const std::shared_ptr<Mission> & mission)28 Mission::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
~Mission()43 Mission::~Mission()
44 {}
45
GetAbilityRecord() const46 std::shared_ptr<AbilityRecord> Mission::GetAbilityRecord() const
47 {
48 return abilityRecord_;
49 }
50
GetMissionId() const51 int32_t Mission::GetMissionId() const
52 {
53 return missionId_;
54 }
55
IsSingletonAbility() const56 bool Mission::IsSingletonAbility() const
57 {
58 if (abilityRecord_) {
59 return abilityRecord_->GetAbilityInfo().launchMode == AppExecFwk::LaunchMode::SINGLETON;
60 }
61
62 return false;
63 }
64
IsSpecifiedAbility() const65 bool Mission::IsSpecifiedAbility() const
66 {
67 if (abilityRecord_) {
68 return abilityRecord_->GetAbilityInfo().launchMode == AppExecFwk::LaunchMode::SPECIFIED;
69 }
70
71 return false;
72 }
73
IsStandardAbility() const74 bool Mission::IsStandardAbility() const
75 {
76 if (abilityRecord_) {
77 return abilityRecord_->GetAbilityInfo().launchMode == AppExecFwk::LaunchMode::STANDARD;
78 }
79
80 return false;
81 }
82
SetSpecifiedFlag(const std::string & flag)83 void Mission::SetSpecifiedFlag(const std::string &flag)
84 {
85 specifiedFlag_ = flag;
86 }
87
GetSpecifiedFlag() const88 std::string Mission::GetSpecifiedFlag() const
89 {
90 return specifiedFlag_;
91 }
92
GetMissionList()93 std::shared_ptr<MissionList> Mission::GetMissionList()
94 {
95 return ownerMissionList_.lock();
96 }
97
GetMissionName() const98 std::string Mission::GetMissionName() const
99 {
100 return missionName_;
101 }
102
SetMissionList(const std::shared_ptr<MissionList> & missionList)103 void Mission::SetMissionList(const std::shared_ptr<MissionList> &missionList)
104 {
105 ownerMissionList_ = missionList;
106 }
107
SetLockedState(bool lockedState)108 void Mission::SetLockedState(bool lockedState)
109 {
110 lockedState_ = lockedState;
111 }
112
IsLockedState() const113 bool Mission::IsLockedState() const
114 {
115 return lockedState_;
116 }
117
SetMovingState(bool movingState)118 void Mission::SetMovingState(bool movingState)
119 {
120 isMovingToFront_ = movingState;
121 }
122
IsMovingState() const123 bool Mission::IsMovingState() const
124 {
125 return isMovingToFront_;
126 }
127
SetANRState(bool state)128 void Mission::SetANRState(bool state)
129 {
130 isANRState_ = state;
131 }
132
IsANRState() const133 bool Mission::IsANRState() const
134 {
135 return isANRState_;
136 }
137
Dump(std::vector<std::string> & info)138 void 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
IsStartByCall()149 bool Mission::IsStartByCall()
150 {
151 return static_cast<int32_t>(StartMethod::START_CALL) == startMethod_;
152 }
153
UpdateMissionId(int32_t id,int32_t method)154 bool 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