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_ISTANDBY_SERVICE_H 17 #define FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_FRAMEWORKS_INCLUDE_ISTANDBY_SERVICE_H 18 19 #include <string> 20 #include <vector> 21 22 #include <ipc_types.h> 23 #include <iremote_broker.h> 24 #include <nocopyable.h> 25 26 #include "allow_info.h" 27 #include "resourcce_request.h" 28 #include "standby_service_errors.h" 29 #include "istandby_service_subscriber.h" 30 #include "standby_res_data.h" 31 32 namespace OHOS { 33 namespace DevStandbyMgr { 34 enum class DeviceStateType: int32_t { 35 DIS_COMP_CHANGE = 0, 36 TELEPHONE_STATE_CHANGE, 37 WIFI_P2P_CHANGE, 38 }; 39 40 class IStandbyService : public IRemoteBroker { 41 public: 42 IStandbyService() = default; 43 ~IStandbyService() override = default; 44 DISALLOW_COPY_AND_MOVE(IStandbyService); 45 46 /** 47 * @brief Subscribes standby state change event. 48 * 49 * @param subscriber Subscriber token. 50 * @return ERR_OK if success, others if fail. 51 */ 52 virtual ErrCode SubscribeStandbyCallback(const sptr<IStandbyServiceSubscriber>& subscriber) = 0; 53 54 /** 55 * @brief Unsubscribes standby state change event. 56 * 57 * @param subscriber Subscriber token. 58 * @return ERR_OK if success, others if fail. 59 */ 60 virtual ErrCode UnsubscribeStandbyCallback(const sptr<IStandbyServiceSubscriber>& subscriber) = 0; 61 62 /** 63 * @brief add allow list for some services or apps. 64 * 65 * @param resourceRequest resource to be added. 66 * @return ErrCode ERR_OK if success, others if fail. 67 */ 68 virtual ErrCode ApplyAllowResource(const sptr<ResourceRequest>& resourceRequest) = 0; 69 70 /** 71 * @brief remove uid with allow type from allow list. 72 * 73 * @param resourceRequest resource to be removed. 74 * @return ErrCode ErrCode ERR_OK if success, others if fail. 75 */ 76 virtual ErrCode UnapplyAllowResource(const sptr<ResourceRequest>& resourceRequest) = 0; 77 78 /** 79 * @brief Get the Allow List object. 80 * 81 * @param allowType the allow type to be retrieved. 82 * @param allowInfoList result represents allowed types and apps. 83 * @param reasonCode represents the reason why invoke the api. 84 * @return ErrCode ERR_OK if success, others if fail. 85 */ 86 virtual ErrCode GetAllowList(uint32_t allowType, std::vector<AllowInfo>& allowInfoList, 87 uint32_t reasonCode) = 0; 88 89 /** 90 * @brief Get the Restrict List object. 91 * 92 * @param restrictType the restrict type to be retrieved. 93 * @param restrictInfoList result represents restricted types and apps. 94 * @param reasonCode represents the reason why invoke the api. 95 * @return ErrCode ERR_OK if success, others if fail. 96 */ 97 virtual ErrCode GetRestrictList(uint32_t restrictType, std::vector<AllowInfo>& restrictInfoList, 98 uint32_t reasonCode) = 0; 99 100 /** 101 * @brief Construct a new Report Work Scheduler Status object. 102 * 103 * @param started true if the work is triggered, else false. 104 * @param uid uid of the applicatoin. 105 * @param bundleName bundleName of the application. 106 * @return ErrCode ERR_OK if success, others if fail. 107 */ 108 virtual ErrCode ReportWorkSchedulerStatus(bool started, int32_t uid, const std::string& bundleName) = 0; 109 110 /** 111 * @brief Whether the restriction strategy enbaled or not. 112 * 113 * @param strategyName the strategy name. 114 * @param enabled true if the strategy is enabled. 115 * @return ErrCode ERR_OK if success, others if fail. 116 */ 117 virtual ErrCode IsStrategyEnabled(const std::string& strategyName, bool& isEnabled) = 0; 118 119 /** 120 * @brief Report event when device state change, such as discomponent device, bluetooth socket. 121 * 122 * @param type type of device state. 123 * @param enabled true if the device state is on. 124 * @return ErrCode ERR_OK if success, others if fail. 125 */ 126 virtual ErrCode ReportDeviceStateChanged(DeviceStateType type, bool enabled) = 0; 127 128 /** 129 * @brief query if the device is in standby mode. 130 * 131 * @param isStandby true if device in standby, else false. 132 * @return ErrCode ERR_OK if success, others if fail. 133 */ 134 virtual ErrCode IsDeviceInStandby(bool& isStandby) = 0; 135 136 /** 137 * @brief set nat timeout interval. 138 * 139 * @param type detect type. 140 * @param enable adjust or not. 141 * @param interval nat timeout interval. 142 * @return ErrCode ERR_OK if success, others if fail. 143 */ 144 virtual ErrCode SetNatInterval(uint32_t& type, bool& enable, uint32_t& interval) = 0; 145 146 /** 147 * @brief Unified handing of events 148 * 149 * @param resType scene type 150 * @param vaule extra scene message 151 * @param sceneInfo detail scene message, such as pid, uid and so on 152 * @return ErrCode ERR_OK if success, others if fail. 153 */ 154 virtual ErrCode HandleEvent(const uint32_t resType, const int64_t value, const std::string &sceneInfo) = 0; 155 156 /** 157 * @brief Report event when a module power energy is overused according to the information from XPower 158 * 159 * @param module module name 160 * @param level rate of power overused 161 * @return ErrCode ERR_OK if success, others if fail. 162 */ 163 virtual ErrCode ReportPowerOverused(const std::string &module, uint32_t level) = 0; 164 165 public: 166 DECLARE_INTERFACE_DESCRIPTOR(u"ohos.resourceschedule.IStandbyService"); 167 168 protected: 169 enum InterfaceId : uint32_t { 170 SUBSCRIBE_STANDBY_CALLBACK = MIN_TRANSACTION_ID, 171 UNSUBSCRIBE_STANDBY_CALLBACK, 172 APPLY_ALLOW_RESOURCE, 173 UNAPPLY_ALLOW_RESOURCE, 174 GET_ALLOW_LIST, 175 IS_DEVICE_IN_STANDBY, 176 REPORT_WORK_SCHEDULER_STATUS, 177 REPORT_DEVICE_STATE_CHANGED, 178 HANDLE_EVENT 179 }; 180 }; 181 } // namespace DevStandbyMgr 182 } // namespace OHOS 183 #endif // FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_FRAMEWORKS_INCLUDE_ISTANDBY_SERVICE_H 184