1 /* 2 * Copyright (C) 2021-2022 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 OHOS_WIFI_HOTSPOT_PROXY_H 17 #define OHOS_WIFI_HOTSPOT_PROXY_H 18 19 #include "iremote_proxy.h" 20 #include "i_wifi_hotspot.h" 21 #include "wifi_errcode.h" 22 #include "wifi_ap_msg.h" 23 24 namespace OHOS { 25 namespace Wifi { 26 class WifiHotspotProxy : public IRemoteProxy<IWifiHotspot> { 27 public: 28 explicit WifiHotspotProxy(const sptr<IRemoteObject> &impl); 29 30 ~WifiHotspotProxy(); 31 32 /** 33 * @Description Check whether the hotspot is active. 34 * 35 * @param isActive - active / inactive 36 * @return ErrCode - operation result 37 */ 38 ErrCode IsHotspotActive(bool &isActive) override; 39 40 /** 41 * @Description Check whether the hotspot supports dual band. 42 * 43 * @param isSupported - Supported / NOT Supported 44 * @return ErrCode - operation result 45 */ 46 ErrCode IsHotspotDualBandSupported(bool &isSupported) override; 47 48 /** 49 * @Description Get the Hotspot Config object 50 * 51 * @param config - HotapotConfig object 52 * @return ErrCode - operation result 53 */ 54 ErrCode GetHotspotConfig(HotspotConfig &config) override; 55 56 /** 57 * @Description Get the Hotspot State object 58 * 59 * @param state - current Hotspot state 60 * @return ErrCode - operation result 61 */ 62 ErrCode GetHotspotState(int &state) override; 63 64 /** 65 * @Description Set the configuration of Hotspot 66 * 67 * @param config - HotspotConfig object 68 * @return ErrCode - operation result 69 */ 70 ErrCode SetHotspotConfig(const HotspotConfig &config) override; 71 72 /** 73 * @Description Set the idel timeout of Hotspot 74 * 75 * @param time -input time, 76 * @return ErrCode - operation result 77 */ 78 ErrCode SetHotspotIdleTimeout(int time) override; 79 80 /** 81 * @Description Get the Station List object 82 * 83 * @param result - Get result vector of connect Station Info 84 * @return ErrCode - operation result 85 */ 86 ErrCode GetStationList(std::vector<StationInfo> &result) override; 87 88 /** 89 * @Description Disconnects a specified sta connection 90 * 91 * @param info - Station object 92 * @return ErrCode - operation result 93 */ 94 ErrCode DisassociateSta(const StationInfo &info) override; 95 96 /** 97 * @Description Enable Hotspot 98 * 99 * @param type - service type 100 * @return ErrCode - operation result 101 */ 102 ErrCode EnableHotspot(const ServiceType type = ServiceType::DEFAULT) override; 103 104 /** 105 * @Description Disable Hotspot 106 * 107 * @param type - service type 108 * @return ErrCode - operation result 109 */ 110 ErrCode DisableHotspot(const ServiceType type = ServiceType::DEFAULT) override; 111 112 /** 113 * @Description Get the Block Lists object 114 * 115 * @param infos - Get Blocklist result vector of StationInfo 116 * @return ErrCode - operation result 117 */ 118 ErrCode GetBlockLists(std::vector<StationInfo> &infos) override; 119 120 /** 121 * @Description Add a StationInfo object to Blocklist 122 * 123 * @param info - Station object 124 * @return ErrCode - operation result 125 */ 126 ErrCode AddBlockList(const StationInfo &info) override; 127 128 /** 129 * @Description Del a StationInfo object from Blocklist 130 * 131 * @param info - StationInfo object 132 * @return ErrCode - operation result 133 */ 134 ErrCode DelBlockList(const StationInfo &info) override; 135 136 /** 137 * @Description Get the Valid Bands object 138 * 139 * @param bands - Get result vector of BandType 140 * @return ErrCode - operation result 141 */ 142 ErrCode GetValidBands(std::vector<BandType> &bands) override; 143 144 /** 145 * @Description Get the Valid Channels object 146 * 147 * @param band - Specified band 148 * @param validchannels - Obtains the channels corresponding to the specified band 149 * @return ErrCode - operation result 150 */ 151 ErrCode GetValidChannels(BandType band, std::vector<int32_t> &validchannels) override; 152 153 /** 154 * @Description Register callback client 155 * 156 * @param callback - callback struct 157 * @return ErrCode - operation result 158 */ 159 ErrCode RegisterCallBack(const sptr<IWifiHotspotCallback> &callback, 160 const std::vector<std::string> &event) override; 161 162 /** 163 * @Description Get supported features 164 * 165 * @param features - return supported features 166 * @return ErrCode - operation result 167 */ 168 ErrCode GetSupportedFeatures(long &features) override; 169 170 /** 171 * @Description Handle remote object died event. 172 * @param remoteObject remote object. 173 */ 174 void OnRemoteDied(const wptr<IRemoteObject>& remoteObject); 175 176 /** 177 * @Description Get supported power model list 178 * 179 * @param setPowerModelList - supported power model list 180 * @return ErrCode - operation result 181 */ 182 ErrCode GetSupportedPowerModel(std::set<PowerModel>& setPowerModelList) override; 183 184 /** 185 * @Description Get power model 186 * 187 * @param model - current power model 188 * @return ErrCode - operation result 189 */ 190 ErrCode GetPowerModel(PowerModel& model) override; 191 192 /** 193 * @Description Get supported power model list 194 * 195 * @param model - the model to be set 196 * @return ErrCode - operation result 197 */ 198 ErrCode SetPowerModel(const PowerModel& model) override; 199 200 /** 201 * @Description Check whether service is died. 202 * 203 * @return bool - true: service is died, false: service is not died. 204 */ 205 bool IsRemoteDied(void) override; 206 207 /** 208 * @Description Get ap iface name 209 * 210 * @param ifaceName - the ifaceName to be set 211 * @return ErrCode - operation result 212 */ 213 ErrCode GetApIfaceName(std::string& ifaceName) override; 214 215 private: 216 class WifiDeathRecipient : public IRemoteObject::DeathRecipient { 217 public: WifiDeathRecipient(WifiHotspotProxy & client)218 explicit WifiDeathRecipient(WifiHotspotProxy &client) : client_(client) {} 219 ~WifiDeathRecipient() override = default; OnRemoteDied(const wptr<IRemoteObject> & remote)220 void OnRemoteDied(const wptr<IRemoteObject> &remote) override 221 { 222 client_.OnRemoteDied(remote); 223 } 224 225 private: 226 WifiHotspotProxy &client_; 227 }; 228 229 void RemoveDeathRecipient(void); 230 static BrokerDelegator<WifiHotspotProxy> g_delegator; 231 std::atomic<bool> mRemoteDied; 232 sptr<IRemoteObject> remote_ = nullptr; 233 std::mutex mutex_; 234 sptr<IRemoteObject::DeathRecipient> deathRecipient_ = nullptr; 235 }; 236 } // namespace Wifi 237 } // namespace OHOS 238 #endif