Merge pull request !2991 from 黎强345/OpenHarmony-5.0-Release
This commit is contained in:
openharmony_ci 2024-09-18 09:33:14 +00:00 committed by Gitee
commit 6e042f0a7b
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
6 changed files with 59 additions and 14 deletions

View File

@ -37,7 +37,6 @@ DEFINE_WIFILOG_LABEL("StaService");
namespace OHOS {
namespace Wifi {
constexpr const char *ANCO_SERVICE_BROKER = "anco_service_broker";
constexpr const int REMOVE_ALL_DEVICECONFIG = 0x7FFFFFFF;
#define EAP_AUTH_IMSI_MCC_POS 0
@ -221,9 +220,10 @@ ErrCode StaService::AddCandidateConfig(const int uid, const WifiDeviceConfig &co
if (config.keyMgmt == KEY_MGMT_WEP) {
#ifndef OHOS_ARCH_LITE
const std::string wifiBrokerFrameProcessName = ANCO_SERVICE_BROKER;
std::string wifiBrokerFrameProcessName = "";
bool success = WifiSettings::GetInstance().GetConfigValueByName("anco_broker_name", wifiBrokerFrameProcessName);
std::string ancoBrokerFrameProcessName = GetBrokerProcessNameByPid(GetCallingUid(), GetCallingPid());
if (ancoBrokerFrameProcessName != wifiBrokerFrameProcessName) {
if (!success || ancoBrokerFrameProcessName != wifiBrokerFrameProcessName) {
LOGE("AddCandidateConfig unsupport wep key!");
return WIFI_OPT_NOT_SUPPORTED;
}
@ -488,9 +488,10 @@ ErrCode StaService::RemoveDevice(int networkId) const
WifiSettings::GetInstance().SyncDeviceConfig();
NotifyDeviceConfigChange(ConfigChange::CONFIG_REMOVE);
#ifndef OHOS_ARCH_LITE
const std::string wifiBrokerFrameProcessName = ANCO_SERVICE_BROKER;
std::string wifiBrokerFrameProcessName = "";
bool success = WifiSettings::GetInstance().GetConfigValueByName("anco_broker_name", wifiBrokerFrameProcessName);
std::string ancoBrokerFrameProcessName = GetBrokerProcessNameByPid(GetCallingUid(), GetCallingPid());
if (ancoBrokerFrameProcessName == wifiBrokerFrameProcessName) {
if (success && ancoBrokerFrameProcessName == wifiBrokerFrameProcessName) {
config.callProcessName = wifiBrokerFrameProcessName;
} else {
config.callProcessName = "";
@ -519,9 +520,10 @@ ErrCode StaService::RemoveAllDevice() const
#ifndef OHOS_ARCH_LITE
WifiDeviceConfig config;
config.networkId = REMOVE_ALL_DEVICECONFIG;
const std::string wifiBrokerFrameProcessName = ANCO_SERVICE_BROKER;
std::string wifiBrokerFrameProcessName = "";
bool success = WifiSettings::GetInstance().GetConfigValueByName("anco_broker_name", wifiBrokerFrameProcessName);
std::string ancoBrokerFrameProcessName = GetBrokerProcessNameByPid(GetCallingUid(), GetCallingPid());
if (ancoBrokerFrameProcessName == wifiBrokerFrameProcessName) {
if (success && ancoBrokerFrameProcessName == wifiBrokerFrameProcessName) {
config.callProcessName = wifiBrokerFrameProcessName;
} else {
config.callProcessName = "";
@ -689,9 +691,10 @@ ErrCode StaService::AutoConnectService(const std::vector<InterScanInfo> &scanInf
LOGI("AutoConnectService: p2p or hml connected, and hotspot is enable");
return WIFI_OPT_FAILED;
}
const std::string wifiBrokerFrameProcessName = ANCO_SERVICE_BROKER;
std::string wifiBrokerFrameProcessName = "";
bool success = WifiSettings::GetInstance().GetConfigValueByName("anco_broker_name", wifiBrokerFrameProcessName);
std::string ancoBrokerFrameProcessName = GetBrokerProcessNameByPid(GetCallingUid(), GetCallingPid());
if (ancoBrokerFrameProcessName == wifiBrokerFrameProcessName) {
if (success && ancoBrokerFrameProcessName == wifiBrokerFrameProcessName) {
WifiConfigCenter::GetInstance().SetWifiConnectedMode(true, m_instId);
WIFI_LOGD("StaService %{public}s, anco, %{public}d", __func__, m_instId);
} else {

View File

@ -47,7 +47,6 @@ DEFINE_WIFILOG_LABEL("WifiDeviceServiceImpl");
namespace OHOS {
namespace Wifi {
constexpr const char *ANCO_SERVICE_BROKER = "anco_service_broker";
constexpr const char *BROKER_PROCESS_PROTECT_FLAG = "register_process_info";
constexpr const char *EXTENSION_SUCCESS = "wifi extension success";
constexpr const char *EXTENSION_FAIL = "wifi extension fail";
@ -364,8 +363,13 @@ bool WifiDeviceServiceImpl::InitWifiBrokerProcessInfo(const WifiDeviceConfig &co
"ancoCallProcessName =[%{public}s],bssid = [%{public}s],ssid=[%{public}s]",
config.networkId, config.callProcessName.c_str(), config.ancoCallProcessName.c_str(),
MacAnonymize(config.bssid).c_str(), SsidAnonymize(config.ssid).c_str());
if (config.networkId == WIFI_BROKER_NETWORK_ID && config.ancoCallProcessName == BROKER_PROCESS_PROTECT_FLAG &&
config.bssid.empty() && config.ssid.empty() && config.callProcessName == ANCO_SERVICE_BROKER) {
if (config.networkId != WIFI_BROKER_NETWORK_ID || config.ancoCallProcessName != BROKER_PROCESS_PROTECT_FLAG ||
!config.bssid.empty() || !config.ssid.empty()) {
return false;
}
std::string ancoWifiValue = "";
bool success = WifiSettings::GetInstance().GetConfigValueByName("anco_broker_name", ancoWifiValue);
if (success && config.callProcessName == ancoWifiValue) {
SetWifiBrokerProcess(GetCallingPid(), config.callProcessName);
return true;
}
@ -390,9 +394,10 @@ bool WifiDeviceServiceImpl::IsWifiBrokerProcess(int uid)
{
#ifndef OHOS_ARCH_LITE
int pid = GetCallingPid();
const std::string wifiBrokerFrameProcessName = ANCO_SERVICE_BROKER;
std::string wifiBrokerFrameProcessName = "";
bool success = WifiSettings::GetInstance().GetConfigValueByName("anco_broker_name", wifiBrokerFrameProcessName);
std::string ancoBrokerFrameProcessName = GetBrokerProcessNameByPid(uid, pid);
if (ancoBrokerFrameProcessName != wifiBrokerFrameProcessName) {
if (!success || ancoBrokerFrameProcessName != wifiBrokerFrameProcessName) {
return false;
}
return true;

View File

@ -1949,6 +1949,26 @@ bool WifiSettings::EncryptionWapiConfig(const WifiEncryptionInfo &wifiEncryption
}
return true;
}
bool WifiSettings::GetConfigValueByName(const std::string &name, std::string &value)
{
if (name.empty()) {
LOGE("name empty");
return false;
}
std::unique_lock<std::mutex> lock(mScanMutex);
std::vector<std::string> values = mFilterMap[name];
if (values.empty()) {
LOGE("GetConfigValueByName values is empty");
return false;
}
value = values.front();
if (value.empty()) {
LOGE("GetConfigValueByName value is empty");
return false;
}
return true;
}
#endif
} // namespace Wifi
} // namespace OHOS

View File

@ -270,6 +270,8 @@ public:
bool EncryptionDeviceConfig(WifiDeviceConfig &config) const;
bool GetConfigValueByName(const std::string &name, std::string &value);
private:
WifiSettings();
int IncreaseNumRebootsSinceLastUse();

View File

@ -90,6 +90,7 @@ public:
virtual int SetStaLastRunState(int bRun, int instId = 0) = 0;
virtual void SetScanOnlySwitchState(const int &state, int instId = 0) = 0;
virtual bool IsModulePreLoad(const std::string &name) = 0;
virtual bool GetConfigValueByName(const std::string &name, std::string &value) = 0;
};
class WifiSettings : public MockWifiSettings {
@ -162,6 +163,7 @@ public:
MOCK_METHOD2(SetScanOnlySwitchState, void(const int &state, int instId));
MOCK_METHOD0(ReloadTrustListPolicies, const std::vector<TrustListPolicy>());
MOCK_METHOD1(IsModulePreLoad, bool(const std::string &name));
MOCK_METHOD2(GetConfigValueByName, bool(const std::string &name, std::string &value));
};
} // namespace OHOS
} // namespace Wifi

View File

@ -579,5 +579,18 @@ HWTEST_F(WifiSettingsTest, DecryptionWapiConfigTest, TestSize.Level1)
config.wifiWapiConfig.wapiUserCertData = "12345678";
WifiSettings::GetInstance().DecryptionDeviceConfig(config);
}
HWTEST_F(WifiSettingsTest, GetConfigValueByName, TestSize.Level1)
{
WIFI_LOGI("GetConfigValueByName enter");
std::string ancoValue = "";
WifiSettings::GetInstance().Init();
bool sucess = WifiSettings::GetInstance().GetConfigValueByName("anco_broker_name", ancoValue);
EXPECT_TRUE(sucess);
std::string ancoNoValue = "";
bool fail = WifiSettings::GetInstance().GetConfigValueByName("Novalue", ancoNoValue);
EXPECT_FALSE(fail);
EXPECT_EQ(ancoNoValue, "");
}
} // namespace Wifi
} // namespace OHO