diff --git a/netmanager_ext_config.gni b/netmanager_ext_config.gni index d23e0dca124984e76b3e2d0d87b8689bb67cafa7..5185a78e06f488bafe2eaa67a26432f0ec38d5e9 100644 --- a/netmanager_ext_config.gni +++ b/netmanager_ext_config.gni @@ -53,9 +53,6 @@ NETWORKSLICE_SOURCE_DIR = "$NETMANAGER_EXT_ROOT/services/networkslicemanager" # args of uitls NETWORKSHAREMANAGER_UTILS_DIR = "$NETMANAGER_EXT_ROOT/utils" -# args of other module -WIFI_MANAGER_ROOT = "//foundation/communication/wifi/wifi" - use_js_debug = false declare_args() { communication_bluetooth_switch_enable = false diff --git a/services/networksharemanager/BUILD.gn b/services/networksharemanager/BUILD.gn index 33dcd4dd5dd74998c776eee7e82a594b17264e33..77b32321b2a1d720e31602554ad4a8e6065e2466 100644 --- a/services/networksharemanager/BUILD.gn +++ b/services/networksharemanager/BUILD.gn @@ -26,9 +26,6 @@ config("net_tether_manager_config") { "$NETWORKSHAREMANAGER_SOURCE_DIR/include/utils", "$NETWORKSHAREMANAGER_UTILS_DIR/event_report/include", ] - if (communication_wifi_switch_enable) { - include_dirs += [ "$WIFI_MANAGER_ROOT/interfaces/kits/c" ] - } } ohos_shared_library("net_tether_manager") { diff --git a/services/networksharemanager/include/networkshare_tracker.h b/services/networksharemanager/include/networkshare_tracker.h index 5d9c03b8226b10db153063e65377ed8c0a695795..c2652e9dd28d952977c6f42ceeec454ae2f38e86 100644 --- a/services/networksharemanager/include/networkshare_tracker.h +++ b/services/networksharemanager/include/networkshare_tracker.h @@ -41,7 +41,6 @@ #ifdef WIFI_MODOULE #include "wifi_ap_msg.h" #include "wifi_hotspot.h" -#include "wifi_device_config.h" #endif namespace OHOS { @@ -115,6 +114,15 @@ private: bool isNcm_; }; +#ifdef WIFI_MODOULE + class WifiHotspotCallback : public IRemoteStub { + public: + void OnHotspotStateChanged(int state) override; + void OnHotspotStaJoin(const Wifi::StationInfo &info) override; + void OnHotspotStaLeave(const Wifi::StationInfo &info) override; + }; +#endif + public: static NetworkShareTracker &GetInstance(); ~NetworkShareTracker() = default; @@ -248,12 +256,9 @@ private: void StopDnsProxy(); SharingIfaceState SubSmStateToExportState(int32_t state); void OnChangeSharingState(const SharingIfaceType &type, bool state); - static void OnWifiHotspotStateChanged(int state); - static void OnWifiHotspotStaLeave(StationInfo *info); - static void OnWifiHotspotStaJoin(StationInfo *info); - void RegisterWifiApCallback(); void RegisterBtPanCallback(); #ifdef WIFI_MODOULE + void RegisterWifiApCallback(); void SetWifiState(const Wifi::ApState &state); void HandleHotSpotStarted(); void HandleHotSpotClosed(); @@ -263,6 +268,9 @@ private: void StopIdleApStopTimer(); void StartIdleApStopTimer(); void GetPowerConnected(); + int32_t EnableHotspot(); + int32_t DisableHotspot(); + int32_t GetStationNum(size_t &num); #endif #ifdef BLUETOOTH_MODOULE void SetBluetoothState(const Bluetooth::BTConnectState &state); @@ -288,8 +296,8 @@ private: bool isStartDnsProxy_ = false; #ifdef WIFI_MODOULE int32_t wifiShareCount_ = 0; + sptr wifiHotspotCallback_ = nullptr; Wifi::ApState curWifiState_ = Wifi::ApState::AP_STATE_NONE; - WifiEvent g_wifiEvent = {0}; uint32_t idleApStopTimerId_ = 0; ffrt::mutex apStopTimerMutex_; bool powerConnected_ = false; diff --git a/services/networksharemanager/src/networkshare_sub_statemachine.cpp b/services/networksharemanager/src/networkshare_sub_statemachine.cpp index cb7a7bf2dcb8a66045d8730158fab1c8b76bbc66..d1ff7cae6e1db776218fdc82978553afd6712b6a 100644 --- a/services/networksharemanager/src/networkshare_sub_statemachine.cpp +++ b/services/networksharemanager/src/networkshare_sub_statemachine.cpp @@ -472,10 +472,13 @@ void NetworkShareSubStateMachine::HandleConnectionChanged(const std::shared_ptr< CleanupUpstreamInterface(); upstreamIfaceName_ = upstreamNetInfo->netLinkPro_->ifaceName_; #ifdef WIFI_MODOULE - int mode = static_cast(Wifi::HotspotMode::NONE); - int32_t ret = GetHotspotMode(&mode); - NETMGR_EXT_LOG_I("get hotspot mode, mode=%{public}d", mode); - if (mode != static_cast(Wifi::HotspotMode::LOCAL_ONLY_SOFTAP)) { + Wifi::HotspotMode mode = Wifi::HotspotMode::NONE; + auto WifiHostInstance = Wifi::WifiHotspot::GetInstance(WIFI_HOTSPOT_ABILITY_ID); + if (WifiHostInstance != nullptr) { + WifiHostInstance->GetHotspotMode(mode); + } + NETMGR_EXT_LOG_I("get hotspot mode, mode=%{public}d", static_cast(mode)); + if (mode != Wifi::HotspotMode::LOCAL_ONLY_SOFTAP) { HandleConnection(); } #else diff --git a/services/networksharemanager/src/networkshare_tracker.cpp b/services/networksharemanager/src/networkshare_tracker.cpp index 4c953f3a7758db99c255d174c53ef3e57bc7f7af..20149839ee5293212c05c0d56c08cd184133f193 100644 --- a/services/networksharemanager/src/networkshare_tracker.cpp +++ b/services/networksharemanager/src/networkshare_tracker.cpp @@ -205,6 +205,40 @@ void NetworkShareTracker::SharingPanObserver::OnConnectionStateChanged(const Blu } } #endif + +#ifdef WIFI_MODOULE +void NetworkShareTracker::WifiHotspotCallback::OnHotspotStateChanged(int state) +{ + NETMGR_EXT_LOG_I("Receive Hotspot state changed event, state[%{public}d]", state); + Wifi::ApState curState = static_cast(state); + NetworkShareTracker::GetInstance().SetWifiState(curState); + switch (curState) { + case Wifi::ApState::AP_STATE_STARTING: + break; + case Wifi::ApState::AP_STATE_STARTED: + NetworkShareTracker::GetInstance().HandleHotSpotStarted(); + break; + case Wifi::ApState::AP_STATE_CLOSING: + break; + case Wifi::ApState::AP_STATE_CLOSED: + NetworkShareTracker::GetInstance().HandleHotSpotClosed(); + break; + default: + break; + } +} + +void NetworkShareTracker::WifiHotspotCallback::OnHotspotStaJoin(const Wifi::StationInfo &info) +{ + NetworkShareTracker::GetInstance().HandleHotSpotStaJoin(); +} + +void NetworkShareTracker::WifiHotspotCallback::OnHotspotStaLeave(const Wifi::StationInfo &info) +{ + NetworkShareTracker::GetInstance().HandleHotSpotStaLeave(); +} +#endif + NetworkShareTracker &NetworkShareTracker::GetInstance() { static NetworkShareTracker instance; @@ -247,7 +281,9 @@ bool NetworkShareTracker::Init() netsysCallback_ = new (std::nothrow) NetsysCallback(); NetsysController::GetInstance().RegisterCallback(netsysCallback_); +#ifdef WIFI_MODOULE RegisterWifiApCallback(); +#endif RegisterBtPanCallback(); isNetworkSharing_ = false; @@ -272,58 +308,29 @@ void NetworkShareTracker::OnChangeSharingState(const SharingIfaceType &type, boo NETMGR_EXT_LOG_I("Hotspot OnChangeSharing, clientRequestsVector_ [%{public}zu]", clientRequestsVector_.size()); } -void NetworkShareTracker::OnWifiHotspotStateChanged(int state) -{ - NETMGR_EXT_LOG_I("Receive Hotspot state changed event, state[%{public}d]", state); -#ifdef WIFI_MODOULE - Wifi::ApState curState = static_cast(state); - NetworkShareTracker::GetInstance().SetWifiState(curState); - switch (curState) { - case Wifi::ApState::AP_STATE_STARTING: - break; - case Wifi::ApState::AP_STATE_STARTED: { - NetworkShareTracker::GetInstance().HandleHotSpotStarted(); - break; - } - case Wifi::ApState::AP_STATE_CLOSING: - break; - case Wifi::ApState::AP_STATE_CLOSED: { - NetworkShareTracker::GetInstance().HandleHotSpotClosed(); - break; - } - default: - break; - } -#endif -} - -void NetworkShareTracker::OnWifiHotspotStaLeave(StationInfo *info) -{ #ifdef WIFI_MODOULE - NetworkShareTracker::GetInstance().HandleHotSpotStaLeave(); -#endif -} - -void NetworkShareTracker::OnWifiHotspotStaJoin(StationInfo *info) -{ -#ifdef WIFI_MODOULE - NetworkShareTracker::GetInstance().HandleHotSpotStaJoin(); -#endif -} - void NetworkShareTracker::RegisterWifiApCallback() { -#ifdef WIFI_MODOULE - g_wifiEvent.OnHotspotStateChanged = NetworkShareTracker::OnWifiHotspotStateChanged; - g_wifiEvent.OnHotspotStaLeave = NetworkShareTracker::OnWifiHotspotStaLeave; - g_wifiEvent.OnHotspotStaJoin = NetworkShareTracker::OnWifiHotspotStaJoin; - int32_t ret = RegisterWifiEvent(&g_wifiEvent); - if (ret != WIFI_SUCCESS) { - NETMGR_EXT_LOG_E("Register wifi hotspot callback error[%{public}d].", ret); - } - return; -#endif + NETMGR_EXT_LOG_I("RegisterWifiApCallback"); + if (wifiHotspotCallback_ == nullptr) { + wifiHotspotCallback_ = sptr::MakeSptr(); + } + auto WifiHostInstance = Wifi::WifiHotspot::GetInstance(WIFI_HOTSPOT_ABILITY_ID); + if (WifiHostInstance == nullptr) { + NETMGR_EXT_LOG_E("WifiHostInstance is nullptr"); + return; + } + static std::vector event = { + EVENT_HOTSPOT_STATE_CHANGE, + EVENT_HOTSPOT_STA_JOIN, + EVENT_HOTSPOT_STA_LEAVE, + }; + int ret = WifiHostInstance->RegisterCallBack(wifiHotspotCallback_, event); + if (ret != Wifi::WIFI_OPT_SUCCESS) { + NETMGR_EXT_LOG_E("NetworkShareTracker::RegisterWifiApCallback failed:%{public}d", ret); + } } +#endif void NetworkShareTracker::RegisterBtPanCallback() { @@ -733,7 +740,7 @@ int32_t NetworkShareTracker::SetWifiNetworkSharing(bool enable) #ifdef WIFI_MODOULE if (enable) { int32_t ret = EnableHotspot(); - if (ret != WIFI_SUCCESS) { + if (ret != Wifi::WIFI_OPT_SUCCESS) { NETMGR_EXT_LOG_E("EnableHotspot error[%{public}d].", ret); result = NETWORKSHARE_ERROR_WIFI_SHARING; NetworkShareHisysEvent::GetInstance().SendFaultEvent( @@ -750,7 +757,7 @@ int32_t NetworkShareTracker::SetWifiNetworkSharing(bool enable) } } else { int32_t ret = DisableHotspot(); - if (ret != WIFI_SUCCESS) { + if (ret != Wifi::WIFI_OPT_SUCCESS) { NetworkShareHisysEvent::GetInstance().SendFaultEvent( SharingIfaceType::SHARING_WIFI, NetworkShareEventOperator::OPERATION_DISABLE_IFACE, NetworkShareEventErrorType::ERROR_DISABLE_IFACE, ERROR_MSG_DISABLE_WIFI, @@ -1386,12 +1393,12 @@ void NetworkShareTracker::OnPowerDisConnected() NETMGR_EXT_LOG_I("Power disConnected"); powerConnected_ = false; - unsigned int size = 0; - int32_t ret = GetStationNum(&size); - if (ret != WIFI_SUCCESS) { + size_t size = 0; + int32_t ret = GetStationNum(size); + if (ret != Wifi::WIFI_OPT_SUCCESS) { NETMGR_EXT_LOG_E("Get softap station num, ret:%{public}d", ret); } - NETMGR_EXT_LOG_I("Current connected station mum is:%{public}d", size); + NETMGR_EXT_LOG_I("Current connected station mum is:%{public}zu", size); staConnected_ = size != 0; NetworkShareTracker::GetInstance().HandleIdleApStopTimer(); #endif @@ -1400,14 +1407,17 @@ void NetworkShareTracker::OnPowerDisConnected() #ifdef WIFI_MODOULE void NetworkShareTracker::HandleHotSpotStarted() { - char tmpData[IFACENAME_LEN]; if (NetworkShareTracker::GetInstance().mApIfaceName_.empty()) { - if (ErrCode(GetApIfaceName(tmpData, IFACENAME_LEN)) != 0) { + std::string ifaceName = WIFI_AP_DEFAULT_IFACE_NAME; + auto WifiHostInstance = Wifi::WifiHotspot::GetInstance(WIFI_HOTSPOT_ABILITY_ID); + int32_t ret = -1; + if (WifiHostInstance != nullptr) { + ret = WifiHostInstance->GetApIfaceName(ifaceName); + } + if (ret != Wifi::WIFI_OPT_SUCCESS) { NETMGR_EXT_LOG_E("get AP ifcace name failed! use default value"); - NetworkShareTracker::GetInstance().mApIfaceName_ = WIFI_AP_DEFAULT_IFACE_NAME; - } else { - NetworkShareTracker::GetInstance().mApIfaceName_ = tmpData; } + NetworkShareTracker::GetInstance().mApIfaceName_ = ifaceName; } NetworkShareTracker::GetInstance().OnChangeSharingState(SharingIfaceType::SHARING_WIFI, true); NetworkShareTracker::GetInstance().EnableWifiSubStateMachine(); @@ -1450,12 +1460,12 @@ void NetworkShareTracker::HandleHotSpotStaLeave() NETMGR_EXT_LOG_I("Receive hotspot sta leave"); NetworkShareTracker::GetInstance().GetPowerConnected(); - unsigned int size = 0; - int32_t ret = GetStationNum(&size); - if (ret != WIFI_SUCCESS) { + size_t size = 0; + int32_t ret = GetStationNum(size); + if (ret != Wifi::WIFI_OPT_SUCCESS) { NETMGR_EXT_LOG_E("Get softap station num, ret:%{public}d", ret); } - NETMGR_EXT_LOG_I("Current connected station mum is:%{public}d", size); + NETMGR_EXT_LOG_I("Current connected station mum is:%{public}zu", size); staConnected_ = size != 0; NetworkShareTracker::GetInstance().HandleIdleApStopTimer(); } @@ -1482,21 +1492,6 @@ void NetworkShareTracker::HandleIdleApStopTimer() } } -static void IdleApStopTimer() -{ - NETMGR_EXT_LOG_I("Disable hotspot and push network share notification"); -#ifdef SHARE_NOTIFICATION_ENABLE - NetworkShareNotification::GetInstance().PublishNetworkShareNotification( - NotificationId::HOTSPOT_IDLE_NOTIFICATION_ID); -#endif - int32_t ret = DisableHotspot(); - if (ret != WIFI_SUCCESS) { - NETMGR_EXT_LOG_E("DisableHotspot error[%{public}d].", ret); - } else { - NETMGR_EXT_LOG_I("DisableHotspot successful."); - } -} - void NetworkShareTracker::StartIdleApStopTimer() { if (idleApStopTimerId_ != 0) { @@ -1505,7 +1500,15 @@ void NetworkShareTracker::StartIdleApStopTimer() } std::shared_ptr timer = std::make_shared(false, 0, false, false); - timer->SetCallbackInfo(IdleApStopTimer); + timer->SetCallbackInfo([this] { + NETMGR_EXT_LOG_I("Disable hotspot and push network share notification"); +#ifdef SHARE_NOTIFICATION_ENABLE + NetworkShareNotification::GetInstance().PublishNetworkShareNotification( + NotificationId::HOTSPOT_IDLE_NOTIFICATION_ID); +#endif + int32_t ret = DisableHotspot(); + NETMGR_EXT_LOG_E("DisableHotspot ret[%{public}d].", ret); + }); idleApStopTimerId_ = MiscServices::TimeServiceClient::GetInstance()->CreateTimer(timer); int64_t currentTime = MiscServices::TimeServiceClient::GetInstance()->GetBootTimeMs(); MiscServices::TimeServiceClient::GetInstance()->StartTimer(idleApStopTimerId_, @@ -1523,6 +1526,36 @@ void NetworkShareTracker::StopIdleApStopTimer() MiscServices::TimeServiceClient::GetInstance()->DestroyTimer(idleApStopTimerId_); idleApStopTimerId_ = 0; } + +int32_t NetworkShareTracker::EnableHotspot() +{ + auto WifiHostInstance = Wifi::WifiHotspot::GetInstance(WIFI_HOTSPOT_ABILITY_ID); + if (WifiHostInstance == nullptr) { + return -1; + } + return WifiHostInstance->EnableHotspot(); +} + +int32_t NetworkShareTracker::DisableHotspot() +{ + auto WifiHostInstance = Wifi::WifiHotspot::GetInstance(WIFI_HOTSPOT_ABILITY_ID); + if (WifiHostInstance == nullptr) { + return -1; + } + return WifiHostInstance->DisableHotspot(); +} + +int32_t NetworkShareTracker::GetStationNum(size_t &num) +{ + auto WifiHostInstance = Wifi::WifiHotspot::GetInstance(WIFI_HOTSPOT_ABILITY_ID); + if (WifiHostInstance == nullptr) { + return -1; + } + std::vector stationInfos; + int32_t ret = WifiHostInstance->GetStationList(stationInfos); + num = stationInfos.size(); + return ret; +} #endif } // namespace NetManagerStandard } // namespace OHOS diff --git a/test/networksharemanager/fuzztest/netshareclient_fuzzer/BUILD.gn b/test/networksharemanager/fuzztest/netshareclient_fuzzer/BUILD.gn index c315ef46b97caebe930e5b49f10654017b9cc166..6d18a97bdc827499e36e1500385dba959521c3f4 100644 --- a/test/networksharemanager/fuzztest/netshareclient_fuzzer/BUILD.gn +++ b/test/networksharemanager/fuzztest/netshareclient_fuzzer/BUILD.gn @@ -37,13 +37,6 @@ ohos_fuzztest("NetShareClientFuzzTest") { "$NETWORKSHAREMANAGER_UTILS_DIR/event_report/include", ] - if (communication_wifi_switch_enable) { - include_dirs += [ - "$WIFI_MANAGER_ROOT/interfaces/kits/c", - "$WIFI_MANAGER_ROOT/frameworks/native/interfaces", - ] - } - cflags = [ "-g", "-O0", diff --git a/test/networksharemanager/fuzztest/netshareclient_fuzzer/netshare_client_fuzzer.cpp b/test/networksharemanager/fuzztest/netshareclient_fuzzer/netshare_client_fuzzer.cpp index 0da8e0d169fe24cf607cf2501f6069541e64bb44..f3295da963a924d5917f54a05f4973aafc0550f6 100644 --- a/test/networksharemanager/fuzztest/netshareclient_fuzzer/netshare_client_fuzzer.cpp +++ b/test/networksharemanager/fuzztest/netshareclient_fuzzer/netshare_client_fuzzer.cpp @@ -541,7 +541,9 @@ void NetworkShareTrackerFuzzTest(const uint8_t *data, size_t size) std::vector ifaceRegexs; std::vector ifaces; int32_t kbByte = 0; + auto wifiHotspotCallback = sptr::MakeSptr(); NetworkShareTracker::GetInstance().Uninit(); + wifiHotspotCallback->OnHotspotStateChanged(num); NetworkShareTracker::GetInstance().IsNetworkSharingSupported(supported); NetworkShareTracker::GetInstance().IsSharing(sharingStatus); NetworkShareTracker::GetInstance().StartNetworkSharing(ifaceType); @@ -613,9 +615,9 @@ void NetworkShareTrackerPrivateFuzzTest(const uint8_t *data, size_t size) tra.SetDnsForwarders(*netHandle); tra.StopDnsProxy(); tra.SubSmStateToExportState(num); - tra.RegisterWifiApCallback(); tra.RegisterBtPanCallback(); #ifdef WIFI_MODOULE + tra.RegisterWifiApCallback(); tra.SetWifiState(Wifi::ApState(num % ENUM_TYPE_VALUE6)); #endif #ifdef BLUETOOTH_MODOULE diff --git a/test/networksharemanager/unittest/networkshare_manager_test/BUILD.gn b/test/networksharemanager/unittest/networkshare_manager_test/BUILD.gn index 25a8d9a21517d3312f6d7dd46cc44b6964bf6538..66e988b6b2e904f9851f85e395a24e9abc8e080c 100644 --- a/test/networksharemanager/unittest/networkshare_manager_test/BUILD.gn +++ b/test/networksharemanager/unittest/networkshare_manager_test/BUILD.gn @@ -67,10 +67,6 @@ ohos_unittest("networkshare_manager_test") { defines = [] if (communication_wifi_switch_enable) { defines += [ "WIFI_MODOULE" ] - include_dirs += [ - "$WIFI_MANAGER_ROOT/interfaces/kits/c", - "$WIFI_MANAGER_ROOT/frameworks/native/interfaces", - ] } if (communication_bluetooth_switch_enable) { defines += [ "BLUETOOTH_MODOULE" ] diff --git a/test/networksharemanager/unittest/networkshare_manager_test/networkshare_sub_statemachine_test.cpp b/test/networksharemanager/unittest/networkshare_manager_test/networkshare_sub_statemachine_test.cpp index f2dfa51a53b0df281575daed1a3eb9a9af4a67e5..b328e6f8d236dc74d914583ae353a847f40af73d 100644 --- a/test/networksharemanager/unittest/networkshare_manager_test/networkshare_sub_statemachine_test.cpp +++ b/test/networksharemanager/unittest/networkshare_manager_test/networkshare_sub_statemachine_test.cpp @@ -404,6 +404,25 @@ HWTEST_F(NetworkShareSubStateMachineTest, HandleConnectionChanged003, TestSize.L networkShareSubStateMachine->HandleConnectionChanged(upstreamNetInfo); } +/** + * @tc.name: HandleConnectionChanged004 + * @tc.desc: Test NetworkShareSubStateMachine HandleConnectionChanged. + * @tc.type: FUNC + */ +HWTEST_F(NetworkShareSubStateMachineTest, HandleConnectionChanged004, TestSize.Level1) +{ + auto configuration = std::make_shared(); + auto networkShareSubStateMachine = std::make_shared( + WIFI_AP_DEFAULT_IFACE_NAME, SharingIfaceType::SHARING_WIFI, configuration); + sptr handle = nullptr; + sptr netcap = new (std::nothrow) NetManagerStandard::NetAllCapabilities(); + sptr link = new (std::nothrow) NetManagerStandard::NetLinkInfo(); + auto upstreamNetInfo = std::make_shared(handle, netcap, link); + networkShareSubStateMachine->upstreamIfaceName_ = "test0"; + upstreamNetInfo->netLinkPro_->ifaceName_ = "test1"; + EXPECT_TRUE(networkShareSubStateMachine->HasChangeUpstreamIfaceSet(upstreamNetInfo->netLinkPro_->ifaceName_)); +} + /** * @tc.name: AddRoutesToLocalNetwork001 * @tc.desc: Test NetworkShareSubStateMachine AddRoutesToLocalNetwork. diff --git a/test/networksharemanager/unittest/networkshare_manager_test/networkshare_tracker_test.cpp b/test/networksharemanager/unittest/networkshare_manager_test/networkshare_tracker_test.cpp index 246e23376ba0de9a6c964ffe76c6b7566ae31297..edbba3decf1235deba7648f522b31e674768cf8e 100644 --- a/test/networksharemanager/unittest/networkshare_manager_test/networkshare_tracker_test.cpp +++ b/test/networksharemanager/unittest/networkshare_manager_test/networkshare_tracker_test.cpp @@ -549,23 +549,24 @@ HWTEST_F(NetworkShareTrackerTest, GetSharedSubSMTraffic03, TestSize.Level1) HWTEST_F(NetworkShareTrackerTest, OnWifiHotspotStateChanged01, TestSize.Level1) { int32_t state = 2; - NetworkShareTracker::GetInstance().OnWifiHotspotStateChanged(state); + auto wifiHotspotCallback = sptr::MakeSptr(); + wifiHotspotCallback->OnHotspotStateChanged(state); EXPECT_EQ(NetworkShareTracker::GetInstance().curWifiState_, Wifi::ApState::AP_STATE_STARTING); state = 3; - NetworkShareTracker::GetInstance().OnWifiHotspotStateChanged(state); + wifiHotspotCallback->OnHotspotStateChanged(state); EXPECT_EQ(NetworkShareTracker::GetInstance().curWifiState_, Wifi::ApState::AP_STATE_STARTED); state = 4; - NetworkShareTracker::GetInstance().OnWifiHotspotStateChanged(state); + wifiHotspotCallback->OnHotspotStateChanged(state); EXPECT_EQ(NetworkShareTracker::GetInstance().curWifiState_, Wifi::ApState::AP_STATE_CLOSING); state = 5; - NetworkShareTracker::GetInstance().OnWifiHotspotStateChanged(state); + wifiHotspotCallback->OnHotspotStateChanged(state); EXPECT_EQ(NetworkShareTracker::GetInstance().curWifiState_, Wifi::ApState::AP_STATE_CLOSED); state = 0; - NetworkShareTracker::GetInstance().OnWifiHotspotStateChanged(state); + wifiHotspotCallback->OnHotspotStateChanged(state); EXPECT_EQ(NetworkShareTracker::GetInstance().curWifiState_, Wifi::ApState::AP_STATE_NONE); } #endif @@ -800,19 +801,21 @@ HWTEST_F(NetworkShareTrackerTest, HandleIdleApStopTimerTest, TestSize.Level1) HWTEST_F(NetworkShareTrackerTest, OnWifiHotspotStaJoinTest, TestSize.Level1) { - StationInfo sta{}; - NetworkShareTracker::GetInstance().OnWifiHotspotStaJoin(&sta); + Wifi::StationInfo sta{}; + auto wifiHotspotCallback = sptr::MakeSptr(); + wifiHotspotCallback->OnHotspotStaJoin(sta); EXPECT_EQ(NetworkShareTracker::GetInstance().staConnected_, true); EXPECT_EQ(NetworkShareTracker::GetInstance().idleApStopTimerId_, 0); } HWTEST_F(NetworkShareTrackerTest, OnWifiHotspotStaLeaveTest, TestSize.Level1) { - StationInfo sta{}; + Wifi::StationInfo sta{}; + auto wifiHotspotCallback = sptr::MakeSptr(); NetworkShareTracker::GetInstance().powerConnected_ = true; NetworkShareTracker::GetInstance().staConnected_ = true; NetworkShareTracker::GetInstance().curWifiState_ = Wifi::ApState::AP_STATE_STARTED; - NetworkShareTracker::GetInstance().OnWifiHotspotStaLeave(&sta); + wifiHotspotCallback->OnHotspotStaLeave(sta); EXPECT_EQ(NetworkShareTracker::GetInstance().idleApStopTimerId_, 0); }