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