Signed-off-by: yangpengfei <yangpengfei34@huawei.com>
This commit is contained in:
yangpengfei 2024-11-19 13:36:20 +00:00 committed by Gitee
parent 291e1cc2ae
commit cd577c1713
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 57 additions and 26 deletions

View File

@ -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

View File

@ -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") {}

View File

@ -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()) {