1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
|
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROMEOS_ASH_COMPONENTS_NETWORK_NETWORK_DEVICE_HANDLER_IMPL_H_
#define CHROMEOS_ASH_COMPONENTS_NETWORK_NETWORK_DEVICE_HANDLER_IMPL_H_
#include <string>
#include <unordered_set>
#include <vector>
#include "base/compiler_specific.h"
#include "base/component_export.h"
#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/scoped_observation.h"
#include "chromeos/ash/components/network/cellular_metrics_logger.h"
#include "chromeos/ash/components/network/network_device_handler.h"
#include "chromeos/ash/components/network/network_handler.h"
#include "chromeos/ash/components/network/network_handler_callbacks.h"
#include "chromeos/ash/components/network/network_state_handler.h"
#include "chromeos/ash/components/network/network_state_handler_observer.h"
namespace ash {
class NetworkStateHandler;
class COMPONENT_EXPORT(CHROMEOS_NETWORK) NetworkDeviceHandlerImpl
: public NetworkDeviceHandler,
public NetworkStateHandlerObserver {
public:
NetworkDeviceHandlerImpl(const NetworkDeviceHandlerImpl&) = delete;
NetworkDeviceHandlerImpl& operator=(const NetworkDeviceHandlerImpl&) = delete;
~NetworkDeviceHandlerImpl() override;
// NetworkDeviceHandler overrides
void GetDeviceProperties(
const std::string& device_path,
network_handler::ResultCallback callback) const override;
void SetDeviceProperty(
const std::string& device_path,
const std::string& property_name,
const base::Value& value,
base::OnceClosure callback,
network_handler::ErrorCallback error_callback) override;
void RegisterCellularNetwork(
const std::string& device_path,
const std::string& network_id,
base::OnceClosure callback,
network_handler::ErrorCallback error_callback) override;
void RequirePin(const std::string& device_path,
bool require_pin,
const std::string& pin,
base::OnceClosure callback,
network_handler::ErrorCallback error_callback) override;
void EnterPin(const std::string& device_path,
const std::string& pin,
base::OnceClosure callback,
network_handler::ErrorCallback error_callback) override;
void UnblockPin(const std::string& device_path,
const std::string& puk,
const std::string& new_pin,
base::OnceClosure callback,
network_handler::ErrorCallback error_callback) override;
void ChangePin(const std::string& device_path,
const std::string& old_pin,
const std::string& new_pin,
base::OnceClosure callback,
network_handler::ErrorCallback error_callback) override;
void SetAllowCellularSimLock(bool allow_cellular_sim_lock) override;
void SetCellularPolicyAllowRoaming(bool policy_allow_roaming) override;
void SetMACAddressRandomizationEnabled(bool enabled) override;
void SetUsbEthernetMacAddressSource(const std::string& source) override;
// NetworkStateHandlerObserver overrides
void DeviceListChanged() override;
void DevicePropertiesUpdated(const DeviceState* device) override;
private:
friend class NetworkHandler;
friend class NetworkDeviceHandler;
friend class NetworkDeviceHandlerTest;
// Some WiFi feature enablement needs to check supported property before
// setting. e.g. MAC address randomization, wake on WiFi.
// When there's no Wi-Fi device or there is one but we haven't asked if
// the feature is supported yet, the value of the member, e.g.
// |mac_addr_randomizaton_supported_|, will be |NOT_REQUESTED|. When we
// try to apply the value e.g. |mac_addr_randomization_enabled_|, we will
// check whether it is supported and change to one of the other two
// values.
enum class WifiFeatureSupport { NOT_REQUESTED, SUPPORTED, UNSUPPORTED };
NetworkDeviceHandlerImpl();
void Init(NetworkStateHandler* network_state_handler);
// Applies the current value of |cellular_policy_allow_roaming_| to all
// existing cellular devices of Shill.
void ApplyCellularAllowRoamingToShill();
// Applies the current value of |mac_addr_randomization_enabled_| to wifi
// devices.
void ApplyMACAddressRandomizationToShill();
// Applies the wake-on-wifi-allowed feature flag to WiFi devices.
void ApplyWakeOnWifiAllowedToShill();
// Applies the current value of |usb_ethernet_mac_address_source_| to primary
// enabled USB Ethernet device. Does nothing if MAC address source is not
// specified yet.
void ApplyUsbEthernetMacAddressSourceToShill();
// Utility function for applying enabled setting of WiFi features that needs
// to check if the feature is supported first.
// This function will update |supported| if it is still NOT_REQUESTED by
// getting |support_property_name| property of the WiFi device. Then, if it
// is supported, set |enable_property_name| property of the WiFi device to
// |enabled|.
void ApplyWifiFeatureToShillIfSupported(std::string enable_property_name,
bool enabled,
std::string support_property_name,
WifiFeatureSupport* supported);
// Callback function used by ApplyWifiFeatureToShillIfSupported to get shill
// property when the supported property is NOT_REQUESTED. It will extract
// |support_property_name| of GetProperties response and update
// |feature_support_to_set|, then call ApplyWifiFeatureToShillIfSupported
// again if the feature is supported.
void HandleWifiFeatureSupportedProperty(
std::string enable_property_name,
bool enabled,
std::string support_property_name,
WifiFeatureSupport* feature_support_to_set,
const std::string& device_path,
std::optional<base::Value::Dict> properties);
// Callback to be called on MAC address source change request failure.
// The request was called on device with |device_path| path and
// |device_mac_address| MAC address to change MAC address source to the new
// |mac_address_source| value.
void OnSetUsbEthernetMacAddressSourceError(
const std::string& device_path,
const std::string& device_mac_address,
const std::string& mac_address_source,
network_handler::ErrorCallback error_callback,
const std::string& shill_error_name,
const std::string& shill_error_message);
// Checks whether Device is enabled USB Ethernet adapter.
bool IsUsbEnabledDevice(const DeviceState* device_state) const;
// Updates the primary enabled USB Ethernet device path.
void UpdatePrimaryEnabledUsbEthernetDevice();
// Resets MAC address source property for secondary USB Ethernet devices.
void ResetMacAddressSourceForSecondaryUsbEthernetDevices() const;
// On a successful SIM PIN unlock, or a successful SIM PUK unblock.
void OnPinValidationSuccess(
const std::string& device_path,
const std::string& pin,
const CellularMetricsLogger::SimPinOperation& pin_operation,
base::OnceClosure callback);
// Get the DeviceState for the wifi device, if any.
const DeviceState* GetWifiDeviceState();
raw_ptr<NetworkStateHandler> network_state_handler_ = nullptr;
base::ScopedObservation<NetworkStateHandler, NetworkStateHandlerObserver>
network_state_handler_observer_{this};
bool allow_cellular_sim_lock_ = true;
bool cellular_policy_allow_roaming_ = true;
WifiFeatureSupport mac_addr_randomization_supported_ =
WifiFeatureSupport::NOT_REQUESTED;
bool mac_addr_randomization_enabled_ = false;
WifiFeatureSupport wake_on_wifi_supported_ =
WifiFeatureSupport::NOT_REQUESTED;
bool wake_on_wifi_allowed_ = false;
std::string usb_ethernet_mac_address_source_;
std::string primary_enabled_usb_ethernet_device_path_;
// Set of device's MAC addresses that do not support MAC address source change
// to |usb_ethernet_mac_address_source_|. Use MAC address as unique device
// identifier, because link name can change.
std::unordered_set<std::string> mac_address_change_not_supported_;
base::WeakPtrFactory<NetworkDeviceHandlerImpl> weak_ptr_factory_{this};
};
} // namespace ash
#endif // CHROMEOS_ASH_COMPONENTS_NETWORK_NETWORK_DEVICE_HANDLER_IMPL_H_
|