#include "chromeos/chromeos_switches.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/shill_device_client.h"
+#include "chromeos/dbus/shill_ipconfig_client.h"
#include "chromeos/dbus/shill_profile_client.h"
#include "chromeos/dbus/shill_property_changed_observer.h"
#include "chromeos/dbus/shill_service_client.h"
};
// Appends string entries from |service_list_in| whose entries in ServiceClient
-// have Type |match_type| to either an active list or an inactive list
-// based on the entry's State.
+// have Type |match_type| to one of the output lists based on the entry's State.
void AppendServicesForType(
const base::ListValue* service_list_in,
const char* match_type,
+ bool technology_enabled,
std::vector<std::string>* active_service_list_out,
- std::vector<std::string>* inactive_service_list_out) {
+ std::vector<std::string>* inactive_service_list_out,
+ std::vector<std::string>* disabled_service_list_out) {
ShillServiceClient::TestInterface* service_client =
DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface();
for (base::ListValue::const_iterator iter = service_list_in->begin();
properties->GetString(shill::kTypeProperty, &type);
if (type != match_type)
continue;
+ bool visible = false;
+ if (technology_enabled)
+ properties->GetBoolean(shill::kVisibleProperty, &visible);
+ if (!visible) {
+ disabled_service_list_out->push_back(service_path);
+ continue;
+ }
std::string state;
properties->GetString(shill::kStateProperty, &state);
if (state == shill::kStateOnline ||
const char* kTechnologyUnavailable = "unavailable";
const char* kNetworkActivated = "activated";
const char* kNetworkDisabled = "disabled";
+const char* kCellularServicePath = "/service/cellular1";
} // namespace
+// static
+const char FakeShillManagerClient::kFakeEthernetNetworkGuid[] = "eth1_guid";
+
FakeShillManagerClient::FakeShillManagerClient()
: interactive_delay_(0),
weak_ptr_factory_(this) {
void FakeShillManagerClient::GetProperties(
const DictionaryValueCallback& callback) {
+ DVLOG(1) << "Manager.GetProperties";
base::MessageLoop::current()->PostTask(
FROM_HERE, base::Bind(
&FakeShillManagerClient::PassStubProperties,
const base::Value& value,
const base::Closure& callback,
const ErrorCallback& error_callback) {
+ DVLOG(2) << "SetProperty: " << name;
stub_properties_.SetWithoutPathExpansion(name, value.DeepCopy());
CallNotifyObserversPropertyChanged(name);
base::MessageLoop::current()->PostTask(FROM_HERE, callback);
if (!existing_properties) {
// Add a new service to the service client stub because none exists, yet.
// This calls AddManagerService.
- service_client->AddServiceWithIPConfig(service_path, guid, type,
- shill::kStateIdle, ipconfig_path,
- true /* visible */,
- true /* watch */);
+ service_client->AddServiceWithIPConfig(service_path,
+ guid /* guid */,
+ guid /* name */,
+ type,
+ shill::kStateIdle,
+ ipconfig_path,
+ true /* visible */);
existing_properties = service_client->GetServiceProperties(service_path);
}
void FakeShillManagerClient::ConnectToBestServices(
const base::Closure& callback,
const ErrorCallback& error_callback) {
+ if (best_service_.empty()) {
+ VLOG(1) << "No 'best' service set.";
+ return;
+ }
+
+ DBusThreadManager::Get()->GetShillServiceClient()->Connect(
+ dbus::ObjectPath(best_service_), callback, error_callback);
}
ShillManagerClient::TestInterface* FakeShillManagerClient::GetTestInterface() {
// ShillManagerClient::TestInterface overrides.
void FakeShillManagerClient::AddDevice(const std::string& device_path) {
- if (GetListProperty(shill::kDevicesProperty)->AppendIfNotPresent(
- base::Value::CreateStringValue(device_path))) {
+ if (GetListProperty(shill::kDevicesProperty)
+ ->AppendIfNotPresent(new base::StringValue(device_path))) {
CallNotifyObserversPropertyChanged(shill::kDevicesProperty);
}
}
void FakeShillManagerClient::AddTechnology(const std::string& type,
bool enabled) {
- if (GetListProperty(shill::kAvailableTechnologiesProperty)->
- AppendIfNotPresent(base::Value::CreateStringValue(type))) {
+ if (GetListProperty(shill::kAvailableTechnologiesProperty)
+ ->AppendIfNotPresent(new base::StringValue(type))) {
CallNotifyObserversPropertyChanged(
shill::kAvailableTechnologiesProperty);
}
if (enabled &&
- GetListProperty(shill::kEnabledTechnologiesProperty)->
- AppendIfNotPresent(base::Value::CreateStringValue(type))) {
+ GetListProperty(shill::kEnabledTechnologiesProperty)
+ ->AppendIfNotPresent(new base::StringValue(type))) {
CallNotifyObserversPropertyChanged(
shill::kEnabledTechnologiesProperty);
}
void FakeShillManagerClient::SetTechnologyInitializing(const std::string& type,
bool initializing) {
if (initializing) {
- if (GetListProperty(shill::kUninitializedTechnologiesProperty)->
- AppendIfNotPresent(base::Value::CreateStringValue(type))) {
+ if (GetListProperty(shill::kUninitializedTechnologiesProperty)
+ ->AppendIfNotPresent(new base::StringValue(type))) {
CallNotifyObserversPropertyChanged(
shill::kUninitializedTechnologiesProperty);
}
base::Bind(&base::DoNothing), base::Bind(&LogErrorCallback));
}
-void FakeShillManagerClient::AddManagerService(const std::string& service_path,
- bool add_to_visible_list,
- bool add_to_watch_list) {
- // Always add to ServiceCompleteListProperty.
- GetListProperty(shill::kServiceCompleteListProperty)->AppendIfNotPresent(
- base::Value::CreateStringValue(service_path));
- // If visible, add to Services and notify if new.
- if (add_to_visible_list &&
- GetListProperty(shill::kServicesProperty)->AppendIfNotPresent(
- base::Value::CreateStringValue(service_path))) {
- CallNotifyObserversPropertyChanged(shill::kServicesProperty);
- }
- if (add_to_watch_list)
- AddServiceToWatchList(service_path);
+void FakeShillManagerClient::AddManagerService(
+ const std::string& service_path,
+ bool notify_observers) {
+ DVLOG(2) << "AddManagerService: " << service_path;
+ GetListProperty(shill::kServiceCompleteListProperty)
+ ->AppendIfNotPresent(new base::StringValue(service_path));
+ SortManagerServices(false);
+ if (notify_observers)
+ CallNotifyObserversPropertyChanged(shill::kServiceCompleteListProperty);
}
void FakeShillManagerClient::RemoveManagerService(
const std::string& service_path) {
+ DVLOG(2) << "RemoveManagerService: " << service_path;
base::StringValue service_path_value(service_path);
- if (GetListProperty(shill::kServicesProperty)->Remove(
- service_path_value, NULL)) {
- CallNotifyObserversPropertyChanged(shill::kServicesProperty);
- }
GetListProperty(shill::kServiceCompleteListProperty)->Remove(
service_path_value, NULL);
- if (GetListProperty(shill::kServiceWatchListProperty)->Remove(
- service_path_value, NULL)) {
- CallNotifyObserversPropertyChanged(
- shill::kServiceWatchListProperty);
- }
+ CallNotifyObserversPropertyChanged(shill::kServiceCompleteListProperty);
}
void FakeShillManagerClient::ClearManagerServices() {
- GetListProperty(shill::kServicesProperty)->Clear();
+ DVLOG(1) << "ClearManagerServices";
GetListProperty(shill::kServiceCompleteListProperty)->Clear();
- GetListProperty(shill::kServiceWatchListProperty)->Clear();
- CallNotifyObserversPropertyChanged(shill::kServicesProperty);
- CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty);
+ CallNotifyObserversPropertyChanged(shill::kServiceCompleteListProperty);
}
void FakeShillManagerClient::ServiceStateChanged(
}
}
-void FakeShillManagerClient::SortManagerServices() {
- static const char* ordered_types[] = {
- shill::kTypeEthernet,
- shill::kTypeWifi,
- shill::kTypeCellular,
- shill::kTypeWimax,
- shill::kTypeVPN
- };
- base::ListValue* service_list = GetListProperty(shill::kServicesProperty);
- if (!service_list || service_list->empty()) {
- if (!default_service_.empty()) {
- default_service_.clear();
- base::StringValue empty_value("");
- SetManagerProperty(shill::kDefaultServiceProperty, empty_value);
- }
+void FakeShillManagerClient::SortManagerServices(bool notify) {
+ DVLOG(1) << "SortManagerServices";
+ static const char* ordered_types[] = {shill::kTypeEthernet,
+ shill::kTypeEthernetEap,
+ shill::kTypeWifi,
+ shill::kTypeCellular,
+ shill::kTypeWimax,
+ shill::kTypeVPN};
+
+ base::ListValue* complete_list =
+ GetListProperty(shill::kServiceCompleteListProperty);
+ if (complete_list->empty())
return;
- }
+ scoped_ptr<base::ListValue> prev_complete_list(complete_list->DeepCopy());
+
std::vector<std::string> active_services;
std::vector<std::string> inactive_services;
+ std::vector<std::string> disabled_services;
for (size_t i = 0; i < arraysize(ordered_types); ++i) {
- AppendServicesForType(service_list, ordered_types[i],
- &active_services, &inactive_services);
+ AppendServicesForType(complete_list,
+ ordered_types[i],
+ TechnologyEnabled(ordered_types[i]),
+ &active_services,
+ &inactive_services,
+ &disabled_services);
}
- service_list->Clear();
+ complete_list->Clear();
for (size_t i = 0; i < active_services.size(); ++i)
- service_list->AppendString(active_services[i]);
+ complete_list->AppendString(active_services[i]);
for (size_t i = 0; i < inactive_services.size(); ++i)
- service_list->AppendString(inactive_services[i]);
+ complete_list->AppendString(inactive_services[i]);
+ for (size_t i = 0; i < disabled_services.size(); ++i)
+ complete_list->AppendString(disabled_services[i]);
- CallNotifyObserversPropertyChanged(shill::kServicesProperty);
+ if (notify && !complete_list->Equals(prev_complete_list.get()))
+ CallNotifyObserversPropertyChanged(shill::kServiceCompleteListProperty);
// Set the first active service as the Default service.
std::string new_default_service;
}
}
-
int FakeShillManagerClient::GetInteractiveDelay() const {
return interactive_delay_;
}
+void FakeShillManagerClient::SetBestServiceToConnect(
+ const std::string& service_path) {
+ best_service_ = service_path;
+}
+
void FakeShillManagerClient::SetupDefaultEnvironment() {
DBusThreadManager* dbus_manager = DBusThreadManager::Get();
ShillServiceClient::TestInterface* services =
dbus_manager->GetShillServiceClient()->GetTestInterface();
+ DCHECK(services);
ShillProfileClient::TestInterface* profiles =
dbus_manager->GetShillProfileClient()->GetTestInterface();
+ DCHECK(profiles);
ShillDeviceClient::TestInterface* devices =
dbus_manager->GetShillDeviceClient()->GetTestInterface();
- if (!services || !profiles || !devices)
- return;
+ DCHECK(devices);
+ ShillIPConfigClient::TestInterface* ip_configs =
+ dbus_manager->GetShillIPConfigClient()->GetTestInterface();
+ DCHECK(ip_configs);
const std::string shared_profile = ShillProfileClient::GetSharedProfilePath();
profiles->AddProfile(shared_profile, std::string());
const bool add_to_visible = true;
- const bool add_to_watchlist = true;
+
+ // IPConfigs
+ base::DictionaryValue ipconfig_v4_dictionary;
+ ipconfig_v4_dictionary.SetStringWithoutPathExpansion(
+ shill::kAddressProperty, "0.0.0.0");
+ ipconfig_v4_dictionary.SetStringWithoutPathExpansion(
+ shill::kGatewayProperty, "0.0.0.1");
+ ipconfig_v4_dictionary.SetIntegerWithoutPathExpansion(
+ shill::kPrefixlenProperty, 0);
+ ipconfig_v4_dictionary.SetStringWithoutPathExpansion(
+ shill::kMethodProperty, shill::kTypeIPv4);
+ ip_configs->AddIPConfig("ipconfig_v4_path", ipconfig_v4_dictionary);
+ base::DictionaryValue ipconfig_v6_dictionary;
+ ipconfig_v6_dictionary.SetStringWithoutPathExpansion(
+ shill::kAddressProperty, "0:0:0:0:0:0:0:0");
+ ipconfig_v6_dictionary.SetStringWithoutPathExpansion(
+ shill::kMethodProperty, shill::kTypeIPv6);
+ ip_configs->AddIPConfig("ipconfig_v6_path", ipconfig_v6_dictionary);
bool enabled;
std::string state;
AddTechnology(shill::kTypeEthernet, enabled);
devices->AddDevice(
"/device/eth1", shill::kTypeEthernet, "stub_eth_device1");
- services->AddService("eth1", "eth1",
+ devices->SetDeviceProperty("/device/eth1",
+ shill::kAddressProperty,
+ base::StringValue("0123456789ab"));
+ base::ListValue eth_ip_configs;
+ eth_ip_configs.AppendString("ipconfig_v4_path");
+ eth_ip_configs.AppendString("ipconfig_v6_path");
+ devices->SetDeviceProperty("/device/eth1",
+ shill::kIPConfigsProperty,
+ eth_ip_configs);
+ const std::string kFakeEthernetNetworkPath = "/service/eth1";
+ services->AddService(kFakeEthernetNetworkPath,
+ kFakeEthernetNetworkGuid,
+ "eth1" /* name */,
shill::kTypeEthernet,
state,
- add_to_visible, add_to_watchlist);
- profiles->AddService(shared_profile, "eth1");
+ add_to_visible);
+ profiles->AddService(shared_profile, kFakeEthernetNetworkPath);
}
// Wifi
}
AddTechnology(shill::kTypeWifi, enabled);
devices->AddDevice("/device/wifi1", shill::kTypeWifi, "stub_wifi_device1");
-
- services->AddService("wifi1",
- "wifi1",
+ devices->SetDeviceProperty("/device/wifi1",
+ shill::kAddressProperty,
+ base::StringValue("23456789abc"));
+ base::ListValue wifi_ip_configs;
+ wifi_ip_configs.AppendString("ipconfig_v4_path");
+ wifi_ip_configs.AppendString("ipconfig_v6_path");
+ devices->SetDeviceProperty("/device/wifi1",
+ shill::kIPConfigsProperty,
+ wifi_ip_configs);
+
+ const std::string kWifi1Path = "/service/wifi1";
+ services->AddService(kWifi1Path,
+ "wifi1_guid",
+ "wifi1" /* name */,
shill::kTypeWifi,
state,
- add_to_visible, add_to_watchlist);
- services->SetServiceProperty("wifi1",
+ add_to_visible);
+ services->SetServiceProperty(kWifi1Path,
shill::kSecurityProperty,
base::StringValue(shill::kSecurityWep));
- profiles->AddService(shared_profile, "wifi1");
-
- services->AddService("wifi2",
- "wifi2_PSK",
+ services->SetServiceProperty(kWifi1Path,
+ shill::kConnectableProperty,
+ base::FundamentalValue(true));
+ profiles->AddService(shared_profile, kWifi1Path);
+
+ const std::string kWifi2Path = "/service/wifi2";
+ services->AddService(kWifi2Path,
+ "wifi2_PSK_guid",
+ "wifi2_PSK" /* name */,
shill::kTypeWifi,
shill::kStateIdle,
- add_to_visible, add_to_watchlist);
- services->SetServiceProperty("wifi2",
+ add_to_visible);
+ services->SetServiceProperty(kWifi2Path,
shill::kSecurityProperty,
base::StringValue(shill::kSecurityPsk));
base::FundamentalValue strength_value(80);
services->SetServiceProperty(
- "wifi2", shill::kSignalStrengthProperty, strength_value);
- profiles->AddService(shared_profile, "wifi2");
+ kWifi2Path, shill::kSignalStrengthProperty, strength_value);
+ profiles->AddService(shared_profile, kWifi2Path);
if (portaled) {
- const std::string kPortaledWifiPath = "portaled_wifi";
+ const std::string kPortaledWifiPath = "/service/portaled_wifi";
services->AddService(kPortaledWifiPath,
- "Portaled Wifi",
+ "portaled_wifi_guid",
+ "Portaled Wifi" /* name */,
shill::kTypeWifi,
shill::kStatePortal,
- add_to_visible, add_to_watchlist);
+ add_to_visible);
services->SetServiceProperty(kPortaledWifiPath,
shill::kSecurityProperty,
base::StringValue(shill::kSecurityNone));
devices->AddDevice(
"/device/wimax1", shill::kTypeWimax, "stub_wimax_device1");
- services->AddService("wimax1",
- "wimax1",
+ services->AddService("/service/wimax1",
+ "wimax1_guid",
+ "wimax1" /* name */,
shill::kTypeWimax,
state,
- add_to_visible, add_to_watchlist);
+ add_to_visible);
+ services->SetServiceProperty("/service/wimax1",
+ shill::kConnectableProperty,
+ base::FundamentalValue(true));
+ base::FundamentalValue strength_value(80);
+ services->SetServiceProperty(
+ "/service/wimax1", shill::kSignalStrengthProperty, strength_value);
+ base::StringValue identity_value("test.identity");
services->SetServiceProperty(
- "wimax1", shill::kConnectableProperty, base::FundamentalValue(true));
+ "/service/wimax1", shill::kEapIdentityProperty, identity_value);
}
// Cellular
shill::kCarrierProperty,
base::StringValue(shill::kCarrierSprint));
- services->AddService("cellular1",
- "cellular1",
+ services->AddService(kCellularServicePath,
+ "cellular1_guid",
+ "cellular1" /* name */,
shill::kTypeCellular,
state,
- add_to_visible, add_to_watchlist);
+ add_to_visible);
base::StringValue technology_value(shill::kNetworkTechnologyGsm);
- services->SetServiceProperty(
- "cellular1", shill::kNetworkTechnologyProperty, technology_value);
+ services->SetServiceProperty(kCellularServicePath,
+ shill::kNetworkTechnologyProperty,
+ technology_value);
if (activated) {
services->SetServiceProperty(
- "cellular1",
+ kCellularServicePath,
shill::kActivationStateProperty,
base::StringValue(shill::kActivationStateActivated));
- services->SetServiceProperty("cellular1",
+ services->SetServiceProperty(kCellularServicePath,
shill::kConnectableProperty,
base::FundamentalValue(true));
} else {
services->SetServiceProperty(
- "cellular1",
+ kCellularServicePath,
shill::kActivationStateProperty,
base::StringValue(shill::kActivationStateNotActivated));
}
- services->SetServiceProperty("cellular1",
+ services->SetServiceProperty(kCellularServicePath,
shill::kRoamingStateProperty,
base::StringValue(shill::kRoamingStateHome));
}
shill::kProviderOpenVpn);
provider_properties.SetString(shill::kHostProperty, "vpn_host");
- services->AddService("vpn1",
- "vpn1",
+ services->AddService("/service/vpn1",
+ "vpn1_guid",
+ "vpn1" /* name */,
shill::kTypeVPN,
state,
- add_to_visible, add_to_watchlist);
+ add_to_visible);
services->SetServiceProperty(
- "vpn1", shill::kProviderProperty, provider_properties);
- profiles->AddService(shared_profile, "vpn1");
+ "/service/vpn1", shill::kProviderProperty, provider_properties);
+ profiles->AddService(shared_profile, "/service/vpn1");
- services->AddService("vpn2",
- "vpn2",
+ services->AddService("/service/vpn2",
+ "vpn2_guid",
+ "vpn2" /* name */,
shill::kTypeVPN,
shill::kStateIdle,
- add_to_visible, add_to_watchlist);
+ add_to_visible);
services->SetServiceProperty(
- "vpn2", shill::kProviderProperty, provider_properties);
+ "/service/vpn2", shill::kProviderProperty, provider_properties);
}
- SortManagerServices();
+ // Additional device states
+ for (DevicePropertyMap::iterator iter1 = shill_device_property_map_.begin();
+ iter1 != shill_device_property_map_.end(); ++iter1) {
+ std::string device_type = iter1->first;
+ std::string device_path = devices->GetDevicePathForType(device_type);
+ for (ShillPropertyMap::iterator iter2 = iter1->second.begin();
+ iter2 != iter1->second.end(); ++iter2) {
+ devices->SetDeviceProperty(device_path, iter2->first, *(iter2->second));
+ delete iter2->second;
+ }
+ }
+
+ SortManagerServices(true);
}
// Private methods
-void FakeShillManagerClient::AddServiceToWatchList(
- const std::string& service_path) {
- // Remove and insert the service, moving it to the front of the watch list.
- GetListProperty(shill::kServiceWatchListProperty)->Remove(
- base::StringValue(service_path), NULL);
- GetListProperty(shill::kServiceWatchListProperty)->Insert(
- 0, base::Value::CreateStringValue(service_path));
- CallNotifyObserversPropertyChanged(
- shill::kServiceWatchListProperty);
-}
-
void FakeShillManagerClient::PassStubProperties(
const DictionaryValueCallback& callback) const {
scoped_ptr<base::DictionaryValue> stub_properties(
stub_properties_.DeepCopy());
- // Remove disabled services from the list.
- stub_properties->SetWithoutPathExpansion(
- shill::kServicesProperty,
- GetEnabledServiceList(shill::kServicesProperty));
stub_properties->SetWithoutPathExpansion(
- shill::kServiceWatchListProperty,
- GetEnabledServiceList(shill::kServiceWatchListProperty));
+ shill::kServiceCompleteListProperty,
+ GetEnabledServiceList(shill::kServiceCompleteListProperty));
callback.Run(DBUS_METHOD_CALL_SUCCESS, *stub_properties);
}
void FakeShillManagerClient::NotifyObserversPropertyChanged(
const std::string& property) {
- if (property == shill::kServicesProperty ||
- property == shill::kServiceWatchListProperty) {
+ DVLOG(1) << "NotifyObserversPropertyChanged: " << property;
+ base::Value* value = NULL;
+ if (!stub_properties_.GetWithoutPathExpansion(property, &value)) {
+ LOG(ERROR) << "Notify for unknown property: " << property;
+ return;
+ }
+ if (property == shill::kServiceCompleteListProperty) {
scoped_ptr<base::ListValue> services(GetEnabledServiceList(property));
FOR_EACH_OBSERVER(ShillPropertyChangedObserver,
observer_list_,
OnPropertyChanged(property, *(services.get())));
return;
}
- if (property == shill::kDevicesProperty) {
- base::ListValue* devices = NULL;
- if (stub_properties_.GetListWithoutPathExpansion(
- shill::kDevicesProperty, &devices)) {
- FOR_EACH_OBSERVER(ShillPropertyChangedObserver,
- observer_list_,
- OnPropertyChanged(property, *devices));
- }
- return;
- }
- base::Value* value = NULL;
- if (!stub_properties_.GetWithoutPathExpansion(property, &value)) {
- LOG(ERROR) << "Notify for unknown property: " << property;
- return;
- }
FOR_EACH_OBSERVER(ShillPropertyChangedObserver,
observer_list_,
OnPropertyChanged(property, *value));
bool FakeShillManagerClient::TechnologyEnabled(const std::string& type) const {
if (type == shill::kTypeVPN)
return true; // VPN is always "enabled" since there is no associated device
+ if (type == shill::kTypeEthernetEap)
+ return true;
bool enabled = false;
const base::ListValue* technologies;
if (stub_properties_.GetListWithoutPathExpansion(
CallNotifyObserversPropertyChanged(
shill::kEnabledTechnologiesProperty);
base::MessageLoop::current()->PostTask(FROM_HERE, callback);
- // May affect available services
- CallNotifyObserversPropertyChanged(shill::kServicesProperty);
- CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty);
+ // May affect available services.
+ SortManagerServices(true);
}
base::ListValue* FakeShillManagerClient::GetEnabledServiceList(
LOG(ERROR) << "Properties not found for service: " << service_path;
continue;
}
- std::string name;
- properties->GetString(shill::kNameProperty, &name);
std::string type;
properties->GetString(shill::kTypeProperty, &type);
if (TechnologyEnabled(type))
shill::kScanningProperty,
base::FundamentalValue(false));
}
- CallNotifyObserversPropertyChanged(shill::kServicesProperty);
- CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty);
+ DVLOG(2) << "ScanCompleted";
+ CallNotifyObserversPropertyChanged(shill::kServiceCompleteListProperty);
base::MessageLoop::current()->PostTask(FROM_HERE, callback);
}
void FakeShillManagerClient::ParseCommandLineSwitch() {
- CommandLine* command_line = CommandLine::ForCurrentProcess();
- if (command_line->HasSwitch(switches::kShillStub)) {
- std::string option_str =
- command_line->GetSwitchValueASCII(switches::kShillStub);
- base::StringPairs string_pairs;
- base::SplitStringIntoKeyValuePairs(option_str, '=', ',', &string_pairs);
- for (base::StringPairs::iterator iter = string_pairs.begin();
- iter != string_pairs.end(); ++iter) {
- ParseOption((*iter).first, (*iter).second);
- }
- return;
- }
// Default setup
SetInitialNetworkState(shill::kTypeEthernet, shill::kStateOnline);
SetInitialNetworkState(shill::kTypeWifi, shill::kStateOnline);
SetInitialNetworkState(shill::kTypeCellular, shill::kStateIdle);
SetInitialNetworkState(shill::kTypeVPN, shill::kStateIdle);
+
+ // Parse additional options
+ CommandLine* command_line = CommandLine::ForCurrentProcess();
+ if (!command_line->HasSwitch(switches::kShillStub))
+ return;
+
+ std::string option_str =
+ command_line->GetSwitchValueASCII(switches::kShillStub);
+ VLOG(1) << "Parsing command line:" << option_str;
+ base::StringPairs string_pairs;
+ base::SplitStringIntoKeyValuePairs(option_str, '=', ',', &string_pairs);
+ for (base::StringPairs::iterator iter = string_pairs.begin();
+ iter != string_pairs.end(); ++iter) {
+ ParseOption((*iter).first, (*iter).second);
+ }
}
bool FakeShillManagerClient::ParseOption(const std::string& arg0,
const std::string& arg1) {
- if (arg0 == "interactive") {
+ VLOG(1) << "Parsing command line option: '" << arg0 << "=" << arg1 << "'";
+ if ((arg0 == "clear" || arg0 == "reset") && arg1 == "1") {
+ shill_initial_state_map_.clear();
+ return true;
+ } else if (arg0 == "interactive") {
int seconds = 3;
if (!arg1.empty())
base::StringToInt(arg1, &seconds);
interactive_delay_ = seconds;
return true;
+ } else if (arg0 == "sim_lock") {
+ bool locked = (arg1 == "1") ? true : false;
+ base::DictionaryValue* simlock_dict = new base::DictionaryValue;
+ simlock_dict->Set(shill::kSIMLockEnabledProperty,
+ new base::FundamentalValue(locked));
+ // TODO(stevenjb): Investigate why non-empty value breaks UI.
+ std::string lock_type = ""; // shill::kSIMLockPin
+ simlock_dict->SetString(shill::kSIMLockTypeProperty, lock_type);
+ simlock_dict->SetInteger(shill::kSIMLockRetriesLeftProperty, 5);
+
+ shill_device_property_map_
+ [shill::kTypeCellular][shill::kSIMLockStatusProperty] = simlock_dict;
+ shill_device_property_map_
+ [shill::kTypeCellular][shill::kTechnologyFamilyProperty] =
+ new base::StringValue(shill::kNetworkTechnologyGsm);
+ return true;
}
return SetInitialNetworkState(arg0, arg1);
}
bool FakeShillManagerClient::SetInitialNetworkState(std::string type_arg,
std::string state_arg) {
std::string state;
- state_arg = StringToLowerASCII(state_arg);
+ state_arg = base::StringToLowerASCII(state_arg);
if (state_arg.empty() || state_arg == "1" || state_arg == "on" ||
state_arg == "enabled" || state_arg == "connected" ||
state_arg == "online") {
return false;
}
- type_arg = StringToLowerASCII(type_arg);
+ type_arg = base::StringToLowerASCII(type_arg);
// Special cases
if (type_arg == "wireless") {
shill_initial_state_map_[shill::kTypeWifi] = state;