• 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 extra parameters.
102      *
103      * @param extras extra parameters.
104      */
105     void RequestExtras(AAFwk::WantParams extras);
106     /**
107      * @brief Refresh uid.
108      *
109      * @param uid The uid.
110      */
111     void RefreshUid(int32_t uid);
112     /**
113      * @brief Get uid.
114      *
115      * @return The uid.
116      */
117     int32_t GetUid();
118 
119     /**
120      * @brief Get the id of work.
121      *
122      * @return The id of work.
123      */
124     int32_t GetWorkId();
125     /**
126      * @brief Get the name of bundle.
127      *
128      * @return The name of bundle.
129      */
130     std::string GetBundleName();
131     /**
132      * @brief Get the name of ability.
133      *
134      * @return The name of ability.
135      */
136     std::string GetAbilityName();
137     /**
138      * @brief Check whether the work is persist.
139      *
140      * @return Persist or not.
141      */
142     bool IsPersisted();
143     /**
144      * @brief Get the type of network.
145      *
146      * @return The type of network.
147      */
148     WorkCondition::Network GetNetworkType();
149     /**
150      * @brief Get the type of charger.
151      *
152      * @return The type of charger.
153      */
154     WorkCondition::Charger GetChargerType();
155     /**
156      * @brief Get the level of battery.
157      *
158      * @return The level of battery.
159      */
160     int32_t GetBatteryLevel();
161     /**
162      * @brief Get the status of battery.
163      *
164      * @return The status of battery.
165      */
166     WorkCondition::BatteryStatus GetBatteryStatus();
167     /**
168      * @brief Get the level of storage.
169      *
170      * @return The level of storage.
171      */
172     WorkCondition::Storage GetStorageLevel();
173     /**
174      * @brief Check whether the work is repeat.
175      *
176      * @return Repeat or not.
177      */
178     bool IsRepeat();
179     /**
180      * @brief Get the time interval.
181      *
182      * @return The time interval.
183      */
184     uint32_t GetTimeInterval();
185     /**
186      * @brief Get the count of cycle.
187      *
188      * @return The count of cycle.
189      */
190     int32_t GetCycleCount();
191     /**
192      * @brief Get the map of condition.
193      *
194      * @return The map of condition.
195      */
196     std::shared_ptr<std::map<WorkCondition::Type, std::shared_ptr<Condition>>> GetConditionMap();
197     /**
198      * @brief Get extra parameters.
199      *
200      * @return extra parameters.
201      */
202     std::shared_ptr<AAFwk::WantParams> GetExtras() const;
203     /**
204      * @brief Marshalling.
205      *
206      * @param parcel The parcel.
207      * @return True if success,else false.
208      */
209     bool Marshalling(Parcel &parcel) const override;
210     /**
211      * @brief Unmarshalling.
212      *
213      * @param parcel The parcel.
214      * @return Read.
215      */
216     static sptr<WorkInfo> Unmarshalling(Parcel &parcel);
217     /**
218      * @brief Dump.
219      *
220      * @param result The result.
221      */
222     void Dump(std::string &result);
223     /**
224      * @brief Parse to json str.
225      *
226      * @return Result.
227      */
228     std::string ParseToJsonStr();
229     /**
230      * @brief Parse from json.
231      *
232      * @param value The value.
233      * @return True if success,else false.
234      */
235     bool ParseFromJson(const Json::Value value);
236 
237 private:
238     int32_t workId_;
239     std::string bundleName_;
240     std::string abilityName_;
241     bool persisted_;
242     int32_t uid_;
243     std::shared_ptr<AAFwk::WantParams> extras_;
244     std::map<WorkCondition::Type, std::shared_ptr<Condition>> conditionMap_;
245 private:
246     static void UnmarshallCondition(Parcel &parcel, sptr<WorkInfo> &read, uint32_t mapsize);
247     void ParseConditionToJsonStr(Json::Value &root);
248     void ParseConditionFromJsonStr(const Json::Value value);
249 };
250 } // namespace WorkScheduler
251 } // namespace OHOS
252 #endif // FOUNDATION_RESOURCESCHEDULE_WORKSCHEDULER_WORK_INFO_H