OSDN Git Service

Plumb through scheduled scan results
authorNingyuan Wang <nywang@google.com>
Fri, 20 Jan 2017 19:18:43 +0000 (11:18 -0800)
committerNingyuan Wang <nywang@google.com>
Mon, 23 Jan 2017 21:52:25 +0000 (13:52 -0800)
Bug: 33398008
Test: compile, unit tests, manual test

Change-Id: I1e9eb84294cf99cda377c5c17edda97baa465895

Android.mk
aidl/android/net/wifi/IPnoScanEvent.aidl [new file with mode: 0644]
aidl/android/net/wifi/IWifiScannerImpl.aidl
scanning/scanner_impl.cpp
scanning/scanner_impl.h

index 1d31905..af33400 100644 (file)
@@ -108,6 +108,7 @@ LOCAL_SRC_FILES := \
     aidl/android/net/wifi/IANQPDoneCallback.aidl \
     aidl/android/net/wifi/IClientInterface.aidl \
     aidl/android/net/wifi/IInterfaceEventCallback.aidl \
+    aidl/android/net/wifi/IPnoScanEvent.aidl \
     aidl/android/net/wifi/IRttClient.aidl \
     aidl/android/net/wifi/IRttController.aidl \
     aidl/android/net/wifi/IScanEvent.aidl \
diff --git a/aidl/android/net/wifi/IPnoScanEvent.aidl b/aidl/android/net/wifi/IPnoScanEvent.aidl
new file mode 100644 (file)
index 0000000..6b6919f
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * 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 android.net.wifi;
+
+// A callback for receiving pno scanning events.
+interface IPnoScanEvent {
+  oneway void OnPnoNetworkFound();
+}
index 29f2674..5f47659 100644 (file)
@@ -16,6 +16,7 @@
 
 package android.net.wifi;
 
+import android.net.wifi.IPnoScanEvent;
 import android.net.wifi.IScanEvent;
 import com.android.server.wifi.wificond.NativeScanResult;
 import com.android.server.wifi.wificond.PnoSettings;
@@ -37,14 +38,22 @@ interface IWifiScannerImpl {
   // Request a single scan using a SingleScanSettings parcelable object.
   boolean scan(in SingleScanSettings scanSettings);
 
-  // Subscribe the scanning events.
+  // Subscribe single scanning events.
   // Scanner assumes there is only one subscriber.
   // This call will replace any existing |handler|.
   void subscribeScanEvents(IScanEvent handler);
 
-  // Unsubscribe the scanning events .
+  // Unsubscribe single scanning events .
   void unsubscribeScanEvents();
 
+  // Subscribe Pno scanning events.
+  // Scanner assumes there is only one subscriber.
+  // This call will replace any existing |handler|.
+  void subscribePnoScanEvents(IPnoScanEvent handler);
+
+  // Unsubscribe Pno scanning events .
+  void unsubscribePnoScanEvents();
+
   // Request a scheduled scan.
   boolean startPnoScan(in PnoSettings pnoSettings);
 
index cd7f003..9ae53de 100644 (file)
@@ -24,6 +24,7 @@
 #include "wificond/scanning/scan_utils.h"
 
 using android::binder::Status;
+using android::net::wifi::IPnoScanEvent;
 using android::net::wifi::IScanEvent;
 using android::String16;
 using android::sp;
@@ -182,6 +183,7 @@ Status ScannerImpl::subscribeScanEvents(const sp<IScanEvent>& handler) {
                << " This subscription request will unsubscribe it";
   }
   scan_event_handler_ = handler;
+  // Subscribe one-shot scan result notification.
   scan_utils_->SubscribeScanResultNotification(
       interface_index_,
       std::bind(&ScannerImpl::OnScanResultsReady,
@@ -192,11 +194,36 @@ Status ScannerImpl::subscribeScanEvents(const sp<IScanEvent>& handler) {
 }
 
 Status ScannerImpl::unsubscribeScanEvents() {
+
   scan_utils_->UnsubscribeScanResultNotification(interface_index_);
   scan_event_handler_ = nullptr;
   return Status::ok();
 }
 
+
+Status ScannerImpl::subscribePnoScanEvents(const sp<IPnoScanEvent>& handler) {
+  if (pno_scan_event_handler_ != nullptr) {
+    LOG(ERROR) << "Found existing pno scan events subscriber."
+               << " This subscription request will unsubscribe it";
+  }
+  pno_scan_event_handler_ = handler;
+
+  // Subscribe scheduled scan result notification.
+  scan_utils_->SubscribeSchedScanResultNotification(
+      interface_index_,
+      std::bind(&ScannerImpl::OnSchedScanResultsReady,
+                this,
+                _1));
+
+  return Status::ok();
+}
+
+Status ScannerImpl::unsubscribePnoScanEvents() {
+  scan_utils_->UnsubscribeSchedScanResultNotification(interface_index_);
+  pno_scan_event_handler_ = nullptr;
+  return Status::ok();
+}
+
 void ScannerImpl::OnScanResultsReady(
     uint32_t interface_index,
     bool aborted,
@@ -212,5 +239,11 @@ void ScannerImpl::OnScanResultsReady(
   }
 }
 
+void ScannerImpl::OnSchedScanResultsReady(uint32_t interface_index) {
+  if (pno_scan_event_handler_ != nullptr) {
+    pno_scan_event_handler_->OnPnoNetworkFound();
+  }
+}
+
 }  // namespace wificond
 }  // namespace android
index 946ed66..8d7770b 100644 (file)
@@ -55,13 +55,17 @@ class ScannerImpl : public android::net::wifi::BnWifiScannerImpl {
       const ::com::android::server::wifi::wificond::SingleScanSettings&
           scan_settings,
       bool* out_success) override;
-  ::android::binder::Status subscribeScanEvents(
-      const ::android::sp<::android::net::wifi::IScanEvent>& handler) override;
-  ::android::binder::Status unsubscribeScanEvents() override;
   ::android::binder::Status startPnoScan(
       const ::com::android::server::wifi::wificond::PnoSettings& pno_settings,
       bool* out_success) override;
   ::android::binder::Status stopPnoScan(bool* out_success) override;
+
+  ::android::binder::Status subscribeScanEvents(
+      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;
+  ::android::binder::Status unsubscribePnoScanEvents() override;
   void Invalidate() { valid_ = false; }
 
  private:
@@ -71,6 +75,7 @@ class ScannerImpl : public android::net::wifi::BnWifiScannerImpl {
       bool aborted,
       std::vector<std::vector<uint8_t>>& ssids,
       std::vector<uint32_t>& frequencies);
+  void OnSchedScanResultsReady(uint32_t interface_index);
 
   bool valid_;
   uint32_t interface_index_;
@@ -81,6 +86,7 @@ class ScannerImpl : public android::net::wifi::BnWifiScannerImpl {
   const WiphyFeatures wiphy_features_;
 
   ScanUtils* scan_utils_;
+  ::android::sp<::android::net::wifi::IPnoScanEvent> pno_scan_event_handler_;
   ::android::sp<::android::net::wifi::IScanEvent> scan_event_handler_;
 
   DISALLOW_COPY_AND_ASSIGN(ScannerImpl);