diff options
author | Samuel Tan <samueltan@google.com> | 2016-05-07 00:46:22 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2016-05-07 00:46:22 +0000 |
commit | 9171fdae5b2cb8250d4296a08288e0c8ec21be8d (patch) | |
tree | 6e7da5ebfc4dc75c00c61b2f568c4b8d0bebc427 | |
parent | f1f25ea0604e5e5f75c1e2f1df162d35615e8078 (diff) | |
parent | f12e310beb74f32fe954681d93074fee7f066172 (diff) | |
download | shill-9171fdae5b2cb8250d4296a08288e0c8ec21be8d.tar.gz |
shill: implement IManager Binder interface methods am: fe01898d9f
am: f12e310beb
* commit 'f12e310beb74f32fe954681d93074fee7f066172':
shill: implement IManager Binder interface methods
Change-Id: Ic5c8aff2405f986496970c29b7d099716c2a6201
-rw-r--r-- | binder/android/system/connectivity/shill/IManager.aidl | 16 | ||||
-rw-r--r-- | binder/binder_control.cc | 2 | ||||
-rw-r--r-- | binder/manager_binder_adaptor.cc | 181 | ||||
-rw-r--r-- | binder/manager_binder_adaptor.h | 34 | ||||
-rw-r--r-- | manager.cc | 28 | ||||
-rw-r--r-- | manager.h | 5 |
6 files changed, 213 insertions, 53 deletions
diff --git a/binder/android/system/connectivity/shill/IManager.aidl b/binder/android/system/connectivity/shill/IManager.aidl index adfecfc5..044d253e 100644 --- a/binder/android/system/connectivity/shill/IManager.aidl +++ b/binder/android/system/connectivity/shill/IManager.aidl @@ -25,7 +25,9 @@ interface IManager { /** * Technology types that can be passed to RequestScan(). */ + // Any technology, i.e. scan request is made for each technology. const int TECHNOLOGY_ANY = 0; + // Wi-Fi const int TECHNOLOGY_WIFI = 1; /** @@ -34,9 +36,11 @@ interface IManager { * of this call. Shill will revert to station mode if the remote * service that called this method vanishes. * + * @param ap_mode_setter Binder reference to the remote service that called + * this method. * @return Interface name on success, empty string on error */ - @utf8InCpp String SetupApModeInterface(); + @utf8InCpp String SetupApModeInterface(IBinder ap_mode_setter); /** * (Brillo only) Ask WiFi driver to setup a station mode interface. @@ -52,22 +56,28 @@ interface IManager { * claimer |claimer_name|. The specified device will be * added to the blacklist. Any current connection on that device * will be terminated, and shill will stop managing that device. + * Pass an empty string as the claimer name to indicate default claimer. * + * @param claimer Binder reference to the remote service that called this + * method. * @param claimer_name Name of the claimer * @param interface_name Name of the interface to be claimed */ - void ClaimInterface( + void ClaimInterface(IBinder claimer, @utf8InCpp String claimer_name, @utf8InCpp String interface_name); /** * Take ownership of a device |interface_name| from * claimer |claimer_name| back to shill. The specified device * will be removed from the blacklist and managed by shill. + * Pass an empty string as the claimer name to indicate default claimer. * + * @param claimer Binder reference to the remote service that called this + * method. * @param claimer_name Name of the claimer * @param interface_name Name of the interface to be released */ - void ReleaseInterface(@utf8InCpp String claimer_name, + void ReleaseInterface(IBinder claimer, @utf8InCpp String claimer_name, @utf8InCpp String interface_name); /** diff --git a/binder/binder_control.cc b/binder/binder_control.cc index d1cc0b1b..072c8671 100644 --- a/binder/binder_control.cc +++ b/binder/binder_control.cc @@ -190,7 +190,7 @@ BinderAdaptor* BinderControl::GetBinderAdaptorForRpcIdentifier( const std::string& rpc_id) { const auto& it = rpc_id_to_adaptor_map_.find(rpc_id); if (it == rpc_id_to_adaptor_map_.end()) { - return NULL; + return nullptr; } return it->second; diff --git a/binder/manager_binder_adaptor.cc b/binder/manager_binder_adaptor.cc index 3da66e23..474e1c28 100644 --- a/binder/manager_binder_adaptor.cc +++ b/binder/manager_binder_adaptor.cc @@ -16,20 +16,34 @@ #include "shill/binder/manager_binder_adaptor.h" +#include <base/bind.h> #include <binder/Status.h> #include <binderwrapper/binder_wrapper.h> #include <utils/String8.h> +// TODO(samueltan): remove these includes once b/27270173 is resolved, +// and Manager is no longer reliant on D-Bus service constants. +#if defined(__ANDROID__) +#include <dbus/service_constants.h> +#else +#include <chromeos/dbus/service_constants.h> +#endif // __ANDROID__ +#include "shill/binder/binder_control.h" +#include "shill/binder/device_binder_adaptor.h" +#include "shill/binder/service_binder_adaptor.h" +#include "shill/error.h" #include "shill/logging.h" #include "shill/manager.h" using android::binder::Status; using android::BinderWrapper; using android::IBinder; +using android::interface_cast; using android::sp; using android::String8; using android::system::connectivity::shill::IPropertyChangedCallback; using android::system::connectivity::shill::IService; +using base::Bind; using std::string; using std::vector; @@ -45,9 +59,19 @@ static string ObjectID(ManagerBinderAdaptor* m) { ManagerBinderAdaptor::ManagerBinderAdaptor(BinderControl* control, Manager* manager, const std::string& id) - : BinderAdaptor(control, id), manager_(manager) {} + : BinderAdaptor(control, id), + manager_(manager), + ap_mode_setter_(nullptr), + device_claimer_(nullptr) {} -ManagerBinderAdaptor::~ManagerBinderAdaptor() { manager_ = nullptr; } +ManagerBinderAdaptor::~ManagerBinderAdaptor() { + if (ap_mode_setter_ != nullptr) { + BinderWrapper::Get()->UnregisterForDeathNotifications(ap_mode_setter_); + } + if (device_claimer_ != nullptr) { + BinderWrapper::Get()->UnregisterForDeathNotifications(device_claimer_); + } +} void ManagerBinderAdaptor::RegisterAsync( const base::Callback<void(bool)>& /*completion_callback*/) { @@ -96,55 +120,154 @@ void ManagerBinderAdaptor::EmitRpcIdentifierArrayChanged( SendPropertyChangedSignal(name); } -Status ManagerBinderAdaptor::SetupApModeInterface(std::string* _aidl_return) { - // STUB IMPLEMENTATION. +Status ManagerBinderAdaptor::SetupApModeInterface( + const sp<IBinder>& ap_mode_setter, std::string* _aidl_return) { + SLOG(this, 2) << __func__; + Error e; +#if !defined(DISABLE_WIFI) && defined(__BRILLO__) + manager_->SetupApModeInterface(_aidl_return, &e); + if (e.IsFailure()) { + return e.ToBinderStatus(); + } + // Register for death notifications from the caller. This will restore + // interface mode to station mode if the caller vanishes. + ap_mode_setter_ = ap_mode_setter; + BinderWrapper::Get()->RegisterForDeathNotifications( + ap_mode_setter, Bind(&ManagerBinderAdaptor::OnApModeSetterVanished, + base::Unretained(this))); return Status::ok(); +#else + return Status::fromExceptionCode(Status::EX_UNSUPPORTED_OPERATION); +#endif // !DISABLE_WIFI && __BRILLO__ } Status ManagerBinderAdaptor::SetupStationModeInterface( std::string* _aidl_return) { - // STUB IMPLEMENTATION. - // TODO(samueltan): replace this with proper implementation. + SLOG(this, 2) << __func__; +#if !defined(DISABLE_WIFI) && defined(__BRILLO__) + Error e; + manager_->SetupStationModeInterface(_aidl_return, &e); + if (e.IsFailure()) { + return e.ToBinderStatus(); + } + if (ap_mode_setter_ != nullptr) { + // Unregister for death notifications from the AP mode setter, if case + // SetupApModeInterface() was previously called. + BinderWrapper::Get()->UnregisterForDeathNotifications(ap_mode_setter_); + ap_mode_setter_ = nullptr; + } return Status::ok(); +#else + return Status::fromExceptionCode(Status::EX_UNSUPPORTED_OPERATION); +#endif // !DISABLE_WIFI && __BRILLO__ } -Status ManagerBinderAdaptor::ClaimInterface(const std::string& claimer_name, +Status ManagerBinderAdaptor::ClaimInterface(const sp<IBinder>& claimer, + const std::string& claimer_name, const std::string& interface_name) { - // STUB IMPLEMENTATION. - // TODO(samueltan): replace this with proper implementation. + SLOG(this, 2) << __func__; + Error e; + // Empty claimer name is used to indicate default claimer. + // TODO(samueltan): update this API or make a new API to use a flag to + // indicate default claimer instead (b/27924738). + manager_->ClaimDevice(claimer_name, interface_name, &e); + if (e.IsFailure()) { + return e.ToBinderStatus(); + } + if (!claimer_name.empty()) { + device_claimer_ = claimer; + BinderWrapper::Get()->RegisterForDeathNotifications( + claimer, Bind(&ManagerBinderAdaptor::OnDeviceClaimerVanished, + base::Unretained(this))); + } return Status::ok(); } Status ManagerBinderAdaptor::ReleaseInterface( - const std::string& claimer_name, const std::string& interface_name) { - // STUB IMPLEMENTATION. - // TODO(samueltan): replace this with proper implementation. + const sp<IBinder>& claimer, const std::string& claimer_name, + const std::string& interface_name) { + SLOG(this, 2) << __func__; + Error e; + bool claimer_removed; + // Empty claimer name is used to indicate default claimer. + // TODO(samueltan): update this API or make a new API to use a flag to + // indicate default claimer instead (b/27924738). + manager_->ReleaseDevice(claimer_name, interface_name, &claimer_removed, &e); + if (e.IsFailure()) { + return e.ToBinderStatus(); + } + if (claimer_removed) { + BinderWrapper::Get()->UnregisterForDeathNotifications(claimer); + } return Status::ok(); } Status ManagerBinderAdaptor::ConfigureService( const android::os::PersistableBundle& properties, sp<IService>* _aidl_return) { - // STUB IMPLEMENTATION. - // TODO(samueltan): replace this with proper implementation. + SLOG(this, 2) << __func__; + ServiceRefPtr service; + KeyValueStore args_store; + KeyValueStore::ConvertFromPersistableBundle(properties, &args_store); + + Error e; + service = manager_->ConfigureService(args_store, &e); + if (e.IsFailure()) { + return e.ToBinderStatus(); + } + *_aidl_return = interface_cast<IService>(static_cast<ServiceBinderAdaptor*>( + control()->GetBinderAdaptorForRpcIdentifier( + service->GetRpcIdentifier()))); return Status::ok(); } Status ManagerBinderAdaptor::RequestScan(int32_t type) { - // STUB IMPLEMENTATION. - // TODO(samueltan): replace this with proper implementation. - return Status::ok(); + string technology; + switch (type) { + // TODO(samueltan): remove the use of these D-Bus service constants once + // b/27270173 is resolved, and Manager is no longer reliant on them. + case IManager::TECHNOLOGY_ANY: + technology = ""; + break; + case IManager::TECHNOLOGY_WIFI: + technology = kTypeWifi; + break; + default: + return Status::fromExceptionCode( + Status::EX_ILLEGAL_ARGUMENT, + String8::format("%s: invalid technology type %d", __func__, type)); + } + + SLOG(this, 2) << __func__ << ": " << technology; + Error e; + manager_->RequestScan(Device::kFullScan, technology, &e); + return e.ToBinderStatus(); } Status ManagerBinderAdaptor::GetDevices(vector<sp<IBinder>>* _aidl_return) { - // STUB IMPLEMENTATION. - // TODO(samueltan): replace this with proper implementation. + SLOG(this, 2) << __func__; + Error e; + RpcIdentifiers device_rpc_ids = manager_->EnumerateDevices(&e); + if (e.IsFailure()) { + return e.ToBinderStatus(); + } + for (const auto& device_rpc_id : device_rpc_ids) { + _aidl_return->emplace_back(static_cast<DeviceBinderAdaptor*>( + control()->GetBinderAdaptorForRpcIdentifier(device_rpc_id))); + } return Status::ok(); } Status ManagerBinderAdaptor::GetDefaultService(sp<IBinder>* _aidl_return) { - // STUB IMPLEMENTATION. - // TODO(samueltan): replace this with proper implementation. + SLOG(this, 2) << __func__; + Error e; + RpcIdentifier default_service_rpc_id = + manager_->GetDefaultServiceRpcIdentifier(&e); + if (e.IsFailure()) { + return e.ToBinderStatus(); + } + *_aidl_return = static_cast<ServiceBinderAdaptor*>( + control()->GetBinderAdaptorForRpcIdentifier(default_service_rpc_id)); return Status::ok(); } @@ -154,4 +277,20 @@ Status ManagerBinderAdaptor::RegisterPropertyChangedSignalHandler( return Status::ok(); } +void ManagerBinderAdaptor::OnApModeSetterVanished() { + SLOG(this, 3) << __func__; +#if !defined(DISABLE_WIFI) && defined(__BRILLO__) + manager_->OnApModeSetterVanished(); +#endif // !DISABLE_WIFI && __BRILLO__ + BinderWrapper::Get()->UnregisterForDeathNotifications(ap_mode_setter_); + ap_mode_setter_ = nullptr; +} + +void ManagerBinderAdaptor::OnDeviceClaimerVanished() { + SLOG(this, 3) << __func__; + manager_->OnDeviceClaimerVanished(); + BinderWrapper::Get()->UnregisterForDeathNotifications(device_claimer_); + device_claimer_ = nullptr; +} + } // namespace shill diff --git a/binder/manager_binder_adaptor.h b/binder/manager_binder_adaptor.h index 0348dfe5..4109a866 100644 --- a/binder/manager_binder_adaptor.h +++ b/binder/manager_binder_adaptor.h @@ -75,28 +75,38 @@ class ManagerBinderAdaptor const std::string& name, const std::vector<std::string>& value) override; // Implementation of BnManager. - android::binder::Status SetupApModeInterface(std::string* _aidl_return); - android::binder::Status SetupStationModeInterface(std::string* _aidl_return); - android::binder::Status ClaimInterface(const std::string& claimer_name, - const std::string& interface_name); - android::binder::Status ReleaseInterface(const std::string& claimer_name, - const std::string& interface_name); + android::binder::Status SetupApModeInterface( + const android::sp<IBinder>& ap_mode_setter, + std::string* _aidl_return) override; + android::binder::Status SetupStationModeInterface( + std::string* _aidl_return) override; + android::binder::Status ClaimInterface( + const android::sp<IBinder>& claimer, const std::string& claimer_name, + const std::string& interface_name) override; + android::binder::Status ReleaseInterface( + const android::sp<IBinder>& claimer, const std::string& claimer_name, + const std::string& interface_name) override; android::binder::Status ConfigureService( const android::os::PersistableBundle& properties, - android::sp<android::system::connectivity::shill::IService>* - _aidl_return); - android::binder::Status RequestScan(int32_t type); + android::sp<android::system::connectivity::shill::IService>* _aidl_return) + override; + android::binder::Status RequestScan(int32_t type) override; android::binder::Status GetDevices( - std::vector<android::sp<android::IBinder>>* _aidl_return); + std::vector<android::sp<android::IBinder>>* _aidl_return) override; android::binder::Status GetDefaultService( - android::sp<android::IBinder>* _aidl_return); + android::sp<android::IBinder>* _aidl_return) override; android::binder::Status RegisterPropertyChangedSignalHandler( const android::sp< android::system::connectivity::shill::IPropertyChangedCallback>& - callback); + callback) override; private: + void OnApModeSetterVanished(); + void OnDeviceClaimerVanished(); + Manager* manager_; + android::sp<IBinder> ap_mode_setter_; + android::sp<IBinder> device_claimer_; DISALLOW_COPY_AND_ASSIGN(ManagerBinderAdaptor); }; @@ -1326,6 +1326,20 @@ void Manager::OnDeviceClaimerVanished() { device_claimer_.reset(); } +RpcIdentifiers Manager::EnumerateDevices(Error* /*error*/) { + RpcIdentifiers device_rpc_ids; + for (const auto& device : devices_) { + device_rpc_ids.push_back(device->GetRpcIdentifier()); + } + // Enumerate devices that are internal to the services, such as PPPoE devices. + for (const auto& service : services_) { + if (!service->GetInnerDeviceRpcIdentifier().empty()) { + device_rpc_ids.push_back(service->GetInnerDeviceRpcIdentifier()); + } + } + return device_rpc_ids; +} + #if !defined(DISABLE_WIFI) bool Manager::SetDisableWiFiVHT(const bool& disable_wifi_vht, Error* error) { if (disable_wifi_vht == wifi_provider_->disable_vht()) { @@ -2219,20 +2233,6 @@ vector<string> Manager::UninitializedTechnologies(Error* /*error*/) { return device_info_.GetUninitializedTechnologies(); } -RpcIdentifiers Manager::EnumerateDevices(Error* /*error*/) { - RpcIdentifiers device_rpc_ids; - for (const auto& device : devices_) { - device_rpc_ids.push_back(device->GetRpcIdentifier()); - } - // Enumerate devices that are internal to the services, such as PPPoE devices. - for (const auto& service : services_) { - if (!service->GetInnerDeviceRpcIdentifier().empty()) { - device_rpc_ids.push_back(service->GetInnerDeviceRpcIdentifier()); - } - } - return device_rpc_ids; -} - RpcIdentifiers Manager::EnumerateProfiles(Error* /*error*/) { RpcIdentifiers profile_rpc_ids; for (const auto& profile : profiles_) { @@ -303,6 +303,7 @@ class Manager : public base::SupportsWeakPtr<Manager> { // Return a reference to the Service associated with the default connection. // If there is no such connection, this function returns a reference to NULL. virtual ServiceRefPtr GetDefaultService() const; + RpcIdentifier GetDefaultServiceRpcIdentifier(Error* error); // Set enabled state of all |technology_name| devices to |enabled_state|. // Persist the state to storage is |persist| is true. @@ -556,6 +557,8 @@ class Manager : public base::SupportsWeakPtr<Manager> { // Called when remote device claimer vanishes. virtual void OnDeviceClaimerVanished(); + RpcIdentifiers EnumerateDevices(Error* error); + private: friend class CellularTest; friend class DeviceInfoTest; @@ -652,12 +655,10 @@ class Manager : public base::SupportsWeakPtr<Manager> { std::string DefaultTechnology(Error* error); std::vector<std::string> EnabledTechnologies(Error* error); std::vector<std::string> UninitializedTechnologies(Error* error); - RpcIdentifiers EnumerateDevices(Error* error); RpcIdentifiers EnumerateProfiles(Error* error); RpcIdentifiers EnumerateWatchedServices(Error* error); std::string GetActiveProfileRpcIdentifier(Error* error); std::string GetCheckPortalList(Error* error); - RpcIdentifier GetDefaultServiceRpcIdentifier(Error* error); std::string GetIgnoredDNSSearchPaths(Error* error); ServiceRefPtr GetServiceInner(const KeyValueStore& args, Error* error); bool SetCheckPortalList(const std::string& portal_list, Error* error); |