• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 #ifndef FOUNDATION_RESOURCESCHEDULE_WORKSCHEDULER_WORK_INFO_H
16 #define FOUNDATION_RESOURCESCHEDULE_WORKSCHEDULER_WORK_INFO_H
17 
18 #include <cstdint>
19 #include <list>
20 #include <map>
21 #include <memory>
22 #include <string>
23 
24 #include <parcel.h>
25 #include "json/json.h"
26 #include "want_params.h"
27 #include "refbase.h"
28 
29 #include "work_condition.h"
30 
31 namespace OHOS {
32 namespace WorkScheduler {
33 class WorkInfo : public Parcelable {
34 public:
35     explicit WorkInfo();
36     ~WorkInfo() override;
37     /**
38      * @brief Set the id of workId.
39      *
40      * @param workId The id of work.
41      */
42     void SetWorkId(int32_t workId);
43     /**
44      * @brief Set element.
45      *
46      * @param bundleName The name of bundle.
47      * @param abilityName The name of ability
48      */
49     void SetElement(std::string bundleName, std::string abilityName);
50     /**
51      * @brief Request persisted.
52      *
53      * @param persisted The persisted.
54      */
55     void RequestPersisted(bool persisted);
56     /**
57      * @brief Request network type.
58      *
59      * @param condition The condition.
60      */
61     void RequestNetworkType(WorkCondition::Network condition);
62     /**
63      * @brief Request charger type.
64      *
65      * @param isCharging Charging or not.
66      * @param condition The condition.
67      */
68     void RequestChargerType(bool isCharging, WorkCondition::Charger condition);
69     /**
70      * @brief Request battery level.
71      *
72      * @param battLevel The battery level.
73      */
74     void RequestBatteryLevel(int32_t battLevel);
75     /**
76      * @brief Request battery status.
77      *
78      * @param condition The condition.
79      */
80     void RequestBatteryStatus(WorkCondition::BatteryStatus condition);
81     /**
82      * @brief Request storage level.
83      *
84      * @param condition The condition.
85      */
86     void RequestStorageLevel(WorkCondition::Storage condition);
87     /**
88      * @brief Request repeat cycle.
89      *
90      * @param timeInterval The time interval.
91      * @param cycle The cycle.
92      */
93     void RequestRepeatCycle(uint32_t timeInterval, int32_t cycle);
94     /**
95      * @brief Request repeat cycle.
96      *
97      * @param timeInterval The time interval.
98      */
99     void RequestRepeatCycle(uint32_t timeInterval);
100     /**
101      * @brief Request base time and repeat cycle.
102      *
103      * @param baseTime The base time.
104      * @param cycle The cycle.
105      */
106     void RequestBaseTimeAndCycle(time_t baseTime, int32_t cycle);
107     /**
108      * @brief Request base time.
109      *
110      * @param baseTime The base time.
111      */
112     void RequestBaseTime(time_t baseTime);
113     /**
114      * @brief Request extra parameters.
115      *
116      * @param extras extra parameters.
117      */
118     void RequestExtras(AAFwk::WantParams extras);
119     /**
120      * @brief Refresh uid.
121      *
122      * @param uid The uid.
123      */
124     void RefreshUid(int32_t uid);
125     /**
126      * @brief Set callBySystemApp flag.
127      */
128     void SetCallBySystemApp(bool callBySystemApp);
129     /**
130      * @brief Get uid.
131      *
132      * @return The uid.
133      */
134     int32_t GetUid();
135 
136     /**
137      * @brief Get the id of work.
138      *
139      * @return The id of work.
140      */
141     int32_t GetWorkId();
142     /**
143      * @brief Get the name of bundle.
144      *
145      * @return The name of bundle.
146      */
147     std::string GetBundleName();
148     /**
149      * @brief Get the name of ability.
150      *
151      * @return The name of ability.
152      */
153     std::string GetAbilityName();
154     /**
155      * @brief Check whether the work is persist.
156      *
157      * @return Persist or not.
158      */
159     bool IsPersisted();
160     /**
161      * @brief Get the type of network.
162      *
163      * @return The type of network.
164      */
165     WorkCondition::Network GetNetworkType();
166     /**
167      * @brief Get the type of charger.
168      *
169      * @return The type of charger.
170      */
171     WorkCondition::Charger GetChargerType();
172     /**
173      * @brief Get the level of battery.
174      *
175      * @return The level of battery.
176      */
177     int32_t GetBatteryLevel();
178     /**
179      * @brief Get the status of battery.
180      *
181      * @return The status of battery.
182      */
183     WorkCondition::BatteryStatus GetBatteryStatus();
184     /**
185      * @brief Get the level of storage.
186      *
187      * @return The level of storage.
188      */
189     WorkCondition::Storage GetStorageLevel();
190     /**
191      * @brief Check whether the work is repeat.
192      *
193      * @return Repeat or not.
194      */
195     bool IsRepeat();
196     /**
197      * @brief Get the time interval.
198      *
199      * @return The time interval.
200      */
201     uint32_t GetTimeInterval();
202     /**
203      * @brief Get the count of cycle.
204      *
205      * @return The count of cycle.
206      */
207     int32_t GetCycleCount();
208     /**
209      * @brief Get the base time.
210      *
211      * @return The base time.
212      */
213     time_t GetBaseTime();
214     /**
215      * @brief Get the map of condition.
216      *
217      * @return The map of condition.
218      */
219     std::shared_ptr<std::map<WorkCondition::Type, std::shared_ptr<Condition>>> GetConditionMap();
220     /**
221      * @brief Get extra parameters.
222      *
223      * @return extra parameters.
224      */
225     std::shared_ptr<AAFwk::WantParams> GetExtras() const;
226     /**
227      * @brief Get callBySystemApp flag.
228      */
229     bool IsCallBySystemApp();
230     /**
231      * @brief Marshalling.
232      *
233      * @param parcel The parcel.
234      * @return True if success,else false.
235      */
236     bool Marshalling(Parcel &parcel) const override;
237     /**
238      * @brief Unmarshalling.
239      *
240      * @param parcel The parcel.
241      * @return Read.
242      */
243     static sptr<WorkInfo> Unmarshalling(Parcel &parcel);
244     /**
245      * @brief Dump.
246      *
247      * @param result The result.
248      */
249     void Dump(std::string &result);
250     /**
251      * @brief Parse to json str.
252      *
253      * @return Result.
254      */
255     std::string ParseToJsonStr();
256     /**
257      * @brief Parse from json.
258      *
259      * @param value The value.
260      * @return True if success,else false.
261      */
262     bool ParseFromJson(const Json::Value value);
263 
264 private:
265     int32_t workId_;
266     std::string bundleName_;
267     std::string abilityName_;
268     bool persisted_;
269     int32_t uid_;
270     std::shared_ptr<AAFwk::WantParams> extras_;
271     std::map<WorkCondition::Type, std::shared_ptr<Condition>> conditionMap_;
272     bool callBySystemApp_ {false};
273 private:
274     static void UnmarshallCondition(Parcel &parcel, sptr<WorkInfo> &read, uint32_t mapsize);
275     void ParseConditionToJsonStr(Json::Value &root);
276     void ParseConditionFromJsonStr(const Json::Value value);
277 };
278 } // namespace WorkScheduler
279 } // namespace OHOS
280 #endif // FOUNDATION_RESOURCESCHEDULE_WORKSCHEDULER_WORK_INFO_H