| 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" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 state == shill::kStateReady; | 98 state == shill::kStateReady; |
| 99 } | 99 } |
| 100 | 100 |
| 101 void UpdatePortaledWifiState(const std::string& service_path) { | 101 void UpdatePortaledWifiState(const std::string& service_path) { |
| 102 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface() | 102 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface() |
| 103 ->SetServiceProperty(service_path, | 103 ->SetServiceProperty(service_path, |
| 104 shill::kStateProperty, | 104 shill::kStateProperty, |
| 105 base::StringValue(shill::kStatePortal)); | 105 base::StringValue(shill::kStatePortal)); |
| 106 } | 106 } |
| 107 | 107 |
| 108 bool IsCellularTechnology(const std::string& type) { |
| 109 return (type == shill::kNetworkTechnology1Xrtt || |
| 110 type == shill::kNetworkTechnologyEvdo || |
| 111 type == shill::kNetworkTechnologyGsm || |
| 112 type == shill::kNetworkTechnologyGprs || |
| 113 type == shill::kNetworkTechnologyEdge || |
| 114 type == shill::kNetworkTechnologyUmts || |
| 115 type == shill::kNetworkTechnologyHspa || |
| 116 type == shill::kNetworkTechnologyHspaPlus || |
| 117 type == shill::kNetworkTechnologyLte || |
| 118 type == shill::kNetworkTechnologyLteAdvanced); |
| 119 } |
| 120 |
| 108 const char* kTechnologyUnavailable = "unavailable"; | 121 const char* kTechnologyUnavailable = "unavailable"; |
| 109 const char* kNetworkActivated = "activated"; | 122 const char* kNetworkActivated = "activated"; |
| 110 const char* kNetworkDisabled = "disabled"; | 123 const char* kNetworkDisabled = "disabled"; |
| 111 const char* kCellularServicePath = "/service/cellular1"; | 124 const char* kCellularServicePath = "/service/cellular1"; |
| 112 const char* kRoamingRequired = "required"; | 125 const char* kRoamingRequired = "required"; |
| 113 | 126 |
| 114 } // namespace | 127 } // namespace |
| 115 | 128 |
| 116 // static | 129 // static |
| 117 const char FakeShillManagerClient::kFakeEthernetNetworkGuid[] = "eth1_guid"; | 130 const char FakeShillManagerClient::kFakeEthernetNetworkGuid[] = "eth1_guid"; |
| 118 | 131 |
| 119 FakeShillManagerClient::FakeShillManagerClient() | 132 FakeShillManagerClient::FakeShillManagerClient() |
| 120 : interactive_delay_(0), | 133 : interactive_delay_(0), |
| 134 cellular_technology_(shill::kNetworkTechnologyGsm), |
| 121 weak_ptr_factory_(this) { | 135 weak_ptr_factory_(this) { |
| 122 ParseCommandLineSwitch(); | 136 ParseCommandLineSwitch(); |
| 123 } | 137 } |
| 124 | 138 |
| 125 FakeShillManagerClient::~FakeShillManagerClient() {} | 139 FakeShillManagerClient::~FakeShillManagerClient() {} |
| 126 | 140 |
| 127 // ShillManagerClient overrides. | 141 // ShillManagerClient overrides. |
| 128 | 142 |
| 129 void FakeShillManagerClient::Init(dbus::Bus* bus) {} | 143 void FakeShillManagerClient::Init(dbus::Bus* bus) {} |
| 130 | 144 |
| (...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 769 shill::kProviderRequiresRoamingProperty, | 783 shill::kProviderRequiresRoamingProperty, |
| 770 base::FundamentalValue(true)); | 784 base::FundamentalValue(true)); |
| 771 } | 785 } |
| 772 | 786 |
| 773 services->AddService(kCellularServicePath, | 787 services->AddService(kCellularServicePath, |
| 774 "cellular1_guid", | 788 "cellular1_guid", |
| 775 "cellular1" /* name */, | 789 "cellular1" /* name */, |
| 776 shill::kTypeCellular, | 790 shill::kTypeCellular, |
| 777 state, | 791 state, |
| 778 add_to_visible); | 792 add_to_visible); |
| 779 base::StringValue technology_value(shill::kNetworkTechnologyGsm); | 793 base::StringValue technology_value(cellular_technology_); |
| 780 devices->SetDeviceProperty("/device/cellular1", | 794 devices->SetDeviceProperty("/device/cellular1", |
| 781 shill::kTechnologyFamilyProperty, | 795 shill::kTechnologyFamilyProperty, |
| 782 technology_value); | 796 technology_value); |
| 783 services->SetServiceProperty(kCellularServicePath, | 797 services->SetServiceProperty(kCellularServicePath, |
| 784 shill::kNetworkTechnologyProperty, | 798 shill::kNetworkTechnologyProperty, |
| 785 technology_value); | 799 technology_value); |
| 786 | 800 |
| 787 if (activated) { | 801 if (activated) { |
| 788 services->SetServiceProperty( | 802 services->SetServiceProperty( |
| 789 kCellularServicePath, | 803 kCellularServicePath, |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1059 // "home", "roaming", or "required" | 1073 // "home", "roaming", or "required" |
| 1060 roaming_state_ = arg1; | 1074 roaming_state_ = arg1; |
| 1061 return true; | 1075 return true; |
| 1062 } | 1076 } |
| 1063 return SetInitialNetworkState(arg0, arg1); | 1077 return SetInitialNetworkState(arg0, arg1); |
| 1064 } | 1078 } |
| 1065 | 1079 |
| 1066 bool FakeShillManagerClient::SetInitialNetworkState(std::string type_arg, | 1080 bool FakeShillManagerClient::SetInitialNetworkState(std::string type_arg, |
| 1067 std::string state_arg) { | 1081 std::string state_arg) { |
| 1068 std::string state; | 1082 std::string state; |
| 1069 state_arg = base::StringToLowerASCII(state_arg); | |
| 1070 if (state_arg.empty() || state_arg == "1" || state_arg == "on" || | 1083 if (state_arg.empty() || state_arg == "1" || state_arg == "on" || |
| 1071 state_arg == "enabled" || state_arg == "connected" || | 1084 state_arg == "enabled" || state_arg == "connected" || |
| 1072 state_arg == "online") { | 1085 state_arg == "online") { |
| 1073 // Enabled and connected (default value) | 1086 // Enabled and connected (default value) |
| 1074 state = shill::kStateOnline; | 1087 state = shill::kStateOnline; |
| 1075 } else if (state_arg == "0" || state_arg == "off" || | 1088 } else if (state_arg == "0" || state_arg == "off" || |
| 1076 state_arg == "inactive" || state_arg == shill::kStateIdle) { | 1089 state_arg == "inactive" || state_arg == shill::kStateIdle) { |
| 1077 // Technology enabled, services are created but are not connected. | 1090 // Technology enabled, services are created but are not connected. |
| 1078 state = shill::kStateIdle; | 1091 state = shill::kStateIdle; |
| 1079 } else if (state_arg == "disabled" || state_arg == "disconnect") { | 1092 } else if (state_arg == "disabled" || state_arg == "disconnect") { |
| 1080 // Technology disabled but available, services created but not connected. | 1093 // Technology disabled but available, services created but not connected. |
| 1081 state = kNetworkDisabled; | 1094 state = kNetworkDisabled; |
| 1082 } else if (state_arg == "none" || state_arg == "offline") { | 1095 } else if (state_arg == "none" || state_arg == "offline") { |
| 1083 // Technology not available, do not create services. | 1096 // Technology not available, do not create services. |
| 1084 state = kTechnologyUnavailable; | 1097 state = kTechnologyUnavailable; |
| 1085 } else if (state_arg == "portal") { | 1098 } else if (state_arg == "portal") { |
| 1086 // Technology is enabled, a service is connected and in Portal state. | 1099 // Technology is enabled, a service is connected and in Portal state. |
| 1087 state = shill::kStatePortal; | 1100 state = shill::kStatePortal; |
| 1088 } else if (state_arg == "active" || state_arg == "activated") { | 1101 } else if (state_arg == "active" || state_arg == "activated") { |
| 1089 // Technology is enabled, a service is connected and Activated. | 1102 // Technology is enabled, a service is connected and Activated. |
| 1090 state = kNetworkActivated; | 1103 state = kNetworkActivated; |
| 1104 } else if (type_arg == shill::kTypeCellular && |
| 1105 IsCellularTechnology(state_arg)) { |
| 1106 state = shill::kStateOnline; |
| 1107 cellular_technology_ = state_arg; |
| 1108 } else if (type_arg == shill::kTypeCellular && state_arg == "LTEAdvanced") { |
| 1109 // Special case, Shill name contains a ' '. |
| 1110 state = shill::kStateOnline; |
| 1111 cellular_technology_ = shill::kNetworkTechnologyLteAdvanced; |
| 1091 } else { | 1112 } else { |
| 1092 LOG(ERROR) << "Unrecognized initial state: " << state_arg; | 1113 LOG(ERROR) << "Unrecognized initial state: " << type_arg << "=" |
| 1114 << state_arg; |
| 1093 return false; | 1115 return false; |
| 1094 } | 1116 } |
| 1095 | 1117 |
| 1096 type_arg = base::StringToLowerASCII(type_arg); | |
| 1097 // Special cases | 1118 // Special cases |
| 1098 if (type_arg == "wireless") { | 1119 if (type_arg == "wireless") { |
| 1099 shill_initial_state_map_[shill::kTypeWifi] = state; | 1120 shill_initial_state_map_[shill::kTypeWifi] = state; |
| 1100 shill_initial_state_map_[shill::kTypeCellular] = state; | 1121 shill_initial_state_map_[shill::kTypeCellular] = state; |
| 1101 return true; | 1122 return true; |
| 1102 } | 1123 } |
| 1103 // Convenience synonyms. | 1124 // Convenience synonyms. |
| 1104 if (type_arg == "eth") | 1125 if (type_arg == "eth") |
| 1105 type_arg = shill::kTypeEthernet; | 1126 type_arg = shill::kTypeEthernet; |
| 1106 | 1127 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1140 *enabled = true; | 1161 *enabled = true; |
| 1141 if ((state == shill::kStatePortal && type != shill::kTypeWifi) || | 1162 if ((state == shill::kStatePortal && type != shill::kTypeWifi) || |
| 1142 (state == kNetworkActivated && type != shill::kTypeCellular)) { | 1163 (state == kNetworkActivated && type != shill::kTypeCellular)) { |
| 1143 LOG(WARNING) << "Invalid state: " << state << " for " << type; | 1164 LOG(WARNING) << "Invalid state: " << state << " for " << type; |
| 1144 return shill::kStateIdle; | 1165 return shill::kStateIdle; |
| 1145 } | 1166 } |
| 1146 return state; | 1167 return state; |
| 1147 } | 1168 } |
| 1148 | 1169 |
| 1149 } // namespace chromeos | 1170 } // namespace chromeos |
| OLD | NEW |