diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_pro/wifi_pro_state_machine.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_pro/wifi_pro_state_machine.cpp index 8e41067deca9814787dc38ca31027ddbcc92c29b..74a31f5257b2a892255c9ea573e50f8a4fca9163 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_pro/wifi_pro_state_machine.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_pro/wifi_pro_state_machine.cpp @@ -542,6 +542,23 @@ bool WifiProStateMachine::IsAllowScan(bool hasSwitchRecord) } return true; } + +bool WifiProStateMachine::IsFirstConnectAndNonet() +{ + WifiLinkedInfo linkedInfo; + WifiConfigCenter::GetInstance().GetLinkedInfo(linkedInfo); + if (linkedInfo.networkId == INVALID_NETWORK_ID) { + WIFI_LOGE("IsFirstConnectAndNonet: current state : disconnected."); + return true; + } + WifiDeviceConfig config; + if (WifiSettings::GetInstance().GetDeviceConfig(linkedInfo.networkId, config) != 0) { + WIFI_LOGE("IsFirstConnectAndNonet: Failed to get device config."); + return true; + } + return currentState_ == WifiProState::WIFI_NONET && WifiProUtils::IsUserSelectNetwork() && + config.numAssociation <= 1; +} /* --------------------------- state machine default state ------------------------------ */ WifiProStateMachine::DefaultState::DefaultState(WifiProStateMachine *pWifiProStateMachine) : State("DefaultState"), @@ -1280,6 +1297,10 @@ void WifiProStateMachine::WifiNoNetState::HandleWifiNoInternet(const InternalMes return; } WIFI_LOGI("NoInternet X: select network fail."); + if (pWifiProStateMachine_->IsFirstConnectAndNonet()) { + WIFI_LOGI("user select and nonet, not selfcure."); + return; + } if (pWifiProStateMachine_->TrySelfCure(false)) { pWifiProStateMachine_->Wifi2WifiFinish(); } @@ -1288,6 +1309,10 @@ void WifiProStateMachine::WifiNoNetState::HandleWifiNoInternet(const InternalMes WIFI_LOGI("NoNetSwitch 2: receive good ap."); if (!pWifiProStateMachine_->IsSatisfiedWifi2WifiCondition()) { + if (pWifiProStateMachine_->IsFirstConnectAndNonet()) { + WIFI_LOGI("user select and nonet, not selfcure."); + return; + } if (pWifiProStateMachine_->TrySelfCure(false)) { pWifiProStateMachine_->Wifi2WifiFinish(); } diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_pro/wifi_pro_state_machine.h b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_pro/wifi_pro_state_machine.h index 407af5894a71fb6fb559501823fa2cb8c30dab23..8f53b25b3d9ec8c972ea8b683fc06ed5c9febacf 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_pro/wifi_pro_state_machine.h +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_pro/wifi_pro_state_machine.h @@ -262,6 +262,7 @@ private: void ProcessSwitchResult(const InternalMessagePtr msg); bool InLandscapeSwitchLimitList(); bool IsAllowScan(bool hasSwitchRecord); + bool IsFirstConnectAndNonet(); }; } // namespace Wifi } // namespace OHOS diff --git a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_pro/wifi_pro_state_machine_test.cpp b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_pro/wifi_pro_state_machine_test.cpp index a3fc47b4fd81377f2094c7c8469946582a4550eb..1da04ea738244b652afd8ec25667179fcf8c4f82 100644 --- a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_pro/wifi_pro_state_machine_test.cpp +++ b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_pro/wifi_pro_state_machine_test.cpp @@ -310,6 +310,12 @@ HWTEST_F(WifiProStateMachineTest, TryNoNetSwitchTest, TestSize.Level1) EXPECT_NE(pWifiProStateMachine_->wifiSwitchReason_, TEN); } +HWTEST_F(WifiProStateMachineTest, IsFirstConnectAndNonetTest01, TestSize.Level1) +{ + pWifiProStateMachine_->currentState_ = WifiProState::WIFI_HASNET; + EXPECT_EQ(pWifiProStateMachine_->IsFirstConnectAndNonet(), false); +} + HWTEST_F(WifiProStateMachineTest, WifiProEnableStateTransitionNetStateTest01, TestSize.Level1) { wifiProEnableState_->pWifiProStateMachine_ = new WifiProStateMachine();