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 #ifndef CHROMEOS_NETWORK_DEVICE_STATE_H_ 6 #define CHROMEOS_NETWORK_DEVICE_STATE_H_ 7 8 #include <stdint.h> 9 10 #include "base/macros.h" 11 #include "base/values.h" 12 #include "chromeos/network/managed_state.h" 13 #include "chromeos/network/network_util.h" 14 15 namespace chromeos { 16 17 // Simple class to provide device state information. Similar to NetworkState; 18 // see network_state.h for usage guidelines. COMPONENT_EXPORT(CHROMEOS_NETWORK)19class COMPONENT_EXPORT(CHROMEOS_NETWORK) DeviceState : public ManagedState { 20 public: 21 typedef std::vector<CellularScanResult> CellularScanResults; 22 23 explicit DeviceState(const std::string& path); 24 ~DeviceState() override; 25 26 // ManagedState overrides 27 bool PropertyChanged(const std::string& key, 28 const base::Value& value) override; 29 bool IsActive() const override; 30 31 void IPConfigPropertiesChanged(const std::string& ip_config_path, 32 const base::Value& properties); 33 34 // Accessors 35 const std::string& mac_address() const { return mac_address_; } 36 const std::string& interface() const { return interface_; } 37 bool scanning() const { return scanning_; } 38 void set_scanning(bool scanning) { scanning_ = scanning; } 39 40 // Cellular specific accessors 41 const std::string& operator_name() const { return operator_name_; } 42 const std::string& country_code() const { return country_code_; } 43 bool allow_roaming() const { return allow_roaming_; } 44 bool provider_requires_roaming() const { return provider_requires_roaming_; } 45 bool support_network_scan() const { return support_network_scan_; } 46 const std::string& technology_family() const { return technology_family_; } 47 bool sim_present() const { return sim_present_; } 48 const std::string& sim_lock_type() const { return sim_lock_type_; } 49 int sim_retries_left() const { return sim_retries_left_; } 50 bool sim_lock_enabled() const { return sim_lock_enabled_; } 51 const std::string& meid() const { return meid_; } 52 const std::string& imei() const { return imei_; } 53 const std::string& iccid() const { return iccid_; } 54 const std::string& mdn() const { return mdn_; } 55 const base::ListValue& apn_list() const { return apn_list_; } 56 const CellularScanResults& scan_results() const { return scan_results_; } 57 58 // |ip_configs_| is kept up to date by NetworkStateHandler. 59 const base::DictionaryValue& ip_configs() const { return ip_configs_; } 60 61 // Do not use this. It exists temporarily for internet_options_handler.cc 62 // which is being deprecated. 63 const base::DictionaryValue& properties() const { return properties_; } 64 65 // Ethernet specific accessors 66 bool eap_authentication_completed() const { 67 return eap_authentication_completed_; 68 } 69 bool link_up() const { return link_up_; } 70 const std::string& device_bus_type() const { return device_bus_type_; } 71 const std::string& mac_address_source() const { return mac_address_source_; } 72 73 // WiFi specific accessors 74 const std::string& available_managed_network_path() const { 75 return available_managed_network_path_; 76 } 77 void set_available_managed_network_path( 78 const std::string available_managed_network_path) { 79 available_managed_network_path_ = available_managed_network_path; 80 } 81 82 // Returns a human readable string for the device. 83 std::string GetName() const; 84 85 // Returns the IP Address for |type| if it exists or an empty string. 86 std::string GetIpAddressByType(const std::string& type) const; 87 88 // The following return false if the technology does not require a SIM. 89 bool IsSimAbsent() const; 90 bool IsSimLocked() const; 91 92 // Returns true if |access_point_name| exists in apn_list for this device. 93 bool HasAPN(const std::string& access_point_name) const; 94 95 private: 96 // Common Device Properties 97 std::string mac_address_; 98 std::string interface_; 99 100 // Cellular specific properties 101 std::string operator_name_; 102 std::string country_code_; 103 bool allow_roaming_ = false; 104 bool provider_requires_roaming_ = false; 105 bool support_network_scan_ = false; 106 bool scanning_ = false; 107 std::string technology_family_; 108 std::string sim_lock_type_; 109 int sim_retries_left_ = 0; 110 bool sim_lock_enabled_ = false; 111 bool sim_present_ = true; 112 std::string meid_; 113 std::string imei_; 114 std::string iccid_; 115 std::string mdn_; 116 CellularScanResults scan_results_; 117 118 // Ethernet specific properties 119 bool eap_authentication_completed_ = false; 120 bool link_up_ = false; 121 std::string device_bus_type_; 122 std::string mac_address_source_; 123 124 // WiFi specific properties 125 std::string available_managed_network_path_; 126 127 // Keep all Device properties in a dictionary for now. See comment above. 128 base::DictionaryValue properties_; 129 130 // List of APNs. 131 base::ListValue apn_list_; 132 133 // Dictionary of IPConfig properties, keyed by IpConfig path. 134 base::DictionaryValue ip_configs_; 135 136 DISALLOW_COPY_AND_ASSIGN(DeviceState); 137 }; 138 139 } // namespace chromeos 140 141 #endif // CHROMEOS_NETWORK_DEVICE_STATE_H_ 142