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_MISSION_RECORD_H 17 #define OHOS_AAFWK_MISSION_RECORD_H 18 19 #include <list> 20 21 #include "ability_record.h" 22 #include "mission_stack.h" 23 #include "mission_description_info.h" 24 #include "mission_option.h" 25 26 namespace OHOS { 27 namespace AAFwk { 28 class MissionStack; 29 /** 30 * @class MissionRecord 31 * MissionRecord records mission info and ability records. 32 */ 33 class MissionRecord : public ConfigurationHolder { 34 public: 35 MissionRecord(const std::string &bundleName = ""); 36 MissionRecord(const std::shared_ptr<MissionRecord> &mission); 37 virtual ~MissionRecord(); 38 39 /** 40 * calculate next mission id 41 * 42 * @return mission id. 43 */ 44 static int GetNextMissionId(); 45 46 /** 47 * get this mission record id 48 * 49 * @return mission record id. 50 */ 51 int GetMissionRecordId() const; 52 53 /** 54 * get the number of abilities owned by this mission 55 * 56 * @return count. 57 */ 58 int GetAbilityRecordCount() const; 59 60 /** 61 * get the bottom ability of this mission 62 * 63 * @return AbilityRecord. 64 */ 65 std::shared_ptr<AbilityRecord> GetBottomAbilityRecord() const; 66 67 /** 68 * get the top ability of this mission 69 * 70 * @return AbilityRecord. 71 */ 72 std::shared_ptr<AbilityRecord> GetTopAbilityRecord() const; 73 74 /** 75 * get the last top ability of this mission 76 * 77 * @return AbilityRecord. 78 */ 79 std::shared_ptr<AbilityRecord> GetLastTopAbility() const; 80 81 /** 82 * get the ability by token 83 * 84 * @return AbilityRecord. 85 */ 86 std::shared_ptr<AbilityRecord> GetAbilityRecordByToken(const sptr<IRemoteObject> &token) const; 87 88 /** 89 * get the ability by id 90 * 91 * @return AbilityRecord. 92 */ 93 std::shared_ptr<AbilityRecord> GetAbilityRecordById(const int64_t recordId) const; 94 95 /** 96 * get the ability record by caller token and request code 97 * 98 * @return AbilityRecord. 99 */ 100 std::shared_ptr<AbilityRecord> GetAbilityRecordByCaller( 101 const std::shared_ptr<AbilityRecord> &caller, int requestCode); 102 103 /** 104 * put the ability at the top of the stack 105 * 106 * @param AbilityRecord. 107 */ 108 void AddAbilityRecordToTop(std::shared_ptr<AbilityRecord> ability); 109 110 /** 111 * remove the ability from the stack 112 * 113 * @param AbilityRecord. 114 */ 115 bool RemoveAbilityRecord(std::shared_ptr<AbilityRecord> ability); 116 117 /** 118 * remove the ability at the top of the stack 119 * 120 * @param AbilityRecord. 121 */ 122 bool RemoveTopAbilityRecord(); 123 124 /** 125 * remove all ability record from stack 126 * 127 * @param AbilityRecord. 128 */ 129 void RemoveAll(); 130 131 /** 132 * dump the mission and ability stack information 133 * 134 * @param info 135 */ 136 void Dump(std::vector<std::string> &info); 137 138 /** 139 * check whether it is the same mission by bundleName 140 * 141 * @param bundleName 142 */ 143 bool IsSameMissionRecord(const std::string &bundleName) const; 144 145 /** 146 * Get all the ability information in this mission 147 * 148 * @param abilityInfos 149 */ 150 void GetAllAbilityInfo(std::vector<AbilityRecordInfo> &abilityInfos); 151 152 /** 153 * check whether it is the top ability by abilityName 154 * 155 * @param abilityName 156 */ 157 bool IsTopAbilityRecordByName(const std::string &abilityName); 158 159 /** 160 * set whether it is created by luncher 161 * 162 * @param isCreate 163 */ 164 void SetIsLauncherCreate(); 165 166 /** 167 * is luncher create 168 * 169 * @return is create 170 */ 171 bool IsLauncherCreate() const; 172 173 /** 174 * set mission's previous mission record. 175 * 176 * @param record , previous mission record 177 */ 178 void SetPreMissionRecord(const std::shared_ptr<MissionRecord> &record); 179 180 /** 181 * get mission's previous mission record. 182 * 183 * @return previous mission record 184 */ 185 std::shared_ptr<MissionRecord> GetPreMissionRecord() const; 186 187 /** 188 * Check whether it exists through record ID 189 * 190 * @param id: ability record id 191 */ 192 bool IsExistAbilityRecord(int32_t id); 193 194 /** 195 * set parent mission stack. 196 * 197 * @param missionStack: the parent mission stack 198 */ 199 void SetMissionStack(const std::shared_ptr<MissionStack> &missionStack, int stackId); 200 std::shared_ptr<MissionStack> GetMissionStack() const; 201 GetName()202 std::string GetName() const 203 { 204 return bundleName_; 205 }; 206 SetMissionDescriptionInfo(std::shared_ptr<MissionDescriptionInfo> & description)207 void SetMissionDescriptionInfo(std::shared_ptr<MissionDescriptionInfo> &description) 208 { 209 missionDescriptionInfo_ = description; 210 }; 211 GetMissionDescriptionInfo()212 std::shared_ptr<MissionDescriptionInfo> GetMissionDescriptionInfo() const 213 { 214 return missionDescriptionInfo_; 215 }; 216 217 bool SupportMultWindow() const; 218 219 void SetMissionOption(const MissionOption &option); 220 const MissionOption &GetMissionOption() const; 221 222 bool IsEmpty(); 223 void Resume(const std::shared_ptr<MissionRecord> &backup); 224 225 protected: 226 virtual std::shared_ptr<ConfigurationHolder> GetParent() override; 227 virtual unsigned int GetChildSize() override; 228 virtual std::shared_ptr<ConfigurationHolder> FindChild(unsigned int index) override; 229 230 private: 231 static int nextMissionId_; 232 int missionId_; 233 std::string bundleName_; 234 std::list<std::shared_ptr<AbilityRecord>> abilities_; 235 bool isLauncherCreate_ = false; 236 std::weak_ptr<MissionRecord> preMissionRecord_; 237 std::weak_ptr<MissionStack> parentMissionStack_; 238 239 std::shared_ptr<MissionDescriptionInfo> missionDescriptionInfo_ = nullptr; 240 MissionOption option_; 241 }; 242 } // namespace AAFwk 243 } // namespace OHOS 244 #endif // OHOS_AAFWK_MISSION_RECORD_H