mukesh agrawal | 8a3188d | 2011-12-01 20:56:44 +0000 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -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 | |
| 5 | #include "shill/cellular_service.h" |
| 6 | |
| 7 | #include <string> |
| 8 | |
Ben Chan | a0ddf46 | 2014-02-06 11:32:42 -0800 | [diff] [blame] | 9 | #include <base/strings/stringprintf.h> |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 10 | #include <chromeos/dbus/service_constants.h> |
| 11 | |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 12 | #include "shill/adaptor_interfaces.h" |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 13 | #include "shill/cellular.h" |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 14 | #include "shill/property_accessor.h" |
| 15 | #include "shill/store_interface.h" |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 16 | |
| 17 | using std::string; |
| 18 | |
| 19 | namespace shill { |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 20 | |
mukesh agrawal | a70ec27 | 2013-08-19 16:08:31 -0700 | [diff] [blame] | 21 | // statics |
Christopher Wiley | 1582bdd | 2012-11-15 11:31:14 -0800 | [diff] [blame] | 22 | const char CellularService::kAutoConnActivating[] = "activating"; |
mukesh agrawal | d477388 | 2013-08-14 17:21:14 -0700 | [diff] [blame] | 23 | const char CellularService::kAutoConnBadPPPCredentials[] = |
| 24 | "bad PPP credentials"; |
Ben Chan | 19f8397 | 2012-10-03 23:25:56 -0700 | [diff] [blame] | 25 | const char CellularService::kAutoConnDeviceDisabled[] = "device disabled"; |
Thieu Le | 398b1da | 2013-03-11 17:31:10 -0700 | [diff] [blame] | 26 | const char CellularService::kAutoConnOutOfCredits[] = "device out of credits"; |
| 27 | const char CellularService::kAutoConnOutOfCreditsDetectionInProgress[] = |
| 28 | "device detecting out-of-credits"; |
mukesh agrawal | a70ec27 | 2013-08-19 16:08:31 -0700 | [diff] [blame] | 29 | const char CellularService::kStoragePPPUsername[] = "Cellular.PPP.Username"; |
| 30 | const char CellularService::kStoragePPPPassword[] = "Cellular.PPP.Password"; |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 31 | |
Darin Petkov | 381928f | 2012-02-02 23:00:12 +0100 | [diff] [blame] | 32 | // TODO(petkov): Add these to system_api/dbus/service_constants.h |
| 33 | namespace { |
mukesh agrawal | 3ffe52c | 2013-06-20 15:21:29 -0700 | [diff] [blame] | 34 | const char kCellularPPPUsernameProperty[] = "Cellular.PPP.Username"; |
| 35 | const char kCellularPPPPasswordProperty[] = "Cellular.PPP.Password"; |
| 36 | } // namespace |
| 37 | |
| 38 | namespace { |
| 39 | const char kStorageAPN[] = "Cellular.APN"; |
| 40 | const char kStorageLastGoodAPN[] = "Cellular.LastGoodAPN"; |
Ben Chan | 19f8397 | 2012-10-03 23:25:56 -0700 | [diff] [blame] | 41 | } // namespace |
Darin Petkov | 381928f | 2012-02-02 23:00:12 +0100 | [diff] [blame] | 42 | |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 43 | static bool GetNonEmptyField(const Stringmap &stringmap, |
| 44 | const string &fieldname, |
| 45 | string *value) { |
| 46 | Stringmap::const_iterator it = stringmap.find(fieldname); |
| 47 | if (it != stringmap.end() && !it->second.empty()) { |
| 48 | *value = it->second; |
| 49 | return true; |
| 50 | } |
| 51 | return false; |
| 52 | } |
| 53 | |
Prathmesh Prabhu | 0d36b4f | 2013-04-01 11:45:54 -0700 | [diff] [blame] | 54 | CellularService::CellularService(ModemInfo *modem_info, |
mukesh agrawal | 51a7e93 | 2011-07-27 16:18:26 -0700 | [diff] [blame] | 55 | const CellularRefPtr &device) |
Prathmesh Prabhu | 0d36b4f | 2013-04-01 11:45:54 -0700 | [diff] [blame] | 56 | : Service(modem_info->control_interface(), modem_info->dispatcher(), |
| 57 | modem_info->metrics(), modem_info->manager(), |
Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 58 | Technology::kCellular), |
Thieu Le | 398b1da | 2013-03-11 17:31:10 -0700 | [diff] [blame] | 59 | weak_ptr_factory_(this), |
Ben Chan | 3d6de0e | 2012-12-10 12:01:34 -0800 | [diff] [blame] | 60 | activate_over_non_cellular_network_(false), |
Thieu Le | 7cf36b0 | 2013-01-30 17:15:56 -0800 | [diff] [blame] | 61 | cellular_(device), |
Ben Chan | a0ddf46 | 2014-02-06 11:32:42 -0800 | [diff] [blame] | 62 | is_auto_connecting_(false) { |
mukesh agrawal | cbfb34e | 2013-04-17 19:33:25 -0700 | [diff] [blame] | 63 | SetConnectable(true); |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 64 | PropertyStore *store = this->mutable_store(); |
Ben Chan | 3d6de0e | 2012-12-10 12:01:34 -0800 | [diff] [blame] | 65 | store->RegisterConstBool(kActivateOverNonCellularNetworkProperty, |
| 66 | &activate_over_non_cellular_network_); |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 67 | store->RegisterConstString(kActivationStateProperty, &activation_state_); |
| 68 | HelpRegisterDerivedStringmap(kCellularApnProperty, |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 69 | &CellularService::GetApn, |
| 70 | &CellularService::SetApn); |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 71 | store->RegisterConstStringmap(kCellularLastGoodApnProperty, |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 72 | &last_good_apn_info_); |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 73 | store->RegisterConstString(kNetworkTechnologyProperty, &network_technology_); |
Thieu Le | 43ce4d4 | 2013-10-04 16:08:55 -0700 | [diff] [blame] | 74 | HelpRegisterDerivedBool(kOutOfCreditsProperty, |
| 75 | &CellularService::IsOutOfCredits, |
| 76 | NULL); |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame] | 77 | store->RegisterConstStringmap(kPaymentPortalProperty, &olp_); |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 78 | store->RegisterConstString(kRoamingStateProperty, &roaming_state_); |
| 79 | store->RegisterConstStringmap(kServingOperatorProperty, |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 80 | &serving_operator_.ToDict()); |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 81 | store->RegisterConstString(kUsageURLProperty, &usage_url_); |
mukesh agrawal | 3ffe52c | 2013-06-20 15:21:29 -0700 | [diff] [blame] | 82 | store->RegisterString(kCellularPPPUsernameProperty, &ppp_username_); |
| 83 | store->RegisterWriteOnlyString(kCellularPPPPasswordProperty, &ppp_password_); |
Darin Petkov | ac635a8 | 2012-01-10 16:51:58 +0100 | [diff] [blame] | 84 | |
Prathmesh Prabhu | 95afcbb | 2014-04-08 16:05:42 -0700 | [diff] [blame] | 85 | set_friendly_name(cellular_->CreateDefaultFriendlyServiceName()); |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 86 | SetStorageIdentifier(string(kTypeCellular) + "_" + |
Prathmesh Prabhu | 401a5b9 | 2014-04-29 17:37:55 -0700 | [diff] [blame] | 87 | cellular_->address() + "_" + friendly_name()); |
Thieu Le | 43ce4d4 | 2013-10-04 16:08:55 -0700 | [diff] [blame] | 88 | // Assume we are not performing any out-of-credits detection. |
| 89 | // The capability can reinitialize with the appropriate type later. |
| 90 | InitOutOfCreditsDetection(OutOfCreditsDetector::OOCTypeNone); |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | CellularService::~CellularService() { } |
| 94 | |
Ben Chan | 19f8397 | 2012-10-03 23:25:56 -0700 | [diff] [blame] | 95 | bool CellularService::IsAutoConnectable(const char **reason) const { |
| 96 | if (!cellular_->running()) { |
| 97 | *reason = kAutoConnDeviceDisabled; |
| 98 | return false; |
| 99 | } |
Christopher Wiley | 1582bdd | 2012-11-15 11:31:14 -0800 | [diff] [blame] | 100 | if (cellular_->IsActivating()) { |
| 101 | *reason = kAutoConnActivating; |
| 102 | return false; |
| 103 | } |
mukesh agrawal | d477388 | 2013-08-14 17:21:14 -0700 | [diff] [blame] | 104 | if (failure() == kFailurePPPAuth) { |
| 105 | *reason = kAutoConnBadPPPCredentials; |
| 106 | return false; |
| 107 | } |
Thieu Le | 43ce4d4 | 2013-10-04 16:08:55 -0700 | [diff] [blame] | 108 | if (out_of_credits_detector_->IsDetecting()) { |
Thieu Le | 398b1da | 2013-03-11 17:31:10 -0700 | [diff] [blame] | 109 | *reason = kAutoConnOutOfCreditsDetectionInProgress; |
| 110 | return false; |
| 111 | } |
Thieu Le | 43ce4d4 | 2013-10-04 16:08:55 -0700 | [diff] [blame] | 112 | if (out_of_credits_detector_->out_of_credits()) { |
Thieu Le | 398b1da | 2013-03-11 17:31:10 -0700 | [diff] [blame] | 113 | *reason = kAutoConnOutOfCredits; |
| 114 | return false; |
| 115 | } |
Ben Chan | 19f8397 | 2012-10-03 23:25:56 -0700 | [diff] [blame] | 116 | return Service::IsAutoConnectable(reason); |
| 117 | } |
| 118 | |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 119 | void CellularService::HelpRegisterDerivedStringmap( |
| 120 | const string &name, |
| 121 | Stringmap(CellularService::*get)(Error *error), |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 122 | bool(CellularService::*set)( |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 123 | const Stringmap &value, Error *error)) { |
| 124 | mutable_store()->RegisterDerivedStringmap( |
| 125 | name, |
| 126 | StringmapAccessor( |
| 127 | new CustomAccessor<CellularService, Stringmap>(this, get, set))); |
| 128 | } |
| 129 | |
Thieu Le | 43ce4d4 | 2013-10-04 16:08:55 -0700 | [diff] [blame] | 130 | void CellularService::HelpRegisterDerivedBool( |
| 131 | const string &name, |
Alex Vakulenko | 8a53229 | 2014-06-16 17:18:44 -0700 | [diff] [blame] | 132 | bool(CellularService::*get)(Error *error), |
Thieu Le | 43ce4d4 | 2013-10-04 16:08:55 -0700 | [diff] [blame] | 133 | bool(CellularService::*set)(const bool&, Error *)) { |
| 134 | mutable_store()->RegisterDerivedBool( |
| 135 | name, |
| 136 | BoolAccessor(new CustomAccessor<CellularService, bool>(this, get, set))); |
| 137 | } |
| 138 | |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 139 | Stringmap *CellularService::GetUserSpecifiedApn() { |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 140 | Stringmap::iterator it = apn_info_.find(kApnProperty); |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 141 | if (it == apn_info_.end() || it->second.empty()) |
| 142 | return NULL; |
| 143 | return &apn_info_; |
| 144 | } |
| 145 | |
| 146 | Stringmap *CellularService::GetLastGoodApn() { |
Paul Stewart | 6db7b24 | 2014-05-02 15:34:21 -0700 | [diff] [blame] | 147 | Stringmap::iterator it = last_good_apn_info_.find(kApnProperty); |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 148 | if (it == last_good_apn_info_.end() || it->second.empty()) |
| 149 | return NULL; |
| 150 | return &last_good_apn_info_; |
| 151 | } |
| 152 | |
| 153 | Stringmap CellularService::GetApn(Error */*error*/) { |
| 154 | return apn_info_; |
| 155 | } |
| 156 | |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 157 | bool CellularService::SetApn(const Stringmap &value, Error *error) { |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 158 | // Only copy in the fields we care about, and validate the contents. |
Eric Shienbrood | c707330 | 2012-04-03 14:41:44 -0400 | [diff] [blame] | 159 | // If the "apn" field is missing or empty, the APN is cleared. |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 160 | string str; |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 161 | Stringmap new_apn_info; |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 162 | if (GetNonEmptyField(value, kApnProperty, &str)) { |
| 163 | new_apn_info[kApnProperty] = str; |
| 164 | if (GetNonEmptyField(value, kApnUsernameProperty, &str)) |
| 165 | new_apn_info[kApnUsernameProperty] = str; |
| 166 | if (GetNonEmptyField(value, kApnPasswordProperty, &str)) |
| 167 | new_apn_info[kApnPasswordProperty] = str; |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 168 | } |
| 169 | if (apn_info_ == new_apn_info) { |
| 170 | return false; |
| 171 | } |
| 172 | apn_info_ = new_apn_info; |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 173 | if (ContainsKey(apn_info_, kApnProperty)) { |
Eric Shienbrood | c707330 | 2012-04-03 14:41:44 -0400 | [diff] [blame] | 174 | // Clear the last good APN, otherwise the one the user just |
| 175 | // set won't be used, since LastGoodApn comes first in the |
| 176 | // search order when trying to connect. Only do this if a |
| 177 | // non-empty user APN has been supplied. If the user APN is |
| 178 | // being cleared, leave LastGoodApn alone. |
| 179 | ClearLastGoodApn(); |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 180 | } |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 181 | adaptor()->EmitStringmapChanged(kCellularApnProperty, apn_info_); |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 182 | return true; |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | void CellularService::SetLastGoodApn(const Stringmap &apn_info) { |
| 186 | last_good_apn_info_ = apn_info; |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 187 | adaptor()->EmitStringmapChanged(kCellularLastGoodApnProperty, |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 188 | last_good_apn_info_); |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | void CellularService::ClearLastGoodApn() { |
| 192 | last_good_apn_info_.clear(); |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 193 | adaptor()->EmitStringmapChanged(kCellularLastGoodApnProperty, |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 194 | last_good_apn_info_); |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 195 | } |
| 196 | |
Thieu Le | 99dc56d | 2013-04-01 14:22:21 -0700 | [diff] [blame] | 197 | void CellularService::OnAfterResume() { |
| 198 | Service::OnAfterResume(); |
| 199 | resume_start_time_ = base::Time::Now(); |
| 200 | } |
| 201 | |
Thieu Le | 43ce4d4 | 2013-10-04 16:08:55 -0700 | [diff] [blame] | 202 | void CellularService::InitOutOfCreditsDetection( |
| 203 | OutOfCreditsDetector::OOCType ooc_type) { |
| 204 | out_of_credits_detector_.reset( |
| 205 | OutOfCreditsDetector::CreateDetector(ooc_type, |
| 206 | dispatcher(), |
| 207 | manager(), |
| 208 | metrics(), |
| 209 | this)); |
| 210 | } |
| 211 | |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 212 | bool CellularService::Load(StoreInterface *storage) { |
| 213 | // Load properties common to all Services. |
| 214 | if (!Service::Load(storage)) |
| 215 | return false; |
| 216 | |
| 217 | const string id = GetStorageIdentifier(); |
| 218 | LoadApn(storage, id, kStorageAPN, &apn_info_); |
| 219 | LoadApn(storage, id, kStorageLastGoodAPN, &last_good_apn_info_); |
mukesh agrawal | a70ec27 | 2013-08-19 16:08:31 -0700 | [diff] [blame] | 220 | |
| 221 | const string old_username = ppp_username_; |
| 222 | const string old_password = ppp_password_; |
mukesh agrawal | 3ffe52c | 2013-06-20 15:21:29 -0700 | [diff] [blame] | 223 | storage->GetString(id, kStoragePPPUsername, &ppp_username_); |
| 224 | storage->GetString(id, kStoragePPPPassword, &ppp_password_); |
mukesh agrawal | a70ec27 | 2013-08-19 16:08:31 -0700 | [diff] [blame] | 225 | if (IsFailed() && failure() == kFailurePPPAuth && |
| 226 | (old_username != ppp_username_ || old_password != ppp_password_)) { |
| 227 | SetState(kStateIdle); |
| 228 | } |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 229 | return true; |
| 230 | } |
| 231 | |
| 232 | void CellularService::LoadApn(StoreInterface *storage, |
| 233 | const string &storage_group, |
| 234 | const string &keytag, |
| 235 | Stringmap *apn_info) { |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 236 | if (!LoadApnField(storage, storage_group, keytag, kApnProperty, apn_info)) |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 237 | return; |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 238 | LoadApnField(storage, storage_group, keytag, kApnUsernameProperty, apn_info); |
| 239 | LoadApnField(storage, storage_group, keytag, kApnPasswordProperty, apn_info); |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | bool CellularService::LoadApnField(StoreInterface *storage, |
| 243 | const string &storage_group, |
| 244 | const string &keytag, |
| 245 | const string &apntag, |
| 246 | Stringmap *apn_info) { |
| 247 | string value; |
| 248 | if (storage->GetString(storage_group, keytag + "." + apntag, &value) && |
| 249 | !value.empty()) { |
| 250 | (*apn_info)[apntag] = value; |
| 251 | return true; |
| 252 | } |
| 253 | return false; |
| 254 | } |
| 255 | |
| 256 | bool CellularService::Save(StoreInterface *storage) { |
| 257 | // Save properties common to all Services. |
| 258 | if (!Service::Save(storage)) |
| 259 | return false; |
| 260 | |
| 261 | const string id = GetStorageIdentifier(); |
| 262 | SaveApn(storage, id, GetUserSpecifiedApn(), kStorageAPN); |
| 263 | SaveApn(storage, id, GetLastGoodApn(), kStorageLastGoodAPN); |
mukesh agrawal | 3ffe52c | 2013-06-20 15:21:29 -0700 | [diff] [blame] | 264 | SaveString(storage, id, kStoragePPPUsername, ppp_username_, false, true); |
| 265 | SaveString(storage, id, kStoragePPPPassword, ppp_password_, false, true); |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 266 | return true; |
| 267 | } |
| 268 | |
| 269 | void CellularService::SaveApn(StoreInterface *storage, |
| 270 | const string &storage_group, |
| 271 | const Stringmap *apn_info, |
| 272 | const string &keytag) { |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 273 | SaveApnField(storage, storage_group, apn_info, keytag, kApnProperty); |
| 274 | SaveApnField(storage, storage_group, apn_info, keytag, kApnUsernameProperty); |
| 275 | SaveApnField(storage, storage_group, apn_info, keytag, kApnPasswordProperty); |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | void CellularService::SaveApnField(StoreInterface *storage, |
| 279 | const string &storage_group, |
| 280 | const Stringmap *apn_info, |
| 281 | const string &keytag, |
| 282 | const string &apntag) { |
| 283 | const string key = keytag + "." + apntag; |
| 284 | string str; |
| 285 | if (apn_info && GetNonEmptyField(*apn_info, apntag, &str)) |
| 286 | storage->SetString(storage_group, key, str); |
| 287 | else |
| 288 | storage->DeleteKey(storage_group, key); |
| 289 | } |
| 290 | |
Thieu Le | 43ce4d4 | 2013-10-04 16:08:55 -0700 | [diff] [blame] | 291 | bool CellularService::IsOutOfCredits(Error */*error*/) { |
| 292 | return out_of_credits_detector_->out_of_credits(); |
| 293 | } |
| 294 | |
| 295 | void CellularService::set_out_of_credits_detector( |
| 296 | OutOfCreditsDetector *detector) { |
| 297 | out_of_credits_detector_.reset(detector); |
| 298 | } |
| 299 | |
| 300 | void CellularService::SignalOutOfCreditsChanged(bool state) const { |
| 301 | adaptor()->EmitBoolChanged(kOutOfCreditsProperty, state); |
| 302 | } |
| 303 | |
Thieu Le | 7cf36b0 | 2013-01-30 17:15:56 -0800 | [diff] [blame] | 304 | void CellularService::AutoConnect() { |
| 305 | is_auto_connecting_ = true; |
| 306 | Service::AutoConnect(); |
| 307 | is_auto_connecting_ = false; |
| 308 | } |
| 309 | |
mukesh agrawal | dc7b844 | 2012-09-27 13:48:14 -0700 | [diff] [blame] | 310 | void CellularService::Connect(Error *error, const char *reason) { |
mukesh agrawal | dc7b844 | 2012-09-27 13:48:14 -0700 | [diff] [blame] | 311 | Service::Connect(error, reason); |
Darin Petkov | 4d6d941 | 2011-08-24 13:19:54 -0700 | [diff] [blame] | 312 | cellular_->Connect(error); |
Thieu Le | 398b1da | 2013-03-11 17:31:10 -0700 | [diff] [blame] | 313 | if (error->IsFailure()) |
Thieu Le | 43ce4d4 | 2013-10-04 16:08:55 -0700 | [diff] [blame] | 314 | out_of_credits_detector_->ResetDetector(); |
Darin Petkov | c5f5656 | 2011-08-06 16:40:05 -0700 | [diff] [blame] | 315 | } |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 316 | |
Samuel Tan | 0d06119 | 2014-07-07 15:45:15 -0700 | [diff] [blame] | 317 | void CellularService::Disconnect(Error *error, const char *reason) { |
| 318 | Service::Disconnect(error, reason); |
| 319 | cellular_->Disconnect(error, reason); |
Darin Petkov | fb0625e | 2012-01-16 13:05:56 +0100 | [diff] [blame] | 320 | } |
| 321 | |
Darin Petkov | b100ae7 | 2011-08-24 16:19:45 -0700 | [diff] [blame] | 322 | void CellularService::ActivateCellularModem(const string &carrier, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 323 | Error *error, |
| 324 | const ResultCallback &callback) { |
| 325 | cellular_->Activate(carrier, error, callback); |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 326 | } |
| 327 | |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 328 | void CellularService::CompleteCellularActivation(Error *error) { |
| 329 | cellular_->CompleteActivation(error); |
| 330 | } |
| 331 | |
Thieu Le | 398b1da | 2013-03-11 17:31:10 -0700 | [diff] [blame] | 332 | void CellularService::SetState(ConnectState new_state) { |
Thieu Le | 43ce4d4 | 2013-10-04 16:08:55 -0700 | [diff] [blame] | 333 | out_of_credits_detector_->NotifyServiceStateChanged(state(), new_state); |
Thieu Le | 398b1da | 2013-03-11 17:31:10 -0700 | [diff] [blame] | 334 | Service::SetState(new_state); |
| 335 | } |
| 336 | |
Darin Petkov | 3133241 | 2012-01-28 01:50:02 +0100 | [diff] [blame] | 337 | void CellularService::SetStorageIdentifier(const string &identifier) { |
Prathmesh Prabhu | 401a5b9 | 2014-04-29 17:37:55 -0700 | [diff] [blame] | 338 | SLOG(Cellular, 3) << __func__ << ": " << identifier; |
Darin Petkov | 3133241 | 2012-01-28 01:50:02 +0100 | [diff] [blame] | 339 | storage_identifier_ = identifier; |
| 340 | std::replace_if(storage_identifier_.begin(), |
| 341 | storage_identifier_.end(), |
| 342 | &Service::IllegalChar, '_'); |
| 343 | } |
| 344 | |
Chris Masone | 6515aab | 2011-10-12 16:19:09 -0700 | [diff] [blame] | 345 | string CellularService::GetStorageIdentifier() const { |
Darin Petkov | 3133241 | 2012-01-28 01:50:02 +0100 | [diff] [blame] | 346 | return storage_identifier_; |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 347 | } |
| 348 | |
Paul Stewart | 1cf7eb8 | 2013-12-03 19:34:36 -0800 | [diff] [blame] | 349 | string CellularService::GetDeviceRpcId(Error */*error*/) const { |
Chris Masone | 95207da | 2011-06-29 16:50:49 -0700 | [diff] [blame] | 350 | return cellular_->GetRpcIdentifier(); |
| 351 | } |
| 352 | |
Ben Chan | 3d6de0e | 2012-12-10 12:01:34 -0800 | [diff] [blame] | 353 | void CellularService::SetActivateOverNonCellularNetwork(bool state) { |
| 354 | if (state == activate_over_non_cellular_network_) { |
| 355 | return; |
| 356 | } |
| 357 | activate_over_non_cellular_network_ = state; |
| 358 | adaptor()->EmitBoolChanged(kActivateOverNonCellularNetworkProperty, state); |
| 359 | } |
| 360 | |
Darin Petkov | b9c9933 | 2012-01-12 13:13:00 +0100 | [diff] [blame] | 361 | void CellularService::SetActivationState(const string &state) { |
| 362 | if (state == activation_state_) { |
| 363 | return; |
| 364 | } |
| 365 | activation_state_ = state; |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 366 | adaptor()->EmitStringChanged(kActivationStateProperty, state); |
| 367 | SetConnectableFull(state != kActivationStateNotActivated); |
Darin Petkov | b9c9933 | 2012-01-12 13:13:00 +0100 | [diff] [blame] | 368 | } |
| 369 | |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame] | 370 | void CellularService::SetOLP(const string &url, |
| 371 | const string &method, |
| 372 | const string &post_data) { |
| 373 | Stringmap olp; |
| 374 | olp[kPaymentPortalURL] = url; |
| 375 | olp[kPaymentPortalMethod] = method; |
| 376 | olp[kPaymentPortalPostData] = post_data; |
| 377 | |
| 378 | if (olp_ == olp) { |
Darin Petkov | 381928f | 2012-02-02 23:00:12 +0100 | [diff] [blame] | 379 | return; |
| 380 | } |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame] | 381 | olp_ = olp; |
| 382 | adaptor()->EmitStringmapChanged(kPaymentPortalProperty, olp); |
Darin Petkov | 381928f | 2012-02-02 23:00:12 +0100 | [diff] [blame] | 383 | } |
| 384 | |
Arman Uguray | 2717a10 | 2013-01-29 23:36:06 -0800 | [diff] [blame] | 385 | void CellularService::SetUsageURL(const string &url) { |
Darin Petkov | 381928f | 2012-02-02 23:00:12 +0100 | [diff] [blame] | 386 | if (url == usage_url_) { |
| 387 | return; |
| 388 | } |
| 389 | usage_url_ = url; |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 390 | adaptor()->EmitStringChanged(kUsageURLProperty, url); |
Darin Petkov | 381928f | 2012-02-02 23:00:12 +0100 | [diff] [blame] | 391 | } |
| 392 | |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 393 | void CellularService::SetNetworkTechnology(const string &technology) { |
| 394 | if (technology == network_technology_) { |
| 395 | return; |
| 396 | } |
| 397 | network_technology_ = technology; |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 398 | adaptor()->EmitStringChanged(kNetworkTechnologyProperty, |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 399 | technology); |
| 400 | } |
| 401 | |
| 402 | void CellularService::SetRoamingState(const string &state) { |
| 403 | if (state == roaming_state_) { |
| 404 | return; |
| 405 | } |
| 406 | roaming_state_ = state; |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 407 | adaptor()->EmitStringChanged(kRoamingStateProperty, state); |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 408 | } |
| 409 | |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 410 | const Cellular::Operator &CellularService::serving_operator() const { |
| 411 | return serving_operator_; |
| 412 | } |
| 413 | |
Darin Petkov | 9cb0268 | 2012-01-28 00:17:38 +0100 | [diff] [blame] | 414 | void CellularService::SetServingOperator(const Cellular::Operator &oper) { |
| 415 | if (serving_operator_.Equals(oper)) { |
| 416 | return; |
| 417 | } |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 418 | serving_operator_.CopyFrom(oper); |
Ben Chan | 7ea768e | 2013-09-20 15:08:40 -0700 | [diff] [blame] | 419 | adaptor()->EmitStringmapChanged(kServingOperatorProperty, oper.ToDict()); |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 420 | } |
| 421 | |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 422 | } // namespace shill |