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.
5 #include "chromeos/network/device_state.h"
7 #include "base/logging.h"
8 #include "base/metrics/histogram.h"
9 #include "base/strings/stringprintf.h"
10 #include "chromeos/network/network_event_log.h"
11 #include "chromeos/network/shill_property_util.h"
12 #include "third_party/cros_system_api/dbus/service_constants.h"
16 DeviceState::DeviceState(const std::string
& path
)
17 : ManagedState(MANAGED_TYPE_DEVICE
, path
),
18 allow_roaming_(false),
19 provider_requires_roaming_(false),
20 support_network_scan_(false),
23 sim_lock_enabled_(false),
25 eap_authentication_completed_(false) {
28 DeviceState::~DeviceState() {
31 bool DeviceState::PropertyChanged(const std::string
& key
,
32 const base::Value
& value
) {
33 // All property values get stored in |properties_|.
34 properties_
.SetWithoutPathExpansion(key
, value
.DeepCopy());
36 if (ManagedStatePropertyChanged(key
, value
))
38 if (key
== shill::kAddressProperty
) {
39 return GetStringValue(key
, value
, &mac_address_
);
40 } else if (key
== shill::kScanningProperty
) {
41 return GetBooleanValue(key
, value
, &scanning_
);
42 } else if (key
== shill::kSupportNetworkScanProperty
) {
43 return GetBooleanValue(key
, value
, &support_network_scan_
);
44 } else if (key
== shill::kCellularAllowRoamingProperty
) {
45 return GetBooleanValue(key
, value
, &allow_roaming_
);
46 } else if (key
== shill::kProviderRequiresRoamingProperty
) {
47 return GetBooleanValue(key
, value
, &provider_requires_roaming_
);
48 } else if (key
== shill::kHomeProviderProperty
) {
49 return shill_property_util::GetHomeProviderFromProperty(
50 value
, &home_provider_id_
);
51 } else if (key
== shill::kTechnologyFamilyProperty
) {
52 return GetStringValue(key
, value
, &technology_family_
);
53 } else if (key
== shill::kCarrierProperty
) {
54 return GetStringValue(key
, value
, &carrier_
);
55 } else if (key
== shill::kFoundNetworksProperty
) {
56 const base::ListValue
* list
= NULL
;
57 if (!value
.GetAsList(&list
))
59 CellularScanResults parsed_results
;
60 if (!network_util::ParseCellularScanResults(*list
, &parsed_results
))
62 scan_results_
.swap(parsed_results
);
64 } else if (key
== shill::kSIMLockStatusProperty
) {
65 const base::DictionaryValue
* dict
= NULL
;
66 if (!value
.GetAsDictionary(&dict
))
69 // Return true if at least one of the property values changed.
70 bool property_changed
= false;
71 const base::Value
* out_value
= NULL
;
72 if (!dict
->GetWithoutPathExpansion(shill::kSIMLockRetriesLeftProperty
,
75 if (GetUInt32Value(shill::kSIMLockRetriesLeftProperty
,
76 *out_value
, &sim_retries_left_
))
77 property_changed
= true;
79 if (!dict
->GetWithoutPathExpansion(shill::kSIMLockTypeProperty
,
82 if (GetStringValue(shill::kSIMLockTypeProperty
,
83 *out_value
, &sim_lock_type_
))
84 property_changed
= true;
86 if (!dict
->GetWithoutPathExpansion(shill::kSIMLockEnabledProperty
,
89 if (GetBooleanValue(shill::kSIMLockEnabledProperty
,
90 *out_value
, &sim_lock_enabled_
))
91 property_changed
= true;
93 return property_changed
;
94 } else if (key
== shill::kMeidProperty
) {
95 return GetStringValue(key
, value
, &meid_
);
96 } else if (key
== shill::kImeiProperty
) {
97 return GetStringValue(key
, value
, &imei_
);
98 } else if (key
== shill::kIccidProperty
) {
99 return GetStringValue(key
, value
, &iccid_
);
100 } else if (key
== shill::kMdnProperty
) {
101 return GetStringValue(key
, value
, &mdn_
);
102 } else if (key
== shill::kSIMPresentProperty
) {
103 return GetBooleanValue(key
, value
, &sim_present_
);
104 } else if (key
== shill::kEapAuthenticationCompletedProperty
) {
105 return GetBooleanValue(key
, value
, &eap_authentication_completed_
);
106 } else if (key
== shill::kIPConfigsProperty
) {
107 // If kIPConfigsProperty changes, clear any previous ip_configs_.
108 // ShillPropertyhandler will request the IPConfig objects which will trigger
109 // calls to IPConfigPropertiesChanged.
111 return false; // No actual state change.
116 bool DeviceState::InitialPropertiesReceived(
117 const base::DictionaryValue
& properties
) {
120 bool locked
= !sim_lock_type_
.empty();
121 UMA_HISTOGRAM_BOOLEAN("Cellular.SIMLocked", locked
);
126 void DeviceState::IPConfigPropertiesChanged(
127 const std::string
& ip_config_path
,
128 const base::DictionaryValue
& properties
) {
129 base::DictionaryValue
* ip_config
= NULL
;
130 if (ip_configs_
.GetDictionaryWithoutPathExpansion(
131 ip_config_path
, &ip_config
)) {
132 NET_LOG_EVENT("IPConfig Updated: " + ip_config_path
, path());
135 NET_LOG_EVENT("IPConfig Added: " + ip_config_path
, path());
136 ip_config
= new base::DictionaryValue
;
137 ip_configs_
.SetWithoutPathExpansion(ip_config_path
, ip_config
);
139 ip_config
->MergeDictionary(&properties
);
142 bool DeviceState::IsSimAbsent() const {
143 return technology_family_
== shill::kTechnologyFamilyGsm
&& !sim_present_
;
146 } // namespace chromeos