OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/mobile/mobile_activator.h" | 5 #include "chrome/browser/chromeos/mobile/mobile_activator.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "ash/system/chromeos/network/network_connect.h" | 11 #include "ash/system/chromeos/network/network_connect.h" |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
14 #include "base/file_util.h" | 14 #include "base/file_util.h" |
15 #include "base/json/json_reader.h" | 15 #include "base/json/json_reader.h" |
16 #include "base/location.h" | |
16 #include "base/logging.h" | 17 #include "base/logging.h" |
17 #include "base/memory/ref_counted_memory.h" | 18 #include "base/memory/ref_counted_memory.h" |
18 #include "base/message_loop/message_loop.h" | 19 #include "base/message_loop/message_loop.h" |
19 #include "base/metrics/histogram.h" | 20 #include "base/metrics/histogram.h" |
20 #include "base/observer_list_threadsafe.h" | 21 #include "base/observer_list_threadsafe.h" |
21 #include "base/prefs/pref_service.h" | 22 #include "base/prefs/pref_service.h" |
22 #include "base/strings/string_piece.h" | 23 #include "base/strings/string_piece.h" |
23 #include "base/strings/string_util.h" | 24 #include "base/strings/string_util.h" |
24 #include "base/strings/utf_string_conversions.h" | 25 #include "base/strings/utf_string_conversions.h" |
25 #include "base/timer/timer.h" | 26 #include "base/timer/timer.h" |
26 #include "base/values.h" | 27 #include "base/values.h" |
27 #include "chrome/browser/browser_process.h" | 28 #include "chrome/browser/browser_process.h" |
28 #include "chrome/browser/chromeos/cros/network_library.h" | |
29 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
30 #include "chromeos/network/device_state.h" | |
31 #include "chromeos/network/network_activation_handler.h" | |
32 #include "chromeos/network/network_configuration_handler.h" | |
33 #include "chromeos/network/network_connection_handler.h" | |
34 #include "chromeos/network/network_event_log.h" | |
35 #include "chromeos/network/network_handler_callbacks.h" | |
36 #include "chromeos/network/network_state.h" | |
37 #include "chromeos/network/network_state_handler.h" | |
30 #include "content/public/browser/browser_thread.h" | 38 #include "content/public/browser/browser_thread.h" |
39 #include "third_party/cros_system_api/dbus/service_constants.h" | |
31 | 40 |
32 using content::BrowserThread; | 41 using content::BrowserThread; |
33 | 42 |
34 namespace { | 43 namespace { |
35 | 44 |
36 // Cellular configuration file path. | 45 // Cellular configuration file path. |
37 const char kCellularConfigPath[] = | 46 const char kCellularConfigPath[] = |
38 "/usr/share/chromeos-assets/mobile/mobile_config.json"; | 47 "/usr/share/chromeos-assets/mobile/mobile_config.json"; |
39 | 48 |
40 // Cellular config file field names. | 49 // Cellular config file field names. |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
144 //////////////////////////////////////////////////////////////////////////////// | 153 //////////////////////////////////////////////////////////////////////////////// |
145 // | 154 // |
146 // MobileActivator | 155 // MobileActivator |
147 // | 156 // |
148 //////////////////////////////////////////////////////////////////////////////// | 157 //////////////////////////////////////////////////////////////////////////////// |
149 MobileActivator::MobileActivator() | 158 MobileActivator::MobileActivator() |
150 : cellular_config_(new CellularConfigDocument()), | 159 : cellular_config_(new CellularConfigDocument()), |
151 state_(PLAN_ACTIVATION_PAGE_LOADING), | 160 state_(PLAN_ACTIVATION_PAGE_LOADING), |
152 reenable_cert_check_(false), | 161 reenable_cert_check_(false), |
153 terminated_(true), | 162 terminated_(true), |
163 pending_activation_request_(false), | |
154 connection_retry_count_(0), | 164 connection_retry_count_(0), |
165 initial_OTASP_attempts_(0), | |
166 trying_OTASP_attempts_(0), | |
167 final_OTASP_attempts_(0), | |
155 payment_reconnect_count_(0) { | 168 payment_reconnect_count_(0) { |
156 } | 169 } |
157 | 170 |
158 MobileActivator::~MobileActivator() { | 171 MobileActivator::~MobileActivator() { |
159 TerminateActivation(); | 172 TerminateActivation(); |
160 } | 173 } |
161 | 174 |
162 MobileActivator* MobileActivator::GetInstance() { | 175 MobileActivator* MobileActivator::GetInstance() { |
163 return Singleton<MobileActivator>::get(); | 176 return Singleton<MobileActivator>::get(); |
164 } | 177 } |
165 | 178 |
166 void MobileActivator::TerminateActivation() { | 179 void MobileActivator::TerminateActivation() { |
167 // We're exiting; don't continue with termination. | |
168 if (!NetworkLibrary::Get()) | |
169 return; | |
170 | |
171 state_duration_timer_.Stop(); | 180 state_duration_timer_.Stop(); |
172 continue_reconnect_timer_.Stop(); | 181 continue_reconnect_timer_.Stop(); |
173 reconnect_timeout_timer_.Stop(); | 182 reconnect_timeout_timer_.Stop(); |
174 | 183 |
175 NetworkLibrary* lib = GetNetworkLibrary(); | 184 if (NetworkHandler::IsInitialized()) |
176 lib->RemoveNetworkManagerObserver(this); | 185 NetworkHandler::Get()->network_state_handler()->RemoveObserver(this, |
177 lib->RemoveObserverForAllNetworks(this); | 186 FROM_HERE); |
178 ReEnableCertRevocationChecking(); | 187 ReEnableCertRevocationChecking(); |
179 meid_.clear(); | 188 meid_.clear(); |
180 iccid_.clear(); | 189 iccid_.clear(); |
181 service_path_.clear(); | 190 service_path_.clear(); |
191 device_path_.clear(); | |
182 state_ = PLAN_ACTIVATION_PAGE_LOADING; | 192 state_ = PLAN_ACTIVATION_PAGE_LOADING; |
183 reenable_cert_check_ = false; | 193 reenable_cert_check_ = false; |
184 terminated_ = true; | 194 terminated_ = true; |
185 // Release the previous cellular config and setup a new empty one. | 195 // Release the previous cellular config and setup a new empty one. |
186 cellular_config_ = new CellularConfigDocument(); | 196 cellular_config_ = new CellularConfigDocument(); |
187 } | 197 } |
188 | 198 |
189 void MobileActivator::OnNetworkManagerChanged(NetworkLibrary* cros) { | 199 void MobileActivator::DefaultNetworkChanged(const NetworkState* network) { |
190 if (state_ == PLAN_ACTIVATION_PAGE_LOADING || | 200 RefreshCellularNetworks(); |
191 state_ == PLAN_ACTIVATION_DONE || | 201 } |
192 state_ == PLAN_ACTIVATION_ERROR) { | 202 |
203 void MobileActivator::NetworkPropertiesUpdated(const NetworkState* network) { | |
204 if (state_ == PLAN_ACTIVATION_PAGE_LOADING) | |
205 return; | |
206 | |
207 if (!network || network->type() != flimflam::kTypeCellular) | |
208 return; | |
209 | |
210 const DeviceState* device = NetworkHandler::Get()->network_state_handler()-> | |
211 GetDeviceState(network->device_path()); | |
212 if (!device) { | |
213 LOG(ERROR) << "Cellular device can't be found: " << network->device_path(); | |
214 return; | |
215 } | |
216 if (network->device_path() != device_path_) { | |
217 LOG(WARNING) << "Ignoring property update for cellular service " | |
218 << network->path() | |
219 << " on unknown device " << network->device_path() | |
220 << " (Stored device path = " << device_path_ << ")"; | |
193 return; | 221 return; |
194 } | 222 } |
195 | 223 |
196 CellularNetwork* network = FindMatchingCellularNetwork(true); | 224 // A modem reset leads to a new service path. Since we have verified that we |
197 if (network && network->activate_over_non_cellular_network()) { | 225 // are a cellular service on a still valid stored device path, update it. |
198 bool waiting = (state_ == PLAN_ACTIVATION_WAITING_FOR_CONNECTION); | 226 service_path_ = network->path(); |
199 bool is_online = | |
200 cros->connected_network() && cros->connected_network()->online(); | |
201 if (waiting && is_online) { | |
202 ChangeState(network, post_reconnect_state_, ""); | |
203 } else if (!waiting && !is_online) { | |
204 ChangeState(network, PLAN_ACTIVATION_WAITING_FOR_CONNECTION, ""); | |
205 } | |
206 } | |
207 | 227 |
208 EvaluateCellularNetwork(network); | 228 EvaluateCellularNetwork(network); |
209 } | 229 } |
210 | 230 |
211 void MobileActivator::OnNetworkChanged(NetworkLibrary* cros, | |
212 const Network* network) { | |
213 if (state_ == PLAN_ACTIVATION_PAGE_LOADING) | |
214 return; | |
215 | |
216 if (!network || network->type() != TYPE_CELLULAR) { | |
217 NOTREACHED(); | |
218 return; | |
219 } | |
220 | |
221 EvaluateCellularNetwork( | |
222 static_cast<CellularNetwork*>(const_cast<Network*>(network))); | |
223 } | |
224 | |
225 void MobileActivator::AddObserver(MobileActivator::Observer* observer) { | 231 void MobileActivator::AddObserver(MobileActivator::Observer* observer) { |
226 DCHECK(content::BrowserThread::CurrentlyOn(BrowserThread::UI)); | 232 DCHECK(content::BrowserThread::CurrentlyOn(BrowserThread::UI)); |
227 observers_.AddObserver(observer); | 233 observers_.AddObserver(observer); |
228 } | 234 } |
229 | 235 |
230 void MobileActivator::RemoveObserver(MobileActivator::Observer* observer) { | 236 void MobileActivator::RemoveObserver(MobileActivator::Observer* observer) { |
231 DCHECK(content::BrowserThread::CurrentlyOn(BrowserThread::UI)); | 237 DCHECK(content::BrowserThread::CurrentlyOn(BrowserThread::UI)); |
232 observers_.RemoveObserver(observer); | 238 observers_.RemoveObserver(observer); |
233 } | 239 } |
234 | 240 |
235 void MobileActivator::InitiateActivation(const std::string& service_path) { | 241 void MobileActivator::InitiateActivation(const std::string& service_path) { |
236 DCHECK(content::BrowserThread::CurrentlyOn(BrowserThread::UI)); | 242 DCHECK(content::BrowserThread::CurrentlyOn(BrowserThread::UI)); |
237 NetworkLibrary* lib = GetNetworkLibrary(); | 243 const NetworkState* network = GetNetworkState(service_path); |
238 CellularNetwork* network = lib->FindCellularNetworkByPath(service_path); | |
239 if (!network) { | 244 if (!network) { |
240 LOG(ERROR) << "Cellular service can't be found: " << service_path; | 245 LOG(ERROR) << "Cellular service can't be found: " << service_path; |
241 return; | 246 return; |
242 } | 247 } |
243 | 248 |
244 const chromeos::NetworkDevice* device = | 249 const DeviceState* device = NetworkHandler::Get()->network_state_handler()-> |
245 lib->FindNetworkDeviceByPath(network->device_path()); | 250 GetDeviceState(network->device_path()); |
246 if (!device) { | 251 if (!device) { |
247 LOG(ERROR) << "Cellular device can't be found: " << network->device_path(); | 252 LOG(ERROR) << "Cellular device can't be found: " << network->device_path(); |
248 return; | 253 return; |
249 } | 254 } |
250 | 255 |
251 terminated_ = false; | 256 terminated_ = false; |
252 meid_ = device->meid(); | 257 meid_ = device->meid(); |
253 iccid_ = device->iccid(); | 258 iccid_ = device->iccid(); |
254 service_path_ = service_path; | 259 service_path_ = service_path; |
260 device_path_ = network->device_path(); | |
255 | 261 |
256 ChangeState(network, PLAN_ACTIVATION_PAGE_LOADING, ""); | 262 ChangeState(network, PLAN_ACTIVATION_PAGE_LOADING, ""); |
257 | 263 |
258 BrowserThread::PostTaskAndReply(BrowserThread::FILE, FROM_HERE, | 264 BrowserThread::PostTaskAndReply(BrowserThread::FILE, FROM_HERE, |
259 base::Bind(&CellularConfigDocument::LoadCellularConfigFile, | 265 base::Bind(&CellularConfigDocument::LoadCellularConfigFile, |
260 cellular_config_.get()), | 266 cellular_config_.get()), |
261 base::Bind(&MobileActivator::ContinueActivation, AsWeakPtr())); | 267 base::Bind(&MobileActivator::ContinueActivation, AsWeakPtr())); |
262 } | 268 } |
263 | 269 |
264 void MobileActivator::ContinueActivation() { | 270 void MobileActivator::ContinueActivation() { |
265 CellularNetwork* network = FindMatchingCellularNetwork(false); | 271 const NetworkState* network = GetNetworkState(service_path_); |
266 if (!network || !network->SupportsActivation()) | 272 if (!network || |
273 (network->payment_url().empty() && network->usage_url().empty())) | |
267 return; | 274 return; |
268 | 275 |
269 DisableCertRevocationChecking(); | 276 DisableCertRevocationChecking(); |
270 // We want shill to connect us after activations. | |
271 network->SetAutoConnect(true); | |
272 | 277 |
278 // We want shill to connect us after activations, so enable autoconnect. | |
279 DictionaryValue auto_connect_property; | |
280 auto_connect_property.SetBoolean(flimflam::kAutoConnectProperty, true); | |
281 NetworkHandler::Get()->network_configuration_handler()->SetProperties( | |
282 network->path(), | |
283 auto_connect_property, | |
284 base::Bind(&base::DoNothing), | |
285 network_handler::ErrorCallback()); | |
273 StartActivation(); | 286 StartActivation(); |
274 } | 287 } |
275 | 288 |
276 void MobileActivator::OnSetTransactionStatus(bool success) { | 289 void MobileActivator::OnSetTransactionStatus(bool success) { |
277 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 290 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
278 base::Bind(&MobileActivator::HandleSetTransactionStatus, | 291 base::Bind(&MobileActivator::HandleSetTransactionStatus, |
279 AsWeakPtr(), success)); | 292 AsWeakPtr(), success)); |
280 } | 293 } |
281 | 294 |
282 void MobileActivator::HandleSetTransactionStatus(bool success) { | 295 void MobileActivator::HandleSetTransactionStatus(bool success) { |
283 // The payment is received, try to reconnect and check the status all over | 296 // The payment is received, try to reconnect and check the status all over |
284 // again. | 297 // again. |
285 if (success && state_ == PLAN_ACTIVATION_SHOWING_PAYMENT) { | 298 if (success && state_ == PLAN_ACTIVATION_SHOWING_PAYMENT) { |
286 NetworkLibrary* lib = GetNetworkLibrary(); | 299 SignalCellularPlanPayment(); |
287 lib->SignalCellularPlanPayment(); | |
288 UMA_HISTOGRAM_COUNTS("Cellular.PaymentReceived", 1); | 300 UMA_HISTOGRAM_COUNTS("Cellular.PaymentReceived", 1); |
289 CellularNetwork* network = FindMatchingCellularNetwork(true); | 301 const NetworkState* network = GetNetworkState(service_path_); |
290 if (network && network->activate_over_non_cellular_network()) { | 302 if (network && network->activate_over_non_cellular_networks()) { |
291 state_ = PLAN_ACTIVATION_DONE; | 303 state_ = PLAN_ACTIVATION_DONE; |
292 network->CompleteActivation(); | 304 NetworkHandler::Get()->network_activation_handler()-> |
305 CompleteActivation(network->path(), | |
306 base::Bind(&base::DoNothing), | |
307 network_handler::ErrorCallback()); | |
293 } else { | 308 } else { |
294 StartOTASP(); | 309 StartOTASP(); |
295 } | 310 } |
296 } else { | 311 } else { |
297 UMA_HISTOGRAM_COUNTS("Cellular.PaymentFailed", 1); | 312 UMA_HISTOGRAM_COUNTS("Cellular.PaymentFailed", 1); |
298 } | 313 } |
299 } | 314 } |
300 | 315 |
301 void MobileActivator::OnPortalLoaded(bool success) { | 316 void MobileActivator::OnPortalLoaded(bool success) { |
302 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 317 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
303 base::Bind(&MobileActivator::HandlePortalLoaded, | 318 base::Bind(&MobileActivator::HandlePortalLoaded, |
304 AsWeakPtr(), success)); | 319 AsWeakPtr(), success)); |
305 } | 320 } |
306 | 321 |
307 void MobileActivator::HandlePortalLoaded(bool success) { | 322 void MobileActivator::HandlePortalLoaded(bool success) { |
308 CellularNetwork* network = FindMatchingCellularNetwork(true); | 323 const NetworkState* network = GetNetworkState(service_path_); |
309 if (!network) { | 324 if (!network) { |
310 ChangeState(NULL, PLAN_ACTIVATION_ERROR, | 325 ChangeState(NULL, PLAN_ACTIVATION_ERROR, |
311 GetErrorMessage(kErrorNoService)); | 326 GetErrorMessage(kErrorNoService)); |
312 return; | 327 return; |
313 } | 328 } |
314 if (state_ == PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING || | 329 if (state_ == PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING || |
315 state_ == PLAN_ACTIVATION_SHOWING_PAYMENT) { | 330 state_ == PLAN_ACTIVATION_SHOWING_PAYMENT) { |
316 if (success) { | 331 if (success) { |
317 payment_reconnect_count_ = 0; | 332 payment_reconnect_count_ = 0; |
318 ChangeState(network, PLAN_ACTIVATION_SHOWING_PAYMENT, std::string()); | 333 ChangeState(network, PLAN_ACTIVATION_SHOWING_PAYMENT, std::string()); |
319 } else { | 334 } else { |
320 // There is no point in forcing reconnecting the cellular network if the | 335 // There is no point in forcing reconnecting the cellular network if the |
321 // activation should not be done over it. | 336 // activation should not be done over it. |
322 if (network->activate_over_non_cellular_network()) | 337 if (network->activate_over_non_cellular_networks()) |
323 return; | 338 return; |
324 | 339 |
325 payment_reconnect_count_++; | 340 payment_reconnect_count_++; |
326 if (payment_reconnect_count_ > kMaxPortalReconnectCount) { | 341 if (payment_reconnect_count_ > kMaxPortalReconnectCount) { |
327 ChangeState(NULL, PLAN_ACTIVATION_ERROR, | 342 ChangeState(NULL, PLAN_ACTIVATION_ERROR, |
328 GetErrorMessage(kErrorNoService)); | 343 GetErrorMessage(kErrorNoService)); |
329 return; | 344 return; |
330 } | 345 } |
331 | 346 |
332 // Reconnect and try and load the frame again. | 347 // Reconnect and try and load the frame again. |
333 ChangeState(network, | 348 ChangeState(network, |
334 PLAN_ACTIVATION_RECONNECTING, | 349 PLAN_ACTIVATION_RECONNECTING, |
335 GetErrorMessage(kFailedPaymentError)); | 350 GetErrorMessage(kFailedPaymentError)); |
336 } | 351 } |
337 } else { | 352 } else { |
338 NOTREACHED() << "Called paymentPortalLoad while in unexpected state: " | 353 NOTREACHED() << "Called paymentPortalLoad while in unexpected state: " |
339 << GetStateDescription(state_); | 354 << GetStateDescription(state_); |
340 } | 355 } |
341 } | 356 } |
342 | 357 |
343 CellularNetwork* MobileActivator::FindMatchingCellularNetwork( | |
344 bool reattach_observer) { | |
345 NetworkLibrary* lib = GetNetworkLibrary(); | |
346 for (CellularNetworkVector::const_iterator it = | |
347 lib->cellular_networks().begin(); | |
348 it != lib->cellular_networks().end(); ++it) { | |
349 const chromeos::NetworkDevice* device = | |
350 lib->FindNetworkDeviceByPath((*it)->device_path()); | |
351 if (device && ((!meid_.empty() && meid_ == device->meid()) || | |
352 (!iccid_.empty() && iccid_ == device->iccid()))) { | |
353 CellularNetwork* network = *it; | |
354 // If service path has changed, reattach the event observer for this | |
355 // network service. | |
356 if (reattach_observer && service_path_ != network->service_path()) { | |
357 lib->RemoveObserverForAllNetworks(this); | |
358 lib->AddNetworkObserver(network->service_path(), this); | |
359 service_path_ = network->service_path(); | |
360 } | |
361 return network; | |
362 } | |
363 } | |
364 return NULL; | |
365 } | |
366 | |
367 void MobileActivator::StartOTASPTimer() { | 358 void MobileActivator::StartOTASPTimer() { |
359 pending_activation_request_ = false; | |
368 state_duration_timer_.Start( | 360 state_duration_timer_.Start( |
369 FROM_HERE, | 361 FROM_HERE, |
370 base::TimeDelta::FromMilliseconds(kOTASPRetryDelay), | 362 base::TimeDelta::FromMilliseconds(kOTASPRetryDelay), |
371 this, &MobileActivator::HandleOTASPTimeout); | 363 this, &MobileActivator::HandleOTASPTimeout); |
372 } | 364 } |
373 | 365 |
374 void MobileActivator::StartActivation() { | 366 void MobileActivator::StartActivation() { |
375 UMA_HISTOGRAM_COUNTS("Cellular.MobileSetupStart", 1); | 367 UMA_HISTOGRAM_COUNTS("Cellular.MobileSetupStart", 1); |
376 NetworkLibrary* lib = GetNetworkLibrary(); | 368 const NetworkState* network = GetNetworkState(service_path_); |
377 CellularNetwork* network = FindMatchingCellularNetwork(true); | |
378 // Check if we can start activation process. | 369 // Check if we can start activation process. |
379 if (!network) { | 370 if (!network) { |
371 NetworkStateHandler::TechnologyState technology_state = | |
372 NetworkHandler::Get()->network_state_handler()->GetTechnologyState( | |
373 flimflam::kTypeCellular); | |
380 std::string error; | 374 std::string error; |
381 if (!lib->cellular_available()) | 375 if (technology_state == NetworkStateHandler::TECHNOLOGY_UNAVAILABLE) { |
382 error = kErrorNoDevice; | 376 error = kErrorNoDevice; |
383 else if (!lib->cellular_enabled()) | 377 } else if (technology_state !=NetworkStateHandler::TECHNOLOGY_ENABLED) { |
stevenjb
2013/08/28 21:22:47
' ' after !=
gauravsh
2013/08/28 23:45:07
Done.
| |
384 error = kErrorDisabled; | 378 error = kErrorDisabled; |
385 else | 379 } else { |
386 error = kErrorNoService; | 380 error = kErrorNoService; |
381 } | |
387 ChangeState(NULL, PLAN_ACTIVATION_ERROR, GetErrorMessage(error)); | 382 ChangeState(NULL, PLAN_ACTIVATION_ERROR, GetErrorMessage(error)); |
388 return; | 383 return; |
389 } | 384 } |
390 | 385 |
391 // Start monitoring network property changes. | 386 // Start monitoring network property changes. |
392 lib->AddNetworkManagerObserver(this); | 387 NetworkHandler::Get()->network_state_handler()->AddObserver(this, FROM_HERE); |
393 if (network->activate_over_non_cellular_network()) { | 388 if (network->activate_over_non_cellular_networks()) { |
394 // Fast forward to payment portal loading if the activation is performed | 389 // Fast forward to payment portal loading if the activation is performed |
395 // over a non-cellular network. | 390 // over a non-cellular network. |
396 ChangeState(network, | 391 ChangeState( |
397 (network->activation_state() == ACTIVATION_STATE_ACTIVATED) ? | 392 network, |
398 PLAN_ACTIVATION_DONE : | 393 (network->activation_state() == flimflam::kActivationStateActivated) ? |
399 PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING, | 394 PLAN_ACTIVATION_DONE : |
400 ""); | 395 PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING, |
396 ""); | |
401 // Verify that there is no need to wait for the connection. This will also | 397 // Verify that there is no need to wait for the connection. This will also |
402 // evaluate the network. | 398 // evaluate the network. |
403 OnNetworkManagerChanged(lib); | 399 RefreshCellularNetworks(); |
404 return; | 400 return; |
405 } | 401 } |
406 | 402 |
407 if (lib->HasRecentCellularPlanPayment() && | 403 if (HasRecentCellularPlanPayment() && |
408 network->activation_state() == ACTIVATION_STATE_PARTIALLY_ACTIVATED) { | 404 (network->activation_state() == |
405 flimflam::kActivationStatePartiallyActivated)) { | |
409 // Try to start with OTASP immediately if we have received payment recently. | 406 // Try to start with OTASP immediately if we have received payment recently. |
410 state_ = PLAN_ACTIVATION_START_OTASP; | 407 state_ = PLAN_ACTIVATION_START_OTASP; |
411 } else { | 408 } else { |
412 state_ = PLAN_ACTIVATION_START; | 409 state_ = PLAN_ACTIVATION_START; |
413 } | 410 } |
414 | 411 |
415 EvaluateCellularNetwork(network); | 412 EvaluateCellularNetwork(network); |
416 } | 413 } |
417 | 414 |
418 void MobileActivator::RetryOTASP() { | 415 void MobileActivator::RetryOTASP() { |
419 DCHECK(state_ == PLAN_ACTIVATION_DELAY_OTASP); | 416 DCHECK(state_ == PLAN_ACTIVATION_DELAY_OTASP); |
420 StartOTASP(); | 417 StartOTASP(); |
421 } | 418 } |
422 | 419 |
423 void MobileActivator::StartOTASP() { | 420 void MobileActivator::StartOTASP() { |
424 CellularNetwork* network = FindMatchingCellularNetwork(true); | 421 const NetworkState* network = GetNetworkState(service_path_); |
425 ChangeState(network, PLAN_ACTIVATION_START_OTASP, std::string()); | 422 ChangeState(network, PLAN_ACTIVATION_START_OTASP, std::string()); |
426 EvaluateCellularNetwork(network); | 423 EvaluateCellularNetwork(network); |
427 } | 424 } |
428 | 425 |
429 void MobileActivator::HandleOTASPTimeout() { | 426 void MobileActivator::HandleOTASPTimeout() { |
430 LOG(WARNING) << "OTASP seems to be taking too long."; | 427 LOG(WARNING) << "OTASP seems to be taking too long."; |
431 CellularNetwork* network = FindMatchingCellularNetwork(true); | 428 const NetworkState* network = GetNetworkState(service_path_); |
432 // We're here because one of OTASP steps is taking too long to complete. | 429 // We're here because one of OTASP steps is taking too long to complete. |
433 // Usually, this means something bad has happened below us. | 430 // Usually, this means something bad has happened below us. |
434 if (state_ == PLAN_ACTIVATION_INITIATING_ACTIVATION) { | 431 if (state_ == PLAN_ACTIVATION_INITIATING_ACTIVATION) { |
435 ++initial_OTASP_attempts_; | 432 ++initial_OTASP_attempts_; |
436 if (initial_OTASP_attempts_ <= kMaxOTASPTries) { | 433 if (initial_OTASP_attempts_ <= kMaxOTASPTries) { |
437 ChangeState(network, | 434 ChangeState(network, |
438 PLAN_ACTIVATION_RECONNECTING, | 435 PLAN_ACTIVATION_RECONNECTING, |
439 GetErrorMessage(kErrorDefault)); | 436 GetErrorMessage(kErrorDefault)); |
440 return; | 437 return; |
441 } | 438 } |
(...skipping 16 matching lines...) Expand all Loading... | |
458 } | 455 } |
459 } else { | 456 } else { |
460 LOG(ERROR) << "OTASP timed out from a non-OTASP wait state?"; | 457 LOG(ERROR) << "OTASP timed out from a non-OTASP wait state?"; |
461 } | 458 } |
462 LOG(ERROR) << "OTASP failed too many times; aborting."; | 459 LOG(ERROR) << "OTASP failed too many times; aborting."; |
463 ChangeState(network, | 460 ChangeState(network, |
464 PLAN_ACTIVATION_ERROR, | 461 PLAN_ACTIVATION_ERROR, |
465 GetErrorMessage(kErrorDefault)); | 462 GetErrorMessage(kErrorDefault)); |
466 } | 463 } |
467 | 464 |
468 void MobileActivator::ForceReconnect(CellularNetwork* network, | 465 void MobileActivator::ForceReconnect(const NetworkState* network, |
469 PlanActivationState next_state) { | 466 PlanActivationState next_state) { |
470 DCHECK(network); | 467 DCHECK(network); |
471 // Store away our next destination for when we complete. | 468 // Store away our next destination for when we complete. |
472 post_reconnect_state_ = next_state; | 469 post_reconnect_state_ = next_state; |
473 UMA_HISTOGRAM_COUNTS("Cellular.ActivationRetry", 1); | 470 UMA_HISTOGRAM_COUNTS("Cellular.ActivationRetry", 1); |
474 // First, disconnect... | 471 // First, disconnect... |
475 LOG(INFO) << "Disconnecting from " << network->service_path(); | 472 LOG(INFO) << "Disconnecting from " << network->path(); |
476 // Explicit service Disconnect()s disable autoconnect on the service until | 473 // Explicit service Disconnect()s disable autoconnect on the service until |
477 // Connect() is called on the service again. Hence this dance to explicitly | 474 // Connect() is called on the service again. Hence this dance to explicitly |
478 // call Connect(). | 475 // call Connect(). |
479 GetNetworkLibrary()->DisconnectFromNetwork(network); | 476 NetworkHandler::Get()->network_connection_handler()->DisconnectNetwork( |
477 network->path(), | |
478 base::Bind(&base::DoNothing), | |
479 network_handler::ErrorCallback()); | |
480 // Keep trying to connect until told otherwise. | 480 // Keep trying to connect until told otherwise. |
481 continue_reconnect_timer_.Stop(); | 481 continue_reconnect_timer_.Stop(); |
482 continue_reconnect_timer_.Start( | 482 continue_reconnect_timer_.Start( |
483 FROM_HERE, | 483 FROM_HERE, |
484 base::TimeDelta::FromMilliseconds(kReconnectDelayMS), | 484 base::TimeDelta::FromMilliseconds(kReconnectDelayMS), |
485 this, &MobileActivator::ContinueConnecting); | 485 this, &MobileActivator::ContinueConnecting); |
486 // If we don't ever connect again, we're going to call this a failure. | 486 // If we don't ever connect again, we're going to call this a failure. |
487 reconnect_timeout_timer_.Stop(); | 487 reconnect_timeout_timer_.Stop(); |
488 reconnect_timeout_timer_.Start( | 488 reconnect_timeout_timer_.Start( |
489 FROM_HERE, | 489 FROM_HERE, |
490 base::TimeDelta::FromMilliseconds(kMaxReconnectTime), | 490 base::TimeDelta::FromMilliseconds(kMaxReconnectTime), |
491 this, &MobileActivator::ReconnectTimedOut); | 491 this, &MobileActivator::ReconnectTimedOut); |
492 } | 492 } |
493 | 493 |
494 void MobileActivator::ReconnectTimedOut() { | 494 void MobileActivator::ReconnectTimedOut() { |
495 LOG(ERROR) << "Ending activation attempt after failing to reconnect."; | 495 LOG(ERROR) << "Ending activation attempt after failing to reconnect."; |
496 ChangeState(FindMatchingCellularNetwork(true), | 496 const NetworkState* network = GetNetworkState(service_path_); |
497 ChangeState(network, | |
497 PLAN_ACTIVATION_ERROR, | 498 PLAN_ACTIVATION_ERROR, |
498 GetErrorMessage(kFailedConnectivity)); | 499 GetErrorMessage(kFailedConnectivity)); |
499 } | 500 } |
500 | 501 |
501 void MobileActivator::ContinueConnecting() { | 502 void MobileActivator::ContinueConnecting() { |
502 CellularNetwork* network = FindMatchingCellularNetwork(true); | 503 const NetworkState* network = GetNetworkState(service_path_); |
503 if (network && network->connected()) { | 504 if (network && network->IsConnectedState()) { |
504 if (network->restricted_pool() && | 505 if (network->connection_state() == flimflam::kStatePortal && |
505 network->error() == ERROR_DNS_LOOKUP_FAILED) { | 506 network->error() == flimflam::kErrorDNSLookupFailed) { |
506 // It isn't an error to be in a restricted pool, but if DNS doesn't work, | 507 // It isn't an error to be in a restricted pool, but if DNS doesn't work, |
507 // then we're not getting traffic through at all. Just disconnect and | 508 // then we're not getting traffic through at all. Just disconnect and |
508 // try again. | 509 // try again. |
509 GetNetworkLibrary()->DisconnectFromNetwork(network); | 510 NetworkHandler::Get()->network_connection_handler()->DisconnectNetwork( |
511 network->path(), | |
512 base::Bind(&base::DoNothing), | |
513 network_handler::ErrorCallback()); | |
510 return; | 514 return; |
511 } | 515 } |
512 // Stop this callback | 516 // Stop this callback |
513 continue_reconnect_timer_.Stop(); | 517 continue_reconnect_timer_.Stop(); |
514 EvaluateCellularNetwork(network); | 518 EvaluateCellularNetwork(network); |
515 } else { | 519 } else { |
516 LOG(WARNING) << "Connect failed, will try again in a little bit."; | 520 LOG(WARNING) << "Connect failed, will try again in a little bit."; |
517 if (network) { | 521 if (network) { |
518 LOG(INFO) << "Connecting to: " << network->service_path(); | 522 LOG(INFO) << "Connecting to: " << network->path(); |
519 ash::network_connect::ConnectToNetwork( | 523 ash::network_connect::ConnectToNetwork( |
520 network->service_path(), NULL /* no parent window */); | 524 network->path(), NULL /* no parent window */); |
521 } | 525 } |
522 } | 526 } |
523 } | 527 } |
524 | 528 |
525 void MobileActivator::EvaluateCellularNetwork(CellularNetwork* network) { | 529 void MobileActivator::RefreshCellularNetworks() { |
530 if (state_ == PLAN_ACTIVATION_PAGE_LOADING || | |
531 state_ == PLAN_ACTIVATION_DONE || | |
532 state_ == PLAN_ACTIVATION_ERROR) { | |
533 return; | |
534 } | |
535 | |
536 NetworkStateHandler* nsh = NetworkHandler::Get()->network_state_handler(); | |
537 const NetworkState* network = GetNetworkState(service_path_); | |
538 if (network && network->activate_over_non_cellular_networks()) { | |
539 bool waiting = (state_ == PLAN_ACTIVATION_WAITING_FOR_CONNECTION); | |
540 bool is_online = nsh->DefaultNetwork() && | |
541 nsh->DefaultNetwork()->connection_state() == flimflam::kStateOnline; | |
542 if (waiting && is_online) { | |
543 ChangeState(network, post_reconnect_state_, ""); | |
544 } else if (!waiting && !is_online) { | |
545 ChangeState(network, PLAN_ACTIVATION_WAITING_FOR_CONNECTION, ""); | |
546 } | |
547 } | |
548 | |
549 EvaluateCellularNetwork(network); | |
550 } | |
551 | |
552 const NetworkState*MobileActivator::GetNetworkState( | |
stevenjb
2013/08/28 21:22:47
' ' after *
gauravsh
2013/08/28 23:45:07
Done.
| |
553 const std::string& service_path) { | |
554 return NetworkHandler::Get()->network_state_handler()->GetNetworkState( | |
555 service_path); | |
556 } | |
557 | |
558 void MobileActivator::EvaluateCellularNetwork(const NetworkState* network) { | |
526 if (terminated_) { | 559 if (terminated_) { |
527 LOG(ERROR) << "Tried to run MobileActivator state machine while " | 560 LOG(ERROR) << "Tried to run MobileActivator state machine while " |
528 << "terminated."; | 561 << "terminated."; |
529 return; | 562 return; |
530 } | 563 } |
531 | 564 |
532 if (!network) { | 565 if (!network) { |
533 LOG(WARNING) << "Cellular service lost"; | 566 LOG(WARNING) << "Cellular service lost"; |
534 return; | 567 return; |
535 } | 568 } |
536 | 569 |
537 LOG(WARNING) << "Cellular:\n service=" << network->GetStateString() | 570 LOG(WARNING) << "Cellular:\n service state=" << network->connection_state() |
538 << "\n ui=" << GetStateDescription(state_) | 571 << "\n ui=" << GetStateDescription(state_) |
539 << "\n activation=" << network->GetActivationStateString() | 572 << "\n activation=" << network->activation_state() |
540 << "\n error=" << network->GetErrorString() | 573 << "\n error=" << network->error() |
541 << "\n setvice_path=" << network->service_path() | 574 << "\n setvice_path=" << network->path() |
542 << "\n connected=" << network->connected(); | 575 << "\n connected=" << network->IsConnectedState(); |
543 | 576 |
544 // If the network is activated over non cellular network, the activator state | 577 // If the network is activated over non cellular network, the activator state |
545 // does not depend on the network's own state. | 578 // does not depend on the network's own state. |
546 if (network->activate_over_non_cellular_network()) | 579 if (network->activate_over_non_cellular_networks()) |
547 return; | 580 return; |
548 | 581 |
549 std::string error_description; | 582 std::string error_description; |
550 PlanActivationState new_state = PickNextState(network, &error_description); | 583 PlanActivationState new_state = PickNextState(network, &error_description); |
551 | 584 |
552 ChangeState(network, new_state, error_description); | 585 ChangeState(network, new_state, error_description); |
553 } | 586 } |
554 | 587 |
555 MobileActivator::PlanActivationState MobileActivator::PickNextState( | 588 MobileActivator::PlanActivationState MobileActivator::PickNextState( |
556 CellularNetwork* network, std::string* error_description) const { | 589 const NetworkState* network, std::string* error_description) const { |
557 PlanActivationState new_state = state_; | 590 PlanActivationState new_state = state_; |
558 if (!network->connected()) | 591 if (!network->IsConnectedState()) |
559 new_state = PickNextOfflineState(network); | 592 new_state = PickNextOfflineState(network); |
560 else | 593 else |
561 new_state = PickNextOnlineState(network); | 594 new_state = PickNextOnlineState(network); |
562 if (new_state != PLAN_ACTIVATION_ERROR && | 595 if (new_state != PLAN_ACTIVATION_ERROR && |
563 GotActivationError(network, error_description)) { | 596 GotActivationError(network, error_description)) { |
564 // Check for this special case when we try to do activate partially | 597 // Check for this special case when we try to do activate partially |
565 // activated device. If that attempt failed, try to disconnect to clear the | 598 // activated device. If that attempt failed, try to disconnect to clear the |
566 // state and reconnect again. | 599 // state and reconnect again. |
567 if ((network->activation_state() == ACTIVATION_STATE_PARTIALLY_ACTIVATED || | 600 const std::string& activation = network->activation_state(); |
568 network->activation_state() == ACTIVATION_STATE_ACTIVATING) && | 601 bool is_partially_activated = |
569 (network->error() == ERROR_NO_ERROR || | 602 activation == flimflam::kActivationStatePartiallyActivated || |
570 network->error() == ERROR_OTASP_FAILED) && | 603 activation == flimflam::kActivationStateActivating; |
stevenjb
2013/08/28 21:22:47
nit: not sure that local is_partially_activated ma
gauravsh
2013/08/28 23:45:07
Done.
| |
571 network->state() == STATE_ACTIVATION_FAILURE) { | 604 if (is_partially_activated && |
572 LOG(WARNING) << "Activation failure detected " | 605 (network->error().empty() || |
573 << network->service_path(); | 606 network->error() == flimflam::kErrorOtaspFailed) && |
607 network->connection_state() == flimflam::kStateActivationFailure) { | |
608 LOG(WARNING) << "Activation failure detected " << network->path(); | |
stevenjb
2013/08/28 21:22:47
NET_LOG_EVENT()
gauravsh
2013/08/28 23:45:07
Done.
| |
574 switch (state_) { | 609 switch (state_) { |
575 case PLAN_ACTIVATION_OTASP: | 610 case PLAN_ACTIVATION_OTASP: |
576 new_state = PLAN_ACTIVATION_DELAY_OTASP; | 611 new_state = PLAN_ACTIVATION_DELAY_OTASP; |
577 break; | 612 break; |
578 case PLAN_ACTIVATION_INITIATING_ACTIVATION: | 613 case PLAN_ACTIVATION_INITIATING_ACTIVATION: |
579 case PLAN_ACTIVATION_TRYING_OTASP: | 614 case PLAN_ACTIVATION_TRYING_OTASP: |
580 new_state = PLAN_ACTIVATION_START; | 615 new_state = PLAN_ACTIVATION_START; |
581 break; | 616 break; |
582 case PLAN_ACTIVATION_START: | 617 case PLAN_ACTIVATION_START: |
583 // We are just starting, so this must be previous activation attempt | 618 // We are just starting, so this must be previous activation attempt |
584 // failure. | 619 // failure. |
585 new_state = PLAN_ACTIVATION_TRYING_OTASP; | 620 new_state = PLAN_ACTIVATION_TRYING_OTASP; |
586 break; | 621 break; |
587 case PLAN_ACTIVATION_DELAY_OTASP: | 622 case PLAN_ACTIVATION_DELAY_OTASP: |
588 new_state = state_; | 623 new_state = state_; |
589 break; | 624 break; |
590 default: | 625 default: |
591 new_state = PLAN_ACTIVATION_ERROR; | 626 new_state = PLAN_ACTIVATION_ERROR; |
592 break; | 627 break; |
593 } | 628 } |
594 } else { | 629 } else { |
595 LOG(WARNING) << "Unexpected activation failure for " | 630 LOG(WARNING) << "Unexpected activation failure for " << network->path(); |
596 << network->service_path(); | |
597 new_state = PLAN_ACTIVATION_ERROR; | 631 new_state = PLAN_ACTIVATION_ERROR; |
598 } | 632 } |
599 } | 633 } |
600 | 634 |
601 if (new_state == PLAN_ACTIVATION_ERROR && !error_description->length()) | 635 if (new_state == PLAN_ACTIVATION_ERROR && !error_description->length()) |
602 *error_description = GetErrorMessage(kErrorDefault); | 636 *error_description = GetErrorMessage(kErrorDefault); |
603 return new_state; | 637 return new_state; |
604 } | 638 } |
605 | 639 |
606 MobileActivator::PlanActivationState MobileActivator::PickNextOfflineState( | 640 MobileActivator::PlanActivationState MobileActivator::PickNextOfflineState( |
607 CellularNetwork* network) const { | 641 const NetworkState* network) const { |
608 PlanActivationState new_state = state_; | 642 PlanActivationState new_state = state_; |
643 const std::string& activation = network->activation_state(); | |
609 switch (state_) { | 644 switch (state_) { |
610 case PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING: | 645 case PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING: |
611 case PLAN_ACTIVATION_SHOWING_PAYMENT: | 646 case PLAN_ACTIVATION_SHOWING_PAYMENT: |
612 if (!network->activate_over_non_cellular_network()) | 647 if (!network->activate_over_non_cellular_networks()) |
613 new_state = PLAN_ACTIVATION_RECONNECTING; | 648 new_state = PLAN_ACTIVATION_RECONNECTING; |
614 break; | 649 break; |
615 case PLAN_ACTIVATION_START: | 650 case PLAN_ACTIVATION_START: |
616 switch (network->activation_state()) { | 651 if (activation == flimflam::kActivationStateActivated) { |
617 case ACTIVATION_STATE_ACTIVATED: | 652 if (network->connection_state() == flimflam::kStatePortal) |
618 if (network->restricted_pool()) | 653 new_state = PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING; |
619 new_state = PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING; | 654 else |
620 else | 655 new_state = PLAN_ACTIVATION_DONE; |
621 new_state = PLAN_ACTIVATION_DONE; | 656 } else if (activation == flimflam::kActivationStatePartiallyActivated) { |
622 break; | 657 new_state = PLAN_ACTIVATION_TRYING_OTASP; |
623 case ACTIVATION_STATE_PARTIALLY_ACTIVATED: | 658 } else { |
624 new_state = PLAN_ACTIVATION_TRYING_OTASP; | 659 new_state = PLAN_ACTIVATION_INITIATING_ACTIVATION; |
625 break; | |
626 default: | |
627 new_state = PLAN_ACTIVATION_INITIATING_ACTIVATION; | |
628 break; | |
629 } | 660 } |
630 break; | 661 break; |
631 default: { | 662 default: |
632 LOG(INFO) << "Waiting for cellular service to connect."; | 663 LOG(INFO) << "Waiting for cellular service to connect."; |
633 } break; | 664 break; |
634 } | 665 } |
635 return new_state; | 666 return new_state; |
636 } | 667 } |
637 | 668 |
638 MobileActivator::PlanActivationState MobileActivator::PickNextOnlineState( | 669 MobileActivator::PlanActivationState MobileActivator::PickNextOnlineState( |
639 CellularNetwork* network) const { | 670 const NetworkState* network) const { |
640 PlanActivationState new_state = state_; | 671 PlanActivationState new_state = state_; |
672 const std::string& activation = network->activation_state(); | |
641 switch (state_) { | 673 switch (state_) { |
642 case PLAN_ACTIVATION_START: | 674 case PLAN_ACTIVATION_START: |
643 switch (network->activation_state()) { | 675 if (activation == flimflam::kActivationStateActivated) { |
644 case ACTIVATION_STATE_ACTIVATED: | 676 if (network->connection_state() == flimflam::kStatePortal) |
645 if (network->restricted_pool()) | 677 new_state = PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING; |
646 new_state = PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING; | 678 else |
647 else | 679 new_state = PLAN_ACTIVATION_DONE; |
648 new_state = PLAN_ACTIVATION_DONE; | 680 } else if (activation == flimflam::kActivationStatePartiallyActivated) { |
649 break; | 681 new_state = PLAN_ACTIVATION_TRYING_OTASP; |
650 case ACTIVATION_STATE_PARTIALLY_ACTIVATED: | 682 } else { |
651 new_state = PLAN_ACTIVATION_TRYING_OTASP; | 683 new_state = PLAN_ACTIVATION_INITIATING_ACTIVATION; |
652 break; | |
653 default: | |
654 new_state = PLAN_ACTIVATION_INITIATING_ACTIVATION; | |
655 break; | |
656 } | 684 } |
657 break; | 685 break; |
658 case PLAN_ACTIVATION_START_OTASP: { | 686 case PLAN_ACTIVATION_START_OTASP: { |
659 switch (network->activation_state()) { | 687 if (activation == flimflam::kActivationStatePartiallyActivated) { |
660 case ACTIVATION_STATE_PARTIALLY_ACTIVATED: | |
661 new_state = PLAN_ACTIVATION_OTASP; | 688 new_state = PLAN_ACTIVATION_OTASP; |
662 break; | 689 } else if (activation == flimflam::kActivationStateActivated) { |
663 case ACTIVATION_STATE_ACTIVATED: | 690 new_state = PLAN_ACTIVATION_RECONNECTING; |
664 new_state = PLAN_ACTIVATION_RECONNECTING; | 691 } else { |
665 break; | 692 LOG(WARNING) << "Unexpected activation state for device " |
666 default: { | 693 << network->path(); |
667 LOG(WARNING) << "Unexpected activation state for device " | |
668 << network->service_path(); | |
669 break; | |
670 } | |
671 } | 694 } |
672 break; | 695 break; |
673 } | 696 } |
674 case PLAN_ACTIVATION_DELAY_OTASP: | 697 case PLAN_ACTIVATION_DELAY_OTASP: |
675 // Just ignore any changes until the OTASP retry timer kicks in. | 698 // Just ignore any changes until the OTASP retry timer kicks in. |
676 break; | 699 break; |
677 case PLAN_ACTIVATION_INITIATING_ACTIVATION: { | 700 case PLAN_ACTIVATION_INITIATING_ACTIVATION: { |
678 switch (network->activation_state()) { | 701 if (pending_activation_request_) { |
679 case ACTIVATION_STATE_ACTIVATED: | 702 LOG(INFO) << "Waiting for pending activation attempt to finish"; |
680 case ACTIVATION_STATE_PARTIALLY_ACTIVATED: | 703 } else if (activation == flimflam::kActivationStateActivated || |
681 new_state = PLAN_ACTIVATION_START; | 704 activation == flimflam::kActivationStatePartiallyActivated) { |
682 break; | 705 new_state = PLAN_ACTIVATION_START; |
683 case ACTIVATION_STATE_NOT_ACTIVATED: | 706 } else if (activation == flimflam::kActivationStateNotActivated || |
684 case ACTIVATION_STATE_ACTIVATING: | 707 activation == flimflam::kActivationStateActivating) { |
685 // Wait in this state until activation state changes. | 708 // Wait in this state until activation state changes. |
686 break; | 709 } else { |
687 default: | 710 LOG(WARNING) << "Unknown transition"; |
688 LOG(WARNING) << "Unknown transition"; | |
689 break; | |
690 } | 711 } |
691 break; | 712 break; |
692 } | 713 } |
693 case PLAN_ACTIVATION_OTASP: | 714 case PLAN_ACTIVATION_OTASP: |
694 case PLAN_ACTIVATION_TRYING_OTASP: | 715 case PLAN_ACTIVATION_TRYING_OTASP: |
695 if (network->activation_state() == ACTIVATION_STATE_NOT_ACTIVATED || | 716 if (pending_activation_request_) { |
696 network->activation_state() == ACTIVATION_STATE_ACTIVATING) { | 717 LOG(INFO) << "Waiting for pending activation attempt to finish"; |
718 } else if (activation == flimflam::kActivationStateNotActivated || | |
719 activation == flimflam::kActivationStateActivating) { | |
697 LOG(INFO) << "Waiting for the OTASP to finish and the service to " | 720 LOG(INFO) << "Waiting for the OTASP to finish and the service to " |
698 << "come back online"; | 721 << "come back online"; |
699 } else if (network->activation_state() == ACTIVATION_STATE_ACTIVATED) { | 722 } else if (activation == flimflam::kActivationStateActivated) { |
700 new_state = PLAN_ACTIVATION_DONE; | 723 new_state = PLAN_ACTIVATION_DONE; |
701 } else { | 724 } else { |
702 new_state = PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING; | 725 new_state = PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING; |
703 } | 726 } |
704 break; | 727 break; |
705 case PLAN_ACTIVATION_RECONNECTING_PAYMENT: | 728 case PLAN_ACTIVATION_RECONNECTING_PAYMENT: |
706 if (!network->restricted_pool() && | 729 if (network->connection_state() != flimflam::kStatePortal && |
707 network->activation_state() == ACTIVATION_STATE_ACTIVATED) | 730 activation == flimflam::kActivationStateActivated) |
708 // We're not portalled, and we're already activated, so we're online! | 731 // We're not portalled, and we're already activated, so we're online! |
709 new_state = PLAN_ACTIVATION_DONE; | 732 new_state = PLAN_ACTIVATION_DONE; |
710 else | 733 else |
711 new_state = PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING; | 734 new_state = PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING; |
712 break; | 735 break; |
713 // Initial state | 736 // Initial state |
714 case PLAN_ACTIVATION_PAGE_LOADING: | 737 case PLAN_ACTIVATION_PAGE_LOADING: |
715 break; | 738 break; |
716 // Just ignore all signals until the site confirms payment. | 739 // Just ignore all signals until the site confirms payment. |
717 case PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING: | 740 case PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING: |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
760 return "ERROR"; | 783 return "ERROR"; |
761 case PLAN_ACTIVATION_RECONNECTING: | 784 case PLAN_ACTIVATION_RECONNECTING: |
762 return "RECONNECTING"; | 785 return "RECONNECTING"; |
763 case PLAN_ACTIVATION_WAITING_FOR_CONNECTION: | 786 case PLAN_ACTIVATION_WAITING_FOR_CONNECTION: |
764 return "WAITING FOR CONNECTION"; | 787 return "WAITING FOR CONNECTION"; |
765 } | 788 } |
766 return "UNKNOWN"; | 789 return "UNKNOWN"; |
767 } | 790 } |
768 | 791 |
769 | 792 |
770 void MobileActivator::CompleteActivation( | 793 void MobileActivator::CompleteActivation() { |
771 CellularNetwork* network) { | |
772 // Remove observers, we are done with this page. | 794 // Remove observers, we are done with this page. |
773 NetworkLibrary* lib = GetNetworkLibrary(); | 795 NetworkHandler::Get()->network_state_handler()->RemoveObserver( |
774 lib->RemoveNetworkManagerObserver(this); | 796 this, FROM_HERE); |
775 lib->RemoveObserverForAllNetworks(this); | 797 |
776 // Reactivate other types of connections if we have | 798 // Reactivate other types of connections if we have |
777 // shut them down previously. | 799 // shut them down previously. |
778 ReEnableCertRevocationChecking(); | 800 ReEnableCertRevocationChecking(); |
779 } | 801 } |
780 | 802 |
781 bool MobileActivator::RunningActivation() const { | 803 bool MobileActivator::RunningActivation() const { |
782 return !(state_ == PLAN_ACTIVATION_DONE || | 804 return !(state_ == PLAN_ACTIVATION_DONE || |
783 state_ == PLAN_ACTIVATION_ERROR || | 805 state_ == PLAN_ACTIVATION_ERROR || |
784 state_ == PLAN_ACTIVATION_PAGE_LOADING); | 806 state_ == PLAN_ACTIVATION_PAGE_LOADING); |
785 } | 807 } |
786 | 808 |
787 void MobileActivator::ChangeState(CellularNetwork* network, | 809 void MobileActivator::HandleActivationFailure( |
810 const std::string& service_path, | |
811 PlanActivationState new_state, | |
812 const std::string& error_name, | |
813 scoped_ptr<base::DictionaryValue> error_data) { | |
814 pending_activation_request_ = false; | |
815 const NetworkState* network = GetNetworkState(service_path); | |
816 if (!network) { | |
817 NET_LOG_ERROR("Cellular service no longer exists", service_path); | |
818 return; | |
819 } | |
820 UMA_HISTOGRAM_COUNTS("Cellular.ActivationFailure", 1); | |
821 NET_LOG_ERROR("Failed to call Activate() on service", service_path); | |
822 if (new_state == PLAN_ACTIVATION_OTASP) { | |
823 ChangeState(network, PLAN_ACTIVATION_DELAY_OTASP, std::string()); | |
824 } else { | |
825 ChangeState(network, | |
826 PLAN_ACTIVATION_ERROR, | |
827 GetErrorMessage(kFailedConnectivity)); | |
828 } | |
829 } | |
830 | |
831 void MobileActivator::RequestCellularActivation( | |
832 const NetworkState* network, | |
833 const base::Closure& success_callback, | |
834 const network_handler::ErrorCallback& error_callback) { | |
835 DCHECK(network); | |
836 NET_LOG_EVENT("Activating cellular service", network->path()); | |
837 UMA_HISTOGRAM_COUNTS("Cellular.ActivationTry", 1); | |
838 pending_activation_request_ = true; | |
839 NetworkHandler::Get()->network_activation_handler()-> | |
840 Activate(network->path(), | |
841 "", // carrier | |
842 success_callback, | |
843 error_callback); | |
844 } | |
845 | |
846 void MobileActivator::ChangeState(const NetworkState* network, | |
788 PlanActivationState new_state, | 847 PlanActivationState new_state, |
789 const std::string& error_description) { | 848 const std::string& error_description) { |
790 static bool first_time = true; | 849 static bool first_time = true; |
791 LOG(INFO) << "Activation state flip old = " | 850 LOG(INFO) << "Activation state flip old = " |
792 << GetStateDescription(state_) | 851 << GetStateDescription(state_) |
793 << ", new = " << GetStateDescription(new_state); | 852 << ", new = " << GetStateDescription(new_state); |
794 if (state_ == new_state && !first_time) | 853 if (state_ == new_state && !first_time) |
795 return; | 854 return; |
796 first_time = false; | 855 first_time = false; |
797 LOG(INFO) << "Transitioning..."; | 856 LOG(INFO) << "Transitioning..."; |
(...skipping 17 matching lines...) Expand all Loading... | |
815 UMA_HISTOGRAM_COUNTS("Cellular.RetryOTASP", 1); | 874 UMA_HISTOGRAM_COUNTS("Cellular.RetryOTASP", 1); |
816 BrowserThread::PostDelayedTask(BrowserThread::UI, FROM_HERE, | 875 BrowserThread::PostDelayedTask(BrowserThread::UI, FROM_HERE, |
817 base::Bind(&MobileActivator::RetryOTASP, AsWeakPtr()), | 876 base::Bind(&MobileActivator::RetryOTASP, AsWeakPtr()), |
818 base::TimeDelta::FromMilliseconds(kOTASPRetryDelay)); | 877 base::TimeDelta::FromMilliseconds(kOTASPRetryDelay)); |
819 break; | 878 break; |
820 } | 879 } |
821 case PLAN_ACTIVATION_START_OTASP: | 880 case PLAN_ACTIVATION_START_OTASP: |
822 break; | 881 break; |
823 case PLAN_ACTIVATION_INITIATING_ACTIVATION: | 882 case PLAN_ACTIVATION_INITIATING_ACTIVATION: |
824 case PLAN_ACTIVATION_TRYING_OTASP: | 883 case PLAN_ACTIVATION_TRYING_OTASP: |
825 case PLAN_ACTIVATION_OTASP: | 884 case PLAN_ACTIVATION_OTASP: { |
826 DCHECK(network); | 885 DCHECK(network); |
827 LOG(WARNING) << "Activating service " << network->service_path(); | 886 network_handler::ErrorCallback on_activation_error = |
828 UMA_HISTOGRAM_COUNTS("Cellular.ActivationTry", 1); | 887 base::Bind(&MobileActivator::HandleActivationFailure, AsWeakPtr(), |
829 if (!network->StartActivation()) { | 888 network->path(), |
830 UMA_HISTOGRAM_COUNTS("Cellular.ActivationFailure", 1); | 889 new_state); |
831 LOG(ERROR) << "Failed to call Activate() on service in shill."; | 890 RequestCellularActivation( |
832 if (new_state == PLAN_ACTIVATION_OTASP) { | 891 network, |
833 ChangeState(network, PLAN_ACTIVATION_DELAY_OTASP, std::string()); | 892 base::Bind(&MobileActivator::StartOTASPTimer, AsWeakPtr()), |
834 } else { | 893 on_activation_error); |
835 ChangeState(network, | |
836 PLAN_ACTIVATION_ERROR, | |
837 GetErrorMessage(kFailedConnectivity)); | |
838 } | |
839 } else { | |
840 StartOTASPTimer(); | |
841 } | 894 } |
842 break; | 895 break; |
843 case PLAN_ACTIVATION_PAGE_LOADING: | 896 case PLAN_ACTIVATION_PAGE_LOADING: |
844 return; | 897 return; |
845 case PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING: | 898 case PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING: |
846 case PLAN_ACTIVATION_SHOWING_PAYMENT: | 899 case PLAN_ACTIVATION_SHOWING_PAYMENT: |
847 case PLAN_ACTIVATION_RECONNECTING_PAYMENT: | 900 case PLAN_ACTIVATION_RECONNECTING_PAYMENT: |
848 // Fix for fix SSL for the walled gardens where cert chain verification | 901 // Fix for fix SSL for the walled gardens where cert chain verification |
849 // might not work. | 902 // might not work. |
850 break; | 903 break; |
851 case PLAN_ACTIVATION_WAITING_FOR_CONNECTION: | 904 case PLAN_ACTIVATION_WAITING_FOR_CONNECTION: |
852 post_reconnect_state_ = old_state; | 905 post_reconnect_state_ = old_state; |
853 break; | 906 break; |
854 case PLAN_ACTIVATION_RECONNECTING: { | 907 case PLAN_ACTIVATION_RECONNECTING: { |
855 PlanActivationState next_state = old_state; | 908 PlanActivationState next_state = old_state; |
856 // Pick where we want to return to after we reconnect. | 909 // Pick where we want to return to after we reconnect. |
857 switch (old_state) { | 910 switch (old_state) { |
858 case PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING: | 911 case PLAN_ACTIVATION_PAYMENT_PORTAL_LOADING: |
859 case PLAN_ACTIVATION_SHOWING_PAYMENT: | 912 case PLAN_ACTIVATION_SHOWING_PAYMENT: |
860 // We decide here what to do next based on the state of the modem. | 913 // We decide here what to do next based on the state of the modem. |
861 next_state = PLAN_ACTIVATION_RECONNECTING_PAYMENT; | 914 next_state = PLAN_ACTIVATION_RECONNECTING_PAYMENT; |
862 break; | 915 break; |
863 case PLAN_ACTIVATION_INITIATING_ACTIVATION: | 916 case PLAN_ACTIVATION_INITIATING_ACTIVATION: |
864 case PLAN_ACTIVATION_TRYING_OTASP: | 917 case PLAN_ACTIVATION_TRYING_OTASP: |
865 next_state = PLAN_ACTIVATION_START; | 918 next_state = PLAN_ACTIVATION_START; |
866 break; | 919 break; |
867 case PLAN_ACTIVATION_START_OTASP: | 920 case PLAN_ACTIVATION_START_OTASP: |
868 case PLAN_ACTIVATION_OTASP: | 921 case PLAN_ACTIVATION_OTASP: |
869 if (!network || !network->connected()) { | 922 if (!network || !network->IsConnectedState()) { |
870 next_state = PLAN_ACTIVATION_START_OTASP; | 923 next_state = PLAN_ACTIVATION_START_OTASP; |
871 } else { | 924 } else { |
872 // We're online, which means we've conspired with | 925 // We're online, which means we've conspired with |
873 // PickNextOnlineState to reconnect after activation (that's the | 926 // PickNextOnlineState to reconnect after activation (that's the |
874 // only way we see this transition). Thus, after we reconnect, we | 927 // only way we see this transition). Thus, after we reconnect, we |
875 // should be done. | 928 // should be done. |
876 next_state = PLAN_ACTIVATION_DONE; | 929 next_state = PLAN_ACTIVATION_DONE; |
877 } | 930 } |
878 break; | 931 break; |
879 default: | 932 default: |
880 LOG(ERROR) << "Transitioned to RECONNECTING from an unexpected " | 933 LOG(ERROR) << "Transitioned to RECONNECTING from an unexpected " |
881 << "state."; | 934 << "state."; |
882 break; | 935 break; |
883 } | 936 } |
884 ForceReconnect(network, next_state); | 937 ForceReconnect(network, next_state); |
885 break; | 938 break; |
886 } | 939 } |
887 case PLAN_ACTIVATION_DONE: | 940 case PLAN_ACTIVATION_DONE: |
888 DCHECK(network); | 941 DCHECK(network); |
889 CompleteActivation(network); | 942 CompleteActivation(); |
890 UMA_HISTOGRAM_COUNTS("Cellular.MobileSetupSucceeded", 1); | 943 UMA_HISTOGRAM_COUNTS("Cellular.MobileSetupSucceeded", 1); |
891 break; | 944 break; |
892 case PLAN_ACTIVATION_ERROR: | 945 case PLAN_ACTIVATION_ERROR: |
893 CompleteActivation(NULL); | 946 CompleteActivation(); |
894 UMA_HISTOGRAM_COUNTS("Cellular.PlanFailed", 1); | 947 UMA_HISTOGRAM_COUNTS("Cellular.PlanFailed", 1); |
895 break; | 948 break; |
896 default: | 949 default: |
897 break; | 950 break; |
898 } | 951 } |
899 } | 952 } |
900 | 953 |
901 void MobileActivator::ReEnableCertRevocationChecking() { | 954 void MobileActivator::ReEnableCertRevocationChecking() { |
902 PrefService* prefs = g_browser_process->local_state(); | 955 PrefService* prefs = g_browser_process->local_state(); |
903 if (reenable_cert_check_) { | 956 if (reenable_cert_check_) { |
(...skipping 10 matching lines...) Expand all Loading... | |
914 PrefService* prefs = g_browser_process->local_state(); | 967 PrefService* prefs = g_browser_process->local_state(); |
915 if (!reenable_cert_check_ && | 968 if (!reenable_cert_check_ && |
916 prefs->GetBoolean( | 969 prefs->GetBoolean( |
917 prefs::kCertRevocationCheckingEnabled)) { | 970 prefs::kCertRevocationCheckingEnabled)) { |
918 reenable_cert_check_ = true; | 971 reenable_cert_check_ = true; |
919 prefs->SetBoolean(prefs::kCertRevocationCheckingEnabled, false); | 972 prefs->SetBoolean(prefs::kCertRevocationCheckingEnabled, false); |
920 } | 973 } |
921 } | 974 } |
922 | 975 |
923 bool MobileActivator::GotActivationError( | 976 bool MobileActivator::GotActivationError( |
924 CellularNetwork* network, std::string* error) const { | 977 const NetworkState* network, std::string* error) const { |
925 DCHECK(network); | 978 DCHECK(network); |
926 bool got_error = false; | 979 bool got_error = false; |
927 const char* error_code = kErrorDefault; | 980 const char* error_code = kErrorDefault; |
981 const std::string& activation = network->activation_state(); | |
928 | 982 |
929 // This is the magic for detection of errors in during activation process. | 983 // This is the magic for detection of errors in during activation process. |
930 if (network->state() == STATE_FAILURE && | 984 if (network->connection_state() == flimflam::kStateFailure && |
931 network->error() == ERROR_AAA_FAILED) { | 985 network->error() == flimflam::kErrorAaaFailed) { |
932 if (network->activation_state() == | 986 if (activation == flimflam::kActivationStatePartiallyActivated) { |
933 ACTIVATION_STATE_PARTIALLY_ACTIVATED) { | |
934 error_code = kErrorBadConnectionPartial; | 987 error_code = kErrorBadConnectionPartial; |
935 } else if (network->activation_state() == ACTIVATION_STATE_ACTIVATED) { | 988 } else if (activation == flimflam::kActivationStateActivated) { |
936 if (network->roaming_state() == ROAMING_STATE_HOME) | 989 if (network->roaming() == flimflam::kRoamingStateHome) |
937 error_code = kErrorBadConnectionActivated; | 990 error_code = kErrorBadConnectionActivated; |
938 else if (network->roaming_state() == ROAMING_STATE_ROAMING) | 991 else if (network->roaming() == flimflam::kRoamingStateRoaming) |
939 error_code = kErrorRoamingOnConnection; | 992 error_code = kErrorRoamingOnConnection; |
940 } | 993 } |
941 got_error = true; | 994 got_error = true; |
942 } else if (network->state() == STATE_ACTIVATION_FAILURE) { | 995 } else if (network->connection_state() == flimflam::kStateActivationFailure) { |
943 if (network->error() == ERROR_NEED_EVDO) { | 996 if (network->error() == flimflam::kErrorNeedEvdo) { |
944 if (network->activation_state() == ACTIVATION_STATE_PARTIALLY_ACTIVATED) | 997 if (activation == flimflam::kActivationStatePartiallyActivated) |
945 error_code = kErrorNoEVDO; | 998 error_code = kErrorNoEVDO; |
946 } else if (network->error() == ERROR_NEED_HOME_NETWORK) { | 999 } else if (network->error() == flimflam::kErrorNeedHomeNetwork) { |
947 if (network->activation_state() == ACTIVATION_STATE_NOT_ACTIVATED) { | 1000 if (activation == flimflam::kActivationStateNotActivated) { |
948 error_code = kErrorRoamingActivation; | 1001 error_code = kErrorRoamingActivation; |
949 } else if (network->activation_state() == | 1002 } else if (activation == flimflam::kActivationStatePartiallyActivated) { |
950 ACTIVATION_STATE_PARTIALLY_ACTIVATED) { | |
951 error_code = kErrorRoamingPartiallyActivated; | 1003 error_code = kErrorRoamingPartiallyActivated; |
952 } | 1004 } |
953 } | 1005 } |
954 got_error = true; | 1006 got_error = true; |
955 } | 1007 } |
956 | 1008 |
957 if (got_error) | 1009 if (got_error) |
958 *error = GetErrorMessage(error_code); | 1010 *error = GetErrorMessage(error_code); |
959 | 1011 |
960 return got_error; | 1012 return got_error; |
961 } | 1013 } |
962 | 1014 |
963 void MobileActivator::GetDeviceInfo(CellularNetwork* network, | 1015 void MobileActivator::GetDeviceInfo(const NetworkState* network, |
964 DictionaryValue* value) { | 1016 DictionaryValue* value) { |
965 DCHECK(network); | 1017 DCHECK(network); |
966 NetworkLibrary* cros = NetworkLibrary::Get(); | |
967 if (!cros) | |
968 return; | |
969 value->SetString("carrier", network->name()); | 1018 value->SetString("carrier", network->name()); |
970 value->SetString("payment_url", network->payment_url()); | 1019 value->SetString("payment_url", network->payment_url()); |
971 if (network->using_post() && network->post_data().length()) | 1020 if (network->post_method() == "post" && !network->post_data().empty()) |
972 value->SetString("post_data", network->post_data()); | 1021 value->SetString("post_data", network->post_data()); |
973 | 1022 |
974 const NetworkDevice* device = | 1023 const DeviceState* device = |
975 cros->FindNetworkDeviceByPath(network->device_path()); | 1024 NetworkHandler::Get()->network_state_handler()->GetDeviceState( |
1025 network->device_path()); | |
976 if (device) { | 1026 if (device) { |
977 value->SetString("MEID", device->meid()); | 1027 value->SetString("MEID", device->meid()); |
978 value->SetString("IMEI", device->imei()); | 1028 value->SetString("IMEI", device->imei()); |
979 value->SetString("MDN", device->mdn()); | 1029 value->SetString("MDN", device->mdn()); |
980 } | 1030 } |
stevenjb
2013/08/28 21:22:47
I know it was like this, but all of these strings
gauravsh
2013/08/28 23:45:07
Actually, this method isn't even used anywhere. So
| |
981 } | 1031 } |
982 | 1032 |
983 std::string MobileActivator::GetErrorMessage(const std::string& code) const { | 1033 std::string MobileActivator::GetErrorMessage(const std::string& code) const { |
984 return cellular_config_->GetErrorMessage(code); | 1034 return cellular_config_->GetErrorMessage(code); |
985 } | 1035 } |
986 | 1036 |
987 NetworkLibrary* MobileActivator::GetNetworkLibrary() const { | 1037 void MobileActivator::SignalCellularPlanPayment() { |
988 return NetworkLibrary::Get(); | 1038 DCHECK(!HasRecentCellularPlanPayment()); |
1039 cellular_plan_payment_time_ = base::Time::Now(); | |
1040 } | |
1041 | |
1042 bool MobileActivator::HasRecentCellularPlanPayment() const { | |
1043 const int kRecentPlanPaymentHours = 6; | |
1044 return (base::Time::Now() - | |
1045 cellular_plan_payment_time_).InHours() < kRecentPlanPaymentHours; | |
989 } | 1046 } |
990 | 1047 |
991 } // namespace chromeos | 1048 } // namespace chromeos |
OLD | NEW |