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_LIST_H 17 #define OHOS_ABILITY_RUNTIME_MISSION_LIST_H 18 19 #include <list> 20 #include <memory> 21 22 #include "ability_record.h" 23 #include "iremote_object.h" 24 #include "mission.h" 25 26 using IRemoteObject = OHOS::IRemoteObject; 27 28 namespace OHOS { 29 namespace AAFwk { 30 enum MissionListType { 31 CURRENT = 0, 32 DEFAULT_STANDARD, 33 DEFAULT_SINGLE, 34 LAUNCHER 35 }; 36 37 class MissionList : public std::enable_shared_from_this<MissionList> { 38 public: 39 explicit MissionList(MissionListType type = MissionListType::CURRENT); MissionList(const MissionList & missionList)40 explicit MissionList(const MissionList& missionList) : type_(missionList.type_), missions_(missionList.missions_) {} 41 virtual ~MissionList(); 42 43 /** 44 * Add mission to top of this mission list. 45 * 46 * @param mission target mission 47 */ 48 void AddMissionToTop(const std::shared_ptr<Mission> &mission); 49 50 /** 51 * Remove mission from this mission list. 52 * 53 * @param mission target mission 54 */ 55 void RemoveMission(const std::shared_ptr<Mission> &mission); 56 57 /** 58 * Get singleton mission by name. 59 * 60 * @param missionName target mission name. 61 * @return founded mission. 62 */ 63 std::shared_ptr<Mission> GetSingletonMissionByName(const std::string& missionName) const; 64 65 /** 66 * Get specified mission by name and flag. 67 * 68 * @param missionName target mission name. 69 * @param flag target mission specified flag. 70 * @return founded mission. 71 */ 72 std::shared_ptr<Mission> GetSpecifiedMission(const std::string& missionName, const std::string& flag) const; 73 74 /** 75 * Get recent standard mission by name. 76 * 77 * @param missionName target mission name. 78 * @return founded mission. 79 */ 80 std::shared_ptr<Mission> GetRecentStandardMission(const std::string& missionName) const; 81 82 /** 83 * Get recent standard mission by name. 84 * 85 * @param missionAffinity target mission uni-key. 86 * @return founded mission. 87 */ 88 std::shared_ptr<Mission> GetRecentStandardMissionWithAffinity(const std::string& missionAffinity) const; 89 90 /** 91 * Get top mission of this mission list. 92 * 93 * @return founded mission. 94 */ 95 std::shared_ptr<Mission> GetTopMission() const; 96 97 /** 98 * @brief Get the Ability Record By Token object 99 * 100 * @param token the ability to search 101 * @return std::shared_ptr<AbilityRecord> the ability 102 */ 103 std::shared_ptr<AbilityRecord> GetAbilityRecordByToken(const sptr<IRemoteObject> &token) const; 104 105 /** 106 * @brief remove mission by ability record 107 * 108 * @param abilityRecord the ability need to remove 109 */ 110 void RemoveMissionByAbilityRecord(const std::shared_ptr<AbilityRecord> &abilityRecord); 111 112 /** 113 * whether the missionList contains mission. 114 * 115 * @return finded mission. 116 */ 117 bool IsEmpty(); 118 119 /** 120 * @brief Get the Top Ability object 121 * 122 * @return std::shared_ptr<AbilityRecord> the top ability 123 */ 124 std::shared_ptr<AbilityRecord> GetTopAbility() const; 125 126 /** 127 * @brief Get the Mission By Id object 128 * 129 * @param missionId the given missionId 130 * @return the mission of the given id 131 */ 132 std::shared_ptr<Mission> GetMissionById(int missionId) const; 133 134 /** 135 * @brief Get the Mission By Id object 136 * 137 * @param missionId the given missionId 138 * @return the mission of the given id 139 */ 140 std::list<std::shared_ptr<Mission>>& GetAllMissions(); 141 142 /** 143 * @brief Get the type of the missionList 144 * 145 * @return the mission list type 146 */ 147 MissionListType GetType() const; 148 149 /** 150 * @brief Get the launcher root 151 * 152 * @return launcher root 153 */ 154 std::shared_ptr<AbilityRecord> GetLauncherRoot() const; 155 156 /** 157 * @brief get ability record by id 158 * 159 * @param abilityRecordId ability record id 160 * @return std::shared_ptr<AbilityRecord> return ability record 161 */ 162 std::shared_ptr<AbilityRecord> GetAbilityRecordById(int64_t abilityRecordId) const; 163 164 /** 165 * @brief Get the Ability Record By Caller object 166 * 167 * @param caller the ability which call terminateAbility 168 * @param requestCode startAbilityWithRequstCode 169 * @return std::shared_ptr<AbilityRecord> the ability record which find 170 */ 171 std::shared_ptr<AbilityRecord> GetAbilityRecordByCaller( 172 const std::shared_ptr<AbilityRecord> &caller, int requestCode); 173 174 /** 175 * @brief Get the Ability Record By elementName 176 * 177 * @param element 178 * @return std::shared_ptr<AbilityRecord> the ability record which find 179 */ 180 std::shared_ptr<AbilityRecord> GetAbilityRecordByName(const AppExecFwk::ElementName &element); 181 182 /** 183 * @brief Get the Ability Records By elementName 184 * 185 * @param element conditions for search 186 * @param records out of parameter, list of returned records 187 * @return void 188 */ 189 void GetAbilityRecordsByName( 190 const AppExecFwk::ElementName &element, std::vector<std::shared_ptr<AbilityRecord>> &records); 191 192 /** 193 * Get ability token by target mission id. 194 * 195 * @param missionId target missionId. 196 * @return the ability token of target mission. 197 */ 198 sptr<IRemoteObject> GetAbilityTokenByMissionId(int32_t missionId); 199 200 /** 201 * Handle uninstall bundle. 202 * 203 * @param bundleName name of bundle. 204 * @param uid the uid of bundle. 205 */ 206 void HandleUnInstallApp(const std::string &bundleName, int32_t uid); 207 208 /** 209 * @brief dump mission 210 * 211 * @param info dump result. 212 */ 213 void Dump(std::vector<std::string> &info); 214 215 /** 216 * @brief dump mission list info 217 * 218 * @param info dump result. 219 */ 220 void DumpList(std::vector<std::string> &info, bool isClient); 221 222 void DumpStateByRecordId( 223 std::vector<std::string> &info, bool isClient, int32_t abilityRecordId, const std::vector<std::string> ¶ms); 224 225 std::shared_ptr<Mission> GetMissionBySpecifiedFlag(const AAFwk::Want &want, const std::string &flag) const; 226 #ifdef ABILITY_COMMAND_FOR_TEST 227 int BlockAbilityByRecordId(int32_t abilityRecordId); 228 #endif 229 230 int32_t GetMissionCountByUid(int32_t targetUid) const; 231 void FindEarliestMission(std::shared_ptr<Mission>& targetMission) const; 232 int32_t GetMissionCount() const; 233 void GetActiveAbilityList(const std::string &bundleName, std::vector<std::string> &abilityList); 234 235 private: 236 std::string GetTypeName(); 237 bool MatchedInitialMission(const std::shared_ptr<Mission>& mission, const std::string &bundleName, int32_t uid); 238 239 MissionListType type_; 240 std::list<std::shared_ptr<Mission>> missions_ {}; 241 }; 242 } // namespace AAFwk 243 } // namespace OHOS 244 #endif // OHOS_ABILITY_RUNTIME_MISSION_LIST_H 245