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_ABILITY_RUNTIME_ABILITY_RUNNING_RECORD_H
17 #define OHOS_ABILITY_RUNTIME_ABILITY_RUNNING_RECORD_H
18 
19 #include <string>
20 
21 #include "ability_info.h"
22 #include "application_info.h"
23 #include "app_mgr_constants.h"
24 #include "iremote_object.h"
25 #include "want.h"
26 
27 namespace OHOS {
28 namespace AppExecFwk {
29 class AbilityRunningRecord {
30 public:
31     AbilityRunningRecord(std::shared_ptr<AbilityInfo> info, sptr<IRemoteObject> token,
32         int32_t abilityRecordId);
33     virtual ~AbilityRunningRecord();
34 
35     /**
36      * @brief Obtains the name of the ability.
37      *
38      * @return Returns the ability name.
39      */
40     const std::string &GetName() const;
41 
42     /**
43      * @brief Obtains the bundle name of the ability.
44      *
45      * @return Returns the bundle name.
46      */
47     const std::string &GetBundleName() const;
48 
49     /**
50      * @brief Obtains the module name of the ability.
51      *
52      * @return Returns the module name.
53      */
54     const std::string &GetModuleName() const;
55 
56     /**
57      * @brief Obtains the info of the ability.
58      *
59      * @return Returns the ability info.
60      */
61     const std::shared_ptr<AbilityInfo> &GetAbilityInfo() const;
62 
63     /**
64      * @brief Obtains the info of the ability.
65      *
66      * @return Returns the ability want.
67      */
68     const std::shared_ptr<AAFwk::Want> &GetWant() const;
69 
70     void SetWant(const std::shared_ptr<AAFwk::Want> &want);
71 
72     /**
73      * @brief Obtains the token of the ability.
74      *
75      * @return Returns the ability token.
76      */
77     const sptr<IRemoteObject> &GetToken() const;
GetAbilityRecordId()78     int32_t GetAbilityRecordId() const
79     {
80         return abilityRecordId_;
81     }
82 
83     /**
84      * @brief Setting id for ability record.
85      *
86      * @param appId, the ability record id.
87      */
88     void SetAppRunningRecordId(const int32_t appId);
89 
90     /**
91      * @brief Setting state for ability record.
92      *
93      * @param state, the ability record state.
94      */
95     void SetState(const AbilityState state);
96 
97     /**
98      * @brief Obtains the state of the ability.
99      *
100      * @return Returns the ability state.
101      */
102     AbilityState GetState() const;
103 
104     /**
105      * @brief Judge whether the ability status is the same.
106      *
107      * @param state, the ability state.
108      *
109      * @return Returns If true is returned, the ID will be the same, otherwise it fails.
110      */
111     bool IsSameState(const AbilityState state) const;
112 
113     /**
114      * @brief Obtains the last launch time of the ability record.
115      *
116      * @return Returns the last launch time.
117      */
118     int32_t GetLastLaunchTime() const;
119 
120     /**
121      * @brief Setting the unique identification to call the ability.
122      *
123      * @param preToken, the unique identification to call the ability.
124      */
125     void SetPreToken(const sptr<IRemoteObject> &preToken);
126 
127     /**
128      * @brief Obtains the unique identification to call the ability.
129      *
130      * @return Returns the unique identification to call the ability.
131      */
132     const sptr<IRemoteObject> GetPreToken() const;
133 
134     /**
135      * @brief Setting the visibility to ability.
136      *
137      * @param preToken, the visibility to ability.
138      */
139     void SetVisibility(const int32_t visibility);
140 
141     /**
142      * @brief Obtains the visibility to ability.
143      *
144      * @return Returns the visibility to ability.
145      */
146     int32_t GetVisibility() const;
147 
148     /**
149      * @brief Setting the perceptibility to ability.
150      *
151      * @param preToken, the perceptibility to ability.
152      */
153     void SetPerceptibility(const int32_t perceptibility);
154 
155     /**
156      * @brief Obtains the perceptibility to ability.
157      *
158      * @return Returns the perceptibility to ability.
159      */
160     int32_t GetPerceptibility() const;
161 
162     /**
163      * @brief Setting the connection state to service ability.
164      *
165      * @param preToken, the connection state to service ability.
166      */
167     void SetConnectionState(const int32_t connectionState);
168 
169     /**
170      * @brief Obtains the connection state to service ability.
171      *
172      * @return Returns the connection state to service ability.
173      */
174     int32_t GetConnectionState() const;
175 
176     /**
177      * @brief Set the Terminating object.
178      */
179     void SetTerminating();
180 
181     /**
182      * @brief Whether the ability is terminating.
183      *
184      * @return Returns whether the ability is terminating.
185      */
186     bool IsTerminating() const;
187 
188     void SetEventId(const int64_t eventId);
189     int64_t GetEventId() const;
190 
191     void SetOwnerUserId(int32_t ownerUserId);
192     int32_t GetOwnerUserId() const;
193     void SetIsSingleUser(bool flag);
194     bool IsSingleUser() const;
195     void UpdateFocusState(bool isFocus);
196     bool GetFocusFlag() const;
197     void SetUIExtensionAbilityId(const int32_t uiExtensionAbilityId);
198     int32_t GetUIExtensionAbilityId() const;
199     void SetUserRequestCleaningStatus();
200     bool IsUserRequestCleaning() const;
201     bool IsSceneBoard() const;
202 
203 private:
204     int32_t lastLaunchTime_ = 0;
205     int32_t visibility_ = 0;
206     int32_t perceptibility_ = 0;
207     int32_t connectionState_ = 0;
208     int64_t eventId_ = 0;
209     bool isTerminating_ = false;
210     AbilityState state_ = AbilityState::ABILITY_STATE_CREATE;
211     bool isFocused_ = false;
212     std::shared_ptr<AbilityInfo> info_;
213     std::shared_ptr<AAFwk::Want> want_ = nullptr;
214     sptr<IRemoteObject> token_;
215     int32_t abilityRecordId_ = 0;
216     int32_t uiExtensionAbilityId_ = 0;
217     sptr<IRemoteObject> preToken_;
218     int32_t ownerUserId_ = -1;
219     bool isSingleUser_ = false;
220     bool isUserRequestCleaning_ = false;
221 };
222 }  // namespace AppExecFwk
223 }  // namespace OHOS
224 #endif  // OHOS_ABILITY_RUNTIME_ABILITY_RUNNING_RECORD_H
225