mirror of
https://gitee.com/openharmony/communication_wifi.git
synced 2024-11-27 01:01:03 +00:00
commit
658f558063
@ -72,16 +72,29 @@ void NetworkSelectionManager::GetAllDeviceConfigs(std::vector<NetworkSelection::
|
||||
const std::vector<InterScanInfo> &scanInfos)
|
||||
{
|
||||
std::map<int, std::size_t> wifiDeviceConfigs;
|
||||
std::map<int, std::size_t> wifiCandidateConfigs;
|
||||
for (auto &scanInfo : scanInfos) {
|
||||
auto& networkCandidate = networkCandidates.emplace_back(scanInfo);
|
||||
std::string deviceKeyMgmt;
|
||||
scanInfo.GetDeviceMgmt(deviceKeyMgmt);
|
||||
WifiSettings::GetInstance().GetDeviceConfig(scanInfo.ssid, deviceKeyMgmt, networkCandidate.wifiDeviceConfig);
|
||||
|
||||
// save the indexes of saved network candidate in networkCandidates;
|
||||
if (networkCandidates.back().wifiDeviceConfig.networkId != INVALID_NETWORK_ID) {
|
||||
wifiDeviceConfigs.insert({networkCandidate.wifiDeviceConfig.networkId, networkCandidates.size() - 1});
|
||||
continue;
|
||||
}
|
||||
|
||||
// add suggesion network
|
||||
WifiSettings::GetInstance().GetCandidateConfigWithoutUid(scanInfo.ssid, deviceKeyMgmt,
|
||||
networkCandidate.wifiDeviceConfig);
|
||||
if (networkCandidates.back().wifiDeviceConfig.networkId != INVALID_NETWORK_ID &&
|
||||
networkCandidates.back().wifiDeviceConfig.uid != WIFI_INVALID_UID &&
|
||||
networkCandidates.back().wifiDeviceConfig.isShared == false) {
|
||||
wifiCandidateConfigs.insert({networkCandidate.wifiDeviceConfig.networkId, networkCandidates.size() - 1});
|
||||
}
|
||||
}
|
||||
|
||||
std::stringstream wifiDevicesInfo;
|
||||
for (auto &pair: wifiDeviceConfigs) {
|
||||
if (wifiDevicesInfo.rdbuf() ->in_avail() != 0) {
|
||||
@ -91,6 +104,16 @@ void NetworkSelectionManager::GetAllDeviceConfigs(std::vector<NetworkSelection::
|
||||
SsidAnonymize(networkCandidates.at(pair.second).wifiDeviceConfig.ssid) << "\"";
|
||||
}
|
||||
WIFI_LOGI("Find savedNetworks in scanInfos: [%{public}s]", wifiDevicesInfo.str().c_str());
|
||||
|
||||
std::stringstream wifiCandidateInfos;
|
||||
for (auto &pair: wifiCandidateConfigs) {
|
||||
if (wifiCandidateInfos.rdbuf() ->in_avail() != 0) {
|
||||
wifiCandidateInfos << ",";
|
||||
}
|
||||
wifiCandidateInfos << "\"" << pair.first << "_" <<
|
||||
SsidAnonymize(networkCandidates.at(pair.second).wifiDeviceConfig.ssid) << "\"";
|
||||
}
|
||||
WIFI_LOGI("Find suggestion networks in scanInfos: [%{public}s]", wifiCandidateInfos.str().c_str());
|
||||
}
|
||||
|
||||
void NetworkSelectionManager::TryNominate(std::vector<NetworkSelection::NetworkCandidate> &networkCandidates,
|
||||
|
@ -48,6 +48,7 @@ AutoConnectIntegrator::AutoConnectIntegrator() : CompositeNetworkSelector(
|
||||
}
|
||||
SetWifiFilter(filters);
|
||||
AddSubNetworkSelector(make_shared<SavedNetworkTracker>());
|
||||
AddSubNetworkSelector(make_shared<SuggestionNetworkTracker>());
|
||||
auto comparator = make_shared<WifiScorerComparator>(m_networkSelectorName);
|
||||
comparator->AddScorer(make_shared<ThroughputScorer>());
|
||||
SetWifiComparator(comparator);
|
||||
@ -156,6 +157,14 @@ void SavedNetworkTracker::GetCandidatesFromSubNetworkSelector()
|
||||
}
|
||||
}
|
||||
|
||||
SuggestionNetworkTracker::SuggestionNetworkTracker() : SimpleNetworkSelector("suggestionNetworkTracker")
|
||||
{
|
||||
auto andFilter = make_shared<AndWifiFilter>();
|
||||
andFilter->AddFilter(make_shared<SuggestionNetworkWifiFilter>());
|
||||
andFilter->AddFilter(make_shared<DisableWifiFilter>());
|
||||
SetWifiFilter(andFilter);
|
||||
}
|
||||
|
||||
SimpleFilterNetworkSelector::SimpleFilterNetworkSelector(const std::string &networkSelectorName)
|
||||
: SimpleNetworkSelector(networkSelectorName), SimpleWifiFilter(networkSelectorName) {}
|
||||
|
||||
|
@ -45,6 +45,11 @@ protected:
|
||||
void GetCandidatesFromSubNetworkSelector() override;
|
||||
};
|
||||
|
||||
class SuggestionNetworkTracker final: public SimpleNetworkSelector {
|
||||
public:
|
||||
SuggestionNetworkTracker();
|
||||
};
|
||||
|
||||
class SimpleFilterNetworkSelector : public SimpleNetworkSelector, public SimpleWifiFilter {
|
||||
public:
|
||||
explicit SimpleFilterNetworkSelector(const std::string &networkSelectorName);
|
||||
|
@ -87,7 +87,8 @@ SavedWifiFilter::~SavedWifiFilter()
|
||||
|
||||
bool SavedWifiFilter::Filter(NetworkCandidate &networkCandidate)
|
||||
{
|
||||
return networkCandidate.wifiDeviceConfig.networkId != INVALID_NETWORK_ID;
|
||||
return networkCandidate.wifiDeviceConfig.networkId != INVALID_NETWORK_ID &&
|
||||
(networkCandidate.wifiDeviceConfig.uid == -1 || networkCandidate.wifiDeviceConfig.isShared == true);
|
||||
}
|
||||
|
||||
|
||||
@ -569,4 +570,21 @@ bool WifiSwitchThresholdFilter::Filter(NetworkCandidate &networkCandidate)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
SuggestionNetworkWifiFilter::SuggestionNetworkWifiFilter() : SimpleWifiFilter("suggestionNetworkWifiFilter") {}
|
||||
|
||||
SuggestionNetworkWifiFilter::~SuggestionNetworkWifiFilter()
|
||||
{
|
||||
if (!filteredNetworkCandidates.empty()) {
|
||||
WIFI_LOGI("filteredNetworkCandidates in %{public}s: %{public}s",
|
||||
filterName.c_str(),
|
||||
NetworkSelectionUtils::GetNetworkCandidatesInfo(filteredNetworkCandidates).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
bool SuggestionNetworkWifiFilter::Filter(NetworkCandidate &networkCandidate)
|
||||
{
|
||||
return networkCandidate.wifiDeviceConfig.uid != WIFI_INVALID_UID &&
|
||||
networkCandidate.wifiDeviceConfig.isShared == false;
|
||||
}
|
||||
}
|
@ -187,5 +187,13 @@ public:
|
||||
protected:
|
||||
bool Filter(NetworkCandidate &networkCandidate) override;
|
||||
};
|
||||
|
||||
class SuggestionNetworkWifiFilter final : public SimpleWifiFilter {
|
||||
public:
|
||||
SuggestionNetworkWifiFilter();
|
||||
~SuggestionNetworkWifiFilter() override;
|
||||
protected:
|
||||
bool Filter(NetworkCandidate &networkCandidate) override;
|
||||
};
|
||||
}
|
||||
#endif //OHOS_WIFI_WIFI_FILTER_H
|
||||
|
@ -28,6 +28,7 @@ constexpr int SUFFICIENT_RSSI_2G = -73;
|
||||
constexpr int RSSI_SCORE_OFFSET = 85;
|
||||
constexpr int RSSI_SCORE_SLOPE_IS_4 = 4;
|
||||
constexpr int TOP_TIME_BASE_SCORE = 1000000;
|
||||
constexpr int BOTTOM_TIME_BASE_SCORE = -1000000;
|
||||
constexpr int MAX_RECENT_SELECTION_SECONDS = 8 * 60 * 60;
|
||||
constexpr int MIN_5G_FREQUENCY = 5160;
|
||||
constexpr int MAX_5G_FREQUENCY = 5865;
|
||||
@ -127,17 +128,25 @@ bool ThroughputScorer::IsSecurityNetwork(NetworkCandidate &networkCandidate) con
|
||||
|
||||
void ThroughputScorer::DoScore(NetworkCandidate &networkCandidate, ScoreResult &scoreResult)
|
||||
{
|
||||
scoreResult.scorerName = "ThroughputScorer";
|
||||
double rssiBaseScore = GetRssiBaseScore(networkCandidate);
|
||||
double savedNetworkAward = GetSavedNetworkAward(networkCandidate);
|
||||
scoreResult.scorerName = "ThroughputScorer";
|
||||
if (IsRecentUserSelected(networkCandidate)) {
|
||||
scoreResult.score = TOP_TIME_BASE_SCORE + rssiBaseScore + savedNetworkAward;
|
||||
return;
|
||||
}
|
||||
scoreResult.score = rssiBaseScore + savedNetworkAward;
|
||||
if (IsSecurityNetwork(networkCandidate)) {
|
||||
scoreResult.score += SECURITY_AWARD_SCORE;
|
||||
}
|
||||
|
||||
// It is suggestion network that the network priority be very low.
|
||||
if (networkCandidate.wifiDeviceConfig.uid != -1 &&
|
||||
networkCandidate.wifiDeviceConfig.isShared == 0) {
|
||||
scoreResult.score += BOTTOM_TIME_BASE_SCORE;
|
||||
return;
|
||||
}
|
||||
|
||||
if (IsRecentUserSelected(networkCandidate)) {
|
||||
scoreResult.score = TOP_TIME_BASE_SCORE + rssiBaseScore + savedNetworkAward;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
SecurityBonusScorer::SecurityBonusScorer() : SimpleWifiScorer("securityScore") {}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -1207,7 +1207,7 @@ void StaStateMachine::DealConnectToUserSelectedNetwork(InternalMessagePtr msg)
|
||||
}
|
||||
SetConnectMethod(connTriggerMode);
|
||||
WifiConfigCenter::GetInstance().EnableNetwork(networkId, connTriggerMode == NETWORK_SELECTED_BY_USER, m_instId);
|
||||
WifiSettings::GetInstance().SetDeviceState(networkId, (int)WifiDeviceConfigStatus::ENABLED, false);
|
||||
BlockConnectService::GetInstance().EnableNetworkSelectStatus(networkId);
|
||||
}
|
||||
|
||||
void StaStateMachine::DealConnectTimeOutCmd(InternalMessagePtr msg)
|
||||
@ -3644,8 +3644,7 @@ void StaStateMachine::LinkedState::GoInState()
|
||||
#endif
|
||||
}
|
||||
WifiSettings::GetInstance().SetDeviceAfterConnect(pStaStateMachine->linkedInfo.networkId);
|
||||
WifiSettings::GetInstance().SetDeviceState(pStaStateMachine->linkedInfo.networkId,
|
||||
static_cast<int32_t>(WifiDeviceConfigStatus::ENABLED), false);
|
||||
BlockConnectService::GetInstance().EnableNetworkSelectStatus(pStaStateMachine->linkedInfo.networkId);
|
||||
WifiSettings::GetInstance().SyncDeviceConfig();
|
||||
pStaStateMachine->SaveDiscReason(DisconnectedReason::DISC_REASON_DEFAULT);
|
||||
pStaStateMachine->SaveLinkstate(ConnState::CONNECTED, DetailedState::CONNECTED);
|
||||
|
@ -43,6 +43,7 @@
|
||||
#include "wifi_sta_hal_interface.h"
|
||||
#include "wifi_randommac_helper.h"
|
||||
#include "wifi_sta_hal_interface.h"
|
||||
#include "block_connect_service.h"
|
||||
|
||||
DEFINE_WIFILOG_LABEL("WifiDeviceServiceImpl");
|
||||
namespace OHOS {
|
||||
@ -948,7 +949,7 @@ ErrCode WifiDeviceServiceImpl::ConnectToNetwork(int networkId, bool isCandidate)
|
||||
}
|
||||
}
|
||||
WifiSettings::GetInstance().SetDeviceEphemeral(networkId, false);
|
||||
WifiSettings::GetInstance().SetDeviceState(networkId, static_cast<int>(WifiDeviceConfigStatus::ENABLED), false);
|
||||
BlockConnectService::GetInstance().EnableNetworkSelectStatus(networkId);
|
||||
WifiLinkedInfo linkedInfo;
|
||||
WifiConfigCenter::GetInstance().GetLinkedInfo(linkedInfo, m_instId);
|
||||
if (linkedInfo.connState == ConnState::CONNECTING || linkedInfo.connState == ConnState::CONNECTED) {
|
||||
|
@ -279,27 +279,6 @@ int WifiSettings::GetDeviceConfig(const std::string &ssid, const std::string &ke
|
||||
return -1;
|
||||
}
|
||||
|
||||
int WifiSettings::SetDeviceState(int networkId, int state, bool bSetOther)
|
||||
{
|
||||
if (state < 0 || state >= (int)WifiDeviceConfigStatus::UNKNOWN) {
|
||||
return -1;
|
||||
}
|
||||
std::unique_lock<std::mutex> lock(mStaMutex);
|
||||
auto iter = mWifiDeviceConfig.find(networkId);
|
||||
if (iter == mWifiDeviceConfig.end()) {
|
||||
return -1;
|
||||
}
|
||||
iter->second.status = state;
|
||||
if (bSetOther && state == (int)WifiDeviceConfigStatus::ENABLED) {
|
||||
for (iter = mWifiDeviceConfig.begin(); iter != mWifiDeviceConfig.end(); ++iter) {
|
||||
if (iter->first != networkId && iter->second.status == state) {
|
||||
iter->second.status = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int WifiSettings::SetDeviceEphemeral(int networkId, bool isEphemeral)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mStaMutex);
|
||||
@ -379,6 +358,23 @@ bool WifiSettings::GetAcceptUnvalidated(int networkId)
|
||||
return iter->second.acceptUnvalidated;
|
||||
}
|
||||
|
||||
int WifiSettings::GetCandidateConfigWithoutUid(const std::string &ssid, const std::string &keymgmt,
|
||||
WifiDeviceConfig &config)
|
||||
{
|
||||
std::vector<WifiDeviceConfig> configs;
|
||||
if (GetAllCandidateConfigWithoutUid(configs) != 0) {
|
||||
return -1;
|
||||
}
|
||||
for (const auto &it : configs) {
|
||||
// -1: Connect by system, use default uid.
|
||||
if (it.uid != -1 && !(it.isShared) && it.ssid == ssid && it.keyMgmt == keymgmt) {
|
||||
config = it;
|
||||
return it.networkId;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int WifiSettings::GetCandidateConfig(const int uid, const std::string &ssid, const std::string &keymgmt,
|
||||
WifiDeviceConfig &config)
|
||||
{
|
||||
@ -412,6 +408,24 @@ int WifiSettings::GetCandidateConfig(const int uid, const int &networkId, WifiDe
|
||||
return -1;
|
||||
}
|
||||
|
||||
int WifiSettings::GetAllCandidateConfigWithoutUid(std::vector<WifiDeviceConfig> &configs)
|
||||
{
|
||||
if (!deviceConfigLoadFlag.test_and_set()) {
|
||||
LOGD("Reload wifi config");
|
||||
ReloadDeviceConfig();
|
||||
}
|
||||
|
||||
std::unique_lock<std::mutex> lock(mStaMutex);
|
||||
bool found = false;
|
||||
for (auto iter = mWifiDeviceConfig.begin(); iter != mWifiDeviceConfig.end(); iter++) {
|
||||
if (iter->second.uid != -1 && !iter->second.isShared) {
|
||||
configs.push_back(iter->second);
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
return found ? 0 : -1;
|
||||
}
|
||||
|
||||
int WifiSettings::GetAllCandidateConfig(const int uid, std::vector<WifiDeviceConfig> &configs)
|
||||
{
|
||||
if (!deviceConfigLoadFlag.test_and_set()) {
|
||||
|
@ -122,8 +122,6 @@ public:
|
||||
|
||||
int GetDeviceConfig(const std::string &ssid, const std::string &keymgmt, WifiDeviceConfig &config, int instId = 0);
|
||||
|
||||
int SetDeviceState(int networkId, int state, bool bSetOther = false);
|
||||
|
||||
int SetDeviceEphemeral(int networkId, bool isEphemeral);
|
||||
|
||||
int SetDeviceAfterConnect(int networkId);
|
||||
@ -138,6 +136,9 @@ public:
|
||||
|
||||
bool GetAcceptUnvalidated(int networkId);
|
||||
|
||||
int GetCandidateConfigWithoutUid(const std::string &ssid, const std::string &keymgmt,
|
||||
WifiDeviceConfig &config);
|
||||
|
||||
int GetCandidateConfig(const int uid, const std::string &ssid, const std::string &keymgmt,
|
||||
WifiDeviceConfig &config);
|
||||
|
||||
@ -322,6 +323,7 @@ private:
|
||||
bool EncryptionWapiConfig(const WifiEncryptionInfo &wifiEncryptionInfo, WifiDeviceConfig &config) const;
|
||||
#endif
|
||||
void SyncAfterDecryped(WifiDeviceConfig &config);
|
||||
int GetAllCandidateConfigWithoutUid(std::vector<WifiDeviceConfig> &configs);
|
||||
private:
|
||||
// STA
|
||||
std::mutex mStaMutex;
|
||||
|
@ -250,11 +250,11 @@
|
||||
"OHOS::Wifi::WifiSettings::AddDeviceConfig(OHOS::Wifi::WifiDeviceConfig const&)";
|
||||
"OHOS::Wifi::WifiSettings::RemoveDevice(int)";
|
||||
"OHOS::Wifi::WifiSettings::ClearDeviceConfig()";
|
||||
"OHOS::Wifi::WifiSettings::GetCandidateConfigWithoutUid(std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>> const&, std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>> const&, OHOS::Wifi::WifiDeviceConfig&)";
|
||||
"OHOS::Wifi::WifiSettings::GetDeviceConfig(std::__h::vector<OHOS::Wifi::WifiDeviceConfig, std::__h::allocator<OHOS::Wifi::WifiDeviceConfig>>&, int)";
|
||||
"OHOS::Wifi::WifiSettings::GetDeviceConfig(int const&, OHOS::Wifi::WifiDeviceConfig&, int)";
|
||||
"OHOS::Wifi::WifiSettings::GetDeviceConfig(std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>> const&, int const&, OHOS::Wifi::WifiDeviceConfig&, int)";
|
||||
"OHOS::Wifi::WifiSettings::GetDeviceConfig(std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>> const&, std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>> const&, OHOS::Wifi::WifiDeviceConfig&, int)";
|
||||
"OHOS::Wifi::WifiSettings::SetDeviceState(int, int, bool)";
|
||||
"OHOS::Wifi::WifiSettings::SetDeviceEphemeral(int, bool)";
|
||||
"OHOS::Wifi::WifiSettings::SetDeviceAfterConnect(int)";
|
||||
"OHOS::Wifi::WifiSettings::SetDeviceRandomizedMacSuccessEver(int)";
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "mock_wifi_manager.h"
|
||||
#include "mock_wifi_sta_hal_interface.h"
|
||||
#include "wifi_error_no.h"
|
||||
#include "mock_block_connect_service.h"
|
||||
|
||||
using ::testing::_;
|
||||
using ::testing::AtLeast;
|
||||
@ -380,7 +381,6 @@ public:
|
||||
void DealConnectionEventSuccess()
|
||||
{
|
||||
EXPECT_CALL(WifiSettings::GetInstance(), SetDeviceAfterConnect(_)).Times(testing::AtLeast(0));
|
||||
EXPECT_CALL(WifiSettings::GetInstance(), SetDeviceState(_, _, _)).Times(testing::AtLeast(0));
|
||||
EXPECT_CALL(WifiSettings::GetInstance(), SyncDeviceConfig()).Times(testing::AtLeast(0));
|
||||
EXPECT_CALL(WifiConfigCenter::GetInstance(), SaveLinkedInfo(_, _)).Times(AtLeast(0));
|
||||
EXPECT_CALL(WifiConfigCenter::GetInstance(), SetUserLastSelectedNetworkId(_, _)).Times(testing::AtLeast(0));
|
||||
|
@ -46,7 +46,8 @@ public:
|
||||
const std::string &ssid, const std::string &keymgmt, WifiDeviceConfig &config, int instId = 0) = 0;
|
||||
virtual int GetDeviceConfig(
|
||||
const std::string &index, const int &indexType, WifiDeviceConfig &config, int instId = 0) = 0;
|
||||
virtual int SetDeviceState(int networkId, int state, bool bSetOther = false) = 0;
|
||||
virtual int GetCandidateConfigWithoutUid(const std::string &ssid, const std::string &keymgmt,
|
||||
WifiDeviceConfig &config) = 0;
|
||||
virtual int SyncDeviceConfig() = 0;
|
||||
virtual int ReloadDeviceConfig() = 0;
|
||||
virtual int GetIpInfo(IpInfo &info, int instId = 0) = 0;
|
||||
@ -220,7 +221,8 @@ public:
|
||||
GetDeviceConfig, int(const std::string &ssid, const std::string &keymgmt, WifiDeviceConfig &config, int));
|
||||
MOCK_METHOD4(
|
||||
GetDeviceConfig, int(const std::string &index, const int &indexType, WifiDeviceConfig &config, int));
|
||||
MOCK_METHOD3(SetDeviceState, int(int networkId, int state, bool bSetOther));
|
||||
MOCK_METHOD3(GetCandidateConfigWithoutUid, int(const std::string &ssid, const std::string &keymgmt,
|
||||
WifiDeviceConfig &config));
|
||||
MOCK_METHOD0(SyncDeviceConfig, int());
|
||||
MOCK_METHOD0(ReloadDeviceConfig, int());
|
||||
MOCK_METHOD2(GetIpInfo, int(IpInfo &info, int));
|
||||
|
@ -42,7 +42,6 @@ local_base_sources = [
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/network_select/wifi_scorer_impl.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/app_network_speed_limit/app_network_speed_limit_service.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/app_network_speed_limit/speed_limit_configs_writer.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/block_connect_service.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/network_black_list/network_black_list_manager.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/network_status_history/network_status_history_manager.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/wifi_app_state_aware.cpp",
|
||||
@ -72,6 +71,7 @@ local_base_sources = [
|
||||
"$WIFI_ROOT_DIR/test/wifi_standard/wifi_framework/wifi_manage/wifi_native/Mock/mock_wifi_supplicant_hal_interface.cpp",
|
||||
"$WIFI_ROOT_DIR/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta/Mock/net_conn_client.cpp",
|
||||
"$WIFI_ROOT_DIR/test/wifi_standard/wifi_framework/wifi_toolkit/unittest/Mock/mock_wifi_config_center.cpp",
|
||||
"Mock/mock_block_connect_service.cpp",
|
||||
"Mock/mock_dhcp_service.cpp",
|
||||
"Mock/mock_if_config.cpp",
|
||||
"Mock/mock_mac_address.cpp",
|
||||
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "mock_block_connect_service.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Wifi {
|
||||
BlockConnectService &BlockConnectService::GetInstance(void)
|
||||
{
|
||||
static BlockConnectService inst;
|
||||
return inst;
|
||||
}
|
||||
} // namespace Wifi
|
||||
} // namespace OHOS
|
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef OHOS_MOCK_BLOCKCONNECTSERVICE_H
|
||||
#define OHOS_MOCK_BLOCKCONNECTSERVICE_H
|
||||
|
||||
#include "wifi_ap_msg.h"
|
||||
#include "wifi_msg.h"
|
||||
#include <gmock/gmock.h>
|
||||
#include "wifi_internal_msg.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Wifi {
|
||||
class MockBlockConnectService {
|
||||
public:
|
||||
virtual ~MockBlockConnectService() = default;
|
||||
virtual bool ShouldAutoConnect(const WifiDeviceConfig &config) = 0;
|
||||
virtual bool UpdateAllNetworkSelectStatus() = 0;
|
||||
virtual bool UpdateNetworkSelectStatus(int targetNetworkId, DisabledReason disableReason, int wpaReason) = 0;
|
||||
virtual bool UpdateNetworkSelectStatus(int targetNetworkId, DisabledReason disableReason) = 0;
|
||||
virtual bool EnableNetworkSelectStatus(int targetNetworkId) = 0;
|
||||
virtual bool IsFrequentDisconnect(std::string bssid, int wpaReason) = 0;
|
||||
virtual bool IsWrongPassword(int targetNetworkId) = 0;
|
||||
};
|
||||
|
||||
class BlockConnectService : public MockBlockConnectService {
|
||||
public:
|
||||
BlockConnectService() = default;
|
||||
static BlockConnectService &GetInstance(void);
|
||||
|
||||
MOCK_METHOD1(ShouldAutoConnect, bool(const WifiDeviceConfig &config));
|
||||
MOCK_METHOD0(UpdateAllNetworkSelectStatus, bool());
|
||||
MOCK_METHOD3(UpdateNetworkSelectStatus, bool(int targetNetworkId, DisabledReason disableReason, int wpaReason));
|
||||
MOCK_METHOD2(UpdateNetworkSelectStatus, bool(int targetNetworkId, DisabledReason disableReason));
|
||||
MOCK_METHOD1(EnableNetworkSelectStatus, bool(int targetNetworkId));
|
||||
MOCK_METHOD2(IsFrequentDisconnect, bool(std::string bssid, int wpaReason));
|
||||
MOCK_METHOD1(IsWrongPassword, bool(int targetNetworkId));
|
||||
};
|
||||
} // namespace OHOS
|
||||
} // namespace Wifi
|
||||
#endif
|
@ -34,7 +34,8 @@ public:
|
||||
const std::string &ssid, const std::string &keymgmt, WifiDeviceConfig &config, int instId = 0) = 0;
|
||||
virtual int GetDeviceConfig(
|
||||
const std::string &index, const int &indexType, WifiDeviceConfig &config, int instId = 0) = 0;
|
||||
virtual int SetDeviceState(int networkId, int state, bool bSetOther = false) = 0;
|
||||
virtual int GetCandidateConfigWithoutUid(const std::string &ssid, const std::string &keymgmt,
|
||||
WifiDeviceConfig &config) = 0;
|
||||
virtual int SyncDeviceConfig() = 0;
|
||||
virtual int ReloadDeviceConfig() = 0;
|
||||
virtual int SetCountryCode(const std::string &countryCode) = 0;
|
||||
@ -111,7 +112,8 @@ public:
|
||||
MOCK_METHOD4(GetDeviceConfig, int(const std::string &ssid, const std::string &keymgmt,
|
||||
WifiDeviceConfig &config, int));
|
||||
MOCK_METHOD4(GetDeviceConfig, int(const std::string &index, const int &indexType, WifiDeviceConfig &config, int));
|
||||
MOCK_METHOD3(SetDeviceState, int(int networkId, int state, bool bSetOther));
|
||||
MOCK_METHOD3(GetCandidateConfigWithoutUid, int(const std::string &ssid, const std::string &keymgmt,
|
||||
WifiDeviceConfig &config));
|
||||
MOCK_METHOD0(SyncDeviceConfig, int());
|
||||
MOCK_METHOD0(ReloadDeviceConfig, int());
|
||||
MOCK_METHOD1(SetCountryCode, int(const std::string &countryCode));
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "sta_device_appraisal.h"
|
||||
#include "wifi_native_struct.h"
|
||||
#include "wifi_error_no.h"
|
||||
#include "mock_block_connect_service.h"
|
||||
|
||||
using ::testing::_;
|
||||
using ::testing::AtLeast;
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include "wifi_internal_msg.h"
|
||||
#include "wifi_msg.h"
|
||||
#include "mock_wifi_sta_hal_interface.h"
|
||||
#include "mock_block_connect_service.h"
|
||||
|
||||
using ::testing::_;
|
||||
using ::testing::AtLeast;
|
||||
@ -368,7 +369,6 @@ public:
|
||||
void DealConnectToUserSelectedNetworkSuccess()
|
||||
{
|
||||
EXPECT_CALL(WifiConfigCenter::GetInstance(), EnableNetwork(_, _, _)).Times(AtLeast(0));
|
||||
EXPECT_CALL(WifiSettings::GetInstance(), SetDeviceState(_, _, _)).Times(AtLeast(0));
|
||||
EXPECT_CALL(WifiConfigCenter::GetInstance(), SaveLinkedInfo(_, _)).Times(testing::AtLeast(0));
|
||||
EXPECT_CALL(WifiSettings::GetInstance(), SetDeviceAfterConnect(_)).Times(AtLeast(0));
|
||||
EXPECT_CALL(WifiConfigCenter::GetInstance(), GetScanInfoList(_)).Times(AtLeast(0));
|
||||
@ -394,7 +394,6 @@ public:
|
||||
pStaStateMachine->linkedInfo.connState = ConnState::CONNECTING;
|
||||
pStaStateMachine->linkedInfo.detailedState = DetailedState::OBTAINING_IPADDR;
|
||||
EXPECT_CALL(WifiConfigCenter::GetInstance(), EnableNetwork(_, _, _)).Times(AtLeast(0));
|
||||
EXPECT_CALL(WifiSettings::GetInstance(), SetDeviceState(_, _, _)).Times(AtLeast(0));
|
||||
EXPECT_CALL(WifiConfigCenter::GetInstance(), SaveLinkedInfo(_, _)).Times(testing::AtLeast(0));
|
||||
pStaStateMachine->DealConnectToUserSelectedNetwork(msg);
|
||||
pStaStateMachine->DealConnectToUserSelectedNetwork(nullptr);
|
||||
@ -422,7 +421,6 @@ public:
|
||||
pStaStateMachine->linkedInfo.connState = ConnState::CONNECTING;
|
||||
pStaStateMachine->linkedInfo.detailedState = DetailedState::NOTWORKING;
|
||||
EXPECT_CALL(WifiConfigCenter::GetInstance(), EnableNetwork(_, _, _)).Times(AtLeast(0));
|
||||
EXPECT_CALL(WifiSettings::GetInstance(), SetDeviceState(_, _, _)).Times(AtLeast(0));
|
||||
EXPECT_CALL(WifiConfigCenter::GetInstance(), SaveLinkedInfo(_, _)).Times(testing::AtLeast(0));
|
||||
pStaStateMachine->DealConnectToUserSelectedNetwork(msg);
|
||||
}
|
||||
@ -980,7 +978,6 @@ public:
|
||||
EXPECT_CALL(WifiSettings::GetInstance(), AddDeviceConfig(_)).Times(AtLeast(0));
|
||||
EXPECT_CALL(WifiSettings::GetInstance(), SyncDeviceConfig()).Times(AtLeast(0));
|
||||
EXPECT_CALL(WifiManager::GetInstance(), DealStaConnChanged(_, _, _)).Times(AtLeast(0));
|
||||
EXPECT_CALL(WifiSettings::GetInstance(), SetDeviceState(_, _, _)).Times(AtLeast(0));
|
||||
InternalMessagePtr msg = std::make_shared<InternalMessage>();
|
||||
msg->SetMessageName(WIFI_SVR_CMD_STA_NETWORK_CONNECTION_EVENT);
|
||||
EXPECT_TRUE(pStaStateMachine->pWpsState->ExecuteStateMsg(msg));
|
||||
@ -1562,7 +1559,6 @@ public:
|
||||
void DealConnectionEventSuccess()
|
||||
{
|
||||
EXPECT_CALL(WifiSettings::GetInstance(), SetDeviceAfterConnect(_)).Times(testing::AtLeast(0));
|
||||
EXPECT_CALL(WifiSettings::GetInstance(), SetDeviceState(_, _, _)).Times(testing::AtLeast(0));
|
||||
EXPECT_CALL(WifiSettings::GetInstance(), SyncDeviceConfig()).Times(testing::AtLeast(0));
|
||||
EXPECT_CALL(WifiConfigCenter::GetInstance(), SaveLinkedInfo(_, _)).Times(AtLeast(0));
|
||||
EXPECT_CALL(WifiConfigCenter::GetInstance(), SetUserLastSelectedNetworkId(_, _)).Times(testing::AtLeast(0));
|
||||
@ -1574,7 +1570,6 @@ public:
|
||||
void DealConnectionEventFail()
|
||||
{
|
||||
EXPECT_CALL(WifiSettings::GetInstance(), SetDeviceAfterConnect(_)).Times(testing::AtLeast(0));
|
||||
EXPECT_CALL(WifiSettings::GetInstance(), SetDeviceState(_, _, _)).Times(testing::AtLeast(0));
|
||||
EXPECT_CALL(WifiSettings::GetInstance(), SyncDeviceConfig()).Times(testing::AtLeast(0));
|
||||
EXPECT_CALL(WifiConfigCenter::GetInstance(), SaveLinkedInfo(_, _)).Times(AtLeast(0));
|
||||
EXPECT_CALL(WifiConfigCenter::GetInstance(), SetUserLastSelectedNetworkId(_, _)).Times(testing::AtLeast(0));
|
||||
|
@ -80,20 +80,6 @@ HWTEST_F(WifiSettingsTest, GetDeviceConfig3Test, TestSize.Level1)
|
||||
EXPECT_EQ(result, WIFI_OPT_RETURN);
|
||||
}
|
||||
|
||||
HWTEST_F(WifiSettingsTest, SetDeviceStateTest, TestSize.Level1)
|
||||
{
|
||||
WIFI_LOGE("SetDeviceStateTest enter!");
|
||||
int result = WifiSettings::GetInstance().SetDeviceState(NETWORK_ID, WIFI_OPT_RETURN, true);
|
||||
EXPECT_EQ(result, WIFI_OPT_RETURN);
|
||||
result = WifiSettings::GetInstance().SetDeviceState(NETWORK_ID, NETWORK_ID, true);
|
||||
EXPECT_EQ(result, WIFI_OPT_RETURN);
|
||||
result = WifiSettings::GetInstance().SetDeviceState(NETWORK_ID, STATE, true);
|
||||
EXPECT_EQ(result, WIFI_OPT_RETURN);
|
||||
result = WifiSettings::GetInstance().SetDeviceState(SCORE, STATE, true);
|
||||
WIFI_LOGE("SetDeviceStateTest result(%{public}d)", result);
|
||||
EXPECT_EQ(result, WIFI_OPT_RETURN);
|
||||
}
|
||||
|
||||
HWTEST_F(WifiSettingsTest, SetDeviceEphemeralTest, TestSize.Level1)
|
||||
{
|
||||
WIFI_LOGE("SetDeviceEphemeralTest enter!");
|
||||
@ -142,6 +128,38 @@ HWTEST_F(WifiSettingsTest, IncreaseDeviceConnFailedCountTest, TestSize.Level1)
|
||||
EXPECT_EQ(result, WIFI_OPT_RETURN);
|
||||
}
|
||||
|
||||
HWTEST_F(WifiSettingsTest, GetCandidateConfigWithoutUidTest, TestSize.Level1)
|
||||
{
|
||||
WIFI_LOGI("GetCandidateConfigWithoutUidTest enter!");
|
||||
WifiDeviceConfig config1;
|
||||
config1.ssid = "test";
|
||||
config1.keyMgmt = "SAE";
|
||||
config1.uid = 1;
|
||||
config1.isShared = false;
|
||||
WifiSettings::GetInstance().AddDeviceConfig(config1);
|
||||
|
||||
WifiDeviceConfig config2;
|
||||
int result = WifiSettings::GetInstance().GetCandidateConfigWithoutUid("test", "SAE", config2);
|
||||
WIFI_LOGI("GetCandidateConfigWithoutUidTest result(%{public}d)", result);
|
||||
EXPECT_NE(result, WIFI_OPT_RETURN);
|
||||
}
|
||||
|
||||
HWTEST_F(WifiSettingsTest, GetAllCandidateConfigWithoutUidTest, TestSize.Level1)
|
||||
{
|
||||
WIFI_LOGI("GetAllCandidateConfigWithoutUidTest enter!");
|
||||
WifiDeviceConfig config1;
|
||||
config1.ssid = "test";
|
||||
config1.keyMgmt = "SAE";
|
||||
config1.uid = 1;
|
||||
config1.isShared = false;
|
||||
WifiSettings::GetInstance().AddDeviceConfig(config1);
|
||||
|
||||
std::vector<WifiDeviceConfig> config2;
|
||||
int result = WifiSettings::GetInstance().GetAllCandidateConfigWithoutUid(config2);
|
||||
WIFI_LOGI("GetAllCandidateConfigWithoutUidTest result(%{public}d)", result);
|
||||
EXPECT_NE(result, WIFI_OPT_RETURN);
|
||||
}
|
||||
|
||||
HWTEST_F(WifiSettingsTest, SetDeviceConnFailedCountTest, TestSize.Level1)
|
||||
{
|
||||
WIFI_LOGE("SetDeviceConnFailedCountTest enter!");
|
||||
@ -507,17 +525,6 @@ HWTEST_F(WifiSettingsTest, ClearHotspotConfigTest, TestSize.Level1)
|
||||
WifiSettings::GetInstance().ClearHotspotConfig();
|
||||
}
|
||||
|
||||
HWTEST_F(WifiSettingsTest, SetDeviceStateTest1, TestSize.Level1)
|
||||
{
|
||||
WIFI_LOGI("SetDeviceStateTest enter");
|
||||
WifiDeviceConfig config;
|
||||
WifiSettings::GetInstance().mWifiDeviceConfig.emplace(SCORE, config);
|
||||
int result = WifiSettings::GetInstance().SetDeviceState(SCORE, SCORE, true);
|
||||
EXPECT_EQ(result, 0);
|
||||
result = WifiSettings::GetInstance().SetDeviceState(SCORE, SCORE, false);
|
||||
EXPECT_EQ(result, 0);
|
||||
}
|
||||
|
||||
HWTEST_F(WifiSettingsTest, GetDeviceConfigTest, TestSize.Level1)
|
||||
{
|
||||
WIFI_LOGI("GetDeviceConfigTest enter");
|
||||
|
Loading…
Reference in New Issue
Block a user