diff options
author | Chiachang Wang <chiachangwang@google.com> | 2019-04-09 21:14:56 -0700 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2019-04-09 21:14:56 -0700 |
commit | 93f9d0961c4a552cffb38a8e114e3d40be0b5218 (patch) | |
tree | 47fda2e17639e0d52772a35b253355054802b2b0 /src/android/net/util/NetworkStackUtils.java | |
parent | 47cec910711d2e4bab39d5efc04d89d783c58e05 (diff) | |
parent | 816dd2a60f7b55ac3253953f74ed238189e60db5 (diff) |
Merge "Move data stall definitions out from Setting"
am: e9a39ceb6b
Change-Id: Iff3db380ed6210811965ec8919acb6c06fbbf1da
Diffstat (limited to 'src/android/net/util/NetworkStackUtils.java')
-rw-r--r-- | src/android/net/util/NetworkStackUtils.java | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/android/net/util/NetworkStackUtils.java b/src/android/net/util/NetworkStackUtils.java index ee83a85..fa8f65e 100644 --- a/src/android/net/util/NetworkStackUtils.java +++ b/src/android/net/util/NetworkStackUtils.java @@ -31,6 +31,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 { } /** + * 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. */ public static native void attachDhcpFilter(FileDescriptor fd) throws SocketException; |