description:WIFI STA&AP 互斥

Signed-off-by: zha.wei <zhawei@kaihong.com>
This commit is contained in:
zha.wei 2023-06-27 14:34:58 +08:00
parent 0c6ea8d419
commit ba7ca12efe
8 changed files with 120 additions and 6 deletions

View File

@ -56,7 +56,8 @@
"wifi_feature_with_app_frozen",
"wifi_feature_non_seperate_p2p",
"wifi_feature_non_hdf_driver",
"wifi_feature_is_random_mac_supported"
"wifi_feature_is_random_mac_supported",
"wifi_feature_sta_ap_exclusion"
],
"adapted_system_type": [
"standard"

View File

@ -42,7 +42,9 @@ enum ErrCode {
WIFI_OPT_P2P_ERR_SIZE_NW_NAME,
WIFI_OPT_MOVING_FREEZE_CTRL, /* moving freeze scanning control */
WIFI_OPT_NON_SYSTEMAPP, /* not system app denied */
WIFI_OPT_STA_AP_EXCLUSION_STA_CLOSE_FAILED, /* sta close failure in STA_AP_EXCLUSION scene */
WIFI_OPT_STA_AP_EXCLUSION_AP_CLOSE_FAILED /* ap close failure in STA_AP_EXCLUSION scene */
};
} // namespace Wifi
} // namespace OHOS
#endif
#endif

View File

