rx listen

Signed-off-by: wujun <2019125625@qq.com>
This commit is contained in:
wujun 2023-12-06 17:54:55 +08:00
parent 8e777276bd
commit 34c8a8f73c
12 changed files with 753 additions and 1 deletions

View File

@ -173,6 +173,7 @@ if (defined(ohos_lite)) {
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_power_saving",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/hid2d",
"$WIFI_ROOT_DIR/utils/inc",
@ -443,6 +444,7 @@ if (defined(ohos_lite)) {
"$WIFI_ROOT_DIR/services/wifi_standard/etc/init:etc",
"$WIFI_ROOT_DIR/services/wifi_standard/etc/param:etc",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_native:wifi_native",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_pawer_saving:wifi_power_saving_service",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit:wifi_toolkit",
"$WIFI_ROOT_DIR/utils:wifi_utils",
]
@ -537,6 +539,10 @@ if (defined(ohos_lite)) {
defines += [ "FEATURE_HPF_SUPPORT" ]
}
if (wifi_feature_with_rx_listen_supported) {
defines += [ "FEATURE_RX_LISTEN_SUPPORT" ]
}
part_name = "wifi"
subsystem_name = "communication"
}

View File

@ -0,0 +1,108 @@
/*
* Copyright (C) 2023-2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
if (defined(ohos_lite)) {
import("//build/lite/config/component/lite_component.gni")
import("//foundation/communication/wifi/wifi/wifi_lite.gni")
} else {
import("//build/ohos.gni")
import("//foundation/communication/wifi/wifi/wifi.gni")
}
local_base_sources = [
"wifi_power_cmd_client.cpp",
"rx_listen/wifi_rx_listen_arbitration.cpp",
]
local_base_include_dirs = [
"$WIFI_ROOT_DIR/interfaces/inner_api",
"$WIFI_ROOT_DIR/frameworks/native/interfaces",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_power_saving",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_power_saving/rx_listen",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/net_helper",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/include",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/utils",
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit/log",
"//foundation/appexecfwk/adapter/interfaces/innerkits/appexecfwk_base/include",
]
if (defined(ohos_lite)) {
shared_library("wifi_power_saving_service") {
sources = local_base_sources
include_dirs = local_base_include_dirs
deps = [
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit:wifi_toolkit",
"$WIFI_ROOT_DIR/utils:wifi_utils",
]
external_deps = [
"hilog:libhilog",
"init:libbegetutil",
"c_utils:utils",
"ability_runtime:app_manager",
]
configs -= [ "//build/lite/config:language_cpp" ]
cflags_cc = [
"-std=c++17",
"-fno-rtti",
]
defines = [ "OHOS_ARCH_LITE" ]
ldflags = [
"-fPIC",
"-Wl,-E",
]
}
} else {
ohos_shared_library("wifi_power_saving_service") {
branch_protector_ret = "pac_ret"
sanitize = {
cfi = true
boundary_sanitize = true
cfi_cross_dso = true
debug = false
}
install_enable = true
sources = local_base_sources
include_dirs = local_base_include_dirs
cflags_cc = [
"-std=c++17",
"-fno-rtti",
]
ldflags = [
"-fPIC",
"-Wl,-E",
]
deps = [
"$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit:wifi_toolkit",
"$WIFI_ROOT_DIR/utils:wifi_utils",
]
external_deps = [
"hilog:libhilog",
"init:libbegetutil",
"c_utils:utils",
"ability_runtime:app_manager",
]
part_name = "wifi"
subsystem_name = "communication"
}
}

View File

@ -0,0 +1,88 @@
/*
* Copyright (C) 2023-2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "wifi_rx_listen_arbitration.h"
#include "wifi_logger.h"
#include "wifi_power_cmd_client.h"
#include "app_parser.h"
namespace OHOS {
namespace Wifi {
DEFINE_WIFILOG_LABEL("WifiRxListen");
static const int SHIFT_BIT_UTIL = 1;
static const int GAME_APP_SHIFT = 0;
static const int RX_LISTEN_SWITCH_LEN = 1;
static const auto ENABLE_RX_LISTEN = "Y";
static const auto DISABLE_RX_LISTEN = "N";
RxListenArbitration::RxListenArbitration()
{
WIFI_LOGI("%{public}s enter", __FUNCTION__);
}
RxListenArbitration::~RxListenArbitration()
{
WIFI_LOGI("%{public}s enter", __FUNCTION__);
}
RxListenArbitration &RxListenArbitration::GetInstance()
{
static RxListenArbitration instance;
return instance;
}
void RxListenArbitration::OnForegroundAppChanged(const AppExecFwk::AppStateData &appStateData)
{
if (appStateData.state == static_cast<int>(AppExecFwk::ApplicationState::APP_STATE_FOREGROUND) &&
appStateData.isFocused) {
WIFI_LOGD("%{public}s enter rx_listen arbitration, appName: %{public}s", __FUNCTION__,
appStateData.bundleName.c_str());
if (AppParser::GetInstance().IsGameApp(appStateData.bundleName)) {
// game scene: set m_arbitrationCond to zero to enable rx_listen
m_arbitrationCond = m_arbitrationCond | (SHIFT_BIT_UTIL << GAME_APP_SHIFT);
} else {
// not game scene: set m_arbitrationCond to one to disable rx_listen
m_arbitrationCond = m_arbitrationCond & (~(SHIFT_BIT_UTIL << GAME_APP_SHIFT));
}
CheckRxListenSwitch();
}
}
void RxListenArbitration::CheckRxListenSwitch()
{
if ((m_arbitrationCond == 0) && !m_isRxListenOn) {
if (WifiPowerCmdClient::GetInstance().SendCmdToDriver(WIFI_IFNAME, CMD_SET_RX_LISTEN_POWER_SAVING_SWITCH,
ENABLE_RX_LISTEN, RX_LISTEN_SWITCH_LEN) != 0) {
WIFI_LOGE("%{public}s enable rx_listen fail", __FUNCTION__);
return;
}
m_isRxListenOn = true;
WIFI_LOGD("%{public}s enable rx_listen successful", __FUNCTION__);
} else if ((m_arbitrationCond != 0) && m_isRxListenOn) {
if (WifiPowerCmdClient::GetInstance().SendCmdToDriver(WIFI_IFNAME, CMD_SET_RX_LISTEN_POWER_SAVING_SWITCH,
DISABLE_RX_LISTEN, RX_LISTEN_SWITCH_LEN) != 0) {
WIFI_LOGE("%{public}s disable rx_listen fail", __FUNCTION__);
return;
}
m_isRxListenOn = false;
WIFI_LOGD("%{public}s disable rx_listen successful", __FUNCTION__);
} else {
WIFI_LOGD("%{public}s no switch", __FUNCTION__);
}
}
} // namespace Wifi
} // namespace OHOS

View File

@ -0,0 +1,42 @@
/*
* Copyright (C) 2023-2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <string>
#include "app_mgr_interface.h"
#include "app_mgr_constants.h"
#ifndef OHOS_WIFI_POWER_RX_LISTEN_H
#define OHOS_WIFI_POWER_RX_LISTEN_H
namespace OHOS {
namespace Wifi {
class RxListenArbitration {
public:
RxListenArbitration();
~RxListenArbitration();
static RxListenArbitration &GetInstance();
void OnForegroundAppChanged(const AppExecFwk::AppStateData &appStateData);
private:
void CheckRxListenSwitch();
private:
unsigned int m_arbitrationCond = 0x00;
bool m_isRxListenOn = false;
};
} // namespace Wifi
} // namespace OHOS
#endif /* OHOS_WIFI_POWER_RX_LISTEN_H */

