diff options
author | Chiachang Wang <chiachangwang@google.com> | 2019-04-10 03:27:19 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2019-04-10 03:27:19 +0000 |
commit | 816dd2a60f7b55ac3253953f74ed238189e60db5 (patch) | |
tree | 47fda2e17639e0d52772a35b253355054802b2b0 /src/android/net/util/NetworkStackUtils.java | |
parent | 9f61a127c4ee8e094ede70bcfefa124624f53c65 (diff) | |
parent | 9a87f80faac43791325c97ace8f36e52b8ea3363 (diff) |
Merge "Move data stall definitions out from Setting"
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; |