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_FRAMEWORKS_INCLUDE_STANDBY_SERVICE_PROXY_H
17 #define FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_FRAMEWORKS_INCLUDE_STANDBY_SERVICE_PROXY_H
18 
19 #include <iremote_proxy.h>
20 #include <nocopyable.h>
21 
22 #include "istandby_service.h"
23 
24 namespace OHOS {
25 namespace DevStandbyMgr {
26 class StandbyServiceProxy final : public IRemoteProxy<IStandbyService> {
27 public:
28     explicit StandbyServiceProxy(const sptr<IRemoteObject>& impl);
29     ~StandbyServiceProxy() override;
30     DISALLOW_COPY_AND_MOVE(StandbyServiceProxy);
31 
32     /**
33      * @brief Subscribes standby state change event.
34      *
35      * @param subscriber Subscriber token.
36      * @return ERR_OK if success, else fail.
37      */
38     ErrCode SubscribeStandbyCallback(const sptr<IStandbyServiceSubscriber>& subscriber) override;
39 
40     /**
41      * @brief Unsubscribes standby state change event.
42      *
43      * @param subscriber Subscriber token.
44      * @return ERR_OK if success, else fail.
45      */
46     ErrCode UnsubscribeStandbyCallback(const sptr<IStandbyServiceSubscriber>& subscriber) override;
47 
48     /**
49      * @brief add allow list for some services or apps.
50      *
51      * @param resourceRequest resource to be added.
52      * @return ErrCode ERR_OK if success, others if fail.
53      */
54     ErrCode ApplyAllowResource(const sptr<ResourceRequest>& resourceRequest) override;
55 
56     /**
57      * @brief remove uid with allow type from allow list.
58      *
59      * @param resourceRequest resource to be removed.
60      * @return ErrCode ErrCode ERR_OK if success, others if fail.
61      */
62     ErrCode UnapplyAllowResource(const sptr<ResourceRequest>& resourceRequest) override;
63 
64     /**
65      * @brief Get the Allow List object.
66      *
67      * @param allowType the allow type to be retrieved.
68      * @param allowInfoList result represents allowed types and apps.
69      * @param isApp represents the reason why invoke the api.
70      * @return ErrCode ERR_OK if success, others if fail.
71      */
72     ErrCode GetAllowList(uint32_t allowType, std::vector<AllowInfo>& allowInfoList,
73         uint32_t reasonCode) override;
74 
75     /**
76      * @brief query if the device is in standby mode;
77      *
78      * @param isStandby true if device in standby, else false.
79      * @return ErrCode ERR_OK if success, others if fail.
80      */
81     ErrCode IsDeviceInStandby(bool& isStandby) override;
82 
83     /**
84      * @brief set nat timeout interval;
85      *
86      * @param type detect type.
87      * @param enable adjust or not.
88      * @param interval nat timeout interval.
89      * @return ErrCode ERR_OK if success, else fail.
90      */
91     ErrCode SetNatInterval(uint32_t& type, bool& enable, uint32_t& interval) override;
92 
93     /**
94      * @brief Construct a new Report Work Scheduler Status object.
95      *
96      * @param started true if the work is triggered, else false.
97      * @param uid uid of the applicatoin.
98      * @param bundleName bundleName of the application.
99      */
100     ErrCode ReportWorkSchedulerStatus(bool started, int32_t uid, const std::string& bundleName) override;
101 
102     /**
103      * @brief Get the Restrict List object.
104      *
105      * @param allowType the allow type to be retrieved.
106      * @param allowInfoList result represents allowed types and apps.
107      * @param reasonCode represents the reason why invoke the api.
108      * @return ErrCode ERR_OK if success, others if fail.
109      */
110     ErrCode GetRestrictList(uint32_t restrictType, std::vector<AllowInfo>& restrictInfoList,
111         uint32_t reasonCode) override;
112 
113     /**
114      * @brief Whether the restriction strategy enbaled or not.
115      *
116      * @param strategyName the strategy name.
117      * @param enabled true if the strategy is enabled.
118      */
119     ErrCode IsStrategyEnabled(const std::string& strategyName, bool& enabled) override;
120 
121     /**
122      * @brief Report event when device state change.
123      *
124      * @param type type of device state.
125      * @param enabled true if the device state is on.
126      */
127     ErrCode ReportDeviceStateChanged(DeviceStateType type, bool enabled) override;
128 
129     /**
130      * @brief Unified handing of events
131      *
132      * @param resType scene type
133      * @param vaule extra scene message
134      * @param sceneInfo detail scene message, such as pid, uid and so on
135      * @return ErrCode ERR_OK if success, others if fail.
136      */
137     ErrCode HandleEvent(const uint32_t resType, const int64_t value, const std::string &sceneInfo) override;
138 
139     /**
140      * @brief Report event when a module power energy is overused according to the information from XPower
141      *
142      * @param module module name
143      * @param level rate of power overused
144      * @return ErrCode ERR_OK if success, others if fail.
145      */
146     ErrCode ReportPowerOverused(const std::string &module, uint32_t level) override;
147 
148 private:
149     ErrCode InnerTransact(uint32_t code, MessageOption& flags, MessageParcel& data, MessageParcel& reply);
150 
151     static inline BrokerDelegator<StandbyServiceProxy> delegator_;
152 };
153 }  // namespace DevStandbyMgr
154 }  // namespace OHOS
155 #endif  // FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_FRAMEWORKS_INCLUDE_STANDBY_SERVICE_PROXY_H
156