From 596a1f4c40b515267e65f41670a2960a6e039c6c Mon Sep 17 00:00:00 2001 From: Wuhongbo Date: Wed, 3 Jan 2024 10:26:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E9=87=8D=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Wuhongbo --- .../wifi_p2p_sa/wifi_p2p_service_impl.cpp | 330 ++++-------------- .../wifi_p2p_sa/wifi_p2p_service_impl.h | 2 + .../wifi_sta/wifip2pstub_fuzzer/BUILD.gn | 1 + 3 files changed, 78 insertions(+), 255 deletions(-) diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p_sa/wifi_p2p_service_impl.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p_sa/wifi_p2p_service_impl.cpp index b2e981c6b..b4bf0b3db 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p_sa/wifi_p2p_service_impl.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p_sa/wifi_p2p_service_impl.cpp @@ -227,17 +227,25 @@ ErrCode WifiP2pServiceImpl::DiscoverDevices(void) #endif } + IP2pService *pService = nullptr; + if (CheckP2pCanOpt(pService) != WIFI_OPT_SUCCESS) { + return WIFI_OPT_P2P_NOT_OPENED; + } + return pService->DiscoverDevices(); +} + +ErrCode WifiP2pServiceImpl::CheckP2pCanOpt(IP2pService *pService) +{ if (!IsP2pServiceRunning()) { WIFI_LOGE("P2pService is not running!"); return WIFI_OPT_P2P_NOT_OPENED; } - - IP2pService *pService = WifiServiceManager::GetInstance().GetP2pServiceInst(); + pService = WifiServiceManager::GetInstance().GetP2pServiceInst(); if (pService == nullptr) { WIFI_LOGE("Get P2P service failed!"); return WIFI_OPT_P2P_NOT_OPENED; } - return pService->DiscoverDevices(); + return WIFI_OPT_SUCCESS; } ErrCode WifiP2pServiceImpl::StopDiscoverDevices(void) @@ -248,14 +256,8 @@ ErrCode WifiP2pServiceImpl::StopDiscoverDevices(void) return WIFI_OPT_PERMISSION_DENIED; } - if (!IsP2pServiceRunning()) { - WIFI_LOGE("P2pService is not running!"); - return WIFI_OPT_P2P_NOT_OPENED; - } - - IP2pService *pService = WifiServiceManager::GetInstance().GetP2pServiceInst(); - if (pService == nullptr) { - WIFI_LOGE("Get P2P service failed!"); + IP2pService *pService = nullptr; + if (!CheckP2pCanOpt(pService)) { return WIFI_OPT_P2P_NOT_OPENED; } return pService->StopDiscoverDevices(); @@ -269,14 +271,8 @@ ErrCode WifiP2pServiceImpl::DiscoverServices(void) return WIFI_OPT_PERMISSION_DENIED; } - if (!IsP2pServiceRunning()) { - WIFI_LOGE("P2pService is not running!"); - return WIFI_OPT_P2P_NOT_OPENED; - } - - IP2pService *pService = WifiServiceManager::GetInstance().GetP2pServiceInst(); - if (pService == nullptr) { - WIFI_LOGE("Get P2P service failed!"); + IP2pService *pService = nullptr; + if (!CheckP2pCanOpt(pService)) { return WIFI_OPT_P2P_NOT_OPENED; } return pService->DiscoverServices(); @@ -289,14 +285,8 @@ ErrCode WifiP2pServiceImpl::StopDiscoverServices(void) WIFI_LOGE("StopDiscoverServices:NOT NATIVE PROCESS, PERMISSION_DENIED!"); return WIFI_OPT_PERMISSION_DENIED; } - if (!IsP2pServiceRunning()) { - WIFI_LOGE("P2pService is not running!"); - return WIFI_OPT_P2P_NOT_OPENED; - } - - IP2pService *pService = WifiServiceManager::GetInstance().GetP2pServiceInst(); - if (pService == nullptr) { - WIFI_LOGE("Get P2P service failed!"); + IP2pService *pService = nullptr; + if (!CheckP2pCanOpt(pService)) { return WIFI_OPT_P2P_NOT_OPENED; } return pService->StopDiscoverServices(); @@ -310,14 +300,8 @@ ErrCode WifiP2pServiceImpl::RequestService(const WifiP2pDevice &device, const Wi return WIFI_OPT_PERMISSION_DENIED; } - if (!IsP2pServiceRunning()) { - WIFI_LOGE("P2pService is not running!"); - return WIFI_OPT_P2P_NOT_OPENED; - } - - IP2pService *pService = WifiServiceManager::GetInstance().GetP2pServiceInst(); - if (pService == nullptr) { - WIFI_LOGE("Get P2P service failed!"); + IP2pService *pService = nullptr; + if (!CheckP2pCanOpt(pService)) { return WIFI_OPT_P2P_NOT_OPENED; } return pService->RequestService(device, request); @@ -330,14 +314,8 @@ ErrCode WifiP2pServiceImpl::PutLocalP2pService(const WifiP2pServiceInfo &srvInfo WIFI_LOGE("PutLocalP2pService:VerifyGetWifiInfoInternalPermission PERMISSION_DENIED!"); return WIFI_OPT_PERMISSION_DENIED; } - if (!IsP2pServiceRunning()) { - WIFI_LOGE("P2pService is not running!"); - return WIFI_OPT_P2P_NOT_OPENED; - } - - IP2pService *pService = WifiServiceManager::GetInstance().GetP2pServiceInst(); - if (pService == nullptr) { - WIFI_LOGE("Get P2P service failed!"); + IP2pService *pService = nullptr; + if (!CheckP2pCanOpt(pService)) { return WIFI_OPT_P2P_NOT_OPENED; } return pService->PutLocalP2pService(srvInfo); @@ -350,14 +328,8 @@ ErrCode WifiP2pServiceImpl::DeleteLocalP2pService(const WifiP2pServiceInfo &srvI WIFI_LOGE("DeleteLocalP2pService:VerifyGetWifiInfoInternalPermission PERMISSION_DENIED!"); return WIFI_OPT_PERMISSION_DENIED; } - if (!IsP2pServiceRunning()) { - WIFI_LOGE("P2pService is not running!"); - return WIFI_OPT_P2P_NOT_OPENED; - } - - IP2pService *pService = WifiServiceManager::GetInstance().GetP2pServiceInst(); - if (pService == nullptr) { - WIFI_LOGE("Get P2P service failed!"); + IP2pService *pService = nullptr; + if (!CheckP2pCanOpt(pService)) { return WIFI_OPT_P2P_NOT_OPENED; } return pService->DeleteLocalP2pService(srvInfo); @@ -371,14 +343,8 @@ ErrCode WifiP2pServiceImpl::StartP2pListen(int period, int interval) return WIFI_OPT_PERMISSION_DENIED; } - if (!IsP2pServiceRunning()) { - WIFI_LOGE("P2pService is not running!"); - return WIFI_OPT_P2P_NOT_OPENED; - } - - IP2pService *pService = WifiServiceManager::GetInstance().GetP2pServiceInst(); - if (pService == nullptr) { - WIFI_LOGE("Get P2P service failed!"); + IP2pService *pService = nullptr; + if (!CheckP2pCanOpt(pService)) { return WIFI_OPT_P2P_NOT_OPENED; } return pService->StartP2pListen(period, interval); @@ -392,14 +358,8 @@ ErrCode WifiP2pServiceImpl::StopP2pListen() return WIFI_OPT_PERMISSION_DENIED; } - if (!IsP2pServiceRunning()) { - WIFI_LOGE("P2pService is not running!"); - return WIFI_OPT_P2P_NOT_OPENED; - } - - IP2pService *pService = WifiServiceManager::GetInstance().GetP2pServiceInst(); - if (pService == nullptr) { - WIFI_LOGE("Get P2P service failed!"); + IP2pService *pService = nullptr; + if (!CheckP2pCanOpt(pService)) { return WIFI_OPT_P2P_NOT_OPENED; } return pService->StopP2pListen(); @@ -422,14 +382,8 @@ ErrCode WifiP2pServiceImpl::CreateGroup(const WifiP2pConfig &config) return WIFI_OPT_INVALID_PARAM; } - if (!IsP2pServiceRunning()) { - WIFI_LOGE("P2pService is not running!"); - return WIFI_OPT_P2P_NOT_OPENED; - } - - IP2pService *pService = WifiServiceManager::GetInstance().GetP2pServiceInst(); - if (pService == nullptr) { - WIFI_LOGE("Get P2P service failed!"); + IP2pService *pService = nullptr; + if (!CheckP2pCanOpt(pService)) { return WIFI_OPT_P2P_NOT_OPENED; } return pService->CreateGroup(config); @@ -443,14 +397,8 @@ ErrCode WifiP2pServiceImpl::RemoveGroup() return WIFI_OPT_PERMISSION_DENIED; } - if (!IsP2pServiceRunning()) { - WIFI_LOGE("P2pService is not running!"); - return WIFI_OPT_P2P_NOT_OPENED; - } - - IP2pService *pService = WifiServiceManager::GetInstance().GetP2pServiceInst(); - if (pService == nullptr) { - WIFI_LOGE("Get P2P service failed!"); + IP2pService *pService = nullptr; + if (!CheckP2pCanOpt(pService)) { return WIFI_OPT_P2P_NOT_OPENED; } WifiP2pGroupInfo config; @@ -480,14 +428,8 @@ ErrCode WifiP2pServiceImpl::DeleteGroup(const WifiP2pGroupInfo &group) return WIFI_OPT_PERMISSION_DENIED; } - if (!IsP2pServiceRunning()) { - WIFI_LOGE("P2pService is not running!"); - return WIFI_OPT_P2P_NOT_OPENED; - } - - IP2pService *pService = WifiServiceManager::GetInstance().GetP2pServiceInst(); - if (pService == nullptr) { - WIFI_LOGE("Get P2P service failed!"); + IP2pService *pService = nullptr; + if (!CheckP2pCanOpt(pService)) { return WIFI_OPT_P2P_NOT_OPENED; } return pService->DeleteGroup(group); @@ -523,9 +465,8 @@ ErrCode WifiP2pServiceImpl::P2pConnect(const WifiP2pConfig &config) WIFI_LOGE("P2pConnect:VerifyPassphrase failed!"); return WIFI_OPT_INVALID_PARAM; } - - if (!IsP2pServiceRunning()) { - WIFI_LOGE("P2pService is not running!"); + IP2pService *pService = nullptr; + if (!CheckP2pCanOpt(pService)) { return WIFI_OPT_P2P_NOT_OPENED; } WifiP2pConfig updateConfig = config; @@ -559,12 +500,6 @@ ErrCode WifiP2pServiceImpl::P2pConnect(const WifiP2pConfig &config) WIFI_LOGW("invalid mac address"); } #endif - - IP2pService *pService = WifiServiceManager::GetInstance().GetP2pServiceInst(); - if (pService == nullptr) { - WIFI_LOGE("Get P2P service failed!"); - return WIFI_OPT_P2P_NOT_OPENED; - } WriteP2pKpiCountHiSysEvent(static_cast(P2P_CHR_EVENT::CONN_CNT)); return pService->P2pConnect(updateConfig); } @@ -577,14 +512,8 @@ ErrCode WifiP2pServiceImpl::P2pCancelConnect() return WIFI_OPT_PERMISSION_DENIED; } - if (!IsP2pServiceRunning()) { - WIFI_LOGE("P2pService is not running!"); - return WIFI_OPT_P2P_NOT_OPENED; - } - - IP2pService *pService = WifiServiceManager::GetInstance().GetP2pServiceInst(); - if (pService == nullptr) { - WIFI_LOGE("Get P2P service failed!"); + IP2pService *pService = nullptr; + if (!CheckP2pCanOpt(pService)) { return WIFI_OPT_P2P_NOT_OPENED; } return pService->P2pCancelConnect(); @@ -599,14 +528,8 @@ ErrCode WifiP2pServiceImpl::QueryP2pLinkedInfo(WifiP2pLinkedInfo &linkedInfo) return WIFI_OPT_PERMISSION_DENIED; } - if (!IsP2pServiceRunning()) { - WIFI_LOGE("P2pService is not running!"); - return WIFI_OPT_P2P_NOT_OPENED; - } - - IP2pService *pService = WifiServiceManager::GetInstance().GetP2pServiceInst(); - if (pService == nullptr) { - WIFI_LOGE("Get P2P service failed!"); + IP2pService *pService = nullptr; + if (!CheckP2pCanOpt(pService)) { return WIFI_OPT_P2P_NOT_OPENED; } @@ -640,14 +563,8 @@ ErrCode WifiP2pServiceImpl::GetCurrentGroup(WifiP2pGroupInfo &group) #endif } - if (!IsP2pServiceRunning()) { - WIFI_LOGE("P2pService is not running!"); - return WIFI_OPT_P2P_NOT_OPENED; - } - - IP2pService *pService = WifiServiceManager::GetInstance().GetP2pServiceInst(); - if (pService == nullptr) { - WIFI_LOGE("Get P2P service failed!"); + IP2pService *pService = nullptr; + if (!CheckP2pCanOpt(pService)) { return WIFI_OPT_P2P_NOT_OPENED; } ErrCode errCode = pService->GetCurrentGroup(group); @@ -707,14 +624,8 @@ ErrCode WifiP2pServiceImpl::GetP2pDiscoverStatus(int &status) WIFI_LOGE("GetP2pDiscoverStatus:VerifyGetWifiInfoInternalPermission PERMISSION_DENIED!"); return WIFI_OPT_PERMISSION_DENIED; } - if (!IsP2pServiceRunning()) { - WIFI_LOGE("P2pService is not running!"); - return WIFI_OPT_P2P_NOT_OPENED; - } - - IP2pService *pService = WifiServiceManager::GetInstance().GetP2pServiceInst(); - if (pService == nullptr) { - WIFI_LOGE("Get P2P service failed!"); + IP2pService *pService = nullptr; + if (!CheckP2pCanOpt(pService)) { return WIFI_OPT_P2P_NOT_OPENED; } return pService->GetP2pDiscoverStatus(status); @@ -727,14 +638,8 @@ ErrCode WifiP2pServiceImpl::GetP2pConnectedStatus(int &status) WIFI_LOGE("GetP2pConnectedStatus:NOT NATIVE PROCESS, PERMISSION_DENIED!"); return WIFI_OPT_PERMISSION_DENIED; } - if (!IsP2pServiceRunning()) { - WIFI_LOGE("P2pService is not running!"); - return WIFI_OPT_P2P_NOT_OPENED; - } - - IP2pService *pService = WifiServiceManager::GetInstance().GetP2pServiceInst(); - if (pService == nullptr) { - WIFI_LOGE("Get P2P service failed!"); + IP2pService *pService = nullptr; + if (!CheckP2pCanOpt(pService)) { return WIFI_OPT_P2P_NOT_OPENED; } return pService->GetP2pConnectedStatus(status); @@ -758,14 +663,8 @@ ErrCode WifiP2pServiceImpl::QueryP2pDevices(std::vector &devices) #endif } - if (!IsP2pServiceRunning()) { - WIFI_LOGE("P2pService is not running!"); - return WIFI_OPT_P2P_NOT_OPENED; - } - - IP2pService *pService = WifiServiceManager::GetInstance().GetP2pServiceInst(); - if (pService == nullptr) { - WIFI_LOGE("Get P2P service failed!"); + IP2pService *pService = nullptr; + if (!CheckP2pCanOpt(pService)) { return WIFI_OPT_P2P_NOT_OPENED; } ErrCode errCode = pService->QueryP2pDevices(devices); @@ -805,14 +704,8 @@ ErrCode WifiP2pServiceImpl::QueryP2pLocalDevice(WifiP2pDevice &device) return WIFI_OPT_PERMISSION_DENIED; } - if (!IsP2pServiceRunning()) { - WIFI_LOGE("P2pService is not runing!"); - return WIFI_OPT_P2P_NOT_OPENED; - } - - IP2pService *pService = WifiServiceManager::GetInstance().GetP2pServiceInst(); - if (pService == nullptr) { - WIFI_LOGE("Get P2P service failed!"); + IP2pService *pService = nullptr; + if (!CheckP2pCanOpt(pService)) { return WIFI_OPT_P2P_NOT_OPENED; } @@ -845,14 +738,8 @@ ErrCode WifiP2pServiceImpl::QueryP2pGroups(std::vector &groups } } - if (!IsP2pServiceRunning()) { - WIFI_LOGE("P2pService is not running!"); - return WIFI_OPT_P2P_NOT_OPENED; - } - - IP2pService *pService = WifiServiceManager::GetInstance().GetP2pServiceInst(); - if (pService == nullptr) { - WIFI_LOGE("Get P2P service failed!"); + IP2pService *pService = nullptr; + if (!CheckP2pCanOpt(pService)) { return WIFI_OPT_P2P_NOT_OPENED; } ErrCode errCode = pService->QueryP2pGroups(groups); @@ -904,14 +791,8 @@ ErrCode WifiP2pServiceImpl::QueryP2pServices(std::vector &se WIFI_LOGE("QueryP2pServices:VerifyGetWifiInfoInternalPermission PERMISSION_DENIED!"); return WIFI_OPT_PERMISSION_DENIED; } - if (!IsP2pServiceRunning()) { - WIFI_LOGE("P2pService is not running!"); - return WIFI_OPT_P2P_NOT_OPENED; - } - - IP2pService *pService = WifiServiceManager::GetInstance().GetP2pServiceInst(); - if (pService == nullptr) { - WIFI_LOGE("Get P2P service failed!"); + IP2pService *pService = nullptr; + if (!CheckP2pCanOpt(pService)) { return WIFI_OPT_P2P_NOT_OPENED; } return pService->QueryP2pServices(services); @@ -971,13 +852,8 @@ ErrCode WifiP2pServiceImpl::SetP2pDeviceName(const std::string &deviceName) return WIFI_OPT_INVALID_PARAM; } WifiConfigCenter::GetInstance().SetP2pDeviceName(deviceName); - if (!IsP2pServiceRunning()) { - WIFI_LOGE("P2pService is not running!"); - return WIFI_OPT_SUCCESS; - } - IP2pService *pService = WifiServiceManager::GetInstance().GetP2pServiceInst(); - if (pService == nullptr) { - WIFI_LOGE("Get P2P service failed!"); + IP2pService *pService = nullptr; + if (!CheckP2pCanOpt(pService)) { return WIFI_OPT_P2P_NOT_OPENED; } return pService->SetP2pDeviceName(deviceName); @@ -990,13 +866,8 @@ ErrCode WifiP2pServiceImpl::SetP2pWfdInfo(const WifiP2pWfdInfo &wfdInfo) WIFI_LOGE("SetP2pWfdInfo:VerifyGetWifiInfoInternalPermission PERMISSION_DENIED!"); return WIFI_OPT_PERMISSION_DENIED; } - if (!IsP2pServiceRunning()) { - WIFI_LOGE("P2pService is not running!"); - return WIFI_OPT_P2P_NOT_OPENED; - } - IP2pService *pService = WifiServiceManager::GetInstance().GetP2pServiceInst(); - if (pService == nullptr) { - WIFI_LOGE("Get P2P service failed!"); + IP2pService *pService = nullptr; + if (!CheckP2pCanOpt(pService)) { return WIFI_OPT_P2P_NOT_OPENED; } return pService->SetP2pWfdInfo(wfdInfo); @@ -1009,13 +880,8 @@ ErrCode WifiP2pServiceImpl::Hid2dRequestGcIp(const std::string& gcMac, std::stri WIFI_LOGE("Hid2dRequestGcIp:NOT NATIVE PROCESS, PERMISSION_DENIED!"); return WIFI_OPT_PERMISSION_DENIED; } - if (!IsP2pServiceRunning()) { - WIFI_LOGE("P2pService is not runing!"); - return WIFI_OPT_P2P_NOT_OPENED; - } - IP2pService *pService = WifiServiceManager::GetInstance().GetP2pServiceInst(); - if (pService == nullptr) { - WIFI_LOGE("Get P2P service failed!"); + IP2pService *pService = nullptr; + if (!CheckP2pCanOpt(pService)) { return WIFI_OPT_P2P_NOT_OPENED; } return pService->Hid2dRequestGcIp(gcMac, ipAddr); @@ -1054,13 +920,8 @@ ErrCode WifiP2pServiceImpl::Hid2dSharedlinkDecrease() WIFI_LOGE("Hid2dSharedlinkDecrease:NOT NATIVE PROCESS, PERMISSION_DENIED!"); return WIFI_OPT_PERMISSION_DENIED; } - if (!IsP2pServiceRunning()) { - WIFI_LOGE("P2pService is not runing!"); - return WIFI_OPT_P2P_NOT_OPENED; - } - IP2pService *pService = WifiServiceManager::GetInstance().GetP2pServiceInst(); - if (pService == nullptr) { - WIFI_LOGE("Get P2P service failed!"); + IP2pService *pService = nullptr; + if (!CheckP2pCanOpt(pService)) { return WIFI_OPT_P2P_NOT_OPENED; } if (pService->GetSharedLinkCount() > 0) { @@ -1081,14 +942,8 @@ ErrCode WifiP2pServiceImpl::Hid2dCreateGroup(const int frequency, FreqType type) return WIFI_OPT_PERMISSION_DENIED; } - if (!IsP2pServiceRunning()) { - WIFI_LOGE("P2pService is not running!"); - return WIFI_OPT_P2P_NOT_OPENED; - } - - IP2pService *pService = WifiServiceManager::GetInstance().GetP2pServiceInst(); - if (pService == nullptr) { - WIFI_LOGE("Get P2P service failed!"); + IP2pService *pService = nullptr; + if (!CheckP2pCanOpt(pService)) { return WIFI_OPT_P2P_NOT_OPENED; } WifiSettings::GetInstance().SetP2pBusinessType(P2pBusinessType::P2P_TYPE_HID2D); @@ -1110,14 +965,8 @@ ErrCode WifiP2pServiceImpl::Hid2dConnect(const Hid2dConnectConfig& config) return WIFI_OPT_PERMISSION_DENIED; } - if (!IsP2pServiceRunning()) { - WIFI_LOGE("P2pService is not running!"); - return WIFI_OPT_P2P_NOT_OPENED; - } - - IP2pService *pService = WifiServiceManager::GetInstance().GetP2pServiceInst(); - if (pService == nullptr) { - WIFI_LOGE("Get P2P service failed!"); + IP2pService *pService = nullptr; + if (!CheckP2pCanOpt(pService)) { return WIFI_OPT_P2P_NOT_OPENED; } WifiSettings::GetInstance().SetP2pBusinessType(P2pBusinessType::P2P_TYPE_HID2D); @@ -1156,13 +1005,8 @@ ErrCode WifiP2pServiceImpl::Hid2dGetRecommendChannel(const RecommendChannelReque WIFI_LOGE("Hid2dGetRecommendChannel:NOT NATIVE PROCESS, PERMISSION_DENIED!"); return WIFI_OPT_PERMISSION_DENIED; } - if (!IsP2pServiceRunning()) { - WIFI_LOGE("P2pService is not runing!"); - return WIFI_OPT_P2P_NOT_OPENED; - } - IP2pService *pService = WifiServiceManager::GetInstance().GetP2pServiceInst(); - if (pService == nullptr) { - WIFI_LOGE("Get P2P service failed!"); + IP2pService *pService = nullptr; + if (!CheckP2pCanOpt(pService)) { return WIFI_OPT_P2P_NOT_OPENED; } int channel = pService->GetP2pRecommendChannel(); @@ -1211,14 +1055,8 @@ ErrCode WifiP2pServiceImpl::Hid2dGetSelfWifiCfgInfo(SelfCfgType cfgType, WIFI_LOGE("Hid2dGetSelfWifiCfgInfo:NOT NATIVE PROCESS, PERMISSION_DENIED!"); return WIFI_OPT_PERMISSION_DENIED; } - if (!IsP2pServiceRunning()) { - WIFI_LOGE("P2pService is not runing!"); - return WIFI_OPT_P2P_NOT_OPENED; - } - - IP2pService *pService = WifiServiceManager::GetInstance().GetP2pServiceInst(); - if (pService == nullptr) { - WIFI_LOGE("Get P2P service failed!"); + IP2pService *pService = nullptr; + if (!CheckP2pCanOpt(pService)) { return WIFI_OPT_P2P_NOT_OPENED; } return pService->Hid2dGetSelfWifiCfgInfo(cfgType, cfgData, getDatValidLen); @@ -1232,14 +1070,8 @@ ErrCode WifiP2pServiceImpl::Hid2dSetPeerWifiCfgInfo(PeerCfgType cfgType, WIFI_LOGE("Hid2dSetPeerWifiCfgInfo:NOT NATIVE PROCESS, PERMISSION_DENIED!"); return WIFI_OPT_PERMISSION_DENIED; } - if (!IsP2pServiceRunning()) { - WIFI_LOGE("P2pService is not runing!"); - return WIFI_OPT_P2P_NOT_OPENED; - } - - IP2pService *pService = WifiServiceManager::GetInstance().GetP2pServiceInst(); - if (pService == nullptr) { - WIFI_LOGE("Get P2P service failed!"); + IP2pService *pService = nullptr; + if (!CheckP2pCanOpt(pService)) { return WIFI_OPT_P2P_NOT_OPENED; } return pService->Hid2dSetPeerWifiCfgInfo(cfgType, cfgData, setDataValidLen); @@ -1252,14 +1084,8 @@ ErrCode WifiP2pServiceImpl::Hid2dSetUpperScene(const std::string& ifName, const WIFI_LOGE("Hid2dSetUpperScene:NOT NATIVE PROCESS, PERMISSION_DENIED!"); return WIFI_OPT_PERMISSION_DENIED; } - if (!IsP2pServiceRunning()) { - WIFI_LOGE("P2pService is not runing!"); - return WIFI_OPT_P2P_NOT_OPENED; - } - - IP2pService *pService = WifiServiceManager::GetInstance().GetP2pServiceInst(); - if (pService == nullptr) { - WIFI_LOGE("Get P2P service failed!"); + IP2pService *pService = nullptr; + if (!CheckP2pCanOpt(pService)) { return WIFI_OPT_P2P_NOT_OPENED; } WifiSettings::GetInstance().SetHid2dUpperScene(ifName, scene); @@ -1269,14 +1095,8 @@ ErrCode WifiP2pServiceImpl::Hid2dSetUpperScene(const std::string& ifName, const ErrCode WifiP2pServiceImpl::MonitorCfgChange(void) { WIFI_LOGI("MonitorCfgChange"); - if (!IsP2pServiceRunning()) { - WIFI_LOGE("P2pService is not runing!"); - return WIFI_OPT_P2P_NOT_OPENED; - } - - IP2pService *pService = WifiServiceManager::GetInstance().GetP2pServiceInst(); - if (pService == nullptr) { - WIFI_LOGE("Get P2P service failed!"); + IP2pService *pService = nullptr; + if (!CheckP2pCanOpt(pService)) { return WIFI_OPT_P2P_NOT_OPENED; } return pService->MonitorCfgChange(); diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p_sa/wifi_p2p_service_impl.h b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p_sa/wifi_p2p_service_impl.h index da8261422..9a78863b0 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p_sa/wifi_p2p_service_impl.h +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p_sa/wifi_p2p_service_impl.h @@ -21,6 +21,7 @@ #include "system_ability.h" #include "wifi_p2p_stub.h" #include "iremote_object.h" +#include "ip2p_service.h" namespace OHOS { namespace Wifi { @@ -65,6 +66,7 @@ public: */ ErrCode StopDiscoverDevices(void) override; + ErrCode CheckP2pCanOpt(IP2pService *pService); /** * @Description Start the search for the Wi-Fi P2P service * diff --git a/wifi/test/fuzztest/wifi_sta/wifip2pstub_fuzzer/BUILD.gn b/wifi/test/fuzztest/wifi_sta/wifip2pstub_fuzzer/BUILD.gn index 2419e6e4d..f2604390a 100644 --- a/wifi/test/fuzztest/wifi_sta/wifip2pstub_fuzzer/BUILD.gn +++ b/wifi/test/fuzztest/wifi_sta/wifip2pstub_fuzzer/BUILD.gn @@ -26,6 +26,7 @@ ohos_fuzztest("WifiP2pStubFuzzTest") { "$WIFI_ROOT_DIR/frameworks/native/include", "$WIFI_ROOT_DIR/frameworks/native/interfaces", "$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage", + "$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p", "$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p_sa", "$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/net_helper", "$WIFI_ROOT_DIR/test/fuzztest/fuzz_common_func",