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