device_state.cc revision 868fa2fe829687343ffae624259930155e16dbd8
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 3// found in the LICENSE file. 4 5#include "chromeos/network/device_state.h" 6 7#include "base/logging.h" 8#include "base/strings/stringprintf.h" 9#include "base/values.h" 10#include "third_party/cros_system_api/dbus/service_constants.h" 11 12namespace chromeos { 13 14DeviceState::DeviceState(const std::string& path) 15 : ManagedState(MANAGED_TYPE_DEVICE, path), 16 provider_requires_roaming_(false), 17 support_network_scan_(false), 18 scanning_(false), 19 sim_present_(true) { 20} 21 22DeviceState::~DeviceState() { 23} 24 25bool DeviceState::PropertyChanged(const std::string& key, 26 const base::Value& value) { 27 if (ManagedStatePropertyChanged(key, value)) 28 return true; 29 if (key == flimflam::kAddressProperty) { 30 return GetStringValue(key, value, &mac_address_); 31 } else if (key == flimflam::kScanningProperty) { 32 return GetBooleanValue(key, value, &scanning_); 33 } else if (key == flimflam::kSupportNetworkScanProperty) { 34 return GetBooleanValue(key, value, &support_network_scan_); 35 } else if (key == shill::kProviderRequiresRoamingProperty) { 36 return GetBooleanValue(key, value, &provider_requires_roaming_); 37 } else if (key == flimflam::kHomeProviderProperty) { 38 const DictionaryValue* dict = NULL; 39 if (!value.GetAsDictionary(&dict)) 40 return false; 41 std::string home_provider_country; 42 std::string home_provider_name; 43 dict->GetStringWithoutPathExpansion(flimflam::kOperatorCountryKey, 44 &home_provider_country); 45 dict->GetStringWithoutPathExpansion(flimflam::kOperatorNameKey, 46 &home_provider_name); 47 // Set home_provider_id_ 48 if (!home_provider_name.empty() && !home_provider_country.empty()) { 49 home_provider_id_ = base::StringPrintf( 50 "%s (%s)", 51 home_provider_name.c_str(), 52 home_provider_country.c_str()); 53 } else { 54 dict->GetStringWithoutPathExpansion(flimflam::kOperatorCodeKey, 55 &home_provider_id_); 56 LOG(WARNING) << "Carrier ID not defined, using code instead: " 57 << home_provider_id_; 58 } 59 return true; 60 } else if (key == flimflam::kTechnologyFamilyProperty) { 61 return GetStringValue(key, value, &technology_family_); 62 } else if (key == flimflam::kSIMLockStatusProperty) { 63 const DictionaryValue* dict = NULL; 64 if (!value.GetAsDictionary(&dict)) 65 return false; 66 if (!dict->GetStringWithoutPathExpansion(flimflam::kSIMLockTypeProperty, 67 &sim_lock_type_)) 68 return false; 69 // Ignore other SIMLockStatus properties. 70 return true; 71 } else if (key == shill::kSIMPresentProperty) { 72 return GetBooleanValue(key, value, &sim_present_); 73 } 74 return false; 75} 76 77bool DeviceState::IsSimAbsent() const { 78 return technology_family_ == flimflam::kTechnologyFamilyGsm && !sim_present_; 79} 80 81} // namespace chromeos 82