OSDN Git Service

Wificond: Client for Offload HAL HIDL service
authorSohani Rao <sohanirao@google.com>
Thu, 22 Dec 2016 04:34:27 +0000 (20:34 -0800)
committerSohani Rao <sohanirao@google.com>
Mon, 3 Apr 2017 23:50:55 +0000 (16:50 -0700)
This CL creates the client side implementation for Offload HAL and
exports it's API's to wificond. It also creates the interface object
for callback from the Offload HAL.
Cherry pick from 1f05294be907f55add2533e83fca1cea440a6d6c
Bug: 32842314
Test: Unit tests and Mannual tests of verifying Wifi can be turned on
connected and ensure we are getting a handle on Offload HAL service
Change-Id: Ie63b31742a6b53d60c4c2a3560829fc69a2a5f3d

Android.mk
scanning/offload/offload_callback.cpp [new file with mode: 0644]
scanning/offload/offload_callback.h [new file with mode: 0644]
scanning/offload/offload_scan_manager.cpp [new file with mode: 0644]
scanning/offload/offload_scan_manager.h [new file with mode: 0644]
scanning/offload/offload_scan_utils.cpp [new file with mode: 0644]
scanning/offload/offload_scan_utils.h [new file with mode: 0644]
scanning/offload/offload_service_utils.cpp [new file with mode: 0644]
scanning/offload/offload_service_utils.h [new file with mode: 0644]
scanning/scanner_impl.cpp
scanning/scanner_impl.h

index e293246..3c7a4bb 100644 (file)
@@ -30,9 +30,13 @@ LOCAL_C_INCLUDES := $(wificond_includes)
 LOCAL_SRC_FILES := \
     main.cpp
 LOCAL_SHARED_LIBRARIES := \
+    android.hardware.wifi.offload@1.0 \
     libbinder \
     libbase \
     libcutils \
+    libhidlbase \
+    libhwbinder \
+    libhidltransport \
     libminijail \
     libutils \
     libwifi-system
@@ -64,10 +68,18 @@ LOCAL_SRC_FILES := \
     scanning/single_scan_settings.cpp \
     scanning/scan_utils.cpp \
     scanning/scanner_impl.cpp \
+    scanning/offload/offload_scan_manager.cpp \
+    scanning/offload/offload_callback.cpp \
+    scanning/offload/offload_service_utils.cpp \
+    scanning/offload/offload_scan_utils.cpp \
     server.cpp
 LOCAL_SHARED_LIBRARIES := \
+    android.hardware.wifi.offload@1.0 \
     libbase \
     libutils \
+    libhidlbase \
+    libhwbinder \
+    libhidltransport \
     libwifi-system
 LOCAL_WHOLE_STATIC_LIBRARIES := \
     libwificond_ipc \
@@ -170,8 +182,12 @@ LOCAL_STATIC_LIBRARIES := \
     libwificond \
     libwificond_nl
 LOCAL_SHARED_LIBRARIES := \
+    android.hardware.wifi.offload@1.0 \
     libbase \
     libbinder \
+    libhidltransport \
+    libhidlbase \
+    libhwbinder \
     liblog \
     libutils \
     libwifi-system
