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 <list> 19 #include <map> 20 #include <memory> 21 #include <string> 22 23 #include <parcel.h> 24 #include "json/json.h" 25 26 #include "work_condition.h" 27 28 namespace OHOS { 29 namespace WorkScheduler { 30 class WorkInfo : public Parcelable { 31 public: 32 explicit WorkInfo(); 33 ~WorkInfo(); 34 void SetWorkId(int32_t workId); 35 void SetElement(std::string bundleName, std::string abilityName); 36 void RequestPersisted(bool persisted); 37 void RequestNetworkType(WorkCondition::Network condition); 38 void RequestChargerType(bool isCharging, WorkCondition::Charger condition); 39 void RequestBatteryLevel(int32_t battLevel); 40 void RequestBatteryStatus(WorkCondition::BatteryStatus condition); 41 void RequestStorageLevel(WorkCondition::Storage condition); 42 void RequestRepeatCycle(uint32_t timeInterval, int32_t cycle); 43 void RequestRepeatCycle(uint32_t timeInterval); 44 void RefreshUid(int32_t uid); 45 int32_t GetUid(); 46 47 int32_t GetWorkId(); 48 std::string GetBundleName(); 49 std::string GetAbilityName(); 50 bool IsPersisted(); 51 WorkCondition::Network GetNetworkType(); 52 WorkCondition::Charger GetChargerType(); 53 int32_t GetBatteryLevel(); 54 WorkCondition::BatteryStatus GetBatteryStatus(); 55 WorkCondition::Storage GetStorageLevel(); 56 bool IsRepeat(); 57 uint32_t GetTimeInterval(); 58 int32_t GetCycleCount(); 59 std::shared_ptr<std::map<WorkCondition::Type, std::shared_ptr<Condition>>> GetConditionMap(); 60 bool Marshalling(Parcel &parcel) const override; 61 static sptr<WorkInfo> Unmarshalling(Parcel &parcel); 62 void Dump(std::string &result); 63 std::string ParseToJsonStr(); 64 bool ParseFromJson(const Json::Value value); 65 66 private: 67 int32_t workId_; 68 std::string bundleName_; 69 std::string abilityName_; 70 bool persisted_; 71 int32_t uid_; 72 std::map<WorkCondition::Type, std::shared_ptr<Condition>> conditionMap_; 73 }; 74 } // namespace WorkScheduler 75 } // namespace OHOS 76 #endif // FOUNDATION_RESOURCESCHEDULE_WORKSCHEDULER_WORK_INFO_H