From 39c18a795d101e234174a78cc6a1e304dfe3412b Mon Sep 17 00:00:00 2001 From: yangpengfei Date: Tue, 19 Nov 2024 13:36:40 +0000 Subject: [PATCH] update Signed-off-by: yangpengfei --- .../network_select/network_selector_impl.h | 8 ++++++++ .../wifi_manage/wifi_sta/sta_service.cpp | 9 ++++----- .../wifi_manage/wifi_sta/sta_service_test.cpp | 19 +++++++++---------- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/network_select/network_selector_impl.h b/wifi/services/wifi_standard/wifi_framework/wifi_manage/network_select/network_selector_impl.h index 558d9b518..cf40ea0f2 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/network_select/network_selector_impl.h +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/network_select/network_selector_impl.h @@ -45,6 +45,14 @@ protected: void GetCandidatesFromSubNetworkSelector() override; }; +class SuggestionNetworkTracker final: public CompositeNetworkSelector { +public: + SuggestionNetworkTracker(); +protected: + bool Nominate(NetworkCandidate &networkCandidate) override; + void GetCandidatesFromSubNetworkSelector() override; +}; + class SimpleFilterNetworkSelector : public SimpleNetworkSelector, public SimpleWifiFilter { public: explicit SimpleFilterNetworkSelector(const std::string &networkSelectorName); diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_service.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_service.cpp index b5d28039a..fadf66193 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_service.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_service.cpp @@ -32,6 +32,7 @@ #include "wifi_config_center.h" #include "external_wifi_filter_builder_manager.h" #include "external_wifi_common_builder_manager.h" +#include "block_connect_service.h" DEFINE_WIFILOG_LABEL("StaService"); @@ -640,12 +641,10 @@ ErrCode StaService::EnableDeviceConfig(int networkId, bool attemptEnable) const WIFI_LOGI("Enter EnableDeviceConfig, networkid is %{public}d", networkId); /* Update wifi status. */ - if (WifiSettings::GetInstance().SetDeviceState(networkId, (int)WifiDeviceConfigStatus::ENABLED, attemptEnable) < - 0) { + if (!BlockConnectService::GetInstance().EnableNetworkSelectStatus(networkId)) { WIFI_LOGE("Enable device config failed!"); return WIFI_OPT_FAILED; } - WifiSettings::GetInstance().SyncDeviceConfig(); return WIFI_OPT_SUCCESS; } @@ -653,11 +652,11 @@ ErrCode StaService::DisableDeviceConfig(int networkId) const { WIFI_LOGI("Enter DisableDeviceConfig, networkid is %{public}d", networkId); - if (WifiSettings::GetInstance().SetDeviceState(networkId, (int)WifiDeviceConfigStatus::DISABLED) < 0) { + if (!BlockConnectService::GetInstance().UpdateNetworkSelectStatus(networkId, + DisabledReason::DISABLED_BY_WIFI_MANAGER)) { WIFI_LOGE("Disable device config failed!"); return WIFI_OPT_FAILED; } - WifiSettings::GetInstance().SyncDeviceConfig(); return WIFI_OPT_SUCCESS; } diff --git a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_service_test.cpp b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_service_test.cpp index a5f7a3a64..3b7142ad0 100644 --- a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_service_test.cpp +++ b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_service_test.cpp @@ -24,6 +24,7 @@ #include "wifi_msg.h" #include "wifi_internal_msg.h" #include "wifi_error_no.h" +#include "mock_block_connect_service.h" using ::testing::_; using ::testing::AtLeast; @@ -397,9 +398,8 @@ void StaServiceTest::StaServiceEnableDeviceConfigSuccess() { int networkId = NETWORK_ID; bool attemptEnable = true; - EXPECT_CALL(WifiSettings::GetInstance(), - SetDeviceState(networkId, (int)WifiDeviceConfigStatus::ENABLED, attemptEnable)) - .WillRepeatedly(Return(0)); + EXPECT_CALL(BlockConnectService::GetInstance(), + EnableNetworkSelectStatus(networkId)).WillRepeatedly(Return(0)); EXPECT_TRUE(pStaService->EnableDeviceConfig(networkId, attemptEnable) == WIFI_OPT_SUCCESS); } @@ -407,9 +407,8 @@ void StaServiceTest::StaServiceEnableDeviceConfigFail1() { int networkId = NETWORK_ID; bool attemptEnable = true; - EXPECT_CALL(WifiSettings::GetInstance(), - SetDeviceState(networkId, (int)WifiDeviceConfigStatus::ENABLED, attemptEnable)) - .WillRepeatedly(Return(-1)); + EXPECT_CALL(BlockConnectService::GetInstance(), + EnableNetworkSelectStatus(networkId)).WillRepeatedly(Return(-1)); EXPECT_TRUE(pStaService->EnableDeviceConfig(networkId, attemptEnable) == WIFI_OPT_FAILED); } @@ -424,8 +423,8 @@ void StaServiceTest::StaServiceDisableDeviceConfigSuccess() { int networkId = NETWORK_ID; bool attemptEnable = false; - EXPECT_CALL(WifiSettings::GetInstance(), - SetDeviceState(networkId, (int)WifiDeviceConfigStatus::DISABLED, attemptEnable)) + EXPECT_CALL(BlockConnectService::GetInstance(), + UpdateNetworkSelectStatus(networkId, DisabledReason::DISABLED_BY_WIFI_MANAGER)) .WillRepeatedly(Return(0)); EXPECT_TRUE(pStaService->DisableDeviceConfig(networkId) == WIFI_OPT_SUCCESS); } @@ -434,8 +433,8 @@ void StaServiceTest::StaServiceDisableDeviceConfigFail1() { int networkId = NETWORK_ID; bool attemptEnable = false; - EXPECT_CALL(WifiSettings::GetInstance(), - SetDeviceState(networkId, (int)WifiDeviceConfigStatus::DISABLED, attemptEnable)) + EXPECT_CALL(BlockConnectService::GetInstance(), + UpdateNetworkSelectStatus(networkId, DisabledReason::DISABLED_BY_WIFI_MANAGER)) .WillRepeatedly(Return(-1)); EXPECT_TRUE(pStaService->DisableDeviceConfig(networkId) == WIFI_OPT_FAILED); }