| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chromeos/dbus/shill_stub_helper.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/command_line.h" | |
| 9 #include "base/strings/string_tokenizer.h" | |
| 10 #include "chromeos/chromeos_switches.h" | |
| 11 #include "chromeos/dbus/dbus_thread_manager.h" | |
| 12 #include "chromeos/dbus/shill_device_client.h" | |
| 13 #include "chromeos/dbus/shill_manager_client.h" | |
| 14 #include "chromeos/dbus/shill_profile_client.h" | |
| 15 #include "chromeos/dbus/shill_service_client.h" | |
| 16 #include "third_party/cros_system_api/dbus/service_constants.h" | |
| 17 | |
| 18 namespace chromeos { | |
| 19 namespace shill_stub_helper { | |
| 20 | |
| 21 namespace { | |
| 22 | |
| 23 void UpdatePortalledWifiState(const std::string& service_path) { | |
| 24 ShillServiceClient::TestInterface* services = | |
| 25 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); | |
| 26 | |
| 27 services->SetServiceProperty(service_path, | |
| 28 shill::kStateProperty, | |
| 29 base::StringValue(shill::kStatePortal)); | |
| 30 } | |
| 31 | |
| 32 // Returns true if |network_type| is found in the comma separated list given | |
| 33 // with kEnabledStubNetworkTypes switch. | |
| 34 bool IsStubNetworkTypeEnabled(const std::string& network_type) { | |
| 35 CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
| 36 // If the switch is not present, enabled by default. | |
| 37 if (!command_line->HasSwitch(switches::kEnabledStubNetworkTypes)) | |
| 38 return true; | |
| 39 | |
| 40 const std::string value = | |
| 41 command_line->GetSwitchValueASCII(switches::kEnabledStubNetworkTypes); | |
| 42 base::StringTokenizer tokenizer(value, ","); | |
| 43 while (tokenizer.GetNext()) { | |
| 44 if (tokenizer.token() == network_type) | |
| 45 return true; | |
| 46 } | |
| 47 return false; | |
| 48 } | |
| 49 | |
| 50 } // namespace | |
| 51 | |
| 52 void SetupDefaultEnvironment() { | |
| 53 ShillServiceClient::TestInterface* services = | |
| 54 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); | |
| 55 ShillProfileClient::TestInterface* profiles = | |
| 56 DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface(); | |
| 57 ShillManagerClient::TestInterface* manager = | |
| 58 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface(); | |
| 59 ShillDeviceClient::TestInterface* devices = | |
| 60 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface(); | |
| 61 if (!services || !profiles || !manager | !devices) | |
| 62 return; | |
| 63 | |
| 64 // Stub Technologies. | |
| 65 manager->AddTechnology(shill::kTypeEthernet, true); | |
| 66 manager->AddTechnology(shill::kTypeWifi, true); | |
| 67 manager->AddTechnology(shill::kTypeCellular, true); | |
| 68 manager->AddTechnology(shill::kTypeWimax, true); | |
| 69 | |
| 70 std::string shared_profile = ShillProfileClient::GetSharedProfilePath(); | |
| 71 profiles->AddProfile(shared_profile, std::string()); | |
| 72 | |
| 73 devices->AddDevice("/device/eth1", shill::kTypeEthernet, "stub_eth_device1"); | |
| 74 devices->AddDevice("/device/wifi1", shill::kTypeWifi, "stub_wifi_device1"); | |
| 75 | |
| 76 devices->AddDevice( | |
| 77 "/device/cellular1", shill::kTypeCellular, "stub_cellular_device1"); | |
| 78 devices->SetDeviceProperty("/device/cellular1", | |
| 79 shill::kCarrierProperty, | |
| 80 base::StringValue(shill::kCarrierSprint)); | |
| 81 | |
| 82 devices->AddDevice("/device/wimax1", shill::kTypeWimax, "stub_wimax_device1"); | |
| 83 | |
| 84 const bool add_to_visible = true; | |
| 85 const bool add_to_watchlist = true; | |
| 86 | |
| 87 // On real devices, service is not added for ethernet if cable is disconneted. | |
| 88 if (IsStubNetworkTypeEnabled(shill::kTypeEthernet)) { | |
| 89 services->AddService("eth1", "eth1", | |
| 90 shill::kTypeEthernet, | |
| 91 shill::kStateOnline, | |
| 92 add_to_visible, add_to_watchlist); | |
| 93 profiles->AddService(shared_profile, "eth1"); | |
| 94 } | |
| 95 | |
| 96 // Wifi | |
| 97 | |
| 98 services->AddService("wifi1", | |
| 99 "wifi1", | |
| 100 shill::kTypeWifi, | |
| 101 IsStubNetworkTypeEnabled(shill::kTypeWifi) ? | |
| 102 shill::kStateOnline : shill::kStateIdle, | |
| 103 add_to_visible, add_to_watchlist); | |
| 104 services->SetServiceProperty("wifi1", | |
| 105 shill::kSecurityProperty, | |
| 106 base::StringValue(shill::kSecurityWep)); | |
| 107 profiles->AddService(shared_profile, "wifi1"); | |
| 108 | |
| 109 services->AddService("wifi2", | |
| 110 "wifi2_PSK", | |
| 111 shill::kTypeWifi, | |
| 112 shill::kStateIdle, | |
| 113 add_to_visible, add_to_watchlist); | |
| 114 services->SetServiceProperty("wifi2", | |
| 115 shill::kSecurityProperty, | |
| 116 base::StringValue(shill::kSecurityPsk)); | |
| 117 base::FundamentalValue strength_value(80); | |
| 118 services->SetServiceProperty( | |
| 119 "wifi2", shill::kSignalStrengthProperty, strength_value); | |
| 120 profiles->AddService(shared_profile, "wifi2"); | |
| 121 | |
| 122 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
| 123 chromeos::switches::kEnableStubPortalledWifi)) { | |
| 124 const std::string kPortalledWifiPath = "portalled_wifi"; | |
| 125 services->AddService(kPortalledWifiPath, | |
| 126 "Portalled Wifi", | |
| 127 shill::kTypeWifi, | |
| 128 shill::kStatePortal, | |
| 129 add_to_visible, add_to_watchlist); | |
| 130 services->SetServiceProperty(kPortalledWifiPath, | |
| 131 shill::kSecurityProperty, | |
| 132 base::StringValue(shill::kSecurityNone)); | |
| 133 services->SetConnectBehavior(kPortalledWifiPath, | |
| 134 base::Bind(&UpdatePortalledWifiState, | |
| 135 kPortalledWifiPath)); | |
| 136 services->SetServiceProperty(kPortalledWifiPath, | |
| 137 shill::kConnectableProperty, | |
| 138 base::FundamentalValue(true)); | |
| 139 profiles->AddService(shared_profile, kPortalledWifiPath); | |
| 140 } | |
| 141 | |
| 142 // Wimax | |
| 143 | |
| 144 services->AddService("wimax1", | |
| 145 "wimax1", | |
| 146 shill::kTypeWimax, | |
| 147 shill::kStateIdle, | |
| 148 add_to_visible, add_to_watchlist); | |
| 149 services->SetServiceProperty( | |
| 150 "wimax1", shill::kConnectableProperty, base::FundamentalValue(true)); | |
| 151 | |
| 152 // Cellular | |
| 153 | |
| 154 services->AddService("cellular1", | |
| 155 "cellular1", | |
| 156 shill::kTypeCellular, | |
| 157 shill::kStateIdle, | |
| 158 add_to_visible, add_to_watchlist); | |
| 159 base::StringValue technology_value(shill::kNetworkTechnologyGsm); | |
| 160 services->SetServiceProperty( | |
| 161 "cellular1", shill::kNetworkTechnologyProperty, technology_value); | |
| 162 services->SetServiceProperty( | |
| 163 "cellular1", | |
| 164 shill::kActivationStateProperty, | |
| 165 base::StringValue(shill::kActivationStateNotActivated)); | |
| 166 services->SetServiceProperty("cellular1", | |
| 167 shill::kRoamingStateProperty, | |
| 168 base::StringValue(shill::kRoamingStateHome)); | |
| 169 | |
| 170 // VPN | |
| 171 | |
| 172 // Set the "Provider" dictionary properties. Note: when setting these in | |
| 173 // Shill, "Provider.Type", etc keys are used, but when reading the values | |
| 174 // "Provider" . "Type", etc keys are used. Here we are setting the values | |
| 175 // that will be read (by the UI, tests, etc). | |
| 176 base::DictionaryValue provider_properties; | |
| 177 provider_properties.SetString(shill::kTypeProperty, shill::kProviderOpenVpn); | |
| 178 provider_properties.SetString(shill::kHostProperty, "vpn_host"); | |
| 179 | |
| 180 services->AddService("vpn1", | |
| 181 "vpn1", | |
| 182 shill::kTypeVPN, | |
| 183 IsStubNetworkTypeEnabled(shill::kTypeVPN) ? | |
| 184 shill::kStateOnline : shill::kStateIdle, | |
| 185 add_to_visible, add_to_watchlist); | |
| 186 services->SetServiceProperty( | |
| 187 "vpn1", shill::kProviderProperty, provider_properties); | |
| 188 profiles->AddService(shared_profile, "vpn1"); | |
| 189 | |
| 190 services->AddService("vpn2", | |
| 191 "vpn2", | |
| 192 shill::kTypeVPN, | |
| 193 shill::kStateIdle, | |
| 194 add_to_visible, add_to_watchlist); | |
| 195 services->SetServiceProperty( | |
| 196 "vpn2", shill::kProviderProperty, provider_properties); | |
| 197 | |
| 198 manager->SortManagerServices(); | |
| 199 } | |
| 200 | |
| 201 } // namespace shill_stub_helper | |
| 202 } // namespace chromeos | |
| OLD | NEW |