diff options
author | Chiachang Wang <chiachangwang@google.com> | 2019-04-08 19:06:21 +0800 |
---|---|---|
committer | Chiachang Wang <chiachangwang@google.com> | 2019-04-10 02:37:57 +0000 |
commit | 9a87f80faac43791325c97ace8f36e52b8ea3363 (patch) | |
tree | bb55d240588aa748abd8f364d3cf805b12f5ade1 /src/android/net/util/NetworkStackUtils.java | |
parent | 2c08f1023991f4707fab19c3647cdb68fbcc06d9 (diff) |
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
Merged-In: I8e1fb5b47fff3bf624131ba1f5732daabd991e6d
Merged-In: I0a2a1e5d3de14ea86556ca471e26064df3481412
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; |