diff --git a/scanning/offload/offload_callback.cpp b/scanning/offload/offload_callback.cpp
new file mode 100644 (file)
index 0000000..3599779
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * 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 <memory>
+#include <vector>
+
+#include <android-base/logging.h>
+
+#include "wificond/scanning/offload/offload_callback.h"
+#include "wificond/scanning/offload/offload_scan_manager.h"
+#include "wificond/scanning/scan_result.h"
+
+using ::android::hardware::wifi::offload::V1_0::ScanResult;
+using ::android::hardware::hidl_vec;
+using ::android::hardware::Return;
+
+namespace android {
+namespace wificond {
+
+OffloadCallback::OffloadCallback(OnOffloadScanResultsReadyHandler handler)
+    : scan_result_handler_(handler) {
+}
+
+// Methods from ::android::hardware::wifi::offload::V1_0::IOffloadCallback follow.
+Return<void> OffloadCallback::onScanResult(const hidl_vec<ScanResult>& scan_result) {
+  if (scan_result_handler_ != nullptr) {
+    scan_result_handler_(std::vector<ScanResult>(scan_result));
+  } else {
+    LOG(WARNING) << "No handler available for Offload scan results";
+  }
+  return Void();
+}
+
+OffloadCallback::~OffloadCallback() {}
+
+}  // namespace wificond
+}  // namespace android
diff --git a/scanning/offload/offload_callback.h b/scanning/offload/offload_callback.h
new file mode 100644 (file)
index 0000000..e3748a8
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * 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 ANDROID_HARDWARE_WIFI_OFFLOAD_V1_0_OFFLOADCALLBACK_H
+#define ANDROID_HARDWARE_WIFI_OFFLOAD_V1_0_OFFLOADCALLBACK_H
+
+#include <android/hardware/wifi/offload/1.0/IOffloadCallback.h>
+#include <hidl/Status.h>
+#include <vector>
+
+namespace android {
+namespace wificond {
+
+using ::android::hardware::hidl_vec;
+using ::android::hardware::wifi::offload::V1_0::IOffloadCallback;
+using ::android::hardware::wifi::offload::V1_0::ScanResult;
+using ::android::hardware::Void;
+using ::android::hidl::base::V1_0::IBase;
+
+typedef std::function<void(
+    const std::vector<ScanResult>& scanResult)> OnOffloadScanResultsReadyHandler;
+
+class OffloadCallback : public IOffloadCallback {
+ public:
+  explicit OffloadCallback(OnOffloadScanResultsReadyHandler handler);
+  virtual ~OffloadCallback();
+
+  // Methods from ::android::hardware::wifi::offload::V1_0::IOffloadCallback follow.
+  ::android::hardware::Return<void> onScanResult(
+      const hidl_vec<ScanResult>& scanResult) override;
+
+  // Methods from ::android::hidl::base::V1_0::IBase follow.
+
+ private:
+  OnOffloadScanResultsReadyHandler scan_result_handler_;
+};
+
+}  // namespace wificond
+}  // namespace android
+
+#endif  // ANDROID_HARDWARE_WIFI_OFFLOAD_V1_0_OFFLOADCALLBACK_H
diff --git a/scanning/offload/offload_scan_manager.cpp b/scanning/offload/offload_scan_manager.cpp
new file mode 100644 (file)
index 0000000..2a1731b
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * 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/offload_scan_manager.h"
+
+#include <vector>
+
+#include <android-base/logging.h>
+
+#include "wificond/scanning/offload/offload_scan_utils.h"
+#include "wificond/scanning/offload/offload_service_utils.h"
+#include "wificond/scanning/scan_result.h"
+
+using ::android::hardware::hidl_vec;
+using android::hardware::wifi::offload::V1_0::IOffload;
+using android::hardware::wifi::offload::V1_0::ScanResult;
+using android::wificond::OffloadCallback;
+using ::com::android::server::wifi::wificond::NativeScanResult;
+using android::wificond::OnNativeScanResultsReadyHandler;
+
+namespace android {
+namespace wificond {
+
+OffloadScanManager::OffloadScanManager(OffloadServiceUtils *utils,
+    OnNativeScanResultsReadyHandler handler)
+    : wifi_offload_hal_(nullptr),
+      wifi_offload_callback_(nullptr),
+      scan_result_handler_(handler) {
+  if (utils == nullptr) return;
+  if (scan_result_handler_ == nullptr) return;
+  wifi_offload_hal_ = utils->GetOffloadService();
+  if (wifi_offload_hal_ == nullptr) {
+    LOG(WARNING) << "No Offload Service available";
+    return;
+  }
+  wifi_offload_callback_ = utils->GetOffloadCallback(
+      std::bind(&OffloadScanManager::ReportScanResults, this,
+          std::placeholders::_1));
+  wifi_offload_hal_->setEventCallback(wifi_offload_callback_);
+}
+
+OffloadScanManager::~OffloadScanManager() {}
+
+void OffloadScanManager::ReportScanResults(
+    const std::vector<ScanResult> scanResult) {
+  if (scan_result_handler_ != nullptr) {
+    scan_result_handler_(OffloadScanUtils::convertToNativeScanResults(scanResult));
+  }
+}
+
+bool OffloadScanManager::isServiceAvailable() const {
+  return wifi_offload_hal_ != nullptr;
+}
+
+}  // namespace wificond
+}  // namespace android
diff --git a/scanning/offload/offload_scan_manager.h b/scanning/offload/offload_scan_manager.h
new file mode 100644 (file)
index 0000000..a45cb98
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * 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_OFFLOAD_SCAN_MANAGER_H_
+#define WIFICOND_OFFLOAD_SCAN_MANAGER_H_
+
+#include <android/hardware/wifi/offload/1.0/IOffload.h>
+#include "wificond/scanning/offload/offload_callback.h"
+#include "wificond/scanning/offload/offload_service_utils.h"
+
+#include <vector>
+
+using ::android::hardware::hidl_vec;
+using android::hardware::wifi::offload::V1_0::ScanResult;
+using android::hardware::wifi::offload::V1_0::IOffload;
+
+using std::unique_ptr;
+
+namespace com {
+namespace android {
+namespace server {
+namespace wifi {
+namespace wificond {
+
+class NativeScanResult;
+
+}  // namespace wificond
+}  // namespace wifi
+}  // namespace server
+}  // namespace android
+}  // namespace com
+
+namespace android {
+namespace wificond {
+
+typedef std::function<void(
+    const std::vector<::com::android::server::wifi::wificond::NativeScanResult>
+        scanResult)> OnNativeScanResultsReadyHandler;
+
+// Provides methods to interact with Offload HAL
+class OffloadScanManager {
+ public:
+  explicit OffloadScanManager(OffloadServiceUtils* utils,
+      OnNativeScanResultsReadyHandler handler);
+  virtual ~OffloadScanManager();
+  bool isServiceAvailable() const;
+
+ private:
+  void ReportScanResults(const std::vector<ScanResult> scanResult);
+
+  android::sp<IOffload> wifi_offload_hal_;
+  android::sp<OffloadCallback> wifi_offload_callback_;
+  OnNativeScanResultsReadyHandler scan_result_handler_;
+};
+
+}  // namespace wificond
+}  // namespace android
+
+#endif // WIFICOND_OFFLOAD_SCAN_MANAGER_H_
diff --git a/scanning/offload/offload_scan_utils.cpp b/scanning/offload/offload_scan_utils.cpp
new file mode 100644 (file)
index 0000000..7f468b5
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * 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/offload_scan_utils.h"
+#include "wificond/scanning/scan_result.h"
+
+using ::com::android::server::wifi::wificond::NativeScanResult;
+using android::hardware::wifi::offload::V1_0::ScanResult;
+
+namespace android {
+namespace wificond {
+
+std::vector<NativeScanResult> OffloadScanUtils::convertToNativeScanResults(
+    const std::vector<ScanResult>& scanResult) {
+  std::vector<NativeScanResult> nativeScanResult;
+  nativeScanResult.reserve(scanResult.size());
+  for (size_t i = 0; i < scanResult.size(); i++) {
+    NativeScanResult singleScanResult;
+    singleScanResult.ssid = scanResult[i].networkInfo.ssid;
+    singleScanResult.bssid.assign(scanResult[i].networkInfo.ssid.begin(),
+      scanResult[i].networkInfo.ssid.end());
+    singleScanResult.frequency = scanResult[i].frequency;
+    singleScanResult.signal_mbm = scanResult[i].rssi;
+    singleScanResult.tsf = scanResult[i].tsf;
+    singleScanResult.capability = scanResult[i].capability;
+    singleScanResult.associated = false;
+    nativeScanResult.emplace_back(singleScanResult);
+  }
+  return nativeScanResult;
+}
+
+} // wificond
+} // android
+
diff --git a/scanning/offload/offload_scan_utils.h b/scanning/offload/offload_scan_utils.h
new file mode 100644 (file)
index 0000000..e1f20a3
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * 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_OFFLOAD_SCAN_UTILS_H_
+#define WIFICOND_OFFLOAD_SCAN_UTILS_H_
+
+#include <android/hardware/wifi/offload/1.0/IOffload.h>
+#include "wificond/scanning/offload/offload_callback.h"
+
+#include <vector>
+
+using android::hardware::wifi::offload::V1_0::ScanResult;
+
+namespace com {
+namespace android {
+namespace server {
+namespace wifi {
+namespace wificond {
+
+class NativeScanResult;
+
+}  // namespace wificond
+}  // namespace wifi
+}  // namespace server
+}  // namespace android
+}  // namespace com
+
+namespace android {
+namespace wificond {
+
+// Provides utility methods for Offload Scan Manager
+class OffloadScanUtils {
+ public:
+  static std::vector<::com::android::server::wifi::wificond::NativeScanResult>
+      convertToNativeScanResults(const std::vector<ScanResult>&);
+};
+
+}  // namespace wificond
+}  // namespace android
+
+#endif // WIFICOND_OFFLOAD_SCAN_UTILS_H_
+
diff --git a/scanning/offload/offload_service_utils.cpp b/scanning/offload/offload_service_utils.cpp
new file mode 100644 (file)
index 0000000..fe4e4dd
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * 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/offload_service_utils.h"
+
+namespace android {
+namespace wificond {
+
+android::sp<IOffload> OffloadServiceUtils::GetOffloadService() {
+  return IOffload::getService();
+}
+
+android::sp<OffloadCallback> OffloadServiceUtils::GetOffloadCallback(
+    OnOffloadScanResultsReadyHandler handler) {
+  return new OffloadCallback(handler);
+}
+
+} // wificond
+} // android
+
diff --git a/scanning/offload/offload_service_utils.h b/scanning/offload/offload_service_utils.h
new file mode 100644 (file)
index 0000000..e5f29bf
--- /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_OFFLOAD_SERVICE_UTILS_H_
+#define WIFICOND_OFFLOAD_SERVICE_UTILS_H_
+
+#include <android/hardware/wifi/offload/1.0/IOffload.h>
+#include "wificond/scanning/offload/offload_callback.h"
+
+using android::hardware::wifi::offload::V1_0::IOffload;
+
+namespace android {
+namespace wificond {
+
+// Provides methods to get Offload HAL service and create callback
+class OffloadServiceUtils {
+ public:
+  OffloadServiceUtils() = default;
+  virtual ~OffloadServiceUtils() = default;
+  virtual android::sp<IOffload> GetOffloadService();
+  virtual android::sp<OffloadCallback> GetOffloadCallback(
+      OnOffloadScanResultsReadyHandler handler);
+};
+
+}  // namespace wificond
+}  // namespace android
+
+#endif // WIFICOND_OFFLOAD_SERVICE_UTILS_H
+
index 0fa5165..a3bc402 100644 (file)
 
 #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"
 
 using android::binder::Status;
 using android::net::wifi::IPnoScanEvent;
 using android::net::wifi::IScanEvent;
