From d64f58e96166e3695179f64a5eac52e6f53e39ca Mon Sep 17 00:00:00 2001 From: Xiao Ma Date: Tue, 10 Dec 2019 15:56:41 +0900 Subject: Read ARP timing properties from DeviceConfig appropriately. Overload NetworkStackUtils.getDeviceConfigPropertyInt API to check if the value of property read from DeviceConfig is valid, value in the range of mininum and maximum would be acceptable, otherwise, return the default value. Bug: 128639898 Test: atest NetworkStackTests NetworkStackIntegrationTests Change-Id: I07e3e9d1e1b7252d852d4665d2ea254f29a1c3eb --- src/android/net/util/NetworkStackUtils.java | 17 +++++++++++++++++ 1 file changed, 17 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 45ed367..d147b45 100644 --- a/src/android/net/util/NetworkStackUtils.java +++ b/src/android/net/util/NetworkStackUtils.java @@ -228,6 +228,23 @@ 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 minimumValue The minimum value of a property. + * @param maximumValue The maximum value of a property. + * @param defaultValue The value to return if the property does not exist or its value is null. + * @return the corresponding value, or defaultValue if none exists or the fetched value is + * greater than maximumValue. + */ + public static int getDeviceConfigPropertyInt(@NonNull String namespace, @NonNull String name, + int minimumValue, int maximumValue, int defaultValue) { + int value = getDeviceConfigPropertyInt(namespace, name, defaultValue); + if (value < minimumValue || value > maximumValue) return defaultValue; + return value; + } + /** * Look up the value of a property for a particular namespace from {@link DeviceConfig}. * @param namespace The namespace containing the property to look up. -- cgit v1.2.3