OSDN Git Service

Wificond: Async Errors from Offload HAL service
authorSohani Rao <sohanirao@google.com>
Wed, 12 Jul 2017 00:59:54 +0000 (17:59 -0700)
committerSohani Rao <sohanirao@google.com>
Sat, 12 Aug 2017 00:21:29 +0000 (17:21 -0700)
Asynchronous errors from the Offload HAL service must be forwarded to
Wificond scanner implementation which can then switch over to the other
interfaces for completing disconnected PNO scans. This requires
specification of an interface from Offload HAL client to Wificond's
scanner implementation. Unit tetsts are updated accordingly.

Bug: 32842314
Test: Unit test and VTS
Change-Id: Ie56a52caf161c851d1945584a2bf93734008598a

12 files changed:
Android.mk
scanning/offload/offload_scan_manager.cpp
scanning/offload/offload_scan_manager.h
scanning/offload/offload_service_utils.cpp
scanning/offload_scan_callback_interface.h [new file with mode: 0644]
scanning/offload_scan_callback_interface_impl.cpp [new file with mode: 0644]
scanning/offload_scan_callback_interface_impl.h [new file with mode: 0644]
scanning/scanner_impl.cpp
scanning/scanner_impl.h
tests/mock_offload_scan_callback_interface.cpp [new file with mode: 0644]
tests/mock_offload_scan_callback_interface.h [new file with mode: 0644]
tests/offload_scan_manager_test.cpp

index a5dc6e0..fd42006 100644 (file)
@@ -66,6 +66,7 @@ LOCAL_SRC_FILES := \
     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 \
@@ -175,6 +176,7 @@ LOCAL_SRC_FILES := \
     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 \
index 5e3d90d..5c73362 100644 (file)
@@ -35,11 +35,11 @@ using android::hardware::wifi::offload::V1_0::OffloadStatus;
 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;
 
@@ -69,19 +69,15 @@ void OffloadCallbackHandlersImpl::OnErrorHandler(const OffloadStatus& status) {
   }
 }
 
-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";
@@ -110,14 +106,15 @@ OffloadScanManager::OffloadScanManager(weak_ptr<OffloadServiceUtils> utils,
 }
 
 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;
@@ -177,12 +174,13 @@ bool OffloadScanManager::startScan(
     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;
 }
 
@@ -214,6 +212,14 @@ OffloadScanManager::StatusCode OffloadScanManager::getOffloadStatus() const {
   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";
@@ -230,11 +236,13 @@ OffloadScanManager::~OffloadScanManager() {
 
 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";
   }
 }
 
@@ -260,6 +268,12 @@ void OffloadScanManager::ReportError(const OffloadStatus& status) {
   }
   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;
 }
@@ -267,6 +281,14 @@ void OffloadScanManager::ReportError(const OffloadStatus& status) {
 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";
   }
 }
index e2c2b0c..c928ba9 100644 (file)
@@ -20,6 +20,7 @@
 #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>
 
