OSDN Git Service

Add binder interface for registering/unregistering interface changes am: dea7ebe307...
authorNingyuan Wang <nywang@google.com>
Fri, 9 Sep 2016 23:01:17 +0000 (23:01 +0000)
committerandroid-build-merger <android-build-merger@google.com>
Fri, 9 Sep 2016 23:01:17 +0000 (23:01 +0000)
am: 6c751561d2

Change-Id: I5c99aa95a77bd6bfe5a60504c16770d9ecd29e2b

Android.mk
aidl/android/net/wifi/IInterfaceEventCallback.aidl [new file with mode: 0644]
aidl/android/net/wifi/IWificond.aidl
server.cpp
server.h

index a508261..2472b7e 100644 (file)
@@ -95,6 +95,7 @@ LOCAL_SRC_FILES := \
     ipc_constants.cpp \
     aidl/android/net/wifi/IApInterface.aidl \
     aidl/android/net/wifi/IClientInterface.aidl \
+    aidl/android/net/wifi/IInterfaceEventCallback.aidl \
     aidl/android/net/wifi/IWificond.aidl
 LOCAL_SHARED_LIBRARIES := \
     libbinder
diff --git a/aidl/android/net/wifi/IInterfaceEventCallback.aidl b/aidl/android/net/wifi/IInterfaceEventCallback.aidl
new file mode 100644 (file)
index 0000000..0728086
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * 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;
+
+import android.net.wifi.IApInterface;
+import android.net.wifi.IClientInterface;
+
+// A callback for receiving events related to this chip.
+interface IInterfaceEventCallback {
+
+  // Signals that the provided interface is ready for future commands.
+  oneway void OnClientInterfaceReady(IClientInterface network_interface);
+  oneway void OnApInterfaceReady(IApInterface network_interface);
+
+  // Signals that an interface was torn down.
+  // No future callbacks will be delivered via this callback, and the callback
+  // is automatically unregistered.
+  oneway void OnClientTorndownEvent();
+  oneway void OnApTorndownEvent();
+}
index d6e3896..8a35104 100644 (file)
@@ -18,6 +18,7 @@ package android.net.wifi;
 
 import android.net.wifi.IApInterface;
 import android.net.wifi.IClientInterface;
+import android.net.wifi.IInterfaceEventCallback;
 
 // Service interface that exposes primitives for controlling the WiFi
 // subsystems of a device.
@@ -33,4 +34,20 @@ interface IWificond {
     // future interfaces immediately after this method returns.
     void tearDownInterfaces();
 
+    // Register a callback to receive interface status updates.
+    //
+    // Multiple callbacks can be registered simultaneously.
+    // Duplicate registrations of the same callback will be ignored.
+    //
+    // @param callback object to add to the set of registered callbacks.
+    oneway void RegisterCallback(IInterfaceEventCallback callback);
+
+    // Remove a callback from the set of registered callbacks.
+    //
+    // This must be the same instance as previously registered.
+    // Requests to remove unknown callbacks will be ignored.
+    //
+    // @param callback object to remove from the set of registered callbacks.
+    oneway void UnregisterCallback(IInterfaceEventCallback callback);
+
 }
index 3ccf566..857e2ed 100644 (file)
@@ -29,6 +29,7 @@ using std::vector;
 using std::unique_ptr;
 using android::net::wifi::IApInterface;
 using android::net::wifi::IClientInterface;
+using android::net::wifi::IInterfaceEventCallback;
 using android::wifi_hal::DriverTool;
 using android::wifi_system::HalTool;
 using android::wifi_system::HostapdManager;
@@ -54,6 +55,34 @@ Server::Server(unique_ptr<HalTool> hal_tool,
       scan_utils_(scan_utils) {
 }
 
+Status Server::RegisterCallback(const sp<IInterfaceEventCallback>& callback) {
+  for (auto& it : interface_event_callbacks_) {
+    if (IInterface::asBinder(callback) == IInterface::asBinder(it)) {
+      LOG(WARNING) << "Ignore duplicate interface event callback registration";
+      return Status::ok();
+    }
+  }
+  LOG(INFO) << "New interface event callback registered";
+  interface_event_callbacks_.push_back(callback);
+  return Status::ok();
+}
+
+Status Server::UnregisterCallback(const sp<IInterfaceEventCallback>& callback) {
+  for (auto it = interface_event_callbacks_.begin();
+       it != interface_event_callbacks_.end();
+       it++) {
+    if (IInterface::asBinder(callback) == IInterface::asBinder(*it)) {
+      interface_event_callbacks_.erase(it);
+      LOG(INFO) << "Unregister interface event callback";
+      return Status::ok();
+    }
+  }
+  LOG(WARNING) << "Failed to find registered interface event callback"
+               << " to unregister";
+  return Status::ok();
+}
+
+
 Status Server::createApInterface(sp<IApInterface>* created_interface) {
   string interface_name;
   uint32_t interface_index;
index b9aa146..9f0b160 100644 (file)
--- a/server.h
+++ b/server.h
@@ -29,6 +29,7 @@
 #include "android/net/wifi/BnWificond.h"
 #include "android/net/wifi/IApInterface.h"
 #include "android/net/wifi/IClientInterface.h"
+#include "android/net/wifi/IInterfaceEventCallback.h"
 
 #include "wificond/ap_interface_impl.h"
 #include "wificond/client_interface_impl.h"
@@ -51,6 +52,13 @@ class Server : public android::net::wifi::BnWificond {
          ScanUtils* scan_utils);
   ~Server() override = default;
 
+  android::binder::Status RegisterCallback(
+      const android::sp<android::net::wifi::IInterfaceEventCallback>&
+          callback) override;
+  android::binder::Status UnregisterCallback(
+      const android::sp<android::net::wifi::IInterfaceEventCallback>&
+          callback) override;
+
   android::binder::Status createApInterface(
       android::sp<android::net::wifi::IApInterface>*
           created_interface) override;
@@ -91,6 +99,8 @@ class Server : public android::net::wifi::BnWificond {
   uint32_t wiphy_index_;
   std::vector<std::unique_ptr<ApInterfaceImpl>> ap_interfaces_;
   std::vector<std::unique_ptr<ClientInterfaceImpl>> client_interfaces_;
+  std::vector<android::sp<android::net::wifi::IInterfaceEventCallback>>
+      interface_event_callbacks_;
 
   DISALLOW_COPY_AND_ASSIGN(Server);
 };