From 14550572ba8f500922f546e12c56e09d4600b1c5 Mon Sep 17 00:00:00 2001 From: Chiachang Wang Date: Mon, 1 Apr 2019 15:41:06 +0800 Subject: Link to android experimental flags API Bug: 120013793 Test: Build and atest NetworkStackTests Change-Id: I5c12b48e886e124025ecaa8548b70f26ebd20263 --- src/android/net/util/NetworkStackUtils.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/android/net/util/NetworkStackUtils.java') diff --git a/src/android/net/util/NetworkStackUtils.java b/src/android/net/util/NetworkStackUtils.java index 670563c..9d2df57 100644 --- a/src/android/net/util/NetworkStackUtils.java +++ b/src/android/net/util/NetworkStackUtils.java @@ -18,6 +18,7 @@ package android.net.util; import android.annotation.NonNull; import android.annotation.Nullable; +import android.provider.DeviceConfig; import android.util.SparseArray; import java.io.FileDescriptor; @@ -94,7 +95,7 @@ public class NetworkStackUtils { @Nullable public static String getDeviceConfigProperty(@NonNull String namespace, @NonNull String name, @Nullable String defaultValue) { - // TODO: Link to DeviceConfig API once it is ready. - return defaultValue; + String value = DeviceConfig.getProperty(namespace, name); + return value != null ? value : defaultValue; } } -- cgit v1.2.3 From f38a564a2ae4550fccce6ffa9007478135ebaaff Mon Sep 17 00:00:00 2001 From: Remi NGUYEN VAN Date: Fri, 5 Apr 2019 04:44:45 -0700 Subject: Move attach*Filter() and addArpEntry() methods to NetworkStack The SocketUtils.attach*Filter and SocketUtils.addArpEntry methods were added there because they could not be added as JNI inside the NetworkStack. This was not possible because on Go devices, the NetworkStack was a jar library. But now, Go also uses an APK. Hence, move these methods to the NetworkStack. Fixes: 129433183 Merged-In: I66d7b3e4fbfa32bb0bc853e8cf9399031daff8a9 (cherry picked from commit fe71be2b04a3213828dc0347a1dd4a3675d20562) Change-Id: Ice433a41469e784385f19498c154345d7b9c69b5 --- src/android/net/util/NetworkStackUtils.java | 41 ++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'src/android/net/util/NetworkStackUtils.java') diff --git a/src/android/net/util/NetworkStackUtils.java b/src/android/net/util/NetworkStackUtils.java index 9d2df57..dada61c 100644 --- a/src/android/net/util/NetworkStackUtils.java +++ b/src/android/net/util/NetworkStackUtils.java @@ -23,14 +23,18 @@ import android.util.SparseArray; import java.io.FileDescriptor; import java.io.IOException; +import java.net.Inet4Address; +import java.net.SocketException; import java.util.List; import java.util.function.Predicate; - /** * Collection of utilities for the network stack. */ public class NetworkStackUtils { + static { + System.loadLibrary("networkstackutilsjni"); + } /** * @return True if the array is null or 0-length. @@ -98,4 +102,39 @@ public class NetworkStackUtils { String value = DeviceConfig.getProperty(namespace, name); return value != null ? value : defaultValue; } + + /** + * Attaches a socket filter that accepts DHCP packets to the given socket. + */ + public static native void attachDhcpFilter(FileDescriptor fd) throws SocketException; + + /** + * Attaches a socket filter that accepts ICMPv6 router advertisements to the given socket. + * @param fd the socket's {@link FileDescriptor}. + * @param packetType the hardware address type, one of ARPHRD_*. + */ + public static native void attachRaFilter(FileDescriptor fd, int packetType) + throws SocketException; + + /** + * Attaches a socket filter that accepts L2-L4 signaling traffic required for IP connectivity. + * + * This includes: all ARP, ICMPv6 RS/RA/NS/NA messages, and DHCPv4 exchanges. + * + * @param fd the socket's {@link FileDescriptor}. + * @param packetType the hardware address type, one of ARPHRD_*. + */ + public static native void attachControlPacketFilter(FileDescriptor fd, int packetType) + throws SocketException; + + /** + * Add an entry into the ARP cache. + */ + public static void addArpEntry(Inet4Address ipv4Addr, android.net.MacAddress ethAddr, + String ifname, FileDescriptor fd) throws IOException { + addArpEntry(ethAddr.toByteArray(), ipv4Addr.getAddress(), ifname, fd); + } + + private static native void addArpEntry(byte[] ethAddr, byte[] netAddr, String ifname, + FileDescriptor fd) throws IOException; } -- cgit v1.2.3 From 7f14d3f66b5725dfc7c8aca6fbbfa8955ea9565e Mon Sep 17 00:00:00 2001 From: Chiachang Wang Date: Mon, 8 Apr 2019 19:06:21 +0800 Subject: Move data stall definitions out from Setting From mainline perspective, we should use android flag api instead of using Settings. Thus, move the definitions into NetworkStack. Bug:120013793 Test: atest NetworkStackTests SettingsBackupTest Change-Id: I8e1fb5b47fff3bf624131ba1f5732daabd991e6d --- src/android/net/util/NetworkStackUtils.java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/android/net/util/NetworkStackUtils.java') diff --git a/src/android/net/util/NetworkStackUtils.java b/src/android/net/util/NetworkStackUtils.java index dada61c..e7a607b 100644 --- a/src/android/net/util/NetworkStackUtils.java +++ b/src/android/net/util/NetworkStackUtils.java @@ -32,6 +32,9 @@ import java.util.function.Predicate; * Collection of utilities for the network stack. */ public class NetworkStackUtils { + // TODO: Refer to DeviceConfig definition. + public static final String NAMESPACE_CONNECTIVITY = "connectivity"; + static { System.loadLibrary("networkstackutilsjni"); } @@ -103,6 +106,24 @@ public class NetworkStackUtils { return value != null ? value : defaultValue; } + /** + * Look up the value of a property for a particular namespace from {@link DeviceConfig}. + * @param namespace The namespace containing the property to look up. + * @param name The name of the property to look up. + * @param defaultValue The value to return if the property does not exist or has no non-null + * value. + * @return the corresponding value, or defaultValue if none exists. + */ + public static int getDeviceConfigPropertyInt(@NonNull String namespace, @NonNull String name, + int defaultValue) { + String value = getDeviceConfigProperty(namespace, name, null /* defaultValue */); + try { + return (value != null) ? Integer.parseInt(value) : defaultValue; + } catch (NumberFormatException e) { + return defaultValue; + } + } + /** * Attaches a socket filter that accepts DHCP packets to the given socket. */ -- cgit v1.2.3 From 6f196bf372269f473629d46a65ee533d72ab0f53 Mon Sep 17 00:00:00 2001 From: Chiachang Wang Date: Thu, 11 Apr 2019 12:43:52 -0700 Subject: Address nit in NetworkStackUtils Follow up commit to fix nit in aosp/937891 Bug: 120013793 Test: Build Change-Id: I61a6306d3c439a2d72323ab56e2b47771cc60d48 Merged-In: Ide4741305724a9e0d26305f8406c5445f9de12b3 (cherry picked from commit cfb4e06b14925a7ed4324df0e40ec521256ed249) --- src/android/net/util/NetworkStackUtils.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/android/net/util/NetworkStackUtils.java') diff --git a/src/android/net/util/NetworkStackUtils.java b/src/android/net/util/NetworkStackUtils.java index e7a607b..8226787 100644 --- a/src/android/net/util/NetworkStackUtils.java +++ b/src/android/net/util/NetworkStackUtils.java @@ -95,8 +95,7 @@ public class NetworkStackUtils { * Look up the value of a property for a particular namespace from {@link DeviceConfig}. * @param namespace The namespace containing the property to look up. * @param name The name of the property to look up. - * @param defaultValue The value to return if the property does not exist or has no non-null - * value. + * @param defaultValue The value to return if the property does not exist or has no valid value. * @return the corresponding value, or defaultValue if none exists. */ @Nullable -- cgit v1.2.3 From 0d78f81dc3ddbe2ff0c6f1828e862d6148e9675d Mon Sep 17 00:00:00 2001 From: Chiachang Wang Date: Thu, 18 Apr 2019 01:25:00 -0700 Subject: Move Setting constants for NetworkStack From mainline perspective, we should use android flag api instead of using Settings. Thus, move the definitions into NetworkStack and apply new flag design. Bug: 123167629 Test: atest NetworkStackTests Change-Id: I9602263f0bff5d8e942bd652de69ccfcb3034a2f Merged-In: I6820300c412f94989a5fce7bd6c6f2a3b983b96e Merged-In: I4f6d130ffbee14f5087d75a8bc211680a34be682 (cherry picked from commit 01440ea909732e5d6f81604b61841f07b3d83217) --- src/android/net/util/NetworkStackUtils.java | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/android/net/util/NetworkStackUtils.java') diff --git a/src/android/net/util/NetworkStackUtils.java b/src/android/net/util/NetworkStackUtils.java index 8226787..97e8186 100644 --- a/src/android/net/util/NetworkStackUtils.java +++ b/src/android/net/util/NetworkStackUtils.java @@ -35,6 +35,34 @@ public class NetworkStackUtils { // TODO: Refer to DeviceConfig definition. public static final String NAMESPACE_CONNECTIVITY = "connectivity"; + /** + * A list of captive portal detection specifications used in addition to the fallback URLs. + * Each spec has the format url@@/@@statusCodeRegex@@/@@contentRegex. Specs are separated + * by "@@,@@". + */ + public static final String CAPTIVE_PORTAL_FALLBACK_PROBE_SPECS = + "captive_portal_fallback_probe_specs"; + + /** + * A comma separated list of URLs used for captive portal detection in addition to the + * fallback HTTP url associated with the CAPTIVE_PORTAL_FALLBACK_URL settings. + */ + public static final String CAPTIVE_PORTAL_OTHER_FALLBACK_URLS = + "captive_portal_other_fallback_urls"; + + /** + * Which User-Agent string to use in the header of the captive portal detection probes. + * The User-Agent field is unset when this setting has no value (HttpUrlConnection default). + */ + public static final String CAPTIVE_PORTAL_USER_AGENT = "captive_portal_user_agent"; + + /** + * Whether to use HTTPS for network validation. This is enabled by default and the setting + * needs to be set to 0 to disable it. This setting is a misnomer because captive portals + * don't actually use HTTPS, but it's consistent with the other settings. + */ + public static final String CAPTIVE_PORTAL_USE_HTTPS = "captive_portal_use_https"; + static { System.loadLibrary("networkstackutilsjni"); } -- cgit v1.2.3 From 11347f878dc6750249800752c208d899da40de9e Mon Sep 17 00:00:00 2001 From: Chiachang Wang Date: Tue, 23 Apr 2019 09:32:14 +0800 Subject: Remove Settings constants for NetworkStack The definitions reference of these constants are moved from Settings to DeviceConfig. These definitions are @hide and the usage in the Settings are removed. Thus, remove the definitions from API level. Bug: 123167629 Test: make system-api-stubs-docs-update-current-api \ test-api-stubs-docs-update-current-api Test: atest NetworkStackTests Change-Id: I28c4bf2c0b72e154cea91d11007a9497c7f21570 --- src/android/net/util/NetworkStackUtils.java | 43 +++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'src/android/net/util/NetworkStackUtils.java') diff --git a/src/android/net/util/NetworkStackUtils.java b/src/android/net/util/NetworkStackUtils.java index 97e8186..2934e1c 100644 --- a/src/android/net/util/NetworkStackUtils.java +++ b/src/android/net/util/NetworkStackUtils.java @@ -63,6 +63,49 @@ public class NetworkStackUtils { */ public static final String CAPTIVE_PORTAL_USE_HTTPS = "captive_portal_use_https"; + /** + * The URL used for HTTPS captive portal detection upon a new connection. + * A 204 response code from the server is used for validation. + */ + public static final String CAPTIVE_PORTAL_HTTPS_URL = "captive_portal_https_url"; + + /** + * The URL used for HTTP captive portal detection upon a new connection. + * A 204 response code from the server is used for validation. + */ + public static final String CAPTIVE_PORTAL_HTTP_URL = "captive_portal_http_url"; + + /** + * The URL used for fallback HTTP captive portal detection when previous HTTP + * and HTTPS captive portal detection attemps did not return a conclusive answer. + */ + public static final String CAPTIVE_PORTAL_FALLBACK_URL = "captive_portal_fallback_url"; + + /** + * What to do when connecting a network that presents a captive portal. + * Must be one of the CAPTIVE_PORTAL_MODE_* constants above. + * + * The default for this setting is CAPTIVE_PORTAL_MODE_PROMPT. + */ + public static final String CAPTIVE_PORTAL_MODE = "captive_portal_mode"; + + /** + * Don't attempt to detect captive portals. + */ + public static final int CAPTIVE_PORTAL_MODE_IGNORE = 0; + + /** + * When detecting a captive portal, display a notification that + * prompts the user to sign in. + */ + public static final int CAPTIVE_PORTAL_MODE_PROMPT = 1; + + /** + * When detecting a captive portal, immediately disconnect from the + * network and do not reconnect to that network in the future. + */ + public static final int CAPTIVE_PORTAL_MODE_AVOID = 2; + static { System.loadLibrary("networkstackutilsjni"); } -- cgit v1.2.3