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_STACK_H 17 #define OHOS_AAFWK_MISSION_STACK_H 18 19 #include <list> 20 #include <vector> 21 22 #include "ability_info.h" 23 #include "application_info.h" 24 #include "mission_record.h" 25 #include "mission_record_info.h" 26 #include "want.h" 27 #include "stack_setting.h" 28 29 namespace OHOS { 30 namespace AAFwk { 31 /** 32 * @class MissionStack 33 * MissionStack records mission info. 34 */ 35 class MissionStack : public ConfigurationHolder { 36 public: 37 MissionStack(int id, int userId); 38 virtual ~MissionStack(); 39 40 /** 41 * get target mission record by app name 42 * 43 * @return mission record. 44 */ 45 std::shared_ptr<MissionRecord> GetTargetMissionRecord(const std::string &appName); 46 47 /** 48 * get mission stack id 49 * 50 * @return id. 51 */ 52 int GetMissionStackId() const; 53 54 /** 55 * get mission stack user id 56 * 57 * @return user id. 58 */ 59 int GetMissionStackUserId() const; 60 61 /** 62 * get the number of missions owned by this mission stack 63 * 64 * @return count. 65 */ 66 int GetMissionRecordCount() const; 67 68 /** 69 * get the top ability of this mission stack 70 * 71 * @return AbilityRecord. 72 */ 73 std::shared_ptr<AbilityRecord> GetTopAbilityRecord() const; 74 75 /** 76 * get the top mission of this mission stack 77 * 78 * @return MissionRecord. 79 */ 80 std::shared_ptr<MissionRecord> GetTopMissionRecord(); 81 82 /** 83 * get the bottom mission of this mission stack 84 * 85 * @return MissionRecord. 86 */ 87 std::shared_ptr<MissionRecord> GetBottomMissionRecord(); 88 89 /** 90 * get the mission by id 91 * 92 * @return MissionRecord. 93 */ 94 std::shared_ptr<MissionRecord> GetMissionRecordById(int id); 95 96 /** 97 * get the mission by token 98 * 99 * @return AbilityRecord. 100 */ 101 std::shared_ptr<AbilityRecord> GetAbilityRecordByToken(const sptr<IRemoteObject> &token); 102 103 /** 104 * get the ability record by caller token and request code 105 * 106 * @return AbilityRecord. 107 */ 108 std::shared_ptr<AbilityRecord> GetAbilityRecordByCaller( 109 const std::shared_ptr<AbilityRecord> &caller, int requestCode); 110 111 /** 112 * get the mission by id 113 * 114 * @return AbilityRecord. 115 */ 116 std::shared_ptr<AbilityRecord> GetAbilityRecordById(const int64_t recordId); 117 118 /** 119 * remove the ability record from stack by token 120 */ 121 bool RemoveAbilityRecordByToken(const Token &token); 122 123 /** 124 * remove the mission record from stack by id 125 */ 126 bool RemoveMissionRecord(int id); 127 128 /** 129 * remove all mission from stack 130 */ 131 void RemoveAll(); 132 133 /** 134 * add the mission at the top of the stack 135 */ 136 void AddMissionRecordToTop(std::shared_ptr<MissionRecord> mission); 137 138 /** 139 * put the mission at the top of the stack 140 */ 141 void MoveMissionRecordToTop(std::shared_ptr<MissionRecord> mission); 142 143 void MoveMissionRecordToBottom(const std::shared_ptr<MissionRecord> &mission); 144 145 /** 146 * dump the mission stack information 147 */ 148 void Dump(std::vector<std::string> &info); 149 void DumpStackList(std::vector<std::string> &info); 150 151 /** 152 * get all mission info about this stack 153 */ 154 void GetAllMissionInfo(std::vector<MissionRecordInfo> &missionInfos); 155 156 /** 157 * Check whether there is a mission record in the mission stack 158 */ 159 bool IsExistMissionRecord(int missionId); 160 161 bool IsTopMissionRecord(std::shared_ptr<MissionRecord> &missionRecord) const; 162 163 bool IsEqualStackId(int stackId); 164 165 bool IsEmpty(); 166 167 protected: 168 virtual std::shared_ptr<ConfigurationHolder> GetParent() override; 169 virtual unsigned int GetChildSize() override; 170 virtual std::shared_ptr<ConfigurationHolder> FindChild(unsigned int index) override; 171 172 private: 173 int missionStackId_; 174 int userId_; 175 std::list<std::shared_ptr<MissionRecord>> missions_; 176 }; 177 } // namespace AAFwk 178 } // namespace OHOS 179 #endif // OHOS_AAFWK_MISSION_STACK_H 180