1 /* 2 * Copyright (C) 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_NET_OBSERVER_H 17 #define WIFI_NET_OBSERVER_H 18 19 #include <memory> 20 #include <string> 21 #include <vector> 22 #include "wifi_log.h" 23 #include "net_detection_callback_stub.h" 24 #include "net_handle.h" 25 #include "net_all_capabilities.h" 26 #include "net_conn_client.h" 27 #include "sta_define.h" 28 29 namespace OHOS { 30 namespace Wifi { 31 class NetStateObserver : public NetManagerStandard::NetDetectionCallbackStub { 32 public: 33 /** 34 * @Description Construct of NetStateObserver 35 */ 36 NetStateObserver(); 37 38 /** 39 * @Description Destructor function 40 */ 41 ~NetStateObserver(); 42 43 /** 44 * @Description registering a Network Detection Callback Listener 45 * 46 * @param netStateObserverPtr - netStateObserver ptr 47 */ 48 void StartNetStateObserver(sptr<NetStateObserver> &netStateObserverPtr); 49 50 /** 51 * @Description unregistering a Network Detection Callback Listener 52 * 53 * @param netStateObserverPtr - netStateObserver ptr 54 */ 55 void StopNetStateObserver(sptr<NetStateObserver> &netStateObserverPtr); 56 57 /** 58 * @Description registers the callback function of the Wi-Fi state machine. 59 * 60 * @param callback - callback func 61 */ 62 void SetNetStateCallback(const std::function<void(SystemNetWorkState, std::string)> &callback); 63 64 /** 65 * @Description callback function used to notify the detection result after the NetConnManager detection ends 66 * 67 * @param detectionResult - detection result 68 * @param urlRedirect - portal network redirection address 69 * @return detect if successful, 0 indicates success, others indicate failure error codes 70 */ 71 int32_t OnNetDetectionResultChanged( 72 NetManagerStandard::NetDetectionResultCode detectionResult, const std::string &urlRedirect) override; 73 74 /** 75 * @Description get network ID 76 * 77 * @return network ID 78 */ 79 int32_t GetWifiNetId(); 80 81 /** 82 * @Description start wifi detection 83 * 84 * @return 0 is success, 1 is fail 85 */ 86 int32_t StartWifiDetection(); 87 private: 88 sptr<NetManagerStandard::NetHandle> GetWifiNetworkHandle(); 89 public: 90 std::function<void(SystemNetWorkState, std::string)> m_callback; 91 }; 92 } 93 } 94 #endif 95