summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Qiu <zqiu@google.com>2016-01-20 20:00:28 +0000
committerandroid-build-merger <android-build-merger@google.com>2016-01-20 20:00:28 +0000
commit838af6fa2682a05622677fd0fda239495bd0179f (patch)
tree1eaaba6de13c5fc70617ab885706f41f52516b0a
parentd1de62fdd95dba82330de7b578c74fa01cc397e9 (diff)
parentb2267c9c1cb77564df9d74b5e81689c7e43b8e10 (diff)
downloadshill-838af6fa2682a05622677fd0fda239495bd0179f.tar.gz
Revert "Revert "shill: store VendorEncapsulatedOptions as ByteArray""
am: b2267c9c1c * commit 'b2267c9c1cb77564df9d74b5e81689c7e43b8e10': Revert "Revert "shill: store VendorEncapsulatedOptions as ByteArray""
-rw-r--r--device.cc18
-rw-r--r--device_unittest.cc13
-rw-r--r--dhcp/dhcpv4_config.cc2
-rw-r--r--doc/ipconfig-api.txt4
-rw-r--r--ipconfig.cc4
-rw-r--r--ipconfig.h2
6 files changed, 30 insertions, 13 deletions
diff --git a/device.cc b/device.cc
index 5dcedc4f..75315433 100644
--- a/device.cc
+++ b/device.cc
@@ -20,6 +20,7 @@
#include <netinet/in.h>
#include <linux/if.h> // NOLINT - Needs definitions from netinet/in.h
#include <stdio.h>
+#include <string.h>
#include <sys/param.h>
#include <time.h>
#include <unistd.h>
@@ -413,10 +414,19 @@ bool Device::IsConnectedToService(const ServiceRefPtr& service) const {
}
bool Device::IsConnectedViaTether() const {
- return
- ipconfig_.get() &&
- ipconfig_->properties().vendor_encapsulated_options ==
- Tethering::kAndroidVendorEncapsulatedOptions;
+ if (!ipconfig_.get())
+ return false;
+
+ ByteArray vendor_encapsulated_options =
+ ipconfig_->properties().vendor_encapsulated_options;
+ size_t android_vendor_encapsulated_options_len =
+ strlen(Tethering::kAndroidVendorEncapsulatedOptions);
+
+ return (vendor_encapsulated_options.size() ==
+ android_vendor_encapsulated_options_len) &&
+ !memcmp(&vendor_encapsulated_options[0],
+ Tethering::kAndroidVendorEncapsulatedOptions,
+ vendor_encapsulated_options.size());
}
string Device::GetRpcIdentifier() const {
diff --git a/device_unittest.cc b/device_unittest.cc
index 33fc8def..2b9e0155 100644
--- a/device_unittest.cc
+++ b/device_unittest.cc
@@ -1246,12 +1246,19 @@ TEST_F(DeviceTest, IsConnectedViaTether) {
// Add an ipconfig property that indicates this is an Android tether.
IPConfig::Properties properties;
- properties.vendor_encapsulated_options =
- Tethering::kAndroidVendorEncapsulatedOptions;
+ properties.vendor_encapsulated_options = ByteArray(
+ Tethering::kAndroidVendorEncapsulatedOptions,
+ Tethering::kAndroidVendorEncapsulatedOptions +
+ strlen(Tethering::kAndroidVendorEncapsulatedOptions)
+ );
device_->ipconfig_->UpdateProperties(properties, true);
EXPECT_TRUE(device_->IsConnectedViaTether());
- properties.vendor_encapsulated_options = "Some other non-empty value";
+ const char kTestVendorEncapsulatedOptions[] = "Some other non-empty value";
+ properties.vendor_encapsulated_options = ByteArray(
+ kTestVendorEncapsulatedOptions,
+ kTestVendorEncapsulatedOptions + sizeof(kTestVendorEncapsulatedOptions)
+ );
device_->ipconfig_->UpdateProperties(properties, true);
EXPECT_FALSE(device_->IsConnectedViaTether());
}
diff --git a/dhcp/dhcpv4_config.cc b/dhcp/dhcpv4_config.cc
index a7ac174c..720870d0 100644
--- a/dhcp/dhcpv4_config.cc
+++ b/dhcp/dhcpv4_config.cc
@@ -396,7 +396,7 @@ bool DHCPv4Config::ParseConfiguration(const KeyValueStore& configuration,
} else if (key == kConfigurationKeyClasslessStaticRoutes) {
classless_static_routes = value.Get<string>();
} else if (key == kConfigurationKeyVendorEncapsulatedOptions) {
- properties->vendor_encapsulated_options = value.Get<string>();
+ properties->vendor_encapsulated_options = value.Get<ByteArray>();
} else if (key == kConfigurationKeyWebProxyAutoDiscoveryUrl) {
properties->web_proxy_auto_discovery = value.Get<string>();
} else if (key == kConfigurationKeyLeaseTime) {
diff --git a/doc/ipconfig-api.txt b/doc/ipconfig-api.txt
index 00017210..958c2bbb 100644
--- a/doc/ipconfig-api.txt
+++ b/doc/ipconfig-api.txt
@@ -92,10 +92,10 @@ Properties string Address [readonly]
a netmask of 255.255.255.0 has a prefixlen of 24
(note arbitrary CIDR masks are not supported.)
- string VendorEncapsulatedOptions [readonly]
+ array{uint8} VendorEncapsulatedOptions [readonly]
Server-provided value for the DHCP option 43
- value. Its interpretation vairies based on
+ value. Its interpretation varies based on
the DHCP server.
string WebProxyAutoDiscoveryUrl [readonly]
diff --git a/ipconfig.cc b/ipconfig.cc
index 7bfa5ee5..4b700302 100644
--- a/ipconfig.cc
+++ b/ipconfig.cc
@@ -91,8 +91,8 @@ void IPConfig::Init() {
store_.RegisterConstInt32(kPrefixlenProperty, &properties_.subnet_prefix);
store_.RegisterConstStrings(kSearchDomainsProperty,
&properties_.domain_search);
- store_.RegisterConstString(kVendorEncapsulatedOptionsProperty,
- &properties_.vendor_encapsulated_options);
+ store_.RegisterConstByteArray(kVendorEncapsulatedOptionsProperty,
+ &properties_.vendor_encapsulated_options);
store_.RegisterConstString(kWebProxyAutoDiscoveryUrlProperty,
&properties_.web_proxy_auto_discovery);
store_.RegisterConstString(kDelegatedPrefixProperty,
diff --git a/ipconfig.h b/ipconfig.h
index 40d196fe..6888ebdb 100644
--- a/ipconfig.h
+++ b/ipconfig.h
@@ -86,7 +86,7 @@ class IPConfig : public base::RefCounted<IPConfig> {
int32_t mtu;
std::vector<Route> routes;
// Vendor encapsulated option string gained from DHCP.
- std::string vendor_encapsulated_options;
+ ByteArray vendor_encapsulated_options;
// Web Proxy Auto Discovery (WPAD) URL gained from DHCP.
std::string web_proxy_auto_discovery;
// Length of time the lease was granted.