mirror of
https://gitee.com/openharmony/communication_wifi.git
synced 2024-11-23 07:00:07 +00:00
commit
bc3e5a6e63
@ -65,7 +65,8 @@
|
||||
"wifi_feature_network_selection",
|
||||
"wifi_feature_with_hdi_chip_supported",
|
||||
"wifi_feature_with_vap_manager",
|
||||
"wifi_feature_with_sta_asset"
|
||||
"wifi_feature_with_sta_asset",
|
||||
"wifi_feature_wifi_pro_ctrl"
|
||||
],
|
||||
"adapted_system_type": [
|
||||
"small",
|
||||
|
@ -78,6 +78,7 @@
|
||||
/* -----------Feature service name-------------- */
|
||||
#define WIFI_SERVICE_STA "StaService" /* STA */
|
||||
#define WIFI_SERVICE_SELFCURE "SelfCureService" /* SELFCURE */
|
||||
#define WIFI_SERVICE_WIFIPRO "WifiProService" /* WIFIPRO */
|
||||
#define WIFI_SERVICE_AP "ApService" /* AP */
|
||||
#define WIFI_SERVICE_P2P "P2pService" /* P2P */
|
||||
#define WIFI_SERVICE_SCAN "ScanService" /* SCAN */
|
||||
|
@ -292,7 +292,8 @@ enum class FilterTag {
|
||||
HAS_INTERNET_NETWORK_SELECTOR_FILTER_TAG,
|
||||
RECOVERY_NETWORK_SELECTOR_FILTER_TAG,
|
||||
PORTAL_NETWORK_SELECTOR_FILTER_TAG,
|
||||
IT_NETWORK_SELECTOR_FILTER_TAG
|
||||
IT_NETWORK_SELECTOR_FILTER_TAG,
|
||||
NOT_P2P_ENHANCE_FREQ_AT_5G_FILTER_TAG,
|
||||
};
|
||||
|
||||
enum class TagType {
|
||||
|
@ -659,6 +659,7 @@ struct WifiDeviceConfig {
|
||||
WifiWapiConfig wifiWapiConfig;
|
||||
IpInfo lastDhcpResult;
|
||||
bool isShared;
|
||||
int64_t lastTrySwitchWifiTimestamp { -1 };
|
||||
|
||||
WifiDeviceConfig()
|
||||
{
|
||||
|
@ -49,6 +49,7 @@ group("wifi_manage") {
|
||||
deps += [
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap:wifi_ap_service",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common:wifi_common_service",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_pro:wifi_pro",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure:wifi_self_cure",
|
||||
]
|
||||
if (wifi_feature_with_p2p) {
|
||||
|
@ -189,6 +189,7 @@ if (defined(ohos_lite)) {
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan_sa",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_pro",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap_sa",
|
||||
@ -499,6 +500,7 @@ if (defined(ohos_lite)) {
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common:wifi_common_service",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_native:wifi_native",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p:wifi_p2p_service",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_pro:wifi_pro",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan:wifi_scan_service",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure:wifi_self_cure",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta:wifi_sta_service",
|
||||
@ -557,6 +559,10 @@ if (defined(ohos_lite)) {
|
||||
defines += [ "SUPPORT_ClOUD_WIFI_ASSET" ]
|
||||
}
|
||||
|
||||
if (wifi_feature_wifi_pro_ctrl) {
|
||||
defines += [ "FEATURE_WIFI_PRO_SUPPORT" ]
|
||||
}
|
||||
|
||||
if (defined(global_parts_info) &&
|
||||
defined(global_parts_info.telephony_core_service)) {
|
||||
external_deps += [ "core_service:tel_core_service_api" ]
|
||||
|
@ -109,6 +109,7 @@ if (defined(ohos_lite)) {
|
||||
}
|
||||
install_enable = true
|
||||
include_dirs = [
|
||||
"network_black_list",
|
||||
"$WIFI_ROOT_DIR/base/utils",
|
||||
"$WIFI_ROOT_DIR/interfaces/inner_api",
|
||||
"$WIFI_ROOT_DIR/frameworks/native/interfaces",
|
||||
@ -132,6 +133,7 @@ if (defined(ohos_lite)) {
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan_sa",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_pro",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap_sa",
|
||||
@ -146,6 +148,7 @@ if (defined(ohos_lite)) {
|
||||
"app_network_speed_limit/app_network_speed_limit_service.cpp",
|
||||
"app_network_speed_limit/speed_limit_configs_writer.cpp",
|
||||
"block_connect_service.cpp",
|
||||
"network_black_list/network_black_list_manager.cpp",
|
||||
"wifi_app_state_aware.cpp",
|
||||
"wifi_auth_center.cpp",
|
||||
"wifi_channel_helper.cpp",
|
||||
@ -215,6 +218,10 @@ if (defined(ohos_lite)) {
|
||||
"FEATURE_SELF_CURE_SUPPORT",
|
||||
]
|
||||
|
||||
if (wifi_feature_wifi_pro_ctrl) {
|
||||
defines += [ "FEATURE_WIFI_PRO_SUPPORT" ]
|
||||
}
|
||||
|
||||
if (is_asan) {
|
||||
defines += [ "DTFUZZ_TEST" ]
|
||||
}
|
||||
|
@ -0,0 +1,147 @@
|
||||
/*
|
||||
* Copyright (C) 2024-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 <ctime>
|
||||
#include <vector>
|
||||
#include "wifi_timer.h"
|
||||
#include "network_black_list_manager.h"
|
||||
#include "wifi_logger.h"
|
||||
#include "wifi_common_util.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Wifi {
|
||||
DEFINE_WIFILOG_LABEL("NetworkBlockListManager");
|
||||
namespace {
|
||||
constexpr int32_t MAX_CONNECT_FAILED_TIMES = 2;
|
||||
}
|
||||
|
||||
NetworkBlockListManager::NetworkBlockListManager()
|
||||
{}
|
||||
|
||||
NetworkBlockListManager::~NetworkBlockListManager()
|
||||
{}
|
||||
|
||||
NetworkBlockListManager &NetworkBlockListManager::GetInstance()
|
||||
{
|
||||
static NetworkBlockListManager gNetworkBlockListManager;
|
||||
return gNetworkBlockListManager;
|
||||
}
|
||||
|
||||
void NetworkBlockListManager::AddWifiBlocklist(const std::string &bssid)
|
||||
{
|
||||
if (bssid.empty()) {
|
||||
WIFI_LOGI("AddWifiBlocklist, bssid is invalid");
|
||||
return;
|
||||
}
|
||||
|
||||
WIFI_LOGI("AddWifiBlocklist, bssid:%{public}s", MacAnonymize(bssid).c_str());
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
wifiBlockSet_.insert(bssid);
|
||||
}
|
||||
|
||||
void NetworkBlockListManager::RemoveWifiBlocklist(const std::string &bssid)
|
||||
{
|
||||
WIFI_LOGI("Enter RemoveWifiBlocklist");
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (wifiBlockSet_.empty()) {
|
||||
WIFI_LOGI("RemoveWifiBlocklist, wifiBlockSet is empty");
|
||||
return;
|
||||
}
|
||||
|
||||
if (wifiBlockSet_.find(bssid) != wifiBlockSet_.end()) {
|
||||
WIFI_LOGI("RemoveWifiBlocklist, bssid:%{public}s", MacAnonymize(bssid).c_str());
|
||||
wifiBlockSet_.erase(bssid);
|
||||
}
|
||||
}
|
||||
|
||||
bool NetworkBlockListManager::IsInWifiBlocklist(const std::string &bssid)
|
||||
{
|
||||
if (bssid.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (wifiBlockSet_.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto iter = wifiBlockSet_.find(bssid);
|
||||
return iter != wifiBlockSet_.end();
|
||||
}
|
||||
|
||||
void NetworkBlockListManager::AddAbnormalWifiBlocklist(const std::string &bssid)
|
||||
{
|
||||
if (bssid.empty()) {
|
||||
WIFI_LOGI("AddAbnormalWifiBlocklist, bssid is invalid");
|
||||
return;
|
||||
}
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
abnormalWifiBlockSet_.insert(bssid);
|
||||
}
|
||||
|
||||
void NetworkBlockListManager::CleanAbnormalWifiBlocklist()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
abnormalWifiBlockSet_.clear();
|
||||
}
|
||||
|
||||
bool NetworkBlockListManager::IsInAbnormalWifiBlocklist(const std::string &bssid)
|
||||
{
|
||||
if (abnormalWifiBlockSet_.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
return abnormalWifiBlockSet_.find(bssid) != abnormalWifiBlockSet_.end();
|
||||
}
|
||||
|
||||
void NetworkBlockListManager::CleanTempWifiBlockList()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
std::map<std::string, int32_t> tempMap;
|
||||
tempWifiBlockMap_.swap(tempMap);
|
||||
}
|
||||
|
||||
bool NetworkBlockListManager::IsInTempWifiBlockList(const std::string &bssid)
|
||||
{
|
||||
if (tempWifiBlockMap_.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
return tempWifiBlockMap_.find(bssid) != tempWifiBlockMap_.end();
|
||||
}
|
||||
|
||||
bool NetworkBlockListManager::IsFailedMultiTimes(const std::string &bssid)
|
||||
{
|
||||
if (bssid.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
int32_t counter = 1;
|
||||
auto iter = tempWifiBlockMap_.find(bssid);
|
||||
if (iter != tempWifiBlockMap_.end()) {
|
||||
counter++;
|
||||
iter->second = counter;
|
||||
} else {
|
||||
tempWifiBlockMap_[bssid] = counter;
|
||||
}
|
||||
|
||||
return counter >= MAX_CONNECT_FAILED_TIMES;
|
||||
}
|
||||
|
||||
} // namespace Wifi
|
||||
} // namespace OHOS
|
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (C) 2024-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_WIFI_NETWORK_BLACK_LIST_MANAGER_H
|
||||
#define OHOS_WIFI_NETWORK_BLACK_LIST_MANAGER_H
|
||||
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include "wifi_log.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Wifi {
|
||||
class NetworkBlockListManager {
|
||||
public:
|
||||
NetworkBlockListManager();
|
||||
~NetworkBlockListManager();
|
||||
static NetworkBlockListManager &GetInstance();
|
||||
void AddWifiBlocklist(const std::string &bssid);
|
||||
bool IsInWifiBlocklist(const std::string &bssid);
|
||||
void AddAbnormalWifiBlocklist(const std::string &bssid);
|
||||
void CleanAbnormalWifiBlocklist();
|
||||
void CleanTempWifiBlockList();
|
||||
bool IsInAbnormalWifiBlocklist(const std::string &bssid);
|
||||
bool IsInTempWifiBlockList(const std::string &bssid);
|
||||
bool IsFailedMultiTimes(const std::string &bssid);
|
||||
void RemoveWifiBlocklist(const std::string &bssid);
|
||||
|
||||
private:
|
||||
std::mutex mutex_;
|
||||
std::set<std::string> wifiBlockSet_;
|
||||
std::set<std::string> abnormalWifiBlockSet_;
|
||||
std::map<std::string, int32_t> tempWifiBlockMap_;
|
||||
};
|
||||
|
||||
} // namespace Wifi
|
||||
} // namespace OHOS
|
||||
#endif
|
@ -599,6 +599,9 @@ ErrCode ConcreteMangerMachine::SwitchSemiFromEnable()
|
||||
WIFI_LOGE("SwitchSemiFromEnable, Instance get sta service is null!");
|
||||
WifiConfigCenter::GetInstance().SetWifiMidState(WifiOprMidState::CLOSED, mid);
|
||||
WifiServiceManager::GetInstance().UnloadService(WIFI_SERVICE_STA, mid);
|
||||
#ifdef FEATURE_WIFI_PRO_SUPPORT
|
||||
WifiServiceManager::GetInstance().UnloadService(WIFI_SERVICE_WIFIPRO, mid);
|
||||
#endif
|
||||
#ifdef FEATURE_SELF_CURE_SUPPORT
|
||||
WifiServiceManager::GetInstance().UnloadService(WIFI_SERVICE_SELFCURE, mid);
|
||||
#endif
|
||||
|
@ -173,11 +173,7 @@ ErrCode WifiServiceScheduler::AutoStopStaService(int instId)
|
||||
IStaService *pService = WifiServiceManager::GetInstance().GetStaServiceInst(instId);
|
||||
if (pService == nullptr) {
|
||||
WIFI_LOGE("AutoStopStaService, Instance get sta service is null!");
|
||||
WifiConfigCenter::GetInstance().SetWifiMidState(WifiOprMidState::CLOSED, instId);
|
||||
WifiServiceManager::GetInstance().UnloadService(WIFI_SERVICE_STA, instId);
|
||||
#ifdef FEATURE_SELF_CURE_SUPPORT
|
||||
WifiServiceManager::GetInstance().UnloadService(WIFI_SERVICE_SELFCURE, instId);
|
||||
#endif
|
||||
HandleGetStaFailed(instId);
|
||||
return WIFI_OPT_SUCCESS;
|
||||
}
|
||||
DispatchWifiCloseRes(OperateResState::CLOSE_WIFI_CLOSING, instId);
|
||||
@ -247,6 +243,18 @@ ErrCode WifiServiceScheduler::AutoStopWifi2Service(int instId)
|
||||
return WIFI_OPT_SUCCESS;
|
||||
}
|
||||
|
||||
void WifiServiceScheduler::HandleGetStaFailed(int instId)
|
||||
{
|
||||
WifiConfigCenter::GetInstance().SetWifiMidState(WifiOprMidState::CLOSED, instId);
|
||||
WifiServiceManager::GetInstance().UnloadService(WIFI_SERVICE_STA, instId);
|
||||
#ifdef FEATURE_WIFI_PRO_SUPPORT
|
||||
WifiServiceManager::GetInstance().UnloadService(WIFI_SERVICE_WIFIPRO, instId);
|
||||
#endif
|
||||
#ifdef FEATURE_SELF_CURE_SUPPORT
|
||||
WifiServiceManager::GetInstance().UnloadService(WIFI_SERVICE_SELFCURE, instId);
|
||||
#endif
|
||||
}
|
||||
|
||||
ErrCode WifiServiceScheduler::AutoStartScanOnly(int instId, std::string &staIfName)
|
||||
{
|
||||
WifiOprMidState curState = WifiConfigCenter::GetInstance().GetWifiScanOnlyMidState(instId);
|
||||
@ -389,6 +397,7 @@ ErrCode WifiServiceScheduler::PostStartWifi(int instId)
|
||||
ErrCode errCode = WifiManager::GetInstance().GetWifiP2pManager()->AutoStartP2pService();
|
||||
if (errCode != WIFI_OPT_SUCCESS && errCode != WIFI_OPT_OPEN_SUCC_WHEN_OPENED) {
|
||||
WIFI_LOGE("AutoStartStaService, AutoStartP2pService failed!");
|
||||
return WIFI_OPT_FAILED;
|
||||
}
|
||||
#endif
|
||||
return WIFI_OPT_SUCCESS;
|
||||
@ -407,18 +416,16 @@ ErrCode WifiServiceScheduler::StartWifiStaService(int instId)
|
||||
return WIFI_OPT_FAILED;
|
||||
}
|
||||
WIFI_LOGD("StartWifiStaService GetStaServiceInst instId:%{public}d", instId);
|
||||
#ifdef FEATURE_SELF_CURE_SUPPORT
|
||||
if (instId == INSTID_WLAN0) {
|
||||
if (StartSelfCureService(instId) != WIFI_OPT_SUCCESS) {
|
||||
WIFI_LOGE("StartSelfCureService failed!");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
IStaService *pService = WifiServiceManager::GetInstance().GetStaServiceInst(instId);
|
||||
if (pService == nullptr) {
|
||||
WIFI_LOGE("StartWifiStaService Create %{public}s service failed!", WIFI_SERVICE_STA);
|
||||
return WIFI_OPT_FAILED;
|
||||
}
|
||||
|
||||
if (StartDependentService(instId) != WIFI_OPT_SUCCESS) {
|
||||
return WIFI_OPT_FAILED;
|
||||
}
|
||||
|
||||
WIFI_LOGD("StartWifiStaService InitStaService instId:%{public}d", instId);
|
||||
if (InitStaService(pService, instId) != WIFI_OPT_SUCCESS) {
|
||||
WIFI_LOGE("StartWifiStaService InitStaService failed!");
|
||||
@ -446,6 +453,28 @@ ErrCode WifiServiceScheduler::StartWifiStaService(int instId)
|
||||
return WIFI_OPT_SUCCESS;
|
||||
}
|
||||
|
||||
ErrCode WifiServiceScheduler::StartDependentService(int instId)
|
||||
{
|
||||
if (instId != INSTID_WLAN0) {
|
||||
return WIFI_OPT_SUCCESS;
|
||||
}
|
||||
|
||||
#ifdef FEATURE_WIFI_PRO_SUPPORT
|
||||
if (StartWifiProService(instId) != WIFI_OPT_SUCCESS) {
|
||||
WIFI_LOGE("StartWifiProService failed!");
|
||||
return WIFI_OPT_FAILED;
|
||||
}
|
||||
#endif
|
||||
#ifdef FEATURE_SELF_CURE_SUPPORT
|
||||
if (StartSelfCureService(instId) != WIFI_OPT_SUCCESS) {
|
||||
WIFI_LOGE("StartSelfCureService failed!");
|
||||
return WIFI_OPT_FAILED;
|
||||
}
|
||||
#endif
|
||||
|
||||
return WIFI_OPT_SUCCESS;
|
||||
}
|
||||
|
||||
ErrCode WifiServiceScheduler::InitStaService(IStaService *pService, int instId)
|
||||
{
|
||||
if (pService == nullptr) {
|
||||
@ -498,6 +527,41 @@ ErrCode WifiServiceScheduler::InitStaService(IStaService *pService, int instId)
|
||||
return WIFI_OPT_SUCCESS;
|
||||
}
|
||||
|
||||
#ifdef FEATURE_WIFI_PRO_SUPPORT
|
||||
ErrCode WifiServiceScheduler::StartWifiProService(int instId)
|
||||
{
|
||||
if (WifiServiceManager::GetInstance().CheckAndEnforceService(WIFI_SERVICE_WIFIPRO) < 0) {
|
||||
WIFI_LOGE("Load %{public}s service failed!", WIFI_SERVICE_WIFIPRO);
|
||||
return WIFI_OPT_FAILED;
|
||||
}
|
||||
|
||||
IWifiProService *pWifiProService = WifiServiceManager::GetInstance().GetWifiProServiceInst(instId);
|
||||
if (pWifiProService == nullptr) {
|
||||
WIFI_LOGE("Create %{public}s service failed!", WIFI_SERVICE_WIFIPRO);
|
||||
return WIFI_OPT_FAILED;
|
||||
}
|
||||
ErrCode errCode = pWifiProService->InitWifiProService();
|
||||
if (errCode != WIFI_OPT_SUCCESS) {
|
||||
WIFI_LOGE("Service enable wifi pro failed, ret %{public}d!", static_cast<int>(errCode));
|
||||
return WIFI_OPT_FAILED;
|
||||
}
|
||||
|
||||
IStaService *pService = WifiServiceManager::GetInstance().GetStaServiceInst(instId);
|
||||
if (pService == nullptr) {
|
||||
WIFI_LOGE("Get %{public}s service failed!", WIFI_SERVICE_STA);
|
||||
return WIFI_OPT_FAILED;
|
||||
}
|
||||
|
||||
errCode = pService->RegisterStaServiceCallback(pWifiProService->GetStaCallback());
|
||||
if (errCode != WIFI_OPT_SUCCESS) {
|
||||
WIFI_LOGE("WifiPro register sta service callback failed!");
|
||||
return WIFI_OPT_FAILED;
|
||||
}
|
||||
|
||||
return WIFI_OPT_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef FEATURE_SELF_CURE_SUPPORT
|
||||
ErrCode WifiServiceScheduler::StartSelfCureService(int instId)
|
||||
{
|
||||
|
@ -62,6 +62,11 @@ private:
|
||||
ErrCode PostStartWifi2(int instId);
|
||||
ErrCode InitStaService(IStaService *pService, int instId);
|
||||
ErrCode StartWifiStaService(int instId);
|
||||
ErrCode StartDependentService(int instId);
|
||||
void HandleGetStaFailed(int instId);
|
||||
#ifdef FEATURE_WIFI_PRO_SUPPORT
|
||||
ErrCode StartWifiProService(int instId);
|
||||
#endif
|
||||
#ifdef FEATURE_SELF_CURE_SUPPORT
|
||||
ErrCode StartSelfCureService(int instId);
|
||||
#endif
|
||||
|
@ -0,0 +1,99 @@
|
||||
# Copyright (C) 2023-2023 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.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
import("//foundation/communication/wifi/wifi/wifi.gni")
|
||||
|
||||
ohos_static_library("wifi_pro") {
|
||||
branch_protector_ret = "pac_ret"
|
||||
|
||||
sanitize = {
|
||||
cfi = true # Enable/disable control flow integrity detection
|
||||
boundary_sanitize = true # Enable boundary san detection
|
||||
cfi_cross_dso = true # Cross-SO CFI Checks
|
||||
integer_overflow = true # Enable integer overflow detection
|
||||
ubsan = true # Enable some Ubsan options
|
||||
debug = false
|
||||
}
|
||||
include_dirs = [
|
||||
"$WIFI_ROOT_DIR/frameworks/native/interfaces",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/config",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_pro",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/common",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/wifi_hal_interface",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_pro",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/network_select",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/network_black_list",
|
||||
]
|
||||
|
||||
sources = [
|
||||
"$WIFI_ROOT_DIR/frameworks/native/src/network_selection.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/network_select/external_wifi_common_builder_manager.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/network_select/external_wifi_filter_builder_manager.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/network_select/network_selection_manager.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/network_select/network_selection_utils.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/network_select/network_selector_factory.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/network_select/network_selector_impl.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/network_select/wifi_comparator_impl.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/network_select/wifi_filter_impl.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/network_select/wifi_scorer_impl.cpp",
|
||||
"wifi_pro_interface.cpp",
|
||||
"wifi_pro_service.cpp",
|
||||
"wifi_pro_state_machine.cpp",
|
||||
"wifi_pro_utils.cpp",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"$WIFI_ROOT_DIR/base:wifi_base",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common:wifi_common_service",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit:wifi_toolkit",
|
||||
"$WIFI_ROOT_DIR/utils:wifi_utils",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_runtime:app_manager",
|
||||
"c_utils:utils",
|
||||
"hilog:libhilog",
|
||||
"init:libbegetutil",
|
||||
"netmanager_base:net_conn_manager_if",
|
||||
]
|
||||
|
||||
defines = []
|
||||
|
||||
if (wifi_feature_wifi_pro_ctrl) {
|
||||
defines += [ "FEATURE_WIFI_PRO_SUPPORT" ]
|
||||
}
|
||||
|
||||
defines += [ "FEATURE_SELF_CURE_SUPPORT" ]
|
||||
|
||||
cflags = memory_optimization_cflags
|
||||
cflags_cc = memory_optimization_cflags_cc
|
||||
cflags_cc += [
|
||||
"-std=c++17",
|
||||
"-Wall",
|
||||
]
|
||||
|
||||
ldflags = [
|
||||
"-fPIC",
|
||||
"-Wl,-E",
|
||||
]
|
||||
|
||||
part_name = "wifi"
|
||||
subsystem_name = "communication"
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (C) 2024-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_WIFI_IWIFI_PRO_SERVICE_H
|
||||
#define OHOS_WIFI_IWIFI_PRO_SERVICE_H
|
||||
|
||||
#include "wifi_errcode.h"
|
||||
#include "wifi_msg.h"
|
||||
#include "sta_service_callback.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Wifi {
|
||||
class IWifiProService {
|
||||
public:
|
||||
virtual ~IWifiProService() = default;
|
||||
/**
|
||||
* @Description wifiPro service initialization function.
|
||||
*
|
||||
* @return ErrCode - success: WIFI_OPT_SUCCESS, failed: WIFI_OPT_FAILED
|
||||
*/
|
||||
virtual ErrCode InitWifiProService() = 0;
|
||||
|
||||
/**
|
||||
* @Description Get register sta callback
|
||||
*
|
||||
* @return StaServiceCallback - sta callback
|
||||
*/
|
||||
virtual StaServiceCallback GetStaCallback() const = 0;
|
||||
|
||||
/**
|
||||
* @Description deal scan results
|
||||
*
|
||||
* @return results - scan results
|
||||
*/
|
||||
virtual void DealScanResult(const std::vector<InterScanInfo> &results) = 0;
|
||||
};
|
||||
} // namespace Wifi
|
||||
} // namespace OHOS
|
||||
#endif
|
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (C) 2024-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_WIFI_PRO_COMMON_H
|
||||
#define OHOS_WIFI_PRO_COMMON_H
|
||||
|
||||
namespace OHOS {
|
||||
namespace Wifi {
|
||||
#define FRIEND_GTEST(test_typename) friend class test_typename##Test
|
||||
|
||||
constexpr int32_t ROAM_SCENE = 1;
|
||||
constexpr int64_t WIFI_SWITCH_RECORD_MAX_TIME = 1000 * 60 * 60 * 24 * 14; // 14天,单位:ms
|
||||
|
||||
enum WifiProCommond {
|
||||
EVENT_NOTIFY_WIFI_PRO_SWITCH_CHANGED = 0,
|
||||
EVENT_WIFI_CONNECT_STATE_CHANGED = 1,
|
||||
EVENT_DISCONNECT_DISCONNECTED = 2,
|
||||
EVENT_HANDLE_SCAN_RESULT = 3,
|
||||
EVENT_WIFI2WIFI_SELECT_NETWORK_RESULT = 4,
|
||||
EVENT_WIFI2WIFI_FAILED = 5,
|
||||
EVENT_WIFI_RSSI_CHANGED = 6,
|
||||
EVENT_CHECK_WIFI_INTERNET_RESULT = 7,
|
||||
EVENT_HTTP_REACHABLE_RESULT = 8,
|
||||
EVENT_REQUEST_SCAN_DELAY = 9,
|
||||
EVENT_REMOVE_BLOCK_LIST = 10,
|
||||
};
|
||||
|
||||
enum SigLevel {
|
||||
SIG_LEVEL_0 = 0,
|
||||
SIG_LEVEL_1 = 1,
|
||||
SIG_LEVEL_2 = 2,
|
||||
SIG_LEVEL_3 = 3,
|
||||
SIG_LEVEL_4 = 4,
|
||||
SIG_LEVEL_MAX = 4,
|
||||
};
|
||||
|
||||
inline const int32_t QUICK_SCAN_INTERVAL[SIG_LEVEL_MAX] = { 10000, 10000, 15000, 30000 };
|
||||
inline const int32_t NORMAL_SCAN_INTERVAL[SIG_LEVEL_MAX] = { 15000, 15000, 30000, 60000 };
|
||||
inline const int32_t QUICK_SCAN_MAX_COUNTER[SIG_LEVEL_MAX] = { 20, 20, 10, 10 };
|
||||
inline const int32_t NORMAL_SCAN_MAX_COUNTER[SIG_LEVEL_MAX] = { 4, 4, 2, 2 };
|
||||
|
||||
enum WifiSwitchReason {
|
||||
// current ap triggers wifi switch because of no internet
|
||||
WIFI_SWITCH_REASON_NO_INTERNET = 1,
|
||||
// current ap triggers wifi switch because of rssi poor
|
||||
WIFI_SWITCH_REASON_POOR_RSSI = 2,
|
||||
// current ap triggers wifi switch because of internet block under poor rssi
|
||||
WIFI_SWITCH_REASON_STRONG_RSSI_INTERNET_SLOW = 3,
|
||||
// current ap triggers wifi switch because of internet block under strong rssi
|
||||
WIFI_SWITCH_REASON_POOR_RSSI_INTERNET_SLOW = 4,
|
||||
// current ap triggers wifi switch because of checking wifi in background
|
||||
WIFI_SWITCH_REASON_BACKGROUND_CHECK_AVAILABLE_WIFI = 5,
|
||||
};
|
||||
|
||||
} // namespace Wifi
|
||||
} // namespace OHOS
|
||||
#endif
|
@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright (C) 2024-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 "define.h"
|
||||
#include "wifi_logger.h"
|
||||
#include "wifi_pro_interface.h"
|
||||
#include "wifi_pro_service.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Wifi {
|
||||
DEFINE_WIFILOG_LABEL("WifiProInterface");
|
||||
|
||||
WifiProInterface::WifiProInterface(int32_t instId) : instId_(instId)
|
||||
{
|
||||
WIFI_LOGI("Enter WifiProInterface");
|
||||
}
|
||||
|
||||
WifiProInterface::~WifiProInterface()
|
||||
{
|
||||
WIFI_LOGI("Enter ~WifiProInterface");
|
||||
}
|
||||
|
||||
ErrCode WifiProInterface::InitWifiProService()
|
||||
{
|
||||
WIFI_LOGI("Enter WifiProInterface::InitWifiProService");
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (pWifiProService_ == nullptr) {
|
||||
pWifiProService_ = std::make_shared<WifiProService>(instId_);
|
||||
if (pWifiProService_ == nullptr) {
|
||||
WIFI_LOGE("Alloc pWifiProService failed.");
|
||||
return WIFI_OPT_FAILED;
|
||||
}
|
||||
InitCallback();
|
||||
if (pWifiProService_->InitWifiProService() != WIFI_OPT_SUCCESS) {
|
||||
WIFI_LOGE("InitWifiProService failed.");
|
||||
return WIFI_OPT_FAILED;
|
||||
}
|
||||
}
|
||||
return WIFI_OPT_SUCCESS;
|
||||
}
|
||||
|
||||
void WifiProInterface::InitCallback()
|
||||
{
|
||||
using namespace std::placeholders;
|
||||
WIFI_LOGI("Enter WifiProInterface::InitCallback");
|
||||
staCallback_.callbackModuleName = "WifiProService";
|
||||
staCallback_.OnStaConnChanged = [this](OperateResState state, const WifiLinkedInfo &linkedInfo, int32_t instId) {
|
||||
this->DealStaConnChanged(state, linkedInfo, instId);
|
||||
};
|
||||
staCallback_.OnStaRssiLevelChanged = [this](int32_t rssi, int32_t instId) {
|
||||
this->DealRssiLevelChanged(rssi, instId);
|
||||
};
|
||||
}
|
||||
|
||||
void WifiProInterface::DealStaConnChanged(OperateResState state, const WifiLinkedInfo &linkedInfo, int32_t instId)
|
||||
{
|
||||
WIFI_LOGI("Enter WifiProInterface::DealStaConnChanged");
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (pWifiProService_ == nullptr) {
|
||||
WIFI_LOGI("pWifiProService is null");
|
||||
return;
|
||||
}
|
||||
pWifiProService_->HandleStaConnChanged(state, linkedInfo);
|
||||
}
|
||||
|
||||
void WifiProInterface::DealRssiLevelChanged(int32_t rssi, int32_t instId)
|
||||
{
|
||||
WIFI_LOGI("Enter WifiProInterface::DealRssiLevelChanged");
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (pWifiProService_ == nullptr) {
|
||||
WIFI_LOGI("pWifiProService is null");
|
||||
return;
|
||||
}
|
||||
pWifiProService_->HandleRssiLevelChanged(rssi);
|
||||
}
|
||||
|
||||
void WifiProInterface::DealScanResult(const std::vector<InterScanInfo> &results)
|
||||
{
|
||||
WIFI_LOGI("Enter WifiProInterface::DealScanResult");
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (pWifiProService_ == nullptr) {
|
||||
WIFI_LOGI("pWifiProService is null");
|
||||
return;
|
||||
}
|
||||
pWifiProService_->HandleScanResult(results);
|
||||
}
|
||||
|
||||
StaServiceCallback WifiProInterface::GetStaCallback() const
|
||||
{
|
||||
return staCallback_;
|
||||
}
|
||||
|
||||
} // namespace Wifi
|
||||
} // namespace OHOS
|
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright (C) 2024-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_WIFI_WIFI_PRO_INTERFACE_H
|
||||
#define OHOS_WIFI_WIFI_PRO_INTERFACE_H
|
||||
|
||||
#include "iwifi_pro_service.h"
|
||||
#include "define.h"
|
||||
#include "wifi_pro_common.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Wifi {
|
||||
class WifiProService;
|
||||
class WifiProInterface : public IWifiProService {
|
||||
FRIEND_GTEST(WifiProInterface);
|
||||
public:
|
||||
explicit WifiProInterface(int32_t instId = 0);
|
||||
~WifiProInterface() override;
|
||||
|
||||
/**
|
||||
* @Description self cure service initialization function.
|
||||
*
|
||||
* @return success: WIFI_OPT_SUCCESS, failed: WIFI_OPT_FAILED
|
||||
*/
|
||||
ErrCode InitWifiProService() override;
|
||||
|
||||
/**
|
||||
* @Description Get register sta callback
|
||||
*
|
||||
* @return StaServiceCallback - sta callback
|
||||
*/
|
||||
StaServiceCallback GetStaCallback() const override;
|
||||
|
||||
/**
|
||||
* @Description deal scan results
|
||||
*
|
||||
* @return results - scan results
|
||||
*/
|
||||
void DealScanResult(const std::vector<InterScanInfo> &results) override;
|
||||
|
||||
private:
|
||||
/**
|
||||
* @Description deal sta connection change
|
||||
*
|
||||
* @param state - OperateResState
|
||||
* @param info - const WifiLinkedInfo
|
||||
*/
|
||||
void DealStaConnChanged(OperateResState state, const WifiLinkedInfo &linkedInfo, int32_t instId = 0);
|
||||
|
||||
/**
|
||||
* @Description rssi level changed
|
||||
*
|
||||
* @param rssi
|
||||
*/
|
||||
void DealRssiLevelChanged(int32_t rssi, int32_t instId = 0);
|
||||
private:
|
||||
std::mutex mutex_;
|
||||
std::shared_ptr<WifiProService> pWifiProService_ { nullptr };
|
||||
int32_t instId_ { 0 };
|
||||
StaServiceCallback staCallback_;
|
||||
void InitCallback();
|
||||
};
|
||||
} // namespace Wifi
|
||||
} // namespace OHOS
|
||||
#endif
|
@ -0,0 +1,138 @@
|
||||
/*
|
||||
* Copyright (C) 2024-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 <memory>
|
||||
#include "wifi_logger.h"
|
||||
#include "wifi_msg.h"
|
||||
#include "wifi_pro_service.h"
|
||||
#include "wifi_pro_utils.h"
|
||||
#include "wifi_common_util.h"
|
||||
|
||||
#ifndef FALLTHROUGH_INTENDED
|
||||
#define FALLTHROUGH_INTENDED [[clang::fallthrough]] // NOLINT
|
||||
#endif
|
||||
|
||||
namespace OHOS {
|
||||
namespace Wifi {
|
||||
DEFINE_WIFILOG_LABEL("WifiProService");
|
||||
|
||||
WifiProService::WifiProService(int32_t instId)
|
||||
: instId_(instId)
|
||||
{
|
||||
WIFI_LOGI("Enter WifiProService");
|
||||
}
|
||||
|
||||
WifiProService::~WifiProService()
|
||||
{
|
||||
WIFI_LOGI("Enter ~WifiProService");
|
||||
}
|
||||
|
||||
ErrCode WifiProService::InitWifiProService()
|
||||
{
|
||||
WIFI_LOGI("Enter InitSelfCureService.");
|
||||
pWifiProStateMachine_ = std::make_shared<WifiProStateMachine>(instId_);
|
||||
if (pWifiProStateMachine_ == nullptr) {
|
||||
WIFI_LOGE("Alloc WifiProStateMachine failed.");
|
||||
return WIFI_OPT_FAILED;
|
||||
}
|
||||
if (pWifiProStateMachine_->Initialize() != WIFI_OPT_SUCCESS) {
|
||||
WIFI_LOGE("Init WifiProStateMachine failed.");
|
||||
return WIFI_OPT_FAILED;
|
||||
}
|
||||
return WIFI_OPT_SUCCESS;
|
||||
}
|
||||
|
||||
void WifiProService::HandleStaConnChanged(OperateResState state, const WifiLinkedInfo &linkedInfo)
|
||||
{
|
||||
WIFI_LOGI("WifiProService wifi connection state change, state:%{public}d,connState:%{public}d,"
|
||||
"supplicantState:%{public}d.", state, linkedInfo.connState, static_cast<int32_t>(linkedInfo.supplicantState));
|
||||
if (pWifiProStateMachine_ == nullptr) {
|
||||
WIFI_LOGE("%{public}s pWifiProStateMachine_ is null.", __FUNCTION__);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (state) {
|
||||
case OperateResState::CONNECT_AP_CONNECTED:
|
||||
FALLTHROUGH_INTENDED;
|
||||
case OperateResState::DISCONNECT_DISCONNECTED:
|
||||
NotifyWifiConnectStateChanged(state, linkedInfo);
|
||||
break;
|
||||
case OperateResState::CONNECT_CHECK_PORTAL:
|
||||
FALLTHROUGH_INTENDED;
|
||||
case OperateResState::CONNECT_NETWORK_DISABLED:
|
||||
FALLTHROUGH_INTENDED;
|
||||
case OperateResState::CONNECT_ENABLE_NETWORK_FAILED:
|
||||
FALLTHROUGH_INTENDED;
|
||||
case OperateResState::CONNECT_CONNECTING_TIMEOUT:
|
||||
FALLTHROUGH_INTENDED;
|
||||
case OperateResState::CONNECT_NETWORK_ENABLED:
|
||||
NotifyCheckWifiInternetResult(state);
|
||||
break;
|
||||
case OperateResState::CONNECT_CONNECTION_REJECT:
|
||||
FALLTHROUGH_INTENDED;
|
||||
case OperateResState::CONNECT_PASSWORD_WRONG:
|
||||
FALLTHROUGH_INTENDED;
|
||||
case OperateResState::CONNECT_OBTAINING_IP_FAILED:
|
||||
NotifyWifi2WifiFailed();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void WifiProService::NotifyWifi2WifiFailed()
|
||||
{
|
||||
WIFI_LOGI("NotifyWifi2WifiFailed: wifi2wifi failed");
|
||||
pWifiProStateMachine_->SendMessage(EVENT_WIFI2WIFI_FAILED);
|
||||
}
|
||||
|
||||
void WifiProService::NotifyWifiConnectStateChanged(OperateResState state, const WifiLinkedInfo &linkedInfo)
|
||||
{
|
||||
WIFI_LOGI("NotifyWifiConnectStateChanged:networkId:%{public}d, ssid:%{public}s,"
|
||||
"bssid:%{public}s", linkedInfo.networkId, MacAnonymize(linkedInfo.ssid).c_str(),
|
||||
MacAnonymize(linkedInfo.bssid).c_str());
|
||||
pWifiProStateMachine_->SendMessage(EVENT_WIFI_CONNECT_STATE_CHANGED, static_cast<int32_t>(state),
|
||||
linkedInfo.networkId, linkedInfo.bssid);
|
||||
}
|
||||
|
||||
void WifiProService::NotifyCheckWifiInternetResult(OperateResState state)
|
||||
{
|
||||
WIFI_LOGI("NotifyCheckWifiInternetResult: wifi internet result:%{public}d", static_cast<int32_t>(state));
|
||||
pWifiProStateMachine_->SendMessage(EVENT_CHECK_WIFI_INTERNET_RESULT, static_cast<int32_t>(state));
|
||||
}
|
||||
|
||||
void WifiProService::HandleRssiLevelChanged(int32_t rssi)
|
||||
{
|
||||
WIFI_LOGI("WifiProService::HandleRssiLevelChanged, %{public}d.", rssi);
|
||||
if (pWifiProStateMachine_ == nullptr) {
|
||||
WIFI_LOGE("%{public}s pWifiProStateMachine_ is null.", __FUNCTION__);
|
||||
return;
|
||||
}
|
||||
|
||||
pWifiProStateMachine_->SendMessage(EVENT_WIFI_RSSI_CHANGED, rssi);
|
||||
}
|
||||
|
||||
void WifiProService::HandleScanResult(const std::vector<InterScanInfo> &scanInfos)
|
||||
{
|
||||
WIFI_LOGI("Enter WifiProService::HandleScanResult.");
|
||||
if (pWifiProStateMachine_ == nullptr) {
|
||||
WIFI_LOGE("%{public}s pWifiProStateMachine_ is null.", __FUNCTION__);
|
||||
return;
|
||||
}
|
||||
|
||||
pWifiProStateMachine_->SendMessage(EVENT_HANDLE_SCAN_RESULT, scanInfos);
|
||||
}
|
||||
} // namespace Wifi
|
||||
} // namespace OHOS
|
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (C) 2024-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_WIFI_PRO_SERVICE_H
|
||||
#define OHOS_WIFI_PRO_SERVICE_H
|
||||
|
||||
#include "define.h"
|
||||
#include "wifi_log.h"
|
||||
#include "wifi_errcode.h"
|
||||
#include "wifi_internal_msg.h"
|
||||
#include "wifi_pro_state_machine.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Wifi {
|
||||
class WifiProService {
|
||||
FRIEND_GTEST(WifiProService);
|
||||
public:
|
||||
explicit WifiProService(int32_t instId = 0);
|
||||
~WifiProService();
|
||||
ErrCode InitWifiProService();
|
||||
void HandleStaConnChanged(OperateResState state, const WifiLinkedInfo &linkedInfo);
|
||||
void HandleRssiLevelChanged(int32_t rssi);
|
||||
void HandleScanResult(const std::vector<InterScanInfo> &scanInfos);
|
||||
private:
|
||||
std::shared_ptr<WifiProStateMachine> pWifiProStateMachine_ { nullptr };
|
||||
int32_t instId_ { 0 };
|
||||
void NotifyWifi2WifiFailed();
|
||||
void NotifyWifiConnectStateChanged(OperateResState state, const WifiLinkedInfo &linkedInfo);
|
||||
void NotifyCheckWifiInternetResult(OperateResState state);
|
||||
};
|
||||
|
||||
} // namespace Wifi
|
||||
} // namespace OHOS
|
||||
#endif
|
@ -0,0 +1,961 @@
|
||||
/*
|
||||
* Copyright (C) 2024-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 <string>
|
||||
#include <vector>
|
||||
#include "iscan_service.h"
|
||||
#include "wifi_config_center.h"
|
||||
#include "wifi_logger.h"
|
||||
#include "wifi_msg.h"
|
||||
#include "wifi_pro_state_machine.h"
|
||||
#include "wifi_service_manager.h"
|
||||
#include "wifi_pro_utils.h"
|
||||
#include "network_black_list_manager.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Wifi {
|
||||
namespace {
|
||||
const std::string WIFI_PRO_STATE_MACHINE = "WifiProStateMachine";
|
||||
constexpr int32_t DEFAULT_RSSI = -200;
|
||||
constexpr int32_t DEFAULT_SCAN_INTERVAL = 10 * 1000; // ms
|
||||
constexpr int64_t BLOCKLIST_VALID_TIME = 120 * 1000; // ms
|
||||
}
|
||||
|
||||
DEFINE_WIFILOG_LABEL("WifiProStateMachine");
|
||||
|
||||
WifiProStateMachine::WifiProStateMachine(int32_t instId)
|
||||
: StateMachine(WIFI_PRO_STATE_MACHINE),
|
||||
instId_(instId)
|
||||
{
|
||||
WIFI_LOGI("Enter WifiProStateMachine");
|
||||
}
|
||||
|
||||
WifiProStateMachine::~WifiProStateMachine()
|
||||
{
|
||||
WIFI_LOGI("Enter ~WifiProStateMachine");
|
||||
StopHandlerThread();
|
||||
ParsePointer(pDefaultState_);
|
||||
ParsePointer(pWifiProEnableState_);
|
||||
ParsePointer(pWifiProDisabledState_);
|
||||
ParsePointer(pWifiConnectedState_);
|
||||
ParsePointer(pWifiDisConnectedState_);
|
||||
ParsePointer(pWifiLinkMonitorState_);
|
||||
}
|
||||
|
||||
void WifiProStateMachine::BuildStateTree()
|
||||
{
|
||||
StatePlus(pDefaultState_, nullptr);
|
||||
StatePlus(pWifiProEnableState_, pDefaultState_);
|
||||
StatePlus(pWifiProDisabledState_, pDefaultState_);
|
||||
StatePlus(pWifiConnectedState_, pWifiProEnableState_);
|
||||
StatePlus(pWifiDisConnectedState_, pWifiProEnableState_);
|
||||
StatePlus(pWifiLinkMonitorState_, pWifiProEnableState_);
|
||||
}
|
||||
|
||||
ErrCode WifiProStateMachine::InitWifiProStates()
|
||||
{
|
||||
WIFI_LOGI("Enter InitWifiProStates");
|
||||
int32_t tmpErrNumber;
|
||||
pDefaultState_ = new (std::nothrow)DefaultState(this);
|
||||
tmpErrNumber = JudgmentEmpty(pDefaultState_);
|
||||
pWifiProEnableState_ = new (std::nothrow)WifiProEnableState(this);
|
||||
tmpErrNumber += JudgmentEmpty(pWifiProEnableState_);
|
||||
pWifiProDisabledState_ = new (std::nothrow)WifiProDisabledState(this);
|
||||
tmpErrNumber += JudgmentEmpty(pWifiProDisabledState_);
|
||||
pWifiConnectedState_ = new (std::nothrow)WifiConnectedState(this);
|
||||
tmpErrNumber += JudgmentEmpty(pWifiConnectedState_);
|
||||
pWifiDisConnectedState_ = new (std::nothrow)WifiDisConnectedState(this);
|
||||
tmpErrNumber += JudgmentEmpty(pWifiDisConnectedState_);
|
||||
pWifiLinkMonitorState_ = new (std::nothrow)WifiLinkMonitorState(this);
|
||||
tmpErrNumber += JudgmentEmpty(pWifiLinkMonitorState_);
|
||||
if (tmpErrNumber != 0) {
|
||||
WIFI_LOGE("InitWifiProStates someone state is null");
|
||||
return WIFI_OPT_FAILED;
|
||||
}
|
||||
return WIFI_OPT_SUCCESS;
|
||||
}
|
||||
|
||||
ErrCode WifiProStateMachine::Initialize()
|
||||
{
|
||||
if (!InitialStateMachine(WIFI_PRO_STATE_MACHINE)) {
|
||||
WIFI_LOGE("Initial WifiProStateMachine failed.");
|
||||
return WIFI_OPT_FAILED;
|
||||
}
|
||||
if (InitWifiProStates() == WIFI_OPT_FAILED) {
|
||||
return WIFI_OPT_FAILED;
|
||||
}
|
||||
BuildStateTree();
|
||||
SetFirstState(pWifiProEnableState_);
|
||||
StartStateMachine();
|
||||
return WIFI_OPT_SUCCESS;
|
||||
}
|
||||
|
||||
bool WifiProStateMachine::IsKeepCurrWifiConnected()
|
||||
{
|
||||
if (WifiProUtils::IsUserSelectNetwork() && (!isWifiNoInternet_)) {
|
||||
WIFI_LOGI("IsKeepCurrWifiConnected, user select network.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (WifiProUtils::IsAppInWhiteLists()) {
|
||||
WIFI_LOGI("IsKeepCurrWifiConnected, in app white lists.");
|
||||
return true;
|
||||
}
|
||||
|
||||
// AP+STA scene, do not switch
|
||||
WifiOprMidState curState = WifiConfigCenter::GetInstance().GetApMidState(instId_);
|
||||
if (curState == WifiOprMidState::RUNNING) {
|
||||
WIFI_LOGI("IsKeepCurrWifiConnected, ap is running, do not switch");
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool WifiProStateMachine::HasWifiSwitchRecord()
|
||||
{
|
||||
RefreshConnectedNetWork();
|
||||
if (pCurrWifiInfo_ == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (pCurrWifiDeviceConfig_ != nullptr && pCurrWifiDeviceConfig_->lastTrySwitchWifiTimestamp > 0) {
|
||||
int64_t now = WifiProUtils::GetCurrentTimeMs();
|
||||
// less than 14 days
|
||||
if (now - pCurrWifiDeviceConfig_->lastTrySwitchWifiTimestamp < WIFI_SWITCH_RECORD_MAX_TIME) {
|
||||
WIFI_LOGI("HasWifiSwitchRecord, has switch record in 14 days");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void WifiProStateMachine::RefreshConnectedNetWork()
|
||||
{
|
||||
WifiLinkedInfo linkedInfo;
|
||||
WifiConfigCenter::GetInstance().GetLinkedInfo(linkedInfo);
|
||||
WIFI_LOGI("RefreshConnectedNetWork, connState:%{public}d,"
|
||||
"supplicantState:%{public}d.", linkedInfo.connState, static_cast<int32_t>(linkedInfo.supplicantState));
|
||||
if (!WifiProUtils::IsSupplicantConnecting(linkedInfo.supplicantState)) {
|
||||
currentBssid_ = "";
|
||||
currentSsid_ = "";
|
||||
currentRssi_ = DEFAULT_RSSI;
|
||||
return;
|
||||
}
|
||||
|
||||
pCurrWifiInfo_ = std::make_shared<WifiLinkedInfo>(linkedInfo);
|
||||
currentBssid_ = linkedInfo.bssid;
|
||||
currentSsid_ = linkedInfo.ssid;
|
||||
currentRssi_ = linkedInfo.rssi;
|
||||
std::vector<WifiDeviceConfig> configs;
|
||||
WifiSettings::GetInstance().GetDeviceConfig(configs);
|
||||
if (configs.empty()) {
|
||||
WIFI_LOGI("RefreshConnectedNetWork, config is empty");
|
||||
return;
|
||||
}
|
||||
for (auto &wifiDeviceConfig : configs) {
|
||||
if (wifiDeviceConfig.networkId == linkedInfo.networkId) {
|
||||
WIFI_LOGI("RefreshConnectedNetWork, find device config,connState:%{public}d,"
|
||||
"networkId:%{public}d.", linkedInfo.connState, linkedInfo.networkId);
|
||||
pCurrWifiDeviceConfig_ = std::make_shared<WifiDeviceConfig>(wifiDeviceConfig);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool WifiProStateMachine::IsReachWifiScanThreshold(int32_t signalLevel)
|
||||
{
|
||||
WIFI_LOGI("IsReachWifiScanThreshold, rssiLevel:%{public}d.", signalLevel);
|
||||
if (signalLevel == SIG_LEVEL_4) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (signalLevel < SIG_LEVEL_3) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (HasWifiSwitchRecord()) {
|
||||
WIFI_LOGI("IsReachWifiScanThreshold, ap is not strong enough, and has switch record.");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (HasAvailableSsidToSwitch()) {
|
||||
WIFI_LOGI("IsReachWifiScanThreshold, ap is not strong enough, and has available ap.");
|
||||
return true;
|
||||
}
|
||||
|
||||
WIFI_LOGI("IsReachWifiScanThreshold, ap is not strong enough, no need to switch.");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool WifiProStateMachine::HasAvailableSsidToSwitch()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
/* --------------------------- state machine default state ------------------------------ */
|
||||
WifiProStateMachine::DefaultState::DefaultState(WifiProStateMachine *pWifiProStateMachine)
|
||||
: State("DefaultState"),
|
||||
pWifiProStateMachine_(pWifiProStateMachine)
|
||||
{
|
||||
WIFI_LOGD("DefaultState construct success.");
|
||||
}
|
||||
|
||||
WifiProStateMachine::DefaultState::~DefaultState() {}
|
||||
|
||||
void WifiProStateMachine::DefaultState::GoInState()
|
||||
{
|
||||
WIFI_LOGI("Enter DefaultState GoInState function.");
|
||||
}
|
||||
|
||||
void WifiProStateMachine::DefaultState::GoOutState()
|
||||
{
|
||||
WIFI_LOGI("Enter DefaultState GoOutState function.");
|
||||
}
|
||||
|
||||
bool WifiProStateMachine::DefaultState::ExecuteStateMsg(InternalMessagePtr msg)
|
||||
{
|
||||
if (msg == nullptr) {
|
||||
return false;
|
||||
}
|
||||
WIFI_LOGD("DefaultState-msgCode=%{public}d is received.", msg->GetMessageName());
|
||||
switch (msg->GetMessageName()) {
|
||||
case EVENT_NOTIFY_WIFI_PRO_SWITCH_CHANGED:
|
||||
HandleWifiProSwitchChanged(msg);
|
||||
break;
|
||||
case EVENT_REMOVE_BLOCK_LIST:
|
||||
HandleRemoveBlockList(msg);
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void WifiProStateMachine::DefaultState::HandleRemoveBlockList(const InternalMessagePtr msg)
|
||||
{
|
||||
if (msg == nullptr) {
|
||||
WIFI_LOGE("HandleRemoveBlockList: msg is nullptr.");
|
||||
return;
|
||||
}
|
||||
|
||||
std::string bssid;
|
||||
msg->GetMessageObj(bssid);
|
||||
NetworkBlockListManager::GetInstance().RemoveWifiBlocklist(bssid);
|
||||
}
|
||||
|
||||
void WifiProStateMachine::DefaultState::HandleWifiProSwitchChanged(const InternalMessagePtr msg)
|
||||
{
|
||||
// the wifiPro switch is on by default
|
||||
pWifiProStateMachine_->isWifiProEnabled_ = true;
|
||||
WIFI_LOGI("state transition: DefaultState -> WifiProEnableState.");
|
||||
pWifiProStateMachine_->SwitchState(pWifiProStateMachine_->pWifiProEnableState_);
|
||||
}
|
||||
|
||||
/* --------------------------- state machine enbale state ------------------------------ */
|
||||
WifiProStateMachine::WifiProEnableState::WifiProEnableState(WifiProStateMachine *pWifiProStateMachine)
|
||||
: State("WifiProEnableState"),
|
||||
pWifiProStateMachine_(pWifiProStateMachine)
|
||||
{
|
||||
WIFI_LOGD("Enter WifiProEnableState.");
|
||||
}
|
||||
|
||||
WifiProStateMachine::WifiProEnableState::~WifiProEnableState()
|
||||
{
|
||||
WIFI_LOGD("Enter ~WifiProEnableState.");
|
||||
}
|
||||
|
||||
void WifiProStateMachine::WifiProEnableState::GoInState()
|
||||
{
|
||||
WIFI_LOGI("WifiProEnableState GoInState function.");
|
||||
pWifiProStateMachine_->isWifiNoInternet_ = false;
|
||||
TransitionNetState();
|
||||
}
|
||||
|
||||
void WifiProStateMachine::WifiProEnableState::GoOutState()
|
||||
{
|
||||
WIFI_LOGI("WifiProEnableState GoOutState function.");
|
||||
}
|
||||
|
||||
bool WifiProStateMachine::WifiProEnableState::ExecuteStateMsg(InternalMessagePtr msg)
|
||||
{
|
||||
if (msg == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
WIFI_LOGD("WifiProEnableState-msgCode=%{public}d is received.", msg->GetMessageName());
|
||||
switch (msg->GetMessageName()) {
|
||||
case EVENT_WIFI_CONNECT_STATE_CHANGED:
|
||||
HandleWifiConnectStateChangedInEnableState(msg);
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void WifiProStateMachine::WifiProEnableState::TransitionNetState()
|
||||
{
|
||||
if (WifiProUtils::IsWifiConnected(pWifiProStateMachine_->instId_)) {
|
||||
WIFI_LOGI("state transition: WifiProEnableState -> WifiConnectedState.");
|
||||
pWifiProStateMachine_->SwitchState(pWifiProStateMachine_->pWifiConnectedState_);
|
||||
} else {
|
||||
WIFI_LOGI("state transition: WifiProEnableState -> WifiDisConnectedStat.");
|
||||
pWifiProStateMachine_->SwitchState(pWifiProStateMachine_->pWifiDisConnectedState_);
|
||||
}
|
||||
}
|
||||
|
||||
void WifiProStateMachine::WifiProEnableState::HandleWifiConnectStateChangedInEnableState(const InternalMessagePtr msg)
|
||||
{
|
||||
int32_t state = msg->GetParam1();
|
||||
if (state == static_cast<int32_t>(OperateResState::CONNECT_AP_CONNECTED)) {
|
||||
WIFI_LOGI("state transition: WifiProEnableState -> WifiConnectedState.");
|
||||
pWifiProStateMachine_->SwitchState(pWifiProStateMachine_->pWifiConnectedState_);
|
||||
} else if (state == static_cast<int32_t>(OperateResState::DISCONNECT_DISCONNECTED)) {
|
||||
WIFI_LOGI("state transition: WifiProEnableState -> WifiDisConnectedStat.");
|
||||
pWifiProStateMachine_->SwitchState(pWifiProStateMachine_->pWifiDisConnectedState_);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------- state machine disbaled state ------------------------------ */
|
||||
WifiProStateMachine::WifiProDisabledState::WifiProDisabledState(WifiProStateMachine *pWifiProStateMachine)
|
||||
: State("WifiProDisabledState"),
|
||||
pWifiProStateMachine_(pWifiProStateMachine)
|
||||
{
|
||||
WIFI_LOGD("WifiProDisabledState construct success.");
|
||||
}
|
||||
|
||||
WifiProStateMachine::WifiProDisabledState::~WifiProDisabledState() {}
|
||||
|
||||
void WifiProStateMachine::WifiProDisabledState::GoInState()
|
||||
{
|
||||
WIFI_LOGI("WifiProDisabledState GoInState function.");
|
||||
}
|
||||
|
||||
void WifiProStateMachine::WifiProDisabledState::GoOutState()
|
||||
{
|
||||
WIFI_LOGI("WifiProDisabledState GoOutState function.");
|
||||
}
|
||||
|
||||
bool WifiProStateMachine::WifiProDisabledState::ExecuteStateMsg(InternalMessagePtr msg)
|
||||
{
|
||||
if (msg == nullptr) {
|
||||
return false;
|
||||
}
|
||||
WIFI_LOGD("WifiProDisabledState-msgCode=%{public}d is received.", msg->GetMessageName());
|
||||
switch (msg->GetMessageName()) {
|
||||
case EVENT_NOTIFY_WIFI_PRO_SWITCH_CHANGED:
|
||||
HandleWifiProSwitchChanged(msg);
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void WifiProStateMachine::WifiProDisabledState::HandleWifiProSwitchChanged(const InternalMessagePtr msg)
|
||||
{
|
||||
pWifiProStateMachine_->isWifiProEnabled_ = static_cast<bool>(msg->GetParam1());
|
||||
if (pWifiProStateMachine_->isWifiProEnabled_) {
|
||||
WIFI_LOGI("state transition: WifiProDisabledState -> WifiProEnableState.");
|
||||
pWifiProStateMachine_->SwitchState(pWifiProStateMachine_->pWifiProEnableState_);
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------- state machine connected state ------------------------------ */
|
||||
WifiProStateMachine::WifiConnectedState::WifiConnectedState(WifiProStateMachine *pWifiProStateMachine)
|
||||
: State("WifiConnectedState"),
|
||||
pWifiProStateMachine_(pWifiProStateMachine)
|
||||
{
|
||||
WIFI_LOGD("WifiConnectedState construct success.");
|
||||
}
|
||||
|
||||
WifiProStateMachine::WifiConnectedState::~WifiConnectedState() {}
|
||||
|
||||
void WifiProStateMachine::WifiConnectedState::GoInState()
|
||||
{
|
||||
WIFI_LOGI("WifiConnectedState GoInState function.");
|
||||
pWifiProStateMachine_->RefreshConnectedNetWork();
|
||||
WifiLinkedInfo linkedInfo;
|
||||
WifiConfigCenter::GetInstance().GetLinkedInfo(linkedInfo);
|
||||
auto &networkBlackListManager = NetworkBlockListManager::GetInstance();
|
||||
if (networkBlackListManager.IsInTempWifiBlockList(linkedInfo.bssid)) {
|
||||
networkBlackListManager.CleanTempWifiBlockList();
|
||||
}
|
||||
InitConnectedState();
|
||||
}
|
||||
|
||||
void WifiProStateMachine::WifiConnectedState::GoOutState()
|
||||
{
|
||||
WIFI_LOGI("WifiConnectedState GoOutState function.");
|
||||
return;
|
||||
}
|
||||
|
||||
bool WifiProStateMachine::WifiConnectedState::ExecuteStateMsg(InternalMessagePtr msg)
|
||||
{
|
||||
if (msg == nullptr) {
|
||||
return false;
|
||||
}
|
||||
WIFI_LOGD("WifiConnectedState-msgCode=%{public}d is received.", msg->GetMessageName());
|
||||
switch (msg->GetMessageName()) {
|
||||
case EVENT_CHECK_WIFI_INTERNET_RESULT:
|
||||
HandleCheckWifiInternetResultWithConnected(msg);
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void WifiProStateMachine::WifiConnectedState::InitConnectedState()
|
||||
{
|
||||
if (pWifiProStateMachine_->duanBandHandoverType_ == ROAM_SCENE) {
|
||||
pWifiProStateMachine_->duanBandHandoverType_ = 0;
|
||||
} else {
|
||||
pWifiProStateMachine_->isWifiNoInternet_ = false;
|
||||
}
|
||||
}
|
||||
|
||||
void WifiProStateMachine::WifiConnectedState::HandleCheckWifiInternetResultWithConnected(const InternalMessagePtr msg)
|
||||
{
|
||||
int32_t state = msg->GetParam1();
|
||||
WIFI_LOGI("Enter HandleCheckWifiInternetResultWithConnected, state:%{public}d.", state);
|
||||
if (state == static_cast<int32_t>(OperateResState::CONNECT_NETWORK_DISABLED)) {
|
||||
HandleWifiInternetResultWithNoInet(state);
|
||||
} else if (state == static_cast<int32_t>(OperateResState::CONNECT_CHECK_PORTAL)) {
|
||||
HandleWifiInternetResultWithPortal(state);
|
||||
} else {
|
||||
HandleWifiInternetResultWithInet(state);
|
||||
}
|
||||
}
|
||||
|
||||
void WifiProStateMachine::WifiConnectedState::HandleWifiInternetResultWithInet(int32_t state)
|
||||
{
|
||||
pWifiProStateMachine_->isWifiNoInternet_ = false;
|
||||
UpdateWifiAgentScore(state);
|
||||
}
|
||||
|
||||
void WifiProStateMachine::WifiConnectedState::UpdateWifiAgentScore(int32_t state)
|
||||
{
|
||||
if (!pWifiProStateMachine_->disconnectToConnectedState_) {
|
||||
if (state == static_cast<int32_t>(OperateResState::CONNECT_NETWORK_DISABLED)) {
|
||||
WIFI_LOGI("UpdateWifiAgentScore, wifi network has no internet.");
|
||||
} else if (state == static_cast<int32_t>(OperateResState::CONNECT_CHECK_PORTAL)) {
|
||||
WIFI_LOGI("UpdateWifiAgentScore, wifi network is portal.");
|
||||
} else {
|
||||
WIFI_LOGI("state transition: WifiConnectedState -> WifiLinkMonitorState.");
|
||||
pWifiProStateMachine_->SwitchState(pWifiProStateMachine_->pWifiLinkMonitorState_);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
pWifiProStateMachine_->disconnectToConnectedState_ = false;
|
||||
}
|
||||
|
||||
void WifiProStateMachine::WifiConnectedState::HandleWifiInternetResultWithPortal(int32_t state)
|
||||
{
|
||||
// portal scene
|
||||
WIFI_LOGI("Enter HandleWifiInternetResultWithPortal.");
|
||||
}
|
||||
|
||||
void WifiProStateMachine::WifiConnectedState::HandleWifiInternetResultWithNoInet(int32_t state)
|
||||
{
|
||||
// no internet scene
|
||||
WIFI_LOGI("Enter HandleWifiInternetResultWithNoInet.");
|
||||
pWifiProStateMachine_->isWifiNoInternet_ = true;
|
||||
UpdateWifiAgentScore(state);
|
||||
}
|
||||
|
||||
/* --------------------------- state machine disconnected state ------------------------------ */
|
||||
WifiProStateMachine::WifiDisConnectedState::WifiDisConnectedState(WifiProStateMachine *pWifiProStateMachine)
|
||||
: State("WifiDisConnectedState"),
|
||||
pWifiProStateMachine_(pWifiProStateMachine)
|
||||
{
|
||||
WIFI_LOGD("WifiDisConnectedState construct success.");
|
||||
}
|
||||
|
||||
WifiProStateMachine::WifiDisConnectedState::~WifiDisConnectedState() {}
|
||||
|
||||
void WifiProStateMachine::WifiDisConnectedState::GoInState()
|
||||
{
|
||||
WIFI_LOGI("WifiDisConnectedState GoInState function.");
|
||||
}
|
||||
|
||||
void WifiProStateMachine::WifiDisConnectedState::GoOutState()
|
||||
{
|
||||
WIFI_LOGI("WifiDisConnectedState GoOutState function.");
|
||||
}
|
||||
|
||||
bool WifiProStateMachine::WifiDisConnectedState::ExecuteStateMsg(InternalMessagePtr msg)
|
||||
{
|
||||
if (msg == nullptr) {
|
||||
return false;
|
||||
}
|
||||
WIFI_LOGD("WifiDisConnectedState-msgCode=%{public}d is received.", msg->GetMessageName());
|
||||
switch (msg->GetMessageName()) {
|
||||
case EVENT_WIFI_CONNECT_STATE_CHANGED:
|
||||
HandleWifiConnectStateChangedInDisConnectedState(msg);
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void WifiProStateMachine::WifiDisConnectedState::HandleWifiConnectStateChangedInDisConnectedState(
|
||||
const InternalMessagePtr msg)
|
||||
{
|
||||
WIFI_LOGD("Enter HandleWifiConnectStateChangedInDisConnectedState.");
|
||||
int32_t state = msg->GetParam1();
|
||||
if (state == static_cast<int32_t>(OperateResState::CONNECT_AP_CONNECTED)) {
|
||||
WIFI_LOGI("state transition: WifiDisConnectedState -> WifiConnectedState.");
|
||||
pWifiProStateMachine_->SwitchState(pWifiProStateMachine_->pWifiConnectedState_);
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------- state machine link monitor state ------------------------------ */
|
||||
WifiProStateMachine::WifiLinkMonitorState::WifiLinkMonitorState(WifiProStateMachine *pWifiProStateMachine)
|
||||
: State("WifiLinkMonitorState"),
|
||||
pWifiProStateMachine_(pWifiProStateMachine)
|
||||
{
|
||||
WIFI_LOGD("WifiLinkMonitorState construct success.");
|
||||
}
|
||||
|
||||
WifiProStateMachine::WifiLinkMonitorState::~WifiLinkMonitorState() {}
|
||||
|
||||
void WifiProStateMachine::WifiLinkMonitorState::GoInState()
|
||||
{
|
||||
WIFI_LOGI("WifiLinkMonitorState GoInState function.");
|
||||
WifiLinkMonitorStateInit();
|
||||
}
|
||||
|
||||
void WifiProStateMachine::WifiLinkMonitorState::WifiLinkMonitorStateInit()
|
||||
{
|
||||
rssiLevel0Or1ScanedCounter_ = 0;
|
||||
rssiLevel2Or3ScanedCounter_ = 0;
|
||||
isScanTriggered_ = false;
|
||||
isWifi2WifiSwitching_ = false;
|
||||
targetBssid_ = "";
|
||||
}
|
||||
|
||||
void WifiProStateMachine::WifiLinkMonitorState::GoOutState()
|
||||
{
|
||||
WIFI_LOGI("WifiLinkMonitorState GoOutState function.");
|
||||
return;
|
||||
}
|
||||
|
||||
bool WifiProStateMachine::WifiLinkMonitorState::ExecuteStateMsg(InternalMessagePtr msg)
|
||||
{
|
||||
if (msg == nullptr) {
|
||||
return false;
|
||||
}
|
||||
WIFI_LOGD("WifiLinkMonitorState-msgCode=%{public}d is received.", msg->GetMessageName());
|
||||
switch (msg->GetMessageName()) {
|
||||
case EVENT_WIFI_RSSI_CHANGED:
|
||||
HandleRssiChangedInMonitor(msg);
|
||||
break;
|
||||
case EVENT_WIFI_CONNECT_STATE_CHANGED:
|
||||
HandleConnectStateChangedInMonitor(msg);
|
||||
break;
|
||||
case EVENT_REQUEST_SCAN_DELAY:
|
||||
HandleReuqestScanInMonitor(msg);
|
||||
break;
|
||||
case EVENT_HANDLE_SCAN_RESULT:
|
||||
HandleScanResultInMonitor(msg);
|
||||
break;
|
||||
case EVENT_CHECK_WIFI_INTERNET_RESULT:
|
||||
HandleHttpResultInLinkMonitorState(msg);
|
||||
break;
|
||||
case EVENT_WIFI2WIFI_FAILED:
|
||||
HandleWifi2WifiFailed(false);
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void WifiProStateMachine::WifiLinkMonitorState::HandleHttpResultInLinkMonitorState(const InternalMessagePtr msg)
|
||||
{
|
||||
int32_t operateResState = msg->GetParam1();
|
||||
bool isWifiNoInternet = (operateResState != static_cast<int32_t>(OperateResState::CONNECT_NETWORK_ENABLED));
|
||||
if (isWifiNoInternet) {
|
||||
pWifiProStateMachine_->isWifiNoInternet_ = true;
|
||||
} else {
|
||||
pWifiProStateMachine_->isWifiNoInternet_ = false;
|
||||
}
|
||||
}
|
||||
|
||||
void WifiProStateMachine::WifiLinkMonitorState::HandleRssiChangedInMonitor(const InternalMessagePtr msg)
|
||||
{
|
||||
pWifiProStateMachine_->currentRssi_ = msg->GetParam1();
|
||||
if ((isWifi2WifiSwitching_) || (pWifiProStateMachine_->isWifiNoInternet_)) {
|
||||
WIFI_LOGI("MonitorState, isWifi2WifiSwitching:%{public}d,isWifiNoInternet:%{public}d.",
|
||||
isWifi2WifiSwitching_, pWifiProStateMachine_->isWifiNoInternet_);
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t signalLevel = WifiProUtils::GetSignalLevel(pWifiProStateMachine_->instId_);
|
||||
WIFI_LOGI("MonitorState, signalLevel:%{public}d.", signalLevel);
|
||||
bool hasSwitchRecord = pWifiProStateMachine_->HasWifiSwitchRecord();
|
||||
if (signalLevel == SIG_LEVEL_4 && hasSwitchRecord) {
|
||||
rssiLevel2Or3ScanedCounter_ = 0;
|
||||
rssiLevel0Or1ScanedCounter_ = 0;
|
||||
}
|
||||
|
||||
if (!pWifiProStateMachine_->IsReachWifiScanThreshold(signalLevel)) {
|
||||
WIFI_LOGI("HandleRssiChangedInMonitor, StopTimer EVENT_REQUEST_SCAN_DELAY.");
|
||||
pWifiProStateMachine_->StopTimer(EVENT_REQUEST_SCAN_DELAY);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!IsSatisfiedWifiOperationCondition()) {
|
||||
return;
|
||||
}
|
||||
|
||||
pWifiProStateMachine_->StopTimer(EVENT_REQUEST_SCAN_DELAY);
|
||||
pWifiProStateMachine_->SendMessage(EVENT_REQUEST_SCAN_DELAY, static_cast<int32_t>(hasSwitchRecord));
|
||||
}
|
||||
|
||||
void WifiProStateMachine::WifiLinkMonitorState::HandleReuqestScanInMonitor(const InternalMessagePtr msg)
|
||||
{
|
||||
if (msg == nullptr) {
|
||||
WIFI_LOGI("HandleReuqestScanInMonitor, msg is nullptr.");
|
||||
return;
|
||||
}
|
||||
|
||||
// selfcure onging, pending scan for 10s
|
||||
ISelfCureService *pSelfCureService =
|
||||
WifiServiceManager::GetInstance().GetSelfCureServiceInst(pWifiProStateMachine_->instId_);
|
||||
bool hasSwitchRecord = static_cast<bool>(msg->GetParam1());
|
||||
if (pSelfCureService != nullptr && pSelfCureService->IsSelfCureOnGoing()) {
|
||||
WIFI_LOGI("HandleReuqestScanInMonitor: self cure is ongoing.");
|
||||
pWifiProStateMachine_->StopTimer(EVENT_REQUEST_SCAN_DELAY);
|
||||
pWifiProStateMachine_->MessageExecutedLater(EVENT_REQUEST_SCAN_DELAY, hasSwitchRecord, DEFAULT_SCAN_INTERVAL);
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t signalLevel = WifiProUtils::GetSignalLevel(pWifiProStateMachine_->instId_);
|
||||
if (!pWifiProStateMachine_->IsReachWifiScanThreshold(signalLevel)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (WifiProUtils::IsUserSelectNetwork() && signalLevel == SIG_LEVEL_2) {
|
||||
WIFI_LOGI("HandleReuqestScanInMonitor, user select network and signal = 2.");
|
||||
return;
|
||||
}
|
||||
|
||||
TryStartScan(hasSwitchRecord, signalLevel);
|
||||
}
|
||||
|
||||
void WifiProStateMachine::WifiLinkMonitorState::TryStartScan(bool hasSwitchRecord, int32_t signalLevel)
|
||||
{
|
||||
// calculate the interval and the max scan counter.
|
||||
IScanService *pScanService = WifiServiceManager::GetInstance().GetScanServiceInst(pWifiProStateMachine_->instId_);
|
||||
if (pScanService == nullptr) {
|
||||
WIFI_LOGI("TryStartScan, pService is nullptr.");
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t scanInterval = WifiProUtils::GetScanInterval(hasSwitchRecord, signalLevel);
|
||||
int32_t scanMaxCounter = WifiProUtils::GetMaxCounter(hasSwitchRecord, signalLevel);
|
||||
if ((signalLevel == SIG_LEVEL_2 || signalLevel == SIG_LEVEL_3) &&
|
||||
rssiLevel2Or3ScanedCounter_ < scanMaxCounter) {
|
||||
WIFI_LOGI("TryStartScan, start scan, signalLevel:%{public}d,"
|
||||
"rssiLevel2Or3ScanedCounter:%{public}d.", signalLevel, rssiLevel2Or3ScanedCounter_);
|
||||
rssiLevel2Or3ScanedCounter_++;
|
||||
pScanService->Scan(true);
|
||||
isScanTriggered_ = true;
|
||||
pWifiProStateMachine_->MessageExecutedLater(EVENT_REQUEST_SCAN_DELAY, hasSwitchRecord, scanInterval);
|
||||
} else if ((signalLevel < SIG_LEVEL_2) && (rssiLevel0Or1ScanedCounter_ < scanMaxCounter)) {
|
||||
WIFI_LOGI("TryStartScan, start scan, signalLevel:%{public}d,"
|
||||
"rssiLevel0Or1ScanedCounter:%{public}d.", signalLevel, rssiLevel0Or1ScanedCounter_);
|
||||
rssiLevel0Or1ScanedCounter_++;
|
||||
pScanService->Scan(true);
|
||||
isScanTriggered_ = true;
|
||||
pWifiProStateMachine_->MessageExecutedLater(EVENT_REQUEST_SCAN_DELAY, hasSwitchRecord, scanInterval);
|
||||
} else {
|
||||
WIFI_LOGI("TryStartScan, do not scan, signalLevel:%{public}d,scanMaxCounter:%{public}d.",
|
||||
signalLevel, scanMaxCounter);
|
||||
}
|
||||
}
|
||||
|
||||
void WifiProStateMachine::WifiLinkMonitorState::HandleScanResultInMonitor(const InternalMessagePtr msg)
|
||||
{
|
||||
if (msg == nullptr) {
|
||||
WIFI_LOGI("HandleScanResultInMonitor, msg is nullptr.");
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<InterScanInfo> scanInfos;
|
||||
msg->GetMessageObj(scanInfos);
|
||||
|
||||
if (!isScanTriggered_) {
|
||||
WIFI_LOGI("HandleScanResultInMonitor, scan is not triggered, skip network selection.");
|
||||
return;
|
||||
}
|
||||
|
||||
WIFI_LOGI("start to wifi2wifi select network.");
|
||||
std::unique_ptr<NetworkSelectionManager> pNetworkSelectionManager = std::make_unique<NetworkSelectionManager>();
|
||||
NetworkSelectionResult networkSelectionResult;
|
||||
if (pNetworkSelectionManager->SelectNetwork(networkSelectionResult, NetworkSelectType::WIFI2WIFI, scanInfos)) {
|
||||
int32_t networkId = networkSelectionResult.wifiDeviceConfig.networkId;
|
||||
std::string &bssid = networkSelectionResult.interScanInfo.bssid;
|
||||
std::string &ssid = networkSelectionResult.interScanInfo.ssid;
|
||||
WIFI_LOGI("Wifi2Wifi select network result networkId: %{public}d, ssid: %{public}s, bssid: %{public}s.",
|
||||
networkId, SsidAnonymize(ssid).c_str(), MacAnonymize(bssid).c_str());
|
||||
targetBssid_ = networkSelectionResult.interScanInfo.bssid;
|
||||
isScanTriggered_ = false;
|
||||
HandleCheckResultInMonitor(networkSelectionResult);
|
||||
} else {
|
||||
WIFI_LOGI("wifi to wifi step X: Wifi2Wifi select network fail.");
|
||||
Wifi2WifiFailed();
|
||||
}
|
||||
}
|
||||
|
||||
bool WifiProStateMachine::WifiLinkMonitorState::IsSatisfiedWifiOperationCondition()
|
||||
{
|
||||
if (pWifiProStateMachine_->isWifiNoInternet_) {
|
||||
WIFI_LOGI("IsSatisfiedWifiOperationCondition, wifi no internet.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isWifi2WifiSwitching_) {
|
||||
WIFI_LOGI("IsSatisfiedWifiOperationCondition, wifi2Wifi is processing.");
|
||||
return false;
|
||||
}
|
||||
|
||||
ISelfCureService *pSelfCureService =
|
||||
WifiServiceManager::GetInstance().GetSelfCureServiceInst(pWifiProStateMachine_->instId_);
|
||||
if (pSelfCureService != nullptr && pSelfCureService->IsSelfCureOnGoing()) {
|
||||
WIFI_LOGI("IsSatisfiedWifiOperationCondition, self cure ongoing.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void WifiProStateMachine::WifiLinkMonitorState::HandleConnectStateChangedInMonitor(
|
||||
const InternalMessagePtr msg)
|
||||
{
|
||||
if (msg == nullptr) {
|
||||
WIFI_LOGI("HandleConnectStateChangedInMonitor, msg is nullptr.");
|
||||
return;
|
||||
}
|
||||
|
||||
WIFI_LOGI("receive wifi2wifi Result,isWifi2WifiSwitching = %{public}d.", isWifi2WifiSwitching_);
|
||||
int32_t state = msg->GetParam1();
|
||||
std::string bssid;
|
||||
msg->GetMessageObj(bssid);
|
||||
if (state == static_cast<int32_t>(OperateResState::CONNECT_AP_CONNECTED)) {
|
||||
if (!isWifi2WifiSwitching_) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (targetBssid_ != bssid) {
|
||||
WIFI_LOGI("selected bssid and switched bssid are not same:selected bssid:%{public}s,"
|
||||
"switched bssid:%{public}s,",
|
||||
MacAnonymize(targetBssid_).c_str(), MacAnonymize(bssid).c_str());
|
||||
NetworkBlockListManager::GetInstance().AddWifiBlocklist(bssid);
|
||||
pWifiProStateMachine_->MessageExecutedLater(EVENT_REMOVE_BLOCK_LIST, bssid, BLOCKLIST_VALID_TIME);
|
||||
HandleWifi2WifiFailed(true);
|
||||
} else {
|
||||
HandleWifi2WifiSucsess();
|
||||
}
|
||||
} else if (state == static_cast<int32_t>(OperateResState::DISCONNECT_DISCONNECTED)) {
|
||||
WIFI_LOGI("Monitor State, network disconnected");
|
||||
if (!isWifi2WifiSwitching_) {
|
||||
pWifiProStateMachine_->SwitchState(pWifiProStateMachine_->pWifiDisConnectedState_);
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void WifiProStateMachine::WifiLinkMonitorState::HandleWifi2WifiSucsess()
|
||||
{
|
||||
WIFI_LOGI("Enter HandleWifi2WifiSucsess");
|
||||
auto &networkBlackListManager = NetworkBlockListManager::GetInstance();
|
||||
networkBlackListManager.AddWifiBlocklist(pWifiProStateMachine_->badBssid_);
|
||||
pWifiProStateMachine_->MessageExecutedLater(EVENT_REMOVE_BLOCK_LIST, pWifiProStateMachine_->badBssid_,
|
||||
BLOCKLIST_VALID_TIME);
|
||||
networkBlackListManager.CleanTempWifiBlockList();
|
||||
pWifiProStateMachine_->RefreshConnectedNetWork();
|
||||
isWifi2WifiSwitching_ = false;
|
||||
WIFI_LOGI("state transition: WifiLinkMonitorState -> WifiConnectedState.");
|
||||
pWifiProStateMachine_->SwitchState(pWifiProStateMachine_->pWifiConnectedState_);
|
||||
}
|
||||
|
||||
void WifiProStateMachine::WifiLinkMonitorState::HandleWifi2WifiFailed(bool isConnected)
|
||||
{
|
||||
WIFI_LOGI("wifi to wifi step X: wifi to Wifi Failed Finally.");
|
||||
auto &networkBlackListManager = NetworkBlockListManager::GetInstance();
|
||||
if (networkBlackListManager.IsFailedMultiTimes(targetBssid_)) {
|
||||
WIFI_LOGI("HandleWifi2WifiFailed, add to abnormal black list:%{public}s.",
|
||||
MacAnonymize(targetBssid_).c_str());
|
||||
networkBlackListManager.AddAbnormalWifiBlocklist(targetBssid_);
|
||||
networkBlackListManager.CleanTempWifiBlockList();
|
||||
}
|
||||
isWifi2WifiSwitching_ = false;
|
||||
isScanTriggered_ = false;
|
||||
pWifiProStateMachine_->badBssid_ = "";
|
||||
targetBssid_ = "";
|
||||
if (isConnected) {
|
||||
pWifiProStateMachine_->SwitchState(pWifiProStateMachine_->pWifiConnectedState_);
|
||||
} else {
|
||||
pWifiProStateMachine_->SwitchState(pWifiProStateMachine_->pWifiDisConnectedState_);
|
||||
}
|
||||
}
|
||||
|
||||
void WifiProStateMachine::WifiLinkMonitorState::HandleCheckResultInMonitor(
|
||||
const NetworkSelectionResult &networkSelectionResult)
|
||||
{
|
||||
WIFI_LOGI("wifi to wifi step 2: receive good ap in monitor state.");
|
||||
if (!IsSatisfiedWifiOperationCondition()) {
|
||||
WIFI_LOGI("wifi to wifi step 3: target AP is not reach handover threshold.");
|
||||
return;
|
||||
}
|
||||
|
||||
// rssi conditions and Wifi2WifiThreshold conditions have been considered when selecting a network.
|
||||
WIFI_LOGI("wifi to wifi step 3: target AP reach handover threshold.");
|
||||
// User preference is not considered for now
|
||||
TryWifiHandoverPreferentially(networkSelectionResult);
|
||||
}
|
||||
|
||||
void WifiProStateMachine::WifiLinkMonitorState::TryWifiHandoverPreferentially(
|
||||
const NetworkSelectionResult &networkSelectionResult)
|
||||
{
|
||||
int32_t signalLevel = WifiProUtils::GetSignalLevel(pWifiProStateMachine_->instId_);
|
||||
if (!pWifiProStateMachine_->IsReachWifiScanThreshold(signalLevel)) {
|
||||
WIFI_LOGI("TryWifiHandoverPreferentially, do not reach wifi scan threshold.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Non-default network does not switch
|
||||
if (!WifiProUtils::IsDefaultNet()) {
|
||||
WIFI_LOGI("TryWifiHandoverPreferentially, not default network, do not switch wifi.");
|
||||
return;
|
||||
}
|
||||
|
||||
WIFI_LOGW("try wifi --> wifi only, current rssi:%{public}d.", signalLevel);
|
||||
TryWifiRoveOut(networkSelectionResult);
|
||||
}
|
||||
|
||||
void WifiProStateMachine::WifiLinkMonitorState::TryWifiRoveOut(const NetworkSelectionResult &networkSelectionResult)
|
||||
{
|
||||
WIFI_LOGI("wifi to wifi step 4: try wifi Rove Out.");
|
||||
if (pWifiProStateMachine_->IsKeepCurrWifiConnected()) {
|
||||
return;
|
||||
}
|
||||
|
||||
HandleWifiRoveOut(networkSelectionResult);
|
||||
}
|
||||
|
||||
void WifiProStateMachine::WifiLinkMonitorState::HandleWifiRoveOut(const NetworkSelectionResult &networkSelectionResult)
|
||||
{
|
||||
bool isCallingInCs = IsCallingInCs();
|
||||
if ((isDisableWifiAutoSwitch_) || isCallingInCs) {
|
||||
WIFI_LOGW("isDisableWifiAutoSwitch:%{public}d, isCallingInCs:%{public}d.",
|
||||
isDisableWifiAutoSwitch_, isCallingInCs);
|
||||
return;
|
||||
}
|
||||
|
||||
TryWifi2Wifi(networkSelectionResult);
|
||||
}
|
||||
|
||||
void WifiProStateMachine::WifiLinkMonitorState::TryWifi2Wifi(const NetworkSelectionResult &networkSelectionResult)
|
||||
{
|
||||
pWifiProStateMachine_->badBssid_ = pWifiProStateMachine_->currentBssid_;
|
||||
pWifiProStateMachine_->badSsid_ = pWifiProStateMachine_->currentSsid_;
|
||||
pWifiProStateMachine_->StopTimer(EVENT_REQUEST_SCAN_DELAY);
|
||||
|
||||
if (pWifiProStateMachine_->isWifiNoInternet_) {
|
||||
pWifiProStateMachine_->wifiSwitchReason_ = WIFI_SWITCH_REASON_NO_INTERNET;
|
||||
} else {
|
||||
pWifiProStateMachine_->wifiSwitchReason_ = WIFI_SWITCH_REASON_POOR_RSSI;
|
||||
}
|
||||
|
||||
if (!HandleWifiToWifi(pWifiProStateMachine_->wifiSwitchReason_, networkSelectionResult)) {
|
||||
WIFI_LOGI("wifi to wifi step X: HandleWifiToWifi Failed.");
|
||||
Wifi2WifiFailed();
|
||||
}
|
||||
}
|
||||
|
||||
void WifiProStateMachine::WifiLinkMonitorState::Wifi2WifiFailed()
|
||||
{
|
||||
isWifi2WifiSwitching_ = false;
|
||||
isScanTriggered_ = false;
|
||||
pWifiProStateMachine_->badBssid_ = "";
|
||||
targetBssid_ = "";
|
||||
}
|
||||
|
||||
bool WifiProStateMachine::WifiLinkMonitorState::HandleWifiToWifi(int32_t switchReason,
|
||||
const NetworkSelectionResult &networkSelectionResult)
|
||||
{
|
||||
WIFI_LOGI("wifi to wifi step 5: handle wifi2wifi command.");
|
||||
if (switchReason == WIFI_SWITCH_REASON_POOR_RSSI) {
|
||||
WIFI_LOGI("wifi to wifi step 5.5: direct wifi 2 wifi handover.");
|
||||
UpdateWifiSwitchTimeStamp();
|
||||
return TrySwitchWifiNetwork(networkSelectionResult);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void WifiProStateMachine::WifiLinkMonitorState::UpdateWifiSwitchTimeStamp()
|
||||
{
|
||||
int64_t now = WifiProUtils::GetCurrentTimeMs();
|
||||
WifiLinkedInfo linkedInfo;
|
||||
WifiDeviceConfig config;
|
||||
WifiConfigCenter::GetInstance().GetLinkedInfo(linkedInfo);
|
||||
if (WifiSettings::GetInstance().GetDeviceConfig(linkedInfo.networkId, config) == 0) {
|
||||
config.lastTrySwitchWifiTimestamp = now;
|
||||
WifiSettings::GetInstance().AddDeviceConfig(config);
|
||||
WifiSettings::GetInstance().SyncDeviceConfig();
|
||||
} else {
|
||||
WIFI_LOGI("UpdateWifiSwitchTimeStamp, get device config failed");
|
||||
}
|
||||
}
|
||||
|
||||
bool WifiProStateMachine::WifiLinkMonitorState::TrySwitchWifiNetwork(
|
||||
const NetworkSelectionResult &networkSelectionResult)
|
||||
{
|
||||
int32_t networkId = networkSelectionResult.wifiDeviceConfig.networkId;
|
||||
WIFI_LOGI("wifi to wifi step 7: start to connect to new wifi. networkId:%{public}d", networkId);
|
||||
IStaService *pStaService = WifiServiceManager::GetInstance().GetStaServiceInst(pWifiProStateMachine_->instId_);
|
||||
if (pStaService == nullptr) {
|
||||
WIFI_LOGE("TrySwitchWifiNetwork, pStaService is invalid");
|
||||
return false;
|
||||
}
|
||||
isWifi2WifiSwitching_ = true;
|
||||
if (pStaService->ConnectToNetwork(networkId, NETWORK_SELECTED_BY_AUTO) != WIFI_OPT_SUCCESS) {
|
||||
WIFI_LOGE("TrySwitchWifiNetwork, ConnectToNetwork failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WifiProStateMachine::WifiLinkMonitorState::IsCallingInCs()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool WifiProStateMachine::WifiLinkMonitorState::IsFullscreen()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
} // namespace Wifi
|
||||
} // namespace OHOS
|
@ -0,0 +1,230 @@
|
||||
/*
|
||||
* Copyright (C) 2024-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_WIFI_PRO_STATE_MACHINE_H
|
||||
#define OHOS_WIFI_PRO_STATE_MACHINE_H
|
||||
|
||||
#include "define.h"
|
||||
#include "wifi_log.h"
|
||||
#include "wifi_errcode.h"
|
||||
#include "state_machine.h"
|
||||
#include "wifi_pro_common.h"
|
||||
#include "network_selection_manager.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Wifi {
|
||||
class WifiProStateMachine : public StateMachine {
|
||||
FRIEND_GTEST(WifiProStateMachine);
|
||||
|
||||
public:
|
||||
explicit WifiProStateMachine(int32_t instId = 0);
|
||||
~WifiProStateMachine();
|
||||
|
||||
/**
|
||||
* @Description Definition of DefaultState class in WifiProStateMachine.
|
||||
*
|
||||
*/
|
||||
class DefaultState : public State {
|
||||
public:
|
||||
explicit DefaultState(WifiProStateMachine *pWifiProStateMachine);
|
||||
~DefaultState() override;
|
||||
void GoInState() override;
|
||||
void GoOutState() override;
|
||||
bool ExecuteStateMsg(InternalMessagePtr msg) override;
|
||||
private:
|
||||
WifiProStateMachine *pWifiProStateMachine_ { nullptr };
|
||||
void HandleWifiProSwitchChanged(const InternalMessagePtr msg);
|
||||
void HandleRemoveBlockList(const InternalMessagePtr msg);
|
||||
};
|
||||
|
||||
/**
|
||||
* @Description Definition of WifiProEnableState class in WifiProStateMachine.
|
||||
*
|
||||
*/
|
||||
class WifiProEnableState : public State {
|
||||
public:
|
||||
explicit WifiProEnableState(WifiProStateMachine *pWifiProStateMachine);
|
||||
~WifiProEnableState() override;
|
||||
void GoInState() override;
|
||||
void GoOutState() override;
|
||||
bool ExecuteStateMsg(InternalMessagePtr msg) override;
|
||||
private:
|
||||
WifiProStateMachine *pWifiProStateMachine_ { nullptr };
|
||||
void TransitionNetState();
|
||||
void HandleWifiConnectStateChangedInEnableState(const InternalMessagePtr msg);
|
||||
};
|
||||
|
||||
/**
|
||||
* @Description Definition of WifiProDisabledState class in WifiProStateMachine.
|
||||
*
|
||||
*/
|
||||
class WifiProDisabledState : public State {
|
||||
public:
|
||||
explicit WifiProDisabledState(WifiProStateMachine *pWifiProStateMachine);
|
||||
~WifiProDisabledState() override;
|
||||
void GoInState() override;
|
||||
void GoOutState() override;
|
||||
bool ExecuteStateMsg(InternalMessagePtr msg) override;
|
||||
private:
|
||||
WifiProStateMachine *pWifiProStateMachine_ { nullptr};
|
||||
void HandleWifiProSwitchChanged(const InternalMessagePtr msg);
|
||||
};
|
||||
|
||||
/**
|
||||
* @Description Definition of WifiConnectedState class in WifiProStateMachine.
|
||||
*
|
||||
*/
|
||||
class WifiConnectedState : public State {
|
||||
public:
|
||||
explicit WifiConnectedState(WifiProStateMachine *pWifiProStateMachine);
|
||||
~WifiConnectedState() override;
|
||||
void GoInState() override;
|
||||
void GoOutState() override;
|
||||
bool ExecuteStateMsg(InternalMessagePtr msg) override;
|
||||
private:
|
||||
WifiProStateMachine *pWifiProStateMachine_ { nullptr };
|
||||
int32_t internetFailureDetectedCount_ { 0 };
|
||||
void InitConnectedState();
|
||||
void HandleCheckWifiInternetResultWithConnected(const InternalMessagePtr msg);
|
||||
void HandleWifiInternetResultInLinkMonitorState();
|
||||
void HandleWifiInternetResultWithNoInet(int32_t state);
|
||||
void HandleWifiInternetResultWithPortal(int32_t state);
|
||||
void HandleWifiInternetResultWithInet(int32_t state);
|
||||
void UpdateWifiAgentScore(int32_t state);
|
||||
};
|
||||
|
||||
/**
|
||||
* @Description Definition of WifiDisConnectedState class in WifiProStateMachine.
|
||||
*
|
||||
*/
|
||||
class WifiDisConnectedState : public State {
|
||||
public:
|
||||
explicit WifiDisConnectedState(WifiProStateMachine *pWifiProStateMachine);
|
||||
~WifiDisConnectedState() override;
|
||||
void GoInState() override;
|
||||
void GoOutState() override;
|
||||
bool ExecuteStateMsg(InternalMessagePtr msg) override;
|
||||
private:
|
||||
WifiProStateMachine *pWifiProStateMachine_ { nullptr };
|
||||
void HandleWifiConnectStateChangedInDisConnectedState(const InternalMessagePtr msg);
|
||||
};
|
||||
|
||||
/**
|
||||
* @Description Definition of WifiLinkMonitorState class in WifiProStateMachine.
|
||||
*
|
||||
*/
|
||||
class WifiLinkMonitorState : public State {
|
||||
public:
|
||||
explicit WifiLinkMonitorState(WifiProStateMachine *pWifiProStateMachine);
|
||||
~WifiLinkMonitorState() override;
|
||||
void GoInState() override;
|
||||
void GoOutState() override;
|
||||
bool ExecuteStateMsg(InternalMessagePtr msg) override;
|
||||
private:
|
||||
WifiProStateMachine *pWifiProStateMachine_ { nullptr};
|
||||
bool isScanTriggered_ { false };
|
||||
bool isWifi2WifiSwitching_ { false };
|
||||
bool isDisableWifiAutoSwitch_ { false };
|
||||
int32_t rssiLevel2Or3ScanedCounter_ { 0 };
|
||||
int32_t rssiLevel0Or1ScanedCounter_ { 0 };
|
||||
std::string targetBssid_;
|
||||
NetworkSelectionResult networkSelectionResult_;
|
||||
void WifiLinkMonitorStateInit();
|
||||
void HandleCheckResultInMonitor(const NetworkSelectionResult &networkSelectionResult);
|
||||
bool IsSatisfiedWifiOperationCondition();
|
||||
bool IsFullscreen();
|
||||
void TryWifiHandoverPreferentially(const NetworkSelectionResult &networkSelectionResult);
|
||||
void TryWifiRoveOut(const NetworkSelectionResult &networkSelectionResult);
|
||||
void HandleWifiRoveOut(const NetworkSelectionResult &networkSelectionResult);
|
||||
bool IsCallingInCs();
|
||||
void TryWifi2Wifi(const NetworkSelectionResult &networkSelectionResult);
|
||||
void HandleConnectStateChangedInMonitor(const InternalMessagePtr msg);
|
||||
void HandleRssiChangedInMonitor(const InternalMessagePtr msg);
|
||||
void HandleReuqestScanInMonitor(const InternalMessagePtr msg);
|
||||
void HandleScanResultInMonitor(const InternalMessagePtr msg);
|
||||
void TryStartScan(bool hasSwitchRecord, int32_t signalLevel);
|
||||
void HandleHttpResultInLinkMonitorState(const InternalMessagePtr msg);
|
||||
void HandleWifi2WifiSucsess();
|
||||
void HandleWifi2WifiFailed(bool isConnected);
|
||||
void Wifi2WifiFailed();
|
||||
bool HandleWifiToWifi(int32_t switchReason, const NetworkSelectionResult &networkSelectionResult);
|
||||
void UpdateWifiSwitchTimeStamp();
|
||||
bool TrySwitchWifiNetwork(const NetworkSelectionResult &networkSelectionResult);
|
||||
};
|
||||
|
||||
ErrCode Initialize();
|
||||
|
||||
private:
|
||||
/**
|
||||
* @Description Destruct state.
|
||||
*
|
||||
*/
|
||||
template <typename T>
|
||||
inline void ParsePointer(T *&pointer)
|
||||
{
|
||||
if (pointer != nullptr) {
|
||||
delete pointer;
|
||||
pointer = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline ErrCode JudgmentEmpty(T *&pointer)
|
||||
{
|
||||
if (pointer == nullptr) {
|
||||
return WIFI_OPT_FAILED;
|
||||
}
|
||||
return WIFI_OPT_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Description Build state tree
|
||||
*
|
||||
*/
|
||||
void BuildStateTree();
|
||||
|
||||
ErrCode InitWifiProStates();
|
||||
|
||||
private:
|
||||
int32_t instId_ { 0 };
|
||||
DefaultState *pDefaultState_ { nullptr };
|
||||
WifiProEnableState *pWifiProEnableState_ { nullptr };
|
||||
WifiProDisabledState *pWifiProDisabledState_ { nullptr };
|
||||
WifiConnectedState *pWifiConnectedState_ { nullptr };
|
||||
WifiDisConnectedState *pWifiDisConnectedState_ { nullptr };
|
||||
WifiLinkMonitorState *pWifiLinkMonitorState_ { nullptr };
|
||||
/* 0:unknow 1:singleAP 2:Mixed Type */
|
||||
int32_t duanBandHandoverType_ { 0 };
|
||||
int32_t wiFiNoInternetReason_ { 0 };
|
||||
bool disconnectToConnectedState_ { false };
|
||||
bool isWifiProEnabled_ { true }; // enabled by default, it should be assigned according to the settings.
|
||||
bool isWifiNoInternet_ { false };
|
||||
std::string badBssid_ { 0 };
|
||||
std::string badSsid_ { 0 };
|
||||
int32_t wifiSwitchReason_ { 0 };
|
||||
int32_t currentRssi_ { 0 };
|
||||
std::string currentBssid_;
|
||||
std::string currentSsid_;
|
||||
std::shared_ptr<WifiLinkedInfo> pCurrWifiInfo_ { nullptr };
|
||||
std::shared_ptr<WifiDeviceConfig> pCurrWifiDeviceConfig_ { nullptr };
|
||||
bool IsKeepCurrWifiConnected();
|
||||
bool IsReachWifiScanThreshold(int32_t signalLevel);
|
||||
bool HasWifiSwitchRecord();
|
||||
void RefreshConnectedNetWork();
|
||||
bool HasAvailableSsidToSwitch();
|
||||
};
|
||||
} // namespace Wifi
|
||||
} // namespace OHOS
|
||||
#endif
|
@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright (C) 2024-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 <sys/time.h>
|
||||
#include "net_conn_client.h"
|
||||
#include "wifi_net_observer.h"
|
||||
#include "parameters.h"
|
||||
#include "wifi_config_center.h"
|
||||
#include "wifi_logger.h"
|
||||
#include "wifi_msg.h"
|
||||
#include "wifi_pro_utils.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Wifi {
|
||||
DEFINE_WIFILOG_LABEL("WifiProUtils");
|
||||
int32_t WifiProUtils::GetSignalLevel(int32_t instId)
|
||||
{
|
||||
WifiLinkedInfo linkedInfo;
|
||||
WifiConfigCenter::GetInstance().GetLinkedInfo(linkedInfo);
|
||||
return WifiSettings::GetInstance().GetSignalLevel(linkedInfo.rssi, linkedInfo.band, instId);
|
||||
}
|
||||
|
||||
bool WifiProUtils::IsWifiConnected(int32_t instId)
|
||||
{
|
||||
WifiLinkedInfo linkedInfo;
|
||||
WifiConfigCenter::GetInstance().GetLinkedInfo(linkedInfo, instId);
|
||||
return linkedInfo.connState == ConnState::CONNECTED;
|
||||
}
|
||||
|
||||
int32_t WifiProUtils::GetScanInterval(bool hasWifiSwitchRecord, int32_t rssiLevel)
|
||||
{
|
||||
if (rssiLevel >= SIG_LEVEL_MAX) {
|
||||
WIFI_LOGI("GetScanInterval, invalid rssiLevel:%{public}d.", rssiLevel);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return hasWifiSwitchRecord ? QUICK_SCAN_INTERVAL[rssiLevel] : NORMAL_SCAN_INTERVAL[rssiLevel];
|
||||
}
|
||||
|
||||
int32_t WifiProUtils::GetMaxCounter(bool hasWifiSwitchRecord, int32_t rssiLevel)
|
||||
{
|
||||
if (rssiLevel >= SIG_LEVEL_MAX) {
|
||||
WIFI_LOGI("GetMaxCounter, invalid rssiLevel:%{public}d.", rssiLevel);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return hasWifiSwitchRecord ? QUICK_SCAN_MAX_COUNTER[rssiLevel] : NORMAL_SCAN_MAX_COUNTER[rssiLevel];
|
||||
}
|
||||
|
||||
int64_t WifiProUtils::GetCurrentTimeMs()
|
||||
{
|
||||
auto timePoint = std::chrono::system_clock::now().time_since_epoch();
|
||||
return std::chrono::duration_cast<std::chrono::milliseconds>(timePoint).count();
|
||||
}
|
||||
|
||||
bool WifiProUtils::IsUserSelectNetwork()
|
||||
{
|
||||
return system::GetParameter("persist.wifi.is_connect_from_user", "") == "1";
|
||||
}
|
||||
|
||||
bool WifiProUtils::IsSupplicantConnecting(SupplicantState supplicantState)
|
||||
{
|
||||
return supplicantState == SupplicantState::AUTHENTICATING ||
|
||||
supplicantState == SupplicantState::ASSOCIATING ||
|
||||
supplicantState == SupplicantState::ASSOCIATED ||
|
||||
supplicantState == SupplicantState::FOUR_WAY_HANDSHAKE ||
|
||||
supplicantState == SupplicantState::GROUP_HANDSHAKE ||
|
||||
supplicantState == SupplicantState::COMPLETED;
|
||||
}
|
||||
|
||||
bool WifiProUtils::IsDefaultNet()
|
||||
{
|
||||
NetManagerStandard::NetHandle defaultNet;
|
||||
NetManagerStandard::NetConnClient::GetInstance().GetDefaultNet(defaultNet);
|
||||
NetStateObserver netStateObserver;
|
||||
int32_t wifiNetId = netStateObserver.GetWifiNetId();
|
||||
WIFI_LOGI("IsDefaultNet, default netId:%{public}d, wifiNetId:%{public}d.", defaultNet.GetNetId(), wifiNetId);
|
||||
return defaultNet.GetNetId() == wifiNetId;
|
||||
}
|
||||
|
||||
bool WifiProUtils::IsAppInWhiteLists()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
} // namespace Wifi
|
||||
} // namespace OHOS
|
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (C) 2024-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_WIFI_PRO_UTILS_H
|
||||
#define OHOS_WIFI_PRO_UTILS_H
|
||||
|
||||
#include "wifi_log.h"
|
||||
#include "wifi_pro_common.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Wifi {
|
||||
class WifiProUtils {
|
||||
FRIEND_GTEST(WifiProUtils);
|
||||
public:
|
||||
WifiProUtils() = default;
|
||||
~WifiProUtils() = default;
|
||||
static int32_t GetSignalLevel(int32_t instId);
|
||||
static bool IsWifiConnected(int32_t instId);
|
||||
static int32_t GetScanInterval(bool hasWifiSwitchRecord, int32_t rssiLevel);
|
||||
static int32_t GetMaxCounter(bool hasWifiSwitchRecord, int32_t rssiLevel);
|
||||
static int64_t GetCurrentTimeMs();
|
||||
static bool IsUserSelectNetwork();
|
||||
static bool IsSupplicantConnecting(SupplicantState supplicantState);
|
||||
static bool IsDefaultNet();
|
||||
static bool IsAppInWhiteLists();
|
||||
};
|
||||
|
||||
} // namespace Wifi
|
||||
} // namespace OHOS
|
||||
#endif
|
@ -38,6 +38,7 @@ ohos_static_library("wifi_self_cure") {
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/config",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/log",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_pro",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure",
|
||||
|
@ -25,6 +25,9 @@
|
||||
#endif
|
||||
#include "scan_interface.h"
|
||||
#include "sta_interface.h"
|
||||
#ifdef FEATURE_WIFI_PRO_SUPPORT
|
||||
#include "wifi_pro_interface.h"
|
||||
#endif
|
||||
#ifdef FEATURE_SELF_CURE_SUPPORT
|
||||
#include "self_cure_interface.h"
|
||||
#endif
|
||||
@ -54,6 +57,9 @@ int WifiServiceManager::Init()
|
||||
#ifdef FEATURE_AP_SUPPORT
|
||||
mApServiceHandle.Clear();
|
||||
#endif
|
||||
#ifdef FEATURE_WIFI_PRO_SUPPORT
|
||||
mWifiProServiceHandle.Clear();
|
||||
#endif
|
||||
#ifdef FEATURE_SELF_CURE_SUPPORT
|
||||
mSelfCureServiceHandle.Clear();
|
||||
#endif
|
||||
@ -128,6 +134,22 @@ int WifiServiceManager::LoadStaService(const std::string &dlname, int instId, bo
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef FEATURE_WIFI_PRO_SUPPORT
|
||||
int32_t WifiServiceManager::LoadWifiProService(bool bCreate, int32_t instId)
|
||||
{
|
||||
WIFI_LOGI("WifiServiceManager::LoadWifiProService");
|
||||
std::unique_lock<std::mutex> lock(mWifiProMutex);
|
||||
if (mWifiProServiceHandle.pService[instId]) {
|
||||
WIFI_LOGI("WifiServiceManager::LoadWifiProService pService is not NULL");
|
||||
return 0;
|
||||
}
|
||||
IWifiProService *service = new WifiProInterface();
|
||||
WIFI_LOGI("WifiServiceManager::LoadWifiProService new pService %{public}d", instId);
|
||||
mWifiProServiceHandle.pService[instId] = service;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef FEATURE_SELF_CURE_SUPPORT
|
||||
int WifiServiceManager::LoadSelfCureService(const std::string &dlname, bool bCreate)
|
||||
{
|
||||
@ -214,6 +236,12 @@ int WifiServiceManager::LoadEnhanceService(const std::string &dlname, bool bCrea
|
||||
int WifiServiceManager::CheckAndEnforceService(const std::string &name, int instId, bool bCreate)
|
||||
{
|
||||
WIFI_LOGD("WifiServiceManager::CheckAndEnforceService name: %{public}s", name.c_str());
|
||||
#ifdef FEATURE_WIFI_PRO_SUPPORT
|
||||
if (name == WIFI_SERVICE_WIFIPRO) {
|
||||
return LoadWifiProService(bCreate, instId);
|
||||
}
|
||||
#endif
|
||||
|
||||
std::string dlname;
|
||||
if (GetServiceDll(name, dlname) < 0) {
|
||||
WIFI_LOGE("%{public}s does not support", name.c_str());
|
||||
@ -260,6 +288,21 @@ IStaService *WifiServiceManager::GetStaServiceInst(int instId)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
#ifdef FEATURE_WIFI_PRO_SUPPORT
|
||||
IWifiProService *WifiServiceManager::GetWifiProServiceInst(int32_t instId)
|
||||
{
|
||||
WIFI_LOGD("WifiServiceManager::GetWifiProServiceInst, instId: %{public}d", instId);
|
||||
std::unique_lock<std::mutex> lock(mWifiProMutex);
|
||||
|
||||
auto iter = mWifiProServiceHandle.pService.find(instId);
|
||||
if (iter != mWifiProServiceHandle.pService.end()) {
|
||||
WIFI_LOGD("find a new WifiPro service instance, instId: %{public}d", instId);
|
||||
return iter->second;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef FEATURE_SELF_CURE_SUPPORT
|
||||
ISelfCureService *WifiServiceManager::GetSelfCureServiceInst(int instId)
|
||||
{
|
||||
@ -343,6 +386,28 @@ IEnhanceService *WifiServiceManager::GetEnhanceServiceInst()
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef FEATURE_WIFI_PRO_SUPPORT
|
||||
NO_SANITIZE("cfi") int32_t WifiServiceManager::UnloadWifiProService(bool bPreLoad, int32_t instId)
|
||||
{
|
||||
WIFI_LOGI("WifiServiceManager::UnloadWifiProService, instId: %{public}d", instId);
|
||||
std::unique_lock<std::mutex> lock(mWifiProMutex);
|
||||
|
||||
auto iter = mWifiProServiceHandle.pService.find(instId);
|
||||
if (iter != mWifiProServiceHandle.pService.end()) {
|
||||
if (iter->second != nullptr) {
|
||||
delete iter->second;
|
||||
iter->second = nullptr;
|
||||
}
|
||||
mWifiProServiceHandle.pService.erase(iter);
|
||||
}
|
||||
|
||||
if (!bPreLoad && mWifiProServiceHandle.pService.empty()) {
|
||||
mWifiProServiceHandle.Clear();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef FEATURE_SELF_CURE_SUPPORT
|
||||
NO_SANITIZE("cfi") int WifiServiceManager::UnloadSelfCureService(bool bPreLoad, int instId)
|
||||
{
|
||||
@ -468,6 +533,11 @@ int WifiServiceManager::UnloadService(const std::string &name, int id)
|
||||
if (name == WIFI_SERVICE_STA) {
|
||||
return UnloadStaService(bPreLoad, id);
|
||||
}
|
||||
#ifdef FEATURE_WIFI_PRO_SUPPORT
|
||||
if (name == WIFI_SERVICE_WIFIPRO) {
|
||||
return UnloadWifiProService(bPreLoad, id);
|
||||
}
|
||||
#endif
|
||||
#ifdef FEATURE_SELF_CURE_SUPPORT
|
||||
if (name == WIFI_SERVICE_SELFCURE) {
|
||||
return UnloadSelfCureService(bPreLoad, id);
|
||||
@ -509,6 +579,9 @@ void WifiServiceManager::UninstallAllService()
|
||||
#endif
|
||||
#ifdef FEATURE_SELF_CURE_SUPPORT
|
||||
UnloadSelfCureService(false);
|
||||
#endif
|
||||
#ifdef FEATURE_WIFI_PRO_SUPPORT
|
||||
UnloadWifiProService(false);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
@ -32,6 +32,9 @@
|
||||
#ifdef FEATURE_SELF_CURE_SUPPORT
|
||||
#include "iself_cure_service.h"
|
||||
#endif
|
||||
#ifdef FEATURE_WIFI_PRO_SUPPORT
|
||||
#include "iwifi_pro_service.h"
|
||||
#endif
|
||||
|
||||
namespace OHOS {
|
||||
namespace Wifi {
|
||||
@ -47,6 +50,20 @@ struct StaServiceHandle {
|
||||
}
|
||||
};
|
||||
|
||||
#ifdef FEATURE_WIFI_PRO_SUPPORT
|
||||
struct WifiProServiceHandle {
|
||||
std::map<int, IWifiProService *> pService;
|
||||
WifiProServiceHandle()
|
||||
{}
|
||||
~WifiProServiceHandle()
|
||||
{}
|
||||
void Clear()
|
||||
{
|
||||
pService.clear();
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef FEATURE_SELF_CURE_SUPPORT
|
||||
struct SelfCureServiceHandle {
|
||||
std::map<int, ISelfCureService *> pService;
|
||||
@ -161,6 +178,15 @@ public:
|
||||
ISelfCureService *GetSelfCureServiceInst(int instId = 0);
|
||||
#endif
|
||||
|
||||
#ifdef FEATURE_WIFI_PRO_SUPPORT
|
||||
/**
|
||||
* @Description Get the WifiPro Service Inst object
|
||||
*
|
||||
* @return IWifiProService* - wifi pro service pointer, if wifi pro not supported, nullptr is returned
|
||||
*/
|
||||
IWifiProService *GetWifiProServiceInst(int32_t instId);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @Description Get the Scan Service Inst object
|
||||
*
|
||||
@ -216,6 +242,10 @@ private:
|
||||
int GetServiceDll(const std::string &name, std::string &dlname);
|
||||
int LoadStaService(const std::string &dlname, int insId, bool bCreate);
|
||||
int UnloadStaService(bool bPreLoad, int instId = 0);
|
||||
#ifdef FEATURE_WIFI_PRO_SUPPORT
|
||||
int32_t LoadWifiProService(bool bCreate, int32_t instId = 0);
|
||||
int32_t UnloadWifiProService(bool bPreLoad, int32_t instId = 0);
|
||||
#endif
|
||||
#ifdef FEATURE_SELF_CURE_SUPPORT
|
||||
int LoadSelfCureService(const std::string &dlname, bool bCreate);
|
||||
int UnloadSelfCureService(bool bPreLoad, int instId = 0);
|
||||
@ -235,12 +265,16 @@ private:
|
||||
private:
|
||||
std::mutex mStaMutex;
|
||||
std::mutex mSelfCureMutex;
|
||||
std::mutex mWifiProMutex;
|
||||
std::mutex mScanMutex;
|
||||
std::mutex mP2pMutex;
|
||||
std::mutex mApMutex;
|
||||
std::mutex mEnhanceMutex;
|
||||
std::unordered_map<std::string, std::string> mServiceDllMap;
|
||||
StaServiceHandle mStaServiceHandle;
|
||||
#ifdef FEATURE_WIFI_PRO_SUPPORT
|
||||
WifiProServiceHandle mWifiProServiceHandle;
|
||||
#endif
|
||||
#ifdef FEATURE_SELF_CURE_SUPPORT
|
||||
SelfCureServiceHandle mSelfCureServiceHandle;
|
||||
#endif
|
||||
|
@ -66,6 +66,7 @@ local_base_include_dirs = [
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/include",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/wifi_country_code",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/wifi_network_stats",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/network_black_list",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/network_select",
|
||||
]
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
#ifndef OHOS_WIFI_STA_SERVICE_H
|
||||
#define OHOS_WIFI_STA_SERVICE_H
|
||||
|
||||
#include "sta_define.h"
|
||||
#include "wifi_errcode.h"
|
||||
#ifndef OHOS_ARCH_LITE
|
||||
#include "app_state_data.h"
|
||||
@ -62,12 +63,13 @@ public:
|
||||
* @Description Connecting to a specified network.
|
||||
*
|
||||
* @param networkId - interior saved network index.(in)
|
||||
* @param type - select network type: SelectedType
|
||||
* @Output: Return operating results to Interface Service after enable wifi
|
||||
successfully through callback function instead of returning
|
||||
result immediately.
|
||||
* @Return success: WIFI_OPT_SUCCESS fail: WIFI_OPT_FAILED
|
||||
*/
|
||||
virtual ErrCode ConnectToNetwork(int networkId) = 0;
|
||||
virtual ErrCode ConnectToNetwork(int networkId, int type = NETWORK_SELECTED_BY_USER) = 0;
|
||||
|
||||
/**
|
||||
* @Description roam to target bssid
|
||||
|
@ -16,17 +16,19 @@
|
||||
#include "network_selection_utils.h"
|
||||
#include "network_status_history_manager.h"
|
||||
#include "wifi_common_util.h"
|
||||
|
||||
#ifdef FEATURE_ITNETWORK_PREFERRED_SUPPORT
|
||||
#include "wifi_config_center.h"
|
||||
#include "wifi_p2p_msg.h"
|
||||
#include "wifi_logger.h"
|
||||
#ifdef FEATURE_ITNETWORK_PREFERRED_SUPPORT
|
||||
#include "parameter.h"
|
||||
#endif
|
||||
|
||||
namespace OHOS::Wifi::NetworkSelection {
|
||||
namespace {
|
||||
constexpr int32_t SCAN_5GHZ_BAND = 2;
|
||||
}
|
||||
|
||||
#ifdef FEATURE_ITNETWORK_PREFERRED_SUPPORT
|
||||
DEFINE_WIFILOG_LABEL("NetworkSelectionUtils")
|
||||
#endif
|
||||
|
||||
bool NetworkSelectionUtils::IsOpenNetwork(const NetworkCandidate &networkCandidate)
|
||||
{
|
||||
@ -82,6 +84,50 @@ std::string NetworkSelectionUtils::GetScoreResultsInfo(const std::vector<ScoreRe
|
||||
return scoreMsg.str();
|
||||
}
|
||||
|
||||
bool NetworkSelectionUtils::IsConfigOpenType(const NetworkCandidate &networkCandidate)
|
||||
{
|
||||
return !(IsOpenNetwork(networkCandidate) || NetworkSelectionUtils::IsScanResultForOweNetwork(networkCandidate)) &&
|
||||
!HasWepKeys(networkCandidate.wifiDeviceConfig);
|
||||
}
|
||||
|
||||
bool NetworkSelectionUtils::HasWepKeys(const WifiDeviceConfig &wifiConfig)
|
||||
{
|
||||
for (int32_t i = 0; i < WEPKEYS_SIZE; i++) {
|
||||
if (!wifiConfig.wepKeys[i].empty()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool NetworkSelectionUtils::IsEnterprise(const NetworkCandidate &networkCandidate)
|
||||
{
|
||||
auto &keyMgmt = networkCandidate.wifiDeviceConfig.keyMgmt;
|
||||
bool isEnterpriseSecurityType = (keyMgmt == KEY_MGMT_EAP) || (keyMgmt == KEY_MGMT_SUITE_B_192) ||
|
||||
(keyMgmt == KEY_MGMT_WAPI_CERT);
|
||||
auto &eap = networkCandidate.wifiDeviceConfig.wifiEapConfig.eap;
|
||||
return isEnterpriseSecurityType && (eap != EAP_METHOD_NONE);
|
||||
}
|
||||
|
||||
bool NetworkSelectionUtils::IsConfigOpenOrEapType(const NetworkCandidate &networkCandidate)
|
||||
{
|
||||
return IsConfigOpenType(networkCandidate) || IsEnterprise(networkCandidate);
|
||||
}
|
||||
|
||||
bool NetworkSelectionUtils::IsSameFreqAsP2p(const NetworkCandidate &networkCandidate)
|
||||
{
|
||||
WifiP2pGroupInfo group = WifiConfigCenter::GetInstance().GetCurrentP2pGroupInfo();
|
||||
auto &interScanInfo = networkCandidate.interScanInfo;
|
||||
int32_t p2pFrequency = group.GetFrequency();
|
||||
if (interScanInfo.band == SCAN_5GHZ_BAND && p2pFrequency == interScanInfo.frequency) {
|
||||
return true;
|
||||
} else {
|
||||
WIFI_LOGI("IsSameFreqAsP2p, p2p frequency:%{public}d and scanInfo frequency:%{public}d are not same",
|
||||
p2pFrequency, interScanInfo.frequency);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef FEATURE_ITNETWORK_PREFERRED_SUPPORT
|
||||
bool NetworkSelectionUtils::CheckDeviceTypeByVendorCountry()
|
||||
{
|
||||
|
@ -70,6 +70,40 @@ public:
|
||||
*/
|
||||
static std::string GetScoreResultsInfo(const std::vector<ScoreResult> &scoreResults);
|
||||
|
||||
/**
|
||||
* check if wifi is open.
|
||||
*
|
||||
* @param networkCandidate candidate network.
|
||||
* @return return ture if the candidate network is Open, else false.
|
||||
*/
|
||||
static bool IsConfigOpenType(const NetworkCandidate &networkCandidate);
|
||||
|
||||
/**
|
||||
* check if wifi is Is enterprise.
|
||||
*
|
||||
* @param networkCandidate candidate network.
|
||||
* @return return ture if the candidate network is enterprise, else false.
|
||||
*/
|
||||
static bool IsEnterprise(const NetworkCandidate &networkCandidate);
|
||||
|
||||
/**
|
||||
* check if wifi is open or enterprise.
|
||||
*
|
||||
* @param networkCandidate candidate network.
|
||||
* @return return ture if the candidate network is enterprise, else false.
|
||||
*/
|
||||
static bool IsConfigOpenOrEapType(const NetworkCandidate &networkCandidate);
|
||||
|
||||
/**
|
||||
* check if wifi has web keys.
|
||||
*
|
||||
* @param networkCandidate candidate network.
|
||||
* @return return ture if wifi device config has web keys, else false.
|
||||
*/
|
||||
static bool HasWepKeys(const WifiDeviceConfig &wifiConfig);
|
||||
|
||||
static bool IsSameFreqAsP2p(const NetworkCandidate &networkCandidate);
|
||||
|
||||
#ifdef FEATURE_ITNETWORK_PREFERRED_SUPPORT
|
||||
/**
|
||||
* Get vendor country from param to determine it is ItDevice.
|
||||
|
@ -24,6 +24,8 @@ NetworkSelectorFactory::NetworkSelectorFactory()
|
||||
{
|
||||
handleFuncMap[static_cast<uint32_t>(NetworkSelectType::AUTO_CONNECT)] =
|
||||
&NetworkSelectorFactory::CreateAutoConnectNetworkSelector;
|
||||
handleFuncMap[static_cast<uint32_t>(NetworkSelectType::WIFI2WIFI)] =
|
||||
&NetworkSelectorFactory::CreateWifi2WifiNetworkSelector;
|
||||
}
|
||||
|
||||
std::optional<std::unique_ptr<NetworkSelection::INetworkSelector>> NetworkSelectorFactory::GetNetworkSelector(
|
||||
@ -41,4 +43,9 @@ std::unique_ptr<NetworkSelection::INetworkSelector> NetworkSelectorFactory::Crea
|
||||
{
|
||||
return std::make_unique<NetworkSelection::AutoConnectIntegrator>();
|
||||
}
|
||||
|
||||
std::unique_ptr<NetworkSelection::INetworkSelector> NetworkSelectorFactory::CreateWifi2WifiNetworkSelector()
|
||||
{
|
||||
return std::make_unique<NetworkSelection::Wifi2WifiIntegrator>();
|
||||
}
|
||||
} // namespace OHOS::Wifi
|
||||
|
@ -22,7 +22,11 @@
|
||||
#include "wifi_errcode.h"
|
||||
|
||||
namespace OHOS::Wifi {
|
||||
enum class NetworkSelectType { AUTO_CONNECT };
|
||||
enum class NetworkSelectType {
|
||||
AUTO_CONNECT,
|
||||
WIFI2WIFI
|
||||
};
|
||||
|
||||
class NetworkSelectorFactory {
|
||||
public:
|
||||
NetworkSelectorFactory();
|
||||
@ -42,6 +46,12 @@ public:
|
||||
* @return the network selector
|
||||
*/
|
||||
std::unique_ptr<NetworkSelection::INetworkSelector> CreateAutoConnectNetworkSelector();
|
||||
|
||||
/**
|
||||
* the function to create wifi2wifi networkSelector
|
||||
* @return the network selector
|
||||
*/
|
||||
std::unique_ptr<NetworkSelection::INetworkSelector> CreateWifi2WifiNetworkSelector();
|
||||
private:
|
||||
HandleFuncMap handleFuncMap;
|
||||
};
|
||||
|
@ -60,6 +60,37 @@ bool AutoConnectIntegrator::Nominate(NetworkCandidate &networkCandidate)
|
||||
return false;
|
||||
}
|
||||
|
||||
void Wifi2WifiIntegrator::GetCandidatesFromSubNetworkSelector()
|
||||
{
|
||||
for (const auto &subNetworkSelector : subNetworkSelectors) {
|
||||
subNetworkSelector->GetBestCandidates(networkCandidates);
|
||||
}
|
||||
}
|
||||
|
||||
Wifi2WifiIntegrator::Wifi2WifiIntegrator() : CompositeNetworkSelector("Wifi2WifiIntegrator")
|
||||
{
|
||||
auto andFilters = make_shared<AndWifiFilter>();
|
||||
andFilters->AddFilter(make_shared<NotCurrentNetworkFilter>());
|
||||
andFilters->AddFilter(make_shared<NotNetworkBlackListFilter>());
|
||||
ExternalWifiFilterBuildManager::GetInstance().BuildFilter(FilterTag::NOT_P2P_ENHANCE_FREQ_AT_5G_FILTER_TAG,
|
||||
*andFilters);
|
||||
andFilters->AddFilter(make_shared<NotP2pFreqAt5gFilter>());
|
||||
andFilters->AddFilter(make_shared<SignalLevelFilter>());
|
||||
andFilters->AddFilter(make_shared<WifiSwitchThresholdFilter>());
|
||||
andFilters->AddFilter(make_shared<ValidConfigNetworkFilter>());
|
||||
SetWifiFilter(andFilters);
|
||||
|
||||
AddSubNetworkSelector(make_shared<PreferredApSelector>());
|
||||
}
|
||||
|
||||
bool Wifi2WifiIntegrator::Nominate(NetworkCandidate &networkCandidate)
|
||||
{
|
||||
for (auto &networkSelector : subNetworkSelectors) {
|
||||
networkSelector->TryNominate(networkCandidate);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
SavedNetworkTracker::SavedNetworkTracker() : CompositeNetworkSelector("savedNetworkTracker")
|
||||
{
|
||||
auto andFilter = make_shared<AndWifiFilter>();
|
||||
@ -294,4 +325,19 @@ bool NoInternetNetworkSelector::Filter(NetworkCandidate &networkCandidate)
|
||||
TryNominate(networkCandidate);
|
||||
return false;
|
||||
}
|
||||
|
||||
PreferredApSelector::PreferredApSelector() : SimpleFilterNetworkSelector("PreferredApSelector")
|
||||
{
|
||||
// The filtering conditions have already been done outside, so no further filtering is needed here.
|
||||
auto networkScoreComparator = make_shared<WifiScorerComparator>(m_networkSelectorName);
|
||||
networkScoreComparator->AddScorer(make_shared<ApQualityScorer>("ApQualityScorer"));
|
||||
networkScoreComparator->AddScorer(make_shared<RssiScorer>());
|
||||
SetWifiComparator(networkScoreComparator);
|
||||
}
|
||||
|
||||
bool PreferredApSelector::Filter(NetworkCandidate &networkCandidate)
|
||||
{
|
||||
TryNominate(networkCandidate);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -28,6 +28,15 @@ protected:
|
||||
void GetCandidatesFromSubNetworkSelector() override;
|
||||
};
|
||||
|
||||
class Wifi2WifiIntegrator : public CompositeNetworkSelector {
|
||||
public:
|
||||
Wifi2WifiIntegrator();
|
||||
~Wifi2WifiIntegrator() = default;
|
||||
protected:
|
||||
bool Nominate(NetworkCandidate &networkCandidate) override;
|
||||
void GetCandidatesFromSubNetworkSelector() override;
|
||||
};
|
||||
|
||||
class SavedNetworkTracker final: public CompositeNetworkSelector {
|
||||
public:
|
||||
SavedNetworkTracker();
|
||||
@ -90,5 +99,12 @@ public:
|
||||
protected:
|
||||
bool Filter(NetworkCandidate &networkCandidate) override;
|
||||
};
|
||||
|
||||
class PreferredApSelector final: public SimpleFilterNetworkSelector {
|
||||
public:
|
||||
PreferredApSelector();
|
||||
protected:
|
||||
bool Filter(NetworkCandidate &networkCandidate) override;
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
@ -16,20 +16,28 @@
|
||||
#include "wifi_filter_impl.h"
|
||||
#include "network_selection_utils.h"
|
||||
#include "network_status_history_manager.h"
|
||||
#include "wifi_config_center.h"
|
||||
#include "wifi_logger.h"
|
||||
#include "wifi_settings.h"
|
||||
#include "network_black_list_manager.h"
|
||||
#include "wifi_ap_msg.h"
|
||||
#ifndef OHOS_ARCH_LITE
|
||||
#include "wifi_app_state_aware.h"
|
||||
#endif
|
||||
namespace OHOS::Wifi::NetworkSelection {
|
||||
DEFINE_WIFILOG_LABEL("WifiFilter")
|
||||
|
||||
namespace {
|
||||
constexpr int RECHECK_DELAYED_SECONDS = 1 * 60 * 60;
|
||||
constexpr int MIN_5GHZ_BAND_FREQUENCY = 5000;
|
||||
constexpr int MIN_RSSI_VALUE_24G = -77;
|
||||
constexpr int MIN_RSSI_VALUE_5G = -80;
|
||||
constexpr int SIGNAL_LEVEL_TWO = 2;
|
||||
constexpr int POOR_PORTAL_RECHECK_DELAYED_SECONDS = 2 * RECHECK_DELAYED_SECONDS;
|
||||
constexpr int32_t MIN_SIGNAL_LEVEL_INTERVAL = 2;
|
||||
constexpr int32_t SIGNAL_LEVEL_THREE = 3;
|
||||
constexpr int32_t SIGNAL_LEVEL_FOUR = 4;
|
||||
constexpr int32_t MIN_RSSI_INTERVAL = 8;
|
||||
}
|
||||
|
||||
HiddenWifiFilter::HiddenWifiFilter() : SimpleWifiFilter("notHidden") {}
|
||||
|
||||
@ -253,7 +261,6 @@ bool PortalWifiFilter::Filter(NetworkCandidate &networkCandidate)
|
||||
return networkCandidate.wifiDeviceConfig.isPortal;
|
||||
}
|
||||
|
||||
|
||||
MaybePortalWifiFilter::MaybePortalWifiFilter() : SimpleWifiFilter("maybePortal") {}
|
||||
|
||||
MaybePortalWifiFilter::~MaybePortalWifiFilter()
|
||||
@ -292,7 +299,6 @@ bool NoInternetWifiFilter::Filter(NetworkCandidate &networkCandidate)
|
||||
return NetworkStatusHistoryManager::HasInternetEverByHistory(wifiDeviceConfig.networkStatusHistory);
|
||||
}
|
||||
|
||||
|
||||
WeakAlgorithmWifiFilter::WeakAlgorithmWifiFilter() : SimpleWifiFilter("noWeakAlgorithm") {}
|
||||
|
||||
WeakAlgorithmWifiFilter::~WeakAlgorithmWifiFilter()
|
||||
@ -320,4 +326,221 @@ bool WeakAlgorithmWifiFilter::Filter(NetworkCandidate &networkCandidate)
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
NotCurrentNetworkFilter::NotCurrentNetworkFilter() : SimpleWifiFilter("NotCurrentNetwork") {}
|
||||
|
||||
NotCurrentNetworkFilter::~NotCurrentNetworkFilter()
|
||||
{
|
||||
if (!filteredNetworkCandidates.empty()) {
|
||||
WIFI_LOGI("filteredNetworkCandidates in %{public}s: %{public}s",
|
||||
filterName.c_str(),
|
||||
NetworkSelectionUtils::GetNetworkCandidatesInfo(filteredNetworkCandidates).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
bool NotCurrentNetworkFilter::Filter(NetworkCandidate &networkCandidate)
|
||||
{
|
||||
WifiLinkedInfo linkedInfo;
|
||||
WifiConfigCenter::GetInstance().GetLinkedInfo(linkedInfo);
|
||||
if (networkCandidate.interScanInfo.bssid == linkedInfo.bssid) {
|
||||
WIFI_LOGI("NotCurrentNetworkFilter, same bssid:%{public}s",
|
||||
networkCandidate.ToString().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((networkCandidate.interScanInfo.ssid == linkedInfo.ssid) &&
|
||||
NetworkSelectionUtils::IsConfigOpenOrEapType(networkCandidate)) {
|
||||
WIFI_LOGI("NotCurrentNetworkFilter, same ssid and open or eap type:%{public}s",
|
||||
networkCandidate.ToString().c_str());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
SignalLevelFilter::SignalLevelFilter() : SimpleWifiFilter("SignalLevel") {}
|
||||
|
||||
SignalLevelFilter::~SignalLevelFilter()
|
||||
{
|
||||
if (!filteredNetworkCandidates.empty()) {
|
||||
WIFI_LOGI("filteredNetworkCandidates in %{public}s: %{public}s",
|
||||
filterName.c_str(),
|
||||
NetworkSelectionUtils::GetNetworkCandidatesInfo(filteredNetworkCandidates).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
bool SignalLevelFilter::Filter(NetworkCandidate &networkCandidate)
|
||||
{
|
||||
auto &interScanInfo = networkCandidate.interScanInfo;
|
||||
int32_t signalLevel = WifiSettings::GetInstance().GetSignalLevel(interScanInfo.rssi, interScanInfo.band);
|
||||
return signalLevel > SIGNAL_LEVEL_TWO;
|
||||
}
|
||||
|
||||
NotNetworkBlackListFilter::NotNetworkBlackListFilter() : SimpleWifiFilter("NotNetworkBlackList") {}
|
||||
|
||||
NotNetworkBlackListFilter::~NotNetworkBlackListFilter()
|
||||
{
|
||||
if (!filteredNetworkCandidates.empty()) {
|
||||
WIFI_LOGI("filteredNetworkCandidates in %{public}s: %{public}s",
|
||||
filterName.c_str(),
|
||||
NetworkSelectionUtils::GetNetworkCandidatesInfo(filteredNetworkCandidates).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
bool NotNetworkBlackListFilter::Filter(NetworkCandidate &networkCandidate)
|
||||
{
|
||||
if (NetworkBlockListManager::GetInstance().IsInAbnormalWifiBlocklist(networkCandidate.interScanInfo.bssid)) {
|
||||
WIFI_LOGI("NotNetworkBlockListFilter, in abnormal wifi blocklist, skip candidate:%{public}s",
|
||||
networkCandidate.ToString().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
WifiLinkedInfo linkedInfo;
|
||||
WifiConfigCenter::GetInstance().GetLinkedInfo(linkedInfo);
|
||||
int32_t curSignalLevel = WifiSettings::GetInstance().GetSignalLevel(linkedInfo.rssi, linkedInfo.band);
|
||||
auto scanInfo = networkCandidate.interScanInfo;
|
||||
int32_t targetSignalLevel = WifiSettings::GetInstance().GetSignalLevel(scanInfo.rssi, scanInfo.band);
|
||||
if (NetworkBlockListManager::GetInstance().IsInWifiBlocklist(networkCandidate.interScanInfo.bssid) &&
|
||||
(targetSignalLevel <= SIGNAL_LEVEL_THREE || targetSignalLevel - curSignalLevel < MIN_SIGNAL_LEVEL_INTERVAL)) {
|
||||
WIFI_LOGI("NotNetworkBlackListFilter, in wifi blocklist and level interval is not enough,"
|
||||
"skip candidate:%{public}s", networkCandidate.ToString().c_str());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
NotP2pFreqAt5gFilter::NotP2pFreqAt5gFilter() : SimpleWifiFilter("NotP2pFreqAt5g") {}
|
||||
|
||||
NotP2pFreqAt5gFilter::~NotP2pFreqAt5gFilter()
|
||||
{
|
||||
if (!filteredNetworkCandidates.empty()) {
|
||||
WIFI_LOGI("filteredNetworkCandidates in %{public}s: %{public}s",
|
||||
filterName.c_str(),
|
||||
NetworkSelectionUtils::GetNetworkCandidatesInfo(filteredNetworkCandidates).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
bool NotP2pFreqAt5gFilter::Filter(NetworkCandidate &networkCandidate)
|
||||
{
|
||||
if (networkCandidate.interScanInfo.band == static_cast<int>(BandType::BAND_2GHZ)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Hid2dUpperScene softbusScene;
|
||||
Hid2dUpperScene castScene;
|
||||
Hid2dUpperScene shareScene;
|
||||
Hid2dUpperScene mouseCrossScene;
|
||||
Hid2dUpperScene miracastScene;
|
||||
WifiP2pLinkedInfo linkedInfo;
|
||||
WifiConfigCenter::GetInstance().GetHid2dUpperScene(SOFT_BUS_SERVICE_UID, softbusScene);
|
||||
WifiConfigCenter::GetInstance().GetHid2dUpperScene(CAST_ENGINE_SERVICE_UID, castScene);
|
||||
WifiConfigCenter::GetInstance().GetHid2dUpperScene(MIRACAST_SERVICE_UID, miracastScene);
|
||||
WifiConfigCenter::GetInstance().GetHid2dUpperScene(SHARE_SERVICE_UID, shareScene);
|
||||
WifiConfigCenter::GetInstance().GetHid2dUpperScene(MOUSE_CROSS_SERVICE_UID, mouseCrossScene);
|
||||
WifiConfigCenter::GetInstance().GetP2pInfo(linkedInfo);
|
||||
if (linkedInfo.GetConnectState() == P2pConnectedState::P2P_DISCONNECTED
|
||||
&& WifiConfigCenter::GetInstance().GetP2pEnhanceState() == 0) {
|
||||
return true;
|
||||
}
|
||||
// scene bit 0-2 is valid, 0x01: video, 0x02: audio, 0x04: file,
|
||||
// scene & 0x07 > 0 means one of them takes effect.
|
||||
bool isCastScene = false;
|
||||
if ((softbusScene.scene & 0x07) > 0 || (castScene.scene & 0x07) > 0 || (shareScene.scene & 0x07) > 0 ||
|
||||
(mouseCrossScene.scene & 0x07) > 0 || (miracastScene.scene & 0x07) > 0) {
|
||||
isCastScene = true;
|
||||
}
|
||||
|
||||
if (!isCastScene) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return NetworkSelectionUtils::IsSameFreqAsP2p(networkCandidate);
|
||||
}
|
||||
|
||||
ValidConfigNetworkFilter::ValidConfigNetworkFilter() : SimpleWifiFilter("ValidConfigNetwork") {}
|
||||
|
||||
ValidConfigNetworkFilter::~ValidConfigNetworkFilter()
|
||||
{
|
||||
if (!filteredNetworkCandidates.empty()) {
|
||||
WIFI_LOGI("filteredNetworkCandidates in %{public}s: %{public}s",
|
||||
filterName.c_str(),
|
||||
NetworkSelectionUtils::GetNetworkCandidatesInfo(filteredNetworkCandidates).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
bool ValidConfigNetworkFilter::Filter(NetworkCandidate &networkCandidate)
|
||||
{
|
||||
// no internet filtering
|
||||
auto &wifiDeviceConfig = networkCandidate.wifiDeviceConfig;
|
||||
if (wifiDeviceConfig.noInternetAccess) {
|
||||
WIFI_LOGI("ValidConfigNetworkFilter, no internet access, skip candidate:%{public}s",
|
||||
networkCandidate.ToString().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
// portal network filtering
|
||||
if (networkCandidate.wifiDeviceConfig.isPortal) {
|
||||
WIFI_LOGI("ValidConfigNetworkFilter, portal network, skip candidate:%{public}s",
|
||||
networkCandidate.ToString().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
// disable network filtering
|
||||
auto &networkSelectionStatus = networkCandidate.wifiDeviceConfig.networkSelectionStatus;
|
||||
if (networkSelectionStatus.networkSelectionDisableReason != DisabledReason::DISABLED_NONE) {
|
||||
WIFI_LOGI("ValidConfigNetworkFilter, disable network, skip candidate:%{public}s",
|
||||
networkCandidate.ToString().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
// empty network status history
|
||||
if (NetworkStatusHistoryManager::IsEmptyNetworkStatusHistory(wifiDeviceConfig.networkStatusHistory)) {
|
||||
WIFI_LOGI("ValidConfigNetworkFilter, no network status history, skip candidate:%{public}s",
|
||||
networkCandidate.ToString().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
// maybe portal network filtering
|
||||
if (NetworkSelectionUtils::IsScanResultForOweNetwork(networkCandidate) &&
|
||||
NetworkSelectionUtils::IsOpenAndMaybePortal(networkCandidate)) {
|
||||
WIFI_LOGI("ValidConfigNetworkFilter, maybe portal network, skip candidate:%{public}s",
|
||||
networkCandidate.ToString().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
WifiSwitchThresholdFilter::WifiSwitchThresholdFilter() : SimpleWifiFilter("WifiSwitchThreshold") {}
|
||||
|
||||
WifiSwitchThresholdFilter::~WifiSwitchThresholdFilter()
|
||||
{
|
||||
if (!filteredNetworkCandidates.empty()) {
|
||||
WIFI_LOGI("filteredNetworkCandidates in %{public}s: %{public}s",
|
||||
filterName.c_str(),
|
||||
NetworkSelectionUtils::GetNetworkCandidatesInfo(filteredNetworkCandidates).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
bool WifiSwitchThresholdFilter::Filter(NetworkCandidate &networkCandidate)
|
||||
{
|
||||
WifiLinkedInfo linkedInfo;
|
||||
WifiConfigCenter::GetInstance().GetLinkedInfo(linkedInfo);
|
||||
int32_t curSignalLevel = WifiSettings::GetInstance().GetSignalLevel(linkedInfo.rssi, linkedInfo.band);
|
||||
auto &interScanInfo = networkCandidate.interScanInfo;
|
||||
if (linkedInfo.band == static_cast<int>(BandType::BAND_5GHZ) && curSignalLevel == SIGNAL_LEVEL_THREE &&
|
||||
interScanInfo.band == static_cast<int>(BandType::BAND_2GHZ)) {
|
||||
WIFI_LOGI("WifiSwitchThresholdFilter, current network is 5G and level is three and target network is 2G, "
|
||||
"skip candidate:%{public}s", networkCandidate.ToString().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (curSignalLevel == SIGNAL_LEVEL_FOUR || (interScanInfo.rssi - linkedInfo.rssi < MIN_RSSI_INTERVAL)) {
|
||||
WIFI_LOGI("WifiSwitchThresholdFilter, curSignalLevel:%{public}d, scan info rssi:%{public}d,"
|
||||
"cur rssi:%{public}d, skip candidate:%{public}s",
|
||||
curSignalLevel, interScanInfo.rssi, linkedInfo.rssi, networkCandidate.ToString().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -26,6 +26,54 @@ protected:
|
||||
bool Filter(NetworkCandidate &networkCandidate) override;
|
||||
};
|
||||
|
||||
class NotCurrentNetworkFilter final : public SimpleWifiFilter {
|
||||
public:
|
||||
NotCurrentNetworkFilter();
|
||||
~NotCurrentNetworkFilter() override;
|
||||
protected:
|
||||
bool Filter(NetworkCandidate &networkCandidate) override;
|
||||
};
|
||||
|
||||
class SignalLevelFilter final : public SimpleWifiFilter {
|
||||
public:
|
||||
SignalLevelFilter();
|
||||
~SignalLevelFilter() override;
|
||||
protected:
|
||||
bool Filter(NetworkCandidate &networkCandidate) override;
|
||||
};
|
||||
|
||||
class NotNetworkBlackListFilter final : public SimpleWifiFilter {
|
||||
public:
|
||||
NotNetworkBlackListFilter();
|
||||
~NotNetworkBlackListFilter() override;
|
||||
protected:
|
||||
bool Filter(NetworkCandidate &networkCandidate) override;
|
||||
};
|
||||
|
||||
class NotP2pFreqAt5gFilter final : public SimpleWifiFilter {
|
||||
public:
|
||||
NotP2pFreqAt5gFilter();
|
||||
~NotP2pFreqAt5gFilter() override;
|
||||
protected:
|
||||
bool Filter(NetworkCandidate &networkCandidate) override;
|
||||
};
|
||||
|
||||
class ValidConfigNetworkFilter final : public SimpleWifiFilter {
|
||||
public:
|
||||
ValidConfigNetworkFilter();
|
||||
~ValidConfigNetworkFilter() override;
|
||||
protected:
|
||||
bool Filter(NetworkCandidate &networkCandidate) override;
|
||||
};
|
||||
|
||||
class WifiSwitchThresholdFilter final : public SimpleWifiFilter {
|
||||
public:
|
||||
WifiSwitchThresholdFilter();
|
||||
~WifiSwitchThresholdFilter() override;
|
||||
protected:
|
||||
bool Filter(NetworkCandidate &networkCandidate) override;
|
||||
};
|
||||
|
||||
class SignalStrengthWifiFilter final : public SimpleWifiFilter {
|
||||
public:
|
||||
SignalStrengthWifiFilter();
|
||||
|
@ -22,7 +22,7 @@
|
||||
|
||||
namespace OHOS::Wifi::NetworkSelection {
|
||||
DEFINE_WIFILOG_LABEL("WifiScorerImpl")
|
||||
|
||||
namespace {
|
||||
constexpr int SUFFICIENT_RSSI_5G = -70;
|
||||
constexpr int SUFFICIENT_RSSI_2G = -73;
|
||||
constexpr int RSSI_SCORE_OFFSET = 85;
|
||||
@ -36,6 +36,8 @@ constexpr int WIFI_2G_BAND_SCORE = 20;
|
||||
constexpr int SECURITY_BONUS_SCORE = 5;
|
||||
constexpr int RSSI_LEVEL_FOUR_SCORE = 80;
|
||||
constexpr int RSSI_LEVEL_THREE_SCORE = 60;
|
||||
constexpr int RSSI_LEVEL_TWO_SCORE = 20;
|
||||
constexpr int WIFI_DEFAULT_SCORE = -1;
|
||||
constexpr int RSSI_LEVEL_TWO_SCORE_5G = 40;
|
||||
constexpr int RSSI_LEVEL_TWO_SCORE_2G = 20;
|
||||
constexpr int SIGNAL_LEVEL_TWO = 2;
|
||||
@ -47,6 +49,7 @@ constexpr int EMPTY_NETWORK_STATUS_HISTORY_AWARD = 1;
|
||||
constexpr int MAX_HISTORY_NETWORK_STATUS_NUM = 10;
|
||||
constexpr int HISTORY_NETWORK_STATUS_WEIGHTED_SCORE[MAX_HISTORY_NETWORK_STATUS_NUM] = {
|
||||
0, 40960, 20480, 10240, 5120, 2560, 1280, 640, 320, 160};
|
||||
}
|
||||
|
||||
RssiScorer::RssiScorer() : SimpleWifiScorer("rssiScorer") {}
|
||||
|
||||
@ -218,6 +221,31 @@ double RssiLevelBonusScorer::Score(NetworkCandidate &networkCandidate)
|
||||
return 0;
|
||||
}
|
||||
|
||||
SignalLevelScorer::SignalLevelScorer() : SimpleWifiScorer("SignalLevelScorer") {}
|
||||
|
||||
double SignalLevelScorer::Score(NetworkCandidate &networkCandidate)
|
||||
{
|
||||
auto &scanInfo = networkCandidate.interScanInfo;
|
||||
int signalLevel = WifiSettings::GetInstance().GetSignalLevel(scanInfo.rssi, scanInfo.band);
|
||||
int32_t levelScore = 0;
|
||||
switch (signalLevel) {
|
||||
case SIGNAL_LEVEL_FOUR:
|
||||
levelScore = RSSI_LEVEL_FOUR_SCORE;
|
||||
break;
|
||||
case SIGNAL_LEVEL_THREE:
|
||||
levelScore = RSSI_LEVEL_THREE_SCORE;
|
||||
break;
|
||||
case SIGNAL_LEVEL_TWO:
|
||||
levelScore = RSSI_LEVEL_TWO_SCORE;
|
||||
break;
|
||||
default:
|
||||
levelScore = WIFI_DEFAULT_SCORE;
|
||||
break;
|
||||
}
|
||||
|
||||
return levelScore;
|
||||
}
|
||||
|
||||
Network5gBonusScorer::Network5gBonusScorer() : SimpleWifiScorer("5gBonusScore") {}
|
||||
|
||||
double Network5gBonusScorer::Score(NetworkCandidate &networkCandidate)
|
||||
@ -254,4 +282,13 @@ double NoInternetNetworkStatusHistoryScorer::Score(NetworkCandidate &networkCand
|
||||
}
|
||||
return score;
|
||||
}
|
||||
|
||||
ApQualityScorer::ApQualityScorer(const std::string &scorerName) : CompositeWifiScorer(scorerName)
|
||||
{
|
||||
AddScorer(std::make_shared<SignalLevelScorer>());
|
||||
AddScorer(std::make_shared<Network5gBonusScorer>());
|
||||
ExternalWifiCommonBuildManager::GetInstance().BuildScore(
|
||||
TagType::HAS_INTERNET_NETWORK_SELECTOR_SCORE_WIFI_CATEGORY_TAG, *this);
|
||||
AddScorer(std::make_shared<SecurityBonusScorer>());
|
||||
}
|
||||
}
|
||||
|
@ -137,6 +137,12 @@ public:
|
||||
double Score(NetworkCandidate &networkCandidate) override;
|
||||
};
|
||||
|
||||
class SignalLevelScorer : public SimpleWifiScorer {
|
||||
public:
|
||||
SignalLevelScorer();
|
||||
double Score(NetworkCandidate &networkCandidate) override;
|
||||
};
|
||||
|
||||
class Network5gBonusScorer : public SimpleWifiScorer {
|
||||
public:
|
||||
Network5gBonusScorer();
|
||||
@ -153,6 +159,12 @@ public:
|
||||
NoInternetNetworkStatusHistoryScorer();
|
||||
double Score(NetworkCandidate &networkCandidate) override;
|
||||
};
|
||||
|
||||
class ApQualityScorer : public CompositeWifiScorer {
|
||||
public:
|
||||
explicit ApQualityScorer(const std::string &scorerName);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -17,7 +17,6 @@
|
||||
#include "wifi_sta_hal_interface.h"
|
||||
#include "wifi_config_center.h"
|
||||
#include "wifi_common_util.h"
|
||||
#include "wifi_service_manager.h"
|
||||
#include "block_connect_service.h"
|
||||
|
||||
DEFINE_WIFILOG_LABEL("StaAutoConnectService");
|
||||
|
@ -82,10 +82,12 @@ namespace Wifi {
|
||||
#define VALUE_LIMIT_MIN_RSSI (-100)
|
||||
#define VALUE_LIMIT_MAX_RSSI (-55)
|
||||
|
||||
#define NETWORK_SELECTED_BY_UNKNOWN (-1)
|
||||
#define NETWORK_SELECTED_BY_AUTO 0
|
||||
#define NETWORK_SELECTED_BY_USER 1
|
||||
#define NETWORK_SELECTED_BY_RETRY 2
|
||||
enum SelectedType {
|
||||
NETWORK_SELECTED_BY_UNKNOWN = -1,
|
||||
NETWORK_SELECTED_BY_AUTO = 0,
|
||||
NETWORK_SELECTED_BY_USER = 1,
|
||||
NETWORK_SELECTED_BY_RETRY = 2
|
||||
};
|
||||
|
||||
#define WIFI_SIM_GSM_AUTH_MIN_PARAM_COUNT 3
|
||||
#define WIFI_SIM_GSM_AUTH_MAX_PARAM_COUNT 4
|
||||
|
@ -76,12 +76,12 @@ ErrCode StaInterface::DisableStaService()
|
||||
return WIFI_OPT_SUCCESS;
|
||||
}
|
||||
|
||||
ErrCode StaInterface::ConnectToNetwork(int networkId)
|
||||
ErrCode StaInterface::ConnectToNetwork(int networkId, int type)
|
||||
{
|
||||
LOGI("Enter Connect.\n");
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
CHECK_NULL_AND_RETURN(pStaService, WIFI_OPT_FAILED);
|
||||
if (pStaService->ConnectToNetwork(networkId) != WIFI_OPT_SUCCESS) {
|
||||
if (pStaService->ConnectToNetwork(networkId, type) != WIFI_OPT_SUCCESS) {
|
||||
LOGE("ConnectTo failed.\n");
|
||||
return WIFI_OPT_FAILED;
|
||||
}
|
||||
|
@ -50,17 +50,18 @@ public:
|
||||
/**
|
||||
* @Description Connect to a new network
|
||||
*
|
||||
* @param config - the configuration of network which is going to connect.(in)
|
||||
* @param networkId - interior saved network index.(in)
|
||||
* @param type - select network type: SelectedType
|
||||
* @Output: Return operating results to Interface Service after enable wifi
|
||||
successfully through callback function instead of returning
|
||||
result immediately.
|
||||
* @Return success: WIFI_OPT_SUCCESS fail: WIFI_OPT_FAILED
|
||||
*/
|
||||
virtual ErrCode ConnectToNetwork(int networkId) override;
|
||||
virtual ErrCode ConnectToNetwork(int networkId, int type = NETWORK_SELECTED_BY_USER) override;
|
||||
/**
|
||||
* @Description Connecting to a specified network.
|
||||
*
|
||||
* @param networkId - interior saved network index.(in)
|
||||
* @param config - the configuration of network which is going to connect.(in)
|
||||
* @Output: Return operating results to Interface Service after enable wifi
|
||||
successfully through callback function instead of returning
|
||||
result immediately.
|
||||
|
@ -557,7 +557,7 @@ ErrCode StaService::ConnectToDevice(const WifiDeviceConfig &config) const
|
||||
return WIFI_OPT_SUCCESS;
|
||||
}
|
||||
|
||||
ErrCode StaService::ConnectToNetwork(int networkId) const
|
||||
ErrCode StaService::ConnectToNetwork(int networkId, int type) const
|
||||
{
|
||||
LOGI("Enter ConnectToNetwork, networkId is %{public}d.", networkId);
|
||||
WifiDeviceConfig config;
|
||||
@ -570,7 +570,7 @@ ErrCode StaService::ConnectToNetwork(int networkId) const
|
||||
LOGI("ConnectToNetwork, ssid = %{public}s.", SsidAnonymize(config.ssid).c_str());
|
||||
pStaAutoConnectService->EnableOrDisableBssid(config.bssid, true, 0);
|
||||
pStaStateMachine->SetPortalBrowserFlag(false);
|
||||
pStaStateMachine->SendMessage(WIFI_SVR_CMD_STA_CONNECT_SAVED_NETWORK, networkId, NETWORK_SELECTED_BY_USER);
|
||||
pStaStateMachine->SendMessage(WIFI_SVR_CMD_STA_CONNECT_SAVED_NETWORK, networkId, type);
|
||||
return WIFI_OPT_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -73,12 +73,13 @@ public:
|
||||
* @Description Connecting to a specified network.
|
||||
*
|
||||
* @param networkId - interior saved network index.(in)
|
||||
* @param type - select network type: SelectedType
|
||||
* @Output: Return operating results to Interface Service after enable wifi
|
||||
successfully through callback function instead of returning
|
||||
result immediately.
|
||||
* @Return success: WIFI_OPT_SUCCESS fail: WIFI_OPT_FAILED
|
||||
*/
|
||||
virtual ErrCode ConnectToNetwork(int networkId) const;
|
||||
virtual ErrCode ConnectToNetwork(int networkId, int type = NETWORK_SELECTED_BY_USER) const;
|
||||
|
||||
/**
|
||||
* @Description roam to target bssid
|
||||
|
@ -25,15 +25,15 @@ namespace OHOS {
|
||||
namespace Wifi {
|
||||
struct StaServiceCallback {
|
||||
std::string callbackModuleName;
|
||||
std::function<void(OperateResState, int)> OnStaOpenRes;
|
||||
std::function<void(OperateResState, int)> OnStaCloseRes;
|
||||
std::function<void(OperateResState, const WifiLinkedInfo &, int)> OnStaConnChanged;
|
||||
std::function<void(WpsStartState, const int, int)> OnWpsChanged;
|
||||
std::function<void(StreamDirection, int)> OnStaStreamChanged;
|
||||
std::function<void(int, int)> OnStaRssiLevelChanged;
|
||||
std::function<void(OperateResState, int)> OnStaSemiActiveRes;
|
||||
std::function<void(IpInfo, int)> OnDhcpOfferReport;
|
||||
std::function<void(int, int)> OnAutoSelectNetworkRes;
|
||||
std::function<void(OperateResState, int)> OnStaOpenRes { nullptr };
|
||||
std::function<void(OperateResState, int)> OnStaCloseRes { nullptr };
|
||||
std::function<void(OperateResState, const WifiLinkedInfo &, int)> OnStaConnChanged { nullptr };
|
||||
std::function<void(WpsStartState, const int, int)> OnWpsChanged { nullptr };
|
||||
std::function<void(StreamDirection, int)> OnStaStreamChanged { nullptr };
|
||||
std::function<void(int, int)> OnStaRssiLevelChanged { nullptr };
|
||||
std::function<void(OperateResState, int)> OnStaSemiActiveRes { nullptr };
|
||||
std::function<void(IpInfo, int)> OnDhcpOfferReport { nullptr };
|
||||
std::function<void(int, int)> OnAutoSelectNetworkRes { nullptr };
|
||||
};
|
||||
} // namespace Wifi
|
||||
} // namespace OHOS
|
||||
|
@ -243,6 +243,13 @@ void WifiScanManager::DealScanInfoNotify(std::vector<InterScanInfo> &results, in
|
||||
if (pService != nullptr) {
|
||||
pService->ConnectivityManager(results);
|
||||
}
|
||||
|
||||
#ifdef FEATURE_WIFI_PRO_SUPPORT
|
||||
IWifiProService *pWifiProService = WifiServiceManager::GetInstance().GetWifiProServiceInst(instId);
|
||||
if (pWifiProService != nullptr) {
|
||||
pWifiProService->DealScanResult(results);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,7 @@ group("unittest") {
|
||||
"wifi_standard/wifi_framework/wifi_manage/wifi_ap:WifiApServiceTest",
|
||||
"wifi_standard/wifi_framework/wifi_manage/wifi_native:wifi_native_test",
|
||||
"wifi_standard/wifi_framework/wifi_manage/wifi_p2p/test:wifi_p2p_test",
|
||||
"wifi_standard/wifi_framework/wifi_manage/wifi_pro:wifi_pro_unittest",
|
||||
"wifi_standard/wifi_framework/wifi_manage/wifi_scan:wifi_scan_unittest",
|
||||
"wifi_standard/wifi_framework/wifi_manage/wifi_sta:wifi_selfcure_unittest",
|
||||
"wifi_standard/wifi_framework/wifi_manage/wifi_sta:wifi_sta_unittest",
|
||||
|
@ -45,6 +45,7 @@ ohos_fuzztest("WifiDeviceStubFuzzTest") {
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan_sa",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_pro",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap_sa",
|
||||
|
@ -45,6 +45,7 @@ ohos_fuzztest("WifiHotspotImplFuzzTest") {
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan_sa",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_pro",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap_sa",
|
||||
|
@ -45,6 +45,7 @@ ohos_fuzztest("WifiHotSpotStubFuzzTest") {
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan_sa",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_pro",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap_sa",
|
||||
|
@ -44,6 +44,7 @@ ohos_fuzztest("WifiP2pStubFuzzTest") {
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan_sa",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_pro",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap_sa",
|
||||
|
@ -44,6 +44,7 @@ ohos_fuzztest("WifiScansaFuzzTest") {
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan_sa",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_pro",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap_sa",
|
||||
|
@ -45,6 +45,7 @@ ohos_fuzztest("WifiScanServerFuzzTest") {
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan_sa",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_pro",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap_sa",
|
||||
|
@ -44,6 +44,7 @@ ohos_fuzztest("WifiScanStubFuzzTest") {
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan_sa",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_pro",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap_sa",
|
||||
|
@ -46,6 +46,7 @@ ohos_fuzztest("WifiStaServerFuzzTest") {
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan_sa",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_pro",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap_sa",
|
||||
@ -56,6 +57,7 @@ ohos_fuzztest("WifiStaServerFuzzTest") {
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/include",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/wifi_country_code",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/network_select",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/network_black_list",
|
||||
"$WIFI_ROOT_DIR/test/fuzztest/fuzz_common_func",
|
||||
]
|
||||
|
||||
|
@ -53,6 +53,7 @@ ohos_unittest("wifi_non_mock_unittest") {
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/hid2d",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_pro",
|
||||
"$WIFI_ROOT_DIR/interfaces/inner_api",
|
||||
"$WIFI_ROOT_DIR/frameworks/native/interfaces",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/app_network_speed_limit",
|
||||
|
@ -88,6 +88,7 @@ ohos_unittest("precompiled_macro_unittest") {
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/net_conf",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_pro",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/depends/include/hardware/libhardware/include",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/depends/include/system/core/include",
|
||||
|
@ -87,6 +87,7 @@ ohos_unittest("manager_unittest") {
|
||||
"$WIFI_ROOT_DIR/test/wifi_standard/wifi_framework/wifi_manage/wifi_ap/Mock/mock_wifi_ap_hal_interface.cpp",
|
||||
"$WIFI_ROOT_DIR/test/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/test/Mock/mock_p2p_interface.cpp",
|
||||
"$WIFI_ROOT_DIR/test/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/test/Mock/mock_wifi_p2p_hal_interface.cpp",
|
||||
"$WIFI_ROOT_DIR/test/wifi_standard/wifi_framework/wifi_manage/wifi_pro/mock/mock_wifi_pro_interface.cpp",
|
||||
"$WIFI_ROOT_DIR/test/wifi_standard/wifi_framework/wifi_manage/wifi_scan/Mock/mock_scan_interface.cpp",
|
||||
"$WIFI_ROOT_DIR/test/wifi_standard/wifi_framework/wifi_manage/wifi_scan/Mock/mock_scan_service.cpp",
|
||||
"$WIFI_ROOT_DIR/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta/Mock/mock_sta_interface.cpp",
|
||||
@ -146,6 +147,7 @@ ohos_unittest("manager_unittest") {
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/hid2d",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_pro",
|
||||
"$WIFI_ROOT_DIR/interfaces/inner_api",
|
||||
"$WIFI_ROOT_DIR/frameworks/native/interfaces",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/app_network_speed_limit",
|
||||
@ -236,6 +238,10 @@ ohos_unittest("manager_unittest") {
|
||||
"UT_TEST",
|
||||
]
|
||||
|
||||
if (wifi_feature_wifi_pro_ctrl) {
|
||||
defines += [ "FEATURE_WIFI_PRO_SUPPORT" ]
|
||||
}
|
||||
|
||||
if (is_asan) {
|
||||
sources += [ "$WIFI_ROOT_DIR/test/wifi_standard/wifi_framework/wifi_manage/wifi_scan/Mock/mock_scan_service_new.cpp" ]
|
||||
}
|
||||
|
@ -82,6 +82,7 @@ ohos_unittest("wifi_controller_unittest") {
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/hid2d",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_pro",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/network_select",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage",
|
||||
@ -97,7 +98,7 @@ ohos_unittest("wifi_controller_unittest") {
|
||||
"--coverage",
|
||||
]
|
||||
deps = [
|
||||
"$WIFI_ROOT_DIR/base:wifi_base_without_crpc",
|
||||
"$WIFI_ROOT_DIR/base:wifi_base",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common:wifi_common_service",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_native:wifi_native",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit:wifi_toolkit",
|
||||
@ -141,11 +142,14 @@ ohos_unittest("wifi_controller_unittest") {
|
||||
]
|
||||
defines += [
|
||||
"FEATURE_AP_SUPPORT",
|
||||
"FEATURE_SELF_CURE_SUPPORT",
|
||||
"FEATURE_STA_SUPPORT",
|
||||
"FEATURE_P2P_SUPPORT",
|
||||
"STA_INSTANCE_MAX_NUM=$wifi_feature_with_sta_num",
|
||||
]
|
||||
|
||||
if (wifi_feature_wifi_pro_ctrl) {
|
||||
defines += [ "FEATURE_WIFI_PRO_SUPPORT" ]
|
||||
}
|
||||
part_name = "wifi"
|
||||
subsystem_name = "communication"
|
||||
}
|
||||
|
@ -0,0 +1,142 @@
|
||||
# Copyright (C) 2024-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.
|
||||
|
||||
import("//build/test.gni")
|
||||
import("//foundation/communication/wifi/wifi/wifi.gni")
|
||||
module_output_path = "wifi/wifi_pro_unittest"
|
||||
defines = []
|
||||
|
||||
config("module_private_config") {
|
||||
visibility = [ ":*" ]
|
||||
include_dirs = [
|
||||
"$WIFI_ROOT_DIR/test/wifi_standard/wifi_framework/wifi_manage/wifi_pro",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_unittest("wifi_pro_unittest") {
|
||||
module_out_path = module_output_path
|
||||
sources = [
|
||||
"$WIFI_ROOT_DIR/frameworks/native/src/network_selection.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_pro/wifi_pro_service.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_pro/wifi_pro_state_machine.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_pro/wifi_pro_utils.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/network_select/external_wifi_common_builder_manager.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/network_select/external_wifi_filter_builder_manager.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/network_select/network_selection_manager.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/network_select/network_selection_utils.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/network_select/network_selector_factory.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/network_select/network_selector_impl.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/network_select/wifi_comparator_impl.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/network_select/wifi_filter_impl.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/network_select/wifi_scorer_impl.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/network_status_history_manager.cpp",
|
||||
"$WIFI_ROOT_DIR/test/wifi_standard/wifi_framework/wifi_manage/wifi_scan/Mock/mock_scan_interface.cpp",
|
||||
"$WIFI_ROOT_DIR/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta/Mock/mock_sta_interface.cpp",
|
||||
"$WIFI_ROOT_DIR/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta_sa/mock/mock_wifi_service_manager.cpp",
|
||||
"$WIFI_ROOT_DIR/test/wifi_standard/wifi_framework/wifi_toolkit/unittest/Mock/mock_wifi_config_center.cpp",
|
||||
"mock/mock_wifi_pro_interface.cpp",
|
||||
"wifi_pro_state_machine_test.cpp",
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
"//third_party/googletest/googlemock/include",
|
||||
"//third_party/googletest/googletest/include",
|
||||
"$WIFI_ROOT_DIR/interfaces/inner_api",
|
||||
"$WIFI_ROOT_DIR/frameworks/native/include",
|
||||
"$WIFI_ROOT_DIR/frameworks/native/interfaces",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/interface",
|
||||
"$WIFI_ROOT_DIR/base/cRPC/include",
|
||||
"$WIFI_ROOT_DIR/base/utils",
|
||||
"$WIFI_ROOT_DIR/base/state_machine/include",
|
||||
"$WIFI_ROOT_DIR/utils/inc",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/include",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/include",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/net_helper",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/log",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/config",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/utils",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/wifi_country_code",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/network_select",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_pro",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/network_black_list",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/common",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/wifi_hal_interface",
|
||||
"$WIFI_ROOT_DIR/test/wifi_standard/wifi_framework/wifi_toolkit/unittest/Mock",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"$WIFI_ROOT_DIR/base:wifi_base",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common:wifi_common_service",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_native:wifi_native",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit:wifi_toolkit",
|
||||
"$WIFI_ROOT_DIR/utils:wifi_utils",
|
||||
"//third_party/googletest:gmock_main",
|
||||
"//third_party/googletest:gtest_main",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:want",
|
||||
"ability_base:zuri",
|
||||
"ability_runtime:ability_manager",
|
||||
"ability_runtime:app_manager",
|
||||
"ability_runtime:extension_manager",
|
||||
"ability_runtime:wantagent_innerkits",
|
||||
"access_token:libaccesstoken_sdk",
|
||||
"access_token:libtokenid_sdk",
|
||||
"bundle_framework:appexecfwk_base",
|
||||
"bundle_framework:appexecfwk_core",
|
||||
"c_utils:utils",
|
||||
"cellular_data:tel_cellular_data_api",
|
||||
"core_service:tel_core_service_api",
|
||||
"data_share:datashare_consumer",
|
||||
"dhcp:dhcp_sdk",
|
||||
"hilog:libhilog",
|
||||
"init:libbegetutil",
|
||||
"ipc:ipc_single",
|
||||
"jsoncpp:jsoncpp",
|
||||
"libxml2:libxml2",
|
||||
"netmanager_base:net_conn_manager_if",
|
||||
"netmanager_base:net_native_manager_if",
|
||||
"netmanager_base:net_stats_manager_if",
|
||||
"netstack:http_client",
|
||||
"samgr:samgr_proxy",
|
||||
"time_service:time_client",
|
||||
]
|
||||
|
||||
if (wifi_ffrt_enable) {
|
||||
external_deps += [ "ffrt:libffrt" ]
|
||||
defines += [ "WIFI_FFRT_ENABLE" ]
|
||||
}
|
||||
|
||||
defines += [
|
||||
"AP_INSTANCE_MAX_NUM=$wifi_feature_with_ap_num",
|
||||
"private=public",
|
||||
"SUPPORT_RANDOM_MAC_ADDR",
|
||||
"FEATURE_SELF_CURE_SUPPORT",
|
||||
]
|
||||
|
||||
if (wifi_feature_wifi_pro_ctrl) {
|
||||
defines += [ "FEATURE_WIFI_PRO_SUPPORT" ]
|
||||
}
|
||||
part_name = "wifi"
|
||||
subsystem_name = "communication"
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (C) 2024-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 "wifi_logger.h"
|
||||
#include "wifi_pro_interface.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Wifi {
|
||||
DEFINE_WIFILOG_LABEL("WifiPrWifiProInterfaceoService");
|
||||
|
||||
WifiProInterface::WifiProInterface(int32_t instId) : instId_(instId)
|
||||
{
|
||||
WIFI_LOGI("Enter WifiProInterface");
|
||||
}
|
||||
|
||||
WifiProInterface::~WifiProInterface()
|
||||
{
|
||||
WIFI_LOGI("Enter ~WifiProInterface");
|
||||
}
|
||||
|
||||
ErrCode WifiProInterface::InitWifiProService()
|
||||
{
|
||||
WIFI_LOGI("Enter WifiProInterface::InitWifiProService");
|
||||
return WIFI_OPT_SUCCESS;
|
||||
}
|
||||
|
||||
void WifiProInterface::InitCallback()
|
||||
{
|
||||
using namespace std::placeholders;
|
||||
staCallback_.callbackModuleName = "WifiProService";
|
||||
staCallback_.OnStaConnChanged = [this](OperateResState state, const WifiLinkedInfo &linkedInfo, int32_t instId) {
|
||||
this->DealStaConnChanged(state, linkedInfo, instId);
|
||||
};
|
||||
staCallback_.OnStaRssiLevelChanged = [this](int32_t rssi, int32_t instId) {
|
||||
this->DealRssiLevelChanged(rssi, instId);
|
||||
};
|
||||
}
|
||||
|
||||
void WifiProInterface::DealStaConnChanged(OperateResState state, const WifiLinkedInfo &info, int32_t instId)
|
||||
{
|
||||
WIFI_LOGI("Enter WifiProInterface::DealStaConnChanged");
|
||||
}
|
||||
|
||||
void WifiProInterface::DealRssiLevelChanged(int32_t rssi, int32_t instId)
|
||||
{
|
||||
WIFI_LOGI("Enter WifiProInterface::DealRssiLevelChanged");
|
||||
}
|
||||
|
||||
void WifiProInterface::DealScanResult(const std::vector<InterScanInfo> &results)
|
||||
{
|
||||
WIFI_LOGI("Enter WifiProInterface::DealScanResult");
|
||||
}
|
||||
|
||||
StaServiceCallback WifiProInterface::GetStaCallback() const
|
||||
{
|
||||
return staCallback_;
|
||||
}
|
||||
|
||||
} // namespace Wifi
|
||||
} // namespace OHOS
|
@ -0,0 +1,134 @@
|
||||
/*
|
||||
* 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 <gtest/gtest.h>
|
||||
#include <gmock/gmock.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "define.h"
|
||||
#include "wifi_log.h"
|
||||
#include "wifi_errcode.h"
|
||||
#include "state_machine.h"
|
||||
#include "wifi_pro_common.h"
|
||||
#include "iscan_service.h"
|
||||
#include "wifi_logger.h"
|
||||
#include "wifi_msg.h"
|
||||
#include "wifi_pro_state_machine.h"
|
||||
#include "wifi_service_manager.h"
|
||||
#include "wifi_pro_utils.h"
|
||||
#include "net_conn_client.h"
|
||||
#include "mock_wifi_config_center.h"
|
||||
|
||||
using ::testing::_;
|
||||
using ::testing::AtLeast;
|
||||
using ::testing::DoAll;
|
||||
using ::testing::Eq;
|
||||
using ::testing::Return;
|
||||
using ::testing::SetArgReferee;
|
||||
using ::testing::StrEq;
|
||||
using ::testing::TypedEq;
|
||||
using ::testing::ext::TestSize;
|
||||
|
||||
namespace OHOS {
|
||||
namespace Wifi {
|
||||
|
||||
class WifiProStateMachineTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase() {}
|
||||
static void TearDownTestCase() {}
|
||||
virtual void SetUp()
|
||||
{
|
||||
pWifiProStateMachine_ = std::make_unique<WifiProStateMachine>();
|
||||
pWifiProStateMachine_->Initialize();
|
||||
}
|
||||
|
||||
virtual void TearDown()
|
||||
{
|
||||
if (pWifiProStateMachine_->pCurrWifiInfo_ != nullptr) {
|
||||
pWifiProStateMachine_->pCurrWifiInfo_.reset();
|
||||
}
|
||||
|
||||
if (pWifiProStateMachine_->pCurrWifiDeviceConfig_ != nullptr) {
|
||||
pWifiProStateMachine_->pCurrWifiDeviceConfig_.reset();
|
||||
}
|
||||
|
||||
pWifiProStateMachine_.reset();
|
||||
}
|
||||
|
||||
std::unique_ptr<WifiProStateMachine> pWifiProStateMachine_;
|
||||
};
|
||||
|
||||
HWTEST_F(WifiProStateMachineTest, HandleRssiChangedInLinkMonitorStateTest, TestSize.Level1)
|
||||
{
|
||||
InternalMessagePtr msg = std::make_shared<InternalMessage>();
|
||||
msg->SetMessageName(EVENT_WIFI_RSSI_CHANGED);
|
||||
msg->SetParam1(-30);
|
||||
auto pWiFiLinkMonitorState = pWifiProStateMachine_->pWifiLinkMonitorState_;
|
||||
pWiFiLinkMonitorState->rssiLevel2Or3ScanedCounter_ = 1;
|
||||
pWiFiLinkMonitorState->HandleRssiChangedInMonitor(msg);
|
||||
EXPECT_EQ(pWiFiLinkMonitorState->rssiLevel2Or3ScanedCounter_, 1);
|
||||
}
|
||||
|
||||
HWTEST_F(WifiProStateMachineTest, IsReachWifiScanThresholdTest01, TestSize.Level1)
|
||||
{
|
||||
// wifi signal 4 bars
|
||||
int32_t signalLevel = SIG_LEVEL_4;
|
||||
int32_t ret = pWifiProStateMachine_->IsReachWifiScanThreshold(signalLevel);
|
||||
EXPECT_EQ(ret, false);
|
||||
}
|
||||
|
||||
HWTEST_F(WifiProStateMachineTest, IsReachWifiScanThresholdTest02, TestSize.Level1)
|
||||
{
|
||||
// The wifi signal is lower than 3 bars
|
||||
int32_t signalLevel = SIG_LEVEL_2;
|
||||
int32_t ret = pWifiProStateMachine_->IsReachWifiScanThreshold(signalLevel);
|
||||
EXPECT_EQ(ret, true);
|
||||
}
|
||||
|
||||
HWTEST_F(WifiProStateMachineTest, IsReachWifiScanThresholdTest03, TestSize.Level1)
|
||||
{
|
||||
// The wifi signal is equal to 3 bars, and there are switching records within 14 days
|
||||
int32_t signalLevel = SIG_LEVEL_3;
|
||||
WifiLinkedInfo wifiLinkedInfo;
|
||||
wifiLinkedInfo.supplicantState = SupplicantState::INVALID;
|
||||
EXPECT_CALL(WifiConfigCenter::GetInstance(), GetLinkedInfo(_, _))
|
||||
.WillRepeatedly(DoAll(SetArgReferee<0>(wifiLinkedInfo), Return(0)));
|
||||
pWifiProStateMachine_->pCurrWifiInfo_ = std::make_shared<WifiLinkedInfo>(wifiLinkedInfo);
|
||||
|
||||
WifiDeviceConfig wifiDeviceConfig;
|
||||
wifiDeviceConfig.lastTrySwitchWifiTimestamp = WifiProUtils::GetCurrentTimeMs();
|
||||
pWifiProStateMachine_->pCurrWifiDeviceConfig_ = std::make_shared<WifiDeviceConfig>(wifiDeviceConfig);
|
||||
bool ret = pWifiProStateMachine_->IsReachWifiScanThreshold(signalLevel);
|
||||
EXPECT_EQ(ret, true);
|
||||
}
|
||||
|
||||
HWTEST_F(WifiProStateMachineTest, IsReachWifiScanThresholdTest04, TestSize.Level1)
|
||||
{
|
||||
// The wifi signal is equal to 3 bars, and there is no connection record within 14 days.
|
||||
int32_t signalLevel = SIG_LEVEL_3;
|
||||
WifiLinkedInfo wifiLinkedInfo;
|
||||
wifiLinkedInfo.supplicantState = SupplicantState::INVALID;
|
||||
EXPECT_CALL(WifiConfigCenter::GetInstance(), GetLinkedInfo(_, _))
|
||||
.WillRepeatedly(DoAll(SetArgReferee<0>(wifiLinkedInfo), Return(0)));
|
||||
pWifiProStateMachine_->pCurrWifiInfo_ = std::make_shared<WifiLinkedInfo>(wifiLinkedInfo);
|
||||
|
||||
WifiDeviceConfig wifiDeviceConfig;
|
||||
wifiDeviceConfig.lastTrySwitchWifiTimestamp = 0;
|
||||
pWifiProStateMachine_->pCurrWifiDeviceConfig_ = std::make_shared<WifiDeviceConfig>(wifiDeviceConfig);
|
||||
bool ret = pWifiProStateMachine_->IsReachWifiScanThreshold(signalLevel);
|
||||
EXPECT_EQ(ret, false);
|
||||
}
|
||||
} // namespace Wifi
|
||||
} // namespace OHOS
|
@ -72,6 +72,7 @@ ohos_unittest("wifi_scan_unittest") {
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/net_conf",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_pro",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sub_manage",
|
||||
"//base/hiviewdfx/hilog/interfaces/native/innerkits/include",
|
||||
|
@ -21,7 +21,6 @@ defines += [ "OHOS_WIFI_STA_TEST" ]
|
||||
config("module_private_config") {
|
||||
visibility = [ ":*" ]
|
||||
include_dirs = [
|
||||
"//commonlibrary/c_utils/base/include",
|
||||
"$WIFI_ROOT_DIR/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta",
|
||||
]
|
||||
}
|
||||
@ -35,6 +34,7 @@ local_base_sources = [
|
||||
"$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/wifi_app_state_aware.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/wifi_auth_center.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/wifi_channel_helper.cpp",
|
||||
@ -105,9 +105,11 @@ local_base_include_dirs = [
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/client/idl_client/idl_interface",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/wifi_country_code",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/network_black_list",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_pro",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/network_select",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_controller",
|
||||
@ -289,6 +291,10 @@ ohos_unittest("wifi_selfcure_unittest") {
|
||||
"FEATURE_AP_SUPPORT",
|
||||
"FEATURE_STA_SUPPORT",
|
||||
]
|
||||
|
||||
if (wifi_feature_wifi_pro_ctrl) {
|
||||
defines += [ "FEATURE_WIFI_PRO_SUPPORT" ]
|
||||
}
|
||||
part_name = "wifi"
|
||||
subsystem_name = "communication"
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ ErrCode StaInterface::DisableStaService()
|
||||
return WIFI_OPT_SUCCESS;
|
||||
}
|
||||
|
||||
ErrCode StaInterface::ConnectToNetwork(int networkId)
|
||||
ErrCode StaInterface::ConnectToNetwork(int networkId, int type)
|
||||
{
|
||||
LOGI("Enter Connect.\n");
|
||||
return WIFI_OPT_SUCCESS;
|
||||
|
@ -28,7 +28,7 @@ public:
|
||||
MOCK_METHOD0(EnableStaService, ErrCode());
|
||||
MOCK_CONST_METHOD0(DisableStaService, ErrCode());
|
||||
MOCK_CONST_METHOD1(ConnectToDevice, ErrCode(const WifiDeviceConfig &config));
|
||||
MOCK_CONST_METHOD1(ConnectToNetwork, ErrCode(int networkId));
|
||||
MOCK_CONST_METHOD2(ConnectToNetwork, ErrCode(int networkId, int type));
|
||||
MOCK_CONST_METHOD0(ReConnect, ErrCode());
|
||||
MOCK_CONST_METHOD0(Disconnect, ErrCode());
|
||||
MOCK_CONST_METHOD0(ReAssociate, ErrCode());
|
||||
|
@ -883,10 +883,10 @@ public:
|
||||
pSelfCureStateMachine->pInternetSelfCureState->currentRssi = MIN_VAL_LEVEL_4;
|
||||
pSelfCureStateMachine->pInternetSelfCureState->SelfCureForRandMacReassoc(requestCureLevel);
|
||||
|
||||
EXPECT_CALL(*pMockStaService, ConnectToNetwork(_)).WillRepeatedly(Return(WIFI_OPT_FAILED));
|
||||
EXPECT_CALL(*pMockStaService, ConnectToNetwork(_, _)).WillRepeatedly(Return(WIFI_OPT_FAILED));
|
||||
pSelfCureStateMachine->pInternetSelfCureState->SelfCureForRandMacReassoc(requestCureLevel);
|
||||
|
||||
EXPECT_CALL(*pMockStaService, ConnectToNetwork(_)).WillRepeatedly(Return(WIFI_OPT_SUCCESS));
|
||||
EXPECT_CALL(*pMockStaService, ConnectToNetwork(_, _)).WillRepeatedly(Return(WIFI_OPT_SUCCESS));
|
||||
pSelfCureStateMachine->pInternetSelfCureState->SelfCureForRandMacReassoc(requestCureLevel);
|
||||
}
|
||||
|
||||
@ -1049,10 +1049,10 @@ public:
|
||||
pSelfCureStateMachine->useWithRandMacAddress = FAC_MAC_REASSOC;
|
||||
pSelfCureStateMachine->pInternetSelfCureState->HandleSelfCureFailedForRandMacReassoc();
|
||||
|
||||
EXPECT_CALL(*pMockStaService, ConnectToNetwork(_)).WillRepeatedly(Return(WIFI_OPT_FAILED));
|
||||
EXPECT_CALL(*pMockStaService, ConnectToNetwork(_, _)).WillRepeatedly(Return(WIFI_OPT_FAILED));
|
||||
pSelfCureStateMachine->pInternetSelfCureState->HandleSelfCureFailedForRandMacReassoc();
|
||||
|
||||
EXPECT_CALL(*pMockStaService, ConnectToNetwork(_)).WillRepeatedly(Return(WIFI_OPT_SUCCESS));
|
||||
EXPECT_CALL(*pMockStaService, ConnectToNetwork(_, _)).WillRepeatedly(Return(WIFI_OPT_SUCCESS));
|
||||
pSelfCureStateMachine->pInternetSelfCureState->HandleSelfCureFailedForRandMacReassoc();
|
||||
|
||||
pSelfCureStateMachine->useWithRandMacAddress = RAND_MAC_REASSOC;
|
||||
@ -1529,10 +1529,10 @@ public:
|
||||
Return(MODE_STATE_CLOSE));
|
||||
pSelfCureStateMachine->pDisconnectedMonitorState->HandleResetConnectNetwork(msg);
|
||||
|
||||
EXPECT_CALL(*pMockStaService, ConnectToNetwork(_)).WillRepeatedly(Return(WIFI_OPT_FAILED));
|
||||
EXPECT_CALL(*pMockStaService, ConnectToNetwork(_, _)).WillRepeatedly(Return(WIFI_OPT_FAILED));
|
||||
pSelfCureStateMachine->pDisconnectedMonitorState->HandleResetConnectNetwork(msg);
|
||||
|
||||
EXPECT_CALL(*pMockStaService, ConnectToNetwork(_)).WillRepeatedly(Return(WIFI_OPT_SUCCESS));
|
||||
EXPECT_CALL(*pMockStaService, ConnectToNetwork(_, _)).WillRepeatedly(Return(WIFI_OPT_SUCCESS));
|
||||
pSelfCureStateMachine->pDisconnectedMonitorState->HandleResetConnectNetwork(msg);
|
||||
}
|
||||
|
||||
|
@ -93,14 +93,14 @@ public:
|
||||
void ConnectToNetworkIdSuceess()
|
||||
{
|
||||
int networkId = 0;
|
||||
EXPECT_CALL(*pMockStaService, ConnectToNetwork(networkId)).WillRepeatedly(Return(WIFI_OPT_SUCCESS));
|
||||
EXPECT_CALL(*pMockStaService, ConnectToNetwork(networkId, _)).WillRepeatedly(Return(WIFI_OPT_SUCCESS));
|
||||
EXPECT_TRUE(pStaInterface->ConnectToNetwork(0) == WIFI_OPT_SUCCESS);
|
||||
}
|
||||
|
||||
void ConnectToNetworkIdFail1()
|
||||
{
|
||||
int networkId = 0;
|
||||
EXPECT_CALL(*pMockStaService, ConnectToNetwork(networkId)).WillRepeatedly(Return(WIFI_OPT_FAILED));
|
||||
EXPECT_CALL(*pMockStaService, ConnectToNetwork(networkId, _)).WillRepeatedly(Return(WIFI_OPT_FAILED));
|
||||
EXPECT_TRUE(pStaInterface->ConnectToNetwork(0) == WIFI_OPT_FAILED);
|
||||
}
|
||||
|
||||
|
@ -1,158 +1,160 @@
|
||||
# Copyright (C) 2021-2023 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.
|
||||
|
||||
import("//build/test.gni")
|
||||
import("//foundation/communication/wifi/wifi/wifi.gni")
|
||||
|
||||
################################################################################
|
||||
|
||||
module_output_path = "wifi/wifi_sta_new_test"
|
||||
|
||||
config("module_private_config") {
|
||||
visibility = [ ":*" ]
|
||||
include_dirs = []
|
||||
}
|
||||
|
||||
ohos_unittest("wifi_sta_new_unittest") {
|
||||
module_out_path = module_output_path
|
||||
sources = [
|
||||
"$WIFI_ROOT_DIR/frameworks/native/src/network_selection.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/network_select/external_wifi_common_builder_manager.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/network_select/external_wifi_filter_builder_manager.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/network_select/network_selection_manager.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/network_select/network_selection_utils.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/network_select/network_selector_factory.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/network_select/network_selector_impl.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/network_select/wifi_comparator_impl.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/network_select/wifi_filter_impl.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/network_select/wifi_scorer_impl.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/network_status_history_manager.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_app_acceleration.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_auto_connect_service.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_interface.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_monitor.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_saved_device_appraisal.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_service.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_state_machine.cpp",
|
||||
"$WIFI_ROOT_DIR/test/wifi_standard/wifi_framework/wifi_manage/wifi_native/Mock/mock_wifi_sta_hal_interface.cpp",
|
||||
"$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/mock_if_config.cpp",
|
||||
"$WIFI_ROOT_DIR/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta/Mock/mock_wifi_settings.cpp",
|
||||
"$WIFI_ROOT_DIR/test/wifi_standard/wifi_framework/wifi_toolkit/unittest/Mock/mock_wifi_config_center.cpp",
|
||||
"network_status_history_manager_test.cpp",
|
||||
"sta_app_acceleration_test.cpp",
|
||||
"sta_auto_connect_service_test.cpp",
|
||||
"sta_interface_test.cpp",
|
||||
"sta_monitor_test.cpp",
|
||||
"wifi_scorer_impl_test.cpp",
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
"$WIFI_ROOT_DIR/interfaces/inner_api",
|
||||
"$WIFI_ROOT_DIR/frameworks/native/interfaces",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/sdk/include",
|
||||
"$WIFI_ROOT_DIR/base/cRPC/include",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/include",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/net_helper",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/log",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/config",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/utils",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan",
|
||||
"$WIFI_ROOT_DIR/test/wifi_standard/wifi_framework/wifi_manage/wifi_scan",
|
||||
"$WIFI_ROOT_DIR/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta/Mock",
|
||||
"$WIFI_ROOT_DIR/test/wifi_standard/wifi_framework/wifi_toolkit/unittest/Mock",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/common",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/wifi_hal_interface",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/client/idl_client",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/client/idl_client/idl_interface",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/net_conf",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/depends/include/hardware/libhardware/include",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/depends/include/system/core/include",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/depends/include/frameworks/native/include",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/depends/include/system/core/libutils/include",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/depends/include/system/core/base/include",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/depends/include/system/libbase/include",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/depends/include/system/core/libnetutils/include/netutils",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/network_select",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/wifi_country_code",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/wifi_network_stats",
|
||||
"//third_party/googletest/googlemock/include",
|
||||
"//third_party/googletest/googletest/include",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/include",
|
||||
"$WIFI_ROOT_DIR/utils/inc",
|
||||
"$WIFI_ROOT_DIR/test/wifi_standard/wifi_framework/wifi_manage/unittest/Mock",
|
||||
"$WIFI_ROOT_DIR/base/utils",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/app_network_speed_limit",
|
||||
"$WIFI_ROOT_DIR/test/wifi_standard/wifi_framework/wifi_manage/wifi_native/Mock",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"$WIFI_ROOT_DIR/base:wifi_base",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage:wifi_manager_service",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common:wifi_common_service",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit:wifi_toolkit",
|
||||
"$WIFI_ROOT_DIR/utils:wifi_utils",
|
||||
"//third_party/googletest:gmock_main",
|
||||
"//third_party/googletest:gtest_main",
|
||||
]
|
||||
|
||||
deps += [
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage:wifi_device_ability",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage:wifi_hotspot_ability",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage:wifi_scan_ability",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_native:wifi_native",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta:wifi_sta_service",
|
||||
]
|
||||
|
||||
ldflags = [
|
||||
"-fPIC",
|
||||
"--coverage",
|
||||
"-Wl,-E",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:want",
|
||||
"ability_base:zuri",
|
||||
"ability_runtime:ability_manager",
|
||||
"ability_runtime:app_manager",
|
||||
"ability_runtime:wantagent_innerkits",
|
||||
"bundle_framework:appexecfwk_base",
|
||||
"bundle_framework:appexecfwk_core",
|
||||
"c_utils:utils",
|
||||
"cellular_data:tel_cellular_data_api",
|
||||
"core_service:tel_core_service_api",
|
||||
"dhcp:dhcp_sdk",
|
||||
"hilog:libhilog",
|
||||
"init:libbegetutil",
|
||||
"ipc:ipc_single",
|
||||
"netmanager_base:net_conn_manager_if",
|
||||
"time_service:time_client",
|
||||
]
|
||||
|
||||
defines = [
|
||||
"private = public",
|
||||
"protected = public",
|
||||
"SUPPORT_SCAN_CONTROL",
|
||||
"SUPPORT_LOCAL_RANDOM_MAC",
|
||||
]
|
||||
|
||||
part_name = "wifi"
|
||||
subsystem_name = "communication"
|
||||
testonly = true
|
||||
}
|
||||
# Copyright (C) 2021-2023 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.
|
||||
|
||||
import("//build/test.gni")
|
||||
import("//foundation/communication/wifi/wifi/wifi.gni")
|
||||
|
||||
################################################################################
|
||||
|
||||
module_output_path = "wifi/wifi_sta_new_test"
|
||||
|
||||
config("module_private_config") {
|
||||
visibility = [ ":*" ]
|
||||
include_dirs = []
|
||||
}
|
||||
|
||||
ohos_unittest("wifi_sta_new_unittest") {
|
||||
module_out_path = module_output_path
|
||||
sources = [
|
||||
"$WIFI_ROOT_DIR/frameworks/native/src/network_selection.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/network_select/external_wifi_common_builder_manager.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/network_select/external_wifi_filter_builder_manager.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/network_select/network_selection_manager.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/network_select/network_selection_utils.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/network_select/network_selector_factory.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/network_select/network_selector_impl.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/network_select/wifi_comparator_impl.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/network_select/wifi_filter_impl.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/network_select/wifi_scorer_impl.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/network_status_history_manager.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_app_acceleration.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_auto_connect_service.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_interface.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_monitor.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_saved_device_appraisal.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_service.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_state_machine.cpp",
|
||||
"$WIFI_ROOT_DIR/test/wifi_standard/wifi_framework/wifi_manage/wifi_native/Mock/mock_wifi_sta_hal_interface.cpp",
|
||||
"$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/mock_if_config.cpp",
|
||||
"$WIFI_ROOT_DIR/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta/Mock/mock_wifi_settings.cpp",
|
||||
"$WIFI_ROOT_DIR/test/wifi_standard/wifi_framework/wifi_toolkit/unittest/Mock/mock_wifi_config_center.cpp",
|
||||
"network_status_history_manager_test.cpp",
|
||||
"sta_app_acceleration_test.cpp",
|
||||
"sta_auto_connect_service_test.cpp",
|
||||
"sta_interface_test.cpp",
|
||||
"sta_monitor_test.cpp",
|
||||
"wifi_scorer_impl_test.cpp",
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
"$WIFI_ROOT_DIR/interfaces/inner_api",
|
||||
"$WIFI_ROOT_DIR/frameworks/native/interfaces",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/sdk/include",
|
||||
"$WIFI_ROOT_DIR/base/cRPC/include",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/include",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/net_helper",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/log",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/config",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/utils",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan",
|
||||
"$WIFI_ROOT_DIR/test/wifi_standard/wifi_framework/wifi_manage/wifi_scan",
|
||||
"$WIFI_ROOT_DIR/test/wifi_standard/wifi_framework/wifi_manage/wifi_sta/Mock",
|
||||
"$WIFI_ROOT_DIR/test/wifi_standard/wifi_framework/wifi_toolkit/unittest/Mock",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/common",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/wifi_hal_interface",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/client/idl_client",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/client/idl_client/idl_interface",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/net_conf",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_self_cure",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_pro",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/depends/include/hardware/libhardware/include",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/depends/include/system/core/include",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/depends/include/frameworks/native/include",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/depends/include/system/core/libutils/include",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/depends/include/system/core/base/include",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/depends/include/system/libbase/include",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/depends/include/system/core/libnetutils/include/netutils",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/network_select",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/wifi_country_code",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/network_black_list",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/wifi_network_stats",
|
||||
"//third_party/googletest/googlemock/include",
|
||||
"//third_party/googletest/googletest/include",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/include",
|
||||
"$WIFI_ROOT_DIR/utils/inc",
|
||||
"$WIFI_ROOT_DIR/test/wifi_standard/wifi_framework/wifi_manage/unittest/Mock",
|
||||
"$WIFI_ROOT_DIR/base/utils",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common/app_network_speed_limit",
|
||||
"$WIFI_ROOT_DIR/test/wifi_standard/wifi_framework/wifi_manage/wifi_native/Mock",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"$WIFI_ROOT_DIR/base:wifi_base",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage:wifi_manager_service",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common:wifi_common_service",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit:wifi_toolkit",
|
||||
"$WIFI_ROOT_DIR/utils:wifi_utils",
|
||||
"//third_party/googletest:gmock_main",
|
||||
"//third_party/googletest:gtest_main",
|
||||
]
|
||||
|
||||
deps += [
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage:wifi_device_ability",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage:wifi_hotspot_ability",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage:wifi_scan_ability",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_native:wifi_native",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta:wifi_sta_service",
|
||||
]
|
||||
|
||||
ldflags = [
|
||||
"-fPIC",
|
||||
"--coverage",
|
||||
"-Wl,-E",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:want",
|
||||
"ability_base:zuri",
|
||||
"ability_runtime:ability_manager",
|
||||
"ability_runtime:app_manager",
|
||||
"ability_runtime:wantagent_innerkits",
|
||||
"bundle_framework:appexecfwk_base",
|
||||
"bundle_framework:appexecfwk_core",
|
||||
"c_utils:utils",
|
||||
"cellular_data:tel_cellular_data_api",
|
||||
"core_service:tel_core_service_api",
|
||||
"dhcp:dhcp_sdk",
|
||||
"hilog:libhilog",
|
||||
"init:libbegetutil",
|
||||
"ipc:ipc_single",
|
||||
"netmanager_base:net_conn_manager_if",
|
||||
"time_service:time_client",
|
||||
]
|
||||
|
||||
defines = [
|
||||
"private = public",
|
||||
"protected = public",
|
||||
"SUPPORT_SCAN_CONTROL",
|
||||
"SUPPORT_LOCAL_RANDOM_MAC",
|
||||
]
|
||||
|
||||
part_name = "wifi"
|
||||
subsystem_name = "communication"
|
||||
testonly = true
|
||||
}
|
||||
|
@ -25,6 +25,7 @@
|
||||
#endif
|
||||
#include "scan_interface.h"
|
||||
#include "sta_interface.h"
|
||||
#include "wifi_pro_interface.h"
|
||||
#ifdef FEATURE_SELF_CURE_SUPPORT
|
||||
#include "self_cure_interface.h"
|
||||
#endif
|
||||
@ -67,6 +68,14 @@ int WifiServiceManager::LoadStaService(const std::string &dlname, int instId, bo
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef FEATURE_WIFI_PRO_SUPPORT
|
||||
int32_t WifiServiceManager::LoadWifiProService(bool bCreate, int32_t instId)
|
||||
{
|
||||
WIFI_LOGI("WifiServiceManager::LoadWifiProService");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef FEATURE_SELF_CURE_SUPPORT
|
||||
int WifiServiceManager::LoadSelfCureService(const std::string &dlname, bool bCreate)
|
||||
{
|
||||
@ -115,6 +124,14 @@ IStaService *WifiServiceManager::GetStaServiceInst(int instId)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
#ifdef FEATURE_WIFI_PRO_SUPPORT
|
||||
IWifiProService *WifiServiceManager::GetWifiProServiceInst(int32_t instId)
|
||||
{
|
||||
WIFI_LOGD("WifiServiceManager::GetWifiProServiceInst, instId: %{public}d", instId);
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef FEATURE_SELF_CURE_SUPPORT
|
||||
ISelfCureService *WifiServiceManager::GetSelfCureServiceInst(int instId)
|
||||
{
|
||||
@ -154,6 +171,14 @@ IEnhanceService *WifiServiceManager::GetEnhanceServiceInst()
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
#ifdef FEATURE_WIFI_PRO_SUPPORT
|
||||
NO_SANITIZE("cfi") int32_t WifiServiceManager::UnloadWifiProService(bool bPreLoad, int32_t instId)
|
||||
{
|
||||
WIFI_LOGI("WifiServiceManager::UnloadWifiProService, instId: %{public}d", instId);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef FEATURE_SELF_CURE_SUPPORT
|
||||
NO_SANITIZE("cfi") int WifiServiceManager::UnloadSelfCureService(bool bPreLoad, int instId)
|
||||
{
|
||||
|
@ -29,35 +29,39 @@ public:
|
||||
|
||||
explicit WifiEventHandler(const std::string &threadName, const Callback &timeOutFunc = nullptr);
|
||||
~WifiEventHandler();
|
||||
/**
|
||||
* @submit sync task to Handler
|
||||
*
|
||||
* @param Callback - Input task
|
||||
* @return bool - true: submit success, false: submit failed
|
||||
*/
|
||||
|
||||
/**
|
||||
* @submit sync task to Handler
|
||||
*
|
||||
* @param Callback - Input task
|
||||
* @return bool - true: submit success, false: submit failed
|
||||
*/
|
||||
bool PostSyncTask(const Callback &callback);
|
||||
/**
|
||||
* @submit Async task to Handler
|
||||
*
|
||||
* @param Callback - Input task
|
||||
* @param delayTime - Wait delayTime ms excute task
|
||||
* @return bool - true: submit success, false: submit failed
|
||||
*/
|
||||
|
||||
/**
|
||||
* @submit Async task to Handler
|
||||
*
|
||||
* @param Callback - Input task
|
||||
* @param delayTime - Wait delayTime ms excute task
|
||||
* @return bool - true: submit success, false: submit failed
|
||||
*/
|
||||
bool PostAsyncTask(const Callback &callback, int64_t delayTime = 0);
|
||||
/**
|
||||
* @submit Async task to Handler
|
||||
*
|
||||
* @param Callback - Input task
|
||||
* @param name - Describer of task
|
||||
* @param delayTime - Wait delayTime ms excute task
|
||||
* @return bool - true: submit success, false: submit failed
|
||||
*/
|
||||
|
||||
/**
|
||||
* @submit Async task to Handler
|
||||
*
|
||||
* @param Callback - Input task
|
||||
* @param name - Describer of task
|
||||
* @param delayTime - Wait delayTime ms excute task
|
||||
* @return bool - true: submit success, false: submit failed
|
||||
*/
|
||||
bool PostAsyncTask(const Callback &callback, const std::string &name, int64_t delayTime = 0);
|
||||
/**
|
||||
* @Remove Async task
|
||||
*
|
||||
* @param name - Describer of task
|
||||
*/
|
||||
|
||||
/**
|
||||
* @Remove Async task
|
||||
*
|
||||
* @param name - Describer of task
|
||||
*/
|
||||
void RemoveAsyncTask(const std::string &name);
|
||||
|
||||
/**
|
||||
|
@ -31,6 +31,7 @@ declare_args() {
|
||||
wifi_feature_non_seperate_p2p = false
|
||||
wifi_feature_non_hdf_driver = false
|
||||
wifi_feature_with_local_random_mac = true
|
||||
wifi_feature_wifi_pro_ctrl = true
|
||||
if (defined(global_parts_info) &&
|
||||
defined(global_parts_info.resourceschedule_efficiency_manager)) {
|
||||
wifi_feature_with_app_frozen = true
|
||||
|
@ -29,6 +29,7 @@ declare_args() {
|
||||
wifi_feature_with_hpf_supported = false
|
||||
wifi_feature_with_hdi_wpa_supported = false
|
||||
wifi_feature_with_vap_manager = false
|
||||
wifi_feature_wifi_pro_ctrl = true
|
||||
}
|
||||
|
||||
memory_optimization_cflags = [
|
||||
|
Loading…
Reference in New Issue
Block a user