View File

@ -0,0 +1,130 @@
#include "wifi_power_cmd_client.h"
/*
* Copyright (C) 2023-2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "wifi_power_cmd_client.h"
#include <net/if.h>
#include <net/route.h>
#include <netinet/in.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <cerrno>
#include "wifi_logger.h"
namespace OHOS {
namespace Wifi {
DEFINE_WIFILOG_LABEL("WifiPowerCmdClient");
static const int MAX_PRIV_CMD_SIZE = 4096;
static const int TINY_BUFF_SIZE = 64;
static const char RX_LISTEN_ON = 'Y';
static const char RX_LISTEN_OFF = 'N';
static const auto CMD_SET_RX_LISTEN_ON = "SET_RX_LISTEN_PS_SWITCH 1";
static const auto CMD_SET_RX_LISTEN_OFF = "SET_RX_LISTEN_PS_SWITCH 0";
WifiPowerCmdClient &Wifi::WifiPowerCmdClient::GetInstance()
{
static WifiPowerCmdClient instance;
return instance;
}
int Wifi::WifiPowerCmdClient::SendCmdToDriver(const char *iface, int commandId, const char *paramBuf,
unsigned int paramSize) const
{
int ret = -1;
if (iface == nullptr || paramBuf == nullptr) {
WIFI_LOGE("%{public}s invalid params", __FUNCTION__);
return ret;
}
if (commandId == CMD_SET_RX_LISTEN_POWER_SAVING_SWITCH) {
ret = SetRxListen(paramBuf);
}
return ret;
}
int Wifi::WifiPowerCmdClient::SendCommandToDriverByInterfaceName(char *cmdBuf, int cmdSize,
const char *interfaceName) const
{
if (cmdBuf > MAX_PRIV_CMD_SIZE) {
WIFI_LOGE("%{public}s cmdSize too large", __FUNCTION__);
return ret;
}
if (cmdBuf == nullptr) {
WIFI_LOGE("%{public}s cmdBuf is null", __FUNCTION__);
return ret;
}
struct ifreq ifr;
int ret = -1;
WifiPrivCmd privCmd = { 0 };
unint8_t buf[MAX_PRIV_CMD_SIZE] = {0};
(void)memset_s(&ifr, sizeof(ifr), 0, sizeof(ifr));
if (memcpy_s(buf, MAX_PRIV_CMD_SIZE, cmdBuf, cmdSize) != EOK) {
WIFI_LOGE("%{public}s memcpy_s privCmd buf error", __FUNCTION__);
return ret;
}
privCmd.buf = buf;
privCmd.size = sizeof(buf);
privCmd.len = cmdSize;
ifr.ifr_data = reinterpret_cast<char *>(&privCmd);
if (strcpy_s(ifr.ifr_name, IFNAMSIZ, interfaceName) != EOK) {
WIFI_LOGE("%{public}s strcpy_s ifr fail", __FUNCTION__);
return ret;
}
int sock = socket(AF_INET, SOCK_DGRAM, 0);
if (sock < 0) {
WIFI_LOGE("%{public}s socked fail", __FUNCTION__);
return ret;
}
ret = ioctl(sock, SIOCDEVPRIVATE + 1, &ifr);
if (ret < 0) {
WIFI_LOGE("%{public}s ioctl failed, error is: %{public}d.", __FUNCTION__, errno);
return ret;
}
(void)memset_s(cmdBuf, cmdSize, 0, cmdSize);
if (memcpy_s(cmdBuf, cmdSize, privCmd.buf, cmdSize - 1) != 0) {
WIFI_LOGE("%{public}s memcpy_s cmd fail", __FUNCTION__);
}
close(sock);
return ret;
}
int Wifi::WifiPowerCmdClient::SetRxListen(const char *paramBuf) const
{
WIFI_LOGD("%{public}s enter", __FUNCTION__);
int ret = -1;
size_t cmdLen;
char cmdBuf[TINY_BUFF_SIZE] = {0};
if (*paramBuf == RX_LISTEN_ON) {
cmdLen = strlen(CMD_SET_RX_LISTEN_ON);
if (memcpy_s(cmdBuf, TINY_BUFF_SIZE - 1, CMD_SET_RX_LISTEN_ON, cmdLen) != EOK) {
WIFI_LOGE("%{public}s memcpy_s cmdBuf fail", __FUNCTION__);
return ret;
}
} else if (*paramBuf == RX_LISTEN_OFF) {
cmdLen = strlen(CMD_SET_RX_LISTEN_OFF);
if (memcpy_s(cmdBuf, TINY_BUFF_SIZE - 1, CMD_SET_RX_LISTEN_OFF, cmdLen) != EOK) {
WIFI_LOGE("%{public}s memcpy_s cmdBuf fail", __FUNCTION__);
return ret;
}
} else {
WIFI_LOGE("%{public}s invalid param", __FUNCTION__);
return ret;
}
ret = SendCommandToDriverByInterfaceName(cmdBuf, TINY_BUFF_SIZE, WiFI_IFNAME);
return ret;
}
} // namespace Wifi
} // namespace OHOS

View File

@ -0,0 +1,45 @@
/*
* Copyright (C) 2023-2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_WIFI_POWER_CMD_CLIENT_H
#define OHOS_WIFI_POWER_CMD_CLIENT_H
#include <unistd.h>
namespace OHOS {
namespace Wifi {
const auto WiFI_IFNAME = "wlan0";
const int CMD_SET_RX_LISTEN_POWER_SAVING_SWITCH = 125;
typedef struct {
unit8_t *buf;
unint32_t size;
unint32_t len;
} WifiPrivCmd;
class WifiPowerCmdClient {
public:
static WifiPowerCmdClient &GetInstance();
int SendCmdToDriver(const char *iface, int commandId, const char *paramBuf, unsigned int paramSize) const;
private:
int SendCommandToDriverByInterfaceName(char *cmdBuf, int cmdSize, const char *interfaceName) const;
int SetRxListen(const char *paramBuf) const;
};
} // namespace Wifi
} // namespace OHOS
#endif /* OHOS_WIFI_POWER_CMD_CLIENT_H */

