diff options
author | android-build-team Robot | 2017-08-16 02:26:10 -0500 |
---|---|---|
committer | android-build-team Robot | 2017-08-16 02:26:10 -0500 |
commit | 2ccf7c874f0bdf9ec591f782db4890f2e54e74dd (patch) | |
tree | 785d94839d790b928ecf803fd12ebd01e0315cce | |
parent | 06b05540ea335bd3b8a4c1ac9eaaf582e2f17c34 (diff) | |
parent | 7439bcacc8805ae85bf1440d5f28df88dd1aee56 (diff) | |
download | system-connectivity-wificond-2ccf7c874f0bdf9ec591f782db4890f2e54e74dd.tar.gz system-connectivity-wificond-2ccf7c874f0bdf9ec591f782db4890f2e54e74dd.tar.xz system-connectivity-wificond-2ccf7c874f0bdf9ec591f782db4890f2e54e74dd.zip |
release-request-a0f7506a-1cd6-4a03-927b-8d29e0c545e6-for-git_oc-mr1-release-4277764 snap-temp-L23600000093606242
Change-Id: I06dea035d6ab37f55f6a68f5bda7a21919aac91a
-rw-r--r-- | Android.mk | 2 | ||||
-rw-r--r-- | aidl/android/net/wifi/IPnoScanEvent.aidl | 9 | ||||
-rw-r--r-- | scanning/offload/offload_scan_manager.cpp | 119 | ||||
-rw-r--r-- | scanning/offload/offload_scan_manager.h | 35 | ||||
-rw-r--r-- | scanning/offload/offload_service_utils.cpp | 5 | ||||
-rw-r--r-- | scanning/offload_scan_callback_interface.h | 42 | ||||
-rw-r--r-- | scanning/offload_scan_callback_interface_impl.cpp | 42 | ||||
-rw-r--r-- | scanning/offload_scan_callback_interface_impl.h | 44 | ||||
-rw-r--r-- | scanning/scanner_impl.cpp | 194 | ||||
-rw-r--r-- | scanning/scanner_impl.h | 36 | ||||
-rw-r--r-- | tests/mock_offload_scan_callback_interface.cpp | 25 | ||||
-rw-r--r-- | tests/mock_offload_scan_callback_interface.h | 41 | ||||
-rw-r--r-- | tests/offload_scan_manager_test.cpp | 87 |
13 files changed, 479 insertions, 202 deletions
@@ -66,6 +66,7 @@ LOCAL_SRC_FILES := \ | |||
66 | rtt/rtt_controller_impl.cpp \ | 66 | rtt/rtt_controller_impl.cpp \ |
67 | scanning/channel_settings.cpp \ | 67 | scanning/channel_settings.cpp \ |
68 | scanning/hidden_network.cpp \ | 68 | scanning/hidden_network.cpp \ |
69 | scanning/offload_scan_callback_interface_impl.cpp \ | ||
69 | scanning/pno_network.cpp \ | 70 | scanning/pno_network.cpp \ |
70 | scanning/pno_settings.cpp \ | 71 | scanning/pno_settings.cpp \ |
71 | scanning/scan_result.cpp \ | 72 | scanning/scan_result.cpp \ |
@@ -175,6 +176,7 @@ LOCAL_SRC_FILES := \ | |||
175 | tests/mock_netlink_utils.cpp \ | 176 | tests/mock_netlink_utils.cpp \ |
176 | tests/mock_offload.cpp \ | 177 | tests/mock_offload.cpp \ |
177 | tests/mock_offload_callback_handlers.cpp \ | 178 | tests/mock_offload_callback_handlers.cpp \ |
179 | tests/mock_offload_scan_callback_interface.cpp \ | ||
178 | tests/mock_offload_service_utils.cpp \ | 180 | tests/mock_offload_service_utils.cpp \ |
179 | tests/mock_scan_utils.cpp \ | 181 | tests/mock_scan_utils.cpp \ |
180 | tests/netlink_manager_unittest.cpp \ | 182 | tests/netlink_manager_unittest.cpp \ |
diff --git a/aidl/android/net/wifi/IPnoScanEvent.aidl b/aidl/android/net/wifi/IPnoScanEvent.aidl index 6488c19..50c1918 100644 --- a/aidl/android/net/wifi/IPnoScanEvent.aidl +++ b/aidl/android/net/wifi/IPnoScanEvent.aidl | |||
@@ -18,6 +18,15 @@ package android.net.wifi; | |||
18 | 18 | ||
19 | // A callback for receiving pno scanning events. | 19 | // A callback for receiving pno scanning events. |
20 | interface IPnoScanEvent { | 20 | interface IPnoScanEvent { |
21 | const int PNO_SCAN_OVER_OFFLOAD_BINDER_FAILURE = 0; | ||
22 | const int PNO_SCAN_OVER_OFFLOAD_REMOTE_FAILURE = 1; | ||
23 | |||
21 | oneway void OnPnoNetworkFound(); | 24 | oneway void OnPnoNetworkFound(); |
22 | oneway void OnPnoScanFailed(); | 25 | oneway void OnPnoScanFailed(); |
26 | // Callback notifying the framework that PNO scan is started over Offload HAL | ||
27 | // interface, this is meant for metrics collection only | ||
28 | oneway void OnPnoScanOverOffloadStarted(); | ||
29 | // Callback notifying the framework that a PNO scan running over Offload HAL | ||
30 | // has failed, this is meant for metrics collection only | ||
31 | oneway void OnPnoScanOverOffloadFailed(int reason); | ||
23 | } | 32 | } |
diff --git a/scanning/offload/offload_scan_manager.cpp b/scanning/offload/offload_scan_manager.cpp index 5e3d90d..420c2fa 100644 --- a/scanning/offload/offload_scan_manager.cpp +++ b/scanning/offload/offload_scan_manager.cpp | |||
@@ -35,11 +35,11 @@ using android::hardware::wifi::offload::V1_0::OffloadStatus; | |||
35 | using android::hardware::wifi::offload::V1_0::OffloadStatusCode; | 35 | using android::hardware::wifi::offload::V1_0::OffloadStatusCode; |
36 | 36 | ||
37 | using android::wificond::OffloadCallback; | 37 | using android::wificond::OffloadCallback; |
38 | using android::wificond::OnNativeScanResultsReadyHandler; | ||
39 | using ::com::android::server::wifi::wificond::NativeScanResult; | 38 | using ::com::android::server::wifi::wificond::NativeScanResult; |
40 | using ::com::android::server::wifi::wificond::NativeScanStats; | 39 | using ::com::android::server::wifi::wificond::NativeScanStats; |
41 | using std::vector; | 40 | using std::vector; |
42 | using std::weak_ptr; | 41 | using std::weak_ptr; |
42 | using std::shared_ptr; | ||
43 | 43 | ||
44 | using namespace std::placeholders; | 44 | using namespace std::placeholders; |
45 | 45 | ||
@@ -69,55 +69,77 @@ void OffloadCallbackHandlersImpl::OnErrorHandler(const OffloadStatus& status) { | |||
69 | } | 69 | } |
70 | } | 70 | } |
71 | 71 | ||
72 | OffloadScanManager::OffloadScanManager(weak_ptr<OffloadServiceUtils> utils, | 72 | OffloadScanManager::OffloadScanManager( |
73 | OnNativeScanResultsReadyHandler handler) | 73 | weak_ptr<OffloadServiceUtils> utils, |
74 | shared_ptr<OffloadScanCallbackInterface> callback) | ||
74 | : wifi_offload_hal_(nullptr), | 75 | : wifi_offload_hal_(nullptr), |
75 | wifi_offload_callback_(nullptr), | 76 | wifi_offload_callback_(nullptr), |
77 | death_recipient_(nullptr), | ||
76 | offload_status_(OffloadScanManager::kError), | 78 | offload_status_(OffloadScanManager::kError), |
77 | subscription_enabled_(false), | 79 | service_available_(false), |
80 | offload_service_utils_(utils), | ||
78 | offload_callback_handlers_(new OffloadCallbackHandlersImpl(this)), | 81 | offload_callback_handlers_(new OffloadCallbackHandlersImpl(this)), |
79 | scan_result_handler_(handler) { | 82 | event_callback_(callback) { |
80 | auto offload_scan_utils = utils.lock(); | 83 | if (InitService()) { |
81 | if (scan_result_handler_ == nullptr) { | 84 | offload_status_ = OffloadScanManager::kNoError; |
82 | LOG(ERROR) << "Invalid Offload scan result handler"; | ||
83 | return; | ||
84 | } | 85 | } |
85 | wifi_offload_hal_ = offload_scan_utils->GetOffloadService(); | 86 | } |
87 | |||
88 | bool OffloadScanManager::InitService() { | ||
89 | wifi_offload_hal_ = offload_service_utils_.lock()->GetOffloadService(); | ||
86 | if (wifi_offload_hal_ == nullptr) { | 90 | if (wifi_offload_hal_ == nullptr) { |
87 | LOG(ERROR) << "No Offload Service available"; | 91 | LOG(ERROR) << "No Offload Service available"; |
88 | return; | 92 | return false; |
89 | } | 93 | } |
90 | 94 | ||
91 | death_recipient_ = offload_scan_utils->GetOffloadDeathRecipient( | 95 | death_recipient_ = offload_service_utils_.lock()->GetOffloadDeathRecipient( |
92 | std::bind(&OffloadScanManager::OnObjectDeath, this, _1)); | 96 | std::bind(&OffloadScanManager::OnObjectDeath, this, _1)); |
93 | uint64_t cookie = reinterpret_cast<uint64_t>(wifi_offload_hal_.get()); | 97 | uint64_t cookie = reinterpret_cast<uint64_t>(wifi_offload_hal_.get()); |
98 | |||
94 | auto link_to_death_status = | 99 | auto link_to_death_status = |
95 | wifi_offload_hal_->linkToDeath(death_recipient_, cookie); | 100 | wifi_offload_hal_->linkToDeath(death_recipient_, cookie); |
96 | if (!link_to_death_status.isOk()) { | 101 | if (!link_to_death_status.isOk()) { |
97 | LOG(ERROR) << "Unable to register death handler " | 102 | LOG(ERROR) << "Unable to register death handler " |
98 | << link_to_death_status.description(); | 103 | << link_to_death_status.description(); |
99 | return; | 104 | return false; |
100 | } | 105 | } |
101 | 106 | ||
102 | wifi_offload_callback_ = | 107 | wifi_offload_callback_ = offload_service_utils_.lock()->GetOffloadCallback( |
103 | offload_scan_utils->GetOffloadCallback(offload_callback_handlers_.get()); | 108 | offload_callback_handlers_.get()); |
104 | if (wifi_offload_callback_ == nullptr) { | 109 | if (wifi_offload_callback_ == nullptr) { |
105 | LOG(ERROR) << "Invalid Offload callback object"; | 110 | LOG(ERROR) << "Invalid Offload callback object"; |
106 | return; | 111 | return false; |
107 | } | 112 | } |
108 | wifi_offload_hal_->setEventCallback(wifi_offload_callback_); | 113 | |
109 | offload_status_ = OffloadScanManager::kNoError; | 114 | auto set_callback_status = |
115 | wifi_offload_hal_->setEventCallback(wifi_offload_callback_); | ||
116 | if (!set_callback_status.isOk()) { | ||
117 | LOG(ERROR) << "Unable to set event callback for Offload HAL"; | ||
118 | return false; | ||
119 | } | ||
120 | |||
121 | service_available_ = true; | ||
122 | return true; | ||
123 | } | ||
124 | |||
125 | bool OffloadScanManager::InitServiceIfNeeded() { | ||
126 | if (!service_available_) { | ||
127 | return InitService(); | ||
128 | } | ||
129 | return true; | ||
110 | } | 130 | } |
111 | 131 | ||
112 | bool OffloadScanManager::stopScan(OffloadScanManager::ReasonCode* reason_code) { | 132 | bool OffloadScanManager::stopScan(OffloadScanManager::ReasonCode* reason_code) { |
113 | if (!subscription_enabled_) { | 133 | if (!InitServiceIfNeeded() || |
114 | LOG(VERBOSE) << "Scans are not subscribed over Offload HAL"; | 134 | (getOffloadStatus() != OffloadScanManager::kNoError)) { |
115 | *reason_code = OffloadScanManager::kNotSubscribed; | 135 | *reason_code = OffloadScanManager::kNotAvailable; |
116 | return false; | 136 | return false; |
117 | } | 137 | } |
118 | if (wifi_offload_hal_ != nullptr) { | 138 | const auto& res = wifi_offload_hal_->unsubscribeScanResults(); |
119 | wifi_offload_hal_->unsubscribeScanResults(); | 139 | if (!res.isOk()) { |
120 | subscription_enabled_ = false; | 140 | *reason_code = OffloadScanManager::kTransactionFailed; |
141 | LOG(WARNING) << "unsubscribeScanResults() failed " << res.description(); | ||
142 | return false; | ||
121 | } | 143 | } |
122 | *reason_code = OffloadScanManager::kNone; | 144 | *reason_code = OffloadScanManager::kNone; |
123 | return true; | 145 | return true; |
@@ -163,7 +185,8 @@ bool OffloadScanManager::startScan( | |||
163 | const vector<vector<uint8_t>>& match_ssids, | 185 | const vector<vector<uint8_t>>& match_ssids, |
164 | const vector<uint8_t>& match_security, const vector<uint32_t>& freqs, | 186 | const vector<uint8_t>& match_security, const vector<uint32_t>& freqs, |
165 | OffloadScanManager::ReasonCode* reason_code) { | 187 | OffloadScanManager::ReasonCode* reason_code) { |
166 | if (getOffloadStatus() != OffloadScanManager::kNoError) { | 188 | if (!InitServiceIfNeeded() || |
189 | getOffloadStatus() != OffloadScanManager::kNoError) { | ||
167 | *reason_code = OffloadScanManager::kNotAvailable; | 190 | *reason_code = OffloadScanManager::kNotAvailable; |
168 | LOG(WARNING) << "Offload HAL scans are not available"; | 191 | LOG(WARNING) << "Offload HAL scans are not available"; |
169 | return false; | 192 | return false; |
@@ -177,12 +200,13 @@ bool OffloadScanManager::startScan( | |||
177 | return false; | 200 | return false; |
178 | } | 201 | } |
179 | 202 | ||
180 | if (!subscription_enabled_ && !SubscribeScanResults(reason_code)) { | 203 | if (!SubscribeScanResults(reason_code)) { |
181 | return false; | 204 | return false; |
182 | } | 205 | } |
183 | 206 | ||
184 | subscription_enabled_ = true; | ||
185 | *reason_code = OffloadScanManager::kNone; | 207 | *reason_code = OffloadScanManager::kNone; |
208 | /* Clear up the scan cache every time a new scan is requested */ | ||
209 | cached_scan_results_.clear(); | ||
186 | return true; | 210 | return true; |
187 | } | 211 | } |
188 | 212 | ||
@@ -208,13 +232,25 @@ bool OffloadScanManager::SubscribeScanResults( | |||
208 | } | 232 | } |
209 | 233 | ||
210 | OffloadScanManager::StatusCode OffloadScanManager::getOffloadStatus() const { | 234 | OffloadScanManager::StatusCode OffloadScanManager::getOffloadStatus() const { |
211 | if (wifi_offload_hal_ == nullptr) { | 235 | if (!service_available_) { |
212 | return OffloadScanManager::kNoService; | 236 | return OffloadScanManager::kNoService; |
213 | } | 237 | } |
214 | return offload_status_; | 238 | return offload_status_; |
215 | } | 239 | } |
216 | 240 | ||
241 | bool OffloadScanManager::getScanResults( | ||
242 | std::vector<NativeScanResult>* out_scan_results) { | ||
243 | for (auto scan_result : cached_scan_results_) { | ||
244 | out_scan_results->push_back(scan_result); | ||
245 | } | ||
246 | return true; | ||
247 | } | ||
248 | |||
217 | bool OffloadScanManager::getScanStats(NativeScanStats* native_scan_stats) { | 249 | bool OffloadScanManager::getScanStats(NativeScanStats* native_scan_stats) { |
250 | if (!InitServiceIfNeeded()) { | ||
251 | LOG(ERROR) << "Offload HAL service unavailable"; | ||
252 | return false; | ||
253 | } | ||
218 | if (getOffloadStatus() != OffloadScanManager::kNoError) { | 254 | if (getOffloadStatus() != OffloadScanManager::kNoError) { |
219 | LOG(WARNING) << "Unable to get scan stats due to Wifi Offload HAL error"; | 255 | LOG(WARNING) << "Unable to get scan stats due to Wifi Offload HAL error"; |
220 | return false; | 256 | return false; |
@@ -230,11 +266,13 @@ OffloadScanManager::~OffloadScanManager() { | |||
230 | 266 | ||
231 | void OffloadScanManager::ReportScanResults( | 267 | void OffloadScanManager::ReportScanResults( |
232 | const vector<ScanResult>& scanResult) { | 268 | const vector<ScanResult>& scanResult) { |
233 | if (scan_result_handler_ != nullptr) { | 269 | cached_scan_results_ = |
234 | scan_result_handler_( | 270 | OffloadScanUtils::convertToNativeScanResults(scanResult); |
235 | OffloadScanUtils::convertToNativeScanResults(scanResult)); | 271 | if (event_callback_ != nullptr) { |
272 | event_callback_->OnOffloadScanResult(); | ||
236 | } else { | 273 | } else { |
237 | LOG(ERROR) << "No scan result handler for Offload ScanManager"; | 274 | LOG(WARNING) |
275 | << "No callback to report Offload HAL's scan results to wificond"; | ||
238 | } | 276 | } |
239 | } | 277 | } |
240 | 278 | ||
@@ -260,14 +298,29 @@ void OffloadScanManager::ReportError(const OffloadStatus& status) { | |||
260 | } | 298 | } |
261 | if (status_result != OffloadScanManager::kNoError) { | 299 | if (status_result != OffloadScanManager::kNoError) { |
262 | LOG(WARNING) << "Offload Error reported " << status.description; | 300 | LOG(WARNING) << "Offload Error reported " << status.description; |
301 | if (event_callback_ != nullptr) { | ||
302 | event_callback_->OnOffloadError( | ||
303 | OffloadScanCallbackInterface::REMOTE_FAILURE); | ||
304 | } else { | ||
305 | LOG(WARNING) << "No callback to report Offload HAL Errors to wificond"; | ||
306 | } | ||
263 | } | 307 | } |
264 | offload_status_ = status_result; | 308 | offload_status_ = status_result; |
265 | } | 309 | } |
266 | 310 | ||
267 | void OffloadScanManager::OnObjectDeath(uint64_t cookie) { | 311 | void OffloadScanManager::OnObjectDeath(uint64_t cookie) { |
268 | if (wifi_offload_hal_ == reinterpret_cast<IOffload*>(cookie)) { | 312 | if (wifi_offload_hal_ == reinterpret_cast<IOffload*>(cookie)) { |
269 | wifi_offload_hal_.clear(); | ||
270 | LOG(ERROR) << "Death Notification for Wifi Offload HAL"; | 313 | LOG(ERROR) << "Death Notification for Wifi Offload HAL"; |
314 | wifi_offload_hal_.clear(); | ||
315 | if (event_callback_ != nullptr) { | ||
316 | event_callback_->OnOffloadError( | ||
317 | OffloadScanCallbackInterface::BINDER_DEATH); | ||
318 | } else { | ||
319 | LOG(WARNING) | ||
320 | << "No callback to report Offload HAL Binder death to wificond"; | ||
321 | } | ||
322 | service_available_ = false; | ||
323 | death_recipient_.clear(); | ||
271 | } | 324 | } |
272 | } | 325 | } |
273 | 326 | ||
diff --git a/scanning/offload/offload_scan_manager.h b/scanning/offload/offload_scan_manager.h index e2c2b0c..9cc3d47 100644 --- a/scanning/offload/offload_scan_manager.h +++ b/scanning/offload/offload_scan_manager.h | |||
@@ -20,6 +20,7 @@ | |||
20 | #include "wificond/scanning/offload/offload_callback.h" | 20 | #include "wificond/scanning/offload/offload_callback.h" |
21 | #include "wificond/scanning/offload/offload_callback_handlers.h" | 21 | #include "wificond/scanning/offload/offload_callback_handlers.h" |
22 | #include "wificond/scanning/offload/offload_service_utils.h" | 22 | #include "wificond/scanning/offload/offload_service_utils.h" |
23 | #include "wificond/scanning/offload_scan_callback_interface.h" | ||
23 | 24 | ||
24 | #include <vector> | 25 | #include <vector> |
25 | 26 | ||
@@ -43,11 +44,6 @@ namespace wificond { | |||
43 | 44 | ||
44 | class OffloadScanManager; | 45 | class OffloadScanManager; |
45 | 46 | ||
46 | typedef std::function<void( | ||
47 | const std::vector<::com::android::server::wifi::wificond::NativeScanResult> | ||
48 | scanResult)> | ||
49 | OnNativeScanResultsReadyHandler; | ||
50 | |||
51 | // Provides callback interface implementation from Offload HAL | 47 | // Provides callback interface implementation from Offload HAL |
52 | class OffloadCallbackHandlersImpl : public OffloadCallbackHandlers { | 48 | class OffloadCallbackHandlersImpl : public OffloadCallbackHandlers { |
53 | public: | 49 | public: |
@@ -86,21 +82,19 @@ class OffloadScanManager { | |||
86 | kNone, | 82 | kNone, |
87 | /* Offload HAL scans is not available */ | 83 | /* Offload HAL scans is not available */ |
88 | kNotAvailable, | 84 | kNotAvailable, |
89 | /* Offload HAL service is not subscribed to */ | ||
90 | kNotSubscribed, | ||
91 | /* Offload HAL requested operation failure */ | 85 | /* Offload HAL requested operation failure */ |
92 | kOperationFailed, | 86 | kOperationFailed, |
93 | /* Binder failed to deliver message to Offload HAL*/ | 87 | /* Binder failed to deliver message to Offload HAL*/ |
94 | kTransactionFailed, | 88 | kTransactionFailed, |
95 | }; | 89 | }; |
96 | 90 | ||
97 | explicit OffloadScanManager(std::weak_ptr<OffloadServiceUtils> utils, | 91 | explicit OffloadScanManager( |
98 | OnNativeScanResultsReadyHandler handler); | 92 | std::weak_ptr<OffloadServiceUtils> utils, |
93 | std::shared_ptr<OffloadScanCallbackInterface> callback); | ||
99 | virtual ~OffloadScanManager(); | 94 | virtual ~OffloadScanManager(); |
100 | /* Request start of offload scans with scan parameters and scan filter | 95 | /* Request start of offload scans with scan parameters and scan filter |
101 | * settings. Internally calls Offload HAL service with configureScans() | 96 | * settings. Internally calls Offload HAL service with configureScans() |
102 | * and subscribeScanResults() APIs. If already subscribed, it updates | 97 | * and subscribeScanResults() APIs. Reason code indicates failure reason. |
103 | * the scan configuration only. Reason code is updated in failure case | ||
104 | */ | 98 | */ |
105 | bool startScan(uint32_t /* interval_ms */, int32_t /* rssi_threshold */, | 99 | bool startScan(uint32_t /* interval_ms */, int32_t /* rssi_threshold */, |
106 | const std::vector<std::vector<uint8_t>>& /* scan_ssids */, | 100 | const std::vector<std::vector<uint8_t>>& /* scan_ssids */, |
@@ -108,9 +102,8 @@ class OffloadScanManager { | |||
108 | const std::vector<uint8_t>& /* match_security */, | 102 | const std::vector<uint8_t>& /* match_security */, |
109 | const std::vector<uint32_t>& /* freqs */, | 103 | const std::vector<uint32_t>& /* freqs */, |
110 | ReasonCode* /* failure reason */); | 104 | ReasonCode* /* failure reason */); |
111 | /* Request stop of offload scans, returns true if scans were subscribed | 105 | /* Request stop of offload scans, returns true if the operation succeeds |
112 | * to from the Offload HAL service. Otherwise, returns false. Reason code | 106 | * Otherwise, returns false. Reason code is updated in case of failure. |
113 | * is updated in case of failure. | ||
114 | */ | 107 | */ |
115 | bool stopScan(ReasonCode* /* failure reason */); | 108 | bool stopScan(ReasonCode* /* failure reason */); |
116 | /* Get statistics for scans performed by Offload HAL */ | 109 | /* Get statistics for scans performed by Offload HAL */ |
@@ -118,6 +111,10 @@ class OffloadScanManager { | |||
118 | ::com::android::server::wifi::wificond::NativeScanStats* /* scanStats */); | 111 | ::com::android::server::wifi::wificond::NativeScanStats* /* scanStats */); |
119 | /* Otain status of the Offload HAL service */ | 112 | /* Otain status of the Offload HAL service */ |
120 | StatusCode getOffloadStatus() const; | 113 | StatusCode getOffloadStatus() const; |
114 | /* Returns the most recent scan result available from Offload HAL */ | ||
115 | bool getScanResults( | ||
116 | std::vector<::com::android::server::wifi::wificond::NativeScanResult>* | ||
117 | out_scan_results); | ||
121 | 118 | ||
122 | private: | 119 | private: |
123 | void ReportScanResults( | 120 | void ReportScanResults( |
@@ -135,6 +132,9 @@ class OffloadScanManager { | |||
135 | bool ConfigureScans(android::hardware::wifi::offload::V1_0::ScanParam, | 132 | bool ConfigureScans(android::hardware::wifi::offload::V1_0::ScanParam, |
136 | android::hardware::wifi::offload::V1_0::ScanFilter, | 133 | android::hardware::wifi::offload::V1_0::ScanFilter, |
137 | OffloadScanManager::ReasonCode* reason_code); | 134 | OffloadScanManager::ReasonCode* reason_code); |
135 | bool InitServiceIfNeeded(); | ||
136 | bool InitService(); | ||
137 | |||
138 | /* Handle binder death */ | 138 | /* Handle binder death */ |
139 | void OnObjectDeath(uint64_t /* cookie */); | 139 | void OnObjectDeath(uint64_t /* cookie */); |
140 | 140 | ||
@@ -143,10 +143,13 @@ class OffloadScanManager { | |||
143 | android::sp<OffloadCallback> wifi_offload_callback_; | 143 | android::sp<OffloadCallback> wifi_offload_callback_; |
144 | android::sp<OffloadDeathRecipient> death_recipient_; | 144 | android::sp<OffloadDeathRecipient> death_recipient_; |
145 | StatusCode offload_status_; | 145 | StatusCode offload_status_; |
146 | bool subscription_enabled_; | 146 | std::vector<::com::android::server::wifi::wificond::NativeScanResult> |
147 | cached_scan_results_; | ||
148 | bool service_available_; | ||
147 | 149 | ||
150 | const std::weak_ptr<OffloadServiceUtils> offload_service_utils_; | ||
148 | const std::unique_ptr<OffloadCallbackHandlersImpl> offload_callback_handlers_; | 151 | const std::unique_ptr<OffloadCallbackHandlersImpl> offload_callback_handlers_; |
149 | OnNativeScanResultsReadyHandler scan_result_handler_; | 152 | std::shared_ptr<OffloadScanCallbackInterface> event_callback_; |
150 | 153 | ||
151 | friend class OffloadCallbackHandlersImpl; | 154 | friend class OffloadCallbackHandlersImpl; |
152 | }; | 155 | }; |
diff --git a/scanning/offload/offload_service_utils.cpp b/scanning/offload/offload_service_utils.cpp index 2a14a32..a4a2474 100644 --- a/scanning/offload/offload_service_utils.cpp +++ b/scanning/offload/offload_service_utils.cpp | |||
@@ -14,6 +14,9 @@ | |||
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | #include "wificond/scanning/offload/offload_service_utils.h" | 16 | #include "wificond/scanning/offload/offload_service_utils.h" |
17 | |||
18 | #include <android-base/logging.h> | ||
19 | |||
17 | #include "wificond/scanning/offload/offload_scan_manager.h" | 20 | #include "wificond/scanning/offload/offload_scan_manager.h" |
18 | 21 | ||
19 | using ::android::hardware::wifi::offload::V1_0::IOffload; | 22 | using ::android::hardware::wifi::offload::V1_0::IOffload; |
@@ -22,7 +25,7 @@ namespace android { | |||
22 | namespace wificond { | 25 | namespace wificond { |
23 | 26 | ||
24 | android::sp<IOffload> OffloadServiceUtils::GetOffloadService() { | 27 | android::sp<IOffload> OffloadServiceUtils::GetOffloadService() { |
25 | return IOffload::getService(); | 28 | return IOffload::tryGetService(); |
26 | } | 29 | } |
27 | 30 | ||
28 | android::sp<OffloadCallback> OffloadServiceUtils::GetOffloadCallback( | 31 | android::sp<OffloadCallback> OffloadServiceUtils::GetOffloadCallback( |
diff --git a/scanning/offload_scan_callback_interface.h b/scanning/offload_scan_callback_interface.h new file mode 100644 index 0000000..507a69f --- /dev/null +++ b/scanning/offload_scan_callback_interface.h | |||
@@ -0,0 +1,42 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2017 The Android Open Source Project | ||
3 | * | ||
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | * you may not use this file except in compliance with the License. | ||
6 | * You may obtain a copy of the License at | ||
7 | * | ||
8 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | * | ||
10 | * Unless required by applicable law or agreed to in writing, software | ||
11 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | * See the License for the specific language governing permissions and | ||
14 | * limitations under the License. | ||
15 | */ | ||
16 | #ifndef ANDROID_WIFICOND_OFFLOAD_SCAN_CALLBACK_INTERFACE_H | ||
17 | #define ANDROID_WIFICOND_OFFLOAD_SCAN_CALLBACK_INTERFACE_H | ||
18 | |||
19 | #include <vector> | ||
20 | |||
21 | #include "wificond/scanning/scan_result.h" | ||
22 | |||
23 | namespace android { | ||
24 | namespace wificond { | ||
25 | |||
26 | class OffloadScanCallbackInterface { | ||
27 | public: | ||
28 | enum AsyncErrorReason { | ||
29 | BINDER_DEATH = 0, | ||
30 | REMOTE_FAILURE, | ||
31 | }; | ||
32 | |||
33 | virtual ~OffloadScanCallbackInterface() {} | ||
34 | |||
35 | virtual void OnOffloadScanResult() = 0; | ||
36 | virtual void OnOffloadError(AsyncErrorReason) = 0; | ||
37 | }; | ||
38 | |||
39 | } // namespace wificond | ||
40 | } // namespace android | ||
41 | |||
42 | #endif // ANDROID_WIFICOND_OFFLOAD_SCAN_CALLBACK_INTERFACE_H | ||
diff --git a/scanning/offload_scan_callback_interface_impl.cpp b/scanning/offload_scan_callback_interface_impl.cpp new file mode 100644 index 0000000..a3e39da --- /dev/null +++ b/scanning/offload_scan_callback_interface_impl.cpp | |||
@@ -0,0 +1,42 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2016 The Android Open Source Project | ||
3 | * | ||
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | * you may not use this file except in compliance with the License. | ||
6 | * You may obtain a copy of the License at | ||
7 | * | ||
8 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | * | ||
10 | * Unless required by applicable law or agreed to in writing, software | ||
11 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | * See the License for the specific language governing permissions and | ||
14 | * limitations under the License. | ||
15 | */ | ||
16 | |||
17 | #include "wificond/scanning/offload_scan_callback_interface_impl.h" | ||
18 | |||
19 | #include <android-base/logging.h> | ||
20 | |||
21 | using com::android::server::wifi::wificond::NativeScanResult; | ||
22 | |||
23 | namespace android { | ||
24 | namespace wificond { | ||
25 | |||
26 | OffloadScanCallbackInterfaceImpl::OffloadScanCallbackInterfaceImpl( | ||
27 | ScannerImpl* parent) | ||
28 | : scanner_impl_(parent) {} | ||
29 | |||
30 | OffloadScanCallbackInterfaceImpl::~OffloadScanCallbackInterfaceImpl() {} | ||
31 | |||
32 | void OffloadScanCallbackInterfaceImpl::OnOffloadScanResult() { | ||
33 | scanner_impl_->OnOffloadScanResult(); | ||
34 | } | ||
35 | |||
36 | void OffloadScanCallbackInterfaceImpl::OnOffloadError( | ||
37 | OffloadScanCallbackInterface::AsyncErrorReason error_code) { | ||
38 | scanner_impl_->OnOffloadError(error_code); | ||
39 | } | ||
40 | |||
41 | } // namespace wificond | ||
42 | } // namespace android | ||
diff --git a/scanning/offload_scan_callback_interface_impl.h b/scanning/offload_scan_callback_interface_impl.h new file mode 100644 index 0000000..0f500a4 --- /dev/null +++ b/scanning/offload_scan_callback_interface_impl.h | |||
@@ -0,0 +1,44 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2016 The Android Open Source Project | ||
3 | * | ||
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | * you may not use this file except in compliance with the License. | ||
6 | * You may obtain a copy of the License at | ||
7 | * | ||
8 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | * | ||
10 | * Unless required by applicable law or agreed to in writing, software | ||
11 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | * See the License for the specific language governing permissions and | ||
14 | * limitations under the License. | ||
15 | */ | ||
16 | |||
17 | #ifndef WIFICOND_SCANNER_OFFLOAD_SCAN_CALLBACK_INTERFACE_IML_H_ | ||
18 | #define WIFICOND_SCANNER_OFFLOAD_SCAN_CALLBACK_INTERFACE_IML_H_ | ||
19 | |||
20 | #include "wificond/scanning/offload_scan_callback_interface.h" | ||
21 | #include "wificond/scanning/scanner_impl.h" | ||
22 | |||
23 | namespace android { | ||
24 | namespace wificond { | ||
25 | |||
26 | class ScannerImpl; | ||
27 | |||
28 | class OffloadScanCallbackInterfaceImpl | ||
29 | : public android::wificond::OffloadScanCallbackInterface { | ||
30 | public: | ||
31 | OffloadScanCallbackInterfaceImpl(ScannerImpl* parent); | ||
32 | ~OffloadScanCallbackInterfaceImpl() override; | ||
33 | |||
34 | void OnOffloadScanResult() override; | ||
35 | void OnOffloadError(OffloadScanCallbackInterface::AsyncErrorReason) override; | ||
36 | |||
37 | private: | ||
38 | ScannerImpl* scanner_impl_; | ||
39 | }; | ||
40 | |||
41 | } // namespace wificond | ||
42 | } // namespace android | ||
43 | |||
44 | #endif // WIFICOND_SCANNER_OFFLOAD_SCAN_CALLBACK_INTERFACE_IML_H_ | ||
diff --git a/scanning/scanner_impl.cpp b/scanning/scanner_impl.cpp index 9bf13b3..e9ff517 100644 --- a/scanning/scanner_impl.cpp +++ b/scanning/scanner_impl.cpp | |||
@@ -22,9 +22,9 @@ | |||
22 | #include <android-base/logging.h> | 22 | #include <android-base/logging.h> |
23 | 23 | ||
24 | #include "wificond/client_interface_impl.h" | 24 | #include "wificond/client_interface_impl.h" |
25 | #include "wificond/scanning/scan_utils.h" | ||
26 | #include "wificond/scanning/offload/offload_service_utils.h" | ||
27 | #include "wificond/scanning/offload/offload_scan_manager.h" | 25 | #include "wificond/scanning/offload/offload_scan_manager.h" |
26 | #include "wificond/scanning/offload/offload_service_utils.h" | ||
27 | #include "wificond/scanning/scan_utils.h" | ||
28 | 28 | ||
29 | using android::binder::Status; | 29 | using android::binder::Status; |
30 | using android::net::wifi::IPnoScanEvent; | 30 | using android::net::wifi::IPnoScanEvent; |
@@ -39,19 +39,18 @@ using std::pair; | |||
39 | using std::string; | 39 | using std::string; |
40 | using std::vector; | 40 | using std::vector; |
41 | using std::weak_ptr; | 41 | using std::weak_ptr; |
42 | using std::shared_ptr; | ||
42 | 43 | ||
43 | using namespace std::placeholders; | 44 | using namespace std::placeholders; |
44 | 45 | ||
45 | namespace android { | 46 | namespace android { |
46 | namespace wificond { | 47 | namespace wificond { |
47 | 48 | ||
48 | ScannerImpl::ScannerImpl(uint32_t wiphy_index, | 49 | ScannerImpl::ScannerImpl(uint32_t wiphy_index, uint32_t interface_index, |
49 | uint32_t interface_index, | ||
50 | const ScanCapabilities& scan_capabilities, | 50 | const ScanCapabilities& scan_capabilities, |
51 | const WiphyFeatures& wiphy_features, | 51 | const WiphyFeatures& wiphy_features, |
52 | ClientInterfaceImpl* client_interface, | 52 | ClientInterfaceImpl* client_interface, |
53 | NetlinkUtils* netlink_utils, | 53 | NetlinkUtils* netlink_utils, ScanUtils* scan_utils, |
54 | ScanUtils* scan_utils, | ||
55 | weak_ptr<OffloadServiceUtils> offload_service_utils) | 54 | weak_ptr<OffloadServiceUtils> offload_service_utils) |
56 | : valid_(true), | 55 | : valid_(true), |
57 | scan_started_(false), | 56 | scan_started_(false), |
@@ -70,25 +69,23 @@ ScannerImpl::ScannerImpl(uint32_t wiphy_index, | |||
70 | << (int)interface_index_; | 69 | << (int)interface_index_; |
71 | scan_utils_->SubscribeScanResultNotification( | 70 | scan_utils_->SubscribeScanResultNotification( |
72 | interface_index_, | 71 | interface_index_, |
73 | std::bind(&ScannerImpl::OnScanResultsReady, | 72 | std::bind(&ScannerImpl::OnScanResultsReady, this, _1, _2, _3, _4)); |
74 | this, | ||
75 | _1, _2, _3, _4)); | ||
76 | // Subscribe scheduled scan result notification from kernel. | 73 | // Subscribe scheduled scan result notification from kernel. |
77 | scan_utils_->SubscribeSchedScanResultNotification( | 74 | scan_utils_->SubscribeSchedScanResultNotification( |
78 | interface_index_, | 75 | interface_index_, |
79 | std::bind(&ScannerImpl::OnSchedScanResultsReady, | 76 | std::bind(&ScannerImpl::OnSchedScanResultsReady, |
80 | this, | 77 | this, |
81 | _1, _2)); | 78 | _1, _2)); |
82 | offload_scan_manager_.reset( | 79 | std::shared_ptr<OffloadScanCallbackInterfaceImpl> |
83 | new OffloadScanManager( | 80 | offload_scan_callback_interface = |
84 | offload_service_utils, | 81 | std::make_shared<OffloadScanCallbackInterfaceImpl>( |
85 | std::bind(&ScannerImpl::OnOffloadScanResult, | 82 | *(new OffloadScanCallbackInterfaceImpl(this))); |
86 | this, _1))); | 83 | offload_scan_manager_.reset(new OffloadScanManager( |
84 | offload_service_utils, offload_scan_callback_interface)); | ||
87 | offload_scan_supported_ = offload_service_utils.lock()->IsOffloadScanSupported(); | 85 | offload_scan_supported_ = offload_service_utils.lock()->IsOffloadScanSupported(); |
88 | } | 86 | } |
89 | 87 | ||
90 | ScannerImpl::~ScannerImpl() { | 88 | ScannerImpl::~ScannerImpl() {} |
91 | } | ||
92 | 89 | ||
93 | void ScannerImpl::Invalidate() { | 90 | void ScannerImpl::Invalidate() { |
94 | LOG(INFO) << "Unsubscribe scan result for interface with index: " | 91 | LOG(INFO) << "Unsubscribe scan result for interface with index: " |
@@ -111,17 +108,15 @@ Status ScannerImpl::getAvailable2gChannels( | |||
111 | return Status::ok(); | 108 | return Status::ok(); |
112 | } | 109 | } |
113 | BandInfo band_info; | 110 | BandInfo band_info; |
114 | if (!netlink_utils_->GetWiphyInfo(wiphy_index_, | 111 | if (!netlink_utils_->GetWiphyInfo(wiphy_index_, &band_info, |
115 | &band_info, | 112 | &scan_capabilities_, &wiphy_features_)) { |
116 | &scan_capabilities_, | ||
117 | &wiphy_features_)) { | ||
118 | LOG(ERROR) << "Failed to get wiphy info from kernel"; | 113 | LOG(ERROR) << "Failed to get wiphy info from kernel"; |
119 | out_frequencies->reset(nullptr); | 114 | out_frequencies->reset(nullptr); |
120 | return Status::ok(); | 115 | return Status::ok(); |
121 | } | 116 | } |
122 | 117 | ||
123 | out_frequencies->reset(new vector<int32_t>(band_info.band_2g.begin(), | 118 | out_frequencies->reset( |
124 | band_info.band_2g.end())); | 119 | new vector<int32_t>(band_info.band_2g.begin(), band_info.band_2g.end())); |
125 | return Status::ok(); | 120 | return Status::ok(); |
126 | } | 121 | } |
127 | 122 | ||
@@ -131,17 +126,15 @@ Status ScannerImpl::getAvailable5gNonDFSChannels( | |||
131 | return Status::ok(); | 126 | return Status::ok(); |
132 | } | 127 | } |
133 | BandInfo band_info; | 128 | BandInfo band_info; |
134 | if (!netlink_utils_->GetWiphyInfo(wiphy_index_, | 129 | if (!netlink_utils_->GetWiphyInfo(wiphy_index_, &band_info, |
135 | &band_info, | 130 | &scan_capabilities_, &wiphy_features_)) { |
136 | &scan_capabilities_, | ||
137 | &wiphy_features_)) { | ||
138 | LOG(ERROR) << "Failed to get wiphy info from kernel"; | 131 | LOG(ERROR) << "Failed to get wiphy info from kernel"; |
139 | out_frequencies->reset(nullptr); | 132 | out_frequencies->reset(nullptr); |
140 | return Status::ok(); | 133 | return Status::ok(); |
141 | } | 134 | } |
142 | 135 | ||
143 | out_frequencies->reset(new vector<int32_t>(band_info.band_5g.begin(), | 136 | out_frequencies->reset( |
144 | band_info.band_5g.end())); | 137 | new vector<int32_t>(band_info.band_5g.begin(), band_info.band_5g.end())); |
145 | return Status::ok(); | 138 | return Status::ok(); |
146 | } | 139 | } |
147 | 140 | ||
@@ -151,10 +144,8 @@ Status ScannerImpl::getAvailableDFSChannels( | |||
151 | return Status::ok(); | 144 | return Status::ok(); |
152 | } | 145 | } |
153 | BandInfo band_info; | 146 | BandInfo band_info; |
154 | if (!netlink_utils_->GetWiphyInfo(wiphy_index_, | 147 | if (!netlink_utils_->GetWiphyInfo(wiphy_index_, &band_info, |
155 | &band_info, | 148 | &scan_capabilities_, &wiphy_features_)) { |
156 | &scan_capabilities_, | ||
157 | &wiphy_features_)) { | ||
158 | LOG(ERROR) << "Failed to get wiphy info from kernel"; | 149 | LOG(ERROR) << "Failed to get wiphy info from kernel"; |
159 | out_frequencies->reset(nullptr); | 150 | out_frequencies->reset(nullptr); |
160 | return Status::ok(); | 151 | return Status::ok(); |
@@ -186,8 +177,8 @@ Status ScannerImpl::scan(const SingleScanSettings& scan_settings, | |||
186 | LOG(WARNING) << "Scan already started"; | 177 | LOG(WARNING) << "Scan already started"; |
187 | } | 178 | } |
188 | // Only request MAC address randomization when station is not associated. | 179 | // Only request MAC address randomization when station is not associated. |
189 | bool request_random_mac = wiphy_features_.supports_random_mac_oneshot_scan && | 180 | bool request_random_mac = wiphy_features_.supports_random_mac_oneshot_scan && |
190 | !client_interface_->IsAssociated(); | 181 | !client_interface_->IsAssociated(); |
191 | 182 | ||
192 | // Initialize it with an empty ssid for a wild card scan. | 183 | // Initialize it with an empty ssid for a wild card scan. |
193 | vector<vector<uint8_t>> ssids = {{}}; | 184 | vector<vector<uint8_t>> ssids = {{}}; |
@@ -222,11 +213,12 @@ Status ScannerImpl::scan(const SingleScanSettings& scan_settings, | |||
222 | 213 | ||
223 | Status ScannerImpl::startPnoScan(const PnoSettings& pno_settings, | 214 | Status ScannerImpl::startPnoScan(const PnoSettings& pno_settings, |
224 | bool* out_success) { | 215 | bool* out_success) { |
225 | if (!offload_scan_supported_ || !StartPnoScanOffload(pno_settings)) { | 216 | pno_settings_ = pno_settings; |
226 | *out_success = StartPnoScanDefault(pno_settings); | 217 | if (offload_scan_supported_ && StartPnoScanOffload(pno_settings)) { |
227 | } else { | ||
228 | // scanning over offload succeeded | 218 | // scanning over offload succeeded |
229 | *out_success = true; | 219 | *out_success = true; |
220 | } else { | ||
221 | *out_success = StartPnoScanDefault(pno_settings); | ||
230 | } | 222 | } |
231 | return Status::ok(); | 223 | return Status::ok(); |
232 | } | 224 | } |
@@ -239,25 +231,28 @@ bool ScannerImpl::StartPnoScanOffload(const PnoSettings& pno_settings) { | |||
239 | // Empty frequency list: scan all frequencies. | 231 | // Empty frequency list: scan all frequencies. |
240 | vector<uint32_t> freqs; | 232 | vector<uint32_t> freqs; |
241 | 233 | ||
242 | ParsePnoSettings(pno_settings, &scan_ssids, &match_ssids, &freqs, &match_security); | 234 | ParsePnoSettings(pno_settings, &scan_ssids, &match_ssids, &freqs, |
243 | 235 | &match_security); | |
244 | bool success = offload_scan_manager_->startScan( | 236 | |
245 | pno_settings.interval_ms_, | 237 | pno_scan_running_over_offload_ = offload_scan_manager_->startScan( |
246 | // TODO: honor both rssi thresholds. | 238 | pno_settings.interval_ms_, |
247 | pno_settings.min_5g_rssi_, | 239 | // TODO: honor both rssi thresholds. |
248 | scan_ssids, | 240 | pno_settings.min_5g_rssi_, scan_ssids, match_ssids, match_security, freqs, |
249 | match_ssids, | 241 | &reason_code); |
250 | match_security, | 242 | if (pno_scan_running_over_offload_) { |
251 | freqs, | 243 | LOG(VERBOSE) << "Pno scans requested over Offload HAL"; |
252 | &reason_code); | 244 | if (pno_scan_event_handler_ != nullptr) { |
253 | return success; | 245 | pno_scan_event_handler_->OnPnoScanOverOffloadStarted(); |
246 | } | ||
247 | } | ||
248 | return pno_scan_running_over_offload_; | ||
254 | } | 249 | } |
255 | 250 | ||
256 | void ScannerImpl::ParsePnoSettings(const PnoSettings& pno_settings, | 251 | void ScannerImpl::ParsePnoSettings(const PnoSettings& pno_settings, |
257 | vector<vector<uint8_t>>* scan_ssids, | 252 | vector<vector<uint8_t>>* scan_ssids, |
258 | vector<vector<uint8_t>>* match_ssids, | 253 | vector<vector<uint8_t>>* match_ssids, |
259 | vector<uint32_t>* freqs, | 254 | vector<uint32_t>* freqs, |
260 | vector<uint8_t>* match_security) { | 255 | vector<uint8_t>* match_security) { |
261 | // TODO provide actionable security match parameters | 256 | // TODO provide actionable security match parameters |
262 | const uint8_t kNetworkFlagsDefault = 0; | 257 | const uint8_t kNetworkFlagsDefault = 0; |
263 | vector<vector<uint8_t>> skipped_scan_ssids; | 258 | vector<vector<uint8_t>> skipped_scan_ssids; |
@@ -266,7 +261,8 @@ void ScannerImpl::ParsePnoSettings(const PnoSettings& pno_settings, | |||
266 | // Add hidden network ssid. | 261 | // Add hidden network ssid. |
267 | if (network.is_hidden_) { | 262 | if (network.is_hidden_) { |
268 | // TODO remove pruning for Offload Scans | 263 | // TODO remove pruning for Offload Scans |
269 | if (scan_ssids->size() + 1 > scan_capabilities_.max_num_sched_scan_ssids) { | 264 | if (scan_ssids->size() + 1 > |
265 | scan_capabilities_.max_num_sched_scan_ssids) { | ||
270 | skipped_scan_ssids.emplace_back(network.ssid_); | 266 | skipped_scan_ssids.emplace_back(network.ssid_); |
271 | continue; | 267 | continue; |
272 | } | 268 | } |
@@ -287,7 +283,7 @@ void ScannerImpl::ParsePnoSettings(const PnoSettings& pno_settings, | |||
287 | 283 | ||
288 | bool ScannerImpl::StartPnoScanDefault(const PnoSettings& pno_settings) { | 284 | bool ScannerImpl::StartPnoScanDefault(const PnoSettings& pno_settings) { |
289 | if (!CheckIsValid()) { | 285 | if (!CheckIsValid()) { |
290 | return false; | 286 | return false; |
291 | } | 287 | } |
292 | if (pno_scan_started_) { | 288 | if (pno_scan_started_) { |
293 | LOG(WARNING) << "Pno scan already started"; | 289 | LOG(WARNING) << "Pno scan already started"; |
@@ -324,18 +320,27 @@ bool ScannerImpl::StartPnoScanDefault(const PnoSettings& pno_settings) { | |||
324 | } | 320 | } |
325 | 321 | ||
326 | Status ScannerImpl::stopPnoScan(bool* out_success) { | 322 | Status ScannerImpl::stopPnoScan(bool* out_success) { |
327 | if (!offload_scan_supported_ || !StopPnoScanOffload()) { | 323 | if (offload_scan_supported_ && StopPnoScanOffload()) { |
328 | *out_success = StopPnoScanDefault(); | ||
329 | } else { | ||
330 | // Pno scans over offload stopped successfully | 324 | // Pno scans over offload stopped successfully |
331 | *out_success = true; | 325 | *out_success = true; |
326 | } else { | ||
327 | // Pno scans were not requested over offload | ||
328 | *out_success = StopPnoScanDefault(); | ||
332 | } | 329 | } |
333 | return Status::ok(); | 330 | return Status::ok(); |
334 | } | 331 | } |
335 | 332 | ||
336 | bool ScannerImpl::StopPnoScanOffload() { | 333 | bool ScannerImpl::StopPnoScanOffload() { |
337 | OffloadScanManager::ReasonCode reason_code; | 334 | OffloadScanManager::ReasonCode reason_code; |
338 | return(offload_scan_manager_->stopScan(&reason_code)); | 335 | if (!pno_scan_running_over_offload_) { |
336 | return false; | ||
337 | } | ||
338 | if (!offload_scan_manager_->stopScan(&reason_code)) { | ||
339 | LOG(WARNING) << "Unable to unsubscribe to Offload scan results"; | ||
340 | } | ||
341 | pno_scan_running_over_offload_ = false; | ||
342 | LOG(VERBOSE) << "Pno scans over Offload stopped"; | ||
343 | return true; | ||
339 | } | 344 | } |
340 | 345 | ||
341 | bool ScannerImpl::StopPnoScanDefault() { | 346 | bool ScannerImpl::StopPnoScanDefault() { |
@@ -387,7 +392,6 @@ Status ScannerImpl::unsubscribeScanEvents() { | |||
387 | return Status::ok(); | 392 | return Status::ok(); |
388 | } | 393 | } |
389 | 394 | ||
390 | |||
391 | Status ScannerImpl::subscribePnoScanEvents(const sp<IPnoScanEvent>& handler) { | 395 | Status ScannerImpl::subscribePnoScanEvents(const sp<IPnoScanEvent>& handler) { |
392 | if (!CheckIsValid()) { | 396 | if (!CheckIsValid()) { |
393 | return Status::ok(); | 397 | return Status::ok(); |
@@ -407,11 +411,9 @@ Status ScannerImpl::unsubscribePnoScanEvents() { | |||
407 | return Status::ok(); | 411 | return Status::ok(); |
408 | } | 412 | } |
409 | 413 | ||
410 | void ScannerImpl::OnScanResultsReady( | 414 | void ScannerImpl::OnScanResultsReady(uint32_t interface_index, bool aborted, |
411 | uint32_t interface_index, | 415 | vector<vector<uint8_t>>& ssids, |
412 | bool aborted, | 416 | vector<uint32_t>& frequencies) { |
413 | vector<vector<uint8_t>>& ssids, | ||
414 | vector<uint32_t>& frequencies) { | ||
415 | if (!scan_started_) { | 417 | if (!scan_started_) { |
416 | LOG(INFO) << "Received external scan result notification from kernel."; | 418 | LOG(INFO) << "Received external scan result notification from kernel."; |
417 | } | 419 | } |
@@ -476,6 +478,58 @@ SchedScanIntervalSetting ScannerImpl::GenerateIntervalSetting( | |||
476 | } | 478 | } |
477 | } | 479 | } |
478 | 480 | ||
481 | void ScannerImpl::OnOffloadScanResult() { | ||
482 | if (!pno_scan_running_over_offload_) { | ||
483 | LOG(WARNING) << "Scan results from Offload HAL but scan not requested over " | ||
484 | "this interface"; | ||
485 | return; | ||
486 | } | ||
487 | LOG(INFO) << "Offload Scan results received"; | ||
488 | if (pno_scan_event_handler_ != nullptr) { | ||
489 | pno_scan_event_handler_->OnPnoNetworkFound(); | ||
490 | } else { | ||
491 | LOG(WARNING) << "No scan event handler Offload Scan result"; | ||
492 | } | ||
493 | } | ||
494 | |||
495 | void ScannerImpl::OnOffloadError( | ||
496 | OffloadScanCallbackInterface::AsyncErrorReason error_code) { | ||
497 | bool success; | ||
498 | if (!pno_scan_running_over_offload_) { | ||
499 | // Ignore irrelevant error notifications | ||
500 | LOG(WARNING) << "Offload HAL Async Error occured but Offload HAL is not " | ||
501 | "subscribed to"; | ||
502 | return; | ||
503 | } | ||
504 | LOG(ERROR) << "Offload Service Async Failure error_code=" << error_code; | ||
505 | // Stop scans over Offload HAL and request them over netlink | ||
506 | stopPnoScan(&success); | ||
507 | if (success) { | ||
508 | LOG(INFO) << "Pno scans stopped"; | ||
509 | } | ||
510 | switch (error_code) { | ||
511 | case OffloadScanCallbackInterface::AsyncErrorReason::BINDER_DEATH: | ||
512 | if (pno_scan_event_handler_ != nullptr) { | ||
513 | pno_scan_event_handler_->OnPnoScanOverOffloadFailed( | ||
514 | net::wifi::IPnoScanEvent::PNO_SCAN_OVER_OFFLOAD_BINDER_FAILURE); | ||
515 | } | ||
516 | break; | ||
517 | case OffloadScanCallbackInterface::AsyncErrorReason::REMOTE_FAILURE: | ||
518 | if (pno_scan_event_handler_ != nullptr) { | ||
519 | pno_scan_event_handler_->OnPnoScanOverOffloadFailed( | ||
520 | net::wifi::IPnoScanEvent::PNO_SCAN_OVER_OFFLOAD_REMOTE_FAILURE); | ||
521 | } | ||
522 | break; | ||
523 | default: | ||
524 | LOG(WARNING) << "Invalid Error code"; | ||
525 | break; | ||
526 | } | ||
527 | startPnoScan(pno_settings_, &success); | ||
528 | if (success) { | ||
529 | LOG(INFO) << "Pno scans restarted"; | ||
530 | } | ||
531 | } | ||
532 | |||
479 | void ScannerImpl::LogSsidList(vector<vector<uint8_t>>& ssid_list, | 533 | void ScannerImpl::LogSsidList(vector<vector<uint8_t>>& ssid_list, |
480 | string prefix) { | 534 | string prefix) { |
481 | if (ssid_list.empty()) { | 535 | if (ssid_list.empty()) { |
@@ -491,15 +545,5 @@ void ScannerImpl::LogSsidList(vector<vector<uint8_t>>& ssid_list, | |||
491 | LOG(WARNING) << prefix << ": " << ssid_list_string; | 545 | LOG(WARNING) << prefix << ": " << ssid_list_string; |
492 | } | 546 | } |
493 | 547 | ||
494 | void ScannerImpl::OnOffloadScanResult( | ||
495 | std::vector<NativeScanResult> scanResult) { | ||
496 | LOG(INFO) << "Offload Scan results received"; | ||
497 | if (pno_scan_event_handler_ != nullptr) { | ||
498 | pno_scan_event_handler_->OnPnoNetworkFound(); | ||
499 | } else { | ||
500 | LOG(WARNING) << "No scan event handler Offload Scan result"; | ||
501 | } | ||
502 | } | ||
503 | |||
504 | } // namespace wificond | 548 | } // namespace wificond |
505 | } // namespace android | 549 | } // namespace android |
diff --git a/scanning/scanner_impl.h b/scanning/scanner_impl.h index 2bb9262..e97e967 100644 --- a/scanning/scanner_impl.h +++ b/scanning/scanner_impl.h | |||
@@ -26,22 +26,23 @@ | |||
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 | #include "wificond/scanning/scan_utils.h" |
29 | #include "wificond/scanning/offload_scan_callback_interface_impl.h" | ||
29 | 30 | ||
30 | namespace android { | 31 | namespace android { |
31 | namespace wificond { | 32 | namespace wificond { |
32 | 33 | ||
33 | class ClientInterfaceImpl; | 34 | class ClientInterfaceImpl; |
34 | class OffloadServiceUtils; | 35 | class OffloadServiceUtils; |
36 | class ScanUtils; | ||
37 | class OffloadScanCallbackInterfaceImpl; | ||
35 | 38 | ||
36 | class ScannerImpl : public android::net::wifi::BnWifiScannerImpl { | 39 | class ScannerImpl : public android::net::wifi::BnWifiScannerImpl { |
37 | public: | 40 | public: |
38 | ScannerImpl(uint32_t wiphy_index, | 41 | ScannerImpl(uint32_t wiphy_index, uint32_t interface_index, |
39 | uint32_t interface_index, | ||
40 | const ScanCapabilities& scan_capabilities, | 42 | const ScanCapabilities& scan_capabilities, |
41 | const WiphyFeatures& wiphy_features, | 43 | const WiphyFeatures& wiphy_features, |
42 | ClientInterfaceImpl* client_interface, | 44 | ClientInterfaceImpl* client_interface, |
43 | NetlinkUtils* netlink_utils, | 45 | NetlinkUtils* netlink_utils, ScanUtils* scan_utils, |
44 | ScanUtils* scan_utils, | ||
45 | std::weak_ptr<OffloadServiceUtils> offload_service_utils); | 46 | std::weak_ptr<OffloadServiceUtils> offload_service_utils); |
46 | ~ScannerImpl(); | 47 | ~ScannerImpl(); |
47 | // Returns a vector of available frequencies for 2.4GHz channels. | 48 | // Returns a vector of available frequencies for 2.4GHz channels. |
@@ -71,19 +72,19 @@ class ScannerImpl : public android::net::wifi::BnWifiScannerImpl { | |||
71 | const ::android::sp<::android::net::wifi::IScanEvent>& handler) override; | 72 | const ::android::sp<::android::net::wifi::IScanEvent>& handler) override; |
72 | ::android::binder::Status unsubscribeScanEvents() override; | 73 | ::android::binder::Status unsubscribeScanEvents() override; |
73 | ::android::binder::Status subscribePnoScanEvents( | 74 | ::android::binder::Status subscribePnoScanEvents( |
74 | const ::android::sp<::android::net::wifi::IPnoScanEvent>& handler) override; | 75 | const ::android::sp<::android::net::wifi::IPnoScanEvent>& handler) |
76 | override; | ||
75 | ::android::binder::Status unsubscribePnoScanEvents() override; | 77 | ::android::binder::Status unsubscribePnoScanEvents() override; |
78 | void OnOffloadScanResult(); | ||
79 | void OnOffloadError( | ||
80 | OffloadScanCallbackInterface::AsyncErrorReason error_code); | ||
76 | void Invalidate(); | 81 | void Invalidate(); |
77 | 82 | ||
78 | private: | 83 | private: |
79 | bool CheckIsValid(); | 84 | bool CheckIsValid(); |
80 | void OnOffloadScanResult( | 85 | void OnScanResultsReady(uint32_t interface_index, bool aborted, |
81 | std::vector<::com::android::server::wifi::wificond::NativeScanResult>); | 86 | std::vector<std::vector<uint8_t>>& ssids, |
82 | void OnScanResultsReady( | 87 | std::vector<uint32_t>& frequencies); |
83 | uint32_t interface_index, | ||
84 | bool aborted, | ||
85 | std::vector<std::vector<uint8_t>>& ssids, | ||
86 | std::vector<uint32_t>& frequencies); | ||
87 | void OnSchedScanResultsReady(uint32_t interface_index, bool scan_stopped); | 88 | void OnSchedScanResultsReady(uint32_t interface_index, bool scan_stopped); |
88 | void LogSsidList(std::vector<std::vector<uint8_t>>& ssid_list, | 89 | void LogSsidList(std::vector<std::vector<uint8_t>>& ssid_list, |
89 | std::string prefix); | 90 | std::string prefix); |
@@ -94,11 +95,10 @@ class ScannerImpl : public android::net::wifi::BnWifiScannerImpl { | |||
94 | bool StopPnoScanDefault(); | 95 | bool StopPnoScanDefault(); |
95 | bool StopPnoScanOffload(); | 96 | bool StopPnoScanOffload(); |
96 | void ParsePnoSettings( | 97 | void ParsePnoSettings( |
97 | const ::com::android::server::wifi::wificond::PnoSettings& pno_settings, | 98 | const ::com::android::server::wifi::wificond::PnoSettings& pno_settings, |
98 | std::vector<std::vector<uint8_t>>* scan_ssids, | 99 | std::vector<std::vector<uint8_t>>* scan_ssids, |
99 | std::vector<std::vector<uint8_t>>* match_ssids, | 100 | std::vector<std::vector<uint8_t>>* match_ssids, |
100 | std::vector<uint32_t>* freqs, | 101 | std::vector<uint32_t>* freqs, std::vector<uint8_t>* match_security); |
101 | std::vector<uint8_t>* match_security); | ||
102 | SchedScanIntervalSetting GenerateIntervalSetting( | 102 | SchedScanIntervalSetting GenerateIntervalSetting( |
103 | const ::com::android::server::wifi::wificond::PnoSettings& pno_settings) const; | 103 | const ::com::android::server::wifi::wificond::PnoSettings& pno_settings) const; |
104 | 104 | ||
@@ -107,6 +107,8 @@ class ScannerImpl : public android::net::wifi::BnWifiScannerImpl { | |||
107 | bool scan_started_; | 107 | bool scan_started_; |
108 | bool pno_scan_started_; | 108 | bool pno_scan_started_; |
109 | bool offload_scan_supported_; | 109 | bool offload_scan_supported_; |
110 | bool pno_scan_running_over_offload_; | ||
111 | ::com::android::server::wifi::wificond::PnoSettings pno_settings_; | ||
110 | 112 | ||
111 | const uint32_t wiphy_index_; | 113 | const uint32_t wiphy_index_; |
112 | const uint32_t interface_index_; | 114 | const uint32_t interface_index_; |
diff --git a/tests/mock_offload_scan_callback_interface.cpp b/tests/mock_offload_scan_callback_interface.cpp new file mode 100644 index 0000000..cb76e45 --- /dev/null +++ b/tests/mock_offload_scan_callback_interface.cpp | |||
@@ -0,0 +1,25 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2017 The Android Open Source Project | ||
3 | * | ||
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | * you may not use this file except in compliance with the License. | ||
6 | * You may obtain a copy of the License at | ||
7 | * | ||
8 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | * | ||
10 | * Unless required by applicable law or agreed to in writing, software | ||
11 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | * See the License for the specific language governing permissions and | ||
14 | * limitations under the License. | ||
15 | */ | ||
16 | |||
17 | #include "wificond/tests/mock_offload_scan_callback_interface.h" | ||
18 | |||
19 | namespace android { | ||
20 | namespace wificond { | ||
21 | |||
22 | MockOffloadScanCallbackInterface::MockOffloadScanCallbackInterface() {} | ||
23 | |||
24 | } // namespace wificond | ||
25 | } // namespace android | ||
diff --git a/tests/mock_offload_scan_callback_interface.h b/tests/mock_offload_scan_callback_interface.h new file mode 100644 index 0000000..e7cdcc1 --- /dev/null +++ b/tests/mock_offload_scan_callback_interface.h | |||
@@ -0,0 +1,41 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2016 The Android Open Source Project | ||
3 | * | ||
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | * you may not use this file except in compliance with the License. | ||
6 | * You may obtain a copy of the License at | ||
7 | * | ||
8 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | * | ||
10 | * Unless required by applicable law or agreed to in writing, software | ||
11 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | * See the License for the specific language governing permissions and | ||
14 | * limitations under the License. | ||
15 | */ | ||
16 | |||
17 | #ifndef WIFICOND_TESTS_MOCK_OFFLOAD_CALLBACK_HANDLERS_H_ | ||
18 | #define WIFICOND_TESTS_MOCK_OFFLOAD_CALLBACK_HANDLERS_H_ | ||
19 | |||
20 | #include <gmock/gmock.h> | ||
21 | #include <gtest/gtest.h> | ||
22 | |||
23 | #include "wificond/scanning/offload_scan_callback_interface.h" | ||
24 | |||
25 | namespace android { | ||
26 | namespace wificond { | ||
27 | |||
28 | class MockOffloadScanCallbackInterface : public OffloadScanCallbackInterface { | ||
29 | public: | ||
30 | MockOffloadScanCallbackInterface(); | ||
31 | ~MockOffloadScanCallbackInterface() override = default; | ||
32 | |||
33 | MOCK_METHOD0(OnOffloadScanResult, void()); | ||
34 | MOCK_METHOD1(OnOffloadError, | ||
35 | void(OffloadScanCallbackInterface::AsyncErrorReason)); | ||
36 | }; | ||
37 | |||
38 | } // namespace wificond | ||
39 | } // namespace android | ||
40 | |||
41 | #endif // WIFICOND_TESTS_MOCK_OFFLOAD_CALLBACK_HANDLERS_H_ | ||
diff --git a/tests/offload_scan_manager_test.cpp b/tests/offload_scan_manager_test.cpp index 2dbf953..9e586cb 100644 --- a/tests/offload_scan_manager_test.cpp +++ b/tests/offload_scan_manager_test.cpp | |||
@@ -23,6 +23,7 @@ | |||
23 | #include <gtest/gtest.h> | 23 | #include <gtest/gtest.h> |
24 | 24 | ||
25 | #include "wificond/tests/mock_offload.h" | 25 | #include "wificond/tests/mock_offload.h" |
26 | #include "wificond/tests/mock_offload_scan_callback_interface.h" | ||
26 | #include "wificond/tests/mock_offload_service_utils.h" | 27 | #include "wificond/tests/mock_offload_service_utils.h" |
27 | #include "wificond/tests/offload_hal_test_constants.h" | 28 | #include "wificond/tests/offload_hal_test_constants.h" |
28 | #include "wificond/tests/offload_test_utils.h" | 29 | #include "wificond/tests/offload_test_utils.h" |
@@ -112,6 +113,9 @@ class OffloadScanManagerTest : public ::testing::Test { | |||
112 | sp<OffloadDeathRecipient> death_recipient_; | 113 | sp<OffloadDeathRecipient> death_recipient_; |
113 | shared_ptr<NiceMock<MockOffloadServiceUtils>> mock_offload_service_utils_{ | 114 | shared_ptr<NiceMock<MockOffloadServiceUtils>> mock_offload_service_utils_{ |
114 | new NiceMock<MockOffloadServiceUtils>()}; | 115 | new NiceMock<MockOffloadServiceUtils>()}; |
116 | shared_ptr<NiceMock<MockOffloadScanCallbackInterface>> | ||
117 | mock_offload_scan_callback_interface_{ | ||
118 | new NiceMock<MockOffloadScanCallbackInterface>()}; | ||
115 | unique_ptr<OffloadScanManager> offload_scan_manager_; | 119 | unique_ptr<OffloadScanManager> offload_scan_manager_; |
116 | OffloadStatus status; | 120 | OffloadStatus status; |
117 | vector<vector<uint8_t>> scan_ssids{kSsid1, kSsid2}; | 121 | vector<vector<uint8_t>> scan_ssids{kSsid1, kSsid2}; |
@@ -131,8 +135,8 @@ TEST_F(OffloadScanManagerTest, BinderDeathRegisteredCookieAndService) { | |||
131 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) | 135 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) |
132 | .WillByDefault(testing::Return(mock_offload_)); | 136 | .WillByDefault(testing::Return(mock_offload_)); |
133 | offload_scan_manager_.reset(new OffloadScanManager( | 137 | offload_scan_manager_.reset(new OffloadScanManager( |
134 | mock_offload_service_utils_, | 138 | mock_offload_service_utils_, mock_offload_scan_callback_interface_)); |
135 | [](vector<NativeScanResult> scanResult) -> void {})); | 139 | EXPECT_CALL(*mock_offload_scan_callback_interface_, OnOffloadError(_)); |
136 | death_recipient_->serviceDied(cookie_, mock_offload_); | 140 | death_recipient_->serviceDied(cookie_, mock_offload_); |
137 | EXPECT_EQ(OffloadScanManager::kNoService, | 141 | EXPECT_EQ(OffloadScanManager::kNoService, |
138 | offload_scan_manager_->getOffloadStatus()); | 142 | offload_scan_manager_->getOffloadStatus()); |
@@ -147,8 +151,7 @@ TEST_F(OffloadScanManagerTest, BinderDeathUnregisteredCookie) { | |||
147 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) | 151 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) |
148 | .WillByDefault(testing::Return(mock_offload_)); | 152 | .WillByDefault(testing::Return(mock_offload_)); |
149 | offload_scan_manager_.reset(new OffloadScanManager( | 153 | offload_scan_manager_.reset(new OffloadScanManager( |
150 | mock_offload_service_utils_, | 154 | mock_offload_service_utils_, mock_offload_scan_callback_interface_)); |
151 | [](vector<NativeScanResult> scanResult) -> void {})); | ||
152 | death_recipient_->serviceDied(kDeathCode, mock_offload_); | 155 | death_recipient_->serviceDied(kDeathCode, mock_offload_); |
153 | EXPECT_FALSE(OffloadScanManager::kNoService == | 156 | EXPECT_FALSE(OffloadScanManager::kNoService == |
154 | offload_scan_manager_->getOffloadStatus()); | 157 | offload_scan_manager_->getOffloadStatus()); |
@@ -163,8 +166,7 @@ TEST_F(OffloadScanManagerTest, ServiceNotAvailableTest) { | |||
163 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) | 166 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) |
164 | .WillByDefault(testing::Return(nullptr)); | 167 | .WillByDefault(testing::Return(nullptr)); |
165 | offload_scan_manager_.reset(new OffloadScanManager( | 168 | offload_scan_manager_.reset(new OffloadScanManager( |
166 | mock_offload_service_utils_, | 169 | mock_offload_service_utils_, mock_offload_scan_callback_interface_)); |
167 | [](vector<NativeScanResult> scanResult) -> void {})); | ||
168 | EXPECT_EQ(OffloadScanManager::kNoService, | 170 | EXPECT_EQ(OffloadScanManager::kNoService, |
169 | offload_scan_manager_->getOffloadStatus()); | 171 | offload_scan_manager_->getOffloadStatus()); |
170 | } | 172 | } |
@@ -180,8 +182,7 @@ TEST_F(OffloadScanManagerTest, ServiceAvailableTest) { | |||
180 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) | 182 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) |
181 | .WillByDefault(testing::Return(mock_offload_)); | 183 | .WillByDefault(testing::Return(mock_offload_)); |
182 | offload_scan_manager_.reset(new OffloadScanManager( | 184 | offload_scan_manager_.reset(new OffloadScanManager( |
183 | mock_offload_service_utils_, | 185 | mock_offload_service_utils_, mock_offload_scan_callback_interface_)); |
184 | [](vector<NativeScanResult> scanResult) -> void {})); | ||
185 | EXPECT_EQ(OffloadScanManager::kNoError, | 186 | EXPECT_EQ(OffloadScanManager::kNoError, |
186 | offload_scan_manager_->getOffloadStatus()); | 187 | offload_scan_manager_->getOffloadStatus()); |
187 | } | 188 | } |
@@ -192,21 +193,17 @@ TEST_F(OffloadScanManagerTest, ServiceAvailableTest) { | |||
192 | * scan results are available | 193 | * scan results are available |
193 | */ | 194 | */ |
194 | TEST_F(OffloadScanManagerTest, CallbackInvokedTest) { | 195 | TEST_F(OffloadScanManagerTest, CallbackInvokedTest) { |
195 | bool callback_invoked = false; | ||
196 | EXPECT_CALL(*mock_offload_service_utils_, GetOffloadService()); | 196 | EXPECT_CALL(*mock_offload_service_utils_, GetOffloadService()); |
197 | EXPECT_CALL(*mock_offload_service_utils_, GetOffloadCallback(_)); | 197 | EXPECT_CALL(*mock_offload_service_utils_, GetOffloadCallback(_)); |
198 | EXPECT_CALL(*mock_offload_service_utils_, GetOffloadDeathRecipient(_)); | 198 | EXPECT_CALL(*mock_offload_service_utils_, GetOffloadDeathRecipient(_)); |
199 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) | 199 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) |
200 | .WillByDefault(testing::Return(mock_offload_)); | 200 | .WillByDefault(testing::Return(mock_offload_)); |
201 | EXPECT_CALL(*mock_offload_scan_callback_interface_, OnOffloadScanResult()); | ||
201 | offload_scan_manager_.reset(new OffloadScanManager( | 202 | offload_scan_manager_.reset(new OffloadScanManager( |
202 | mock_offload_service_utils_, | 203 | mock_offload_service_utils_, mock_offload_scan_callback_interface_)); |
203 | [&callback_invoked](vector<NativeScanResult> scanResult) -> void { | ||
204 | callback_invoked = true; | ||
205 | })); | ||
206 | vector<ScanResult> dummy_scan_results_ = | 204 | vector<ScanResult> dummy_scan_results_ = |
207 | OffloadTestUtils::createOffloadScanResults(); | 205 | OffloadTestUtils::createOffloadScanResults(); |
208 | offload_callback_->onScanResult(dummy_scan_results_); | 206 | offload_callback_->onScanResult(dummy_scan_results_); |
209 | EXPECT_EQ(true, callback_invoked); | ||
210 | } | 207 | } |
211 | 208 | ||
212 | /** | 209 | /** |
@@ -220,10 +217,10 @@ TEST_F(OffloadScanManagerTest, ErrorCallbackInvokedTest) { | |||
220 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) | 217 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) |
221 | .WillByDefault(testing::Return(mock_offload_)); | 218 | .WillByDefault(testing::Return(mock_offload_)); |
222 | offload_scan_manager_.reset(new OffloadScanManager( | 219 | offload_scan_manager_.reset(new OffloadScanManager( |
223 | mock_offload_service_utils_, | 220 | mock_offload_service_utils_, mock_offload_scan_callback_interface_)); |
224 | [](vector<NativeScanResult> scanResult) -> void {})); | ||
225 | OffloadStatus status = | 221 | OffloadStatus status = |
226 | OffloadTestUtils::createOffloadStatus(OffloadStatusCode::ERROR); | 222 | OffloadTestUtils::createOffloadStatus(OffloadStatusCode::ERROR); |
223 | EXPECT_CALL(*mock_offload_scan_callback_interface_, OnOffloadError(_)); | ||
227 | offload_callback_->onError(status); | 224 | offload_callback_->onError(status); |
228 | EXPECT_EQ(offload_scan_manager_->getOffloadStatus(), | 225 | EXPECT_EQ(offload_scan_manager_->getOffloadStatus(), |
229 | OffloadScanManager::kError); | 226 | OffloadScanManager::kError); |
@@ -240,8 +237,7 @@ TEST_F(OffloadScanManagerTest, StartScanTestWhenServiceIsOk) { | |||
240 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) | 237 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) |
241 | .WillByDefault(testing::Return(mock_offload_)); | 238 | .WillByDefault(testing::Return(mock_offload_)); |
242 | offload_scan_manager_.reset(new OffloadScanManager( | 239 | offload_scan_manager_.reset(new OffloadScanManager( |
243 | mock_offload_service_utils_, | 240 | mock_offload_service_utils_, mock_offload_scan_callback_interface_)); |
244 | [](vector<NativeScanResult> scanResult) -> void {})); | ||
245 | EXPECT_CALL(*mock_offload_, subscribeScanResults(_, _)); | 241 | EXPECT_CALL(*mock_offload_, subscribeScanResults(_, _)); |
246 | EXPECT_CALL(*mock_offload_, configureScans(_, _, _)); | 242 | EXPECT_CALL(*mock_offload_, configureScans(_, _, _)); |
247 | OffloadScanManager::ReasonCode reason_code = OffloadScanManager::kNone; | 243 | OffloadScanManager::ReasonCode reason_code = OffloadScanManager::kNone; |
@@ -256,12 +252,11 @@ TEST_F(OffloadScanManagerTest, StartScanTestWhenServiceIsOk) { | |||
256 | * Offload HAL when service is not available | 252 | * Offload HAL when service is not available |
257 | */ | 253 | */ |
258 | TEST_F(OffloadScanManagerTest, StartScanTestWhenServiceIsNotAvailable) { | 254 | TEST_F(OffloadScanManagerTest, StartScanTestWhenServiceIsNotAvailable) { |
259 | EXPECT_CALL(*mock_offload_service_utils_, GetOffloadService()); | 255 | EXPECT_CALL(*mock_offload_service_utils_, GetOffloadService()).Times(2); |
260 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) | 256 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) |
261 | .WillByDefault(testing::Return(nullptr)); | 257 | .WillByDefault(testing::Return(nullptr)); |
262 | offload_scan_manager_.reset(new OffloadScanManager( | 258 | offload_scan_manager_.reset(new OffloadScanManager( |
263 | mock_offload_service_utils_, | 259 | mock_offload_service_utils_, mock_offload_scan_callback_interface_)); |
264 | [](vector<NativeScanResult> scanResult) -> void {})); | ||
265 | OffloadScanManager::ReasonCode reason_code = OffloadScanManager::kNone; | 260 | OffloadScanManager::ReasonCode reason_code = OffloadScanManager::kNone; |
266 | bool result = offload_scan_manager_->startScan( | 261 | bool result = offload_scan_manager_->startScan( |
267 | kDisconnectedModeScanIntervalMs, kRssiThreshold, scan_ssids, match_ssids, | 262 | kDisconnectedModeScanIntervalMs, kRssiThreshold, scan_ssids, match_ssids, |
@@ -281,8 +276,7 @@ TEST_F(OffloadScanManagerTest, StartScanTestWhenServiceIsNotConnected) { | |||
281 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) | 276 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) |
282 | .WillByDefault(testing::Return(mock_offload_)); | 277 | .WillByDefault(testing::Return(mock_offload_)); |
283 | offload_scan_manager_.reset(new OffloadScanManager( | 278 | offload_scan_manager_.reset(new OffloadScanManager( |
284 | mock_offload_service_utils_, | 279 | mock_offload_service_utils_, mock_offload_scan_callback_interface_)); |
285 | [](vector<NativeScanResult> scanResult) -> void {})); | ||
286 | OffloadStatus status = | 280 | OffloadStatus status = |
287 | OffloadTestUtils::createOffloadStatus(OffloadStatusCode::NO_CONNECTION); | 281 | OffloadTestUtils::createOffloadStatus(OffloadStatusCode::NO_CONNECTION); |
288 | offload_callback_->onError(status); | 282 | offload_callback_->onError(status); |
@@ -305,9 +299,8 @@ TEST_F(OffloadScanManagerTest, StartScanTwiceTestWhenServiceIsOk) { | |||
305 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) | 299 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) |
306 | .WillByDefault(testing::Return(mock_offload_)); | 300 | .WillByDefault(testing::Return(mock_offload_)); |
307 | offload_scan_manager_.reset(new OffloadScanManager( | 301 | offload_scan_manager_.reset(new OffloadScanManager( |
308 | mock_offload_service_utils_, | 302 | mock_offload_service_utils_, mock_offload_scan_callback_interface_)); |
309 | [](vector<NativeScanResult> scanResult) -> void {})); | 303 | EXPECT_CALL(*mock_offload_, subscribeScanResults(_, _)).Times(2); |
310 | EXPECT_CALL(*mock_offload_, subscribeScanResults(_, _)).Times(1); | ||
311 | EXPECT_CALL(*mock_offload_, configureScans(_, _, _)).Times(2); | 304 | EXPECT_CALL(*mock_offload_, configureScans(_, _, _)).Times(2); |
312 | OffloadScanManager::ReasonCode reason_code = OffloadScanManager::kNone; | 305 | OffloadScanManager::ReasonCode reason_code = OffloadScanManager::kNone; |
313 | bool result = offload_scan_manager_->startScan( | 306 | bool result = offload_scan_manager_->startScan( |
@@ -331,8 +324,7 @@ TEST_F(OffloadScanManagerTest, StopScanTestWhenServiceIsOk) { | |||
331 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) | 324 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) |
332 | .WillByDefault(testing::Return(mock_offload_)); | 325 | .WillByDefault(testing::Return(mock_offload_)); |
333 | offload_scan_manager_.reset(new OffloadScanManager( | 326 | offload_scan_manager_.reset(new OffloadScanManager( |
334 | mock_offload_service_utils_, | 327 | mock_offload_service_utils_, mock_offload_scan_callback_interface_)); |
335 | [](vector<NativeScanResult> scanResult) -> void {})); | ||
336 | EXPECT_CALL(*mock_offload_, subscribeScanResults(_, _)); | 328 | EXPECT_CALL(*mock_offload_, subscribeScanResults(_, _)); |
337 | EXPECT_CALL(*mock_offload_, configureScans(_, _, _)); | 329 | EXPECT_CALL(*mock_offload_, configureScans(_, _, _)); |
338 | EXPECT_CALL(*mock_offload_, unsubscribeScanResults()); | 330 | EXPECT_CALL(*mock_offload_, unsubscribeScanResults()); |
@@ -347,26 +339,7 @@ TEST_F(OffloadScanManagerTest, StopScanTestWhenServiceIsOk) { | |||
347 | 339 | ||
348 | /** | 340 | /** |
349 | * Testing OffloadScanManager for unsubscribing to the scan results from | 341 | * Testing OffloadScanManager for unsubscribing to the scan results from |
350 | * Offload HAL without first subscribing | 342 | * when service is not connected to the hardware |
351 | */ | ||
352 | TEST_F(OffloadScanManagerTest, StopScanTestWithoutStartWhenServiceIsOk) { | ||
353 | EXPECT_CALL(*mock_offload_service_utils_, GetOffloadService()); | ||
354 | EXPECT_CALL(*mock_offload_service_utils_, GetOffloadCallback(_)); | ||
355 | EXPECT_CALL(*mock_offload_service_utils_, GetOffloadDeathRecipient(_)); | ||
356 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) | ||
357 | .WillByDefault(testing::Return(mock_offload_)); | ||
358 | offload_scan_manager_.reset(new OffloadScanManager( | ||
359 | mock_offload_service_utils_, | ||
360 | [](vector<NativeScanResult> scanResult) -> void {})); | ||
361 | OffloadScanManager::ReasonCode reason_code = OffloadScanManager::kNone; | ||
362 | bool result = offload_scan_manager_->stopScan(&reason_code); | ||
363 | EXPECT_EQ(result, false); | ||
364 | EXPECT_EQ(reason_code, OffloadScanManager::kNotSubscribed); | ||
365 | } | ||
366 | |||
367 | /** | ||
368 | * Testing OffloadScanManager for unsubscribing to the scan results from | ||
369 | * Offload HAL without first subscribing when service is not working correctly | ||
370 | */ | 343 | */ |
371 | TEST_F(OffloadScanManagerTest, StopScanTestWhenServiceIsNotConnectedAnymore) { | 344 | TEST_F(OffloadScanManagerTest, StopScanTestWhenServiceIsNotConnectedAnymore) { |
372 | EXPECT_CALL(*mock_offload_service_utils_, GetOffloadService()); | 345 | EXPECT_CALL(*mock_offload_service_utils_, GetOffloadService()); |
@@ -374,11 +347,9 @@ TEST_F(OffloadScanManagerTest, StopScanTestWhenServiceIsNotConnectedAnymore) { | |||
374 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) | 347 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) |
375 | .WillByDefault(testing::Return(mock_offload_)); | 348 | .WillByDefault(testing::Return(mock_offload_)); |
376 | offload_scan_manager_.reset(new OffloadScanManager( | 349 | offload_scan_manager_.reset(new OffloadScanManager( |
377 | mock_offload_service_utils_, | 350 | mock_offload_service_utils_, mock_offload_scan_callback_interface_)); |
378 | [](vector<NativeScanResult> scanResult) -> void {})); | ||
379 | EXPECT_CALL(*mock_offload_, subscribeScanResults(_, _)); | 351 | EXPECT_CALL(*mock_offload_, subscribeScanResults(_, _)); |
380 | EXPECT_CALL(*mock_offload_, configureScans(_, _, _)); | 352 | EXPECT_CALL(*mock_offload_, configureScans(_, _, _)); |
381 | EXPECT_CALL(*mock_offload_, unsubscribeScanResults()); | ||
382 | OffloadScanManager::ReasonCode reason_code = OffloadScanManager::kNone; | 353 | OffloadScanManager::ReasonCode reason_code = OffloadScanManager::kNone; |
383 | bool result = offload_scan_manager_->startScan( | 354 | bool result = offload_scan_manager_->startScan( |
384 | kDisconnectedModeScanIntervalMs, kRssiThreshold, scan_ssids, match_ssids, | 355 | kDisconnectedModeScanIntervalMs, kRssiThreshold, scan_ssids, match_ssids, |
@@ -388,7 +359,7 @@ TEST_F(OffloadScanManagerTest, StopScanTestWhenServiceIsNotConnectedAnymore) { | |||
388 | OffloadTestUtils::createOffloadStatus(OffloadStatusCode::NO_CONNECTION); | 359 | OffloadTestUtils::createOffloadStatus(OffloadStatusCode::NO_CONNECTION); |
389 | offload_callback_->onError(status); | 360 | offload_callback_->onError(status); |
390 | result = offload_scan_manager_->stopScan(&reason_code); | 361 | result = offload_scan_manager_->stopScan(&reason_code); |
391 | EXPECT_EQ(result, true); | 362 | EXPECT_EQ(result, false); |
392 | } | 363 | } |
393 | 364 | ||
394 | /** | 365 | /** |
@@ -402,8 +373,7 @@ TEST_F(OffloadScanManagerTest, getScanStatsTestWhenServiceIsOk) { | |||
402 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) | 373 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) |
403 | .WillByDefault(testing::Return(mock_offload_)); | 374 | .WillByDefault(testing::Return(mock_offload_)); |
404 | offload_scan_manager_.reset(new OffloadScanManager( | 375 | offload_scan_manager_.reset(new OffloadScanManager( |
405 | mock_offload_service_utils_, | 376 | mock_offload_service_utils_, mock_offload_scan_callback_interface_)); |
406 | [](vector<NativeScanResult> scanResult) -> void {})); | ||
407 | EXPECT_CALL(*mock_offload_, getScanStats(_)); | 377 | EXPECT_CALL(*mock_offload_, getScanStats(_)); |
408 | NativeScanStats stats; | 378 | NativeScanStats stats; |
409 | bool result = offload_scan_manager_->getScanStats(&stats); | 379 | bool result = offload_scan_manager_->getScanStats(&stats); |
@@ -421,8 +391,7 @@ TEST_F(OffloadScanManagerTest, getScanStatsTestWhenServiceIsNotOk) { | |||
421 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) | 391 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) |
422 | .WillByDefault(testing::Return(mock_offload_)); | 392 | .WillByDefault(testing::Return(mock_offload_)); |
423 | offload_scan_manager_.reset(new OffloadScanManager( | 393 | offload_scan_manager_.reset(new OffloadScanManager( |
424 | mock_offload_service_utils_, | 394 | mock_offload_service_utils_, mock_offload_scan_callback_interface_)); |
425 | [](vector<NativeScanResult> scanResult) -> void {})); | ||
426 | OffloadStatus status = | 395 | OffloadStatus status = |
427 | OffloadTestUtils::createOffloadStatus(OffloadStatusCode::NO_CONNECTION); | 396 | OffloadTestUtils::createOffloadStatus(OffloadStatusCode::NO_CONNECTION); |
428 | offload_callback_->onError(status); | 397 | offload_callback_->onError(status); |
@@ -443,8 +412,7 @@ TEST_F(OffloadScanManagerTest, StartScanFailedTest) { | |||
443 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) | 412 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) |
444 | .WillByDefault(testing::Return(mock_offload_)); | 413 | .WillByDefault(testing::Return(mock_offload_)); |
445 | offload_scan_manager_.reset(new OffloadScanManager( | 414 | offload_scan_manager_.reset(new OffloadScanManager( |
446 | mock_offload_service_utils_, | 415 | mock_offload_service_utils_, mock_offload_scan_callback_interface_)); |
447 | [](vector<NativeScanResult> scanResult) -> void {})); | ||
448 | EXPECT_CALL(*mock_offload_, subscribeScanResults(_, _)).Times(0); | 416 | EXPECT_CALL(*mock_offload_, subscribeScanResults(_, _)).Times(0); |
449 | EXPECT_CALL(*mock_offload_, configureScans(_, _, _)).Times(1); | 417 | EXPECT_CALL(*mock_offload_, configureScans(_, _, _)).Times(1); |
450 | status = OffloadTestUtils::createOffloadStatus(OffloadStatusCode::ERROR); | 418 | status = OffloadTestUtils::createOffloadStatus(OffloadStatusCode::ERROR); |
@@ -467,8 +435,7 @@ TEST_F(OffloadScanManagerTest, getScanStatsFailedTest) { | |||
467 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) | 435 | ON_CALL(*mock_offload_service_utils_, GetOffloadService()) |
468 | .WillByDefault(testing::Return(mock_offload_)); | 436 | .WillByDefault(testing::Return(mock_offload_)); |
469 | offload_scan_manager_.reset(new OffloadScanManager( | 437 | offload_scan_manager_.reset(new OffloadScanManager( |
470 | mock_offload_service_utils_, | 438 | mock_offload_service_utils_, mock_offload_scan_callback_interface_)); |
471 | [](vector<NativeScanResult> scanResult) -> void {})); | ||
472 | status = OffloadTestUtils::createOffloadStatus(OffloadStatusCode::TIMEOUT); | 439 | status = OffloadTestUtils::createOffloadStatus(OffloadStatusCode::TIMEOUT); |
473 | EXPECT_CALL(*mock_offload_, getScanStats(_)); | 440 | EXPECT_CALL(*mock_offload_, getScanStats(_)); |
474 | NativeScanStats stats; | 441 | NativeScanStats stats; |