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 #ifndef OHOS_ABILITY_RUNTIME_MISSION_H 17 #define OHOS_ABILITY_RUNTIME_MISSION_H 18 19 #include <memory> 20 21 #include "ability_record.h" 22 #include "inner_mission_info.h" 23 24 namespace OHOS { 25 namespace AAFwk { 26 class MissionList; 27 28 /** 29 * @class Mission 30 * a mission only contains an AbilityRecord 31 */ 32 class Mission : public std::enable_shared_from_this<Mission> { 33 public: 34 Mission(int32_t id, const std::shared_ptr<AbilityRecord> abilityRecord, const std::string &missionName = "", 35 int32_t startMethod = 0); 36 explicit Mission(const std::shared_ptr<Mission> &mission); 37 virtual ~Mission(); 38 39 /** 40 * set the mission list. 41 * 42 * @param missionList: the parent mission list 43 */ 44 void SetMissionList(const std::shared_ptr<MissionList> &missionList); 45 46 /** 47 * check whether ability contains by this mission is singleton. 48 * 49 * @return is ability contains by this mission is singleton. 50 */ 51 bool IsSingletonAbility() const; 52 53 /** 54 * check whether ability contains by this mission is specified. 55 * 56 * @return is ability contains by this mission is specified. 57 */ 58 bool IsSpecifiedAbility() const; 59 60 /** 61 * check whether ability contains by this mission is standard. 62 * 63 * @return is ability contains by this mission is standard. 64 */ 65 bool IsStandardAbility() const; 66 67 /** 68 * get owner mission list. 69 * 70 * @return mission list. 71 */ 72 std::shared_ptr<MissionList> GetMissionList(); 73 74 /** 75 * get name of this mission. 76 * 77 * @return missionName. 78 */ 79 std::string GetMissionName() const; 80 81 /** 82 * @brief Get the Ability Record object 83 * 84 * @return std::shared_ptr<AbilityRecord> 85 */ 86 std::shared_ptr<AbilityRecord> GetAbilityRecord() const; 87 88 /** 89 * @brief Get the mission id 90 * 91 * @return the mission id 92 */ 93 int32_t GetMissionId() const; 94 95 /** 96 * @brief Set the Locked State 97 * 98 * @param lockedState true/false 99 */ 100 void SetLockedState(bool lockedState); 101 102 /** 103 * @brief get the Locked State 104 * 105 * @return the lockedState 106 */ 107 bool IsLockedState() const; 108 109 /** 110 * @brief Set the Moving State 111 * 112 * @param movingState true/false 113 */ 114 void SetMovingState(bool movingState); 115 116 /** 117 * @brief get the Moving State 118 * 119 * @return the movingState 120 */ 121 bool IsMovingState() const; 122 123 /** 124 * @brief Set application not response state true 125 */ 126 void SetANRState(bool state); 127 128 /** 129 * @brief Is application not response state 130 */ 131 bool IsANRState() const; 132 133 /** 134 * @brief dump mission 135 * 136 * @param info dump result. 137 */ 138 void Dump(std::vector<std::string> &info); 139 140 /** 141 * @brief whether it is a form ByCall start-up 142 * 143 * @return true form BaCall start-up, false other 144 */ 145 bool IsStartByCall(); 146 147 /** 148 * @brief update mission id 149 * 150 * @param id mission id. 151 * @param method start method. 152 * @return Returns true on success, false on failure 153 */ 154 bool UpdateMissionId(int32_t id, int32_t method); 155 156 /** 157 * Set whether to notify Launcher that the mission has been created. 158 * 159 * @param needNotify Indicates whether the Launcher needs to be notified. 160 */ SetNotifyLabel(bool needNotify)161 inline void SetNotifyLabel(bool needNotify) 162 { 163 needNotify_ = needNotify; 164 } 165 166 /** 167 * Get whether to notify Launcher that the mission has been created. 168 * 169 * @param return Whether the Launcher needs to be notified. 170 */ NeedNotify()171 inline bool NeedNotify() const 172 { 173 return needNotify_; 174 } 175 176 /** 177 * Set mission specified flag. 178 * 179 * @param flag specified flag. 180 */ 181 void SetSpecifiedFlag(const std::string &flag); 182 183 /** 184 * Get mission specified flag. 185 * 186 * @return specified flag. 187 */ 188 std::string GetSpecifiedFlag() const; 189 SetNeedNotifyUpdateLabel(bool flag)190 inline void SetNeedNotifyUpdateLabel(bool flag) 191 { 192 needNotifyUpdateLabel_ = flag; 193 } 194 NeedNotifyUpdateLabel()195 inline bool NeedNotifyUpdateLabel() const 196 { 197 return needNotifyUpdateLabel_; 198 } 199 UpdateMissionTime(const std::string & missionTime)200 inline void UpdateMissionTime(const std::string &missionTime) 201 { 202 missionTime_ = missionTime; 203 } 204 GetMissionTime()205 inline std::string GetMissionTime() const 206 { 207 return missionTime_; 208 } 209 SetUnclearable(const bool & unclearable)210 inline void SetUnclearable(const bool &unclearable) 211 { 212 unclearable_ = unclearable; 213 } 214 IsUnclearable()215 bool IsUnclearable() 216 { 217 return unclearable_; 218 } 219 220 private: 221 int32_t missionId_; 222 int32_t startMethod_; 223 std::shared_ptr<AbilityRecord> abilityRecord_; 224 std::string missionName_; 225 std::string specifiedFlag_; 226 std::weak_ptr<MissionList> ownerMissionList_; 227 bool lockedState_ = false; 228 bool isMovingToFront_ = false; 229 bool isANRState_ = false; 230 bool needNotify_ = true; 231 bool needNotifyUpdateLabel_ = false; 232 std::string missionTime_ = "0"; 233 bool unclearable_ = false; 234 }; 235 } // namespace AAFwk 236 } // namespace OHOS 237 #endif // OHOS_ABILITY_RUNTIME_MISSION_H 238