!1666 解决湖外扫描管控的问题

Merge pull request !1666 from likuanxin/master
This commit is contained in:
openharmony_ci 2024-01-03 12:41:28 +00:00 committed by Gitee
commit 720f801a49
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
5 changed files with 104 additions and 24 deletions

View File

@ -25,6 +25,8 @@
#include "wifi_hdi_wpa_proxy.h"
#include "servmgr_hdi.h"
#include "devmgr_hdi.h"
#include "hdf_remote_service.h"
#include "osal_mem.h"
#undef LOG_TAG
#define LOG_TAG "WifiHdiWpaProxy"
@ -37,21 +39,62 @@
const char *HDI_WPA_SERVICE_NAME = "wpa_interface_service";
static pthread_mutex_t g_wpaObjMutex = PTHREAD_MUTEX_INITIALIZER;
static unsigned int g_wpaRefCount = 0;
static unsigned int g_wpaRefCount = 0x0;
static struct IWpaInterface *g_wpaObj = NULL;
static struct HDIDeviceManager *g_devMgr = NULL;
static void ProxyOnRemoteDied(struct HdfDeathRecipient* recipient, struct HdfRemoteService* service)
{
LOGI("%{public}s enter", __func__);
if (recipient == NULL || service == NULL) {
LOGE("%{public}s input param is null", __func__);
HdiWpaResetGlobalObj();
return;
}
HdfRemoteServiceRemoveDeathRecipient(service, recipient);
HdfRemoteServiceRecycle(service);
if (recipient == NULL) {
LOGE("%{public}s param recipient is null", __func__);
HdiWpaResetGlobalObj();
return;
}
OsalMemFree(recipient);
recipient = NULL;
HdiWpaResetGlobalObj();
}
WifiErrorNo RegistHdfDeathCallBack()
{
struct HDIServiceManager* serviceMgr = HDIServiceManagerGet();
if (serviceMgr == NULL) {
LOGE("%{public}s: failed to get HDIServiceManager", __func__);
return WIFI_IDL_OPT_FAILED;
}
struct HdfRemoteService* remote = serviceMgr->GetService(serviceMgr, HDI_WPA_SERVICE_NAME);
HDIServiceManagerRelease(serviceMgr);
if (remote == NULL) {
LOGE("%{public}s: failed to get HdfRemoteService", __func__);
return WIFI_IDL_OPT_FAILED;
}
LOGI("%{public}s: success to get HdfRemoteService", __func__);
struct HdfDeathRecipient* recipient = (struct HdfDeathRecipient*)OsalMemCalloc(sizeof(struct HdfDeathRecipient));
recipient->OnRemoteDied = ProxyOnRemoteDied;
HdfRemoteServiceAddDeathRecipient(remote, recipient);
return WIFI_IDL_OPT_OK;
}
WifiErrorNo HdiWpaStart()
{
LOGI("HdiWpaStart start...");
pthread_mutex_lock(&g_wpaObjMutex);
if (g_wpaRefCount != 0) {
if (g_wpaRefCount != 0 && g_wpaObj != NULL && g_devMgr != NULL) {
++g_wpaRefCount;
pthread_mutex_unlock(&g_wpaObjMutex);
LOGI("%{public}s wpa ref count: %d", __func__, g_wpaRefCount);
LOGI("%{public}s wpa ref count: %{public}d", __func__, g_wpaRefCount);
return WIFI_IDL_OPT_OK;
} else {
g_wpaRefCount = 0x0;
}
g_devMgr = HDIDeviceManagerGet();
if (g_devMgr == NULL) {
pthread_mutex_unlock(&g_wpaObjMutex);
@ -65,7 +108,6 @@ WifiErrorNo HdiWpaStart()
LOGE("%{public}s LoadDevice failed", __func__);
return WIFI_IDL_OPT_FAILED;
}
g_wpaObj = IWpaInterfaceGetInstance(HDI_WPA_SERVICE_NAME, false);
if (g_wpaObj == NULL) {
g_devMgr->UnloadDevice(g_devMgr, HDI_WPA_SERVICE_NAME);
@ -85,8 +127,8 @@ WifiErrorNo HdiWpaStart()
pthread_mutex_unlock(&g_wpaObjMutex);
return WIFI_IDL_OPT_FAILED;
}
++g_wpaRefCount;
RegistHdfDeathCallBack();
pthread_mutex_unlock(&g_wpaObjMutex);
LOGI("HdiWpaStart is started");
return WIFI_IDL_OPT_OK;
@ -97,6 +139,7 @@ WifiErrorNo HdiWpaStop()
LOGI("HdiWpaStop stop...");
pthread_mutex_lock(&g_wpaObjMutex);
if (g_wpaObj == NULL || g_wpaRefCount == 0) {
g_wpaRefCount = 0x0;
pthread_mutex_unlock(&g_wpaObjMutex);
LOGE("%{public}s g_wpaObj is NULL or ref count is 0", __func__);
return WIFI_IDL_OPT_FAILED;
@ -259,4 +302,13 @@ WifiErrorNo CopyConfigFile(const char* configName)
LOGE("Copy config file failed: %{public}s", configName);
return WIFI_IDL_OPT_FAILED;
}
void HdiWpaResetGlobalObj()
{
g_wpaRefCount = 0;
g_wpaObj = NULL;
g_devMgr = NULL;
LOGE("%{public}s reset wpa g_wpaObj", __func__);
HdiWpaStart();
}
#endif

View File

@ -111,6 +111,8 @@ WifiErrorNo CopyUserFile(const char *srcFilePath, const char* destFilePath);
*/
WifiErrorNo CopyConfigFile(const char* configName);
void HdiWpaResetGlobalObj();
#ifdef __cplusplus
}
#endif

View File

@ -93,6 +93,7 @@ int32_t OnEventStateChanged(struct IWpaCallback *self,
if (cbk.onWpaStateChanged) {
cbk.onWpaStateChanged(statechangedParam->status);
}
LOGI("OnEventStateChanged:callback out status = %{public}d", statechangedParam->status);
return 0;
}

View File

@ -39,6 +39,7 @@ WifiStaHalInterface &WifiStaHalInterface::GetInstance(void)
initFlag = 1;
}
#endif
#ifdef HDI_INTERFACE_SUPPORT
if (inst.InitHdiClient()) {
initFlag = 1;
@ -51,38 +52,45 @@ WifiStaHalInterface &WifiStaHalInterface::GetInstance(void)
WifiErrorNo WifiStaHalInterface::StartWifi(void)
{
WifiErrorNo ret = WIFI_IDL_OPT_OK;
int32_t ret = WIFI_IDL_OPT_OK;
#ifdef HDI_WPA_INTERFACE_SUPPORT
CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_IDL_OPT_FAILED);
ret = mHdiWpaClient->StartWifi();
ret |= mHdiWpaClient->StartWifi();
#else
CHECK_NULL_AND_RETURN(mIdlClient, WIFI_IDL_OPT_FAILED);
ret = mIdlClient->StartWifi();
ret |= mIdlClient->StartWifi();
#endif
#ifdef HDI_INTERFACE_SUPPORT
CHECK_NULL_AND_RETURN(mHdiClient, WIFI_IDL_OPT_FAILED);
ret = mHdiClient->StartWifi();
ret |= mHdiClient->StartWifi();
#endif
return ret;
if (ret != WIFI_IDL_OPT_OK) {
return WIFI_IDL_OPT_FAILED;
}
return WIFI_IDL_OPT_OK;
}
WifiErrorNo WifiStaHalInterface::StopWifi(void)
{
WifiErrorNo ret = WIFI_IDL_OPT_OK;
#ifdef HDI_WPA_INTERFACE_SUPPORT
CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_IDL_OPT_FAILED);
ret = mHdiWpaClient->StopWifi();
#else
CHECK_NULL_AND_RETURN(mIdlClient, WIFI_IDL_OPT_FAILED);
ret = mIdlClient->StopWifi();
#endif
int32_t ret = WIFI_IDL_OPT_OK;
#ifdef HDI_INTERFACE_SUPPORT
CHECK_NULL_AND_RETURN(mHdiClient, WIFI_IDL_OPT_FAILED);
ret = mHdiClient->StopWifi();
ret |= mHdiClient->StopWifi();
#endif
return ret;
#ifdef HDI_WPA_INTERFACE_SUPPORT
CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_IDL_OPT_FAILED);
ret |= mHdiWpaClient->StopWifi();
#else
CHECK_NULL_AND_RETURN(mIdlClient, WIFI_IDL_OPT_FAILED);
ret |= mIdlClient->StopWifi();
#endif
if (ret != WIFI_IDL_OPT_OK) {
return WIFI_IDL_OPT_FAILED;
}
return WIFI_IDL_OPT_OK;
}
WifiErrorNo WifiStaHalInterface::Connect(int networkId)

