diff --git a/wifi/bundle.json b/wifi/bundle.json index e87cce3d0b5fb0c1153820acfdc1d04e22aeed8c..627e5241e08153dc989379866a3dc1d4ecf08498 100644 --- a/wifi/bundle.json +++ b/wifi/bundle.json @@ -50,7 +50,8 @@ "wifi_feature_with_ap_num", "wifi_feature_with_auth_disable", "wifi_feature_with_dhcp_disable", - "wifi_feature_is_hdi_supported" + "wifi_feature_is_hdi_supported", + "wifi_feature_with_sched_scan_control_enable" ], "adapted_system_type": [ "standard" diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/BUILD.gn b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/BUILD.gn index 571543e457694a8ae881f28bf83f3062f6c85627..28d74cb8e5e680df6843bc67dac61d3f446fead5 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/BUILD.gn +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/BUILD.gn @@ -48,6 +48,7 @@ local_base_include_dirs = [ "$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/net_conf", "$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta", "$WIFI_ROOT_DIR/services/wifi_standard/include", + "//foundation/communication/wifi/wifi/utils/inc", ] if (defined(ohos_lite)) { @@ -92,12 +93,21 @@ if (defined(ohos_lite)) { deps = [ "$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage/idl_client:wifi_idl_client", "$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_toolkit:wifi_toolkit", + "$WIFI_ROOT_DIR/utils:wifi_utils", ] external_deps = [ "c_utils:utils", "hiviewdfx_hilog_native:libhilog", ] + + defines = [] + if (wifi_feature_with_sched_scan_control_enable) { + include_dirs += [ "//foundation/resourceschedule/efficiency_manager/interfaces/innerkits/component_scheduler/client/include" ] + external_deps += [ "efficiency_manager:component_sched_client" ] + defines += [ "WIFI_SCHED_SCAN_CONTROL_ENALE" ] + } + cflags_cc = [ "-std=c++17", "-fno-rtti", diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_service.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_service.cpp index e87805800cb012b6f3e205b6dfe2e06481f1dea2..c984252ef18f18635b434c279909fba1bacd43a4 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_service.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_service.cpp @@ -21,6 +21,11 @@ #include "wifi_logger.h" #include "wifi_settings.h" #include "wifi_sta_hal_interface.h" +#include "wifi_common_util.h" +#ifdef WIFI_SCHED_SCAN_CONTROL_ENALE +#include "scan_strategy.h" +#include "component_sched_client.h" +#endif DEFINE_WIFILOG_SCAN_LABEL("ScanService"); @@ -45,7 +50,8 @@ ScanService::ScanService() scanTrustMode(false), isAbsFreezeState(false), isAbsFreezeScaned(false), - scanResultBackup(-1) + scanResultBackup(-1), + lastScanResultsAvailableTime(0) {} ScanService::~ScanService() @@ -555,6 +561,10 @@ void ScanService::HandleCommonScanInfo( } } + struct timespec times = {0, 0}; + clock_gettime(CLOCK_MONOTONIC, ×); + lastScanResultsAvailableTime = static_cast(times.tv_sec) * SECOND_TO_MICRO_SECOND + + times.tv_nsec / SECOND_TO_MILLI_SECOND; /* Send the scanning result to the module registered for listening. */ ScanInfoHandlerMap::iterator handleIter = scanInfoHandlerMap.begin(); for (; handleIter != scanInfoHandlerMap.end(); ++handleIter) { @@ -1119,6 +1129,10 @@ ErrCode ScanService::AllowExternScan() WIFI_LOGW("extern scan not allow by disable scan control."); return WIFI_OPT_FAILED; } + if (!AllowScanBySchedStrategy()) { + WIFI_LOGW("extern scan not allow by sched strategy."); + return WIFI_OPT_FAILED; + } WIFI_LOGI("extern scan has allowed"); return WIFI_OPT_SUCCESS; @@ -2175,6 +2189,45 @@ bool ScanService::AllowScanByDisableScanCtrl() return !disableScanFlag; } +bool ScanService::AllowScanBySchedStrategy() +{ + WIFI_LOGI("Enter ScanService::AllowScanBySchedStrategy."); +#ifdef WIFI_SCHED_SCAN_CONTROL_ENALE + sptr strategy = nullptr; + int ret = OHOS::ComponentScheduler::ComponentSchedClient::GetInstance().GetScanStrategy(GetBundleName(), + GetCallingUid(), ComponentScheduler::ScanStrategy::ScanType::SCAN_TYPE_WIFI, strategy); + if (ret != 0 || strategy == nullptr) { + WIFI_LOGW("GetScanStrategy fail: %{public}d.", ret); + return true; + } + + WIFI_LOGI("GetScanStrategy return mode: %{public}d.", strategy->GetMode()); + if (strategy->GetMode() == 0) { + return true; + } + + if (strategy->GetMode() < 0) { + WIFI_LOGE("ComponentSchedClient don't allow scan."); + return false; + } + + if (strategy->GetTimeStamp() < lastScanResultsAvailableTime) { + struct timespec times = {0, 0}; + clock_gettime(CLOCK_MONOTONIC, ×); + int64_t currTime = + static_cast(times.tv_sec) * SECOND_TO_MICRO_SECOND + times.tv_nsec / SECOND_TO_MILLI_SECOND; + int64_t sinceLastScanTime = currTime - lastScanResultsAvailableTime; + if (sinceLastScanTime > strategy->GetMode()) { + return true; + } + WIFI_LOGE("sinceLastScanTime:%{public}llu is less than GetMode:%{public}d, don't allow scan.", + sinceLastScanTime, strategy->GetMode()); + return false; + } +#endif + return true; +} + bool ScanService::AllowScanByMovingFreeze() { LOGI("Enter ScanService::AllowScanByMovingFreeze.\n"); diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_service.h b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_service.h index 7a02b67c4e68f18190663a24626cc94afbe9eba0..44a8946013ed27bfa8f5164bf6d10a78313d55b4 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_service.h +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_service.h @@ -229,6 +229,7 @@ private: bool isAbsFreezeState; /* absolute freeze state. */ bool isAbsFreezeScaned; /* scanned in freeze state. */ int scanResultBackup; /* scan result backup. */ + int64_t lastScanResultsAvailableTime; /* scan results available time */ /** * @Description Obtains the frequency of a specified band. @@ -699,6 +700,13 @@ private: */ bool AllowScanByDisableScanCtrl(); + /** + * @Description Determines whether scanning is allowed by sched strategy scan control. + * + * @return true: allow, false: not allowed. + */ + bool AllowScanBySchedStrategy(); + /** * @Description Determines whether scanning is allowed in movingfreeze mode. * diff --git a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_scan/BUILD.gn b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_scan/BUILD.gn index e3cf04fa0d132cf12e5be8b7433b514fe7fa7a20..df0d3d3e8587cda586ebaeb4f060da0cf39e921f 100644 --- a/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_scan/BUILD.gn +++ b/wifi/test/wifi_standard/wifi_framework/wifi_manage/wifi_scan/BUILD.gn @@ -77,6 +77,7 @@ ohos_unittest("wifi_scan_unittest") { "//third_party/googletest/googlemock/include", "//third_party/googletest/googletest/include", "$WIFI_ROOT_DIR/services/wifi_standard/include", + "//foundation/communication/wifi/wifi/utils/inc", ] deps = [ "$WIFI_ROOT_DIR/services/wifi_standard/wifi_framework/wifi_manage:wifi_manager_service", diff --git a/wifi/wifi.gni b/wifi/wifi.gni index 5ffdbcf359746787c0f3640078e87a53f80b0b6c..223c18fd1541879e9ab6dfe6398d41e224648b73 100644 --- a/wifi/wifi.gni +++ b/wifi/wifi.gni @@ -23,4 +23,5 @@ declare_args() { wifi_feature_with_auth_disable = false wifi_feature_with_dhcp_disable = false wifi_feature_is_hdi_supported = false + wifi_feature_with_sched_scan_control_enable = false } diff --git a/wifi/wifi_lite.gni b/wifi/wifi_lite.gni index 3dd85109dcc12face87470130396809174d9bf01..7f40a4faf874cac2a14c8257a2f39769375be755 100644 --- a/wifi/wifi_lite.gni +++ b/wifi/wifi_lite.gni @@ -26,4 +26,5 @@ declare_args() { wifi_feature_with_auth_disable = false wifi_feature_with_dhcp_disable = false wifi_feature_is_hdi_supported = false + wifi_feature_with_sched_scan_control_enable = false }