@ -243,6 +243,10 @@ if (defined(ohos_lite)) {
defines += [ "FEATURE_AP_SUPPORT" ]
}
if (wifi_feature_sta_ap_exclusion) {
defines += [ "WIFI_FEATURE_STA_AP_EXCLUSION" ]
}
deps = [
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit:wifi_toolkit",
"$WIFI_ROOT_DIR/utils:wifi_utils",
@ -303,6 +307,10 @@ if (defined(ohos_lite)) {
"AP_INSTANCE_MAX_NUM=$wifi_feature_with_ap_num",
]
if (wifi_feature_sta_ap_exclusion) {
defines += [ "WIFI_FEATURE_STA_AP_EXCLUSION" ]
}
if (wifi_feature_with_ap_extension) {
defines += [ "FEATURE_AP_EXTENSION" ]
}

View File

@ -223,11 +223,18 @@ ErrCode WifiDeviceServiceImpl::EnableWifi()
}
#ifdef FEATURE_AP_SUPPORT
curState = WifiConfigCenter::GetInstance().GetApMidState(0);
if (curState != WifiOprMidState::CLOSED) {
WifiOprMidState apState = WifiConfigCenter::GetInstance().GetApMidState(0);
if (apState != WifiOprMidState::CLOSED) {
#ifdef WIFI_FEATURE_STA_AP_EXCLUSION
auto ret = DisableHotspot();
if (ret != WIFI_OPT_SUCCESS) {
return WIFI_OPT_STA_AP_EXCLUSION_AP_CLOSE_FAILED;
}
#else
WIFI_LOGW("current ap state is %{public}d, please close SoftAp first!",
static_cast<int>(curState));
return WIFI_OPT_NOT_SUPPORTED;
#endif
}
#endif
@ -328,7 +335,7 @@ ErrCode WifiDeviceServiceImpl::DisableWifi()
#endif
if (!WifiConfigCenter::GetInstance().SetWifiMidState(curState, WifiOprMidState::CLOSING)) {
WIFI_LOGI("set wifi mid state opening failed! may be other activity has been operated");
WIFI_LOGI("set wifi mid state opening failed! may be other app has been operated");
return WIFI_OPT_CLOSE_SUCC_WHEN_CLOSED;
}
IStaService *pService = WifiServiceManager::GetInstance().GetStaServiceInst();
@ -1378,6 +1385,38 @@ ErrCode WifiDeviceServiceImpl::Get5GHzChannelList(std::vector<int> &result)
return WIFI_OPT_SUCCESS;
}
#ifdef WIFI_FEATURE_STA_AP_EXCLUSION
ErrCode WifiDeviceServiceImpl::DisableHotspot()
{
WIFI_LOGI("enter disableHotspot");
WifiOprMidState curState = WifiConfigCenter::GetInstance().GetApMidState(0);
if (curState != WifiOprMidState::RUNNING) {
WIFI_LOGE("current ap state is %{public}d", static_cast<int>(curState));
if (curState == WifiOprMidState::OPENING) { /* when ap is opening, return */
return WIFI_OPT_CLOSE_FAIL_WHEN_OPENING;
} else {
return WIFI_OPT_CLOSE_SUCC_WHEN_CLOSED;
}
}
if (!WifiConfigCenter::GetInstance().SetApMidState(curState, WifiOprMidState::CLOSING, 0)) {
WIFI_LOGI("set ap mid state closing failed! may be other app has been operated");
return WIFI_OPT_CLOSE_SUCC_WHEN_CLOSED;
}
IApService *apService = WifiServiceManager::GetInstance().GetApServiceInst(0);
if (apService == nullptr) {
WIFI_LOGE("ap service instant 0 is null");
return WIFI_OPT_AP_NOT_OPENED;
}
auto ret = apService->DisableHotspot();
if (ret != WIFI_OPT_SUCCESS) {
WIFI_LOGE("apService disable hotspot failed");
return ret;
}
sleep(1);
return WIFI_OPT_SUCCESS;
}
#endif
#ifndef OHOS_ARCH_LITE
int32_t WifiDeviceServiceImpl::Dump(int32_t fd, const std::vector<std::u16string>& args)
{

View File

@ -180,6 +180,9 @@ private:
void UnRegisterAppRemoved();
void RegisterThermalLevel();
void UnRegisterThermalLevel();
#ifdef WIFI_FEATURE_STA_AP_EXCLUSION
ErrCode DisableHotspot();
#endif
#endif
private:

View File

@ -326,9 +326,16 @@ ErrCode WifiHotspotServiceImpl::CheckCanEnableHotspot(const ServiceType type)
WifiOprMidState curState = WifiConfigCenter::GetInstance().GetWifiMidState();
if (curState != WifiOprMidState::CLOSED) {
#ifdef WIFI_FEATURE_STA_AP_EXCLUSION
auto ret = DisableWifi();
if (ret != WIFI_OPT_SUCCESS) {
return WIFI_OPT_STA_AP_EXCLUSION_STA_CLOSE_FAILED;
}
#else
WIFI_LOGI("current wifi state is %{public}d, please close sta first!",
static_cast<int>(curState));
return WIFI_OPT_NOT_SUPPORTED;
#endif
}
return WIFI_OPT_SUCCESS;
}
@ -742,5 +749,55 @@ bool WifiHotspotServiceImpl::IsRemoteDied(void)
{
return false;
}
#ifdef WIFI_FEATURE_STA_AP_EXCLUSION
ErrCode WifiHotspotServiceImpl::DisableWifi()
{
WifiOprMidState curState = WifiConfigCenter::GetInstance().GetWifiMidState();
if (curState != WifiOprMidState::RUNNING) {
WIFI_LOGI("current wifi state is %{public}d", static_cast<int>(curState));
if (curState == WifiOprMidState::OPENING) { /* when current wifi is opening, return */
return WIFI_OPT_CLOSE_FAIL_WHEN_OPENING;
} else {
return WIFI_OPT_CLOSE_SUCC_WHEN_CLOSED;
}
}
#ifdef FEATURE_P2P_SUPPORT
sptr<WifiP2pServiceImpl> p2pService = WifiP2pServiceImpl::GetInstance();
if (p2pService != nullptr && p2pService->DisableP2p() != WIFI_OPT_SUCCESS) {
WIFI_LOGE("Disable P2p failed!");
return WIFI_OPT_FAILED;
}
#endif
if (!WifiConfigCenter::GetInstance().SetWifiMidState(curState, WifiOprMidState::CLOSING)) {
WIFI_LOGI("set wifi mid state opening failed! may be other activity has been operated");
return WIFI_OPT_CLOSE_SUCC_WHEN_CLOSED;
}
IStaService *pService = WifiServiceManager::GetInstance().GetStaServiceInst();
if (pService == nullptr) {
WifiConfigCenter::GetInstance().SetWifiMidState(WifiOprMidState::CLOSED);
WifiServiceManager::GetInstance().UnloadService(WIFI_SERVICE_STA);
return WIFI_OPT_SUCCESS;
}
ErrCode ret = pService->DisableWifi();
if (ret != WIFI_OPT_SUCCESS) {
WifiConfigCenter::GetInstance().SetWifiMidState(WifiOprMidState::CLOSING, WifiOprMidState::RUNNING);
} else {
WifiConfigCenter::GetInstance().SetStaLastRunState(false);
WifiManager::GetInstance().GetAirplaneModeByDatashare(WIFI_DEVICE_ABILITY_ID);
if (WifiConfigCenter::GetInstance().GetOperatorWifiType() ==
static_cast<int>(OperatorWifiType::USER_OPEN_WIFI_IN_AIRPLANEMODE) &&
WifiConfigCenter::GetInstance().GetAirplaneModeState() == MODE_STATE_OPEN) {
WifiConfigCenter::GetInstance().SetOperatorWifiType(
static_cast<int>(OperatorWifiType::USER_CLOSE_WIFI_IN_AIRPLANEMODE));
WIFI_LOGI("EnableWifi, current airplane mode is opened, user close wifi!");
}
}
sleep(1);
return ret;
}
#endif
} // namespace Wifi
} // namespace OHOS

View File

@ -209,10 +209,13 @@ private:
static void StationsInfoDump(std::string& result);
static void SigHandler(int sig);
static bool IsProcessNeedToRestart();
#ifdef WIFI_FEATURE_STA_AP_EXCLUSION
ErrCode DisableWifi();
#endif
private:
bool mGetChannels = false;
};
} // namespace Wifi
} // namespace OHOS
#endif
#endif

View File

@ -33,4 +33,5 @@ declare_args() {
defined(global_parts_info.resourceschedule_efficiency_manager)) {
wifi_feature_with_app_frozen = true
}
wifi_feature_sta_ap_exclusion = true
}