• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Aucun tag

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

system/connectivity/wificond


Commit MetaInfo

Révision7a3d8ddff0ea3bca99fb3e554651e1541a93121e (tree)
l'heure2017-07-13 03:11:07
AuteurNingyuan Wang <nywang@goog...>
CommiterNingyuan Wang

Message de Log

ScannerImpl: Add unit tests for scheduled scans

This patch adds unit tests for scheduled scans.
In order to do that, this also moves the isOffloadScanSupprted()
out of OffloadScanManager to OffloadServiceUtils. By injecting
MockOffloadServiceUtils to ScannerImpl, we can test either offload
supported or not supported cases.

Bug: 33452931
Test: compile, unit tests
Test: manual test that offload scan is not enabled by mistake.
This is done by checking manually inserted logs.

Change-Id: I6c78df78605321013676e5f4578026f21d953e3b

Change Summary

Modification

--- a/client_interface_impl.cpp
+++ b/client_interface_impl.cpp
@@ -24,6 +24,7 @@
2424 #include "wificond/client_interface_binder.h"
2525 #include "wificond/net/mlme_event.h"
2626 #include "wificond/net/netlink_utils.h"
27+#include "wificond/scanning/offload/offload_service_utils.h"
2728 #include "wificond/scanning/scan_result.h"
2829 #include "wificond/scanning/scan_utils.h"
2930 #include "wificond/scanning/scanner_impl.h"
@@ -116,6 +117,7 @@ ClientInterfaceImpl::ClientInterfaceImpl(
116117 supplicant_manager_(supplicant_manager),
117118 netlink_utils_(netlink_utils),
118119 scan_utils_(scan_utils),
120+ offload_service_utils_(new OffloadServiceUtils()),
119121 mlme_event_handler_(new MlmeEventHandlerImpl(this)),
120122 binder_(new ClientInterfaceBinder(this)),
121123 is_associated_(false) {
@@ -136,7 +138,8 @@ ClientInterfaceImpl::ClientInterfaceImpl(
136138 wiphy_features_,
137139 this,
138140 netlink_utils_,
139- scan_utils_);
141+ scan_utils_,
142+ offload_service_utils_);
140143 }
141144
142145 ClientInterfaceImpl::~ClientInterfaceImpl() {
--- a/client_interface_impl.h
+++ b/client_interface_impl.h
@@ -27,6 +27,7 @@
2727 #include "android/net/wifi/IClientInterface.h"
2828 #include "wificond/net/mlme_event_handler.h"
2929 #include "wificond/net/netlink_utils.h"
30+#include "wificond/scanning/offload/offload_service_utils.h"
3031 #include "wificond/scanning/scanner_impl.h"
3132
3233 namespace android {
@@ -96,6 +97,7 @@ class ClientInterfaceImpl {
9697 android::wifi_system::SupplicantManager* const supplicant_manager_;
9798 NetlinkUtils* const netlink_utils_;
9899 ScanUtils* const scan_utils_;
100+ const std::shared_ptr<OffloadServiceUtils> offload_service_utils_;
99101 const std::unique_ptr<MlmeEventHandlerImpl> mlme_event_handler_;
100102 const android::sp<ClientInterfaceBinder> binder_;
101103 android::sp<ScannerImpl> scanner_;
--- a/scanning/offload/offload_scan_manager.cpp
+++ b/scanning/offload/offload_scan_manager.cpp
@@ -38,8 +38,10 @@ using android::wificond::OffloadCallback;
3838 using android::wificond::OnNativeScanResultsReadyHandler;
3939 using ::com::android::server::wifi::wificond::NativeScanResult;
4040 using ::com::android::server::wifi::wificond::NativeScanStats;
41-using namespace std::placeholders;
4241 using std::vector;
42+using std::weak_ptr;
43+
44+using namespace std::placeholders;
4345
4446 namespace {
4547 const uint32_t kSubscriptionDelayMs = 5000;
@@ -67,7 +69,7 @@ void OffloadCallbackHandlersImpl::OnErrorHandler(const OffloadStatus& status) {
6769 }
6870 }
6971
70-OffloadScanManager::OffloadScanManager(OffloadServiceUtils* utils,
72+OffloadScanManager::OffloadScanManager(weak_ptr<OffloadServiceUtils> utils,
7173 OnNativeScanResultsReadyHandler handler)
7274 : wifi_offload_hal_(nullptr),
7375 wifi_offload_callback_(nullptr),
@@ -75,21 +77,18 @@ OffloadScanManager::OffloadScanManager(OffloadServiceUtils* utils,
7577 subscription_enabled_(false),
7678 offload_callback_handlers_(new OffloadCallbackHandlersImpl(this)),
7779 scan_result_handler_(handler) {
78- if (utils == nullptr) {
79- LOG(ERROR) << "Invalid arguments for Offload ScanManager";
80- return;
81- }
80+ auto offload_scan_utils = utils.lock();
8281 if (scan_result_handler_ == nullptr) {
8382 LOG(ERROR) << "Invalid Offload scan result handler";
8483 return;
8584 }
86- wifi_offload_hal_ = utils->GetOffloadService();
85+ wifi_offload_hal_ = offload_scan_utils->GetOffloadService();
8786 if (wifi_offload_hal_ == nullptr) {
8887 LOG(ERROR) << "No Offload Service available";
8988 return;
9089 }
9190
92- death_recipient_ = utils->GetOffloadDeathRecipient(
91+ death_recipient_ = offload_scan_utils->GetOffloadDeathRecipient(
9392 std::bind(&OffloadScanManager::OnObjectDeath, this, _1));
9493 uint64_t cookie = reinterpret_cast<uint64_t>(wifi_offload_hal_.get());
9594 auto link_to_death_status =
@@ -101,7 +100,7 @@ OffloadScanManager::OffloadScanManager(OffloadServiceUtils* utils,
101100 }
102101
103102 wifi_offload_callback_ =
104- utils->GetOffloadCallback(offload_callback_handlers_.get());
103+ offload_scan_utils->GetOffloadCallback(offload_callback_handlers_.get());
105104 if (wifi_offload_callback_ == nullptr) {
106105 LOG(ERROR) << "Invalid Offload callback object";
107106 return;
@@ -215,15 +214,6 @@ OffloadScanManager::StatusCode OffloadScanManager::getOffloadStatus() const {
215214 return offload_status_;
216215 }
217216
218-bool OffloadScanManager::isOffloadScanSupported() const {
219- bool result = false;
220-#ifdef WIFI_OFFLOAD_SCANS
221- LOG(VERBOSE) << "Offload HAL supported";
222- result = true;
223-#endif
224- return result;
225-}
226-
227217 bool OffloadScanManager::getScanStats(NativeScanStats* native_scan_stats) {
228218 if (getOffloadStatus() != OffloadScanManager::kNoError) {
229219 LOG(WARNING) << "Unable to get scan stats due to Wifi Offload HAL error";
--- a/scanning/offload/offload_scan_manager.h
+++ b/scanning/offload/offload_scan_manager.h
@@ -94,7 +94,7 @@ class OffloadScanManager {
9494 kTransactionFailed,
9595 };
9696
97- explicit OffloadScanManager(OffloadServiceUtils* utils,
97+ explicit OffloadScanManager(std::weak_ptr<OffloadServiceUtils> utils,
9898 OnNativeScanResultsReadyHandler handler);
9999 virtual ~OffloadScanManager();
100100 /* Request start of offload scans with scan parameters and scan filter
@@ -118,8 +118,6 @@ class OffloadScanManager {
118118 ::com::android::server::wifi::wificond::NativeScanStats* /* scanStats */);
119119 /* Otain status of the Offload HAL service */
120120 StatusCode getOffloadStatus() const;
121- /* Check if Offload service is supported on this device */
122- bool isOffloadScanSupported() const;
123121
124122 private:
125123 void ReportScanResults(
--- a/scanning/offload/offload_service_utils.cpp
+++ b/scanning/offload/offload_service_utils.cpp
@@ -35,6 +35,15 @@ OffloadDeathRecipient* OffloadServiceUtils::GetOffloadDeathRecipient(
3535 return new OffloadDeathRecipient(handler);
3636 }
3737
38+bool OffloadServiceUtils::IsOffloadScanSupported() const {
39+ bool result = false;
40+#ifdef WIFI_OFFLOAD_SCANS
41+ LOG(VERBOSE) << "Offload HAL supported";
42+ result = true;
43+#endif
44+ return result;
45+}
46+
3847 OffloadDeathRecipient::OffloadDeathRecipient(
3948 OffloadDeathRecipientHandler handler)
4049 : handler_(handler) {}
--- a/scanning/offload/offload_service_utils.h
+++ b/scanning/offload/offload_service_utils.h
@@ -46,6 +46,8 @@ class OffloadServiceUtils {
4646 virtual ~OffloadServiceUtils() = default;
4747 virtual android::sp<android::hardware::wifi::offload::V1_0::IOffload>
4848 GetOffloadService();
49+ // Check if Offload scan is supported on this device.
50+ virtual bool IsOffloadScanSupported() const;
4951 virtual android::sp<OffloadCallback> GetOffloadCallback(
5052 OffloadCallbackHandlers* handlers);
5153 virtual OffloadDeathRecipient* GetOffloadDeathRecipient(
--- a/scanning/scanner_impl.cpp
+++ b/scanning/scanner_impl.cpp
@@ -37,6 +37,7 @@ using com::android::server::wifi::wificond::SingleScanSettings;
3737
3838 using std::string;
3939 using std::vector;
40+using std::weak_ptr;
4041
4142 using namespace std::placeholders;
4243
@@ -49,7 +50,8 @@ ScannerImpl::ScannerImpl(uint32_t wiphy_index,
4950 const WiphyFeatures& wiphy_features,
5051 ClientInterfaceImpl* client_interface,
5152 NetlinkUtils* netlink_utils,
52- ScanUtils* scan_utils)
53+ ScanUtils* scan_utils,
54+ weak_ptr<OffloadServiceUtils> offload_service_utils)
5355 : valid_(true),
5456 scan_started_(false),
5557 pno_scan_started_(false),
@@ -77,10 +79,11 @@ ScannerImpl::ScannerImpl(uint32_t wiphy_index,
7779 this,
7880 _1, _2));
7981 offload_scan_manager_.reset(
80- new OffloadScanManager(new OffloadServiceUtils(),
82+ new OffloadScanManager(
83+ offload_service_utils,
8184 std::bind(&ScannerImpl::OnOffloadScanResult,
8285 this, _1)));
83- offload_scan_supported_ = offload_scan_manager_->isOffloadScanSupported();
86+ offload_scan_supported_ = offload_service_utils.lock()->IsOffloadScanSupported();
8487 }
8588
8689 ScannerImpl::~ScannerImpl() {
--- a/scanning/scanner_impl.h
+++ b/scanning/scanner_impl.h
@@ -30,6 +30,7 @@ namespace android {
3030 namespace wificond {
3131
3232 class ClientInterfaceImpl;
33+class OffloadServiceUtils;
3334 class ScanUtils;
3435
3536 class ScannerImpl : public android::net::wifi::BnWifiScannerImpl {
@@ -40,7 +41,8 @@ class ScannerImpl : public android::net::wifi::BnWifiScannerImpl {
4041 const WiphyFeatures& wiphy_features,
4142 ClientInterfaceImpl* client_interface,
4243 NetlinkUtils* netlink_utils,
43- ScanUtils* scan_utils);
44+ ScanUtils* scan_utils,
45+ std::weak_ptr<OffloadServiceUtils> offload_service_utils);
4446 ~ScannerImpl();
4547 // Returns a vector of available frequencies for 2.4GHz channels.
4648 ::android::binder::Status getAvailable2gChannels(
--- a/tests/mock_offload_service_utils.h
+++ b/tests/mock_offload_service_utils.h
@@ -32,7 +32,7 @@ class MockOffloadServiceUtils : public OffloadServiceUtils {
3232 public:
3333 MockOffloadServiceUtils();
3434 ~MockOffloadServiceUtils() override = default;
35-
35+ MOCK_CONST_METHOD0(IsOffloadScanSupported, bool());
3636 MOCK_METHOD0(GetOffloadService,
3737 sp<android::hardware::wifi::offload::V1_0::IOffload>());
3838 MOCK_METHOD1(GetOffloadCallback,
--- a/tests/mock_scan_utils.h
+++ b/tests/mock_scan_utils.h
@@ -29,8 +29,14 @@ class MockScanUtils : public ScanUtils {
2929 MockScanUtils(NetlinkManager* netlink_manager);
3030 ~MockScanUtils() override = default;
3131
32+ MOCK_METHOD1(UnsubscribeScanResultNotification,
33+ void(uint32_t interface_index));
3234 MOCK_METHOD1(AbortScan, bool(uint32_t interface_index));
35+ MOCK_METHOD1(StopScheduledScan, bool(uint32_t interface_index));
3336
37+ MOCK_METHOD2(SubscribeScanResultNotification,void(
38+ uint32_t interface_index,
39+ OnScanResultsReadyHandler handler));
3440 MOCK_METHOD2(GetScanResult, bool(
3541 uint32_t interface_index,
3642 std::vector<::com::android::server::wifi::wificond::NativeScanResult>* out_scan_results));
@@ -42,12 +48,15 @@ class MockScanUtils : public ScanUtils {
4248 const std::vector<uint32_t>& freqs,
4349 int* error_code));
4450
45- MOCK_METHOD2(SubscribeScanResultNotification,void(
51+ MOCK_METHOD8(StartScheduledScan, bool(
4652 uint32_t interface_index,
47- OnScanResultsReadyHandler handler));
48-
49- MOCK_METHOD1(UnsubscribeScanResultNotification,
50- void(uint32_t interface_index));
53+ uint32_t interval_ms,
54+ int32_t rssi_threshold,
55+ bool request_random_mac,
56+ const std::vector<std::vector<uint8_t>>& scan_ssids,
57+ const std::vector<std::vector<uint8_t>>& match_ssids,
58+ const std::vector<uint32_t>& freqs,
59+ int* error_code));
5160
5261 }; // class MockScanUtils
5362
--- a/tests/offload_scan_manager_test.cpp
+++ b/tests/offload_scan_manager_test.cpp
@@ -47,6 +47,7 @@ using com::android::server::wifi::wificond::NativeScanStats;
4747 using testing::NiceMock;
4848 using testing::_;
4949 using testing::Invoke;
50+using std::shared_ptr;
5051 using std::unique_ptr;
5152 using std::vector;
5253 using std::bind;
@@ -109,7 +110,7 @@ class OffloadScanManagerTest : public ::testing::Test {
109110 sp<NiceMock<MockOffload>> mock_offload_{new NiceMock<MockOffload>()};
110111 sp<OffloadCallback> offload_callback_;
111112 sp<OffloadDeathRecipient> death_recipient_;
112- unique_ptr<NiceMock<MockOffloadServiceUtils>> mock_offload_service_utils_{
113+ shared_ptr<NiceMock<MockOffloadServiceUtils>> mock_offload_service_utils_{
113114 new NiceMock<MockOffloadServiceUtils>()};
114115 unique_ptr<OffloadScanManager> offload_scan_manager_;
115116 OffloadStatus status;
@@ -130,7 +131,7 @@ TEST_F(OffloadScanManagerTest, BinderDeathRegisteredCookieAndService) {
130131 ON_CALL(*mock_offload_service_utils_, GetOffloadService())
131132 .WillByDefault(testing::Return(mock_offload_));
132133 offload_scan_manager_.reset(new OffloadScanManager(
133- mock_offload_service_utils_.get(),
134+ mock_offload_service_utils_,
134135 [](vector<NativeScanResult> scanResult) -> void {}));
135136 death_recipient_->serviceDied(cookie_, mock_offload_);
136137 EXPECT_EQ(OffloadScanManager::kNoService,
@@ -146,7 +147,7 @@ TEST_F(OffloadScanManagerTest, BinderDeathUnregisteredCookie) {
146147 ON_CALL(*mock_offload_service_utils_, GetOffloadService())
147148 .WillByDefault(testing::Return(mock_offload_));
148149 offload_scan_manager_.reset(new OffloadScanManager(
149- mock_offload_service_utils_.get(),
150+ mock_offload_service_utils_,
150151 [](vector<NativeScanResult> scanResult) -> void {}));
151152 death_recipient_->serviceDied(kDeathCode, mock_offload_);
152153 EXPECT_FALSE(OffloadScanManager::kNoService ==
@@ -154,15 +155,6 @@ TEST_F(OffloadScanManagerTest, BinderDeathUnregisteredCookie) {
154155 }
155156
156157 /**
157- * Testing OffloadScanManager with OffloadServiceUtils null argument
158- */
159-TEST_F(OffloadScanManagerTest, ServiceUtilsNotAvailableTest) {
160- offload_scan_manager_.reset(new OffloadScanManager(nullptr, nullptr));
161- EXPECT_EQ(OffloadScanManager::kNoService,
162- offload_scan_manager_->getOffloadStatus());
163-}
164-
165-/**
166158 * Testing OffloadScanManager with no handle on Offloal HAL service
167159 * and no registered handler for Offload Scan results
168160 */
@@ -171,7 +163,7 @@ TEST_F(OffloadScanManagerTest, ServiceNotAvailableTest) {
171163 ON_CALL(*mock_offload_service_utils_, GetOffloadService())
172164 .WillByDefault(testing::Return(nullptr));
173165 offload_scan_manager_.reset(new OffloadScanManager(
174- mock_offload_service_utils_.get(),
166+ mock_offload_service_utils_,
175167 [](vector<NativeScanResult> scanResult) -> void {}));
176168 EXPECT_EQ(OffloadScanManager::kNoService,
177169 offload_scan_manager_->getOffloadStatus());
@@ -188,7 +180,7 @@ TEST_F(OffloadScanManagerTest, ServiceAvailableTest) {
188180 ON_CALL(*mock_offload_service_utils_, GetOffloadService())
189181 .WillByDefault(testing::Return(mock_offload_));
190182 offload_scan_manager_.reset(new OffloadScanManager(
191- mock_offload_service_utils_.get(),
183+ mock_offload_service_utils_,
192184 [](vector<NativeScanResult> scanResult) -> void {}));
193185 EXPECT_EQ(OffloadScanManager::kNoError,
194186 offload_scan_manager_->getOffloadStatus());
@@ -207,7 +199,7 @@ TEST_F(OffloadScanManagerTest, CallbackInvokedTest) {
207199 ON_CALL(*mock_offload_service_utils_, GetOffloadService())
208200 .WillByDefault(testing::Return(mock_offload_));
209201 offload_scan_manager_.reset(new OffloadScanManager(
210- mock_offload_service_utils_.get(),
202+ mock_offload_service_utils_,
211203 [&callback_invoked](vector<NativeScanResult> scanResult) -> void {
212204 callback_invoked = true;
213205 }));
@@ -228,7 +220,7 @@ TEST_F(OffloadScanManagerTest, ErrorCallbackInvokedTest) {
228220 ON_CALL(*mock_offload_service_utils_, GetOffloadService())
229221 .WillByDefault(testing::Return(mock_offload_));
230222 offload_scan_manager_.reset(new OffloadScanManager(
231- mock_offload_service_utils_.get(),
223+ mock_offload_service_utils_,
232224 [](vector<NativeScanResult> scanResult) -> void {}));
233225 OffloadStatus status =
234226 OffloadTestUtils::createOffloadStatus(OffloadStatusCode::ERROR);
@@ -248,7 +240,7 @@ TEST_F(OffloadScanManagerTest, StartScanTestWhenServiceIsOk) {
248240 ON_CALL(*mock_offload_service_utils_, GetOffloadService())
249241 .WillByDefault(testing::Return(mock_offload_));
250242 offload_scan_manager_.reset(new OffloadScanManager(
251- mock_offload_service_utils_.get(),
243+ mock_offload_service_utils_,
252244 [](vector<NativeScanResult> scanResult) -> void {}));
253245 EXPECT_CALL(*mock_offload_, subscribeScanResults(_, _));
254246 EXPECT_CALL(*mock_offload_, configureScans(_, _, _));
@@ -268,7 +260,7 @@ TEST_F(OffloadScanManagerTest, StartScanTestWhenServiceIsNotAvailable) {
268260 ON_CALL(*mock_offload_service_utils_, GetOffloadService())
269261 .WillByDefault(testing::Return(nullptr));
270262 offload_scan_manager_.reset(new OffloadScanManager(
271- mock_offload_service_utils_.get(),
263+ mock_offload_service_utils_,
272264 [](vector<NativeScanResult> scanResult) -> void {}));
273265 OffloadScanManager::ReasonCode reason_code = OffloadScanManager::kNone;
274266 bool result = offload_scan_manager_->startScan(
@@ -289,7 +281,7 @@ TEST_F(OffloadScanManagerTest, StartScanTestWhenServiceIsNotConnected) {
289281 ON_CALL(*mock_offload_service_utils_, GetOffloadService())
290282 .WillByDefault(testing::Return(mock_offload_));
291283 offload_scan_manager_.reset(new OffloadScanManager(
292- mock_offload_service_utils_.get(),
284+ mock_offload_service_utils_,
293285 [](vector<NativeScanResult> scanResult) -> void {}));
294286 OffloadStatus status =
295287 OffloadTestUtils::createOffloadStatus(OffloadStatusCode::NO_CONNECTION);
@@ -313,7 +305,7 @@ TEST_F(OffloadScanManagerTest, StartScanTwiceTestWhenServiceIsOk) {
313305 ON_CALL(*mock_offload_service_utils_, GetOffloadService())
314306 .WillByDefault(testing::Return(mock_offload_));
315307 offload_scan_manager_.reset(new OffloadScanManager(
316- mock_offload_service_utils_.get(),
308+ mock_offload_service_utils_,
317309 [](vector<NativeScanResult> scanResult) -> void {}));
318310 EXPECT_CALL(*mock_offload_, subscribeScanResults(_, _)).Times(1);
319311 EXPECT_CALL(*mock_offload_, configureScans(_, _, _)).Times(2);
@@ -339,7 +331,7 @@ TEST_F(OffloadScanManagerTest, StopScanTestWhenServiceIsOk) {
339331 ON_CALL(*mock_offload_service_utils_, GetOffloadService())
340332 .WillByDefault(testing::Return(mock_offload_));
341333 offload_scan_manager_.reset(new OffloadScanManager(
342- mock_offload_service_utils_.get(),
334+ mock_offload_service_utils_,
343335 [](vector<NativeScanResult> scanResult) -> void {}));
344336 EXPECT_CALL(*mock_offload_, subscribeScanResults(_, _));
345337 EXPECT_CALL(*mock_offload_, configureScans(_, _, _));
@@ -364,7 +356,7 @@ TEST_F(OffloadScanManagerTest, StopScanTestWithoutStartWhenServiceIsOk) {
364356 ON_CALL(*mock_offload_service_utils_, GetOffloadService())
365357 .WillByDefault(testing::Return(mock_offload_));
366358 offload_scan_manager_.reset(new OffloadScanManager(
367- mock_offload_service_utils_.get(),
359+ mock_offload_service_utils_,
368360 [](vector<NativeScanResult> scanResult) -> void {}));
369361 OffloadScanManager::ReasonCode reason_code = OffloadScanManager::kNone;
370362 bool result = offload_scan_manager_->stopScan(&reason_code);
@@ -382,7 +374,7 @@ TEST_F(OffloadScanManagerTest, StopScanTestWhenServiceIsNotConnectedAnymore) {
382374 ON_CALL(*mock_offload_service_utils_, GetOffloadService())
383375 .WillByDefault(testing::Return(mock_offload_));
384376 offload_scan_manager_.reset(new OffloadScanManager(
385- mock_offload_service_utils_.get(),
377+ mock_offload_service_utils_,
386378 [](vector<NativeScanResult> scanResult) -> void {}));
387379 EXPECT_CALL(*mock_offload_, subscribeScanResults(_, _));
388380 EXPECT_CALL(*mock_offload_, configureScans(_, _, _));
@@ -410,7 +402,7 @@ TEST_F(OffloadScanManagerTest, getScanStatsTestWhenServiceIsOk) {
410402 ON_CALL(*mock_offload_service_utils_, GetOffloadService())
411403 .WillByDefault(testing::Return(mock_offload_));
412404 offload_scan_manager_.reset(new OffloadScanManager(
413- mock_offload_service_utils_.get(),
405+ mock_offload_service_utils_,
414406 [](vector<NativeScanResult> scanResult) -> void {}));
415407 EXPECT_CALL(*mock_offload_, getScanStats(_));
416408 NativeScanStats stats;
@@ -429,7 +421,7 @@ TEST_F(OffloadScanManagerTest, getScanStatsTestWhenServiceIsNotOk) {
429421 ON_CALL(*mock_offload_service_utils_, GetOffloadService())
430422 .WillByDefault(testing::Return(mock_offload_));
431423 offload_scan_manager_.reset(new OffloadScanManager(
432- mock_offload_service_utils_.get(),
424+ mock_offload_service_utils_,
433425 [](vector<NativeScanResult> scanResult) -> void {}));
434426 OffloadStatus status =
435427 OffloadTestUtils::createOffloadStatus(OffloadStatusCode::NO_CONNECTION);
@@ -451,7 +443,7 @@ TEST_F(OffloadScanManagerTest, StartScanFailedTest) {
451443 ON_CALL(*mock_offload_service_utils_, GetOffloadService())
452444 .WillByDefault(testing::Return(mock_offload_));
453445 offload_scan_manager_.reset(new OffloadScanManager(
454- mock_offload_service_utils_.get(),
446+ mock_offload_service_utils_,
455447 [](vector<NativeScanResult> scanResult) -> void {}));
456448 EXPECT_CALL(*mock_offload_, subscribeScanResults(_, _)).Times(0);
457449 EXPECT_CALL(*mock_offload_, configureScans(_, _, _)).Times(1);
@@ -475,7 +467,7 @@ TEST_F(OffloadScanManagerTest, getScanStatsFailedTest) {
475467 ON_CALL(*mock_offload_service_utils_, GetOffloadService())
476468 .WillByDefault(testing::Return(mock_offload_));
477469 offload_scan_manager_.reset(new OffloadScanManager(
478- mock_offload_service_utils_.get(),
470+ mock_offload_service_utils_,
479471 [](vector<NativeScanResult> scanResult) -> void {}));
480472 status = OffloadTestUtils::createOffloadStatus(OffloadStatusCode::TIMEOUT);
481473 EXPECT_CALL(*mock_offload_, getScanStats(_));
--- a/tests/scanner_unittest.cpp
+++ b/tests/scanner_unittest.cpp
@@ -25,17 +25,21 @@
2525 #include "wificond/tests/mock_client_interface_impl.h"
2626 #include "wificond/tests/mock_netlink_manager.h"
2727 #include "wificond/tests/mock_netlink_utils.h"
28+#include "wificond/tests/mock_offload_service_utils.h"
2829 #include "wificond/tests/mock_scan_utils.h"
2930
3031 using ::android::binder::Status;
3132 using ::android::wifi_system::MockInterfaceTool;
3233 using ::android::wifi_system::MockSupplicantManager;
3334 using ::com::android::server::wifi::wificond::SingleScanSettings;
35+using ::com::android::server::wifi::wificond::PnoSettings;
3436 using ::com::android::server::wifi::wificond::NativeScanResult;
3537 using ::testing::Invoke;
3638 using ::testing::NiceMock;
3739 using ::testing::Return;
3840 using ::testing::_;
41+using std::shared_ptr;
42+using std::unique_ptr;
3943 using std::vector;
4044
4145 using namespace std::placeholders;
@@ -69,6 +73,17 @@ bool ReturnErrorCodeForScanRequest(
6973
7074 class ScannerTest : public ::testing::Test {
7175 protected:
76+ void SetUp() override {
77+ ON_CALL(*offload_service_utils_, IsOffloadScanSupported()).WillByDefault(
78+ Return(false));
79+ netlink_scanner_.reset(new ScannerImpl(
80+ kFakeWiphyIndex, kFakeInterfaceIndex,
81+ scan_capabilities_, wiphy_features_,
82+ &client_interface_impl_,
83+ &netlink_utils_, &scan_utils_, offload_service_utils_));
84+ }
85+
86+ unique_ptr<ScannerImpl> netlink_scanner_;
7287 NiceMock<MockNetlinkManager> netlink_manager_;
7388 NiceMock<MockNetlinkUtils> netlink_utils_{&netlink_manager_};
7489 NiceMock<MockScanUtils> scan_utils_{&netlink_manager_};
@@ -76,19 +91,16 @@ class ScannerTest : public ::testing::Test {
7691 NiceMock<MockSupplicantManager> supplicant_manager_;
7792 NiceMock<MockClientInterfaceImpl> client_interface_impl_{
7893 &if_tool_, &supplicant_manager_, &netlink_utils_, &scan_utils_};
94+ shared_ptr<NiceMock<MockOffloadServiceUtils>> offload_service_utils_{
95+ new NiceMock<MockOffloadServiceUtils>()};
7996 ScanCapabilities scan_capabilities_;
8097 WiphyFeatures wiphy_features_;
81- ScannerImpl scanner_{
82- kFakeWiphyIndex, kFakeInterfaceIndex,
83- scan_capabilities_, wiphy_features_,
84- &client_interface_impl_,
85- &netlink_utils_, &scan_utils_};
8698 };
8799
88100 TEST_F(ScannerTest, TestSingleScan) {
89101 EXPECT_CALL(scan_utils_, Scan(_, _, _, _, _)).WillOnce(Return(true));
90102 bool success = false;
91- EXPECT_TRUE(scanner_.scan(SingleScanSettings(), &success).isOk());
103+ EXPECT_TRUE(netlink_scanner_->scan(SingleScanSettings(), &success).isOk());
92104 EXPECT_TRUE(success);
93105 }
94106
@@ -100,7 +112,7 @@ TEST_F(ScannerTest, TestSingleScanFailure) {
100112 ReturnErrorCodeForScanRequest, EBUSY, _1, _2, _3, _4, _5)));
101113
102114 bool success = false;
103- EXPECT_TRUE(scanner_.scan(SingleScanSettings(), &success).isOk());
115+ EXPECT_TRUE(netlink_scanner_->scan(SingleScanSettings(), &success).isOk());
104116 EXPECT_FALSE(success);
105117 }
106118
@@ -113,33 +125,48 @@ TEST_F(ScannerTest, TestProcessAbortsOnScanReturningNoDeviceError) {
113125
114126 bool success_ignored;
115127 EXPECT_DEATH(
116- scanner_.scan(SingleScanSettings(), &success_ignored),
128+ netlink_scanner_->scan(SingleScanSettings(), &success_ignored),
117129 "Driver is in a bad state*");
118130 }
119131
120132 TEST_F(ScannerTest, TestAbortScan) {
121133 bool single_scan_success = false;
122134 EXPECT_CALL(scan_utils_, Scan(_, _, _, _, _)).WillOnce(Return(true));
123- EXPECT_TRUE(scanner_.scan(SingleScanSettings(),
135+ EXPECT_TRUE(netlink_scanner_->scan(SingleScanSettings(),
124136 &single_scan_success).isOk());
125137 EXPECT_TRUE(single_scan_success);
126138
127139 EXPECT_CALL(scan_utils_, AbortScan(_));
128- EXPECT_TRUE(scanner_.abortScan().isOk());
140+ EXPECT_TRUE(netlink_scanner_->abortScan().isOk());
129141 }
130142
131143 TEST_F(ScannerTest, TestAbortScanNotIssuedIfNoOngoingScan) {
132144 EXPECT_CALL(scan_utils_, AbortScan(_)).Times(0);
133- EXPECT_TRUE(scanner_.abortScan().isOk());
145+ EXPECT_TRUE(netlink_scanner_->abortScan().isOk());
134146 }
135147
136148 TEST_F(ScannerTest, TestGetScanResults) {
137149 vector<NativeScanResult> scan_results;
138150 EXPECT_CALL(scan_utils_, GetScanResult(_, _)).WillOnce(Return(true));
139- EXPECT_TRUE(scanner_.getScanResults(&scan_results).isOk());
151+ EXPECT_TRUE(netlink_scanner_->getScanResults(&scan_results).isOk());
140152 }
141153
142-//TODO(b/33452931): Add more test cases for ScannerImpl.
154+TEST_F(ScannerTest, TestStartPnoScanViaNetlink) {
155+ bool success = false;
156+ EXPECT_CALL(scan_utils_, StartScheduledScan(_, _, _, _, _, _, _, _)).
157+ WillOnce(Return(true));
158+ EXPECT_TRUE(netlink_scanner_->startPnoScan(PnoSettings(), &success).isOk());
159+ EXPECT_TRUE(success);
160+}
161+
162+TEST_F(ScannerTest, TestStopPnoScanViaNetlink) {
163+ bool success = false;
164+ // StopScheduledScan() will be called no matter if there is an ongoing
165+ // scheduled scan or not. This is for making the system more robust.
166+ EXPECT_CALL(scan_utils_, StopScheduledScan(_)).WillOnce(Return(true));
167+ EXPECT_TRUE(netlink_scanner_->stopPnoScan(&success).isOk());
168+ EXPECT_TRUE(success);
169+}
143170
144171 } // namespace wificond
145172 } // namespace android