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 top mission of this mission list. 84 * 85 * @return founded mission. 86 */ 87 std::shared_ptr<Mission> GetTopMission() const; 88 89 /** 90 * @brief Get the Ability Record By Token object 91 * 92 * @param token the ability to search 93 * @return std::shared_ptr<AbilityRecord> the ability 94 */ 95 std::shared_ptr<AbilityRecord> GetAbilityRecordByToken(const sptr<IRemoteObject> &token) const; 96 97 /** 98 * @brief remove mission by ability record 99 * 100 * @param abilityRecord the ability need to remove 101 */ 102 void RemoveMissionByAbilityRecord(const std::shared_ptr<AbilityRecord> &abilityRecord); 103 104 /** 105 * whether the missionList contains mission. 106 * 107 * @return finded mission. 108 */ 109 bool IsEmpty(); 110 111 /** 112 * @brief Get the Top Ability object 113 * 114 * @return std::shared_ptr<AbilityRecord> the top ability 115 */ 116 std::shared_ptr<AbilityRecord> GetTopAbility() const; 117 118 /** 119 * @brief Get the Mission By Id object 120 * 121 * @param missionId the given missionId 122 * @return the mission of the given id 123 */ 124 std::shared_ptr<Mission> GetMissionById(int missionId) 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::list<std::shared_ptr<Mission>>& GetAllMissions(); 133 134 /** 135 * @brief Get the type of the missionList 136 * 137 * @return the mission list type 138 */ 139 MissionListType GetType() const; 140 141 /** 142 * @brief Get the launcher root 143 * 144 * @return launcher root 145 */ 146 std::shared_ptr<AbilityRecord> GetLauncherRoot() const; 147 148 /** 149 * @brief get ability record by id 150 * 151 * @param abilityRecordId ability record id 152 * @return std::shared_ptr<AbilityRecord> return ability record 153 */ 154 std::shared_ptr<AbilityRecord> GetAbilityRecordById(int64_t abilityRecordId) const; 155 156 /** 157 * @brief Get the Ability Record By Caller object 158 * 159 * @param caller the ability which call terminateAbility 160 * @param requestCode startAbilityWithRequstCode 161 * @return std::shared_ptr<AbilityRecord> the ability record which find 162 */ 163 std::shared_ptr<AbilityRecord> GetAbilityRecordByCaller( 164 const std::shared_ptr<AbilityRecord> &caller, int requestCode); 165 166 /** 167 * @brief Get the Ability Record By elementName 168 * 169 * @param element 170 * @return std::shared_ptr<AbilityRecord> the ability record which find 171 */ 172 std::shared_ptr<AbilityRecord> GetAbilityRecordByName(const AppExecFwk::ElementName &element); 173 174 /** 175 * @brief Get the Ability Records By elementName 176 * 177 * @param element conditions for search 178 * @param records out of parameter, list of returned records 179 * @return void 180 */ 181 void GetAbilityRecordsByName( 182 const AppExecFwk::ElementName &element, std::vector<std::shared_ptr<AbilityRecord>> &records); 183 184 /** 185 * Get ability token by target mission id. 186 * 187 * @param missionId target missionId. 188 * @return the ability token of target mission. 189 */ 190 sptr<IRemoteObject> GetAbilityTokenByMissionId(int32_t missionId); 191 192 /** 193 * Handle uninstall bundle. 194 * 195 * @param bundleName name of bundle. 196 * @param uid the uid of bundle. 197 */ 198 void HandleUnInstallApp(const std::string &bundleName, int32_t uid); 199 200 /** 201 * @brief dump mission 202 * 203 * @param info dump result. 204 */ 205 void Dump(std::vector<std::string> &info); 206 207 /** 208 * @brief dump mission list info 209 * 210 * @param info dump result. 211 */ 212 void DumpList(std::vector<std::string> &info, bool isClient); 213 214 void DumpStateByRecordId( 215 std::vector<std::string> &info, bool isClient, int32_t abilityRecordId, const std::vector<std::string> ¶ms); 216 217 std::shared_ptr<Mission> GetMissionBySpecifiedFlag(const AAFwk::Want &want, const std::string &flag) const; 218 #ifdef ABILITY_COMMAND_FOR_TEST 219 int BlockAbilityByRecordId(int32_t abilityRecordId); 220 #endif 221 222 int32_t GetMissionCountByUid(int32_t targetUid) const; 223 void FindEarliestMission(std::shared_ptr<Mission>& targetMission) const; 224 int32_t GetMissionCount() const; 225 void GetActiveAbilityList(const std::string &bundleName, std::vector<std::string> &abilityList); 226 227 private: 228 std::string GetTypeName(); 229 bool MatchedInitialMission(const std::shared_ptr<Mission>& mission, const std::string &bundleName, int32_t uid); 230 231 MissionListType type_; 232 std::list<std::shared_ptr<Mission>> missions_ {}; 233 }; 234 } // namespace AAFwk 235 } // namespace OHOS 236 #endif // OHOS_ABILITY_RUNTIME_MISSION_LIST_H 237