@@ -43,11 +44,6 @@ namespace wificond {
 
 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:
@@ -86,21 +82,19 @@ class OffloadScanManager {
     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 */,
@@ -108,9 +102,8 @@ class OffloadScanManager {
                  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 */
@@ -118,6 +111,10 @@ class OffloadScanManager {
       ::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(
@@ -143,10 +140,11 @@ class OffloadScanManager {
   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;
 };
index 2a14a32..da26b71 100644 (file)
@@ -14,6 +14,9 @@
  * 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;
diff --git a/scanning/offload_scan_callback_interface.h b/scanning/offload_scan_callback_interface.h
new file mode 100644 (file)
index 0000000..507a69f
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * 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
diff --git a/scanning/offload_scan_callback_interface_impl.cpp b/scanning/offload_scan_callback_interface_impl.cpp
new file mode 100644 (file)
index 0000000..a3e39da
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * 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
diff --git a/scanning/offload_scan_callback_interface_impl.h b/scanning/offload_scan_callback_interface_impl.h
new file mode 100644 (file)
index 0000000..0f500a4
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * 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_
index 9bf13b3..e9ff517 100644 (file)
@@ -22,9 +22,9 @@
 #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;
@@ -39,19 +39,18 @@ using std::pair;
 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),
@@ -70,25 +69,23 @@ ScannerImpl::ScannerImpl(uint32_t wiphy_index,
             << (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: "
@@ -111,17 +108,15 @@ Status ScannerImpl::getAvailable2gChannels(
     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();
 }
 
@@ -131,17 +126,15 @@ Status ScannerImpl::getAvailable5gNonDFSChannels(
     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();
 }
 
@@ -151,10 +144,8 @@ Status ScannerImpl::getAvailableDFSChannels(
     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();
@@ -186,8 +177,8 @@ Status ScannerImpl::scan(const SingleScanSettings& scan_settings,
     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 = {{}};
@@ -222,11 +213,12 @@ Status ScannerImpl::scan(const SingleScanSettings& scan_settings,
 
 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();
 }
@@ -239,25 +231,28 @@ bool ScannerImpl::StartPnoScanOffload(const PnoSettings& pno_settings) {
   // 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;
@@ -266,7 +261,8 @@ void ScannerImpl::ParsePnoSettings(const PnoSettings& pno_settings,
     // 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;
       }
@@ -287,7 +283,7 @@ void ScannerImpl::ParsePnoSettings(const PnoSettings& pno_settings,
 
 bool ScannerImpl::StartPnoScanDefault(const PnoSettings& pno_settings) {
   if (!CheckIsValid()) {
-      return false;
+    return false;
   }
   if (pno_scan_started_) {
     LOG(WARNING) << "Pno scan already started";
@@ -324,18 +320,27 @@ bool ScannerImpl::StartPnoScanDefault(const PnoSettings& pno_settings) {
 }
 
 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() {
@@ -387,7 +392,6 @@ Status ScannerImpl::unsubscribeScanEvents() {
   return Status::ok();
 }
 
-
 Status ScannerImpl::subscribePnoScanEvents(const sp<IPnoScanEvent>& handler) {
   if (!CheckIsValid()) {
     return Status::ok();
@@ -407,11 +411,9 @@ Status ScannerImpl::unsubscribePnoScanEvents() {
   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.";
   }
@@ -476,6 +478,58 @@ SchedScanIntervalSetting ScannerImpl::GenerateIntervalSetting(
   }
 }
 
+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()) {
@@ -491,15 +545,5 @@ void ScannerImpl::LogSsidList(vector<vector<uint8_t>>& ssid_list,
   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
index 2bb9262..e97e967 100644 (file)
 #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.
@@ -71,19 +72,19 @@ class ScannerImpl : public android::net::wifi::BnWifiScannerImpl {
       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);
@@ -94,11 +95,10 @@ class ScannerImpl : public android::net::wifi::BnWifiScannerImpl {
   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;
 
@@ -107,6 +107,8 @@ class ScannerImpl : public android::net::wifi::BnWifiScannerImpl {
   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_;
diff --git a/tests/mock_offload_scan_callback_interface.cpp b/tests/mock_offload_scan_callback_interface.cpp
new file mode 100644 (file)
index 0000000..cb76e45
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * 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
diff --git a/tests/mock_offload_scan_callback_interface.h b/tests/mock_offload_scan_callback_interface.h
new file mode 100644 (file)
index 0000000..e7cdcc1
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * 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_
index 2dbf953..9c612ae 100644 (file)
@@ -23,6 +23,7 @@
 #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"
@@ -112,6 +113,9 @@ class OffloadScanManagerTest : public ::testing::Test {
   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};
@@ -131,8 +135,8 @@ TEST_F(OffloadScanManagerTest, BinderDeathRegisteredCookieAndService) {
   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());
@@ -147,8 +151,7 @@ TEST_F(OffloadScanManagerTest, BinderDeathUnregisteredCookie) {
   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());
@@ -163,8 +166,7 @@ TEST_F(OffloadScanManagerTest, ServiceNotAvailableTest) {
   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());
 }
@@ -180,8 +182,7 @@ TEST_F(OffloadScanManagerTest, ServiceAvailableTest) {
   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());
 }
@@ -192,21 +193,17 @@ TEST_F(OffloadScanManagerTest, ServiceAvailableTest) {
  * 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);
 }
 
 /**
@@ -220,10 +217,10 @@ TEST_F(OffloadScanManagerTest, ErrorCallbackInvokedTest) {
   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);
@@ -240,8 +237,7 @@ TEST_F(OffloadScanManagerTest, StartScanTestWhenServiceIsOk) {
   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;
@@ -260,8 +256,7 @@ TEST_F(OffloadScanManagerTest, StartScanTestWhenServiceIsNotAvailable) {
   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,
@@ -281,8 +276,7 @@ TEST_F(OffloadScanManagerTest, StartScanTestWhenServiceIsNotConnected) {
   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);
@@ -305,9 +299,8 @@ TEST_F(OffloadScanManagerTest, StartScanTwiceTestWhenServiceIsOk) {
   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(
@@ -331,8 +324,7 @@ TEST_F(OffloadScanManagerTest, StopScanTestWhenServiceIsOk) {
   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());
@@ -347,26 +339,7 @@ TEST_F(OffloadScanManagerTest, StopScanTestWhenServiceIsOk) {
 
 /**
  * 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());
@@ -374,11 +347,9 @@ TEST_F(OffloadScanManagerTest, StopScanTestWhenServiceIsNotConnectedAnymore) {
   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,
@@ -388,7 +359,7 @@ TEST_F(OffloadScanManagerTest, StopScanTestWhenServiceIsNotConnectedAnymore) {
       OffloadTestUtils::createOffloadStatus(OffloadStatusCode::NO_CONNECTION);
   offload_callback_->onError(status);
   result = offload_scan_manager_->stopScan(&reason_code);
-  EXPECT_EQ(result, true);
+  EXPECT_EQ(result, false);
 }
 
 /**
@@ -402,8 +373,7 @@ TEST_F(OffloadScanManagerTest, getScanStatsTestWhenServiceIsOk) {
   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);
@@ -421,8 +391,7 @@ TEST_F(OffloadScanManagerTest, getScanStatsTestWhenServiceIsNotOk) {
   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);
@@ -443,8 +412,7 @@ TEST_F(OffloadScanManagerTest, StartScanFailedTest) {
   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);
@@ -467,8 +435,7 @@ TEST_F(OffloadScanManagerTest, getScanStatsFailedTest) {
   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;