View File

@ -31,6 +31,9 @@ DEFINE_WIFILOG_SCAN_LABEL("ScanService");
namespace OHOS {
namespace Wifi {
constexpr const char *ANCO_SERVICE_BROKER = "anco_service_broker";
ScanService::ScanService(int instId)
: pScanStateMachine(nullptr),
pScanMonitor(nullptr),
@ -1249,7 +1252,14 @@ ErrCode ScanService::AllowExternScan()
WIFI_LOGW("extern scan not allow by power idel state");
return WIFI_OPT_FAILED;
}
#ifndef OHOS_ARCH_LITE
const std::string wifiBrokerFrameProcessName = ANCO_SERVICE_BROKER;
std::string ancoBrokerFrameProcessName = GetRunningProcessNameByPid(GetCallingUid(), GetCallingPid());
if (ancoBrokerFrameProcessName != wifiBrokerFrameProcessName) {
LOGD("ScanService AllowExternScan %{public}s!", ANCO_SERVICE_BROKER);
return WIFI_OPT_SUCCESS;
}
#endif
if (!AllowExternScanByThermal()) {
WIFI_LOGW("extern scan not allow by thermal level");
return WIFI_OPT_FAILED;
@ -1322,7 +1332,14 @@ ErrCode ScanService::AllowExternScan()
int staScene = GetStaScene();
ScanMode scanMode = WifiSettings::GetInstance().GetAppRunningState();
WIFI_LOGI("AllowExternScan, staScene is %{public}d, scanMode is %{public}d", staScene, (int)scanMode);
#ifndef OHOS_ARCH_LITE
const std::string wifiBrokerFrameProcessName = ANCO_SERVICE_BROKER;
std::string ancoBrokerFrameProcessName = GetRunningProcessNameByPid(GetCallingUid(), GetCallingPid());
if (ancoBrokerFrameProcessName != wifiBrokerFrameProcessName) {
LOGD("ScanService AllowExternScan %{public}s!", ANCO_SERVICE_BROKER);
return WIFI_OPT_SUCCESS;
}
#endif
if (!AllowExternScanByThermal()) {
WIFI_LOGW("extern scan not allow by thermal level");
return WIFI_OPT_FAILED;