• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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_STANDBY_SERVICE_INTERFACE_INNERKITS_INCLUDE_STANDBY_SERVICE_CLIENT_H
17 #define FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_INTERFACE_INNERKITS_INCLUDE_STANDBY_SERVICE_CLIENT_H
18 
19 #include <iremote_proxy.h>
20 #include <nocopyable.h>
21 
22 #include "istandby_service.h"
23 #include "allow_info.h"
24 #include "resource_request.h"
25 #include "standby_service_errors.h"
26 #include "istandby_service_subscriber.h"
27 #include "res_data.h"
28 
29 namespace OHOS {
30 namespace DevStandbyMgr {
31 
32 enum class DeviceStateType: int32_t {
33     DIS_COMP_CHANGE = 0,
34     TELEPHONE_STATE_CHANGE,
35     WIFI_P2P_CHANGE,
36 };
37 
38 enum class PowerOverusedLevel : uint32_t {
39     NORMAL = 0,
40     MINOR,
41     WARNING,
42     SERIOUS,
43     EXTREME,
44     FATAL,
45 };
46 
47 class StandbyServiceClient {
48 public:
49     StandbyServiceClient();
50 
51     virtual ~StandbyServiceClient();
52 
53     static StandbyServiceClient& GetInstance();
54 
55     /**
56      * @brief Subscribes sleep state change event.
57      *
58      * @param subscriber Subscriber token.
59      * @return ERR_OK if success, else fail.
60      */
61     ErrCode SubscribeStandbyCallback(const sptr<IStandbyServiceSubscriber>& subscriber);
62 
63     /**
64      * @brief Unsubscribes sleep state change event.
65      *
66      * @param subscriber Subscriber token.
67      * @return ERR_OK if success, else fail.
68      */
69     ErrCode UnsubscribeStandbyCallback(const sptr<IStandbyServiceSubscriber>& subscriber);
70 
71     /**
72      * @brief add allow list for some services or apps.
73      *
74      * @param resourceRequest resource to be added.
75      * @return ErrCode ERR_OK if success, others if fail.
76      */
77     ErrCode ApplyAllowResource(const sptr<ResourceRequest>& resourceRequest);
78 
79     /**
80      * @brief remove uid with allow type from allow list.
81      *
82      * @param resourceRequest resource to be removed.
83      * @return ErrCode ErrCode ERR_OK if success, others if fail.
84      */
85     ErrCode UnapplyAllowResource(const sptr<ResourceRequest>& resourceRequest);
86 
87     /**
88      * @brief Get the Allow List object.
89      *
90      * @param allowType the allow type to be retrieved.
91      * @param allowInfoList result represents allowed types and apps.
92      * @param reasonCode represents the reason why invoke the api.
93      * @return ErrCode ERR_OK if success, else fail.
94      */
95     ErrCode GetAllowList(uint32_t allowType, std::vector<AllowInfo>& allowInfoList,
96         uint32_t reasonCode);
97 
98     /**
99      * @brief Get the Restrict List object.
100      *
101      * @param restrictType the restrict type to be retrieved.
102      * @param restrictInfoList result represents restricted types and apps.
103      * @param reasonCode represents the reason why invoke the api.
104      * @return ErrCode ERR_OK if success, others if fail.
105      */
106     ErrCode GetRestrictList(uint32_t restrictType, std::vector<AllowInfo>& restrictInfoList,
107         uint32_t reasonCode);
108 
109     /**
110      * @brief Construct a new Report Work Scheduler Status object.
111      *
112      * @param started true if the work is triggered, else false.
113      * @param uid uid of the applicatoin.
114      * @param bundleName bundleName of the application.
115      * @return ErrCode ERR_OK if success, others if fail.
116      */
117     ErrCode ReportWorkSchedulerStatus(bool started, int32_t uid, const std::string& bundleName);
118 
119     /**
120      * @brief Whether the restriction strategy enbaled or not.
121      *
122      * @param strategyName the strategy name.
123      * @param enabled true if the strategy is enabled.
124      * @return ErrCode ERR_OK if success, others if fail.
125      */
126     ErrCode IsStrategyEnabled(const std::string& strategyName, bool& isEnabled);
127 
128     /**
129      * @brief Report event when device state change, such as discomponent device, bluetooth socket..
130      *
131      * @param type type of device state.
132      * @param enabled true if the device state is on.
133      * @return ErrCode ERR_OK if success, others if fail.
134      */
135     ErrCode ReportDeviceStateChanged(DeviceStateType type, bool enabled);
136 
137     /**
138      * @brief query if the device is in standby mode;
139      *
140      * @param isStandby true if device in standby, else false.
141      * @return ErrCode ERR_OK if success, else fail.
142      */
143     ErrCode IsDeviceInStandby(bool& isStandby);
144 
145     /**
146      * @brief set nat timeout interval;
147      *
148      * @param type detect type.
149      * @param enable adjust or not.
150      * @param interval nat timeout interval.
151      * @return ErrCode ERR_OK if success, else fail.
152      */
153     ErrCode SetNatInterval(uint32_t& type, bool& enable, uint32_t& interval);
154 
155     /**
156      * @brief Unified handling of events;
157      *
158      * @param resData event data.
159      * @return ErrCode ERR_OK if success, else fail.
160      */
161     ErrCode HandleEvent(const std::shared_ptr<ResourceSchedule::ResData> &resData);
162 
163     /**
164      * @brief Report event when a module power energy is overused according to the information from XPower
165      *
166      * @param module module name
167      * @param level rate of power overused
168      * @return ErrCode ERR_OK if success, others if fail.
169      */
170     ErrCode ReportPowerOverused(const std::string &module, uint32_t level);
171 
172     /**
173      * @brief Push receives the message as the start point of the heartbeat.
174      *
175      * @param timestamp push msg recv timestamp.
176      * @return ErrCode ERR_OK if success, others if fail.
177      */
178     ErrCode DelayHeartBeat(int64_t timestamp);
179 
180 private:
181     bool GetStandbyServiceProxy();
182     void ResetStandbyServiceClient();
183 
184     class StandbyServiceDeathRecipient : public IRemoteObject::DeathRecipient {
185     public:
186         explicit StandbyServiceDeathRecipient(StandbyServiceClient& standbyServiceClient);
187 
188         ~StandbyServiceDeathRecipient() override;
189 
190         void OnRemoteDied(const wptr<IRemoteObject>& object) override;
191 
192     private:
193         StandbyServiceClient& standbyServiceClient_;
194     };
195 
196 private:
197     std::mutex mutex_;
198     sptr<IStandbyService> standbyServiceProxy_;
199     sptr<StandbyServiceDeathRecipient> deathRecipient_;
200 };
201 }  // namespace DevStandbyMgr
202 }  // namespace OHOS
203 #endif  // FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_INTERFACE_INNERKITS_INCLUDE_STANDBY_SERVICE_CLIENT_H
204