mirror of
https://gitee.com/openharmony/communication_wifi.git
synced 2024-11-27 01:01:03 +00:00
!2991 code同步
Merge pull request !2991 from 黎强345/OpenHarmony-5.0-Release
This commit is contained in:
commit
6e042f0a7b
@ -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 {
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -270,6 +270,8 @@ public:
|
||||
|
||||
bool EncryptionDeviceConfig(WifiDeviceConfig &config) const;
|
||||
|
||||
bool GetConfigValueByName(const std::string &name, std::string &value);
|
||||
|
||||
private:
|
||||
WifiSettings();
|
||||
int IncreaseNumRebootsSinceLastUse();
|
||||
|
@ -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
|
||||
|
@ -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
|
Loading…
Reference in New Issue
Block a user