+using android::hardware::wifi::offload::V1_0::IOffload;
 using android::sp;
 using com::android::server::wifi::wificond::NativeScanResult;
 using com::android::server::wifi::wificond::PnoSettings;
@@ -72,6 +75,10 @@ ScannerImpl::ScannerImpl(uint32_t wiphy_index,
       std::bind(&ScannerImpl::OnSchedScanResultsReady,
                 this,
                 _1, _2));
+  offload_scan_manager_.reset(
+      new OffloadScanManager(new OffloadServiceUtils(),
+          std::bind(&ScannerImpl::OnOffloadScanResult,
+              this, _1)));
 }
 
 ScannerImpl::~ScannerImpl() {
@@ -378,5 +385,15 @@ void ScannerImpl::LogSsidList(vector<vector<uint8_t>>& ssid_list,
   LOG(WARNING) << prefix << ": " << ssid_list_string;
 }
 
+void ScannerImpl::OnOffloadScanResult(
+    std::vector<NativeScanResult> scanResult) {
+  // TODO: Process scan result
+  if (scan_event_handler_ != nullptr) {
+    scan_event_handler_->OnScanResultReady();
+  } else {
+    LOG(WARNING) << "No scan event handler Offload Scan result";
+  }
+}
+
 }  // namespace wificond
 }  // namespace android
index d7f8728..5950cae 100644 (file)
@@ -24,6 +24,7 @@
 
 #include "android/net/wifi/BnWifiScannerImpl.h"
 #include "wificond/net/netlink_utils.h"
+#include "wificond/scanning/offload/offload_scan_manager.h"
 
 namespace android {
 namespace wificond {
@@ -73,6 +74,8 @@ class ScannerImpl : public android::net::wifi::BnWifiScannerImpl {
 
  private:
   bool CheckIsValid();
+  void OnOffloadScanResult(
+      std::vector<::com::android::server::wifi::wificond::NativeScanResult>);
   void OnScanResultsReady(
       uint32_t interface_index,
       bool aborted,
@@ -99,6 +102,7 @@ class ScannerImpl : public android::net::wifi::BnWifiScannerImpl {
   ScanUtils* const scan_utils_;
   ::android::sp<::android::net::wifi::IPnoScanEvent> pno_scan_event_handler_;
   ::android::sp<::android::net::wifi::IScanEvent> scan_event_handler_;
+  std::unique_ptr<OffloadScanManager> offload_scan_manager_;
 
   DISALLOW_COPY_AND_ASSIGN(ScannerImpl);
 };