| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 const ErrorCallback& error_callback) { | 194 const ErrorCallback& error_callback) { |
| 195 VLOG(1) << "RequestScan: " << type; | 195 VLOG(1) << "RequestScan: " << type; |
| 196 // For Stub purposes, default to a Wifi scan. | 196 // For Stub purposes, default to a Wifi scan. |
| 197 std::string device_type = shill::kTypeWifi; | 197 std::string device_type = shill::kTypeWifi; |
| 198 if (!type.empty()) | 198 if (!type.empty()) |
| 199 device_type = type; | 199 device_type = type; |
| 200 ShillDeviceClient::TestInterface* device_client = | 200 ShillDeviceClient::TestInterface* device_client = |
| 201 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface(); | 201 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface(); |
| 202 std::string device_path = device_client->GetDevicePathForType(device_type); | 202 std::string device_path = device_client->GetDevicePathForType(device_type); |
| 203 if (!device_path.empty()) { | 203 if (!device_path.empty()) { |
| 204 device_client->SetDeviceProperty( | 204 device_client->SetDeviceProperty(device_path, shill::kScanningProperty, |
| 205 device_path, shill::kScanningProperty, base::FundamentalValue(true)); | 205 base::Value(true)); |
| 206 } | 206 } |
| 207 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 207 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 208 FROM_HERE, | 208 FROM_HERE, |
| 209 base::Bind(&FakeShillManagerClient::ScanCompleted, | 209 base::Bind(&FakeShillManagerClient::ScanCompleted, |
| 210 weak_ptr_factory_.GetWeakPtr(), device_path, callback), | 210 weak_ptr_factory_.GetWeakPtr(), device_path, callback), |
| 211 base::TimeDelta::FromSeconds(interactive_delay_)); | 211 base::TimeDelta::FromSeconds(interactive_delay_)); |
| 212 } | 212 } |
| 213 | 213 |
| 214 void FakeShillManagerClient::EnableTechnology( | 214 void FakeShillManagerClient::EnableTechnology( |
| 215 const std::string& type, | 215 const std::string& type, |
| (...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 696 const std::string kWifi1Path = "/service/wifi1"; | 696 const std::string kWifi1Path = "/service/wifi1"; |
| 697 services->AddService(kWifi1Path, | 697 services->AddService(kWifi1Path, |
| 698 "wifi1_guid", | 698 "wifi1_guid", |
| 699 "wifi1" /* name */, | 699 "wifi1" /* name */, |
| 700 shill::kTypeWifi, | 700 shill::kTypeWifi, |
| 701 state, | 701 state, |
| 702 add_to_visible); | 702 add_to_visible); |
| 703 services->SetServiceProperty(kWifi1Path, | 703 services->SetServiceProperty(kWifi1Path, |
| 704 shill::kSecurityClassProperty, | 704 shill::kSecurityClassProperty, |
| 705 base::StringValue(shill::kSecurityWep)); | 705 base::StringValue(shill::kSecurityWep)); |
| 706 services->SetServiceProperty(kWifi1Path, | 706 services->SetServiceProperty(kWifi1Path, shill::kConnectableProperty, |
| 707 shill::kConnectableProperty, | 707 base::Value(true)); |
| 708 base::FundamentalValue(true)); | |
| 709 profiles->AddService(shared_profile, kWifi1Path); | 708 profiles->AddService(shared_profile, kWifi1Path); |
| 710 | 709 |
| 711 const std::string kWifi2Path = "/service/wifi2"; | 710 const std::string kWifi2Path = "/service/wifi2"; |
| 712 services->AddService(kWifi2Path, "wifi2_guid", | 711 services->AddService(kWifi2Path, "wifi2_guid", |
| 713 s_dynamic_wep ? "wifi2_WEP" : "wifi2_PSK" /* name */, | 712 s_dynamic_wep ? "wifi2_WEP" : "wifi2_PSK" /* name */, |
| 714 shill::kTypeWifi, shill::kStateIdle, add_to_visible); | 713 shill::kTypeWifi, shill::kStateIdle, add_to_visible); |
| 715 if (s_dynamic_wep) { | 714 if (s_dynamic_wep) { |
| 716 services->SetServiceProperty(kWifi2Path, shill::kSecurityClassProperty, | 715 services->SetServiceProperty(kWifi2Path, shill::kSecurityClassProperty, |
| 717 base::StringValue(shill::kSecurityWep)); | 716 base::StringValue(shill::kSecurityWep)); |
| 718 services->SetServiceProperty( | 717 services->SetServiceProperty( |
| 719 kWifi2Path, shill::kEapKeyMgmtProperty, | 718 kWifi2Path, shill::kEapKeyMgmtProperty, |
| 720 base::StringValue(shill::kKeyManagementIEEE8021X)); | 719 base::StringValue(shill::kKeyManagementIEEE8021X)); |
| 721 services->SetServiceProperty(kWifi2Path, shill::kEapMethodProperty, | 720 services->SetServiceProperty(kWifi2Path, shill::kEapMethodProperty, |
| 722 base::StringValue(shill::kEapMethodPEAP)); | 721 base::StringValue(shill::kEapMethodPEAP)); |
| 723 services->SetServiceProperty(kWifi2Path, shill::kEapIdentityProperty, | 722 services->SetServiceProperty(kWifi2Path, shill::kEapIdentityProperty, |
| 724 base::StringValue("John Doe")); | 723 base::StringValue("John Doe")); |
| 725 } else { | 724 } else { |
| 726 services->SetServiceProperty(kWifi2Path, shill::kSecurityClassProperty, | 725 services->SetServiceProperty(kWifi2Path, shill::kSecurityClassProperty, |
| 727 base::StringValue(shill::kSecurityPsk)); | 726 base::StringValue(shill::kSecurityPsk)); |
| 728 } | 727 } |
| 729 services->SetServiceProperty( | 728 services->SetServiceProperty(kWifi2Path, shill::kSignalStrengthProperty, |
| 730 kWifi2Path, shill::kSignalStrengthProperty, base::FundamentalValue(80)); | 729 base::Value(80)); |
| 731 profiles->AddService(shared_profile, kWifi2Path); | 730 profiles->AddService(shared_profile, kWifi2Path); |
| 732 | 731 |
| 733 const std::string kWifi3Path = "/service/wifi3"; | 732 const std::string kWifi3Path = "/service/wifi3"; |
| 734 services->AddService(kWifi3Path, | 733 services->AddService(kWifi3Path, |
| 735 "", /* empty GUID */ | 734 "", /* empty GUID */ |
| 736 "wifi3" /* name */, | 735 "wifi3" /* name */, |
| 737 shill::kTypeWifi, | 736 shill::kTypeWifi, |
| 738 shill::kStateIdle, | 737 shill::kStateIdle, |
| 739 add_to_visible); | 738 add_to_visible); |
| 740 services->SetServiceProperty( | 739 services->SetServiceProperty(kWifi3Path, shill::kSignalStrengthProperty, |
| 741 kWifi3Path, shill::kSignalStrengthProperty, base::FundamentalValue(40)); | 740 base::Value(40)); |
| 742 | 741 |
| 743 if (portaled) { | 742 if (portaled) { |
| 744 const std::string kPortaledWifiPath = "/service/portaled_wifi"; | 743 const std::string kPortaledWifiPath = "/service/portaled_wifi"; |
| 745 services->AddService(kPortaledWifiPath, "portaled_wifi_guid", | 744 services->AddService(kPortaledWifiPath, "portaled_wifi_guid", |
| 746 "Portaled Wifi" /* name */, shill::kTypeWifi, | 745 "Portaled Wifi" /* name */, shill::kTypeWifi, |
| 747 shill::kStateIdle, add_to_visible); | 746 shill::kStateIdle, add_to_visible); |
| 748 services->SetServiceProperty(kPortaledWifiPath, | 747 services->SetServiceProperty(kPortaledWifiPath, |
| 749 shill::kSecurityClassProperty, | 748 shill::kSecurityClassProperty, |
| 750 base::StringValue(shill::kSecurityNone)); | 749 base::StringValue(shill::kSecurityNone)); |
| 751 services->SetConnectBehavior( | 750 services->SetConnectBehavior( |
| 752 kPortaledWifiPath, | 751 kPortaledWifiPath, |
| 753 base::Bind(&UpdatePortaledWifiState, kPortaledWifiPath)); | 752 base::Bind(&UpdatePortaledWifiState, kPortaledWifiPath)); |
| 754 services->SetServiceProperty(kPortaledWifiPath, | 753 services->SetServiceProperty( |
| 755 shill::kConnectableProperty, | 754 kPortaledWifiPath, shill::kConnectableProperty, base::Value(true)); |
| 756 base::FundamentalValue(true)); | |
| 757 profiles->AddService(shared_profile, kPortaledWifiPath); | 755 profiles->AddService(shared_profile, kPortaledWifiPath); |
| 758 } | 756 } |
| 759 | 757 |
| 760 for (int i = 0; i < s_extra_wifi_networks; ++i) { | 758 for (int i = 0; i < s_extra_wifi_networks; ++i) { |
| 761 int id = 4 + i; | 759 int id = 4 + i; |
| 762 std::string path = base::StringPrintf("/service/wifi%d", id); | 760 std::string path = base::StringPrintf("/service/wifi%d", id); |
| 763 std::string guid = base::StringPrintf("wifi%d_guid", id); | 761 std::string guid = base::StringPrintf("wifi%d_guid", id); |
| 764 std::string name = base::StringPrintf("wifi%d", id); | 762 std::string name = base::StringPrintf("wifi%d", id); |
| 765 services->AddService(path, guid, name, shill::kTypeWifi, | 763 services->AddService(path, guid, name, shill::kTypeWifi, |
| 766 shill::kStateIdle, add_to_visible); | 764 shill::kStateIdle, add_to_visible); |
| 767 } | 765 } |
| 768 } | 766 } |
| 769 | 767 |
| 770 // Wimax | 768 // Wimax |
| 771 const std::string kWimaxPath = "/service/wimax1"; | 769 const std::string kWimaxPath = "/service/wimax1"; |
| 772 state = GetInitialStateForType(shill::kTypeWimax, &enabled); | 770 state = GetInitialStateForType(shill::kTypeWimax, &enabled); |
| 773 if (state != kTechnologyUnavailable) { | 771 if (state != kTechnologyUnavailable) { |
| 774 AddTechnology(shill::kTypeWimax, enabled); | 772 AddTechnology(shill::kTypeWimax, enabled); |
| 775 devices->AddDevice( | 773 devices->AddDevice( |
| 776 "/device/wimax1", shill::kTypeWimax, "stub_wimax_device1"); | 774 "/device/wimax1", shill::kTypeWimax, "stub_wimax_device1"); |
| 777 | 775 |
| 778 services->AddService(kWimaxPath, "wimax1_guid", "wimax1" /* name */, | 776 services->AddService(kWimaxPath, "wimax1_guid", "wimax1" /* name */, |
| 779 shill::kTypeWimax, state, add_to_visible); | 777 shill::kTypeWimax, state, add_to_visible); |
| 780 services->SetServiceProperty(kWimaxPath, shill::kConnectableProperty, | 778 services->SetServiceProperty(kWimaxPath, shill::kConnectableProperty, |
| 781 base::FundamentalValue(true)); | 779 base::Value(true)); |
| 782 base::FundamentalValue strength_value(80); | 780 base::Value strength_value(80); |
| 783 services->SetServiceProperty(kWimaxPath, shill::kSignalStrengthProperty, | 781 services->SetServiceProperty(kWimaxPath, shill::kSignalStrengthProperty, |
| 784 strength_value); | 782 strength_value); |
| 785 profiles->AddService(shared_profile, kWimaxPath); | 783 profiles->AddService(shared_profile, kWimaxPath); |
| 786 } | 784 } |
| 787 | 785 |
| 788 // Cellular | 786 // Cellular |
| 789 state = GetInitialStateForType(shill::kTypeCellular, &enabled); | 787 state = GetInitialStateForType(shill::kTypeCellular, &enabled); |
| 790 if (state != kTechnologyUnavailable) { | 788 if (state != kTechnologyUnavailable) { |
| 791 bool activated = false; | 789 bool activated = false; |
| 792 if (state == kNetworkActivated) { | 790 if (state == kNetworkActivated) { |
| 793 activated = true; | 791 activated = true; |
| 794 state = shill::kStateOnline; | 792 state = shill::kStateOnline; |
| 795 } | 793 } |
| 796 AddTechnology(shill::kTypeCellular, enabled); | 794 AddTechnology(shill::kTypeCellular, enabled); |
| 797 devices->AddDevice( | 795 devices->AddDevice( |
| 798 "/device/cellular1", shill::kTypeCellular, "stub_cellular_device1"); | 796 "/device/cellular1", shill::kTypeCellular, "stub_cellular_device1"); |
| 799 devices->SetDeviceProperty("/device/cellular1", | 797 devices->SetDeviceProperty("/device/cellular1", |
| 800 shill::kCarrierProperty, | 798 shill::kCarrierProperty, |
| 801 base::StringValue(shill::kCarrierSprint)); | 799 base::StringValue(shill::kCarrierSprint)); |
| 802 base::ListValue carrier_list; | 800 base::ListValue carrier_list; |
| 803 carrier_list.AppendString(shill::kCarrierSprint); | 801 carrier_list.AppendString(shill::kCarrierSprint); |
| 804 carrier_list.AppendString(shill::kCarrierGenericUMTS); | 802 carrier_list.AppendString(shill::kCarrierGenericUMTS); |
| 805 devices->SetDeviceProperty("/device/cellular1", | 803 devices->SetDeviceProperty("/device/cellular1", |
| 806 shill::kSupportedCarriersProperty, | 804 shill::kSupportedCarriersProperty, |
| 807 carrier_list); | 805 carrier_list); |
| 808 devices->SetDeviceProperty("/device/cellular1", | 806 devices->SetDeviceProperty("/device/cellular1", |
| 809 shill::kSupportNetworkScanProperty, | 807 shill::kSupportNetworkScanProperty, |
| 810 base::FundamentalValue(true)); | 808 base::Value(true)); |
| 811 if (roaming_state_ == kRoamingRequired) { | 809 if (roaming_state_ == kRoamingRequired) { |
| 812 devices->SetDeviceProperty("/device/cellular1", | 810 devices->SetDeviceProperty("/device/cellular1", |
| 813 shill::kProviderRequiresRoamingProperty, | 811 shill::kProviderRequiresRoamingProperty, |
| 814 base::FundamentalValue(true)); | 812 base::Value(true)); |
| 815 } | 813 } |
| 816 if (cellular_technology_ == shill::kNetworkTechnologyGsm) { | 814 if (cellular_technology_ == shill::kNetworkTechnologyGsm) { |
| 817 devices->SetDeviceProperty("/device/cellular1", | 815 devices->SetDeviceProperty("/device/cellular1", |
| 818 shill::kSIMPresentProperty, | 816 shill::kSIMPresentProperty, base::Value(true)); |
| 819 base::FundamentalValue(true)); | |
| 820 devices->SetSimLocked("/device/cellular1", false); | 817 devices->SetSimLocked("/device/cellular1", false); |
| 821 } | 818 } |
| 822 | 819 |
| 823 services->AddService(kCellularServicePath, | 820 services->AddService(kCellularServicePath, |
| 824 "cellular1_guid", | 821 "cellular1_guid", |
| 825 "cellular1" /* name */, | 822 "cellular1" /* name */, |
| 826 shill::kTypeCellular, | 823 shill::kTypeCellular, |
| 827 state, | 824 state, |
| 828 add_to_visible); | 825 add_to_visible); |
| 829 base::StringValue technology_value(cellular_technology_); | 826 base::StringValue technology_value(cellular_technology_); |
| 830 devices->SetDeviceProperty("/device/cellular1", | 827 devices->SetDeviceProperty("/device/cellular1", |
| 831 shill::kTechnologyFamilyProperty, | 828 shill::kTechnologyFamilyProperty, |
| 832 technology_value); | 829 technology_value); |
| 833 services->SetServiceProperty(kCellularServicePath, | 830 services->SetServiceProperty(kCellularServicePath, |
| 834 shill::kNetworkTechnologyProperty, | 831 shill::kNetworkTechnologyProperty, |
| 835 technology_value); | 832 technology_value); |
| 836 | 833 |
| 837 if (activated) { | 834 if (activated) { |
| 838 services->SetServiceProperty( | 835 services->SetServiceProperty( |
| 839 kCellularServicePath, | 836 kCellularServicePath, |
| 840 shill::kActivationStateProperty, | 837 shill::kActivationStateProperty, |
| 841 base::StringValue(shill::kActivationStateActivated)); | 838 base::StringValue(shill::kActivationStateActivated)); |
| 842 services->SetServiceProperty(kCellularServicePath, | 839 services->SetServiceProperty( |
| 843 shill::kConnectableProperty, | 840 kCellularServicePath, shill::kConnectableProperty, base::Value(true)); |
| 844 base::FundamentalValue(true)); | |
| 845 } else { | 841 } else { |
| 846 services->SetServiceProperty( | 842 services->SetServiceProperty( |
| 847 kCellularServicePath, | 843 kCellularServicePath, |
| 848 shill::kActivationStateProperty, | 844 shill::kActivationStateProperty, |
| 849 base::StringValue(shill::kActivationStateNotActivated)); | 845 base::StringValue(shill::kActivationStateNotActivated)); |
| 850 } | 846 } |
| 851 | 847 |
| 852 std::string shill_roaming_state; | 848 std::string shill_roaming_state; |
| 853 if (roaming_state_ == kRoamingRequired) | 849 if (roaming_state_ == kRoamingRequired) |
| 854 shill_roaming_state = shill::kRoamingStateRoaming; | 850 shill_roaming_state = shill::kRoamingStateRoaming; |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1048 if (TechnologyEnabled(type)) | 1044 if (TechnologyEnabled(type)) |
| 1049 new_service_list->Append((*iter)->CreateDeepCopy()); | 1045 new_service_list->Append((*iter)->CreateDeepCopy()); |
| 1050 } | 1046 } |
| 1051 } | 1047 } |
| 1052 return new_service_list; | 1048 return new_service_list; |
| 1053 } | 1049 } |
| 1054 | 1050 |
| 1055 void FakeShillManagerClient::ScanCompleted(const std::string& device_path, | 1051 void FakeShillManagerClient::ScanCompleted(const std::string& device_path, |
| 1056 const base::Closure& callback) { | 1052 const base::Closure& callback) { |
| 1057 if (!device_path.empty()) { | 1053 if (!device_path.empty()) { |
| 1058 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface()-> | 1054 DBusThreadManager::Get() |
| 1059 SetDeviceProperty(device_path, | 1055 ->GetShillDeviceClient() |
| 1060 shill::kScanningProperty, | 1056 ->GetTestInterface() |
| 1061 base::FundamentalValue(false)); | 1057 ->SetDeviceProperty(device_path, shill::kScanningProperty, |
| 1058 base::Value(false)); |
| 1062 } | 1059 } |
| 1063 VLOG(1) << "ScanCompleted"; | 1060 VLOG(1) << "ScanCompleted"; |
| 1064 CallNotifyObserversPropertyChanged(shill::kServiceCompleteListProperty); | 1061 CallNotifyObserversPropertyChanged(shill::kServiceCompleteListProperty); |
| 1065 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback); | 1062 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback); |
| 1066 } | 1063 } |
| 1067 | 1064 |
| 1068 void FakeShillManagerClient::ParseCommandLineSwitch() { | 1065 void FakeShillManagerClient::ParseCommandLineSwitch() { |
| 1069 // Default setup | 1066 // Default setup |
| 1070 SetInitialNetworkState(shill::kTypeEthernet, shill::kStateOnline); | 1067 SetInitialNetworkState(shill::kTypeEthernet, shill::kStateOnline); |
| 1071 SetInitialNetworkState(shill::kTypeWifi, shill::kStateOnline); | 1068 SetInitialNetworkState(shill::kTypeWifi, shill::kStateOnline); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1111 FakeShillDeviceClient::kSimPinRetryCount); | 1108 FakeShillDeviceClient::kSimPinRetryCount); |
| 1112 } | 1109 } |
| 1113 shill_device_property_map_[shill::kTypeCellular] | 1110 shill_device_property_map_[shill::kTypeCellular] |
| 1114 [shill::kSIMLockStatusProperty] = simlock_dict; | 1111 [shill::kSIMLockStatusProperty] = simlock_dict; |
| 1115 shill_device_property_map_ | 1112 shill_device_property_map_ |
| 1116 [shill::kTypeCellular][shill::kTechnologyFamilyProperty] = | 1113 [shill::kTypeCellular][shill::kTechnologyFamilyProperty] = |
| 1117 new base::StringValue(shill::kNetworkTechnologyGsm); | 1114 new base::StringValue(shill::kNetworkTechnologyGsm); |
| 1118 return true; | 1115 return true; |
| 1119 } else if (arg0 == "sim_present") { | 1116 } else if (arg0 == "sim_present") { |
| 1120 bool present = (arg1 == "1"); | 1117 bool present = (arg1 == "1"); |
| 1121 base::FundamentalValue* sim_present = new base::FundamentalValue(present); | 1118 base::Value* sim_present = new base::Value(present); |
| 1122 shill_device_property_map_[shill::kTypeCellular] | 1119 shill_device_property_map_[shill::kTypeCellular] |
| 1123 [shill::kSIMPresentProperty] = sim_present; | 1120 [shill::kSIMPresentProperty] = sim_present; |
| 1124 return true; | 1121 return true; |
| 1125 } else if (arg0 == "tdls_busy") { | 1122 } else if (arg0 == "tdls_busy") { |
| 1126 if (!arg1.empty()) | 1123 if (!arg1.empty()) |
| 1127 base::StringToInt(arg1, &s_tdls_busy_count); | 1124 base::StringToInt(arg1, &s_tdls_busy_count); |
| 1128 else | 1125 else |
| 1129 s_tdls_busy_count = 1; | 1126 s_tdls_busy_count = 1; |
| 1130 return true; | 1127 return true; |
| 1131 } else if (arg0 == "roaming") { | 1128 } else if (arg0 == "roaming") { |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1235 LOG(WARNING) << "Invalid state: " << state << " for " << type; | 1232 LOG(WARNING) << "Invalid state: " << state << " for " << type; |
| 1236 result = shill::kStateIdle; | 1233 result = shill::kStateIdle; |
| 1237 } | 1234 } |
| 1238 } | 1235 } |
| 1239 VLOG(1) << "Initial state for: " << type << " = " << result | 1236 VLOG(1) << "Initial state for: " << type << " = " << result |
| 1240 << " Enabled: " << *enabled; | 1237 << " Enabled: " << *enabled; |
| 1241 return result; | 1238 return result; |
| 1242 } | 1239 } |
| 1243 | 1240 |
| 1244 } // namespace chromeos | 1241 } // namespace chromeos |
| OLD | NEW |