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 WIFI_SCAN_PROXY 17 #define WIFI_SCAN_PROXY 18 19 #include <vector> 20 #ifdef OHOS_ARCH_LITE 21 #include "iproxy_client.h" 22 #else 23 #include "iremote_broker.h" 24 #include "iremote_object.h" 25 #include "iremote_proxy.h" 26 #endif 27 #include "i_wifi_scan.h" 28 #include "i_wifi_scan_callback.h" 29 #include "refbase.h" 30 #include "wifi_errcode.h" 31 #include "wifi_scan_msg.h" 32 33 namespace OHOS { 34 namespace Wifi { 35 #ifdef OHOS_ARCH_LITE 36 class WifiScanProxy : public IWifiScan { 37 public:static WifiScanProxy *GetInstance(void); 38 static void ReleaseInstance(void); 39 explicit WifiScanProxy(void); 40 ErrCode Init(void); 41 #else 42 class WifiScanProxy : public IRemoteProxy<IWifiScan> { 43 public: 44 explicit WifiScanProxy(const sptr<IRemoteObject> &remote); 45 #endif 46 virtual ~WifiScanProxy(); 47 48 /** 49 * @Description Start scan Wifi 50 * 51 * @param compatible - indicates whether compatibility is maintained 52 * @return ErrCode - operation result 53 */ 54 virtual ErrCode Scan(bool compatible) override; 55 56 /** 57 * @Description Set the Scan Control Info object 58 * 59 * @param info - ScanControlInfo object 60 * @return ErrCode - operation result 61 */ 62 virtual ErrCode SetScanControlInfo(const tagScanControlInfo &info) override; 63 64 /** 65 * @Description Start scan with specified params 66 * 67 * @param params - WifiScanParams object 68 * @return ErrCode - operation result 69 */ 70 virtual ErrCode AdvanceScan(const WifiScanParams ¶ms) override; 71 72 /** 73 * @Description Check whether the ScanAlways mode is enabled 74 * 75 * @param bOpen - true / false 76 * @return ErrCode - operation result 77 */ 78 virtual ErrCode IsWifiClosedScan(bool &bOpen) override; 79 80 /** 81 * @Description Obtain the scanning result 82 * 83 * @param result - Get result venctor of WifiScanInfo 84 * @param compatible - indicates whether compatibility is maintained 85 * @return ErrCode - operation result 86 */ 87 virtual ErrCode GetScanInfoList(std::vector<WifiScanInfo> &result, bool compatible) override; 88 89 #ifdef OHOS_ARCH_LITE 90 virtual ErrCode RegisterCallBack(const std::shared_ptr<IWifiScanCallback> &callback, 91 const std::vector<std::string> &event) override; 92 #else 93 virtual ErrCode RegisterCallBack(const sptr<IWifiScanCallback> &callback, 94 const std::vector<std::string> &event) override; 95 #endif 96 97 /** 98 * @Description Get supported features 99 * 100 * @param features - return supported features 101 * @return ErrCode - operation result 102 */ 103 ErrCode GetSupportedFeatures(long &features) override; 104 105 /** 106 * @Description Check whether service is died. 107 * 108 * @return bool - true: service is died, false: service is not died. 109 */ 110 bool IsRemoteDied(void) override; 111 112 /** 113 * @Description SetScanOnlyAvailable. 114 * 115 * @return ErrCode - operation result 116 */ 117 ErrCode SetScanOnlyAvailable(bool bScanOnlyAvailable) override; 118 119 /** 120 * @Description GetScanAlways Whether Available. 121 * 122 * @return ErrCode - operation result 123 */ 124 ErrCode GetScanOnlyAvailable(bool &bScanOnlyAvailable) override; 125 126 /** 127 * @Description Start pno scan 128 * 129 * @param isStartAction - true:start pno scan; false:stop pno scan 130 * @param periodMs - pno scan interval 131 * @param suspendReason - pno scan suspent reason 132 * @return ErrCode - operation result 133 */ 134 ErrCode StartWifiPnoScan(bool isStartAction, int periodMs, int suspendReason) override; 135 136 #ifdef OHOS_ARCH_LITE 137 void OnRemoteDied(void); 138 private: 139 static WifiScanProxy *g_instance; 140 IClientProxy *remote_ = nullptr; 141 SvcIdentity svcIdentity_ = { 0 }; 142 bool remoteDied_; 143 #else 144 void OnRemoteDied(const wptr<IRemoteObject>& remoteObject); 145 private: 146 class WifiDeathRecipient : public IRemoteObject::DeathRecipient { 147 public: WifiDeathRecipient(WifiScanProxy & client)148 explicit WifiDeathRecipient(WifiScanProxy &client) : client_(client) {} 149 ~WifiDeathRecipient() override = default; OnRemoteDied(const wptr<IRemoteObject> & remote)150 void OnRemoteDied(const wptr<IRemoteObject> &remote) override 151 { 152 client_.OnRemoteDied(remote); 153 } 154 155 private: 156 WifiScanProxy &client_; 157 }; 158 ErrCode ParseScanInfos(MessageParcel &reply, std::vector<WifiScanInfo> &result, int contentSize); 159 ErrCode ParseScanInfosSmall(MessageParcel &reply, std::vector<WifiScanInfo> &result, int contentSize); 160 void RemoveDeathRecipient(void); 161 static BrokerDelegator<WifiScanProxy> g_delegator; 162 std::atomic<bool> mRemoteDied; 163 sptr<IRemoteObject> remote_ = nullptr; 164 std::mutex mutex_; 165 sptr<IRemoteObject::DeathRecipient> deathRecipient_ = nullptr; 166 #endif 167 }; 168 } // namespace Wifi 169 } // namespace OHOS 170 #endif 171