Arman Uguray | 2717a10 | 2013-01-29 23:36:06 -0800 | [diff] [blame] | 1 | // Copyright (c) 2013 The Chromium OS Authors. All rights reserved. |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Chris Masone | b2e326b | 2011-07-12 13:28:51 -0700 | [diff] [blame] | 5 | #include "shill/service.h" |
| 6 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 7 | #include <stdio.h> |
Alex Vakulenko | a41ab51 | 2014-07-23 14:24:23 -0700 | [diff] [blame] | 8 | #include <time.h> |
Chris Masone | ee929b7 | 2011-05-10 10:02:18 -0700 | [diff] [blame] | 9 | |
Alex Vakulenko | 8a53229 | 2014-06-16 17:18:44 -0700 | [diff] [blame] | 10 | #include <algorithm> |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 11 | #include <map> |
Ben Chan | cd47732 | 2014-10-17 14:19:30 -0700 | [diff] [blame] | 12 | #include <memory> |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 13 | #include <string> |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 14 | #include <vector> |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 15 | |
Ben Chan | a0ddf46 | 2014-02-06 11:32:42 -0800 | [diff] [blame] | 16 | #include <base/strings/string_number_conversions.h> |
| 17 | #include <base/strings/stringprintf.h> |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 18 | #include <chromeos/dbus/service_constants.h> |
Chris Masone | ee929b7 | 2011-05-10 10:02:18 -0700 | [diff] [blame] | 19 | |
Paul Stewart | be5f5b3 | 2011-12-07 17:11:11 -0800 | [diff] [blame] | 20 | #include "shill/connection.h" |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 21 | #include "shill/control_interface.h" |
Darin Petkov | 385b9bc | 2012-12-03 15:25:05 +0100 | [diff] [blame] | 22 | #include "shill/diagnostics_reporter.h" |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 23 | #include "shill/eap_credentials.h" |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 24 | #include "shill/error.h" |
Paul Stewart | be5f5b3 | 2011-12-07 17:11:11 -0800 | [diff] [blame] | 25 | #include "shill/http_proxy.h" |
Christopher Wiley | b691efd | 2012-08-09 13:51:51 -0700 | [diff] [blame] | 26 | #include "shill/logging.h" |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 27 | #include "shill/manager.h" |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 28 | #include "shill/metrics.h" |
Samuel Tan | 07dfabc | 2015-01-20 15:10:39 -0800 | [diff] [blame] | 29 | #include "shill/net/event_history.h" |
Peter Qiu | 8d6b597 | 2014-10-28 15:33:34 -0700 | [diff] [blame] | 30 | #include "shill/net/sockets.h" |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 31 | #include "shill/profile.h" |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 32 | #include "shill/property_accessor.h" |
Chris Masone | 7aa5f90 | 2011-07-11 11:13:35 -0700 | [diff] [blame] | 33 | #include "shill/refptr_types.h" |
Chris Masone | d7732e4 | 2011-05-20 11:08:56 -0700 | [diff] [blame] | 34 | #include "shill/service_dbus_adaptor.h" |
Paul Stewart | 45170bc | 2014-06-02 15:49:34 -0700 | [diff] [blame] | 35 | #include "shill/service_property_change_notifier.h" |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 36 | #include "shill/store_interface.h" |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 37 | |
Christopher Wiley | 0801d19 | 2012-09-24 11:57:15 -0700 | [diff] [blame] | 38 | using base::Bind; |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 39 | using std::map; |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 40 | using std::string; |
Chris Masone | 8fe2c7e | 2011-06-09 15:51:19 -0700 | [diff] [blame] | 41 | using std::vector; |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 42 | |
| 43 | namespace shill { |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 44 | |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 45 | namespace Logging { |
| 46 | static auto kModuleLogScope = ScopeLogger::kService; |
| 47 | static string ObjectID(const Service *s) { return s->GetRpcIdentifier(); } |
| 48 | } |
| 49 | |
mukesh agrawal | 03c15ce | 2012-11-29 17:36:21 -0800 | [diff] [blame] | 50 | const char Service::kAutoConnBusy[] = "busy"; |
mukesh agrawal | bf14e94 | 2012-03-02 14:36:34 -0800 | [diff] [blame] | 51 | const char Service::kAutoConnConnected[] = "connected"; |
| 52 | const char Service::kAutoConnConnecting[] = "connecting"; |
| 53 | const char Service::kAutoConnExplicitDisconnect[] = "explicitly disconnected"; |
| 54 | const char Service::kAutoConnNotConnectable[] = "not connectable"; |
Darin Petkov | 4cbff5b | 2013-01-29 16:29:05 +0100 | [diff] [blame] | 55 | const char Service::kAutoConnOffline[] = "offline"; |
Ben Chan | 8e6b8ef | 2014-07-14 21:50:18 -0700 | [diff] [blame] | 56 | const char Service::kAutoConnTechnologyNotConnectable[] = |
| 57 | "technology not connectable"; |
Christopher Wiley | 0801d19 | 2012-09-24 11:57:15 -0700 | [diff] [blame] | 58 | const char Service::kAutoConnThrottled[] = "throttled"; |
mukesh agrawal | bf14e94 | 2012-03-02 14:36:34 -0800 | [diff] [blame] | 59 | |
Paul Stewart | bc6e739 | 2012-05-24 07:07:48 -0700 | [diff] [blame] | 60 | const size_t Service::kEAPMaxCertificationElements = 10; |
| 61 | |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 62 | const char Service::kCheckPortalAuto[] = "auto"; |
| 63 | const char Service::kCheckPortalFalse[] = "false"; |
| 64 | const char Service::kCheckPortalTrue[] = "true"; |
| 65 | |
Darin Petkov | aba8932 | 2013-03-11 14:48:22 +0100 | [diff] [blame] | 66 | const char Service::kErrorDetailsNone[] = ""; |
| 67 | |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 68 | const int Service::kPriorityNone = 0; |
| 69 | |
Darin Petkov | 2f903b3 | 2012-04-18 12:56:43 +0200 | [diff] [blame] | 70 | const char Service::kServiceSortAutoConnect[] = "AutoConnect"; |
| 71 | const char Service::kServiceSortConnectable[] = "Connectable"; |
Paul Stewart | df3c0a8 | 2012-11-09 15:54:33 -0800 | [diff] [blame] | 72 | const char Service::kServiceSortDependency[] = "Dependency"; |
Paul Stewart | 2da34c0 | 2013-10-17 15:28:56 -0700 | [diff] [blame] | 73 | const char Service::kServiceSortHasEverConnected[] = "HasEverConnected"; |
mukesh agrawal | ddc378f | 2012-02-17 18:26:20 -0800 | [diff] [blame] | 74 | const char Service::kServiceSortIsConnected[] = "IsConnected"; |
| 75 | const char Service::kServiceSortIsConnecting[] = "IsConnecting"; |
| 76 | const char Service::kServiceSortIsFailed[] = "IsFailed"; |
Paul Stewart | a121c44 | 2012-06-09 14:12:58 -0700 | [diff] [blame] | 77 | const char Service::kServiceSortIsPortalled[] = "IsPortal"; |
Darin Petkov | 2f903b3 | 2012-04-18 12:56:43 +0200 | [diff] [blame] | 78 | const char Service::kServiceSortPriority[] = "Priority"; |
Paul Stewart | d9c7cfc | 2015-01-06 14:26:22 -0800 | [diff] [blame] | 79 | const char Service::kServiceSortPriorityWithinTechnology[] = |
| 80 | "PriorityWithinTechnology"; |
Rebecca Silberstein | 6d4836b | 2014-07-16 14:28:28 -0700 | [diff] [blame] | 81 | const char Service::kServiceSortSecurity[] = "Security"; |
| 82 | const char Service::kServiceSortProfileOrder[] = "ProfileOrder"; |
| 83 | const char Service::kServiceSortEtc[] = "Etc"; |
mukesh agrawal | e37ad32 | 2013-10-08 16:33:56 -0700 | [diff] [blame] | 84 | const char Service::kServiceSortSerialNumber[] = "SerialNumber"; |
Darin Petkov | 2f903b3 | 2012-04-18 12:56:43 +0200 | [diff] [blame] | 85 | const char Service::kServiceSortTechnology[] = "Technology"; |
mukesh agrawal | ddc378f | 2012-02-17 18:26:20 -0800 | [diff] [blame] | 86 | |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 87 | const char Service::kStorageAutoConnect[] = "AutoConnect"; |
| 88 | const char Service::kStorageCheckPortal[] = "CheckPortal"; |
Peter Qiu | a89154b | 2014-05-23 15:45:42 -0700 | [diff] [blame] | 89 | const char Service::kStorageDNSAutoFallback[] = "DNSAutoFallback"; |
Paul Stewart | 0756db9 | 2012-01-27 08:34:47 -0800 | [diff] [blame] | 90 | const char Service::kStorageError[] = "Error"; |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 91 | const char Service::kStorageFavorite[] = "Favorite"; |
Paul Stewart | 0756db9 | 2012-01-27 08:34:47 -0800 | [diff] [blame] | 92 | const char Service::kStorageGUID[] = "GUID"; |
mukesh agrawal | cf24a24 | 2012-05-21 16:46:11 -0700 | [diff] [blame] | 93 | const char Service::kStorageHasEverConnected[] = "HasEverConnected"; |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 94 | const char Service::kStorageName[] = "Name"; |
| 95 | const char Service::kStoragePriority[] = "Priority"; |
Paul Stewart | d9c7cfc | 2015-01-06 14:26:22 -0800 | [diff] [blame] | 96 | const char Service::kStoragePriorityWithinTechnology[] |
| 97 | = "PriorityWithinTechnology"; |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 98 | const char Service::kStorageProxyConfig[] = "ProxyConfig"; |
| 99 | const char Service::kStorageSaveCredentials[] = "SaveCredentials"; |
Paul Stewart | 2706aaf | 2011-12-14 16:44:04 -0800 | [diff] [blame] | 100 | const char Service::kStorageType[] = "Type"; |
Paul Stewart | 987e71e | 2011-12-05 09:45:06 -0800 | [diff] [blame] | 101 | const char Service::kStorageUIData[] = "UIData"; |
Peter Qiu | 9d58193 | 2014-04-14 16:37:37 -0700 | [diff] [blame] | 102 | const char Service::kStorageConnectionId[] = "ConnectionId"; |
Peter Qiu | d49760e | 2014-09-19 16:13:42 -0700 | [diff] [blame] | 103 | const char Service::kStorageLinkMonitorDisabled[] = "LinkMonitorDisabled"; |
Paul Stewart | 3fee7e3 | 2014-10-15 21:39:29 -0700 | [diff] [blame] | 104 | const char Service::kStorageManagedCredentials[] = "ManagedCredentials"; |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 105 | |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 106 | const uint8_t Service::kStrengthMax = 100; |
| 107 | const uint8_t Service::kStrengthMin = 0; |
mukesh agrawal | 8f3f775 | 2012-02-17 19:42:09 -0800 | [diff] [blame] | 108 | |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 109 | const uint64_t Service::kMaxAutoConnectCooldownTimeMilliseconds = |
| 110 | 30 * 60 * 1000; |
| 111 | const uint64_t Service::kMinAutoConnectCooldownTimeMilliseconds = 1000; |
| 112 | const uint64_t Service::kAutoConnectCooldownBackoffFactor = 2; |
Christopher Wiley | 0801d19 | 2012-09-24 11:57:15 -0700 | [diff] [blame] | 113 | |
Darin Petkov | 385b9bc | 2012-12-03 15:25:05 +0100 | [diff] [blame] | 114 | const int Service::kDisconnectsMonitorSeconds = 5 * 60; |
| 115 | const int Service::kMisconnectsMonitorSeconds = 5 * 60; |
| 116 | const int Service::kReportDisconnectsThreshold = 2; |
| 117 | const int Service::kReportMisconnectsThreshold = 3; |
| 118 | const int Service::kMaxDisconnectEventHistory = 20; |
Samuel Tan | 07dfabc | 2015-01-20 15:10:39 -0800 | [diff] [blame] | 119 | const int Service::kMaxMisconnectEventHistory = 20; |
Darin Petkov | 385b9bc | 2012-12-03 15:25:05 +0100 | [diff] [blame] | 120 | |
mukesh agrawal | 51a7e93 | 2011-07-27 16:18:26 -0700 | [diff] [blame] | 121 | // static |
mukesh agrawal | e37ad32 | 2013-10-08 16:33:56 -0700 | [diff] [blame] | 122 | unsigned int Service::next_serial_number_ = 0; |
mukesh agrawal | 51a7e93 | 2011-07-27 16:18:26 -0700 | [diff] [blame] | 123 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 124 | Service::Service(ControlInterface *control_interface, |
mukesh agrawal | b54601c | 2011-06-07 17:39:22 -0700 | [diff] [blame] | 125 | EventDispatcher *dispatcher, |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 126 | Metrics *metrics, |
mukesh agrawal | 7a4e400 | 2011-09-06 11:26:05 -0700 | [diff] [blame] | 127 | Manager *manager, |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 128 | Technology::Identifier technology) |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 129 | : weak_ptr_factory_(this), |
| 130 | state_(kStateIdle), |
Darin Petkov | c8d91e5 | 2013-01-21 11:43:47 +0100 | [diff] [blame] | 131 | previous_state_(kStateIdle), |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 132 | failure_(kFailureUnknown), |
| 133 | auto_connect_(false), |
Paul Stewart | 2da34c0 | 2013-10-17 15:28:56 -0700 | [diff] [blame] | 134 | retain_auto_connect_(false), |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 135 | check_portal_(kCheckPortalAuto), |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 136 | connectable_(false), |
Paul Stewart | f2d6091 | 2012-07-15 08:37:30 -0700 | [diff] [blame] | 137 | error_(ConnectFailureToString(failure_)), |
Darin Petkov | aba8932 | 2013-03-11 14:48:22 +0100 | [diff] [blame] | 138 | error_details_(kErrorDetailsNone), |
Paul Stewart | d7c09a5 | 2014-02-19 12:50:29 -0800 | [diff] [blame] | 139 | previous_error_serial_number_(0), |
mukesh agrawal | adb6848 | 2012-01-17 16:31:51 -0800 | [diff] [blame] | 140 | explicitly_disconnected_(false), |
Peter Qiu | dc4e099 | 2014-05-01 10:02:52 -0700 | [diff] [blame] | 141 | is_in_user_connect_(false), |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 142 | priority_(kPriorityNone), |
Paul Stewart | d9c7cfc | 2015-01-06 14:26:22 -0800 | [diff] [blame] | 143 | priority_within_technology_(kPriorityNone), |
mukesh agrawal | 43970a2 | 2013-02-15 16:00:07 -0800 | [diff] [blame] | 144 | crypto_algorithm_(kCryptoNone), |
| 145 | key_rotation_(false), |
| 146 | endpoint_auth_(false), |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 147 | strength_(0), |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 148 | save_credentials_(true), |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 149 | technology_(technology), |
mukesh agrawal | 568b5c6 | 2012-02-28 14:44:47 -0800 | [diff] [blame] | 150 | failed_time_(0), |
mukesh agrawal | cf24a24 | 2012-05-21 16:46:11 -0700 | [diff] [blame] | 151 | has_ever_connected_(false), |
Samuel Tan | 07dfabc | 2015-01-20 15:10:39 -0800 | [diff] [blame] | 152 | disconnects_(kMaxDisconnectEventHistory), |
| 153 | misconnects_(kMaxMisconnectEventHistory), |
Christopher Wiley | 0801d19 | 2012-09-24 11:57:15 -0700 | [diff] [blame] | 154 | auto_connect_cooldown_milliseconds_(0), |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 155 | store_(PropertyStore::PropertyChangeCallback( |
| 156 | base::Bind(&Service::OnPropertyChanged, |
| 157 | weak_ptr_factory_.GetWeakPtr()))), |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 158 | dispatcher_(dispatcher), |
mukesh agrawal | e37ad32 | 2013-10-08 16:33:56 -0700 | [diff] [blame] | 159 | serial_number_(next_serial_number_++), |
| 160 | unique_name_(base::UintToString(serial_number_)), |
mukesh agrawal | d835b20 | 2011-10-07 15:26:47 -0700 | [diff] [blame] | 161 | friendly_name_(unique_name_), |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 162 | adaptor_(control_interface->CreateServiceAdaptor(this)), |
Paul Stewart | 45170bc | 2014-06-02 15:49:34 -0700 | [diff] [blame] | 163 | property_change_notifier_( |
| 164 | new ServicePropertyChangeNotifier(adaptor_.get())), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 165 | metrics_(metrics), |
Darin Petkov | 5eb0542 | 2012-05-11 15:45:25 +0200 | [diff] [blame] | 166 | manager_(manager), |
Christopher Wiley | 0801d19 | 2012-09-24 11:57:15 -0700 | [diff] [blame] | 167 | sockets_(new Sockets()), |
Darin Petkov | 385b9bc | 2012-12-03 15:25:05 +0100 | [diff] [blame] | 168 | time_(Time::GetInstance()), |
Paul Stewart | dded007 | 2013-10-24 12:38:54 -0700 | [diff] [blame] | 169 | diagnostics_reporter_(DiagnosticsReporter::GetInstance()), |
Peter Qiu | a89154b | 2014-05-23 15:45:42 -0700 | [diff] [blame] | 170 | connection_id_(0), |
Peter Qiu | d49760e | 2014-09-19 16:13:42 -0700 | [diff] [blame] | 171 | is_dns_auto_fallback_allowed_(false), |
Paul Stewart | 3fee7e3 | 2014-10-15 21:39:29 -0700 | [diff] [blame] | 172 | link_monitor_disabled_(false), |
| 173 | managed_credentials_(false) { |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 174 | HelpRegisterDerivedBool(kAutoConnectProperty, |
Thieu Le | 284fe79 | 2012-01-31 17:53:19 -0800 | [diff] [blame] | 175 | &Service::GetAutoConnect, |
Paul Stewart | 43d8dc0 | 2013-10-17 10:32:53 -0700 | [diff] [blame] | 176 | &Service::SetAutoConnectFull, |
| 177 | &Service::ClearAutoConnect); |
Chris Masone | 4d42df8 | 2011-07-02 17:09:39 -0700 | [diff] [blame] | 178 | |
Thieu Le | 71f81a6 | 2014-07-11 15:17:47 -0700 | [diff] [blame] | 179 | // kActivationTypeProperty: Registered in CellularService |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 180 | // kActivationStateProperty: Registered in CellularService |
| 181 | // kCellularApnProperty: Registered in CellularService |
| 182 | // kCellularLastGoodApnProperty: Registered in CellularService |
| 183 | // kNetworkTechnologyProperty: Registered in CellularService |
Ben Chan | 408a856 | 2014-02-05 00:02:18 -0800 | [diff] [blame] | 184 | // kOutOfCreditsProperty: Registered in CellularService |
| 185 | // kPaymentPortalProperty: Registered in CellularService |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 186 | // kRoamingStateProperty: Registered in CellularService |
| 187 | // kServingOperatorProperty: Registered in CellularService |
Ben Chan | 408a856 | 2014-02-05 00:02:18 -0800 | [diff] [blame] | 188 | // kUsageURLProperty: Registered in CellularService |
| 189 | // kCellularPPPUsernameProperty: Registered in CellularService |
| 190 | // kCellularPPPPasswordProperty: Registered in CellularService |
| 191 | |
| 192 | // kNetworkIdProperty: Registered in WiMaxService |
Chris Masone | 4d42df8 | 2011-07-02 17:09:39 -0700 | [diff] [blame] | 193 | |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 194 | HelpRegisterDerivedString(kCheckPortalProperty, |
Paul Stewart | d215af6 | 2012-04-24 23:25:50 -0700 | [diff] [blame] | 195 | &Service::GetCheckPortal, |
| 196 | &Service::SetCheckPortal); |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 197 | store_.RegisterConstBool(kConnectableProperty, &connectable_); |
| 198 | HelpRegisterConstDerivedRpcIdentifier(kDeviceProperty, |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 199 | &Service::GetDeviceRpcId); |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 200 | store_.RegisterConstStrings(kEapRemoteCertificationProperty, |
| 201 | &remote_certification_); |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 202 | HelpRegisterDerivedString(kGuidProperty, |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 203 | &Service::GetGuid, |
| 204 | &Service::SetGuid); |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 205 | |
Eric Shienbrood | cc95c5d | 2012-03-30 15:25:49 -0400 | [diff] [blame] | 206 | // TODO(ers): in flimflam clearing Error has the side-effect of |
| 207 | // setting the service state to IDLE. Is this important? I could |
| 208 | // see an autotest depending on it. |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 209 | store_.RegisterConstString(kErrorProperty, &error_); |
Ben Chan | 39a7beb | 2013-09-21 11:28:00 -0700 | [diff] [blame] | 210 | store_.RegisterConstString(kErrorDetailsProperty, &error_details_); |
Ben Chan | 39a7beb | 2013-09-21 11:28:00 -0700 | [diff] [blame] | 211 | HelpRegisterConstDerivedUint16(kHTTPProxyPortProperty, |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 212 | &Service::GetHTTPProxyPort); |
Ben Chan | 39a7beb | 2013-09-21 11:28:00 -0700 | [diff] [blame] | 213 | HelpRegisterConstDerivedRpcIdentifier(kIPConfigProperty, |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 214 | &Service::GetIPConfigRpcIdentifier); |
Ben Chan | cc225ef | 2014-09-30 13:26:51 -0700 | [diff] [blame] | 215 | HelpRegisterDerivedBool(kIsActiveProperty, &Service::IsActive, nullptr, |
| 216 | nullptr); |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 217 | // kModeProperty: Registered in WiFiService |
Paul Stewart | 0c43833 | 2012-04-11 07:55:27 -0700 | [diff] [blame] | 218 | |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 219 | HelpRegisterDerivedString(kNameProperty, |
Paul Stewart | 0c43833 | 2012-04-11 07:55:27 -0700 | [diff] [blame] | 220 | &Service::GetNameProperty, |
Darin Petkov | 9c6e981 | 2013-03-26 13:49:07 +0100 | [diff] [blame] | 221 | &Service::SetNameProperty); |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 222 | // kPassphraseProperty: Registered in WiFiService |
Ben Chan | 408a856 | 2014-02-05 00:02:18 -0800 | [diff] [blame] | 223 | // kPassphraseRequiredProperty: Registered in WiFiService, WiMaxService |
Paul Stewart | d7c09a5 | 2014-02-19 12:50:29 -0800 | [diff] [blame] | 224 | store_.RegisterConstString(kPreviousErrorProperty, |
| 225 | &previous_error_); |
| 226 | store_.RegisterConstInt32(kPreviousErrorSerialNumberProperty, |
| 227 | &previous_error_serial_number_); |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 228 | HelpRegisterDerivedInt32(kPriorityProperty, |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 229 | &Service::GetPriority, |
| 230 | &Service::SetPriority); |
Paul Stewart | d9c7cfc | 2015-01-06 14:26:22 -0800 | [diff] [blame] | 231 | HelpRegisterDerivedInt32(kPriorityWithinTechnologyProperty, |
| 232 | &Service::GetPriorityWithinTechnology, |
| 233 | &Service::SetPriorityWithinTechnology); |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 234 | HelpRegisterDerivedString(kProfileProperty, |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 235 | &Service::GetProfileRpcId, |
Paul Stewart | 1b1a7f2 | 2012-01-06 16:24:06 -0800 | [diff] [blame] | 236 | &Service::SetProfileRpcId); |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 237 | HelpRegisterDerivedString(kProxyConfigProperty, |
Philipp Neubeck | 7917360 | 2012-11-13 21:10:09 +0100 | [diff] [blame] | 238 | &Service::GetProxyConfig, |
| 239 | &Service::SetProxyConfig); |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 240 | store_.RegisterBool(kSaveCredentialsProperty, &save_credentials_); |
Paul Stewart | fa11e28 | 2013-12-02 22:04:25 -0800 | [diff] [blame] | 241 | HelpRegisterConstDerivedString(kTetheringProperty, |
| 242 | &Service::GetTethering); |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 243 | HelpRegisterDerivedString(kTypeProperty, |
Darin Petkov | 58f0b6d | 2012-06-12 12:52:30 +0200 | [diff] [blame] | 244 | &Service::CalculateTechnology, |
Ben Chan | cc225ef | 2014-09-30 13:26:51 -0700 | [diff] [blame] | 245 | nullptr); |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 246 | // kSecurityProperty: Registered in WiFiService |
| 247 | HelpRegisterDerivedString(kStateProperty, |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 248 | &Service::CalculateState, |
Ben Chan | cc225ef | 2014-09-30 13:26:51 -0700 | [diff] [blame] | 249 | nullptr); |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 250 | store_.RegisterConstUint8(kSignalStrengthProperty, &strength_); |
| 251 | store_.RegisterString(kUIDataProperty, &ui_data_); |
Ben Chan | 39a7beb | 2013-09-21 11:28:00 -0700 | [diff] [blame] | 252 | HelpRegisterConstDerivedStrings(kDiagnosticsDisconnectsProperty, |
Darin Petkov | 0c65bdd | 2012-12-05 13:42:41 +0100 | [diff] [blame] | 253 | &Service::GetDisconnectsProperty); |
Ben Chan | 39a7beb | 2013-09-21 11:28:00 -0700 | [diff] [blame] | 254 | HelpRegisterConstDerivedStrings(kDiagnosticsMisconnectsProperty, |
Darin Petkov | 0c65bdd | 2012-12-05 13:42:41 +0100 | [diff] [blame] | 255 | &Service::GetMisconnectsProperty); |
Peter Qiu | 9d58193 | 2014-04-14 16:37:37 -0700 | [diff] [blame] | 256 | store_.RegisterConstInt32(kConnectionIdProperty, &connection_id_); |
Peter Qiu | a89154b | 2014-05-23 15:45:42 -0700 | [diff] [blame] | 257 | store_.RegisterBool(kDnsAutoFallbackProperty, &is_dns_auto_fallback_allowed_); |
Peter Qiu | d49760e | 2014-09-19 16:13:42 -0700 | [diff] [blame] | 258 | store_.RegisterBool(kLinkMonitorDisableProperty, &link_monitor_disabled_); |
Paul Stewart | 3fee7e3 | 2014-10-15 21:39:29 -0700 | [diff] [blame] | 259 | store_.RegisterBool(kManagedCredentialsProperty, &managed_credentials_); |
Peter Qiu | 9d58193 | 2014-04-14 16:37:37 -0700 | [diff] [blame] | 260 | |
Paul Stewart | 45170bc | 2014-06-02 15:49:34 -0700 | [diff] [blame] | 261 | HelpRegisterObservedDerivedBool(kVisibleProperty, |
| 262 | &Service::GetVisibleProperty, |
Ben Chan | cc225ef | 2014-09-30 13:26:51 -0700 | [diff] [blame] | 263 | nullptr, |
| 264 | nullptr); |
Paul Stewart | cca85b1 | 2014-05-30 13:56:35 -0700 | [diff] [blame] | 265 | |
Peter Qiu | 9b83c89 | 2014-08-09 23:06:02 -0700 | [diff] [blame] | 266 | store_.RegisterConstString(kPortalDetectionFailedPhaseProperty, |
| 267 | &portal_detection_failure_phase_); |
| 268 | store_.RegisterConstString(kPortalDetectionFailedStatusProperty, |
| 269 | &portal_detection_failure_status_); |
| 270 | |
Wade Guthrie | 7ac610b | 2013-10-01 17:48:14 -0700 | [diff] [blame] | 271 | metrics_->RegisterService(*this); |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 272 | |
Paul Stewart | 1062d9d | 2012-04-27 10:42:27 -0700 | [diff] [blame] | 273 | static_ip_parameters_.PlumbPropertyStore(&store_); |
| 274 | |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 275 | IgnoreParameterForConfigure(kTypeProperty); |
| 276 | IgnoreParameterForConfigure(kProfileProperty); |
Paul Stewart | cb59fed | 2012-03-21 21:14:46 -0700 | [diff] [blame] | 277 | |
Darin Petkov | 9c36699 | 2013-01-10 12:32:21 +0100 | [diff] [blame] | 278 | LOG(INFO) << Technology::NameFromIdentifier(technology) << " service " |
| 279 | << unique_name_ << " constructed."; |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 280 | } |
| 281 | |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 282 | Service::~Service() { |
Wade Guthrie | 7ac610b | 2013-10-01 17:48:14 -0700 | [diff] [blame] | 283 | metrics_->DeregisterService(*this); |
mukesh agrawal | 6cfe53f | 2013-08-13 13:39:01 -0700 | [diff] [blame] | 284 | LOG(INFO) << "Service " << unique_name_ << " destroyed."; |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 285 | } |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 286 | |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 287 | void Service::AutoConnect() { |
Ben Chan | cc225ef | 2014-09-30 13:26:51 -0700 | [diff] [blame] | 288 | const char *reason = nullptr; |
Darin Petkov | 3abc3be | 2012-06-27 10:48:23 +0200 | [diff] [blame] | 289 | if (IsAutoConnectable(&reason)) { |
mukesh agrawal | dc7b844 | 2012-09-27 13:48:14 -0700 | [diff] [blame] | 290 | Error error; |
Darin Petkov | 457728b | 2013-01-09 09:49:08 +0100 | [diff] [blame] | 291 | LOG(INFO) << "Auto-connecting to service " << unique_name_; |
Christopher Wiley | 0801d19 | 2012-09-24 11:57:15 -0700 | [diff] [blame] | 292 | ThrottleFutureAutoConnects(); |
mukesh agrawal | dc7b844 | 2012-09-27 13:48:14 -0700 | [diff] [blame] | 293 | Connect(&error, __func__); |
mukesh agrawal | 76d1388 | 2012-01-12 15:23:11 -0800 | [diff] [blame] | 294 | } else { |
mukesh agrawal | 03c15ce | 2012-11-29 17:36:21 -0800 | [diff] [blame] | 295 | if (reason == kAutoConnConnected || reason == kAutoConnBusy) { |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 296 | SLOG(this, 1) |
Darin Petkov | 457728b | 2013-01-09 09:49:08 +0100 | [diff] [blame] | 297 | << "Suppressed autoconnect to service " << unique_name_ << " " |
mukesh agrawal | 03c15ce | 2012-11-29 17:36:21 -0800 | [diff] [blame] | 298 | << "(" << reason << ")"; |
| 299 | } else { |
Darin Petkov | 457728b | 2013-01-09 09:49:08 +0100 | [diff] [blame] | 300 | LOG(INFO) << "Suppressed autoconnect to service " << unique_name_ << " " |
mukesh agrawal | 03c15ce | 2012-11-29 17:36:21 -0800 | [diff] [blame] | 301 | << "(" << reason << ")"; |
| 302 | } |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 303 | } |
| 304 | } |
| 305 | |
mukesh agrawal | dc7b844 | 2012-09-27 13:48:14 -0700 | [diff] [blame] | 306 | void Service::Connect(Error */*error*/, const char *reason) { |
| 307 | LOG(INFO) << "Connect to service " << unique_name() <<": " << reason; |
Paul Stewart | 2eee613 | 2014-05-09 13:33:26 -0700 | [diff] [blame] | 308 | ClearExplicitlyDisconnected(); |
Thieu Le | af47141 | 2013-06-27 14:12:37 -0700 | [diff] [blame] | 309 | // Clear any failure state from a previous connect attempt. |
| 310 | if (state() == kStateFailure) |
| 311 | SetState(kStateIdle); |
mukesh agrawal | adb6848 | 2012-01-17 16:31:51 -0800 | [diff] [blame] | 312 | } |
| 313 | |
Samuel Tan | 0d06119 | 2014-07-07 15:45:15 -0700 | [diff] [blame] | 314 | void Service::Disconnect(Error */*error*/, const char *reason) { |
Paul Stewart | 7273735 | 2015-02-12 14:49:09 -0800 | [diff] [blame] | 315 | string log_message = base::StringPrintf( |
| 316 | "Disconnecting from service %s: %s", unique_name_.c_str(), reason); |
| 317 | if (IsActive(nullptr)) { |
| 318 | LOG(INFO) << log_message; |
| 319 | } else { |
| 320 | SLOG(this, 1) << log_message; |
| 321 | } |
mukesh agrawal | adb6848 | 2012-01-17 16:31:51 -0800 | [diff] [blame] | 322 | } |
| 323 | |
Samuel Tan | 0d06119 | 2014-07-07 15:45:15 -0700 | [diff] [blame] | 324 | void Service::DisconnectWithFailure(ConnectFailure failure, |
| 325 | Error *error, |
| 326 | const char *reason) { |
| 327 | Disconnect(error, reason); |
Christopher Wiley | abd3b50 | 2012-09-26 13:08:52 -0700 | [diff] [blame] | 328 | SetFailure(failure); |
| 329 | } |
| 330 | |
| 331 | void Service::UserInitiatedDisconnect(Error *error) { |
Samuel Tan | 0d06119 | 2014-07-07 15:45:15 -0700 | [diff] [blame] | 332 | Disconnect(error, "D-Bus RPC"); |
Christopher Wiley | abd3b50 | 2012-09-26 13:08:52 -0700 | [diff] [blame] | 333 | explicitly_disconnected_ = true; |
| 334 | } |
| 335 | |
Peter Qiu | dc4e099 | 2014-05-01 10:02:52 -0700 | [diff] [blame] | 336 | void Service::UserInitiatedConnect(Error *error) { |
| 337 | Connect(error, "D-Bus RPC"); |
| 338 | is_in_user_connect_ = true; |
| 339 | } |
| 340 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 341 | void Service::ActivateCellularModem(const string &/*carrier*/, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 342 | Error *error, |
| 343 | const ResultCallback &/*callback*/) { |
Paul Stewart | 34f424e | 2015-01-16 15:30:20 -0800 | [diff] [blame] | 344 | Error::PopulateAndLog(FROM_HERE, error, Error::kNotSupported, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 345 | "Service doesn't support cellular modem activation."); |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 346 | } |
| 347 | |
Ben Chan | 5d92454 | 2013-02-14 17:49:08 -0800 | [diff] [blame] | 348 | void Service::CompleteCellularActivation(Error *error) { |
| 349 | Error::PopulateAndLog( |
Paul Stewart | 34f424e | 2015-01-16 15:30:20 -0800 | [diff] [blame] | 350 | FROM_HERE, error, Error::kNotSupported, |
Ben Chan | 5d92454 | 2013-02-14 17:49:08 -0800 | [diff] [blame] | 351 | "Service doesn't support cellular activation completion."); |
| 352 | } |
| 353 | |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 354 | bool Service::IsActive(Error */*error*/) { |
Paul Stewart | bfb8255 | 2012-10-24 16:48:48 -0700 | [diff] [blame] | 355 | return state() != kStateUnknown && |
| 356 | state() != kStateIdle && |
| 357 | state() != kStateFailure; |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 358 | } |
| 359 | |
Darin Petkov | c8d91e5 | 2013-01-21 11:43:47 +0100 | [diff] [blame] | 360 | // static |
| 361 | bool Service::IsConnectedState(ConnectState state) { |
| 362 | return (state == kStateConnected || |
| 363 | state == kStatePortal || |
| 364 | state == kStateOnline); |
| 365 | } |
| 366 | |
| 367 | // static |
| 368 | bool Service::IsConnectingState(ConnectState state) { |
| 369 | return (state == kStateAssociating || |
| 370 | state == kStateConfiguring); |
| 371 | } |
| 372 | |
| 373 | bool Service::IsConnected() const { |
| 374 | return IsConnectedState(state()); |
| 375 | } |
| 376 | |
| 377 | bool Service::IsConnecting() const { |
| 378 | return IsConnectingState(state()); |
| 379 | } |
| 380 | |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 381 | void Service::SetState(ConnectState state) { |
| 382 | if (state == state_) { |
| 383 | return; |
| 384 | } |
| 385 | |
Darin Petkov | 457728b | 2013-01-09 09:49:08 +0100 | [diff] [blame] | 386 | LOG(INFO) << "Service " << unique_name_ << ": state " |
| 387 | << ConnectStateToString(state_) << " -> " |
| 388 | << ConnectStateToString(state); |
| 389 | |
Peter Qiu | dc4e099 | 2014-05-01 10:02:52 -0700 | [diff] [blame] | 390 | // Metric reporting for result of user-initiated connection attempt. |
| 391 | if (is_in_user_connect_ && ((state == kStateConnected) || |
| 392 | (state == kStateFailure) || (state == kStateIdle))) { |
| 393 | ReportUserInitiatedConnectionResult(state); |
| 394 | is_in_user_connect_ = false; |
| 395 | } |
| 396 | |
Darin Petkov | 0857f8e | 2012-12-21 10:49:17 +0100 | [diff] [blame] | 397 | if (state == kStateFailure) { |
Darin Petkov | 385b9bc | 2012-12-03 15:25:05 +0100 | [diff] [blame] | 398 | NoteDisconnectEvent(); |
| 399 | } |
| 400 | |
Darin Petkov | c8d91e5 | 2013-01-21 11:43:47 +0100 | [diff] [blame] | 401 | previous_state_ = state_; |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 402 | state_ = state; |
| 403 | if (state != kStateFailure) { |
| 404 | failure_ = kFailureUnknown; |
Darin Petkov | aba8932 | 2013-03-11 14:48:22 +0100 | [diff] [blame] | 405 | SetErrorDetails(kErrorDetailsNone); |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 406 | } |
mukesh agrawal | cf24a24 | 2012-05-21 16:46:11 -0700 | [diff] [blame] | 407 | if (state == kStateConnected) { |
Christopher Wiley | 0801d19 | 2012-09-24 11:57:15 -0700 | [diff] [blame] | 408 | failed_time_ = 0; |
mukesh agrawal | cf24a24 | 2012-05-21 16:46:11 -0700 | [diff] [blame] | 409 | has_ever_connected_ = true; |
| 410 | SaveToProfile(); |
Christopher Wiley | 0801d19 | 2012-09-24 11:57:15 -0700 | [diff] [blame] | 411 | // When we succeed in connecting, forget that connects failed in the past. |
| 412 | // Give services one chance at a fast autoconnect retry by resetting the |
| 413 | // cooldown to 0 to indicate that the last connect was successful. |
| 414 | auto_connect_cooldown_milliseconds_ = 0; |
| 415 | reenable_auto_connect_task_.Cancel(); |
mukesh agrawal | cf24a24 | 2012-05-21 16:46:11 -0700 | [diff] [blame] | 416 | } |
Paul Stewart | f2d6091 | 2012-07-15 08:37:30 -0700 | [diff] [blame] | 417 | UpdateErrorProperty(); |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 418 | manager_->UpdateService(this); |
Wade Guthrie | 7ac610b | 2013-10-01 17:48:14 -0700 | [diff] [blame] | 419 | metrics_->NotifyServiceStateChanged(*this, state); |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 420 | adaptor_->EmitStringChanged(kStateProperty, GetStateString()); |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 421 | } |
| 422 | |
Peter Qiu | 9b83c89 | 2014-08-09 23:06:02 -0700 | [diff] [blame] | 423 | void Service::SetPortalDetectionFailure(const string &phase, |
| 424 | const string &status) { |
| 425 | portal_detection_failure_phase_ = phase; |
| 426 | portal_detection_failure_status_ = status; |
| 427 | adaptor_->EmitStringChanged(kPortalDetectionFailedPhaseProperty, phase); |
| 428 | adaptor_->EmitStringChanged(kPortalDetectionFailedStatusProperty, status); |
| 429 | } |
| 430 | |
Christopher Wiley | 0801d19 | 2012-09-24 11:57:15 -0700 | [diff] [blame] | 431 | void Service::ReEnableAutoConnectTask() { |
| 432 | // Kill the thing blocking AutoConnect(). |
| 433 | reenable_auto_connect_task_.Cancel(); |
| 434 | // Post to the manager, giving it an opportunity to AutoConnect again. |
| 435 | manager_->UpdateService(this); |
| 436 | } |
| 437 | |
| 438 | void Service::ThrottleFutureAutoConnects() { |
| 439 | if (auto_connect_cooldown_milliseconds_ > 0) { |
mukesh agrawal | dc7b844 | 2012-09-27 13:48:14 -0700 | [diff] [blame] | 440 | LOG(INFO) << "Throttling future autoconnects to service " << unique_name_ |
| 441 | << ". Next autoconnect in " |
Christopher Wiley | 0801d19 | 2012-09-24 11:57:15 -0700 | [diff] [blame] | 442 | << auto_connect_cooldown_milliseconds_ << " milliseconds."; |
| 443 | reenable_auto_connect_task_.Reset(Bind(&Service::ReEnableAutoConnectTask, |
| 444 | weak_ptr_factory_.GetWeakPtr())); |
| 445 | dispatcher_->PostDelayedTask(reenable_auto_connect_task_.callback(), |
| 446 | auto_connect_cooldown_milliseconds_); |
| 447 | } |
| 448 | auto_connect_cooldown_milliseconds_ = |
| 449 | std::min(kMaxAutoConnectCooldownTimeMilliseconds, |
| 450 | std::max(kMinAutoConnectCooldownTimeMilliseconds, |
| 451 | auto_connect_cooldown_milliseconds_ * |
| 452 | kAutoConnectCooldownBackoffFactor)); |
| 453 | } |
| 454 | |
Paul Stewart | d7c09a5 | 2014-02-19 12:50:29 -0800 | [diff] [blame] | 455 | void Service::SaveFailure() { |
| 456 | previous_error_ = ConnectFailureToString(failure_); |
| 457 | ++previous_error_serial_number_; |
| 458 | } |
| 459 | |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 460 | void Service::SetFailure(ConnectFailure failure) { |
| 461 | failure_ = failure; |
Paul Stewart | d7c09a5 | 2014-02-19 12:50:29 -0800 | [diff] [blame] | 462 | SaveFailure(); |
Ben Chan | cc225ef | 2014-09-30 13:26:51 -0700 | [diff] [blame] | 463 | failed_time_ = time(nullptr); |
Paul Stewart | f2d6091 | 2012-07-15 08:37:30 -0700 | [diff] [blame] | 464 | UpdateErrorProperty(); |
Paul Stewart | 03dba0b | 2011-08-22 16:32:45 -0700 | [diff] [blame] | 465 | SetState(kStateFailure); |
| 466 | } |
| 467 | |
mukesh agrawal | 568b5c6 | 2012-02-28 14:44:47 -0800 | [diff] [blame] | 468 | void Service::SetFailureSilent(ConnectFailure failure) { |
Darin Petkov | 0857f8e | 2012-12-21 10:49:17 +0100 | [diff] [blame] | 469 | NoteDisconnectEvent(); |
mukesh agrawal | 568b5c6 | 2012-02-28 14:44:47 -0800 | [diff] [blame] | 470 | // Note that order matters here, since SetState modifies |failure_| and |
| 471 | // |failed_time_|. |
| 472 | SetState(kStateIdle); |
| 473 | failure_ = failure; |
Paul Stewart | d7c09a5 | 2014-02-19 12:50:29 -0800 | [diff] [blame] | 474 | SaveFailure(); |
Paul Stewart | f2d6091 | 2012-07-15 08:37:30 -0700 | [diff] [blame] | 475 | UpdateErrorProperty(); |
Ben Chan | cc225ef | 2014-09-30 13:26:51 -0700 | [diff] [blame] | 476 | failed_time_ = time(nullptr); |
mukesh agrawal | 568b5c6 | 2012-02-28 14:44:47 -0800 | [diff] [blame] | 477 | } |
| 478 | |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 479 | string Service::GetRpcIdentifier() const { |
Chris Masone | 3c3f6a1 | 2011-07-01 10:01:41 -0700 | [diff] [blame] | 480 | return adaptor_->GetRpcIdentifier(); |
| 481 | } |
| 482 | |
Paul Stewart | e7de294 | 2013-04-25 17:07:31 -0700 | [diff] [blame] | 483 | string Service::GetLoadableStorageIdentifier( |
| 484 | const StoreInterface &storage) const { |
| 485 | return IsLoadableFrom(storage) ? GetStorageIdentifier() : ""; |
| 486 | } |
| 487 | |
| 488 | bool Service::IsLoadableFrom(const StoreInterface &storage) const { |
| 489 | return storage.ContainsGroup(GetStorageIdentifier()); |
Paul Stewart | bba6a5b | 2011-11-02 18:45:59 -0700 | [diff] [blame] | 490 | } |
| 491 | |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 492 | bool Service::Load(StoreInterface *storage) { |
| 493 | const string id = GetStorageIdentifier(); |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 494 | if (!storage->ContainsGroup(id)) { |
| 495 | LOG(WARNING) << "Service is not available in the persistent store: " << id; |
| 496 | return false; |
| 497 | } |
Paul Stewart | 2da34c0 | 2013-10-17 15:28:56 -0700 | [diff] [blame] | 498 | |
Paul Stewart | 000f033 | 2013-10-25 13:30:28 -0700 | [diff] [blame] | 499 | auto_connect_ = IsAutoConnectByDefault(); |
Paul Stewart | 2da34c0 | 2013-10-17 15:28:56 -0700 | [diff] [blame] | 500 | retain_auto_connect_ = |
| 501 | storage->GetBool(id, kStorageAutoConnect, &auto_connect_); |
| 502 | // The legacy "Favorite" flag will override retain_auto_connect_ if present. |
| 503 | storage->GetBool(id, kStorageFavorite, &retain_auto_connect_); |
| 504 | |
Paul Stewart | c3dbff1 | 2013-07-17 10:32:48 -0700 | [diff] [blame] | 505 | LoadString(storage, id, kStorageCheckPortal, kCheckPortalAuto, |
| 506 | &check_portal_); |
Paul Stewart | c3dbff1 | 2013-07-17 10:32:48 -0700 | [diff] [blame] | 507 | LoadString(storage, id, kStorageGUID, "", &guid_); |
Paul Stewart | c3dbff1 | 2013-07-17 10:32:48 -0700 | [diff] [blame] | 508 | if (!storage->GetInt(id, kStoragePriority, &priority_)) { |
| 509 | priority_ = kPriorityNone; |
| 510 | } |
Paul Stewart | d9c7cfc | 2015-01-06 14:26:22 -0800 | [diff] [blame] | 511 | if (!storage->GetInt(id, kStoragePriorityWithinTechnology, |
| 512 | &priority_within_technology_)) { |
| 513 | priority_within_technology_ = kPriorityNone; |
| 514 | } |
Paul Stewart | c3dbff1 | 2013-07-17 10:32:48 -0700 | [diff] [blame] | 515 | LoadString(storage, id, kStorageProxyConfig, "", &proxy_config_); |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 516 | storage->GetBool(id, kStorageSaveCredentials, &save_credentials_); |
Paul Stewart | c3dbff1 | 2013-07-17 10:32:48 -0700 | [diff] [blame] | 517 | LoadString(storage, id, kStorageUIData, "", &ui_data_); |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 518 | |
Peter Qiu | 9d58193 | 2014-04-14 16:37:37 -0700 | [diff] [blame] | 519 | storage->GetInt(id, kStorageConnectionId, &connection_id_); |
Peter Qiu | a89154b | 2014-05-23 15:45:42 -0700 | [diff] [blame] | 520 | storage->GetBool(id, kStorageDNSAutoFallback, &is_dns_auto_fallback_allowed_); |
Peter Qiu | d49760e | 2014-09-19 16:13:42 -0700 | [diff] [blame] | 521 | storage->GetBool(id, kStorageLinkMonitorDisabled, &link_monitor_disabled_); |
Paul Stewart | 3fee7e3 | 2014-10-15 21:39:29 -0700 | [diff] [blame] | 522 | if (!storage->GetBool(id, kStorageManagedCredentials, |
| 523 | &managed_credentials_)) { |
| 524 | managed_credentials_ = false; |
| 525 | } |
Paul Stewart | dded007 | 2013-10-24 12:38:54 -0700 | [diff] [blame] | 526 | |
Paul Stewart | 1062d9d | 2012-04-27 10:42:27 -0700 | [diff] [blame] | 527 | static_ip_parameters_.Load(storage, id); |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 528 | |
Rebecca Silberstein | 5777690 | 2014-09-15 21:43:02 -0700 | [diff] [blame] | 529 | // Call OnEapCredentialsChanged with kReasonCredentialsLoaded to avoid |
| 530 | // resetting the has_ever_connected value. |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 531 | if (mutable_eap()) { |
| 532 | mutable_eap()->Load(storage, id); |
Rebecca Silberstein | 5777690 | 2014-09-15 21:43:02 -0700 | [diff] [blame] | 533 | OnEapCredentialsChanged(kReasonCredentialsLoaded); |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 534 | } |
| 535 | |
Paul Stewart | 2eee613 | 2014-05-09 13:33:26 -0700 | [diff] [blame] | 536 | ClearExplicitlyDisconnected(); |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 537 | |
Rebecca Silberstein | 73dd0dc | 2014-08-07 16:44:23 -0700 | [diff] [blame] | 538 | // Read has_ever_connected_ value from stored profile |
| 539 | // now that the credentials have been loaded. |
| 540 | storage->GetBool(id, kStorageHasEverConnected, &has_ever_connected_); |
| 541 | |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 542 | return true; |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 543 | } |
| 544 | |
Paul Stewart | 65512e1 | 2012-03-26 18:01:08 -0700 | [diff] [blame] | 545 | bool Service::Unload() { |
Paul Stewart | 7fb0938 | 2012-07-18 17:32:27 -0700 | [diff] [blame] | 546 | auto_connect_ = IsAutoConnectByDefault(); |
Paul Stewart | 2da34c0 | 2013-10-17 15:28:56 -0700 | [diff] [blame] | 547 | retain_auto_connect_ = false; |
Paul Stewart | d8ad3c4 | 2012-01-09 12:39:38 -0800 | [diff] [blame] | 548 | check_portal_ = kCheckPortalAuto; |
Paul Stewart | 2eee613 | 2014-05-09 13:33:26 -0700 | [diff] [blame] | 549 | ClearExplicitlyDisconnected(); |
Paul Stewart | e7cce8f | 2012-09-11 10:56:38 -0700 | [diff] [blame] | 550 | guid_ = ""; |
Paul Stewart | 88769de | 2012-09-21 13:14:36 -0700 | [diff] [blame] | 551 | has_ever_connected_ = false; |
Paul Stewart | d8ad3c4 | 2012-01-09 12:39:38 -0800 | [diff] [blame] | 552 | priority_ = kPriorityNone; |
Paul Stewart | d9c7cfc | 2015-01-06 14:26:22 -0800 | [diff] [blame] | 553 | priority_within_technology_ = kPriorityNone; |
Paul Stewart | d8ad3c4 | 2012-01-09 12:39:38 -0800 | [diff] [blame] | 554 | proxy_config_ = ""; |
| 555 | save_credentials_ = true; |
| 556 | ui_data_ = ""; |
Peter Qiu | a89154b | 2014-05-23 15:45:42 -0700 | [diff] [blame] | 557 | connection_id_ = 0; |
| 558 | is_dns_auto_fallback_allowed_ = false; |
Peter Qiu | d49760e | 2014-09-19 16:13:42 -0700 | [diff] [blame] | 559 | link_monitor_disabled_ = false; |
Paul Stewart | 3fee7e3 | 2014-10-15 21:39:29 -0700 | [diff] [blame] | 560 | managed_credentials_ = false; |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 561 | if (mutable_eap()) { |
| 562 | mutable_eap()->Reset(); |
| 563 | } |
| 564 | ClearEAPCertification(); |
Paul Stewart | d8ad3c4 | 2012-01-09 12:39:38 -0800 | [diff] [blame] | 565 | |
Wade Guthrie | 9e0c250 | 2012-04-19 15:26:40 -0700 | [diff] [blame] | 566 | Error error; // Ignored. |
Samuel Tan | 0d06119 | 2014-07-07 15:45:15 -0700 | [diff] [blame] | 567 | Disconnect(&error, __func__); |
Paul Stewart | 65512e1 | 2012-03-26 18:01:08 -0700 | [diff] [blame] | 568 | return false; |
Paul Stewart | a41e38d | 2011-11-11 07:47:29 -0800 | [diff] [blame] | 569 | } |
| 570 | |
Albert Chaulk | 0e1cdea | 2013-02-27 15:32:55 -0800 | [diff] [blame] | 571 | void Service::Remove(Error */*error*/) { |
Paul Stewart | d3d0388 | 2013-08-29 15:43:42 -0700 | [diff] [blame] | 572 | manager()->RemoveService(this); |
| 573 | // |this| may no longer be valid now. |
Albert Chaulk | 0e1cdea | 2013-02-27 15:32:55 -0800 | [diff] [blame] | 574 | } |
| 575 | |
Chris Masone | 9d77993 | 2011-08-25 16:33:41 -0700 | [diff] [blame] | 576 | bool Service::Save(StoreInterface *storage) { |
| 577 | const string id = GetStorageIdentifier(); |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 578 | |
Darin Petkov | 58f0b6d | 2012-06-12 12:52:30 +0200 | [diff] [blame] | 579 | storage->SetString(id, kStorageType, GetTechnologyString()); |
Paul Stewart | 2706aaf | 2011-12-14 16:44:04 -0800 | [diff] [blame] | 580 | |
Paul Stewart | 2da34c0 | 2013-10-17 15:28:56 -0700 | [diff] [blame] | 581 | if (retain_auto_connect_) { |
| 582 | storage->SetBool(id, kStorageAutoConnect, auto_connect_); |
| 583 | } else { |
| 584 | storage->DeleteKey(id, kStorageAutoConnect); |
| 585 | } |
| 586 | |
| 587 | // Remove this legacy flag. |
| 588 | storage->DeleteKey(id, kStorageFavorite); |
| 589 | |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 590 | if (check_portal_ == kCheckPortalAuto) { |
| 591 | storage->DeleteKey(id, kStorageCheckPortal); |
| 592 | } else { |
| 593 | storage->SetString(id, kStorageCheckPortal, check_portal_); |
| 594 | } |
Paul Stewart | 2da34c0 | 2013-10-17 15:28:56 -0700 | [diff] [blame] | 595 | |
mukesh agrawal | cf24a24 | 2012-05-21 16:46:11 -0700 | [diff] [blame] | 596 | SaveString(storage, id, kStorageGUID, guid_, false, true); |
| 597 | storage->SetBool(id, kStorageHasEverConnected, has_ever_connected_); |
mukesh agrawal | d835b20 | 2011-10-07 15:26:47 -0700 | [diff] [blame] | 598 | storage->SetString(id, kStorageName, friendly_name_); |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 599 | if (priority_ != kPriorityNone) { |
| 600 | storage->SetInt(id, kStoragePriority, priority_); |
| 601 | } else { |
| 602 | storage->DeleteKey(id, kStoragePriority); |
| 603 | } |
Paul Stewart | d9c7cfc | 2015-01-06 14:26:22 -0800 | [diff] [blame] | 604 | if (priority_within_technology_ != kPriorityNone) { |
| 605 | storage->SetInt(id, kStoragePriorityWithinTechnology, |
| 606 | priority_within_technology_); |
| 607 | } else { |
| 608 | storage->DeleteKey(id, kStoragePriorityWithinTechnology); |
| 609 | } |
Paul Stewart | 987e71e | 2011-12-05 09:45:06 -0800 | [diff] [blame] | 610 | SaveString(storage, id, kStorageProxyConfig, proxy_config_, false, true); |
Darin Petkov | 0debec0 | 2013-01-22 10:40:05 +0100 | [diff] [blame] | 611 | storage->SetBool(id, kStorageSaveCredentials, save_credentials_); |
Paul Stewart | 987e71e | 2011-12-05 09:45:06 -0800 | [diff] [blame] | 612 | SaveString(storage, id, kStorageUIData, ui_data_, false, true); |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 613 | |
Peter Qiu | 9d58193 | 2014-04-14 16:37:37 -0700 | [diff] [blame] | 614 | storage->SetInt(id, kStorageConnectionId, connection_id_); |
Peter Qiu | a89154b | 2014-05-23 15:45:42 -0700 | [diff] [blame] | 615 | storage->SetBool(id, kStorageDNSAutoFallback, is_dns_auto_fallback_allowed_); |
Peter Qiu | d49760e | 2014-09-19 16:13:42 -0700 | [diff] [blame] | 616 | storage->SetBool(id, kStorageLinkMonitorDisabled, link_monitor_disabled_); |
Paul Stewart | 3fee7e3 | 2014-10-15 21:39:29 -0700 | [diff] [blame] | 617 | storage->SetBool(id, kStorageManagedCredentials, managed_credentials_); |
Paul Stewart | dded007 | 2013-10-24 12:38:54 -0700 | [diff] [blame] | 618 | |
Paul Stewart | 1062d9d | 2012-04-27 10:42:27 -0700 | [diff] [blame] | 619 | static_ip_parameters_.Save(storage, id); |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 620 | if (eap()) { |
| 621 | eap()->Save(storage, id, save_credentials_); |
| 622 | } |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 623 | return true; |
| 624 | } |
| 625 | |
Gary Morain | d93615e | 2012-04-27 11:50:03 -0700 | [diff] [blame] | 626 | void Service::SaveToCurrentProfile() { |
| 627 | // Some unittests do not specify a manager. |
| 628 | if (manager()) { |
| 629 | manager()->SaveServiceToProfile(this); |
| 630 | } |
Thieu Le | d4e9e55 | 2012-02-16 16:26:07 -0800 | [diff] [blame] | 631 | } |
| 632 | |
Paul Stewart | cb59fed | 2012-03-21 21:14:46 -0700 | [diff] [blame] | 633 | void Service::Configure(const KeyValueStore &args, Error *error) { |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 634 | SLOG(this, 5) << "Configuring bool properties:"; |
Paul Stewart | 99dc9f3 | 2013-06-27 07:39:25 -0700 | [diff] [blame] | 635 | for (const auto &bool_it : args.bool_properties()) { |
| 636 | if (ContainsKey(parameters_ignored_for_configure_, bool_it.first)) { |
Paul Stewart | cb59fed | 2012-03-21 21:14:46 -0700 | [diff] [blame] | 637 | continue; |
| 638 | } |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 639 | SLOG(this, 5) << " " << bool_it.first; |
Paul Stewart | cb59fed | 2012-03-21 21:14:46 -0700 | [diff] [blame] | 640 | Error set_error; |
Paul Stewart | 99dc9f3 | 2013-06-27 07:39:25 -0700 | [diff] [blame] | 641 | store_.SetBoolProperty(bool_it.first, bool_it.second, &set_error); |
Paul Stewart | cb59fed | 2012-03-21 21:14:46 -0700 | [diff] [blame] | 642 | if (error->IsSuccess() && set_error.IsFailure()) { |
| 643 | error->CopyFrom(set_error); |
| 644 | } |
| 645 | } |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 646 | SLOG(this, 5) << "Configuring int32_t properties:"; |
Paul Stewart | 99dc9f3 | 2013-06-27 07:39:25 -0700 | [diff] [blame] | 647 | for (const auto &int_it : args.int_properties()) { |
| 648 | if (ContainsKey(parameters_ignored_for_configure_, int_it.first)) { |
Paul Stewart | cb59fed | 2012-03-21 21:14:46 -0700 | [diff] [blame] | 649 | continue; |
| 650 | } |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 651 | SLOG(this, 5) << " " << int_it.first; |
Paul Stewart | cb59fed | 2012-03-21 21:14:46 -0700 | [diff] [blame] | 652 | Error set_error; |
Paul Stewart | 99dc9f3 | 2013-06-27 07:39:25 -0700 | [diff] [blame] | 653 | store_.SetInt32Property(int_it.first, int_it.second, &set_error); |
Paul Stewart | 99dc9f3 | 2013-06-27 07:39:25 -0700 | [diff] [blame] | 654 | if (error->IsSuccess() && set_error.IsFailure()) { |
| 655 | error->CopyFrom(set_error); |
| 656 | } |
| 657 | } |
Paul Stewart | bb83356 | 2015-01-21 23:30:46 -0800 | [diff] [blame] | 658 | SLOG(this, 5) << "Configuring key value store properties:"; |
| 659 | for (const auto &key_value_it : args.key_value_store_properties()) { |
| 660 | if (ContainsKey(parameters_ignored_for_configure_, key_value_it.first)) { |
| 661 | continue; |
| 662 | } |
| 663 | SLOG(this, 5) << " " << key_value_it.first; |
| 664 | Error set_error; |
| 665 | store_.SetKeyValueStoreProperty(key_value_it.first, |
| 666 | key_value_it.second, &set_error); |
| 667 | if (error->IsSuccess() && set_error.IsFailure()) { |
| 668 | error->CopyFrom(set_error); |
| 669 | } |
| 670 | } |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 671 | SLOG(this, 5) << "Configuring string properties:"; |
Paul Stewart | 99dc9f3 | 2013-06-27 07:39:25 -0700 | [diff] [blame] | 672 | for (const auto &string_it : args.string_properties()) { |
| 673 | if (ContainsKey(parameters_ignored_for_configure_, string_it.first)) { |
| 674 | continue; |
| 675 | } |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 676 | SLOG(this, 5) << " " << string_it.first; |
Paul Stewart | 99dc9f3 | 2013-06-27 07:39:25 -0700 | [diff] [blame] | 677 | Error set_error; |
| 678 | store_.SetStringProperty(string_it.first, string_it.second, &set_error); |
Paul Stewart | 99dc9f3 | 2013-06-27 07:39:25 -0700 | [diff] [blame] | 679 | if (error->IsSuccess() && set_error.IsFailure()) { |
| 680 | error->CopyFrom(set_error); |
| 681 | } |
| 682 | } |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 683 | SLOG(this, 5) << "Configuring string array properties:"; |
Paul Stewart | 99dc9f3 | 2013-06-27 07:39:25 -0700 | [diff] [blame] | 684 | for (const auto &strings_it : args.strings_properties()) { |
| 685 | if (ContainsKey(parameters_ignored_for_configure_, strings_it.first)) { |
| 686 | continue; |
| 687 | } |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 688 | SLOG(this, 5) << " " << strings_it.first; |
Paul Stewart | 99dc9f3 | 2013-06-27 07:39:25 -0700 | [diff] [blame] | 689 | Error set_error; |
| 690 | store_.SetStringsProperty(strings_it.first, strings_it.second, &set_error); |
Paul Stewart | cb59fed | 2012-03-21 21:14:46 -0700 | [diff] [blame] | 691 | if (error->IsSuccess() && set_error.IsFailure()) { |
| 692 | error->CopyFrom(set_error); |
| 693 | } |
| 694 | } |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 695 | SLOG(this, 5) << "Configuring string map properties:"; |
Arman Uguray | 631c7e4 | 2013-07-30 16:41:12 -0700 | [diff] [blame] | 696 | for (const auto &stringmap_it : args.stringmap_properties()) { |
| 697 | if (ContainsKey(parameters_ignored_for_configure_, stringmap_it.first)) { |
| 698 | continue; |
| 699 | } |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 700 | SLOG(this, 5) << " " << stringmap_it.first; |
Arman Uguray | 631c7e4 | 2013-07-30 16:41:12 -0700 | [diff] [blame] | 701 | Error set_error; |
| 702 | store_.SetStringmapProperty( |
| 703 | stringmap_it.first, stringmap_it.second, &set_error); |
Arman Uguray | 631c7e4 | 2013-07-30 16:41:12 -0700 | [diff] [blame] | 704 | if (error->IsSuccess() && set_error.IsFailure()) { |
| 705 | error->CopyFrom(set_error); |
| 706 | } |
| 707 | } |
Paul Stewart | cb59fed | 2012-03-21 21:14:46 -0700 | [diff] [blame] | 708 | } |
| 709 | |
Paul Stewart | 7a20aa4 | 2013-01-17 12:21:41 -0800 | [diff] [blame] | 710 | bool Service::DoPropertiesMatch(const KeyValueStore &args) const { |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 711 | SLOG(this, 5) << "Checking bool properties:"; |
Alex Vakulenko | 8a53229 | 2014-06-16 17:18:44 -0700 | [diff] [blame] | 712 | for (const auto &bool_it : args.bool_properties()) { |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 713 | SLOG(this, 5) << " " << bool_it.first; |
Paul Stewart | 7a20aa4 | 2013-01-17 12:21:41 -0800 | [diff] [blame] | 714 | Error get_error; |
| 715 | bool value; |
Paul Stewart | 99dc9f3 | 2013-06-27 07:39:25 -0700 | [diff] [blame] | 716 | if (!store_.GetBoolProperty(bool_it.first, &value, &get_error) || |
| 717 | value != bool_it.second) { |
Paul Stewart | 7a20aa4 | 2013-01-17 12:21:41 -0800 | [diff] [blame] | 718 | return false; |
| 719 | } |
| 720 | } |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 721 | SLOG(this, 5) << "Checking int32_t properties:"; |
Paul Stewart | 99dc9f3 | 2013-06-27 07:39:25 -0700 | [diff] [blame] | 722 | for (const auto &int_it : args.int_properties()) { |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 723 | SLOG(this, 5) << " " << int_it.first; |
Paul Stewart | 7a20aa4 | 2013-01-17 12:21:41 -0800 | [diff] [blame] | 724 | Error get_error; |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 725 | int32_t value; |
Paul Stewart | 99dc9f3 | 2013-06-27 07:39:25 -0700 | [diff] [blame] | 726 | if (!store_.GetInt32Property(int_it.first, &value, &get_error) || |
| 727 | value != int_it.second) { |
| 728 | return false; |
| 729 | } |
| 730 | } |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 731 | SLOG(this, 5) << "Checking string properties:"; |
Paul Stewart | 99dc9f3 | 2013-06-27 07:39:25 -0700 | [diff] [blame] | 732 | for (const auto &string_it : args.string_properties()) { |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 733 | SLOG(this, 5) << " " << string_it.first; |
Paul Stewart | 99dc9f3 | 2013-06-27 07:39:25 -0700 | [diff] [blame] | 734 | Error get_error; |
| 735 | string value; |
| 736 | if (!store_.GetStringProperty(string_it.first, &value, &get_error) || |
| 737 | value != string_it.second) { |
| 738 | return false; |
| 739 | } |
| 740 | } |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 741 | SLOG(this, 5) << "Checking string array properties:"; |
Paul Stewart | 99dc9f3 | 2013-06-27 07:39:25 -0700 | [diff] [blame] | 742 | for (const auto &strings_it : args.strings_properties()) { |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 743 | SLOG(this, 5) << " " << strings_it.first; |
Paul Stewart | 99dc9f3 | 2013-06-27 07:39:25 -0700 | [diff] [blame] | 744 | Error get_error; |
| 745 | vector<string> value; |
| 746 | if (!store_.GetStringsProperty(strings_it.first, &value, &get_error) || |
| 747 | value != strings_it.second) { |
Paul Stewart | 7a20aa4 | 2013-01-17 12:21:41 -0800 | [diff] [blame] | 748 | return false; |
| 749 | } |
| 750 | } |
Paul Stewart | bb83356 | 2015-01-21 23:30:46 -0800 | [diff] [blame] | 751 | SLOG(this, 5) << "Checking key value store properties:"; |
| 752 | for (const auto &key_value_it : args.key_value_store_properties()) { |
| 753 | SLOG(this, 5) << " " << key_value_it.first; |
| 754 | Error get_error; |
| 755 | KeyValueStore value; |
| 756 | if (!store_.GetKeyValueStoreProperty( |
| 757 | key_value_it.first, &value, &get_error) || |
| 758 | !value.Equals(key_value_it.second)) { |
| 759 | return false; |
| 760 | } |
| 761 | } |
Paul Stewart | 7a20aa4 | 2013-01-17 12:21:41 -0800 | [diff] [blame] | 762 | return true; |
| 763 | } |
| 764 | |
Paul Stewart | 10ccbb3 | 2012-04-26 15:59:30 -0700 | [diff] [blame] | 765 | bool Service::IsRemembered() const { |
| 766 | return profile_ && !manager_->IsServiceEphemeral(this); |
| 767 | } |
| 768 | |
Paul Stewart | df3c0a8 | 2012-11-09 15:54:33 -0800 | [diff] [blame] | 769 | bool Service::IsDependentOn(const ServiceRefPtr &b) const { |
Paul Stewart | cd7f585 | 2013-03-27 13:54:23 -0700 | [diff] [blame] | 770 | if (!connection_ || !b || !b->connection()) { |
Paul Stewart | df3c0a8 | 2012-11-09 15:54:33 -0800 | [diff] [blame] | 771 | return false; |
| 772 | } |
| 773 | return connection_->GetLowerConnection() == b->connection(); |
| 774 | } |
| 775 | |
Paul Stewart | 2da34c0 | 2013-10-17 15:28:56 -0700 | [diff] [blame] | 776 | void Service::EnableAndRetainAutoConnect() { |
| 777 | if (retain_auto_connect_) { |
mukesh agrawal | 00917ce | 2011-11-22 23:56:55 +0000 | [diff] [blame] | 778 | // We do not want to clobber the value of auto_connect_ (it may |
| 779 | // be user-set). So return early. |
| 780 | return; |
| 781 | } |
| 782 | |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 783 | SetAutoConnect(true); |
Paul Stewart | 2da34c0 | 2013-10-17 15:28:56 -0700 | [diff] [blame] | 784 | RetainAutoConnect(); |
mukesh agrawal | 00917ce | 2011-11-22 23:56:55 +0000 | [diff] [blame] | 785 | } |
| 786 | |
Darin Petkov | 5eb0542 | 2012-05-11 15:45:25 +0200 | [diff] [blame] | 787 | void Service::SetConnection(const ConnectionRefPtr &connection) { |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 788 | if (connection.get()) { |
Paul Stewart | 1e3bc496 | 2012-09-14 12:20:22 -0700 | [diff] [blame] | 789 | // TODO(pstew): Make this function testable by using a factory here. |
Paul Stewart | ee6b3d7 | 2013-07-12 16:07:51 -0700 | [diff] [blame] | 790 | // http://crbug.com/216664 |
Paul Stewart | c8f4bef | 2011-12-13 09:45:51 -0800 | [diff] [blame] | 791 | http_proxy_.reset(new HTTPProxy(connection)); |
Darin Petkov | 5eb0542 | 2012-05-11 15:45:25 +0200 | [diff] [blame] | 792 | http_proxy_->Start(dispatcher_, sockets_.get()); |
Paul Stewart | 7f5d9c0 | 2013-12-03 18:26:00 -0800 | [diff] [blame] | 793 | Error unused_error; |
| 794 | connection->set_tethering(GetTethering(&unused_error)); |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 795 | } else { |
| 796 | http_proxy_.reset(); |
Paul Stewart | def189e | 2012-08-02 20:12:09 -0700 | [diff] [blame] | 797 | static_ip_parameters_.ClearSavedParameters(); |
Paul Stewart | c1dec4d | 2011-12-08 15:25:28 -0800 | [diff] [blame] | 798 | } |
| 799 | connection_ = connection; |
Peter Qiu | a89154b | 2014-05-23 15:45:42 -0700 | [diff] [blame] | 800 | NotifyIPConfigChanges(); |
| 801 | } |
| 802 | |
| 803 | void Service::NotifyIPConfigChanges() { |
Paul Stewart | 1e3bc496 | 2012-09-14 12:20:22 -0700 | [diff] [blame] | 804 | Error error; |
| 805 | string ipconfig = GetIPConfigRpcIdentifier(&error); |
| 806 | if (error.IsSuccess()) { |
Ben Chan | 39a7beb | 2013-09-21 11:28:00 -0700 | [diff] [blame] | 807 | adaptor_->EmitRpcIdentifierChanged(kIPConfigProperty, ipconfig); |
Paul Stewart | 1e3bc496 | 2012-09-14 12:20:22 -0700 | [diff] [blame] | 808 | } |
Paul Stewart | be5f5b3 | 2011-12-07 17:11:11 -0800 | [diff] [blame] | 809 | } |
| 810 | |
Gaurav Shah | 10109f2 | 2011-11-11 20:16:22 -0800 | [diff] [blame] | 811 | bool Service::Is8021xConnectable() const { |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 812 | return eap() && eap()->IsConnectable(); |
Gaurav Shah | 10109f2 | 2011-11-11 20:16:22 -0800 | [diff] [blame] | 813 | } |
| 814 | |
Paul Stewart | bc6e739 | 2012-05-24 07:07:48 -0700 | [diff] [blame] | 815 | bool Service::AddEAPCertification(const string &name, size_t depth) { |
| 816 | if (depth >= kEAPMaxCertificationElements) { |
| 817 | LOG(WARNING) << "Ignoring certification " << name |
| 818 | << " because depth " << depth |
| 819 | << " exceeds our maximum of " |
| 820 | << kEAPMaxCertificationElements; |
| 821 | return false; |
| 822 | } |
| 823 | |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 824 | if (depth >= remote_certification_.size()) { |
| 825 | remote_certification_.resize(depth + 1); |
| 826 | } else if (name == remote_certification_[depth]) { |
Paul Stewart | bc6e739 | 2012-05-24 07:07:48 -0700 | [diff] [blame] | 827 | return true; |
| 828 | } |
| 829 | |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 830 | remote_certification_[depth] = name; |
Paul Stewart | bc6e739 | 2012-05-24 07:07:48 -0700 | [diff] [blame] | 831 | LOG(INFO) << "Received certification for " |
| 832 | << name |
| 833 | << " at depth " |
| 834 | << depth; |
| 835 | return true; |
| 836 | } |
| 837 | |
| 838 | void Service::ClearEAPCertification() { |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 839 | remote_certification_.clear(); |
Paul Stewart | bc6e739 | 2012-05-24 07:07:48 -0700 | [diff] [blame] | 840 | } |
| 841 | |
Paul Stewart | 316acef | 2014-05-29 18:40:48 -0700 | [diff] [blame] | 842 | bool Service::HasStaticIPAddress() const { |
| 843 | return static_ip_parameters().ContainsAddress(); |
| 844 | } |
| 845 | |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 846 | void Service::SetAutoConnect(bool connect) { |
| 847 | if (auto_connect() == connect) { |
| 848 | return; |
| 849 | } |
| 850 | auto_connect_ = connect; |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 851 | adaptor_->EmitBoolChanged(kAutoConnectProperty, auto_connect()); |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 852 | } |
| 853 | |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 854 | void Service::SetEapCredentials(EapCredentials *eap) { |
| 855 | // This operation must be done at most once for the lifetime of the service. |
| 856 | CHECK(eap && !eap_); |
| 857 | |
| 858 | eap_.reset(eap); |
| 859 | eap_->InitPropertyStore(mutable_store()); |
Gaurav Shah | 10109f2 | 2011-11-11 20:16:22 -0800 | [diff] [blame] | 860 | } |
| 861 | |
mukesh agrawal | 00917ce | 2011-11-22 23:56:55 +0000 | [diff] [blame] | 862 | // static |
Gaurav Shah | c6d6c72 | 2011-11-17 18:59:39 -0800 | [diff] [blame] | 863 | const char *Service::ConnectFailureToString(const ConnectFailure &state) { |
| 864 | switch (state) { |
| 865 | case kFailureUnknown: |
| 866 | return "Unknown"; |
Paul Stewart | f2d6091 | 2012-07-15 08:37:30 -0700 | [diff] [blame] | 867 | case kFailureAAA: |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 868 | return kErrorAaaFailed; |
Paul Stewart | f2d6091 | 2012-07-15 08:37:30 -0700 | [diff] [blame] | 869 | case kFailureActivation: |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 870 | return kErrorActivationFailed; |
Paul Stewart | f2d6091 | 2012-07-15 08:37:30 -0700 | [diff] [blame] | 871 | case kFailureBadPassphrase: |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 872 | return kErrorBadPassphrase; |
Paul Stewart | f2d6091 | 2012-07-15 08:37:30 -0700 | [diff] [blame] | 873 | case kFailureBadWEPKey: |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 874 | return kErrorBadWEPKey; |
Paul Stewart | f2d6091 | 2012-07-15 08:37:30 -0700 | [diff] [blame] | 875 | case kFailureConnect: |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 876 | return kErrorConnectFailed; |
Paul Stewart | f2d6091 | 2012-07-15 08:37:30 -0700 | [diff] [blame] | 877 | case kFailureDNSLookup: |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 878 | return kErrorDNSLookupFailed; |
Paul Stewart | f2d6091 | 2012-07-15 08:37:30 -0700 | [diff] [blame] | 879 | case kFailureDHCP: |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 880 | return kErrorDhcpFailed; |
Darin Petkov | 1c049c7 | 2013-03-21 13:15:45 +0100 | [diff] [blame] | 881 | case kFailureEAPAuthentication: |
Ben Chan | 39a7beb | 2013-09-21 11:28:00 -0700 | [diff] [blame] | 882 | return kErrorEapAuthenticationFailed; |
Darin Petkov | 1c049c7 | 2013-03-21 13:15:45 +0100 | [diff] [blame] | 883 | case kFailureEAPLocalTLS: |
Ben Chan | 39a7beb | 2013-09-21 11:28:00 -0700 | [diff] [blame] | 884 | return kErrorEapLocalTlsFailed; |
Darin Petkov | 1c049c7 | 2013-03-21 13:15:45 +0100 | [diff] [blame] | 885 | case kFailureEAPRemoteTLS: |
Ben Chan | 39a7beb | 2013-09-21 11:28:00 -0700 | [diff] [blame] | 886 | return kErrorEapRemoteTlsFailed; |
Paul Stewart | f2d6091 | 2012-07-15 08:37:30 -0700 | [diff] [blame] | 887 | case kFailureHTTPGet: |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 888 | return kErrorHTTPGetFailed; |
Darin Petkov | 1c049c7 | 2013-03-21 13:15:45 +0100 | [diff] [blame] | 889 | case kFailureInternal: |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 890 | return kErrorInternal; |
Darin Petkov | 1c049c7 | 2013-03-21 13:15:45 +0100 | [diff] [blame] | 891 | case kFailureIPSecCertAuth: |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 892 | return kErrorIpsecCertAuthFailed; |
Darin Petkov | 1c049c7 | 2013-03-21 13:15:45 +0100 | [diff] [blame] | 893 | case kFailureIPSecPSKAuth: |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 894 | return kErrorIpsecPskAuthFailed; |
Gaurav Shah | c6d6c72 | 2011-11-17 18:59:39 -0800 | [diff] [blame] | 895 | case kFailureNeedEVDO: |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 896 | return kErrorNeedEvdo; |
Gaurav Shah | c6d6c72 | 2011-11-17 18:59:39 -0800 | [diff] [blame] | 897 | case kFailureNeedHomeNetwork: |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 898 | return kErrorNeedHomeNetwork; |
Paul Stewart | f2d6091 | 2012-07-15 08:37:30 -0700 | [diff] [blame] | 899 | case kFailureOTASP: |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 900 | return kErrorOtaspFailed; |
Paul Stewart | f2d6091 | 2012-07-15 08:37:30 -0700 | [diff] [blame] | 901 | case kFailureOutOfRange: |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 902 | return kErrorOutOfRange; |
Paul Stewart | f2d6091 | 2012-07-15 08:37:30 -0700 | [diff] [blame] | 903 | case kFailurePinMissing: |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 904 | return kErrorPinMissing; |
Paul Stewart | f2d6091 | 2012-07-15 08:37:30 -0700 | [diff] [blame] | 905 | case kFailurePPPAuth: |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 906 | return kErrorPppAuthFailed; |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 907 | case kFailureMax: |
Darin Petkov | 1c049c7 | 2013-03-21 13:15:45 +0100 | [diff] [blame] | 908 | NOTREACHED(); |
Gaurav Shah | c6d6c72 | 2011-11-17 18:59:39 -0800 | [diff] [blame] | 909 | } |
| 910 | return "Invalid"; |
| 911 | } |
| 912 | |
| 913 | // static |
| 914 | const char *Service::ConnectStateToString(const ConnectState &state) { |
| 915 | switch (state) { |
| 916 | case kStateUnknown: |
| 917 | return "Unknown"; |
| 918 | case kStateIdle: |
| 919 | return "Idle"; |
| 920 | case kStateAssociating: |
| 921 | return "Associating"; |
| 922 | case kStateConfiguring: |
| 923 | return "Configuring"; |
| 924 | case kStateConnected: |
| 925 | return "Connected"; |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 926 | case kStatePortal: |
| 927 | return "Portal"; |
Gaurav Shah | c6d6c72 | 2011-11-17 18:59:39 -0800 | [diff] [blame] | 928 | case kStateFailure: |
| 929 | return "Failure"; |
| 930 | case kStateOnline: |
| 931 | return "Online"; |
| 932 | } |
| 933 | return "Invalid"; |
| 934 | } |
| 935 | |
Darin Petkov | 58f0b6d | 2012-06-12 12:52:30 +0200 | [diff] [blame] | 936 | string Service::GetTechnologyString() const { |
Gaurav Shah | 435de2c | 2011-11-17 19:01:07 -0800 | [diff] [blame] | 937 | return Technology::NameFromIdentifier(technology()); |
| 938 | } |
| 939 | |
Darin Petkov | 58f0b6d | 2012-06-12 12:52:30 +0200 | [diff] [blame] | 940 | string Service::CalculateTechnology(Error */*error*/) { |
| 941 | return GetTechnologyString(); |
| 942 | } |
| 943 | |
Darin Petkov | 385b9bc | 2012-12-03 15:25:05 +0100 | [diff] [blame] | 944 | void Service::NoteDisconnectEvent() { |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 945 | SLOG(this, 2) << __func__; |
Darin Petkov | cb0b566 | 2012-12-13 09:59:44 +0100 | [diff] [blame] | 946 | // Ignore the event if it's user-initiated explicit disconnect. |
Darin Petkov | 385b9bc | 2012-12-03 15:25:05 +0100 | [diff] [blame] | 947 | if (explicitly_disconnected_) { |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 948 | SLOG(this, 2) << "Explicit disconnect ignored."; |
Darin Petkov | cb0b566 | 2012-12-13 09:59:44 +0100 | [diff] [blame] | 949 | return; |
| 950 | } |
| 951 | // Ignore the event if manager is not running (e.g., service disconnects on |
| 952 | // shutdown). |
| 953 | if (!manager_->running()) { |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 954 | SLOG(this, 2) << "Disconnect while manager stopped ignored."; |
Darin Petkov | cb0b566 | 2012-12-13 09:59:44 +0100 | [diff] [blame] | 955 | return; |
| 956 | } |
Daniel Erat | fac0953 | 2014-04-17 20:25:59 -0700 | [diff] [blame] | 957 | // Ignore the event if the system is suspending. |
Darin Petkov | cb0b566 | 2012-12-13 09:59:44 +0100 | [diff] [blame] | 958 | PowerManager *power_manager = manager_->power_manager(); |
Daniel Erat | fac0953 | 2014-04-17 20:25:59 -0700 | [diff] [blame] | 959 | if (!power_manager || power_manager->suspending()) { |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 960 | SLOG(this, 2) << "Disconnect in transitional power state ignored."; |
Darin Petkov | 385b9bc | 2012-12-03 15:25:05 +0100 | [diff] [blame] | 961 | return; |
| 962 | } |
Paul Stewart | 483e472 | 2012-12-18 10:23:17 -0800 | [diff] [blame] | 963 | int period = 0; |
Darin Petkov | 385b9bc | 2012-12-03 15:25:05 +0100 | [diff] [blame] | 964 | size_t threshold = 0; |
Samuel Tan | 07dfabc | 2015-01-20 15:10:39 -0800 | [diff] [blame] | 965 | EventHistory *events = nullptr; |
Darin Petkov | c8d91e5 | 2013-01-21 11:43:47 +0100 | [diff] [blame] | 966 | // Sometimes services transition to Idle before going into a failed state so |
| 967 | // take into account the last non-idle state. |
| 968 | ConnectState state = state_ == kStateIdle ? previous_state_ : state_; |
| 969 | if (IsConnectedState(state)) { |
Darin Petkov | cb0b566 | 2012-12-13 09:59:44 +0100 | [diff] [blame] | 970 | LOG(INFO) << "Noting an unexpected connection drop."; |
Paul Stewart | 483e472 | 2012-12-18 10:23:17 -0800 | [diff] [blame] | 971 | period = kDisconnectsMonitorSeconds; |
Darin Petkov | 385b9bc | 2012-12-03 15:25:05 +0100 | [diff] [blame] | 972 | threshold = kReportDisconnectsThreshold; |
| 973 | events = &disconnects_; |
Darin Petkov | c8d91e5 | 2013-01-21 11:43:47 +0100 | [diff] [blame] | 974 | } else if (IsConnectingState(state)) { |
Darin Petkov | cb0b566 | 2012-12-13 09:59:44 +0100 | [diff] [blame] | 975 | LOG(INFO) << "Noting an unexpected failure to connect."; |
Paul Stewart | 483e472 | 2012-12-18 10:23:17 -0800 | [diff] [blame] | 976 | period = kMisconnectsMonitorSeconds; |
Darin Petkov | 385b9bc | 2012-12-03 15:25:05 +0100 | [diff] [blame] | 977 | threshold = kReportMisconnectsThreshold; |
| 978 | events = &misconnects_; |
| 979 | } else { |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 980 | SLOG(this, 2) |
Darin Petkov | cb0b566 | 2012-12-13 09:59:44 +0100 | [diff] [blame] | 981 | << "Not connected or connecting, state transition ignored."; |
Darin Petkov | 385b9bc | 2012-12-03 15:25:05 +0100 | [diff] [blame] | 982 | return; |
| 983 | } |
Samuel Tan | 07dfabc | 2015-01-20 15:10:39 -0800 | [diff] [blame] | 984 | events->RecordEventAndExpireEventsBefore(period, false); |
| 985 | if (events->Size() >= threshold) { |
Darin Petkov | 385b9bc | 2012-12-03 15:25:05 +0100 | [diff] [blame] | 986 | diagnostics_reporter_->OnConnectivityEvent(); |
| 987 | } |
| 988 | } |
| 989 | |
Peter Qiu | dc4e099 | 2014-05-01 10:02:52 -0700 | [diff] [blame] | 990 | void Service::ReportUserInitiatedConnectionResult(ConnectState state) { |
| 991 | // Report stats for wifi only for now. |
| 992 | if (technology_ != Technology::kWifi) |
| 993 | return; |
| 994 | |
| 995 | int result; |
| 996 | switch (state) { |
| 997 | case kStateConnected: |
| 998 | result = Metrics::kUserInitiatedConnectionResultSuccess; |
| 999 | break; |
| 1000 | case kStateFailure: |
| 1001 | result = Metrics::kUserInitiatedConnectionResultFailure; |
Peter Qiu | d87179e | 2014-07-10 18:29:22 -0700 | [diff] [blame] | 1002 | metrics_->NotifyUserInitiatedConnectionFailureReason( |
| 1003 | Metrics::kMetricWifiUserInitiatedConnectionFailureReason, failure_); |
Peter Qiu | dc4e099 | 2014-05-01 10:02:52 -0700 | [diff] [blame] | 1004 | break; |
| 1005 | case kStateIdle: |
| 1006 | // This assumes the device specific class (wifi, cellular) will advance |
| 1007 | // the service's state from idle to other state after connection attempt |
| 1008 | // is initiated for the given service. |
| 1009 | result = Metrics::kUserInitiatedConnectionResultAborted; |
| 1010 | break; |
| 1011 | default: |
| 1012 | return; |
| 1013 | } |
| 1014 | |
| 1015 | metrics_->NotifyUserInitiatedConnectionResult( |
| 1016 | Metrics::kMetricWifiUserInitiatedConnectionResult, result); |
| 1017 | } |
| 1018 | |
Paul Stewart | 483e472 | 2012-12-18 10:23:17 -0800 | [diff] [blame] | 1019 | bool Service::HasRecentConnectionIssues() { |
Samuel Tan | 07dfabc | 2015-01-20 15:10:39 -0800 | [diff] [blame] | 1020 | disconnects_.ExpireEventsBefore(kDisconnectsMonitorSeconds, false); |
| 1021 | misconnects_.ExpireEventsBefore(kMisconnectsMonitorSeconds, false); |
| 1022 | return !disconnects_.Empty() || !misconnects_.Empty(); |
Paul Stewart | 483e472 | 2012-12-18 10:23:17 -0800 | [diff] [blame] | 1023 | } |
| 1024 | |
Jason Glasgow | b579005 | 2012-01-27 01:03:52 -0500 | [diff] [blame] | 1025 | // static |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1026 | bool Service::DecideBetween(int a, int b, bool *decision) { |
| 1027 | if (a == b) |
| 1028 | return false; |
| 1029 | *decision = (a > b); |
| 1030 | return true; |
| 1031 | } |
| 1032 | |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 1033 | uint16_t Service::SecurityLevel() { |
mukesh agrawal | 43970a2 | 2013-02-15 16:00:07 -0800 | [diff] [blame] | 1034 | return (crypto_algorithm_ << 2) | (key_rotation_ << 1) | endpoint_auth_; |
| 1035 | } |
| 1036 | |
mukesh agrawal | 00917ce | 2011-11-22 23:56:55 +0000 | [diff] [blame] | 1037 | // static |
Rebecca Silberstein | 6d4836b | 2014-07-16 14:28:28 -0700 | [diff] [blame] | 1038 | bool Service::Compare(Manager *manager, |
| 1039 | ServiceRefPtr a, |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1040 | ServiceRefPtr b, |
Paul Stewart | 39db5ca | 2013-03-18 14:15:17 -0700 | [diff] [blame] | 1041 | bool compare_connectivity_state, |
mukesh agrawal | ddc378f | 2012-02-17 18:26:20 -0800 | [diff] [blame] | 1042 | const vector<Technology::Identifier> &tech_order, |
| 1043 | const char **reason) { |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1044 | bool ret; |
| 1045 | |
Paul Stewart | 39db5ca | 2013-03-18 14:15:17 -0700 | [diff] [blame] | 1046 | if (compare_connectivity_state && a->state() != b->state()) { |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1047 | if (DecideBetween(a->IsConnected(), b->IsConnected(), &ret)) { |
mukesh agrawal | ddc378f | 2012-02-17 18:26:20 -0800 | [diff] [blame] | 1048 | *reason = kServiceSortIsConnected; |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1049 | return ret; |
| 1050 | } |
| 1051 | |
Paul Stewart | a121c44 | 2012-06-09 14:12:58 -0700 | [diff] [blame] | 1052 | if (DecideBetween(!a->IsPortalled(), !b->IsPortalled(), &ret)) { |
| 1053 | *reason = kServiceSortIsPortalled; |
| 1054 | return ret; |
| 1055 | } |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1056 | |
| 1057 | if (DecideBetween(a->IsConnecting(), b->IsConnecting(), &ret)) { |
mukesh agrawal | ddc378f | 2012-02-17 18:26:20 -0800 | [diff] [blame] | 1058 | *reason = kServiceSortIsConnecting; |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1059 | return ret; |
| 1060 | } |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1061 | |
| 1062 | if (DecideBetween(!a->IsFailed(), !b->IsFailed(), &ret)) { |
mukesh agrawal | ddc378f | 2012-02-17 18:26:20 -0800 | [diff] [blame] | 1063 | *reason = kServiceSortIsFailed; |
mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1064 | return ret; |
| 1065 | } |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1066 | } |
| 1067 | |
Darin Petkov | 2f903b3 | 2012-04-18 12:56:43 +0200 | [diff] [blame] | 1068 | if (DecideBetween(a->connectable(), b->connectable(), &ret)) { |
| 1069 | *reason = kServiceSortConnectable; |
| 1070 | return ret; |
| 1071 | } |
| 1072 | |
Paul Stewart | df3c0a8 | 2012-11-09 15:54:33 -0800 | [diff] [blame] | 1073 | if (DecideBetween(a->IsDependentOn(b), b->IsDependentOn(a), &ret)) { |
| 1074 | *reason = kServiceSortDependency; |
| 1075 | return ret; |
| 1076 | } |
| 1077 | |
Darin Petkov | 2f903b3 | 2012-04-18 12:56:43 +0200 | [diff] [blame] | 1078 | // Ignore the auto-connect property if both services are connected |
| 1079 | // already. This allows connected non-autoconnectable VPN services to be |
| 1080 | // sorted higher than other connected services based on technology order. |
| 1081 | if (!a->IsConnected() && |
| 1082 | DecideBetween(a->auto_connect(), b->auto_connect(), &ret)) { |
| 1083 | *reason = kServiceSortAutoConnect; |
| 1084 | return ret; |
| 1085 | } |
| 1086 | |
Paul Stewart | 3fee7e3 | 2014-10-15 21:39:29 -0700 | [diff] [blame] | 1087 | if (DecideBetween(a->has_ever_connected() || a->managed_credentials_, |
| 1088 | b->has_ever_connected() || b->managed_credentials_, |
| 1089 | &ret)) { |
Paul Stewart | 2da34c0 | 2013-10-17 15:28:56 -0700 | [diff] [blame] | 1090 | *reason = kServiceSortHasEverConnected; |
Darin Petkov | 2f903b3 | 2012-04-18 12:56:43 +0200 | [diff] [blame] | 1091 | return ret; |
| 1092 | } |
| 1093 | |
| 1094 | if (DecideBetween(a->priority(), b->priority(), &ret)) { |
| 1095 | *reason = kServiceSortPriority; |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1096 | return ret; |
| 1097 | } |
| 1098 | |
| 1099 | // TODO(pstew): Below this point we are making value judgements on |
| 1100 | // services that are not related to anything intrinsic or |
| 1101 | // user-specified. These heuristics should be richer (contain |
| 1102 | // historical information, for example) and be subject to user |
| 1103 | // customization. |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1104 | for (vector<Technology::Identifier>::const_iterator it = tech_order.begin(); |
| 1105 | it != tech_order.end(); |
| 1106 | ++it) { |
Joshua Kroll | 053fa82 | 2012-06-05 09:50:43 -0700 | [diff] [blame] | 1107 | if (DecideBetween(a->technology() == *it, b->technology() == *it, &ret)) { |
mukesh agrawal | ddc378f | 2012-02-17 18:26:20 -0800 | [diff] [blame] | 1108 | *reason = kServiceSortTechnology; |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1109 | return ret; |
mukesh agrawal | ddc378f | 2012-02-17 18:26:20 -0800 | [diff] [blame] | 1110 | } |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1111 | } |
| 1112 | |
Paul Stewart | d9c7cfc | 2015-01-06 14:26:22 -0800 | [diff] [blame] | 1113 | if (DecideBetween(a->priority_within_technology(), |
| 1114 | b->priority_within_technology(), &ret)) { |
| 1115 | *reason = kServiceSortPriorityWithinTechnology; |
| 1116 | return ret; |
| 1117 | } |
| 1118 | |
Rebecca Silberstein | 6d4836b | 2014-07-16 14:28:28 -0700 | [diff] [blame] | 1119 | if (DecideBetween(a->SecurityLevel(), b->SecurityLevel(), &ret)) { |
| 1120 | *reason = kServiceSortSecurity; |
| 1121 | return ret; |
| 1122 | } |
| 1123 | |
| 1124 | // If the profiles for the two services are different, |
| 1125 | // we want to pick the highest priority one. The |
| 1126 | // ephemeral profile is explicitly tested for since it is not |
| 1127 | // listed in the manager profiles_ list. |
| 1128 | if (a->profile() != b->profile()) { |
| 1129 | *reason = kServiceSortProfileOrder; |
| 1130 | if (manager->IsServiceEphemeral(b)) { |
| 1131 | return true; |
| 1132 | } else if (manager->IsServiceEphemeral(a)) { |
| 1133 | return false; |
| 1134 | } else if (manager->IsProfileBefore(b->profile(), a->profile())) { |
| 1135 | return true; |
| 1136 | } else { |
| 1137 | return false; |
| 1138 | } |
| 1139 | } |
| 1140 | |
| 1141 | if (DecideBetween(a->strength(), b->strength(), &ret)) { |
| 1142 | *reason = kServiceSortEtc; |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1143 | return ret; |
| 1144 | } |
| 1145 | |
mukesh agrawal | e37ad32 | 2013-10-08 16:33:56 -0700 | [diff] [blame] | 1146 | *reason = kServiceSortSerialNumber; |
| 1147 | return a->serial_number_ < b->serial_number_; |
Paul Stewart | 22aa71b | 2011-09-16 12:15:11 -0700 | [diff] [blame] | 1148 | } |
| 1149 | |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 1150 | const ProfileRefPtr &Service::profile() const { return profile_; } |
| 1151 | |
| 1152 | void Service::set_profile(const ProfileRefPtr &p) { profile_ = p; } |
| 1153 | |
Philipp Neubeck | 7917360 | 2012-11-13 21:10:09 +0100 | [diff] [blame] | 1154 | void Service::SetProfile(const ProfileRefPtr &p) { |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 1155 | SLOG(this, 2) << "SetProfile from " |
| 1156 | << (profile_ ? profile_->GetFriendlyName() : "(none)") |
| 1157 | << " to " << (p ? p->GetFriendlyName() : "(none)") |
| 1158 | << "."; |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 1159 | if (profile_ == p) { |
| 1160 | return; |
| 1161 | } |
Philipp Neubeck | 7917360 | 2012-11-13 21:10:09 +0100 | [diff] [blame] | 1162 | profile_ = p; |
| 1163 | Error error; |
| 1164 | string profile_rpc_id = GetProfileRpcId(&error); |
| 1165 | if (!error.IsSuccess()) { |
| 1166 | return; |
| 1167 | } |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 1168 | adaptor_->EmitStringChanged(kProfileProperty, profile_rpc_id); |
Philipp Neubeck | 7917360 | 2012-11-13 21:10:09 +0100 | [diff] [blame] | 1169 | } |
| 1170 | |
Paul Stewart | ff14b02 | 2012-04-24 20:06:23 -0700 | [diff] [blame] | 1171 | void Service::OnPropertyChanged(const string &property) { |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 1172 | SLOG(this, 1) << __func__ << " " << property; |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 1173 | if (Is8021x() && EapCredentials::IsEapAuthenticationProperty(property)) { |
Rebecca Silberstein | 5777690 | 2014-09-15 21:43:02 -0700 | [diff] [blame] | 1174 | OnEapCredentialsChanged(kReasonPropertyUpdate); |
Paul Stewart | 8142613 | 2012-05-16 10:05:10 -0700 | [diff] [blame] | 1175 | } |
mukesh agrawal | cf24a24 | 2012-05-21 16:46:11 -0700 | [diff] [blame] | 1176 | SaveToProfile(); |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 1177 | if ((property == kCheckPortalProperty || |
| 1178 | property == kProxyConfigProperty) && |
Paul Stewart | d215af6 | 2012-04-24 23:25:50 -0700 | [diff] [blame] | 1179 | (state_ == kStateConnected || |
| 1180 | state_ == kStatePortal || |
| 1181 | state_ == kStateOnline)) { |
| 1182 | manager_->RecheckPortalOnService(this); |
| 1183 | } |
Paul Stewart | ff14b02 | 2012-04-24 20:06:23 -0700 | [diff] [blame] | 1184 | } |
| 1185 | |
Christopher Wiley | 0801d19 | 2012-09-24 11:57:15 -0700 | [diff] [blame] | 1186 | void Service::OnAfterResume() { |
| 1187 | // Forget old autoconnect failures across suspend/resume. |
| 1188 | auto_connect_cooldown_milliseconds_ = 0; |
| 1189 | reenable_auto_connect_task_.Cancel(); |
Christopher Wiley | a4c61ae | 2012-10-01 11:04:30 -0700 | [diff] [blame] | 1190 | // Forget if the user disconnected us, we might be able to connect now. |
Paul Stewart | 2eee613 | 2014-05-09 13:33:26 -0700 | [diff] [blame] | 1191 | ClearExplicitlyDisconnected(); |
Christopher Wiley | 0801d19 | 2012-09-24 11:57:15 -0700 | [diff] [blame] | 1192 | } |
| 1193 | |
Prathmesh Prabhu | 64ad238 | 2014-08-26 11:19:30 -0700 | [diff] [blame] | 1194 | void Service::OnDarkResume() { |
| 1195 | // Nothing to do in the general case. |
| 1196 | } |
| 1197 | |
Paul Stewart | 1cf7eb8 | 2013-12-03 19:34:36 -0800 | [diff] [blame] | 1198 | string Service::GetIPConfigRpcIdentifier(Error *error) const { |
Paul Stewart | 10241e3 | 2012-04-23 18:15:06 -0700 | [diff] [blame] | 1199 | if (!connection_) { |
| 1200 | error->Populate(Error::kNotFound); |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 1201 | return DBusAdaptor::kNullPath; |
Paul Stewart | 10241e3 | 2012-04-23 18:15:06 -0700 | [diff] [blame] | 1202 | } |
| 1203 | |
| 1204 | string id = connection_->ipconfig_rpc_identifier(); |
| 1205 | |
| 1206 | if (id.empty()) { |
| 1207 | // Do not return an empty IPConfig. |
| 1208 | error->Populate(Error::kNotFound); |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 1209 | return DBusAdaptor::kNullPath; |
Paul Stewart | 10241e3 | 2012-04-23 18:15:06 -0700 | [diff] [blame] | 1210 | } |
| 1211 | |
| 1212 | return id; |
| 1213 | } |
| 1214 | |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 1215 | void Service::SetConnectable(bool connectable) { |
| 1216 | if (connectable_ == connectable) |
| 1217 | return; |
mukesh agrawal | 29c13a1 | 2011-11-24 00:09:19 +0000 | [diff] [blame] | 1218 | connectable_ = connectable; |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 1219 | adaptor_->EmitBoolChanged(kConnectableProperty, connectable_); |
mukesh agrawal | 29c13a1 | 2011-11-24 00:09:19 +0000 | [diff] [blame] | 1220 | } |
| 1221 | |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 1222 | void Service::SetConnectableFull(bool connectable) { |
Darin Petkov | b2ba39f | 2012-06-06 10:33:43 +0200 | [diff] [blame] | 1223 | if (connectable_ == connectable) { |
| 1224 | return; |
| 1225 | } |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 1226 | SetConnectable(connectable); |
Darin Petkov | b2ba39f | 2012-06-06 10:33:43 +0200 | [diff] [blame] | 1227 | if (manager_->HasService(this)) { |
| 1228 | manager_->UpdateService(this); |
| 1229 | } |
| 1230 | } |
| 1231 | |
Darin Petkov | 58f0b6d | 2012-06-12 12:52:30 +0200 | [diff] [blame] | 1232 | string Service::GetStateString() const { |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 1233 | // TODO(benchan): We may want to rename shill::kState* to avoid name clashing |
| 1234 | // with Service::kState*. |
Paul Stewart | 03e29f7 | 2013-09-26 00:49:48 -0700 | [diff] [blame] | 1235 | switch (state()) { |
Gaurav Shah | c6d6c72 | 2011-11-17 18:59:39 -0800 | [diff] [blame] | 1236 | case kStateIdle: |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 1237 | return shill::kStateIdle; |
Gaurav Shah | c6d6c72 | 2011-11-17 18:59:39 -0800 | [diff] [blame] | 1238 | case kStateAssociating: |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 1239 | return shill::kStateAssociation; |
Gaurav Shah | c6d6c72 | 2011-11-17 18:59:39 -0800 | [diff] [blame] | 1240 | case kStateConfiguring: |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 1241 | return shill::kStateConfiguration; |
mukesh agrawal | f2f68a5 | 2011-09-01 12:15:48 -0700 | [diff] [blame] | 1242 | case kStateConnected: |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 1243 | return shill::kStateReady; |
Gaurav Shah | c6d6c72 | 2011-11-17 18:59:39 -0800 | [diff] [blame] | 1244 | case kStateFailure: |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 1245 | return shill::kStateFailure; |
Paul Stewart | 20088d8 | 2012-02-16 06:58:55 -0800 | [diff] [blame] | 1246 | case kStatePortal: |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 1247 | return shill::kStatePortal; |
Gaurav Shah | c6d6c72 | 2011-11-17 18:59:39 -0800 | [diff] [blame] | 1248 | case kStateOnline: |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 1249 | return shill::kStateOnline; |
Gaurav Shah | c6d6c72 | 2011-11-17 18:59:39 -0800 | [diff] [blame] | 1250 | case kStateUnknown: |
mukesh agrawal | f2f68a5 | 2011-09-01 12:15:48 -0700 | [diff] [blame] | 1251 | default: |
Gaurav Shah | c6d6c72 | 2011-11-17 18:59:39 -0800 | [diff] [blame] | 1252 | return ""; |
mukesh agrawal | f2f68a5 | 2011-09-01 12:15:48 -0700 | [diff] [blame] | 1253 | } |
| 1254 | } |
| 1255 | |
Darin Petkov | 58f0b6d | 2012-06-12 12:52:30 +0200 | [diff] [blame] | 1256 | string Service::CalculateState(Error */*error*/) { |
| 1257 | return GetStateString(); |
| 1258 | } |
| 1259 | |
mukesh agrawal | bf14e94 | 2012-03-02 14:36:34 -0800 | [diff] [blame] | 1260 | bool Service::IsAutoConnectable(const char **reason) const { |
Ben Chan | 8e6b8ef | 2014-07-14 21:50:18 -0700 | [diff] [blame] | 1261 | if (manager_->IsTechnologyAutoConnectDisabled(technology_)) { |
| 1262 | *reason = kAutoConnTechnologyNotConnectable; |
| 1263 | return false; |
| 1264 | } |
| 1265 | |
mukesh agrawal | bf14e94 | 2012-03-02 14:36:34 -0800 | [diff] [blame] | 1266 | if (!connectable()) { |
| 1267 | *reason = kAutoConnNotConnectable; |
| 1268 | return false; |
| 1269 | } |
| 1270 | |
| 1271 | if (IsConnected()) { |
| 1272 | *reason = kAutoConnConnected; |
| 1273 | return false; |
| 1274 | } |
| 1275 | |
| 1276 | if (IsConnecting()) { |
| 1277 | *reason = kAutoConnConnecting; |
| 1278 | return false; |
| 1279 | } |
| 1280 | |
| 1281 | if (explicitly_disconnected_) { |
| 1282 | *reason = kAutoConnExplicitDisconnect; |
| 1283 | return false; |
| 1284 | } |
| 1285 | |
Christopher Wiley | 0801d19 | 2012-09-24 11:57:15 -0700 | [diff] [blame] | 1286 | if (!reenable_auto_connect_task_.IsCancelled()) { |
| 1287 | *reason = kAutoConnThrottled; |
| 1288 | return false; |
| 1289 | } |
| 1290 | |
Darin Petkov | 4cbff5b | 2013-01-29 16:29:05 +0100 | [diff] [blame] | 1291 | if (!Technology::IsPrimaryConnectivityTechnology(technology_) && |
Peter Qiu | 700de64 | 2014-07-14 16:31:30 -0700 | [diff] [blame] | 1292 | !manager_->IsConnected()) { |
Darin Petkov | 4cbff5b | 2013-01-29 16:29:05 +0100 | [diff] [blame] | 1293 | *reason = kAutoConnOffline; |
| 1294 | return false; |
| 1295 | } |
| 1296 | |
mukesh agrawal | bf14e94 | 2012-03-02 14:36:34 -0800 | [diff] [blame] | 1297 | return true; |
mukesh agrawal | 76d1388 | 2012-01-12 15:23:11 -0800 | [diff] [blame] | 1298 | } |
| 1299 | |
Paul Stewart | d215af6 | 2012-04-24 23:25:50 -0700 | [diff] [blame] | 1300 | bool Service::IsPortalDetectionDisabled() const { |
| 1301 | return check_portal_ == kCheckPortalFalse; |
| 1302 | } |
| 1303 | |
| 1304 | bool Service::IsPortalDetectionAuto() const { |
| 1305 | return check_portal_ == kCheckPortalAuto; |
| 1306 | } |
| 1307 | |
mukesh agrawal | ffa3d04 | 2011-10-06 15:26:10 -0700 | [diff] [blame] | 1308 | void Service::HelpRegisterDerivedBool( |
| 1309 | const string &name, |
Alex Vakulenko | 8a53229 | 2014-06-16 17:18:44 -0700 | [diff] [blame] | 1310 | bool(Service::*get)(Error *error), |
Paul Stewart | 43d8dc0 | 2013-10-17 10:32:53 -0700 | [diff] [blame] | 1311 | bool(Service::*set)(const bool&, Error *), |
| 1312 | void(Service::*clear)(Error *)) { |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 1313 | store_.RegisterDerivedBool( |
| 1314 | name, |
Paul Stewart | 43d8dc0 | 2013-10-17 10:32:53 -0700 | [diff] [blame] | 1315 | BoolAccessor(new CustomAccessor<Service, bool>(this, get, set, clear))); |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 1316 | } |
| 1317 | |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 1318 | void Service::HelpRegisterDerivedInt32( |
| 1319 | const string &name, |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 1320 | int32_t(Service::*get)(Error *error), |
| 1321 | bool(Service::*set)(const int32_t&, Error *)) { |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 1322 | store_.RegisterDerivedInt32( |
| 1323 | name, |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 1324 | Int32Accessor(new CustomAccessor<Service, int32_t>(this, get, set))); |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 1325 | } |
| 1326 | |
mukesh agrawal | ffa3d04 | 2011-10-06 15:26:10 -0700 | [diff] [blame] | 1327 | void Service::HelpRegisterDerivedString( |
| 1328 | const string &name, |
Alex Vakulenko | 8a53229 | 2014-06-16 17:18:44 -0700 | [diff] [blame] | 1329 | string(Service::*get)(Error *error), |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 1330 | bool(Service::*set)(const string&, Error *)) { |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 1331 | store_.RegisterDerivedString( |
| 1332 | name, |
| 1333 | StringAccessor(new CustomAccessor<Service, string>(this, get, set))); |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 1334 | } |
| 1335 | |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 1336 | void Service::HelpRegisterConstDerivedRpcIdentifier( |
Jason Glasgow | acdc11f | 2012-03-30 14:12:22 -0400 | [diff] [blame] | 1337 | const string &name, |
Paul Stewart | 1cf7eb8 | 2013-12-03 19:34:36 -0800 | [diff] [blame] | 1338 | RpcIdentifier(Service::*get)(Error *) const) { |
Jason Glasgow | acdc11f | 2012-03-30 14:12:22 -0400 | [diff] [blame] | 1339 | store_.RegisterDerivedRpcIdentifier( |
| 1340 | name, |
Paul Stewart | 1cf7eb8 | 2013-12-03 19:34:36 -0800 | [diff] [blame] | 1341 | RpcIdentifierAccessor(new CustomReadOnlyAccessor<Service, RpcIdentifier>( |
| 1342 | this, get))); |
Jason Glasgow | acdc11f | 2012-03-30 14:12:22 -0400 | [diff] [blame] | 1343 | } |
| 1344 | |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 1345 | void Service::HelpRegisterConstDerivedUint16( |
Paul Stewart | be5f5b3 | 2011-12-07 17:11:11 -0800 | [diff] [blame] | 1346 | const string &name, |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 1347 | uint16_t(Service::*get)(Error *) const) { |
Paul Stewart | be5f5b3 | 2011-12-07 17:11:11 -0800 | [diff] [blame] | 1348 | store_.RegisterDerivedUint16( |
| 1349 | name, |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 1350 | Uint16Accessor(new CustomReadOnlyAccessor<Service, uint16_t>(this, get))); |
Paul Stewart | be5f5b3 | 2011-12-07 17:11:11 -0800 | [diff] [blame] | 1351 | } |
| 1352 | |
Darin Petkov | 0c65bdd | 2012-12-05 13:42:41 +0100 | [diff] [blame] | 1353 | void Service::HelpRegisterConstDerivedStrings( |
Paul Stewart | 1cf7eb8 | 2013-12-03 19:34:36 -0800 | [diff] [blame] | 1354 | const string &name, Strings(Service::*get)(Error *error) const) { |
Darin Petkov | 0c65bdd | 2012-12-05 13:42:41 +0100 | [diff] [blame] | 1355 | store_.RegisterDerivedStrings( |
| 1356 | name, |
Paul Stewart | 1cf7eb8 | 2013-12-03 19:34:36 -0800 | [diff] [blame] | 1357 | StringsAccessor(new CustomReadOnlyAccessor<Service, Strings>(this, get))); |
| 1358 | } |
| 1359 | |
| 1360 | void Service::HelpRegisterConstDerivedString( |
| 1361 | const string &name, string(Service::*get)(Error *error) const) { |
| 1362 | store_.RegisterDerivedString( |
| 1363 | name, |
| 1364 | StringAccessor(new CustomReadOnlyAccessor<Service, string>(this, get))); |
Darin Petkov | 0c65bdd | 2012-12-05 13:42:41 +0100 | [diff] [blame] | 1365 | } |
| 1366 | |
Paul Stewart | 45170bc | 2014-06-02 15:49:34 -0700 | [diff] [blame] | 1367 | void Service::HelpRegisterObservedDerivedBool( |
| 1368 | const string &name, |
Alex Vakulenko | 8a53229 | 2014-06-16 17:18:44 -0700 | [diff] [blame] | 1369 | bool(Service::*get)(Error *error), |
Paul Stewart | 45170bc | 2014-06-02 15:49:34 -0700 | [diff] [blame] | 1370 | bool(Service::*set)(const bool&, Error *), |
| 1371 | void(Service::*clear)(Error *)) { |
| 1372 | BoolAccessor accessor( |
| 1373 | new CustomAccessor<Service, bool>(this, get, set, clear)); |
| 1374 | store_.RegisterDerivedBool(name, accessor); |
| 1375 | property_change_notifier_->AddBoolPropertyObserver(name, accessor); |
| 1376 | } |
| 1377 | |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 1378 | // static |
Paul Stewart | c3dbff1 | 2013-07-17 10:32:48 -0700 | [diff] [blame] | 1379 | void Service::LoadString(StoreInterface *storage, |
| 1380 | const string &id, |
| 1381 | const string &key, |
| 1382 | const string &default_value, |
| 1383 | string *value) { |
| 1384 | if (!storage->GetString(id, key, value)) { |
| 1385 | *value = default_value; |
| 1386 | } |
| 1387 | } |
| 1388 | |
| 1389 | // static |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 1390 | void Service::SaveString(StoreInterface *storage, |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 1391 | const string &id, |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 1392 | const string &key, |
| 1393 | const string &value, |
| 1394 | bool crypted, |
| 1395 | bool save) { |
| 1396 | if (value.empty() || !save) { |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 1397 | storage->DeleteKey(id, key); |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 1398 | return; |
| 1399 | } |
| 1400 | if (crypted) { |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 1401 | storage->SetCryptedString(id, key, value); |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 1402 | return; |
| 1403 | } |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 1404 | storage->SetString(id, key, value); |
Darin Petkov | ba40dd3 | 2011-07-11 20:06:39 -0700 | [diff] [blame] | 1405 | } |
| 1406 | |
Paul Stewart | 967eaeb | 2013-04-25 19:53:07 -0700 | [diff] [blame] | 1407 | map<string, string> Service::GetLoadableProfileEntries() { |
| 1408 | return manager_->GetLoadableProfileEntriesForService(this); |
| 1409 | } |
| 1410 | |
Paul Stewart | cb59fed | 2012-03-21 21:14:46 -0700 | [diff] [blame] | 1411 | void Service::IgnoreParameterForConfigure(const string ¶meter) { |
| 1412 | parameters_ignored_for_configure_.insert(parameter); |
| 1413 | } |
| 1414 | |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 1415 | const string &Service::GetEAPKeyManagement() const { |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 1416 | CHECK(eap()); |
| 1417 | return eap()->key_management(); |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 1418 | } |
| 1419 | |
| 1420 | void Service::SetEAPKeyManagement(const string &key_management) { |
Paul Stewart | c43cbbe | 2013-04-11 06:29:30 -0700 | [diff] [blame] | 1421 | CHECK(mutable_eap()); |
Ben Chan | cc225ef | 2014-09-30 13:26:51 -0700 | [diff] [blame] | 1422 | mutable_eap()->SetKeyManagement(key_management, nullptr); |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 1423 | } |
| 1424 | |
Thieu Le | 284fe79 | 2012-01-31 17:53:19 -0800 | [diff] [blame] | 1425 | bool Service::GetAutoConnect(Error */*error*/) { |
| 1426 | return auto_connect(); |
| 1427 | } |
| 1428 | |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 1429 | bool Service::SetAutoConnectFull(const bool &connect, Error */*error*/) { |
Darin Petkov | 36d962d | 2013-03-25 13:03:14 +0100 | [diff] [blame] | 1430 | LOG(INFO) << "Service " << unique_name() << ": AutoConnect=" |
| 1431 | << auto_connect() << "->" << connect; |
Prathmesh Prabhu | 765d5df | 2014-04-22 16:43:15 -0700 | [diff] [blame] | 1432 | if (!retain_auto_connect_) { |
| 1433 | RetainAutoConnect(); |
| 1434 | // Irrespective of an actual change in the |kAutoConnectPropety|, we must |
| 1435 | // flush the current value of the property to the profile. |
| 1436 | if (IsRemembered()) { |
| 1437 | SaveToProfile(); |
| 1438 | } |
| 1439 | } |
Paul Stewart | 36e67be | 2013-12-12 14:36:10 -0800 | [diff] [blame] | 1440 | |
| 1441 | if (auto_connect() == connect) { |
| 1442 | return false; |
Darin Petkov | 36d962d | 2013-03-25 13:03:14 +0100 | [diff] [blame] | 1443 | } |
Paul Stewart | 96a6d09 | 2013-08-26 09:32:49 -0700 | [diff] [blame] | 1444 | |
Paul Stewart | 36e67be | 2013-12-12 14:36:10 -0800 | [diff] [blame] | 1445 | SetAutoConnect(connect); |
| 1446 | manager_->UpdateService(this); |
| 1447 | return true; |
Thieu Le | 284fe79 | 2012-01-31 17:53:19 -0800 | [diff] [blame] | 1448 | } |
| 1449 | |
Paul Stewart | 43d8dc0 | 2013-10-17 10:32:53 -0700 | [diff] [blame] | 1450 | void Service::ClearAutoConnect(Error */*error*/) { |
Paul Stewart | 43d8dc0 | 2013-10-17 10:32:53 -0700 | [diff] [blame] | 1451 | if (auto_connect()) { |
| 1452 | SetAutoConnect(false); |
Paul Stewart | 43d8dc0 | 2013-10-17 10:32:53 -0700 | [diff] [blame] | 1453 | manager_->UpdateService(this); |
| 1454 | } |
Paul Stewart | 2da34c0 | 2013-10-17 15:28:56 -0700 | [diff] [blame] | 1455 | |
| 1456 | retain_auto_connect_ = false; |
Paul Stewart | 43d8dc0 | 2013-10-17 10:32:53 -0700 | [diff] [blame] | 1457 | } |
| 1458 | |
Paul Stewart | d215af6 | 2012-04-24 23:25:50 -0700 | [diff] [blame] | 1459 | string Service::GetCheckPortal(Error *error) { |
| 1460 | return check_portal_; |
| 1461 | } |
| 1462 | |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 1463 | bool Service::SetCheckPortal(const string &check_portal, Error *error) { |
Paul Stewart | d215af6 | 2012-04-24 23:25:50 -0700 | [diff] [blame] | 1464 | if (check_portal != kCheckPortalFalse && |
| 1465 | check_portal != kCheckPortalTrue && |
| 1466 | check_portal != kCheckPortalAuto) { |
Paul Stewart | 34f424e | 2015-01-16 15:30:20 -0800 | [diff] [blame] | 1467 | Error::PopulateAndLog(FROM_HERE, error, Error::kInvalidArguments, |
Paul Stewart | d215af6 | 2012-04-24 23:25:50 -0700 | [diff] [blame] | 1468 | base::StringPrintf( |
| 1469 | "Invalid Service CheckPortal property value: %s", |
| 1470 | check_portal.c_str())); |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 1471 | return false; |
| 1472 | } |
| 1473 | if (check_portal == check_portal_) { |
| 1474 | return false; |
Paul Stewart | d215af6 | 2012-04-24 23:25:50 -0700 | [diff] [blame] | 1475 | } |
| 1476 | check_portal_ = check_portal; |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 1477 | return true; |
Paul Stewart | d215af6 | 2012-04-24 23:25:50 -0700 | [diff] [blame] | 1478 | } |
| 1479 | |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 1480 | string Service::GetGuid(Error *error) { |
| 1481 | return guid_; |
| 1482 | } |
| 1483 | |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 1484 | bool Service::SetGuid(const string &guid, Error */*error*/) { |
| 1485 | if (guid_ == guid) { |
| 1486 | return false; |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 1487 | } |
| 1488 | guid_ = guid; |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 1489 | adaptor_->EmitStringChanged(kGuidProperty, guid_); |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 1490 | return true; |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 1491 | } |
| 1492 | |
Paul Stewart | 2da34c0 | 2013-10-17 15:28:56 -0700 | [diff] [blame] | 1493 | void Service::RetainAutoConnect() { |
| 1494 | retain_auto_connect_ = true; |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 1495 | } |
| 1496 | |
mukesh agrawal | 43970a2 | 2013-02-15 16:00:07 -0800 | [diff] [blame] | 1497 | void Service::SetSecurity(CryptoAlgorithm crypto_algorithm, bool key_rotation, |
| 1498 | bool endpoint_auth) { |
| 1499 | crypto_algorithm_ = crypto_algorithm; |
| 1500 | key_rotation_ = key_rotation; |
| 1501 | endpoint_auth_ = endpoint_auth; |
| 1502 | } |
| 1503 | |
mukesh agrawal | d4dc083 | 2013-03-25 14:38:26 -0700 | [diff] [blame] | 1504 | string Service::GetNameProperty(Error */*error*/) { |
Paul Stewart | 0c43833 | 2012-04-11 07:55:27 -0700 | [diff] [blame] | 1505 | return friendly_name_; |
| 1506 | } |
| 1507 | |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 1508 | bool Service::SetNameProperty(const string &name, Error *error) { |
Paul Stewart | 0c43833 | 2012-04-11 07:55:27 -0700 | [diff] [blame] | 1509 | if (name != friendly_name_) { |
Paul Stewart | 34f424e | 2015-01-16 15:30:20 -0800 | [diff] [blame] | 1510 | Error::PopulateAndLog(FROM_HERE, error, Error::kInvalidArguments, |
Paul Stewart | 2bf424f | 2012-04-11 18:59:39 -0700 | [diff] [blame] | 1511 | base::StringPrintf( |
Darin Petkov | 457728b | 2013-01-09 09:49:08 +0100 | [diff] [blame] | 1512 | "Service %s Name property cannot be modified.", |
| 1513 | unique_name_.c_str())); |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 1514 | return false; |
Paul Stewart | 0c43833 | 2012-04-11 07:55:27 -0700 | [diff] [blame] | 1515 | } |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 1516 | return false; |
Paul Stewart | 0c43833 | 2012-04-11 07:55:27 -0700 | [diff] [blame] | 1517 | } |
| 1518 | |
Rebecca Silberstein | e99f664 | 2014-07-09 14:04:31 -0700 | [diff] [blame] | 1519 | void Service::SetHasEverConnected(bool has_ever_connected) { |
| 1520 | if (has_ever_connected_ == has_ever_connected) |
| 1521 | return; |
| 1522 | has_ever_connected_ = has_ever_connected; |
Rebecca Silberstein | e99f664 | 2014-07-09 14:04:31 -0700 | [diff] [blame] | 1523 | } |
| 1524 | |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 1525 | int32_t Service::GetPriority(Error *error) { |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 1526 | return priority_; |
| 1527 | } |
| 1528 | |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 1529 | bool Service::SetPriority(const int32_t &priority, Error *error) { |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 1530 | if (priority_ == priority) { |
| 1531 | return false; |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 1532 | } |
| 1533 | priority_ = priority; |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 1534 | adaptor_->EmitIntChanged(kPriorityProperty, priority_); |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 1535 | return true; |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 1536 | } |
| 1537 | |
Paul Stewart | d9c7cfc | 2015-01-06 14:26:22 -0800 | [diff] [blame] | 1538 | int32_t Service::GetPriorityWithinTechnology(Error *error) { |
| 1539 | return priority_within_technology_; |
| 1540 | } |
| 1541 | |
| 1542 | bool Service::SetPriorityWithinTechnology(const int32_t &priority, |
| 1543 | Error *error) { |
| 1544 | if (priority_within_technology_ == priority) { |
| 1545 | return false; |
| 1546 | } |
| 1547 | priority_within_technology_ = priority; |
| 1548 | adaptor_->EmitIntChanged(kPriorityWithinTechnologyProperty, |
| 1549 | priority_within_technology_); |
| 1550 | return true; |
| 1551 | } |
| 1552 | |
Paul Stewart | 1b1a7f2 | 2012-01-06 16:24:06 -0800 | [diff] [blame] | 1553 | string Service::GetProfileRpcId(Error *error) { |
| 1554 | if (!profile_) { |
| 1555 | // This happens in some unit tests where profile_ is not set. |
| 1556 | error->Populate(Error::kNotFound); |
| 1557 | return ""; |
| 1558 | } |
| 1559 | return profile_->GetRpcIdentifier(); |
| 1560 | } |
| 1561 | |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 1562 | bool Service::SetProfileRpcId(const string &profile, Error *error) { |
| 1563 | if (profile_ && profile_->GetRpcIdentifier() == profile) { |
| 1564 | return false; |
| 1565 | } |
| 1566 | ProfileConstRefPtr old_profile = profile_; |
| 1567 | // No need to Emit afterwards, since SetProfileForService will call |
| 1568 | // into SetProfile (if the profile actually changes). |
Paul Stewart | 1b1a7f2 | 2012-01-06 16:24:06 -0800 | [diff] [blame] | 1569 | manager_->SetProfileForService(this, profile, error); |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 1570 | // Can't just use error.IsSuccess(), because that also requires saving |
| 1571 | // the profile to succeed. (See Profile::AdoptService) |
| 1572 | return (profile_ != old_profile); |
Paul Stewart | 1b1a7f2 | 2012-01-06 16:24:06 -0800 | [diff] [blame] | 1573 | } |
| 1574 | |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 1575 | uint16_t Service::GetHTTPProxyPort(Error */*error*/) const { |
Paul Stewart | be5f5b3 | 2011-12-07 17:11:11 -0800 | [diff] [blame] | 1576 | if (http_proxy_.get()) { |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 1577 | return static_cast<uint16_t>(http_proxy_->proxy_port()); |
Paul Stewart | be5f5b3 | 2011-12-07 17:11:11 -0800 | [diff] [blame] | 1578 | } |
| 1579 | return 0; |
| 1580 | } |
| 1581 | |
Philipp Neubeck | 7917360 | 2012-11-13 21:10:09 +0100 | [diff] [blame] | 1582 | string Service::GetProxyConfig(Error *error) { |
| 1583 | return proxy_config_; |
| 1584 | } |
| 1585 | |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 1586 | bool Service::SetProxyConfig(const string &proxy_config, Error *error) { |
| 1587 | if (proxy_config_ == proxy_config) |
| 1588 | return false; |
Philipp Neubeck | 7917360 | 2012-11-13 21:10:09 +0100 | [diff] [blame] | 1589 | proxy_config_ = proxy_config; |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 1590 | adaptor_->EmitStringChanged(kProxyConfigProperty, proxy_config_); |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 1591 | return true; |
Philipp Neubeck | 7917360 | 2012-11-13 21:10:09 +0100 | [diff] [blame] | 1592 | } |
| 1593 | |
Paul Stewart | fa11e28 | 2013-12-02 22:04:25 -0800 | [diff] [blame] | 1594 | string Service::GetTethering(Error *error) const { |
| 1595 | // The "Tethering" property isn't supported by the Service base class, and |
| 1596 | // therefore should not be listed in the properties returned by |
| 1597 | // the GetProperties() RPC method. |
| 1598 | error->Populate(Error::kNotSupported); |
| 1599 | return ""; |
| 1600 | } |
| 1601 | |
Paul Stewart | 7cc9068 | 2014-05-30 17:01:56 -0700 | [diff] [blame] | 1602 | |
Paul Stewart | 45170bc | 2014-06-02 15:49:34 -0700 | [diff] [blame] | 1603 | void Service::NotifyPropertyChanges() { |
| 1604 | property_change_notifier_->UpdatePropertyObservers(); |
Paul Stewart | 7cc9068 | 2014-05-30 17:01:56 -0700 | [diff] [blame] | 1605 | } |
| 1606 | |
Paul Stewart | 1cf7eb8 | 2013-12-03 19:34:36 -0800 | [diff] [blame] | 1607 | Strings Service::GetDisconnectsProperty(Error */*error*/) const { |
Samuel Tan | 07dfabc | 2015-01-20 15:10:39 -0800 | [diff] [blame] | 1608 | return disconnects_.ExtractWallClockToStrings(); |
Darin Petkov | 0c65bdd | 2012-12-05 13:42:41 +0100 | [diff] [blame] | 1609 | } |
| 1610 | |
Paul Stewart | 1cf7eb8 | 2013-12-03 19:34:36 -0800 | [diff] [blame] | 1611 | Strings Service::GetMisconnectsProperty(Error */*error*/) const { |
Samuel Tan | 07dfabc | 2015-01-20 15:10:39 -0800 | [diff] [blame] | 1612 | return misconnects_.ExtractWallClockToStrings(); |
Darin Petkov | 0c65bdd | 2012-12-05 13:42:41 +0100 | [diff] [blame] | 1613 | } |
| 1614 | |
Paul Stewart | cca85b1 | 2014-05-30 13:56:35 -0700 | [diff] [blame] | 1615 | bool Service::GetVisibleProperty(Error */*error*/) { |
| 1616 | return IsVisible(); |
| 1617 | } |
| 1618 | |
mukesh agrawal | cf24a24 | 2012-05-21 16:46:11 -0700 | [diff] [blame] | 1619 | void Service::SaveToProfile() { |
| 1620 | if (profile_.get() && profile_->GetConstStorage()) { |
| 1621 | profile_->UpdateService(this); |
| 1622 | } |
| 1623 | } |
| 1624 | |
Arman Uguray | 2717a10 | 2013-01-29 23:36:06 -0800 | [diff] [blame] | 1625 | void Service::SetFriendlyName(const string &friendly_name) { |
| 1626 | if (friendly_name == friendly_name_) |
| 1627 | return; |
| 1628 | friendly_name_ = friendly_name; |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 1629 | adaptor()->EmitStringChanged(kNameProperty, friendly_name_); |
Arman Uguray | 2717a10 | 2013-01-29 23:36:06 -0800 | [diff] [blame] | 1630 | } |
| 1631 | |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 1632 | void Service::SetStrength(uint8_t strength) { |
Darin Petkov | d78ee7e | 2012-01-12 11:21:10 +0100 | [diff] [blame] | 1633 | if (strength == strength_) { |
| 1634 | return; |
| 1635 | } |
| 1636 | strength_ = strength; |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 1637 | adaptor_->EmitUint8Changed(kSignalStrengthProperty, strength); |
Darin Petkov | d78ee7e | 2012-01-12 11:21:10 +0100 | [diff] [blame] | 1638 | } |
| 1639 | |
Darin Petkov | aba8932 | 2013-03-11 14:48:22 +0100 | [diff] [blame] | 1640 | void Service::SetErrorDetails(const string &details) { |
| 1641 | if (error_details_ == details) { |
| 1642 | return; |
| 1643 | } |
| 1644 | error_details_ = details; |
Ben Chan | 39a7beb | 2013-09-21 11:28:00 -0700 | [diff] [blame] | 1645 | adaptor_->EmitStringChanged(kErrorDetailsProperty, error_details_); |
Darin Petkov | aba8932 | 2013-03-11 14:48:22 +0100 | [diff] [blame] | 1646 | } |
| 1647 | |
Paul Stewart | f2d6091 | 2012-07-15 08:37:30 -0700 | [diff] [blame] | 1648 | void Service::UpdateErrorProperty() { |
| 1649 | const string error(ConnectFailureToString(failure_)); |
| 1650 | if (error == error_) { |
| 1651 | return; |
| 1652 | } |
| 1653 | error_ = error; |
Ben Chan | 923a502 | 2013-09-20 11:23:23 -0700 | [diff] [blame] | 1654 | adaptor_->EmitStringChanged(kErrorProperty, error); |
Paul Stewart | f2d6091 | 2012-07-15 08:37:30 -0700 | [diff] [blame] | 1655 | } |
| 1656 | |
Paul Stewart | 2eee613 | 2014-05-09 13:33:26 -0700 | [diff] [blame] | 1657 | void Service::ClearExplicitlyDisconnected() { |
| 1658 | if (explicitly_disconnected_) { |
| 1659 | explicitly_disconnected_ = false; |
| 1660 | manager_->UpdateService(this); |
| 1661 | } |
| 1662 | } |
| 1663 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 1664 | } // namespace shill |