• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2025 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,
resourceNumber_(resourceNumber)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 
128     /**
129      * @brief Set the pid.
130      *
131      * @param pid The pid of app.
132      */
SetPid(int32_t pid)133     inline void SetPid(int32_t pid)
134     {
135         pid_ = pid;
136     }
137 
138     /**
139      * @brief Get the pid.
140      *
141      * @return the pid.
142      */
GetPid()143     inline int32_t GetPid() const
144     {
145         return pid_;
146     }
147 
148     /**
149      * @brief Set the uid.
150      *
151      * @param uid The uid of app.
152      */
SetUid(int32_t uid)153     inline void SetUid(int32_t uid)
154     {
155         uid_ = uid;
156     }
157 
158     /**
159      * @brief Get the uid.
160      *
161      * @return the uid.
162      */
GetUid()163     inline int32_t GetUid() const
164     {
165         return uid_;
166     }
167 
168 private:
169     bool ReadFromParcel(Parcel& in);
170 
171     uint32_t resourceNumber_;
172     bool isApply_;
173     uint32_t timeOut_;
174     std::string reason_;
175     bool isPersist_ {false};
176     bool isProcess_ {false};
177     int32_t uid_ {-1};
178     int32_t pid_ {-1};
179 };
180 }  // namespace BackgroundTaskMgr
181 }  // namespace OHOS
182 #endif  // FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_INTERFACES_INNERKITS_EFFICIENCY_RESOURCE_INFO_H