OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/cros/network_library.h" | 5 #include "chrome/browser/chromeos/cros/network_library.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 | 10 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 const int kNetworkNotifyDelayMs = 50; | 96 const int kNetworkNotifyDelayMs = 50; |
97 | 97 |
98 // How long we should remember that cellular plan payment was received. | 98 // How long we should remember that cellular plan payment was received. |
99 const int kRecentPlanPaymentHours = 6; | 99 const int kRecentPlanPaymentHours = 6; |
100 | 100 |
101 // Default value of the SIM unlock retries count. It is updated to the real | 101 // Default value of the SIM unlock retries count. It is updated to the real |
102 // retries count once cellular device with SIM card is initialized. | 102 // retries count once cellular device with SIM card is initialized. |
103 // If cellular device doesn't have SIM card, then retries are never used. | 103 // If cellular device doesn't have SIM card, then retries are never used. |
104 const int kDefaultSimUnlockRetriesCount = 999; | 104 const int kDefaultSimUnlockRetriesCount = 999; |
105 | 105 |
| 106 // List of cellular operators names that should have data roaming always enabled |
| 107 // to be able to connect to any network. |
| 108 const char* kAlwaysInRoamingOperators[] = { |
| 109 "CUBIC" |
| 110 }; |
| 111 |
106 //////////////////////////////////////////////////////////////////////////////// | 112 //////////////////////////////////////////////////////////////////////////////// |
107 // Misc. | 113 // Misc. |
108 | 114 |
109 // Safe string constructor since we can't rely on non NULL pointers | 115 // Safe string constructor since we can't rely on non NULL pointers |
110 // for string values from libcros. | 116 // for string values from libcros. |
111 static std::string SafeString(const char* s) { | 117 static std::string SafeString(const char* s) { |
112 return s ? std::string(s) : std::string(); | 118 return s ? std::string(s) : std::string(); |
113 } | 119 } |
114 | 120 |
115 // Erase the memory used by a string, then clear it. | 121 // Erase the memory used by a string, then clear it. |
(...skipping 1251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1367 virtual std::string GetCellularHomeCarrierId() const OVERRIDE; | 1373 virtual std::string GetCellularHomeCarrierId() const OVERRIDE; |
1368 | 1374 |
1369 // virtual ChangePin implemented in derived classes. | 1375 // virtual ChangePin implemented in derived classes. |
1370 // virtual ChangeRequiredPin implemented in derived classes. | 1376 // virtual ChangeRequiredPin implemented in derived classes. |
1371 // virtual EnterPin implemented in derived classes. | 1377 // virtual EnterPin implemented in derived classes. |
1372 // virtual UnblockPin implemented in derived classes. | 1378 // virtual UnblockPin implemented in derived classes. |
1373 | 1379 |
1374 // virtual RequestCellularScan implemented in derived classes. | 1380 // virtual RequestCellularScan implemented in derived classes. |
1375 // virtual RequestCellularRegister implemented in derived classes. | 1381 // virtual RequestCellularRegister implemented in derived classes. |
1376 // virtual SetCellularDataRoamingAllowed implemented in derived classes. | 1382 // virtual SetCellularDataRoamingAllowed implemented in derived classes. |
| 1383 // virtual IsCellularAlwaysInRoaming implemented in derived classes. |
1377 // virtual RequestNetworkScan implemented in derived classes. | 1384 // virtual RequestNetworkScan implemented in derived classes. |
1378 // virtual GetWifiAccessPoints implemented in derived classes. | 1385 // virtual GetWifiAccessPoints implemented in derived classes. |
1379 | 1386 |
1380 virtual bool HasProfileType(NetworkProfileType type) const OVERRIDE; | 1387 virtual bool HasProfileType(NetworkProfileType type) const OVERRIDE; |
1381 virtual void SetNetworkProfile(const std::string& service_path, | 1388 virtual void SetNetworkProfile(const std::string& service_path, |
1382 NetworkProfileType type) OVERRIDE; | 1389 NetworkProfileType type) OVERRIDE; |
1383 virtual bool CanConnectToNetwork(const Network* network) const OVERRIDE; | 1390 virtual bool CanConnectToNetwork(const Network* network) const OVERRIDE; |
1384 | 1391 |
1385 // Connect to an existing network. | 1392 // Connect to an existing network. |
1386 virtual void ConnectToWifiNetwork(WifiNetwork* wifi) OVERRIDE; | 1393 virtual void ConnectToWifiNetwork(WifiNetwork* wifi) OVERRIDE; |
(...skipping 1561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2948 virtual void ChangePin(const std::string& old_pin, | 2955 virtual void ChangePin(const std::string& old_pin, |
2949 const std::string& new_pin) OVERRIDE; | 2956 const std::string& new_pin) OVERRIDE; |
2950 virtual void ChangeRequirePin(bool require_pin, | 2957 virtual void ChangeRequirePin(bool require_pin, |
2951 const std::string& pin) OVERRIDE; | 2958 const std::string& pin) OVERRIDE; |
2952 virtual void EnterPin(const std::string& pin) OVERRIDE; | 2959 virtual void EnterPin(const std::string& pin) OVERRIDE; |
2953 virtual void UnblockPin(const std::string& puk, | 2960 virtual void UnblockPin(const std::string& puk, |
2954 const std::string& new_pin) OVERRIDE; | 2961 const std::string& new_pin) OVERRIDE; |
2955 virtual void RequestCellularScan() OVERRIDE; | 2962 virtual void RequestCellularScan() OVERRIDE; |
2956 virtual void RequestCellularRegister(const std::string& network_id) OVERRIDE; | 2963 virtual void RequestCellularRegister(const std::string& network_id) OVERRIDE; |
2957 virtual void SetCellularDataRoamingAllowed(bool new_value) OVERRIDE; | 2964 virtual void SetCellularDataRoamingAllowed(bool new_value) OVERRIDE; |
| 2965 virtual bool IsCellularAlwaysInRoaming() OVERRIDE; |
2958 virtual void RequestNetworkScan() OVERRIDE; | 2966 virtual void RequestNetworkScan() OVERRIDE; |
2959 virtual bool GetWifiAccessPoints(WifiAccessPointVector* result) OVERRIDE; | 2967 virtual bool GetWifiAccessPoints(WifiAccessPointVector* result) OVERRIDE; |
2960 | 2968 |
2961 virtual void DisconnectFromNetwork(const Network* network) OVERRIDE; | 2969 virtual void DisconnectFromNetwork(const Network* network) OVERRIDE; |
2962 virtual void CallEnableNetworkDeviceType( | 2970 virtual void CallEnableNetworkDeviceType( |
2963 ConnectionType device, bool enable) OVERRIDE; | 2971 ConnectionType device, bool enable) OVERRIDE; |
2964 virtual void EnableOfflineMode(bool enable) OVERRIDE; | 2972 virtual void EnableOfflineMode(bool enable) OVERRIDE; |
2965 | 2973 |
2966 virtual NetworkIPConfigVector GetIPConfigs( | 2974 virtual NetworkIPConfigVector GetIPConfigs( |
2967 const std::string& device_path, | 2975 const std::string& device_path, |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3204 | 3212 |
3205 void NetworkLibraryImplCros::UpdateNetworkDeviceStatus( | 3213 void NetworkLibraryImplCros::UpdateNetworkDeviceStatus( |
3206 const std::string& path, const std::string& key, const Value& value) { | 3214 const std::string& path, const std::string& key, const Value& value) { |
3207 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3215 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3208 NetworkDevice* device = FindNetworkDeviceByPath(path); | 3216 NetworkDevice* device = FindNetworkDeviceByPath(path); |
3209 if (device) { | 3217 if (device) { |
3210 VLOG(2) << "UpdateNetworkDeviceStatus: " << device->name() << "." << key; | 3218 VLOG(2) << "UpdateNetworkDeviceStatus: " << device->name() << "." << key; |
3211 PropertyIndex index = PROPERTY_INDEX_UNKNOWN; | 3219 PropertyIndex index = PROPERTY_INDEX_UNKNOWN; |
3212 if (device->UpdateStatus(key, value, &index)) { | 3220 if (device->UpdateStatus(key, value, &index)) { |
3213 if (index == PROPERTY_INDEX_CELLULAR_ALLOW_ROAMING) { | 3221 if (index == PROPERTY_INDEX_CELLULAR_ALLOW_ROAMING) { |
3214 bool settings_value = | 3222 if (!device->data_roaming_allowed() && IsCellularAlwaysInRoaming()) { |
3215 UserCrosSettingsProvider::cached_data_roaming_enabled(); | 3223 SetCellularDataRoamingAllowed(true); |
3216 if (device->data_roaming_allowed() != settings_value) { | 3224 } else { |
3217 // Switch back to signed settings value. | 3225 bool settings_value = |
3218 SetCellularDataRoamingAllowed(settings_value); | 3226 UserCrosSettingsProvider::cached_data_roaming_enabled(); |
3219 return; | 3227 if (device->data_roaming_allowed() != settings_value) { |
| 3228 // Switch back to signed settings value. |
| 3229 SetCellularDataRoamingAllowed(settings_value); |
| 3230 return; |
| 3231 } |
3220 } | 3232 } |
3221 } | 3233 } |
3222 } else { | 3234 } else { |
3223 VLOG(1) << "UpdateNetworkDeviceStatus: Failed to update: " | 3235 VLOG(1) << "UpdateNetworkDeviceStatus: Failed to update: " |
3224 << path << "." << key; | 3236 << path << "." << key; |
3225 } | 3237 } |
3226 // Notify only observers on device property change. | 3238 // Notify only observers on device property change. |
3227 NotifyNetworkDeviceChanged(device, index); | 3239 NotifyNetworkDeviceChanged(device, index); |
3228 // If a device's power state changes, new properties may become defined. | 3240 // If a device's power state changes, new properties may become defined. |
3229 if (index == PROPERTY_INDEX_POWERED) | 3241 if (index == PROPERTY_INDEX_POWERED) |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3469 NOTREACHED() << "Calling SetCellularDataRoamingAllowed method " | 3481 NOTREACHED() << "Calling SetCellularDataRoamingAllowed method " |
3470 "w/o cellular device."; | 3482 "w/o cellular device."; |
3471 return; | 3483 return; |
3472 } | 3484 } |
3473 scoped_ptr<Value> value(Value::CreateBooleanValue(new_value)); | 3485 scoped_ptr<Value> value(Value::CreateBooleanValue(new_value)); |
3474 chromeos::SetNetworkDeviceProperty(cellular->device_path().c_str(), | 3486 chromeos::SetNetworkDeviceProperty(cellular->device_path().c_str(), |
3475 kCellularAllowRoamingProperty, | 3487 kCellularAllowRoamingProperty, |
3476 value.get()); | 3488 value.get()); |
3477 } | 3489 } |
3478 | 3490 |
| 3491 bool NetworkLibraryImplCros::IsCellularAlwaysInRoaming() { |
| 3492 const NetworkDevice* cellular = FindCellularDevice(); |
| 3493 if (!cellular) { |
| 3494 NOTREACHED() << "Calling IsCellularAlwaysInRoaming method " |
| 3495 "w/o cellular device."; |
| 3496 return false; |
| 3497 } |
| 3498 const std::string& home_provider_name = cellular->home_provider_name(); |
| 3499 for (size_t i = 0; i < arraysize(kAlwaysInRoamingOperators); i++) { |
| 3500 if (home_provider_name == kAlwaysInRoamingOperators[i]) |
| 3501 return true; |
| 3502 } |
| 3503 return false; |
| 3504 } |
| 3505 |
3479 void NetworkLibraryImplCros::RequestNetworkScan() { | 3506 void NetworkLibraryImplCros::RequestNetworkScan() { |
3480 if (wifi_enabled()) { | 3507 if (wifi_enabled()) { |
3481 wifi_scanning_ = true; // Cleared when updates are received. | 3508 wifi_scanning_ = true; // Cleared when updates are received. |
3482 chromeos::RequestNetworkScan(kTypeWifi); | 3509 chromeos::RequestNetworkScan(kTypeWifi); |
3483 } | 3510 } |
3484 if (cellular_network()) | 3511 if (cellular_network()) |
3485 cellular_network()->RefreshDataPlansIfNeeded(); | 3512 cellular_network()->RefreshDataPlansIfNeeded(); |
3486 // Make sure all Manager info is up to date. This will also update | 3513 // Make sure all Manager info is up to date. This will also update |
3487 // remembered networks and visible services. | 3514 // remembered networks and visible services. |
3488 chromeos::RequestNetworkManagerInfo(&NetworkManagerUpdate, this); | 3515 chromeos::RequestNetworkManagerInfo(&NetworkManagerUpdate, this); |
(...skipping 755 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4244 } else { | 4271 } else { |
4245 NativeNetworkDeviceParser parser; | 4272 NativeNetworkDeviceParser parser; |
4246 device = parser.CreateDeviceFromInfo(device_path, info); | 4273 device = parser.CreateDeviceFromInfo(device_path, info); |
4247 VLOG(2) << " Adding device: " << device_path; | 4274 VLOG(2) << " Adding device: " << device_path; |
4248 if (device) { | 4275 if (device) { |
4249 device_map_[device_path] = device; | 4276 device_map_[device_path] = device; |
4250 } | 4277 } |
4251 CHECK(device) << "Attempted to add NULL device for path: " << device_path; | 4278 CHECK(device) << "Attempted to add NULL device for path: " << device_path; |
4252 } | 4279 } |
4253 VLOG(1) << "ParseNetworkDevice:" << device->name(); | 4280 VLOG(1) << "ParseNetworkDevice:" << device->name(); |
| 4281 if (device && device->type() == TYPE_CELLULAR) { |
| 4282 if (!device->data_roaming_allowed() && IsCellularAlwaysInRoaming()) { |
| 4283 SetCellularDataRoamingAllowed(true); |
| 4284 } else { |
| 4285 bool settings_value = |
| 4286 UserCrosSettingsProvider::cached_data_roaming_enabled(); |
| 4287 if (device->data_roaming_allowed() != settings_value) { |
| 4288 // Switch back to signed settings value. |
| 4289 SetCellularDataRoamingAllowed(settings_value); |
| 4290 } |
| 4291 } |
| 4292 } |
4254 NotifyNetworkManagerChanged(false); // Not forced. | 4293 NotifyNetworkManagerChanged(false); // Not forced. |
4255 AddNetworkDeviceObserver(device_path, network_device_observer_.get()); | 4294 AddNetworkDeviceObserver(device_path, network_device_observer_.get()); |
4256 } | 4295 } |
4257 | 4296 |
4258 //////////////////////////////////////////////////////////////////////////// | 4297 //////////////////////////////////////////////////////////////////////////// |
4259 | 4298 |
4260 class NetworkLibraryImplStub : public NetworkLibraryImplBase { | 4299 class NetworkLibraryImplStub : public NetworkLibraryImplBase { |
4261 public: | 4300 public: |
4262 NetworkLibraryImplStub(); | 4301 NetworkLibraryImplStub(); |
4263 virtual ~NetworkLibraryImplStub(); | 4302 virtual ~NetworkLibraryImplStub(); |
(...skipping 29 matching lines...) Expand all Loading... |
4293 virtual void ChangeRequirePin(bool require_pin, | 4332 virtual void ChangeRequirePin(bool require_pin, |
4294 const std::string& pin) OVERRIDE; | 4333 const std::string& pin) OVERRIDE; |
4295 virtual void EnterPin(const std::string& pin) OVERRIDE; | 4334 virtual void EnterPin(const std::string& pin) OVERRIDE; |
4296 virtual void UnblockPin(const std::string& puk, | 4335 virtual void UnblockPin(const std::string& puk, |
4297 const std::string& new_pin) OVERRIDE; | 4336 const std::string& new_pin) OVERRIDE; |
4298 | 4337 |
4299 virtual void RequestCellularScan() OVERRIDE {} | 4338 virtual void RequestCellularScan() OVERRIDE {} |
4300 virtual void RequestCellularRegister( | 4339 virtual void RequestCellularRegister( |
4301 const std::string& network_id) OVERRIDE {} | 4340 const std::string& network_id) OVERRIDE {} |
4302 virtual void SetCellularDataRoamingAllowed(bool new_value) OVERRIDE {} | 4341 virtual void SetCellularDataRoamingAllowed(bool new_value) OVERRIDE {} |
| 4342 virtual bool IsCellularAlwaysInRoaming() OVERRIDE { return false; } |
4303 virtual void RequestNetworkScan() OVERRIDE {} | 4343 virtual void RequestNetworkScan() OVERRIDE {} |
4304 | 4344 |
4305 virtual bool GetWifiAccessPoints(WifiAccessPointVector* result) OVERRIDE; | 4345 virtual bool GetWifiAccessPoints(WifiAccessPointVector* result) OVERRIDE; |
4306 | 4346 |
4307 virtual void DisconnectFromNetwork(const Network* network) OVERRIDE; | 4347 virtual void DisconnectFromNetwork(const Network* network) OVERRIDE; |
4308 | 4348 |
4309 virtual void CallEnableNetworkDeviceType( | 4349 virtual void CallEnableNetworkDeviceType( |
4310 ConnectionType device, bool enable) OVERRIDE {} | 4350 ConnectionType device, bool enable) OVERRIDE {} |
4311 virtual void EnableOfflineMode(bool enable) OVERRIDE { | 4351 virtual void EnableOfflineMode(bool enable) OVERRIDE { |
4312 offline_mode_ = enable; | 4352 offline_mode_ = enable; |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4612 return network_library; | 4652 return network_library; |
4613 } | 4653 } |
4614 | 4654 |
4615 ///////////////////////////////////////////////////////////////////////////// | 4655 ///////////////////////////////////////////////////////////////////////////// |
4616 | 4656 |
4617 } // namespace chromeos | 4657 } // namespace chromeos |
4618 | 4658 |
4619 // Allows InvokeLater without adding refcounting. This class is a Singleton and | 4659 // Allows InvokeLater without adding refcounting. This class is a Singleton and |
4620 // won't be deleted until its last InvokeLater is run. | 4660 // won't be deleted until its last InvokeLater is run. |
4621 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::NetworkLibraryImplBase); | 4661 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::NetworkLibraryImplBase); |
OLD | NEW |