From dea7ebe3078dc347ef4d49d2293b391a479242cf Mon Sep 17 00:00:00 2001 From: Ningyuan Wang Date: Fri, 9 Sep 2016 10:31:17 -0700 Subject: [PATCH] Add binder interface for registering/unregistering interface changes BUG=31349441 TEST=compile, unit tests Change-Id: I0fa00ecdeec46246875f7de2479dab1470d102e5 --- Android.mk | 1 + aidl/android/net/wifi/IInterfaceEventCallback.aidl | 34 ++++++++++++++++++++++ aidl/android/net/wifi/IWificond.aidl | 17 +++++++++++ server.cpp | 29 ++++++++++++++++++ server.h | 10 +++++++ 5 files changed, 91 insertions(+) create mode 100644 aidl/android/net/wifi/IInterfaceEventCallback.aidl diff --git a/Android.mk b/Android.mk index a508261..2472b7e 100644 --- a/Android.mk +++ b/Android.mk @@ -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 index 0000000..0728086 --- /dev/null +++ b/aidl/android/net/wifi/IInterfaceEventCallback.aidl @@ -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(); +} diff --git a/aidl/android/net/wifi/IWificond.aidl b/aidl/android/net/wifi/IWificond.aidl index d6e3896..8a35104 100644 --- a/aidl/android/net/wifi/IWificond.aidl +++ b/aidl/android/net/wifi/IWificond.aidl @@ -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); + } diff --git a/server.cpp b/server.cpp index 3ccf566..857e2ed 100644 --- a/server.cpp +++ b/server.cpp @@ -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 hal_tool, scan_utils_(scan_utils) { } +Status Server::RegisterCallback(const sp& 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& 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* created_interface) { string interface_name; uint32_t interface_index; diff --git a/server.h b/server.h index b9aa146..9f0b160 100644 --- 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& + callback) override; + android::binder::Status UnregisterCallback( + const android::sp& + callback) override; + android::binder::Status createApInterface( android::sp* created_interface) override; @@ -91,6 +99,8 @@ class Server : public android::net::wifi::BnWificond { uint32_t wiphy_index_; std::vector> ap_interfaces_; std::vector> client_interfaces_; + std::vector> + interface_event_callbacks_; DISALLOW_COPY_AND_ASSIGN(Server); }; -- 2.11.0