OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chromeos/dbus/fake_shill_manager_client.h" | 5 #include "chromeos/dbus/fake_shill_manager_client.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
11 #include "base/strings/string_split.h" | 11 #include "base/strings/string_split.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "base/strings/stringprintf.h" |
13 #include "base/values.h" | 14 #include "base/values.h" |
14 #include "chromeos/chromeos_switches.h" | 15 #include "chromeos/chromeos_switches.h" |
15 #include "chromeos/dbus/dbus_thread_manager.h" | 16 #include "chromeos/dbus/dbus_thread_manager.h" |
16 #include "chromeos/dbus/shill_device_client.h" | 17 #include "chromeos/dbus/shill_device_client.h" |
17 #include "chromeos/dbus/shill_ipconfig_client.h" | 18 #include "chromeos/dbus/shill_ipconfig_client.h" |
18 #include "chromeos/dbus/shill_profile_client.h" | 19 #include "chromeos/dbus/shill_profile_client.h" |
19 #include "chromeos/dbus/shill_property_changed_observer.h" | 20 #include "chromeos/dbus/shill_property_changed_observer.h" |
20 #include "chromeos/dbus/shill_service_client.h" | 21 #include "chromeos/dbus/shill_service_client.h" |
21 #include "dbus/bus.h" | 22 #include "dbus/bus.h" |
22 #include "dbus/message.h" | 23 #include "dbus/message.h" |
23 #include "dbus/object_path.h" | 24 #include "dbus/object_path.h" |
24 #include "dbus/values_util.h" | 25 #include "dbus/values_util.h" |
25 #include "third_party/cros_system_api/dbus/service_constants.h" | 26 #include "third_party/cros_system_api/dbus/service_constants.h" |
26 | 27 |
27 namespace chromeos { | 28 namespace chromeos { |
28 | 29 |
29 namespace { | 30 namespace { |
30 | 31 |
31 // Allow parsed command line option 'tdls_busy' to set the fake busy count. | 32 // Allow parsed command line option 'tdls_busy' to set the fake busy count. |
32 int s_tdls_busy_count = 0; | 33 int s_tdls_busy_count = 0; |
| 34 int s_extra_wifi_networks = 0; |
33 | 35 |
34 // Used to compare values for finding entries to erase in a ListValue. | 36 // Used to compare values for finding entries to erase in a ListValue. |
35 // (ListValue only implements a const_iterator version of Find). | 37 // (ListValue only implements a const_iterator version of Find). |
36 struct ValueEquals { | 38 struct ValueEquals { |
37 explicit ValueEquals(const base::Value* first) : first_(first) {} | 39 explicit ValueEquals(const base::Value* first) : first_(first) {} |
38 bool operator()(const base::Value* second) const { | 40 bool operator()(const base::Value* second) const { |
39 return first_->Equals(second); | 41 return first_->Equals(second); |
40 } | 42 } |
41 const base::Value* first_; | 43 const base::Value* first_; |
42 }; | 44 }; |
(...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
728 shill::kSecurityClassProperty, | 730 shill::kSecurityClassProperty, |
729 base::StringValue(shill::kSecurityNone)); | 731 base::StringValue(shill::kSecurityNone)); |
730 services->SetConnectBehavior( | 732 services->SetConnectBehavior( |
731 kPortaledWifiPath, | 733 kPortaledWifiPath, |
732 base::Bind(&UpdatePortaledWifiState, kPortaledWifiPath)); | 734 base::Bind(&UpdatePortaledWifiState, kPortaledWifiPath)); |
733 services->SetServiceProperty(kPortaledWifiPath, | 735 services->SetServiceProperty(kPortaledWifiPath, |
734 shill::kConnectableProperty, | 736 shill::kConnectableProperty, |
735 base::FundamentalValue(true)); | 737 base::FundamentalValue(true)); |
736 profiles->AddService(shared_profile, kPortaledWifiPath); | 738 profiles->AddService(shared_profile, kPortaledWifiPath); |
737 } | 739 } |
| 740 |
| 741 for (int i = 0; i < s_extra_wifi_networks; ++i) { |
| 742 int id = 4 + i; |
| 743 std::string path = base::StringPrintf("/service/wifi%d", id); |
| 744 std::string guid = base::StringPrintf("wifi%d_guid", id); |
| 745 std::string name = base::StringPrintf("wifi%d", id); |
| 746 services->AddService(path, guid, name, shill::kTypeWifi, |
| 747 shill::kStateIdle, add_to_visible); |
| 748 } |
738 } | 749 } |
739 | 750 |
740 // Wimax | 751 // Wimax |
741 const std::string kWimaxPath = "/service/wimax1"; | 752 const std::string kWimaxPath = "/service/wimax1"; |
742 state = GetInitialStateForType(shill::kTypeWimax, &enabled); | 753 state = GetInitialStateForType(shill::kTypeWimax, &enabled); |
743 if (state != kTechnologyUnavailable) { | 754 if (state != kTechnologyUnavailable) { |
744 AddTechnology(shill::kTypeWimax, enabled); | 755 AddTechnology(shill::kTypeWimax, enabled); |
745 devices->AddDevice( | 756 devices->AddDevice( |
746 "/device/wimax1", shill::kTypeWimax, "stub_wimax_device1"); | 757 "/device/wimax1", shill::kTypeWimax, "stub_wimax_device1"); |
747 | 758 |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1071 } else if (arg0 == "roaming") { | 1082 } else if (arg0 == "roaming") { |
1072 // "home", "roaming", or "required" | 1083 // "home", "roaming", or "required" |
1073 roaming_state_ = arg1; | 1084 roaming_state_ = arg1; |
1074 return true; | 1085 return true; |
1075 } | 1086 } |
1076 return SetInitialNetworkState(arg0, arg1); | 1087 return SetInitialNetworkState(arg0, arg1); |
1077 } | 1088 } |
1078 | 1089 |
1079 bool FakeShillManagerClient::SetInitialNetworkState(std::string type_arg, | 1090 bool FakeShillManagerClient::SetInitialNetworkState(std::string type_arg, |
1080 std::string state_arg) { | 1091 std::string state_arg) { |
| 1092 int state_arg_as_int = -1; |
| 1093 base::StringToInt(state_arg, &state_arg_as_int); |
| 1094 |
1081 std::string state; | 1095 std::string state; |
1082 if (state_arg.empty() || state_arg == "1" || state_arg == "on" || | 1096 if (state_arg.empty() || state_arg == "1" || state_arg == "on" || |
1083 state_arg == "enabled" || state_arg == "connected" || | 1097 state_arg == "enabled" || state_arg == "connected" || |
1084 state_arg == "online") { | 1098 state_arg == "online") { |
1085 // Enabled and connected (default value) | 1099 // Enabled and connected (default value) |
1086 state = shill::kStateOnline; | 1100 state = shill::kStateOnline; |
1087 } else if (state_arg == "0" || state_arg == "off" || | 1101 } else if (state_arg == "0" || state_arg == "off" || |
1088 state_arg == "inactive" || state_arg == shill::kStateIdle) { | 1102 state_arg == "inactive" || state_arg == shill::kStateIdle) { |
1089 // Technology enabled, services are created but are not connected. | 1103 // Technology enabled, services are created but are not connected. |
1090 state = shill::kStateIdle; | 1104 state = shill::kStateIdle; |
| 1105 } else if (type_arg == shill::kTypeWifi && state_arg_as_int > 1) { |
| 1106 // Enabled and connected, add extra wifi networks. |
| 1107 state = shill::kStateOnline; |
| 1108 s_extra_wifi_networks = state_arg_as_int - 1; |
1091 } else if (state_arg == "disabled" || state_arg == "disconnect") { | 1109 } else if (state_arg == "disabled" || state_arg == "disconnect") { |
1092 // Technology disabled but available, services created but not connected. | 1110 // Technology disabled but available, services created but not connected. |
1093 state = kNetworkDisabled; | 1111 state = kNetworkDisabled; |
1094 } else if (state_arg == "none" || state_arg == "offline") { | 1112 } else if (state_arg == "none" || state_arg == "offline") { |
1095 // Technology not available, do not create services. | 1113 // Technology not available, do not create services. |
1096 state = kTechnologyUnavailable; | 1114 state = kTechnologyUnavailable; |
1097 } else if (state_arg == "portal") { | 1115 } else if (state_arg == "portal") { |
1098 // Technology is enabled, a service is connected and in Portal state. | 1116 // Technology is enabled, a service is connected and in Portal state. |
1099 state = shill::kStatePortal; | 1117 state = shill::kStatePortal; |
1100 } else if (state_arg == "active" || state_arg == "activated") { | 1118 } else if (state_arg == "active" || state_arg == "activated") { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1160 *enabled = true; | 1178 *enabled = true; |
1161 if ((state == shill::kStatePortal && type != shill::kTypeWifi) || | 1179 if ((state == shill::kStatePortal && type != shill::kTypeWifi) || |
1162 (state == kNetworkActivated && type != shill::kTypeCellular)) { | 1180 (state == kNetworkActivated && type != shill::kTypeCellular)) { |
1163 LOG(WARNING) << "Invalid state: " << state << " for " << type; | 1181 LOG(WARNING) << "Invalid state: " << state << " for " << type; |
1164 return shill::kStateIdle; | 1182 return shill::kStateIdle; |
1165 } | 1183 } |
1166 return state; | 1184 return state; |
1167 } | 1185 } |
1168 | 1186 |
1169 } // namespace chromeos | 1187 } // namespace chromeos |
OLD | NEW |