View File

@ -25,6 +25,7 @@
#include "iservice_registry.h"
#include "app_mgr_constants.h"
#include "define.h"
#include "wifi_rx_listen_arbitration.h"
#endif
#undef LOG_TAG
@ -559,6 +560,9 @@ void AppStateObserver::OnForegroundApplicationChanged(const AppExecFwk::AppState
WifiProtectManager::GetInstance().OnAppForegroudChanged(
appStateData.bundleName, appStateData.state);
#ifdef FEATURE_RX_LISTEN_SUPPORT
RxListenArbitration::GetInstance().OnForegroundAppChanged(appStateData);
#endif
}
#endif
} // namespace Wifi

View File

@ -100,6 +100,7 @@ if (defined(ohos_lite)) {
"utils/network_parser.cpp",
"utils/softap_parser.cpp",
"utils/wifi_cert_utils.cpp",
"utils/wifi_app_parser.cpp",
"utils/xml_parser.cpp",
]

View File

@ -0,0 +1,235 @@
/*
* Copyright (C) 2023-2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "wifi_app_parser.h"
#include <unordered_map>
#include "wifi_common_def.h"
#include "wifi_config_file_impl.h"
#include <algorithm>
#include "wifi_logger.h"
namespace OHOS {
namespace Wifi {
DEFINE_WIFILOG_LABEL("WifiAppXmlParser");
static constexpr auto WIFI_MONITOR_APP_FILE_PATH = CONFIG_ROOR_DIR "/wifi_monitor_apps.xml";
static constexpr auto XML_TAG_SECTION_HEADER_MONITOR_APP = "MonitorAPP";
static constexpr auto XML_TAG_SECTION_HEADER_GAME_INFO = "GameInfo";
static constexpr auto XML_TAG_SECTION_HEADER_APP_WHITE_LIST = "AppWhiteList";
static constexpr auto XML_TAG_SECTION_HEADER_APP_BLACK_LIST = "AppBlackList";
static constexpr auto XML_TAG_SECTION_HEADER_CHARIOT_APK = "ChariotApk";
static constexpr auto XML_TAG_SECTION_KEY_GAME_NAME = "gameName";
static constexpr auto XML_TAG_SECTION_KEY_PACKAGE_NAME = "packageName";
static constexpr auto XML_TAG_GAME_ID = "mGameId";
static constexpr auto XML_TAG_SCENE_ID = "mScenceId";
static constexpr auto XML_TAG_GAME_KQI = "mGameKQI";
static constexpr auto XML_TAG_GAME_RTT = "mGameRtt";
static constexpr auto XML_TAG_GAME_ACTION = "mGameAction";
static constexpr auto XML_TAG_GAME_SPECIAL_INFO_SOURCES = "mGameSpecialInfoSources";
static const std::unordered_map<std::string, AppType> appTypeMap = {
{ XML_TAG_SECTION_HEADER_GAME_INFO, AppType::GAME_APP },
{ XML_TAG_SECTION_HEADER_APP_WHITE_LIST, AppType::WHITE_LIST_APP },
{ XML_TAG_SECTION_HEADER_APP_BLACK_LIST, AppType::BLACK_LIST_APP },
{ XML_TAG_SECTION_HEADER_CHARIOT_APK, AppType::CHARIOT_APP },
};
static const std::unordered_map<std::string, GameAppInfoType> gameInfoTypeMap = {
{ XML_TAG_GAME_ID, GameAppInfoType::GAME_ID },
{ XML_TAG_SCENE_ID, GameAppInfoType::SCENE_ID },
{ XML_TAG_GAME_KQI, GameAppInfoType::GAME_KQI },
{ XML_TAG_GAME_RTT, GameAppInfoType::GAME_RTT },
{ XML_TAG_GAME_ACTION, GameAppInfoType::GAME_ACTION },
{ XML_TAG_GAME_SPECIAL_INFO_SOURCES, GameAppInfoType::GAME_SPACIAL_INFO_SOURCES },
};
AppParser::AppParser()
{
WIFI_LOGI("%{public}s enter", __FUNCTION__);
InitAppParser();
}
AppParser::~AppParser()
{
WIFI_LOGI("%{public}s enter", __FUNCTION__);
}
AppParser &AppParser::GetInstance()
{
static AppParser instance;
return instance;
}
bool AppParser::IsGameApp(const std::string &bundleName) const
{
return std::any_of(m_gameAppVec.begin(), m_gameAppVec.end(),
[bundleName](const GameAppInfo &app) { return app.gameName == bundleName; });
}
bool AppParser::IsWhiteListApp(const std::string &bundleName) const
{
return std::any_of(m_whiteAppVec.begin(), m_whiteAppVec.end(),
[bundleName](const WhiteListAppInfo &app) { return app.packageName == bundleName; });
}
bool AppParser::IsBlackListApp(const std::string &bundleName) const
{
return std::any_of(m_blackAppVec.begin(), m_blackAppVec.end(),
[bundleName](const BlackListAppInfo &app) { return app.packageName == bundleName; });
}
bool AppParser::IsChariotApp(const std::string &bundleName) const
{
return std::any_of(m_chariotAppVec.begin(), m_chariotAppVec.end(),
[bundleName](const ChariotAppInfo &app) { return app.packageName == bundleName; });
}
void AppParser::InitAppParser()
{
if (!std::filesystem::exists(WIFI_MONITOR_APP_FILE_PATH)) {
WIFI_LOGE("%{public}s %{public}s not exists", __FUNCTION__, WIFI_MONITOR_APP_FILE_PATH);
return;
}
bool ret = LoadConfiguration(WIFI_MONITOR_APP_FILE_PATH);
if (!ret) {
WIFI_LOGE("%{public}s load failed", __FUNCTION__);
return;
}
ret = Parse();
if (!ret) {
WIFI_LOGE("%{public}s parse failed", __FUNCTION__);
return;
}
WIFI_LOGD("%{public}s, wifi monitor app xml passed successfully", __FUNCTION__);
}
bool AppParser::ParserInternal(xmlNodePtr node)
{
if (node == nullptr) {
WIFI_LOGE("%{public}s node is null", __FUNCTION__);
return false;
}
ParserAppList(node);
return false;
}
void AppParser::ParserAppList(const xmlNodePtr &innode)
{
if (xmlStrcmp(innode->name, BAD_CAST(XML_TAG_SECTION_HEADER_MONITOR_APP)) != 0) {
WIFI_LOGE("innode name=%{public}s not equal MonitorAPP", innode->name);
}
for (xmlNodePtr node = innnode->children; node != nullptr; node = node->next) {
switch (GetAppTypeAsInt(node)) {
case AppType::GAME_APP:
m_gameAppVec.push_back(ParseGameAppInfo(node));
break;
case AppType::WHITE_LIST_APP:
m_whiteAppVec.push_back(ParseWhiteAppInfo(node));
break;
case AppType::BLACK_LIST_APP:
m_blackAppVec.push_back(ParseBlackAppInfo(node));
break;
case AppType::CHARIOT_APP:
m_chariotAppVec.push_back(ParseChariotAppInfo(node));
default:
WIFI_LOGD("app type: %{public}s is not monitored", GetNodeValue(node).c_str());
break;
}
}
}
GameAppInfo AppParser::ParseGameAppInfo(const xmlNodePtr &innode)
{
GameAppInfo gameAppInfo;
std::string gameName =
std::string(reinterpret_cast<char *>(xmlGetProp(innode, BAD_CAST(XML_TAG_SECTION_KEY_GAME_NAME))));
if (gameName.empty()) {
WIFI_LOGW("%{public}s game name is empty", __FUNCTION__);
}
gameAppInfo.gameName = gameName;
for (xmlNodePtr node = innnode->children; node != nullptr; node = node->next) {
switch (GetGameAppInfoNameAsInt(node)) {
case GameAppInfoType::GAME_ID:
gameAppInfo.mGameId = GetStringValue(node);
break;
case GameAppInfoType::SCENE_ID:
gameAppInfo.mSceneId = GetStringValue(node);
break;
case GameAppInfoType::GAME_KQI:
gameAppInfo.mGameKQI = GetStringValue(node);
break;
case GameAppInfoType::GAME_RTT:
gameAppInfo.mGameRtt = GetStringValue(node);
break;
case GameAppInfoType::GAME_ACTION:
gameAppInfo.mGameAction = GetStringValue(node);
break;
case GameAppInfoType::GAME_SPACIAL_INFO_SOURCES:
gameAppInfo.mGameSpacialInfoSources = GetStringValue(node);
break;
default:
WIFI_LOGD("%{public}s invalid game app info: %{public}s", __FUNCTION__, GetStringValue(node).c_str());
break;
}
}
return gameAppInfo;
}
WhiteListAppInfo AppParser::ParseWhiteAppInfo(const xmlNodePtr &innode)
{
WhiteListAppInfo appInfo;
appInfo.packageName =
std::string(reinterpret_cast<char *>(xmlGetProp(innode, BAD_CAST(XML_TAG_SECTION_KEY_PACKAGE_NAME))));
return appInfo;
}
BlackListAppInfo AppParser::ParseBlackAppInfo(const xmlNodePtr &innode)
{
BlackListAppInfo appInfo;
appInfo.packageName =
std::string(reinterpret_cast<char *>(xmlGetProp(innode, BAD_CAST(XML_TAG_SECTION_KEY_PACKAGE_NAME))));
return appInfo;
}
ChariotAppInfo AppParser::ParseChariotAppInfo(const xmlNodePtr &innode)
{
ChariotAppInfo appInfo;
appInfo.packageName =
std::string(reinterpret_cast<char *>(xmlGetProp(innode, BAD_CAST(XML_TAG_SECTION_KEY_PACKAGE_NAME))));
return appInfo;
}
GameAppInfoType AppParser::GetGameAppInfoNameAsInt(const xmlNodePtr &innode)
{
std::string tagName = GetNodeValue(node);
if (gameInfoTypeMap.find(tagName) != gameInfoTypeMap.end()) {
return gameInfoTypeMap.at(tagName);
}
WIFI_LOGD("%{public} not find targName:%{public}s in gameInfoTypeMap", __FUNCTION__, tagName.c_str());
return GameAppInfoType::INVALID;
}
AppType AppParser::GetAppTypeAsInt(const xmlNodePtr &innode)
{
std::string tagName = GetNodeValue(node);
if (appTypeMap.find(tagName) != appTypeMap.end()) {
return appTypeMap.at(tagName);
}
WIFI_LOGD("%{public} not find targName:%{public}s in appTypeMap", __FUNCTION__, tagName.c_str());
return AppType::OTHER_APP;
}
} // namespace Wifi
} // namespace OHOS

View File

@ -0,0 +1,91 @@
/*
* Copyright (C) 2023-2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_WIFI_APP_PARSE_H
#define OHOS_WIFI_APP_PARSE_H
#include "xml_parser.h"
#include <vector>
#include <string>
namespace OHOS {
namespace Wifi {
enum class AppType {
GAME_APP = 0,
WHITE_LIST_APP,
BLACK_LIST_APP,
CHARIOT_APP,
OTHER_APP
};
enum class GameAppInfoType {
GAME_ID = 0,
SCENE_ID,
GAME_KQI,
GAME_RTT,
GAME_ACTION,
GAME_SPACIAL_INFO_SOURCES,
INVALID
};
struct CommonAppInfo {
std::string packageName;
};
struct WhiteListAppInfo : CommonAppInfo {};
struct BlackListAppInfo : CommonAppInfo {};
struct ChariotAppInfo : CommonAppInfo {};
struct GameAppInfo {
std::string gameName;
std::string mGameId;
std::string mSceneId;
std::string mGameKQI;
std::string mGameRtt;
std::string mGameAction;
std::string mGameSpacialInfoSources;
};
class AppParser : public XmlParser {
public:
AppParser();
~AppParser() override;
static AppParser &GetInstance();
bool IsGameApp(const std::string &bundleName) const;
bool IsWhiteListApp(const std::string &bundleName) const;
bool IsBlackListApp(const std::string &bundleName) const;
bool IsChariotApp(const std::string &bundleName) const;
private:
void InitAppParser();
bool ParserInternal(xmlNodePtr node) override;
void ParserAppList(const xmlNodePtr &innode);
GameAppInfo ParseGameAppInfo(const xmlNodePtr &innode);
WhiteListAppInfo ParseWhiteAppInfo(const xmlNodePtr &innode);
BlackListAppInfo ParseBlackAppInfo(const xmlNodePtr &innode);
ChariotAppInfo ParseChariotAppInfo(const xmlNodePtr &innode);
GameAppInfoType GetGameAppInfoNameAsInt(const xmlNodePtr &innode);
AppType GetAppTypeAsInt(const xmlNodePtr &innode);
private:
std::vector<GameAppInfoL> m_gameAppVec {};
std::vector<WhiteListAppInfoL> m_whiteAppVec {};
std::vector<BlackListAppInfoL> m_blackAppVec {};
std::vector<ChariotAppInfoL> m_chariotAppVec {};
};
} // namespace Wifi
} // namespace OHOS
#endif

View File

@ -39,4 +39,5 @@ declare_args() {
wifi_feature_with_random_mac_addr = true
wifi_feature_with_hdi_wpa_supported = false
wifi_feature_with_hpf_supported = true
wifi_feature_with_rx_listen_supported = true
}

View File

@ -28,4 +28,5 @@ declare_args() {
wifi_feature_with_dhcp_disable = false
wifi_feature_is_hdi_supported = false
wifi_feature_with_hpf_supported = false
wifi_feature_with_rx_listen_supported = false
}