From 12c81113109c20c730b66e8c33df948c231cb9f0 Mon Sep 17 00:00:00 2001 From: Remi NGUYEN VAN Date: Thu, 4 Feb 2021 16:36:24 +0900 Subject: [PATCH 1/6] Rename StringNetworkSpecifier to Ethernet The new specifier represents ethernet interfaces more specifically and is part of the public API. Bug: 179329291 Test: atest CtsNetTestCases Change-Id: I6cba1709b3007a22d95849a1281237c77e1464a4 --- .../android/server/ethernet/EthernetNetworkFactory.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/service-t/src/com/android/server/ethernet/EthernetNetworkFactory.java b/service-t/src/com/android/server/ethernet/EthernetNetworkFactory.java index b9ebf8974e..dba152cc4e 100644 --- a/service-t/src/com/android/server/ethernet/EthernetNetworkFactory.java +++ b/service-t/src/com/android/server/ethernet/EthernetNetworkFactory.java @@ -23,6 +23,7 @@ import android.annotation.NonNull; import android.annotation.Nullable; import android.content.Context; import android.net.ConnectivityManager; +import android.net.EthernetNetworkSpecifier; import android.net.IpConfiguration; import android.net.IpConfiguration.IpAssignment; import android.net.IpConfiguration.ProxySettings; @@ -33,7 +34,6 @@ import android.net.NetworkCapabilities; import android.net.NetworkFactory; import android.net.NetworkRequest; import android.net.NetworkSpecifier; -import android.net.StringNetworkSpecifier; import android.net.ip.IIpClient; import android.net.ip.IpClientCallbacks; import android.net.ip.IpClientUtil; @@ -219,8 +219,9 @@ public class EthernetNetworkFactory extends NetworkFactory { String requestedIface = null; NetworkSpecifier specifier = request.getNetworkSpecifier(); - if (specifier instanceof StringNetworkSpecifier) { - requestedIface = ((StringNetworkSpecifier) specifier).specifier; + if (specifier instanceof EthernetNetworkSpecifier) { + requestedIface = ((EthernetNetworkSpecifier) specifier) + .getInterfaceName(); } NetworkInterfaceState network = null; From 4a0cbe98c1bb9ef45d098abfb3ade0135a9768c2 Mon Sep 17 00:00:00 2001 From: lucaslin Date: Fri, 19 Mar 2021 15:14:23 +0800 Subject: [PATCH 2/6] Use public API instead of hidden API in EthernetTracker - Use public API of StaticIpConfiguration.Builder to set ipaddress, domains, gateway and dnsServers. - Use public constructor to create an instance of IpConfiguration and set IpAssignment, ProxySettings, StaticIpConfiguration and HttpProxy by public API. Bug: 182963415 Test: m ethernet-service Change-Id: Idce8bfe7afc31baa644c816afa1f8004987e8c6e --- .../server/ethernet/EthernetTracker.java | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/service-t/src/com/android/server/ethernet/EthernetTracker.java b/service-t/src/com/android/server/ethernet/EthernetTracker.java index a831f34a5a..a190240edb 100644 --- a/service-t/src/com/android/server/ethernet/EthernetTracker.java +++ b/service-t/src/com/android/server/ethernet/EthernetTracker.java @@ -579,7 +579,8 @@ final class EthernetTracker { */ @VisibleForTesting static IpConfiguration parseStaticIpConfiguration(String staticIpConfig) { - StaticIpConfiguration ipConfig = new StaticIpConfiguration(); + final StaticIpConfiguration.Builder staticIpConfigBuilder = + new StaticIpConfiguration.Builder(); for (String keyValueAsString : staticIpConfig.trim().split(" ")) { if (TextUtils.isEmpty(keyValueAsString)) continue; @@ -595,20 +596,20 @@ final class EthernetTracker { switch (key) { case "ip": - ipConfig.ipAddress = new LinkAddress(value); + staticIpConfigBuilder.setIpAddress(new LinkAddress(value)); break; case "domains": - ipConfig.domains = value; + staticIpConfigBuilder.setDomains(value); break; case "gateway": - ipConfig.gateway = InetAddress.parseNumericAddress(value); + staticIpConfigBuilder.setGateway(InetAddress.parseNumericAddress(value)); break; case "dns": { ArrayList dnsAddresses = new ArrayList<>(); for (String address: value.split(",")) { dnsAddresses.add(InetAddress.parseNumericAddress(address)); } - ipConfig.dnsServers.addAll(dnsAddresses); + staticIpConfigBuilder.setDnsServers(dnsAddresses); break; } default : { @@ -617,11 +618,18 @@ final class EthernetTracker { } } } - return new IpConfiguration(IpAssignment.STATIC, ProxySettings.NONE, ipConfig, null); + final IpConfiguration ret = new IpConfiguration(); + ret.setIpAssignment(IpAssignment.STATIC); + ret.setProxySettings(ProxySettings.NONE); + ret.setStaticIpConfiguration(staticIpConfigBuilder.build()); + return ret; } private static IpConfiguration createDefaultIpConfiguration() { - return new IpConfiguration(IpAssignment.DHCP, ProxySettings.NONE, null, null); + final IpConfiguration ret = new IpConfiguration(); + ret.setIpAssignment(IpAssignment.DHCP); + ret.setProxySettings(ProxySettings.NONE); + return ret; } private void updateIfaceMatchRegexp() { From 4450c1542bb79273b5e194fc3cb1a7a57eb5ed0e Mon Sep 17 00:00:00 2001 From: lucaslin Date: Tue, 30 Mar 2021 16:54:45 +0800 Subject: [PATCH 3/6] Add transport type in capabilities filter of EthernetNetworkFacotry Bug: 167544279 Test: atest EthernetServiceTests Change-Id: Ie64e3cff0ace413f14682736de7a1b65fa93e705 --- .../src/com/android/server/ethernet/EthernetNetworkFactory.java | 1 + 1 file changed, 1 insertion(+) diff --git a/service-t/src/com/android/server/ethernet/EthernetNetworkFactory.java b/service-t/src/com/android/server/ethernet/EthernetNetworkFactory.java index 75e77b9596..f9e8b00562 100644 --- a/service-t/src/com/android/server/ethernet/EthernetNetworkFactory.java +++ b/service-t/src/com/android/server/ethernet/EthernetNetworkFactory.java @@ -169,6 +169,7 @@ public class EthernetNetworkFactory extends NetworkFactory { private void updateCapabilityFilter() { NetworkCapabilities capabilitiesFilter = new NetworkCapabilities.Builder() .clearAll() + .addTransportType(NetworkCapabilities.TRANSPORT_ETHERNET) .build(); for (NetworkInterfaceState iface: mTrackingInterfaces.values()) { From 3056b7418bfc37b601b52c90fcdd8cb1fd97e37e Mon Sep 17 00:00:00 2001 From: paulhu Date: Tue, 30 Mar 2021 10:55:37 +0800 Subject: [PATCH 4/6] Enforce ACCESS_NETWORK_STATE to getAvailableInterfaces() getAvailableInterfaces() will return available ethernet interfaces which are the information about networks. So it should enforce ACCESS_NETWORK_STATE permission check to ensure the applications are allowed to access the information. Bug: 174573778 Test: TetheringTests Test: CtsTetheringTest Change-Id: I7aaa5225d56f2feecc51ba263489ed0ce02fd651 --- .../src/com/android/server/ethernet/EthernetServiceImpl.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/service-t/src/com/android/server/ethernet/EthernetServiceImpl.java b/service-t/src/com/android/server/ethernet/EthernetServiceImpl.java index 3fc6aab758..c06f61e446 100644 --- a/service-t/src/com/android/server/ethernet/EthernetServiceImpl.java +++ b/service-t/src/com/android/server/ethernet/EthernetServiceImpl.java @@ -87,6 +87,8 @@ public class EthernetServiceImpl extends IEthernetManager.Stub { @Override public String[] getAvailableInterfaces() throws RemoteException { + enforceAccessPermission(); + return mTracker.getInterfaces(checkUseRestrictedNetworksPermission()); } From 6d8141caa14772668a95375df33f60f1b84b59d7 Mon Sep 17 00:00:00 2001 From: Chiachang Wang Date: Thu, 13 May 2021 10:21:59 +0800 Subject: [PATCH 5/6] Replace clearAll with withoutDefaultCapabilities in NC#Builder Update the naming and usgae according to API review feedback. Bug: 184735772 Test: atest EthernetTrackerTest Change-Id: Ie8dc0bcdf46ceebda5d6062231b48c1f63b250f6 --- .../android/server/ethernet/EthernetNetworkFactory.java | 4 ++-- .../src/com/android/server/ethernet/EthernetTracker.java | 7 +++---- .../com/android/server/ethernet/EthernetTrackerTest.java | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/service-t/src/com/android/server/ethernet/EthernetNetworkFactory.java b/service-t/src/com/android/server/ethernet/EthernetNetworkFactory.java index f9e8b00562..aa80e4de2d 100644 --- a/service-t/src/com/android/server/ethernet/EthernetNetworkFactory.java +++ b/service-t/src/com/android/server/ethernet/EthernetNetworkFactory.java @@ -167,8 +167,8 @@ public class EthernetNetworkFactory extends NetworkFactory { } private void updateCapabilityFilter() { - NetworkCapabilities capabilitiesFilter = new NetworkCapabilities.Builder() - .clearAll() + NetworkCapabilities capabilitiesFilter = + NetworkCapabilities.Builder.withoutDefaultCapabilities() .addTransportType(NetworkCapabilities.TRANSPORT_ETHERNET) .build(); diff --git a/service-t/src/com/android/server/ethernet/EthernetTracker.java b/service-t/src/com/android/server/ethernet/EthernetTracker.java index a190240edb..b2b60fcb83 100644 --- a/service-t/src/com/android/server/ethernet/EthernetTracker.java +++ b/service-t/src/com/android/server/ethernet/EthernetTracker.java @@ -507,10 +507,9 @@ final class EthernetTracker { boolean clearDefaultCapabilities, @Nullable String commaSeparatedCapabilities, @Nullable String overrideTransport) { - final NetworkCapabilities.Builder builder = new NetworkCapabilities.Builder(); - if (clearDefaultCapabilities) { - builder.clearAll(); // Remove default capabilities and transports - } + final NetworkCapabilities.Builder builder = clearDefaultCapabilities + ? NetworkCapabilities.Builder.withoutDefaultCapabilities() + : new NetworkCapabilities.Builder(); // Determine the transport type. If someone has tried to define an override transport then // attempt to add it. Since we can only have one override, all errors with it will diff --git a/tests/ethernet/java/com/android/server/ethernet/EthernetTrackerTest.java b/tests/ethernet/java/com/android/server/ethernet/EthernetTrackerTest.java index 22b1b6939e..ee9f349a28 100644 --- a/tests/ethernet/java/com/android/server/ethernet/EthernetTrackerTest.java +++ b/tests/ethernet/java/com/android/server/ethernet/EthernetTrackerTest.java @@ -107,7 +107,7 @@ public class EthernetTrackerTest { private NetworkCapabilities.Builder makeEthernetCapabilitiesBuilder(boolean clearAll) { final NetworkCapabilities.Builder builder = - clearAll ? new NetworkCapabilities.Builder().clearAll() + clearAll ? NetworkCapabilities.Builder.withoutDefaultCapabilities() : new NetworkCapabilities.Builder(); return builder.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_ROAMING) .addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_CONGESTED) From 75f629ace72451d2d73d3fa22e021a6325f9c20f Mon Sep 17 00:00:00 2001 From: Lorenzo Colitti Date: Mon, 21 Jun 2021 10:34:48 +0000 Subject: [PATCH 6/6] Stop using LinkPropertiesParcelableUtil. Its methods are all no-ops. Stop using them. Test: m Bug: 151052811 Original-Change: https://android-review.googlesource.com/1733473 Merged-In: Iace3ba898bec2940ec3c3323c5bf8a13627d545f Change-Id: Iace3ba898bec2940ec3c3323c5bf8a13627d545f --- .../com/android/server/ethernet/EthernetNetworkFactory.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/service-t/src/com/android/server/ethernet/EthernetNetworkFactory.java b/service-t/src/com/android/server/ethernet/EthernetNetworkFactory.java index aa80e4de2d..28b24f1fb1 100644 --- a/service-t/src/com/android/server/ethernet/EthernetNetworkFactory.java +++ b/service-t/src/com/android/server/ethernet/EthernetNetworkFactory.java @@ -16,8 +16,6 @@ package com.android.server.ethernet; -import static android.net.shared.LinkPropertiesParcelableUtil.toStableParcelable; - import static com.android.internal.util.Preconditions.checkNotNull; import android.annotation.NonNull; @@ -560,7 +558,7 @@ public class EthernetNetworkFactory extends NetworkFactory { if (config.getProxySettings() == ProxySettings.STATIC || config.getProxySettings() == ProxySettings.PAC) { try { - ipClient.setHttpProxy(toStableParcelable(config.getHttpProxy())); + ipClient.setHttpProxy(config.getHttpProxy()); } catch (RemoteException e) { e.rethrowFromSystemServer(); }