Commit a2c71349 authored by Markus Heintz's avatar Markus Heintz Committed by Commit Bot

Revert "arc: net: remove ARC N legacy APIs"

This reverts commit 956b131c.

Reason for revert: 
Specualtive revert in order to fix broken test in
https://ci.chromium.org/p/chrome/builders/ci/chromeos-betty-chrome/2747

Original change's description:
> arc: net: remove ARC N legacy APIs
> 
> This patch removes net.mojom APIs and fields only used in ARC N:
>  - NetworkConfiguration mac_address: the host mac_address of a network
>  is now completely hidden in ARC P.
>  - GetDefaultNetwork and DefaultNetworkChanged: ARC P is multinetwork
>  aware and always need the full list of connected services.
> 
> BUG=b:149716479
> BUG=b:145960788
> TEST=Compiled, flashed eve, ran CtsNetTestCases.
> 
> Change-Id: I3368d620d44dd910aae7a12c84c207c3d5cb6cf3
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2086362
> Reviewed-by: Kazuhiro Inaba <kinaba@chromium.org>
> Reviewed-by: Hidehiko Abe <hidehiko@chromium.org>
> Reviewed-by: Dominick Ng <dominickn@chromium.org>
> Commit-Queue: Hugo Benichi <hugobenichi@google.com>
> Cr-Commit-Position: refs/heads/master@{#748094}

TBR=kinaba@chromium.org,jorgelo@chromium.org,hidehiko@chromium.org,mnissler@chromium.org,dominickn@chromium.org,hugobenichi@google.com,garrick@chromium.org,jasongustaman@chromium.org,taoyl@chromium.org

Change-Id: Id248f5e5f23d8c995404f509c30289b77f94e2cc
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: b:149716479, b:145960788
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2094307Reviewed-by: default avatarMarkus Heintz <markusheintz@chromium.org>
Commit-Queue: Markus Heintz <markusheintz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#748217}
parent c48c7354
......@@ -192,8 +192,8 @@ struct NetworkConfiguration {
// IP configuration for the network service inside ARC.
array<IPConfiguration>? ip_configs;
// Deprecated field unused from ARC P and later.
string? deprecated_mac_address;
// MAC address of the network interface inside the ARC.
string? mac_address;
// The type of the underlying physical network.
NetworkType type;
......@@ -336,7 +336,7 @@ struct AndroidVpnConfiguration {
};
// Next Method ID: 14
// IDs 3 and 9 are missing as they belonged to deprecated methods.
// ID 3 is missing as it belonged to a deprecated method.
interface NetHost {
// Sends a request to get enabled / disabled status of WiFi.
GetWifiEnabledState@1() => (bool is_enabled);
......@@ -364,6 +364,11 @@ interface NetHost {
// Disconnects from network |guid|.
[MinVersion=4] StartDisconnect@8(string guid) => (NetworkResult status);
// Retrieve details (IP, SSID, etc.) about the current network connection.
[MinVersion=5] GetDefaultNetwork@9() => (
NetworkConfiguration? logical_default,
NetworkConfiguration? physical_default);
// Sends a request to get the subset of network services existing on Chrome OS
// that match the kind specified with GetNetworksRequestType. This call
// supports three usages:
......@@ -396,7 +401,6 @@ interface NetHost {
};
// Next Method ID: 8
// ID 2 is missing as it belonged to deprecated method.
interface NetInstance {
// DEPRECATED: Please use Init@6 instead.
InitDeprecated@0(NetHost host_ptr);
......@@ -407,6 +411,11 @@ interface NetInstance {
// Notifies the instance of a WiFI AP scan being completed.
[MinVersion=1] ScanCompleted@1();
// Notifies the instance of a change in the host default network service.
[MinVersion=2] DefaultNetworkChanged@2(
NetworkConfiguration? logical_default,
NetworkConfiguration? physical_default);
// Notifies the instance of a change in the state of WiFi on the host.
[MinVersion=3] WifiEnabledStateChanged@3(bool is_enabled);
......
......@@ -355,6 +355,8 @@ arc::mojom::NetworkConfigurationPtr TranslateONCConfiguration(
mojo->guid = GetStringFromONCDictionary(dict, onc::network_config::kGUID,
true /* required */);
mojo->mac_address = GetStringFromONCDictionary(
dict, onc::network_config::kMacAddress, false /* required */);
TranslateONCNetworkTypeDetails(dict, mojo.get());
if (network_state) {
......@@ -454,6 +456,36 @@ void StartDisconnectFailureCallback(
std::move(callback).Run(arc::mojom::NetworkResult::FAILURE);
}
void GetDefaultNetworkSuccessCallback(
base::OnceCallback<void(arc::mojom::NetworkConfigurationPtr,
arc::mojom::NetworkConfigurationPtr)> callback,
const std::string& service_path,
const base::DictionaryValue& dictionary) {
// TODO(cernekee): Figure out how to query Chrome for the default physical
// service if a VPN is connected, rather than just reporting the
// default logical service in both fields.
const chromeos::NetworkState* network_state =
GetStateHandler()->GetNetworkState(service_path);
std::move(callback).Run(
TranslateONCConfiguration(network_state, &dictionary),
TranslateONCConfiguration(network_state, &dictionary));
}
void GetDefaultNetworkFailureCallback(
base::OnceCallback<void(arc::mojom::NetworkConfigurationPtr,
arc::mojom::NetworkConfigurationPtr)> callback,
const std::string& error_name,
std::unique_ptr<base::DictionaryValue> error_data) {
LOG(ERROR) << "Failed to query default logical network: " << error_name;
std::move(callback).Run(nullptr, nullptr);
}
void DefaultNetworkFailureCallback(
const std::string& error_name,
std::unique_ptr<base::DictionaryValue> error_data) {
LOG(ERROR) << "Failed to query default logical network: " << error_name;
}
void ArcVpnSuccessCallback() {
DVLOG(1) << "ArcVpnSuccessCallback";
}
......@@ -767,8 +799,80 @@ void ArcNetHostImpl::ScanCompleted(const chromeos::DeviceState* /*unused*/) {
net_instance->ScanCompleted();
}
const chromeos::NetworkState* ArcNetHostImpl::GetDefaultNetworkFromChrome() {
// If an Android VPN is connected, report the underlying physical
// connection only. Never tell Android about its own VPN.
// If a Chrome OS VPN is connected, report the Chrome OS VPN as the
// default connection.
if (arc_vpn_service_path_.empty()) {
return GetShillBackedNetwork(GetStateHandler()->DefaultNetwork());
}
return GetShillBackedNetwork(GetStateHandler()->ConnectedNetworkByType(
chromeos::NetworkTypePattern::NonVirtual()));
}
void ArcNetHostImpl::GetDefaultNetwork(GetDefaultNetworkCallback callback) {
const chromeos::NetworkState* default_network = GetDefaultNetworkFromChrome();
if (!default_network) {
VLOG(1) << "GetDefaultNetwork: no default network";
std::move(callback).Run(nullptr, nullptr);
return;
}
VLOG(1) << "GetDefaultNetwork: default network is "
<< default_network->path();
std::string user_id_hash = chromeos::LoginState::Get()->primary_user_hash();
// TODO(crbug.com/730593): Remove AdaptCallbackForRepeating() by updating
// the callee interface.
auto repeating_callback =
base::AdaptCallbackForRepeating(std::move(callback));
GetManagedConfigurationHandler()->GetProperties(
user_id_hash, default_network->path(),
base::Bind(&GetDefaultNetworkSuccessCallback, repeating_callback),
base::Bind(&GetDefaultNetworkFailureCallback, repeating_callback));
}
void ArcNetHostImpl::DefaultNetworkSuccessCallback(
const std::string& service_path,
const base::DictionaryValue& dictionary) {
auto* net_instance = ARC_GET_INSTANCE_FOR_METHOD(arc_bridge_service_->net(),
DefaultNetworkChanged);
if (!net_instance)
return;
const chromeos::NetworkState* network_state =
GetStateHandler()->GetNetworkState(service_path);
net_instance->DefaultNetworkChanged(
TranslateONCConfiguration(network_state, &dictionary),
TranslateONCConfiguration(network_state, &dictionary));
}
void ArcNetHostImpl::UpdateDefaultNetwork() {
const chromeos::NetworkState* default_network = GetDefaultNetworkFromChrome();
if (!default_network) {
VLOG(1) << "No default network";
auto* net_instance = ARC_GET_INSTANCE_FOR_METHOD(arc_bridge_service_->net(),
DefaultNetworkChanged);
if (net_instance)
net_instance->DefaultNetworkChanged(nullptr, nullptr);
return;
}
VLOG(1) << "New default network: " << default_network->path() << " ("
<< default_network->type() << ")";
std::string user_id_hash = chromeos::LoginState::Get()->primary_user_hash();
GetManagedConfigurationHandler()->GetProperties(
user_id_hash, default_network->path(),
base::Bind(&ArcNetHostImpl::DefaultNetworkSuccessCallback,
weak_factory_.GetWeakPtr()),
base::Bind(&DefaultNetworkFailureCallback));
}
void ArcNetHostImpl::DefaultNetworkChanged(
const chromeos::NetworkState* network) {
UpdateDefaultNetwork();
UpdateActiveNetworks();
}
......@@ -966,6 +1070,12 @@ void ArcNetHostImpl::DisconnectRequested(const std::string& service_path) {
void ArcNetHostImpl::NetworkConnectionStateChanged(
const chromeos::NetworkState* network) {
// DefaultNetworkChanged() won't be invoked if an ARC VPN is the default
// network and the underlying physical connection changed, so check for
// that condition here. This is invoked any time any service state
// changes.
UpdateDefaultNetwork();
const chromeos::NetworkState* shill_backed_network =
GetShillBackedNetwork(network);
if (!shill_backed_network)
......@@ -1034,6 +1144,7 @@ void ArcNetHostImpl::NetworkListChanged() {
// During the transition when a new service comes online, it will
// temporarily be ranked below "inferior" services. This callback
// informs us that shill's ordering has been updated.
UpdateDefaultNetwork();
UpdateActiveNetworks();
}
......
......@@ -96,6 +96,7 @@ class ArcNetHostImpl : public KeyedService,
const std::vector<const chromeos::NetworkState*>& networks) override;
void NetworkListChanged() override;
void DeviceListChanged() override;
void GetDefaultNetwork(GetDefaultNetworkCallback callback) override;
// Overriden from chromeos::NetworkConnectionObserver.
void DisconnectRequested(const std::string& service_path) override;
......@@ -106,6 +107,7 @@ class ArcNetHostImpl : public KeyedService,
private:
const chromeos::NetworkState* GetDefaultNetworkFromChrome();
void UpdateDefaultNetwork();
void UpdateActiveNetworks();
void DefaultNetworkSuccessCallback(const std::string& service_path,
const base::DictionaryValue& dictionary);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment