rtt/rtt_controller_impl.cpp \
scanning/channel_settings.cpp \
scanning/hidden_network.cpp \
+ scanning/offload_scan_callback_interface_impl.cpp \
scanning/pno_network.cpp \
scanning/pno_settings.cpp \
scanning/scan_result.cpp \
tests/mock_netlink_utils.cpp \
tests/mock_offload.cpp \
tests/mock_offload_callback_handlers.cpp \
+ tests/mock_offload_scan_callback_interface.cpp \
tests/mock_offload_service_utils.cpp \
tests/mock_scan_utils.cpp \
tests/netlink_manager_unittest.cpp \
using android::hardware::wifi::offload::V1_0::OffloadStatusCode;
using android::wificond::OffloadCallback;
-using android::wificond::OnNativeScanResultsReadyHandler;
using ::com::android::server::wifi::wificond::NativeScanResult;
using ::com::android::server::wifi::wificond::NativeScanStats;
using std::vector;
using std::weak_ptr;
+using std::shared_ptr;
using namespace std::placeholders;
}
}
-OffloadScanManager::OffloadScanManager(weak_ptr<OffloadServiceUtils> utils,
- OnNativeScanResultsReadyHandler handler)
+OffloadScanManager::OffloadScanManager(
+ weak_ptr<OffloadServiceUtils> utils,
+ shared_ptr<OffloadScanCallbackInterface> callback)
: wifi_offload_hal_(nullptr),
wifi_offload_callback_(nullptr),
offload_status_(OffloadScanManager::kError),
- subscription_enabled_(false),
offload_callback_handlers_(new OffloadCallbackHandlersImpl(this)),
- scan_result_handler_(handler) {
+ event_callback_(callback) {
auto offload_scan_utils = utils.lock();
- if (scan_result_handler_ == nullptr) {
- LOG(ERROR) << "Invalid Offload scan result handler";
- return;
- }
wifi_offload_hal_ = offload_scan_utils->GetOffloadService();
if (wifi_offload_hal_ == nullptr) {
LOG(ERROR) << "No Offload Service available";
}
bool OffloadScanManager::stopScan(OffloadScanManager::ReasonCode* reason_code) {
- if (!subscription_enabled_) {
- LOG(VERBOSE) << "Scans are not subscribed over Offload HAL";
- *reason_code = OffloadScanManager::kNotSubscribed;
+ if (getOffloadStatus() != OffloadScanManager::kNoError) {
+ *reason_code = OffloadScanManager::kNotAvailable;
return false;
}
- if (wifi_offload_hal_ != nullptr) {
- wifi_offload_hal_->unsubscribeScanResults();
- subscription_enabled_ = false;
+ const auto& res = wifi_offload_hal_->unsubscribeScanResults();
+ if (!res.isOk()) {
+ *reason_code = OffloadScanManager::kTransactionFailed;
+ LOG(WARNING) << "unsubscribeScanResults() failed " << res.description();
+ return false;
}
*reason_code = OffloadScanManager::kNone;
return true;
return false;
}
- if (!subscription_enabled_ && !SubscribeScanResults(reason_code)) {
+ if (!SubscribeScanResults(reason_code)) {
return false;
}
- subscription_enabled_ = true;
*reason_code = OffloadScanManager::kNone;
+ /* Clear up the scan cache every time a new scan is requested */
+ cached_scan_results_.clear();
return true;
}
return offload_status_;
}
+bool OffloadScanManager::getScanResults(
+ std::vector<NativeScanResult>* out_scan_results) {
+ for (auto scan_result : cached_scan_results_) {
+ out_scan_results->push_back(scan_result);
+ }
+ return true;
+}
+
bool OffloadScanManager::getScanStats(NativeScanStats* native_scan_stats) {
if (getOffloadStatus() != OffloadScanManager::kNoError) {
LOG(WARNING) << "Unable to get scan stats due to Wifi Offload HAL error";
void OffloadScanManager::ReportScanResults(
const vector<ScanResult>& scanResult) {
- if (scan_result_handler_ != nullptr) {
- scan_result_handler_(
- OffloadScanUtils::convertToNativeScanResults(scanResult));
+ cached_scan_results_ =
+ OffloadScanUtils::convertToNativeScanResults(scanResult);
+ if (event_callback_ != nullptr) {
+ event_callback_->OnOffloadScanResult();
} else {
- LOG(ERROR) << "No scan result handler for Offload ScanManager";
+ LOG(WARNING)
+ << "No callback to report Offload HAL's scan results to wificond";
}
}
}
if (status_result != OffloadScanManager::kNoError) {
LOG(WARNING) << "Offload Error reported " << status.description;
+ if (event_callback_ != nullptr) {
+ event_callback_->OnOffloadError(
+ OffloadScanCallbackInterface::REMOTE_FAILURE);
+ } else {
+ LOG(WARNING) << "No callback to report Offload HAL Errors to wificond";
+ }
}
offload_status_ = status_result;
}
void OffloadScanManager::OnObjectDeath(uint64_t cookie) {
if (wifi_offload_hal_ == reinterpret_cast<IOffload*>(cookie)) {
wifi_offload_hal_.clear();
+ if (event_callback_ != nullptr) {
+ event_callback_->OnOffloadError(
+ OffloadScanCallbackInterface::BINDER_DEATH);
+ } else {
+ LOG(WARNING)
+ << "No callback to report Offload HAL Binder death to wificond";
+ }
+
LOG(ERROR) << "Death Notification for Wifi Offload HAL";
}
}
#include "wificond/scanning/offload/offload_callback.h"
#include "wificond/scanning/offload/offload_callback_handlers.h"
#include "wificond/scanning/offload/offload_service_utils.h"
+#include "wificond/scanning/offload_scan_callback_interface.h"
#include <vector>
class OffloadScanManager;
-typedef std::function<void(
- const std::vector<::com::android::server::wifi::wificond::NativeScanResult>
- scanResult)>
- OnNativeScanResultsReadyHandler;
-
// Provides callback interface implementation from Offload HAL
class OffloadCallbackHandlersImpl : public OffloadCallbackHandlers {
public:
kNone,
/* Offload HAL scans is not available */
kNotAvailable,
- /* Offload HAL service is not subscribed to */
- kNotSubscribed,
/* Offload HAL requested operation failure */
kOperationFailed,
/* Binder failed to deliver message to Offload HAL*/
kTransactionFailed,
};
- explicit OffloadScanManager(std::weak_ptr<OffloadServiceUtils> utils,
- OnNativeScanResultsReadyHandler handler);
+ explicit OffloadScanManager(
+ std::weak_ptr<OffloadServiceUtils> utils,
+ std::shared_ptr<OffloadScanCallbackInterface> callback);
virtual ~OffloadScanManager();
/* Request start of offload scans with scan parameters and scan filter
* settings. Internally calls Offload HAL service with configureScans()
- * and subscribeScanResults() APIs. If already subscribed, it updates
- * the scan configuration only. Reason code is updated in failure case
+ * and subscribeScanResults() APIs. Reason code indicates failure reason.
*/
bool startScan(uint32_t /* interval_ms */, int32_t /* rssi_threshold */,
const std::vector<std::vector<uint8_t>>& /* scan_ssids */,
const std::vector<uint8_t>& /* match_security */,
const std::vector<uint32_t>& /* freqs */,
ReasonCode* /* failure reason */);
- /* Request stop of offload scans, returns true if scans were subscribed
- * to from the Offload HAL service. Otherwise, returns false. Reason code
- * is updated in case of failure.
+ /* Request stop of offload scans, returns true if the operation succeeds
+ * Otherwise, returns false. Reason code is updated in case of failure.
*/
bool stopScan(ReasonCode* /* failure reason */);
/* Get statistics for scans performed by Offload HAL */
::com::android::server::wifi::wificond::NativeScanStats* /* scanStats */);
/* Otain status of the Offload HAL service */
StatusCode getOffloadStatus() const;
+ /* Returns the most recent scan result available from Offload HAL */
+ bool getScanResults(
+ std::vector<::com::android::server::wifi::wificond::NativeScanResult>*
+ out_scan_results);
private:
void ReportScanResults(
android::sp<OffloadCallback> wifi_offload_callback_;
android::sp<OffloadDeathRecipient> death_recipient_;
StatusCode offload_status_;
- bool subscription_enabled_;
+ std::vector<::com::android::server::wifi::wificond::NativeScanResult>
+ cached_scan_results_;
const std::unique_ptr<OffloadCallbackHandlersImpl> offload_callback_handlers_;
- OnNativeScanResultsReadyHandler scan_result_handler_;
+ std::shared_ptr<OffloadScanCallbackInterface> event_callback_;
friend class OffloadCallbackHandlersImpl;
};
* limitations under the License.
*/
#include "wificond/scanning/offload/offload_service_utils.h"
+
+#include <android-base/logging.h>
+
#include "wificond/scanning/offload/offload_scan_manager.h"
using ::android::hardware::wifi::offload::V1_0::IOffload;
--- /dev/null
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef ANDROID_WIFICOND_OFFLOAD_SCAN_CALLBACK_INTERFACE_H
+#define ANDROID_WIFICOND_OFFLOAD_SCAN_CALLBACK_INTERFACE_H
+
+#include <vector>
+
+#include "wificond/scanning/scan_result.h"
+
+namespace android {
+namespace wificond {
+
+class OffloadScanCallbackInterface {
+ public:
+ enum AsyncErrorReason {
+ BINDER_DEATH = 0,
+ REMOTE_FAILURE,
+ };
+
+ virtual ~OffloadScanCallbackInterface() {}
+
+ virtual void OnOffloadScanResult() = 0;
+ virtual void OnOffloadError(AsyncErrorReason) = 0;
+};
+
+} // namespace wificond
+} // namespace android
+
+#endif // ANDROID_WIFICOND_OFFLOAD_SCAN_CALLBACK_INTERFACE_H
--- /dev/null
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "wificond/scanning/offload_scan_callback_interface_impl.h"
+
+#include <android-base/logging.h>
+
+using com::android::server::wifi::wificond::NativeScanResult;
+
+namespace android {
+namespace wificond {
+
+OffloadScanCallbackInterfaceImpl::OffloadScanCallbackInterfaceImpl(
+ ScannerImpl* parent)
+ : scanner_impl_(parent) {}
+
+OffloadScanCallbackInterfaceImpl::~OffloadScanCallbackInterfaceImpl() {}
+
+void OffloadScanCallbackInterfaceImpl::OnOffloadScanResult() {
+ scanner_impl_->OnOffloadScanResult();
+}
+
+void OffloadScanCallbackInterfaceImpl::OnOffloadError(
+ OffloadScanCallbackInterface::AsyncErrorReason error_code) {
+ scanner_impl_->OnOffloadError(error_code);
+}
+
+} // namespace wificond
+} // namespace android
--- /dev/null
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef WIFICOND_SCANNER_OFFLOAD_SCAN_CALLBACK_INTERFACE_IML_H_
+#define WIFICOND_SCANNER_OFFLOAD_SCAN_CALLBACK_INTERFACE_IML_H_
+
+#include "wificond/scanning/offload_scan_callback_interface.h"
+#include "wificond/scanning/scanner_impl.h"
+
+namespace android {
+namespace wificond {
+
+class ScannerImpl;
+
+class OffloadScanCallbackInterfaceImpl
+ : public android::wificond::OffloadScanCallbackInterface {
+ public:
+ OffloadScanCallbackInterfaceImpl(ScannerImpl* parent);
+ ~OffloadScanCallbackInterfaceImpl() override;
+
+ void OnOffloadScanResult() override;
+ void OnOffloadError(OffloadScanCallbackInterface::AsyncErrorReason) override;
+
+ private:
+ ScannerImpl* scanner_impl_;
+};
+
+} // namespace wificond
+} // namespace android
+
+#endif // WIFICOND_SCANNER_OFFLOAD_SCAN_CALLBACK_INTERFACE_IML_H_
#include <android-base/logging.h>
#include "wificond/client_interface_impl.h"
-#include "wificond/scanning/scan_utils.h"
-#include "wificond/scanning/offload/offload_service_utils.h"
#include "wificond/scanning/offload/offload_scan_manager.h"
+#include "wificond/scanning/offload/offload_service_utils.h"
+#include "wificond/scanning/scan_utils.h"
using android::binder::Status;
using android::net::wifi::IPnoScanEvent;
using std::string;
using std::vector;
using std::weak_ptr;
+using std::shared_ptr;
using namespace std::placeholders;
namespace android {
namespace wificond {
-ScannerImpl::ScannerImpl(uint32_t wiphy_index,
- uint32_t interface_index,
+ScannerImpl::ScannerImpl(uint32_t wiphy_index, uint32_t interface_index,
const ScanCapabilities& scan_capabilities,
const WiphyFeatures& wiphy_features,
ClientInterfaceImpl* client_interface,
- NetlinkUtils* netlink_utils,
- ScanUtils* scan_utils,
+ NetlinkUtils* netlink_utils, ScanUtils* scan_utils,
weak_ptr<OffloadServiceUtils> offload_service_utils)
: valid_(true),
scan_started_(false),
<< (int)interface_index_;
scan_utils_->SubscribeScanResultNotification(
interface_index_,
- std::bind(&ScannerImpl::OnScanResultsReady,
- this,
- _1, _2, _3, _4));
+ std::bind(&ScannerImpl::OnScanResultsReady, this, _1, _2, _3, _4));
// Subscribe scheduled scan result notification from kernel.
scan_utils_->SubscribeSchedScanResultNotification(
interface_index_,
std::bind(&ScannerImpl::OnSchedScanResultsReady,
this,
_1, _2));
- offload_scan_manager_.reset(
- new OffloadScanManager(
- offload_service_utils,
- std::bind(&ScannerImpl::OnOffloadScanResult,
- this, _1)));
+ std::shared_ptr<OffloadScanCallbackInterfaceImpl>
+ offload_scan_callback_interface =
+ std::make_shared<OffloadScanCallbackInterfaceImpl>(
+ *(new OffloadScanCallbackInterfaceImpl(this)));
+ offload_scan_manager_.reset(new OffloadScanManager(
+ offload_service_utils, offload_scan_callback_interface));
offload_scan_supported_ = offload_service_utils.lock()->IsOffloadScanSupported();
}
-ScannerImpl::~ScannerImpl() {
-}
+ScannerImpl::~ScannerImpl() {}
void ScannerImpl::Invalidate() {
LOG(INFO) << "Unsubscribe scan result for interface with index: "
return Status::ok();
}
BandInfo band_info;
- if (!netlink_utils_->GetWiphyInfo(wiphy_index_,
- &band_info,
- &scan_capabilities_,
- &wiphy_features_)) {
+ if (!netlink_utils_->GetWiphyInfo(wiphy_index_, &band_info,
+ &scan_capabilities_, &wiphy_features_)) {
LOG(ERROR) << "Failed to get wiphy info from kernel";
out_frequencies->reset(nullptr);
return Status::ok();
}
- out_frequencies->reset(new vector<int32_t>(band_info.band_2g.begin(),
- band_info.band_2g.end()));
+ out_frequencies->reset(
+ new vector<int32_t>(band_info.band_2g.begin(), band_info.band_2g.end()));
return Status::ok();
}
return Status::ok();
}
BandInfo band_info;
- if (!netlink_utils_->GetWiphyInfo(wiphy_index_,
- &band_info,
- &scan_capabilities_,
- &wiphy_features_)) {
+ if (!netlink_utils_->GetWiphyInfo(wiphy_index_, &band_info,
+ &scan_capabilities_, &wiphy_features_)) {
LOG(ERROR) << "Failed to get wiphy info from kernel";
out_frequencies->reset(nullptr);
return Status::ok();
}
- out_frequencies->reset(new vector<int32_t>(band_info.band_5g.begin(),
- band_info.band_5g.end()));
+ out_frequencies->reset(
+ new vector<int32_t>(band_info.band_5g.begin(), band_info.band_5g.end()));
return Status::ok();
}
return Status::ok();
}
BandInfo band_info;
- if (!netlink_utils_->GetWiphyInfo(wiphy_index_,
- &band_info,
- &scan_capabilities_,
- &wiphy_features_)) {
+ if (!netlink_utils_->GetWiphyInfo(wiphy_index_, &band_info,
+ &scan_capabilities_, &wiphy_features_)) {
LOG(ERROR) << "Failed to get wiphy info from kernel";
out_frequencies->reset(nullptr);
return Status::ok();
LOG(WARNING) << "Scan already started";
}
// Only request MAC address randomization when station is not associated.
- bool request_random_mac = wiphy_features_.supports_random_mac_oneshot_scan &&
- !client_interface_->IsAssociated();
+ bool request_random_mac = wiphy_features_.supports_random_mac_oneshot_scan &&
+ !client_interface_->IsAssociated();
// Initialize it with an empty ssid for a wild card scan.
vector<vector<uint8_t>> ssids = {{}};
Status ScannerImpl::startPnoScan(const PnoSettings& pno_settings,
bool* out_success) {
- if (!offload_scan_supported_ || !StartPnoScanOffload(pno_settings)) {
- *out_success = StartPnoScanDefault(pno_settings);
- } else {
+ pno_settings_ = pno_settings;
+ if (offload_scan_supported_ && StartPnoScanOffload(pno_settings)) {
// scanning over offload succeeded
*out_success = true;
+ } else {
+ *out_success = StartPnoScanDefault(pno_settings);
}
return Status::ok();
}
// Empty frequency list: scan all frequencies.
vector<uint32_t> freqs;
- ParsePnoSettings(pno_settings, &scan_ssids, &match_ssids, &freqs, &match_security);
-
- bool success = offload_scan_manager_->startScan(
- pno_settings.interval_ms_,
- // TODO: honor both rssi thresholds.
- pno_settings.min_5g_rssi_,
- scan_ssids,
- match_ssids,
- match_security,
- freqs,
- &reason_code);
- return success;
+ ParsePnoSettings(pno_settings, &scan_ssids, &match_ssids, &freqs,
+ &match_security);
+
+ pno_scan_running_over_offload_ = offload_scan_manager_->startScan(
+ pno_settings.interval_ms_,
+ // TODO: honor both rssi thresholds.
+ pno_settings.min_5g_rssi_, scan_ssids, match_ssids, match_security, freqs,
+ &reason_code);
+ if (pno_scan_running_over_offload_) {
+ LOG(VERBOSE) << "Pno scans requested over Offload HAL";
+ if (pno_scan_event_handler_ != nullptr) {
+ pno_scan_event_handler_->OnPnoScanOverOffloadStarted();
+ }
+ }
+ return pno_scan_running_over_offload_;
}
void ScannerImpl::ParsePnoSettings(const PnoSettings& pno_settings,
- vector<vector<uint8_t>>* scan_ssids,
- vector<vector<uint8_t>>* match_ssids,
- vector<uint32_t>* freqs,
- vector<uint8_t>* match_security) {
+ vector<vector<uint8_t>>* scan_ssids,
+ vector<vector<uint8_t>>* match_ssids,
+ vector<uint32_t>* freqs,
+ vector<uint8_t>* match_security) {
// TODO provide actionable security match parameters
const uint8_t kNetworkFlagsDefault = 0;
vector<vector<uint8_t>> skipped_scan_ssids;
// Add hidden network ssid.
if (network.is_hidden_) {
// TODO remove pruning for Offload Scans
- if (scan_ssids->size() + 1 > scan_capabilities_.max_num_sched_scan_ssids) {
+ if (scan_ssids->size() + 1 >
+ scan_capabilities_.max_num_sched_scan_ssids) {
skipped_scan_ssids.emplace_back(network.ssid_);
continue;
}
bool ScannerImpl::StartPnoScanDefault(const PnoSettings& pno_settings) {
if (!CheckIsValid()) {
- return false;
+ return false;
}
if (pno_scan_started_) {
LOG(WARNING) << "Pno scan already started";
}
Status ScannerImpl::stopPnoScan(bool* out_success) {
- if (!offload_scan_supported_ || !StopPnoScanOffload()) {
- *out_success = StopPnoScanDefault();
- } else {
+ if (offload_scan_supported_ && StopPnoScanOffload()) {
// Pno scans over offload stopped successfully
*out_success = true;
+ } else {
+ // Pno scans were not requested over offload
+ *out_success = StopPnoScanDefault();
}
return Status::ok();
}
bool ScannerImpl::StopPnoScanOffload() {
OffloadScanManager::ReasonCode reason_code;
- return(offload_scan_manager_->stopScan(&reason_code));
+ if (!pno_scan_running_over_offload_) {
+ return false;
+ }
+ if (!offload_scan_manager_->stopScan(&reason_code)) {
+ LOG(WARNING) << "Unable to unsubscribe to Offload scan results";
+ }
+ pno_scan_running_over_offload_ = false;
+ LOG(VERBOSE) << "Pno scans over Offload stopped";
+ return true;
}
bool ScannerImpl::StopPnoScanDefault() {
return Status::ok();
}
-
Status ScannerImpl::subscribePnoScanEvents(const sp<IPnoScanEvent>& handler) {
if (!CheckIsValid()) {
return Status::ok();
return Status::ok();
}
-void ScannerImpl::OnScanResultsReady(
- uint32_t interface_index,
- bool aborted,
- vector<vector<uint8_t>>& ssids,
- vector<uint32_t>& frequencies) {
+void ScannerImpl::OnScanResultsReady(uint32_t interface_index, bool aborted,
+ vector<vector<uint8_t>>& ssids,
+ vector<uint32_t>& frequencies) {
if (!scan_started_) {
LOG(INFO) << "Received external scan result notification from kernel.";
}
}
}
+void ScannerImpl::OnOffloadScanResult() {
+ if (!pno_scan_running_over_offload_) {
+ LOG(WARNING) << "Scan results from Offload HAL but scan not requested over "
+ "this interface";
+ return;
+ }
+ LOG(INFO) << "Offload Scan results received";
+ if (pno_scan_event_handler_ != nullptr) {
+ pno_scan_event_handler_->OnPnoNetworkFound();
+ } else {
+ LOG(WARNING) << "No scan event handler Offload Scan result";
+ }
+}
+
+void ScannerImpl::OnOffloadError(
+ OffloadScanCallbackInterface::AsyncErrorReason error_code) {
+ bool success;
+ if (!pno_scan_running_over_offload_) {
+ // Ignore irrelevant error notifications
+ LOG(WARNING) << "Offload HAL Async Error occured but Offload HAL is not "
+ "subscribed to";
+ return;
+ }
+ LOG(ERROR) << "Offload Service Async Failure error_code=" << error_code;
+ // Stop scans over Offload HAL and request them over netlink
+ stopPnoScan(&success);
+ if (success) {
+ LOG(INFO) << "Pno scans stopped";
+ }
+ switch (error_code) {
+ case OffloadScanCallbackInterface::AsyncErrorReason::BINDER_DEATH:
+ if (pno_scan_event_handler_ != nullptr) {
+ pno_scan_event_handler_->OnPnoScanOverOffloadFailed(
+ net::wifi::IPnoScanEvent::PNO_SCAN_OVER_OFFLOAD_BINDER_FAILURE);
+ }
+ break;
+ case OffloadScanCallbackInterface::AsyncErrorReason::REMOTE_FAILURE:
+ if (pno_scan_event_handler_ != nullptr) {
+ pno_scan_event_handler_->OnPnoScanOverOffloadFailed(
+ net::wifi::IPnoScanEvent::PNO_SCAN_OVER_OFFLOAD_REMOTE_FAILURE);
+ }
+ break;
+ default:
+ LOG(WARNING) << "Invalid Error code";
+ break;
+ }
+ startPnoScan(pno_settings_, &success);
+ if (success) {
+ LOG(INFO) << "Pno scans restarted";
+ }
+}
+
void ScannerImpl::LogSsidList(vector<vector<uint8_t>>& ssid_list,
string prefix) {
if (ssid_list.empty()) {
LOG(WARNING) << prefix << ": " << ssid_list_string;
}
-void ScannerImpl::OnOffloadScanResult(
- std::vector<NativeScanResult> scanResult) {
- LOG(INFO) << "Offload Scan results received";
- if (pno_scan_event_handler_ != nullptr) {
- pno_scan_event_handler_->OnPnoNetworkFound();
- } else {
- LOG(WARNING) << "No scan event handler Offload Scan result";
- }
-}
-
} // namespace wificond
} // namespace android
#include "wificond/net/netlink_utils.h"
#include "wificond/scanning/offload/offload_scan_manager.h"
#include "wificond/scanning/scan_utils.h"
+#include "wificond/scanning/offload_scan_callback_interface_impl.h"
namespace android {
namespace wificond {
class ClientInterfaceImpl;
class OffloadServiceUtils;
+class ScanUtils;
+class OffloadScanCallbackInterfaceImpl;
class ScannerImpl : public android::net::wifi::BnWifiScannerImpl {
public:
- ScannerImpl(uint32_t wiphy_index,
- uint32_t interface_index,
+ ScannerImpl(uint32_t wiphy_index, uint32_t interface_index,
const ScanCapabilities& scan_capabilities,
const WiphyFeatures& wiphy_features,
ClientInterfaceImpl* client_interface,
- NetlinkUtils* netlink_utils,
- ScanUtils* scan_utils,
+ NetlinkUtils* netlink_utils, ScanUtils* scan_utils,
std::weak_ptr<OffloadServiceUtils> offload_service_utils);
~ScannerImpl();
// Returns a vector of available frequencies for 2.4GHz channels.
const ::android::sp<::android::net::wifi::IScanEvent>& handler) override;
::android::binder::Status unsubscribeScanEvents() override;
::android::binder::Status subscribePnoScanEvents(
- const ::android::sp<::android::net::wifi::IPnoScanEvent>& handler) override;
+ const ::android::sp<::android::net::wifi::IPnoScanEvent>& handler)
+ override;
::android::binder::Status unsubscribePnoScanEvents() override;
+ void OnOffloadScanResult();
+ void OnOffloadError(
+ OffloadScanCallbackInterface::AsyncErrorReason error_code);
void Invalidate();
private:
bool CheckIsValid();
- void OnOffloadScanResult(
- std::vector<::com::android::server::wifi::wificond::NativeScanResult>);
- void OnScanResultsReady(
- uint32_t interface_index,
- bool aborted,
- std::vector<std::vector<uint8_t>>& ssids,
- std::vector<uint32_t>& frequencies);
+ void OnScanResultsReady(uint32_t interface_index, bool aborted,
+ std::vector<std::vector<uint8_t>>& ssids,
+ std::vector<uint32_t>& frequencies);
void OnSchedScanResultsReady(uint32_t interface_index, bool scan_stopped);
void LogSsidList(std::vector<std::vector<uint8_t>>& ssid_list,
std::string prefix);
bool StopPnoScanDefault();
bool StopPnoScanOffload();
void ParsePnoSettings(
- const ::com::android::server::wifi::wificond::PnoSettings& pno_settings,
- std::vector<std::vector<uint8_t>>* scan_ssids,
- std::vector<std::vector<uint8_t>>* match_ssids,
- std::vector<uint32_t>* freqs,
- std::vector<uint8_t>* match_security);
+ const ::com::android::server::wifi::wificond::PnoSettings& pno_settings,
+ std::vector<std::vector<uint8_t>>* scan_ssids,
+ std::vector<std::vector<uint8_t>>* match_ssids,
+ std::vector<uint32_t>* freqs, std::vector<uint8_t>* match_security);
SchedScanIntervalSetting GenerateIntervalSetting(
const ::com::android::server::wifi::wificond::PnoSettings& pno_settings) const;
bool scan_started_;
bool pno_scan_started_;
bool offload_scan_supported_;
+ bool pno_scan_running_over_offload_;
+ ::com::android::server::wifi::wificond::PnoSettings pno_settings_;
const uint32_t wiphy_index_;
const uint32_t interface_index_;
--- /dev/null
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "wificond/tests/mock_offload_scan_callback_interface.h"
+
+namespace android {
+namespace wificond {
+
+MockOffloadScanCallbackInterface::MockOffloadScanCallbackInterface() {}
+
+} // namespace wificond
+} // namespace android
--- /dev/null
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef WIFICOND_TESTS_MOCK_OFFLOAD_CALLBACK_HANDLERS_H_
+#define WIFICOND_TESTS_MOCK_OFFLOAD_CALLBACK_HANDLERS_H_
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#include "wificond/scanning/offload_scan_callback_interface.h"
+
+namespace android {
+namespace wificond {
+
+class MockOffloadScanCallbackInterface : public OffloadScanCallbackInterface {
+ public:
+ MockOffloadScanCallbackInterface();
+ ~MockOffloadScanCallbackInterface() override = default;
+
+ MOCK_METHOD0(OnOffloadScanResult, void());
+ MOCK_METHOD1(OnOffloadError,
+ void(OffloadScanCallbackInterface::AsyncErrorReason));
+};
+
+} // namespace wificond
+} // namespace android
+
+#endif // WIFICOND_TESTS_MOCK_OFFLOAD_CALLBACK_HANDLERS_H_
#include <gtest/gtest.h>
#include "wificond/tests/mock_offload.h"
+#include "wificond/tests/mock_offload_scan_callback_interface.h"
#include "wificond/tests/mock_offload_service_utils.h"
#include "wificond/tests/offload_hal_test_constants.h"
#include "wificond/tests/offload_test_utils.h"
sp<OffloadDeathRecipient> death_recipient_;
shared_ptr<NiceMock<MockOffloadServiceUtils>> mock_offload_service_utils_{
new NiceMock<MockOffloadServiceUtils>()};
+ shared_ptr<NiceMock<MockOffloadScanCallbackInterface>>
+ mock_offload_scan_callback_interface_{
+ new NiceMock<MockOffloadScanCallbackInterface>()};
unique_ptr<OffloadScanManager> offload_scan_manager_;
OffloadStatus status;
vector<vector<uint8_t>> scan_ssids{kSsid1, kSsid2};
ON_CALL(*mock_offload_service_utils_, GetOffloadService())
.WillByDefault(testing::Return(mock_offload_));
offload_scan_manager_.reset(new OffloadScanManager(
- mock_offload_service_utils_,
- [](vector<NativeScanResult> scanResult) -> void {}));
+ mock_offload_service_utils_, mock_offload_scan_callback_interface_));
+ EXPECT_CALL(*mock_offload_scan_callback_interface_, OnOffloadError(_));
death_recipient_->serviceDied(cookie_, mock_offload_);
EXPECT_EQ(OffloadScanManager::kNoService,
offload_scan_manager_->getOffloadStatus());
ON_CALL(*mock_offload_service_utils_, GetOffloadService())
.WillByDefault(testing::Return(mock_offload_));
offload_scan_manager_.reset(new OffloadScanManager(
- mock_offload_service_utils_,
- [](vector<NativeScanResult> scanResult) -> void {}));
+ mock_offload_service_utils_, mock_offload_scan_callback_interface_));
death_recipient_->serviceDied(kDeathCode, mock_offload_);
EXPECT_FALSE(OffloadScanManager::kNoService ==
offload_scan_manager_->getOffloadStatus());
ON_CALL(*mock_offload_service_utils_, GetOffloadService())
.WillByDefault(testing::Return(nullptr));
offload_scan_manager_.reset(new OffloadScanManager(
- mock_offload_service_utils_,
- [](vector<NativeScanResult> scanResult) -> void {}));
+ mock_offload_service_utils_, mock_offload_scan_callback_interface_));
EXPECT_EQ(OffloadScanManager::kNoService,
offload_scan_manager_->getOffloadStatus());
}
ON_CALL(*mock_offload_service_utils_, GetOffloadService())
.WillByDefault(testing::Return(mock_offload_));
offload_scan_manager_.reset(new OffloadScanManager(
- mock_offload_service_utils_,
- [](vector<NativeScanResult> scanResult) -> void {}));
+ mock_offload_service_utils_, mock_offload_scan_callback_interface_));
EXPECT_EQ(OffloadScanManager::kNoError,
offload_scan_manager_->getOffloadStatus());
}
* scan results are available
*/
TEST_F(OffloadScanManagerTest, CallbackInvokedTest) {
- bool callback_invoked = false;
EXPECT_CALL(*mock_offload_service_utils_, GetOffloadService());
EXPECT_CALL(*mock_offload_service_utils_, GetOffloadCallback(_));
EXPECT_CALL(*mock_offload_service_utils_, GetOffloadDeathRecipient(_));
ON_CALL(*mock_offload_service_utils_, GetOffloadService())
.WillByDefault(testing::Return(mock_offload_));
+ EXPECT_CALL(*mock_offload_scan_callback_interface_, OnOffloadScanResult());
offload_scan_manager_.reset(new OffloadScanManager(
- mock_offload_service_utils_,
- [&callback_invoked](vector<NativeScanResult> scanResult) -> void {
- callback_invoked = true;
- }));
+ mock_offload_service_utils_, mock_offload_scan_callback_interface_));
vector<ScanResult> dummy_scan_results_ =
OffloadTestUtils::createOffloadScanResults();
offload_callback_->onScanResult(dummy_scan_results_);
- EXPECT_EQ(true, callback_invoked);
}
/**
ON_CALL(*mock_offload_service_utils_, GetOffloadService())
.WillByDefault(testing::Return(mock_offload_));
offload_scan_manager_.reset(new OffloadScanManager(
- mock_offload_service_utils_,
- [](vector<NativeScanResult> scanResult) -> void {}));
+ mock_offload_service_utils_, mock_offload_scan_callback_interface_));
OffloadStatus status =
OffloadTestUtils::createOffloadStatus(OffloadStatusCode::ERROR);
+ EXPECT_CALL(*mock_offload_scan_callback_interface_, OnOffloadError(_));
offload_callback_->onError(status);
EXPECT_EQ(offload_scan_manager_->getOffloadStatus(),
OffloadScanManager::kError);
ON_CALL(*mock_offload_service_utils_, GetOffloadService())
.WillByDefault(testing::Return(mock_offload_));
offload_scan_manager_.reset(new OffloadScanManager(
- mock_offload_service_utils_,
- [](vector<NativeScanResult> scanResult) -> void {}));
+ mock_offload_service_utils_, mock_offload_scan_callback_interface_));
EXPECT_CALL(*mock_offload_, subscribeScanResults(_, _));
EXPECT_CALL(*mock_offload_, configureScans(_, _, _));
OffloadScanManager::ReasonCode reason_code = OffloadScanManager::kNone;
ON_CALL(*mock_offload_service_utils_, GetOffloadService())
.WillByDefault(testing::Return(nullptr));
offload_scan_manager_.reset(new OffloadScanManager(
- mock_offload_service_utils_,
- [](vector<NativeScanResult> scanResult) -> void {}));
+ mock_offload_service_utils_, mock_offload_scan_callback_interface_));
OffloadScanManager::ReasonCode reason_code = OffloadScanManager::kNone;
bool result = offload_scan_manager_->startScan(
kDisconnectedModeScanIntervalMs, kRssiThreshold, scan_ssids, match_ssids,
ON_CALL(*mock_offload_service_utils_, GetOffloadService())
.WillByDefault(testing::Return(mock_offload_));
offload_scan_manager_.reset(new OffloadScanManager(
- mock_offload_service_utils_,
- [](vector<NativeScanResult> scanResult) -> void {}));
+ mock_offload_service_utils_, mock_offload_scan_callback_interface_));
OffloadStatus status =
OffloadTestUtils::createOffloadStatus(OffloadStatusCode::NO_CONNECTION);
offload_callback_->onError(status);
ON_CALL(*mock_offload_service_utils_, GetOffloadService())
.WillByDefault(testing::Return(mock_offload_));
offload_scan_manager_.reset(new OffloadScanManager(
- mock_offload_service_utils_,
- [](vector<NativeScanResult> scanResult) -> void {}));
- EXPECT_CALL(*mock_offload_, subscribeScanResults(_, _)).Times(1);
+ mock_offload_service_utils_, mock_offload_scan_callback_interface_));
+ EXPECT_CALL(*mock_offload_, subscribeScanResults(_, _)).Times(2);
EXPECT_CALL(*mock_offload_, configureScans(_, _, _)).Times(2);
OffloadScanManager::ReasonCode reason_code = OffloadScanManager::kNone;
bool result = offload_scan_manager_->startScan(
ON_CALL(*mock_offload_service_utils_, GetOffloadService())
.WillByDefault(testing::Return(mock_offload_));
offload_scan_manager_.reset(new OffloadScanManager(
- mock_offload_service_utils_,
- [](vector<NativeScanResult> scanResult) -> void {}));
+ mock_offload_service_utils_, mock_offload_scan_callback_interface_));
EXPECT_CALL(*mock_offload_, subscribeScanResults(_, _));
EXPECT_CALL(*mock_offload_, configureScans(_, _, _));
EXPECT_CALL(*mock_offload_, unsubscribeScanResults());
/**
* Testing OffloadScanManager for unsubscribing to the scan results from
- * Offload HAL without first subscribing
- */
-TEST_F(OffloadScanManagerTest, StopScanTestWithoutStartWhenServiceIsOk) {
- EXPECT_CALL(*mock_offload_service_utils_, GetOffloadService());
- EXPECT_CALL(*mock_offload_service_utils_, GetOffloadCallback(_));
- EXPECT_CALL(*mock_offload_service_utils_, GetOffloadDeathRecipient(_));
- ON_CALL(*mock_offload_service_utils_, GetOffloadService())
- .WillByDefault(testing::Return(mock_offload_));
- offload_scan_manager_.reset(new OffloadScanManager(
- mock_offload_service_utils_,
- [](vector<NativeScanResult> scanResult) -> void {}));
- OffloadScanManager::ReasonCode reason_code = OffloadScanManager::kNone;
- bool result = offload_scan_manager_->stopScan(&reason_code);
- EXPECT_EQ(result, false);
- EXPECT_EQ(reason_code, OffloadScanManager::kNotSubscribed);
-}
-
-/**
- * Testing OffloadScanManager for unsubscribing to the scan results from
- * Offload HAL without first subscribing when service is not working correctly
+ * when service is not connected to the hardware
*/
TEST_F(OffloadScanManagerTest, StopScanTestWhenServiceIsNotConnectedAnymore) {
EXPECT_CALL(*mock_offload_service_utils_, GetOffloadService());
ON_CALL(*mock_offload_service_utils_, GetOffloadService())
.WillByDefault(testing::Return(mock_offload_));
offload_scan_manager_.reset(new OffloadScanManager(
- mock_offload_service_utils_,
- [](vector<NativeScanResult> scanResult) -> void {}));
+ mock_offload_service_utils_, mock_offload_scan_callback_interface_));
EXPECT_CALL(*mock_offload_, subscribeScanResults(_, _));
EXPECT_CALL(*mock_offload_, configureScans(_, _, _));
- EXPECT_CALL(*mock_offload_, unsubscribeScanResults());
OffloadScanManager::ReasonCode reason_code = OffloadScanManager::kNone;
bool result = offload_scan_manager_->startScan(
kDisconnectedModeScanIntervalMs, kRssiThreshold, scan_ssids, match_ssids,
OffloadTestUtils::createOffloadStatus(OffloadStatusCode::NO_CONNECTION);
offload_callback_->onError(status);
result = offload_scan_manager_->stopScan(&reason_code);
- EXPECT_EQ(result, true);
+ EXPECT_EQ(result, false);
}
/**
ON_CALL(*mock_offload_service_utils_, GetOffloadService())
.WillByDefault(testing::Return(mock_offload_));
offload_scan_manager_.reset(new OffloadScanManager(
- mock_offload_service_utils_,
- [](vector<NativeScanResult> scanResult) -> void {}));
+ mock_offload_service_utils_, mock_offload_scan_callback_interface_));
EXPECT_CALL(*mock_offload_, getScanStats(_));
NativeScanStats stats;
bool result = offload_scan_manager_->getScanStats(&stats);
ON_CALL(*mock_offload_service_utils_, GetOffloadService())
.WillByDefault(testing::Return(mock_offload_));
offload_scan_manager_.reset(new OffloadScanManager(
- mock_offload_service_utils_,
- [](vector<NativeScanResult> scanResult) -> void {}));
+ mock_offload_service_utils_, mock_offload_scan_callback_interface_));
OffloadStatus status =
OffloadTestUtils::createOffloadStatus(OffloadStatusCode::NO_CONNECTION);
offload_callback_->onError(status);
ON_CALL(*mock_offload_service_utils_, GetOffloadService())
.WillByDefault(testing::Return(mock_offload_));
offload_scan_manager_.reset(new OffloadScanManager(
- mock_offload_service_utils_,
- [](vector<NativeScanResult> scanResult) -> void {}));
+ mock_offload_service_utils_, mock_offload_scan_callback_interface_));
EXPECT_CALL(*mock_offload_, subscribeScanResults(_, _)).Times(0);
EXPECT_CALL(*mock_offload_, configureScans(_, _, _)).Times(1);
status = OffloadTestUtils::createOffloadStatus(OffloadStatusCode::ERROR);
ON_CALL(*mock_offload_service_utils_, GetOffloadService())
.WillByDefault(testing::Return(mock_offload_));
offload_scan_manager_.reset(new OffloadScanManager(
- mock_offload_service_utils_,
- [](vector<NativeScanResult> scanResult) -> void {}));
+ mock_offload_service_utils_, mock_offload_scan_callback_interface_));
status = OffloadTestUtils::createOffloadStatus(OffloadStatusCode::TIMEOUT);
EXPECT_CALL(*mock_offload_, getScanStats(_));
NativeScanStats stats;