diff options
author | Ningyuan Wang | 2017-08-01 22:59:09 -0500 |
---|---|---|
committer | android-build-merger | 2017-08-01 22:59:09 -0500 |
commit | 3579413d25b46ea0c4ec0d647cfba561b7389b83 (patch) | |
tree | 3eff1f8dc89d997244abd7ab0e19fd66727612f6 | |
parent | dd4c84a8d7aa08ff8de4f302a95dee650bfb4efe (diff) | |
parent | dfbe7e4e12824527fac840391f31d2b4a4578e3e (diff) | |
download | system-connectivity-wificond-3579413d25b46ea0c4ec0d647cfba561b7389b83.tar.gz system-connectivity-wificond-3579413d25b46ea0c4ec0d647cfba561b7389b83.tar.xz system-connectivity-wificond-3579413d25b46ea0c4ec0d647cfba561b7389b83.zip |
Support scan plan attribute for scheduled scan
am: dfbe7e4e12
Change-Id: Ie95cfb7746db96a64dab898a55edccabb34d75cc
-rw-r--r-- | scanning/pno_settings.cpp | 3 | ||||
-rw-r--r-- | scanning/pno_settings.h | 3 | ||||
-rw-r--r-- | scanning/scan_utils.cpp | 32 | ||||
-rw-r--r-- | scanning/scan_utils.h | 13 | ||||
-rw-r--r-- | scanning/scanner_impl.cpp | 31 | ||||
-rw-r--r-- | scanning/scanner_impl.h | 5 | ||||
-rw-r--r-- | tests/mock_scan_utils.h | 2 | ||||
-rw-r--r-- | tests/scan_utils_unittest.cpp | 51 | ||||
-rw-r--r-- | tests/scanner_unittest.cpp | 81 |
9 files changed, 211 insertions, 10 deletions
diff --git a/scanning/pno_settings.cpp b/scanning/pno_settings.cpp index c8b5ff6..be051dd 100644 --- a/scanning/pno_settings.cpp +++ b/scanning/pno_settings.cpp | |||
@@ -28,6 +28,9 @@ namespace server { | |||
28 | namespace wifi { | 28 | namespace wifi { |
29 | namespace wificond { | 29 | namespace wificond { |
30 | 30 | ||
31 | const uint32_t PnoSettings::kFastScanIterations = 3; | ||
32 | const uint32_t PnoSettings::kSlowScanIntervalMultiplier = 3; | ||
33 | |||
31 | status_t PnoSettings::writeToParcel(::android::Parcel* parcel) const { | 34 | status_t PnoSettings::writeToParcel(::android::Parcel* parcel) const { |
32 | RETURN_IF_FAILED(parcel->writeInt32(interval_ms_)); | 35 | RETURN_IF_FAILED(parcel->writeInt32(interval_ms_)); |
33 | RETURN_IF_FAILED(parcel->writeInt32(min_2g_rssi_)); | 36 | RETURN_IF_FAILED(parcel->writeInt32(min_2g_rssi_)); |
diff --git a/scanning/pno_settings.h b/scanning/pno_settings.h index e236ec8..a606b0f 100644 --- a/scanning/pno_settings.h +++ b/scanning/pno_settings.h | |||
@@ -32,6 +32,9 @@ namespace wificond { | |||
32 | 32 | ||
33 | class PnoSettings : public ::android::Parcelable { | 33 | class PnoSettings : public ::android::Parcelable { |
34 | public: | 34 | public: |
35 | static const uint32_t kFastScanIterations; | ||
36 | static const uint32_t kSlowScanIntervalMultiplier; | ||
37 | |||
35 | PnoSettings() | 38 | PnoSettings() |
36 | : interval_ms_(0), | 39 | : interval_ms_(0), |
37 | min_2g_rssi_(0), | 40 | min_2g_rssi_(0), |
diff --git a/scanning/scan_utils.cpp b/scanning/scan_utils.cpp index 5f0a6e3..dfd051c 100644 --- a/scanning/scan_utils.cpp +++ b/scanning/scan_utils.cpp | |||
@@ -36,6 +36,7 @@ namespace wificond { | |||
36 | namespace { | 36 | namespace { |
37 | 37 | ||
38 | constexpr uint8_t kElemIdSsid = 0; | 38 | constexpr uint8_t kElemIdSsid = 0; |
39 | constexpr unsigned int kMsecPerSec = 1000; | ||
39 | 40 | ||
40 | } // namespace | 41 | } // namespace |
41 | 42 | ||
@@ -348,7 +349,7 @@ bool ScanUtils::AbortScan(uint32_t interface_index) { | |||
348 | 349 | ||
349 | bool ScanUtils::StartScheduledScan( | 350 | bool ScanUtils::StartScheduledScan( |
350 | uint32_t interface_index, | 351 | uint32_t interface_index, |
351 | uint32_t interval_ms, | 352 | const SchedScanIntervalSetting& interval_setting, |
352 | int32_t rssi_threshold, | 353 | int32_t rssi_threshold, |
353 | bool request_random_mac, | 354 | bool request_random_mac, |
354 | const std::vector<std::vector<uint8_t>>& scan_ssids, | 355 | const std::vector<std::vector<uint8_t>>& scan_ssids, |
@@ -385,6 +386,7 @@ bool ScanUtils::StartScheduledScan( | |||
385 | NL80211Attr<int32_t>(NL80211_SCHED_SCAN_MATCH_ATTR_RSSI, rssi_threshold)); | 386 | NL80211Attr<int32_t>(NL80211_SCHED_SCAN_MATCH_ATTR_RSSI, rssi_threshold)); |
386 | scan_match_attr.AddAttribute(match_group); | 387 | scan_match_attr.AddAttribute(match_group); |
387 | } | 388 | } |
389 | start_sched_scan.AddAttribute(scan_match_attr); | ||
388 | 390 | ||
389 | // Append all attributes to the NL80211_CMD_START_SCHED_SCAN packet. | 391 | // Append all attributes to the NL80211_CMD_START_SCHED_SCAN packet. |
390 | start_sched_scan.AddAttribute( | 392 | start_sched_scan.AddAttribute( |
@@ -395,9 +397,31 @@ bool ScanUtils::StartScheduledScan( | |||
395 | if (!freqs.empty()) { | 397 | if (!freqs.empty()) { |
396 | start_sched_scan.AddAttribute(freqs_attr); | 398 | start_sched_scan.AddAttribute(freqs_attr); |
397 | } | 399 | } |
398 | start_sched_scan.AddAttribute( | 400 | |
399 | NL80211Attr<uint32_t>(NL80211_ATTR_SCHED_SCAN_INTERVAL, interval_ms)); | 401 | if (!interval_setting.plans.empty()) { |
400 | start_sched_scan.AddAttribute(scan_match_attr); | 402 | NL80211NestedAttr scan_plans(NL80211_ATTR_SCHED_SCAN_PLANS); |
403 | for (unsigned int i = 0; i < interval_setting.plans.size(); i++) { | ||
404 | NL80211NestedAttr scan_plan(i + 1); | ||
405 | scan_plan.AddAttribute( | ||
406 | NL80211Attr<uint32_t>(NL80211_SCHED_SCAN_PLAN_INTERVAL, | ||
407 | interval_setting.plans[i].interval_ms / kMsecPerSec)); | ||
408 | scan_plan.AddAttribute( | ||
409 | NL80211Attr<uint32_t>(NL80211_SCHED_SCAN_PLAN_ITERATIONS, | ||
410 | interval_setting.plans[i].n_iterations)); | ||
411 | scan_plans.AddAttribute(scan_plan); | ||
412 | } | ||
413 | NL80211NestedAttr last_scan_plan(interval_setting.plans.size() + 1); | ||
414 | last_scan_plan.AddAttribute( | ||
415 | NL80211Attr<uint32_t>(NL80211_SCHED_SCAN_PLAN_INTERVAL, | ||
416 | interval_setting.final_interval_ms / kMsecPerSec)); | ||
417 | scan_plans.AddAttribute(last_scan_plan); | ||
418 | start_sched_scan.AddAttribute(scan_plans); | ||
419 | } else { | ||
420 | start_sched_scan.AddAttribute( | ||
421 | NL80211Attr<uint32_t>(NL80211_ATTR_SCHED_SCAN_INTERVAL, | ||
422 | interval_setting.final_interval_ms)); | ||
423 | } | ||
424 | |||
401 | if (request_random_mac) { | 425 | if (request_random_mac) { |
402 | start_sched_scan.AddAttribute( | 426 | start_sched_scan.AddAttribute( |
403 | NL80211Attr<uint32_t>(NL80211_ATTR_SCAN_FLAGS, | 427 | NL80211Attr<uint32_t>(NL80211_ATTR_SCAN_FLAGS, |
diff --git a/scanning/scan_utils.h b/scanning/scan_utils.h index dbc2556..87df13a 100644 --- a/scanning/scan_utils.h +++ b/scanning/scan_utils.h | |||
@@ -44,6 +44,17 @@ namespace wificond { | |||
44 | class NL80211NestedAttr; | 44 | class NL80211NestedAttr; |
45 | class NL80211Packet; | 45 | class NL80211Packet; |
46 | 46 | ||
47 | struct SchedScanIntervalSetting { | ||
48 | struct ScanPlan { | ||
49 | uint32_t interval_ms; | ||
50 | uint32_t n_iterations; | ||
51 | }; | ||
52 | std::vector<ScanPlan> plans; | ||
53 | // After |plans| has been exhausted, scan at every | ||
54 | // |final_interval_ms|. | ||
55 | uint32_t final_interval_ms{0}; | ||
56 | }; | ||
57 | |||
47 | // Provides scanning helper functions. | 58 | // Provides scanning helper functions. |
48 | class ScanUtils { | 59 | class ScanUtils { |
49 | public: | 60 | public: |
@@ -98,7 +109,7 @@ class ScanUtils { | |||
98 | // Returns true on success. | 109 | // Returns true on success. |
99 | virtual bool StartScheduledScan( | 110 | virtual bool StartScheduledScan( |
100 | uint32_t interface_index, | 111 | uint32_t interface_index, |
101 | uint32_t interval_ms, | 112 | const SchedScanIntervalSetting& interval_setting, |
102 | int32_t rssi_threshold, | 113 | int32_t rssi_threshold, |
103 | bool request_random_mac, | 114 | bool request_random_mac, |
104 | const std::vector<std::vector<uint8_t>>& scan_ssids, | 115 | const std::vector<std::vector<uint8_t>>& scan_ssids, |
diff --git a/scanning/scanner_impl.cpp b/scanning/scanner_impl.cpp index a1ea261..9bf13b3 100644 --- a/scanning/scanner_impl.cpp +++ b/scanning/scanner_impl.cpp | |||
@@ -35,6 +35,7 @@ using com::android::server::wifi::wificond::NativeScanResult; | |||
35 | using com::android::server::wifi::wificond::PnoSettings; | 35 | using com::android::server::wifi::wificond::PnoSettings; |
36 | using com::android::server::wifi::wificond::SingleScanSettings; | 36 | using com::android::server::wifi::wificond::SingleScanSettings; |
37 | 37 | ||
38 | using std::pair; | ||
38 | using std::string; | 39 | using std::string; |
39 | using std::vector; | 40 | using std::vector; |
40 | using std::weak_ptr; | 41 | using std::weak_ptr; |
@@ -305,7 +306,7 @@ bool ScannerImpl::StartPnoScanDefault(const PnoSettings& pno_settings) { | |||
305 | 306 | ||
306 | int error_code = 0; | 307 | int error_code = 0; |
307 | if (!scan_utils_->StartScheduledScan(interface_index_, | 308 | if (!scan_utils_->StartScheduledScan(interface_index_, |
308 | pno_settings.interval_ms_, | 309 | GenerateIntervalSetting(pno_settings), |
309 | // TODO: honor both rssi thresholds. | 310 | // TODO: honor both rssi thresholds. |
310 | pno_settings.min_5g_rssi_, | 311 | pno_settings.min_5g_rssi_, |
311 | request_random_mac, | 312 | request_random_mac, |
@@ -447,6 +448,34 @@ void ScannerImpl::OnSchedScanResultsReady(uint32_t interface_index, | |||
447 | } | 448 | } |
448 | } | 449 | } |
449 | 450 | ||
451 | SchedScanIntervalSetting ScannerImpl::GenerateIntervalSetting( | ||
452 | const ::com::android::server::wifi::wificond::PnoSettings& | ||
453 | pno_settings) const { | ||
454 | bool support_num_scan_plans = scan_capabilities_.max_num_scan_plans >= 2; | ||
455 | bool support_scan_plan_interval = | ||
456 | scan_capabilities_.max_scan_plan_interval * 1000 >= | ||
457 | pno_settings.interval_ms_ * PnoSettings::kSlowScanIntervalMultiplier; | ||
458 | bool support_scan_plan_iterations = | ||
459 | scan_capabilities_.max_scan_plan_iterations >= | ||
460 | PnoSettings::kFastScanIterations; | ||
461 | |||
462 | uint32_t fast_scan_interval = | ||
463 | static_cast<uint32_t>(pno_settings.interval_ms_); | ||
464 | if (support_num_scan_plans && support_scan_plan_interval && | ||
465 | support_scan_plan_iterations) { | ||
466 | return SchedScanIntervalSetting{ | ||
467 | {{fast_scan_interval, PnoSettings::kFastScanIterations}}, | ||
468 | fast_scan_interval * PnoSettings::kSlowScanIntervalMultiplier}; | ||
469 | } else { | ||
470 | // Device doesn't support the provided scan plans. | ||
471 | // Specify single interval instead. | ||
472 | // In this case, the driver/firmware is expected to implement back off | ||
473 | // logic internally using |pno_settings.interval_ms_| as "fast scan" | ||
474 | // interval. | ||
475 | return SchedScanIntervalSetting{{}, fast_scan_interval}; | ||
476 | } | ||
477 | } | ||
478 | |||
450 | void ScannerImpl::LogSsidList(vector<vector<uint8_t>>& ssid_list, | 479 | void ScannerImpl::LogSsidList(vector<vector<uint8_t>>& ssid_list, |
451 | string prefix) { | 480 | string prefix) { |
452 | if (ssid_list.empty()) { | 481 | if (ssid_list.empty()) { |
diff --git a/scanning/scanner_impl.h b/scanning/scanner_impl.h index fe66f17..2bb9262 100644 --- a/scanning/scanner_impl.h +++ b/scanning/scanner_impl.h | |||
@@ -25,13 +25,13 @@ | |||
25 | #include "android/net/wifi/BnWifiScannerImpl.h" | 25 | #include "android/net/wifi/BnWifiScannerImpl.h" |
26 | #include "wificond/net/netlink_utils.h" | 26 | #include "wificond/net/netlink_utils.h" |
27 | #include "wificond/scanning/offload/offload_scan_manager.h" | 27 | #include "wificond/scanning/offload/offload_scan_manager.h" |
28 | #include "wificond/scanning/scan_utils.h" | ||
28 | 29 | ||
29 | namespace android { | 30 | namespace android { |
30 | namespace wificond { | 31 | namespace wificond { |
31 | 32 | ||
32 | class ClientInterfaceImpl; | 33 | class ClientInterfaceImpl; |
33 | class OffloadServiceUtils; | 34 | class OffloadServiceUtils; |
34 | class ScanUtils; | ||
35 | 35 | ||
36 | class ScannerImpl : public android::net::wifi::BnWifiScannerImpl { | 36 | class ScannerImpl : public android::net::wifi::BnWifiScannerImpl { |
37 | public: | 37 | public: |
@@ -99,6 +99,9 @@ class ScannerImpl : public android::net::wifi::BnWifiScannerImpl { | |||
99 | std::vector<std::vector<uint8_t>>* match_ssids, | 99 | std::vector<std::vector<uint8_t>>* match_ssids, |
100 | std::vector<uint32_t>* freqs, | 100 | std::vector<uint32_t>* freqs, |
101 | std::vector<uint8_t>* match_security); | 101 | std::vector<uint8_t>* match_security); |
102 | SchedScanIntervalSetting GenerateIntervalSetting( | ||
103 | const ::com::android::server::wifi::wificond::PnoSettings& pno_settings) const; | ||
104 | |||
102 | // Boolean variables describing current scanner status. | 105 | // Boolean variables describing current scanner status. |
103 | bool valid_; | 106 | bool valid_; |
104 | bool scan_started_; | 107 | bool scan_started_; |
diff --git a/tests/mock_scan_utils.h b/tests/mock_scan_utils.h index f3e1777..3e5cc7f 100644 --- a/tests/mock_scan_utils.h +++ b/tests/mock_scan_utils.h | |||
@@ -50,7 +50,7 @@ class MockScanUtils : public ScanUtils { | |||
50 | 50 | ||
51 | MOCK_METHOD8(StartScheduledScan, bool( | 51 | MOCK_METHOD8(StartScheduledScan, bool( |
52 | uint32_t interface_index, | 52 | uint32_t interface_index, |
53 | uint32_t interval_ms, | 53 | const SchedScanIntervalSetting& interval_setting, |
54 | int32_t rssi_threshold, | 54 | int32_t rssi_threshold, |
55 | bool request_random_mac, | 55 | bool request_random_mac, |
56 | const std::vector<std::vector<uint8_t>>& scan_ssids, | 56 | const std::vector<std::vector<uint8_t>>& scan_ssids, |
diff --git a/tests/scan_utils_unittest.cpp b/tests/scan_utils_unittest.cpp index 9e36ab2..28ea283 100644 --- a/tests/scan_utils_unittest.cpp +++ b/tests/scan_utils_unittest.cpp | |||
@@ -32,8 +32,10 @@ using std::placeholders::_1; | |||
32 | using std::placeholders::_2; | 32 | using std::placeholders::_2; |
33 | using std::unique_ptr; | 33 | using std::unique_ptr; |
34 | using std::vector; | 34 | using std::vector; |
35 | using testing::AllOf; | ||
35 | using testing::Invoke; | 36 | using testing::Invoke; |
36 | using testing::NiceMock; | 37 | using testing::NiceMock; |
38 | using testing::Not; | ||
37 | using testing::Return; | 39 | using testing::Return; |
38 | using testing::_; | 40 | using testing::_; |
39 | 41 | ||
@@ -106,6 +108,11 @@ MATCHER_P(DoesNL80211PacketMatchCommand, command, | |||
106 | return arg.GetCommand() == command; | 108 | return arg.GetCommand() == command; |
107 | } | 109 | } |
108 | 110 | ||
111 | MATCHER_P(DoesNL80211PacketHaveAttribute, attr, | ||
112 | "Check if the netlink packet has atttribute |attr|") { | ||
113 | return arg.HasAttribute(attr); | ||
114 | } | ||
115 | |||
109 | TEST_F(ScanUtilsTest, CanGetScanResult) { | 116 | TEST_F(ScanUtilsTest, CanGetScanResult) { |
110 | vector<NativeScanResult> scan_results; | 117 | vector<NativeScanResult> scan_results; |
111 | EXPECT_CALL( | 118 | EXPECT_CALL( |
@@ -162,7 +169,7 @@ TEST_F(ScanUtilsTest, CanSendSchedScanRequest) { | |||
162 | int errno_ignored; | 169 | int errno_ignored; |
163 | EXPECT_TRUE(scan_utils_.StartScheduledScan( | 170 | EXPECT_TRUE(scan_utils_.StartScheduledScan( |
164 | kFakeInterfaceIndex, | 171 | kFakeInterfaceIndex, |
165 | kFakeScheduledScanIntervalMs, | 172 | SchedScanIntervalSetting(), |
166 | kFakeRssiThreshold, kFakeUseRandomMAC, {}, {}, {}, &errno_ignored)); | 173 | kFakeRssiThreshold, kFakeUseRandomMAC, {}, {}, {}, &errno_ignored)); |
167 | // TODO(b/34231420): Add validation of requested scan ssids, threshold, | 174 | // TODO(b/34231420): Add validation of requested scan ssids, threshold, |
168 | // and frequencies. | 175 | // and frequencies. |
@@ -179,11 +186,51 @@ TEST_F(ScanUtilsTest, CanHandleSchedScanRequestFailure) { | |||
179 | int error_code; | 186 | int error_code; |
180 | EXPECT_FALSE(scan_utils_.StartScheduledScan( | 187 | EXPECT_FALSE(scan_utils_.StartScheduledScan( |
181 | kFakeInterfaceIndex, | 188 | kFakeInterfaceIndex, |
182 | kFakeScheduledScanIntervalMs, | 189 | SchedScanIntervalSetting(), |
183 | kFakeRssiThreshold, kFakeUseRandomMAC, {}, {}, {}, &error_code)); | 190 | kFakeRssiThreshold, kFakeUseRandomMAC, {}, {}, {}, &error_code)); |
184 | EXPECT_EQ(kFakeErrorCode, error_code); | 191 | EXPECT_EQ(kFakeErrorCode, error_code); |
185 | } | 192 | } |
186 | 193 | ||
194 | TEST_F(ScanUtilsTest, CanSpecifyScanPlansForSchedScanRequest) { | ||
195 | EXPECT_CALL( | ||
196 | netlink_manager_, | ||
197 | SendMessageAndGetResponses( | ||
198 | AllOf( | ||
199 | DoesNL80211PacketMatchCommand(NL80211_CMD_START_SCHED_SCAN), | ||
200 | DoesNL80211PacketHaveAttribute(NL80211_ATTR_SCHED_SCAN_PLANS), | ||
201 | Not(DoesNL80211PacketHaveAttribute( | ||
202 | NL80211_ATTR_SCHED_SCAN_INTERVAL))), | ||
203 | _)); | ||
204 | int errno_ignored; | ||
205 | SchedScanIntervalSetting interval_setting{ | ||
206 | {{kFakeScheduledScanIntervalMs, 10 /* repeated times */}}, | ||
207 | kFakeScheduledScanIntervalMs * 3 /* interval for infinite scans */}; | ||
208 | |||
209 | scan_utils_.StartScheduledScan( | ||
210 | kFakeInterfaceIndex, | ||
211 | interval_setting, | ||
212 | kFakeRssiThreshold, kFakeUseRandomMAC, {}, {}, {}, &errno_ignored); | ||
213 | } | ||
214 | |||
215 | TEST_F(ScanUtilsTest, CanSpecifySingleIntervalForSchedScanRequest) { | ||
216 | EXPECT_CALL( | ||
217 | netlink_manager_, | ||
218 | SendMessageAndGetResponses( | ||
219 | AllOf( | ||
220 | DoesNL80211PacketMatchCommand(NL80211_CMD_START_SCHED_SCAN), | ||
221 | DoesNL80211PacketHaveAttribute(NL80211_ATTR_SCHED_SCAN_INTERVAL), | ||
222 | Not(DoesNL80211PacketHaveAttribute( | ||
223 | NL80211_ATTR_SCHED_SCAN_PLANS))), | ||
224 | _)); | ||
225 | int errno_ignored; | ||
226 | SchedScanIntervalSetting interval_setting{{}, kFakeScheduledScanIntervalMs}; | ||
227 | |||
228 | scan_utils_.StartScheduledScan( | ||
229 | kFakeInterfaceIndex, | ||
230 | interval_setting, | ||
231 | kFakeRssiThreshold, kFakeUseRandomMAC, {}, {}, {}, &errno_ignored); | ||
232 | } | ||
233 | |||
187 | TEST_F(ScanUtilsTest, CanPrioritizeLastSeenSinceBootNetlinkAttribute) { | 234 | TEST_F(ScanUtilsTest, CanPrioritizeLastSeenSinceBootNetlinkAttribute) { |
188 | constexpr uint64_t kLastSeenTimestampNanoSeconds = 123456; | 235 | constexpr uint64_t kLastSeenTimestampNanoSeconds = 123456; |
189 | constexpr uint64_t kBssTsfTimestampMicroSeconds = 654321; | 236 | constexpr uint64_t kBssTsfTimestampMicroSeconds = 654321; |
diff --git a/tests/scanner_unittest.cpp b/tests/scanner_unittest.cpp index 85f6330..bbaeffd 100644 --- a/tests/scanner_unittest.cpp +++ b/tests/scanner_unittest.cpp | |||
@@ -51,6 +51,7 @@ namespace { | |||
51 | 51 | ||
52 | constexpr uint32_t kFakeInterfaceIndex = 12; | 52 | constexpr uint32_t kFakeInterfaceIndex = 12; |
53 | constexpr uint32_t kFakeWiphyIndex = 5; | 53 | constexpr uint32_t kFakeWiphyIndex = 5; |
54 | constexpr uint32_t kFakeScanIntervalMs = 10000; | ||
54 | 55 | ||
55 | // This is a helper function to mock the behavior of ScanUtils::Scan() | 56 | // This is a helper function to mock the behavior of ScanUtils::Scan() |
56 | // when we expect a error code. | 57 | // when we expect a error code. |
@@ -69,6 +70,20 @@ bool ReturnErrorCodeForScanRequest( | |||
69 | return false; | 70 | return false; |
70 | } | 71 | } |
71 | 72 | ||
73 | bool CaptureSchedScanIntervalSetting( | ||
74 | uint32_t /* interface_index */, | ||
75 | const SchedScanIntervalSetting& interval_setting, | ||
76 | int32_t /* rssi_threshold */, | ||
77 | bool /* request_random_mac */, | ||
78 | const std::vector<std::vector<uint8_t>>& /* scan_ssids */, | ||
79 | const std::vector<std::vector<uint8_t>>& /* match_ssids */, | ||
80 | const std::vector<uint32_t>& /* freqs */, | ||
81 | int* /* error_code */, | ||
82 | SchedScanIntervalSetting* out_interval_setting) { | ||
83 | *out_interval_setting = interval_setting; | ||
84 | return true; | ||
85 | } | ||
86 | |||
72 | } // namespace | 87 | } // namespace |
73 | 88 | ||
74 | class ScannerTest : public ::testing::Test { | 89 | class ScannerTest : public ::testing::Test { |
@@ -168,5 +183,71 @@ TEST_F(ScannerTest, TestStopPnoScanViaNetlink) { | |||
168 | EXPECT_TRUE(success); | 183 | EXPECT_TRUE(success); |
169 | } | 184 | } |
170 | 185 | ||
186 | TEST_F(ScannerTest, TestGenerateScanPlansIfDeviceSupports) { | ||
187 | ScanCapabilities scan_capabilities_scan_plan_supported( | ||
188 | 0 /* max_num_scan_ssids */, | ||
189 | 0 /* max_num_sched_scan_ssids */, | ||
190 | 0 /* max_match_sets */, | ||
191 | // Parameters above are not related to this test. | ||
192 | 2 /* 1 plan for finite repeated scan and 1 plan for ininfite scan loop */, | ||
193 | kFakeScanIntervalMs * PnoSettings::kSlowScanIntervalMultiplier / 1000, | ||
194 | PnoSettings::kFastScanIterations); | ||
195 | ScannerImpl scanner( | ||
196 | kFakeWiphyIndex, kFakeInterfaceIndex, | ||
197 | scan_capabilities_scan_plan_supported, wiphy_features_, | ||
198 | &client_interface_impl_, | ||
199 | &netlink_utils_, &scan_utils_, offload_service_utils_); | ||
200 | |||
201 | PnoSettings pno_settings; | ||
202 | pno_settings.interval_ms_ = kFakeScanIntervalMs; | ||
203 | |||
204 | SchedScanIntervalSetting interval_setting; | ||
205 | EXPECT_CALL( | ||
206 | scan_utils_, | ||
207 | StartScheduledScan(_, _, _, _, _, _, _, _)). | ||
208 | WillOnce(Invoke(bind( | ||
209 | CaptureSchedScanIntervalSetting, | ||
210 | _1, _2, _3, _4, _5, _6, _7, _8, &interval_setting))); | ||
211 | |||
212 | bool success_ignored = 0; | ||
213 | EXPECT_TRUE(scanner.startPnoScan(pno_settings, &success_ignored).isOk()); | ||
214 | /* 1 plan for finite repeated scan */ | ||
215 | EXPECT_EQ(1U, interval_setting.plans.size()); | ||
216 | EXPECT_EQ(kFakeScanIntervalMs * PnoSettings::kSlowScanIntervalMultiplier, | ||
217 | interval_setting.final_interval_ms); | ||
218 | } | ||
219 | |||
220 | TEST_F(ScannerTest, TestGenerateSingleIntervalIfDeviceDoesNotSupportScanPlan) { | ||
221 | ScanCapabilities scan_capabilities_no_scan_plan_support( | ||
222 | 0 /* max_num_scan_ssids */, | ||
223 | 0 /* max_num_sched_scan_ssids */, | ||
224 | 0 /* max_match_sets */, | ||
225 | // Parameters above are not related to this test. | ||
226 | 0 /* max_num_scan_plans */, | ||
227 | 0 /* max_scan_plan_interval */, | ||
228 | 0 /* max_scan_plan_iterations */); | ||
229 | ScannerImpl scanner( | ||
230 | kFakeWiphyIndex, kFakeInterfaceIndex, | ||
231 | scan_capabilities_no_scan_plan_support, wiphy_features_, | ||
232 | &client_interface_impl_, | ||
233 | &netlink_utils_, &scan_utils_, offload_service_utils_); | ||
234 | PnoSettings pno_settings; | ||
235 | pno_settings.interval_ms_ = kFakeScanIntervalMs; | ||
236 | |||
237 | SchedScanIntervalSetting interval_setting; | ||
238 | EXPECT_CALL( | ||
239 | scan_utils_, | ||
240 | StartScheduledScan(_, _, _, _, _, _, _, _)). | ||
241 | WillOnce(Invoke(bind( | ||
242 | CaptureSchedScanIntervalSetting, | ||
243 | _1, _2, _3, _4, _5, _6, _7, _8, &interval_setting))); | ||
244 | |||
245 | bool success_ignored = 0; | ||
246 | EXPECT_TRUE(scanner.startPnoScan(pno_settings, &success_ignored).isOk()); | ||
247 | |||
248 | EXPECT_EQ(0U, interval_setting.plans.size()); | ||
249 | EXPECT_EQ(kFakeScanIntervalMs, interval_setting.final_interval_ms); | ||
250 | } | ||
251 | |||
171 | } // namespace wificond | 252 | } // namespace wificond |
172 | } // namespace android | 253 | } // namespace android |