diff options
Diffstat (limited to 'scanning/offload/offload_scan_manager.cpp')
-rw-r--r-- | scanning/offload/offload_scan_manager.cpp | 64 |
1 files changed, 43 insertions, 21 deletions
diff --git a/scanning/offload/offload_scan_manager.cpp b/scanning/offload/offload_scan_manager.cpp index 5e3d90d..5c73362 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,19 +69,15 @@ 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), |
76 | offload_status_(OffloadScanManager::kError), | 77 | offload_status_(OffloadScanManager::kError), |
77 | subscription_enabled_(false), | ||
78 | offload_callback_handlers_(new OffloadCallbackHandlersImpl(this)), | 78 | offload_callback_handlers_(new OffloadCallbackHandlersImpl(this)), |
79 | scan_result_handler_(handler) { | 79 | event_callback_(callback) { |
80 | auto offload_scan_utils = utils.lock(); | 80 | auto offload_scan_utils = utils.lock(); |
81 | if (scan_result_handler_ == nullptr) { | ||
82 | LOG(ERROR) << "Invalid Offload scan result handler"; | ||
83 | return; | ||
84 | } | ||
85 | wifi_offload_hal_ = offload_scan_utils->GetOffloadService(); | 81 | wifi_offload_hal_ = offload_scan_utils->GetOffloadService(); |
86 | if (wifi_offload_hal_ == nullptr) { | 82 | if (wifi_offload_hal_ == nullptr) { |
87 | LOG(ERROR) << "No Offload Service available"; | 83 | LOG(ERROR) << "No Offload Service available"; |
@@ -110,14 +106,15 @@ OffloadScanManager::OffloadScanManager(weak_ptr<OffloadServiceUtils> utils, | |||
110 | } | 106 | } |
111 | 107 | ||
112 | bool OffloadScanManager::stopScan(OffloadScanManager::ReasonCode* reason_code) { | 108 | bool OffloadScanManager::stopScan(OffloadScanManager::ReasonCode* reason_code) { |
113 | if (!subscription_enabled_) { | 109 | if (getOffloadStatus() != OffloadScanManager::kNoError) { |
114 | LOG(VERBOSE) << "Scans are not subscribed over Offload HAL"; | 110 | *reason_code = OffloadScanManager::kNotAvailable; |
115 | *reason_code = OffloadScanManager::kNotSubscribed; | ||
116 | return false; | 111 | return false; |
117 | } | 112 | } |
118 | if (wifi_offload_hal_ != nullptr) { | 113 | const auto& res = wifi_offload_hal_->unsubscribeScanResults(); |
119 | wifi_offload_hal_->unsubscribeScanResults(); | 114 | if (!res.isOk()) { |
120 | subscription_enabled_ = false; | 115 | *reason_code = OffloadScanManager::kTransactionFailed; |
116 | LOG(WARNING) << "unsubscribeScanResults() failed " << res.description(); | ||
117 | return false; | ||
121 | } | 118 | } |
122 | *reason_code = OffloadScanManager::kNone; | 119 | *reason_code = OffloadScanManager::kNone; |
123 | return true; | 120 | return true; |
@@ -177,12 +174,13 @@ bool OffloadScanManager::startScan( | |||
177 | return false; | 174 | return false; |
178 | } | 175 | } |
179 | 176 | ||
180 | if (!subscription_enabled_ && !SubscribeScanResults(reason_code)) { | 177 | if (!SubscribeScanResults(reason_code)) { |
181 | return false; | 178 | return false; |
182 | } | 179 | } |
183 | 180 | ||
184 | subscription_enabled_ = true; | ||
185 | *reason_code = OffloadScanManager::kNone; | 181 | *reason_code = OffloadScanManager::kNone; |
182 | /* Clear up the scan cache every time a new scan is requested */ | ||
183 | cached_scan_results_.clear(); | ||
186 | return true; | 184 | return true; |
187 | } | 185 | } |
188 | 186 | ||
@@ -214,6 +212,14 @@ OffloadScanManager::StatusCode OffloadScanManager::getOffloadStatus() const { | |||
214 | return offload_status_; | 212 | return offload_status_; |
215 | } | 213 | } |
216 | 214 | ||
215 | bool OffloadScanManager::getScanResults( | ||
216 | std::vector<NativeScanResult>* out_scan_results) { | ||
217 | for (auto scan_result : cached_scan_results_) { | ||
218 | out_scan_results->push_back(scan_result); | ||
219 | } | ||
220 | return true; | ||
221 | } | ||
222 | |||
217 | bool OffloadScanManager::getScanStats(NativeScanStats* native_scan_stats) { | 223 | bool OffloadScanManager::getScanStats(NativeScanStats* native_scan_stats) { |
218 | if (getOffloadStatus() != OffloadScanManager::kNoError) { | 224 | if (getOffloadStatus() != OffloadScanManager::kNoError) { |
219 | LOG(WARNING) << "Unable to get scan stats due to Wifi Offload HAL error"; | 225 | LOG(WARNING) << "Unable to get scan stats due to Wifi Offload HAL error"; |
@@ -230,11 +236,13 @@ OffloadScanManager::~OffloadScanManager() { | |||
230 | 236 | ||
231 | void OffloadScanManager::ReportScanResults( | 237 | void OffloadScanManager::ReportScanResults( |
232 | const vector<ScanResult>& scanResult) { | 238 | const vector<ScanResult>& scanResult) { |
233 | if (scan_result_handler_ != nullptr) { | 239 | cached_scan_results_ = |
234 | scan_result_handler_( | 240 | OffloadScanUtils::convertToNativeScanResults(scanResult); |
235 | OffloadScanUtils::convertToNativeScanResults(scanResult)); | 241 | if (event_callback_ != nullptr) { |
242 | event_callback_->OnOffloadScanResult(); | ||
236 | } else { | 243 | } else { |
237 | LOG(ERROR) << "No scan result handler for Offload ScanManager"; | 244 | LOG(WARNING) |
245 | << "No callback to report Offload HAL's scan results to wificond"; | ||
238 | } | 246 | } |
239 | } | 247 | } |
240 | 248 | ||
@@ -260,6 +268,12 @@ void OffloadScanManager::ReportError(const OffloadStatus& status) { | |||
260 | } | 268 | } |
261 | if (status_result != OffloadScanManager::kNoError) { | 269 | if (status_result != OffloadScanManager::kNoError) { |
262 | LOG(WARNING) << "Offload Error reported " << status.description; | 270 | LOG(WARNING) << "Offload Error reported " << status.description; |
271 | if (event_callback_ != nullptr) { | ||
272 | event_callback_->OnOffloadError( | ||
273 | OffloadScanCallbackInterface::REMOTE_FAILURE); | ||
274 | } else { | ||
275 | LOG(WARNING) << "No callback to report Offload HAL Errors to wificond"; | ||
276 | } | ||
263 | } | 277 | } |
264 | offload_status_ = status_result; | 278 | offload_status_ = status_result; |
265 | } | 279 | } |
@@ -267,6 +281,14 @@ void OffloadScanManager::ReportError(const OffloadStatus& status) { | |||
267 | void OffloadScanManager::OnObjectDeath(uint64_t cookie) { | 281 | void OffloadScanManager::OnObjectDeath(uint64_t cookie) { |
268 | if (wifi_offload_hal_ == reinterpret_cast<IOffload*>(cookie)) { | 282 | if (wifi_offload_hal_ == reinterpret_cast<IOffload*>(cookie)) { |
269 | wifi_offload_hal_.clear(); | 283 | wifi_offload_hal_.clear(); |
284 | if (event_callback_ != nullptr) { | ||
285 | event_callback_->OnOffloadError( | ||
286 | OffloadScanCallbackInterface::BINDER_DEATH); | ||
287 | } else { | ||
288 | LOG(WARNING) | ||
289 | << "No callback to report Offload HAL Binder death to wificond"; | ||
290 | } | ||
291 | |||
270 | LOG(ERROR) << "Death Notification for Wifi Offload HAL"; | 292 | LOG(ERROR) << "Death Notification for Wifi Offload HAL"; |
271 | } | 293 | } |
272 | } | 294 | } |