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