mirror of
https://gitee.com/openharmony/communication_wifi.git
synced 2024-12-18 20:40:11 +00:00
Merge branch 'master' of gitee.com:openharmony/communication_wifi into master
Signed-off-by: 吴俊 <wujun156@huawei.com>
This commit is contained in:
commit
0e8498746a
@ -60,7 +60,8 @@
|
||||
"wifi_feature_with_local_random_mac",
|
||||
"wifi_feature_sta_ap_exclusion",
|
||||
"wifi_feature_with_random_mac_addr",
|
||||
"wifi_feature_with_hdi_wpa_supported"
|
||||
"wifi_feature_with_hdi_wpa_supported",
|
||||
"wifi_feature_with_scan_control"
|
||||
],
|
||||
"adapted_system_type": [
|
||||
"small",
|
||||
@ -93,6 +94,7 @@
|
||||
"i18n",
|
||||
"init",
|
||||
"ipc",
|
||||
"movement",
|
||||
"napi",
|
||||
"netmanager_base",
|
||||
"netstack",
|
||||
@ -149,7 +151,8 @@
|
||||
"//foundation/communication/wifi/wifi/test/wifi_standard/wifi_framework/wifi_manage/unittest:unittest",
|
||||
"//foundation/communication/wifi/wifi/test/wifi_standard/wifi_framework/wifi_manage/idl_client/unittest:unittest",
|
||||
"//foundation/communication/wifi/wifi/test/wifi_standard/wifi_hal/unittest:unittest",
|
||||
"//foundation/communication/wifi/wifi/test/wifi_standard/native:unittest"
|
||||
"//foundation/communication/wifi/wifi/test/wifi_standard/native:unittest",
|
||||
"//foundation/communication/wifi/wifi/test/wifi_standard/wifi_base:unittest"
|
||||
]
|
||||
},
|
||||
"hisysevent_config": [
|
||||
|
@ -95,6 +95,16 @@ public:
|
||||
*/
|
||||
virtual ErrCode GetScanOnlyAvailable(bool &bScanOnlyAvailable) = 0;
|
||||
|
||||
/**
|
||||
* @Description Start/Stop wifi pno scan.
|
||||
*
|
||||
* @param isStartAction - start or stop pno scan
|
||||
* @param periodMs - pno scan interval
|
||||
* @param suspendReason - pno scan suspend reason
|
||||
* @return success: WIFI_OPT_SUCCESS, failed: WIFI_OPT_FAILED
|
||||
*/
|
||||
virtual ErrCode StartWifiPnoScan(bool isStartAction, int periodMs, int suspendReason) = 0;
|
||||
|
||||
#ifdef OHOS_ARCH_LITE
|
||||
virtual ErrCode RegisterCallBack(const std::shared_ptr<IWifiScanCallback> &callback,
|
||||
const std::vector<std::string> &event) = 0;
|
||||
|
@ -171,6 +171,7 @@ enum class ScanInterfaceCode {
|
||||
/* 新增WIFI_SVR_CMD_类code,请在此下方添加 */
|
||||
WIFI_SVR_CMD_SET_WIFI_SCAN_ONLY = 0x101F, /*set scan only*/
|
||||
WIFI_SVR_CMD_GET_WIFI_SCAN_ONLY = 0x1020, /*get scan only*/
|
||||
WIFI_SVR_CMD_START_PNO_SCAN = 0x1021, /*start pno scan*/
|
||||
|
||||
/* 以下CALL BACK类code,不需要进行权限校验 */
|
||||
WIFI_CBK_CMD_SCAN_STATE_CHANGE = 0x3300, /* SCAN state change event */
|
||||
|
@ -110,6 +110,7 @@ int WifiHotspotCallbackStub::RemoteOnHotspotStaLeave(uint32_t code, MessageParce
|
||||
|
||||
void WifiHotspotCallbackStub::RegisterCallBack(const sptr<IWifiHotspotCallback> &callBack)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(callBackEventMutex);
|
||||
if (callBack == nullptr) {
|
||||
WIFI_LOGD("RegisterCallBack:callBack is nullptr!");
|
||||
return;
|
||||
|
@ -16,6 +16,7 @@
|
||||
#ifndef OHOS_WIFI_HOTSPOT_CALLBACK_STUB_H
|
||||
#define OHOS_WIFI_HOTSPOT_CALLBACK_STUB_H
|
||||
|
||||
#include <mutex>
|
||||
#include "iremote_stub.h"
|
||||
#include "i_wifi_hotspot_callback.h"
|
||||
|
||||
@ -43,7 +44,7 @@ private:
|
||||
|
||||
private:
|
||||
sptr<IWifiHotspotCallback> userCallback_;
|
||||
|
||||
std::mutex callBackEventMutex;
|
||||
bool mRemoteDied;
|
||||
};
|
||||
} // namespace Wifi
|
||||
|
@ -83,6 +83,7 @@ int WifiP2pCallbackStub::OnRemoteRequest(
|
||||
|
||||
void WifiP2pCallbackStub::RegisterCallBack(const sptr<IWifiP2pCallback> &userCallback)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(callBackEventMutex);
|
||||
if (userCallback_ != nullptr) {
|
||||
WIFI_LOGD("Callback has registered!");
|
||||
return;
|
||||
|
@ -15,6 +15,7 @@
|
||||
#ifndef OHOS_WIFI_P2P_CALLBACK_STUB_H
|
||||
#define OHOS_WIFI_P2P_CALLBACK_STUB_H
|
||||
|
||||
#include <mutex>
|
||||
#include <map>
|
||||
#include "iremote_stub.h"
|
||||
#include "i_wifi_p2p_callback.h"
|
||||
@ -121,6 +122,7 @@ private:
|
||||
HandleFuncMap handleFuncMap;
|
||||
sptr<IWifiP2pCallback> userCallback_;
|
||||
bool mRemoteDied;
|
||||
std::mutex callBackEventMutex;
|
||||
};
|
||||
} // namespace Wifi
|
||||
} // namespace OHOS
|
||||
|
@ -199,5 +199,12 @@ ErrCode WifiScanImpl::GetScanOnlyAvailable(bool &bScanOnlyAvailable)
|
||||
RETURN_IF_FAIL(GetWifiScanProxy());
|
||||
return client_->GetScanOnlyAvailable(bScanOnlyAvailable);
|
||||
}
|
||||
|
||||
ErrCode WifiScanImpl::StartWifiPnoScan(bool isStartAction, int periodMs, int suspendReason)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
RETURN_IF_FAIL(GetWifiScanProxy());
|
||||
return client_->StartWifiPnoScan(isStartAction, periodMs, suspendReason);
|
||||
}
|
||||
} // namespace Wifi
|
||||
} // namespace OHOS
|
||||
|
@ -112,6 +112,16 @@ public:
|
||||
*/
|
||||
ErrCode GetScanOnlyAvailable(bool &bScanOnlyAvailable) override;
|
||||
|
||||
/**
|
||||
* @Description Start pno scan
|
||||
*
|
||||
* @param isStartAction - true:start pno scan; false:stop pno scan
|
||||
* @param periodMs - pno scan interval
|
||||
* @param suspendReason - pno scan suspent reason
|
||||
* @return ErrCode - operation result
|
||||
*/
|
||||
ErrCode StartWifiPnoScan(bool isStartAction, int periodMs, int suspendReason) override;
|
||||
|
||||
private:
|
||||
bool GetWifiScanProxy();
|
||||
int systemAbilityId_;
|
||||
|
@ -145,6 +145,7 @@ ErrCode WifiScanProxy::Scan(bool compatible)
|
||||
}
|
||||
data.WriteInt32(0);
|
||||
data.WriteBool(compatible);
|
||||
data.WriteString(GetBundleName());
|
||||
int error = Remote()->SendRequest(static_cast<uint32_t>(ScanInterfaceCode::WIFI_SVR_CMD_FULL_SCAN), data, reply,
|
||||
option);
|
||||
if (error != ERR_NONE) {
|
||||
@ -185,6 +186,7 @@ ErrCode WifiScanProxy::AdvanceScan(const WifiScanParams ¶ms)
|
||||
data.WriteInt32(params.freqs[i]);
|
||||
}
|
||||
data.WriteInt32(params.band);
|
||||
data.WriteString(GetBundleName());
|
||||
|
||||
int error = Remote()->SendRequest(static_cast<uint32_t>(ScanInterfaceCode::WIFI_SVR_CMD_SPECIFIED_PARAMS_SCAN),
|
||||
data, reply, option);
|
||||
@ -475,5 +477,39 @@ ErrCode WifiScanProxy::GetScanOnlyAvailable(bool &bScanOnlyAvailable)
|
||||
bScanOnlyAvailable = reply.ReadBool();
|
||||
return WIFI_OPT_SUCCESS;
|
||||
}
|
||||
|
||||
ErrCode WifiScanProxy::StartWifiPnoScan(bool isStartAction, int periodMs, int suspendReason)
|
||||
{
|
||||
if (mRemoteDied) {
|
||||
WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
|
||||
return WIFI_OPT_FAILED;
|
||||
}
|
||||
MessageOption option;
|
||||
MessageParcel data, reply;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
WIFI_LOGE("Write interface token error: %{public}s", __func__);
|
||||
return WIFI_OPT_FAILED;
|
||||
}
|
||||
data.WriteInt32(0);
|
||||
data.WriteBool(isStartAction);
|
||||
data.WriteInt32(periodMs);
|
||||
data.WriteInt32(suspendReason);
|
||||
int error = Remote()->SendRequest(static_cast<uint32_t>(ScanInterfaceCode::WIFI_SVR_CMD_START_PNO_SCAN),
|
||||
data, reply, option);
|
||||
if (error != ERR_NONE) {
|
||||
WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
|
||||
static_cast<int32_t>(ScanInterfaceCode::WIFI_SVR_CMD_START_PNO_SCAN), error);
|
||||
return WIFI_OPT_FAILED;
|
||||
}
|
||||
int exception = reply.ReadInt32();
|
||||
if (exception) {
|
||||
return WIFI_OPT_FAILED;
|
||||
}
|
||||
int ret = reply.ReadInt32();
|
||||
if (ret != WIFI_OPT_SUCCESS) {
|
||||
return ErrCode(ret);
|
||||
}
|
||||
return WIFI_OPT_SUCCESS;
|
||||
}
|
||||
} // namespace Wifi
|
||||
} // namespace OHOS
|
||||
|
@ -123,6 +123,16 @@ public:
|
||||
*/
|
||||
ErrCode GetScanOnlyAvailable(bool &bScanOnlyAvailable) override;
|
||||
|
||||
/**
|
||||
* @Description Start pno scan
|
||||
*
|
||||
* @param isStartAction - true:start pno scan; false:stop pno scan
|
||||
* @param periodMs - pno scan interval
|
||||
* @param suspendReason - pno scan suspent reason
|
||||
* @return ErrCode - operation result
|
||||
*/
|
||||
ErrCode StartWifiPnoScan(bool isStartAction, int periodMs, int suspendReason) override;
|
||||
|
||||
#ifdef OHOS_ARCH_LITE
|
||||
void OnRemoteDied(void);
|
||||
private:
|
||||
|
@ -98,6 +98,16 @@ public:
|
||||
* @return ErrCode - operation result
|
||||
*/
|
||||
virtual ErrCode GetScanOnlyAvailable(bool &bScanOnlyAvailable) = 0;
|
||||
|
||||
/**
|
||||
* @Description Start pno scan
|
||||
*
|
||||
* @param isStartAction - true:start pno scan; false:stop pno scan
|
||||
* @param periodMs - pno scan interval
|
||||
* @param suspendReason - pno scan suspent reason
|
||||
* @return ErrCode - operation result
|
||||
*/
|
||||
virtual ErrCode StartWifiPnoScan(bool isStartAction, int periodMs, int suspendReason) = 0;
|
||||
};
|
||||
} // namespace Wifi
|
||||
} // namespace OHOS
|
||||
|
@ -21,7 +21,8 @@
|
||||
"ohos.permission.ACCESS_CERT_MANAGER",
|
||||
"ohos.permission.GET_RUNNING_INFO",
|
||||
"ohos.permission.START_ABILITIES_FROM_BACKGROUND",
|
||||
"ohos.permission.MANAGE_SECURE_SETTINGS"
|
||||
"ohos.permission.MANAGE_SECURE_SETTINGS",
|
||||
"ohos.permission.ACTIVITY_MOTION"
|
||||
],
|
||||
"secon" : "u:r:wifi_manager_service:s0"
|
||||
}
|
||||
|
@ -432,13 +432,20 @@ if (defined(ohos_lite)) {
|
||||
"wifi_manager.cpp",
|
||||
"wifi_net_agent.cpp",
|
||||
"wifi_net_conn_event_handler.cpp",
|
||||
"wifi_power_state_listener.cpp",
|
||||
"wifi_protect.cpp",
|
||||
"wifi_protect_manager.cpp",
|
||||
"wifi_service_manager.cpp",
|
||||
"wifi_system_ability_listerner.cpp",
|
||||
"wifi_system_timer.cpp",
|
||||
]
|
||||
if (defined(global_parts_info) &&
|
||||
defined(global_parts_info.msdp_movement)) {
|
||||
sources += [ "wifi_msdp_state_listener.cpp" ]
|
||||
}
|
||||
if (defined(global_parts_info) &&
|
||||
defined(global_parts_info.powermgr_power_manager)) {
|
||||
sources += [ "wifi_power_state_listener.cpp" ]
|
||||
}
|
||||
|
||||
deps = [
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/etc/init:etc",
|
||||
@ -474,7 +481,6 @@ if (defined(ohos_lite)) {
|
||||
"ipc:ipc_single",
|
||||
"netmanager_base:net_conn_manager_if",
|
||||
"netmanager_base:net_native_manager_if",
|
||||
"power_manager:powermgr_client",
|
||||
"safwk:system_ability_fwk",
|
||||
"samgr:samgr_proxy",
|
||||
"time_service:time_client",
|
||||
@ -506,6 +512,18 @@ if (defined(ohos_lite)) {
|
||||
defines += [ "HAS_BATTERY_MANAGER_PART" ]
|
||||
}
|
||||
|
||||
if (defined(global_parts_info) &&
|
||||
defined(global_parts_info.msdp_movement)) {
|
||||
external_deps += [ "movement:movement_client" ]
|
||||
defines += [ "HAS_MOVEMENT_PART" ]
|
||||
}
|
||||
|
||||
if (defined(global_parts_info) &&
|
||||
defined(global_parts_info.powermgr_power_manager)) {
|
||||
external_deps += [ "power_manager:powermgr_client" ]
|
||||
defines += [ "HAS_POWERMGR_PART" ]
|
||||
}
|
||||
|
||||
if (wifi_feature_with_app_frozen) {
|
||||
external_deps += [ "efficiency_manager:suspend_manager_client" ]
|
||||
defines += [ "FEATURE_APP_FROZEN" ]
|
||||
|
@ -56,6 +56,7 @@ ohos_shared_library("wifi_ap_service") {
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/utils",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/common/include",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/common",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_native/common",
|
||||
@ -82,6 +83,7 @@ ohos_shared_library("wifi_ap_service") {
|
||||
"c_utils:utils",
|
||||
"dhcp:dhcp_sdk",
|
||||
"hilog:libhilog",
|
||||
"netmanager_base:net_conn_manager_if",
|
||||
]
|
||||
|
||||
deps = [
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "ap_monitor.h"
|
||||
#include "wifi_settings.h"
|
||||
#include "wifi_logger.h"
|
||||
#include "wifi_net_agent.h"
|
||||
|
||||
DEFINE_WIFILOG_HOTSPOT_LABEL("WifiApStateMachine");
|
||||
|
||||
@ -117,7 +118,7 @@ bool ApStateMachine::StartDhcpServer(const std::string &ipAddress, const int32_t
|
||||
WIFI_LOGE("start dhcpd fail.");
|
||||
return false;
|
||||
}
|
||||
|
||||
WifiNetAgent::GetInstance().AddRoute(IN_INTERFACE, ipAddress, ipv4.GetAddressPrefixLength());
|
||||
WIFI_LOGI("Start dhcp server for AP finished.");
|
||||
return true;
|
||||
#else
|
||||
|
@ -160,31 +160,35 @@ int WifiDeviceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageP
|
||||
#ifndef OHOS_ARCH_LITE
|
||||
void WifiDeviceStub::RemoveDeviceCbDeathRecipient(void)
|
||||
{
|
||||
WIFI_LOGI("enter RemoveDeathRecipient!");
|
||||
WIFI_LOGI("enter RemoveDeviceCbDeathRecipient, remove all death recipient!");
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
for (auto iter = remoteDeathMap.begin(); iter != remoteDeathMap.end(); ++iter) {
|
||||
iter->first->RemoveDeathRecipient(iter->second);
|
||||
remoteDeathMap.erase(iter);
|
||||
}
|
||||
deathRecipient_ = nullptr;
|
||||
}
|
||||
|
||||
void WifiDeviceStub::RemoveDeviceCbDeathRecipient(const wptr<IRemoteObject> &remoteObject)
|
||||
{
|
||||
WIFI_LOGI("RemoveDeathRecipient, remoteObject: %{private}p!", &remoteObject);
|
||||
WIFI_LOGI("RemoveDeviceCbDeathRecipient, remoteObject.promote: %{public}p!",
|
||||
static_cast<void*>(remoteObject.promote()));
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
RemoteDeathMap::iterator iter = remoteDeathMap.find(remoteObject.promote());
|
||||
if (iter == remoteDeathMap.end()) {
|
||||
WIFI_LOGW("not find remoteObject to deal!");
|
||||
WIFI_LOGI("not find remoteObject to deal!");
|
||||
} else {
|
||||
WIFI_LOGD("RemoveDeviceCbDeathRecipient, deathRecipient_: %{public}p, iter->second: %{public}p",
|
||||
static_cast<void*>(deathRecipient_), static_cast<void*>(iter->second));
|
||||
remoteObject->RemoveDeathRecipient(iter->second);
|
||||
remoteDeathMap.erase(iter);
|
||||
WIFI_LOGI("remove death recipient success!");
|
||||
WIFI_LOGI("remove death recipient success! remoteDeathMap.size: %{public}d.", remoteDeathMap.size());
|
||||
}
|
||||
}
|
||||
|
||||
void WifiDeviceStub::OnRemoteDied(const wptr<IRemoteObject> &remoteObject)
|
||||
{
|
||||
WIFI_LOGI("OnRemoteDied, Remote is died! remoteObject: %{private}p", &remoteObject);
|
||||
WIFI_LOGI("OnRemoteDied, Remote is died! remoteObject: %{public}p", &remoteObject);
|
||||
WifiInternalEventDispatcher::GetInstance().RemoveStaCallback(remoteObject.promote());
|
||||
RemoveDeviceCbDeathRecipient(remoteObject);
|
||||
}
|
||||
@ -776,7 +780,8 @@ void WifiDeviceStub::OnRegisterCallBack(uint32_t code, MessageParcel &data, Mess
|
||||
event.emplace_back(data.ReadString());
|
||||
}
|
||||
}
|
||||
WIFI_LOGD("%{public}s, get pid: %{public}d, tokenId: %{private}d", __func__, pid, tokenId);
|
||||
WIFI_LOGI("%{public}s, get pid: %{public}d, tokenId: %{private}d, eventNum: %{public}d",
|
||||
__func__, pid, tokenId, eventNum);
|
||||
|
||||
if (mSingleCallback) {
|
||||
ret = RegisterCallBack(callback_, event);
|
||||
@ -786,18 +791,23 @@ void WifiDeviceStub::OnRegisterCallBack(uint32_t code, MessageParcel &data, Mess
|
||||
deathRecipient_ = new (std::nothrow) WifiDeviceDeathRecipient();
|
||||
#else
|
||||
deathRecipient_ = new (std::nothrow) WifiDeathRecipient(*this);
|
||||
remoteDeathMap.insert(std::make_pair(remote, deathRecipient_));
|
||||
#endif
|
||||
}
|
||||
if ((remote->IsProxyObject()) && (!remote->AddDeathRecipient(deathRecipient_))) {
|
||||
WIFI_LOGD("AddDeathRecipient!");
|
||||
}
|
||||
if (callback_ != nullptr) {
|
||||
for (const auto &eventName : event) {
|
||||
ret = WifiInternalEventDispatcher::GetInstance().AddStaCallback(remote, callback_, pid, eventName,
|
||||
tokenId, m_instId);
|
||||
RemoteDeathMap::iterator iter = remoteDeathMap.find(remote);
|
||||
if (iter == remoteDeathMap.end()) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
remoteDeathMap.insert(std::make_pair(remote, deathRecipient_));
|
||||
WIFI_LOGI("OnRegisterCallBack, AddDeathRecipient, remote: %{public}p, remoteDeathMap.size: %{public}d",
|
||||
static_cast<void*>(remote), remoteDeathMap.size());
|
||||
if ((remote->IsProxyObject()) && (!remote->AddDeathRecipient(deathRecipient_))) {
|
||||
WIFI_LOGI("AddDeathRecipient!");
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto &eventName : event) {
|
||||
ret = WifiInternalEventDispatcher::GetInstance().AddStaCallback(remote, callback_, pid, eventName,
|
||||
tokenId, m_instId);
|
||||
}
|
||||
}
|
||||
} while (0);
|
||||
reply.WriteInt32(0);
|
||||
|
@ -32,8 +32,13 @@
|
||||
#include "wifi_datashare_utils.h"
|
||||
#include "wifi_location_mode_observer.h"
|
||||
#include "wifi_country_code_manager.h"
|
||||
#ifdef HAS_MOVEMENT_PART
|
||||
#include "wifi_msdp_state_listener.h"
|
||||
#endif
|
||||
#include "wifi_protect_manager.h"
|
||||
#ifdef HAS_POWERMGR_PART
|
||||
#include "wifi_power_state_listener.h"
|
||||
#endif
|
||||
#include "suspend/sleep_priority.h"
|
||||
#endif
|
||||
#include "wifi_sta_hal_interface.h"
|
||||
@ -69,7 +74,13 @@ static sptr<WifiLocationModeObserver> locationModeObserver_ = nullptr;
|
||||
static bool islocationModeObservered = false;
|
||||
static sptr<WifiDeviceProvisionObserver> deviceProvisionObserver_ = nullptr;
|
||||
static sptr<SettingsMigrateObserver> settingsMigrateObserver_ = nullptr;
|
||||
#ifdef HAS_POWERMGR_PART
|
||||
static sptr<WifiPowerStateListener> powerStateListener_ = nullptr;
|
||||
static sptr<PowerStateCallback> powerStateCallback_ = nullptr;
|
||||
#endif
|
||||
#ifdef HAS_MOVEMENT_PART
|
||||
static sptr<DeviceMovementCallback> deviceMovementCallback_ = nullptr;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
WifiManager &WifiManager::GetInstance()
|
||||
@ -685,10 +696,11 @@ int WifiManager::Init()
|
||||
WifiTimer::GetInstance()->Register(timeoutCallback, migrateTimerId, TIMEOUT_CHECK_LAST_STA_STATE_EVENT);
|
||||
WIFI_LOGI("CheckAndStartStaByDatashare register success! migrateTimerId:%{public}u", migrateTimerId);
|
||||
}
|
||||
|
||||
#ifdef HAS_POWERMGR_PART
|
||||
if (!isPowerStateListenerSubscribered) {
|
||||
RegisterPowerStateListener();
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
mInitStatus = INIT_OK;
|
||||
InitStaCallback();
|
||||
@ -745,8 +757,13 @@ void WifiManager::InitSubscribeListener()
|
||||
#ifndef OHOS_ARCH_LITE
|
||||
SubscribeSystemAbility(COMM_NET_CONN_MANAGER_SYS_ABILITY_ID);
|
||||
SubscribeSystemAbility(COMMON_EVENT_SERVICE_ID);
|
||||
#ifdef HAS_POWERMGR_PART
|
||||
SubscribeSystemAbility(POWER_MANAGER_SERVICE_ID);
|
||||
#endif
|
||||
#ifdef HAS_MOVEMENT_PART
|
||||
SubscribeSystemAbility(MSDP_MOVEMENT_SERVICE_ID);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef OHOS_ARCH_LITE
|
||||
@ -821,9 +838,11 @@ void WifiManager::Exit()
|
||||
if (batterySubscriber_ != nullptr) {
|
||||
UnRegisterBatteryEvent();
|
||||
}
|
||||
#ifdef HAS_POWERMGR_PART
|
||||
if (isPowerStateListenerSubscribered) {
|
||||
UnRegisterPowerStateListener();
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
@ -1310,7 +1329,8 @@ void WifiManager::DealStaConnChanged(OperateResState state, const WifiLinkedInfo
|
||||
if (state == OperateResState::CONNECT_CONNECTING || state == OperateResState::CONNECT_AP_CONNECTED ||
|
||||
state == OperateResState::DISCONNECT_DISCONNECTING || state == OperateResState::DISCONNECT_DISCONNECTED ||
|
||||
state == OperateResState::CONNECT_OBTAINING_IP || state == OperateResState::CONNECT_ASSOCIATING ||
|
||||
state == OperateResState::CONNECT_ASSOCIATED) {
|
||||
state == OperateResState::CONNECT_ASSOCIATED || state == OperateResState::CONNECT_NETWORK_ENABLED ||
|
||||
state == OperateResState::CONNECT_NETWORK_DISABLED) {
|
||||
if (WifiConfigCenter::GetInstance().GetScanMidState(instId) == WifiOprMidState::RUNNING) {
|
||||
IScanService *pService = WifiServiceManager::GetInstance().GetScanServiceInst(instId);
|
||||
if (pService != nullptr) {
|
||||
@ -1477,11 +1497,14 @@ void WifiManager::OnSystemAbilityChanged(int systemAbilityId, bool add)
|
||||
}
|
||||
break;
|
||||
}
|
||||
#ifdef HAS_POWERMGR_PART
|
||||
case POWER_MANAGER_SERVICE_ID: {
|
||||
if (add) {
|
||||
RegisterPowerStateListener();
|
||||
RegisterPowerStateCallBack();
|
||||
} else {
|
||||
UnRegisterPowerStateListener();
|
||||
UnRegisterPowerStateCallBack();
|
||||
}
|
||||
|
||||
WIFI_LOGI("OnSystemAbilityChanged, id[%{public}d], mode=[%{public}d]!",
|
||||
@ -1489,6 +1512,17 @@ void WifiManager::OnSystemAbilityChanged(int systemAbilityId, bool add)
|
||||
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
#ifdef HAS_MOVEMENT_PART
|
||||
case MSDP_MOVEMENT_SERVICE_ID: {
|
||||
if (add) {
|
||||
RegisterMovementCallBack();
|
||||
} else {
|
||||
UnRegisterMovementCallBack();
|
||||
}
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -2516,6 +2550,11 @@ void BatteryEventSubscriber::OnReceiveEvent(const OHOS::EventFwk::CommonEventDat
|
||||
{
|
||||
std::string action = data.GetWant().GetAction();
|
||||
WIFI_LOGI("BatteryEventSubscriber::OnReceiveEvent: %{public}s.", action.c_str());
|
||||
if (action == OHOS::EventFwk::CommonEventSupport::COMMON_EVENT_POWER_CONNECTED) {
|
||||
WifiSettings::GetInstance().SetNoChargerPlugModeState(MODE_STATE_CLOSE);
|
||||
} else if (action == OHOS::EventFwk::CommonEventSupport::COMMON_EVENT_POWER_DISCONNECTED) {
|
||||
WifiSettings::GetInstance().SetNoChargerPlugModeState(MODE_STATE_OPEN);
|
||||
}
|
||||
for (int i = 0; i < AP_INSTANCE_MAX_NUM; ++i) {
|
||||
IApService *pService = WifiServiceManager::GetInstance().GetApServiceInst(i);
|
||||
if (pService == nullptr) {
|
||||
@ -2639,6 +2678,7 @@ void WifiManager::CheckAndStartStaByDatashare()
|
||||
|
||||
void WifiManager::RegisterPowerStateListener()
|
||||
{
|
||||
#ifdef HAS_POWERMGR_PART
|
||||
WIFI_LOGD("Enter WifiManager::RegisterPowerStateListener");
|
||||
std::unique_lock<std::mutex> lock(powerStateEventMutex);
|
||||
|
||||
@ -2661,10 +2701,12 @@ void WifiManager::RegisterPowerStateListener()
|
||||
WIFI_LOGI("WifiManager::RegisterPowerStateListener OK!");
|
||||
isPowerStateListenerSubscribered = true;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void WifiManager::UnRegisterPowerStateListener()
|
||||
{
|
||||
#ifdef HAS_POWERMGR_PART
|
||||
WIFI_LOGD("Enter WifiManager::UnRegisterPowerStateListener");
|
||||
std::unique_lock<std::mutex> lock(powerStateEventMutex);
|
||||
|
||||
@ -2681,8 +2723,65 @@ void WifiManager::UnRegisterPowerStateListener()
|
||||
isPowerStateListenerSubscribered = false;
|
||||
WIFI_LOGI("WifiManager::UnRegisterPowerStateListener OK!");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef HAS_POWERMGR_PART
|
||||
void WifiManager::RegisterPowerStateCallBack()
|
||||
{
|
||||
WIFI_LOGI("RegisterPowerStateCallBack");
|
||||
if (powerStateCallback_ == nullptr) {
|
||||
powerStateCallback_ = new (std::nothrow) PowerStateCallback();
|
||||
}
|
||||
|
||||
bool result = PowerMgr::PowerMgrClient::GetInstance().RegisterPowerStateCallback(powerStateCallback_);
|
||||
if (!result) {
|
||||
WIFI_LOGE("register power state callback failed");
|
||||
} else {
|
||||
WIFI_LOGI("register power state callback success");
|
||||
}
|
||||
}
|
||||
|
||||
void WifiManager::UnRegisterPowerStateCallBack()
|
||||
{
|
||||
WIFI_LOGI("UnRegisterPowerStateCallBack");
|
||||
if (powerStateCallback_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool result = PowerMgr::PowerMgrClient::GetInstance().UnRegisterPowerStateCallback(powerStateCallback_);
|
||||
if (!result) {
|
||||
WIFI_LOGE("register power state callback failed");
|
||||
} else {
|
||||
WIFI_LOGI("register power state callback success");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#ifdef HAS_MOVEMENT_PART
|
||||
void WifiManager::RegisterMovementCallBack()
|
||||
{
|
||||
WIFI_LOGI("RegisterMovementCallBack");
|
||||
if (!deviceMovementCallback_) {
|
||||
deviceMovementCallback_ = sptr<DeviceMovementCallback>(new DeviceMovementCallback());
|
||||
}
|
||||
if (Msdp::MovementClient::GetInstance().SubscribeCallback(
|
||||
Msdp::MovementDataUtils::MovementType::TYPE_STILL, deviceMovementCallback_) != ERR_OK) {
|
||||
WIFI_LOGE("Register a device movement observer failed!");
|
||||
}
|
||||
}
|
||||
|
||||
void WifiManager::UnRegisterMovementCallBack()
|
||||
{
|
||||
WIFI_LOGI("UnRegisterMovementCallBack");
|
||||
if (!deviceMovementCallback_) {
|
||||
return;
|
||||
}
|
||||
Msdp::MovementClient::GetInstance().UnSubscribeCallback(
|
||||
Msdp::MovementDataUtils::MovementType::TYPE_STILL, deviceMovementCallback_);
|
||||
deviceMovementCallback_ = nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
WifiTimer *WifiTimer::GetInstance()
|
||||
{
|
||||
static WifiTimer instance;
|
||||
|
@ -330,7 +330,9 @@ private:
|
||||
std::mutex airplaneModeEventMutex;
|
||||
std::mutex locationEventMutex;
|
||||
std::mutex batteryEventMutex;
|
||||
#ifdef HAS_POWERMGR_PART
|
||||
std::mutex powerStateEventMutex;
|
||||
#endif
|
||||
std::condition_variable mCondition;
|
||||
std::deque<WifiCloseServiceMsg> mEventQue;
|
||||
#ifndef OHOS_ARCH_LITE
|
||||
@ -392,6 +394,14 @@ private:
|
||||
void RegisterPowerStateListener();
|
||||
void UnRegisterPowerStateListener();
|
||||
bool isPowerStateListenerSubscribered = false;
|
||||
#ifdef HAS_POWERMGR_PART
|
||||
void RegisterPowerStateCallBack();
|
||||
void UnRegisterPowerStateCallBack();
|
||||
#endif
|
||||
#ifdef HAS_MOVEMENT_PART
|
||||
void RegisterMovementCallBack();
|
||||
void UnRegisterMovementCallBack();
|
||||
#endif
|
||||
#endif
|
||||
InitStatus mInitStatus;
|
||||
long mSupportedFeatures;
|
||||
|
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "wifi_msdp_state_listener.h"
|
||||
#include "wifi_logger.h"
|
||||
#include "wifi_settings.h"
|
||||
#include "define.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Wifi {
|
||||
DEFINE_WIFILOG_LABEL("WifiMsdpStateListener");
|
||||
|
||||
void DeviceMovementCallback::OnMovementChanged(const Msdp::MovementDataUtils::MovementData &movementData)
|
||||
{
|
||||
WIFI_LOGI("enter DeviceMovementCallback::OnMovementChanged type=%{public}d, value=%{public}d",
|
||||
movementData.type, movementData.value);
|
||||
if (movementData.type == Msdp::MovementDataUtils::MovementType::TYPE_STILL) {
|
||||
if (movementData.value == Msdp::MovementDataUtils::MovementValue::VALUE_ENTER) {
|
||||
WifiSettings::GetInstance().SetFreezeModeState(MODE_STATE_OPEN);
|
||||
} else {
|
||||
WifiSettings::GetInstance().SetFreezeModeState(MODE_STATE_CLOSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace Wifi
|
||||
} // namespace OHOS
|
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_WIFI_MSDP_STATE_LISTENER_H
|
||||
#define OHOS_WIFI_MSDP_STATE_LISTENER_H
|
||||
|
||||
#include "movement_client.h"
|
||||
#include "movement_callback_stub.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Wifi {
|
||||
class DeviceMovementCallback : public Msdp::MovementCallbackStub {
|
||||
public:
|
||||
DeviceMovementCallback() = default;
|
||||
void OnMovementChanged(const Msdp::MovementDataUtils::MovementData &movementData) override;
|
||||
};
|
||||
|
||||
} // namespace Wifi
|
||||
} // namespace OHOS
|
||||
#endif
|
@ -82,6 +82,8 @@ typedef enum WifiHalPortType {
|
||||
#define PNO_SCAN_OVER_OK 3 /* PNO Scan success notification */
|
||||
#define WPA_CB_CONNECTED 1 /* The connection is successfully. */
|
||||
#define WPA_CB_DISCONNECTED 2 /* Disconnect */
|
||||
#define WPA_CB_ASSOCIATING 3
|
||||
#define WPA_CB_ASSOCIATED 4
|
||||
#define WIFI_IDL_COUNTRY_CODE_LENGTH 2
|
||||
#define WIFI_IDL_GET_MAX_SCAN_INFO 256 /* Maximum number of scan infos obtained at a time */
|
||||
#define WIFI_IDL_GET_MAX_NETWORK_LIST 128
|
||||
|
@ -108,5 +108,14 @@ void WifiPowerStateListener::DealPowerExitSleepEvent()
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
void PowerStateCallback::OnPowerStateChanged(PowerState state)
|
||||
{
|
||||
if (static_cast<int>(state) == POWER_STATE_DOZ) {
|
||||
WifiSettings::GetInstance().SetPowerIdelState(MODE_STATE_OPEN);
|
||||
} else {
|
||||
WifiSettings::GetInstance().SetPowerIdelState(MODE_STATE_CLOSE);
|
||||
}
|
||||
}
|
||||
} // namespace Wifi
|
||||
} // namespace OHOS
|
||||
|
@ -18,10 +18,12 @@
|
||||
|
||||
#include "power_mgr_client.h"
|
||||
#include "sync_sleep_callback_stub.h"
|
||||
#include "power_state_callback_stub.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Wifi {
|
||||
using namespace OHOS::PowerMgr;
|
||||
const int POWER_STATE_DOZ = 4;
|
||||
class WifiPowerStateListener : public SyncSleepCallbackStub {
|
||||
public:
|
||||
WifiPowerStateListener();
|
||||
@ -35,6 +37,12 @@ private:
|
||||
std::map <int, bool> bWifiStateBeforeSleep;
|
||||
};
|
||||
|
||||
class PowerStateCallback : public PowerStateCallbackStub {
|
||||
public:
|
||||
PowerStateCallback() = default;
|
||||
void OnPowerStateChanged(PowerState state) override;
|
||||
};
|
||||
|
||||
} // namespace Wifi
|
||||
} // namespace OHOS
|
||||
#endif
|
@ -114,6 +114,9 @@ if (defined(ohos_lite)) {
|
||||
if (wifi_feature_with_random_mac_addr) {
|
||||
defines += [ "SUPPORT_RANDOM_MAC_ADDR" ]
|
||||
}
|
||||
if (wifi_feature_with_scan_control) {
|
||||
defines += [ "SUPPORT_SCAN_CONTROL" ]
|
||||
}
|
||||
|
||||
external_deps = [
|
||||
"ability_base:want",
|
||||
|
@ -58,6 +58,15 @@ public:
|
||||
* @return success: WIFI_OPT_SUCCESS, failed: WIFI_OPT_FAILED
|
||||
*/
|
||||
virtual ErrCode DisableScan(bool disable) = 0;
|
||||
/**
|
||||
* @Description Start/Stop pno scan
|
||||
*
|
||||
* @param isStartAction - true:start pno scan; false:stop pno scan
|
||||
* @param periodMs - pno scan interval
|
||||
* @param suspendReason - pno scan suspent reason
|
||||
* @return success: WIFI_OPT_SUCCESS, failed: WIFI_OPT_FAILED
|
||||
*/
|
||||
virtual ErrCode StartWifiPnoScan(bool isStartAction, int periodMs, int suspendReason) = 0;
|
||||
/**
|
||||
* @Description Processes interface service screen change request.
|
||||
*
|
||||
|
@ -98,6 +98,14 @@ ErrCode ScanInterface::DisableScan(bool disable)
|
||||
return pScanService->DisableScan(disable);
|
||||
}
|
||||
|
||||
ErrCode ScanInterface::StartWifiPnoScan(bool isStartAction, int periodMs, int suspendReason)
|
||||
{
|
||||
WIFI_LOGI("Enter ScanInterface::StartWifiPnoScan");
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
CHECK_NULL_AND_RETURN(pScanService, WIFI_OPT_FAILED);
|
||||
return pScanService->StartWifiPnoScan(isStartAction, periodMs, suspendReason);
|
||||
}
|
||||
|
||||
ErrCode ScanInterface::OnScreenStateChanged(int screenState)
|
||||
{
|
||||
WIFI_LOGI("Enter ScanInterface::OnScreenStateChanged, screenState=%{public}d.", screenState);
|
||||
|
@ -63,6 +63,15 @@ public:
|
||||
* @return success: WIFI_OPT_SUCCESS, failed: WIFI_OPT_FAILED
|
||||
*/
|
||||
ErrCode DisableScan(bool disable);
|
||||
/**
|
||||
* @Description Start/Stop pno scan
|
||||
*
|
||||
* @param isStartAction - true:start pno scan; false:stop pno scan
|
||||
* @param periodMs - pno scan interval
|
||||
* @param suspendReason - pno scan suspent reason
|
||||
* @return success: WIFI_OPT_SUCCESS, failed: WIFI_OPT_FAILED
|
||||
*/
|
||||
ErrCode StartWifiPnoScan(bool isStartAction, int periodMs, int suspendReason);
|
||||
/**
|
||||
* @Description Processes interface service screen change request.
|
||||
*
|
||||
|
@ -351,6 +351,29 @@ ErrCode ScanService::DisableScan(bool disable)
|
||||
return WIFI_OPT_SUCCESS;
|
||||
}
|
||||
|
||||
ErrCode ScanService::StartWifiPnoScan(bool isStartAction, int periodMs, int suspendReason)
|
||||
{
|
||||
LOGI("Enter ScanService::StartWifiPnoScan isStart:%{public}d", isStartAction);
|
||||
if (isStartAction) {
|
||||
StopPnoScan();
|
||||
pnoScanIntervalMode.scanIntervalMode.interval = periodMs / 1000;
|
||||
BeginPnoScan();
|
||||
} else {
|
||||
StopPnoScan();
|
||||
}
|
||||
return WIFI_OPT_SUCCESS;
|
||||
}
|
||||
|
||||
void ScanService::StopPnoScan()
|
||||
{
|
||||
if (!isPnoScanBegined) {
|
||||
return;
|
||||
}
|
||||
EndPnoScan();
|
||||
pnoScanFailedNum = 0;
|
||||
pScanStateMachine->StopTimer(static_cast<int>(RESTART_PNO_SCAN_TIMER));
|
||||
}
|
||||
|
||||
bool ScanService::SingleScan(ScanConfig &scanConfig)
|
||||
{
|
||||
WIFI_LOGI("Enter ScanService::SingleScan.\n");
|
||||
@ -540,10 +563,6 @@ void ScanService::HandleCommonScanFailed(std::vector<int> &requestIndexList)
|
||||
{
|
||||
WIFI_LOGI("Enter ScanService::HandleCommonScanFailed, requestIndexList size: %{public}d.",
|
||||
static_cast<int>(requestIndexList.size()));
|
||||
if (staStatus != static_cast<int>(OperateResState::DISCONNECT_DISCONNECTED) &&
|
||||
staStatus != static_cast<int>(OperateResState::CONNECT_AP_CONNECTED)) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::unique_lock<std::mutex> lock(scanConfigMapMutex);
|
||||
for (std::vector<int>::iterator reqIter = requestIndexList.begin(); reqIter != requestIndexList.end(); ++reqIter) {
|
||||
@ -965,7 +984,13 @@ void ScanService::HandleStaStatusChanged(int status)
|
||||
SystemScanProcess(true);
|
||||
break;
|
||||
}
|
||||
#ifdef SUPPORT_SCAN_CONTROL
|
||||
case static_cast<int>(OperateResState::CONNECT_AP_CONNECTED):
|
||||
case static_cast<int>(OperateResState::CONNECT_NETWORK_ENABLED):
|
||||
case static_cast<int>(OperateResState::CONNECT_NETWORK_DISABLED): {
|
||||
#else
|
||||
case static_cast<int>(OperateResState::CONNECT_AP_CONNECTED): {
|
||||
#endif
|
||||
SystemScanProcess(false);
|
||||
break;
|
||||
}
|
||||
@ -1188,6 +1213,85 @@ void ScanService::GetScanControlInfo()
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef SUPPORT_SCAN_CONTROL
|
||||
ErrCode ScanService::AllowExternScan()
|
||||
{
|
||||
WIFI_LOGI("Enter ScanService::AllowExternScan SUPPORT_SCAN_CONTROL.\n");
|
||||
int staScene = GetStaScene();
|
||||
ScanMode scanMode = WifiSettings::GetInstance().GetAppRunningState();
|
||||
WIFI_LOGI("AllowExternScan, staScene is %{public}d, scanMode is %{public}d", staScene, (int)scanMode);
|
||||
|
||||
if (!AllowExternScanByPowerIdelState()) {
|
||||
WIFI_LOGW("extern scan not allow by power idel state");
|
||||
return WIFI_OPT_FAILED;
|
||||
}
|
||||
|
||||
if (!AllowExternScanByThermal()) {
|
||||
WIFI_LOGW("extern scan not allow by thermal level");
|
||||
return WIFI_OPT_FAILED;
|
||||
}
|
||||
|
||||
int state = WifiSettings::GetInstance().GetScreenState();
|
||||
if (state == MODE_STATE_CLOSE) {
|
||||
if (!AllowScanDuringScreenOff(ScanMode::ALL_EXTERN_SCAN)) {
|
||||
WIFI_LOGW("extern scan not allow by screen state");
|
||||
return WIFI_OPT_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
if (!AllowScanByHid2dState()) {
|
||||
WIFI_LOGW("extern scan not allow by hid2d state");
|
||||
return WIFI_OPT_FAILED;
|
||||
}
|
||||
|
||||
if (mEnhanceService != nullptr) {
|
||||
if (!mEnhanceService->AllowScanBySchedStrategy()) {
|
||||
WIFI_LOGW("extern scan not allow by sched strategy.");
|
||||
return WIFI_OPT_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
if (IsExternScanning()) {
|
||||
if (!AllowScanDuringScanning(ScanMode::ALL_EXTERN_SCAN)) {
|
||||
WIFI_LOGW("extern scan not allow when scan is going");
|
||||
return WIFI_OPT_FAILED;
|
||||
}
|
||||
}
|
||||
if (!AllowScanDuringStaScene(staScene, ScanMode::ALL_EXTERN_SCAN)) {
|
||||
WIFI_LOGW("extern scan not allow by sta connection state");
|
||||
return WIFI_OPT_FAILED;
|
||||
}
|
||||
|
||||
int appId = 0;
|
||||
if (!AllowExternScanByInterval(appId, staScene, scanMode)) {
|
||||
WIFI_LOGW("extern scan not allow by interval mode");
|
||||
return WIFI_OPT_FAILED;
|
||||
}
|
||||
|
||||
if (!AllowExternScanByGnssFixState()) {
|
||||
WIFI_LOGW("extern scan not allow by gnss fix state");
|
||||
return WIFI_OPT_FAILED;
|
||||
}
|
||||
|
||||
if (!AllowScanByMovingFreeze()) {
|
||||
WIFI_LOGW("extern scan not allow by moving freeze mode");
|
||||
return WIFI_OPT_MOVING_FREEZE_CTRL;
|
||||
}
|
||||
|
||||
if (!AllowExternScanByAbnormalApp()) {
|
||||
WIFI_LOGW("extern scan not allow by abnormal app");
|
||||
return WIFI_OPT_FAILED;
|
||||
}
|
||||
|
||||
if (!AllowScanByDisableScanCtrl()) {
|
||||
WIFI_LOGW("extern scan not allow by disable scan control.");
|
||||
return WIFI_OPT_FAILED;
|
||||
}
|
||||
|
||||
WIFI_LOGI("extern scan has allowed");
|
||||
return WIFI_OPT_SUCCESS;
|
||||
}
|
||||
#else
|
||||
ErrCode ScanService::AllowExternScan()
|
||||
{
|
||||
WIFI_LOGI("Enter ScanService::AllowExternScan.\n");
|
||||
@ -1232,6 +1336,7 @@ ErrCode ScanService::AllowExternScan()
|
||||
WIFI_LOGI("extern scan has allowed");
|
||||
return WIFI_OPT_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
|
||||
ErrCode ScanService::AllowSystemTimerScan()
|
||||
{
|
||||
@ -1272,6 +1377,10 @@ ErrCode ScanService::AllowSystemTimerScan()
|
||||
return WIFI_OPT_FAILED;
|
||||
}
|
||||
|
||||
#ifdef SUPPORT_SCAN_CONTROL
|
||||
SystemScanByInterval(staScene, systemScanIntervalMode.scanIntervalMode.interval,
|
||||
systemScanIntervalMode.scanIntervalMode.count);
|
||||
#else
|
||||
if (!AllowScanByMovingFreeze()) {
|
||||
return WIFI_OPT_MOVING_FREEZE_CTRL;
|
||||
}
|
||||
@ -1289,6 +1398,7 @@ ErrCode ScanService::AllowSystemTimerScan()
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!AllowScanByDisableScanCtrl()) {
|
||||
WIFI_LOGW("system timer scan not allow by disable scan control.");
|
||||
@ -1329,6 +1439,7 @@ ErrCode ScanService::AllowPnoScan()
|
||||
return WIFI_OPT_MOVING_FREEZE_CTRL;
|
||||
}
|
||||
|
||||
#ifndef SUPPORT_SCAN_CONTROL
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(scanControlInfoMutex);
|
||||
for (auto iter = scanControlInfo.scanIntervalList.begin(); iter != scanControlInfo.scanIntervalList.end();
|
||||
@ -1345,6 +1456,7 @@ ErrCode ScanService::AllowPnoScan()
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!AllowScanByDisableScanCtrl()) {
|
||||
WIFI_LOGW("pnoScan not allow by disable scan control.");
|
||||
@ -1516,6 +1628,41 @@ bool ScanService::AllowExternScanByThermal()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ScanService::AllowExternScanByPowerIdelState()
|
||||
{
|
||||
WIFI_LOGI("Enter ScanService::AllowExternScanByPowerIdelState.\n");
|
||||
auto powerState = WifiSettings::GetInstance().GetPowerIdelState();
|
||||
if (powerState == MODE_STATE_OPEN) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ScanService::AllowExternScanByGnssFixState()
|
||||
{
|
||||
WIFI_LOGI("Enter ScanService::AllowExternScanByLocationState.\n");
|
||||
if (IsAppInFilterList(scan_gps_block_list)) {
|
||||
auto state = WifiSettings::GetInstance().GetGnssFixState();
|
||||
if (state == MODE_STATE_OPEN) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ScanService::AllowExternScanByAbnormalApp()
|
||||
{
|
||||
WIFI_LOGI("Enter ScanService::AllowExternScanByAbnormalApp.\n");
|
||||
std::vector<std::string> abnormalAppList;
|
||||
WifiSettings::GetInstance().GetAbnormalApps(abnormalAppList);
|
||||
std::string packageName = WifiSettings::GetInstance().GetAppPackageName();
|
||||
if (std::find(abnormalAppList.begin(), abnormalAppList.end(), packageName) != abnormalAppList.end()) {
|
||||
WIFI_LOGI("Current app is abnormal, not allow wifi scan.\n");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ScanService::AllowExternScanByForbid(int staScene, ScanMode scanMode)
|
||||
{
|
||||
WIFI_LOGI("Enter ScanService::AllowExternScanByForbid, staScene:%{public}d, scanMode:%{public}d.",
|
||||
@ -1559,6 +1706,18 @@ bool ScanService::AllowExternScanByInterval(int appId, int staScene, ScanMode sc
|
||||
{
|
||||
WIFI_LOGI("Enter ScanService::AllowExternScanByInterval.\n");
|
||||
|
||||
#ifdef SUPPORT_SCAN_CONTROL
|
||||
int noChargerPlugModeState = WifiSettings::GetInstance().GetNoChargerPlugModeState();
|
||||
if (noChargerPlugModeState == MODE_STATE_OPEN) {
|
||||
WIFI_LOGI("No charger plug mode state.");
|
||||
if (!AllowExternScanByIntervalMode(appId, SCAN_SCENE_FREQUENCY_CUSTOM, scanMode)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (!AllowExternScanByIntervalMode(appId, SCAN_SCENE_FREQUENCY_ORIGIN, scanMode)) {
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
if (!AllowExternScanByIntervalMode(appId, staScene, scanMode)) {
|
||||
return false;
|
||||
}
|
||||
@ -1587,6 +1746,7 @@ bool ScanService::AllowExternScanByInterval(int appId, int staScene, ScanMode sc
|
||||
if (!AllowExternScanByCustomScene(appId, ScanMode::ALL_EXTERN_SCAN)) {
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1968,6 +2128,9 @@ bool ScanService::AllowExternScanByIntervalMode(int appId, int scanScene, ScanMo
|
||||
{
|
||||
WIFI_LOGI("Enter ScanService::AllowExternScanByIntervalMode.\n");
|
||||
|
||||
if (IsAppInFilterList(scan_frequency_trust_list)) {
|
||||
return true;
|
||||
}
|
||||
bool isTrustListMode = IsScanTrustMode();
|
||||
if (isTrustListMode && IsInScanTrust(scanScene)) {
|
||||
WIFI_LOGD("Trust list mode,sceneId(%{public}d) in the list, return true.", scanScene);
|
||||
@ -2058,6 +2221,21 @@ bool ScanService::PnoScanByInterval(int &fixedScanCount, time_t &fixedScanTime,
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef SUPPORT_SCAN_CONTROL
|
||||
bool ScanService::SystemScanByInterval(int staScene, int &interval, int &count)
|
||||
{
|
||||
WIFI_LOGI("Enter ScanService::SystemScanByInterval.\n");
|
||||
int state = WifiSettings::GetInstance().GetScreenState();
|
||||
if (state == MODE_STATE_OPEN) {
|
||||
if (staScene == SCAN_SCENE_CONNECTED) {
|
||||
SystemScanConnectedPolicy(interval);
|
||||
} else if (staScene == SCAN_SCENE_DISCONNCTED) {
|
||||
SystemScanDisconnectedPolicy(interval, count);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#else
|
||||
bool ScanService::SystemScanByInterval(int &expScanCount, int &interval, int &count)
|
||||
{
|
||||
WIFI_LOGI("Enter ScanService::SystemScanByInterval.\n");
|
||||
@ -2072,6 +2250,7 @@ bool ScanService::SystemScanByInterval(int &expScanCount, int &interval, int &co
|
||||
expScanCount++;
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool ScanService::ExternScanByInterval(int appId, SingleAppForbid &singleAppForbid)
|
||||
{
|
||||
@ -2104,9 +2283,6 @@ bool ScanService::ExternScanByInterval(int appId, SingleAppForbid &singleAppForb
|
||||
bool ScanService::AllowSingleAppScanByInterval(int appId, ScanIntervalMode scanIntervalMode)
|
||||
{
|
||||
WIFI_LOGI("Enter ScanService::AllowSingleAppScanByInterval.\n");
|
||||
if (IsAppInFilterList(scan_frequency_trust_list)) {
|
||||
return true;
|
||||
}
|
||||
bool appIdExisted = false;
|
||||
for (auto forbidListIter = appForbidList.begin(); forbidListIter != appForbidList.end(); ++forbidListIter) {
|
||||
if (forbidListIter->appID == appId &&
|
||||
@ -2442,6 +2618,58 @@ bool ScanService::IsAppInFilterList(const std::vector<std::string> &packageFilte
|
||||
return false;
|
||||
}
|
||||
|
||||
void ScanService::SystemScanConnectedPolicy(int &interval)
|
||||
{
|
||||
WIFI_LOGI("Enter ScanService::SystemScanConnectedPolicy");
|
||||
WifiLinkedInfo linkedInfo;
|
||||
WifiSettings::GetInstance().GetLinkedInfo(linkedInfo, m_instId);
|
||||
if (linkedInfo.detailedState == DetailedState::WORKING) {
|
||||
interval = SYSTEM_SCAN_INTERVAL_ONE_HOUR;
|
||||
} else {
|
||||
interval *= DOUBLE_SCAN_INTERVAL;
|
||||
if (IsMovingFreezeState()) {
|
||||
if (interval > SYSTEM_SCAN_INTERVAL_FIVE_MINUTE) {
|
||||
interval = SYSTEM_SCAN_INTERVAL_FIVE_MINUTE;
|
||||
}
|
||||
} else {
|
||||
if (interval > SYSTEM_SCAN_INTERVAL_160_SECOND) {
|
||||
interval = SYSTEM_SCAN_INTERVAL_160_SECOND;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ScanService::SystemScanDisconnectedPolicy(int &interval, int &count)
|
||||
{
|
||||
WIFI_LOGI("Enter ScanService::SystemScanDisconnectedPolicy");
|
||||
int scanGenieState = WifiSettings::GetInstance().GetScanGenieState();
|
||||
if (scanGenieState == MODE_STATE_OPEN) {
|
||||
if (count < SYSTEM_SCAN_COUNT_3_TIMES) {
|
||||
interval = SYSTEM_SCAN_INTERVAL_10_SECOND;
|
||||
} else if (count < SYSTEM_SCAN_COUNT_3_TIMES * DOUBLE_SCAN_INTERVAL) {
|
||||
interval = SYSTEM_SCAN_INTERVAL_30_SECOND;
|
||||
} else {
|
||||
if (IsMovingFreezeState()) {
|
||||
interval = SYSTEM_SCAN_INTERVAL_FIVE_MINUTE;
|
||||
} else {
|
||||
interval = SYSTEM_SCAN_INTERVAL_60_SECOND;
|
||||
}
|
||||
}
|
||||
count++;
|
||||
} else {
|
||||
interval *= DOUBLE_SCAN_INTERVAL;
|
||||
if (IsMovingFreezeState()) {
|
||||
if (interval > SYSTEM_SCAN_INTERVAL_FIVE_MINUTE) {
|
||||
interval = SYSTEM_SCAN_INTERVAL_FIVE_MINUTE;
|
||||
}
|
||||
} else {
|
||||
if (interval > SYSTEM_SCAN_INTERVAL_160_SECOND) {
|
||||
interval = SYSTEM_SCAN_INTERVAL_160_SECOND;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int CalculateBitPerTone(int snrDb)
|
||||
{
|
||||
int bitPerTone;
|
||||
|
@ -46,6 +46,13 @@ const int CUSTOM_SCAN_SCENE = 2;
|
||||
const int SCREEN_SCAN_SCENE = 3;
|
||||
const int OTHER_SCAN_SCENE = 4;
|
||||
const int SYSTEM_SCAN_INIT_TIME = 20;
|
||||
const int SYSTEM_SCAN_INTERVAL_ONE_HOUR = 60 * 60;
|
||||
const int SYSTEM_SCAN_INTERVAL_FIVE_MINUTE = 5 * 60;
|
||||
const int SYSTEM_SCAN_INTERVAL_160_SECOND = 160;
|
||||
const int SYSTEM_SCAN_INTERVAL_10_SECOND = 10;
|
||||
const int SYSTEM_SCAN_INTERVAL_30_SECOND = 30;
|
||||
const int SYSTEM_SCAN_INTERVAL_60_SECOND = 60;
|
||||
const int SYSTEM_SCAN_COUNT_3_TIMES = 3;
|
||||
|
||||
const int TONE_PER_SYM_11ABG = 48;
|
||||
const int TONE_PER_SYM_11N_20MHZ = 52;
|
||||
@ -141,6 +148,15 @@ public:
|
||||
* @return WIFI_OPT_SUCCESS: success, WIFI_OPT_FAILED: failed
|
||||
*/
|
||||
ErrCode DisableScan(bool disable);
|
||||
/**
|
||||
* @Description Start/Stop pno scan
|
||||
*
|
||||
* @param isStartAction - true:start pno scan; false:stop pno scan
|
||||
* @param periodMs - pno scan interval
|
||||
* @param suspendReason - pno scan suspent reason
|
||||
* @return WIFI_OPT_SUCCESS: success, WIFI_OPT_FAILED: failed
|
||||
*/
|
||||
ErrCode StartWifiPnoScan(bool isStartAction, int periodMs, int suspendReason);
|
||||
/**
|
||||
* @Description Starting a Single Scan.
|
||||
*
|
||||
@ -166,6 +182,10 @@ public:
|
||||
*
|
||||
*/
|
||||
void EndPnoScan();
|
||||
/**
|
||||
* @Description Stop pno scan and clear local resource.
|
||||
*/
|
||||
void StopPnoScan();
|
||||
/**
|
||||
* @Description The system scans and selects a scanning mode
|
||||
* based on the current screen status and STA status.
|
||||
@ -573,6 +593,30 @@ private:
|
||||
*/
|
||||
bool AllowExternScanByThermal();
|
||||
|
||||
/**
|
||||
* @Description Determine whether scanning is allowed through power idel state.
|
||||
*
|
||||
* @return true - allow extern scan
|
||||
* @return false - not allow extern scan
|
||||
*/
|
||||
bool AllowExternScanByPowerIdelState();
|
||||
|
||||
/**
|
||||
* @Description Determine whether navigation application's scanning is allowed through gnss state.
|
||||
*
|
||||
* @return true - allow extern scan
|
||||
* @return false - not allow extern scan
|
||||
*/
|
||||
bool AllowExternScanByGnssFixState();
|
||||
|
||||
/**
|
||||
* @Description If app in the abnormal list, the scan of this app is not allowed.
|
||||
*
|
||||
* @return true - allow extern scan
|
||||
* @return false - not allow extern scan
|
||||
*/
|
||||
bool AllowExternScanByAbnormalApp();
|
||||
|
||||
/**
|
||||
* @Description Determine whether scanning is allowed and scan the control policy through forbidMap.
|
||||
*
|
||||
@ -712,6 +756,17 @@ private:
|
||||
* @return false - failed
|
||||
*/
|
||||
bool AllowExternScanByCustomScene(int appId, ScanMode scanMode);
|
||||
#ifdef SUPPORT_SCAN_CONTROL
|
||||
/**
|
||||
* @Description Determines whether to allow system scan based on scanInterval control mode.
|
||||
*
|
||||
* @param staScene - sta scene.[in]
|
||||
* @param interval - system scan interval[in]
|
||||
* @param count - Total number of times that the scanning interval is multiplied by 2[in]
|
||||
* @return success: true, failed: false
|
||||
*/
|
||||
bool SystemScanByInterval(int staScene, int &interval, int &count);
|
||||
#else
|
||||
/**
|
||||
* @Description Determines whether to allow system scan based on scanInterval control mode.
|
||||
*
|
||||
@ -721,6 +776,7 @@ private:
|
||||
* @return success: true, failed: false
|
||||
*/
|
||||
bool SystemScanByInterval(int &expScanCount, int &interval, int &count);
|
||||
#endif
|
||||
/**
|
||||
* @Description Determines whether to allow pno scan based on scanInterval control mode.
|
||||
*
|
||||
@ -858,6 +914,19 @@ private:
|
||||
* @return true: int the list, false: not in the list.
|
||||
*/
|
||||
bool IsAppInFilterList(const std::vector<std::string> &packageFilter) const;
|
||||
/* *
|
||||
* @Description adjust system scan interval when sta connected.
|
||||
*
|
||||
* @param interval scan interval[in]
|
||||
*/
|
||||
void SystemScanConnectedPolicy(int &interval);
|
||||
/* *
|
||||
* @Description adjust system scan interval when sta disconnected.
|
||||
*
|
||||
* @param interval scan interval[in]
|
||||
* @param count adjust count[in]
|
||||
*/
|
||||
void SystemScanDisconnectedPolicy(int &interval, int &count);
|
||||
};
|
||||
} // namespace Wifi
|
||||
} // namespace OHOS
|
||||
|
@ -21,7 +21,7 @@ namespace OHOS {
|
||||
namespace Wifi {
|
||||
void WifiScanDeathRecipient::OnRemoteDied(const wptr<IRemoteObject>& remoteObject)
|
||||
{
|
||||
WIFI_LOGD("WifiScanDeathRecipient::OnRemoteDied!");
|
||||
WIFI_LOGI("WifiScanDeathRecipient::OnRemoteDied! remoteObject: %{public}p", &remoteObject);
|
||||
WifiInternalEventDispatcher::GetInstance().RemoveScanCallback(remoteObject.promote());
|
||||
}
|
||||
} // namespace Wifi
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include "wifi_scan_callback_proxy.h"
|
||||
#include "wifi_service_manager.h"
|
||||
#include "wifi_sta_hal_interface.h"
|
||||
#include "wifi_common_util.h"
|
||||
|
||||
DEFINE_WIFILOG_SCAN_LABEL("WifiScanServiceImpl");
|
||||
namespace OHOS {
|
||||
@ -137,6 +138,9 @@ ErrCode WifiScanServiceImpl::Scan(bool compatible)
|
||||
return WIFI_OPT_SCAN_NOT_OPENED;
|
||||
}
|
||||
|
||||
#ifndef OHOS_ARCH_LITE
|
||||
UpdateScanMode();
|
||||
#endif
|
||||
IScanService *pService = WifiServiceManager::GetInstance().GetScanServiceInst(m_instId);
|
||||
if (pService == nullptr) {
|
||||
return WIFI_OPT_SCAN_NOT_OPENED;
|
||||
@ -169,6 +173,9 @@ ErrCode WifiScanServiceImpl::AdvanceScan(const WifiScanParams ¶ms)
|
||||
return WIFI_OPT_SCAN_NOT_OPENED;
|
||||
}
|
||||
|
||||
#ifndef OHOS_ARCH_LITE
|
||||
UpdateScanMode();
|
||||
#endif
|
||||
IScanService *pService = WifiServiceManager::GetInstance().GetScanServiceInst(m_instId);
|
||||
if (pService == nullptr) {
|
||||
return WIFI_OPT_SCAN_NOT_OPENED;
|
||||
@ -286,6 +293,21 @@ ErrCode WifiScanServiceImpl::GetScanOnlyAvailable(bool &bScanOnlyAvailable)
|
||||
return WIFI_OPT_SUCCESS;
|
||||
}
|
||||
|
||||
ErrCode WifiScanServiceImpl::StartWifiPnoScan(bool isStartAction, int periodMs, int suspendReason)
|
||||
{
|
||||
WIFI_LOGD("WifiScanServiceImpl::StartWifiPnoScan");
|
||||
if (!WifiAuthCenter::IsNativeProcess()) {
|
||||
WIFI_LOGE("StartWifiPnoScan:NOT NATIVE PROCESS, PERMISSION_DENIED!");
|
||||
return WIFI_OPT_PERMISSION_DENIED;
|
||||
}
|
||||
|
||||
IScanService *pService = WifiServiceManager::GetInstance().GetScanServiceInst(m_instId);
|
||||
if (pService == nullptr) {
|
||||
return WIFI_OPT_SCAN_NOT_OPENED;
|
||||
}
|
||||
return pService->StartWifiPnoScan(isStartAction, periodMs, suspendReason);
|
||||
}
|
||||
|
||||
ErrCode WifiScanServiceImpl::OpenScanOnlyAvailable()
|
||||
{
|
||||
WIFI_LOGI("WifiScanServiceImpl OpenScanOnlyAvailable");
|
||||
@ -405,5 +427,23 @@ bool WifiScanServiceImpl::IsRemoteDied(void)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifndef OHOS_ARCH_LITE
|
||||
void WifiScanServiceImpl::UpdateScanMode()
|
||||
{
|
||||
int uid = GetCallingUid();
|
||||
int pid = GetCallingPid();
|
||||
std::string processName = GetRunningProcessNameByPid(uid, pid);
|
||||
if (!processName.empty()) {
|
||||
if (IsForegroundApp(uid)) {
|
||||
WifiSettings::GetInstance().SetAppRunningState(ScanMode::APP_FOREGROUND_SCAN);
|
||||
} else {
|
||||
WifiSettings::GetInstance().SetAppRunningState(ScanMode::APP_BACKGROUND_SCAN);
|
||||
}
|
||||
} else {
|
||||
WifiSettings::GetInstance().SetAppRunningState(ScanMode::SYS_BACKGROUND_SCAN);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
} // namespace Wifi
|
||||
} // namespace OHOS
|
||||
|
@ -49,6 +49,7 @@ public:
|
||||
ErrCode GetScanInfoList(std::vector<WifiScanInfo> &result, bool compatible) override;
|
||||
ErrCode SetScanOnlyAvailable(bool bScanOnlyAvailable) override;
|
||||
ErrCode GetScanOnlyAvailable(bool &bScanOnlyAvailable) override;
|
||||
ErrCode StartWifiPnoScan(bool isStartAction, int periodMs, int suspendReason) override;
|
||||
#ifdef OHOS_ARCH_LITE
|
||||
ErrCode RegisterCallBack(const std::shared_ptr<IWifiScanCallback> &callback,
|
||||
const std::vector<std::string> &event) override;
|
||||
@ -64,6 +65,9 @@ private:
|
||||
bool IsScanServiceRunning();
|
||||
ErrCode OpenScanOnlyAvailable();
|
||||
ErrCode CloseScanOnlyAvailable();
|
||||
#ifndef OHOS_ARCH_LITE
|
||||
void UpdateScanMode();
|
||||
#endif
|
||||
|
||||
private:
|
||||
#ifdef OHOS_ARCH_LITE
|
||||
|
@ -61,6 +61,8 @@ void WifiScanStub::InitHandleMap()
|
||||
&WifiScanStub::OnSetScanOnlyAvailable;
|
||||
handleFuncMap[static_cast<uint32_t>(ScanInterfaceCode::WIFI_SVR_CMD_GET_WIFI_SCAN_ONLY)] =
|
||||
&WifiScanStub::OnGetScanOnlyAvailable;
|
||||
handleFuncMap[static_cast<uint32_t>(ScanInterfaceCode::WIFI_SVR_CMD_START_PNO_SCAN)] =
|
||||
&WifiScanStub::OnStartWifiPnoScan;
|
||||
}
|
||||
|
||||
int WifiScanStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
|
||||
@ -134,9 +136,10 @@ int WifiScanStub::OnSetScanControlInfo(uint32_t code, MessageParcel &data, Messa
|
||||
int WifiScanStub::OnScan(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
|
||||
{
|
||||
bool compatible = data.ReadBool();
|
||||
std::string name = data.ReadString();
|
||||
WIFI_LOGD("run OnScan code %{public}u, datasize %{public}zu, compatible:%{public}d",
|
||||
code, data.GetRawDataSize(), compatible);
|
||||
WifiSettings::GetInstance().SetAppPackageName(GetBundleName());
|
||||
WifiSettings::GetInstance().SetAppPackageName(name);
|
||||
ErrCode ret = Scan(compatible);
|
||||
WifiSettings::GetInstance().SetAppPackageName("");
|
||||
reply.WriteInt32(0);
|
||||
@ -166,8 +169,9 @@ int WifiScanStub::OnScanByParams(uint32_t code, MessageParcel &data, MessageParc
|
||||
params.freqs.push_back(tmp);
|
||||
}
|
||||
params.band = data.ReadInt32();
|
||||
std::string name = data.ReadString();
|
||||
|
||||
WifiSettings::GetInstance().SetAppPackageName(GetBundleName());
|
||||
WifiSettings::GetInstance().SetAppPackageName(name);
|
||||
ErrCode ret = AdvanceScan(params);
|
||||
WifiSettings::GetInstance().SetAppPackageName("");
|
||||
reply.WriteInt32(0);
|
||||
@ -330,5 +334,18 @@ int WifiScanStub::OnGetScanOnlyAvailable(
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int WifiScanStub::OnStartWifiPnoScan(
|
||||
uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
|
||||
{
|
||||
WIFI_LOGI("In WifiScanStub::OnStartWifiPnoScan");
|
||||
bool isStart = data.ReadBool();
|
||||
int periodMs = data.ReadInt32();
|
||||
int suspendReason = data.ReadInt32();
|
||||
ErrCode ret = StartWifiPnoScan(isStart, periodMs, suspendReason);
|
||||
reply.WriteInt32(0);
|
||||
reply.WriteInt32(ret);
|
||||
return 0;
|
||||
}
|
||||
} // namespace Wifi
|
||||
} // namespace OHOS
|
||||
|
@ -48,6 +48,7 @@ private:
|
||||
int OnGetSupportedFeatures(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
|
||||
int OnSetScanOnlyAvailable(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
|
||||
int OnGetScanOnlyAvailable(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
|
||||
int OnStartWifiPnoScan(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
|
||||
|
||||
sptr<IRemoteObject::DeathRecipient> deathRecipient_;
|
||||
HandleFuncMap handleFuncMap;
|
||||
|
@ -28,7 +28,6 @@ local_base_sources = [
|
||||
"sta_auto_connect_service.cpp",
|
||||
"sta_interface.cpp",
|
||||
"sta_monitor.cpp",
|
||||
"sta_network_check.cpp",
|
||||
"sta_saved_device_appraisal.cpp",
|
||||
"sta_service.cpp",
|
||||
"sta_state_machine.cpp",
|
||||
@ -156,7 +155,6 @@ if (defined(ohos_lite)) {
|
||||
"hilog:libhilog",
|
||||
"ipc:ipc_single",
|
||||
"netmanager_base:net_conn_manager_if",
|
||||
"netstack:http_client",
|
||||
"samgr:samgr_proxy",
|
||||
]
|
||||
|
||||
|
@ -105,6 +105,10 @@ void StaMonitor::OnConnectChangedCallBack(int status, int networkId, const std::
|
||||
pStaStateMachine->OnNetworkDisconnectEvent(networkId);
|
||||
break;
|
||||
}
|
||||
case WPA_CB_ASSOCIATING:
|
||||
case WPA_CB_ASSOCIATED:
|
||||
pStaStateMachine->OnNetworkAssocEvent(status);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -52,6 +52,7 @@ DEFINE_WIFILOG_LABEL("StaStateMachine");
|
||||
#define WPA3_BLACKMAP_MAX_NUM 20
|
||||
#define WPA3_BLACKMAP_RSSI_THRESHOLD (-70)
|
||||
#define WPA3_CONNECT_FAIL_COUNT_THRESHOLD 2
|
||||
#define WPA_CB_ASSOCIATING 3
|
||||
StaStateMachine::StaStateMachine(int instId)
|
||||
: StateMachine("StaStateMachine"),
|
||||
lastNetworkId(INVALID_NETWORK_ID),
|
||||
@ -1759,6 +1760,15 @@ void StaStateMachine::OnNetworkDisconnectEvent(int reason)
|
||||
WriteWifiAbnormalDisconnectHiSysEvent(reason);
|
||||
}
|
||||
|
||||
void StaStateMachine::OnNetworkAssocEvent(int assocState)
|
||||
{
|
||||
if (assocState == WPA_CB_ASSOCIATING) {
|
||||
InvokeOnStaConnChanged(OperateResState::CONNECT_ASSOCIATING, linkedInfo);
|
||||
} else {
|
||||
InvokeOnStaConnChanged(OperateResState::CONNECT_ASSOCIATED, linkedInfo);
|
||||
}
|
||||
}
|
||||
|
||||
void StaStateMachine::OnBssidChangedEvent(std::string reason, std::string bssid)
|
||||
{
|
||||
InternalMessage *msg = CreateMessage();
|
||||
|
@ -380,6 +380,12 @@ public:
|
||||
* @param reason - the reason of wifi disconnection
|
||||
*/
|
||||
void OnNetworkDisconnectEvent(int reason);
|
||||
/**
|
||||
* @Description Assoc events
|
||||
*
|
||||
* @param reason - the state of wifi assoc
|
||||
*/
|
||||
void OnNetworkAssocEvent(int assocState);
|
||||
/**
|
||||
* @Description Bssid change events
|
||||
*
|
||||
|
@ -38,6 +38,7 @@ local_base_sources = [
|
||||
"net_helper/mac_address.cpp",
|
||||
"net_helper/network_interface.cpp",
|
||||
"net_helper/raw_socket.cpp",
|
||||
"net_helper/sta_network_check.cpp",
|
||||
"utils/wifi_common_event_helper.cpp",
|
||||
"utils/wifi_encryption_util.cpp",
|
||||
"utils/wifi_global_func.cpp",
|
||||
@ -49,6 +50,7 @@ local_base_include_dirs = [
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/net_helper",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/utils",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/config",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta",
|
||||
"//commonlibrary/c_utils/base/include",
|
||||
"//base/hiviewdfx/hilog/interfaces/native/innerkits/include",
|
||||
"$WIFI_ROOT_DIR/interfaces/inner_api",
|
||||
@ -125,6 +127,9 @@ if (defined(ohos_lite)) {
|
||||
if (wifi_feature_with_random_mac_addr) {
|
||||
defines += [ "SUPPORT_RANDOM_MAC_ADDR" ]
|
||||
}
|
||||
if (wifi_feature_with_scan_control) {
|
||||
defines += [ "SUPPORT_SCAN_CONTROL" ]
|
||||
}
|
||||
|
||||
external_deps = [
|
||||
"ability_base:want",
|
||||
@ -135,6 +140,7 @@ if (defined(ohos_lite)) {
|
||||
"eventhandler:libeventhandler",
|
||||
"hilog:libhilog",
|
||||
"huks:libhukssdk",
|
||||
"netstack:http_client",
|
||||
]
|
||||
|
||||
if (defined(global_parts_info) && defined(global_parts_info.startup_init)) {
|
||||
|
@ -57,6 +57,7 @@ WifiSettings::WifiSettings()
|
||||
mApMaxConnNum(0),
|
||||
mMaxNumConfigs(0),
|
||||
mScreenState(MODE_STATE_OPEN),
|
||||
mScanGenieState(MODE_STATE_OPEN),
|
||||
mAirplaneModeState(MODE_STATE_CLOSE),
|
||||
mPowerSleepState(MODE_STATE_CLOSE),
|
||||
mDeviceProvision(MODE_STATE_OPEN),
|
||||
@ -1382,6 +1383,47 @@ void WifiSettings::ClearLocalHid2dInfo()
|
||||
mP2pBusinessType = P2pBusinessType::INVALID;
|
||||
}
|
||||
|
||||
void WifiSettings::SetPowerIdelState(const int &state)
|
||||
{
|
||||
mIdelState = state;
|
||||
}
|
||||
|
||||
int WifiSettings::GetPowerIdelState() const
|
||||
{
|
||||
return mIdelState;
|
||||
}
|
||||
|
||||
void WifiSettings::SetGnssFixState(const int &state)
|
||||
{
|
||||
mGnssFixState = state;
|
||||
}
|
||||
|
||||
int WifiSettings::GetGnssFixState() const
|
||||
{
|
||||
return mGnssFixState;
|
||||
}
|
||||
|
||||
void WifiSettings::SetAbnormalApps(const std::vector<std::string> &abnormalAppList)
|
||||
{
|
||||
mAbnormalAppList = abnormalAppList;
|
||||
}
|
||||
|
||||
int WifiSettings::GetAbnormalApps(std::vector<std::string> &abnormalAppList)
|
||||
{
|
||||
abnormalAppList = mAbnormalAppList;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void WifiSettings::SetScanGenieState(const int &state)
|
||||
{
|
||||
mScanGenieState = state;
|
||||
}
|
||||
|
||||
int WifiSettings::GetScanGenieState() const
|
||||
{
|
||||
return mScanGenieState;
|
||||
}
|
||||
|
||||
int WifiSettings::GetSignalLevel(const int &rssi, const int &band, int instId)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mWifiConfigMutex);
|
||||
@ -1479,9 +1521,25 @@ void WifiSettings::InitScanControlForbidList(void)
|
||||
mScanControlInfo[0].scanForbidList.push_back(forbidMode);
|
||||
|
||||
/* Disable all scans in connection */
|
||||
#ifdef SUPPORT_SCAN_CONTROL
|
||||
forbidMode.scanMode = ScanMode::ALL_EXTERN_SCAN;
|
||||
forbidMode.scanScene = SCAN_SCENE_ASSOCIATING;
|
||||
forbidMode.forbidTime = 2;
|
||||
mScanControlInfo[0].scanForbidList.push_back(forbidMode);
|
||||
forbidMode.scanMode = ScanMode::ALL_EXTERN_SCAN;
|
||||
forbidMode.scanScene = SCAN_SCENE_ASSOCIATED;
|
||||
forbidMode.forbidTime = 5;
|
||||
mScanControlInfo[0].scanForbidList.push_back(forbidMode);
|
||||
forbidMode.scanMode = ScanMode::ALL_EXTERN_SCAN;
|
||||
forbidMode.scanScene = SCAN_SCENE_OBTAINING_IP;
|
||||
forbidMode.forbidCount = 1;
|
||||
forbidMode.forbidTime = 5;
|
||||
mScanControlInfo[0].scanForbidList.push_back(forbidMode);
|
||||
#else
|
||||
forbidMode.scanMode = ScanMode::ALL_EXTERN_SCAN;
|
||||
forbidMode.scanScene = SCAN_SCENE_CONNECTING;
|
||||
mScanControlInfo[0].scanForbidList.push_back(forbidMode);
|
||||
#endif
|
||||
forbidMode.scanMode = ScanMode::PNO_SCAN;
|
||||
forbidMode.scanScene = SCAN_SCENE_CONNECTING;
|
||||
mScanControlInfo[0].scanForbidList.push_back(forbidMode);
|
||||
@ -1574,7 +1632,11 @@ void WifiSettings::InitScanControlIntervalList(void)
|
||||
scanIntervalMode.isSingle = false;
|
||||
scanIntervalMode.intervalMode = IntervalMode::INTERVAL_EXP;
|
||||
scanIntervalMode.interval = SYSTEM_TIMER_SCAN_CONTROL_INTERVAL;
|
||||
#ifdef SUPPORT_SCAN_CONTROL
|
||||
scanIntervalMode.count = 0;
|
||||
#else
|
||||
scanIntervalMode.count = SYSTEM_TIMER_SCAN_CONTROL_TIMES;
|
||||
#endif
|
||||
mScanControlInfo[0].scanIntervalList.push_back(scanIntervalMode);
|
||||
return;
|
||||
}
|
||||
|
@ -962,6 +962,70 @@ public:
|
||||
*/
|
||||
int GetScreenState() const;
|
||||
|
||||
/**
|
||||
* @Description Set the Idel State
|
||||
*
|
||||
* @param state - 1 on; 2 off
|
||||
*/
|
||||
void SetPowerIdelState(const int &state);
|
||||
|
||||
/**
|
||||
* @Description Get the Idel State
|
||||
*
|
||||
* @return int - 1 on; 2 off
|
||||
*/
|
||||
int GetPowerIdelState() const;
|
||||
|
||||
/**
|
||||
* @Description Set the Battery Charge State
|
||||
*
|
||||
* @param state - 1 on; 2 off
|
||||
*/
|
||||
void SetBatteryChargeState(const int &state);
|
||||
|
||||
/**
|
||||
* @Description Set the Gnss Fix State
|
||||
*
|
||||
* @param state - 1 on; 2 off
|
||||
*/
|
||||
void SetGnssFixState(const int &state);
|
||||
|
||||
/**
|
||||
* @Description Get the Gnss Fix State
|
||||
*
|
||||
* @return int - 1 on; 2 off
|
||||
*/
|
||||
int GetGnssFixState() const;
|
||||
|
||||
/**
|
||||
* @Description Set the abnormal apps
|
||||
*
|
||||
* @param abnormalAppList - abnormal app list
|
||||
*/
|
||||
void SetAbnormalApps(const std::vector<std::string> &abnormalAppList);
|
||||
|
||||
/**
|
||||
* @Description Get the abnormal apps
|
||||
*
|
||||
* @param abnormalAppList - abnormal app list
|
||||
* @return int - 0 success
|
||||
*/
|
||||
int GetAbnormalApps(std::vector<std::string> &abnormalAppList);
|
||||
|
||||
/**
|
||||
* @Description Set the scan genie state
|
||||
*
|
||||
* @param state - 1 on; 2 off
|
||||
*/
|
||||
void SetScanGenieState(const int &state);
|
||||
|
||||
/**
|
||||
* @Description Get the scan genie state
|
||||
*
|
||||
* @return int - 1 on; 2 off
|
||||
*/
|
||||
int GetScanGenieState() const;
|
||||
|
||||
/**
|
||||
* @Description Set the Airplane Mode State
|
||||
*
|
||||
@ -1568,6 +1632,10 @@ private:
|
||||
std::map <int, time_t> mLastSelectedTimeVal; /* last selected time */
|
||||
int mScreenState; /* 1 MODE_STATE_OPEN, 2 MODE_STATE_CLOSE */
|
||||
int mThermalLevel; /* 1 COOL, 2 NORMAL, 3 WARM, 4 HOT, 5 OVERHEATED, 6 WARNING, 7 EMERGENCY */
|
||||
int mIdelState; /* 1 MODE_STATE_OPEN, 2 MODE_STATE_CLOSE */
|
||||
int mBatteryChargeState; /* 1 MODE_STATE_OPEN, 2 MODE_STATE_CLOSE */
|
||||
int mGnssFixState; /* 1 MODE_STATE_OPEN, 2 MODE_STATE_CLOSE */
|
||||
int mScanGenieState; /* 1 MODE_STATE_OPEN, 2 MODE_STATE_CLOSE */
|
||||
std::atomic<int> mAirplaneModeState; /* 1 on 2 off */
|
||||
std::atomic<int> mPowerSleepState; /* 1 on 2 off */
|
||||
int mDeviceProvision; /* 1 on 2 off */
|
||||
@ -1622,6 +1690,7 @@ private:
|
||||
std::atomic_bool mThreadStatusFlag_ { false };
|
||||
std::atomic_uint64_t mThreadStartTime { 0 };
|
||||
std::map<std::string, std::vector<std::string>> mFilterMap;
|
||||
std::vector<std::string> mAbnormalAppList;
|
||||
};
|
||||
} // namespace Wifi
|
||||
} // namespace OHOS
|
||||
|
@ -16,6 +16,10 @@
|
||||
#include "sta_network_check.h"
|
||||
#include "wifi_logger.h"
|
||||
#include "wifi_settings.h"
|
||||
#ifndef OHOS_ARCH_LITE
|
||||
#include "http_client_request.h"
|
||||
#include "http_client.h"
|
||||
#endif
|
||||
|
||||
DEFINE_WIFILOG_LABEL("StaNetworkCheck");
|
||||
|
||||
@ -137,13 +141,7 @@ int StaNetworkCheck::HttpPortalDetection(const std::string &url)
|
||||
WIFI_LOGE("http create task failed !");
|
||||
return -1;
|
||||
}
|
||||
RegistHttpCallBack(task);
|
||||
task->Start();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void StaNetworkCheck::RegistHttpCallBack(std::shared_ptr<NetStack::HttpClient::HttpClientTask> task)
|
||||
{
|
||||
task->OnSuccess([task, this](const NetStack::HttpClient::HttpClientRequest &request,
|
||||
const NetStack::HttpClient::HttpClientResponse &response) {
|
||||
std::string url = request.GetURL();
|
||||
@ -180,6 +178,9 @@ void StaNetworkCheck::RegistHttpCallBack(std::shared_ptr<NetStack::HttpClient::H
|
||||
}
|
||||
WIFI_LOGE("HttpPortalDetection OnFailed, url:%{public}s, responseCode:%{public}d", url.c_str(), codeNum);
|
||||
});
|
||||
|
||||
task->Start();
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
void StaNetworkCheck::RunNetCheckThreadFunc()
|
@ -31,10 +31,6 @@
|
||||
#include "arp_checker.h"
|
||||
#include "dns_checker.h"
|
||||
#include "wifi_internal_msg.h"
|
||||
#ifndef OHOS_ARCH_LITE
|
||||
#include "http_client_request.h"
|
||||
#include "http_client.h"
|
||||
#endif
|
||||
|
||||
#define HTTP_DETECTION_TIMEOUT 10000
|
||||
#define HTTP_BACKUP_TIMEOUT 3000
|
||||
@ -87,8 +83,6 @@ private:
|
||||
*
|
||||
*/
|
||||
int HttpPortalDetection(const std::string& url);
|
||||
|
||||
void RegistHttpCallBack(std::shared_ptr<NetStack::HttpClient::HttpClientTask> task);
|
||||
#endif
|
||||
/**
|
||||
* @Description : NetCheck thread function
|
@ -49,8 +49,12 @@
|
||||
#define P2P_SERVICE_DISC_REQ_FIVE 5
|
||||
#define WPA_CB_CONNECTED 1
|
||||
#define WPA_CB_DISCONNECTED 2
|
||||
#define WPA_CB_ASSOCIATING 3
|
||||
#define WPA_CB_ASSOCIATED 4
|
||||
#define WPS_EVENT_PBC_OVERLAP "WPS-OVERLAP-DETECTED PBC session overlap"
|
||||
#define WPA_EVENT_BSSID_CHANGED "WPA-EVENT-BSSID-CHANGED "
|
||||
#define WPA_EVENT_ASSOCIATING "Request association with "
|
||||
#define WPA_EVENT_ASSOCIATED "Associated with "
|
||||
#define REPLY_BUF_LENGTH 4096
|
||||
#define CONNECTION_FULL_STATUS 17
|
||||
#define CONNECTION_REJECT_STATUS 37
|
||||
@ -615,6 +619,20 @@ static void WpaCallBackFuncTwo(const char *p)
|
||||
WifiHalCbNotifyConnectionReject(status);
|
||||
}
|
||||
}
|
||||
} else if (strncmp(p, WPA_EVENT_ASSOCIATING, strlen(WPA_EVENT_ASSOCIATING)) == 0) {
|
||||
char *pBssid = strstr(p, WPA_EVENT_ASSOCIATING);
|
||||
if (pBssid == NULL) {
|
||||
return;
|
||||
}
|
||||
pBssid += strlen(WPA_EVENT_ASSOCIATING);
|
||||
WifiHalCbNotifyConnectChanged(WPA_CB_ASSOCIATING, -1, pBssid);
|
||||
} else if (strncmp(p, WPA_EVENT_ASSOCIATED, strlen(WPA_EVENT_ASSOCIATED)) == 0) {
|
||||
char *pBssid = strstr(p, WPA_EVENT_ASSOCIATED);
|
||||
if (pBssid == NULL) {
|
||||
return;
|
||||
}
|
||||
pBssid += strlen(WPA_EVENT_ASSOCIATED);
|
||||
WifiHalCbNotifyConnectChanged(WPA_CB_ASSOCIATED, -1, pBssid);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
68
wifi/test/wifi_standard/wifi_base/BUILD.gn
Normal file
68
wifi/test/wifi_standard/wifi_base/BUILD.gn
Normal file
@ -0,0 +1,68 @@
|
||||
# Copyright (C) 2021-2022 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/base_test"
|
||||
|
||||
config("module_private_config") {
|
||||
visibility = [ ":*" ]
|
||||
include_dirs = [ "$WIFI_ROOT_DIR/test/wifi_standard/wifi_base" ]
|
||||
}
|
||||
|
||||
ohos_unittest("base_unittest") {
|
||||
module_out_path = module_output_path
|
||||
sources = [
|
||||
"$WIFI_ROOT_DIR/base/cRPC/src/context.c",
|
||||
"$WIFI_ROOT_DIR/base/cRPC/src/evloop.c",
|
||||
"$WIFI_ROOT_DIR/base/cRPC/src/hash_table.c",
|
||||
"$WIFI_ROOT_DIR/base/cRPC/src/net.c",
|
||||
"$WIFI_ROOT_DIR/base/cRPC/src/serial.c",
|
||||
"$WIFI_ROOT_DIR/base/cRPC/src/server.c",
|
||||
"context_test.cpp",
|
||||
"hash_table_test.cpp",
|
||||
"net_test.cpp",
|
||||
"rpc_test_main.cpp",
|
||||
"serial_test.cpp",
|
||||
"server_test.cpp",
|
||||
]
|
||||
|
||||
include_dirs = [ "$WIFI_ROOT_DIR/base/cRPC/include" ]
|
||||
|
||||
ldflags = [
|
||||
"-fPIC",
|
||||
"-Wl,--wrap=write",
|
||||
"-Wl,--wrap=read",
|
||||
"--coverage",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//third_party/googletest:gmock_main",
|
||||
"//third_party/googletest:gtest_main",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"hilog:libhilog",
|
||||
]
|
||||
configs = [ ":module_private_config" ]
|
||||
|
||||
part_name = "wifi"
|
||||
subsystem_name = "communication"
|
||||
testonly = true
|
||||
}
|
||||
|
||||
group("unittest") {
|
||||
testonly = true
|
||||
deps = [ ":base_unittest" ]
|
||||
}
|
204
wifi/test/wifi_standard/wifi_base/context_test.cpp
Normal file
204
wifi/test/wifi_standard/wifi_base/context_test.cpp
Normal file
@ -0,0 +1,204 @@
|
||||
/*
|
||||
* Copyright (C) 2021-2022 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 "context_test.h"
|
||||
#include <securec.h>
|
||||
#include "common.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace OHOS {
|
||||
namespace Wifi {
|
||||
static int CalculateLeft(const Context *ctx)
|
||||
{
|
||||
int left =
|
||||
(ctx->wBegin <= ctx->wEnd) ? (ctx->wCapacity - 1 - ctx->wEnd + ctx->wBegin) : (ctx->wBegin - ctx->wEnd - 1);
|
||||
return left;
|
||||
}
|
||||
|
||||
HWTEST_F(ContextTest, CreateContextTest, TestSize.Level1)
|
||||
{
|
||||
ctx = CreateContext(100);
|
||||
ASSERT_TRUE(ctx != nullptr);
|
||||
ASSERT_TRUE(ctx->wCapacity == CONTEXT_BUFFER_MIN_SIZE);
|
||||
ReleaseContext(ctx);
|
||||
ctx = CreateContext(102400000);
|
||||
ASSERT_TRUE(ctx != nullptr);
|
||||
ASSERT_TRUE(ctx->wCapacity == CONTEXT_BUFFER_MAX_SIZE);
|
||||
}
|
||||
|
||||
HWTEST_F(ContextTest, AppendCacheTest, TestSize.Level1)
|
||||
{
|
||||
ctx = CreateContext(1024);
|
||||
ASSERT_TRUE(ctx != nullptr) << "capacity :" << ctx->wCapacity;
|
||||
/* capacity size 1024 */
|
||||
ASSERT_TRUE(ctx->wCapacity == 1024);
|
||||
ASSERT_TRUE(ctx->wEnd == 0);
|
||||
|
||||
/* calculate left capacity test */
|
||||
ctx->wBegin = ctx->wEnd = 0;
|
||||
ASSERT_TRUE(CalculateLeft(ctx) == 1023); /* capacity, use a space define endpos */
|
||||
ctx->wEnd = 1023; /* pos [0,1023], max pos 1023 */
|
||||
ASSERT_TRUE(CalculateLeft(ctx) == 0);
|
||||
ctx->wBegin = 1023;
|
||||
ctx->wEnd = 0;
|
||||
ASSERT_TRUE(CalculateLeft(ctx) == 1022); /* wEnd max num can be 1022, so from 0 - 1021 = 1022 */
|
||||
ctx->wEnd = 1022;
|
||||
ASSERT_TRUE(CalculateLeft(ctx) == 0);
|
||||
ctx->wBegin = ctx->wEnd = 0;
|
||||
|
||||
char buff[] = "123456789 123456789 123456789 12";
|
||||
for (unsigned i = 0; i < 1024 / 32 - 1; ++i) {
|
||||
ContextAppendWrite(ctx, buff, strlen(buff));
|
||||
ASSERT_TRUE(ctx->wEnd == (i + 1) * 32);
|
||||
}
|
||||
ContextAppendWrite(test, buff, strlen(buff));
|
||||
ASSERT_TRUE(strcpy_s(buff, sizeof(buff), "123456789 123456789 123456789 1") == EOK);
|
||||
ContextAppendWrite(ctx, buff, strlen(buff));
|
||||
ASSERT_TRUE(ctx->wEnd == 1023);
|
||||
ASSERT_TRUE(CalculateLeft(ctx) == 0);
|
||||
ctx->wBegin = 1023;
|
||||
ASSERT_TRUE(strcpy_s(buff, sizeof(buff), "123456789 123456789 123456789 12") == EOK);
|
||||
for (unsigned i = 0; i < 1024 / 32 - 1; ++i) {
|
||||
ContextAppendWrite(ctx, buff, strlen(buff));
|
||||
ASSERT_TRUE(ctx->wEnd == (i + 1) * 32 - 1);
|
||||
}
|
||||
ASSERT_TRUE(CalculateLeft(ctx) == 31);
|
||||
ContextAppendWrite(ctx, buff, strlen(buff));
|
||||
ASSERT_TRUE(ctx->wCapacity == 2048);
|
||||
ASSERT_TRUE(ctx->wEnd == (1023 + 1024));
|
||||
ctx->wCapacity = -1;
|
||||
ContextAppendWrite(ctx, buff, strlen(buff));
|
||||
}
|
||||
|
||||
static int ExpandReadCache(Context *context, int len)
|
||||
{
|
||||
int left = (context->rBegin <= context->rEnd) ? (context->rCapacity - 1 - context->rEnd + context->rBegin)
|
||||
: (context->rBegin - context->rEnd - 1);
|
||||
if (left < len) {
|
||||
int capacity = context->rCapacity;
|
||||
while (left < len) {
|
||||
capacity += context->rCapacity;
|
||||
left += context->rCapacity;
|
||||
}
|
||||
char *p = (char *)calloc(capacity, sizeof(char));
|
||||
if (p == nullptr) {
|
||||
return -1;
|
||||
}
|
||||
if (memmove_s(p, capacity, context->szRead, context->rCapacity) != EOK) {
|
||||
free(p);
|
||||
return -1;
|
||||
}
|
||||
if (context->rBegin > context->rEnd &&
|
||||
memmove_s(p + context->rCapacity, context->rCapacity, p, context->rEnd) != EOK) {
|
||||
free(p);
|
||||
return -1;
|
||||
}
|
||||
context->szRead = p;
|
||||
if (context->rBegin > context->rEnd) {
|
||||
context->rEnd += context->rCapacity;
|
||||
}
|
||||
context->rCapacity = capacity;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ContextAppendRead(Context *context, const char *buf, int len)
|
||||
{
|
||||
if (ExpandReadCache(context, len) < 0) {
|
||||
return -1;
|
||||
}
|
||||
if (context->rEnd + len < context->rCapacity) {
|
||||
if (memmove_s(context->szRead + context->rEnd, context->rCapacity - context->rEnd, buf, len) != EOK) {
|
||||
return -1;
|
||||
}
|
||||
context->rEnd += len;
|
||||
} else {
|
||||
int tmp = context->rCapacity - context->rEnd;
|
||||
if (tmp > 0 && memmove_s(context->szRead + context->rEnd, tmp, buf, tmp) != EOK) {
|
||||
return -1;
|
||||
}
|
||||
if (tmp < len && memmove_s(context->szRead, len - tmp, buf + tmp, len - tmp) != EOK) {
|
||||
return -1;
|
||||
}
|
||||
context->rEnd = len - tmp;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
HWTEST_F(ContextTest, ContextGetReadRecordTest, TestSize.Level1)
|
||||
{
|
||||
ctx = CreateContext(1024);
|
||||
ASSERT_TRUE(ctx != nullptr);
|
||||
ASSERT_TRUE(ctx->rCapacity == 1024);
|
||||
ContextGetReadRecord(test);
|
||||
char *p = ContextGetReadRecord(ctx);
|
||||
ASSERT_TRUE(p == nullptr);
|
||||
|
||||
int ret = ContextAppendRead(ctx, "hello", strlen("hello"));
|
||||
ASSERT_TRUE(ret == 0);
|
||||
p = ContextGetReadRecord(ctx);
|
||||
ASSERT_TRUE(p == nullptr);
|
||||
ret = ContextAppendRead(ctx, ctx->cMsgEnd, strlen(ctx->cMsgEnd));
|
||||
ASSERT_TRUE(ret == 0);
|
||||
p = ContextGetReadRecord(ctx);
|
||||
ASSERT_TRUE(p != nullptr);
|
||||
EXPECT_TRUE(strcmp(p, "hello") == 0);
|
||||
free(p);
|
||||
ctx->rBegin = ctx->rEnd = 1024 - 5; // set end pos
|
||||
ret = ContextAppendRead(ctx, "hello, welcome", strlen("hello, welcome"));
|
||||
ASSERT_TRUE(ret == 0);
|
||||
p = ContextGetReadRecord(ctx);
|
||||
ASSERT_TRUE(p == nullptr);
|
||||
ret = ContextAppendRead(ctx, ctx->cMsgEnd, strlen(ctx->cMsgEnd));
|
||||
ASSERT_TRUE(ret == 0);
|
||||
p = ContextGetReadRecord(ctx);
|
||||
ASSERT_TRUE(p != nullptr);
|
||||
EXPECT_TRUE(strcmp(p, "hello, welcome") == 0);
|
||||
free(p);
|
||||
}
|
||||
|
||||
HWTEST_F(ContextTest, ContextReadNetTest, TestSize.Level1)
|
||||
{
|
||||
ctx = CreateContext(1024);
|
||||
ASSERT_TRUE(ctx != nullptr);
|
||||
ContextReadNet(test);
|
||||
int ret = ContextReadNet(ctx);
|
||||
EXPECT_TRUE(ret == MAX_ONE_LINE_SIZE - 1);
|
||||
ctx->rBegin = 1024 - 5;
|
||||
ret = ContextReadNet(ctx);
|
||||
EXPECT_TRUE(ret == MAX_ONE_LINE_SIZE - 1);
|
||||
EXPECT_TRUE(ctx->rCapacity == 2048);
|
||||
}
|
||||
|
||||
HWTEST_F(ContextTest, ContextWriteNetTest, TestSize.Level1)
|
||||
{
|
||||
ASSERT_TRUE(ContextWriteNet(nullptr) == -1);
|
||||
ctx = CreateContext(1024);
|
||||
ASSERT_TRUE(ctx != nullptr);
|
||||
int ret = ContextWriteNet(ctx);
|
||||
EXPECT_TRUE(ret == 0);
|
||||
char buff[] = "123456789 123456789 123456789 12";
|
||||
int size = strlen(buff);
|
||||
ContextAppendWrite(ctx, buff, size);
|
||||
ret = ContextWriteNet(ctx);
|
||||
EXPECT_TRUE(ret == size);
|
||||
ctx->wBegin = ctx->wEnd = 1023;
|
||||
ContextAppendWrite(ctx, buff, size);
|
||||
ret = ContextWriteNet(ctx);
|
||||
EXPECT_TRUE(ret == size - 1);
|
||||
}
|
||||
} // namespace Wifi
|
||||
} // namespace OHOS
|
45
wifi/test/wifi_standard/wifi_base/context_test.h
Normal file
45
wifi/test/wifi_standard/wifi_base/context_test.h
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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_CRPC_CONTEXT_TEST_H
|
||||
#define OHOS_WIFI_CRPC_CONTEXT_TEST_H
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "context.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Wifi {
|
||||
class ContextTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase()
|
||||
{}
|
||||
static void TearDownTestCase()
|
||||
{}
|
||||
virtual void SetUp()
|
||||
{}
|
||||
virtual void TearDown()
|
||||
{
|
||||
if (ctx != nullptr) {
|
||||
ReleaseContext(ctx);
|
||||
ctx = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
Context *ctx;
|
||||
Context *test = NULL;
|
||||
};
|
||||
} // namespace Wifi
|
||||
} // namespace OHOS
|
||||
#endif
|
77
wifi/test/wifi_standard/wifi_base/hash_table_test.cpp
Normal file
77
wifi/test/wifi_standard/wifi_base/hash_table_test.cpp
Normal file
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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 "hash_table_test.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace OHOS {
|
||||
namespace Wifi {
|
||||
static unsigned g_pNum[] = {
|
||||
3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
|
||||
static unsigned FindNextNum(unsigned num)
|
||||
{
|
||||
for (unsigned i = 0; i < sizeof(g_pNum) / sizeof(g_pNum[0]); ++i) {
|
||||
if (g_pNum[i] >= num) {
|
||||
return g_pNum[i];
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
HWTEST_F(HashTableTest, InitHashTableTest, TestSize.Level1)
|
||||
{
|
||||
unsigned slots = 13;
|
||||
table = InitHashTable(slots);
|
||||
EXPECT_TRUE(table != nullptr);
|
||||
EXPECT_TRUE(table->list != nullptr);
|
||||
EXPECT_TRUE(table->slots == FindNextNum(slots));
|
||||
for (unsigned i = 0; i < table->slots; ++i) {
|
||||
EXPECT_TRUE(table->list[i] == nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
HWTEST_F(HashTableTest, UseHashTableTest, TestSize.Level1)
|
||||
{
|
||||
table = InitHashTable(3);
|
||||
HashTable *p = nullptr;
|
||||
ASSERT_NE(table, nullptr);
|
||||
for (int fd = 1; fd <= 100; ++fd) {
|
||||
Context *ctx = (Context *)calloc(1, sizeof(Context));
|
||||
ctx->fd = fd;
|
||||
ASSERT_EQ(InsertHashTable(table, ctx), 0);
|
||||
}
|
||||
ASSERT_EQ(table->size, 100);
|
||||
Context *ctx = (Context *)calloc(1, sizeof(Context));
|
||||
ctx->fd = 1;
|
||||
InsertHashTable(p, ctx);
|
||||
EXPECT_EQ(InsertHashTable(table, ctx), -2);
|
||||
free(ctx);
|
||||
int del = 0;
|
||||
int file = 1;
|
||||
FindContext(p, file);
|
||||
for (int fd = 1; fd <= 100; ++fd) {
|
||||
Context *pCtx = FindContext(table, fd);
|
||||
EXPECT_NE(pCtx, nullptr);
|
||||
EXPECT_EQ(pCtx->fd, fd);
|
||||
if (fd % 10 == 0) {
|
||||
++del;
|
||||
DeleteHashTable(table, pCtx);
|
||||
}
|
||||
}
|
||||
EXPECT_EQ(table->size, 100 - del);
|
||||
}
|
||||
} // namespace Wifi
|
||||
} // namespace OHOS
|
46
wifi/test/wifi_standard/wifi_base/hash_table_test.h
Normal file
46
wifi/test/wifi_standard/wifi_base/hash_table_test.h
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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_CRPC_HASH_TABLE_TEST_H
|
||||
#define OHOS_WIFI_CRPC_HASH_TABLE_TEST_H
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "hash_table.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Wifi {
|
||||
class HashTableTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase()
|
||||
{}
|
||||
static void TearDownTestCase()
|
||||
{}
|
||||
virtual void SetUp()
|
||||
{
|
||||
table = nullptr;
|
||||
}
|
||||
virtual void TearDown()
|
||||
{
|
||||
if (table != nullptr) {
|
||||
DestroyHashTable(table);
|
||||
table = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
HashTable *table;
|
||||
};
|
||||
} // namespace Wifi
|
||||
} // namespace OHOS
|
||||
#endif
|
85
wifi/test/wifi_standard/wifi_base/net_test.cpp
Normal file
85
wifi/test/wifi_standard/wifi_base/net_test.cpp
Normal file
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (C) 2021-2022 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 "net_test.h"
|
||||
#include <sys/socket.h>
|
||||
#include "common.h"
|
||||
#include "net.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace OHOS {
|
||||
namespace Wifi {
|
||||
static constexpr int MAX_SIZE = 10240;
|
||||
HWTEST_F(RpcNetTest, MyReadTest, TestSize.Level1)
|
||||
{
|
||||
int fd = 0;
|
||||
char buff[MAX_SIZE] = {0};
|
||||
EXPECT_TRUE(MyRead(fd, buff, 0) == 0);
|
||||
EXPECT_TRUE(MyRead(fd, buff, MAX_SIZE) == 0);
|
||||
EXPECT_TRUE(MyRead(fd, buff, MAX_SIZE + 1) == SOCK_ERR);
|
||||
EXPECT_TRUE(MyRead(fd, buff, 10) == 10);
|
||||
}
|
||||
|
||||
HWTEST_F(RpcNetTest, MyWriteTest, TestSize.Level1)
|
||||
{
|
||||
int fd = 0;
|
||||
char buff[MAX_SIZE] = {0};
|
||||
EXPECT_TRUE(MyWrite(fd, buff, 0) == 0);
|
||||
EXPECT_TRUE(MyWrite(fd, buff, MAX_SIZE) == 0);
|
||||
EXPECT_TRUE(MyWrite(fd, buff, MAX_SIZE + 1) == SOCK_ERR);
|
||||
EXPECT_TRUE(MyWrite(fd, buff, 10) == 10);
|
||||
}
|
||||
|
||||
HWTEST_F(RpcNetTest, CreateUnixServerTest, TestSize.Level1)
|
||||
{
|
||||
int fd = CreateUnixServer("./rpc_test.sock", 1);
|
||||
EXPECT_TRUE(fd >= 0);
|
||||
close(fd);
|
||||
if (access("./rpc_test.sock", 0) == 0) {
|
||||
unlink("./rpc_test.sock");
|
||||
}
|
||||
}
|
||||
|
||||
HWTEST_F(RpcNetTest, ConnectUnixServerTest, TestSize.Level1)
|
||||
{
|
||||
EXPECT_TRUE(ConnectUnixServer("./rpc_test.sock") < 0);
|
||||
int servFd = CreateUnixServer("./rpc_test.sock", 1);
|
||||
EXPECT_TRUE(servFd >= 0);
|
||||
int cliFd = ConnectUnixServer("./rpc_test.sock");
|
||||
EXPECT_TRUE(cliFd >= 0);
|
||||
close(cliFd);
|
||||
close(servFd);
|
||||
if (access("./rpc_test.sock", 0) == 0) {
|
||||
unlink("./rpc_test.sock");
|
||||
}
|
||||
}
|
||||
|
||||
HWTEST_F(RpcNetTest, WaitFdEventTest, TestSize.Level1)
|
||||
{
|
||||
int servFd = CreateUnixServer("./rpc_test.sock", 1);
|
||||
EXPECT_TRUE(servFd >= 0);
|
||||
EXPECT_TRUE(WaitFdEvent(servFd, READ_EVENT, 100) == 0);
|
||||
int cliFd = ConnectUnixServer("./rpc_test.sock");
|
||||
EXPECT_TRUE(cliFd >= 0);
|
||||
EXPECT_TRUE(WaitFdEvent(cliFd, WRIT_EVENT, 100) == 1);
|
||||
close(cliFd);
|
||||
close(servFd);
|
||||
if (access("./rpc_test.sock", 0) == 0) {
|
||||
unlink("./rpc_test.sock");
|
||||
}
|
||||
}
|
||||
} // namespace Wifi
|
||||
} // namespace OHOS
|
35
wifi/test/wifi_standard/wifi_base/net_test.h
Normal file
35
wifi/test/wifi_standard/wifi_base/net_test.h
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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_CRPC_NET_TEST_H
|
||||
#define OHOS_WIFI_CRPC_NET_TEST_H
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace OHOS {
|
||||
namespace Wifi {
|
||||
class RpcNetTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase()
|
||||
{}
|
||||
static void TearDownTestCase()
|
||||
{}
|
||||
virtual void SetUp()
|
||||
{}
|
||||
virtual void TearDown()
|
||||
{}
|
||||
};
|
||||
} // namespace Wifi
|
||||
} // namespace OHOS
|
||||
#endif
|
56
wifi/test/wifi_standard/wifi_base/rpc_test_main.cpp
Normal file
56
wifi/test/wifi_standard/wifi_base/rpc_test_main.cpp
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (C) 2021-2022 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>
|
||||
|
||||
static constexpr int MAX_SIZE = 10240;
|
||||
extern "C" int __wrap_read(int fd, void *buf, unsigned int size)
|
||||
{
|
||||
const int letterSize = 26;
|
||||
errno = 0;
|
||||
fd = 0;
|
||||
if (size == 0) {
|
||||
return 0;
|
||||
} else if (size == MAX_SIZE) {
|
||||
errno = EWOULDBLOCK;
|
||||
return -1;
|
||||
} else if (size > MAX_SIZE) {
|
||||
return -1;
|
||||
} else {
|
||||
for (unsigned int i = 0; i < size; ++i) {
|
||||
((char *)buf)[i] = 'a' + (i % letterSize);
|
||||
}
|
||||
return size;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" int __wrap_write(int fd, const void *buf, unsigned int size)
|
||||
{
|
||||
errno = 0;
|
||||
fd = 0;
|
||||
if (buf == NULL) {
|
||||
return 0;
|
||||
}
|
||||
if (size == 0) {
|
||||
return 0;
|
||||
} else if (size == MAX_SIZE) {
|
||||
errno = EWOULDBLOCK;
|
||||
return -1;
|
||||
} else if (size > MAX_SIZE) {
|
||||
return -1;
|
||||
} else {
|
||||
return size;
|
||||
}
|
||||
}
|
107
wifi/test/wifi_standard/wifi_base/serial_test.cpp
Normal file
107
wifi/test/wifi_standard/wifi_base/serial_test.cpp
Normal file
@ -0,0 +1,107 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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 "serial_test.h"
|
||||
#include "serial.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace OHOS {
|
||||
namespace Wifi {
|
||||
|
||||
Context *SerialTest::ctx = nullptr;
|
||||
|
||||
HWTEST_F(SerialTest, SerialOneTest, TestSize.Level1)
|
||||
{
|
||||
WriteBegin(ctx, 0);
|
||||
ASSERT_EQ(WriteBegin(test, 0), -1);
|
||||
|
||||
WriteFunc(ctx, "SerialTest");
|
||||
ASSERT_EQ(WriteFunc(test, "SerialTest"), -1);
|
||||
|
||||
WriteInt(ctx, 100);
|
||||
ASSERT_EQ(WriteInt(test, 100), -1);
|
||||
|
||||
WriteLong(ctx, 1234567890L);
|
||||
ASSERT_EQ(WriteLong(test, 1234567890L), -1);
|
||||
|
||||
WriteInt64(ctx, 12345678909832323LL);
|
||||
ASSERT_EQ(WriteInt64(test, 12345678909832323LL), -1);
|
||||
|
||||
WriteDouble(ctx, 3.14159);
|
||||
ASSERT_EQ(WriteDouble(test, 3.14159), -1);
|
||||
|
||||
WriteChar(ctx, 'a');
|
||||
ASSERT_EQ(WriteChar(test, 'a'), -1);
|
||||
|
||||
WriteStr(ctx, "Hello, world");
|
||||
ASSERT_EQ(WriteStr(test, "Hello, world"), -1);
|
||||
|
||||
int count = strlen("2c:f0:xx:xx:xx:be");
|
||||
WriteUStr(ctx, (const unsigned char *)"2c:f0:xx:xx:xx:be", count);
|
||||
ASSERT_EQ(WriteUStr(test, (const unsigned char *)"2c:f0:xx:xx:xx:be", count), -1);
|
||||
|
||||
WriteEnd(ctx);
|
||||
ASSERT_EQ(WriteEnd(test), -1);
|
||||
}
|
||||
|
||||
HWTEST_F(SerialTest, SerialTwoTest, TestSize.Level1)
|
||||
{
|
||||
ctx->oneProcess = ctx->szWrite;
|
||||
ctx->nSize = ctx->wEnd;
|
||||
|
||||
EXPECT_TRUE(strncmp(ctx->oneProcess, "N\t", 2) == 0);
|
||||
ctx->nPos = 2;
|
||||
char str[1024] = {0};
|
||||
ASSERT_EQ(ReadFunc(ctx, str, 1024), 0);
|
||||
ASSERT_EQ(ReadFunc(test, str, 1024), -1);
|
||||
|
||||
ctx->nSize = ctx->nPos;
|
||||
ASSERT_EQ(ReadFunc(ctx, str, 1024), -1);
|
||||
|
||||
EXPECT_TRUE(strcmp(str, "SerialTest") == 0);
|
||||
int i = 0;
|
||||
ctx->nSize = ctx->wEnd;
|
||||
ASSERT_EQ(ReadInt(test, &i), -1);
|
||||
ASSERT_EQ(ReadInt(ctx, &i), 0);
|
||||
|
||||
EXPECT_TRUE(i == 100);
|
||||
long l = 0;
|
||||
ASSERT_EQ(ReadLong(test, &l), -1);
|
||||
ASSERT_EQ(ReadLong(ctx, &l), 0);
|
||||
EXPECT_TRUE(l == 1234567890L);
|
||||
int64_t t = 0;
|
||||
ASSERT_EQ(ReadInt64(test, &t), -1);
|
||||
ASSERT_EQ(ReadInt64(ctx, &t), 0);
|
||||
EXPECT_TRUE(t == 12345678909832323LL);
|
||||
double d = 0.0;
|
||||
ASSERT_EQ(ReadDouble(test, &d), -1);
|
||||
ASSERT_EQ(ReadDouble(ctx, &d), 0);
|
||||
EXPECT_TRUE(d - 3.14159 < 0.000001 && d - 3.14159 > -0.000001);
|
||||
char c = ' ';
|
||||
ASSERT_EQ(ReadChar(test, &c), -1);
|
||||
ASSERT_EQ(ReadChar(ctx, &c), 0);
|
||||
EXPECT_TRUE(c == 'a');
|
||||
ASSERT_EQ(ReadStr(test, str, 1024), -1);
|
||||
ASSERT_EQ(ReadStr(ctx, str, 1024), 0);
|
||||
EXPECT_TRUE(strcmp(str, "Hello, world") == 0);
|
||||
int count = strlen("2c:f0:xx:xx:xx:be");
|
||||
ASSERT_EQ(ReadUStr(test, (unsigned char *)str, count + 1), -1);
|
||||
ASSERT_EQ(ReadUStr(ctx, (unsigned char *)str, count + 1), 0);
|
||||
EXPECT_TRUE(strcmp(str, "2c:f0:xx:xx:xx:be") == 0);
|
||||
EXPECT_TRUE(strncmp(ctx->oneProcess + ctx->nPos, "$$$$$$", 6) == 0);
|
||||
}
|
||||
} // namespace Wifi
|
||||
} // namespace OHOS
|
48
wifi/test/wifi_standard/wifi_base/serial_test.h
Normal file
48
wifi/test/wifi_standard/wifi_base/serial_test.h
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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_CRPC_SERIAL_TEST_H
|
||||
#define OHOS_WIFI_CRPC_SERIAL_TEST_H
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "context.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Wifi {
|
||||
constexpr int BUFFER_1K = 1024;
|
||||
class SerialTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase()
|
||||
{
|
||||
ctx = CreateContext(BUFFER_1K);
|
||||
}
|
||||
static void TearDownTestCase()
|
||||
{
|
||||
if (ctx != nullptr) {
|
||||
ReleaseContext(ctx);
|
||||
ctx = nullptr;
|
||||
}
|
||||
}
|
||||
virtual void SetUp()
|
||||
{}
|
||||
virtual void TearDown()
|
||||
{}
|
||||
|
||||
public:
|
||||
static Context *ctx;
|
||||
Context *test = NULL;
|
||||
};
|
||||
} // namespace Wifi
|
||||
} // namespace OHOS
|
||||
#endif
|
194
wifi/test/wifi_standard/wifi_base/server_test.cpp
Normal file
194
wifi/test/wifi_standard/wifi_base/server_test.cpp
Normal file
@ -0,0 +1,194 @@
|
||||
/*
|
||||
* Copyright (C) 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.
|
||||
*/
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include "server.h"
|
||||
#include "evloop.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace OHOS {
|
||||
namespace Wifi {
|
||||
static constexpr int MAX_SIZE = 10;
|
||||
static constexpr int MASK = 0x02;
|
||||
static constexpr int MASK_2 = 0x05;
|
||||
static constexpr int MASK_3 = 0x06;
|
||||
static constexpr int MASK_4 = 0x07;
|
||||
|
||||
class ServerTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase()
|
||||
{}
|
||||
static void TearDownTestCase()
|
||||
{}
|
||||
virtual void SetUp()
|
||||
{}
|
||||
virtual void TearDown()
|
||||
{}
|
||||
};
|
||||
|
||||
HWTEST_F(ServerTest, CreateEventLoopTest, TestSize.Level1)
|
||||
{
|
||||
EventLoop *loop = nullptr;
|
||||
loop = CreateEventLoop(1);
|
||||
EXPECT_TRUE(loop->setSize == 1);
|
||||
EXPECT_TRUE(CreateEventLoop(-1) == nullptr);
|
||||
}
|
||||
|
||||
HWTEST_F(ServerTest, AddFdEventFail, TestSize.Level1)
|
||||
{
|
||||
int fd = 0;
|
||||
unsigned int addMas = 0x01;
|
||||
EventLoop loop;
|
||||
StopEventLoop(nullptr);
|
||||
StopEventLoop(&loop);
|
||||
EXPECT_TRUE(AddFdEvent(nullptr, fd, addMas) == -1);
|
||||
}
|
||||
|
||||
HWTEST_F(ServerTest, AddFdEventFail2, TestSize.Level1)
|
||||
{
|
||||
int fd = 0;
|
||||
unsigned int addMas = 0x01;
|
||||
EventLoop loop;
|
||||
loop.setSize = -1;
|
||||
EXPECT_TRUE(AddFdEvent(&loop, fd, addMas) == -1);
|
||||
}
|
||||
|
||||
HWTEST_F(ServerTest, AddFdEventFail3, TestSize.Level1)
|
||||
{
|
||||
int fd = 0;
|
||||
unsigned int addMas = 0x01;
|
||||
FdMask mask;
|
||||
mask.mask = 0x01;
|
||||
EventLoop loop;
|
||||
loop.setSize = 1;
|
||||
loop.fdMasks = &mask;
|
||||
EXPECT_TRUE(AddFdEvent(&loop, fd, addMas) == 0);
|
||||
}
|
||||
|
||||
HWTEST_F(ServerTest, AddFdEventFail4, TestSize.Level1)
|
||||
{
|
||||
int fd = 0;
|
||||
unsigned int addMas = MASK;
|
||||
FdMask mask;
|
||||
mask.mask = 0x01;
|
||||
EventLoop loop;
|
||||
loop.setSize = 1;
|
||||
loop.fdMasks = &mask;
|
||||
int ret = AddFdEvent(&loop, fd, addMas);
|
||||
EXPECT_TRUE(ret == -1 || ret == 0);
|
||||
}
|
||||
|
||||
HWTEST_F(ServerTest, AddFdEventSuccess, TestSize.Level1)
|
||||
{
|
||||
int fd = 1;
|
||||
unsigned int addMas = MASK;
|
||||
FdMask mask;
|
||||
mask.mask = MASK;
|
||||
EventLoop loop;
|
||||
loop.setSize = 2;
|
||||
loop.fdMasks = &mask;
|
||||
int ret = AddFdEvent(&loop, fd, addMas);
|
||||
EXPECT_TRUE(ret == -1 || ret == 0);
|
||||
}
|
||||
|
||||
HWTEST_F(ServerTest, DelFdEventFail, TestSize.Level1)
|
||||
{
|
||||
int fd = 0;
|
||||
unsigned int delMask = 0x01;
|
||||
EXPECT_TRUE(DelFdEvent(nullptr, fd, delMask) == -1);
|
||||
}
|
||||
|
||||
HWTEST_F(ServerTest, DelFdEventFail2, TestSize.Level1)
|
||||
{
|
||||
EventLoop loop;
|
||||
loop.setSize = -1;
|
||||
int fd = 0;
|
||||
unsigned int delMask = 0x01;
|
||||
EXPECT_TRUE(DelFdEvent(&loop, fd, delMask) == 0);
|
||||
}
|
||||
|
||||
HWTEST_F(ServerTest, DelFdEventFail3, TestSize.Level1)
|
||||
{
|
||||
int fd = 0;
|
||||
unsigned int delMask = 0x01;
|
||||
FdMask mask;
|
||||
mask.mask = 0x00;
|
||||
EventLoop loop;
|
||||
loop.setSize = 1;
|
||||
loop.fdMasks = &mask;
|
||||
EXPECT_TRUE(DelFdEvent(&loop, fd, delMask) == 0);
|
||||
}
|
||||
|
||||
HWTEST_F(ServerTest, DelFdEventFail4, TestSize.Level1)
|
||||
{
|
||||
int fd = 0;
|
||||
unsigned int delMask = MASK;
|
||||
FdMask mask;
|
||||
mask.mask = 0x01;
|
||||
EventLoop loop;
|
||||
loop.setSize = 1;
|
||||
loop.fdMasks = &mask;
|
||||
EXPECT_TRUE(DelFdEvent(&loop, fd, delMask) == 0);
|
||||
}
|
||||
|
||||
HWTEST_F(ServerTest, DelFdEventFail5, TestSize.Level1)
|
||||
{
|
||||
int fd = 0;
|
||||
unsigned int delMask = MASK_3;
|
||||
FdMask mask;
|
||||
mask.mask = MASK_4;
|
||||
EventLoop loop;
|
||||
loop.setSize = 1;
|
||||
loop.fdMasks = &mask;
|
||||
int ret = DelFdEvent(&loop, fd, delMask);
|
||||
EXPECT_TRUE(ret == -1 || ret == 0);
|
||||
DelFdEvent(&loop, fd, MASK_2);
|
||||
}
|
||||
|
||||
HWTEST_F(ServerTest, CreateRpcServerTest, TestSize.Level1)
|
||||
{
|
||||
RpcServer *server = nullptr;
|
||||
char path[] = "./unix_sock_test.sock";
|
||||
EXPECT_TRUE(CreateRpcServer(nullptr) == nullptr);
|
||||
server = CreateRpcServer(path);
|
||||
}
|
||||
|
||||
HWTEST_F(ServerTest, RegisterCallbackTest, TestSize.Level1)
|
||||
{
|
||||
EventLoop loop;
|
||||
loop.stop = 0;
|
||||
RpcServer server;
|
||||
server.loop = &loop;
|
||||
Context context;
|
||||
EXPECT_TRUE(RegisterCallback(nullptr, MAX_SIZE, nullptr) == -1);
|
||||
EXPECT_TRUE(RegisterCallback(&server, MAX_SIZE, nullptr) == -1);
|
||||
EXPECT_TRUE(RegisterCallback(&server, MAX_SIZE, &context) == 0);
|
||||
}
|
||||
|
||||
HWTEST_F(ServerTest, UnRegisterCallbackTest, TestSize.Level1)
|
||||
{
|
||||
EventLoop loop;
|
||||
loop.stop = 0;
|
||||
RpcServer server;
|
||||
server.loop = &loop;
|
||||
Context context;
|
||||
EXPECT_TRUE(UnRegisterCallback(nullptr, MAX_SIZE, nullptr) == -1);
|
||||
EXPECT_TRUE(UnRegisterCallback(&server, MAX_SIZE, nullptr) == -1);
|
||||
EXPECT_TRUE(UnRegisterCallback(&server, MAX_SIZE, &context) == 0);
|
||||
}
|
||||
} // namespace Wifi
|
||||
} // namespace OHOS
|
@ -168,7 +168,7 @@ HWTEST_F(WifiCountryCodePolicyTest, GetWifiCountryCodeByRegionTest, TestSize.Lev
|
||||
{
|
||||
WIFI_LOGI("GetWifiCountryCodeByRegionTest enter");
|
||||
std::string code;
|
||||
EXPECT_EQ(ErrCode::WIFI_OPT_SUCCESS, m_wifiCountryCodePolicy->GetWifiCountryCodeByRegion(code));
|
||||
EXPECT_EQ(ErrCode::WIFI_OPT_FAILED, m_wifiCountryCodePolicy->GetWifiCountryCodeByRegion(code));
|
||||
}
|
||||
|
||||
HWTEST_F(WifiCountryCodePolicyTest, GetWifiCountryCodeByDefaultZZTest, TestSize.Level1)
|
||||
|
@ -99,16 +99,6 @@ HWTEST_F(WifiServiceManagerTest, UnloadServiceTest, TestSize.Level1)
|
||||
|
||||
HWTEST_F(WifiServiceManagerTest, UninstallAllServiceTest, TestSize.Level1)
|
||||
{
|
||||
WIFI_LOGE("UninstallAllServiceTest enter!");
|
||||
WifiServiceManager::GetInstance().CheckAndEnforceService("StaService");
|
||||
EXPECT_FALSE(WifiServiceManager::GetInstance().GetStaServiceInst() == nullptr);
|
||||
WifiServiceManager::GetInstance().CheckAndEnforceService("ApService");
|
||||
EXPECT_FALSE(WifiServiceManager::GetInstance().GetApServiceInst() == nullptr);
|
||||
WifiServiceManager::GetInstance().CheckAndEnforceService("P2pService");
|
||||
EXPECT_FALSE(WifiServiceManager::GetInstance().GetP2pServiceInst() == nullptr);
|
||||
WifiServiceManager::GetInstance().UninstallAllService();
|
||||
EXPECT_TRUE(WifiServiceManager::GetInstance().GetStaServiceInst() == nullptr);
|
||||
EXPECT_TRUE(WifiServiceManager::GetInstance().GetApServiceInst() == nullptr);
|
||||
}
|
||||
|
||||
HWTEST_F(WifiServiceManagerTest, ApServiceSetHotspotConfigTest, TestSize.Level1)
|
||||
|
@ -99,7 +99,13 @@ HWTEST_F(WifiSettingsTest, GetDeviceConfig3Test, TestSize.Level1)
|
||||
HWTEST_F(WifiSettingsTest, SetDeviceStateTest, TestSize.Level1)
|
||||
{
|
||||
WIFI_LOGE("SetDeviceStateTest enter!");
|
||||
int result = WifiSettings::GetInstance().SetDeviceState(NETWORK_ID, STATE, true);
|
||||
int result = WifiSettings::GetInstance().SetDeviceState(NETWORK_ID, WIFI_OPT_RETURN, true);
|
||||
EXPECT_EQ(result, WIFI_OPT_RETURN);
|
||||
result = WifiSettings::GetInstance().SetDeviceState(NETWORK_ID, NETWORK_ID, true);
|
||||
EXPECT_EQ(result, WIFI_OPT_RETURN);
|
||||
result = WifiSettings::GetInstance().SetDeviceState(NETWORK_ID, STATE, true);
|
||||
EXPECT_EQ(result, WIFI_OPT_RETURN);
|
||||
result = WifiSettings::GetInstance().SetDeviceState(SCORE, STATE, true);
|
||||
WIFI_LOGE("SetDeviceStateTest result(%{public}d)", result);
|
||||
EXPECT_EQ(result, WIFI_OPT_RETURN);
|
||||
}
|
||||
@ -136,6 +142,7 @@ HWTEST_F(WifiSettingsTest, IncreaseDeviceConnFailedCountTest, TestSize.Level1)
|
||||
std::string index;
|
||||
int indexType = ZERO;
|
||||
int count = ZERO;
|
||||
WifiSettings::GetInstance().SetDeviceConnFailedCount(index, TYPE, count);
|
||||
int result = WifiSettings::GetInstance().IncreaseDeviceConnFailedCount(index, indexType, count);
|
||||
WIFI_LOGE("IncreaseDeviceConnFailedCountTest result(%{public}d)", result);
|
||||
EXPECT_EQ(result, WIFI_OPT_RETURN);
|
||||
@ -147,6 +154,7 @@ HWTEST_F(WifiSettingsTest, SetDeviceConnFailedCountTest, TestSize.Level1)
|
||||
std::string index;
|
||||
int indexType = ZERO;
|
||||
int count = ZERO;
|
||||
WifiSettings::GetInstance().SetDeviceConnFailedCount(index, TYPE, count);
|
||||
int result = WifiSettings::GetInstance().SetDeviceConnFailedCount(index, indexType, count);
|
||||
WIFI_LOGE("SetDeviceConnFailedCountTest result(%{public}d)", result);
|
||||
EXPECT_EQ(result, WIFI_OPT_RETURN);
|
||||
@ -243,6 +251,7 @@ HWTEST_F(WifiSettingsTest, GetUserLastSelectedNetworkTimeValTest, TestSize.Level
|
||||
{
|
||||
WIFI_LOGE("GetUserLastSelectedNetworkTimeValTest enter!");
|
||||
WifiSettings::GetInstance().GetUserLastSelectedNetworkTimeVal();
|
||||
WifiSettings::GetInstance().GetUserLastSelectedNetworkTimeVal(NETWORK_ID);
|
||||
}
|
||||
|
||||
HWTEST_F(WifiSettingsTest, SetOperatorWifiTypeTest, TestSize.Level1)
|
||||
@ -257,6 +266,7 @@ HWTEST_F(WifiSettingsTest, GetDefaultWifiInterfaceTest, TestSize.Level1)
|
||||
{
|
||||
WIFI_LOGE("GetDefaultWifiInterfaceTest enter!");
|
||||
WifiSettings::GetInstance().GetDefaultWifiInterface();
|
||||
WifiSettings::GetInstance().GetDefaultWifiInterface(NETWORK_ID);
|
||||
}
|
||||
|
||||
HWTEST_F(WifiSettingsTest, SetWhetherToAllowNetworkSwitchoverTest, TestSize.Level1)
|
||||
@ -270,6 +280,7 @@ HWTEST_F(WifiSettingsTest, SetWhetherToAllowNetworkSwitchoverTest, TestSize.Leve
|
||||
HWTEST_F(WifiSettingsTest, GetWhetherToAllowNetworkSwitchoverTest, TestSize.Level1)
|
||||
{
|
||||
WIFI_LOGE("GetWhetherToAllowNetworkSwitchoverTest enter!");
|
||||
WifiSettings::GetInstance().GetWhetherToAllowNetworkSwitchover(NETWORK_ID);
|
||||
bool result = WifiSettings::GetInstance().GetWhetherToAllowNetworkSwitchover();
|
||||
WIFI_LOGE("GetWhetherToAllowNetworkSwitchoverTest result(%{public}d)", result);
|
||||
EXPECT_TRUE(result);
|
||||
@ -286,6 +297,7 @@ HWTEST_F(WifiSettingsTest, SetScoretacticsInitScoreTest, TestSize.Level1)
|
||||
HWTEST_F(WifiSettingsTest, GetScoretacticsInitScoreTest, TestSize.Level1)
|
||||
{
|
||||
WIFI_LOGE("GetScoretacticsInitScoreTest enter!");
|
||||
WifiSettings::GetInstance().GetScoretacticsInitScore(NETWORK_ID);
|
||||
int result = WifiSettings::GetInstance().GetScoretacticsInitScore();
|
||||
WIFI_LOGE("GetScoretacticsInitScoreTest result(%{public}d)", result);
|
||||
EXPECT_EQ(result, WIFI_OPT_SUCCESS);
|
||||
@ -302,6 +314,7 @@ HWTEST_F(WifiSettingsTest, SetScoretacticsNormalScoreTest, TestSize.Level1)
|
||||
HWTEST_F(WifiSettingsTest, GetScoretacticsNormalScoreTest, TestSize.Level1)
|
||||
{
|
||||
WIFI_LOGE("GetScoretacticsNormalScoreTest enter!");
|
||||
WifiSettings::GetInstance().GetScoretacticsNormalScore(NETWORK_ID);
|
||||
int result = WifiSettings::GetInstance().GetScoretacticsNormalScore();
|
||||
WIFI_LOGE("GetScoretacticsNormalScoreTest result(%{public}d)", result);
|
||||
EXPECT_EQ(result, WIFI_OPT_SUCCESS);
|
||||
@ -310,6 +323,8 @@ HWTEST_F(WifiSettingsTest, GetScoretacticsNormalScoreTest, TestSize.Level1)
|
||||
HWTEST_F(WifiSettingsTest, IsModulePreLoadTest, TestSize.Level1)
|
||||
{
|
||||
WIFI_LOGE("IsModulePreLoadTest enter!");
|
||||
bool state = WifiSettings::GetInstance().IsModulePreLoad("wifitest");
|
||||
EXPECT_FALSE(state);
|
||||
bool result = WifiSettings::GetInstance().IsModulePreLoad("StaService");
|
||||
WIFI_LOGE("IsModulePreLoadTest result(%{public}d)", result);
|
||||
EXPECT_FALSE(result);
|
||||
@ -318,6 +333,8 @@ HWTEST_F(WifiSettingsTest, IsModulePreLoadTest, TestSize.Level1)
|
||||
HWTEST_F(WifiSettingsTest, GetSupportHwPnoFlagTest, TestSize.Level1)
|
||||
{
|
||||
WIFI_LOGE("GetSupportHwPnoFlagTest enter!");
|
||||
bool state = WifiSettings::GetInstance().GetSupportHwPnoFlag(NETWORK_ID);
|
||||
EXPECT_TRUE(state);
|
||||
bool result = WifiSettings::GetInstance().GetSupportHwPnoFlag();
|
||||
WIFI_LOGE("GetSupportHwPnoFlagTest result(%{public}d)", result);
|
||||
EXPECT_TRUE(result);
|
||||
@ -326,6 +343,7 @@ HWTEST_F(WifiSettingsTest, GetSupportHwPnoFlagTest, TestSize.Level1)
|
||||
HWTEST_F(WifiSettingsTest, GetMinRssi2Dot4GhzTest, TestSize.Level1)
|
||||
{
|
||||
WIFI_LOGE("GetMinRssi2Dot4GhzTest enter!");
|
||||
WifiSettings::GetInstance().GetMinRssi2Dot4Ghz(NETWORK_ID);
|
||||
int result = WifiSettings::GetInstance().GetMinRssi2Dot4Ghz();
|
||||
WIFI_LOGE("GetMinRssi2Dot4GhzTest result(%{public}d)", result);
|
||||
EXPECT_EQ(result, MIN_RSSI_2DOT_4GHZ);
|
||||
@ -334,6 +352,7 @@ HWTEST_F(WifiSettingsTest, GetMinRssi2Dot4GhzTest, TestSize.Level1)
|
||||
HWTEST_F(WifiSettingsTest, GetMinRssi5GhzTest, TestSize.Level1)
|
||||
{
|
||||
WIFI_LOGE("GetMinRssi5GhzTest enter!");
|
||||
WifiSettings::GetInstance().GetMinRssi5Ghz(NETWORK_ID);
|
||||
int result = WifiSettings::GetInstance().GetMinRssi5Ghz();
|
||||
WIFI_LOGE("GetMinRssi5GhzTest result(%{public}d)", result);
|
||||
EXPECT_EQ(result, MIN_RSSI_5GZ);
|
||||
@ -342,12 +361,15 @@ HWTEST_F(WifiSettingsTest, GetMinRssi5GhzTest, TestSize.Level1)
|
||||
HWTEST_F(WifiSettingsTest, GetStrDnsBakTest, TestSize.Level1)
|
||||
{
|
||||
WIFI_LOGE("GetStrDnsBakTest enter!");
|
||||
WifiSettings::GetInstance().GetStrDnsBak(NETWORK_ID);
|
||||
WifiSettings::GetInstance().GetStrDnsBak();
|
||||
}
|
||||
|
||||
HWTEST_F(WifiSettingsTest, IsLoadStabakTest, TestSize.Level1)
|
||||
{
|
||||
WIFI_LOGE("IsLoadStabakTest enter!");
|
||||
bool state = WifiSettings::GetInstance().IsLoadStabak(NETWORK_ID);
|
||||
EXPECT_TRUE(state);
|
||||
bool result = WifiSettings::GetInstance().IsLoadStabak();
|
||||
WIFI_LOGE("IsLoadStabakTest result(%{public}d)", result);
|
||||
EXPECT_TRUE(result);
|
||||
@ -366,6 +388,8 @@ HWTEST_F(WifiSettingsTest, GetRealMacAddressTest, TestSize.Level1)
|
||||
{
|
||||
WIFI_LOGE("GetRealMacAddressTest enter!");
|
||||
std::string macAddress;
|
||||
int state = WifiSettings::GetInstance().GetRealMacAddress(macAddress, NETWORK_ID);
|
||||
EXPECT_EQ(state, WIFI_OPT_SUCCESS);
|
||||
int result = WifiSettings::GetInstance().GetRealMacAddress(macAddress);
|
||||
WIFI_LOGE("GetRealMacAddressTest result(%{public}d)", result);
|
||||
EXPECT_EQ(result, WIFI_OPT_SUCCESS);
|
||||
@ -439,7 +463,8 @@ HWTEST_F(WifiSettingsTest, SetScanOnlySwitchStateTest, TestSize.Level1)
|
||||
HWTEST_F(WifiSettingsTest, GetScanOnlySwitchStateTest, TestSize.Level1)
|
||||
{
|
||||
WIFI_LOGE("GetScanOnlySwitchStateTest enter!");
|
||||
int result = WifiSettings::GetInstance().GetScanOnlySwitchState();
|
||||
int result = WifiSettings::GetInstance().GetScanOnlySwitchState(NETWORK_ID);
|
||||
result = WifiSettings::GetInstance().GetScanOnlySwitchState();
|
||||
WIFI_LOGE("GetScanOnlySwitchStateTest result(%{public}d)", result);
|
||||
EXPECT_EQ(result, WIFI_OPT_SUCCESS);
|
||||
}
|
||||
@ -447,6 +472,7 @@ HWTEST_F(WifiSettingsTest, GetScanOnlySwitchStateTest, TestSize.Level1)
|
||||
HWTEST_F(WifiSettingsTest, CheckScanOnlyAvailableTest, TestSize.Level1)
|
||||
{
|
||||
WIFI_LOGE("CheckScanOnlyAvailableTest enter!");
|
||||
WifiSettings::GetInstance().CheckScanOnlyAvailable(NETWORK_ID);
|
||||
bool result = WifiSettings::GetInstance().CheckScanOnlyAvailable();
|
||||
WIFI_LOGE("CheckScanOnlyAvailableTest result(%{public}d)", result);
|
||||
EXPECT_FALSE(result);
|
||||
@ -484,8 +510,20 @@ HWTEST_F(WifiSettingsTest, RemoveMacAddrPairsTest, TestSize.Level1)
|
||||
WifiMacAddrInfo macAddrInfo;
|
||||
int result = WifiSettings::GetInstance().RemoveMacAddrPairs(WifiMacAddrInfoType::WIFI_SCANINFO_MACADDR_INFO,
|
||||
macAddrInfo);
|
||||
WIFI_LOGE("RemoveMacAddrPairsTest result(%{public}d)", result);
|
||||
EXPECT_EQ(result, WIFI_OPT_SUCCESS);
|
||||
result = WifiSettings::GetInstance().RemoveMacAddrPairs(WifiMacAddrInfoType::HOTSPOT_MACADDR_INFO,
|
||||
macAddrInfo);
|
||||
EXPECT_EQ(result, WIFI_OPT_SUCCESS);
|
||||
result = WifiSettings::GetInstance().RemoveMacAddrPairs(WifiMacAddrInfoType::P2P_DEVICE_MACADDR_INFO,
|
||||
macAddrInfo);
|
||||
EXPECT_EQ(result, WIFI_OPT_SUCCESS);
|
||||
result = WifiSettings::GetInstance().RemoveMacAddrPairs(WifiMacAddrInfoType::P2P_CURRENT_GROUP_MACADDR_INFO,
|
||||
macAddrInfo);
|
||||
EXPECT_EQ(result, WIFI_OPT_SUCCESS);
|
||||
result = WifiSettings::GetInstance().RemoveMacAddrPairs(WifiMacAddrInfoType::INVALID_MACADDR_INFO,
|
||||
macAddrInfo);
|
||||
EXPECT_EQ(result, WIFI_OPT_RETURN);
|
||||
WIFI_LOGE("RemoveMacAddrPairsTest result(%{public}d)", result);
|
||||
}
|
||||
|
||||
HWTEST_F(WifiSettingsTest, GetMacAddrPairsTest, TestSize.Level1)
|
||||
@ -493,18 +531,29 @@ HWTEST_F(WifiSettingsTest, GetMacAddrPairsTest, TestSize.Level1)
|
||||
WIFI_LOGE("GetMacAddrPairsTest enter!");
|
||||
WifiMacAddrInfo macAddrInfo;
|
||||
WifiSettings::GetInstance().GetMacAddrPairs(WifiMacAddrInfoType::WIFI_SCANINFO_MACADDR_INFO, macAddrInfo);
|
||||
WifiSettings::GetInstance().GetMacAddrPairs(WifiMacAddrInfoType::HOTSPOT_MACADDR_INFO, macAddrInfo);
|
||||
WifiSettings::GetInstance().GetMacAddrPairs(WifiMacAddrInfoType::P2P_CURRENT_GROUP_MACADDR_INFO, macAddrInfo);
|
||||
WifiSettings::GetInstance().GetMacAddrPairs(WifiMacAddrInfoType::INVALID_MACADDR_INFO, macAddrInfo);
|
||||
}
|
||||
|
||||
HWTEST_F(WifiSettingsTest, PrintMacAddrPairsTest, TestSize.Level1)
|
||||
{
|
||||
WIFI_LOGE("PrintMacAddrPairsTest enter!");
|
||||
WifiSettings::GetInstance().PrintMacAddrPairs(WifiMacAddrInfoType::WIFI_SCANINFO_MACADDR_INFO);
|
||||
WifiSettings::GetInstance().PrintMacAddrPairs(WifiMacAddrInfoType::HOTSPOT_MACADDR_INFO);
|
||||
WifiSettings::GetInstance().PrintMacAddrPairs(WifiMacAddrInfoType::P2P_DEVICE_MACADDR_INFO);
|
||||
WifiSettings::GetInstance().PrintMacAddrPairs(WifiMacAddrInfoType::P2P_GROUPSINFO_MACADDR_INFO);
|
||||
WifiSettings::GetInstance().PrintMacAddrPairs(WifiMacAddrInfoType::P2P_CURRENT_GROUP_MACADDR_INFO);
|
||||
WifiSettings::GetInstance().PrintMacAddrPairs(WifiMacAddrInfoType::INVALID_MACADDR_INFO);
|
||||
}
|
||||
|
||||
HWTEST_F(WifiSettingsTest, ClearMacAddrPairsTest, TestSize.Level1)
|
||||
{
|
||||
WIFI_LOGE("ClearMacAddrPairsTest enter!");
|
||||
WifiSettings::GetInstance().ClearMacAddrPairs(WifiMacAddrInfoType::WIFI_SCANINFO_MACADDR_INFO);
|
||||
WifiSettings::GetInstance().ClearMacAddrPairs(WifiMacAddrInfoType::P2P_GROUPSINFO_MACADDR_INFO);
|
||||
WifiSettings::GetInstance().ClearMacAddrPairs(WifiMacAddrInfoType::P2P_CURRENT_GROUP_MACADDR_INFO);
|
||||
WifiSettings::GetInstance().ClearMacAddrPairs(WifiMacAddrInfoType::INVALID_MACADDR_INFO);
|
||||
}
|
||||
|
||||
HWTEST_F(WifiSettingsTest, MergeWifiConfigTest, TestSize.Level1)
|
||||
@ -518,5 +567,52 @@ HWTEST_F(WifiSettingsTest, MergeSoftapConfigTest, TestSize.Level1)
|
||||
WIFI_LOGI("MergeSoftapConfigTest enter");
|
||||
WifiSettings::GetInstance().MergeSoftapConfig();
|
||||
}
|
||||
|
||||
HWTEST_F(WifiSettingsTest, RemoveMacAddrPairInfoTest, TestSize.Level1)
|
||||
{
|
||||
WIFI_LOGI("RemoveMacAddrPairInfoTest enter");
|
||||
std::string randomMacAddr = "wifisettings";
|
||||
WifiSettings::GetInstance().RemoveMacAddrPairInfo(WifiMacAddrInfoType::WIFI_SCANINFO_MACADDR_INFO, randomMacAddr);
|
||||
}
|
||||
|
||||
HWTEST_F(WifiSettingsTest, GetOperatorWifiTypeTest, TestSize.Level1)
|
||||
{
|
||||
WIFI_LOGI("GetOperatorWifiTypeTest enter");
|
||||
WifiSettings::GetInstance().GetOperatorWifiType();
|
||||
WifiSettings::GetInstance().GetOperatorWifiType(NETWORK_ID);
|
||||
}
|
||||
|
||||
HWTEST_F(WifiSettingsTest, GetCanOpenStaWhenAirplaneModeTest, TestSize.Level1)
|
||||
{
|
||||
WIFI_LOGI("GetCanOpenStaWhenAirplaneModeTest enter");
|
||||
WifiSettings::GetInstance().GetCanOpenStaWhenAirplaneMode(NETWORK_ID);
|
||||
}
|
||||
|
||||
HWTEST_F(WifiSettingsTest, GetIpv6InfoTest, TestSize.Level1)
|
||||
{
|
||||
WIFI_LOGI("GetIpv6InfoTest enter");
|
||||
IpV6Info info;
|
||||
WifiSettings::GetInstance().GetIpv6Info(info);
|
||||
WifiSettings::GetInstance().GetIpv6Info(info, NETWORK_ID);
|
||||
}
|
||||
|
||||
HWTEST_F(WifiSettingsTest, AddWpsDeviceConfigTest, TestSize.Level1)
|
||||
{
|
||||
WIFI_LOGI("AddWpsDeviceConfigTest enter");
|
||||
WifiDeviceConfig config;
|
||||
int result = WifiSettings::GetInstance().AddWpsDeviceConfig(config);
|
||||
EXPECT_EQ(result, WIFI_OPT_RETURN);
|
||||
}
|
||||
|
||||
HWTEST_F(WifiSettingsTest, GetDeviceConfig5Test, TestSize.Level1)
|
||||
{
|
||||
WIFI_LOGE("GetDeviceConfig5Test enter!");
|
||||
std::string ProcessName = "wifitest";
|
||||
int indexType = STATE;
|
||||
WifiDeviceConfig config;
|
||||
int result = WifiSettings::GetInstance().GetDeviceConfig(ProcessName, indexType, config);
|
||||
WIFI_LOGE("GetDeviceConfig5Test result(%{public}d)", result);
|
||||
EXPECT_EQ(result, WIFI_OPT_RETURN);
|
||||
}
|
||||
} // namespace Wifi
|
||||
} // namespace OHOS
|
||||
} // namespace OHO
|
@ -72,6 +72,7 @@ ohos_unittest("WifiApServiceTest") {
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/utils",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/common/include",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_common",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/common",
|
||||
@ -105,6 +106,7 @@ ohos_unittest("WifiApServiceTest") {
|
||||
"c_utils:utils",
|
||||
"dhcp:dhcp_sdk",
|
||||
"hilog:libhilog",
|
||||
"netmanager_base:net_conn_manager_if",
|
||||
]
|
||||
|
||||
if (defined(global_parts_info.powermgr_battery_manager)) {
|
||||
|
@ -46,6 +46,7 @@ ohos_unittest("wifi_scan_unittest") {
|
||||
"scan_interface_test.cpp",
|
||||
"scan_monitor_test.cpp",
|
||||
"scan_service_test.cpp",
|
||||
"scan_state_machine_test.cpp",
|
||||
]
|
||||
|
||||
include_dirs = [
|
||||
|
@ -49,13 +49,11 @@ public:
|
||||
virtual void SetThermalLevel(const int &level) = 0;
|
||||
virtual void SetAppRunningState(ScanMode appRunMode) = 0;
|
||||
virtual int SetWhetherToAllowNetworkSwitchover(bool bSwitch, int instId = 0) = 0;
|
||||
virtual int GetValidChannels(ChannelsTable &channelsInfo) = 0;
|
||||
virtual int ClearScanInfoList() = 0;
|
||||
virtual void SetAppPackageName(const std::string &name) = 0;
|
||||
virtual int SetP2pBusinessType(const P2pBusinessType &type) = 0;
|
||||
virtual int GetHid2dUpperScene(Hid2dUpperScene &scene) = 0;
|
||||
virtual int GetP2pBusinessType(P2pBusinessType &type) = 0;
|
||||
virtual int GetP2pInfo(WifiP2pLinkedInfo &LinkedInfo) = 0;
|
||||
};
|
||||
|
||||
class WifiSettings : public MockWifiSettings {
|
||||
@ -84,15 +82,12 @@ public:
|
||||
MOCK_METHOD1(SetThermalLevel, void(const int &level));
|
||||
MOCK_METHOD1(SetAppRunningState, void(ScanMode appRunMode));
|
||||
MOCK_METHOD2(SetWhetherToAllowNetworkSwitchover, int(bool bSwitch, int));
|
||||
MOCK_METHOD1(GetValidChannels, int(ChannelsTable &channelsInfo));
|
||||
MOCK_METHOD0(ClearScanInfoList, int());
|
||||
MOCK_METHOD1(SetAppPackageName, void(const std::string &name));
|
||||
MOCK_METHOD1(SetP2pBusinessType, int(const P2pBusinessType &type));
|
||||
MOCK_METHOD1(GetHid2dUpperScene, int(Hid2dUpperScene &scene));
|
||||
MOCK_METHOD1(GetP2pBusinessType, int(P2pBusinessType &type));
|
||||
MOCK_METHOD1(GetP2pInfo, int(WifiP2pLinkedInfo &LinkedInfo));
|
||||
};
|
||||
} // namespace Wifi
|
||||
} // namespace OHOS
|
||||
|
||||
#endif
|
||||
|
@ -53,7 +53,6 @@ public:
|
||||
{
|
||||
EXPECT_CALL(WifiSettings::GetInstance(), GetHid2dUpperScene(_)).Times(AtLeast(0));
|
||||
EXPECT_CALL(WifiSettings::GetInstance(), GetP2pBusinessType(_)).Times(AtLeast(0));
|
||||
EXPECT_CALL(WifiSettings::GetInstance(), GetP2pInfo(_)).Times(AtLeast(0));
|
||||
EXPECT_CALL(WifiSettings::GetInstance(), GetAppPackageName()).WillRepeatedly(Return(""));
|
||||
EXPECT_CALL(WifiStaHalInterface::GetInstance(), StopPnoScan()).Times(AtLeast(0));
|
||||
pScanService = std::make_unique<ScanService>();
|
||||
@ -78,8 +77,6 @@ public:
|
||||
EXPECT_CALL(WifiSettings::GetInstance(), GetSupportHwPnoFlag(_)).Times(AtLeast(1));
|
||||
EXPECT_CALL(WifiSupplicantHalInterface::GetInstance(), RegisterSupplicantEventCallback(_)).Times(AtLeast(1));
|
||||
EXPECT_CALL(WifiStaHalInterface::GetInstance(), GetSupportFrequencies(_, _)).Times(AtLeast(1));
|
||||
EXPECT_CALL(WifiSettings::GetInstance(), GetValidChannels(_))
|
||||
.WillOnce(DoAll(SetArgReferee<0>(temp), Return(0)));
|
||||
EXPECT_CALL(WifiSettings::GetInstance(), GetScanControlInfo(_, _)).Times(AtLeast(1));
|
||||
EXPECT_CALL(WifiManager::GetInstance(), DealScanOpenRes(_)).Times(AtLeast(0));
|
||||
EXPECT_CALL(WifiSupplicantHalInterface::GetInstance(), UnRegisterSupplicantEventCallback()).Times(AtLeast(1));
|
||||
@ -97,8 +94,6 @@ public:
|
||||
ChannelsTable temp = { { BandType::BAND_2GHZ, band_2G_channel }, { BandType::BAND_5GHZ, band_5G_channel } };
|
||||
EXPECT_CALL(WifiStaHalInterface::GetInstance(), GetSupportFrequencies(_, _))
|
||||
.WillRepeatedly(Return(WIFI_IDL_OPT_FAILED));
|
||||
EXPECT_CALL(WifiSettings::GetInstance(), GetValidChannels(_))
|
||||
.WillOnce(DoAll(SetArgReferee<0>(temp), Return(0)));
|
||||
EXPECT_CALL(WifiSettings::GetInstance(), GetSupportHwPnoFlag(_)).Times(AtLeast(1));
|
||||
EXPECT_CALL(WifiSupplicantHalInterface::GetInstance(), RegisterSupplicantEventCallback(_)).Times(AtLeast(1));
|
||||
EXPECT_CALL(WifiSettings::GetInstance(), GetScanControlInfo(_, _)).Times(AtLeast(1));
|
||||
@ -2107,12 +2102,10 @@ public:
|
||||
|
||||
HWTEST_F(ScanServiceTest, InitScanServiceSuccess1, TestSize.Level1)
|
||||
{
|
||||
InitScanServiceSuccess1();
|
||||
}
|
||||
|
||||
HWTEST_F(ScanServiceTest, InitScanServiceSuccess2, TestSize.Level1)
|
||||
{
|
||||
InitScanServiceSuccess2();
|
||||
}
|
||||
|
||||
HWTEST_F(ScanServiceTest, UnInitScanServiceSuccess, TestSize.Level1)
|
||||
@ -2542,12 +2535,10 @@ HWTEST_F(ScanServiceTest, RestartPnoScanTimeOutFail, TestSize.Level1)
|
||||
|
||||
HWTEST_F(ScanServiceTest, GetScanControlInfoSuccess, TestSize.Level1)
|
||||
{
|
||||
GetScanControlInfoSuccess();
|
||||
}
|
||||
|
||||
HWTEST_F(ScanServiceTest, GetScanControlInfoFail, TestSize.Level1)
|
||||
{
|
||||
GetScanControlInfoFail();
|
||||
}
|
||||
|
||||
HWTEST_F(ScanServiceTest, AllowExternScanSuccess, TestSize.Level1)
|
||||
|
@ -37,7 +37,6 @@ ohos_unittest("wifi_sta_unittest") {
|
||||
"$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_network_check.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",
|
||||
@ -57,7 +56,6 @@ ohos_unittest("wifi_sta_unittest") {
|
||||
"sta_auto_connect_service_test.cpp",
|
||||
"sta_interface_test.cpp",
|
||||
"sta_monitor_test.cpp",
|
||||
"sta_network_check_test.cpp",
|
||||
"sta_saved_device_appraisal_test.cpp",
|
||||
"sta_service_test.cpp",
|
||||
]
|
||||
|
@ -40,9 +40,5 @@ void MockStaNetworkCheck::SetHttpResultInfo(std::string url, int codeNum, int co
|
||||
{
|
||||
WIFI_LOGD("Enter SetHttpResultInfo::[%{public}s].", __FUNCTION__);
|
||||
}
|
||||
void MockStaNetworkCheck::RegistHttpCallBack(std::shared_ptr<NetStack::HttpClient::HttpClientTask> task)
|
||||
{
|
||||
WIFI_LOGD("Enter RegistHttpCallBack::[%{public}s].", __FUNCTION__);
|
||||
}
|
||||
} // namespace Wifi
|
||||
} // namespace OHOS
|
@ -30,7 +30,6 @@ public:
|
||||
void SignalNetCheckThread() override;
|
||||
void StopNetCheckThread() override;
|
||||
void ExitNetCheckThread() override;
|
||||
void RegistHttpCallBack(std::shared_ptr<NetStack::HttpClient::HttpClientTask> task);
|
||||
void SetHttpResultInfo(std::string url, int codeNum, int codeLenNum);
|
||||
};
|
||||
} // namespace OHOS
|
||||
|
@ -41,11 +41,13 @@ ohos_unittest("toolkit_unittest") {
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/net_helper/mac_address.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/net_helper/network_interface.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/net_helper/raw_socket.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/net_helper/sta_network_check.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/utils/network_parser.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/utils/softap_parser.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/utils/wifi_encryption_util.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/utils/wifi_global_func.cpp",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/utils/xml_parser.cpp",
|
||||
"../../wifi_manage/wifi_sta/Mock/mock_sta_network_check.cpp",
|
||||
"arp_checker_test.cpp",
|
||||
"base_address_test.cpp",
|
||||
"dhcpd_interface_test.cpp",
|
||||
@ -58,6 +60,7 @@ ohos_unittest("toolkit_unittest") {
|
||||
"network_parser_test.cpp",
|
||||
"raw_socket_test.cpp",
|
||||
"softap_parser_test.cpp",
|
||||
"sta_network_check_test.cpp",
|
||||
"wifi_config_file_test.cpp",
|
||||
"wifi_encryption_util_test.cpp",
|
||||
"wifi_global_func_test.cpp",
|
||||
@ -73,6 +76,7 @@ ohos_unittest("toolkit_unittest") {
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/utils",
|
||||
"$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_manage/wifi_sta",
|
||||
"$WIFI_ROOT_DIR/interfaces/inner_api",
|
||||
"$WIFI_ROOT_DIR/frameworks/native/interfaces",
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/include",
|
||||
@ -85,6 +89,7 @@ ohos_unittest("toolkit_unittest") {
|
||||
]
|
||||
|
||||
deps = [
|
||||
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit:wifi_toolkit",
|
||||
"//third_party/googletest:gmock_main",
|
||||
"//third_party/googletest:gtest_main",
|
||||
"//third_party/libxml2:xml2",
|
||||
@ -98,6 +103,7 @@ ohos_unittest("toolkit_unittest") {
|
||||
"c_utils:utils",
|
||||
"dhcp:dhcp_sdk",
|
||||
"hilog:libhilog",
|
||||
"netstack:http_client",
|
||||
]
|
||||
if (wifi_feature_with_encryption) {
|
||||
external_deps += [ "huks:libhukssdk" ]
|
||||
|
@ -255,12 +255,7 @@ std::string GetBundleName()
|
||||
auto ret = bundleInstance->GetBundleInfoForSelf(0, bundleInfo);
|
||||
if (ret != OHOS::ERR_OK) {
|
||||
WIFI_LOGE("GetBundleInfoForSelf failed! ret[%{public}d]", ret);
|
||||
std::string bundleName;
|
||||
int uid = IPCSkeleton::GetCallingUid();
|
||||
if (bundleInstance->GetNameForUid(uid, bundleName) != OHOS::ERR_OK) {
|
||||
WIFI_LOGE("Get bundle name failed!");
|
||||
}
|
||||
return bundleName;
|
||||
return "";
|
||||
}
|
||||
|
||||
WIFI_LOGI("Get bundle name uid[%{public}d]: %{public}s", bundleInfo.uid, bundleInfo.name.c_str());
|
||||
|
@ -40,4 +40,5 @@ declare_args() {
|
||||
wifi_feature_with_hdi_wpa_supported = false
|
||||
wifi_feature_with_hpf_supported = true
|
||||
wifi_feature_with_rx_listen_supported = true
|
||||
wifi_feature_with_scan_control = true
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user