!1503 wifi国家码bugfix

Merge pull request !1503 from yangpengfei/master
This commit is contained in:
openharmony_ci 2023-11-30 12:25:12 +00:00 committed by Gitee
commit 7ff9a7e714
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
23 changed files with 196 additions and 147 deletions

View File

@ -1,4 +1,4 @@
# Copyright (C) 2021 Huawei Device Co., Ltd.
# 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
@ -13,4 +13,5 @@
const.wifi_country_code.conf=1
const.wifi_country_code.runmode=normal
const.wifi_country_code.factory=HK
const.wifi_country_code.factory=HK
persist.wifi_country_code.dynamic_update=CN

View File

@ -1,4 +1,4 @@
# Copyright (c) 2022 Huawei Device Co., Ltd.
# 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
@ -11,4 +11,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
const.wifi_country_code. = "wifi:wifi:775"
const.wifi_country_code.conf="wifi:wifi:775"
const.wifi_country_code.runmode="wifi:wifi:775"
const.wifi_country_code.factory="wifi:wifi:775"
persist.wifi_country_code.dynamic_update="wifi:wifi:775"

View File

@ -469,9 +469,6 @@ if (defined(ohos_lite)) {
"eventhandler:libeventhandler",
"hilog:libhilog",
"huks:libhukssdk",
"i18n:intl_util",
"init:libbeget_proxy",
"init:libbegetutil",
"ipc:ipc_single",
"netmanager_base:net_conn_manager_if",
"netmanager_base:net_native_manager_if",
@ -496,6 +493,11 @@ if (defined(ohos_lite)) {
defines += [ "TELEPHONE_CORE_SERVICE_ENABLE" ]
}
if (defined(global_parts_info) && defined(global_parts_info.global_i18n)) {
external_deps += [ "i18n:intl_util" ]
defines += [ "I18N_INTL_UTIL_ENABLE" ]
}
if (defined(global_parts_info) &&
defined(global_parts_info.powermgr_battery_manager)) {
external_deps += [ "battery_manager:batterysrv_client" ]

View File

@ -21,9 +21,7 @@
namespace OHOS {
namespace Wifi {
constexpr int WIFI_COUNTRY_CODE_POLICE_DEF_LEN = 5;
const std::string SETTINGS_DATASHARE_KEY_WIFI_COUNTRY_CODE = "wifi_country_code";
const std::string SETTINGS_DATASHARE_URI_WIFI_COUNTRY_CODE =
"datashare:///com.ohos.settingsdata/entry/settingsdata/SETTINGSDATA?Proxy=true&key=wifi_country_code";
constexpr const char* WIFI_COUNTRY_CODE_DYNAMIC_UPDATE_KEY = "persist.wifi_country_code.dynamic_update";
constexpr const char* DEFAULT_WIFI_COUNTRY_CODE_ZZ = "ZZ"; // for tablets only, priority greater than HK
constexpr const char* DEFAULT_WIFI_COUNTRY_CODE = "HK";
constexpr const char* DEFAULT_RO_RUN_MODE = "normal";
@ -32,11 +30,12 @@ constexpr const char* FACTORY_WIFI_COUNTRY_CODE = "const.wifi_country_code.facto
constexpr const char* WIFI_COUNTRY_CODE_RUN_MODE = "const.wifi_country_code.runmode";
constexpr const char* WIFI_COUNTRY_CODE_CONFIG = "const.wifi_country_code.conf";
constexpr const char* WIFI_COUNTRY_CODE_CONFIG_DEFAULT = "0";
constexpr const char* DEFAULT_REGION_PARAM = "const.global.region";
constexpr const char* DEFAULT_REGION_KEY = "const.global.region";
constexpr const char* DEFAULT_REGION = "CN";
constexpr int WIFI_COUNTRY_CODE_SIZE = 16;
constexpr int FACTORY_WIFI_COUNTRY_CODE_SIZE = 16;
constexpr int WIFI_COUNTRY_CODE_RUN_MODE_SIZE = 16;
constexpr int WIFI_COUNTRY_CODE_DYNAMIC_UPDATE_SIZE = 16;
constexpr int SYSTEM_PARAMETER_ERROR_CODE = 0;
constexpr int PLMN_LEN = 3;
constexpr int PLMN_SUBSTR_LEFT = 0;

View File

@ -16,11 +16,7 @@
#include "wifi_country_code_manager.h"
#include <cstdint>
#include <sstream>
#include "datashare_helper.h"
#include "datashare_predicates.h"
#include "datashare_result_set.h"
#include "i_ap_service.h"
#include "parameter.h"
#include "wifi_ap_hal_interface.h"
#include "wifi_common_event_helper.h"
#include "wifi_datashare_utils.h"
@ -30,10 +26,9 @@
#include "wifi_msg.h"
#include "wifi_settings.h"
DEFINE_WIFILOG_LABEL("WifiCountryCodeManager");
namespace OHOS {
namespace Wifi {
DEFINE_WIFILOG_LABEL("WifiCountryCodeManager");
const std::string CLASS_NAME = "WifiCountryCodeManager";
WifiCountryCodeManager::~WifiCountryCodeManager()
@ -59,7 +54,6 @@ ErrCode WifiCountryCodeManager::Init()
m_staCallback.OnStaConnChanged = DealStaConnChanged;
m_apCallback.callbackModuleName = CLASS_NAME;
m_apCallback.OnApStateChangedEvent = DealApStateChanged;
UpdateWifiCountryCode();
return WIFI_OPT_SUCCESS;
}
@ -96,7 +90,7 @@ ErrCode WifiCountryCodeManager::SetWifiCountryCodeFromExternal(const std::string
ErrCode WifiCountryCodeManager::UpdateWifiCountryCode(const std::string &externalCode)
{
std::string wifiCountryCode;
if (!externalCode.empty() && IsValidCountryCode(externalCode) == WIFI_OPT_SUCCESS) {
if (!externalCode.empty() && !IsValidCountryCode(externalCode)) {
WIFI_LOGI("external set wifi country code, code=%{public}s", externalCode.c_str());
wifiCountryCode = externalCode;
StrToUpper(wifiCountryCode);
@ -196,23 +190,14 @@ void WifiCountryCodeManager::DealApStateChanged(ApState state, int id)
ErrCode WifiCountryCodeManager::UpdateWifiCountryCodeCache(const std::string &wifiCountryCode)
{
WIFI_LOGI("update wifi country code cache");
auto wifiDataShareHelperUtils = DelayedSingleton<WifiDataShareHelperUtils>::GetInstance();
if (wifiDataShareHelperUtils == nullptr) {
WIFI_LOGE("database is null");
if (wifiCountryCode.empty() || !IsValidCountryCode(wifiCountryCode)) {
WIFI_LOGE("wifi country code is empty or invalid");
return WIFI_OPT_FAILED;
}
Uri uri(SETTINGS_DATASHARE_URI_WIFI_COUNTRY_CODE);
std::string tempWifiCountryCode;
ErrCode ret = wifiDataShareHelperUtils->Query(uri, SETTINGS_DATASHARE_KEY_WIFI_COUNTRY_CODE, tempWifiCountryCode);
if (ret == WIFI_OPT_FAILED) {
WIFI_LOGI("database to insert wifi country code");
ret = wifiDataShareHelperUtils->Insert(uri, SETTINGS_DATASHARE_KEY_WIFI_COUNTRY_CODE, wifiCountryCode);
} else if (strcasecmp(tempWifiCountryCode.c_str(), wifiCountryCode.c_str()) != 0) {
ret = wifiDataShareHelperUtils->Update(uri, SETTINGS_DATASHARE_KEY_WIFI_COUNTRY_CODE, wifiCountryCode);
}
WIFI_LOGI("database to insert or update wifi country code, ret=%{public}d", ret);
return WIFI_OPT_SUCCESS;
int ret = SetParamValue(WIFI_COUNTRY_CODE_DYNAMIC_UPDATE_KEY, wifiCountryCode.c_str());
std::string retStr = ret == 0 ? "success" : "fail, ret=" + std::to_string(ret);
WIFI_LOGI("update wifi country code cache %{public}s", retStr.c_str());
return ret == 0 ? WIFI_OPT_SUCCESS : WIFI_OPT_FAILED;
}
}
}

View File

@ -18,11 +18,9 @@
#ifdef TELEPHONE_CORE_SERVICE_ENABLE
#include "core_service_client.h"
#endif
#include "datashare_helper.h"
#include "datashare_predicates.h"
#include "datashare_result_set.h"
#ifdef I18N_INTL_UTIL_ENABLE
#include "locale_config.h"
#include "parameter.h"
#endif
#include "uri.h"
#include "wifi_country_code_manager.h"
#include "wifi_datashare_utils.h"
@ -30,10 +28,10 @@
#include "wifi_logger.h"
#include "wifi_msg.h"
DEFINE_WIFILOG_LABEL("WifiCountryCodePolicy");
namespace OHOS {
namespace Wifi {
DEFINE_WIFILOG_LABEL("WifiCountryCodePolicy");
WifiCountryCodePolicy::WifiCountryCodePolicy()
{
CreatePolicy();
@ -52,7 +50,7 @@ WifiCountryCodePolicy::~WifiCountryCodePolicy()
void WifiCountryCodePolicy::GetWifiCountryCodePolicy()
{
char preValue[WIFI_COUNTRY_CODE_SIZE] = {0};
int errorCode = GetParameter(WIFI_COUNTRY_CODE_CONFIG,
int errorCode = GetParamValue(WIFI_COUNTRY_CODE_CONFIG,
WIFI_COUNTRY_CODE_CONFIG_DEFAULT, preValue, WIFI_COUNTRY_CODE_SIZE);
int policyConf = 0;
if (errorCode <= SYSTEM_PARAMETER_ERROR_CODE) {
@ -106,7 +104,7 @@ void WifiCountryCodePolicy::CreatePolicy()
std::bind(&WifiCountryCodePolicy::GetWifiCountryCodeByDefaultZZ, this, std::placeholders::_1));
}
m_policyList.emplace_back(
std::bind(&WifiCountryCodePolicy::GetWifiCountryCodeByDb, this, std::placeholders::_1));
std::bind(&WifiCountryCodePolicy::GetWifiCountryCodeByCache, this, std::placeholders::_1));
m_policyList.emplace_back(
std::bind(&WifiCountryCodePolicy::GetWifiCountryCodeByDefaultRegion, this, std::placeholders::_1));
m_policyList.emplace_back(
@ -126,7 +124,7 @@ ErrCode WifiCountryCodePolicy::CalculateWifiCountryCode(std::string &wifiCountry
ErrCode WifiCountryCodePolicy::GetWifiCountryCodeByFactory(std::string &wifiCountryCode)
{
char roRunModeValue[WIFI_COUNTRY_CODE_RUN_MODE_SIZE] = {0};
int errorCode = GetParameter(WIFI_COUNTRY_CODE_RUN_MODE, DEFAULT_RO_RUN_MODE, roRunModeValue,
int errorCode = GetParamValue(WIFI_COUNTRY_CODE_RUN_MODE, DEFAULT_RO_RUN_MODE, roRunModeValue,
WIFI_COUNTRY_CODE_RUN_MODE_SIZE);
if (errorCode <= SYSTEM_PARAMETER_ERROR_CODE || strcasecmp(FACTORY_RO_RUN_MODE, roRunModeValue) != 0) {
WIFI_LOGI("wifi country code factory mode does not take effect or fail, ret=%{public}d, "
@ -134,7 +132,7 @@ ErrCode WifiCountryCodePolicy::GetWifiCountryCodeByFactory(std::string &wifiCoun
return WIFI_OPT_FAILED;
}
char factoryWifiCountryCodeValue[FACTORY_WIFI_COUNTRY_CODE_SIZE] = {0};
errorCode = GetParameter(FACTORY_WIFI_COUNTRY_CODE, DEFAULT_WIFI_COUNTRY_CODE,
errorCode = GetParamValue(FACTORY_WIFI_COUNTRY_CODE, DEFAULT_WIFI_COUNTRY_CODE,
factoryWifiCountryCodeValue, FACTORY_WIFI_COUNTRY_CODE_SIZE);
if (errorCode <= SYSTEM_PARAMETER_ERROR_CODE) {
WIFI_LOGI("get wifi country code by factory fail, errorCode=%{public}d", errorCode);
@ -238,7 +236,7 @@ ErrCode WifiCountryCodePolicy::FindLargestCountCountryCode(std::string &wifiCoun
const std::pair<std::string, int> &b) {
return a.second > b.second;
});
if (sortCode.size() <= 0) {
if (sortCode.size() == 0) {
return WIFI_OPT_FAILED;
}
if (sortCode.size() == 1) {
@ -259,7 +257,7 @@ ErrCode WifiCountryCodePolicy::FindLargestCountCountryCode(std::string &wifiCoun
}
ErrCode WifiCountryCodePolicy::ParseCountryCodeElement(
std::vector<WifiInfoElem> &infoElems, std::string &wifiCountryCode)
const std::vector<WifiInfoElem> &infoElems, std::string &wifiCountryCode)
{
if (infoElems.empty()) {
return WIFI_OPT_FAILED;
@ -319,7 +317,10 @@ ErrCode WifiCountryCodePolicy::GetWifiCountryCodeByScanResult(std::string &wifiC
ErrCode WifiCountryCodePolicy::GetWifiCountryCodeByRegion(std::string &wifiCountryCode)
{
// the user selects an area in settings
std::string tempWifiCountryCode = Global::I18n::LocaleConfig::GetSystemRegion();
std::string tempWifiCountryCode;
#ifdef I18N_INTL_UTIL_ENABLE
tempWifiCountryCode = Global::I18n::LocaleConfig::GetSystemRegion();
#endif
if (tempWifiCountryCode.empty() || !IsValidCountryCode(tempWifiCountryCode)) {
WIFI_LOGE("get wifi country code by region fail, code=%{public}s", tempWifiCountryCode.c_str());
return WIFI_OPT_FAILED;
@ -337,26 +338,28 @@ ErrCode WifiCountryCodePolicy::GetWifiCountryCodeByDefaultZZ(std::string &wifiCo
return WIFI_OPT_SUCCESS;
}
ErrCode WifiCountryCodePolicy::GetWifiCountryCodeByDb(std::string &wifiCountryCode)
ErrCode WifiCountryCodePolicy::GetWifiCountryCodeByCache(std::string &wifiCountryCode)
{
auto wifiDataShareHelperUtils = DelayedSingleton<WifiDataShareHelperUtils>::GetInstance();
CHECK_NULL_AND_RETURN(wifiDataShareHelperUtils, WIFI_OPT_FAILED);
std::string wifiCountryCodeCache;
Uri uri(SETTINGS_DATASHARE_URI_WIFI_COUNTRY_CODE);
int ret = wifiDataShareHelperUtils->Query(uri, SETTINGS_DATASHARE_KEY_WIFI_COUNTRY_CODE, wifiCountryCodeCache);
if (ret == WIFI_OPT_SUCCESS) {
WIFI_LOGI("get wifi country code by db success, code=%{public}s", wifiCountryCodeCache.c_str());
wifiCountryCode = wifiCountryCodeCache;
return WIFI_OPT_SUCCESS;
char tempWifiCountryCode[WIFI_COUNTRY_CODE_DYNAMIC_UPDATE_SIZE] = {0};
int ret = GetParamValue(WIFI_COUNTRY_CODE_DYNAMIC_UPDATE_KEY, DEFAULT_WIFI_COUNTRY_CODE,
tempWifiCountryCode, WIFI_COUNTRY_CODE_DYNAMIC_UPDATE_SIZE);
if (ret <= SYSTEM_PARAMETER_ERROR_CODE) {
WIFI_LOGE("get wifi country code by cache fail, ret=%{public}d", ret);
return WIFI_OPT_FAILED;
}
WIFI_LOGE("get wifi country code by db fail, ret=%{public}d", ret);
return WIFI_OPT_FAILED;
if (!IsValidCountryCode(tempWifiCountryCode)) {
WIFI_LOGE("get wifi country code by cache fail, code invalid, code=%{public}s", tempWifiCountryCode);
return WIFI_OPT_FAILED;
}
wifiCountryCode = tempWifiCountryCode;
WIFI_LOGI("get wifi country code by cache success, code=%{public}s", wifiCountryCode.c_str());
return WIFI_OPT_SUCCESS;
}
ErrCode WifiCountryCodePolicy::GetWifiCountryCodeByDefaultRegion(std::string &wifiCountryCode)
{
char defaultRegion[DEFAULT_REGION_SIZE] = {0};
int errorCode = GetParameter(DEFAULT_REGION,
int errorCode = GetParamValue(DEFAULT_REGION_KEY,
DEFAULT_REGION, defaultRegion, DEFAULT_REGION_SIZE);
if (errorCode <= SYSTEM_PARAMETER_ERROR_CODE) {
WIFI_LOGI("get wifi country code by default region fail, errorCode=%{public}d", errorCode);

View File

@ -99,13 +99,13 @@ private:
void HandleScanResultAction();
ErrCode StatisticCountryCodeFromScanResult(std::string &wifiCountryCode);
ErrCode FindLargestCountCountryCode(std::string &wifiCountryCode);
ErrCode ParseCountryCodeElement(std::vector<WifiInfoElem> &infoElems, std::string &wifiCountryCode);
ErrCode ParseCountryCodeElement(const std::vector<WifiInfoElem> &infoElems, std::string &wifiCountryCode);
ErrCode HandleWifiNetworkStateChangeAction(int connectionStatus);
ErrCode GetWifiCountryCodeByRegion(std::string &wifiCountryCode);
ErrCode GetWifiCountryCodeByAP(std::string &wifiCountryCode);
ErrCode GetWifiCountryCodeByScanResult(std::string &wifiCountryCode);
ErrCode GetWifiCountryCodeByDefaultZZ(std::string &wifiCountryCode);
ErrCode GetWifiCountryCodeByDb(std::string &wifiCountryCode);
ErrCode GetWifiCountryCodeByCache(std::string &wifiCountryCode);
ErrCode GetWifiCountryCodeByDefaultRegion(std::string &wifiCountryCode);
ErrCode GetWifiCountryCodeByDefault(std::string &wifiCountryCode);
bool IsContainBssid(const std::vector<std::string> &bssidList, const std::string &bssid);

View File

@ -34,7 +34,6 @@
#include "wifi_country_code_manager.h"
#include "wifi_protect_manager.h"
#include "wifi_power_state_listener.h"
#include "parameter.h"
#include "suspend/sleep_priority.h"
#endif
#include "wifi_sta_hal_interface.h"
@ -755,7 +754,7 @@ void WifiManager::GetMdmProp()
{
char preValue[PROP_FALSE_LEN + 1] = {0};
int errorCode = GetParameter(MDM_WIFI_PROP.c_str(), 0, preValue, PROP_FALSE_LEN + 1);
int errorCode = GetParamValue(MDM_WIFI_PROP.c_str(), 0, preValue, PROP_FALSE_LEN + 1);
if (errorCode > 0) {
if (strncmp(preValue, PROP_TRUE.c_str(), PROP_TRUE_LEN) == 0) {
mIsMdmForbidden = true;
@ -765,7 +764,7 @@ void WifiManager::GetMdmProp()
void WifiManager::RegisterMdmPropListener()
{
int ret = WatchParameter(MDM_WIFI_PROP.c_str(), MdmPropChangeEvt, nullptr);
int ret = WatchParamValue(MDM_WIFI_PROP.c_str(), MdmPropChangeEvt, nullptr);
if (ret != 0) {
WIFI_LOGI("RegisterMdmPropListener failed");
}

View File

@ -136,6 +136,14 @@ if (defined(ohos_lite)) {
"huks:libhukssdk",
]
if (defined(global_parts_info) && defined(global_parts_info.startup_init)) {
external_deps += [
"init:libbeget_proxy",
"init:libbegetutil",
]
defines += [ "INIT_LIB_ENABLE" ]
}
public_deps = []
if (wifi_feature_with_encryption) {

View File

@ -16,9 +16,9 @@
#include "network_parser.h"
#include "wifi_logger.h"
DEFINE_WIFILOG_LABEL("NetworkXmlParser");
namespace OHOS {
namespace Wifi {
DEFINE_WIFILOG_LABEL("NetworkXmlParser");
constexpr auto XML_TAG_SECTION_HEADER_NETWORK_LIST = "NetworkList";
constexpr auto XML_TAG_SECTION_HEADER_NETWORK = "Network";
constexpr auto XML_TAG_SECTION_HEADER_WIFI_CONFIGURATION = "WifiConfiguration";
@ -273,7 +273,7 @@ void NetworkXmlParser::GetKeyMgmt(xmlNodePtr node, WifiDeviceConfig& wifiConfig)
}
if (keyMgmtInt & MGMT_SAE) {
wifiConfig.keyMgmt = KEY_MGMT_SAE;
} else if (keyMgmtInt & MGMT_WPA_PSK || keyMgmtInt & MGMT_WPA2_PSK || keyMgmtInt & MGMT_FT_PSK) {
} else if ((keyMgmtInt & MGMT_WPA_PSK) || (keyMgmtInt & MGMT_WPA2_PSK) || (keyMgmtInt & MGMT_FT_PSK)) {
wifiConfig.keyMgmt = KEY_MGMT_WPA_PSK;
} else if (keyMgmtInt & MGMT_NONE) {
if (HasWepKeys(wifiConfig)) {

View File

@ -17,9 +17,9 @@
#include "wifi_logger.h"
#include "wifi_global_func.h"
DEFINE_WIFILOG_LABEL("SoftapParser");
namespace OHOS {
namespace Wifi {
DEFINE_WIFILOG_LABEL("SoftapParser");
const int BAND_2GHZ = 1 << 0;
const int SECURITY_TYPE_WPA2_PSK = 1;

View File

@ -20,6 +20,9 @@
#ifndef OHOS_ARCH_LITE
#include "wifi_country_code_define.h"
#endif
#ifdef INIT_LIB_ENABLE
#include "parameter.h"
#endif
#undef LOG_TAG
#define LOG_TAG "WifiGlobalFunc"
@ -35,6 +38,9 @@ constexpr int CHANNEL_14 = 14;
constexpr int CENTER_FREP_DIFF = 5;
constexpr int CHANNEL_2G_MIN = 1;
constexpr int CHANNEL_5G_MIN = 34;
#ifndef INIT_LIB_ENABLE
constexpr int EC_INVALID = -9; // using sysparam_errno.h, invalid param value
#endif
std::string GetRandomStr(int len)
{
@ -368,5 +374,32 @@ int ConvertStringToInt(const std::string str)
ss >> result;
return result;
}
int GetParamValue(const char *key, const char *def, char *value, uint32_t len)
{
#ifdef INIT_LIB_ENABLE
return GetParameter(key, def, value, len);
#else
return EC_INVALID;
#endif
}
int SetParamValue(const char *key, const char *value)
{
#ifdef INIT_LIB_ENABLE
return SetParameter(key, value);
#else
return EC_INVALID;
#endif
}
int WatchParamValue(const char *keyprefix, ParameterChgPtr callback, void *context)
{
#ifdef INIT_LIB_ENABLE
return WatchParameter(keyprefix, callback, context);
#else
return EC_INVALID;
#endif
}
} // namespace Wifi
} // namespace OHOS

View File

@ -34,6 +34,7 @@ constexpr int MAX_PSK_LEN = 63;
constexpr int HEX_TYPE_LEN = 3; /* 3 hex type: 0 a A */
constexpr int MAX_AP_CONN = 32;
constexpr int MAX_CONFIGS_NUM = 1000;
typedef void (*ParameterChgPtr)(const char *key, const char *value, void *context);
/**
* @Description Get a random string
@ -275,6 +276,47 @@ int ConvertCharToInt(const char &c);
* @return numbers
*/
int ConvertStringToInt(const std::string str);
/**
* @Description Obtains a system parameter matching the specified key.
*
* @param key - Indicates the key for the system parameter to query.
* The value can contain lowercase letters, digits, underscores (_), and dots (.).
* Its length cannot exceed 32 bytes (including the end-of-text character in the string).
* @param def - Indicates the default value to return when no query result is found.
* This parameter is specified by the caller.
* @param value - Indicates the data buffer that stores the query result.
* This parameter is applied for and released by the caller and can be used as an output parameter.
* @param len - Indicates the length of the data in the buffer.
* @return Returns the number of bytes of the system parameter if the operation is successful;
* returns -9 if a parameter is incorrect; returns -1 in other scenarios.
*/
int GetParamValue(const char *key, const char *def, char *value, uint32_t len);
/**
* @Description Sets or updates a system parameter.
*
* @param key Indicates the key for the parameter to set or update.
* The value can contain lowercase letters, digits, underscores (_), and dots (.).
* Its length cannot exceed 32 bytes (including the end-of-text character in the string).
* @param value Indicates the system parameter value.
* Its length cannot exceed 128 bytes (including the end-of-text character in the string).
* @return Returns 0 if the operation is successful;
* returns -9 if a parameter is incorrect; returns -1 in other scenarios.
*/
int SetParamValue(const char *key, const char *value);
/**
* @Description Watch for system parameter values.
*
* @param keyPrefix - Indicates the key prefix for the parameter to be watched.
* If keyPrefix is not a full name, "A.B." for example, it means to watch for all parameter started with "A.B.".
* @param callback - Indicates value change callback.
* If callback is NULL, it means to cancel the watch.
* @param context - context.
* @return Returns 0 if the operation is successful;
*/
int WatchParamValue(const char *keyprefix, ParameterChgPtr callback, void *context);
} // namespace Wifi
} // namespace OHOS
#endif

View File

@ -17,9 +17,10 @@
#include "wifi_logger.h"
#include <vector>
DEFINE_WIFILOG_LABEL("XmlParser");
namespace OHOS {
namespace Wifi {
DEFINE_WIFILOG_LABEL("XmlParser");
XmlParser::~XmlParser()
{
Destroy();

View File

@ -38,10 +38,10 @@ using ::testing::StrEq;
using ::testing::TypedEq;
using ::testing::ext::TestSize;
DEFINE_WIFILOG_LABEL("WifiCountryCodeManagerTest");
namespace OHOS {
namespace Wifi {
DEFINE_WIFILOG_LABEL("WifiCountryCodeManagerTest");
class WifiCountryCodeChangeObserver : public IWifiCountryCodeChangeListener {
public:
WifiCountryCodeChangeObserver(const std::string &name, StateMachine &stateMachineObj)

View File

@ -36,10 +36,10 @@ using ::testing::StrEq;
using ::testing::TypedEq;
using ::testing::ext::TestSize;
DEFINE_WIFILOG_LABEL("WifiCountryCodePolicyTest");
namespace OHOS {
namespace Wifi {
DEFINE_WIFILOG_LABEL("WifiCountryCodePolicyTest");
class WifiCountryCodePolicyTest : public testing::Test {
public:
static void SetUpTestCase() {}
@ -178,11 +178,11 @@ HWTEST_F(WifiCountryCodePolicyTest, GetWifiCountryCodeByDefaultZZTest, TestSize.
EXPECT_EQ(ErrCode::WIFI_OPT_SUCCESS, m_wifiCountryCodePolicy->GetWifiCountryCodeByDefaultZZ(code));
}
HWTEST_F(WifiCountryCodePolicyTest, GetWifiCountryCodeByDbTest, TestSize.Level1)
HWTEST_F(WifiCountryCodePolicyTest, GetWifiCountryCodeByCacheTest, TestSize.Level1)
{
WIFI_LOGI("GetWifiCountryCodeByDbTest enter");
WIFI_LOGI("GetWifiCountryCodeByCacheTest enter");
std::string code;
EXPECT_EQ(ErrCode::WIFI_OPT_SUCCESS, m_wifiCountryCodePolicy->GetWifiCountryCodeByDb(code));
EXPECT_EQ(ErrCode::WIFI_OPT_SUCCESS, m_wifiCountryCodePolicy->GetWifiCountryCodeByCache(code));
}
HWTEST_F(WifiCountryCodePolicyTest, GetWifiCountryCodeByDefaultRegionTest, TestSize.Level1)

View File

@ -30,10 +30,10 @@ using ::testing::SetArgReferee;
using ::testing::StrEq;
using ::testing::TypedEq;
using ::testing::ext::TestSize;
DEFINE_WIFILOG_LABEL("WifiSettingsTest");
namespace OHOS {
namespace Wifi {
DEFINE_WIFILOG_LABEL("WifiSettingsTest");
constexpr int NETWORK_ID = 15;
constexpr int TYPE = 3;
constexpr int SCORE = 0;
@ -506,5 +506,17 @@ HWTEST_F(WifiSettingsTest, ClearMacAddrPairsTest, TestSize.Level1)
WIFI_LOGE("ClearMacAddrPairsTest enter!");
WifiSettings::GetInstance().ClearMacAddrPairs(WifiMacAddrInfoType::WIFI_SCANINFO_MACADDR_INFO);
}
HWTEST_F(WifiSettingsTest, MergeWifiConfigTest, TestSize.Level1)
{
WIFI_LOGI("MergeWifiConfigTest enter");
WifiSettings::GetInstance().MergeWifiConfig();
}
HWTEST_F(WifiSettingsTest, MergeSoftapConfigTest, TestSize.Level1)
{
WIFI_LOGI("MergeSoftapConfigTest enter");
WifiSettings::GetInstance().MergeSoftapConfig();
}
} // namespace Wifi
} // namespace OHOS

View File

@ -28,7 +28,6 @@ ohos_unittest("toolkit_unittest") {
sources = [
"$WIFI_ROOT_DIR/frameworks/native/src/wifi_p2p_msg.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/config/wifi_config_file_spec.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/config/wifi_settings.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/log/log_helper.c",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/net_helper/arp_checker.cpp",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/net_helper/base_address.cpp",
@ -64,7 +63,6 @@ ohos_unittest("toolkit_unittest") {
"wifi_global_func_test.cpp",
"wifi_ip_tools_test.cpp",
"wifi_log_helper_test.cpp",
"wifi_settings_test.cpp",
"xml_parser_test.cpp",
]

View File

@ -37,11 +37,11 @@ using ::testing::SetArgReferee;
using ::testing::StrEq;
using ::testing::TypedEq;
using ::testing::ext::TestSize;
DEFINE_WIFILOG_LABEL("NetworkParserTest");
namespace OHOS {
namespace Wifi {
DEFINE_WIFILOG_LABEL("NetworkParserTest");
class NetworkParserTest : public testing::Test {
public:
static void SetUpTestCase() {}

View File

@ -36,11 +36,11 @@ using ::testing::SetArgReferee;
using ::testing::StrEq;
using ::testing::TypedEq;
using ::testing::ext::TestSize;
DEFINE_WIFILOG_LABEL("SoftapParserTest");
namespace OHOS {
namespace Wifi {
DEFINE_WIFILOG_LABEL("SoftapParserTest");
class SoftapParserTest : public testing::Test {
public:
static void SetUpTestCase() {}

View File

@ -15,6 +15,7 @@
#include "wifi_global_func_test.h"
#include "wifi_global_func.h"
#include "wifi_country_code_define.h"
using namespace testing::ext;
@ -29,6 +30,7 @@ constexpr int CHANNEL_2G_MIN = 1;
constexpr int CHANNEL_5G = 34;
constexpr int CHANNEL_2G = 14;
constexpr uint32_t PLAIN_LENGTH = 10;
const std::string MDM_WIFI_PROP = "persist.edm.wifi_enable";
HWTEST_F(WifiGlobalFuncTest, GetRandomStr, TestSize.Level1)
{
@ -226,5 +228,25 @@ HWTEST_F(WifiGlobalFuncTest, ConvertStringToIntTest, TestSize.Level1)
int i = ConvertStringToInt(str);
EXPECT_TRUE(i == 2000);
}
HWTEST_F(WifiGlobalFuncTest, GetParamValueTest, TestSize.Level1)
{
char preValue[WIFI_COUNTRY_CODE_SIZE] = {0};
GetParamValue(WIFI_COUNTRY_CODE_CONFIG,
WIFI_COUNTRY_CODE_CONFIG_DEFAULT, preValue, WIFI_COUNTRY_CODE_SIZE);
}
HWTEST_F(WifiGlobalFuncTest, SetParamValueTest, TestSize.Level1)
{
SetParamValue(WIFI_COUNTRY_CODE_DYNAMIC_UPDATE_KEY, "US");
}
void MdmPropChangeEvt(const char *key, const char *value, void *context)
{}
HWTEST_F(WifiGlobalFuncTest, WatchParamValueTest, TestSize.Level1)
{
WatchParamValue(MDM_WIFI_PROP.c_str(), MdmPropChangeEvt, nullptr);
}
} // namespace Wifi
} // namespace OHOS

View File

@ -1,59 +0,0 @@
/*
* 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 <gmock/gmock.h>
#include <gtest/gtest.h>
#include <memory>
#include "wifi_log.h"
#include "wifi_logger.h"
#include "wifi_internal_msg.h"
#include "wifi_msg.h"
#include "wifi_errcode.h"
#include "wifi_settings.h"
using ::testing::_;
using ::testing::DoAll;
using ::testing::Eq;
using ::testing::Return;
using ::testing::SetArgReferee;
using ::testing::StrEq;
using ::testing::TypedEq;
using ::testing::ext::TestSize;
DEFINE_WIFILOG_LABEL("WifiSettingsTest");
namespace OHOS {
namespace Wifi {
class WifiSettingsTest : public testing::Test {
public:
static void SetUpTestCase() {}
static void TearDownTestCase() {}
virtual void SetUp() {}
virtual void TearDown() {}
};
HWTEST_F(WifiSettingsTest, MergeWifiConfigTest, TestSize.Level1)
{
WIFI_LOGI("MergeWifiConfigTest enter");
WifiSettings::GetInstance().MergeWifiConfig();
}
HWTEST_F(WifiSettingsTest, MergeSoftapConfigTest, TestSize.Level1)
{
WIFI_LOGI("MergeSoftapConfigTest enter");
WifiSettings::GetInstance().MergeSoftapConfig();
}
}
}

View File

@ -35,11 +35,11 @@ using ::testing::SetArgReferee;
using ::testing::StrEq;
using ::testing::TypedEq;
using ::testing::ext::TestSize;
DEFINE_WIFILOG_LABEL("XmlParserTest");
namespace OHOS {
namespace Wifi {
DEFINE_WIFILOG_LABEL("XmlParserTest");
class MockXmlParser : public XmlParser {
public:
bool ParseInternal(xmlNodePtr node)