| 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 void UpdatePortaledWifiState(const std::string& service_path) { | 98 void UpdatePortaledWifiState(const std::string& service_path) { |
| 99 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface() | 99 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface() |
| 100 ->SetServiceProperty(service_path, | 100 ->SetServiceProperty(service_path, |
| 101 shill::kStateProperty, | 101 shill::kStateProperty, |
| 102 base::StringValue(shill::kStatePortal)); | 102 base::StringValue(shill::kStatePortal)); |
| 103 } | 103 } |
| 104 | 104 |
| 105 const char* kTechnologyUnavailable = "unavailable"; | 105 const char* kTechnologyUnavailable = "unavailable"; |
| 106 const char* kNetworkActivated = "activated"; | 106 const char* kNetworkActivated = "activated"; |
| 107 const char* kNetworkDisabled = "disabled"; | 107 const char* kNetworkDisabled = "disabled"; |
| 108 const char* kCellularServicePath = "/service/cellular1"; |
| 108 | 109 |
| 109 } // namespace | 110 } // namespace |
| 110 | 111 |
| 111 // static | 112 // static |
| 112 const char FakeShillManagerClient::kFakeEthernetNetworkGuid[] = "eth1_guid"; | 113 const char FakeShillManagerClient::kFakeEthernetNetworkGuid[] = "eth1_guid"; |
| 113 | 114 |
| 114 FakeShillManagerClient::FakeShillManagerClient() | 115 FakeShillManagerClient::FakeShillManagerClient() |
| 115 : interactive_delay_(0), | 116 : interactive_delay_(0), |
| 116 weak_ptr_factory_(this) { | 117 weak_ptr_factory_(this) { |
| 117 ParseCommandLineSwitch(); | 118 ParseCommandLineSwitch(); |
| (...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 DCHECK(devices); | 576 DCHECK(devices); |
| 576 ShillIPConfigClient::TestInterface* ip_configs = | 577 ShillIPConfigClient::TestInterface* ip_configs = |
| 577 dbus_manager->GetShillIPConfigClient()->GetTestInterface(); | 578 dbus_manager->GetShillIPConfigClient()->GetTestInterface(); |
| 578 DCHECK(ip_configs); | 579 DCHECK(ip_configs); |
| 579 | 580 |
| 580 const std::string shared_profile = ShillProfileClient::GetSharedProfilePath(); | 581 const std::string shared_profile = ShillProfileClient::GetSharedProfilePath(); |
| 581 profiles->AddProfile(shared_profile, std::string()); | 582 profiles->AddProfile(shared_profile, std::string()); |
| 582 | 583 |
| 583 const bool add_to_visible = true; | 584 const bool add_to_visible = true; |
| 584 | 585 |
| 585 bool enabled; | |
| 586 std::string state; | |
| 587 | |
| 588 // IPConfigs | 586 // IPConfigs |
| 589 base::DictionaryValue ipconfig_v4_dictionary; | 587 base::DictionaryValue ipconfig_v4_dictionary; |
| 590 ipconfig_v4_dictionary.SetStringWithoutPathExpansion( | 588 ipconfig_v4_dictionary.SetStringWithoutPathExpansion( |
| 591 shill::kAddressProperty, "0.0.0.0"); | 589 shill::kAddressProperty, "0.0.0.0"); |
| 592 ipconfig_v4_dictionary.SetStringWithoutPathExpansion( | 590 ipconfig_v4_dictionary.SetStringWithoutPathExpansion( |
| 593 shill::kGatewayProperty, "0.0.0.1"); | 591 shill::kGatewayProperty, "0.0.0.1"); |
| 594 ipconfig_v4_dictionary.SetIntegerWithoutPathExpansion( | 592 ipconfig_v4_dictionary.SetIntegerWithoutPathExpansion( |
| 595 shill::kPrefixlenProperty, 0); | 593 shill::kPrefixlenProperty, 0); |
| 596 ipconfig_v4_dictionary.SetStringWithoutPathExpansion( | 594 ipconfig_v4_dictionary.SetStringWithoutPathExpansion( |
| 597 shill::kMethodProperty, shill::kTypeIPv4); | 595 shill::kMethodProperty, shill::kTypeIPv4); |
| 598 ip_configs->AddIPConfig("ipconfig_v4_path", ipconfig_v4_dictionary); | 596 ip_configs->AddIPConfig("ipconfig_v4_path", ipconfig_v4_dictionary); |
| 599 base::DictionaryValue ipconfig_v6_dictionary; | 597 base::DictionaryValue ipconfig_v6_dictionary; |
| 600 ipconfig_v6_dictionary.SetStringWithoutPathExpansion( | 598 ipconfig_v6_dictionary.SetStringWithoutPathExpansion( |
| 601 shill::kAddressProperty, "0:0:0:0:0:0:0:0"); | 599 shill::kAddressProperty, "0:0:0:0:0:0:0:0"); |
| 602 ipconfig_v6_dictionary.SetStringWithoutPathExpansion( | 600 ipconfig_v6_dictionary.SetStringWithoutPathExpansion( |
| 603 shill::kMethodProperty, shill::kTypeIPv6); | 601 shill::kMethodProperty, shill::kTypeIPv6); |
| 604 ip_configs->AddIPConfig("ipconfig_v6_path", ipconfig_v6_dictionary); | 602 ip_configs->AddIPConfig("ipconfig_v6_path", ipconfig_v6_dictionary); |
| 605 | 603 |
| 604 bool enabled; |
| 605 std::string state; |
| 606 |
| 606 // Ethernet | 607 // Ethernet |
| 607 state = GetInitialStateForType(shill::kTypeEthernet, &enabled); | 608 state = GetInitialStateForType(shill::kTypeEthernet, &enabled); |
| 608 if (state == shill::kStateOnline) { | 609 if (state == shill::kStateOnline) { |
| 609 AddTechnology(shill::kTypeEthernet, enabled); | 610 AddTechnology(shill::kTypeEthernet, enabled); |
| 610 devices->AddDevice( | 611 devices->AddDevice( |
| 611 "/device/eth1", shill::kTypeEthernet, "stub_eth_device1"); | 612 "/device/eth1", shill::kTypeEthernet, "stub_eth_device1"); |
| 612 devices->SetDeviceProperty("/device/eth1", | 613 devices->SetDeviceProperty("/device/eth1", |
| 613 shill::kAddressProperty, | 614 shill::kAddressProperty, |
| 614 base::StringValue("0123456789ab")); | 615 base::StringValue("0123456789ab")); |
| 615 base::ListValue eth_ip_configs; | 616 base::ListValue eth_ip_configs; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 726 activated = true; | 727 activated = true; |
| 727 state = shill::kStateIdle; | 728 state = shill::kStateIdle; |
| 728 } | 729 } |
| 729 AddTechnology(shill::kTypeCellular, enabled); | 730 AddTechnology(shill::kTypeCellular, enabled); |
| 730 devices->AddDevice( | 731 devices->AddDevice( |
| 731 "/device/cellular1", shill::kTypeCellular, "stub_cellular_device1"); | 732 "/device/cellular1", shill::kTypeCellular, "stub_cellular_device1"); |
| 732 devices->SetDeviceProperty("/device/cellular1", | 733 devices->SetDeviceProperty("/device/cellular1", |
| 733 shill::kCarrierProperty, | 734 shill::kCarrierProperty, |
| 734 base::StringValue(shill::kCarrierSprint)); | 735 base::StringValue(shill::kCarrierSprint)); |
| 735 | 736 |
| 736 services->AddService("/service/cellular1", | 737 services->AddService(kCellularServicePath, |
| 737 "cellular1_guid", | 738 "cellular1_guid", |
| 738 "cellular1" /* name */, | 739 "cellular1" /* name */, |
| 739 shill::kTypeCellular, | 740 shill::kTypeCellular, |
| 740 state, | 741 state, |
| 741 add_to_visible); | 742 add_to_visible); |
| 742 base::StringValue technology_value(shill::kNetworkTechnologyGsm); | 743 base::StringValue technology_value(shill::kNetworkTechnologyGsm); |
| 743 services->SetServiceProperty("/service/cellular1", | 744 services->SetServiceProperty(kCellularServicePath, |
| 744 shill::kNetworkTechnologyProperty, | 745 shill::kNetworkTechnologyProperty, |
| 745 technology_value); | 746 technology_value); |
| 746 | 747 |
| 747 if (activated) { | 748 if (activated) { |
| 748 services->SetServiceProperty( | 749 services->SetServiceProperty( |
| 749 "/service/cellular1", | 750 kCellularServicePath, |
| 750 shill::kActivationStateProperty, | 751 shill::kActivationStateProperty, |
| 751 base::StringValue(shill::kActivationStateActivated)); | 752 base::StringValue(shill::kActivationStateActivated)); |
| 752 services->SetServiceProperty("/service/cellular1", | 753 services->SetServiceProperty(kCellularServicePath, |
| 753 shill::kConnectableProperty, | 754 shill::kConnectableProperty, |
| 754 base::FundamentalValue(true)); | 755 base::FundamentalValue(true)); |
| 755 } else { | 756 } else { |
| 756 services->SetServiceProperty( | 757 services->SetServiceProperty( |
| 757 "/service/cellular1", | 758 kCellularServicePath, |
| 758 shill::kActivationStateProperty, | 759 shill::kActivationStateProperty, |
| 759 base::StringValue(shill::kActivationStateNotActivated)); | 760 base::StringValue(shill::kActivationStateNotActivated)); |
| 760 } | 761 } |
| 761 | 762 |
| 762 services->SetServiceProperty("/service/cellular1", | 763 services->SetServiceProperty(kCellularServicePath, |
| 763 shill::kRoamingStateProperty, | 764 shill::kRoamingStateProperty, |
| 764 base::StringValue(shill::kRoamingStateHome)); | 765 base::StringValue(shill::kRoamingStateHome)); |
| 765 } | 766 } |
| 766 | 767 |
| 767 // VPN | 768 // VPN |
| 768 state = GetInitialStateForType(shill::kTypeVPN, &enabled); | 769 state = GetInitialStateForType(shill::kTypeVPN, &enabled); |
| 769 if (state != kTechnologyUnavailable) { | 770 if (state != kTechnologyUnavailable) { |
| 770 // Set the "Provider" dictionary properties. Note: when setting these in | 771 // Set the "Provider" dictionary properties. Note: when setting these in |
| 771 // Shill, "Provider.Type", etc keys are used, but when reading the values | 772 // Shill, "Provider.Type", etc keys are used, but when reading the values |
| 772 // "Provider" . "Type", etc keys are used. Here we are setting the values | 773 // "Provider" . "Type", etc keys are used. Here we are setting the values |
| (...skipping 16 matching lines...) Expand all Loading... |
| 789 services->AddService("/service/vpn2", | 790 services->AddService("/service/vpn2", |
| 790 "vpn2_guid", | 791 "vpn2_guid", |
| 791 "vpn2" /* name */, | 792 "vpn2" /* name */, |
| 792 shill::kTypeVPN, | 793 shill::kTypeVPN, |
| 793 shill::kStateIdle, | 794 shill::kStateIdle, |
| 794 add_to_visible); | 795 add_to_visible); |
| 795 services->SetServiceProperty( | 796 services->SetServiceProperty( |
| 796 "/service/vpn2", shill::kProviderProperty, provider_properties); | 797 "/service/vpn2", shill::kProviderProperty, provider_properties); |
| 797 } | 798 } |
| 798 | 799 |
| 800 // Additional device states |
| 801 for (DevicePropertyMap::iterator iter1 = shill_device_property_map_.begin(); |
| 802 iter1 != shill_device_property_map_.end(); ++iter1) { |
| 803 std::string device_type = iter1->first; |
| 804 std::string device_path = devices->GetDevicePathForType(device_type); |
| 805 for (ShillPropertyMap::iterator iter2 = iter1->second.begin(); |
| 806 iter2 != iter1->second.end(); ++iter2) { |
| 807 devices->SetDeviceProperty(device_path, iter2->first, *(iter2->second)); |
| 808 delete iter2->second; |
| 809 } |
| 810 } |
| 811 |
| 799 SortManagerServices(true); | 812 SortManagerServices(true); |
| 800 } | 813 } |
| 801 | 814 |
| 802 // Private methods | 815 // Private methods |
| 803 | 816 |
| 804 void FakeShillManagerClient::PassStubProperties( | 817 void FakeShillManagerClient::PassStubProperties( |
| 805 const DictionaryValueCallback& callback) const { | 818 const DictionaryValueCallback& callback) const { |
| 806 scoped_ptr<base::DictionaryValue> stub_properties( | 819 scoped_ptr<base::DictionaryValue> stub_properties( |
| 807 stub_properties_.DeepCopy()); | 820 stub_properties_.DeepCopy()); |
| 808 stub_properties->SetWithoutPathExpansion( | 821 stub_properties->SetWithoutPathExpansion( |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 925 SetDeviceProperty(device_path, | 938 SetDeviceProperty(device_path, |
| 926 shill::kScanningProperty, | 939 shill::kScanningProperty, |
| 927 base::FundamentalValue(false)); | 940 base::FundamentalValue(false)); |
| 928 } | 941 } |
| 929 DVLOG(2) << "ScanCompleted"; | 942 DVLOG(2) << "ScanCompleted"; |
| 930 CallNotifyObserversPropertyChanged(shill::kServiceCompleteListProperty); | 943 CallNotifyObserversPropertyChanged(shill::kServiceCompleteListProperty); |
| 931 base::MessageLoop::current()->PostTask(FROM_HERE, callback); | 944 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 932 } | 945 } |
| 933 | 946 |
| 934 void FakeShillManagerClient::ParseCommandLineSwitch() { | 947 void FakeShillManagerClient::ParseCommandLineSwitch() { |
| 935 CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
| 936 if (command_line->HasSwitch(switches::kShillStub)) { | |
| 937 std::string option_str = | |
| 938 command_line->GetSwitchValueASCII(switches::kShillStub); | |
| 939 base::StringPairs string_pairs; | |
| 940 base::SplitStringIntoKeyValuePairs(option_str, '=', ',', &string_pairs); | |
| 941 for (base::StringPairs::iterator iter = string_pairs.begin(); | |
| 942 iter != string_pairs.end(); ++iter) { | |
| 943 ParseOption((*iter).first, (*iter).second); | |
| 944 } | |
| 945 return; | |
| 946 } | |
| 947 // Default setup | 948 // Default setup |
| 948 SetInitialNetworkState(shill::kTypeEthernet, shill::kStateOnline); | 949 SetInitialNetworkState(shill::kTypeEthernet, shill::kStateOnline); |
| 949 SetInitialNetworkState(shill::kTypeWifi, shill::kStateOnline); | 950 SetInitialNetworkState(shill::kTypeWifi, shill::kStateOnline); |
| 950 SetInitialNetworkState(shill::kTypeCellular, shill::kStateIdle); | 951 SetInitialNetworkState(shill::kTypeCellular, shill::kStateIdle); |
| 951 SetInitialNetworkState(shill::kTypeVPN, shill::kStateIdle); | 952 SetInitialNetworkState(shill::kTypeVPN, shill::kStateIdle); |
| 953 |
| 954 // Parse additional options |
| 955 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 956 if (!command_line->HasSwitch(switches::kShillStub)) |
| 957 return; |
| 958 |
| 959 std::string option_str = |
| 960 command_line->GetSwitchValueASCII(switches::kShillStub); |
| 961 VLOG(1) << "Parsing command line:" << option_str; |
| 962 base::StringPairs string_pairs; |
| 963 base::SplitStringIntoKeyValuePairs(option_str, '=', ',', &string_pairs); |
| 964 for (base::StringPairs::iterator iter = string_pairs.begin(); |
| 965 iter != string_pairs.end(); ++iter) { |
| 966 ParseOption((*iter).first, (*iter).second); |
| 967 } |
| 952 } | 968 } |
| 953 | 969 |
| 954 bool FakeShillManagerClient::ParseOption(const std::string& arg0, | 970 bool FakeShillManagerClient::ParseOption(const std::string& arg0, |
| 955 const std::string& arg1) { | 971 const std::string& arg1) { |
| 956 if (arg0 == "interactive") { | 972 VLOG(1) << "Parsing command line option: '" << arg0 << "=" << arg1 << "'"; |
| 973 if ((arg0 == "clear" || arg0 == "reset") && arg1 == "1") { |
| 974 shill_initial_state_map_.clear(); |
| 975 return true; |
| 976 } else if (arg0 == "interactive") { |
| 957 int seconds = 3; | 977 int seconds = 3; |
| 958 if (!arg1.empty()) | 978 if (!arg1.empty()) |
| 959 base::StringToInt(arg1, &seconds); | 979 base::StringToInt(arg1, &seconds); |
| 960 interactive_delay_ = seconds; | 980 interactive_delay_ = seconds; |
| 961 return true; | 981 return true; |
| 982 } else if (arg0 == "sim_lock") { |
| 983 bool locked = (arg1 == "1") ? true : false; |
| 984 base::DictionaryValue* simlock_dict = new base::DictionaryValue; |
| 985 simlock_dict->Set(shill::kSIMLockEnabledProperty, |
| 986 new base::FundamentalValue(locked)); |
| 987 // TODO(stevenjb): Investigate why non-empty value breaks UI. |
| 988 std::string lock_type = ""; // shill::kSIMLockPin |
| 989 simlock_dict->SetString(shill::kSIMLockTypeProperty, lock_type); |
| 990 simlock_dict->SetInteger(shill::kSIMLockRetriesLeftProperty, 5); |
| 991 |
| 992 shill_device_property_map_ |
| 993 [shill::kTypeCellular][shill::kSIMLockStatusProperty] = simlock_dict; |
| 994 shill_device_property_map_ |
| 995 [shill::kTypeCellular][shill::kTechnologyFamilyProperty] = |
| 996 new base::StringValue(shill::kNetworkTechnologyGsm); |
| 997 return true; |
| 962 } | 998 } |
| 963 return SetInitialNetworkState(arg0, arg1); | 999 return SetInitialNetworkState(arg0, arg1); |
| 964 } | 1000 } |
| 965 | 1001 |
| 966 bool FakeShillManagerClient::SetInitialNetworkState(std::string type_arg, | 1002 bool FakeShillManagerClient::SetInitialNetworkState(std::string type_arg, |
| 967 std::string state_arg) { | 1003 std::string state_arg) { |
| 968 std::string state; | 1004 std::string state; |
| 969 state_arg = StringToLowerASCII(state_arg); | 1005 state_arg = StringToLowerASCII(state_arg); |
| 970 if (state_arg.empty() || state_arg == "1" || state_arg == "on" || | 1006 if (state_arg.empty() || state_arg == "1" || state_arg == "on" || |
| 971 state_arg == "enabled" || state_arg == "connected" || | 1007 state_arg == "enabled" || state_arg == "connected" || |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1040 *enabled = true; | 1076 *enabled = true; |
| 1041 if ((state == shill::kStatePortal && type != shill::kTypeWifi) || | 1077 if ((state == shill::kStatePortal && type != shill::kTypeWifi) || |
| 1042 (state == kNetworkActivated && type != shill::kTypeCellular)) { | 1078 (state == kNetworkActivated && type != shill::kTypeCellular)) { |
| 1043 LOG(WARNING) << "Invalid state: " << state << " for " << type; | 1079 LOG(WARNING) << "Invalid state: " << state << " for " << type; |
| 1044 return shill::kStateIdle; | 1080 return shill::kStateIdle; |
| 1045 } | 1081 } |
| 1046 return state; | 1082 return state; |
| 1047 } | 1083 } |
| 1048 | 1084 |
| 1049 } // namespace chromeos | 1085 } // namespace chromeos |
| OLD | NEW |