summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Tan <samueltan@google.com>2016-05-07 00:46:25 +0000
committerandroid-build-merger <android-build-merger@google.com>2016-05-07 00:46:25 +0000
commit78504d70a6c7e8116ca52c2936b679d77c2d1da9 (patch)
tree3426eb4ceaa7028aaaee3246d4e3bbb8ef4695c5
parent89cd556a3c7878e02eb3d551b79b18632e723795 (diff)
parent0642a4a0969dd1fbf0c47a3ea4d269c0de458ea6 (diff)
downloadshill-78504d70a6c7e8116ca52c2936b679d77c2d1da9.tar.gz
shill: implement IService Binder interface methods am: 7fa0defef4
am: 0642a4a096 * commit '0642a4a0969dd1fbf0c47a3ea4d269c0de458ea6': shill: implement IService Binder interface methods Change-Id: Ibf9b3d7575869ddba8fb7b34d34c7be20cb364c7
-rw-r--r--binder/service_binder_adaptor.cc179
-rw-r--r--binder/service_binder_adaptor.h21
-rw-r--r--service.cc33
-rw-r--r--service.h17
-rw-r--r--vpn/vpn_service.cc26
-rw-r--r--vpn/vpn_service.h8
6 files changed, 216 insertions, 68 deletions
diff --git a/binder/service_binder_adaptor.cc b/binder/service_binder_adaptor.cc
index dfe3a834..2f0716e4 100644
--- a/binder/service_binder_adaptor.cc
+++ b/binder/service_binder_adaptor.cc
@@ -17,16 +17,32 @@
#include "shill/binder/service_binder_adaptor.h"
#include <binder/Status.h>
+#include <utils/String8.h>
+// TODO(samueltan): remove these includes once b/27270173 is resolved,
+// and Service 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/logging.h"
#include "shill/service.h"
+#include "shill/vpn/vpn_service.h"
using android::binder::Status;
using android::IBinder;
using android::sp;
+using android::String8;
using android::system::connectivity::shill::IPropertyChangedCallback;
using std::string;
+namespace {
+const char kBinderRpcReasonString[] = "Binder RPC";
+// Generic error code to indicate failure in any Binder method handler.
+const int kErrorCode = -1;
+} // namespace
+
namespace shill {
namespace Logging {
@@ -97,45 +113,100 @@ void ServiceBinderAdaptor::EmitStringmapChanged(const string& name,
}
Status ServiceBinderAdaptor::Connect() {
- // STUB IMPLEMENTATION.
- // TODO(samueltan): replace this with proper implementation.
- return Status::ok();
+ SLOG(this, 2) << __func__;
+ Error e;
+ service_->UserInitiatedConnect(kBinderRpcReasonString, &e);
+ return e.ToBinderStatus();
}
Status ServiceBinderAdaptor::GetState(int32_t* _aidl_return) {
- // STUB IMPLEMENTATION.
- // TODO(samueltan): replace this with proper implementation.
+ SLOG(this, 2) << __func__;
+ Error e;
+ string state = service_->CalculateState(&e);
+ if (e.IsFailure()) {
+ return e.ToBinderStatus();
+ }
+ if (state == shill::kStateIdle) {
+ *_aidl_return = IService::STATE_IDLE;
+ } else if (state == shill::kStateAssociation) {
+ *_aidl_return = IService::STATE_ASSOC;
+ } else if (state == shill::kStateConfiguration) {
+ *_aidl_return = IService::STATE_CONFIG;
+ } else if (state == shill::kStateReady) {
+ *_aidl_return = IService::STATE_READY;
+ } else if (state == shill::kStateFailure) {
+ *_aidl_return = IService::STATE_FAILURE;
+ } else if (state == shill::kStatePortal) {
+ *_aidl_return = IService::STATE_PORTAL;
+ } else if (state == shill::kStateOnline) {
+ *_aidl_return = IService::STATE_ONLINE;
+ } else {
+ LOG(ERROR) << __func__ << ": unsupported state";
+ return Status::fromServiceSpecificError(
+ kErrorCode, String8("Unsupported state"));
+ }
return Status::ok();
}
Status ServiceBinderAdaptor::GetStrength(int8_t* _aidl_return) {
- // STUB IMPLEMENTATION.
- // TODO(samueltan): replace this with proper implementation.
+ SLOG(this, 2) << __func__;
+ *_aidl_return = service_->strength();
return Status::ok();
}
Status ServiceBinderAdaptor::GetError(int32_t* _aidl_return) {
- // STUB IMPLEMENTATION.
- // TODO(samueltan): replace this with proper implementation.
- return Status::ok();
+ SLOG(this, 2) << __func__;
+ return ShillErrorToIServiceErrorType(service_->error(), _aidl_return);
}
Status ServiceBinderAdaptor::GetTethering(int32_t* _aidl_return) {
- // STUB IMPLEMENTATION.
- // TODO(samueltan): replace this with proper implementation.
+ SLOG(this, 2) << __func__;
+ Error e;
+ string tethering = service_->GetTethering(&e);
+ if (e.IsFailure()) {
+ return e.ToBinderStatus();
+ }
+ if (tethering == kTetheringConfirmedState) {
+ *_aidl_return = IService::TETHERING_CONFIRMED;
+ } else if (tethering == kTetheringSuspectedState) {
+ *_aidl_return = IService::TETHERING_SUSPECTED;
+ } else if (tethering == kTetheringNotDetectedState) {
+ *_aidl_return = IService::TETHERING_NOT_DETECTED;
+ } else {
+ LOG(ERROR) << __func__ << ": unsupported tethering state";
+ return Status::fromServiceSpecificError(
+ kErrorCode, String8("Unsupported tethering state"));
+ }
return Status::ok();
}
Status ServiceBinderAdaptor::GetType(int32_t* _aidl_return) {
- // STUB IMPLEMENTATION.
- // TODO(samueltan): replace this with proper implementation.
- return Status::ok();
+ SLOG(this, 2) << __func__;
+ Error e;
+ string technology = service_->CalculateTechnology(&e);
+ if (e.IsFailure()) {
+ return e.ToBinderStatus();
+ }
+ return ShillTechnologyToIServiceType(technology, _aidl_return);
}
Status ServiceBinderAdaptor::GetPhysicalTechnology(int32_t* _aidl_return) {
- // STUB IMPLEMENTATION.
- // TODO(samueltan): replace this with proper implementation.
- return Status::ok();
+ SLOG(this, 2) << __func__;
+ int32_t service_type;
+ GetType(&service_type);
+ if (service_type != IService::TYPE_VPN) {
+ LOG(ERROR) << __func__ << ": this method is only valid for VPN services";
+ return Status::fromServiceSpecificError(
+ kErrorCode, String8("This method is only valid for VPN services"));
+ }
+ // This is safe, because we know that the service is a VPN service.
+ VPNService* vpn_service = static_cast<VPNService*>(service_);
+ Error e;
+ string physical_techology = vpn_service->GetPhysicalTechnologyProperty(&e);
+ if (e.IsFailure()) {
+ return e.ToBinderStatus();
+ }
+ return ShillTechnologyToIServiceType(physical_techology, _aidl_return);
}
Status ServiceBinderAdaptor::RegisterPropertyChangedSignalHandler(
@@ -144,4 +215,76 @@ Status ServiceBinderAdaptor::RegisterPropertyChangedSignalHandler(
return Status::ok();
}
+Status ServiceBinderAdaptor::ShillTechnologyToIServiceType(
+ const string& technology, int32_t* type) {
+ if (technology == kTypeEthernet) {
+ *type = IService::TYPE_ETHERNET;
+ } else if (technology == kTypeWifi) {
+ *type = IService::TYPE_WIFI;
+ } else if (technology == kTypeWimax) {
+ *type = IService::TYPE_WIMAX;
+ } else if (technology == kTypeCellular) {
+ *type = IService::TYPE_CELLULAR;
+ } else if (technology == kTypeVPN) {
+ *type = IService::TYPE_VPN;
+ } else if (technology == kTypePPPoE) {
+ *type = IService::TYPE_PPPOE;
+ } else {
+ LOG(ERROR) << __func__ << ": unsupported technology type";
+ return Status::fromServiceSpecificError(
+ kErrorCode, String8("Unsupported technology type"));
+ }
+ return Status::ok();
+}
+
+Status ServiceBinderAdaptor::ShillErrorToIServiceErrorType(
+ const string& error, int32_t* error_type) {
+ if (error == kErrorAaaFailed) {
+ *error_type = IService::ERROR_AAA_FAILED;
+ } else if (error == kErrorActivationFailed) {
+ *error_type = IService::ERROR_ACTIVATION_FAILED;
+ } else if (error == kErrorBadPassphrase) {
+ *error_type = IService::ERROR_BAD_PASSPHRASE;
+ } else if (error == kErrorBadWEPKey) {
+ *error_type = IService::ERROR_BAD_WEP_KEY;
+ } else if (error == kErrorConnectFailed) {
+ *error_type = IService::ERROR_CONNECT_FAILED;
+ } else if (error == kErrorDNSLookupFailed) {
+ *error_type = IService::ERROR_DNS_LOOKUP_FAILED;
+ } else if (error == kErrorDhcpFailed) {
+ *error_type = IService::ERROR_DHCP_FAILED;
+ } else if (error == kErrorHTTPGetFailed) {
+ *error_type = IService::ERROR_HTTP_GET_FAILED;
+ } else if (error == kErrorInternal) {
+ *error_type = IService::ERROR_INTERNAL;
+ } else if (error == kErrorInvalidFailure) {
+ *error_type = IService::ERROR_INVALID_FAILURE;
+ } else if (error == kErrorIpsecCertAuthFailed) {
+ *error_type = IService::ERROR_IPSEC_CERT_AUTH_FAILED;
+ } else if (error == kErrorIpsecPskAuthFailed) {
+ *error_type = IService::ERROR_IPSEC_PSK_AUTH_FAILED;
+ } else if (error == kErrorNeedEvdo) {
+ *error_type = IService::ERROR_NEED_EVDO;
+ } else if (error == kErrorNeedHomeNetwork) {
+ *error_type = IService::ERROR_NEED_HOME_NETWORK;
+ } else if (error == kErrorNoFailure) {
+ *error_type = IService::ERROR_NO_FAILURE;
+ } else if (error == kErrorOtaspFailed) {
+ *error_type = IService::ERROR_OTASP_FAILED;
+ } else if (error == kErrorOutOfRange) {
+ *error_type = IService::ERROR_OUT_OF_RANGE;
+ } else if (error == kErrorPinMissing) {
+ *error_type = IService::ERROR_PIN_MISSING;
+ } else if (error == kErrorPppAuthFailed) {
+ *error_type = IService::ERROR_PPP_AUTH_FAILED;
+ } else if (error == kErrorUnknownFailure) {
+ *error_type = IService::ERROR_UNKNOWN_FAILURE;
+ } else {
+ LOG(ERROR) << __func__ << ": unsupported error";
+ return Status::fromServiceSpecificError(kErrorCode,
+ String8("Unsupported error"));
+ }
+ return Status::ok();
+}
+
} // namespace shill
diff --git a/binder/service_binder_adaptor.h b/binder/service_binder_adaptor.h
index 193cf9ca..f7804a9b 100644
--- a/binder/service_binder_adaptor.h
+++ b/binder/service_binder_adaptor.h
@@ -74,21 +74,26 @@ class ServiceBinderAdaptor
const Stringmap& value) override;
// Implementation of BnService.
- android::binder::Status Connect();
- android::binder::Status GetState(int32_t* _aidl_return);
- android::binder::Status GetStrength(int8_t* _aidl_return);
- android::binder::Status GetError(int32_t* _aidl_return);
- android::binder::Status GetTethering(int32_t* _aidl_return);
- android::binder::Status GetType(int32_t* _aidl_return);
- android::binder::Status GetPhysicalTechnology(int32_t* _aidl_return);
+ android::binder::Status Connect() override;
+ android::binder::Status GetState(int32_t* _aidl_return) override;
+ android::binder::Status GetStrength(int8_t* _aidl_return) override;
+ android::binder::Status GetError(int32_t* _aidl_return) override;
+ android::binder::Status GetTethering(int32_t* _aidl_return) override;
+ android::binder::Status GetType(int32_t* _aidl_return) override;
+ android::binder::Status GetPhysicalTechnology(int32_t* _aidl_return) override;
android::binder::Status RegisterPropertyChangedSignalHandler(
const android::sp<
android::system::connectivity::shill::IPropertyChangedCallback>&
- callback);
+ callback) override;
Service* service() const { return service_; }
private:
+ android::binder::Status ShillTechnologyToIServiceType(
+ const std::string& technology, int32_t* type);
+ android::binder::Status ShillErrorToIServiceErrorType(
+ const std::string& error, int32_t* error_type);
+
Service* service_;
DISALLOW_COPY_AND_ASSIGN(ServiceBinderAdaptor);
diff --git a/service.cc b/service.cc
index 9cf5727e..522b54b6 100644
--- a/service.cc
+++ b/service.cc
@@ -969,10 +969,6 @@ string Service::GetTechnologyString() const {
return Technology::NameFromIdentifier(technology());
}
-string Service::CalculateTechnology(Error* /*error*/) {
- return GetTechnologyString();
-}
-
void Service::NoteDisconnectEvent() {
SLOG(this, 2) << __func__;
// Ignore the event if it's user-initiated explicit disconnect.
@@ -1294,10 +1290,6 @@ string Service::GetStateString() const {
}
}
-string Service::CalculateState(Error* /*error*/) {
- return GetStateString();
-}
-
bool Service::IsAutoConnectable(const char** reason) const {
if (manager_->IsTechnologyAutoConnectDisabled(technology_)) {
*reason = kAutoConnTechnologyNotConnectable;
@@ -1449,6 +1441,22 @@ map<string, string> Service::GetLoadableProfileEntries() {
return manager_->GetLoadableProfileEntriesForService(this);
}
+string Service::CalculateState(Error* /*error*/) {
+ return GetStateString();
+}
+
+string Service::CalculateTechnology(Error* /*error*/) {
+ return GetTechnologyString();
+}
+
+string Service::GetTethering(Error* error) const {
+ // The "Tethering" property isn't supported by the Service base class, and
+ // therefore should not be listed in the properties returned by
+ // the GetProperties() RPC method.
+ error->Populate(Error::kNotSupported);
+ return "";
+}
+
void Service::IgnoreParameterForConfigure(const string& parameter) {
parameters_ignored_for_configure_.insert(parameter);
}
@@ -1634,15 +1642,6 @@ bool Service::SetProxyConfig(const string& proxy_config, Error* error) {
return true;
}
-string Service::GetTethering(Error* error) const {
- // The "Tethering" property isn't supported by the Service base class, and
- // therefore should not be listed in the properties returned by
- // the GetProperties() RPC method.
- error->Populate(Error::kNotSupported);
- return "";
-}
-
-
void Service::NotifyPropertyChanges() {
property_change_notifier_->UpdatePropertyObservers();
}
diff --git a/service.h b/service.h
index c0641476..125e31fa 100644
--- a/service.h
+++ b/service.h
@@ -546,6 +546,15 @@ class Service : public base::RefCounted<Service> {
// this service.
std::map<std::string, std::string> GetLoadableProfileEntries();
+ virtual std::string CalculateState(Error* error);
+
+ std::string CalculateTechnology(Error* error);
+
+ // Return whether this service is suspected or confirmed to be
+ // provided by a mobile device, which is likely to be using a
+ // metered backhaul for internet connectivity.
+ virtual std::string GetTethering(Error* error) const;
+
void set_connection_id(int connection_id) { connection_id_ = connection_id; }
int connection_id() const { return connection_id_; }
@@ -565,9 +574,6 @@ class Service : public base::RefCounted<Service> {
// Returns true if a character is disallowed to be in a service storage id.
static bool IllegalChar(char a) { return !LegalChar(a); }
- virtual std::string CalculateState(Error* error);
- std::string CalculateTechnology(Error* error);
-
bool GetVisibleProperty(Error* error);
// Returns whether this service is in a state conducive to auto-connect.
@@ -659,11 +665,6 @@ class Service : public base::RefCounted<Service> {
// that the semantics of SecurityLevel() are appropriate for the subclass.
void SetSecurity(CryptoAlgorithm crypt, bool rotation, bool endpoint_auth);
- // Return whether this service is suspected or confirmed to be
- // provided by a mobile device, which is likely to be using a
- // metered backhaul for internet connectivity.
- virtual std::string GetTethering(Error* error) const;
-
// Emit property change notifications for all observed properties.
void NotifyPropertyChanges();
diff --git a/vpn/vpn_service.cc b/vpn/vpn_service.cc
index 64304751..47d96290 100644
--- a/vpn/vpn_service.cc
+++ b/vpn/vpn_service.cc
@@ -119,6 +119,19 @@ string VPNService::CreateStorageIdentifier(const KeyValueStore& args,
return id;
}
+string VPNService::GetPhysicalTechnologyProperty(Error* error) {
+ ConnectionRefPtr conn = connection();
+ if (conn)
+ conn = conn->GetCarrierConnection();
+
+ if (!conn) {
+ error->Populate(Error::kOperationFailed);
+ return "";
+ }
+
+ return Technology::NameFromIdentifier(conn->technology());
+}
+
string VPNService::GetDeviceRpcId(Error* error) const {
error->Populate(Error::kNotSupported);
return "/";
@@ -245,19 +258,6 @@ bool VPNService::SetNameProperty(const string& name, Error* error) {
return true;
}
-string VPNService::GetPhysicalTechnologyProperty(Error* error) {
- ConnectionRefPtr conn = connection();
- if (conn)
- conn = conn->GetCarrierConnection();
-
- if (!conn) {
- error->Populate(Error::kOperationFailed);
- return "";
- }
-
- return Technology::NameFromIdentifier(conn->technology());
-}
-
void VPNService::OnBeforeSuspend(const ResultCallback& callback) {
driver_->OnBeforeSuspend(callback);
}
diff --git a/vpn/vpn_service.h b/vpn/vpn_service.h
index b6188fe6..a6ed7789 100644
--- a/vpn/vpn_service.h
+++ b/vpn/vpn_service.h
@@ -63,6 +63,10 @@ class VPNService : public Service {
Error* error);
void set_storage_id(const std::string& id) { storage_id_ = id; }
+ // Returns the Type name of the lowest connection (presumably the "physical"
+ // connection) that this service depends on.
+ std::string GetPhysicalTechnologyProperty(Error* error);
+
protected:
// Inherited from Service.
bool IsAutoConnectable(const char** reason) const override;
@@ -81,10 +85,6 @@ class VPNService : public Service {
std::string GetDeviceRpcId(Error* error) const override;
- // Returns the Type name of the lowest connection (presumably the "physical"
- // connection) that this service depends on.
- std::string GetPhysicalTechnologyProperty(Error* error);
-
std::string storage_id_;
std::unique_ptr<VPNDriver> driver_;
std::unique_ptr<Connection::Binder> connection_binder_;