diff --git a/interfaces/innerkits/native_cpp/wifi_standard/interfaces/define.h b/interfaces/innerkits/native_cpp/wifi_standard/interfaces/define.h index c7b93f99dade53bd9281ea8b2b679272998af509..51473c9d0b87fc6077099cc6ecc9d9eeb82eca45 100644 --- a/interfaces/innerkits/native_cpp/wifi_standard/interfaces/define.h +++ b/interfaces/innerkits/native_cpp/wifi_standard/interfaces/define.h @@ -151,4 +151,14 @@ #define WIFI_HOTSPOT_ABILITY_ID 1127 #define WIFI_P2P_ABILITY_ID 1128 +#define MODE_STATE_SCREEN (1) +#define MODE_STATE_AIR_PLANE (2) +#define MODE_STATE_APP_RUN (3) +#define MODE_STATE_POWER_SAVING (4) +#define MODE_STATE_FREEZE (5) +#define MODE_STATE_NO_CHARGER_PLUG (6) + +#define MODE_STATE_OPEN (1) +#define MODE_STATE_CLOSE (2) + #endif \ No newline at end of file diff --git a/interfaces/innerkits/native_cpp/wifi_standard/interfaces/wifi_errcode.h b/interfaces/innerkits/native_cpp/wifi_standard/interfaces/wifi_errcode.h index f172ad149054a1ac9efe348b6b20f430b4ce9c4a..6d2eb764827879ac5023b9bbc4e19b5825d66c19 100644 --- a/interfaces/innerkits/native_cpp/wifi_standard/interfaces/wifi_errcode.h +++ b/interfaces/innerkits/native_cpp/wifi_standard/interfaces/wifi_errcode.h @@ -40,6 +40,7 @@ enum ErrCode { WIFI_OPT_P2P_ERR_MAC_FORMAT, WIFI_OPT_P2P_ERR_INTENT, WIFI_OPT_P2P_ERR_SIZE_NW_NAME, + WIFI_OPT_MOVING_FREEZE_CTRL, /* moving freeze scanning control */ }; } // namespace Wifi } // namespace OHOS diff --git a/interfaces/innerkits/native_cpp/wifi_standard/interfaces/wifi_scan_msg.h b/interfaces/innerkits/native_cpp/wifi_standard/interfaces/wifi_scan_msg.h index 61244ce296033d5fe748b131df084a5d54a3f438..9b33054b62507fcd4018c92630d416bab218907e 100755 --- a/interfaces/innerkits/native_cpp/wifi_standard/interfaces/wifi_scan_msg.h +++ b/interfaces/innerkits/native_cpp/wifi_standard/interfaces/wifi_scan_msg.h @@ -26,18 +26,25 @@ namespace OHOS { namespace Wifi { #define MIN_SCAN_INTERVAL 20 #define DEFAULT_MAX_SCAN_INTERVAL 160 -#define SCAN_SCENE_SCREEN_OFF 0 -#define SCAN_SCENE_SCANNING 1 -#define SCAN_SCENE_CONNECTING 2 -#define SCAN_SCENE_DISCONNCTED 3 -#define SCAN_SCENE_CONNECTED 4 -#define SCAN_SCENE_ASSOCIATING 5 -#define SCAN_SCENE_ASSOCIATED 6 -#define SCAN_SCENE_OBTAINING_IP 7 -#define SCAN_SCENE_DEEP_SLEEP 8 -/* 8~253 Custom Scenario */ +#define SCAN_SCENE_SCREEN_OFF 0 // Screen off state +#define SCAN_SCENE_SCANNING 1 // scanning state +#define SCAN_SCENE_CONNECTING 2 // connecting state +#define SCAN_SCENE_DISCONNCTED 3 // disconnected state +#define SCAN_SCENE_CONNECTED 4 // connected state +#define SCAN_SCENE_ASSOCIATING 5 // associating state +#define SCAN_SCENE_ASSOCIATED 6 // associated state +#define SCAN_SCENE_OBTAINING_IP 7 // Obtaining IP state +#define SCAN_SCENE_DEEP_SLEEP 8 // Deep sleep state +#define SCAN_SCENE_FREQUENCY_ORIGIN 9 // Scan frequency, origin. + // This parameter takes effect when no charger. +#define SCAN_SCENE_FREQUENCY_CUSTOM 10 // Scan frequency, custom. + // This parameter takes effect when no charger. +#define SCAN_SCENE_CUSTOM (SCAN_SCENE_FREQUENCY_CUSTOM + 1) + +/* SCAN_SCENE_CUSTOM~253 Custom Scenario */ #define SCAN_SCENE_ALL 254 /* all Scenario */ #define SCAN_SCENE_MAX 255 /* invalid value */ + /* Scanning mode of the control policy */ enum class ScanMode { APP_FOREGROUND_SCAN = 0, /* Scan initiated by the foreground application */ @@ -141,6 +148,7 @@ struct WifiScanInfo { }; typedef struct tagScanForbidMode { + int scanScene; /* current scanned scene */ int forbidTime; /* * Specifies the scanning duration. * If the value is 0, all invalid values are restricted. @@ -156,6 +164,9 @@ typedef struct tagScanForbidMode { forbidCount = 0; scanMode = ScanMode::SCAN_MODE_MAX; } + + ~tagScanForbidMode() + {} } ScanForbidMode; enum class IntervalMode { @@ -214,11 +225,11 @@ typedef struct tagScanIntervalMode { } } ScanIntervalMode; -typedef std::map> ScanForbidMap; +typedef std::vector ScanForbidList; typedef std::vector ScanIntervalList; typedef struct tagScanControlInfo { - ScanForbidMap scanForbidMap; /* Scanning forbidden list corresponding to the scenario */ + ScanForbidList scanForbidList; /* Scanning forbidden list corresponding to the scenario */ ScanIntervalList scanIntervalList; /* * Interval for scanning mode. * The value cannot be set to 2.4 GHz, 5 GHz, or anytime scan. diff --git a/interfaces/innerkits/native_cpp/wifi_standard/src/wifi_scan_proxy.cpp b/interfaces/innerkits/native_cpp/wifi_standard/src/wifi_scan_proxy.cpp index 51638c45c9995358300d418a7ee1e288bd7fa996..5ce10613e4a9a7677ff6279d6fd0097e86df0008 100755 --- a/interfaces/innerkits/native_cpp/wifi_standard/src/wifi_scan_proxy.cpp +++ b/interfaces/innerkits/native_cpp/wifi_standard/src/wifi_scan_proxy.cpp @@ -46,25 +46,20 @@ ErrCode WifiScanProxy::SetScanControlInfo(const ScanControlInfo &info) MessageParcel data; MessageParcel reply; data.WriteInt32(0); - data.WriteInt32(info.scanForbidMap.size()); - auto iter = info.scanForbidMap.begin(); - for (; iter != info.scanForbidMap.end(); iter++) { - data.WriteInt32((int)iter->first); - data.WriteInt32(iter->second.size()); - for (std::size_t i = 0; i < iter->second.size(); i++) { - data.WriteInt32((int)iter->second[i].scanMode); - data.WriteInt32(iter->second[i].forbidTime); - data.WriteInt32(iter->second[i].forbidCount); - } + data.WriteInt32(info.scanForbidList.size()); + for (auto iter = info.scanForbidList.begin(); iter != info.scanForbidList.end(); iter++) { + data.WriteInt32(iter->scanScene); + data.WriteInt32(static_cast(iter->scanMode)); + data.WriteInt32(iter->forbidTime); + data.WriteInt32(iter->forbidCount); } data.WriteInt32(info.scanIntervalList.size()); - auto iter2 = info.scanIntervalList.begin(); - for (; iter2 != info.scanIntervalList.end(); iter2++) { + for (auto iter2 = info.scanIntervalList.begin(); iter2 != info.scanIntervalList.end(); iter2++) { data.WriteInt32(iter2->scanScene); - data.WriteInt32((int)iter2->scanMode); - data.WriteInt32((int)iter2->isSingle); - data.WriteInt32((int)iter2->intervalMode); + data.WriteInt32(static_cast(iter2->scanMode)); + data.WriteBool(iter2->isSingle); + data.WriteInt32(static_cast(iter2->intervalMode)); data.WriteInt32(iter2->interval); data.WriteInt32(iter2->count); } diff --git a/services/wifi_standard/ipc_framework/cRPC/src/context.c b/services/wifi_standard/ipc_framework/cRPC/src/context.c index 35e3b2f62e317b9248511a57c4c2178381db7a62..5919afdaafeeb5792da045992e3e59ba2e8ee784 100644 --- a/services/wifi_standard/ipc_framework/cRPC/src/context.c +++ b/services/wifi_standard/ipc_framework/cRPC/src/context.c @@ -39,7 +39,7 @@ Context *CreateContext(int capacity) free(context); return NULL; } - context->cSplit = '|'; + context->cSplit = '\t'; context->cMsgEnd = "$$$$$$"; return context; } diff --git a/services/wifi_standard/wifi_framework/common/config/wifi_config_file_impl.h b/services/wifi_standard/wifi_framework/common/config/wifi_config_file_impl.h index 368d31eab6031237f5ddc21669236058be9c6c30..0af4bd08f2c78c3a08b5e800ed8214bc7f9bbcd8 100644 --- a/services/wifi_standard/wifi_framework/common/config/wifi_config_file_impl.h +++ b/services/wifi_standard/wifi_framework/common/config/wifi_config_file_impl.h @@ -91,6 +91,13 @@ public: */ int GetValue(std::vector &results); + /** + * @Description Get config values + * + * @return config values + */ + const std::vector& GetValue() const; + /** * @Description Set the config value * @@ -123,7 +130,6 @@ int WifiConfigFileImpl::LoadConfig() T item; std::string line; while (std::getline(fs, line)) { - DelComment(line); TrimString(line); if (line.empty()) { continue; @@ -188,7 +194,13 @@ int WifiConfigFileImpl::GetValue(std::vector &results) return 0; } -template +template +const std::vector& WifiConfigFileImpl::GetValue() const +{ + return mValues; +} + +template int WifiConfigFileImpl::SetValue(const std::vector &results) { mValues = results; diff --git a/services/wifi_standard/wifi_framework/common/config/wifi_config_file_spec.cpp b/services/wifi_standard/wifi_framework/common/config/wifi_config_file_spec.cpp index 64a95bcb04bc203b67afee64454b49d1e39bad7d..e7eb55fb9f74d9a4308739d5499cbcd7b463acdd 100644 --- a/services/wifi_standard/wifi_framework/common/config/wifi_config_file_spec.cpp +++ b/services/wifi_standard/wifi_framework/common/config/wifi_config_file_spec.cpp @@ -516,6 +516,8 @@ void ClearTClass(WifiConfig &item) item.secondRssiLevel5G = RSSI_LEVEL_2_5G; item.thirdRssiLevel5G = RSSI_LEVEL_3_5G; item.fourthRssiLevel5G = RSSI_LEVEL_4_5G; + item.strDnsBak = "8.8.8.8"; + item.isLoadStabak = true; return; } @@ -595,6 +597,10 @@ void SetTClassKeyValue(WifiConfig &item, const std::string &key, con item.thirdRssiLevel5G = std::stoi(value); } else if (key == "fourthRssiLevel5G") { item.fourthRssiLevel5G = std::stoi(value); + } else if (key == "strDnsBak") { + item.strDnsBak = value; + } else if (key == "isLoadStabak") { + item.isLoadStabak = (std::stoi(value) != 0); } return; } @@ -640,6 +646,8 @@ std::string OutTClassString(WifiConfig &item) ss << "secondRssiLevel5G=" << item.secondRssiLevel5G << std::endl; ss << "thirdRssiLevel5G=" << item.thirdRssiLevel5G << std::endl; ss << "fourthRssiLevel5G=" << item.fourthRssiLevel5G << std::endl; + ss << "strDnsBak=" << item.strDnsBak << std::endl; + ss << "isLoadStabak=" << item.isLoadStabak << std::endl; return ss.str(); } @@ -764,5 +772,71 @@ std::string OutTClassString(WifiP2pGroupInfo &item) } return ss.str(); } -} // namespace Wifi -} // namespace OHOS + +template <> +void ClearTClass(TrustListPolicy &item) +{ + item.sceneId = 0; + item.sceneName.clear(); + item.trustList.clear(); + return; +} + +template <> +void SetTClassKeyValue(TrustListPolicy &item, const std::string &key, const std::string &value) +{ + if (key == "sceneId") { + item.sceneId = std::stoi(value); + } else if (key == "sceneName") { + item.sceneName = value; + } else if (key == "trustList") { + item.trustList = value; + } + + return; +} + +template <> +std::string GetTClassName() +{ + return "TrustListPolicy"; +} + +template <> std::string OutTClassString(TrustListPolicy &item) +{ + std::ostringstream ss; + ss << "sceneId=" << item.sceneId << std::endl; + ss << "sceneName=" << item.sceneName << std::endl; + ss << "trustList=" << item.trustList << std::endl; + return ss.str(); +} + +template <> void ClearTClass(MovingFreezePolicy &item) +{ + item.trustList.clear(); + return; +} + +template <> +void SetTClassKeyValue(MovingFreezePolicy &item, const std::string &key, const std::string &value) +{ + if (key == "trustList") { + item.trustList = value; + } + + return; +} + +template <> std::string GetTClassName() +{ + return "MovingFreezePolicy"; +} + +template <> std::string OutTClassString(MovingFreezePolicy &item) +{ + std::ostringstream ss; + ss << "trustList=" << item.trustList << std::endl; + return ss.str(); +} +} // namespace Wifi +} // namespace OHOS diff --git a/services/wifi_standard/wifi_framework/common/config/wifi_config_file_spec.h b/services/wifi_standard/wifi_framework/common/config/wifi_config_file_spec.h index c76bd86925f655d7f6da8d3332333056de90f325..50ec00074e8b083c2a4e24e0e990ecd88767ce56 100644 --- a/services/wifi_standard/wifi_framework/common/config/wifi_config_file_spec.h +++ b/services/wifi_standard/wifi_framework/common/config/wifi_config_file_spec.h @@ -328,6 +328,86 @@ std::string GetTClassName(); */ template<> std::string OutTClassString(WifiP2pGroupInfo &item); + +/** + * @Description Clear and init TrustListPolicy + * + * @tparam + * @param item - TrustListPolicy &item + */ +template <> +void ClearTClass(TrustListPolicy &item); + +/** + * @Description Set TrustListPolicy item data + * + * @tparam + * @param item - TrustListPolicy &item + * @param key - TrustListPolicy struct member name + * @param value - the TrustListPolicy item member value + */ +template <> +void SetTClassKeyValue(TrustListPolicy &item, const std::string &key, const std::string &value); + +/** + * @Description Output TrustListPolicy class name + * + * @tparam + * @param item - TrustListPolicy &item + * @return std::string - Class name + */ +template <> +std::string GetTClassName(); + +/** + * @Description Output the TrustListPolicy item, format: item's member = the member value + * + * @tparam + * @param item - TrustListPolicy &item + * @return std::string - output total member=value string about the TrustListPolicy item + */ +template <> +std::string OutTClassString(TrustListPolicy &item); + +/** + * @Description Clear and init MovingFreezePolicy + * + * @tparam + * @param item - MovingFreezePolicy &item + */ +template <> +void ClearTClass(MovingFreezePolicy &item); + +/** + * @Description Set MovingFreezePolicy item data + * + * @tparam + * @param item - MovingFreezePolicy &item + * @param key - MovingFreezePolicy struct member name + * @param value - the MovingFreezePolicy item member value + */ +template <> +void SetTClassKeyValue(MovingFreezePolicy &item, const std::string &key, const std::string &value); + +/** + * @Description Output MovingFreezePolicy class name + * + * @tparam + * @param item - MovingFreezePolicy &item + * @return std::string - Class name + */ +template <> +std::string GetTClassName(); + +/** + * @Description Output the MovingFreezePolicy item, format: item's member = the member value + * + * @tparam + * @param item - MovingFreezePolicy &item + * @return std::string - output total member=value string about the MovingFreezePolicy item + */ +template <> +std::string OutTClassString(MovingFreezePolicy &item); /* ----------template function specialization declare end----------- */ } // namespace Wifi } // namespace OHOS diff --git a/services/wifi_standard/wifi_framework/common/config/wifi_settings.cpp b/services/wifi_standard/wifi_framework/common/config/wifi_settings.cpp index ea3256fdc519c658c4d677a895d578eec6725126..daad43cb7ef8b83714a5d9b65c803e365cfebad2 100644 --- a/services/wifi_standard/wifi_framework/common/config/wifi_settings.cpp +++ b/services/wifi_standard/wifi_framework/common/config/wifi_settings.cpp @@ -37,10 +37,12 @@ WifiSettings::WifiSettings() mApMaxConnNum(0), mLastSelectedNetworkId(-1), mLastSelectedTimeVal(0), - mScreenState(1), + mScreenState(MODE_STATE_OPEN), mAirplaneModeState(MODE_STATE_CLOSE), - mAppRunningModeState(1), - mPowerSavingModeState(MODE_STATE_CLOSE) + mAppRunningModeState(ScanMode::SYS_FOREGROUND_SCAN), + mPowerSavingModeState(MODE_STATE_CLOSE), + mFreezeModeState(MODE_STATE_CLOSE), + mNoChargerPlugModeState(MODE_STATE_CLOSE) {} WifiSettings::~WifiSettings() @@ -121,12 +123,17 @@ int WifiSettings::Init() mSavedWifiConfig.SetConfigFilePath(WIFI_CONFIG_FILE_PATH); mSavedWifiP2pGroupInfo.SetConfigFilePath(WIFI_P2P_GROUP_INFO_FILE_PATH); mSavedWifiP2pVendorConfig.SetConfigFilePath(WIFI_P2P_VENDOR_CONFIG_FILE_PATH); + mTrustListPolicies.SetConfigFilePath(WIFI_TRUST_LIST_POLICY_FILE_PATH); + mMovingFreezePolicy.SetConfigFilePath(WIFI_MOVING_FREEZE_POLICY_FILE_PATH); InitWifiConfig(); ReloadDeviceConfig(); InitHotspotConfig(); - InitScanControlInfo(); InitP2pVendorConfig(); ReloadWifiP2pGroupInfoConfig(); + InitScanControlInfo(); + ReloadTrustListPolicies(); + ReloadMovingFreezePolicy(); + return 0; } @@ -798,30 +805,42 @@ void WifiSettings::InitGetApMaxConnNum() void WifiSettings::InitScanControlForbidList(void) { /* Disable external scanning during scanning. */ - std::vector forbidModeList; ScanForbidMode forbidMode; forbidMode.scanMode = ScanMode::ALL_EXTERN_SCAN; - forbidModeList.push_back(forbidMode); - mScanControlInfo.scanForbidMap[SCAN_SCENE_SCANNING] = forbidModeList; + forbidMode.scanScene = SCAN_SCENE_SCANNING; + mScanControlInfo.scanForbidList.push_back(forbidMode); /* Disable external scanning when the screen is shut down. */ - mScanControlInfo.scanForbidMap[SCAN_SCENE_SCREEN_OFF] = forbidModeList; + forbidMode.scanMode = ScanMode::ALL_EXTERN_SCAN; + forbidMode.scanScene = SCAN_SCENE_SCREEN_OFF; + mScanControlInfo.scanForbidList.push_back(forbidMode); /* Disable all scans in connection */ + forbidMode.scanMode = ScanMode::ALL_EXTERN_SCAN; + forbidMode.scanScene = SCAN_SCENE_CONNECTING; + mScanControlInfo.scanForbidList.push_back(forbidMode); forbidMode.scanMode = ScanMode::PNO_SCAN; - forbidModeList.push_back(forbidMode); + forbidMode.scanScene = SCAN_SCENE_CONNECTING; + mScanControlInfo.scanForbidList.push_back(forbidMode); forbidMode.scanMode = ScanMode::SYSTEM_TIMER_SCAN; - forbidModeList.push_back(forbidMode); - mScanControlInfo.scanForbidMap[SCAN_SCENE_CONNECTING] = forbidModeList; + forbidMode.scanScene = SCAN_SCENE_CONNECTING; + mScanControlInfo.scanForbidList.push_back(forbidMode); /* Deep sleep disables all scans. */ - mScanControlInfo.scanForbidMap[SCAN_SCENE_DEEP_SLEEP] = forbidModeList; + forbidMode.scanMode = ScanMode::ALL_EXTERN_SCAN; + forbidMode.scanScene = SCAN_SCENE_DEEP_SLEEP; + mScanControlInfo.scanForbidList.push_back(forbidMode); + forbidMode.scanMode = ScanMode::PNO_SCAN; + forbidMode.scanScene = SCAN_SCENE_DEEP_SLEEP; + mScanControlInfo.scanForbidList.push_back(forbidMode); + forbidMode.scanMode = ScanMode::SYSTEM_TIMER_SCAN; + forbidMode.scanScene = SCAN_SCENE_DEEP_SLEEP; + mScanControlInfo.scanForbidList.push_back(forbidMode); /* PNO scanning disabled */ - forbidModeList.clear(); forbidMode.scanMode = ScanMode::PNO_SCAN; - forbidModeList.push_back(forbidMode); - mScanControlInfo.scanForbidMap[SCAN_SCENE_CONNECTED] = forbidModeList; + forbidMode.scanScene = SCAN_SCENE_CONNECTED; + mScanControlInfo.scanForbidList.push_back(forbidMode); return; } @@ -829,7 +848,7 @@ void WifiSettings::InitScanControlIntervalList(void) { /* Foreground app: 4 times in 2 minutes for a single application */ ScanIntervalMode scanIntervalMode; - scanIntervalMode.scanScene = SCAN_SCENE_ALL; + scanIntervalMode.scanScene = SCAN_SCENE_FREQUENCY_ORIGIN; scanIntervalMode.scanMode = ScanMode::APP_FOREGROUND_SCAN; scanIntervalMode.isSingle = true; scanIntervalMode.intervalMode = IntervalMode::INTERVAL_FIXED; @@ -838,7 +857,7 @@ void WifiSettings::InitScanControlIntervalList(void) mScanControlInfo.scanIntervalList.push_back(scanIntervalMode); /* Backend apps: once every 30 minutes */ - scanIntervalMode.scanScene = SCAN_SCENE_ALL; + scanIntervalMode.scanScene = SCAN_SCENE_FREQUENCY_ORIGIN; scanIntervalMode.scanMode = ScanMode::APP_BACKGROUND_SCAN; scanIntervalMode.isSingle = false; scanIntervalMode.intervalMode = IntervalMode::INTERVAL_FIXED; @@ -846,6 +865,34 @@ void WifiSettings::InitScanControlIntervalList(void) scanIntervalMode.count = BACKGROUND_SCAN_CONTROL_TIMES; mScanControlInfo.scanIntervalList.push_back(scanIntervalMode); + /* no charger plug */ + /* All app: If the scanning interval is less than 5s for five */ + /* consecutive times, the scanning can be performed only after */ + /* the scanning interval is greater than 5s. */ + const int frequencyContinueInterval = 5; + const int frequencyContinueCount = 5; + scanIntervalMode.scanScene = SCAN_SCENE_FREQUENCY_CUSTOM; + scanIntervalMode.scanMode = ScanMode::ALL_EXTERN_SCAN; + scanIntervalMode.isSingle = false; + scanIntervalMode.intervalMode = IntervalMode::INTERVAL_CONTINUE; + scanIntervalMode.interval = frequencyContinueInterval; + scanIntervalMode.count = frequencyContinueCount; + mScanControlInfo.scanIntervalList.push_back(scanIntervalMode); + + /* no charger plug */ + /* Single app: If all scanning interval in 10 times is less than */ + /* the threshold (20s), the app is added to the blocklist and */ + /* cannot initiate scanning. */ + const int frequencyBlocklistInterval = 20; + const int frequencyBlocklistCount = 10; + scanIntervalMode.scanScene = SCAN_SCENE_FREQUENCY_CUSTOM; + scanIntervalMode.scanMode = ScanMode::ALL_EXTERN_SCAN; + scanIntervalMode.isSingle = true; + scanIntervalMode.intervalMode = IntervalMode::INTERVAL_BLOCKLIST; + scanIntervalMode.interval = frequencyBlocklistInterval; + scanIntervalMode.count = frequencyBlocklistCount; + mScanControlInfo.scanIntervalList.push_back(scanIntervalMode); + /* PNO scanning every 20 seconds */ scanIntervalMode.scanScene = SCAN_SCENE_ALL; scanIntervalMode.scanMode = ScanMode::PNO_SCAN; @@ -956,7 +1003,7 @@ void WifiSettings::SetScreenState(const int &state) mScreenState = state; } -int WifiSettings::GetScreenState() +int WifiSettings::GetScreenState() const { return mScreenState; } @@ -966,17 +1013,21 @@ void WifiSettings::SetAirplaneModeState(const int &state) mAirplaneModeState = state; } -int WifiSettings::GetAirplaneModeState() +int WifiSettings::GetAirplaneModeState() const { return mAirplaneModeState; } -void WifiSettings::SetAppRunningState(const int &state) +void WifiSettings::SetAppRunningState(ScanMode appRunMode) { - mAppRunningModeState = state; + if (static_cast(appRunMode) < static_cast(ScanMode::APP_FOREGROUND_SCAN) || + static_cast(appRunMode) > static_cast(ScanMode::SYS_BACKGROUND_SCAN)) { + return; + } + mAppRunningModeState = appRunMode; } -int WifiSettings::GetAppRunningState() +ScanMode WifiSettings::GetAppRunningState() const { return mAppRunningModeState; } @@ -986,11 +1037,41 @@ void WifiSettings::SetPowerSavingModeState(const int &state) mPowerSavingModeState = state; } -int WifiSettings::GetPowerSavingModeState() +int WifiSettings::GetPowerSavingModeState() const { return mPowerSavingModeState; } +void WifiSettings::SetAppPackageName(const std::string &appPackageName) +{ + mAppPackageName = appPackageName; +} + +const std::string& WifiSettings::GetAppPackageName() const +{ + return mAppPackageName; +} + +void WifiSettings::SetFreezeModeState(int state) +{ + mFreezeModeState = state; +} + +int WifiSettings::GetFreezeModeState() const +{ + return mFreezeModeState; +} + +void WifiSettings::SetNoChargerPlugModeState(int state) +{ + mNoChargerPlugModeState = state; +} + +int WifiSettings::GetNoChargerPlugModeState() const +{ + return mNoChargerPlugModeState; +} + int WifiSettings::SetWhetherToAllowNetworkSwitchover(bool bSwitch) { mWifiConfig.whetherToAllowNetworkSwitchover = bSwitch; @@ -1122,11 +1203,57 @@ int WifiSettings::GetMinRssi5Ghz() return mWifiConfig.minRssi5Ghz; } +std::string WifiSettings::GetStrDnsBak() const +{ + return mWifiConfig.strDnsBak; +} + +bool WifiSettings::IsLoadStabak() const +{ + return mWifiConfig.isLoadStabak; +} + int WifiSettings::SetP2pDeviceName(const std::string &deviceName) { std::unique_lock lock(mP2pMutex); mP2pVendorConfig.SetDeviceName(deviceName); return mSavedWifiP2pVendorConfig.SaveConfig(); } -} // namespace Wifi -} // namespace OHOS \ No newline at end of file + +const std::vector& WifiSettings::ReloadTrustListPolicies() +{ + std::unique_lock lock(mStaMutex); + mTrustListPolicies.LoadConfig(); + if (mTrustListPolicies.GetValue().size() <= 0) { + std::vector policies; + TrustListPolicy policy; + policies.push_back(policy); + mTrustListPolicies.SetValue(policies); + mTrustListPolicies.SaveConfig(); + mTrustListPolicies.LoadConfig(); + } + + return mTrustListPolicies.GetValue(); +} + +const MovingFreezePolicy &WifiSettings::ReloadMovingFreezePolicy() +{ + std::unique_lock lock(mStaMutex); + mMovingFreezePolicy.LoadConfig(); + + if (mMovingFreezePolicy.GetValue().size() <= 0) { + std::vector policies; + MovingFreezePolicy policy; + policies.push_back(policy); + mMovingFreezePolicy.SetValue(policies); + mMovingFreezePolicy.SaveConfig(); + mMovingFreezePolicy.LoadConfig(); + } + + if (mMovingFreezePolicy.GetValue().size() <= 0) { + return mFPolicy; + } + return mMovingFreezePolicy.GetValue()[0]; +} +} // namespace Wifi +} // namespace OHOS \ No newline at end of file diff --git a/services/wifi_standard/wifi_framework/common/config/wifi_settings.h b/services/wifi_standard/wifi_framework/common/config/wifi_settings.h index d1b21365c776c41dc836038808ed6cf1a6f4c844..1d8e5c3ab5e2541bebbc25921d00f154897f92c5 100644 --- a/services/wifi_standard/wifi_framework/common/config/wifi_settings.h +++ b/services/wifi_standard/wifi_framework/common/config/wifi_settings.h @@ -24,9 +24,6 @@ #include #include "wifi_config_file_impl.h" -constexpr int MODE_STATE_OPEN = 1; -constexpr int MODE_STATE_CLOSE = 2; - constexpr int RANDOM_STR_LEN = 6; constexpr int MSEC = 1000; constexpr int FOREGROUND_SCAN_CONTROL_TIMES = 4; @@ -49,6 +46,9 @@ constexpr char BLOCK_LIST_FILE_PATH[] = "/data/misc/wifi/block_list.conf"; constexpr char WIFI_CONFIG_FILE_PATH[] = "/data/misc/wifi/wifi_config.conf"; constexpr char WIFI_P2P_GROUP_INFO_FILE_PATH[] = "/data/misc/wifi/p2p_groups.conf"; constexpr char WIFI_P2P_VENDOR_CONFIG_FILE_PATH[] = "/data/misc/wifi/p2p_vendor_config.conf"; +const std::string WIFI_TRUST_LIST_POLICY_FILE_PATH = "/data/misc/wifi/trust_list_polices.conf"; +const std::string WIFI_MOVING_FREEZE_POLICY_FILE_PATH = "/data/misc/wifi/moving_freeze_policy.conf"; + namespace OHOS { namespace Wifi { using ChannelsTable = std::map>; @@ -673,7 +673,7 @@ public: * * @return int - 1 on; 2 off */ - int GetScreenState(); + int GetScreenState() const; /** * @Description Set the Airplane Mode State @@ -687,21 +687,21 @@ public: * * @return int - 1 open; 2 close */ - int GetAirplaneModeState(); + int GetAirplaneModeState() const; /** * @Description Set the App Running State * - * @param state - 1 front; 2 backend + * @param appRunMode - app run mode */ - void SetAppRunningState(const int &state); + void SetAppRunningState(ScanMode appRunMode); /** * @Description Get the App Running State * - * @return int - 1 front; 2 backend + * @return ScanMode */ - int GetAppRunningState(); + ScanMode GetAppRunningState() const; /** * @Description Set the Power Saving Mode State @@ -715,7 +715,49 @@ public: * * @return int - 1 open; 2 close */ - int GetPowerSavingModeState(); + int GetPowerSavingModeState() const; + + /** + * @Description Set app package name. + * + * @param appPackageName - app package name + */ + void SetAppPackageName(const std::string &appPackageName); + + /** + * @Description Get app package name. + * + * @return const std::string& - app package name. + */ + const std::string& GetAppPackageName() const; + + /** + * @Description Set freeze mode state. + * + * @param state - 1 freeze mode; 2 moving mode + */ + void SetFreezeModeState(int state); + + /** + * @Description Get freeze mode state. + * + * @return freeze mode. + */ + int GetFreezeModeState() const; + + /** + * @Description Set no charger plugged in mode. + * + * @param state - 1 no charger plugged in mode; 2 charger plugged in mode + */ + void SetNoChargerPlugModeState(int state); + + /** + * @Description Get no charger plugged in mode. + * + * @return no charger plugged in mode. + */ + int GetNoChargerPlugModeState() const; /** * @Description Set enable/disable Whether to allow network switchover @@ -889,6 +931,19 @@ public: */ int GetMinRssi5Ghz(); + /** + * @Description Get the Alternate dns. + * + * @return string - dns + */ + std::string GetStrDnsBak() const; + /** + * @Description Obtaining Whether to Load the Configuration of the Standby STA. + * + * @return bool - Indicates whether to load the configuration of the standby STA. + */ + bool IsLoadStabak() const; + /** * @Description set the device name * @@ -897,6 +952,19 @@ public: */ int SetP2pDeviceName(const std::string &deviceName); + /** + * @Description get trustlist policies. + * + * @return const std::vector& - trustlist policies. + */ + const std::vector& ReloadTrustListPolicies(); + + /** + * @Description get moving freeze state trustlist. + * + * @return const MovingFreezePolicy& - moving freeze policy. + */ + const MovingFreezePolicy& ReloadMovingFreezePolicy(); private: WifiSettings(); void InitWifiConfig(); @@ -936,8 +1004,11 @@ private: time_t mLastSelectedTimeVal; /* last selected time */ int mScreenState; /* 1 on 2 off */ int mAirplaneModeState; /* 1 on 2 off */ - int mAppRunningModeState; /* 1 front 2 backend */ + ScanMode mAppRunningModeState; /* 0 app for 1 app back 2 sys for 3 sys back */ int mPowerSavingModeState; /* 1 on 2 off */ + std::string mAppPackageName; + int mFreezeModeState; /* 1 on 2 off */ + int mNoChargerPlugModeState; /* 1 on 2 off */ WifiConfig mWifiConfig; std::mutex mStaMutex; @@ -954,6 +1025,9 @@ private: WifiConfigFileImpl mSavedWifiConfig; WifiConfigFileImpl mSavedWifiP2pGroupInfo; WifiConfigFileImpl mSavedWifiP2pVendorConfig; + WifiConfigFileImpl mTrustListPolicies; + WifiConfigFileImpl mMovingFreezePolicy; + MovingFreezePolicy mFPolicy; }; } // namespace Wifi } // namespace OHOS diff --git a/services/wifi_standard/wifi_framework/common/include/wifi_internal_msg.h b/services/wifi_standard/wifi_framework/common/include/wifi_internal_msg.h index bcb2f5475d355944933fe86e36ca1b4eec6d6727..b1776144f61d04d38ceff4e45513125a6462e89f 100755 --- a/services/wifi_standard/wifi_framework/common/include/wifi_internal_msg.h +++ b/services/wifi_standard/wifi_framework/common/include/wifi_internal_msg.h @@ -24,8 +24,6 @@ namespace Wifi { constexpr int REOPEN_STA_INTERVAL = 500; /* when reopen sta, need over last close sta time then interval */ constexpr int DEVICE_CONFIG_INDEX_SSID = 0; constexpr int DEVICE_CONFIG_INDEX_BSSID = 1; -constexpr int STATE_OPEN = 1; -constexpr int STATE_CLOSE = 2; constexpr int PRIORITY_1 = 1; constexpr int PRIORITY_2 = 2; constexpr int PRIORITY_3 = 3; @@ -183,7 +181,7 @@ struct InterScanInfo { struct SingleAppForbid { int appID; ScanIntervalMode scanIntervalMode; - int lessThanIntervalNum; + int lessThanIntervalCount; time_t continueScanTime; time_t blockListScanTime; int expScanCount; @@ -192,7 +190,7 @@ struct SingleAppForbid { SingleAppForbid() { appID = 0; - lessThanIntervalNum = 0; + lessThanIntervalCount = 0; continueScanTime = 0; blockListScanTime = 0; expScanCount = 0; @@ -266,7 +264,8 @@ struct WifiConfig { int secondRssiLevel5G; int thirdRssiLevel5G; int fourthRssiLevel5G; - + std::string strDnsBak; + bool isLoadStabak; WifiConfig() { scanAlwaysSwitch = false; @@ -300,8 +299,20 @@ struct WifiConfig { secondRssiLevel5G = RSSI_LEVEL_2_5G; thirdRssiLevel5G = RSSI_LEVEL_3_5G; fourthRssiLevel5G = RSSI_LEVEL_4_5G; + strDnsBak = "8.8.8.8"; + isLoadStabak = true; } }; + +struct TrustListPolicy { + int sceneId = 0; /* scene id */ + std::string sceneName; /* scene name, just to read. */ + std::string trustList; /* trust list, eg: for A,B,and C,the format is A|B|C */ +}; + +struct MovingFreezePolicy { + std::string trustList; /* trust list */ +}; } // namespace Wifi } // namespace OHOS #endif diff --git a/services/wifi_standard/wifi_framework/common/net_helper/mac_address.cpp b/services/wifi_standard/wifi_framework/common/net_helper/mac_address.cpp index c527ee2b086f1900be4afa5308eeb57c7fe57c26..eea3838ee3239fc99c5d0228e4ced1a45493dcec 100644 --- a/services/wifi_standard/wifi_framework/common/net_helper/mac_address.cpp +++ b/services/wifi_standard/wifi_framework/common/net_helper/mac_address.cpp @@ -110,7 +110,7 @@ bool MacAddress::IsValid() const void MacAddress::Dump() const { - LOGI("MAC: [%s]", mac_.c_str()); + LOGI("MAC: [%{private}s]", mac_.c_str()); } const std::string &MacAddress::GetMacAddressWifiString() const diff --git a/services/wifi_standard/wifi_framework/common/net_helper/network_interface.cpp b/services/wifi_standard/wifi_framework/common/net_helper/network_interface.cpp index 9300a01e3c231fcbc7ce022d365cc79dfd9e457b..48f41b32e9f746329b14cff66a12e6d94347cea2 100755 --- a/services/wifi_standard/wifi_framework/common/net_helper/network_interface.cpp +++ b/services/wifi_standard/wifi_framework/common/net_helper/network_interface.cpp @@ -58,22 +58,22 @@ bool NetworkInterface::IsValidInterfaceName(const std::string &interfaceName) void NetworkInterface::Dump(const std::string &interfaceName) { - WIFI_LOGI("InterfaceName [%s]", interfaceName.c_str()); + WIFI_LOGI("InterfaceName [%{private}s]", interfaceName.c_str()); std::vector vecIPv4; std::vector vecIPv6; bool ret = FetchInterfaceConfig(interfaceName, vecIPv4, vecIPv6); if (!ret) { - WIFI_LOGI("Fetch Interface [%s] failed.", interfaceName.c_str()); + WIFI_LOGI("Fetch Interface [%{private}s] failed.", interfaceName.c_str()); } - WIFI_LOGI("\tIPv4 size [%zu]", vecIPv4.size()); + WIFI_LOGI("\tIPv4 size [%{private}zu]", vecIPv4.size()); for (const auto &item : vecIPv4) { item.Dump(); } - WIFI_LOGI("\tIPv6 size [%zu]", vecIPv6.size()); + WIFI_LOGI("\tIPv6 size [%{private}zu]", vecIPv6.size()); for (const auto &item : vecIPv6) { item.Dump(); } @@ -146,14 +146,14 @@ bool NetworkInterface::AddIpAddress(const std::string &interfaceName, const Base /* Avoid repeated add. */ if (IsExistAddressForInterface(interfaceName, ipAddress)) { - WIFI_LOGI("In interface [%{public}s], the address [%s] is exist.", + WIFI_LOGI("In interface [%{public}s], the address [%{private}s] is exist.", interfaceName.c_str(), ipAddress.GetAddressWithString().c_str()); return true; } if (!IpAddressChange(interfaceName, ipAddress, true)) { - WIFI_LOGE("Interface [%{public}s] add address [%s] failed.", + WIFI_LOGE("Interface [%{public}s] add address [%{private}s] failed.", interfaceName.c_str(), ipAddress.GetAddressWithString().c_str()); return false; @@ -164,18 +164,18 @@ bool NetworkInterface::AddIpAddress(const std::string &interfaceName, const Base bool NetworkInterface::DelIpAddress(const std::string &interfaceName, const BaseAddress &ipAddress) { if (!ipAddress.IsValid()) { - WIFI_LOGE("Del IP address [%s] is not valid.", ipAddress.GetAddressWithString().c_str()); + WIFI_LOGE("Del IP address [%{private}s] is not valid.", ipAddress.GetAddressWithString().c_str()); return false; } if (!IsExistAddressForInterface(interfaceName, ipAddress)) { - WIFI_LOGI("In interface [%{public}s], the address [%s] is not exist.", + WIFI_LOGI("In interface [%{public}s], the address [%{private}s] is not exist.", interfaceName.c_str(), ipAddress.GetAddressWithString().c_str()); return true; } if (!IpAddressChange(interfaceName, ipAddress, false)) { - WIFI_LOGE("Interface [%{public}s] del address [%s] failed.", + WIFI_LOGE("Interface [%{public}s] del address [%{private}s] failed.", interfaceName.c_str(), ipAddress.GetAddressWithString().c_str()); return false; @@ -283,7 +283,7 @@ bool NetworkInterface::IpAddressChange( const std::string &interface, const BaseAddress &ipAddress, bool action, bool dad) { if (!ipAddress.IsValid() || ipAddress.GetFamilyType() == BaseAddress::FamilyType::FAMILY_INET6) { - WIFI_LOGE("bad input parameter [%{public}s][%s]/[%zu]to change ip.", interface.c_str(), + WIFI_LOGE("bad input parameter [%{public}s][%{private}s]/[%{private}zu]to change ip.", interface.c_str(), ipAddress.GetAddressWithString().c_str(), ipAddress.GetAddressPrefixLength()); return false; } @@ -317,7 +317,7 @@ bool NetworkInterface::IpAddressChange( } if (ioctl(fd, SIOCSIFADDR, &ifr) < 0) { close(fd); - WIFI_LOGE("ioctl set ip address failed, error is: %d.", errno); + WIFI_LOGE("ioctl set ip address failed, error is: %{public}d.", errno); return false; } if (inet_aton(Mask.c_str(), &(sin->sin_addr)) < 0) { @@ -326,7 +326,7 @@ bool NetworkInterface::IpAddressChange( } if (ioctl(fd, SIOCSIFNETMASK, &ifr) < 0) { close(fd); - WIFI_LOGE("ioctl set mask address failed, error is: %d.", errno); + WIFI_LOGE("ioctl set mask address failed, error is: %{public}d.", errno); return false; } close(fd); @@ -337,12 +337,12 @@ bool NetworkInterface::WriteDataToFile(const std::string &fileName, const std::s { int fd = open(fileName.c_str(), O_WRONLY | O_CLOEXEC); if (fd < 0) { - WIFI_LOGE("open %{public}s fail, error: %d", fileName.c_str(), errno); + WIFI_LOGE("open %{public}s fail, error: %{public}d", fileName.c_str(), errno); return false; } if (static_cast(write(fd, content.c_str(), content.length())) != content.length()) { - WIFI_LOGE("write content [%s] to file [%{public}s] failed. error: %{public}d.", + WIFI_LOGE("write content [%{public}s] to file [%{public}s] failed. error: %{public}d.", content.c_str(), fileName.c_str(), errno); close(fd); return false; diff --git a/services/wifi_standard/wifi_framework/common/utils/wifi_common_event_helper.cpp b/services/wifi_standard/wifi_framework/common/utils/wifi_common_event_helper.cpp index 655961862b841e0a9cbcb8110508e089ff98557a..525b90f088abdfd698dfa24305d296b4c205b615 100755 --- a/services/wifi_standard/wifi_framework/common/utils/wifi_common_event_helper.cpp +++ b/services/wifi_standard/wifi_framework/common/utils/wifi_common_event_helper.cpp @@ -37,7 +37,7 @@ bool WifiCommonEventHelper::PublishEvent(const std::string &eventAction, const i CommonEventPublishInfo publishInfo; publishInfo.SetSubscriberPermissions(permissions); if (!CommonEventManager::PublishCommonEvent(commonData, publishInfo)) { - WIFI_LOGE("failed to publish event[%s], code:%d", eventAction.c_str(), code); + WIFI_LOGE("failed to publish event[%{public}s], code:%{public}d", eventAction.c_str(), code); return false; } return true; diff --git a/services/wifi_standard/wifi_framework/common/utils/wifi_global_func.cpp b/services/wifi_standard/wifi_framework/common/utils/wifi_global_func.cpp index 55085f21347e16f63c52b0ca893cb899226e5e25..264ff8e08b5d7883476f9b3714b97b666aebdc0b 100755 --- a/services/wifi_standard/wifi_framework/common/utils/wifi_global_func.cpp +++ b/services/wifi_standard/wifi_framework/common/utils/wifi_global_func.cpp @@ -136,12 +136,9 @@ std::string GetRandomStr(int len) bool IsAllowScanAnyTime(const ScanControlInfo &info) { - auto forbidIter = info.scanForbidMap.find(SCAN_SCENE_ALL); - for (; forbidIter != info.scanForbidMap.end(); forbidIter++) { - for (auto iter = forbidIter->second.begin(); iter != forbidIter->second.end(); iter++) { - if (iter->scanMode == ScanMode::ANYTIME_SCAN) { - return false; - } + for (auto forbidIter = info.scanForbidList.begin(); forbidIter != info.scanForbidList.end(); forbidIter++) { + if (forbidIter->scanMode == ScanMode::ANYTIME_SCAN && forbidIter->scanScene == SCAN_SCENE_ALL) { + return false; } } return true; diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/ap_config_use.cpp b/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/ap_config_use.cpp index 9f846f7dd06cb4dab0072514f33b24060ac1d74d..77b92808152bff7bb9874cddf53b3fdf50f40c6d 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/ap_config_use.cpp +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/ap_config_use.cpp @@ -69,8 +69,8 @@ void ApConfigUse::TransformFrequencyIntoChannel(const std::vector &freqVect void ApConfigUse::LogConfig(HotspotConfig &apConfig) const { - WIFI_LOGI("HotspotConfig::SSID = %s", apConfig.GetSsid().c_str()); - WIFI_LOGI("HotspotConfig::preSharedKey = %s", apConfig.GetPreSharedKey().c_str()); + WIFI_LOGI("HotspotConfig::SSID = %{private}s", apConfig.GetSsid().c_str()); + WIFI_LOGI("HotspotConfig::preSharedKey = %{private}s", apConfig.GetPreSharedKey().c_str()); WIFI_LOGI("HotspotConfig::securityType = %{public}d", static_cast(apConfig.GetSecurityType())); WIFI_LOGI("HotspotConfig::band = %{public}d", static_cast(apConfig.GetBand())); WIFI_LOGI("HotspotConfig::channel = %{public}d", apConfig.GetChannel()); diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/ap_started_state.cpp b/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/ap_started_state.cpp index 42876b6aeff4bc9e58d841ca68140bd05fb213cf..14c38c30071343a128bad68e3bc23914e05856a1 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/ap_started_state.cpp +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/ap_started_state.cpp @@ -303,7 +303,8 @@ void ApStartedState::ProcessCmdAddBlockList(InternalMessage &msg) const staInfo.deviceName = msg.GetStringFromMessage(); staInfo.bssid = msg.GetStringFromMessage(); staInfo.ipAddr = msg.GetStringFromMessage(); - WIFI_LOGI("staInfo:%s, %s, %s.", staInfo.deviceName.c_str(), staInfo.bssid.c_str(), staInfo.ipAddr.c_str()); + WIFI_LOGI("staInfo:%{private}s, %{private}s, %{private}s.", staInfo.deviceName.c_str(), staInfo.bssid.c_str(), + staInfo.ipAddr.c_str()); m_ApStateMachine.m_ApStationsManager.AddBlockList(staInfo); } @@ -314,7 +315,8 @@ void ApStartedState::ProcessCmdDelBlockList(InternalMessage &msg) const staInfo.deviceName = msg.GetStringFromMessage(); staInfo.bssid = msg.GetStringFromMessage(); staInfo.ipAddr = msg.GetStringFromMessage(); - WIFI_LOGI("staInfo:%s, %s, %s.", staInfo.deviceName.c_str(), staInfo.bssid.c_str(), staInfo.ipAddr.c_str()); + WIFI_LOGI("staInfo:%{private}s, %{private}s, %{private}s.", staInfo.deviceName.c_str(), staInfo.bssid.c_str(), + staInfo.ipAddr.c_str()); m_ApStateMachine.m_ApStationsManager.DelBlockList(staInfo); } diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/wifi_ap_nat_manager.cpp b/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/wifi_ap_nat_manager.cpp index 99081e7124448ff6b41d43ed7facb2f1fa67d778..f8d376c4948855e590668c4bfb56064f3300474e 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/wifi_ap_nat_manager.cpp +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/wifi_ap_nat_manager.cpp @@ -38,8 +38,8 @@ const int SYSTEM_NOT_EXECUTED = 127; bool WifiApNatManager::EnableInterfaceNat(bool enable, std::string inInterfaceName, std::string outInterfaceName) const { - WIFI_LOGI("EnableInterfaceNat enable [%{public}s], inInterfaceName [%s] outInterfaceName " - "[%s].", + WIFI_LOGI("EnableInterfaceNat enable [%{public}s], inInterfaceName [%privates] outInterfaceName " + "[%privates].", enable ? "true" : "false", inInterfaceName.c_str(), outInterfaceName.c_str()); @@ -148,7 +148,7 @@ bool WifiApNatManager::WriteDataToFile(const std::string &fileName, const std::s { std::ofstream outf(fileName, std::ios::out); if (!outf) { - WIFI_LOGE("write content [%s] to file [%s] failed. error: %{public}d.", + WIFI_LOGE("write content [%publics] to file [%publics] failed. error: %{public}d.", content.c_str(), fileName.c_str(), errno); return false; } @@ -165,11 +165,11 @@ bool WifiApNatManager::ExecCommand(const std::vector &vecCommandArg command += " "; } - WIFI_LOGE("exec cmd: [%s]", command.c_str()); + WIFI_LOGE("exec cmd: [%{private}s]", command.c_str()); int ret = system(command.c_str()); if (ret == -1 || ret == SYSTEM_NOT_EXECUTED) { - WIFI_LOGE("exec failed. cmd: %s, error:%{public}d.", command.c_str(), errno); + WIFI_LOGE("exec failed. cmd: %{private}s, error:%{public}d.", command.c_str(), errno); return false; } diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_config_center.cpp b/services/wifi_standard/wifi_framework/wifi_manage/wifi_config_center.cpp index dabbd675c2f5af26d440126b9e7dd8057f30729b..2c01f7b5cd0f57a35c469e586cb586a1138129f8 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_config_center.cpp +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_config_center.cpp @@ -145,6 +145,11 @@ int WifiConfigCenter::GetCountryCode(std::string &countryCode) return WifiSettings::GetInstance().GetCountryCode(countryCode); } +bool WifiConfigCenter::IsLoadStabak() +{ + return WifiSettings::GetInstance().IsLoadStabak(); +} + WifiOprMidState WifiConfigCenter::GetApMidState() { return mApMidState.load(); @@ -310,7 +315,7 @@ void WifiConfigCenter::SetScreenState(const int &state) WifiSettings::GetInstance().SetScreenState(state); } -int WifiConfigCenter::GetScreenState() +int WifiConfigCenter::GetScreenState() const { return WifiSettings::GetInstance().GetScreenState(); } @@ -320,17 +325,17 @@ void WifiConfigCenter::SetAirplaneModeState(const int &state) WifiSettings::GetInstance().SetAirplaneModeState(state); } -int WifiConfigCenter::GetAirplaneModeState() +int WifiConfigCenter::GetAirplaneModeState() const { return WifiSettings::GetInstance().GetAirplaneModeState(); } -void WifiConfigCenter::SetAppRunningState(const int &state) +void WifiConfigCenter::SetAppRunningState(ScanMode appRunMode) { - WifiSettings::GetInstance().SetAppRunningState(state); + WifiSettings::GetInstance().SetAppRunningState(appRunMode); } -int WifiConfigCenter::GetAppRunningState() +ScanMode WifiConfigCenter::GetAppRunningState() const { return WifiSettings::GetInstance().GetAppRunningState(); } @@ -340,11 +345,41 @@ void WifiConfigCenter::SetPowerSavingModeState(const int &state) WifiSettings::GetInstance().SetPowerSavingModeState(state); } -int WifiConfigCenter::GetPowerSavingModeState() +int WifiConfigCenter::GetPowerSavingModeState() const { return WifiSettings::GetInstance().GetPowerSavingModeState(); } +void WifiConfigCenter::SetAppPackageName(const std::string &appPackageName) +{ + WifiSettings::GetInstance().SetAppPackageName(appPackageName); +} + +const std::string& WifiConfigCenter::GetAppPackageName() const +{ + return WifiSettings::GetInstance().GetAppPackageName(); +} + +void WifiConfigCenter::SetFreezeModeState(int state) +{ + WifiSettings::GetInstance().SetFreezeModeState(state); +} + +int WifiConfigCenter::GetFreezeModeState() const +{ + return WifiSettings::GetInstance().GetFreezeModeState(); +} + +void WifiConfigCenter::SetNoChargerPlugModeState(int state) +{ + WifiSettings::GetInstance().SetNoChargerPlugModeState(state); +} + +int WifiConfigCenter::GetNoChargerPlugModeState() const +{ + return WifiSettings::GetInstance().GetNoChargerPlugModeState(); +} + int WifiConfigCenter::SetP2pDeviceName(const std::string &deviceName) { return WifiSettings::GetInstance().SetP2pDeviceName(deviceName); diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_config_center.h b/services/wifi_standard/wifi_framework/wifi_manage/wifi_config_center.h index c2e2e68510d130f1e2bb276bbac08f3bc7c750fd..cd9a02b2d92b1e85a8508b61fa1c6095e3dc35cd 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_config_center.h +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_config_center.h @@ -194,6 +194,13 @@ public: */ int GetCountryCode(std::string &countryCode); + /** + * @Description Obtaining Whether to Load the Configuration of the Standby STA. + * + * @return bool - Indicates whether to load the configuration of the standby STA. + */ + bool IsLoadStabak(); + /** * @Description Get current hotspot middle state * @@ -433,7 +440,7 @@ public: * * @return int - 1 open; 2 close */ - int GetScreenState(); + int GetScreenState() const; /** * @Description Set current airplane mode state @@ -447,21 +454,21 @@ public: * * @return int - 1 open; 2 close */ - int GetAirplaneModeState(); + int GetAirplaneModeState() const; /** * @Description Set current app running mode * - * @param state - 1 front; 2 backend + * @param appRunMode - app run mode */ - void SetAppRunningState(const int &state); + void SetAppRunningState(ScanMode appRunMode); /** * @Description Get current app running mode * - * @return int - 1 front; 2 backend + * @param ScanMode */ - int GetAppRunningState(); + ScanMode GetAppRunningState() const; /** * @Description Set current power saving mode @@ -475,7 +482,49 @@ public: * * @return int - 1 saving mode; 2 not saving mode */ - int GetPowerSavingModeState(); + int GetPowerSavingModeState() const; + + /** + * @Description Set app package name. + * + * @param appPackageName - app package name + */ + void SetAppPackageName(const std::string &appPackageName); + + /** + * @Description Get app package name. + * + * @return const std::string& - app package name. + */ + const std::string& GetAppPackageName() const; + + /** + * @Description Set freeze mode state. + * + * @param state - 1 freeze mode; 2 moving mode + */ + void SetFreezeModeState(int state); + + /** + * @Description Get freeze mode state. + * + * @return freeze mode. + */ + int GetFreezeModeState() const; + + /** + * @Description Set no charger plugged in mode. + * + * @param state - 1 no charger plugged in mode; 2 charger plugged in mode + */ + void SetNoChargerPlugModeState(int state); + + /** + * @Description Get no charger plugged in mode. + * + * @return no charger plugged in mode. + */ + int GetNoChargerPlugModeState() const; /** * @Description set the device name diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_device_stub.cpp b/services/wifi_standard/wifi_framework/wifi_manage/wifi_device_stub.cpp index fe05033f2eec75dba16bcf16890abe6ab8a78594..f6f39c276f125afd6a8b27bd24202eddd71dc403 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_device_stub.cpp +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_device_stub.cpp @@ -506,7 +506,7 @@ void WifiDeviceStub::OnGetCountryCode(uint32_t code, MessageParcel &data, Messag void WifiDeviceStub::OnRegisterCallBack(uint32_t code, MessageParcel &data, MessageParcel &reply) { - WIFI_LOGD("run %{public}s code %{public}u, datasize %zu", __func__, code, data.GetRawDataSize()); + WIFI_LOGD("run %{public}s code %{public}u, datasize %{public}zu", __func__, code, data.GetRawDataSize()); ErrCode ret = WIFI_OPT_FAILED; do { sptr remote = data.ReadRemoteObject(); diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_hotspot_stub.cpp b/services/wifi_standard/wifi_framework/wifi_manage/wifi_hotspot_stub.cpp index f1453995773a821a682dfbd3552b08101339d0e4..44a4491b21f1982554efd5de10a9ce86e86bafaa 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_hotspot_stub.cpp +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_hotspot_stub.cpp @@ -72,7 +72,7 @@ int WifiHotspotStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Message void WifiHotspotStub::OnIsHotspotActive(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - WIFI_LOGD("run %{public}s code %{public}u, datasize %zu", __func__, code, data.GetRawDataSize()); + WIFI_LOGD("run %{public}s code %{public}u, datasize %{public}zu", __func__, code, data.GetRawDataSize()); bool bActive = false; ErrCode ret = IsHotspotActive(bActive); reply.WriteInt32(0); @@ -85,7 +85,7 @@ void WifiHotspotStub::OnIsHotspotActive(uint32_t code, MessageParcel &data, Mess void WifiHotspotStub::OnGetApStateWifi(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - WIFI_LOGD("run %{public}s code %{public}u, datasize %zu", __func__, code, data.GetRawDataSize()); + WIFI_LOGD("run %{public}s code %{public}u, datasize %{public}zu", __func__, code, data.GetRawDataSize()); int state = 0; ErrCode ret = GetHotspotState(state); reply.WriteInt32(0); @@ -99,7 +99,7 @@ void WifiHotspotStub::OnGetApStateWifi(uint32_t code, MessageParcel &data, Messa void WifiHotspotStub::OnGetHotspotConfig( uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - WIFI_LOGD("run %{public}s code %{public}u, datasize %zu", __func__, code, data.GetRawDataSize()); + WIFI_LOGD("run %{public}s code %{public}u, datasize %{public}zu", __func__, code, data.GetRawDataSize()); HotspotConfig hotspotConfig; ErrCode ret = GetHotspotConfig(hotspotConfig); @@ -119,7 +119,7 @@ void WifiHotspotStub::OnGetHotspotConfig( void WifiHotspotStub::OnSetApConfigWifi(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - WIFI_LOGD("run %{public}s code %{public}u, datasize %zu", __func__, code, data.GetRawDataSize()); + WIFI_LOGD("run %{public}s code %{public}u, datasize %{public}zu", __func__, code, data.GetRawDataSize()); HotspotConfig config; config.SetSsid(data.ReadCString()); config.SetSecurityType(static_cast(data.ReadInt32())); @@ -136,7 +136,7 @@ void WifiHotspotStub::OnSetApConfigWifi(uint32_t code, MessageParcel &data, Mess void WifiHotspotStub::OnGetStationList(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - WIFI_LOGD("run %{public}s code %{public}u, datasize %zu", __func__, code, data.GetRawDataSize()); + WIFI_LOGD("run %{public}s code %{public}u, datasize %{public}zu", __func__, code, data.GetRawDataSize()); std::vector result; ErrCode ret = GetStationList(result); @@ -157,7 +157,7 @@ void WifiHotspotStub::OnGetStationList(uint32_t code, MessageParcel &data, Messa void WifiHotspotStub::OnDisassociateSta(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - WIFI_LOGD("run %{public}s code %{public}u, datasize %zu", __func__, code, data.GetRawDataSize()); + WIFI_LOGD("run %{public}s code %{public}u, datasize %{public}zu", __func__, code, data.GetRawDataSize()); StationInfo info; info.deviceName = data.ReadCString(); info.bssid = data.ReadCString(); @@ -170,7 +170,7 @@ void WifiHotspotStub::OnDisassociateSta(uint32_t code, MessageParcel &data, Mess void WifiHotspotStub::OnGetValidBands(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - WIFI_LOGD("run %{public}s code %{public}u, datasize %zu", __func__, code, data.GetRawDataSize()); + WIFI_LOGD("run %{public}s code %{public}u, datasize %{public}zu", __func__, code, data.GetRawDataSize()); std::vector bands; ErrCode ret = GetValidBands(bands); @@ -189,7 +189,7 @@ void WifiHotspotStub::OnGetValidBands(uint32_t code, MessageParcel &data, Messag void WifiHotspotStub::OnGetValidChannels( uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - WIFI_LOGD("run %{public}s code %{public}u, datasize %zu", __func__, code, data.GetRawDataSize()); + WIFI_LOGD("run %{public}s code %{public}u, datasize %{public}zu", __func__, code, data.GetRawDataSize()); std::vector channels; int32_t band = data.ReadInt32(); ErrCode ret = GetValidChannels(static_cast(band), channels); @@ -208,7 +208,7 @@ void WifiHotspotStub::OnGetValidChannels( void WifiHotspotStub::OnEnableWifiAp(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - WIFI_LOGD("run %{public}s code %{public}u, datasize %zu", __func__, code, data.GetRawDataSize()); + WIFI_LOGD("run %{public}s code %{public}u, datasize %{public}zu", __func__, code, data.GetRawDataSize()); ErrCode ret = EnableHotspot(); reply.WriteInt32(0); reply.WriteInt32(ret); @@ -218,7 +218,7 @@ void WifiHotspotStub::OnEnableWifiAp(uint32_t code, MessageParcel &data, Message void WifiHotspotStub::OnDisableWifiAp(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - WIFI_LOGD("run %{public}s code %{public}u, datasize %zu", __func__, code, data.GetRawDataSize()); + WIFI_LOGD("run %{public}s code %{public}u, datasize %{public}zu", __func__, code, data.GetRawDataSize()); ErrCode ret = DisableHotspot(); reply.WriteInt32(0); reply.WriteInt32(ret); @@ -228,7 +228,7 @@ void WifiHotspotStub::OnDisableWifiAp(uint32_t code, MessageParcel &data, Messag void WifiHotspotStub::OnAddBlockList(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - WIFI_LOGD("run %{public}s code %{public}u, datasize %zu", __func__, code, data.GetRawDataSize()); + WIFI_LOGD("run %{public}s code %{public}u, datasize %{public}zu", __func__, code, data.GetRawDataSize()); StationInfo info; info.deviceName = data.ReadCString(); info.bssid = data.ReadCString(); @@ -242,7 +242,7 @@ void WifiHotspotStub::OnAddBlockList(uint32_t code, MessageParcel &data, Message void WifiHotspotStub::OnDelBlockList(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - WIFI_LOGD("run %{public}s code %{public}u, datasize %zu", __func__, code, data.GetRawDataSize()); + WIFI_LOGD("run %{public}s code %{public}u, datasize %{public}zu", __func__, code, data.GetRawDataSize()); StationInfo info; info.deviceName = data.ReadCString(); info.bssid = data.ReadCString(); @@ -256,7 +256,7 @@ void WifiHotspotStub::OnDelBlockList(uint32_t code, MessageParcel &data, Message void WifiHotspotStub::OnGetBlockLists(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - WIFI_LOGD("run %{public}s code %{public}u, datasize %zu", __func__, code, data.GetRawDataSize()); + WIFI_LOGD("run %{public}s code %{public}u, datasize %{public}zu", __func__, code, data.GetRawDataSize()); std::vector infos; ErrCode ret = GetBlockLists(infos); reply.WriteInt32(0); @@ -277,7 +277,7 @@ void WifiHotspotStub::OnGetBlockLists(uint32_t code, MessageParcel &data, Messag void WifiHotspotStub::OnRegisterCallBack( uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - WIFI_LOGD("run %{public}s code %{public}u, datasize %zu", __func__, code, data.GetRawDataSize()); + WIFI_LOGD("run %{public}s code %{public}u, datasize %{public}zu", __func__, code, data.GetRawDataSize()); ErrCode ret = WIFI_OPT_FAILED; do { sptr remote = data.ReadRemoteObject(); diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_manager.cpp b/services/wifi_standard/wifi_framework/wifi_manage/wifi_manager.cpp index 0b94b453957bf971d265de3e7cf4862861d34392..ea429de0a2aeee26691ba5ff9a30383d51c5fe2b 100755 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_manager.cpp +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_manager.cpp @@ -63,12 +63,12 @@ void WifiManager::AutoStartStaService(void) ErrCode errCode = WIFI_OPT_FAILED; do { if (WifiServiceManager::GetInstance().CheckAndEnforceService(WIFI_SERVICE_STA) < 0) { - WIFI_LOGE("Load %s service failed!", WIFI_SERVICE_STA); + WIFI_LOGE("Load %{public}s service failed!", WIFI_SERVICE_STA); break; } IStaService *pService = WifiServiceManager::GetInstance().GetStaServiceInst(); if (pService == nullptr) { - WIFI_LOGE("Create %s service failed!", WIFI_SERVICE_STA); + WIFI_LOGE("Create %{public}s service failed!", WIFI_SERVICE_STA); break; } errCode = pService->RegisterStaServiceCallback(WifiManager::GetInstance().GetStaCallback()); @@ -78,7 +78,7 @@ void WifiManager::AutoStartStaService(void) } errCode = pService->EnableWifi(); if (errCode != WIFI_OPT_SUCCESS) { - WIFI_LOGE("service enable sta failed, ret %d!", static_cast(errCode)); + WIFI_LOGE("service enable sta failed, ret %{public}d!", static_cast(errCode)); break; } } while (0); diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/group_formed_state.cpp b/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/group_formed_state.cpp index 1f356797e79d74d4a1f02c8940ff89e8ff9ccaf9..a04399aebf99ed13d2751c3141557fb6ddbc951f 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/group_formed_state.cpp +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/group_formed_state.cpp @@ -242,14 +242,15 @@ bool GroupFormedState::ProcessConnectEvt(const InternalMessage &msg) const bool GroupFormedState::ProcessCmdCancelConnect(const InternalMessage &msg) const { - WIFI_LOGI("Process cmd cancel connect recv CMD: %d", msg.GetMessageName()); + WIFI_LOGI("recv CMD: %{public}d", msg.GetMessageName()); p2pStateMachine.BroadcastActionResult(P2pActionCallback::P2pDisConnect, ErrCode::WIFI_OPT_FAILED); return EXECUTED; } bool GroupFormedState::ProcessCmdDiscServices(const InternalMessage &msg) const { - WIFI_LOGI("Process cmd disc services recv CMD: %d", msg.GetMessageName()); + WIFI_LOGI("recv CMD: %{public}d", msg.GetMessageName()); + WIFI_LOGD("p2p_enabled_state recv CMD_DISCOVER_SERVICES"); p2pStateMachine.CancelSupplicantSrvDiscReq(); std::string reqId; @@ -270,7 +271,7 @@ bool GroupFormedState::ProcessCmdDiscServices(const InternalMessage &msg) const retCode = WifiP2PHalInterface::GetInstance().P2pFind(DISC_TIMEOUT_S); if (retCode != WifiErrorNo::WIFI_IDL_OPT_OK) { - WIFI_LOGE("call P2pFind failed, ErrorCode: %d", static_cast(retCode)); + WIFI_LOGE("call P2pFind failed, ErrorCode: %{public}d", static_cast(retCode)); p2pStateMachine.BroadcastActionResult(P2pActionCallback::DiscoverServices, ErrCode::WIFI_OPT_FAILED); return EXECUTED; } @@ -290,7 +291,8 @@ bool GroupFormedState::ProcessCmdStartListen(const InternalMessage &msg) const constexpr int defaultOpClass = 81; constexpr int defaultChannel = 6; if (WifiP2PHalInterface::GetInstance().SetListenChannel(defaultChannel, defaultOpClass)) { - WIFI_LOGI("p2p set listen channel failed. channel:%d, opclass:%d", defaultChannel, defaultOpClass); + WIFI_LOGI("p2p set listen channel failed. channel:%{public}d, opclass:%{public}d", defaultChannel, + defaultOpClass); p2pStateMachine.BroadcastActionResult(P2pActionCallback::StartP2pListen, WIFI_OPT_FAILED); return EXECUTED; } diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/p2p_enabled_state.cpp b/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/p2p_enabled_state.cpp index 94f500b04c68207b91066ea3d430351a1192ce40..b01290f9d5edd2ee46e38cf31a72d387bd74a4ef 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/p2p_enabled_state.cpp +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/p2p_enabled_state.cpp @@ -509,14 +509,14 @@ bool P2pEnabledState::ProcessServiceDiscRspEvt(InternalMessage &msg) const } bool P2pEnabledState::ProcessExceptionTimeOut(InternalMessage &msg) const { - WIFI_LOGI("recv exception timeout event: %d", msg.GetMessageName()); + WIFI_LOGI("recv exception timeout event: %{public}d", msg.GetMessageName()); p2pStateMachine.SwitchState(&p2pStateMachine.p2pIdleState); return EXECUTED; } bool P2pEnabledState::ProcessCmdSetDeviceName(InternalMessage &msg) const { - LOGD("p2p_enabled_state CMD: set device name."); + WIFI_LOGD("p2p_enabled_state CMD: set device name."); std::string deviceName; if (!msg.GetMessageObj(deviceName)) { LOGE("Failed to obtain string information."); @@ -525,11 +525,11 @@ bool P2pEnabledState::ProcessCmdSetDeviceName(InternalMessage &msg) const WifiErrorNo retCode = WifiP2PHalInterface::GetInstance().SetP2pDeviceName(deviceName); if (retCode == WifiErrorNo::WIFI_IDL_OPT_FAILED) { - LOGE("Failed to set the device name."); + WIFI_LOGE("Failed to set the device name."); p2pStateMachine.BroadcastActionResult(P2pActionCallback::P2pSetDeviceName, WIFI_OPT_FAILED); return EXECUTED; } else { - LOGE("Successfully set the device name."); + WIFI_LOGE("Successfully set the device name."); deviceManager.GetThisDevice().SetDeviceName(deviceName); p2pStateMachine.BroadcastThisDeviceChanaged(deviceManager.GetThisDevice()); p2pStateMachine.BroadcastActionResult(P2pActionCallback::P2pSetDeviceName, WIFI_OPT_SUCCESS); @@ -538,16 +538,16 @@ bool P2pEnabledState::ProcessCmdSetDeviceName(InternalMessage &msg) const const std::string ssidPostfixName = std::string("-") + deviceName; retCode = WifiP2PHalInterface::GetInstance().SetP2pSsidPostfix(ssidPostfixName); if (retCode == WifiErrorNo::WIFI_IDL_OPT_FAILED) { - LOGE("Failed to set the SSID prefix"); + WIFI_LOGE("Failed to set the SSID prefix"); } return EXECUTED; } bool P2pEnabledState::ProcessCmdSetWfdInfo(InternalMessage &msg) const { - LOGI("recv CMD: %d", msg.GetMessageName()); + WIFI_LOGI("recv CMD: %{public}d", msg.GetMessageName()); WifiP2pWfdInfo wfdInfo; if (!msg.GetMessageObj(wfdInfo)) { - LOGE("Failed to obtain wfd information."); + WIFI_LOGE("Failed to obtain wfd information."); return EXECUTED; } @@ -555,11 +555,11 @@ bool P2pEnabledState::ProcessCmdSetWfdInfo(InternalMessage &msg) const wfdInfo.GetDeviceInfoElement(subelement); subelement = "0 " + subelement; if (WifiP2PHalInterface::GetInstance().SetWfdDeviceConfig(subelement) != WifiErrorNo::WIFI_IDL_OPT_OK) { - LOGE("Failed to set wfd config:%s.", subelement.c_str()); + WIFI_LOGE("Failed to set wfd config:%{public}s.", subelement.c_str()); return EXECUTED; } if (WifiP2PHalInterface::GetInstance().SetWfdEnable(wfdInfo.GetWfdEnabled()) != WifiErrorNo::WIFI_IDL_OPT_OK) { - LOGE("Set wifidisplay enabled failed."); + WIFI_LOGE("Set wifidisplay enabled failed."); return EXECUTED; } return EXECUTED; @@ -567,7 +567,7 @@ bool P2pEnabledState::ProcessCmdSetWfdInfo(InternalMessage &msg) const bool P2pEnabledState::ProcessCmdCancelConnect(InternalMessage &msg) const { - WIFI_LOGI("recv CMD: %d", msg.GetMessageName()); + WIFI_LOGI("recv CMD: %{public}d", msg.GetMessageName()); p2pStateMachine.BroadcastActionResult(P2pActionCallback::P2pDisConnect, ErrCode::WIFI_OPT_FAILED); return EXECUTED; } diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/p2p_group_operating_state.cpp b/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/p2p_group_operating_state.cpp index 3458e1df7d1858a35696b5ff7237b1b198ac482c..7feea7394afba974eb9d4c77b20164cc212095b1 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/p2p_group_operating_state.cpp +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/p2p_group_operating_state.cpp @@ -83,7 +83,7 @@ bool P2pGroupOperatingState::ProcessCmdCreateGroup(const InternalMessage &msg) c /** * Create a new persistence group. */ - WIFI_LOGE("Create a new %s group.", (netId == PERSISTENT_NET_ID) ? "persistence" : "temporary"); + WIFI_LOGE("Create a new %{public}s group.", (netId == PERSISTENT_NET_ID) ? "persistence" : "temporary"); if (config.GetPassphrase().empty() && config.GetGroupName().empty()) { ret = WifiP2PHalInterface::GetInstance().GroupAdd((netId == PERSISTENT_NET_ID) ? true : false, netId, freq); } else if (!config.GetPassphrase().empty() && !config.GetGroupName().empty() && diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/p2p_state_machine.cpp b/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/p2p_state_machine.cpp index 3d642187ff502d1cf9b33aa9a22629386d27e9ae..fa30520b9a4cbb4ccdc015b2f4b9b7d13375a0ae 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/p2p_state_machine.cpp +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/p2p_state_machine.cpp @@ -707,7 +707,7 @@ void P2pStateMachine::DhcpResultNotify::OnFailed(int status, const std::string & void P2pStateMachine::DhcpResultNotify::OnSerExitNotify(const std::string& ifname) { - WIFI_LOGD("Dhcp exit notify.ifname:%s.", ifname.c_str()); + WIFI_LOGD("Dhcp exit notify.ifname:%{public}s.", ifname.c_str()); pP2pStateMachine->SendMessage(static_cast(P2P_STATE_MACHINE_CMD::CMD_P2P_DISABLE)); } @@ -860,7 +860,7 @@ bool P2pStateMachine::DealCreateNewGroupWithConfig(const WifiP2pConfigInternal & } if (ret == WIFI_IDL_OPT_FAILED || netId == TEMPORARY_NET_ID) { - WIFI_LOGD("Remove network %d!", createdNetId); + WIFI_LOGD("Remove network %{public}d!", createdNetId); WifiP2PHalInterface::GetInstance().RemoveNetwork(createdNetId); } @@ -897,7 +897,7 @@ void P2pStateMachine::UpdateGroupInfoToWpa() const WifiP2PHalInterface::GetInstance().P2pSetGroupConfig(createdNetId, wpaConfig); grpInfo.at(i) = grpBuf; } else { - WIFI_LOGW("AddNetwork failed when add %s group!", grpBuf.GetGroupName().c_str()); + WIFI_LOGW("AddNetwork failed when add %{public}s group!", grpBuf.GetGroupName().c_str()); } } return; diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/provision_discovery_state.cpp b/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/provision_discovery_state.cpp index 581abbae0378b10b25d46796a13753d11f5362b1..685b053d4d879f826ffb6b024b4e3eb30a626873 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/provision_discovery_state.cpp +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/provision_discovery_state.cpp @@ -67,21 +67,21 @@ void ProvisionDiscoveryState::Init() bool ProvisionDiscoveryState::ProcessCmdDiscoverPeer(InternalMessage &msg) const { - WIFI_LOGI("Discover peer recv CMD: %{public}d", msg.GetMessageName()); + WIFI_LOGI("recv CMD: %{public}d", msg.GetMessageName()); p2pStateMachine.BroadcastActionResult(P2pActionCallback::DiscoverDevices, ErrCode::WIFI_OPT_FAILED); return EXECUTED; } bool ProvisionDiscoveryState::ProcessCmdDiscServices(InternalMessage &msg) const { - LOGI("Disc service recv CMD: %d", msg.GetMessageName()); + WIFI_LOGI("recv CMD: %{public}d", msg.GetMessageName()); p2pStateMachine.BroadcastActionResult(P2pActionCallback::DiscoverServices, ErrCode::WIFI_OPT_FAILED); return EXECUTED; } bool ProvisionDiscoveryState::ProcessCmdStartListen(InternalMessage &msg) const { - LOGI("Start listen recv CMD: %d", msg.GetMessageName()); + WIFI_LOGI("recv CMD: %{public}d", msg.GetMessageName()); p2pStateMachine.BroadcastActionResult(P2pActionCallback::StartP2pListen, ErrCode::WIFI_OPT_FAILED); return EXECUTED; } @@ -170,7 +170,7 @@ bool ProvisionDiscoveryState::ProcessProvDiscFailEvt(InternalMessage &msg) const bool ProvisionDiscoveryState::ProcessCmdCancelConnect(InternalMessage &msg) const { - WIFI_LOGI("recv event: %d", msg.GetMessageName()); + WIFI_LOGI("recv event: %{public}d", msg.GetMessageName()); WifiP2PHalInterface::GetInstance().CancelConnect(); p2pStateMachine.DealGroupCreationFailed(); p2pStateMachine.SwitchState(&p2pStateMachine.p2pIdleState); diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/wifi_p2p_service.cpp b/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/wifi_p2p_service.cpp index 53b63ee50ab8cad2396e221de63fb4a841ac1ed8..fc001c223698abe0406c04b17628b732b1934c4c 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/wifi_p2p_service.cpp +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/wifi_p2p_service.cpp @@ -169,7 +169,7 @@ ErrCode WifiP2pService::SetP2pDeviceName(const std::string &devName) ErrCode WifiP2pService::SetP2pWfdInfo(const WifiP2pWfdInfo &wfdInfo) { - WIFI_LOGD("enable = %d device info = %d port = %d throughput = %d\n", + WIFI_LOGD("enable = %{public}d device info = %{public}d port = %{public}d throughput = %{public}d\n", wfdInfo.GetWfdEnabled(), wfdInfo.GetDeviceInfo(), wfdInfo.GetCtrlPort(), wfdInfo.GetMaxThroughput()); p2pStateMachine.SendMessage(static_cast(P2P_STATE_MACHINE_CMD::CMD_SET_WFD_INFO), wfdInfo); return ErrCode::WIFI_OPT_SUCCESS; diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/wifi_p2p_service_manager.cpp b/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/wifi_p2p_service_manager.cpp index beb1a69fac0f53ca9e6f72e8e41f0b4666213c50..ffce8f56bb989d0cb51c60c0584293df0001d01d 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/wifi_p2p_service_manager.cpp +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p/wifi_p2p_service_manager.cpp @@ -369,7 +369,7 @@ bool WifiP2pServiceManager::UpdateServiceName(const std::string &devAddr, const { auto iter = deviceService.find(devAddr); if (iter == deviceService.end()) { - WIFI_LOGE("Cannot find %s, update service name failed!", devAddr.c_str()); + WIFI_LOGE("Cannot find %{public}s, update service name failed!", devAddr.c_str()); return false; } diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p_service_impl.cpp b/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p_service_impl.cpp index c7c29b74bfade250d5e6856b3ebfb6eee7a037c2..aeada0a0f3f9e792fbe4f8ea970e0e471baa8b00 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p_service_impl.cpp +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_p2p_service_impl.cpp @@ -607,7 +607,7 @@ bool WifiP2pServiceImpl::IsP2pServiceRunning() ErrCode WifiP2pServiceImpl::SetP2pDeviceName(const std::string &deviceName) { - WIFI_LOGI("SetDeviceName:%s", deviceName.c_str()); + WIFI_LOGI("SetDeviceName:%{public}s", deviceName.c_str()); int length = deviceName.length(); if (length > DEVICE_NAME_LENGTH || length < 0) { return WIFI_OPT_INVALID_PARAM; diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/BUILD.gn b/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/BUILD.gn index caa661a47f91ed318a48878d4998ae8138d31e87..c0c4bf6278482517d74a143879b3568f2f7abeb8 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/BUILD.gn +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/BUILD.gn @@ -13,6 +13,9 @@ import("//build/ohos.gni") +#defines = [] +#defines += [ "OHOS_WIFI_SCAN_CONTROL_CLOSE" ] + ohos_shared_library("wifi_scan_service") { install_enable = true sources = [ diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/iscan_service.h b/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/iscan_service.h index 4be934564b1567819475f00c6d90297c1941ed2b..e4471b2650cd6f2490a978deb2f348b904092d62 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/iscan_service.h +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/iscan_service.h @@ -50,6 +50,13 @@ public: * @return success: WIFI_OPT_SUCCESS, failed: WIFI_OPT_FAILED */ virtual ErrCode ScanWithParam(const WifiScanParams &wifiScanParams) = 0; + /** + * @Description Disable/Restore the scanning operation. + * + * * @param params - disable or not. + * @return success: WIFI_OPT_SUCCESS, failed: WIFI_OPT_FAILED + */ + virtual ErrCode DisableScan(bool disable) = 0; /** * @Description Processes interface service screen change request. * @@ -70,7 +77,13 @@ public: * @param appMode operate app mode[in] * @return success: WIFI_OPT_SUCCESS, failed: WIFI_OPT_FAILED */ - virtual ErrCode OnAppRunningModeChanged(int appMode) = 0; + virtual ErrCode OnAppRunningModeChanged(ScanMode appRunMode) = 0; + /** + * @Description Updates the MovingFreeze state when the associated state changes. + * + * @return success: WIFI_OPT_SUCCESS, failed: WIFI_OPT_FAILED + */ + virtual ErrCode OnMovingFreezeStateChange() = 0; /** * @Description Processes interface service custom scene change request. * @@ -79,6 +92,13 @@ public: * @return success: WIFI_OPT_SUCCESS, failed: WIFI_OPT_FAILED */ virtual ErrCode OnCustomControlStateChanged(int customScene, int customSceneStatus) = 0; + /** + * @Description Get custom scene state. + * + * @param sceneMap custom scene state map[out] + * @return success: WIFI_OPT_SUCCESS, failed: WIFI_OPT_FAILED + */ + virtual ErrCode OnGetCustomSceneState(std::map& sceneMap) const = 0; /** * @Description Processes interface service scan control info change request. * diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/iscan_service_callbacks.h b/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/iscan_service_callbacks.h index 7b18eeab257a2fdfcb16ea66f62b5e2a35409396..c1e495a002962f9f79f4361275d6d2ca842cdf1c 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/iscan_service_callbacks.h +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/iscan_service_callbacks.h @@ -26,6 +26,7 @@ struct IScanSerivceCallbacks { std::function OnScanStopEvent; std::function OnScanFinishEvent; std::function &)> OnScanInfoEvent; + std::function &)> OnStoreScanInfoEvent; }; } // namespace Wifi } // namespace OHOS diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_common.h b/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_common.h index c7782e81a5fd153a6ad573cc6c78f4cb480815d2..de381653ebb1916c496ebe96c67c28e27d86a01d 100755 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_common.h +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_common.h @@ -52,6 +52,7 @@ struct ScanConfig { int backScanPeriod; /* Scan interval for background scan */ bool fullScanFlag; /* Flag indicating whether the request is full scan */ bool externFlag; /* Flag indicating whether the request is an external scan */ + bool scanningWithParamFlag; /* Flag Indicating whether scanning with parameter */ std::string ssid; /* The network name */ std::string bssid; /* The address of the access point */ int scanStyle; /* Type of scan to perform */ @@ -62,6 +63,7 @@ struct ScanConfig { backScanPeriod = 0; fullScanFlag = false; externFlag = false; + scanningWithParamFlag = false; scanStyle = 0xFF; } }; @@ -101,12 +103,13 @@ struct StoreScanConfig { int64_t scanTime; /* Scan Start Time */ bool fullScanFlag; /* Flag of scan without specifying parameters */ bool externFlag; /* Flag indicating whether the request is an external scan. */ - + bool scanningWithParamFlag; /* Flag Indicating whether scanning with parameter */ StoreScanConfig() { scanTime = 0; fullScanFlag = false; externFlag = false; + scanningWithParamFlag = false; } }; diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_interface.cpp b/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_interface.cpp index da8b40f0962eb4c65b8ca1916acebc6919d0f72b..8d1cd59fc3db4e5d2d52d77bea45441e3474e09f 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_interface.cpp +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_interface.cpp @@ -15,7 +15,7 @@ #include "scan_interface.h" #include "wifi_logger.h" -DEFINE_WIFILOG_SCAN_LABEL("ScanStateMachine"); +DEFINE_WIFILOG_SCAN_LABEL("ScanInterface"); namespace OHOS { namespace Wifi { @@ -83,19 +83,22 @@ ErrCode ScanInterface::ScanWithParam(const WifiScanParams &wifiScanParams) return pScanService->ScanWithParam(wifiScanParams); } +ErrCode ScanInterface::DisableScan(bool disable) +{ + WIFI_LOGI("Enter ScanInterface::DisableScan"); + + return pScanService->DisableScan(disable); +} + ErrCode ScanInterface::OnScreenStateChanged(int screenState) { WIFI_LOGI("Enter ScanInterface::OnScreenStateChanged\n"); - if (screenState != STATE_OPEN && screenState != STATE_CLOSE) { + if (screenState != MODE_STATE_OPEN && screenState != MODE_STATE_CLOSE) { WIFI_LOGE("screenState param is error"); return WIFI_OPT_INVALID_PARAM; } - bool screenOn = true; - if (screenState == STATE_CLOSE) { - screenOn = false; - } - pScanService->HandleScreenStatusChanged(screenOn); + pScanService->HandleScreenStatusChanged(); return WIFI_OPT_SUCCESS; } @@ -108,11 +111,21 @@ ErrCode ScanInterface::OnClientModeStatusChanged(int staStatus) return WIFI_OPT_SUCCESS; } -ErrCode ScanInterface::OnAppRunningModeChanged(int appMode) +ErrCode ScanInterface::OnAppRunningModeChanged(ScanMode appRunMode) { WIFI_LOGI("Enter ScanInterface::OnAppRunningModeChanged\n"); - pScanService->SetOperateAppMode(appMode); + WIFI_LOGD("appRunMode=%{public}d", static_cast(appRunMode)); + + return WIFI_OPT_SUCCESS; +} + +ErrCode ScanInterface::OnMovingFreezeStateChange() +{ + LOGI("Enter ScanInterface::OnMovingFreezeStateChange"); + + pScanService->HandleMovingFreezeChanged(); + return WIFI_OPT_SUCCESS; } @@ -120,7 +133,7 @@ ErrCode ScanInterface::OnCustomControlStateChanged(int customScene, int customSc { WIFI_LOGI("Enter ScanInterface::OnCustomControlStateChanged\n"); - if (customSceneStatus != STATE_OPEN && customSceneStatus != STATE_CLOSE) { + if (customSceneStatus != MODE_STATE_OPEN && customSceneStatus != MODE_STATE_CLOSE) { WIFI_LOGE("screenState param is error"); return WIFI_OPT_INVALID_PARAM; } @@ -128,6 +141,14 @@ ErrCode ScanInterface::OnCustomControlStateChanged(int customScene, int customSc return WIFI_OPT_SUCCESS; } +ErrCode ScanInterface::OnGetCustomSceneState(std::map& sceneMap) const +{ + WIFI_LOGI("Enter ScanInterface::OnGetCustomSceneState\n"); + + pScanService->HandleGetCustomSceneState(sceneMap); + return WIFI_OPT_SUCCESS; +} + ErrCode ScanInterface::OnControlStrategyChanged() { WIFI_LOGI("Enter ScanInterface::OnControlStrategyChanged\n"); diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_interface.h b/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_interface.h index 06da44c944caf97cf3e7f8a9ff4e88d8839c1136..5063ded1469b179320f4a4f40e99e8b7315b8009 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_interface.h +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_interface.h @@ -16,6 +16,8 @@ #ifndef OHOS_WIFI_SCAN_INTERFACE_H #define OHOS_WIFI_SCAN_INTERFACE_H +#include +#include "define.h" #include "iscan_service.h" #include "scan_service.h" @@ -53,6 +55,13 @@ public: * @return success: WIFI_OPT_SUCCESS, failed: WIFI_OPT_FAILED */ ErrCode ScanWithParam(const WifiScanParams &wifiScanParams); + /** + * @Description Disable/Restore the scanning operation. + * + * * @param params - disable or not. + * @return success: WIFI_OPT_SUCCESS, failed: WIFI_OPT_FAILED + */ + ErrCode DisableScan(bool disable); /** * @Description Processes interface service screen change request. * @@ -73,7 +82,13 @@ public: * @param appMode operate app mode[in] * @return success: WIFI_OPT_SUCCESS, failed: WIFI_OPT_FAILED */ - ErrCode OnAppRunningModeChanged(int appMode); + ErrCode OnAppRunningModeChanged(ScanMode appRunMode); + /** + * @Description Updates the MovingFreeze state when the associated state changes. + * + * @return success: WIFI_OPT_SUCCESS, failed: WIFI_OPT_FAILED + */ + ErrCode OnMovingFreezeStateChange(); /** * @Description Processes interface service custom scene change request. * @@ -82,6 +97,13 @@ public: * @return success: WIFI_OPT_SUCCESS, failed: WIFI_OPT_FAILED */ ErrCode OnCustomControlStateChanged(int customScene, int customSceneStatus); + /** + * @Description Get custom scene state. + * + * @param sceneMap custom scene state map[out] + * @return success: WIFI_OPT_SUCCESS, failed: WIFI_OPT_FAILED + */ + ErrCode OnGetCustomSceneState(std::map& customSceneStateMap) const; /** * @Description Processes interface service scan control info change request. * diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_service.cpp b/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_service.cpp index 37134881f41adcb6c4f26e9ca29e0b8c523963b6..87c73ad4641e10fa364f5a903ba398ae783155c7 100755 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_service.cpp +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_service.cpp @@ -12,11 +12,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include + #include "scan_service.h" #include "wifi_logger.h" #include "wifi_settings.h" #include "wifi_sta_hal_interface.h" +#include "wifi_internal_msg.h" +#include "log_helper.h" +#include "wifi_global_func.h" DEFINE_WIFILOG_SCAN_LABEL("ScanService"); @@ -28,16 +31,20 @@ ScanService::ScanService() scanStartedFlag(false), scanConfigStoreIndex(0), pnoScanStartTime(0), - isScreenOn(true), staStatus(static_cast(OperateResState::DISCONNECT_DISCONNECTED)), isPnoScanBegined(false), autoNetworkSelection(false), lastSystemScanTime(0), pnoScanFailedNum(0), - operateAppMode(static_cast(ScanMode::SYS_FOREGROUND_SCAN)), - customScene(SCAN_SCENE_ALL), + disableScanFlag(false), staCurrentTime(0), - customCurrentTime(0) + customCurrentTime(0), + staSceneForbidCount(0), + customSceneForbidCount(0), + scanTrustMode(false), + isAbsFreezeState(false), + isAbsFreezeScaned(false), + scanResultBackup(-1) {} ScanService::~ScanService() @@ -58,7 +65,6 @@ bool ScanService::InitScanService(const IScanSerivceCallbacks &scanSerivceCallba WIFI_LOGI("Enter ScanService::InitScanService.\n"); mScanSerivceCallbacks = scanSerivceCallbacks; - pScanStateMachine = new (std::nothrow) ScanStateMachine(); if (pScanStateMachine == nullptr) { WIFI_LOGE("Alloc pScanStateMachine failed.\n"); @@ -92,25 +98,30 @@ bool ScanService::InitScanService(const IScanSerivceCallbacks &scanSerivceCallba WIFI_IDL_OPT_OK)) { WIFI_LOGE("GetSupportFrequencies failed.\n"); } - GetScanControlInfo(); - GetScreenState(); + pScanMonitor->SetScanStateMachine(pScanStateMachine); pScanStateMachine->SendMessage(static_cast(CMD_SCAN_PREPARE)); + GetScanControlInfo(); + return true; } void ScanService::UnInitScanService() { WIFI_LOGI("Enter ScanService::UnInitScanService.\n"); - pScanStateMachine->SendMessage(static_cast(CMD_SCAN_FINISH)); - scanStartedFlag = false; - pScanStateMachine->StopTimer(static_cast(SYSTEM_SCAN_TIMER)); pScanStateMachine->StopTimer(static_cast(DISCONNECTED_SCAN_TIMER)); pScanStateMachine->StopTimer(static_cast(RESTART_PNO_SCAN_TIMER)); + pScanStateMachine->SendMessage(static_cast(CMD_SCAN_FINISH)); + scanStartedFlag = false; return; } +void ScanService::RegisterScanCallbacks(const IScanSerivceCallbacks &iScanSerivceCallbacks) +{ + mScanSerivceCallbacks = iScanSerivceCallbacks; +} + void ScanService::HandleScanStatusReport(ScanStatusReport &scanStatusReport) { WIFI_LOGI("Enter ScanService::HandleScanStatusReport.\n"); @@ -118,7 +129,7 @@ void ScanService::HandleScanStatusReport(ScanStatusReport &scanStatusReport) switch (scanStatusReport.status) { case SCAN_STARTED_STATUS: { scanStartedFlag = true; - /* Pno scan maybe has started, stop it first */ + /* Pno scan maybe has started, stop it first. */ pScanStateMachine->SendMessage(CMD_STOP_PNO_SCAN); mScanSerivceCallbacks.OnScanStartEvent(); SystemScanProcess(true); @@ -142,7 +153,7 @@ void ScanService::HandleScanStatusReport(ScanStatusReport &scanStatusReport) break; } case PNO_SCAN_FAILED: { - /* Start the timer and restart the PNO scanning after a delay */ + /* Start the timer and restart the PNO scanning after a delay. */ pScanStateMachine->StartTimer(static_cast(RESTART_PNO_SCAN_TIMER), RESTART_PNO_SCAN_TIME); EndPnoScan(); break; @@ -192,17 +203,16 @@ ErrCode ScanService::Scan(bool externFlag) } if (externFlag) { - int appId = 0; - if (!AllowExternScan(appId)) { - WIFI_LOGE("AllowExternScan return false.\n"); - return WIFI_OPT_FAILED; + ErrCode rlt = ApplyScanPolices(ScanType::SCAN_TYPE_EXTERN); + if (rlt != WIFI_OPT_SUCCESS) { + return rlt; } } ScanConfig scanConfig; /* * Invoke the interface provided by the configuration center to obtain the - * hidden network list + * hidden network list. */ if (!GetHiddenNetworkSsidList(scanConfig.hiddenNetworkSsid)) { WIFI_LOGE("GetHiddenNetworkSsidList failed.\n"); @@ -229,10 +239,9 @@ ErrCode ScanService::ScanWithParam(const WifiScanParams ¶ms) return WIFI_OPT_FAILED; } - int appId = 0; - if (!AllowExternScan(appId)) { - WIFI_LOGE("AllowExternScan return false.\n"); - return WIFI_OPT_FAILED; + ErrCode rlt = ApplyScanPolices(ScanType::SCAN_TYPE_EXTERN); + if (rlt != WIFI_OPT_SUCCESS) { + return rlt; } if ((params.band < static_cast(SCAN_BAND_UNSPECIFIED)) || @@ -241,7 +250,7 @@ ErrCode ScanService::ScanWithParam(const WifiScanParams ¶ms) return WIFI_OPT_FAILED; } - /* When the frequency is specified, the band must be SCAN_BAND_UNSPECIFIED */ + /* When the frequency is specified, the band must be SCAN_BAND_UNSPECIFIED. */ if (params.freqs.empty() && (params.band == static_cast(SCAN_BAND_UNSPECIFIED))) { WIFI_LOGE("params is error.\n"); return WIFI_OPT_FAILED; @@ -257,7 +266,7 @@ ErrCode ScanService::ScanWithParam(const WifiScanParams ¶ms) } else { /* * Invoke the interface provided by the configuration center to obtain the - * hidden network list + * hidden network list. */ if (!GetHiddenNetworkSsidList(scanConfig.hiddenNetworkSsid)) { WIFI_LOGE("GetHiddenNetworkSsidList failed.\n"); @@ -269,6 +278,7 @@ ErrCode ScanService::ScanWithParam(const WifiScanParams ¶ms) scanConfig.ssid = params.ssid; scanConfig.bssid = params.bssid; scanConfig.externFlag = true; + scanConfig.scanningWithParamFlag = true; scanConfig.scanStyle = SCAN_TYPE_HIGH_ACCURACY; if (!SingleScan(scanConfig)) { @@ -279,6 +289,14 @@ ErrCode ScanService::ScanWithParam(const WifiScanParams ¶ms) return WIFI_OPT_SUCCESS; } +ErrCode ScanService::DisableScan(bool disable) +{ + LOGI("Enter ScanService::DisableScan"); + std::unique_lock lock(scanControlInfoMutex); + disableScanFlag = disable; + return WIFI_OPT_SUCCESS; +} + bool ScanService::SingleScan(ScanConfig &scanConfig) { WIFI_LOGI("Enter ScanService::SingleScan.\n"); @@ -299,24 +317,25 @@ bool ScanService::SingleScan(ScanConfig &scanConfig) interConfig.scanFreqs.assign(scanConfig.scanFreqs.begin(), scanConfig.scanFreqs.end()); /* * When band is SCAN_BAND_BOTH_WITH_DFS, need to scan all frequency, - * scanFreqs can be empty + * scanFreqs can be empty. */ } else if (scanConfig.scanBand != SCAN_BAND_BOTH_WITH_DFS) { - /* Converting frequency bands to frequencies */ + /* Converting frequency bands to frequencies. */ if (!GetBandFreqs(scanConfig.scanBand, interConfig.scanFreqs)) { WIFI_LOGE("GetBandFreqs failed.\n"); return false; } } - /* Save the configuration */ + /* Save the configuration. */ int requestIndex = StoreRequestScanConfig(scanConfig, interConfig); if (requestIndex == MAX_SCAN_CONFIG_STORE_INDEX) { WIFI_LOGE("StoreRequestScanConfig failed.\n"); return false; } - /* Construct a message */ + std::unique_lock lock(scanConfigMapMutex); + /* Construct a message. */ InternalMessage *interMessage = pScanStateMachine->CreateMessage(static_cast(CMD_START_COMMON_SCAN), requestIndex); if (interMessage == nullptr) { @@ -331,8 +350,8 @@ bool ScanService::SingleScan(ScanConfig &scanConfig) WIFI_LOGE("AddScanMessageBody failed.\n"); return false; } - pScanStateMachine->SendMessage(interMessage); + return true; } @@ -444,7 +463,9 @@ int ScanService::StoreRequestScanConfig(const ScanConfig &scanConfig, const Inte static_cast(times.tv_sec) * SECOND_TO_MICRO_SECOND + times.tv_nsec / SECOND_TO_MILLI_SECOND; storeScanConfig.fullScanFlag = scanConfig.fullScanFlag; storeScanConfig.externFlag = scanConfig.externFlag; + storeScanConfig.scanningWithParamFlag = scanConfig.scanningWithParamFlag; + std::unique_lock lock(scanConfigMapMutex); scanConfigMap.insert(std::pair(scanConfigStoreIndex, storeScanConfig)); return scanConfigStoreIndex; @@ -454,6 +475,12 @@ void ScanService::HandleCommonScanFailed(std::vector &requestIndexList) { WIFI_LOGI("Enter ScanService::HandleCommonScanFailed.\n"); + if (staStatus != static_cast(OperateResState::DISCONNECT_DISCONNECTED) && + staStatus != static_cast(OperateResState::CONNECT_AP_CONNECTED)) { + return; + } + + std::unique_lock lock(scanConfigMapMutex); for (std::vector::iterator reqIter = requestIndexList.begin(); reqIter != requestIndexList.end(); ++reqIter) { ScanConfigMap::iterator configIter = scanConfigMap.find(*reqIter); /* No configuration found. */ @@ -461,8 +488,10 @@ void ScanService::HandleCommonScanFailed(std::vector &requestIndexList) continue; } - /* Notification of the end of scanning */ + /* Notification of the end of scanning. */ mScanSerivceCallbacks.OnScanFinishEvent(static_cast(ScanHandleNotify::SCAN_FAIL)); + scanResultBackup = static_cast(ScanHandleNotify::SCAN_FAIL); + scanConfigMap.erase(*reqIter); } @@ -475,38 +504,44 @@ void ScanService::HandleCommonScanInfo( WIFI_LOGI("Enter ScanService::HandleCommonScanInfo.\n"); bool fullScanStored = false; - for (std::vector::iterator reqIter = requestIndexList.begin(); reqIter != requestIndexList.end(); ++reqIter) { - ScanConfigMap::iterator configIter = scanConfigMap.find(*reqIter); - /* No configuration found. */ - if (configIter == scanConfigMap.end()) { - continue; - } - - /* Full Scan Info */ - if (configIter->second.fullScanFlag) { - if (fullScanStored) { - scanConfigMap.erase(*reqIter); + { + std::unique_lock lock(scanConfigMapMutex); + for (std::vector::iterator reqIter = requestIndexList.begin(); reqIter != requestIndexList.end(); + ++reqIter) { + ScanConfigMap::iterator configIter = scanConfigMap.find(*reqIter); + /* No configuration found. */ + if (configIter == scanConfigMap.end()) { continue; } - if (StoreFullScanInfo(configIter->second, scanInfoList)) { - fullScanStored = true; - mScanSerivceCallbacks.OnScanFinishEvent(static_cast(ScanHandleNotify::SCAN_OK)); + /* Full Scan Info. */ + if (configIter->second.fullScanFlag) { + if (fullScanStored) { + scanConfigMap.erase(*reqIter); + continue; + } + + if (StoreFullScanInfo(configIter->second, scanInfoList)) { + fullScanStored = true; + mScanSerivceCallbacks.OnScanFinishEvent(static_cast(ScanHandleNotify::SCAN_OK)); + scanResultBackup = static_cast(ScanHandleNotify::SCAN_OK); + } else { + WIFI_LOGE("StoreFullScanInfo failed.\n"); + } + /* Specify Scan Info. */ } else { - WIFI_LOGE("StoreFullScanInfo failed.\n"); - } - /* Specify Scan Info */ - } else { - if (!StoreUserScanInfo(configIter->second, scanInfoList)) { - WIFI_LOGE("StoreUserScanInfo failed.\n"); + if (!StoreUserScanInfo(configIter->second, scanInfoList)) { + WIFI_LOGE("StoreUserScanInfo failed.\n"); + } + mScanSerivceCallbacks.OnScanFinishEvent(static_cast(ScanHandleNotify::SCAN_OK)); + scanResultBackup = static_cast(ScanHandleNotify::SCAN_OK); } - mScanSerivceCallbacks.OnScanFinishEvent(static_cast(ScanHandleNotify::SCAN_OK)); - } - scanConfigMap.erase(*reqIter); + scanConfigMap.erase(*reqIter); + } } - /* Send the scanning result to the module registered for listening */ + /* Send the scanning result to the module registered for listening. */ ScanInfoHandlerMap::iterator handleIter = scanInfoHandlerMap.begin(); for (; handleIter != scanInfoHandlerMap.end(); ++handleIter) { if (handleIter->second) { @@ -525,26 +560,30 @@ bool ScanService::StoreFullScanInfo( { WIFI_LOGI("Enter ScanService::StoreFullScanInfo.\n"); - /* Filtering result */ + /* Filtering result. */ WIFI_LOGI("scanConfig.scanTime is %" PRIu64 ".\n", scanConfig.scanTime); WIFI_LOGI("Receive %{public}d scan results.\n", (int)(scanInfoList.size())); - std::vector filterScanInfo; - std::vector::const_iterator iter = scanInfoList.begin(); - for (; iter != scanInfoList.end(); ++iter) { + + std::vector storeInfoList; + for (auto iter = scanInfoList.begin(); iter != scanInfoList.end(); ++iter) { WifiScanInfo scanInfo; scanInfo.bssid = iter->bssid; scanInfo.ssid = iter->ssid; scanInfo.capabilities = iter->capabilities; scanInfo.frequency = iter->frequency; + scanInfo.channelWidth = iter->channelWidth; + scanInfo.centerFrequency0 = iter->centerFrequency0; + scanInfo.centerFrequency1 = iter->centerFrequency1; scanInfo.rssi = iter->rssi; + scanInfo.securityType = iter->securityType; + scanInfo.infoElems = iter->infoElems; + scanInfo.features = iter->features; scanInfo.timestamp = iter->timestamp; scanInfo.band = iter->band; - scanInfo.securityType = iter->securityType; - - filterScanInfo.push_back(scanInfo); + storeInfoList.push_back(scanInfo); } - if (WifiSettings::GetInstance().SaveScanInfoList(filterScanInfo) != 0) { + if (WifiSettings::GetInstance().SaveScanInfoList(storeInfoList) != 0) { WIFI_LOGE("WifiSettings::GetInstance().SaveScanInfoList failed.\n"); return false; } @@ -552,13 +591,10 @@ bool ScanService::StoreFullScanInfo( return true; } -bool ScanService::StoreUserScanInfo( - const StoreScanConfig &scanConfig, const std::vector &scanInfoList) +bool ScanService::StoreUserScanInfo(const StoreScanConfig &scanConfig, std::vector &scanInfoList) { WIFI_LOGI("Enter ScanService::StoreUserScanInfo.\n"); - /* Filtering result */ - std::vector filterScanInfo; std::vector::const_iterator iter = scanInfoList.begin(); for (; iter != scanInfoList.end(); ++iter) { /* Timestamp filtering */ @@ -566,7 +602,7 @@ bool ScanService::StoreUserScanInfo( continue; } - /* frequency filtering */ + /* frequency filtering. */ if (!scanConfig.scanFreqs.empty()) { if (std::find(scanConfig.scanFreqs.begin(), scanConfig.scanFreqs.end(), iter->frequency) == scanConfig.scanFreqs.end()) { @@ -574,32 +610,22 @@ bool ScanService::StoreUserScanInfo( } } - /* SSID filtering */ + /* SSID filtering. */ if ((!scanConfig.ssid.empty()) && (scanConfig.ssid != iter->ssid)) { continue; } - /* BSSID filtering */ + /* BSSID filtering. */ if ((!scanConfig.bssid.empty()) && (scanConfig.bssid != iter->bssid)) { continue; } - - WifiScanInfo scanInfo; - scanInfo.bssid = iter->bssid; - scanInfo.ssid = iter->ssid; - scanInfo.capabilities = iter->capabilities; - scanInfo.frequency = iter->frequency; - scanInfo.rssi = iter->rssi; - scanInfo.timestamp = iter->timestamp; - scanInfo.band = iter->band; - scanInfo.securityType = iter->securityType; - filterScanInfo.push_back(scanInfo); } /* - * The specified parameter scanning is initiated by the system and is not - * stored in the configuration center + * The specified parameter scanning is initiated by the system and + * store in the configuration center. */ + ReportStoreScanInfos(scanInfoList); return true; } @@ -607,29 +633,16 @@ bool ScanService::StoreUserScanInfo( void ScanService::ReportScanInfos(std::vector &interScanList) { WIFI_LOGI("Enter ScanService::ReportScanInfos.\n"); + mScanSerivceCallbacks.OnScanInfoEvent(interScanList); return; } -void ScanService::ConvertScanInfos( - const std::vector &interScanList, std::vector &scanInfoList) +void ScanService::ReportStoreScanInfos(std::vector &interScanList) { - WIFI_LOGI("Enter ScanService::ConvertScanInfos.\n"); + WIFI_LOGI("Enter ScanService::ReportStoreScanInfos.\n"); - /* Filtering result */ - std::vector::const_iterator iter = interScanList.begin(); - for (; iter != interScanList.end(); ++iter) { - WifiScanInfo scanInfo; - scanInfo.bssid = iter->bssid; - scanInfo.ssid = iter->ssid; - scanInfo.capabilities = iter->capabilities; - scanInfo.frequency = iter->frequency; - scanInfo.rssi = iter->rssi; - scanInfo.timestamp = iter->timestamp; - scanInfo.band = iter->band; - scanInfo.securityType = iter->securityType; - scanInfoList.push_back(scanInfo); - } + mScanSerivceCallbacks.OnStoreScanInfoEvent(interScanList); return; } @@ -642,8 +655,8 @@ bool ScanService::BeginPnoScan() return false; } - if (!AllowPnoScan()) { - WIFI_LOGI("AllowPnoScan return false.\n"); + ErrCode rlt = ApplyScanPolices(ScanType::SCAN_TYPE_PNO); + if (rlt != WIFI_OPT_SUCCESS) { return false; } @@ -736,19 +749,19 @@ bool ScanService::AddPnoScanMessageBody(InternalMessage *interMessage, const Pno interMessage->AddIntMessageBody(pnoScanConfig.minRssi5Ghz); interMessage->AddIntMessageBody(pnoScanConfig.hiddenNetworkSsid.size()); - std::vector::const_iterator iter = pnoScanConfig.hiddenNetworkSsid.begin(); + auto iter = pnoScanConfig.hiddenNetworkSsid.begin(); for (; iter != pnoScanConfig.hiddenNetworkSsid.end(); ++iter) { interMessage->AddStringMessageBody(*iter); } interMessage->AddIntMessageBody(pnoScanConfig.savedNetworkSsid.size()); - std::vector::const_iterator iter2 = pnoScanConfig.savedNetworkSsid.begin(); + auto iter2 = pnoScanConfig.savedNetworkSsid.begin(); for (; iter2 != pnoScanConfig.savedNetworkSsid.end(); ++iter2) { interMessage->AddStringMessageBody(*iter2); } interMessage->AddIntMessageBody(pnoScanConfig.freqs.size()); - std::vector::const_iterator iter3 = pnoScanConfig.freqs.begin(); + auto iter3 = pnoScanConfig.freqs.begin(); for (; iter3 != pnoScanConfig.freqs.end(); ++iter3) { interMessage->AddIntMessageBody(*iter3); } @@ -774,7 +787,7 @@ void ScanService::HandlePnoScanInfo(std::vector &scanInfoList) } } - /* Send the scanning result to the module registered for listening */ + /* Send the scanning result to the module registered for listening. */ PnoScanInfoHandlerMap::iterator handleIter = pnoScanInfoHandlerMap.begin(); for (; handleIter != pnoScanInfoHandlerMap.end(); ++handleIter) { if (handleIter->second) { @@ -782,7 +795,7 @@ void ScanService::HandlePnoScanInfo(std::vector &scanInfoList) } } - /* send message to main service */ + /* send message to main service. */ ReportScanInfos(filterScanInfo); return; @@ -801,11 +814,9 @@ void ScanService::EndPnoScan() return; } -void ScanService::HandleScreenStatusChanged(bool screenOn) +void ScanService::HandleScreenStatusChanged() { WIFI_LOGI("Enter ScanService::HandleScreenStatusChanged."); - - isScreenOn = screenOn; SystemScanProcess(false); return; } @@ -830,42 +841,82 @@ void ScanService::HandleStaStatusChanged(int status) } } + staSceneForbidCount = 0; return; } +void ScanService::HandleMovingFreezeChanged() +{ + LOGI("Enter ScanService::HandleMovingFreezeChanged."); + ScanMode appRunMode = WifiSettings::GetInstance().GetAppRunningState(); + int freezeState = WifiSettings::GetInstance().GetFreezeModeState(); + int noChargerPlugModeState = WifiSettings::GetInstance().GetNoChargerPlugModeState(); + + bool movingFreeze = (appRunMode == ScanMode::APP_BACKGROUND_SCAN || appRunMode == ScanMode::SYS_BACKGROUND_SCAN) && + (freezeState == MODE_STATE_OPEN) && (noChargerPlugModeState == MODE_STATE_OPEN); + bool movingFreezeBakup = IsMovingFreezeState(); + + SetMovingFreezeState(movingFreeze); + WIFI_LOGD("moving freeze changed: movingFreeze=%{public}d, movingFreezeBakup=%{public}d", movingFreeze, + movingFreezeBakup); + /* Moving -> Freeze, set the scanned flag to false. */ + if (!movingFreezeBakup && movingFreeze) { + WIFI_LOGD("set movingFreeze scanned false."); + SetMovingFreezeScaned(false); + } +} + void ScanService::HandleCustomStatusChanged(int customScene, int customSceneStatus) { WIFI_LOGI("Enter ScanService::HandleCustomStatusChanged."); + WIFI_LOGD("sizeof(time_t):%{public}d", int(sizeof(time_t))); time_t now = time(nullptr); WIFI_LOGD("customScene:%{public}d, status:%{public}d", customScene, customSceneStatus); - if (customSceneStatus == STATE_OPEN) { + if (customSceneStatus == MODE_STATE_OPEN) { customSceneTimeMap.insert(std::pair(customScene, now)); } - if (customSceneStatus == STATE_CLOSE) { + if (customSceneStatus == MODE_STATE_CLOSE) { customSceneTimeMap.erase(customScene); } SystemScanProcess(false); + customSceneForbidCount = 0; return; } +void ScanService::HandleGetCustomSceneState(std::map& sceneMap) const +{ + sceneMap = customSceneTimeMap; +} + void ScanService::SystemScanProcess(bool scanAtOnce) { WIFI_LOGI("Enter ScanService::SystemScanProcess."); StopSystemScan(); - WIFI_LOGD("isScreenOn is:%{public}d", isScreenOn); - if (isScreenOn) { - for (auto iter = scanControlInfo.scanIntervalList.begin(); iter != scanControlInfo.scanIntervalList.end(); - ++iter) { - if (iter->scanScene == SCAN_SCENE_ALL && iter->scanMode == ScanMode::SYSTEM_TIMER_SCAN && - iter->isSingle == false) { - WIFI_LOGD("iter->intervalMode is:%{public}d", iter->intervalMode); - WIFI_LOGD("iter->interval is:%{public}d", iter->interval); - WIFI_LOGD("iter->count is:%{public}d", iter->count); - systemScanIntervalMode.scanIntervalMode.intervalMode = iter->intervalMode; - systemScanIntervalMode.scanIntervalMode.interval = iter->interval; - systemScanIntervalMode.scanIntervalMode.count = iter->count; + + int state = WifiSettings::GetInstance().GetScreenState(); + if (state == MODE_STATE_OPEN) { + WIFI_LOGD("Screen is on."); + } else { + WIFI_LOGD("ScreenOn is off."); + } + + if (state == MODE_STATE_OPEN) { + { + std::unique_lock lock(scanControlInfoMutex); + for (auto iter = scanControlInfo.scanIntervalList.begin(); iter != scanControlInfo.scanIntervalList.end(); + ++iter) { + if (iter->scanScene == SCAN_SCENE_ALL && iter->scanMode == ScanMode::SYSTEM_TIMER_SCAN && + iter->isSingle == false) { + WIFI_LOGD("iter->intervalMode is:%{public}d", iter->intervalMode); + WIFI_LOGD("iter->interval is:%{public}d", iter->interval); + WIFI_LOGD("iter->count is:%{public}d", iter->count); + systemScanIntervalMode.scanIntervalMode.intervalMode = iter->intervalMode; + systemScanIntervalMode.scanIntervalMode.interval = iter->interval; + systemScanIntervalMode.scanIntervalMode.count = iter->count; + systemScanIntervalMode.expScanCount = 0; + } } } StartSystemTimerScan(scanAtOnce); @@ -894,12 +945,12 @@ void ScanService::StartSystemTimerScan(bool scanAtOnce) { WIFI_LOGI("Enter ScanService::StartSystemTimerScan."); - if (!AllowSystemTimerScan()) { - WIFI_LOGI("AllowSystemTimerScan return false."); + ErrCode rlt = ApplyScanPolices(ScanType::SCAN_TYPE_SYSTEMTIMER); + if (rlt != WIFI_OPT_SUCCESS) { return; } - struct timespec times = {0, 0}; + struct timespec times = { 0, 0 }; clock_gettime(CLOCK_MONOTONIC, ×); int64_t nowTime = static_cast(times.tv_sec) * SECOND_TO_MILLI_SECOND + times.tv_nsec / SECOND_TO_MICRO_SECOND; @@ -910,7 +961,7 @@ void ScanService::StartSystemTimerScan(bool scanAtOnce) /* * The scan is performed immediately, the first scan is required, - * or the time since the last scan is longer than the scan interval + * or the time since the last scan is longer than the scan interval. */ int scanTime = SYSTEM_SCAN_INIT_TIME; WIFI_LOGD("interval:%{public}d", systemScanIntervalMode.scanIntervalMode.interval); @@ -986,165 +1037,296 @@ void ScanService::GetScanControlInfo() { WIFI_LOGI("Enter ScanService::GetScanControlInfo.\n"); + std::unique_lock lock(scanControlInfoMutex); if (WifiSettings::GetInstance().GetScanControlInfo(scanControlInfo) != 0) { WIFI_LOGE("WifiSettings::GetInstance().GetScanControlInfo failed"); } - - return; -} - -void ScanService::GetScreenState() -{ - WIFI_LOGI("Enter ScanService::GetScreenState.\n"); - int screenState = WifiSettings::GetInstance().GetScreenState(); - isScreenOn = true; - if (screenState == SCREEN_CLOSED) { - isScreenOn = false; - } - - return; -} - -void ScanService::SetOperateAppMode(int appMode) -{ - WIFI_LOGI("Enter ScanService::SetOperateAppMode.\n"); - operateAppMode = appMode; - return; } -ScanMode ScanService::GetOperateAppMode() -{ - WIFI_LOGI("Enter ScanService::GetOperateAppMode.\n"); - ScanMode scanMode = ScanMode::SYS_FOREGROUND_SCAN; - switch (operateAppMode) { - case APP_FOREGROUND_SCAN: - scanMode = ScanMode::APP_FOREGROUND_SCAN; - break; - - case APP_BACKGROUND_SCAN: - scanMode = ScanMode::APP_BACKGROUND_SCAN; - break; - - case SYS_FOREGROUND_SCAN: - scanMode = ScanMode::SYS_FOREGROUND_SCAN; - break; - - case SYS_BACKGROUND_SCAN: - scanMode = ScanMode::SYS_BACKGROUND_SCAN; - break; - - default: - WIFI_LOGE("operateAppMode %{public}d is invalid.", operateAppMode); - break; - } - - return scanMode; -} - -bool ScanService::AllowExternScan(int appId) +ErrCode ScanService::AllowExternScan() { WIFI_LOGI("Enter ScanService::AllowExternScan.\n"); int staScene = GetStaScene(); - ScanMode scanMode = GetOperateAppMode(); + ScanMode scanMode = WifiSettings::GetInstance().GetAppRunningState(); WIFI_LOGD("staScene is %{public}d, scanMode is %{public}d", staScene, (int)scanMode); if (!AllowExternScanByForbid(staScene, scanMode)) { WIFI_LOGD("extern scan not allow by forbid mode"); - return false; + return WIFI_OPT_FAILED; } + int appId = 0; if (!AllowExternScanByInterval(appId, staScene, scanMode)) { WIFI_LOGD("extern scan not allow by interval mode"); - return false; + return WIFI_OPT_FAILED; + } + if (!AllowScanByMovingFreeze()) { + WIFI_LOGD("extern scan not allow by moving freeze mode"); + return WIFI_OPT_MOVING_FREEZE_CTRL; + } + + if (!AllowScanByDisableScanCtrl()) { + WIFI_LOGD("extern scan not allow by disable scan control."); + return WIFI_OPT_FAILED; } WIFI_LOGD("extern scan has allowed"); - return true; + return WIFI_OPT_SUCCESS; } -bool ScanService::AllowSystemTimerScan() +ErrCode ScanService::AllowSystemTimerScan() { WIFI_LOGI("Enter ScanService::AllowSystemTimerScan.\n"); if (staStatus != static_cast(OperateResState::DISCONNECT_DISCONNECTED) && staStatus != static_cast(OperateResState::CONNECT_AP_CONNECTED)) { - return false; + return WIFI_OPT_FAILED; } - /* The network is connected and cannot be automatically switched */ + /* The network is connected and cannot be automatically switched. */ autoNetworkSelection = WifiSettings::GetInstance().GetWhetherToAllowNetworkSwitchover(); if ((staStatus == static_cast(OperateResState::CONNECT_AP_CONNECTED)) && (!autoNetworkSelection)) { - return false; + return WIFI_OPT_FAILED; } int staScene = GetStaScene(); /* Determines whether to allow scanning based on the STA status. */ if (staScene == SCAN_SCENE_MAX) { - return false; + return WIFI_OPT_FAILED; } if (!AllowScanDuringStaScene(staScene, ScanMode::SYSTEM_TIMER_SCAN)) { WIFI_LOGD("system timer scan not allowed, staScene is %{public}d", staScene); - return false; + return WIFI_OPT_FAILED; } if (!AllowScanDuringCustomScene(ScanMode::SYSTEM_TIMER_SCAN)) { WIFI_LOGD("system timer scan not allowed"); - return false; + return WIFI_OPT_FAILED; } - for (auto iter = scanControlInfo.scanIntervalList.begin(); iter != scanControlInfo.scanIntervalList.end(); ++iter) { - if (iter->scanScene == SCAN_SCENE_ALL && iter->scanMode == ScanMode::SYSTEM_TIMER_SCAN && - iter->isSingle == false) { - if (!SystemScanByInterval(systemScanIntervalMode.expScanCount, - systemScanIntervalMode.scanIntervalMode.interval, - systemScanIntervalMode.scanIntervalMode.count)) { - return false; + if (!AllowScanByMovingFreeze()) { + return WIFI_OPT_MOVING_FREEZE_CTRL; + } + + { + std::unique_lock lock(scanControlInfoMutex); + for (auto iter = scanControlInfo.scanIntervalList.begin(); iter != scanControlInfo.scanIntervalList.end(); + ++iter) { + if (iter->scanScene == SCAN_SCENE_ALL && iter->scanMode == ScanMode::SYSTEM_TIMER_SCAN && + iter->isSingle == false) { + if (!SystemScanByInterval(systemScanIntervalMode.expScanCount, + systemScanIntervalMode.scanIntervalMode.interval, systemScanIntervalMode.scanIntervalMode.count)) { + return WIFI_OPT_FAILED; + } } } } + if (!AllowScanByDisableScanCtrl()) { + WIFI_LOGD("extern scan not allow by disable scan control."); + return WIFI_OPT_FAILED; + } + WIFI_LOGD("allow system timer scan"); - return true; + return WIFI_OPT_SUCCESS; } -bool ScanService::AllowPnoScan() +ErrCode ScanService::AllowPnoScan() { WIFI_LOGI("Enter ScanService::AllowPnoScan.\n"); if (staStatus != static_cast(OperateResState::DISCONNECT_DISCONNECTED)) { - return false; + return WIFI_OPT_FAILED; } int staScene = GetStaScene(); if (staScene == SCAN_SCENE_MAX) { - return false; + return WIFI_OPT_FAILED; } if (!AllowScanDuringStaScene(staScene, ScanMode::PNO_SCAN)) { WIFI_LOGD("pnoScan is not allowed for forbid map, staScene is %{public}d", staScene); - return false; + return WIFI_OPT_FAILED; } if (!AllowScanDuringCustomScene(ScanMode::PNO_SCAN)) { WIFI_LOGD("pnoScan is not allowed for forbid map"); - return false; + return WIFI_OPT_FAILED; + } + if (!AllowScanByMovingFreeze()) { + return WIFI_OPT_MOVING_FREEZE_CTRL; } - for (auto iter = scanControlInfo.scanIntervalList.begin(); iter != scanControlInfo.scanIntervalList.end(); ++iter) { - if (iter->scanScene == SCAN_SCENE_ALL && iter->scanMode == ScanMode::PNO_SCAN && iter->isSingle == false) { - pnoScanIntervalMode.scanIntervalMode.intervalMode = iter->intervalMode; - pnoScanIntervalMode.scanIntervalMode.interval = iter->interval; - pnoScanIntervalMode.scanIntervalMode.count = iter->count; - if (!PnoScanByInterval(pnoScanIntervalMode.fixedScanCount, - pnoScanIntervalMode.fixedCurrentTime, - pnoScanIntervalMode.scanIntervalMode.interval, - pnoScanIntervalMode.scanIntervalMode.count)) { - WIFI_LOGD("pnoScan is not allowed for interval mode"); - return false; + { + std::unique_lock lock(scanControlInfoMutex); + for (auto iter = scanControlInfo.scanIntervalList.begin(); iter != scanControlInfo.scanIntervalList.end(); + ++iter) { + if (iter->scanScene == SCAN_SCENE_ALL && iter->scanMode == ScanMode::PNO_SCAN && iter->isSingle == false) { + pnoScanIntervalMode.scanIntervalMode.intervalMode = iter->intervalMode; + pnoScanIntervalMode.scanIntervalMode.interval = iter->interval; + pnoScanIntervalMode.scanIntervalMode.count = iter->count; + if (!PnoScanByInterval(pnoScanIntervalMode.fixedScanCount, pnoScanIntervalMode.fixedCurrentTime, + pnoScanIntervalMode.scanIntervalMode.interval, pnoScanIntervalMode.scanIntervalMode.count)) { + WIFI_LOGD("pnoScan is not allowed for interval mode"); + return WIFI_OPT_FAILED; + } } } } + + if (!AllowScanByDisableScanCtrl()) { + WIFI_LOGD("extern scan not allow by disable scan control."); + return WIFI_OPT_FAILED; + } + WIFI_LOGD("pno scan is allowed"); - return true; + return WIFI_OPT_SUCCESS; +} + +ErrCode ScanService::AllowScanByType(ScanType scanType) +{ + LOGI("Enter ScanService::AllowScanByType."); + + ErrCode allScanResult = WIFI_OPT_SUCCESS; + switch (scanType) { + case ScanType::SCAN_TYPE_EXTERN: + allScanResult = AllowExternScan(); + break; + case ScanType::SCAN_TYPE_SYSTEMTIMER: + allScanResult = AllowSystemTimerScan(); + break; + case ScanType::SCAN_TYPE_PNO: + allScanResult = AllowPnoScan(); + break; + default: + LOGE("scanType error.\n"); + break; + } + + WIFI_LOGD("AllowScanByType ErrCode=%{public}d.", static_cast(allScanResult)); + return allScanResult; +} + +void ScanService::SetScanTrustMode() +{ + std::unique_lock lock(scanControlInfoMutex); + scanTrustMode = true; +} + +void ScanService::ResetToNonTrustMode() +{ + std::unique_lock lock(scanControlInfoMutex); + scanTrustMode = false; +} + +bool ScanService::IsScanTrustMode() const +{ + std::unique_lock lock(scanControlInfoMutex); + return scanTrustMode; +} + +void ScanService::AddScanTrustSceneId(int sceneId) +{ + std::unique_lock lock(scanControlInfoMutex); + scanTrustSceneIds.emplace(sceneId); +} + +void ScanService::ClearScanTrustSceneIds() +{ + std::unique_lock lock(scanControlInfoMutex); + scanTrustSceneIds.clear(); +} + +bool ScanService::IsInScanTrust(int sceneId) const +{ + std::unique_lock lock(scanControlInfoMutex); + if (scanTrustSceneIds.find(sceneId) != scanTrustSceneIds.end()) { + return true; + } + + return false; +} + +void ScanService::SetMovingFreezeState(bool state) +{ + std::unique_lock lock(scanControlInfoMutex); + isAbsFreezeState = state; +} + +bool ScanService::IsMovingFreezeState() const +{ + std::unique_lock lock(scanControlInfoMutex); + return isAbsFreezeState; +} + +void ScanService::SetMovingFreezeScaned(bool scanned) +{ + std::unique_lock lock(scanControlInfoMutex); + isAbsFreezeScaned = scanned; +} + +bool ScanService::IsMovingFreezeScaned() const +{ + std::unique_lock lock(scanControlInfoMutex); + return isAbsFreezeScaned; +} + +ErrCode ScanService::ApplyTrustListPolicy(ScanType scanType) +{ + LOGI("Enter ScanService::ApplyTrustListPolicy."); + ErrCode policyResult = WIFI_OPT_SUCCESS; + + SetScanTrustMode(); + policyResult = AllowScanByType(scanType); + if (policyResult != WIFI_OPT_SUCCESS) { + WIFI_LOGD("AllowScanByType failed."); + } + ResetToNonTrustMode(); + WIFI_LOGD("ResetToNonTrustMode"); + + WIFI_LOGD("apply trust list policy, ErrCode=%{public}d", static_cast(policyResult)); + + return policyResult; +} + +ErrCode ScanService::ApplyScanPolices(ScanType type) +{ + LOGI("Enter ScanService::ApplyScanPolices."); + /* Obtains app parameters and scenario status parameters. */ + auto &appPackageName = WifiSettings::GetInstance().GetAppPackageName(); + auto &trustListPolicies = WifiSettings::GetInstance().ReloadTrustListPolicies(); + auto &movingFreezePolicy = WifiSettings::GetInstance().ReloadMovingFreezePolicy(); + ErrCode rlt = WIFI_OPT_SUCCESS; + if (appPackageName.empty()) { + rlt = AllowScanByType(type); + WIFI_LOGD("appPackageName empty, apply scan polices ErrCode=%{public}d.", static_cast(rlt)); + if (scanResultBackup != -1 && rlt == WIFI_OPT_MOVING_FREEZE_CTRL) { + mScanSerivceCallbacks.OnScanFinishEvent(scanResultBackup); + } + return rlt; + } + + /* Generates an scene id list based on appPackageName. */ + ClearScanTrustSceneIds(); + for (auto &policy : trustListPolicies) { + if (IsPackageInTrustList(policy.trustList, policy.sceneId, appPackageName)) { + AddScanTrustSceneId(policy.sceneId); + } + } + const int movingFreezeSceneId = -1; + if (IsPackageInTrustList(movingFreezePolicy.trustList, movingFreezeSceneId, appPackageName)) { + AddScanTrustSceneId(movingFreezeSceneId); + } + + rlt = ApplyTrustListPolicy(type); + if (rlt != WIFI_OPT_SUCCESS) { + if (scanResultBackup != -1 && rlt == WIFI_OPT_MOVING_FREEZE_CTRL) { + LOGE("trust list policy, but moving freeze ctrl failed."); + mScanSerivceCallbacks.OnScanFinishEvent(scanResultBackup); + } + return rlt; + } + WIFI_LOGD("apply scan policies result: scan control ok."); + return WIFI_OPT_SUCCESS; } bool ScanService::AllowExternScanByForbid(int staScene, ScanMode scanMode) @@ -1160,7 +1342,8 @@ bool ScanService::AllowExternScanByForbid(int staScene, ScanMode scanMode) } } - if (isScreenOn == false) { + int state = WifiSettings::GetInstance().GetScreenState(); + if (state == MODE_STATE_CLOSE) { if (!AllowScanDuringScreenOff(scanMode)) { return false; } @@ -1180,6 +1363,7 @@ bool ScanService::AllowExternScanByForbid(int staScene, ScanMode scanMode) if (!AllowScanDuringCustomScene(ScanMode::ALL_EXTERN_SCAN)) { return false; } + return true; } @@ -1193,12 +1377,22 @@ bool ScanService::AllowExternScanByInterval(int appId, int staScene, ScanMode sc if (!AllowExternScanByIntervalMode(appId, staScene, ScanMode::ALL_EXTERN_SCAN)) { return false; } - if (!AllowExternScanByIntervalMode(appId, SCAN_SCENE_ALL, scanMode)) { + if (!AllowExternScanByIntervalMode(appId, SCAN_SCENE_FREQUENCY_ORIGIN, scanMode)) { return false; } - if (!AllowExternScanByIntervalMode(appId, SCAN_SCENE_ALL, ScanMode::ALL_EXTERN_SCAN)) { + if (!AllowExternScanByIntervalMode(appId, SCAN_SCENE_FREQUENCY_ORIGIN, ScanMode::ALL_EXTERN_SCAN)) { return false; } + int noChargerPlugModeState = WifiSettings::GetInstance().GetNoChargerPlugModeState(); + if (noChargerPlugModeState == MODE_STATE_OPEN) { + WIFI_LOGI("No charger plug mode state."); + if (!AllowExternScanByIntervalMode(appId, SCAN_SCENE_FREQUENCY_CUSTOM, scanMode)) { + return false; + } + if (!AllowExternScanByIntervalMode(appId, SCAN_SCENE_FREQUENCY_CUSTOM, ScanMode::ALL_EXTERN_SCAN)) { + return false; + } + } if (!AllowExternScanByCustomScene(appId, scanMode)) { return false; } @@ -1225,15 +1419,22 @@ int ScanService::GetStaScene() case static_cast(OperateResState::CONNECT_OBTAINING_IP): return SCAN_SCENE_OBTAINING_IP; + case static_cast(OperateResState::CONNECT_ASSOCIATING): + return SCAN_SCENE_ASSOCIATING; + + case static_cast(OperateResState::CONNECT_ASSOCIATED): + return SCAN_SCENE_ASSOCIATED; + default: return SCAN_SCENE_MAX; } } -bool ScanService::IsExternScanning() +bool ScanService::IsExternScanning() const { WIFI_LOGI("Enter ScanService::IsExternScanning.\n"); + std::unique_lock lock(scanConfigMapMutex); for (auto iter = scanConfigMap.begin(); iter != scanConfigMap.end(); ++iter) { if (iter->second.externFlag) { return true; @@ -1242,6 +1443,19 @@ bool ScanService::IsExternScanning() return false; } +bool ScanService::IsScanningWithParam() +{ + WIFI_LOGI("Enter ScanService::IsScanningWithParam.\n"); + + std::unique_lock lock(scanConfigMapMutex); + for (auto iter = scanConfigMap.begin(); iter != scanConfigMap.end(); ++iter) { + if (iter->second.scanningWithParamFlag) { + return true; + } + } + return false; +} + void ScanService::GetAllowBandFreqsControlInfo(ScanBandType &scanBand, std::vector &freqs) { WIFI_LOGI("Enter ScanService::GetAllowBandFreqsControlInfo.\n"); @@ -1262,14 +1476,17 @@ void ScanService::GetAllowBandFreqsControlInfo(ScanBandType &scanBand, std::vect if (!AllowScanDuringCustomScene(ScanMode::BAND_5GHZ_SCAN)) { allow5Ghz = false; } - auto forbidIter = scanControlInfo.scanForbidMap.find(SCAN_SCENE_ALL); - if (forbidIter != scanControlInfo.scanForbidMap.end()) { - for (auto iter = forbidIter->second.begin(); iter != forbidIter->second.end(); ++iter) { - if (iter->scanMode == ScanMode::BAND_24GHZ_SCAN) { - allow24Ghz = false; - } - if (iter->scanMode == ScanMode::BAND_5GHZ_SCAN) { - allow5Ghz = false; + + { + std::unique_lock lock(scanControlInfoMutex); + for (auto iter = scanControlInfo.scanForbidList.begin(); iter != scanControlInfo.scanForbidList.end(); ++iter) { + if (iter->scanScene == SCAN_SCENE_ALL) { + if (iter->scanMode == ScanMode::BAND_24GHZ_SCAN) { + allow24Ghz = false; + } + if (iter->scanMode == ScanMode::BAND_5GHZ_SCAN) { + allow5Ghz = false; + } } } } @@ -1407,19 +1624,6 @@ bool ScanService::GetHiddenNetworkSsidList(std::vector &hiddenNetwo return true; } -void ScanService::SetCustomScene(int scene, time_t currentTime) -{ - WIFI_LOGI("Enter ScanService::SetCustomScene.\n"); - - if (scene < static_cast(SCAN_SCENE_DEEP_SLEEP) || scene >= static_cast(SCAN_SCENE_ALL)) { - WIFI_LOGE("invalid CustomScene status:%{public}d", scene); - return; - } - customSceneTimeMap[scene] = currentTime; - - return; -} - void ScanService::ClearScanControlValue() { WIFI_LOGI("Enter ScanService::ClearScanControlValue.\n"); @@ -1438,34 +1642,47 @@ void ScanService::SetStaCurrentTime() time_t now = time(0); staCurrentTime = now; + int state = WifiSettings::GetInstance().GetScreenState(); + if (state == MODE_STATE_CLOSE) { + if (ApplyScanPolices(ScanType::SCAN_TYPE_PNO) != WIFI_OPT_SUCCESS) { + EndPnoScan(); + pnoScanFailedNum = 0; + pScanStateMachine->StopTimer(static_cast(RESTART_PNO_SCAN_TIMER)); + } + } return; } -bool ScanService::AllowScanDuringScanning(ScanMode scanMode) +bool ScanService::AllowScanDuringScanning(ScanMode scanMode) const { WIFI_LOGI("Enter ScanService::AllowScanDuringScanning.\n"); - auto forbidIter = scanControlInfo.scanForbidMap.find(SCAN_SCENE_SCANNING); - if (forbidIter != scanControlInfo.scanForbidMap.end()) { - for (auto iter = forbidIter->second.begin(); iter != forbidIter->second.end(); ++iter) { - if (iter->scanMode == scanMode) { - return false; - } + std::unique_lock lock(scanControlInfoMutex); + for (auto iter = scanControlInfo.scanForbidList.begin(); iter != scanControlInfo.scanForbidList.end(); ++iter) { + if (iter->scanScene == SCAN_SCENE_SCANNING && iter->scanMode == scanMode) { + WIFI_LOGD("scan not allow by scanning scene."); + return false; } } return true; } -bool ScanService::AllowScanDuringScreenOff(ScanMode scanMode) +bool ScanService::AllowScanDuringScreenOff(ScanMode scanMode) const { WIFI_LOGI("Enter ScanService::AllowScanDuringScreenOff.\n"); - auto forbidIter = scanControlInfo.scanForbidMap.find(SCAN_SCENE_SCREEN_OFF); - if (forbidIter != scanControlInfo.scanForbidMap.end()) { - for (auto iter = forbidIter->second.begin(); iter != forbidIter->second.end(); ++iter) { - if (iter->scanMode == scanMode) { - return false; - } + bool isTrustListMode = IsScanTrustMode(); + bool isInList = IsInScanTrust(SCAN_SCENE_SCREEN_OFF); + if (isTrustListMode && isInList) { + WIFI_LOGD("Trust list mode,sceneId(SCAN_SCENE_SCREEN_OFF) in the list,return true."); + return true; + } + + std::unique_lock lock(scanControlInfoMutex); + for (auto iter = scanControlInfo.scanForbidList.begin(); iter != scanControlInfo.scanForbidList.end(); ++iter) { + if (iter->scanScene == SCAN_SCENE_SCREEN_OFF && iter->scanMode == scanMode) { + WIFI_LOGD("scan not allow by screen off scene."); + return false; } } return true; @@ -1475,29 +1692,35 @@ bool ScanService::AllowScanDuringStaScene(int staScene, ScanMode scanMode) { WIFI_LOGI("Enter ScanService::AllowScanDuringStaScene.\n"); - time_t now = time(0); - - auto forbidIter = scanControlInfo.scanForbidMap.find(staScene); - if (forbidIter != scanControlInfo.scanForbidMap.end()) { - for (auto iter = forbidIter->second.begin(); iter != forbidIter->second.end(); ++iter) { - /* forbid scan mode found in scan scene */ - if (iter->scanMode == scanMode) { - /* Unconditional scan control for forbidCount times */ - if (iter->forbidCount > 0) { - iter->forbidCount--; - return false; - } - /* forbidCount=0 and forbidTime=0, directly forbid scan */ - if (iter->forbidTime == 0) { - return false; - } - /* Scan interval less than forbidTime, forbid scan */ - if (iter->forbidTime > 0 && iter->forbidTime > now - staCurrentTime) { - return false; - } + time_t now = time(nullptr); + if (now < 0) { + return false; + } + std::unique_lock lock(scanControlInfoMutex); + for (auto iter = scanControlInfo.scanForbidList.begin(); iter != scanControlInfo.scanForbidList.end(); ++iter) { + WIFI_LOGD("now - staCurrentTime:%{public}d, iter->forbidTime:%{public}d", int(now - staCurrentTime), + iter->forbidTime); + /* forbid scan mode found in scan scene. */ + if (iter->scanScene == staScene && iter->scanMode == scanMode) { + /* forbidCount=0 and forbidTime=0, directly forbid scan. */ + if ((iter->forbidTime == 0) && (iter->forbidCount == 0)) { + WIFI_LOGD("Scan is forbidden by staScene."); + return false; + } + /* Unconditional scan control for forbidCount times */ + if ((iter->forbidCount > 0) && (iter->forbidCount - staSceneForbidCount > 0)) { + WIFI_LOGD("Scan is forbidden in forbidCount."); + staSceneForbidCount++; + return false; + } + /* Scan interval less than forbidTime, forbid scan. */ + if ((iter->forbidTime > 0) && (now - staCurrentTime <= iter->forbidTime)) { + WIFI_LOGD("Scan is forbidden in forbidTime."); + return false; } } } + return true; } @@ -1505,31 +1728,43 @@ bool ScanService::AllowScanDuringCustomScene(ScanMode scanMode) { WIFI_LOGI("Enter ScanService::AllowScanDuringCustomScene.\n"); - time_t now = time(0); - auto customIter = customSceneTimeMap.begin(); - for (; customIter != customSceneTimeMap.end(); ++customIter) { - auto forbidIter = scanControlInfo.scanForbidMap.find(customIter->first); - if (forbidIter != scanControlInfo.scanForbidMap.end()) { - for (auto iter = forbidIter->second.begin(); iter != forbidIter->second.end(); ++iter) { - /* forbid scan mode found in scan scene */ - if (iter->scanMode == scanMode) { - /* Unconditional scan control for forbidCount times */ - if (iter->forbidCount > 0) { - iter->forbidCount--; - return false; - } - /* forbidCount=0 and forbidTime=0, directly forbid scan */ - if (iter->forbidTime == 0) { - return false; - } - /* Scan interval less than forbidTime, forbid scan */ - if (iter->forbidTime > 0 && iter->forbidTime > now - customIter->second) { - return false; - } - } + bool isTrustListMode = IsScanTrustMode(); + for (auto customIter = customSceneTimeMap.begin(); customIter != customSceneTimeMap.end(); ++customIter) { + if (isTrustListMode && IsInScanTrust(customIter->first)) { + WIFI_LOGD("Trust list mode,sceneId(%{public}d) in the list, continue.", customIter->first); + continue; + } + + if (!AllowCustomSceneCheck(customIter, scanMode)) { + return false; + } + } + return true; +} + +bool ScanService::AllowCustomSceneCheck(const std::map::const_iterator &customIter, ScanMode scanMode) +{ + std::unique_lock lock(scanControlInfoMutex); + for (auto iter = scanControlInfo.scanForbidList.begin(); iter != scanControlInfo.scanForbidList.end(); ++iter) { + if (iter->scanScene == customIter->first && iter->scanMode == scanMode) { + /* forbidCount=0 and forbidTime=0, directly forbid scan. */ + if ((iter->forbidTime == 0) && (iter->forbidCount == 0)) { + WIFI_LOGD("Scan is forbidden by staScene."); + return false; + } + /* Unconditional scan control for forbidCount times. */ + if (iter->forbidCount > 0 && iter->forbidCount - customSceneForbidCount > 0) { + customSceneForbidCount++; + return false; + } + /* Scan interval less than forbidTime, forbid scan. */ + time_t now = time(nullptr); + if (iter->forbidTime > 0 && iter->forbidTime > now - customIter->second) { + return false; } } } + return true; } @@ -1537,11 +1772,16 @@ bool ScanService::AllowExternScanByIntervalMode(int appId, int scanScene, ScanMo { WIFI_LOGI("Enter ScanService::AllowExternScanByIntervalMode.\n"); + bool isTrustListMode = IsScanTrustMode(); + if (isTrustListMode && IsInScanTrust(scanScene)) { + WIFI_LOGD("Trust list mode,sceneId(%{public}d) in the list, return true.", scanScene); + return true; + } + + std::unique_lock lock(scanControlInfoMutex); for (auto intervalListIter = scanControlInfo.scanIntervalList.begin(); intervalListIter != scanControlInfo.scanIntervalList.end(); ++intervalListIter) { - WIFI_LOGD( - "scanScene:%{public}d, scanMode:%{public}d", intervalListIter->scanScene, intervalListIter->scanMode); /* Determine whether control is required in the current scene and scan mode. */ if (intervalListIter->scanScene == scanScene && intervalListIter->scanMode == scanMode) { /* If a single application is distinguished. */ @@ -1563,91 +1803,37 @@ bool ScanService::AllowExternScanByCustomScene(int appId, ScanMode scanMode) { WIFI_LOGI("Enter ScanService::AllowExternScanByCustomScene.\n"); - auto customIter = customSceneTimeMap.begin(); - for (; customIter != customSceneTimeMap.end(); ++customIter) { - for (auto intervalListIter = scanControlInfo.scanIntervalList.begin(); - intervalListIter != scanControlInfo.scanIntervalList.end(); - ++intervalListIter) { - /* Determine whether control is required in the current scene and scan mode. */ - if (intervalListIter->scanScene == customIter->first && intervalListIter->scanMode == scanMode) { - /* If a single application is distinguished */ - if (intervalListIter->isSingle) { - if (!AllowSingleAppScanByInterval(appId, *intervalListIter)) { - return false; - } - } else { - if (!AllowFullAppScanByInterval(appId, *intervalListIter)) { - return false; - } - } - break; - } + bool isTrustListMode = IsScanTrustMode(); + for (auto customIter = customSceneTimeMap.begin(); customIter != customSceneTimeMap.end(); ++customIter) { + if (isTrustListMode && IsInScanTrust(customIter->first)) { + WIFI_LOGD("Trust list mode,sceneId(%{public}d) in the list, continue.", customIter->first); + continue; } - } - return true; -} - -bool ScanService::AllowSingleAppScanByInterval(int appId, ScanIntervalMode scanIntervalMode) -{ - WIFI_LOGI("Enter ScanService::AllowSingleAppScan.\n"); - bool appIdExisted = false; - for (auto forbidListIter = appForbidList.begin(); forbidListIter != appForbidList.end(); ++forbidListIter) { - if (forbidListIter->appID == appId && - forbidListIter->scanIntervalMode.scanScene == scanIntervalMode.scanScene && - forbidListIter->scanIntervalMode.scanMode == scanIntervalMode.scanMode) { - appIdExisted = true; - } - } - /* If the appId is the first scan request, add it to appForbidList. */ - if (!appIdExisted) { - SingleAppForbid singleAppForbid; - singleAppForbid.appID = appId; - singleAppForbid.scanIntervalMode.scanScene = scanIntervalMode.scanScene; - singleAppForbid.scanIntervalMode.scanMode = scanIntervalMode.scanMode; - singleAppForbid.scanIntervalMode.interval = scanIntervalMode.interval; - singleAppForbid.scanIntervalMode.intervalMode = scanIntervalMode.intervalMode; - singleAppForbid.scanIntervalMode.count = scanIntervalMode.count; - appForbidList.push_back(singleAppForbid); - } - for (auto iter = appForbidList.begin(); iter != appForbidList.end(); ++iter) { - if (iter->appID == appId && iter->scanIntervalMode.scanScene == scanIntervalMode.scanScene && - iter->scanIntervalMode.scanMode == scanIntervalMode.scanMode) { - if (!ExternScanByInterval(appId, *iter)) { - return false; - } + if (!AllowExternCustomSceneCheck(customIter, appId, scanMode)) { + return false; } } return true; } -bool ScanService::AllowFullAppScanByInterval(int appId, ScanIntervalMode scanIntervalMode) +bool ScanService::AllowExternCustomSceneCheck(const std::map::const_iterator &customIter, int appId, + ScanMode scanMode) { - WIFI_LOGI("Enter ScanService::AllowFullAppScan.\n"); - - bool fullAppExisted = false; - for (auto fullAppForbidIter = fullAppForbidList.begin(); fullAppForbidIter != fullAppForbidList.end(); - ++fullAppForbidIter) { - if (fullAppForbidIter->scanIntervalMode.scanScene == scanIntervalMode.scanScene && - fullAppForbidIter->scanIntervalMode.scanMode == scanIntervalMode.scanMode) { - fullAppExisted = true; - } - } - if (!fullAppExisted) { - SingleAppForbid singleAppForbid; - singleAppForbid.scanIntervalMode.scanScene = scanIntervalMode.scanScene; - singleAppForbid.scanIntervalMode.scanMode = scanIntervalMode.scanMode; - singleAppForbid.scanIntervalMode.interval = scanIntervalMode.interval; - singleAppForbid.scanIntervalMode.intervalMode = scanIntervalMode.intervalMode; - singleAppForbid.scanIntervalMode.count = scanIntervalMode.count; - fullAppForbidList.push_back(singleAppForbid); - } - for (auto iter = fullAppForbidList.begin(); iter != fullAppForbidList.end(); ++iter) { - if (iter->scanIntervalMode.scanScene == scanIntervalMode.scanScene && - iter->scanIntervalMode.scanMode == scanIntervalMode.scanMode) { - if (!ExternScanByInterval(appId, *iter)) { + std::unique_lock lock(scanControlInfoMutex); + for (auto intervalListIter = scanControlInfo.scanIntervalList.begin(); + intervalListIter != scanControlInfo.scanIntervalList.end(); ++intervalListIter) { + /* Determine whether control is required in the current scene and scan mode. */ + if (intervalListIter->scanScene == customIter->first && intervalListIter->scanMode == scanMode && + intervalListIter->isSingle) { + /* If a single application is distinguished. */ + if (!AllowSingleAppScanByInterval(appId, *intervalListIter)) { return false; } + } else if (intervalListIter->scanScene == customIter->first && intervalListIter->scanMode == scanMode && + !intervalListIter->isSingle) { + if (!AllowFullAppScanByInterval(appId, *intervalListIter)) + return false; } } return true; @@ -1697,28 +1883,21 @@ bool ScanService::ExternScanByInterval(int appId, SingleAppForbid &singleAppForb switch (singleAppForbid.scanIntervalMode.intervalMode) { case IntervalMode::INTERVAL_FIXED: - return AllowScanByIntervalFixed(singleAppForbid.fixedScanCount, - singleAppForbid.fixedCurrentTime, - singleAppForbid.scanIntervalMode.interval, - singleAppForbid.scanIntervalMode.count); + return AllowScanByIntervalFixed(singleAppForbid.fixedScanCount, singleAppForbid.fixedCurrentTime, + singleAppForbid.scanIntervalMode.interval, singleAppForbid.scanIntervalMode.count); case IntervalMode::INTERVAL_EXP: - return AllowScanByIntervalExp(singleAppForbid.expScanCount, - singleAppForbid.scanIntervalMode.interval, + return AllowScanByIntervalExp(singleAppForbid.expScanCount, singleAppForbid.scanIntervalMode.interval, singleAppForbid.scanIntervalMode.count); case IntervalMode::INTERVAL_CONTINUE: - return AllowScanByIntervalContinue(singleAppForbid.continueScanTime, - singleAppForbid.lessThanIntervalNum, - singleAppForbid.scanIntervalMode.interval, - singleAppForbid.scanIntervalMode.count); + return AllowScanByIntervalContinue(singleAppForbid.continueScanTime, singleAppForbid.lessThanIntervalCount, + singleAppForbid.scanIntervalMode.interval, singleAppForbid.scanIntervalMode.count); case IntervalMode::INTERVAL_BLOCKLIST: WIFI_LOGI("INTERVAL_BLOCKLIST IntervalMode.\n"); - return AllowScanByIntervalBlocklist(appId, - singleAppForbid.blockListScanTime, - singleAppForbid.lessThanIntervalNum, - singleAppForbid.scanIntervalMode.interval, + return AllowScanByIntervalBlocklist(appId, singleAppForbid.blockListScanTime, + singleAppForbid.lessThanIntervalCount, singleAppForbid.scanIntervalMode.interval, singleAppForbid.scanIntervalMode.count); default: @@ -1726,31 +1905,114 @@ bool ScanService::ExternScanByInterval(int appId, SingleAppForbid &singleAppForb } } +bool ScanService::AllowSingleAppScanByInterval(int appId, ScanIntervalMode scanIntervalMode) +{ + WIFI_LOGI("Enter ScanService::AllowSingleAppScanByInterval.\n"); + + bool appIdExisted = false; + for (auto forbidListIter = appForbidList.begin(); forbidListIter != appForbidList.end(); ++forbidListIter) { + if (forbidListIter->appID == appId && + forbidListIter->scanIntervalMode.scanScene == scanIntervalMode.scanScene && + forbidListIter->scanIntervalMode.scanMode == scanIntervalMode.scanMode) { + appIdExisted = true; + } + } + /* If the appId is the first scan request, add it to appForbidList. */ + if (!appIdExisted) { + SingleAppForbid singleAppForbid; + singleAppForbid.appID = appId; + singleAppForbid.scanIntervalMode.scanScene = scanIntervalMode.scanScene; + singleAppForbid.scanIntervalMode.scanMode = scanIntervalMode.scanMode; + singleAppForbid.scanIntervalMode.interval = scanIntervalMode.interval; + singleAppForbid.scanIntervalMode.intervalMode = scanIntervalMode.intervalMode; + singleAppForbid.scanIntervalMode.count = scanIntervalMode.count; + appForbidList.push_back(singleAppForbid); + } + for (auto iter = appForbidList.begin(); iter != appForbidList.end(); ++iter) { + if (iter->appID == appId && iter->scanIntervalMode.scanScene == scanIntervalMode.scanScene && + iter->scanIntervalMode.scanMode == scanIntervalMode.scanMode) { + if (!ExternScanByInterval(appId, *iter)) { + WIFI_LOGI("AllowSingleAppScanByInterval:false."); + return false; + } + } + } + WIFI_LOGI("AllowSingleAppScanByInterval:true."); + return true; +} + +bool ScanService::AllowFullAppScanByInterval(int appId, ScanIntervalMode scanIntervalMode) +{ + WIFI_LOGI("Enter ScanService::AllowFullAppScanByInterval.\n"); + + bool fullAppExisted = false; + for (auto fullAppForbidIter = fullAppForbidList.begin(); fullAppForbidIter != fullAppForbidList.end(); + ++fullAppForbidIter) { + if (fullAppForbidIter->scanIntervalMode.scanScene == scanIntervalMode.scanScene && + fullAppForbidIter->scanIntervalMode.scanMode == scanIntervalMode.scanMode) { + fullAppExisted = true; + } + } + if (!fullAppExisted) { + SingleAppForbid singleAppForbid; + singleAppForbid.scanIntervalMode.scanScene = scanIntervalMode.scanScene; + singleAppForbid.scanIntervalMode.scanMode = scanIntervalMode.scanMode; + singleAppForbid.scanIntervalMode.interval = scanIntervalMode.interval; + singleAppForbid.scanIntervalMode.intervalMode = scanIntervalMode.intervalMode; + singleAppForbid.scanIntervalMode.count = scanIntervalMode.count; + fullAppForbidList.push_back(singleAppForbid); + } + for (auto iter = fullAppForbidList.begin(); iter != fullAppForbidList.end(); ++iter) { + if (iter->scanIntervalMode.scanScene == scanIntervalMode.scanScene && + iter->scanIntervalMode.scanMode == scanIntervalMode.scanMode) { + if (!ExternScanByInterval(appId, *iter)) { + WIFI_LOGI("AllowFullAppScanByInterval:false."); + return false; + } + } + } + WIFI_LOGI("AllowFullAppScanByInterval:true."); + return true; +} + bool ScanService::AllowScanByIntervalFixed(int &fixedScanCount, time_t &fixedScanTime, int &interval, int &count) { WIFI_LOGI("Enter ScanService::AllowScanByIntervalFixed.\n"); - time_t now = time(0); + time_t now = time(nullptr); /* First scan */ if (fixedScanCount == 0) { fixedScanCount++; fixedScanTime = now; + WIFI_LOGD("first scan, fixedScanTime:%{public}ld, interval:%{public}d count:%{public}d fixed return true.", + fixedScanTime, interval, count); return true; } /* The scanning interval is greater than interval, and counting is restarted. */ + + time_t timeExp = now - fixedScanTime; if (now - fixedScanTime >= interval) { fixedScanCount = 1; fixedScanTime = now; + WIFI_LOGD("interval>interval,fixedScanTime:%{public}ld,interval:%{public}d " + "count:%{public}d,timeExp:%{public}ld,return true.", + fixedScanTime, interval, count, timeExp); return true; } - /** + /* * * Scan is forbidden because the scanning interval is less than interval * and the number of scan times exceeds count. */ if (fixedScanCount >= count) { + WIFI_LOGD(" fixedScanCount=%{public}d count=%{public}d,timeExp:%{public}ld,return false.", fixedScanCount, + count, timeExp); return false; } fixedScanCount++; + WIFI_LOGD("normal " + "scan,fixedScanCount:%{public}d,fixedScanTime:%{public}ld,interval:%{public}d,count:%{public}d,timeExp:" + "%{public}ld,return true.", + fixedScanCount, fixedScanTime, interval, count, timeExp); return true; } @@ -1770,13 +2032,13 @@ bool ScanService::AllowScanByIntervalExp(int &expScanCount, int &interval, int & return true; } -bool ScanService::AllowScanByIntervalContinue( - time_t &continueScanTime, int &lessThanIntervalCount, int &interval, int &count) +bool ScanService::AllowScanByIntervalContinue(time_t &continueScanTime, int &lessThanIntervalCount, int &interval, + int &count) { WIFI_LOGI("Enter ScanService::AllowScanByIntervalContinue.\n"); - WIFI_LOGD("lessThanIntervalCount:%{public}d, interval:%{public}d, count:%{public}d", - lessThanIntervalCount, interval, count); + WIFI_LOGD("lessThanIntervalCount:%{public}d, interval:%{public}d, count:%{public}d", lessThanIntervalCount, + interval, count); time_t now = time(nullptr); /* First scan */ if (continueScanTime == 0) { @@ -1850,5 +2112,62 @@ bool ScanService::AllowScanByIntervalBlocklist( blockListScanTime = now; return true; } + +bool ScanService::AllowScanByDisableScanCtrl() +{ + std::unique_lock lock(scanControlInfoMutex); + return !disableScanFlag; +} + +bool ScanService::AllowScanByMovingFreeze() +{ + LOGI("Enter ScanService::AllowScanByMovingFreeze.\n"); + + /* moving freeze trust mode. */ + bool isTrustListMode = IsScanTrustMode(); + if (isTrustListMode && IsInScanTrust(-1)) { + WIFI_LOGD("Trust list mode,sceneId(MovingFreeze) in the list, return true."); + return true; + } + + if (!IsMovingFreezeState()) { + WIFI_LOGD("It's not in the movingfreeze mode, return true."); + return true; + } + + if (!IsMovingFreezeScaned()) { + SetMovingFreezeScaned(true); + WIFI_LOGD("In movingfreeze mode, return true for the first scan."); + return true; + } else { + WIFI_LOGD("In movingfreeze mode, return false for the already scanned."); + return false; + } + + return true; +} + +bool ScanService::IsPackageInTrustList(const std::string &trustList, int sceneId, + const std::string &appPackageName) const +{ + std::vector trustPackages; + SplitString(trustList, "|", trustPackages); + + bool bFind = false; + for (const auto &package : trustPackages) { + if (package == appPackageName) { + WIFI_LOGD("IsPackageInTrustList=true"); + bFind = true; + break; + } + } + + if (!bFind) { + WIFI_LOGD("sceneId=%{public}d, appName=%{public}s trustList=%{public}s, not in the lists.", sceneId, + appPackageName.c_str(), trustList.c_str()); + } + + return bFind; +} } // namespace Wifi } // namespace OHOS diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_service.h b/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_service.h index 046c0d87a900858c867ae5353a9ad7303957f5a1..9f22cdca59ace9c086fbd1c999d3dd8b5215af78 100755 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_service.h +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_service.h @@ -15,24 +15,24 @@ #ifndef OHOS_WIFI_SCAN_SERVICE_H #define OHOS_WIFI_SCAN_SERVICE_H -#include #include +#include +#include #include +#include +#include #include "iscan_service_callbacks.h" -#include "wifi_log.h" -#include "wifi_error_no.h" #include "define.h" +#include "wifi_scan_msg.h" +#include "wifi_errcode.h" #include "scan_common.h" #include "scan_monitor.h" #include "scan_state_machine.h" -#include "wifi_internal_msg.h" -#include "log_helper.h" namespace OHOS { namespace Wifi { const int DISCONNECTED_SCAN_INTERVAL = 20 * 60 * 1000; const int RESTART_PNO_SCAN_TIME = 5 * 1000; -const int SCREEN_CLOSED = 2; const int FREQS_24G_MAX_VALUE = 2500; const int FREQS_5G_MIN_VALUE = 5000; const int SECOND_TO_MICRO_SECOND = 1000000; @@ -43,10 +43,6 @@ const int CUSTOM_SCAN_SCENE = 2; const int SCREEN_SCAN_SCENE = 3; const int OTHER_SCAN_SCENE = 4; const int SYSTEM_SCAN_INIT_TIME = 20; -const int APP_FOREGROUND_SCAN = 0; -const int APP_BACKGROUND_SCAN = 1; -const int SYS_FOREGROUND_SCAN = 2; -const int SYS_BACKGROUND_SCAN = 3; class ScanService { FRIEND_GTEST(ScanService); @@ -65,6 +61,12 @@ public: * */ virtual void UnInitScanService(); + /** + * @Description Registers the callback function of the scanning module to the interface service. + * + * @param scanSerivceCallbacks callback function + */ + virtual void RegisterScanCallbacks(const IScanSerivceCallbacks &iScanSerivceCallbacks); /** * @Description Start a complete Wi-Fi scan. * @@ -79,6 +81,13 @@ public: * @return success: WIFI_OPT_SUCCESS, failed: WIFI_OPT_FAILED */ virtual ErrCode ScanWithParam(const WifiScanParams ¶ms); + /** + * @Description Disable/Restore the scanning operation. + * + * * @param params - disable or not. + * @return WIFI_OPT_SUCCESS: success, WIFI_OPT_FAILED: failed + */ + ErrCode DisableScan(bool disable); /** * @Description Starting a Single Scan. * @@ -126,15 +135,19 @@ public: /** * @Description Screen State (On/Off) Change Handler * - * @param screenOn - screen state[in] */ - virtual void HandleScreenStatusChanged(bool screenOn); + virtual void HandleScreenStatusChanged(); /** * @Description STA status change processing * * @param state - STA state[in] */ virtual void HandleStaStatusChanged(int status); + /** + * @Description movingfreeze status change processing + * + */ + virtual void HandleMovingFreezeChanged(); /** * @Description custom scene status change processing * @@ -142,24 +155,18 @@ public: * @param customSceneStatus custom scene status[in] */ virtual void HandleCustomStatusChanged(int customScene, int customSceneStatus); - /** - * @Description Sets the type of the app to be operated. + * @Description Get custom scene state. * - * @param appMode - Type of the app to be scanned. + * @param customState custom scene state map[out] + * @return */ - virtual void SetOperateAppMode(int appMode); + virtual void HandleGetCustomSceneState(std::map& sceneMap) const; /** * @Description Query and save the scan control policy. * */ virtual void GetScanControlInfo(); - /** - * @Description Obtain the scenario set by the customer through changeState. - * - * @param scene - Scenario value corresponding to the scenario - */ - virtual void SetCustomScene(int scene, time_t currentTime); /** * @Description When scanning control changes, the count data needs to be cleared. * @@ -177,39 +184,51 @@ private: using PnoScanInfoHandlerMap = std::map; IScanSerivceCallbacks mScanSerivceCallbacks; - ScanStateMachine *pScanStateMachine; /* Scanning state machine pointer */ - ScanMonitor *pScanMonitor; /* Scanning Monitor Pointer */ - bool scanStartedFlag; /* The scanning is started */ + ScanStateMachine *pScanStateMachine; /* Scanning state machine pointer */ + ScanMonitor *pScanMonitor; /* Scanning Monitor Pointer */ + bool scanStartedFlag; /* The scanning is started */ ScanInfoHandlerMap scanInfoHandlerMap; /* Map of obtaining the scanning result */ PnoScanInfoHandlerMap pnoScanInfoHandlerMap; /* Map of obtaining PNO scanning results */ - ScanConfigMap scanConfigMap; /* Save Scan Configuration */ - int scanConfigStoreIndex; /* Index for saving the scan configuration */ - int64_t pnoScanStartTime; /* PNO scanning start time */ - bool isScreenOn; /* Screen state */ - int staStatus; /* STA state */ - bool isPnoScanBegined; /* The PNO scanning has been started */ - bool autoNetworkSelection; /* Automatic network selection */ - int64_t lastSystemScanTime; /* Last System Scan Time */ - int pnoScanFailedNum; /* Number of PNO Scan Failures */ - ScanControlInfo scanControlInfo; /* Scan Control Policy */ - int operateAppMode; /* Operation app type */ - std::vector freqs2G; /* The support frequencys for 2.4G */ - std::vector freqs5G; /* The support frequencys for 5G */ - std::vector freqsDfs; /* The support frequencys for DFS */ - SystemScanIntervalMode systemScanIntervalMode; /* Store system scan data */ - PnoScanIntervalMode pnoScanIntervalMode; /* Store pno scan data */ - int customScene; /* Customer-defined scenario */ - time_t staCurrentTime; /* Indicates the time when the STA enters the STA scenario */ + ScanConfigMap scanConfigMap; /* Save Scan Configuration */ + int scanConfigStoreIndex; /* Index for saving the scan configuration */ + int64_t pnoScanStartTime; /* PNO scanning start time */ + int staStatus; /* STA state */ + bool isPnoScanBegined; /* The PNO scanning has been started */ + bool autoNetworkSelection; /* Automatic network selection */ + int64_t lastSystemScanTime; /* Last System Scan Time */ + int pnoScanFailedNum; /* Number of PNO Scan Failures */ + ScanControlInfo scanControlInfo; /* Scan Control Policy */ + bool disableScanFlag; /* Disable Scan Flag. */ + std::vector freqs2G; /* The support frequencys for 2.4G */ + std::vector freqs5G; /* The support frequencys for 5G */ + std::vector freqsDfs; /* The support frequencys for DFS */ + SystemScanIntervalMode systemScanIntervalMode; /* Store system scan data */ + PnoScanIntervalMode pnoScanIntervalMode; /* Store pno scan data */ + time_t staCurrentTime; /* Indicates the time when the STA enters the STA scenario */ time_t customCurrentTime; /* Indicates the time when the STA enters the Customer-defined scenario */ - std::vector appForbidList; /* Store extern app scan data */ - std::vector scanBlocklist; /* - * If the number of consecutive count times is less than - * the value of interval, the user is added to the blocklist - * and cannot be scanned. - */ - std::vector fullAppForbidList; /* Stores data that is scanned and controlled regardless of - applications. */ - std::map customSceneTimeMap; /* Record the time when a scene is entered. */ + std::vector appForbidList; /* Store extern app scan data */ + /* + * If the number of consecutive count times is less than the value of + * interval, the user is added to the blocklist and cannot be scanned. + */ + std::vector scanBlocklist; + /* Stores data that is scanned and controlled regardless of applications. */ + std::vector fullAppForbidList; + std::map customSceneTimeMap; /* Record the time when a scene is entered. */ + int staSceneForbidCount; + int customSceneForbidCount; + mutable std::mutex scanConfigMapMutex; + mutable std::mutex scanControlInfoMutex; + enum class ScanType { + SCAN_TYPE_EXTERN = 0, + SCAN_TYPE_SYSTEMTIMER, + SCAN_TYPE_PNO, + }; + bool scanTrustMode; /* scan trustlist mode */ + std::unordered_set scanTrustSceneIds; /* scan scene ids */ + bool isAbsFreezeState; /* absolute freeze state. */ + bool isAbsFreezeScaned; /* scanned in freeze state. */ + int scanResultBackup; /* scan result backup. */ /** * @Description Obtains the frequency of a specified band. @@ -250,7 +269,7 @@ private: * @param scanInfoList - scan result list[in] * @return success: true, failed: false */ - bool StoreUserScanInfo(const StoreScanConfig &scanConfig, const std::vector &scanInfoList); + bool StoreUserScanInfo(const StoreScanConfig &scanConfig, std::vector &scanInfoList); /** * @Description Sends the scanning result to the interface service, * which then sends the scanning result to the connection @@ -259,14 +278,16 @@ private: * @param scanInfoList - scan result list[in] */ void ReportScanInfos(std::vector &interScanList); + /** - * @Description Convert the scanning result to the format of the interface service. + * @Description Sends the store scanning result to the interface service, + * which then sends the store scanning result to the connection + * management module for processing. * * @param scanInfoList - scan result list[in] - * @param scanInfoList - Converted list[out] */ - void ConvertScanInfos( - const std::vector &interScanList, std::vector &scanInfoList); + void ReportStoreScanInfos(std::vector &interScanList); + /** * @Description Enter the PNO scanning message body. * @@ -325,31 +346,106 @@ private: * */ void RestartPnoScanTimeOut(); - /** - * @Description Querying the screen status. - * - */ - void GetScreenState(); /** * @Description Determines whether external scanning is allowed based on the scanning policy. * - * @param appId - ID of the app to be scanned.[in] * @return success: true, failed: false */ - bool AllowExternScan(int appId); + ErrCode AllowExternScan(); /** * @Description Determine whether to allow scheduled system scanning. * * @return success: true, failed: false */ - bool AllowSystemTimerScan(); + ErrCode AllowSystemTimerScan(); /** * @Description Determines whether to allow PNO scanning based on the scanning policy. * * @return success: true, failed: false */ - bool AllowPnoScan(); + ErrCode AllowPnoScan(); + /** + * @Description Determines whether to allow scanning based on the scanning type.. + * + * @param scanType - scan type: 0 - Extern; 1 - SystemTimer 2 Pno + * @return true: allow, false: not allowed. + */ + ErrCode AllowScanByType(ScanType scanType); + /** + * @Description Set the current mode to trust list mode. + * + */ + void SetScanTrustMode(); + /** + * @Description Reset to non scan trust list mode. + * + */ + void ResetToNonTrustMode(); + /** + * @Description Is it the trust list mode? + * + * @param sceneId - current scene id[out]. + * @return true: success, false: failed + */ + bool IsScanTrustMode() const; + /** + * @Description Add the scene id to trust list. + * Assume that the scene id of moving freeze is -1. + * + * @param sceneId - scene id. + */ + void AddScanTrustSceneId(int sceneId); + /** + * @Description Clear trust list. + * + */ + void ClearScanTrustSceneIds(); + /** + * @Description Is sceneId in trust list. + * + * @param sceneId - scene id. + */ + bool IsInScanTrust(int sceneId) const; + /** + * @Description Set the moving freeze status by state. + * + * @param state - state value. + */ + void SetMovingFreezeState(bool state); + /** + * @Description Is it the moving freeze state? + * + * @return true: success, false: failed + */ + bool IsMovingFreezeState() const; + /** + * @Description Set the moving freeze state to scanned. + * + * @param scanned - scanned flag. + */ + void SetMovingFreezeScaned(bool scanned); /** + * @Description Whether scanned in moving freeze state.? + * + */ + bool IsMovingFreezeScaned() const; + /** + * @Description Apply trustlists scanning policies. + * + * @param scanType - scan type: 0 - Extern; 1 - SystemTimer 2 Pno + * @return true: success, false: failed + */ + ErrCode ApplyTrustListPolicy(ScanType scanType); + /* * + * @Description Apply trustlists and moving freeze scanning policies. + * + * @param scanType - type: 0 - Extern; 1 - SystemTimer 2 Pno + * @return WIFI_OPT_SUCCESS: success, + * WIFI_OPT_FAILED: general scan control fail, + * WIFI_OPT_MOVING_FREEZE_CTRL: moving freeze scan control fail. + */ + ErrCode ApplyScanPolices(ScanType type); + /* * * @Description Obtains the current screen. * * @return success: ScanScene, failed: SCAN_SCENE_MAX @@ -379,7 +475,13 @@ private: * * @return success: true, failed: false */ - bool IsExternScanning(); + bool IsExternScanning() const; + /** + * @Description Indicates whether scanning with parameter. + * + * @return success: true, failed: false + */ + bool IsScanningWithParam(); /** * @Description Adjust the frequency band and frequency based on the scanning policy. * @@ -413,12 +515,6 @@ private: * @param freqs - frequency list[in] */ void Delete5GhzFreqs(std::vector &freqs); - /** - * @Description Obtains the type of the app to be operated. - * - * @return success: ScanMode, failed: others - */ - ScanMode GetOperateAppMode(); /** * @Description Get the ssid of saved networks. * @@ -449,7 +545,7 @@ private: * @return true - success * @return false - failed */ - bool AllowScanDuringScanning(ScanMode scanMode); + bool AllowScanDuringScanning(ScanMode scanMode) const; /** * @Description Check whether the scan mode can be used during screen off under the forbid mode control. * @@ -457,7 +553,7 @@ private: * @return true - success * @return false - failed */ - bool AllowScanDuringScreenOff(ScanMode scanMode); + bool AllowScanDuringScreenOff(ScanMode scanMode) const; /** * @Description * @@ -586,6 +682,48 @@ private: */ bool AllowScanByIntervalBlocklist( int appId, time_t &blockListScanTime, int &lessThanIntervalCount, int &interval, int &count); + + /** + * @Description Determines whether scanning is allowed by disable scan control. + * + * @return true: allow, false: not allowed. + */ + bool AllowScanByDisableScanCtrl(); + + /** + * @Description Determines whether scanning is allowed in movingfreeze mode. + * + * @return true: allow, false: not allowed. + */ + bool AllowScanByMovingFreeze(); + + /** + * @Description Is the app in the trustlist? + * + * @param trustList trustlist[in] + * @param sceneId scene id[in] + * @param appPackageName app package name[in] + * @return true: in the trustlist, false: not in the trustlist. + */ + bool IsPackageInTrustList(const std::string& trustList, int sceneId, const std::string &appPackageName) const; + /* * + * @Description all scan check at custom check. + * + * @param customIter custom iterator[in] + * @param scanMode scene mode[in] + * @return true: allow, false: not allowed. + */ + bool AllowCustomSceneCheck(const std::map::const_iterator &customIter, ScanMode scanMode); + /* * + * @Description all extern scan check at custom check. + * + * @param customIter custom iterator[in] + * @param appId app id[in] + * @param scanMode scene mode[in] + * @return true: allow, false: not allowed. + */ + bool AllowExternCustomSceneCheck(const std::map::const_iterator &customIter, int appId, + ScanMode scanMode); }; } // namespace Wifi } // namespace OHOS diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan_stub.cpp b/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan_stub.cpp index 4c4de8efe33dc6295e59614cb2b56ef97609ce0a..dbd8ad3f2ef0e3bd92bfe13763d2507a09f3aaa2 100755 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan_stub.cpp +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan_stub.cpp @@ -21,9 +21,10 @@ #include "wifi_internal_event_dispatcher.h" #include "wifi_scan_death_recipient.h" +DEFINE_WIFILOG_SCAN_LABEL("WifiScanStub"); + namespace OHOS { namespace Wifi { -DEFINE_WIFILOG_SCAN_LABEL("WifiScanStub"); WifiScanStub::WifiScanStub() : callback_(nullptr), mSingleCallback(false) {} @@ -83,45 +84,26 @@ sptr WifiScanStub::GetCallback() const int WifiScanStub::OnSetScanControlInfo(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - WIFI_LOGD("run OnSetScanControlInfo code %{public}u, datasize %zu", code, data.GetRawDataSize()); + WIFI_LOGD("run OnSetScanControlInfo code %{public}u, datasize %{public}zu", code, data.GetRawDataSize()); ScanControlInfo info; - int forbidMapSize = data.ReadInt32(); - for (int i = 0; i < forbidMapSize; i++) { - int tmp = data.ReadInt32(); - int modeMapSize = data.ReadInt32(); - std::vector scanModeList; - for (int j = 0; j < modeMapSize; j++) { - ScanForbidMode scanForbidMode; - int tmpScanMode = data.ReadInt32(); - if (tmpScanMode < 0 || tmpScanMode >= int(ScanMode::SCAN_MODE_MAX)) { - continue; - } - scanForbidMode.scanMode = ScanMode(tmpScanMode); - scanForbidMode.forbidTime = data.ReadInt32(); - scanForbidMode.forbidCount = data.ReadInt32(); - scanModeList.push_back(scanForbidMode); - } - if (tmp < 0 || tmp >= int(SCAN_SCENE_MAX)) { - continue; - } - info.scanForbidMap.insert(std::pair>(tmp, scanModeList)); + int forbidListSize = data.ReadInt32(); + for (int i = 0; i < forbidListSize; i++) { + ScanForbidMode scanForbidMode; + scanForbidMode.scanScene = data.ReadInt32(); + scanForbidMode.scanMode = static_cast(data.ReadInt32()); + scanForbidMode.forbidTime = data.ReadInt32(); + scanForbidMode.forbidCount = data.ReadInt32(); + info.scanForbidList.push_back(scanForbidMode); } int intervalSize = data.ReadInt32(); for (int i = 0; i < intervalSize; i++) { ScanIntervalMode scanIntervalMode; scanIntervalMode.scanScene = data.ReadInt32(); - int mode = data.ReadInt32(); - if (mode < 0 || mode >= int(ScanMode::SCAN_MODE_MAX)) { - continue; - } - scanIntervalMode.scanMode = ScanMode(mode); - scanIntervalMode.isSingle = data.ReadInt32(); - scanIntervalMode.intervalMode = (IntervalMode)data.ReadInt32(); + scanIntervalMode.scanMode = static_cast(data.ReadInt32()); + scanIntervalMode.isSingle = data.ReadBool(); + scanIntervalMode.intervalMode = static_cast(data.ReadInt32()); scanIntervalMode.interval = data.ReadInt32(); - if (scanIntervalMode.interval < MIN_SCAN_INTERVAL) { - continue; - } scanIntervalMode.count = data.ReadInt32(); info.scanIntervalList.push_back(scanIntervalMode); } @@ -135,7 +117,7 @@ int WifiScanStub::OnSetScanControlInfo(uint32_t code, MessageParcel &data, Messa int WifiScanStub::OnScan(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - WIFI_LOGD("run OnScan code %{public}u, datasize %zu", code, data.GetRawDataSize()); + WIFI_LOGD("run OnScan code %{public}u, datasize %{public}zu", code, data.GetRawDataSize()); ErrCode ret = Scan(); reply.WriteInt32(0); reply.WriteInt32(ret); @@ -145,7 +127,7 @@ int WifiScanStub::OnScan(uint32_t code, MessageParcel &data, MessageParcel &repl int WifiScanStub::OnScanByParams(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - WIFI_LOGD("run OnScanByParams code %{public}u, datasize %zu", code, data.GetRawDataSize()); + WIFI_LOGD("run OnScanByParams code %{public}u, datasize %{public}zu", code, data.GetRawDataSize()); WifiScanParams params; params.ssid = data.ReadCString(); params.bssid = data.ReadCString(); @@ -165,7 +147,7 @@ int WifiScanStub::OnScanByParams(uint32_t code, MessageParcel &data, MessageParc int WifiScanStub::OnIsWifiClosedScan(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - WIFI_LOGD("run OnIsWifiClosedScan code %{public}u, datasize %zu", code, data.GetRawDataSize()); + WIFI_LOGD("run OnIsWifiClosedScan code %{public}u, datasize %{public}zu", code, data.GetRawDataSize()); bool bOpen = false; ErrCode ret = IsWifiClosedScan(bOpen); reply.WriteInt32(0); @@ -178,7 +160,7 @@ int WifiScanStub::OnIsWifiClosedScan(uint32_t code, MessageParcel &data, Message int WifiScanStub::OnGetScanInfoList(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - WIFI_LOGD("run OnGetScanInfoList code %{public}u, datasize %zu", code, data.GetRawDataSize()); + WIFI_LOGD("run OnGetScanInfoList code %{public}u, datasize %{public}zu", code, data.GetRawDataSize()); std::vector result; ErrCode ret = GetScanInfoList(result); reply.WriteInt32(0); @@ -216,7 +198,7 @@ int WifiScanStub::OnGetScanInfoList(uint32_t code, MessageParcel &data, MessageP int WifiScanStub::OnRegisterCallBack(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - WIFI_LOGD("run %{public}s code %{public}u, datasize %zu", __func__, code, data.GetRawDataSize()); + WIFI_LOGD("run %{public}s code %{public}u, datasize %{public}zu", __func__, code, data.GetRawDataSize()); ErrCode ret = WIFI_OPT_FAILED; do { sptr remote = data.ReadRemoteObject(); diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_monitor.cpp b/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_monitor.cpp index 368f7fb0c7cf4f565328621d7cd5ae21eb71efc7..fa20f67e9360e76554908e712cc0a8e3c91759e2 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_monitor.cpp +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_monitor.cpp @@ -72,7 +72,7 @@ void StaMonitor::SetStateMachine(StaStateMachine *paraStaStateMachine) } void StaMonitor::OnConnectChangedCallBack(int status, int networkId,const std::string &bssid) { - WIFI_LOGI("OnConnectChangedCallBack() status:%{public}d,networkId=%{public}d,bssid={private}%s", + WIFI_LOGI("OnConnectChangedCallBack() status:%{public}d,networkId=%{public}d,bssid=%{private}s", status, networkId, bssid.c_str()); diff --git a/tests/wifi_standard/wifi_framework/wifi_manage/unittest/wifi_config_center_test.cpp b/tests/wifi_standard/wifi_framework/wifi_manage/unittest/wifi_config_center_test.cpp index 9ffa1fa6ad6e3c4b95b197a80015f60556b0a4ce..3ecb4d9a7c2d8f9bdfa1bbb2d5ef4434a63d349a 100644 --- a/tests/wifi_standard/wifi_framework/wifi_manage/unittest/wifi_config_center_test.cpp +++ b/tests/wifi_standard/wifi_framework/wifi_manage/unittest/wifi_config_center_test.cpp @@ -357,7 +357,7 @@ HWTEST_F(WifiConfigCenterTest, SetGetAirplaneModeState_SUCCESS, TestSize.Level1) HWTEST_F(WifiConfigCenterTest, SetGetAppRunningState_SUCCESS, TestSize.Level1) { - int mode = 1; + ScanMode mode = ScanMode::APP_BACKGROUND_SCAN; WifiConfigCenter::GetInstance().SetAppRunningState(mode); EXPECT_EQ(mode, WifiConfigCenter::GetInstance().GetAppRunningState()); } diff --git a/tests/wifi_standard/wifi_framework/wifi_manage/wifi_scan/Mock/mock_scan_service.cpp b/tests/wifi_standard/wifi_framework/wifi_manage/wifi_scan/Mock/mock_scan_service.cpp index 7abdfc5f062e88d5a3b1fdae196fbabe95876eed..1a001a5a6e8a66ceeab091b4bcd728f6709004b0 100644 --- a/tests/wifi_standard/wifi_framework/wifi_manage/wifi_scan/Mock/mock_scan_service.cpp +++ b/tests/wifi_standard/wifi_framework/wifi_manage/wifi_scan/Mock/mock_scan_service.cpp @@ -57,9 +57,8 @@ void MockScanService::SystemScanProcess(bool scanAtOnce) WIFI_LOGI("Enter MockScanService::SystemScanProcess"); } -void MockScanService::HandleScreenStatusChanged(bool screenOn) +void MockScanService::HandleScreenStatusChanged() { - (void)screenOn; WIFI_LOGI("Enter MockScanService::HandleScreenStatusChanged"); } @@ -76,10 +75,10 @@ void MockScanService::HandleCustomStatusChanged(int customScene, int customScene WIFI_LOGI("Enter MockScanService::HandleCustomStatusChanged"); } -void MockScanService::SetOperateAppMode(int appMode) +void MockScanService::HandleGetCustomSceneState(std::map& sceneMap) const { - (void)appMode; - WIFI_LOGI("Enter MockScanService::SetOperateAppMode"); + (void)sceneMap; + WIFI_LOGI("Enter MockScanService::HandleGetCustomSceneState"); } void MockScanService::GetScanControlInfo() diff --git a/tests/wifi_standard/wifi_framework/wifi_manage/wifi_scan/Mock/mock_scan_service.h b/tests/wifi_standard/wifi_framework/wifi_manage/wifi_scan/Mock/mock_scan_service.h index 03a6a481d0610af8457ac5593b1e1f13743c19f0..ea49c00291154c7e456db48a1adfd4303a610cfd 100644 --- a/tests/wifi_standard/wifi_framework/wifi_manage/wifi_scan/Mock/mock_scan_service.h +++ b/tests/wifi_standard/wifi_framework/wifi_manage/wifi_scan/Mock/mock_scan_service.h @@ -30,10 +30,10 @@ public: ErrCode Scan(bool externFlag); ErrCode ScanWithParam(const WifiScanParams ¶ms); void SystemScanProcess(bool scanAtOnce); - void HandleScreenStatusChanged(bool screenOn); + void HandleScreenStatusChanged(); void HandleStaStatusChanged(int status); void HandleCustomStatusChanged(int customScene, int customSceneStatus); - void SetOperateAppMode(int appMode); + void HandleGetCustomSceneState(std::map& sceneMap) const; void GetScanControlInfo(); void ClearScanControlValue(); void SetStaCurrentTime(); diff --git a/tests/wifi_standard/wifi_framework/wifi_manage/wifi_scan/Mock/mock_wifi_settings.h b/tests/wifi_standard/wifi_framework/wifi_manage/wifi_scan/Mock/mock_wifi_settings.h index 77eaedf81b8e7329ab681e4c000f0bb7b243d343..81627606f2ce21944e7d19030c9dd21ee61af799 100644 --- a/tests/wifi_standard/wifi_framework/wifi_manage/wifi_scan/Mock/mock_wifi_settings.h +++ b/tests/wifi_standard/wifi_framework/wifi_manage/wifi_scan/Mock/mock_wifi_settings.h @@ -16,6 +16,7 @@ #define OHOS_MOCK_WIFI_SETTINGS_H #include "wifi_msg.h" +#include "wifi_internal_msg.h" #include namespace OHOS { @@ -28,12 +29,19 @@ public: virtual int GetScanControlInfo(ScanControlInfo &info) = 0; virtual int SetScanControlInfo(const ScanControlInfo &info) = 0; virtual void SetScreenState(const int &state) = 0; - virtual int GetScreenState() = 0; + virtual int GetScreenState() const = 0; + virtual ScanMode GetAppRunningState() const = 0; + virtual const std::string& GetAppPackageName() const = 0; + virtual int GetFreezeModeState() const = 0; + virtual int GetNoChargerPlugModeState() const = 0; + virtual void SetSupportHwPnoFlag(bool supportHwPnoFlag) = 0; virtual bool GetSupportHwPnoFlag() = 0; virtual int GetMinRssi2Dot4Ghz() = 0; virtual int GetMinRssi5Ghz() = 0; virtual bool GetWhetherToAllowNetworkSwitchover() = 0; virtual int GetDeviceConfig(std::vector &results) = 0; + virtual const std::vector& ReloadTrustListPolicies() = 0; + virtual const MovingFreezePolicy& ReloadMovingFreezePolicy() = 0; }; class WifiSettings : public MockWifiSettings { @@ -45,12 +53,19 @@ public: MOCK_METHOD1(GetScanControlInfo, int(ScanControlInfo &info)); MOCK_METHOD1(SetScanControlInfo, int(const ScanControlInfo &info)); MOCK_METHOD1(SetScreenState, void(const int &state)); - MOCK_METHOD0(GetScreenState, int()); + MOCK_CONST_METHOD0(GetScreenState, int()); + MOCK_CONST_METHOD0(GetAppRunningState, ScanMode()); + MOCK_CONST_METHOD0(GetAppPackageName, const std::string&()); + MOCK_CONST_METHOD0(GetFreezeModeState, int()); + MOCK_CONST_METHOD0(GetNoChargerPlugModeState, int()); + MOCK_METHOD1(SetSupportHwPnoFlag, void(bool supportHwPnoFlag)); MOCK_METHOD0(GetSupportHwPnoFlag, bool()); MOCK_METHOD0(GetMinRssi2Dot4Ghz, int()); MOCK_METHOD0(GetMinRssi5Ghz, int()); MOCK_METHOD0(GetWhetherToAllowNetworkSwitchover, bool()); MOCK_METHOD1(GetDeviceConfig, int(std::vector &results)); + MOCK_METHOD0(ReloadTrustListPolicies, const std::vector&()); + MOCK_METHOD0(ReloadMovingFreezePolicy, const MovingFreezePolicy&()); }; } // namespace Wifi } // namespace OHOS diff --git a/tests/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_interface_test.cpp b/tests/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_interface_test.cpp index 513d1b3873c746fd217d9d9adfbdf5fc2774d515..22d1f04395100e89b4b3b5a39581ae15de1f323f 100644 --- a/tests/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_interface_test.cpp +++ b/tests/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_interface_test.cpp @@ -95,13 +95,13 @@ HWTEST_F(ScanInterfaceTest, ScanWithParamSuccess, TestSize.Level1) HWTEST_F(ScanInterfaceTest, OnScreenStateChangedSuccess1, TestSize.Level1) { - int screenState = STATE_OPEN; + int screenState = MODE_STATE_OPEN; EXPECT_EQ(WIFI_OPT_SUCCESS, pScanInterface->OnScreenStateChanged(screenState)); } HWTEST_F(ScanInterfaceTest, OnScreenStateChangedSuccess2, TestSize.Level1) { - int screenState = STATE_CLOSE; + int screenState = MODE_STATE_CLOSE; EXPECT_EQ(WIFI_OPT_SUCCESS, pScanInterface->OnScreenStateChanged(screenState)); } @@ -118,12 +118,12 @@ HWTEST_F(ScanInterfaceTest, OnClientModeStatusChangedSuccess, TestSize.Level1) HWTEST_F(ScanInterfaceTest, OnAppRunningModeChangedSuccess, TestSize.Level1) { - EXPECT_EQ(WIFI_OPT_SUCCESS, pScanInterface->OnAppRunningModeChanged(0)); + EXPECT_EQ(WIFI_OPT_SUCCESS, pScanInterface->OnAppRunningModeChanged(ScanMode::APP_FOREGROUND_SCAN)); } HWTEST_F(ScanInterfaceTest, OnCustomControlStateChangedSuccess, TestSize.Level1) { - int customSceneStatus = STATE_OPEN; + int customSceneStatus = MODE_STATE_OPEN; EXPECT_EQ(WIFI_OPT_SUCCESS, pScanInterface->OnCustomControlStateChanged(0, customSceneStatus)); } diff --git a/tests/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_service_test.cpp b/tests/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_service_test.cpp index 1a6f8e181685b5e6ca1c74562b9c3ded179b33ef..877122c076da99e663c7f7299ce24cc091ddbca1 100644 --- a/tests/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_service_test.cpp +++ b/tests/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_service_test.cpp @@ -43,7 +43,7 @@ public: EXPECT_CALL(WifiStaHalInterface::GetInstance(), StopPnoScan()).Times(AtLeast(0)); pScanService = std::make_unique(); pScanService->pScanStateMachine = new MockScanStateMachine(); - pScanService->mScanSerivceCallbacks = WifiManager::GetInstance().GetScanCallback(); + pScanService->RegisterScanCallbacks(WifiManager::GetInstance().GetScanCallback()); } virtual void TearDown() { @@ -268,7 +268,6 @@ public: { ScanConfig scanConfig; scanConfig.scanBand = SCAN_BAND_24_GHZ; - ; scanConfig.externFlag = true; scanConfig.scanStyle = SCAN_TYPE_HIGH_ACCURACY; EXPECT_EQ(true, pScanService->SingleScan(scanConfig)); @@ -554,8 +553,7 @@ public: void HandleScreenStatusChangedSuccess() { - pScanService->HandleScreenStatusChanged(false); - pScanService->HandleScreenStatusChanged(true); + pScanService->HandleScreenStatusChanged(); } void HandleStaStatusChangedSuccess1() @@ -582,7 +580,7 @@ public: { EXPECT_CALL(WifiSettings::GetInstance(), GetWhetherToAllowNetworkSwitchover()).Times(AtLeast(0)); int customScene = 0; - int customSceneStatus = STATE_CLOSE; + int customSceneStatus = MODE_STATE_CLOSE; pScanService->HandleCustomStatusChanged(customScene, customSceneStatus); } @@ -590,15 +588,15 @@ public: { EXPECT_CALL(WifiSettings::GetInstance(), GetWhetherToAllowNetworkSwitchover()).Times(AtLeast(0)); int customScene = 0; - int customSceneStatus = STATE_OPEN; + int customSceneStatus = MODE_STATE_OPEN; pScanService->HandleCustomStatusChanged(customScene, customSceneStatus); } void SystemScanProcessSuccess1() { EXPECT_CALL(WifiSettings::GetInstance(), GetWhetherToAllowNetworkSwitchover()); - pScanService->isScreenOn = true; ScanIntervalMode mode; + mode.scanScene = SCAN_SCENE_ALL; mode.scanMode = ScanMode::SYSTEM_TIMER_SCAN; mode.isSingle = false; pScanService->scanControlInfo.scanIntervalList.push_back(mode); @@ -610,7 +608,6 @@ public: EXPECT_CALL(WifiSettings::GetInstance(), GetWhetherToAllowNetworkSwitchover()); EXPECT_CALL(WifiSettings::GetInstance(), GetMinRssi2Dot4Ghz()).Times(AtLeast(0)); EXPECT_CALL(WifiSettings::GetInstance(), GetMinRssi5Ghz()).Times(AtLeast(0)); - pScanService->isScreenOn = false; pScanService->SystemScanProcess(true); } @@ -660,51 +657,10 @@ public: EXPECT_CALL(WifiSettings::GetInstance(), GetScanControlInfo(_)).WillRepeatedly(Return(-1)); pScanService->GetScanControlInfo(); } - - void GetScreenStateSuccess() - { - EXPECT_CALL(WifiSettings::GetInstance(), GetScreenState()).WillRepeatedly(Return(SCREEN_CLOSED)); - pScanService->GetScreenState(); - } - - void SetOperateAppModeSuccess() - { - pScanService->SetOperateAppMode(0); - } - - void GetOperateAppModeSuccess1() - { - pScanService->operateAppMode = APP_FOREGROUND_SCAN; - EXPECT_EQ(ScanMode::APP_FOREGROUND_SCAN, pScanService->GetOperateAppMode()); - } - - void GetOperateAppModeSuccess2() - { - pScanService->operateAppMode = APP_BACKGROUND_SCAN; - EXPECT_EQ(ScanMode::APP_BACKGROUND_SCAN, pScanService->GetOperateAppMode()); - } - - void GetOperateAppModeSuccess3() - { - pScanService->operateAppMode = SYS_FOREGROUND_SCAN; - EXPECT_EQ(ScanMode::SYS_FOREGROUND_SCAN, pScanService->GetOperateAppMode()); - } - - void GetOperateAppModeSuccess4() - { - pScanService->operateAppMode = SYS_BACKGROUND_SCAN; - EXPECT_EQ(ScanMode::SYS_BACKGROUND_SCAN, pScanService->GetOperateAppMode()); - } - - void GetOperateAppModeFail() - { - pScanService->operateAppMode = MAX_PNO_SCAN_FAILED_NUM; - EXPECT_EQ(ScanMode::SYS_FOREGROUND_SCAN, pScanService->GetOperateAppMode()); - } - + void AllowExternScanSuccess() { - pScanService->AllowExternScan(0); + pScanService->AllowExternScan(); } void AllowExternScanFail1() @@ -713,13 +669,21 @@ public: StoreScanConfig cfg; cfg.externFlag = true; pScanService->scanConfigMap.emplace(staScene, cfg); - pScanService->AllowExternScan(0); + + ScanMode scanMode = ScanMode::SYS_FOREGROUND_SCAN; + ScanForbidMode forbidMode; + forbidMode.scanScene = SCAN_SCENE_SCANNING; + forbidMode.scanMode = scanMode; + pScanService->scanControlInfo.scanForbidList.push_back(forbidMode); + + pScanService->AllowExternScan(); } void AllowSystemTimerScanSuccess() { EXPECT_CALL(WifiSettings::GetInstance(), GetWhetherToAllowNetworkSwitchover()); ScanIntervalMode mode; + mode.scanScene = SCAN_SCENE_ALL; mode.scanMode = ScanMode::SYSTEM_TIMER_SCAN; mode.isSingle = false; pScanService->scanControlInfo.scanIntervalList.push_back(mode); @@ -729,6 +693,7 @@ public: void AllowPnoScanSuccess() { ScanIntervalMode mode; + mode.scanScene = SCAN_SCENE_ALL; mode.scanMode = ScanMode::PNO_SCAN; mode.isSingle = false; pScanService->scanControlInfo.scanIntervalList.push_back(mode); @@ -741,11 +706,126 @@ public: StoreScanConfig cfg; cfg.externFlag = true; pScanService->scanConfigMap.emplace(staScene, cfg); - pScanService->isScreenOn = false; ScanMode scanMode = ScanMode::SYS_FOREGROUND_SCAN; EXPECT_EQ(pScanService->AllowExternScanByForbid(staScene, scanMode), true); } + void AllowExternScanByForbidFail1() + { + int staScene = 0; + StoreScanConfig cfg; + cfg.externFlag = true; + pScanService->scanConfigMap.emplace(staScene, cfg); + + ScanMode scanMode = ScanMode::SYS_FOREGROUND_SCAN; + ScanForbidMode forbidMode; + forbidMode.scanScene = SCAN_SCENE_SCANNING; + forbidMode.scanMode = scanMode; + pScanService->scanControlInfo.scanForbidList.push_back(forbidMode); + + EXPECT_EQ(pScanService->AllowExternScanByForbid(staScene, scanMode), false); + } + + void AllowExternScanByForbidFail2() + { + int staScene = 0; + StoreScanConfig cfg; + cfg.externFlag = true; + pScanService->scanConfigMap.emplace(staScene, cfg); + + ScanMode scanMode = ScanMode::SYS_FOREGROUND_SCAN; + ScanForbidMode forbidMode; + forbidMode.scanScene = SCAN_SCENE_SCANNING; + forbidMode.scanMode = ScanMode::ALL_EXTERN_SCAN; + pScanService->scanControlInfo.scanForbidList.push_back(forbidMode); + + EXPECT_EQ(pScanService->AllowExternScanByForbid(staScene, scanMode), false); + } + + void AllowExternScanByForbidFail3() + { + int staScene = 0; + ScanMode scanMode = ScanMode::SYS_FOREGROUND_SCAN; + ScanForbidMode forbidMode; + forbidMode.scanScene = SCAN_SCENE_SCREEN_OFF; + forbidMode.scanMode = scanMode; + pScanService->scanControlInfo.scanForbidList.push_back(forbidMode); + EXPECT_EQ(pScanService->AllowExternScanByForbid(staScene, scanMode), false); + } + + void AllowExternScanByForbidFail4() + { + int staScene = 0; + ScanMode scanMode = ScanMode::SYS_FOREGROUND_SCAN; + ScanForbidMode forbidMode; + forbidMode.scanScene = SCAN_SCENE_SCREEN_OFF; + forbidMode.scanMode = ScanMode::ALL_EXTERN_SCAN; + pScanService->scanControlInfo.scanForbidList.push_back(forbidMode); + EXPECT_EQ(pScanService->AllowExternScanByForbid(staScene, scanMode), false); + } + + void AllowExternScanByForbidFail5() + { + int staScene = 0; + ScanMode scanMode = ScanMode::SYS_FOREGROUND_SCAN; + ScanForbidMode scanForbidMode; + scanForbidMode.scanScene = staScene; + scanForbidMode.scanMode = scanMode; + scanForbidMode.forbidTime = 0; + scanForbidMode.forbidCount = 0; + pScanService->scanControlInfo.scanForbidList.push_back(scanForbidMode); + EXPECT_EQ(pScanService->AllowExternScanByForbid(staScene, scanMode), false); + } + + void AllowExternScanByForbidFail6() + { + int staScene = 0; + ScanMode scanMode = ScanMode::SYS_FOREGROUND_SCAN; + ScanForbidMode scanForbidMode; + scanForbidMode.scanScene = staScene; + scanForbidMode.scanMode = ScanMode::ALL_EXTERN_SCAN; + scanForbidMode.forbidTime = 0; + scanForbidMode.forbidCount = 0; + pScanService->scanControlInfo.scanForbidList.push_back(scanForbidMode); + EXPECT_EQ(pScanService->AllowExternScanByForbid(staScene, scanMode), false); + } + + void AllowExternScanByForbidFail7() + { + int staScene = 0; + ScanMode scanMode = ScanMode::SYS_FOREGROUND_SCAN; + time_t now = time(nullptr); + if (now < 0) { + return; + } + pScanService->customSceneTimeMap.emplace(staScene, now); + ScanForbidMode scanForbidMode; + scanForbidMode.scanScene = staScene; + scanForbidMode.scanMode = scanMode; + scanForbidMode.forbidTime = 0; + scanForbidMode.forbidCount = 0; + pScanService->scanControlInfo.scanForbidList.push_back(scanForbidMode); + EXPECT_EQ(pScanService->AllowExternScanByForbid(staScene, scanMode), false); + } + + void AllowExternScanByForbidFail8() + { + int staScene = 0; + ScanMode scanMode = ScanMode::SYS_FOREGROUND_SCAN; + time_t now = time(nullptr); + if (now < 0) { + return; + } + pScanService->customSceneTimeMap.emplace(staScene, now); + ScanForbidMode scanForbidMode; + scanForbidMode.scanScene = staScene; + scanForbidMode.scanMode = ScanMode::ALL_EXTERN_SCAN; + scanForbidMode.forbidTime = 0; + scanForbidMode.forbidCount = 0; + pScanService->scanControlInfo.scanForbidList.push_back(scanForbidMode); + EXPECT_EQ(pScanService->AllowExternScanByForbid(staScene, scanMode), false); + } + void AllowExternScanByIntervaluccess() { pScanService->AllowExternScanByInterval(0, 0, ScanMode::SYS_FOREGROUND_SCAN); @@ -777,10 +857,14 @@ public: void GetStaSceneSuccess5() { + pScanService->staStatus = static_cast(OperateResState::CONNECT_ASSOCIATING); + EXPECT_EQ(SCAN_SCENE_ASSOCIATING, pScanService->GetStaScene()); } void GetStaSceneSuccess6() { + pScanService->staStatus = static_cast(OperateResState::CONNECT_ASSOCIATED); + EXPECT_EQ(SCAN_SCENE_ASSOCIATED, pScanService->GetStaScene()); } void GetStaSceneFail() @@ -925,28 +1009,159 @@ public: EXPECT_EQ(pScanService->AllowScanDuringScanning(scanMode), true); } + void AllowScanDuringScanningFail() + { + ScanMode scanMode = ScanMode::SYS_FOREGROUND_SCAN; + ScanForbidMode forbidMode; + forbidMode.scanScene = SCAN_SCENE_SCANNING; + forbidMode.scanMode = scanMode; + pScanService->scanControlInfo.scanForbidList.push_back(forbidMode); + EXPECT_EQ(pScanService->AllowScanDuringScanning(scanMode), false); + } + void AllowScanDuringScreenOffSuccess() { ScanMode scanMode = ScanMode::SYS_FOREGROUND_SCAN; EXPECT_EQ(pScanService->AllowScanDuringScreenOff(scanMode), true); } + void AllowScanDuringScreenOffFail1() + { + ScanMode scanMode = ScanMode::SYS_FOREGROUND_SCAN; + ScanForbidMode forbidMode; + forbidMode.scanScene = SCAN_SCENE_SCREEN_OFF; + forbidMode.scanMode = scanMode; + pScanService->scanControlInfo.scanForbidList.push_back(forbidMode); + + EXPECT_EQ(pScanService->AllowScanDuringScreenOff(scanMode), false); + } + void AllowScanDuringStaSceneSuccess1() { const int staScene = 0; ScanMode scanMode = ScanMode::SYS_FOREGROUND_SCAN; + ScanForbidMode scanForbidMode; + scanForbidMode.scanScene = staScene; + scanForbidMode.scanMode = scanMode; + scanForbidMode.forbidTime = 1; + scanForbidMode.forbidCount = 1; + pScanService->staSceneForbidCount = 1; time_t nowTime = time(nullptr); const int timeForTest = 2; pScanService->staCurrentTime = nowTime - timeForTest; + pScanService->scanControlInfo.scanForbidList.push_back(scanForbidMode); EXPECT_EQ(pScanService->AllowScanDuringStaScene(staScene, scanMode), true); } + void AllowScanDuringStaSceneFail1() + { + const int staScene = 0; + ScanMode scanMode = ScanMode::SYS_FOREGROUND_SCAN; + ScanForbidMode scanForbidMode; + scanForbidMode.scanScene = staScene; + scanForbidMode.scanMode = scanMode; + scanForbidMode.forbidTime = 0; + scanForbidMode.forbidCount = 0; + pScanService->scanControlInfo.scanForbidList.push_back(scanForbidMode); + EXPECT_EQ(pScanService->AllowScanDuringStaScene(staScene, scanMode), false); + } + + void AllowScanDuringStaSceneFail2() + { + const int staScene = 0; + ScanMode scanMode = ScanMode::SYS_FOREGROUND_SCAN; + ScanForbidMode scanForbidMode; + scanForbidMode.scanScene = staScene; + scanForbidMode.scanMode = scanMode; + scanForbidMode.forbidTime = 1; + scanForbidMode.forbidCount = 1; + pScanService->staSceneForbidCount = 0; + pScanService->scanControlInfo.scanForbidList.push_back(scanForbidMode); + EXPECT_EQ(pScanService->AllowScanDuringStaScene(staScene, scanMode), false); + } + + void AllowScanDuringStaSceneFail3() + { + const int staScene = 0; + ScanMode scanMode = ScanMode::SYS_FOREGROUND_SCAN; + ScanForbidMode scanForbidMode; + scanForbidMode.scanScene = staScene; + scanForbidMode.scanMode = scanMode; + scanForbidMode.forbidTime = 1; + scanForbidMode.forbidCount = 1; + pScanService->staSceneForbidCount = 1; + pScanService->staSceneForbidCount = 1; + time_t nowTime = time(nullptr); + const int timeForTest = 2; + pScanService->staCurrentTime = nowTime + timeForTest; + pScanService->scanControlInfo.scanForbidList.push_back(scanForbidMode); + EXPECT_EQ(pScanService->AllowScanDuringStaScene(staScene, scanMode), false); + } + void AllowScanDuringCustomSceneSuccess() { ScanMode scanMode = ScanMode::SYS_FOREGROUND_SCAN; EXPECT_EQ(pScanService->AllowScanDuringCustomScene(scanMode), true); } + void AllowScanDuringCustomSceneFail1() + { + const int staScene = 0; + ScanMode scanMode = ScanMode::SYS_FOREGROUND_SCAN; + time_t now = time(nullptr); + if (now < 0) { + return; + } + pScanService->customSceneTimeMap.emplace(staScene, now); + ScanForbidMode scanForbidMode; + scanForbidMode.scanScene = staScene; + scanForbidMode.scanMode = scanMode; + scanForbidMode.forbidTime = 0; + scanForbidMode.forbidCount = 0; + pScanService->scanControlInfo.scanForbidList.push_back(scanForbidMode); + EXPECT_EQ(pScanService->AllowScanDuringCustomScene(scanMode), false); + } + + void AllowScanDuringCustomSceneFail2() + { + const int staScene = 0; + ScanMode scanMode = ScanMode::SYS_FOREGROUND_SCAN; + time_t now = time(nullptr); + if (now < 0) { + return; + } + pScanService->customSceneTimeMap.emplace(staScene, now); + ScanForbidMode scanForbidMode; + scanForbidMode.scanScene = staScene; + scanForbidMode.scanMode = scanMode; + scanForbidMode.forbidTime = 1; + scanForbidMode.forbidCount = 1; + pScanService->staSceneForbidCount = 0; + pScanService->scanControlInfo.scanForbidList.push_back(scanForbidMode); + EXPECT_EQ(pScanService->AllowScanDuringCustomScene(scanMode), false); + } + + void AllowScanDuringCustomSceneFail3() + { + const int staScene = 0; + ScanMode scanMode = ScanMode::SYS_FOREGROUND_SCAN; + time_t now = time(nullptr); + if (now < 0) { + return; + } + pScanService->customSceneTimeMap.emplace(staScene, now); + ScanForbidMode scanForbidMode; + scanForbidMode.scanScene = staScene; + scanForbidMode.scanMode = scanMode; + scanForbidMode.forbidTime = 1; + scanForbidMode.forbidCount = 1; + time_t nowTime = time(nullptr); + const int timeForTest = 2; + pScanService->staCurrentTime = nowTime + timeForTest; + pScanService->scanControlInfo.scanForbidList.push_back(scanForbidMode); + EXPECT_EQ(pScanService->AllowScanDuringCustomScene(scanMode), false); + } + void AllowExternScanByIntervalMode() { pScanService->AllowExternScanByIntervalMode(0, 0, ScanMode::SYS_FOREGROUND_SCAN); @@ -1049,6 +1264,7 @@ public: int appId = 0; SingleAppForbid sAppForbid; sAppForbid.appID = appId; + sAppForbid.scanIntervalMode.scanScene = SCAN_SCENE_ALL; sAppForbid.scanIntervalMode.scanMode = ScanMode::SCAN_MODE_MAX; pScanService->appForbidList.push_back(sAppForbid); ScanIntervalMode scanIntervalMode = sAppForbid.scanIntervalMode; @@ -1060,6 +1276,7 @@ public: int appId = 0; SingleAppForbid sAppForbid; sAppForbid.appID = appId; + sAppForbid.scanIntervalMode.scanScene = SCAN_SCENE_ALL; sAppForbid.scanIntervalMode.scanMode = ScanMode::SCAN_MODE_MAX; sAppForbid.fixedScanCount = 1; @@ -1087,6 +1304,7 @@ public: int appId = 0; SingleAppForbid sAppForbid; sAppForbid.appID = appId; + sAppForbid.scanIntervalMode.scanScene = SCAN_SCENE_ALL; sAppForbid.scanIntervalMode.scanMode = ScanMode::SCAN_MODE_MAX; pScanService->fullAppForbidList.push_back(sAppForbid); ScanIntervalMode scanIntervalMode = sAppForbid.scanIntervalMode; @@ -1098,6 +1316,7 @@ public: int appId = 0; SingleAppForbid sAppForbid; sAppForbid.appID = appId; + sAppForbid.scanIntervalMode.scanScene = SCAN_SCENE_ALL; sAppForbid.scanIntervalMode.scanMode = ScanMode::SCAN_MODE_MAX; sAppForbid.fixedScanCount = 1; @@ -1230,9 +1449,8 @@ public: int count = 0; pScanService->scanBlocklist.push_back(appId); pScanService->scanBlocklist.push_back(1); - // blockListScanTime now; branch. - bool rlt = pScanService->AllowScanByIntervalBlocklist(appId, blockListScanTime, lessThanIntervalCount, interval, - count); + bool rlt = pScanService->AllowScanByIntervalBlocklist( + appId, blockListScanTime, lessThanIntervalCount, interval, count); EXPECT_EQ(rlt, true); } @@ -1246,9 +1464,8 @@ public: int lessThanIntervalCount = 0; int interval = time(nullptr) + timeTest; int count = 0; - // if blockListScanTime 0 branch. - bool rlt = pScanService->AllowScanByIntervalBlocklist(appId, blockListScanTime, lessThanIntervalCount, interval, - count); + bool rlt = pScanService->AllowScanByIntervalBlocklist( + appId, blockListScanTime, lessThanIntervalCount, interval, count); EXPECT_EQ(rlt, true); } @@ -1262,9 +1479,8 @@ public: int interval = intervalTest; const int countTest = 2; int count = countTest; - // if lessThanIntervalCount count branch. - bool rlt = pScanService->AllowScanByIntervalBlocklist(appId, blockListScanTime, lessThanIntervalCount, interval, - count); + bool rlt = pScanService->AllowScanByIntervalBlocklist( + appId, blockListScanTime, lessThanIntervalCount, interval, count); EXPECT_EQ(rlt, true); } @@ -1278,9 +1494,8 @@ public: int interval = intervalTest; int count = 0; pScanService->scanBlocklist.push_back(appId); - // if find scanBlocklist.begin() branch. - bool rlt = pScanService->AllowScanByIntervalBlocklist(appId, blockListScanTime, lessThanIntervalCount, interval, - count); + bool rlt = pScanService->AllowScanByIntervalBlocklist( + appId, blockListScanTime, lessThanIntervalCount, interval, count); EXPECT_EQ(rlt, false); } @@ -1293,9 +1508,8 @@ public: const int intervalTest = 10; int interval = intervalTest; int count = 0; - // scanBlocklist (appId) branch. - bool rlt = pScanService->AllowScanByIntervalBlocklist(appId, blockListScanTime, lessThanIntervalCount, interval, - count); + bool rlt = pScanService->AllowScanByIntervalBlocklist( + appId, blockListScanTime, lessThanIntervalCount, interval, count); EXPECT_EQ(rlt, false); } }; @@ -1665,64 +1879,69 @@ HWTEST_F(ScanServiceTest, GetScanControlInfoFail, TestSize.Level1) GetScanControlInfoFail(); } -HWTEST_F(ScanServiceTest, GetScreenStateSuccess, TestSize.Level1) +HWTEST_F(ScanServiceTest, AllowExternScanSuccess, TestSize.Level1) { - GetScreenStateSuccess(); + AllowExternScanSuccess(); } -HWTEST_F(ScanServiceTest, SetOperateAppModeSuccess, TestSize.Level1) +HWTEST_F(ScanServiceTest, AllowExternScanFail1, TestSize.Level1) { - SetOperateAppModeSuccess(); + AllowExternScanFail1(); } -HWTEST_F(ScanServiceTest, GetOperateAppModeSuccess1, TestSize.Level1) +HWTEST_F(ScanServiceTest, AllowSystemTimerScanSuccess, TestSize.Level1) { - GetOperateAppModeSuccess1(); + AllowSystemTimerScanSuccess(); } -HWTEST_F(ScanServiceTest, GetOperateAppModeSuccess2, TestSize.Level1) +HWTEST_F(ScanServiceTest, AllowPnoScanSuccess, TestSize.Level1) { - GetOperateAppModeSuccess2(); + AllowPnoScanSuccess(); } -HWTEST_F(ScanServiceTest, GetOperateAppModeSuccess3, TestSize.Level1) +HWTEST_F(ScanServiceTest, AllowExternScanByForbidSuccess1, TestSize.Level1) { - GetOperateAppModeSuccess3(); + AllowExternScanByForbidSuccess1(); } -HWTEST_F(ScanServiceTest, GetOperateAppModeSuccess4, TestSize.Level1) +HWTEST_F(ScanServiceTest, AllowExternScanByForbidFail1, TestSize.Level1) { - GetOperateAppModeSuccess4(); + AllowExternScanByForbidFail1(); } -HWTEST_F(ScanServiceTest, GetOperateAppModeFail, TestSize.Level1) +HWTEST_F(ScanServiceTest, AllowExternScanByForbidFail2, TestSize.Level1) { - GetOperateAppModeFail(); + AllowExternScanByForbidFail2(); } -HWTEST_F(ScanServiceTest, AllowExternScanSuccess, TestSize.Level1) +HWTEST_F(ScanServiceTest, AllowExternScanByForbidFail3, TestSize.Level1) { - AllowExternScanSuccess(); + AllowExternScanByForbidFail3(); } -HWTEST_F(ScanServiceTest, AllowExternScanFail1, TestSize.Level1) +HWTEST_F(ScanServiceTest, AllowExternScanByForbidFail4, TestSize.Level1) { - AllowExternScanFail1(); + AllowExternScanByForbidFail4(); } -HWTEST_F(ScanServiceTest, AllowSystemTimerScanSuccess, TestSize.Level1) +HWTEST_F(ScanServiceTest, AllowExternScanByForbidFail5, TestSize.Level1) { - AllowSystemTimerScanSuccess(); + AllowExternScanByForbidFail5(); } -HWTEST_F(ScanServiceTest, AllowPnoScanSuccess, TestSize.Level1) +HWTEST_F(ScanServiceTest, AllowExternScanByForbidFail6, TestSize.Level1) { - AllowPnoScanSuccess(); + AllowExternScanByForbidFail6(); } -HWTEST_F(ScanServiceTest, AllowExternScanByForbidSuccess1, TestSize.Level1) +HWTEST_F(ScanServiceTest, AllowExternScanByForbidFail7, TestSize.Level1) { - AllowExternScanByForbidSuccess1(); + AllowExternScanByForbidFail7(); +} + +HWTEST_F(ScanServiceTest, AllowExternScanByForbidFail8, TestSize.Level1) +{ + AllowExternScanByForbidFail8(); } HWTEST_F(ScanServiceTest, AllowExternScanByIntervaluccess, TestSize.Level1) @@ -1865,21 +2084,61 @@ HWTEST_F(ScanServiceTest, AllowScanDuringScanningSuccess, TestSize.Level1) AllowScanDuringScanningSuccess(); } +HWTEST_F(ScanServiceTest, AllowScanDuringScanningFail, TestSize.Level1) +{ + AllowScanDuringScanningFail(); +} + HWTEST_F(ScanServiceTest, AllowScanDuringScreenOffSuccess, TestSize.Level1) { AllowScanDuringScreenOffSuccess(); } +HWTEST_F(ScanServiceTest, AllowScanDuringScreenOffFail1, TestSize.Level1) +{ + AllowScanDuringScreenOffFail1(); +} + HWTEST_F(ScanServiceTest, AllowScanDuringStaSceneSuccess, TestSize.Level1) { AllowScanDuringStaSceneSuccess1(); } +HWTEST_F(ScanServiceTest, AllowScanDuringStaSceneFail1, TestSize.Level1) +{ + AllowScanDuringStaSceneFail1(); +} + +HWTEST_F(ScanServiceTest, AllowScanDuringStaSceneFail2, TestSize.Level1) +{ + AllowScanDuringStaSceneFail2(); +} + +HWTEST_F(ScanServiceTest, AllowScanDuringStaSceneFail3, TestSize.Level1) +{ + AllowScanDuringStaSceneFail3(); +} + HWTEST_F(ScanServiceTest, AllowScanDuringCustomSceneSuccess, TestSize.Level1) { AllowScanDuringCustomSceneSuccess(); } +HWTEST_F(ScanServiceTest, AllowScanDuringCustomSceneFail1, TestSize.Level1) +{ + AllowScanDuringCustomSceneFail1(); +} + +HWTEST_F(ScanServiceTest, AllowScanDuringCustomSceneFail2, TestSize.Level1) +{ + AllowScanDuringCustomSceneFail2(); +} + +HWTEST_F(ScanServiceTest, AllowScanDuringCustomSceneFail3, TestSize.Level1) +{ + AllowScanDuringCustomSceneFail3(); +} + HWTEST_F(ScanServiceTest, AllowExternScanByIntervalMode, TestSize.Level1) { AllowExternScanByIntervalMode(); diff --git a/tests/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_state_machine_test.cpp b/tests/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_state_machine_test.cpp index 0d5575883eab8455392d4b40d0cc2699b13678dc..46e6e0359f1b418214b015b867b0ead51e82ddcd 100644 --- a/tests/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_state_machine_test.cpp +++ b/tests/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_state_machine_test.cpp @@ -1222,6 +1222,7 @@ public: EXPECT_CALL(WifiSettings::GetInstance(), GetIpInfo(_)) .WillRepeatedly(DoAll(SetArgReferee<0>(ipInfo), Return(0))); EXPECT_CALL(WifiSettings::GetInstance(), SaveLinkedInfo(_)).Times(AtLeast(0)); + EXPECT_CALL(WifiSettings::GetInstance(), GetStrDnsBak()).Times(AtLeast(0)); std::string ifname = "wlan0"; DhcpResult result;