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 16 #ifndef FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_INTERFACES_INNERKITS_EFFICIENCY_RESOURCE_INFO_H 17 #define FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_INTERFACES_INNERKITS_EFFICIENCY_RESOURCE_INFO_H 18 19 #include <string> 20 #include <memory> 21 22 #include "parcel.h" 23 namespace OHOS { 24 namespace BackgroundTaskMgr { 25 class EfficiencyResourceInfo : public Parcelable { 26 public: 27 EfficiencyResourceInfo() = default;; 28 EfficiencyResourceInfo(uint32_t resourceNumber, bool isApply, uint32_t timeOut, std::string reason, 29 bool isPersist = false, bool isProcess = false) : resourceNumber_(resourceNumber), isApply_(isApply), 30 timeOut_(timeOut), reason_(reason), isPersist_(isPersist), isProcess_(isProcess) {} 31 32 /** 33 * @brief Unmarshals a purpose from a Parcel. 34 * 35 * @param parcel Indicates the parcel object for unmarshalling. 36 * @return The info of delay suspend. 37 */ 38 static EfficiencyResourceInfo* Unmarshalling(Parcel& in); 39 40 /** 41 * @brief Marshals a purpose into a parcel. 42 * 43 * @param parcel Indicates the parcel object for marshalling. 44 * @return True if success, else false. 45 */ 46 bool Marshalling(Parcel& out) const override; 47 48 /** 49 * @brief Get the resource number used to represent resource type. 50 * 51 * @return the resource number. 52 */ GetResourceNumber()53 inline uint32_t GetResourceNumber() const 54 { 55 return resourceNumber_; 56 } 57 58 /** 59 * @brief Get the apply status. 60 * 61 * @return True if the app begin to use, else false.. 62 */ IsApply()63 inline bool IsApply() const 64 { 65 return isApply_; 66 } 67 68 /** 69 * @brief Get the timeout. 70 * 71 * @return the timeout. 72 */ GetTimeOut()73 inline uint32_t GetTimeOut() const 74 { 75 return timeOut_; 76 } 77 78 /** 79 * @brief Get the reason. 80 * 81 * @return the reason. 82 */ GetReason()83 inline std::string GetReason() const 84 { 85 return reason_; 86 } 87 88 /** 89 * @brief persist or not. 90 * 91 * @return True if persist, else false. 92 */ IsPersist()93 inline bool IsPersist() const 94 { 95 return isPersist_; 96 } 97 98 /** 99 * @brief is process or not. 100 * 101 * @return True if apply for the process, false if apply for the app. 102 */ IsProcess()103 inline bool IsProcess() const 104 { 105 return isProcess_; 106 } 107 108 /** 109 * @brief Set the Resource Number object. 110 * 111 * @param resourceNumber represents resource type. 112 */ SetResourceNumber(uint32_t resourceNumber)113 inline void SetResourceNumber(uint32_t resourceNumber) 114 { 115 resourceNumber_ = resourceNumber; 116 } 117 118 /** 119 * @brief Set the isProcess object. 120 * 121 * @param isProcess true if process, else if app. 122 */ SetProcess(bool isProcess)123 inline void SetProcess(bool isProcess) 124 { 125 isProcess_ = isProcess; 126 } 127 private: 128 bool ReadFromParcel(Parcel& in); 129 130 uint32_t resourceNumber_; 131 bool isApply_; 132 uint32_t timeOut_; 133 std::string reason_; 134 bool isPersist_ {false}; 135 bool isProcess_ {false}; 136 }; 137 } // namespace BackgroundTaskMgr 138 } // namespace OHOS 139 #endif // FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_INTERFACES_INNERKITS_EFFICIENCY_RESOURCE_INFO_H