• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 eventId event id
152      * @return std::shared_ptr<AbilityRecord> return ability record
153      */
154     std::shared_ptr<AbilityRecord> GetAbilityRecordById(int64_t eventId) 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      * Get ability token by target mission id.
176      *
177      * @param missionId target missionId.
178      * @return the ability token of target mission.
179      */
180     sptr<IRemoteObject> GetAbilityTokenByMissionId(int32_t missionId);
181 
182     /**
183      * Handle uninstall bundle.
184      *
185      * @param bundleName name of bundle.
186      * @param uid the uid of bundle.
187      */
188     void HandleUnInstallApp(const std::string &bundleName, int32_t uid);
189 
190     /**
191      * @brief dump mission
192      *
193      * @param info dump result.
194      */
195     void Dump(std::vector<std::string> &info);
196 
197     /**
198      * @brief dump mission list info
199      *
200      * @param info dump result.
201      */
202     void DumpList(std::vector<std::string> &info, bool isClient);
203 
204     void DumpStateByRecordId(
205         std::vector<std::string> &info, bool isClient, int32_t abilityRecordId, const std::vector<std::string> &params);
206 
207     std::shared_ptr<Mission> GetMissionBySpecifiedFlag(const AAFwk::Want &want, const std::string &flag) const;
208     #ifdef ABILITY_COMMAND_FOR_TEST
209     int BlockAbilityByRecordId(int32_t abilityRecordId);
210     #endif
211 
212     int32_t GetMissionCountByUid(int32_t targetUid) const;
213 
214 private:
215     std::string GetTypeName();
216     bool MatchedInitialMission(const std::shared_ptr<Mission>& mission, const std::string &bundleName, int32_t uid);
217 
218     MissionListType type_;
219     std::list<std::shared_ptr<Mission>> missions_ {};
220 };
221 }  // namespace AAFwk
222 }  // namespace OHOS
223 #endif  // OHOS_ABILITY_RUNTIME_MISSION_LIST_H
224