From 9a87f80faac43791325c97ace8f36e52b8ea3363 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 Merged-In: I8e1fb5b47fff3bf624131ba1f5732daabd991e6d Merged-In: I0a2a1e5d3de14ea86556ca471e26064df3481412 --- 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 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"); } @@ -102,6 +105,24 @@ public class NetworkStackUtils { return 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