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 31 namespace OHOS { 32 namespace DevStandbyMgr { 33 enum class DeviceStateType: int32_t { 34 DIS_COMP_CHANGE = 0, 35 TELEPHONE_STATE_CHANGE, 36 WIFI_P2P_CHANGE, 37 }; 38 39 class IStandbyService : public IRemoteBroker { 40 public: 41 IStandbyService() = default; 42 ~IStandbyService() override = default; 43 DISALLOW_COPY_AND_MOVE(IStandbyService); 44 45 /** 46 * @brief Subscribes standby state change event. 47 * 48 * @param subscriber Subscriber token. 49 * @return ERR_OK if success, others if fail. 50 */ 51 virtual ErrCode SubscribeStandbyCallback(const sptr<IStandbyServiceSubscriber>& subscriber) = 0; 52 53 /** 54 * @brief Unsubscribes standby state change event. 55 * 56 * @param subscriber Subscriber token. 57 * @return ERR_OK if success, others if fail. 58 */ 59 virtual ErrCode UnsubscribeStandbyCallback(const sptr<IStandbyServiceSubscriber>& subscriber) = 0; 60 61 /** 62 * @brief add allow list for some services or apps. 63 * 64 * @param resourceRequest resource to be added. 65 * @return ErrCode ERR_OK if success, others if fail. 66 */ 67 virtual ErrCode ApplyAllowResource(const sptr<ResourceRequest>& resourceRequest) = 0; 68 69 /** 70 * @brief remove uid with allow type from allow list. 71 * 72 * @param resourceRequest resource to be removed. 73 * @return ErrCode ErrCode ERR_OK if success, others if fail. 74 */ 75 virtual ErrCode UnapplyAllowResource(const sptr<ResourceRequest>& resourceRequest) = 0; 76 77 /** 78 * @brief Get the Allow List object. 79 * 80 * @param allowType the allow type to be retrieved. 81 * @param allowInfoList result represents allowed types and apps. 82 * @param reasonCode represents the reason why invoke the api. 83 * @return ErrCode ERR_OK if success, others if fail. 84 */ 85 virtual ErrCode GetAllowList(uint32_t allowType, std::vector<AllowInfo>& allowInfoList, 86 uint32_t reasonCode) = 0; 87 88 /** 89 * @brief Get the Restrict List object. 90 * 91 * @param restrictType the restrict type to be retrieved. 92 * @param restrictInfoList result represents restricted types and apps. 93 * @param reasonCode represents the reason why invoke the api. 94 * @return ErrCode ERR_OK if success, others if fail. 95 */ 96 virtual ErrCode GetRestrictList(uint32_t restrictType, std::vector<AllowInfo>& restrictInfoList, 97 uint32_t reasonCode) = 0; 98 99 /** 100 * @brief Construct a new Report Work Scheduler Status object. 101 * 102 * @param started true if the work is triggered, else false. 103 * @param uid uid of the applicatoin. 104 * @param bundleName bundleName of the application. 105 * @return ErrCode ERR_OK if success, others if fail. 106 */ 107 virtual ErrCode ReportWorkSchedulerStatus(bool started, int32_t uid, const std::string& bundleName) = 0; 108 109 /** 110 * @brief Whether the restriction strategy enbaled or not. 111 * 112 * @param strategyName the strategy name. 113 * @param enabled true if the strategy is enabled. 114 * @return ErrCode ERR_OK if success, others if fail. 115 */ 116 virtual ErrCode IsStrategyEnabled(const std::string& strategyName, bool& isEnabled) = 0; 117 118 /** 119 * @brief Report event when device state change, such as discomponent device, bluetooth socket. 120 * 121 * @param type type of device state. 122 * @param enabled true if the device state is on. 123 * @return ErrCode ERR_OK if success, others if fail. 124 */ 125 virtual ErrCode ReportDeviceStateChanged(DeviceStateType type, bool enabled) = 0; 126 127 /** 128 * @brief query if the device is in standby mode. 129 * 130 * @param isStandby true if device in standby, else false. 131 * @return ErrCode ERR_OK if success, others if fail. 132 */ 133 virtual ErrCode IsDeviceInStandby(bool& isStandby) = 0; 134 135 public: 136 DECLARE_INTERFACE_DESCRIPTOR(u"ohos.resourceschedule.IStandbyService"); 137 138 protected: 139 enum InterfaceId : uint32_t { 140 SUBSCRIBE_STANDBY_CALLBACK = MIN_TRANSACTION_ID, 141 UNSUBSCRIBE_STANDBY_CALLBACK, 142 APPLY_ALLOW_RESOURCE, 143 UNAPPLY_ALLOW_RESOURCE, 144 GET_ALLOW_LIST, 145 IS_DEVICE_IN_STANDBY, 146 REPORT_WORK_SCHEDULER_STATUS, 147 REPORT_DEVICE_STATE_CHANGED, 148 }; 149 }; 150 } // namespace DevStandbyMgr 151 } // namespace OHOS 152 #endif // FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_FRAMEWORKS_INCLUDE_ISTANDBY_SERVICE_H 153