OSDN Git Service

Add scan() to wificond scanner
authorNingyuan Wang <nywang@google.com>
Fri, 9 Dec 2016 19:53:12 +0000 (11:53 -0800)
committerNingyuan Wang <nywang@google.com>
Fri, 20 Jan 2017 01:02:43 +0000 (17:02 -0800)
Bug: 33398008
Change-Id: Ib2009547ccc8fc368bd92e88a216b61cefe9a8ad
Test: compile

aidl/android/net/wifi/IWifiScannerImpl.aidl
aidl/com/android/server/wifi/wificond/SingleScanSettings.aidl [new file with mode: 0644]
scanning/scanner_impl.cpp
scanning/scanner_impl.h

index d799330..4306826 100644 (file)
@@ -17,6 +17,7 @@
 package android.net.wifi;
 
 import com.android.server.wifi.wificond.NativeScanResult;
+import com.android.server.wifi.wificond.SingleScanSettings;
 
 interface IWifiScannerImpl {
   // Returns an array of available frequencies for 2.4GHz channels.
@@ -27,5 +28,7 @@ interface IWifiScannerImpl {
   int[] getAvailableDFSChannels();
   // Get the latest scan results from kernel.
   NativeScanResult[] getScanResults();
+  // Request a single scan using a SingleScanSettings parcelable object.
+  boolean scan(in SingleScanSettings scanSettings);
   // TODO(nywang) add more interfaces.
 }
diff --git a/aidl/com/android/server/wifi/wificond/SingleScanSettings.aidl b/aidl/com/android/server/wifi/wificond/SingleScanSettings.aidl
new file mode 100644 (file)
index 0000000..abae5fe
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ * 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.
+ */
+
+package com.android.server.wifi.wificond;
+
+parcelable SingleScanSettings cpp_header "wificond/scanning/single_scan_settings.h";
index 8f389c7..aac2b05 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "wificond/scanning/scanner_impl.h"
 
+#include <string>
 #include <vector>
 
 #include <android-base/logging.h>
 #include "wificond/scanning/scan_utils.h"
 
 using android::binder::Status;
+using android::String16;
 using com::android::server::wifi::wificond::NativeScanResult;
+using com::android::server::wifi::wificond::SingleScanSettings;
+using std::string;
 using std::vector;
 
 namespace android {
@@ -91,5 +95,36 @@ Status ScannerImpl::getScanResults(vector<NativeScanResult>* out_scan_results) {
   return Status::ok();
 }
 
+Status ScannerImpl::scan(const SingleScanSettings& scan_settings,
+                         bool* out_success) {
+  if (!CheckIsValid()) {
+    return Status::ok();
+  }
+  if (scan_settings.is_full_scan_) {
+    if (!scan_utils_->StartFullScan(interface_index_)) {
+      *out_success = false;
+      return Status::ok();
+    }
+  }
+
+  // Initialize it with an empty ssid for a wild card scan.
+  vector<vector<uint8_t>> ssids = {{0}};
+  for (auto& network : scan_settings.hidden_networks_) {
+    ssids.push_back(network.ssid_);
+  }
+  vector<uint32_t> freqs;
+  for (auto& channel : scan_settings.channel_settings_) {
+    freqs.push_back(channel.frequency_);
+  }
+
+  if (!scan_utils_->Scan(interface_index_, ssids, freqs)) {
+    *out_success = false;
+    LOG(ERROR) << "Failed to start a scan";
+    return Status::ok();
+  }
+  *out_success = true;
+  return Status::ok();
+}
+
 }  // namespace wificond
 }  // namespace android
index b0b31aa..945195f 100644 (file)
@@ -51,6 +51,10 @@ class ScannerImpl : public android::net::wifi::BnWifiScannerImpl {
   ::android::binder::Status getScanResults(
       std::vector<com::android::server::wifi::wificond::NativeScanResult>*
           out_scan_results) override;
+  ::android::binder::Status scan(
+      const ::com::android::server::wifi::wificond::SingleScanSettings&
+          scan_settings,
+      bool* out_success) override;
   void Invalidate() { valid_ = false; }
 
  private: